17
17
import org .truffleruby .language .objects .ObjectGraph ;
18
18
import org .truffleruby .language .objects .ShapeCachingGuards ;
19
19
20
- import com .oracle .truffle .api .CompilerDirectives ;
21
20
import com .oracle .truffle .api .dsl .Cached ;
22
21
import com .oracle .truffle .api .dsl .ImportStatic ;
23
22
import com .oracle .truffle .api .dsl .Specialization ;
27
26
import com .oracle .truffle .api .object .ObjectLocation ;
28
27
import com .oracle .truffle .api .object .Property ;
29
28
import com .oracle .truffle .api .object .Shape ;
29
+ import org .truffleruby .utils .RunTwiceBranchProfile ;
30
30
31
31
/** Share the object and all that is reachable from it (see {@link ObjectGraph#getAdjacentObjects}) */
32
32
@ ImportStatic (ShapeCachingGuards .class )
@@ -50,6 +50,7 @@ public ShareObjectNode(int depth) {
50
50
protected void shareCached (RubyDynamicObject object ,
51
51
@ Cached ("object.getShape()" ) Shape cachedShape ,
52
52
@ CachedLibrary (limit = "1" ) DynamicObjectLibrary objectLibrary ,
53
+ @ Cached ("new()" ) RunTwiceBranchProfile shareMetaClassProfile ,
53
54
@ Cached ("createShareInternalFieldsNode()" ) ShareInternalFieldsNode shareInternalFieldsNode ,
54
55
@ Cached ("getObjectProperties(cachedShape)" ) List <Property > properties ,
55
56
@ Cached ("createReadAndShareFieldNodes(properties)" ) ReadAndShareFieldNode [] readAndShareFieldNodes ,
@@ -59,20 +60,14 @@ protected void shareCached(RubyDynamicObject object,
59
60
objectLibrary .markShared (object );
60
61
assert object .getShape () == sharedShape ;
61
62
62
- // Share the logical class
63
- if (!object .getLogicalClass ().getShape ().isShared ()) {
64
- // The logical class is fixed for a given Shape and only needs to be shared once
65
- CompilerDirectives .transferToInterpreterAndInvalidate ();
66
- SharedObjects .writeBarrier (getLanguage (), object .getLogicalClass ());
67
- }
68
-
69
- // Share the metaclass. Note that the metaclass might refer to `object` via `attached`,
70
- // so it is important to share the object first.
63
+ // Share the metaclass. This will also the share the logical class, which is the same or its superclass.
64
+ // Note that the metaclass might refer to `object` via `attached`, so it is important to share the object first.
71
65
if (!object .getMetaClass ().getShape ().isShared ()) {
72
- // The metaclass is fixed for a given Shape and only needs to be shared once
73
- CompilerDirectives .transferToInterpreterAndInvalidate ();
66
+ shareMetaClassProfile .enter ();
74
67
SharedObjects .writeBarrier (getLanguage (), object .getMetaClass ());
75
68
}
69
+ assert SharedObjects
70
+ .isShared (object .getLogicalClass ()) : "the logical class should have been shared by the metaclass" ;
76
71
77
72
shareInternalFieldsNode .executeShare (object );
78
73
0 commit comments