Skip to content

Commit 953b8f8

Browse files
Automatic merge of master into galahad
2 parents 47c1af1 + 733b4eb commit 953b8f8

38 files changed

+1713
-190
lines changed

espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/ClassfileParser.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import static com.oracle.truffle.espresso.classfile.Constants.ACC_SUPER;
5151
import static com.oracle.truffle.espresso.classfile.Constants.ACC_SYNCHRONIZED;
5252
import static com.oracle.truffle.espresso.classfile.Constants.ACC_SYNTHETIC;
53+
import static com.oracle.truffle.espresso.classfile.Constants.ACC_VALUE_BASED;
5354
import static com.oracle.truffle.espresso.classfile.Constants.ACC_VARARGS;
5455
import static com.oracle.truffle.espresso.classfile.Constants.ACC_VOLATILE;
5556
import static com.oracle.truffle.espresso.classfile.Constants.JVM_RECOGNIZED_CLASS_MODIFIERS;
@@ -893,7 +894,7 @@ RuntimeVisibleAnnotationsAttribute parseRuntimeVisibleAnnotations(int attributeS
893894
flags = switch (location) {
894895
case Method -> parseMethodVMAnnotations(subStream);
895896
case Field -> parseFieldVMAnnotations(subStream);
896-
case Class -> 0;
897+
case Class -> parseClassVMAnnotations(subStream);
897898
};
898899
}
899900

@@ -943,6 +944,20 @@ private int parseFieldVMAnnotations(ClassfileStream subStream) {
943944
}
944945
return flags;
945946
}
947+
948+
private int parseClassVMAnnotations(ClassfileStream subStream) {
949+
int flags = 0;
950+
int count = subStream.readU2();
951+
for (int j = 0; j < count; j++) {
952+
int typeIndex = parseAnnotation(subStream);
953+
// Validation of the type is done at runtime by guest java code.
954+
Symbol<?> annotType = pool.utf8At(typeIndex, "annotation type");
955+
if (ParserTypes.jdk_internal_ValueBased.equals(annotType)) {
956+
flags |= ACC_VALUE_BASED;
957+
}
958+
}
959+
return flags;
960+
}
946961
}
947962

948963
@SuppressWarnings("unchecked")
@@ -1111,7 +1126,10 @@ private static Attribute[] spawnAttributesArray(int attributeCount) {
11111126
return attributeCount == 0 ? Attribute.EMPTY_ARRAY : new Attribute[attributeCount];
11121127
}
11131128

