53
53
import com .oracle .graal .python .nodes .PGuards ;
54
54
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
55
55
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
56
- import com .oracle .graal .python .runtime .GilNode ;
57
56
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
58
57
import com .oracle .truffle .api .dsl .Cached ;
59
58
import com .oracle .truffle .api .dsl .Cached .Exclusive ;
60
- import com .oracle .truffle .api .dsl .Cached .Shared ;
61
59
import com .oracle .truffle .api .dsl .Specialization ;
62
60
import com .oracle .truffle .api .library .CachedLibrary ;
63
61
import com .oracle .truffle .api .library .ExportLibrary ;
@@ -157,13 +155,9 @@ PythonObjectLibrary getPythonObjLib() {
157
155
}
158
156
159
157
@ ExportMessage
160
- public int length (@ Shared ("gil" ) @ Cached GilNode gil ) {
161
- boolean mustRelease = gil .acquire ();
162
- try {
163
- return size (values );
164
- } finally {
165
- gil .release (mustRelease );
166
- }
158
+ @ Override
159
+ public int length () {
160
+ return size (values );
167
161
}
168
162
169
163
@ TruffleBoundary
@@ -174,25 +168,15 @@ private static int size(LinkedHashMap<Object, Object> map) {
174
168
@ ExportMessage
175
169
static class GetItemWithState {
176
170
@ Specialization
177
- static Object getItemString (HashMapStorage self , String key , @ SuppressWarnings ("unused" ) ThreadState state , @ Shared ("gil" ) @ Cached GilNode gil ) {
178
- boolean mustRelease = gil .acquire ();
179
- try {
180
- return get (self .values , key );
181
- } finally {
182
- gil .release (mustRelease );
183
- }
171
+ static Object getItemString (HashMapStorage self , String key , @ SuppressWarnings ("unused" ) ThreadState state ) {
172
+ return get (self .values , key );
184
173
}
185
174
186
175
@ Specialization (replaces = "getItemString" , guards = "isSupportedKey(key, profile)" )
187
176
static Object getItem (HashMapStorage self , Object key , @ SuppressWarnings ("unused" ) ThreadState state ,
188
177
@ Cached CastToJavaStringNode castNode ,
189
- @ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile profile , @ Cached GilNode gil ) {
190
- boolean mustRelease = gil .acquire ();
191
- try {
192
- return get (self .values , castNode .execute (key ));
193
- } finally {
194
- gil .release (mustRelease );
195
- }
178
+ @ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile profile ) {
179
+ return get (self .values , castNode .execute (key ));
196
180
}
197
181
198
182
@ TruffleBoundary
@@ -204,49 +188,34 @@ private static Object get(LinkedHashMap<Object, Object> values, Object key) {
204
188
static Object getItemNotSupportedKey (@ SuppressWarnings ("unused" ) HashMapStorage self , Object key , @ SuppressWarnings ("unused" ) ThreadState state ,
205
189
@ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile profile ,
206
190
@ CachedLibrary ("key" ) PythonObjectLibrary lib ,
207
- @ Exclusive @ Cached ("createBinaryProfile()" ) ConditionProfile gotState , @ Cached GilNode gil ) {
208
- boolean mustRelease = gil .acquire ();
209
- try {
210
- // we must still search the map for items that may have the same hash and that may
211
- // return true from key.__eq__, we use artificial object with overridden Java level
212
- // equals and hashCode methods to perform this search
213
- long hash = getHashWithState (key , lib , state , gotState );
214
- if (PInt .isIntRange (hash )) {
215
- CustomKey keyObj = new CustomKey (key , (int ) hash , state );
216
- return get (self .values , keyObj );
217
- }
218
- // else the hashes cannot possibly match
219
- return null ;
220
- } finally {
221
- gil .release (mustRelease );
191
+ @ Exclusive @ Cached ("createBinaryProfile()" ) ConditionProfile gotState ) {
192
+ // we must still search the map for items that may have the same hash and that may
193
+ // return true from key.__eq__, we use artificial object with overridden Java level
194
+ // equals and hashCode methods to perform this search
195
+ long hash = getHashWithState (key , lib , state , gotState );
196
+ if (PInt .isIntRange (hash )) {
197
+ CustomKey keyObj = new CustomKey (key , (int ) hash , state );
198
+ return get (self .values , keyObj );
222
199
}
200
+ // else the hashes cannot possibly match
201
+ return null ;
223
202
}
224
203
}
225
204
226
205
@ ExportMessage
227
206
static class SetItemWithState {
228
207
@ Specialization
229
- static HashingStorage setItemString (HashMapStorage self , String key , Object value , @ SuppressWarnings ("unused" ) ThreadState state , @ Shared ("gil" ) @ Cached GilNode gil ) {
230
- boolean mustRelease = gil .acquire ();
231
- try {
232
- put (self .values , key , value );
233
- return self ;
234
- } finally {
235
- gil .release (mustRelease );
236
- }
208
+ static HashingStorage setItemString (HashMapStorage self , String key , Object value , @ SuppressWarnings ("unused" ) ThreadState state ) {
209
+ put (self .values , key , value );
210
+ return self ;
237
211
}
238
212
239
213
@ Specialization (replaces = "setItemString" , guards = "isSupportedKey(key, profile)" )
240
214
static HashingStorage setItem (HashMapStorage self , Object key , Object value , @ SuppressWarnings ("unused" ) ThreadState state ,
241
215
@ Cached CastToJavaStringNode castNode ,
242
- @ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile profile , @ Cached GilNode gil ) {
243
- boolean mustRelease = gil .acquire ();
244
- try {
245
- put (self .values , castNode .execute (key ), value );
246
- return self ;
247
- } finally {
248
- gil .release (mustRelease );
249
- }
216
+ @ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile profile ) {
217
+ put (self .values , castNode .execute (key ), value );
218
+ return self ;
250
219
}
251
220
252
221
@ TruffleBoundary
@@ -258,43 +227,28 @@ private static void put(LinkedHashMap<Object, Object> values, Object key, Object
258
227
static HashingStorage setItemNotSupportedKey (HashMapStorage self , Object key , Object value , @ SuppressWarnings ("unused" ) ThreadState state ,
259
228
@ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile profile ,
260
229
@ CachedLibrary ("self" ) HashingStorageLibrary thisLib ,
261
- @ CachedLibrary (limit = "1" ) HashingStorageLibrary newLib , @ Cached GilNode gil ) {
262
- boolean mustRelease = gil .acquire ();
263
- try {
264
- HashingStorage newStore = EconomicMapStorage .create (self .length (gil ));
265
- thisLib .addAllToOther (self , newStore );
266
- newLib .setItem (newStore , key , value );
267
- return newStore ;
268
- } finally {
269
- gil .release (mustRelease );
270
- }
230
+ @ CachedLibrary (limit = "1" ) HashingStorageLibrary newLib ) {
231
+ HashingStorage newStore = EconomicMapStorage .create (self .length ());
232
+ thisLib .addAllToOther (self , newStore );
233
+ newLib .setItem (newStore , key , value );
234
+ return newStore ;
271
235
}
272
236
}
273
237
274
238
@ ExportMessage
275
239
static class DelItemWithState {
276
240
@ Specialization
277
- static HashingStorage delItemString (HashMapStorage self , String key , @ SuppressWarnings ("unused" ) ThreadState state , @ Shared ("gil" ) @ Cached GilNode gil ) {
278
- boolean mustRelease = gil .acquire ();
279
- try {
280
- remove (self .values , key );
281
- return self ;
282
- } finally {
283
- gil .release (mustRelease );
284
- }
241
+ static HashingStorage delItemString (HashMapStorage self , String key , @ SuppressWarnings ("unused" ) ThreadState state ) {
242
+ remove (self .values , key );
243
+ return self ;
285
244
}
286
245
287
246
@ Specialization (replaces = "delItemString" , guards = "isSupportedKey(key, profile)" )
288
247
static HashingStorage delItem (HashMapStorage self , Object key , @ SuppressWarnings ("unused" ) ThreadState state ,
289
248
@ Cached CastToJavaStringNode castNode ,
290
- @ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile profile , @ Cached GilNode gil ) {
291
- boolean mustRelease = gil .acquire ();
292
- try {
293
- remove (self .values , castNode .execute (key ));
294
- return self ;
295
- } finally {
296
- gil .release (mustRelease );
297
- }
249
+ @ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile profile ) {
250
+ remove (self .values , castNode .execute (key ));
251
+ return self ;
298
252
}
299
253
300
254
@ TruffleBoundary
@@ -306,48 +260,35 @@ private static void remove(LinkedHashMap<Object, Object> values, Object key) {
306
260
static HashingStorage delItemNonSupportedKey (HashMapStorage self , @ SuppressWarnings ("unused" ) Object key , @ SuppressWarnings ("unused" ) ThreadState state ,
307
261
@ SuppressWarnings ("unused" ) @ Cached IsBuiltinClassProfile profile ,
308
262
@ CachedLibrary ("key" ) PythonObjectLibrary lib ,
309
- @ Exclusive @ Cached ("createBinaryProfile()" ) ConditionProfile gotState , @ Cached GilNode gil ) {
310
- boolean mustRelease = gil .acquire ();
311
- try {
312
- // we must still search the map for items that may have the same hash and that may
313
- // return true from key.__eq__, we use artificial object with overridden Java level
314
- // equals and hashCode methods to perform this search
315
- long hash = getHashWithState (key , lib , state , gotState );
316
- if (PInt .isIntRange (hash )) {
317
- CustomKey keyObj = new CustomKey (key , (int ) hash , state );
318
- remove (self .values , keyObj );
319
- }
320
- // else the hashes cannot possibly match
321
- return self ;
322
- } finally {
323
- gil .release (mustRelease );
263
+ @ Exclusive @ Cached ("createBinaryProfile()" ) ConditionProfile gotState ) {
264
+ // we must still search the map for items that may have the same hash and that may
265
+ // return true from key.__eq__, we use artificial object with overridden Java level
266
+ // equals and hashCode methods to perform this search
267
+ long hash = getHashWithState (key , lib , state , gotState );
268
+ if (PInt .isIntRange (hash )) {
269
+ CustomKey keyObj = new CustomKey (key , (int ) hash , state );
270
+ remove (self .values , keyObj );
324
271
}
272
+ // else the hashes cannot possibly match
273
+ return self ;
325
274
}
326
275
}
327
276
328
277
@ ExportMessage
329
- Object forEachUntyped (ForEachNode <Object > node , Object argIn , @ Shared ("gil" ) @ Cached GilNode gil ) {
330
- boolean mustRelease = gil .acquire ();
331
- try {
332
- Object arg = argIn ;
333
- for (Object key : keys (gil )) {
334
- arg = node .execute (key , arg );
335
- }
336
- return arg ;
337
- } finally {
338
- gil .release (mustRelease );
278
+ @ Override
279
+ Object forEachUntyped (ForEachNode <Object > node , Object argIn ) {
280
+ Object arg = argIn ;
281
+ for (Object key : keys ()) {
282
+ arg = node .execute (key , arg );
339
283
}
284
+ return arg ;
340
285
}
341
286
342
287
@ ExportMessage
343
- public HashingStorage clear (@ Shared ("gil" ) @ Cached GilNode gil ) {
344
- boolean mustRelease = gil .acquire ();
345
- try {
346
- clearMap (values );
347
- return this ;
348
- } finally {
349
- gil .release (mustRelease );
350
- }
288
+ @ Override
289
+ public HashingStorage clear () {
290
+ clearMap (values );
291
+ return this ;
351
292
}
352
293
353
294
@ TruffleBoundary
@@ -356,37 +297,25 @@ private static void clearMap(LinkedHashMap<Object, Object> map) {
356
297
}
357
298
358
299
@ ExportMessage
359
- public HashingStorage copy (@ Shared ("gil" ) @ Cached GilNode gil ) {
360
- boolean mustRelease = gil .acquire ();
361
- try {
362
- return new HashMapStorage (newHashMap (values ));
363
- } finally {
364
- gil .release (mustRelease );
365
- }
300
+ @ Override
301
+ public HashingStorage copy () {
302
+ return new HashMapStorage (newHashMap (values ));
366
303
}
367
304
368
305
@ ExportMessage
369
- public HashingStorageIterable <Object > keys (@ Shared ("gil" ) @ Cached GilNode gil ) {
370
- boolean mustRelease = gil .acquire ();
371
- try {
372
- return new HashingStorageIterable <>(getKeysIterator (values ));
373
- } finally {
374
- gil .release (mustRelease );
375
- }
306
+ @ Override
307
+ public HashingStorageIterable <Object > keys () {
308
+ return new HashingStorageIterable <>(getKeysIterator (values ));
376
309
}
377
310
378
311
private static Iterator <Object > getKeysIterator (LinkedHashMap <Object , Object > map ) {
379
312
return map .keySet ().iterator ();
380
313
}
381
314
382
315
@ ExportMessage
383
- public HashingStorageIterable <Object > reverseKeys (@ Shared ("gil" ) @ Cached GilNode gil ) {
384
- boolean mustRelease = gil .acquire ();
385
- try {
386
- return new HashingStorageIterable <>(getReverseIterator (values ));
387
- } finally {
388
- gil .release (mustRelease );
389
- }
316
+ @ Override
317
+ public HashingStorageIterable <Object > reverseKeys () {
318
+ return new HashingStorageIterable <>(getReverseIterator (values ));
390
319
}
391
320
392
321
@ TruffleBoundary
0 commit comments