23
23
24
24
public class ValueWrapperObjectType extends ObjectType {
25
25
26
- static final int NULL_HANDLE = -1 ;
26
+ static final int UNSET_HANDLE = -1 ;
27
27
28
28
private static DynamicObject UNDEF_WRAPPER = null ;
29
29
@@ -35,16 +35,16 @@ public class ValueWrapperObjectType extends ObjectType {
35
35
private static LongHashMap <WeakReference <DynamicObject >> handleMap = new LongHashMap <>(1024 );
36
36
37
37
public static DynamicObject createValueWrapper (Object value ) {
38
- return Layouts .VALUE_WRAPPER .createValueWrapper (value , NULL_HANDLE );
38
+ return Layouts .VALUE_WRAPPER .createValueWrapper (value , UNSET_HANDLE );
39
39
}
40
40
41
41
public static synchronized DynamicObject createUndefWrapper (NotProvided value ) {
42
- return UNDEF_WRAPPER != null ? UNDEF_WRAPPER : (UNDEF_WRAPPER = Layouts .VALUE_WRAPPER .createValueWrapper (value , NULL_HANDLE ));
42
+ return UNDEF_WRAPPER != null ? UNDEF_WRAPPER : (UNDEF_WRAPPER = Layouts .VALUE_WRAPPER .createValueWrapper (value , UNSET_HANDLE ));
43
43
}
44
44
45
45
public static synchronized DynamicObject createBooleanWrapper (boolean value ) {
46
46
if (value ) {
47
- return TRUE_WRAPPER != null ? TRUE_WRAPPER : (TRUE_WRAPPER = Layouts .VALUE_WRAPPER .createValueWrapper (true , NULL_HANDLE ));
47
+ return TRUE_WRAPPER != null ? TRUE_WRAPPER : (TRUE_WRAPPER = Layouts .VALUE_WRAPPER .createValueWrapper (true , UNSET_HANDLE ));
48
48
} else {
49
49
return FALSE_WRAPPER != null ? FALSE_WRAPPER : (FALSE_WRAPPER = createFalseWrapper ());
50
50
}
@@ -63,15 +63,15 @@ private static DynamicObject createFalseWrapper() {
63
63
public static synchronized DynamicObject createLongWrapper (long value ) {
64
64
DynamicObject wrapper = longMap .get (value );
65
65
if (wrapper == null ) {
66
- wrapper = Layouts .VALUE_WRAPPER .createValueWrapper (value , NULL_HANDLE );
66
+ wrapper = Layouts .VALUE_WRAPPER .createValueWrapper (value , UNSET_HANDLE );
67
67
longMap .put (value , wrapper );
68
68
}
69
69
return wrapper ;
70
70
}
71
71
72
72
@ TruffleBoundary
73
73
public static synchronized DynamicObject createDoubleWrapper (double value ) {
74
- return Layouts .VALUE_WRAPPER .createValueWrapper (value , NULL_HANDLE );
74
+ return Layouts .VALUE_WRAPPER .createValueWrapper (value , UNSET_HANDLE );
75
75
}
76
76
77
77
public static synchronized void addToHandleMap (long handle , DynamicObject wrapper ) {
@@ -83,7 +83,7 @@ public static synchronized Object getFromHandleMap(long handle) {
83
83
WeakReference <DynamicObject > ref = handleMap .get (handle );
84
84
DynamicObject object ;
85
85
if (ref == null ) {
86
- throw new Error ( "Bad handle!" ) ;
86
+ return null ;
87
87
}
88
88
if ((object = ref .get ()) == null ) {
89
89
return null ;
@@ -102,15 +102,16 @@ public static boolean isInstance(TruffleObject receiver) {
102
102
103
103
@ Override
104
104
public boolean equals (DynamicObject object , Object other ) {
105
- if (!(other instanceof ValueWrapperLayout )) {
105
+ if (!(other instanceof DynamicObject ) || Layouts . VALUE_WRAPPER . isValueWrapper ( other )) {
106
106
return false ;
107
107
}
108
108
DynamicObject otherWrapper = (DynamicObject ) other ;
109
+
109
110
final long objectHandle = Layouts .VALUE_WRAPPER .getHandle (object );
110
111
final long otherHandle = Layouts .VALUE_WRAPPER .getHandle (otherWrapper );
111
- if (objectHandle != NULL_HANDLE &&
112
- objectHandle == otherHandle ) {
113
- return true ;
112
+ if (objectHandle != UNSET_HANDLE &&
113
+ otherHandle != UNSET_HANDLE ) {
114
+ return objectHandle == otherHandle ;
114
115
}
115
116
return Layouts .VALUE_WRAPPER .getObject (object ).equals (Layouts .VALUE_WRAPPER .getObject (otherWrapper ));
116
117
}
@@ -119,10 +120,4 @@ public boolean equals(DynamicObject object, Object other) {
119
120
public ForeignAccess getForeignAccessFactory (DynamicObject object ) {
120
121
return ValueWrapperMessageResolutionForeign .ACCESS ;
121
122
}
122
-
123
- @ SuppressWarnings ("serial" )
124
- public static class HandleNotFoundException extends RuntimeException {
125
-
126
- }
127
-
128
123
}
0 commit comments