40
40
import static com .oracle .svm .core .code .RuntimeMetadataDecoderImpl .ALL_RECORD_COMPONENTS_FLAG ;
41
41
import static com .oracle .svm .core .code .RuntimeMetadataDecoderImpl .ALL_SIGNERS_FLAG ;
42
42
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 ;
45
44
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 ;
46
47
import static com .oracle .svm .core .graal .meta .DynamicHubOffsets .writeShort ;
47
- import static com .oracle .svm .core .graal .meta .DynamicHubOffsets .writeByte ;
48
48
import static com .oracle .svm .core .reflect .RuntimeMetadataDecoder .NO_DATA ;
49
49
50
50
import java .io .InputStream ;
@@ -184,7 +184,7 @@ public final class DynamicHub implements AnnotatedElement, java.lang.reflect.Typ
184
184
* The returned category does not necessarily match the {@link LayoutEncoding}, see
185
185
* {@link Hybrid} objects for more details.
186
186
*/
187
- private final int hubType ;
187
+ private final byte hubType ;
188
188
189
189
/**
190
190
* Used to quickly determine if this class is a subclass of {@link Reference}.
@@ -239,17 +239,20 @@ public final class DynamicHub implements AnnotatedElement, java.lang.reflect.Typ
239
239
// region open-world only fields
240
240
241
241
/**
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.
244
247
*/
245
248
@ UnknownPrimitiveField (availability = AfterHostedUniverse .class )//
246
- private int typeIDDepth ;
249
+ private short typeIDDepth ;
247
250
248
251
@ UnknownPrimitiveField (availability = AfterHostedUniverse .class )//
249
- private int numClassTypes ;
252
+ private short numClassTypes ;
250
253
251
254
@ UnknownPrimitiveField (availability = AfterHostedUniverse .class )//
252
- private int numInterfaceTypes ;
255
+ private short numInterfaceTypes ;
253
256
254
257
/**
255
258
* Array containing this type's type check id information. During a type check, these slots are
@@ -452,7 +455,7 @@ public final class DynamicHub implements AnnotatedElement, java.lang.reflect.Typ
452
455
private ReflectionMetadata reflectionMetadata ;
453
456
454
457
@ Platforms (Platform .HOSTED_ONLY .class )
455
- public DynamicHub (Class <?> hostedJavaClass , String name , int hubType , ReferenceType referenceType , DynamicHub superType ,
458
+ public DynamicHub (Class <?> hostedJavaClass , String name , byte hubType , ReferenceType referenceType , DynamicHub superType ,
456
459
DynamicHub componentHub , String sourceFileName , int modifiers , short flags , ClassLoader classLoader ,
457
460
Class <?> nestHost , String simpleBinaryName , Object declaringClass , String signature , int layerId ) {
458
461
this .hostedJavaClass = hostedJavaClass ;
@@ -500,7 +503,7 @@ public static DynamicHub allocate(String name, DynamicHub superHub, DynamicHub c
500
503
501
504
ReferenceType referenceType = ReferenceType .computeReferenceType (DynamicHub .toClass (superHub ));
502
505
// GR-59683: HubType.OBJECT_ARRAY?
503
- int hubTybe = referenceType == ReferenceType .None ? HubType .INSTANCE : HubType .REFERENCE_INSTANCE ;
506
+ byte hubType = ( byte ) (( referenceType == ReferenceType .None ) ? HubType .INSTANCE : HubType .REFERENCE_INSTANCE ) ;
504
507
505
508
DynamicHubCompanion companion = new DynamicHubCompanion (classLoader );
506
509
/* Always allow unsafe allocation for classes that were loaded at run-time. */
@@ -517,9 +520,9 @@ public static DynamicHub allocate(String name, DynamicHub superHub, DynamicHub c
517
520
518
521
// GR-59687: Determine typecheck related infos
519
522
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 ;
523
526
int [] openTypeWorldTypeCheckSlots = new int [numClassTypes + (numInterfacesTypes * 2 )];
524
527
525
528
byte additionalFlags = NumUtil .safeToUByte (makeFlag (IS_INSTANTIATED_BIT , true ));
@@ -552,17 +555,17 @@ public static DynamicHub allocate(String name, DynamicHub superHub, DynamicHub c
552
555
DynamicHubOffsets dynamicHubOffsets = DynamicHubOffsets .singleton ();
553
556
/* Write fields in defining order. */
554
557
writeObject (hub , dynamicHubOffsets .getNameOffset (), name );
555
- writeInt (hub , dynamicHubOffsets .getHubTypeOffset (), hubTybe );
558
+ writeByte (hub , dynamicHubOffsets .getHubTypeOffset (), hubType );
556
559
writeByte (hub , dynamicHubOffsets .getReferenceTypeOffset (), referenceType .getValue ());
557
560
558
561
writeInt (hub , dynamicHubOffsets .getLayoutEncodingOffset (), layoutEncoding );
559
562
writeInt (hub , dynamicHubOffsets .getTypeIDOffset (), typeID );
560
563
// skip typeCheckStart, typeCheckRange, typeCheckSlot and
561
564
// 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 );
564
567
565
- writeInt (hub , dynamicHubOffsets .getNumInterfaceTypesOffset (), numInterfacesTypes );
568
+ writeShort (hub , dynamicHubOffsets .getNumInterfaceTypesOffset (), numInterfacesTypes );
566
569
writeObject (hub , dynamicHubOffsets .getOpenTypeWorldTypeCheckSlotsOffset (), openTypeWorldTypeCheckSlots );
567
570
568
571
writeChar (hub , dynamicHubOffsets .getMonitorOffsetOffset (), monitorOffset );
@@ -677,9 +680,9 @@ public void setOpenTypeWorldData(CFunctionPointer[] vtable, int typeID,
677
680
assert this .vtable == null : "Initialization must be called only once" ;
678
681
679
682
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 ) ;
683
686
this .openTypeWorldTypeCheckSlots = typeCheckSlots ;
684
687
this .vtable = vtable ;
685
688
}
0 commit comments