49
49
import com .oracle .graal .python .nodes .attributes .LookupInheritedAttributeNode ;
50
50
import com .oracle .graal .python .nodes .object .IsBuiltinClassProfile ;
51
51
import com .oracle .graal .python .nodes .util .CastToJavaLongLossyNode ;
52
+ import com .oracle .graal .python .runtime .GilNode ;
52
53
import com .oracle .graal .python .runtime .exception .PException ;
53
54
import com .oracle .truffle .api .CompilerAsserts ;
54
55
import com .oracle .truffle .api .dsl .Cached ;
55
56
import com .oracle .truffle .api .dsl .Cached .Exclusive ;
56
57
import com .oracle .truffle .api .dsl .Cached .Shared ;
58
+ import com .oracle .truffle .api .dsl .Specialization ;
57
59
import com .oracle .truffle .api .exception .AbstractTruffleException ;
58
60
import com .oracle .truffle .api .interop .InteropLibrary ;
59
61
import com .oracle .truffle .api .interop .UnknownKeyException ;
60
62
import com .oracle .truffle .api .interop .UnsupportedTypeException ;
61
- import com .oracle .truffle .api .dsl .Specialization ;
62
63
import com .oracle .truffle .api .library .CachedLibrary ;
63
64
import com .oracle .truffle .api .library .ExportLibrary ;
64
65
import com .oracle .truffle .api .library .ExportMessage ;
@@ -166,22 +167,41 @@ static boolean hasHashEntries(@SuppressWarnings("unused") PDict self) {
166
167
167
168
@ ExportMessage (limit = "2" )
168
169
static long getHashSize (PDict self ,
170
+ @ Exclusive @ Cached GilNode gil ,
169
171
@ CachedLibrary ("self.getDictStorage()" ) HashingStorageLibrary lib ) {
170
- return lib .length (self .getDictStorage ());
172
+ boolean mustRelease = gil .acquire ();
173
+ try {
174
+ return lib .length (self .getDictStorage ());
175
+ } finally {
176
+ gil .release (mustRelease );
177
+ }
171
178
}
172
179
173
180
@ ExportMessage (limit = "2" )
174
181
@ ExportMessage (name = "isHashEntryModifiable" , limit = "2" )
175
182
@ ExportMessage (name = "isHashEntryRemovable" , limit = "2" )
176
183
static boolean isHashEntryReadable (PDict self , Object key ,
184
+ @ Exclusive @ Cached GilNode gil ,
177
185
@ CachedLibrary ("self.getDictStorage()" ) HashingStorageLibrary lib ) {
178
- return lib .hasKey (self .getDictStorage (), key );
186
+ boolean mustRelease = gil .acquire ();
187
+ try {
188
+ return lib .hasKey (self .getDictStorage (), key );
189
+ } finally {
190
+ gil .release (mustRelease );
191
+ }
179
192
}
180
193
181
194
@ ExportMessage (limit = "2" )
182
195
static Object readHashValue (PDict self , Object key ,
196
+ @ Exclusive @ Cached GilNode gil ,
183
197
@ CachedLibrary ("self.getDictStorage()" ) HashingStorageLibrary lib ) throws UnknownKeyException {
184
- Object value = lib .getItem (self .getDictStorage (), key );
198
+ Object value = null ;
199
+ boolean mustRelease = gil .acquire ();
200
+ try {
201
+ value = lib .getItem (self .getDictStorage (), key );
202
+ } finally {
203
+ gil .release (mustRelease );
204
+ }
185
205
if (value == null ) {
186
206
throw UnknownKeyException .create (key );
187
207
} else {
@@ -191,60 +211,94 @@ static Object readHashValue(PDict self, Object key,
191
211
192
212
@ ExportMessage (limit = "3" )
193
213
static boolean isHashEntryInsertable (PDict self , Object key ,
214
+ @ Exclusive @ Cached GilNode gil ,
194
215
@ CachedLibrary ("key" ) PythonObjectLibrary keyLib ,
195
216
@ CachedLibrary ("self.getDictStorage()" ) HashingStorageLibrary lib ) {
196
- if (lib .hasKey (self .getDictStorage (), key )) {
197
- return false ;
198
- } else {
199
- // we can only insert hashable types
200
- try {
201
- keyLib .hash (key );
202
- } catch (AbstractTruffleException e ) {
217
+ boolean mustRelease = gil .acquire ();
218
+ try {
219
+ if (lib .hasKey (self .getDictStorage (), key )) {
203
220
return false ;
221
+ } else {
222
+ // we can only insert hashable types
223
+ try {
224
+ keyLib .hash (key );
225
+ } catch (AbstractTruffleException e ) {
226
+ return false ;
227
+ }
228
+ return true ;
204
229
}
205
- return true ;
230
+ } finally {
231
+ gil .release (mustRelease );
206
232
}
207
233
}
208
234
209
235
@ ExportMessage (limit = "2" )
210
236
static void writeHashEntry (PDict self , Object key , Object value ,
237
+ @ Exclusive @ Cached GilNode gil ,
211
238
@ Cached IsBuiltinClassProfile errorProfile ,
212
239
@ CachedLibrary ("self.getDictStorage()" ) HashingStorageLibrary lib ) throws UnsupportedTypeException {
240
+ boolean mustRelease = gil .acquire ();
213
241
try {
214
242
lib .setItem (self .getDictStorage (), key , value );
215
243
} catch (PException e ) {
216
244
e .expect (PythonBuiltinClassType .TypeError , errorProfile );
217
245
throw UnsupportedTypeException .create (new Object []{key }, "keys for Python arrays must be hashable" );
246
+ } finally {
247
+ gil .release (mustRelease );
218
248
}
219
249
}
220
250
221
251
@ ExportMessage (limit = "2" )
222
252
static void removeHashEntry (PDict self , Object key ,
253
+ @ Exclusive @ Cached GilNode gil ,
223
254
@ CachedLibrary ("self.getDictStorage()" ) HashingStorageLibrary lib ) throws UnknownKeyException {
224
- if (!isHashEntryReadable (self , key , lib )) {
225
- throw UnknownKeyException .create (key );
255
+ boolean mustRelease = gil .acquire ();
256
+ try {
257
+ if (!isHashEntryReadable (self , key , gil , lib )) {
258
+ throw UnknownKeyException .create (key );
259
+ }
260
+ lib .delItem (self .getDictStorage (), key );
261
+ } finally {
262
+ gil .release (mustRelease );
226
263
}
227
- lib .delItem (self .getDictStorage (), key );
228
264
}
229
265
230
266
@ ExportMessage
231
267
static Object getHashEntriesIterator (PDict self ,
268
+ @ Exclusive @ Cached GilNode gil ,
232
269
@ Shared ("iterLib" ) @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ) {
233
- Object dictItems = lib .lookupAndCallSpecialMethod (self , null , ITEMS );
234
- return lib .getIterator (dictItems );
270
+ boolean mustRelease = gil .acquire ();
271
+ try {
272
+ Object dictItems = lib .lookupAndCallSpecialMethod (self , null , ITEMS );
273
+ return lib .getIterator (dictItems );
274
+ } finally {
275
+ gil .release (mustRelease );
276
+ }
235
277
}
236
278
237
279
@ ExportMessage
238
280
static Object getHashKeysIterator (PDict self ,
281
+ @ Exclusive @ Cached GilNode gil ,
239
282
@ Shared ("iterLib" ) @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ) {
240
- Object dictKeys = lib .lookupAndCallSpecialMethod (self , null , KEYS );
241
- return lib .getIterator (dictKeys );
283
+ boolean mustRelease = gil .acquire ();
284
+ try {
285
+ Object dictKeys = lib .lookupAndCallSpecialMethod (self , null , KEYS );
286
+ return lib .getIterator (dictKeys );
287
+ } finally {
288
+ gil .release (mustRelease );
289
+ }
242
290
}
243
291
244
292
@ ExportMessage
245
293
static Object getHashValuesIterator (PDict self ,
294
+ @ Exclusive @ Cached GilNode gil ,
246
295
@ Shared ("iterLib" ) @ CachedLibrary (limit = "2" ) PythonObjectLibrary lib ) {
247
- Object dictValues = lib .lookupAndCallSpecialMethod (self , null , VALUES );
248
- return lib .getIterator (dictValues );
296
+ boolean mustRelease = gil .acquire ();
297
+ try {
298
+ Object dictValues = lib .lookupAndCallSpecialMethod (self , null , VALUES );
299
+ return lib .getIterator (dictValues );
300
+ } finally {
301
+ gil .release (mustRelease );
302
+ }
249
303
}
250
304
}
0 commit comments