From f422d956ad0e0dee233fdf9feae67271800bcf75 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 17 May 2021 13:57:15 -0700 Subject: [PATCH] Mark array types of elemental-type-supertypes as reachable --- .../graal/pointsto/meta/AnalysisType.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java index 059d018a519b..6490532335fc 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java @@ -582,11 +582,22 @@ public void registerAsReachable() { registerAsAllocated(null); componentType.registerAsReachable(); - if (elementalType.isInterface()) { - universe.objectType().getArrayClass(dimension).registerAsReachable(); - } - if (dimension >= 2) { - universe.objectType().getArrayClass(dimension - 1).registerAsReachable(); + + /* + * For a class B extends A, the array type A[] is not a superclass of the array type + * B[]. So there is no strict need to make A[] reachable when B[] is reachable. But + * it turns out that this is puzzling for users, and there are frameworks that + * instantiate such arrays programmatically using Array.newInstance(). To reduce the + * amount of manual configuration that is necessary, we mark all array types of the + * elemental supertypes and superinterfaces also as reachable. + */ + for (int i = 1; i <= dimension; i++) { + if (elementalType.superClass != null) { + elementalType.superClass.getArrayClass(i).registerAsReachable(); + } + for (AnalysisType iface : elementalType.interfaces) { + iface.getArrayClass(i).registerAsReachable(); + } } }