Skip to content

Commit a3d9543

Browse files
committed
[GR-45758] Fix DelegatedArrayStorage and SharedArrayStorage accepts()
PullRequest: truffleruby/3782
2 parents ee179eb + 1c6fdb8 commit a3d9543

File tree

7 files changed

+128
-83
lines changed

7 files changed

+128
-83
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public static ArrayStoreLibrary createDispatched(RubyLanguage language) {
4343
return FACTORY.createDispatched(language.options.ARRAY_STRATEGY_CACHE);
4444
}
4545

46+
public static ArrayStoreLibrary create(Object store) {
47+
return FACTORY.create(store);
48+
}
49+
4650
public static ArrayStoreLibrary getUncached() {
4751
CompilerAsserts.neverPartOfCompilation("uncached libraries must not be used in PE code");
4852
return FACTORY.getUncached();

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,45 +50,45 @@ public DelegatedArrayStorage(Object storage, int offset, int length) {
5050

5151
@ExportMessage
5252
protected static boolean accepts(DelegatedArrayStorage store,
53-
@CachedLibrary(limit = "1") ArrayStoreLibrary backingStores) {
54-
return backingStores.accepts(store.storage);
53+
@CachedLibrary("store.storage") ArrayStoreLibrary stores) {
54+
return true;
5555
}
5656

5757
@ExportMessage
5858
protected Object read(int index,
59-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
59+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
6060
return stores.read(storage, index + offset);
6161
}
6262

6363
@ExportMessage
6464
protected boolean isPrimitive(
65-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
65+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
6666
return stores.isPrimitive(storage);
6767
}
6868

6969
@ExportMessage
7070
public Object backingStore(
71-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
71+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
7272
return stores.backingStore(storage);
7373
}
7474

7575
@ExportMessage
7676
protected Object makeShared(int size,
77-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
78-
stores.shareElements(this, 0, size);
77+
@CachedLibrary("this") ArrayStoreLibrary library) {
78+
library.shareElements(this, 0, size);
7979
return new SharedArrayStorage(this);
8080
}
8181

8282
@ExportMessage
8383
protected void shareElements(int start, int end,
84-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
84+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
8585
stores.shareElements(storage, offset + start, offset + end);
8686
}
8787

8888
@ExportMessage
8989
@TruffleBoundary
9090
protected String toString(
91-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
91+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
9292
return String.format("Delegate of (%s)", stores.toString(storage));
9393
}
9494

@@ -109,16 +109,16 @@ protected Object extractRange(int start, int end) {
109109

110110
@ExportMessage
111111
protected Object[] boxedCopyOfRange(int start, int length,
112-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
112+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
113113
return stores.boxedCopyOfRange(storage, offset + start, length);
114114
}
115115

116-
@ExportMessage
116+
@ExportMessage(limit = "storageStrategyLimit()")
117117
protected void copyContents(int srcStart, Object destStore, int destStart, int length,
118118
@CachedLibrary("this") ArrayStoreLibrary node,
119119
@Cached LoopConditionProfile loopProfile,
120-
@CachedLibrary(limit = "1") ArrayStoreLibrary srcStores,
121-
@CachedLibrary(limit = "storageStrategyLimit()") ArrayStoreLibrary destStores) {
120+
@CachedLibrary("this.storage") ArrayStoreLibrary srcStores,
121+
@CachedLibrary("destStore") ArrayStoreLibrary destStores) {
122122
int i = 0;
123123
try {
124124
for (; loopProfile.inject(i < length); i++) {
@@ -136,7 +136,7 @@ protected void clear(int start, int length) {
136136

137137
@ExportMessage
138138
protected Object toJavaArrayCopy(int length,
139-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
139+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
140140
Object newStore = stores.unsharedAllocator(storage).allocate(length);
141141
stores.copyContents(storage, offset, newStore, 0, length);
142142
return newStore;
@@ -150,49 +150,49 @@ protected void sort(int size) {
150150

151151
@ExportMessage
152152
protected Iterable<Object> getIterable(int from, int length,
153-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
153+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
154154
return stores.getIterable(storage, from + offset, length);
155155
}
156156

157157
@ExportMessage
158158
protected ArrayAllocator generalizeForValue(Object newValue,
159-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
159+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
160160
return stores.generalizeForValue(storage, newValue);
161161
}
162162

163163
@ExportMessage
164164
protected ArrayAllocator generalizeForStore(Object newStore,
165-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
166-
return stores.generalizeForStore(newStore, storage);
165+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
166+
return stores.generalizeForStore(storage, newStore);
167167
}
168168

169169
@ExportMessage
170170
public ArrayAllocator generalizeForSharing(
171-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
171+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
172172
return stores.generalizeForSharing(storage);
173173
}
174174

175175
@ExportMessage
176176
protected Object allocateForNewValue(Object newValue, int length,
177-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
177+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
178178
return stores.allocateForNewValue(storage, newValue, length);
179179
}
180180

181181
@ExportMessage
182182
protected Object allocateForNewStore(Object newStore, int length,
183-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
183+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
184184
return stores.allocateForNewStore(storage, newStore, length);
185185
}
186186

187187
@ExportMessage
188188
protected boolean isDefaultValue(Object value,
189-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
189+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
190190
return stores.isDefaultValue(storage, value);
191191
}
192192

193193
@ExportMessage
194194
protected ArrayAllocator allocator(
195-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
195+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
196196
return stores.unsharedAllocator(storage);
197197
}
198198

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,11 @@ protected static void shareElements(NativeArrayStorage store, int start, int end
171171
}
172172
}
173173

174-
@ExportMessage
174+
@ExportMessage(limit = "storageStrategyLimit()")
175175
protected void copyContents(int srcStart, Object destStore, int destStart, int length,
176176
@CachedLibrary("this") ArrayStoreLibrary srcStores,
177177
@Cached @Exclusive LoopConditionProfile loopProfile,
178-
@CachedLibrary(limit = "storageStrategyLimit()") ArrayStoreLibrary destStores) {
178+
@CachedLibrary("destStore") ArrayStoreLibrary destStores) {
179179
int i = 0;
180180
try {
181181
for (; loopProfile.inject(i < length); i++) {

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,59 +68,59 @@ public boolean allElementsShared(int size) {
6868

6969
@ExportMessage
7070
protected static boolean accepts(SharedArrayStorage store,
71-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
72-
return stores.accepts(store.storage);
71+
@CachedLibrary("store.storage") ArrayStoreLibrary stores) {
72+
return true;
7373
}
7474

7575
@ExportMessage
7676
protected Object read(int index,
77-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
77+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
7878
return stores.read(storage, index);
7979
}
8080

8181
@ExportMessage
8282
protected void write(int index, Object value,
8383
@Shared @Cached WriteBarrierNode writeBarrierNode,
84-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
84+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
8585
writeBarrierNode.executeWriteBarrier(value);
8686
stores.write(storage, index, value);
8787
}
8888

8989
@ExportMessage
9090
protected void fill(int start, int length, Object value,
9191
@Shared @Cached WriteBarrierNode writeBarrierNode,
92-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
92+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
9393
writeBarrierNode.executeWriteBarrier(value);
9494
stores.fill(storage, start, length, value);
9595
}
9696

9797
@ExportMessage
9898
protected boolean acceptsValue(Object value,
99-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
99+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
100100
return stores.acceptsValue(storage, value);
101101
}
102102

103103
@ExportMessage
104104
protected boolean acceptsAllValues(Object otherStore,
105-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
105+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
106106
return stores.acceptsAllValues(storage, otherStore);
107107
}
108108

109109
@ExportMessage
110110
protected boolean isMutable(
111-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
111+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
112112
return stores.isMutable(storage);
113113
}
114114

115115
@ExportMessage
116116
protected boolean isNative(
117-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
117+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
118118
return stores.isNative(storage);
119119
}
120120

121121
@ExportMessage
122122
protected boolean isPrimitive(
123-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
123+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
124124
return stores.isPrimitive(storage);
125125
}
126126

@@ -136,7 +136,7 @@ public Object initialStore() {
136136

137137
@ExportMessage
138138
public Object backingStore(
139-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
139+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
140140
return stores.backingStore(storage);
141141
}
142142

@@ -148,37 +148,37 @@ public Object makeShared(int size) {
148148
@ExportMessage
149149
@TruffleBoundary
150150
protected String toString(
151-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
151+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
152152
return String.format("Shared storage of (%s)", stores.toString(storage));
153153
}
154154

155155
@ExportMessage
156156
protected int capacity(
157-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
157+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
158158
return stores.capacity(storage);
159159
}
160160

161161
@ExportMessage
162162
protected Object expand(int capacity,
163-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
163+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
164164
return new SharedArrayStorage(stores.expand(storage, capacity));
165165
}
166166

167167
@ExportMessage
168168
protected Object extractRange(int start, int end,
169-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
169+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
170170
return new SharedArrayStorage(stores.extractRange(storage, start, end));
171171
}
172172

173173
@ExportMessage
174174
protected Object extractRangeAndUnshare(int start, int end,
175-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
175+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
176176
return stores.extractRange(storage, start, end);
177177
}
178178

179179
@ExportMessage
180180
protected Object[] boxedCopyOfRange(int start, int length,
181-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
181+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
182182
return stores.boxedCopyOfRange(storage, start, length);
183183
}
184184

@@ -196,7 +196,7 @@ protected static void copyContents(
196196
protected static void copyContents(
197197
SharedArrayStorage srcStore, int srcStart, Object destStore, int destStart, int length,
198198
@Cached @Exclusive LoopConditionProfile loopProfile,
199-
@CachedLibrary(limit = "1") ArrayStoreLibrary srcStores,
199+
@CachedLibrary("srcStore.storage") ArrayStoreLibrary srcStores,
200200
@CachedLibrary("destStore") ArrayStoreLibrary destStores) {
201201
int i = 0;
202202
try {
@@ -216,79 +216,79 @@ protected static boolean differentStores(SharedArrayStorage srcStore, Object des
216216

217217
@ExportMessage
218218
protected void clear(int start, int length,
219-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
219+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
220220
stores.clear(storage, start, length);
221221
}
222222

223223
@ExportMessage
224224
protected Object toJavaArrayCopy(int length,
225-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
225+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
226226
return stores.toJavaArrayCopy(storage, length);
227227
}
228228

229229
@ExportMessage
230230
protected void sort(int size,
231-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
231+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
232232
stores.sort(storage, size);
233233
}
234234

235235
@ExportMessage
236236
protected Iterable<Object> getIterable(int from, int length,
237-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
237+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
238238
return stores.getIterable(storage, from, length);
239239
}
240240

241241
@ExportMessage
242242
protected ArrayAllocator generalizeForValue(Object newValue,
243-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
243+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
244244
return stores.generalizeForValue(storage, newValue);
245245
}
246246

247247
@ExportMessage
248248
protected ArrayAllocator generalizeForStore(Object newStore,
249-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
250-
return stores.generalizeForStore(newStore, storage);
249+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
250+
return stores.generalizeForStore(storage, newStore);
251251
}
252252

253253
@ExportMessage
254254
public ArrayAllocator generalizeForSharing(
255-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
255+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
256256
return stores.generalizeForSharing(storage);
257257
}
258258

259259
@ExportMessage
260260
protected Object allocateForNewValue(Object newValue, int length,
261-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
261+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
262262
return new SharedArrayStorage(stores.allocateForNewValue(storage, newValue, length));
263263
}
264264

265265
@ExportMessage
266266
protected Object allocateForNewStore(Object newStore, int length,
267-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
267+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
268268
return new SharedArrayStorage(stores.allocateForNewStore(storage, newStore, length));
269269
}
270270

271271
@ExportMessage
272272
protected Object unsharedAllocateForNewStore(Object newStore, int length,
273-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
273+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
274274
return stores.allocateForNewStore(storage, newStore, length);
275275
}
276276

277277
@ExportMessage
278278
protected boolean isDefaultValue(Object value,
279-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
279+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
280280
return stores.isDefaultValue(storage, value);
281281
}
282282

283283
@ExportMessage
284284
protected ArrayAllocator allocator(
285-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
285+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
286286
return new SharedArrayAllocator(stores.unsharedAllocator(storage));
287287
}
288288

289289
@ExportMessage
290290
protected ArrayAllocator unsharedAllocator(
291-
@CachedLibrary(limit = "1") ArrayStoreLibrary stores) {
291+
@CachedLibrary("this.storage") ArrayStoreLibrary stores) {
292292
return stores.unsharedAllocator(storage);
293293
}
294294

0 commit comments

Comments
 (0)