|
153 | 153 | import jdk.internal.reflect.FieldAccessor;
|
154 | 154 | import jdk.internal.reflect.Reflection;
|
155 | 155 | import jdk.internal.reflect.ReflectionFactory;
|
| 156 | +import jdk.vm.ci.meta.JavaKind; |
156 | 157 | import jdk.vm.ci.meta.ResolvedJavaType;
|
157 | 158 | import sun.reflect.annotation.AnnotationType;
|
158 | 159 | import sun.reflect.generics.factory.GenericsFactory;
|
@@ -432,47 +433,92 @@ public DynamicHub(Class<?> hostedJavaClass, String name, byte hubType, Reference
|
432 | 433 | */
|
433 | 434 | @NeverInline("Fields of DynamicHub are immutable. Immutable reads could float above ANY_LOCATION writes.")
|
434 | 435 | public static DynamicHub allocate(String name, DynamicHub superHub, Object interfacesEncoding, DynamicHub componentHub, String sourceFileName,
|
435 |
| - int modifiers, short flags, ClassLoader classLoader, Class<?> nestHost, String simpleBinaryName, |
436 |
| - Object declaringClass, String signature) { |
| 436 | + int modifiers, short flags, ClassLoader classLoader, Class<?> nestHost, String simpleBinaryName, Module module, |
| 437 | + Object declaringClass, String signature, int typeID, |
| 438 | + short numClassTypes, |
| 439 | + short typeIDDepth, |
| 440 | + short numInterfacesTypes, |
| 441 | + int[] openTypeWorldTypeCheckSlots, int vTableEntries, |
| 442 | + int afterFieldsOffset, boolean valueBased) { |
437 | 443 | VMError.guarantee(RuntimeClassLoading.isSupported());
|
438 | 444 |
|
439 | 445 | ReferenceType referenceType = ReferenceType.computeReferenceType(DynamicHub.toClass(superHub));
|
440 |
| - // GR-59683: HubType.OBJECT_ARRAY? |
441 |
| - byte hubType = HubType.INSTANCE; |
442 |
| - if (referenceType != ReferenceType.None) { |
443 |
| - hubType = HubType.REFERENCE_INSTANCE; |
| 446 | + byte hubType; |
| 447 | + if (componentHub != null) { |
| 448 | + if (componentHub.isPrimitive()) { |
| 449 | + hubType = HubType.PRIMITIVE_ARRAY; |
| 450 | + } else { |
| 451 | + hubType = HubType.OBJECT_ARRAY; |
| 452 | + } |
| 453 | + } else { |
| 454 | + if (referenceType == ReferenceType.None) { |
| 455 | + hubType = HubType.INSTANCE; |
| 456 | + } else { |
| 457 | + hubType = HubType.REFERENCE_INSTANCE; |
| 458 | + } |
444 | 459 | }
|
445 | 460 |
|
446 |
| - // GR-62339 |
447 |
| - Module module = null; |
448 |
| - |
449 |
| - // GR-59683: Setup interpreter metadata at run-time. |
450 |
| - ResolvedJavaType interpreterType = null; |
451 |
| - |
452 |
| - DynamicHubCompanion companion = DynamicHubCompanion.createAtRuntime(module, superHub, sourceFileName, modifiers, classLoader, nestHost, simpleBinaryName, declaringClass, signature, |
453 |
| - interpreterType); |
| 461 | + DynamicHubCompanion companion = DynamicHubCompanion.createAtRuntime(module, superHub, sourceFileName, modifiers, classLoader, nestHost, simpleBinaryName, declaringClass, signature); |
454 | 462 |
|
455 | 463 | /* Always allow unsafe allocation for classes that were loaded at run-time. */
|
456 | 464 | companion.canUnsafeAllocate = true;
|
457 | 465 |
|
458 |
| - // GR-59687: Correct size and content for vtable |
459 |
| - int vTableEntries = 0x100; |
460 | 466 | companion.classInitializationInfo = new ClassInitializationInfo(false);
|
461 | 467 |
|
462 |
| - // GR-60069: Determine size for instance and offsets for monitor and identityHashCode |
463 |
| - int layoutEncoding = 0x40; |
464 |
| - char monitorOffset = 0; |
465 |
| - char identityHashOffset = 0; |
| 468 | + assert !isFlagSet(flags, IS_PRIMITIVE_FLAG_BIT); |
| 469 | + boolean isInterface = isFlagSet(flags, IS_INTERFACE_FLAG_BIT); |
| 470 | + int layoutEncoding; |
| 471 | + int monitorOffset = 0; |
| 472 | + int identityHashOffset = 0; |
| 473 | + |
| 474 | + // See also similar logic in UniverseBuilder.buildHubs |
| 475 | + ObjectLayout ol = ConfigurationValues.getObjectLayout(); |
| 476 | + if (componentHub != null) { |
| 477 | + // array |
| 478 | + JavaKind componentKind = JavaKind.fromJavaClass(DynamicHub.toClass(componentHub)); |
| 479 | + boolean isObject = (componentKind == JavaKind.Object); |
| 480 | + layoutEncoding = LayoutEncoding.forArray(isObject, ol.getArrayBaseOffset(componentKind), ol.getArrayIndexShift(componentKind)); |
| 481 | + if (ol.isIdentityHashFieldInObjectHeader() || ol.isIdentityHashFieldAtTypeSpecificOffset()) { |
| 482 | + identityHashOffset = NumUtil.safeToInt(ol.getObjectHeaderIdentityHashOffset()); |
| 483 | + } |
| 484 | + } else if (isInterface) { |
| 485 | + layoutEncoding = LayoutEncoding.forInterface(); |
| 486 | + } else { |
| 487 | + // instance class |
| 488 | + assert !"java.lang.Class".equals(name); |
| 489 | + // @Hybrid is ignored |
| 490 | + if (Modifier.isAbstract(modifiers)) { |
| 491 | + layoutEncoding = LayoutEncoding.forAbstract(); |
| 492 | + } else { |
| 493 | + int instanceSize = afterFieldsOffset; |
| 494 | + |
| 495 | + boolean needsMonitorOffset = !valueBased; |
| 496 | + if (needsMonitorOffset) { |
| 497 | + // GR-60069 could look for gaps |
| 498 | + int size = ol.getReferenceSize(); |
| 499 | + int bits = size - 1; |
| 500 | + int alignmentAdjust = ((instanceSize + bits) & ~bits) - instanceSize; |
| 501 | + monitorOffset = instanceSize + alignmentAdjust; |
| 502 | + instanceSize = monitorOffset + size; |
| 503 | + } |
466 | 504 |
|
467 |
| - // GR-59687: Determine typecheck related infos |
468 |
| - int typeID = 0; |
469 |
| - short typeIDDepth = 0; |
470 |
| - short numClassTypes = 2; |
471 |
| - short numInterfacesTypes = 0; |
472 |
| - int[] openTypeWorldTypeCheckSlots = new int[numClassTypes + (numInterfacesTypes * 2)]; |
| 505 | + if (ol.isIdentityHashFieldInObjectHeader()) { |
| 506 | + identityHashOffset = ol.getObjectHeaderIdentityHashOffset(); |
| 507 | + } else if (ol.isIdentityHashFieldAtTypeSpecificOffset() || ol.isIdentityHashFieldOptional()) { |
| 508 | + // GR-60069 could look for gaps |
| 509 | + int bits = Integer.BYTES - 1; |
| 510 | + int alignmentAdjust = ((instanceSize + bits) & ~bits) - instanceSize; |
| 511 | + identityHashOffset = instanceSize + alignmentAdjust; |
| 512 | + instanceSize = identityHashOffset + Integer.BYTES; |
| 513 | + } else { |
| 514 | + throw VMError.shouldNotReachHere("Unexpected identity hash mode"); |
| 515 | + } |
| 516 | + layoutEncoding = LayoutEncoding.forPureInstance(ol.alignUp(instanceSize)); |
| 517 | + } |
| 518 | + } |
473 | 519 |
|
474 | 520 | companion.interfacesEncoding = interfacesEncoding;
|
475 |
| - // GR-59683: Proper value needed. |
| 521 | + // GR-57813: setup a LazyFinalReference that calls `values` via reflection. |
476 | 522 | companion.enumConstantsReference = null;
|
477 | 523 |
|
478 | 524 | /*
|
@@ -519,8 +565,10 @@ public static DynamicHub allocate(String name, DynamicHub superHub, Object inter
|
519 | 565 | writeShort(hub, dynamicHubOffsets.getNumInterfaceTypesOffset(), numInterfacesTypes);
|
520 | 566 | writeObject(hub, dynamicHubOffsets.getOpenTypeWorldTypeCheckSlotsOffset(), openTypeWorldTypeCheckSlots);
|
521 | 567 |
|
522 |
| - writeChar(hub, dynamicHubOffsets.getMonitorOffsetOffset(), monitorOffset); |
523 |
| - writeChar(hub, dynamicHubOffsets.getIdentityHashOffsetOffset(), identityHashOffset); |
| 568 | + VMError.guarantee(monitorOffset == (char) monitorOffset); |
| 569 | + VMError.guarantee(identityHashOffset == (char) identityHashOffset); |
| 570 | + writeChar(hub, dynamicHubOffsets.getMonitorOffsetOffset(), (char) monitorOffset); |
| 571 | + writeChar(hub, dynamicHubOffsets.getIdentityHashOffsetOffset(), (char) identityHashOffset); |
524 | 572 |
|
525 | 573 | writeShort(hub, dynamicHubOffsets.getFlagsOffset(), flags);
|
526 | 574 |
|
|
0 commit comments