Skip to content

Commit dc05717

Browse files
committed
Change shareElements message to allow sharing a subset.
1 parent ca9d6a8 commit dc05717

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ public Object makeShared(Object store) {
126126
return new SharedArrayStorage(store);
127127
}
128128

129-
/** Do any work required to start sharing elements across threads. */
130-
public void shareElements(Object store) {
129+
/** Do any work required to start sharing elements across threads in the range from {@code start} (inclusive) to
130+
* {@code end} (exclusive). */
131+
public void shareElements(Object store, int start, int end) {
131132
}
132133

133134
/** Return a description of {@code store} for debugging output. */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ public Object backingStore(
6464
@ExportMessage
6565
protected Object makeShared(
6666
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
67-
stores.shareElements(this);
67+
stores.shareElements(this, 0, length);
6868
return new SharedArrayStorage(this);
6969
}
7070

7171
@ExportMessage
72-
protected void shareElements(
72+
protected void shareElements(int start, int end,
7373
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
74-
stores.shareElements(storage);
74+
stores.shareElements(storage, offset + start, offset + end);
7575
}
7676

7777
@ExportMessage

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,21 +145,21 @@ protected Object[] boxedCopyOfRange(int start, int length,
145145
@ExportMessage
146146
protected static Object makeShared(NativeArrayStorage store,
147147
@CachedLibrary("store") ArrayStoreLibrary stores) {
148-
stores.shareElements(store);
148+
stores.shareElements(store, 0, stores.capacity(store));
149149
return new SharedArrayStorage(store);
150150
}
151151

152152
@ExportMessage
153153
static class ShareElements {
154154

155155
@Specialization
156-
protected static void shareElements(NativeArrayStorage store,
156+
protected static void shareElements(NativeArrayStorage store, int start, int end,
157157
@CachedLibrary("store") ArrayStoreLibrary node,
158158
@Cached @Exclusive LoopConditionProfile loopProfile,
159159
@Cached WriteBarrierNode writeBarrierNode) {
160-
int i = 0;
160+
int i = start;
161161
try {
162-
for (; loopProfile.inject(i < store.length); i++) {
162+
for (; loopProfile.inject(i < end); i++) {
163163
writeBarrierNode.executeWriteBarrier(node.read(store, i));
164164
}
165165
} finally {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,21 @@ protected static Object[] boxedCopyOfRange(Object[] store, int start, int length
8484
@ExportMessage
8585
protected static Object makeShared(Object[] store,
8686
@CachedLibrary("store") ArrayStoreLibrary stores) {
87-
stores.shareElements(store);
87+
stores.shareElements(store, 0, stores.capacity(store));
8888
return new SharedArrayStorage(store);
8989
}
9090

9191
@ExportMessage
9292
static class ShareElements {
9393

9494
@Specialization
95-
protected static void shareElements(Object[] store,
95+
protected static void shareElements(Object[] store, int start, int end,
9696
@CachedLibrary("store") ArrayStoreLibrary node,
9797
@Cached @Exclusive LoopConditionProfile loopProfile,
9898
@Cached WriteBarrierNode writeBarrierNode) {
99-
int i = 0;
99+
int i = start;
100100
try {
101-
for (; loopProfile.inject(i < store.length); i++) {
101+
for (; loopProfile.inject(i < end); i++) {
102102
writeBarrierNode.executeWriteBarrier(store[i]);
103103
}
104104
} finally {

0 commit comments

Comments
 (0)