Skip to content

Commit 1340621

Browse files
committed
Fix up a couple more cases of incorrect sharing.
1 parent 78e9e03 commit 1340621

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ protected RubyArray addGeneralize(RubyArray a, RubyArray b,
150150
final int aSize = aSizeProfile.profile(a.size);
151151
final int bSize = bSizeProfile.profile(b.size);
152152
final int combinedSize = aSize + bSize;
153-
Object newStore = as.allocateForNewStore(aStore, bStore, combinedSize);
153+
Object newStore = as.unsharedAllocateForNewStore(aStore, bStore, combinedSize);
154154
as.copyContents(aStore, 0, newStore, 0, aSize);
155155
bs.copyContents(bStore, 0, newStore, aSize, bSize);
156156
return createArray(newStore, combinedSize);
@@ -2345,7 +2345,7 @@ protected RubyArray zipToPairs(RubyArray array, RubyArray other,
23452345
try {
23462346
for (; loopProfile.inject(n < zippedLength); n++) {
23472347
if (bNotSmallerProfile.profile(n < bSize)) {
2348-
final Object pair = aStores.allocateForNewStore(a, b, 2);
2348+
final Object pair = aStores.unsharedAllocateForNewStore(a, b, 2);
23492349
pairs.write(pair, 0, aStores.read(a, n));
23502350
pairs.write(pair, 1, bStores.read(b, n));
23512351
zipped[n] = createArray(pair, 2);

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ protected void truncateCopy(RubyArray array, int size,
5050

5151
final Object newStore = stores.allocateForNewStore(store, store, size);
5252
stores.copyContents(store, 0, newStore, 0, size);
53-
array.store = newStore;
54-
array.size = size;
53+
ArrayHelpers.setStoreAndSize(array, newStore, size);
5554
}
5655

5756
@ReportPolymorphism.Exclude

src/main/java/org/truffleruby/core/array/library/ArrayStoreLibrary.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ public void sort(Object store, int size) {
201201
* of {@code newStore}. */
202202
public abstract Object allocateForNewStore(Object store, Object newStore, int length);
203203

204+
/** Return a new store of length {@code length} that can accept all the values of {@code store} and all the values
205+
* of {@code newStore} and is unshared. */
206+
public Object unsharedAllocateForNewStore(Object store, Object newStore, int length) {
207+
return allocateForNewStore(store, newStore, length);
208+
}
209+
204210
/** Return an allocator for a mutable version of {@code store}. */
205211
public abstract ArrayAllocator allocator(Object store);
206212

src/main/java/org/truffleruby/core/array/library/SharedArrayStorage.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ protected Object allocateForNewStore(Object newStore, int length,
251251
return new SharedArrayStorage(stores.allocateForNewStore(storage, newStore, length));
252252
}
253253

254+
@ExportMessage
255+
protected Object unsharedAllocateForNewStore(Object newStore, int length,
256+
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
257+
return stores.allocateForNewStore(storage, newStore, length);
258+
}
259+
254260
@ExportMessage
255261
protected boolean isDefaultValue(Object value,
256262
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {

0 commit comments

Comments
 (0)