Skip to content

Commit f40dbb3

Browse files
committed
[GR-60710] Use short for DynamicHub open-world type information.
1 parent 4584bd5 commit f40dbb3

File tree

1 file changed

+20
-17
lines changed
  • substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub

1 file changed

+20
-17
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
import static com.oracle.svm.core.code.RuntimeMetadataDecoderImpl.ALL_RECORD_COMPONENTS_FLAG;
4141
import static com.oracle.svm.core.code.RuntimeMetadataDecoderImpl.ALL_SIGNERS_FLAG;
4242
import static com.oracle.svm.core.code.RuntimeMetadataDecoderImpl.CLASS_ACCESS_FLAGS_MASK;
43-
import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeObject;
44-
import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeInt;
43+
import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeByte;
4544
import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeChar;
45+
import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeInt;
46+
import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeObject;
4647
import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeShort;
47-
import static com.oracle.svm.core.graal.meta.DynamicHubOffsets.writeByte;
4848
import static com.oracle.svm.core.reflect.RuntimeMetadataDecoder.NO_DATA;
4949

5050
import java.io.InputStream;
@@ -239,17 +239,20 @@ public final class DynamicHub implements AnnotatedElement, java.lang.reflect.Typ
239239
// region open-world only fields
240240

241241
/**
242-
* This stores the depth of the type in the inheritance hierarchy. If the type is an interface
243-
* then the typeIDDepth is -1.
242+
* This stores the depth of the type in the inheritance hierarchy. If the type is an interface,
243+
* then the value is negative.
244+
*
245+
* Could be adapted so that {@link #getNumClassTypes()} can compute its value from this field,
246+
* at the cost of increased size of type checks in code.
244247
*/
245248
@UnknownPrimitiveField(availability = AfterHostedUniverse.class)//
246-
private int typeIDDepth;
249+
private short typeIDDepth;
247250

248251
@UnknownPrimitiveField(availability = AfterHostedUniverse.class)//
249-
private int numClassTypes;
252+
private short numClassTypes;
250253

251254
@UnknownPrimitiveField(availability = AfterHostedUniverse.class)//
252-
private int numInterfaceTypes;
255+
private short numInterfaceTypes;
253256

254257
/**
255258
* Array containing this type's type check id information. During a type check, these slots are
@@ -517,9 +520,9 @@ public static DynamicHub allocate(String name, DynamicHub superHub, DynamicHub c
517520

518521
// GR-59687: Determine typecheck related infos
519522
int typeID = 0;
520-
int typeIDDepth = 0;
521-
int numClassTypes = 2;
522-
int numInterfacesTypes = 0;
523+
short typeIDDepth = 0;
524+
short numClassTypes = 2;
525+
short numInterfacesTypes = 0;
523526
int[] openTypeWorldTypeCheckSlots = new int[numClassTypes + (numInterfacesTypes * 2)];
524527

525528
byte additionalFlags = NumUtil.safeToUByte(makeFlag(IS_INSTANTIATED_BIT, true));
@@ -559,10 +562,10 @@ public static DynamicHub allocate(String name, DynamicHub superHub, DynamicHub c
559562
writeInt(hub, dynamicHubOffsets.getTypeIDOffset(), typeID);
560563
// skip typeCheckStart, typeCheckRange, typeCheckSlot and
561564
// closedTypeWorldTypeCheckSlots (closed-world only)
562-
writeInt(hub, dynamicHubOffsets.getTypeIDDepthOffset(), typeIDDepth);
563-
writeInt(hub, dynamicHubOffsets.getNumClassTypesOffset(), numClassTypes);
565+
writeShort(hub, dynamicHubOffsets.getTypeIDDepthOffset(), typeIDDepth);
566+
writeShort(hub, dynamicHubOffsets.getNumClassTypesOffset(), numClassTypes);
564567

565-
writeInt(hub, dynamicHubOffsets.getNumInterfaceTypesOffset(), numInterfacesTypes);
568+
writeShort(hub, dynamicHubOffsets.getNumInterfaceTypesOffset(), numInterfacesTypes);
566569
writeObject(hub, dynamicHubOffsets.getOpenTypeWorldTypeCheckSlotsOffset(), openTypeWorldTypeCheckSlots);
567570

568571
writeChar(hub, dynamicHubOffsets.getMonitorOffsetOffset(), monitorOffset);
@@ -677,9 +680,9 @@ public void setOpenTypeWorldData(CFunctionPointer[] vtable, int typeID,
677680
assert this.vtable == null : "Initialization must be called only once";
678681

679682
this.typeID = typeID;
680-
this.typeIDDepth = typeCheckDepth;
681-
this.numClassTypes = numClassTypes;
682-
this.numInterfaceTypes = numInterfaceTypes;
683+
this.typeIDDepth = NumUtil.safeToShortAE(typeCheckDepth);
684+
this.numClassTypes = NumUtil.safeToShortAE(numClassTypes);
685+
this.numInterfaceTypes = NumUtil.safeToShortAE(numInterfaceTypes);
683686
this.openTypeWorldTypeCheckSlots = typeCheckSlots;
684687
this.vtable = vtable;
685688
}

0 commit comments

Comments
 (0)