67
67
@ ExportLibrary (value = NativeTypeLibrary .class , useForAOT = false )
68
68
@ ExportLibrary (PythonNativeWrapperLibrary .class )
69
69
public final class GraalHPyHandle implements TruffleObject {
70
+ public static final int UNINITIALIZED = Integer .MIN_VALUE ;
70
71
71
72
public static final GraalHPyHandle NULL_HANDLE = new GraalHPyHandle ();
72
73
public static final String I = "_i" ;
73
74
74
75
private final Object delegate ;
76
+ /**
77
+ * The ID of the handle if it was allocated in the handle table.
78
+ * <p>
79
+ * The value also encodes the state:<br/>
80
+ * (1) If the value is {@link #UNINITIALIZED}, then the handle was never allocated in the handle
81
+ * table.<br/>
82
+ * (2) If the value is zero or positive then this is the index for the handle table. If the<br/>
83
+ * (3) If the value is negative but not {@link #UNINITIALIZED} then the handle was already
84
+ * closed (only used in HPy debug mode)<br/>
85
+ * </p>
86
+ */
75
87
private int id ;
76
88
77
89
private GraalHPyHandle () {
@@ -82,7 +94,7 @@ private GraalHPyHandle() {
82
94
GraalHPyHandle (Object delegate ) {
83
95
assert delegate != null : "HPy handles to Java null are not allowed" ;
84
96
this .delegate = delegate ;
85
- this .id = Integer . MIN_VALUE ;
97
+ this .id = UNINITIALIZED ;
86
98
}
87
99
88
100
/**
@@ -101,15 +113,15 @@ public int getId(GraalHPyContext context, ConditionProfile hasIdProfile) {
101
113
102
114
public int getIdDebug (GraalHPyContext context ) {
103
115
int result = id ;
104
- if (id == - 1 ) {
116
+ if (id == UNINITIALIZED ) {
105
117
result = context .getHPyHandleForObject (this );
106
118
id = result ;
107
119
}
108
120
return result ;
109
121
}
110
122
111
123
int getDebugId () {
112
- if (id == Integer . MIN_VALUE ) {
124
+ if (id == UNINITIALIZED ) {
113
125
throw CompilerDirectives .shouldNotReachHere ();
114
126
}
115
127
if (id >= 0 ) {
0 commit comments