Skip to content

Commit 9b71040

Browse files
timfelcosminbasca
authored andcommitted
remove gil from HashingStorageLibrary exports, since this is an internal library
1 parent 7befec2 commit 9b71040

File tree

7 files changed

+621
-1159
lines changed

7 files changed

+621
-1159
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java

Lines changed: 119 additions & 221 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/EconomicMapStorage.java

Lines changed: 181 additions & 333 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/EmptyStorage.java

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@
4848
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.HashingStorageIterable;
4949
import com.oracle.graal.python.builtins.objects.function.PArguments.ThreadState;
5050
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
51-
import com.oracle.graal.python.runtime.GilNode;
5251
import com.oracle.truffle.api.dsl.Cached;
5352
import com.oracle.truffle.api.dsl.Cached.Exclusive;
54-
import com.oracle.truffle.api.dsl.Cached.Shared;
5553
import com.oracle.truffle.api.dsl.CachedLanguage;
5654
import com.oracle.truffle.api.library.CachedLibrary;
5755
import com.oracle.truffle.api.library.ExportLibrary;
@@ -70,53 +68,38 @@ public int length() {
7068
@ExportMessage(limit = "1")
7169
public Object getItemWithState(Object key, ThreadState state,
7270
@CachedLibrary("key") PythonObjectLibrary lib,
73-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState, @Shared("gil") @Cached GilNode gil) {
74-
boolean mustRelease = gil.acquire();
75-
try {
76-
// must call __hash__ for potential side-effect
77-
getHashWithState(key, lib, state, gotState);
78-
return null;
79-
} finally {
80-
gil.release(mustRelease);
81-
}
71+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState) {
72+
// must call __hash__ for potential side-effect
73+
getHashWithState(key, lib, state, gotState);
74+
return null;
8275
}
8376

8477
@ExportMessage
8578
public HashingStorage setItemWithState(Object key, Object value, ThreadState state,
8679
@CachedLanguage PythonLanguage lang,
8780
@CachedLibrary(limit = "2") HashingStorageLibrary lib,
88-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState, @Shared("gil") @Cached GilNode gil) {
89-
boolean mustRelease = gil.acquire();
90-
try {
91-
HashingStorage newStore;
92-
if (key instanceof String) {
93-
newStore = new DynamicObjectStorage(lang);
94-
} else {
95-
newStore = EconomicMapStorage.create();
96-
}
97-
if (gotState.profile(state != null)) {
98-
lib.setItemWithState(newStore, key, value, state);
99-
} else {
100-
lib.setItem(newStore, key, value);
101-
}
102-
return newStore;
103-
} finally {
104-
gil.release(mustRelease);
81+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState) {
82+
HashingStorage newStore;
83+
if (key instanceof String) {
84+
newStore = new DynamicObjectStorage(lang);
85+
} else {
86+
newStore = EconomicMapStorage.create();
87+
}
88+
if (gotState.profile(state != null)) {
89+
lib.setItemWithState(newStore, key, value, state);
90+
} else {
91+
lib.setItem(newStore, key, value);
10592
}
93+
return newStore;
10694
}
10795

10896
@ExportMessage(limit = "1")
10997
public HashingStorage delItemWithState(Object key, ThreadState state,
11098
@CachedLibrary("key") PythonObjectLibrary lib,
111-
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState, @Shared("gil") @Cached GilNode gil) {
112-
boolean mustRelease = gil.acquire();
113-
try {
114-
// must call __hash__ for potential side-effect
115-
getHashWithState(key, lib, state, gotState);
116-
return this;
117-
} finally {
118-
gil.release(mustRelease);
119-
}
99+
@Exclusive @Cached("createBinaryProfile()") ConditionProfile gotState) {
100+
// must call __hash__ for potential side-effect
101+
getHashWithState(key, lib, state, gotState);
102+
return this;
120103
}
121104

122105
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashMapStorage.java

Lines changed: 63 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@
5353
import com.oracle.graal.python.nodes.PGuards;
5454
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
5555
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
56-
import com.oracle.graal.python.runtime.GilNode;
5756
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5857
import com.oracle.truffle.api.dsl.Cached;
5958
import com.oracle.truffle.api.dsl.Cached.Exclusive;
60-
import com.oracle.truffle.api.dsl.Cached.Shared;
6159
import com.oracle.truffle.api.dsl.Specialization;
6260
import com.oracle.truffle.api.library.CachedLibrary;
6361
import com.oracle.truffle.api.library.ExportLibrary;
@@ -157,13 +155,9 @@ PythonObjectLibrary getPythonObjLib() {
157155
}
158156

159157
@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);
167161
}
168162

