Skip to content

Commit

Permalink
JRuby+Truffle support improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pitr-ch committed Nov 25, 2015
1 parent 93aaa08 commit 27b8bb7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
language: ruby

rvm:
- 2.2.3
- 2.2.2
- 2.1.5
- 2.1.4
- 2.0.0
- 1.9.3
- ruby-head
- jruby-1.7.19
- jruby-9.0.0.0
- jruby-9.0.1.0
- jruby-9.0.3.0
- jruby-9.0.4.0
- jruby-head
- rbx-2

Expand Down
4 changes: 3 additions & 1 deletion lib/concurrent/synchronization/lockable_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ module Synchronization
MriMutexLockableObject
when Concurrent.on_jruby?
JRubyLockableObject
when Concurrent.on_rbx? || Concurrent.on_truffle?
when Concurrent.on_rbx?
RbxLockableObject
when Concurrent.on_truffle?
TruffleLockableObject
else
warn 'Possibly unsupported Ruby implementation'
MriMonitorLockableObject
Expand Down
8 changes: 5 additions & 3 deletions lib/concurrent/synchronization/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ module Synchronization
MriObject
when Concurrent.on_jruby?
JRubyObject
when Concurrent.on_rbx? || Concurrent.on_truffle?
when Concurrent.on_rbx?
RbxObject
when Concurrent.on_truffle?
TruffleObject
else
MriObject
end
Expand Down Expand Up @@ -49,8 +51,8 @@ def self.safe_initialization!
# define only once, and not again in children
return if safe_initialization?

def self.new(*)
object = super
def self.new(*args, &block)
object = super(*args, &block)
ensure
object.full_memory_barrier if object
end
Expand Down
2 changes: 2 additions & 0 deletions lib/concurrent/synchronization/rbx_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def self.included(base)
end

module ClassMethods

def attr_volatile(*names)
names.each do |name|
ivar = :"@volatile_#{name}"
Expand All @@ -24,6 +25,7 @@ def #{name}=(value)
end
names.map { |n| [n, :"#{n}="] }.flatten
end

end

def full_memory_barrier
Expand Down
7 changes: 7 additions & 0 deletions lib/concurrent/synchronization/truffle_lockable_object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Concurrent
module Synchronization
class TruffleLockableObject
raise NotImplementedError
end
end
end
32 changes: 32 additions & 0 deletions lib/concurrent/synchronization/truffle_object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Concurrent
module Synchronization

module TruffleAttrVolatile
def self.included(base)
base.extend(ClassMethods)
end

module ClassMethods
def attr_volatile(*names)
# TODO may not always be available
attr_atomic(*names)
end
end

def full_memory_barrier
# Rubinius instance variables are not volatile so we need to insert barrier
Rubinius.memory_barrier

This comment has been minimized.

Copy link
@mighe

mighe Nov 26, 2015

Contributor

We're under JRuby/Truffle, this line is probably wrong

This comment has been minimized.

Copy link
@pitr-ch

pitr-ch Nov 26, 2015

Author Member

JRuby+Truffle supports some of the Rubinius APIs therefore this works, but the comment is definitely outdated and wrong, thanks I fix it.

end
end

# @!visibility private
# @!macro internal_implementation_note
class TruffleObject < AbstractObject
include TruffleAttrVolatile

def initialize
# nothing to do
end
end
end
end

0 comments on commit 27b8bb7

Please sign in to comment.