Skip to content

Commit

Permalink
[GR-50854] Fix clinit simulation for arraycopy with null values.
Browse files Browse the repository at this point in the history
PullRequest: graal/16394
  • Loading branch information
Christian Wimmer committed Dec 17, 2023
2 parents 9028e51 + 94ec1bc commit 4fc8453
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,12 @@ protected boolean handleArrayCopy(ImageHeapArray source, int sourcePos, ImageHea
}
if (destComponentType.getJavaKind() == JavaKind.Object && !destComponentType.isJavaLangObject() && !sourceComponentType.equals(destComponentType)) {
for (int i = 0; i < length; i++) {
var elementValueType = ((TypedConstant) source.getElement(sourcePos + i)).getType(metaAccess);
if (!destComponentType.isAssignableFrom(elementValueType)) {
return false;
var elementValue = (JavaConstant) source.getElement(sourcePos + i);
if (elementValue.isNonNull()) {
var elementValueType = ((TypedConstant) elementValue).getType(metaAccess);
if (!destComponentType.isAssignableFrom(elementValueType)) {
return false;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public static Object defaultValue(Class<?> clazz) {
System.arraycopy(shorts, 1, S1, 2, 5);
System.arraycopy(S1, 3, S1, 5, 5);

Object[] objects = {"42", "43", "44", "45", "46", "47", "48"};
Object[] objects = {"42", null, "44", "45", null, "47", "48"};
O1 = Arrays.copyOf(objects, 3);
O2 = Arrays.copyOfRange(objects, 3, 6, String[].class);
}
Expand Down Expand Up @@ -943,8 +943,8 @@ public static void main(String[] args) {
assertSame(Short.class, BoxingMustBeSimulated.defaultValue(short.class).getClass());
assertSame(Float.class, BoxingMustBeSimulated.defaultValue(float.class).getClass());
assertTrue(Arrays.equals((short[]) BoxingMustBeSimulated.S1, new short[]{0, 0, 43, 44, 45, 44, 45, 46, 47, 0, 0, 0}));
assertTrue(Arrays.equals((Object[]) BoxingMustBeSimulated.O1, new Object[]{"42", "43", "44"}));
assertTrue(Arrays.equals((Object[]) BoxingMustBeSimulated.O2, new String[]{"45", "46", "47"}));
assertTrue(Arrays.equals((Object[]) BoxingMustBeSimulated.O1, new Object[]{"42", null, "44"}));
assertTrue(Arrays.equals((Object[]) BoxingMustBeSimulated.O2, new String[]{"45", null, "47"}));

/*
* The unsafe field offset lookup is constant folded at image build time, which also
Expand Down

0 comments on commit 4fc8453

Please sign in to comment.