Skip to content

Commit 486e2e7

Browse files
committed
Pass the Ruby array size into makeShared.
1 parent c5b753a commit 486e2e7

File tree

8 files changed

+12
-12
lines changed

8 files changed

+12
-12
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
@@ -1247,7 +1247,7 @@ protected Object initializeBlock(RubyArray array, int size, Object unusedFilling
12471247
profileAndReportLoopCount(loopProfile, n);
12481248
Object store = arrayBuilder.finish(state, n);
12491249
if (sharedProfile.profile(isSharedNode.executeIsShared(array))) {
1250-
store = stores.makeShared(store);
1250+
store = stores.makeShared(store, n);
12511251
}
12521252
setStoreAndSize(array, store, n);
12531253
}
@@ -1907,7 +1907,7 @@ protected RubyArray replace(RubyArray array, RubyArray other,
19071907
final int size = other.size;
19081908
Object store = cowNode.execute(other, 0, size);
19091909
if (sharedProfile.profile(isSharedNode.executeIsShared(array))) {
1910-
store = stores.makeShared(store);
1910+
store = stores.makeShared(store, size);
19111911
}
19121912
setStoreAndSize(array, store, size);
19131913
return array;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public Object backingStore(Object store) {
122122
}
123123

124124
/** Return a store that can be shared across threads. */
125-
public Object makeShared(Object store) {
125+
public Object makeShared(Object store, int size) {
126126
return new SharedArrayStorage(store);
127127
}
128128

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public Object backingStore(
6262
}
6363

6464
@ExportMessage
65-
protected Object makeShared(
65+
protected Object makeShared(int size,
6666
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
67-
stores.shareElements(this, 0, length);
67+
stores.shareElements(this, 0, size);
6868
return new SharedArrayStorage(this);
6969
}
7070

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ protected Object[] boxedCopyOfRange(int start, int length,
143143
}
144144

145145
@ExportMessage
146-
protected static Object makeShared(NativeArrayStorage store,
146+
protected static Object makeShared(NativeArrayStorage store, int size,
147147
@CachedLibrary("store") ArrayStoreLibrary stores) {
148-
stores.shareElements(store, 0, stores.capacity(store));
148+
stores.shareElements(store, 0, size);
149149
return new SharedArrayStorage(store);
150150
}
151151

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ protected static Object[] boxedCopyOfRange(Object[] store, int start, int length
8282
}
8383

8484
@ExportMessage
85-
protected static Object makeShared(Object[] store,
85+
protected static Object makeShared(Object[] store, int size,
8686
@CachedLibrary("store") ArrayStoreLibrary stores) {
87-
stores.shareElements(store, 0, stores.capacity(store));
87+
stores.shareElements(store, 0, size);
8888
return new SharedArrayStorage(store);
8989
}
9090

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public Object backingStore(
142142
}
143143

144144
@ExportMessage
145-
public Object makeShared() {
145+
public Object makeShared(int size) {
146146
return this;
147147
}
148148

src/main/java/org/truffleruby/language/objects/shared/ShareInternalFieldsNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public ShareInternalFieldsNode(int depth) {
4747
protected void shareArray(RubyArray array,
4848
@Bind("array.getStore()") Object store,
4949
@CachedLibrary("store") ArrayStoreLibrary stores) {
50-
array.setStore(stores.makeShared(store));
50+
array.setStore(stores.makeShared(store, array.size));
5151
}
5252

5353
@Specialization

src/main/java/org/truffleruby/language/objects/shared/SharedObjects.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static void onShareHook(RubyDynamicObject object) {
172172
DynamicObjectLibrary.getUncached().markShared(classVariables);
173173
} else if (object instanceof RubyArray) {
174174
RubyArray array = (RubyArray) object;
175-
array.setStore(ArrayStoreLibrary.getFactory().getUncached().makeShared(array.getStore()));
175+
array.setStore(ArrayStoreLibrary.getFactory().getUncached().makeShared(array.getStore(), array.size));
176176
}
177177
}
178178

0 commit comments

Comments
 (0)