Skip to content

Commit 1df9498

Browse files
committed
Throw UnexpectedResultException for boxed values, too.
1 parent 08e5e21 commit 1df9498

File tree

3 files changed

+28
-51
lines changed

3 files changed

+28
-51
lines changed

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/api/object/test/DynamicObjectLibraryTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ public void testGet1() throws UnexpectedResultException {
142142

143143
var getNode = createLibraryForReceiverAndKey(o1, k1);
144144
assertEquals(v1, getNode.getOrDefault(o1, k1, null));
145-
assertEquals(v1, getNode.getIntOrDefault(o1, k1, null));
145+
assertEquals(v1, getAsInt(getNode, o1, k1, null));
146146
assertEquals(v1, getNode.getOrDefault(o2, k1, null));
147-
assertEquals(v1, getNode.getIntOrDefault(o2, k1, null));
147+
assertEquals(v1, getAsInt(getNode, o2, k1, null));
148148

149149
String v2 = "asdf";
150150
uncachedSet(o1, k1, v2);
@@ -158,7 +158,7 @@ public void testGet1() throws UnexpectedResultException {
158158
assertEquals(v2, e.getResult());
159159
}
160160
assertEquals(v1, getNode.getOrDefault(o2, k1, null));
161-
assertEquals(v1, getNode.getIntOrDefault(o2, k1, null));
161+
assertEquals(v1, getAsInt(getNode, o2, k1, null));
162162

163163
String missingKey = "missing";
164164
var getMissingKey = createLibraryForReceiverAndKey(o1, missingKey);
@@ -169,6 +169,17 @@ public void testGet1() throws UnexpectedResultException {
169169
assertEquals(404, getMissingKey.getIntOrDefault(o1, missingKey, 404));
170170
}
171171

172+
private static int getAsInt(DynamicObjectLibraryWrapper getNode, DynamicObject o1, String missingKey, Object defaultValue) throws UnexpectedResultException {
173+
try {
174+
return getNode.getIntOrDefault(o1, missingKey, defaultValue);
175+
} catch (UnexpectedResultException e) {
176+
if (e.getResult() instanceof Integer intValue) {
177+
return intValue;
178+
}
179+
throw e;
180+
}
181+
}
182+
172183
@Test
173184
public void testPut1() {
174185
DynamicObject o1 = createEmpty();

truffle/src/com.oracle.truffle.api.object.test/src/com/oracle/truffle/api/object/test/DynamicObjectNodesTest.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ public void testGet1() throws UnexpectedResultException {
271271

272272
var getNode = createGetNode();
273273
assertEquals(v1, getNode.execute(o1, k1, null));
274-
assertEquals(v1, getNode.executeInt(o1, k1, null));
274+
assertEquals(v1, getAsInt(getNode, o1, k1, null));
275275
assertEquals(v1, getNode.execute(o2, k1, null));
276-
assertEquals(v1, getNode.executeInt(o2, k1, null));
276+
assertEquals(v1, getAsInt(getNode, o2, k1, null));
277277

278278
String v2 = "asdf";
279279
uncachedSet(o1, k1, v2);
@@ -287,7 +287,7 @@ public void testGet1() throws UnexpectedResultException {
287287
assertEquals(v2, e.getResult());
288288
}
289289
assertEquals(v1, getNode.execute(o2, k1, null));
290-
assertEquals(v1, getNode.executeInt(o2, k1, null));
290+
assertEquals(v1, getAsInt(getNode, o2, k1, null));
291291

292292
String missingKey = "missing";
293293
var getMissingKey = createGetNode();
@@ -298,6 +298,17 @@ public void testGet1() throws UnexpectedResultException {
298298
assertEquals(404, getMissingKey2.executeInt(o1, missingKey, 404));
299299
}
300300

301+
private static int getAsInt(DynamicObject.GetNode getNode, DynamicObject o1, String missingKey, Object defaultValue) throws UnexpectedResultException {
302+
try {
303+
return getNode.executeInt(o1, missingKey, defaultValue);
304+
} catch (UnexpectedResultException e) {
305+
if (e.getResult() instanceof Integer intValue) {
306+
return intValue;
307+
}
308+
throw e;
309+
}
310+
}
311+
301312
@Test
302313
public void testPut1() {
303314
DynamicObject o1 = createEmpty();

truffle/src/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/Location.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -277,21 +277,6 @@ final int getIntInternal(DynamicObject store, Shape expectedShape, boolean guard
277277
}
278278
return (int) longValue;
279279
}
280-
} else if (this instanceof ObjectLocation objectLocation) {
281-
Object value;
282-
if (field == null) {
283-
Object array = getObjectArray(store, guard);
284-
long offset = getObjectArrayOffset();
285-
value = UnsafeAccess.unsafeGetObject(array, offset, guard, this);
286-
} else {
287-
if (UseVarHandle) {
288-
value = field.varHandle().get(store);
289-
} else {
290-
field.receiverCheck(store);
291-
value = UnsafeAccess.unsafeGetObject(store, getFieldOffset(), guard, this);
292-
}
293-
}
294-
return expectInteger(CompilerDirectives.inInterpreter() ? value : objectLocation.assumedTypeCast(value, guard));
295280
}
296281
return getIntUnexpected(store, expectedShape, guard);
297282
}
@@ -324,21 +309,6 @@ final long getLongInternal(DynamicObject store, Shape expectedShape, boolean gua
324309
}
325310
return longValue;
326311
}
327-
} else if (this instanceof ObjectLocation objectLocation) {
328-
Object value;
329-
if (field == null) {
330-
Object array = getObjectArray(store, guard);
331-
long offset = getObjectArrayOffset();
332-
value = UnsafeAccess.unsafeGetObject(array, offset, guard, this);
333-
} else {
334-
if (UseVarHandle) {
335-
value = field.varHandle().get(store);
336-
} else {
337-
field.receiverCheck(store);
338-
value = UnsafeAccess.unsafeGetObject(store, getFieldOffset(), guard, this);
339-
}
340-
}
341-
return expectLong(CompilerDirectives.inInterpreter() ? value : objectLocation.assumedTypeCast(value, guard));
342312
}
343313
return getLongUnexpected(store, expectedShape, guard);
344314
}
@@ -371,21 +341,6 @@ final double getDoubleInternal(DynamicObject store, Shape expectedShape, boolean
371341
}
372342
return Double.longBitsToDouble(longValue);
373343
}
374-
} else if (this instanceof ObjectLocation objectLocation) {
375-
Object value;
376-
if (field == null) {
377-
Object array = getObjectArray(store, guard);
378-
long offset = getObjectArrayOffset();
379-
value = UnsafeAccess.unsafeGetObject(array, offset, guard, this);
380-
} else {
381-
if (UseVarHandle) {
382-
value = field.varHandle().get(store);
383-
} else {
384-
field.receiverCheck(store);
385-
value = UnsafeAccess.unsafeGetObject(store, getFieldOffset(), guard, this);
386-
}
387-
}
388-
return expectDouble(CompilerDirectives.inInterpreter() ? value : objectLocation.assumedTypeCast(value, guard));
389344
}
390345
return getDoubleUnexpected(store, expectedShape, guard);
391346
}

0 commit comments

Comments
 (0)