17
17
import org .truffleruby .core .array .ArrayGuards ;
18
18
import org .truffleruby .core .array .library .ArrayStoreLibrary .ArrayAllocator ;
19
19
import org .truffleruby .language .RubyBaseNode ;
20
+ import org .truffleruby .language .RubyDynamicObject ;
20
21
import org .truffleruby .language .objects .ObjectGraph ;
21
22
import org .truffleruby .language .objects .ObjectGraphNode ;
23
+ import org .truffleruby .language .objects .shared .SharedObjects ;
22
24
import org .truffleruby .language .objects .shared .WriteBarrierNode ;
23
25
24
26
import com .oracle .truffle .api .TruffleSafepoint ;
@@ -43,6 +45,28 @@ public SharedArrayStorage(Object storage) {
43
45
this .storage = storage ;
44
46
}
45
47
48
+ /* Method for checking that all elements in this array are correctly shared. This can only be called after the whole
49
+ * stack of adjacent objects have been shared, which may not be true at the point the storage is converted to shared
50
+ * storage. */
51
+ @ TruffleBoundary
52
+ public boolean allElementsShared () {
53
+ if (storage == null || storage instanceof ZeroLengthArrayStore ) {
54
+ return true ;
55
+ }
56
+ ArrayStoreLibrary stores = ArrayStoreLibrary .getFactory ()
57
+ .getUncached (storage );
58
+ var elements = stores .getIterable (storage , 0 , stores .capacity (storage ));
59
+ for (var e : elements ) {
60
+ if (e == null || !(e instanceof RubyDynamicObject ) || SharedObjects .isShared (e )) {
61
+ continue ;
62
+ } else {
63
+ System .err .printf ("Unshared element %s.\n " , e );
64
+ return false ;
65
+ }
66
+ }
67
+ return true ;
68
+ }
69
+
46
70
@ ExportMessage
47
71
protected static boolean accepts (SharedArrayStorage store ,
48
72
@ CachedLibrary (limit = "1" ) ArrayStoreLibrary stores ) {
0 commit comments