Skip to content

Commit de3d97d

Browse files
committed
Assert array and storage have matching shared sharing.
1 parent 189927e commit de3d97d

30 files changed

+146
-133
lines changed

src/main/java/org/truffleruby/core/array/ArrayAppendManyNode.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ protected RubyArray appendZero(RubyArray array, RubyArray other) {
3737
}
3838

3939
@Specialization(
40-
guards = { "!isEmptyArray(other)", "stores.acceptsAllValues(array.store, other.store)" },
40+
guards = { "!isEmptyArray(other)", "stores.acceptsAllValues(array.getStore(), other.getStore())" },
4141
limit = "storageStrategyLimit()")
4242
protected RubyArray appendManySameType(RubyArray array, RubyArray other,
43-
@Bind("array.store") Object store,
44-
@Bind("other.store") Object otherStore,
43+
@Bind("array.getStore()") Object store,
44+
@Bind("other.getStore()") Object otherStore,
4545
@CachedLibrary("store") ArrayStoreLibrary stores,
4646
@CachedLibrary("otherStore") ArrayStoreLibrary otherStores,
4747
@Cached ConditionProfile extendProfile) {
@@ -65,11 +65,11 @@ protected RubyArray appendManySameType(RubyArray array, RubyArray other,
6565
// Generalizations
6666

6767
@Specialization(
68-
guards = { "!isEmptyArray(other)", "!stores.acceptsAllValues(array.store, other.store)" },
68+
guards = { "!isEmptyArray(other)", "!stores.acceptsAllValues(array.getStore(), other.getStore())" },
6969
limit = "storageStrategyLimit()")
7070
protected RubyArray appendManyGeneralize(RubyArray array, RubyArray other,
71-
@Bind("array.store") Object store,
72-
@Bind("other.store") Object otherStore,
71+
@Bind("array.getStore()") Object store,
72+
@Bind("other.getStore()") Object otherStore,
7373
@CachedLibrary("store") ArrayStoreLibrary stores,
7474
@CachedLibrary("otherStore") ArrayStoreLibrary otherStores) {
7575
final int oldSize = array.size;

src/main/java/org/truffleruby/core/array/ArrayAppendOneNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static ArrayAppendOneNode create() {
4343
guards = { "stores.acceptsValue(store, value)" },
4444
limit = "storageStrategyLimit()")
4545
protected RubyArray appendOneSameType(RubyArray array, Object value,
46-
@Bind("array.store") Object store,
46+
@Bind("array.getStore()") Object store,
4747
@CachedLibrary("store") ArrayStoreLibrary stores,
4848
@Cached("createCountingProfile()") ConditionProfile extendProfile) {
4949
final int oldSize = array.size;
@@ -65,10 +65,10 @@ protected RubyArray appendOneSameType(RubyArray array, Object value,
6565
// Append forcing a generalization
6666

6767
@Specialization(
68-
guards = "!currentStores.acceptsValue(array.store, value)",
68+
guards = "!currentStores.acceptsValue(array.getStore(), value)",
6969
limit = "storageStrategyLimit()")
7070
protected RubyArray appendOneGeneralizeNonMutable(RubyArray array, Object value,
71-
@Bind("array.store") Object currentStore,
71+
@Bind("array.getStore()") Object currentStore,
7272
@CachedLibrary("currentStore") ArrayStoreLibrary currentStores,
7373
@CachedLibrary(limit = "storageStrategyLimit()") ArrayStoreLibrary newStores) {
7474
final int oldSize = array.size;

src/main/java/org/truffleruby/core/array/ArrayBuilderNode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ public static AppendArrayNode create() {
250250
public abstract void executeAppend(BuilderState state, int index, RubyArray value);
251251

252252
@Specialization(
253-
guards = { "arrays.acceptsAllValues(state.store, other.store)" },
253+
guards = { "arrays.acceptsAllValues(state.store, other.getStore())" },
254254
limit = "storageStrategyLimit()")
255255
protected void appendCompatibleStrategy(BuilderState state, int index, RubyArray other,
256256
@Bind("state.store") Object store,
257-
@Bind("other.store") Object otherStore,
257+
@Bind("other.getStore()") Object otherStore,
258258
@CachedLibrary("store") ArrayStoreLibrary arrays,
259259
@CachedLibrary("otherStore") ArrayStoreLibrary others) {
260260
assert state.nextIndex == index;
@@ -275,7 +275,7 @@ protected void appendCompatibleStrategy(BuilderState state, int index, RubyArray
275275
}
276276

277277
@Specialization(
278-
guards = { "!arrayLibrary.acceptsAllValues(state.store, other.store)" },
278+
guards = { "!arrayLibrary.acceptsAllValues(state.store, other.getStore())" },
279279
limit = "1")
280280
protected void appendNewStrategy(BuilderState state, int index, RubyArray other,
281281
@Bind("state.store") Object store,
@@ -298,13 +298,13 @@ protected void appendNewStrategy(BuilderState state, int index, RubyArray other,
298298
}
299299

300300
ArrayAllocator allocator = replaceNodes(
301-
newArrayLibrary.generalizeForStore(state.store, other.store),
301+
newArrayLibrary.generalizeForStore(state.store, other.getStore()),
302302
neededCapacity);
303303
newStore = allocator.allocate(neededCapacity);
304304

305305
newArrayLibrary.copyContents(state.store, 0, newStore, 0, index);
306306

307-
final Object otherStore = other.store;
307+
final Object otherStore = other.getStore();
308308
newArrayLibrary.copyContents(otherStore, 0, newStore, index, otherSize);
309309

310310
state.store = newStore;

src/main/java/org/truffleruby/core/array/ArrayCopyOnWriteNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ public static ArrayCopyOnWriteNode create() {
3131

3232
@Specialization(guards = "stores.isMutable(store)", limit = "storageStrategyLimit()")
3333
protected Object extractFromMutableArray(RubyArray array, int start, int length,
34-
@Bind("array.store") Object store,
34+
@Bind("array.getStore()") Object store,
3535
@CachedLibrary("store") ArrayStoreLibrary stores) {
3636
int size = array.size;
3737
Object cowStore = stores.extractRange(store, 0, size);
3838
/* This new store should not be shared because the RubyArray object which will own it is not yet shared. */
3939
Object range = stores.extractRangeAndUnshare(store, start, start + length);
40-
array.store = cowStore;
40+
array.setStore(cowStore);
4141
return range;
4242
}
4343

4444
@Specialization(guards = "!stores.isMutable(store)", limit = "storageStrategyLimit()")
4545
protected Object extractFromNonMutableArray(RubyArray array, int start, int length,
46-
@Bind("array.store") Object store,
46+
@Bind("array.getStore()") Object store,
4747
@CachedLibrary("store") ArrayStoreLibrary stores) {
4848
Object range = stores.extractRangeAndUnshare(store, start, start + length);
4949
return range;

src/main/java/org/truffleruby/core/array/ArrayDupNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public abstract class ArrayDupNode extends RubyBaseNode {
3434
"cachedSize <= MAX_EXPLODE_SIZE" },
3535
limit = "getCacheLimit()")
3636
protected RubyArray dupProfiledSize(RubyArray from,
37-
@Bind("from.store") Object fromStore,
37+
@Bind("from.getStore()") Object fromStore,
3838
@CachedLibrary("fromStore") ArrayStoreLibrary fromStores,
3939
@CachedLibrary(limit = "1") ArrayStoreLibrary toStores,
4040
@Cached("from.size") int cachedSize) {
@@ -56,7 +56,7 @@ private RubyArray copyArraySmall(RubyLanguage language,
5656

5757
@Specialization(replaces = "dupProfiledSize")
5858
protected RubyArray dup(RubyArray from,
59-
@Bind("from.store") Object fromStore,
59+
@Bind("from.getStore()") Object fromStore,
6060
@Cached ArrayCopyOnWriteNode cowNode) {
6161
final int size = from.size;
6262
final Object copy = cowNode.execute(from, 0, from.size);

src/main/java/org/truffleruby/core/array/ArrayEachIteratorNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public abstract RubyArray execute(RubyArray array, RubyProc block, int startAt,
4545
@Specialization(limit = "storageStrategyLimit()")
4646
protected RubyArray iterateMany(RubyArray array, RubyProc block, int startAt, ArrayElementConsumerNode consumerNode,
4747
// Checkstyle: stop -- Verified @Bind is not necessary here due to using `Library#accepts()`.
48-
@CachedLibrary("array.store") ArrayStoreLibrary stores,
48+
@CachedLibrary("array.getStore()") ArrayStoreLibrary stores,
4949
// Checkstyle: resume
5050
@Cached LoopConditionProfile loopProfile,
5151
@Cached IntValueProfile arraySizeProfile,
5252
@Cached ConditionProfile strategyMatchProfile) {
5353
int i = startAt;
5454
try {
5555
for (; loopProfile.inject(i < arraySizeProfile.profile(array.size)); i++) {
56-
Object store = array.store;
56+
Object store = array.getStore();
5757
if (strategyMatchProfile.profile(stores.accepts(store))) {
5858
consumerNode.accept(array, block, stores.read(store, i), i);
5959
} else {

src/main/java/org/truffleruby/core/array/ArrayEnsureCapacityNode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static ArrayEnsureCapacityNode create() {
3030

3131
@Specialization(guards = "!stores.isMutable(store)", limit = "storageStrategyLimit()")
3232
protected Object ensureCapacityAndMakeMutable(RubyArray array, int requiredCapacity,
33-
@Bind("array.store") Object store,
33+
@Bind("array.getStore()") Object store,
3434
@CachedLibrary("store") ArrayStoreLibrary stores,
3535
@Cached("createCountingProfile()") ConditionProfile extendProfile) {
3636
final int currentCapacity = stores.capacity(store);
@@ -43,20 +43,20 @@ protected Object ensureCapacityAndMakeMutable(RubyArray array, int requiredCapac
4343

4444
final Object newStore = stores.allocator(store).allocate(capacity);
4545
stores.copyContents(store, 0, newStore, 0, currentCapacity);
46-
array.store = newStore;
46+
array.setStore(newStore);
4747
return newStore;
4848
}
4949

5050
@Specialization(guards = "stores.isMutable(store)", limit = "storageStrategyLimit()")
5151
protected Object ensureCapacity(RubyArray array, int requiredCapacity,
52-
@Bind("array.store") Object store,
52+
@Bind("array.getStore()") Object store,
5353
@CachedLibrary("store") ArrayStoreLibrary stores,
5454
@Cached("createCountingProfile()") ConditionProfile extendProfile) {
5555
final int length = stores.capacity(store);
5656
if (extendProfile.profile(length < requiredCapacity)) {
5757
final int capacity = ArrayUtils.capacity(getLanguage(), length, requiredCapacity);
5858
Object newStore = stores.expand(store, capacity);
59-
array.store = newStore;
59+
array.setStore(newStore);
6060
return newStore;
6161
} else {
6262
return store;

src/main/java/org/truffleruby/core/array/ArrayGuards.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static int storageStrategyLimit() {
2121
// Storage strategies
2222

2323
public static boolean isObjectArray(RubyArray array) {
24-
final Object store = array.store;
24+
final Object store = array.getStore();
2525
return store.getClass() == Object[].class;
2626
}
2727

src/main/java/org/truffleruby/core/array/ArrayHelpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public abstract class ArrayHelpers {
1818

1919
public static void setStoreAndSize(RubyArray array, Object store, int size) {
2020
assert (store instanceof SharedArrayStorage) == (array.getShape().isShared());
21-
array.store = store;
21+
array.setStore(store);
2222
setSize(array, size);
2323
}
2424

src/main/java/org/truffleruby/core/array/ArrayIndexNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected ReadConstantIndexNode(int index) {
4444

4545
@Specialization(limit = "storageStrategyLimit()")
4646
protected Object readInBounds(RubyArray array,
47-
@Bind("array.store") Object store,
47+
@Bind("array.getStore()") Object store,
4848
@CachedLibrary("store") ArrayStoreLibrary stores,
4949
@Cached ConditionProfile isInBounds) {
5050
final int size = array.size;
@@ -75,7 +75,7 @@ public static ReadNormalizedNode create(RubyNode array, RubyNode index) {
7575
guards = "isInBounds(array, index)",
7676
limit = "storageStrategyLimit()")
7777
protected Object readInBounds(RubyArray array, int index,
78-
@Bind("array.store") Object store,
78+
@Bind("array.getStore()") Object store,
7979
@CachedLibrary("store") ArrayStoreLibrary stores) {
8080
return stores.read(store, index);
8181
}

0 commit comments

Comments
 (0)