9
9
*/
10
10
package org .truffleruby .language .objects ;
11
11
12
+ import com .oracle .truffle .api .dsl .CachedContext ;
13
+ import com .oracle .truffle .api .dsl .GenerateUncached ;
14
+ import org .truffleruby .RubyContext ;
15
+ import org .truffleruby .RubyLanguage ;
12
16
import org .truffleruby .core .basicobject .BasicObjectNodes .ObjectIDNode ;
13
17
import org .truffleruby .core .klass .ClassNodes ;
14
18
import org .truffleruby .core .klass .RubyClass ;
15
19
import org .truffleruby .core .numeric .RubyBignum ;
16
20
import org .truffleruby .core .string .StringUtils ;
17
21
import org .truffleruby .core .symbol .RubySymbol ;
18
22
import org .truffleruby .language .Nil ;
19
- import org .truffleruby .language .RubyContextSourceNode ;
20
23
import org .truffleruby .language .RubyDynamicObject ;
21
24
import org .truffleruby .language .RubyNode ;
25
+ import org .truffleruby .language .RubySourceNode ;
22
26
import org .truffleruby .language .control .RaiseException ;
23
27
import org .truffleruby .language .library .RubyLibrary ;
24
28
import org .truffleruby .language .objects .shared .SharedObjects ;
28
32
import com .oracle .truffle .api .dsl .NodeChild ;
29
33
import com .oracle .truffle .api .dsl .Specialization ;
30
34
35
+ @ GenerateUncached
31
36
@ NodeChild (value = "value" , type = RubyNode .class )
32
- public abstract class SingletonClassNode extends RubyContextSourceNode {
37
+ public abstract class SingletonClassNode extends RubySourceNode {
38
+
39
+ public static SingletonClassNode getUncached () {
40
+ return SingletonClassNodeGen .getUncached ();
41
+ }
33
42
34
43
public static SingletonClassNode create () {
35
44
return SingletonClassNodeGen .create (null );
@@ -38,43 +47,51 @@ public static SingletonClassNode create() {
38
47
public abstract RubyClass executeSingletonClass (Object value );
39
48
40
49
@ Specialization (guards = "value" )
41
- protected RubyClass singletonClassTrue (boolean value ) {
42
- return coreLibrary ().trueClass ;
50
+ protected RubyClass singletonClassTrue (boolean value ,
51
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
52
+ return context .getCoreLibrary ().trueClass ;
43
53
}
44
54
45
55
@ Specialization (guards = "!value" )
46
- protected RubyClass singletonClassFalse (boolean value ) {
47
- return coreLibrary ().falseClass ;
56
+ protected RubyClass singletonClassFalse (boolean value ,
57
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
58
+ return context .getCoreLibrary ().falseClass ;
48
59
}
49
60
50
61
@ Specialization
51
- protected RubyClass singletonClassNil (Nil value ) {
52
- return coreLibrary ().nilClass ;
62
+ protected RubyClass singletonClassNil (Nil value ,
63
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
64
+ return context .getCoreLibrary ().nilClass ;
53
65
}
54
66
55
67
@ Specialization
56
- protected RubyClass singletonClass (int value ) {
57
- return noSingletonClass ();
68
+ protected RubyClass singletonClass (int value ,
69
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
70
+ return noSingletonClass (context );
58
71
}
59
72
60
73
@ Specialization
61
- protected RubyClass singletonClass (long value ) {
62
- return noSingletonClass ();
74
+ protected RubyClass singletonClass (long value ,
75
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
76
+ return noSingletonClass (context );
63
77
}
64
78
65
79
@ Specialization
66
- protected RubyClass singletonClass (double value ) {
67
- return noSingletonClass ();
80
+ protected RubyClass singletonClass (double value ,
81
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
82
+ return noSingletonClass (context );
68
83
}
69
84
70
85
@ Specialization
71
- protected RubyClass singletonClassBignum (RubyBignum value ) {
72
- return noSingletonClass ();
86
+ protected RubyClass singletonClassBignum (RubyBignum value ,
87
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
88
+ return noSingletonClass (context );
73
89
}
74
90
75
91
@ Specialization
76
- protected RubyClass singletonClassSymbol (RubySymbol value ) {
77
- return noSingletonClass ();
92
+ protected RubyClass singletonClassSymbol (RubySymbol value ,
93
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
94
+ return noSingletonClass (context );
78
95
}
79
96
80
97
@ Specialization (
@@ -87,8 +104,9 @@ protected RubyClass singletonClassClassCached(RubyClass rubyClass,
87
104
}
88
105
89
106
@ Specialization (replaces = "singletonClassClassCached" )
90
- protected RubyClass singletonClassClassUncached (RubyClass rubyClass ) {
91
- return ClassNodes .getSingletonClass (getContext (), rubyClass );
107
+ protected RubyClass singletonClassClassUncached (RubyClass rubyClass ,
108
+ @ CachedContext (RubyLanguage .class ) RubyContext context ) {
109
+ return ClassNodes .getSingletonClass (context , rubyClass );
92
110
}
93
111
94
112
@ Specialization (
@@ -105,12 +123,12 @@ protected RubyClass singletonClassInstanceUncached(RubyDynamicObject object) {
105
123
return getSingletonClassForInstance (object );
106
124
}
107
125
108
- private RubyClass noSingletonClass () {
109
- throw new RaiseException (getContext (), coreExceptions ().typeErrorCantDefineSingleton (this ));
126
+ private RubyClass noSingletonClass (RubyContext context ) {
127
+ throw new RaiseException (context , context . getCoreExceptions ().typeErrorCantDefineSingleton (this ));
110
128
}
111
129
112
130
protected RubyClass getSingletonClassOrNull (RubyClass rubyClass ) {
113
- return ClassNodes .getSingletonClassOrNull (getContext (), rubyClass );
131
+ return ClassNodes .getSingletonClassOrNull (rubyClass . fields . getContext (), rubyClass );
114
132
}
115
133
116
134
@ TruffleBoundary
@@ -120,6 +138,7 @@ protected RubyClass getSingletonClassForInstance(RubyDynamicObject object) {
120
138
if (metaClass .isSingleton ) {
121
139
return metaClass ;
122
140
}
141
+ final RubyContext context = metaClass .fields .getContext ();
123
142
124
143
final RubyClass logicalClass = object .getLogicalClass ();
125
144
@@ -129,7 +148,7 @@ protected RubyClass getSingletonClassForInstance(RubyDynamicObject object) {
129
148
ObjectIDNode .getUncached ().execute (object ));
130
149
131
150
final RubyClass singletonClass = ClassNodes .createSingletonClassOfObject (
132
- getContext () ,
151
+ context ,
133
152
getEncapsulatingSourceSection (),
134
153
logicalClass ,
135
154
object ,
@@ -139,15 +158,19 @@ protected RubyClass getSingletonClassForInstance(RubyDynamicObject object) {
139
158
RubyLibrary .getUncached ().freeze (singletonClass );
140
159
}
141
160
142
- SharedObjects .propagate (getContext () , object , singletonClass );
161
+ SharedObjects .propagate (context , object , singletonClass );
143
162
object .setMetaClass (singletonClass );
144
163
145
164
return singletonClass ;
146
165
}
147
166
}
148
167
149
168
protected int getCacheLimit () {
150
- return getContext ().getOptions ().CLASS_CACHE ;
169
+ return RubyLanguage .getCurrentContext ().getOptions ().CLASS_CACHE ;
170
+ }
171
+
172
+ protected int getIdentityCacheLimit () {
173
+ return RubyLanguage .getCurrentContext ().getOptions ().IDENTITY_CACHE ;
151
174
}
152
175
153
176
}
0 commit comments