1114-
private static int parseAnnotation(ClassfileStream subStream) {
1129+
/**
1130+
* Parse one annotation in an annotation attribute and return the annotation type index.
1131+
*/
1132+
public static int parseAnnotation(ClassfileStream subStream) {
11151133
int typeIndex = subStream.readU2();
11161134
int numElementValuePairs = subStream.readU2();
11171135
for (int k = 0; k < numElementValuePairs; k++) {
@@ -1248,6 +1266,10 @@ private Attribute[] parseClassAttributes() throws ValidationException {
12481266
throw classFormatError("Duplicate PermittedSubclasses attribute");
12491267
}
12501268
classAttributes[i] = permittedSubclasses = parsePermittedSubclasses(attributeName);
1269+
} else if (attributeName.equals(ParserNames.RuntimeVisibleAnnotations)) {
1270+
RuntimeVisibleAnnotationsAttribute annotations = commonAttributeParser.parseRuntimeVisibleAnnotations(attributeSize, AnnotationLocation.Class);
1271+
classFlags |= annotations.flags;
1272+
classAttributes[i] = annotations.attribute;
12511273
} else {
12521274
Attribute attr = commonAttributeParser.parseCommonAttribute(attributeName, attributeSize);
12531275
// stream.skip(attributeSize);

espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/Constants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ public final class Constants {
5353

5454
// Not part of the spec, used internally by the VM.
5555
// Methods
56-
public static final int ACC_FINALIZER = 0x00010000;
5756
public static final int ACC_FORCE_INLINE = 0x00020000;
5857
public static final int ACC_LAMBDA_FORM_COMPILED = 0x00040000;
5958
public static final int ACC_CALLER_SENSITIVE = 0x00080000;
6059
public static final int ACC_HIDDEN = 0x00100000; // also for fields
6160
public static final int ACC_SCOPED = 0x00200000;
6261
public static final int ACC_DONT_INLINE = 0x00400000;
6362
// Classes
63+
public static final int ACC_FINALIZER = 0x00010000;
6464
public static final int ACC_IS_HIDDEN_CLASS = 0x04000000; // synchronized with JVM_ACC_IS_HIDDEN_CLASS
65+
public static final int ACC_VALUE_BASED = 0x00020000;
6566
// Fields
6667
public static final int ACC_STABLE = 0x00010000;
6768

espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/descriptors/ParserSymbols.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public static final class ParserTypes {
7575
public static final Symbol<Type> jdk_internal_vm_annotation_ForceInline = SYMBOLS.putType("Ljdk/internal/vm/annotation/ForceInline;");
7676
public static final Symbol<Type> java_lang_invoke_DontInline = SYMBOLS.putType("Ljava/lang/invoke/DontInline;");
7777
public static final Symbol<Type> jdk_internal_vm_annotation_DontInline = SYMBOLS.putType("Ljdk/internal/vm/annotation/DontInline;");
78+
public static final Symbol<Type> jdk_internal_ValueBased = SYMBOLS.putType("Ljdk/internal/ValueBased;");
7879

7980
// ScopedMemoryAccess
8081
public static final Symbol<Type> jdk_internal_misc_ScopedMemoryAccess$Scoped = SYMBOLS.putType("Ljdk/internal/misc/ScopedMemoryAccess$Scoped;");

espresso-shared/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/descriptors/SignatureSymbols.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public TypeSymbols getTypes() {
140140
* @return Array of Type symbols representing parameter types followed by return type
141141
*/
142142
public Symbol<Type>[] parsed(Symbol<Signature> signature) {
143-
return parse(SignatureSymbols.this.getTypes(), signature, 0);
143+
return parse(SignatureSymbols.this.getTypes(), signature);
144144
}
145145

146146
/**
@@ -186,12 +186,12 @@ private static Symbol<Type> toBasic(Symbol<Type> type) {
186186
* @throws ParserException.ClassFormatError if {the signature is not well-formed
187187
*/
188188
@SuppressWarnings({"rawtypes", "unchecked"})
189-
static Symbol<Type>[] parse(TypeSymbols typeSymbols, Symbol<Signature> signature, int startIndex) throws ParserException.ClassFormatError {
190-
if ((startIndex > signature.length() - 3) || signature.byteAt(startIndex) != '(') {
189+
public static Symbol<Type>[] parse(TypeSymbols typeSymbols, Symbol<Signature> signature) throws ParserException.ClassFormatError {
190+
if ((signature.length() < 3) || signature.byteAt(0) != '(') {
191191
throw new ParserException.ClassFormatError("Invalid method signature: " + signature);
192192
}
193193
final List<Symbol<Type>> buf = new ArrayList<>();
194-
int i = startIndex + 1;
194+
int i = 1;
195195
while (signature.byteAt(i) != ')') {
196196
final Symbol<Type> descriptor = typeSymbols.parse(signature, i, true);
197197
buf.add(descriptor);

substratevm/mx.substratevm/mx_substratevm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ def prevent_build_path_in_libgraal():
16261626
use_modules='image',
16271627
jar_distributions=['substratevm:SVM_JDWP_SERVER'],
16281628
build_args=libsvmjdwp_build_args + [
1629-
'--features=com.oracle.svm.jdwp.server.ServerJDWPFeature',
1629+
'--features=com.oracle.svm.jdwp.server.ServerJDWPFeature,com.oracle.svm.hosted.SymbolsFeature',
16301630
],
16311631
headers=False,
16321632
)

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,33 @@
2424
*/
2525
package com.oracle.svm.core.hub;
2626

27+
import java.util.List;
28+
29+
import org.graalvm.nativeimage.ImageSingletons;
2730
import org.graalvm.nativeimage.Platform;
2831
import org.graalvm.nativeimage.Platforms;
2932

33+
import com.oracle.svm.espresso.classfile.ParserKlass;
34+
3035
import jdk.vm.ci.meta.ResolvedJavaType;
3136

3237
public interface CremaSupport {
3338
@Platforms(Platform.HOSTED_ONLY.class)
3439
ResolvedJavaType createInterpreterType(DynamicHub hub, ResolvedJavaType analysisType);
40+
41+
int getAfterFieldsOffset(DynamicHub hub);
42+
43+
interface CremaDispatchTable {
44+
int vtableLength();
45+
46+
int itableLength(Class<?> iface);
47+
}
48+
49+
CremaDispatchTable getDispatchTable(ParserKlass parsed, Class<?> superClass, List<Class<?>> superInterfaces);
50+
51+
void fillDynamicHubInfo(DynamicHub hub, CremaDispatchTable table, List<Class<?>> transitiveSuperInterfaces, int[] interfaceIndices);
52+
53+
static CremaSupport singleton() {
54+
return ImageSingletons.lookup(CremaSupport.class);
55+
}
3556
}

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

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
import jdk.internal.reflect.FieldAccessor;
154154
import jdk.internal.reflect.Reflection;
155155
import jdk.internal.reflect.ReflectionFactory;
156+
import jdk.vm.ci.meta.JavaKind;
156157
import jdk.vm.ci.meta.ResolvedJavaType;
157158
import sun.reflect.annotation.AnnotationType;
158159
import sun.reflect.generics.factory.GenericsFactory;
@@ -432,47 +433,95 @@ public DynamicHub(Class<?> hostedJavaClass, String name, byte hubType, Reference
432433
*/
433434
@NeverInline("Fields of DynamicHub are immutable. Immutable reads could float above ANY_LOCATION writes.")
434435
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) {
437443
VMError.guarantee(RuntimeClassLoading.isSupported());
438444

439445
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+
}
444459
}
445460

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);
454462

455463
/* Always allow unsafe allocation for classes that were loaded at run-time. */
456464
companion.canUnsafeAllocate = true;
457465

458-
// GR-59687: Correct size and content for vtable
459-
int vTableEntries = 0x100;
460466
companion.classInitializationInfo = new ClassInitializationInfo(false);
461467

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+
/*
490+
* @Hybrid types are not supported. The absence of the annotation is assumed to be
491+
* checked by callers. See AbstractRuntimeClassRegistry.checkNotHybrid.
492+
*/
493+
if (Modifier.isAbstract(modifiers)) {
494+
layoutEncoding = LayoutEncoding.forAbstract();
495+
} else {
496+
int instanceSize = afterFieldsOffset;
497+
498+
boolean needsMonitorOffset = !valueBased;
499+
if (needsMonitorOffset) {
500+
// GR-60069 could look for gaps
501+
int size = ol.getReferenceSize();
502+
int bits = size - 1;
503+
int alignmentAdjust = ((instanceSize + bits) & ~bits) - instanceSize;
504+
monitorOffset = instanceSize + alignmentAdjust;
505+
instanceSize = monitorOffset + size;
506+
}
466507

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)];
508+
if (ol.isIdentityHashFieldInObjectHeader()) {
509+
identityHashOffset = ol.getObjectHeaderIdentityHashOffset();
510+
} else if (ol.isIdentityHashFieldAtTypeSpecificOffset() || ol.isIdentityHashFieldOptional()) {
511+
// GR-60069 could look for gaps
512+
int bits = Integer.BYTES - 1;
513+
int alignmentAdjust = ((instanceSize + bits) & ~bits) - instanceSize;
514+
identityHashOffset = instanceSize + alignmentAdjust;
515+
instanceSize = identityHashOffset + Integer.BYTES;
516+
} else {
517+
throw VMError.shouldNotReachHere("Unexpected identity hash mode");
518+
}
519+
layoutEncoding = LayoutEncoding.forPureInstance(ol.alignUp(instanceSize));
520+
}
521+
}
473522

474523
companion.interfacesEncoding = interfacesEncoding;
475-
// GR-59683: Proper value needed.
524+
// GR-57813: setup a LazyFinalReference that calls `values` via reflection.
476525
companion.enumConstantsReference = null;
477526

478527
/*
@@ -519,8 +568,10 @@ public static DynamicHub allocate(String name, DynamicHub superHub, Object inter
519568
writeShort(hub, dynamicHubOffsets.getNumInterfaceTypesOffset(), numInterfacesTypes);
520569
writeObject(hub, dynamicHubOffsets.getOpenTypeWorldTypeCheckSlotsOffset(), openTypeWorldTypeCheckSlots);
521570

522-
writeChar(hub, dynamicHubOffsets.getMonitorOffsetOffset(), monitorOffset);
523-
writeChar(hub, dynamicHubOffsets.getIdentityHashOffsetOffset(), identityHashOffset);
571+
VMError.guarantee(monitorOffset == (char) monitorOffset);
572+
VMError.guarantee(identityHashOffset == (char) identityHashOffset);
573+
writeChar(hub, dynamicHubOffsets.getMonitorOffsetOffset(), (char) monitorOffset);
574+
writeChar(hub, dynamicHubOffsets.getIdentityHashOffsetOffset(), (char) identityHashOffset);
524575

525576
writeShort(hub, dynamicHubOffsets.getFlagsOffset(), flags);
526577

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,17 @@ public final class DynamicHubCompanion {
149149
static DynamicHubCompanion createHosted(Module module, DynamicHub superHub, String sourceFileName, int modifiers,
150150
Object classLoader, Class<?> nestHost, String simpleBinaryName, Object declaringClass, String signature) {
151151

152-
return new DynamicHubCompanion(module, superHub, sourceFileName, modifiers, classLoader, nestHost, simpleBinaryName, declaringClass, signature, null);
152+
return new DynamicHubCompanion(module, superHub, sourceFileName, modifiers, classLoader, nestHost, simpleBinaryName, declaringClass, signature);
153153
}
154154

155155
static DynamicHubCompanion createAtRuntime(Module module, DynamicHub superHub, String sourceFileName, int modifiers,
156-
ClassLoader classLoader, Class<?> nestHost, String simpleBinaryName, Object declaringClass, String signature,
157-
ResolvedJavaType interpreterType) {
156+
ClassLoader classLoader, Class<?> nestHost, String simpleBinaryName, Object declaringClass, String signature) {
158157
assert RuntimeClassLoading.isSupported();
159-
return new DynamicHubCompanion(module, superHub, sourceFileName, modifiers, classLoader, nestHost, simpleBinaryName, declaringClass, signature, interpreterType);
158+
return new DynamicHubCompanion(module, superHub, sourceFileName, modifiers, classLoader, nestHost, simpleBinaryName, declaringClass, signature);
160159
}
161160

162161
private DynamicHubCompanion(Module module, DynamicHub superHub, String sourceFileName, int modifiers,
163-
Object classLoader, Class<?> nestHost, String simpleBinaryName, Object declaringClass, String signature, ResolvedJavaType interpreterType) {
162+
Object classLoader, Class<?> nestHost, String simpleBinaryName, Object declaringClass, String signature) {
164163
this.module = module;
165164
this.superHub = superHub;
166165
this.sourceFileName = sourceFileName;
@@ -171,6 +170,5 @@ private DynamicHubCompanion(Module module, DynamicHub superHub, String sourceFil
171170
this.signature = signature;
172171

173172
this.classLoader = classLoader;
174-
this.interpreterType = interpreterType;
175173
}
176174
}

0 commit comments

Comments
 (0)