169163
@TruffleBoundary
@@ -174,25 +168,15 @@ private static int size(LinkedHashMap<Object, Object> map) {
174168
@ExportMessage
175169
static class GetItemWithState {
176170
@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);
184173
}
185174

186175
@Specialization(replaces = "getItemString", guards = "isSupportedKey(key, profile)")
187176
static Object getItem(HashMapStorage self, Object key, @SuppressWarnings("unused") ThreadState state,
188177
@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));
196180
}
197181

198182
@TruffleBoundary
@@ -204,49 +188,34 @@ private static Object get(LinkedHashMap<Object, Object> values, Object key) {
204188
static Object getItemNotSupportedKey(@SuppressWarnings("unused") HashMapStorage self, Object key, @SuppressWarnings("unused") ThreadState state,
205189
@SuppressWarnings("unused") @Cached IsBuiltinClassProfile profile,
206190
@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);
222199
}
200+
// else the hashes cannot possibly match
201+
return null;
223202
}
224203
}
225204

226205
@ExportMessage
227206
static class SetItemWithState {
228207
@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;
237211
}
238212

239213
@Specialization(replaces = "setItemString", guards = "isSupportedKey(key, profile)")
240214
static HashingStorage setItem(HashMapStorage self, Object key, Object value, @SuppressWarnings("unused") ThreadState state,
241215
@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;
250219
}
251220

252221
@TruffleBoundary
@@ -258,43 +227,28 @@ private static void put(LinkedHashMap<Object, Object> values, Object key, Object
258227
static HashingStorage setItemNotSupportedKey(HashMapStorage self, Object key, Object value, @SuppressWarnings("unused") ThreadState state,
259228
@SuppressWarnings("unused") @Cached IsBuiltinClassProfile profile,
260229
@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;
271235
}
272236
}
273237

274238
@ExportMessage
275239
static class DelItemWithState {
276240
@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;
285244
}
286245

287246
@Specialization(replaces = "delItemString", guards = "isSupportedKey(key, profile)")
288247
static HashingStorage delItem(HashMapStorage self, Object key, @SuppressWarnings("unused") ThreadState state,
289248
@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;
298252
}
299253

300254
@TruffleBoundary
@@ -306,48 +260,35 @@ private static void remove(LinkedHashMap<Object, Object> values, Object key) {
306260
static HashingStorage delItemNonSupportedKey(HashMapStorage self, @SuppressWarnings("unused") Object key, @SuppressWarnings("unused") ThreadState state,
307261
@SuppressWarnings("unused") @Cached IsBuiltinClassProfile profile,
308262
@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);
324271
}
272+
// else the hashes cannot possibly match
273+
return self;
325274
}
326275
}
327276

328277
@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);
339283
}
284+
return arg;
340285
}
341286

342287
@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;
351292
}
352293

353294
@TruffleBoundary
@@ -356,37 +297,25 @@ private static void clearMap(LinkedHashMap<Object, Object> map) {
356297
}
357298

358299
@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));
366303
}
367304

368305
@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));
376309
}
377310

378311
private static Iterator<Object> getKeysIterator(LinkedHashMap<Object, Object> map) {
379312
return map.keySet().iterator();
380313
}
381314

382315
@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));
390319
}
391320

392321
@TruffleBoundary

0 commit comments

Comments
 (0)