From ec4af044634ea4d716a512f906aa625ccd2d60de Mon Sep 17 00:00:00 2001 From: Peter Hofer Date: Mon, 23 Dec 2024 12:16:59 +0100 Subject: [PATCH] Encode numClassTypes in DynamicHub.typeIDDepth. --- .../com/oracle/svm/core/hub/DynamicHub.java | 19 +++++++++++-------- .../src/com/oracle/svm/hosted/SVMHost.java | 1 - .../svm/hosted/meta/TypeCheckBuilder.java | 5 +++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java index f329bf51111d..82e0cafc59a6 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java @@ -40,11 +40,11 @@ import static com.oracle.svm.core.code.RuntimeMetadataDecoderImpl.ALL_RECORD_COMPONENTS_FLAG; import static com.oracle.svm.core.code.RuntimeMetadataDecoderImpl.ALL_SIGNERS_FLAG; import static com.oracle.svm.core.code.RuntimeMetadataDecoderImpl.CLASS_ACCESS_FLAGS_MASK; -import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeObject; -import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeInt; +import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeByte; import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeChar; +import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeInt; +import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeObject; import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeShort; -import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeByte; import static com.oracle.svm.core.reflect.RuntimeMetadataDecoder.NO_DATA; import java.io.InputStream; @@ -239,8 +239,8 @@ public final class DynamicHub implements AnnotatedElement, java.lang.reflect.Typ // region open-world only fields /** - * This stores the depth of the type in the inheritance hierarchy. If the type is an interface - * then the typeIDDepth is -1. + * This stores the depth of the type in the inheritance hierarchy. If the type is an interface, + * then the typeIDDepth is negative. */ @UnknownPrimitiveField(availability = AfterHostedUniverse.class)// private int typeIDDepth; @@ -673,15 +673,17 @@ public void setClosedTypeWorldData(CFunctionPointer[] vtable, int typeID, short @Platforms(Platform.HOSTED_ONLY.class) public void setOpenTypeWorldData(CFunctionPointer[] vtable, int typeID, - int typeCheckDepth, int numClassTypes, int numInterfaceTypes, int[] typeCheckSlots) { + int typeIDDepth, int numClassTypes, int numInterfaceTypes, int[] typeCheckSlots) { assert this.vtable == null : "Initialization must be called only once"; this.typeID = typeID; - this.typeIDDepth = typeCheckDepth; + this.typeIDDepth = typeIDDepth; this.numClassTypes = numClassTypes; this.numInterfaceTypes = numInterfaceTypes; this.openTypeWorldTypeCheckSlots = typeCheckSlots; this.vtable = vtable; + + VMError.guarantee(getNumClassTypes() == numClassTypes); } @Platforms(Platform.HOSTED_ONLY.class) @@ -839,8 +841,9 @@ public int getTypeIDDepth() { return typeIDDepth; } + /** @see #setOpenTypeWorldData */ public int getNumClassTypes() { - return numClassTypes; + return (typeIDDepth < 0) ? -(typeIDDepth + 1) : (typeIDDepth + 1); } public int getNumInterfaceTypes() { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java index 6cdd53b0da75..767827a67d93 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java @@ -883,7 +883,6 @@ private void initializeExcludedFields() { excludedFields.add(ReflectionUtil.lookupField(DynamicHub.class, "arrayHub")); excludedFields.add(ReflectionUtil.lookupField(DynamicHub.class, "additionalFlags")); excludedFields.add(ReflectionUtil.lookupField(DynamicHub.class, "layoutEncoding")); - excludedFields.add(ReflectionUtil.lookupField(DynamicHub.class, "numClassTypes")); excludedFields.add(ReflectionUtil.lookupField(DynamicHub.class, "numInterfaceTypes")); excludedFields.add(ReflectionUtil.lookupField(DynamicHub.class, "openTypeWorldTypeCheckSlots")); excludedFields.add(ReflectionUtil.lookupField(DynamicHub.class, "typeIDDepth")); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/TypeCheckBuilder.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/TypeCheckBuilder.java index 663e6d735db4..d7a35c9ad629 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/TypeCheckBuilder.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/TypeCheckBuilder.java @@ -1967,7 +1967,9 @@ private static void generateOpenTypeWorldTypeMetadata(Map= 0) { assert info.classDisplay[idDepth] == type.typeID : String.format("Mismatch between class display and type. idDepth: %s typeID: %s info: %s ", idDepth, type.typeID, info); } @@ -1975,7 +1977,6 @@ private static void generateOpenTypeWorldTypeMetadata(Map orderedInterfaces = info.implementedInterfaces.stream().sorted(Comparator.comparingInt(HostedType::getTypeID)).toList(); int[] interfaceTypeIDs = orderedInterfaces.stream().mapToInt(HostedType::getTypeID).toArray(); - int numClassTypes = info.classDisplay.length; int[] typeIDSlots = new int[numClassTypes + numInterfaceTypes]; System.arraycopy(info.classDisplay, 0, typeIDSlots, 0, numClassTypes); System.arraycopy(interfaceTypeIDs, 0, typeIDSlots, numClassTypes, numInterfaceTypes);