Skip to content

Commit ac5bae4

Browse files
committed
id builtin: global id counter stored in the PythonContext instance
1 parent dc0ef4f commit ac5bae4

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ public abstract static class IdNode extends PythonBuiltinNode {
637637
* The next available global id. We reserve space for all integers to be their own id +
638638
* offset.
639639
*/
640-
private static long GLOBAL_ID = Integer.MAX_VALUE * 2 + 4L;
641640
private static HiddenKey idKey = new HiddenKey("object_id");
642641

643642
@Child private ReadAttributeFromObjectNode readId = null;
@@ -708,7 +707,7 @@ private Object getId(PythonObject obj) {
708707
}
709708
Object id = readId.execute(obj, idKey);
710709
if (id == NO_VALUE) {
711-
id = GLOBAL_ID++;
710+
id = getContext().getNextGlobalId();
712711
writeId.execute(obj, idKey, id);
713712
}
714713
return id;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import java.io.OutputStream;
3333
import java.util.HashMap;
34+
import java.util.concurrent.atomic.AtomicLong;
3435
import java.util.concurrent.locks.ReentrantLock;
3536

3637
import org.graalvm.options.OptionValues;
@@ -55,6 +56,7 @@ public class PythonContext {
5556
private PythonModule mainModule;
5657
private final PythonCore core;
5758
private final HashMap<Object, CallTarget> atExitHooks = new HashMap<>();
59+
private final AtomicLong globalId = new AtomicLong(Integer.MAX_VALUE * 2 + 4L);
5860

5961
@CompilationFinal private TruffleLanguage.Env env;
6062

@@ -89,6 +91,10 @@ public PythonContext(PythonLanguage language, TruffleLanguage.Env env, PythonCor
8991
}
9092
}
9193

94+
public long getNextGlobalId() {
95+
return globalId.incrementAndGet();
96+
}
97+
9298
public OptionValues getOptions() {
9399
return getEnv().getOptions();
94100
}

0 commit comments

Comments
 (0)