6
6
import org .jruby .RubyClass ;
7
7
import org .jruby .RubyModule ;
8
8
import org .jruby .RubyObject ;
9
+ import org .jruby .RubyBasicObject ;
9
10
import org .jruby .anno .JRubyClass ;
10
11
import org .jruby .anno .JRubyMethod ;
11
12
import org .jruby .runtime .ObjectAllocator ;
@@ -47,6 +48,9 @@ public void load(Ruby runtime, boolean wrap) throws IOException {
47
48
defineModule ("Concurrent" ).
48
49
defineModuleUnder ("Synchronization" );
49
50
51
+ RubyModule jrubyAttrVolatileModule = synchronizationModule .defineModuleUnder ("JRubyAttrVolatile" );
52
+ jrubyAttrVolatileModule .defineAnnotatedMethods (JRubyAttrVolatile .class );
53
+
50
54
defineClass (runtime , synchronizationModule , "AbstractObject" , "JRubyObject" ,
51
55
JRubyObject .class , JRUBY_OBJECT_ALLOCATOR );
52
56
@@ -81,21 +85,12 @@ private RubyClass defineClass(Ruby runtime, RubyModule namespace, String parentN
81
85
// SynchronizedVariableAccessor wraps with synchronized block, StampedVariableAccessor uses fullFence or
82
86
// volatilePut
83
87
84
- @ JRubyClass ( name = "JRubyObject" , parent = "AbstractObject" )
85
- public static class JRubyObject extends RubyObject {
88
+ // module JRubyAttrVolatile
89
+ public static class JRubyAttrVolatile {
86
90
private static volatile ThreadContext threadContext = null ;
87
91
88
- public JRubyObject (Ruby runtime , RubyClass metaClass ) {
89
- super (runtime , metaClass );
90
- }
91
-
92
- @ JRubyMethod
93
- public IRubyObject initialize (ThreadContext context ) {
94
- return this ;
95
- }
96
-
97
92
@ JRubyMethod (name = "full_memory_barrier" , visibility = Visibility .PRIVATE )
98
- public IRubyObject fullMemoryBarrier (ThreadContext context ) {
93
+ public static IRubyObject fullMemoryBarrier (ThreadContext context , IRubyObject self ) {
99
94
// Prevent reordering of ivar writes with publication of this instance
100
95
if (UnsafeHolder .U == null || !UnsafeHolder .SUPPORTS_FENCES ) {
101
96
// Assuming that following volatile read and write is not eliminated it simulates fullFence.
@@ -109,35 +104,43 @@ public IRubyObject fullMemoryBarrier(ThreadContext context) {
109
104
}
110
105
111
106
@ JRubyMethod (name = "instance_variable_get_volatile" , visibility = Visibility .PROTECTED )
112
- public IRubyObject instanceVariableGetVolatile (ThreadContext context , IRubyObject name ) {
107
+ public static IRubyObject instanceVariableGetVolatile (ThreadContext context , IRubyObject self , IRubyObject name ) {
113
108
// Ensure we ses latest value with loadFence
114
109
if (UnsafeHolder .U == null || !UnsafeHolder .SUPPORTS_FENCES ) {
115
110
// piggybacking on volatile read, simulating loadFence
116
111
final ThreadContext oldContext = threadContext ;
117
- return instance_variable_get (context , name );
112
+ return (( RubyBasicObject ) self ). instance_variable_get (context , name );
118
113
} else {
119
114
UnsafeHolder .loadFence ();
120
- return instance_variable_get (context , name );
115
+ return (( RubyBasicObject ) self ). instance_variable_get (context , name );
121
116
}
122
117
}
123
118
124
119
@ JRubyMethod (name = "instance_variable_set_volatile" , visibility = Visibility .PROTECTED )
125
- public IRubyObject InstanceVariableSetVolatile (ThreadContext context , IRubyObject name , IRubyObject value ) {
120
+ public static IRubyObject InstanceVariableSetVolatile (ThreadContext context , IRubyObject self , IRubyObject name , IRubyObject value ) {
126
121
// Ensure we make last update visible
127
122
if (UnsafeHolder .U == null || !UnsafeHolder .SUPPORTS_FENCES ) {
128
123
// piggybacking on volatile write, simulating storeFence
129
- final IRubyObject result = instance_variable_set (name , value );
124
+ final IRubyObject result = (( RubyBasicObject ) self ). instance_variable_set (name , value );
130
125
threadContext = context ;
131
126
return result ;
132
127
} else {
133
128
// JRuby uses StampedVariableAccessor which calls fullFence
134
129
// so no additional steps needed.
135
130
// See https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/runtime/ivars/StampedVariableAccessor.java#L151-L159
136
- return instance_variable_set (name , value );
131
+ return (( RubyBasicObject ) self ). instance_variable_set (name , value );
137
132
}
138
133
}
139
134
}
140
135
136
+ @ JRubyClass (name = "JRubyObject" , parent = "AbstractObject" )
137
+ public static class JRubyObject extends RubyObject {
138
+
139
+ public JRubyObject (Ruby runtime , RubyClass metaClass ) {
140
+ super (runtime , metaClass );
141
+ }
142
+ }
143
+
141
144
@ JRubyClass (name = "Object" , parent = "JRubyObject" )
142
145
public static class Object extends JRubyObject {
143
146
0 commit comments