Skip to content

Commit e0ba5cb

Browse files
Automatic merge of master into galahad
2 parents 5d6f0ff + bb418a9 commit e0ba5cb

File tree

5 files changed

+82
-92
lines changed

5 files changed

+82
-92
lines changed

espresso/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/attributes/CodeAttribute.java

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,16 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23-
2423
package com.oracle.truffle.espresso.classfile.attributes;
2524

26-
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.INVOKEDYNAMIC;
27-
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.JSR;
28-
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.JSR_W;
29-
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.MONITORENTER;
30-
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.MONITOREXIT;
31-
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.RET;
32-
33-
import com.oracle.truffle.api.CompilerDirectives;
3425
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
3526
import com.oracle.truffle.espresso.classfile.ClassfileParser;
3627
import com.oracle.truffle.espresso.classfile.ExceptionHandler;
37-
import com.oracle.truffle.espresso.classfile.bytecode.BytecodeStream;
3828
import com.oracle.truffle.espresso.classfile.descriptors.Name;
3929
import com.oracle.truffle.espresso.classfile.descriptors.ParserSymbols.ParserNames;
4030
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
4131

4232
public final class CodeAttribute extends Attribute {
43-
4433
public static final Symbol<Name> NAME = ParserNames.Code;
4534

4635
private final int majorVersion;
@@ -57,12 +46,6 @@ public final class CodeAttribute extends Attribute {
5746
@CompilationFinal(dimensions = 1) //
5847
private final Attribute[] attributes;
5948

60-
private static final int FLAGS_READY = 0x1;
61-
private static final int FLAGS_HAS_JSR = 0x2;
62-
private static final int FLAGS_USES_MONITORS = 0x4;
63-
private static final int FLAGS_HAS_INDY = 0x8;
64-
@CompilationFinal byte flags;
65-
6649
public CodeAttribute(Symbol<Name> name, int maxStack, int maxLocals, byte[] code, ExceptionHandler[] exceptionHandlerEntries, Attribute[] attributes, int majorVersion) {
6750
super(name, null);
6851
this.maxStack = maxStack;
@@ -107,50 +90,6 @@ public StackMapTableAttribute getStackMapFrame() {
10790
return null;
10891
}
10992

110-
/**
111-
* Returns true if this method uses the JSR/RET bytecodes.
112-
*/
113-
public boolean hasJsr() {
114-
return (getFlags() & FLAGS_HAS_JSR) != 0;
115-
}
116-
117-
public boolean usesMonitors() {
118-
return (getFlags() & FLAGS_USES_MONITORS) != 0;
119-
}
120-
121-
public boolean usesIndy() {
122-
return (getFlags() & FLAGS_HAS_INDY) != 0;
123-
}
124-
125-
private byte getFlags() {
126-
byte localFlags = flags;
127-
if (localFlags == 0) {
128-
CompilerDirectives.transferToInterpreterAndInvalidate();
129-
flags = localFlags = computeFlags(originalCode);
130-
assert localFlags != 0;
131-
}
132-
return localFlags;
133-
}
134-
135-
private static byte computeFlags(byte[] code) {
136-
BytecodeStream bs = new BytecodeStream(code);
137-
int bci = 0;
138-
int flags = FLAGS_READY;
139-
while (bci < bs.endBCI()) {
140-
int opcode = bs.opcode(bci);
141-
switch (opcode) {
142-
case JSR, JSR_W, RET ->
143-
flags |= FLAGS_HAS_JSR;
144-
case MONITORENTER, MONITOREXIT ->
145-
flags |= FLAGS_USES_MONITORS;
146-
case INVOKEDYNAMIC ->
147-
flags |= FLAGS_HAS_INDY;
148-
}
149-
bci = bs.nextBCI(bci);
150-
}
151-
return (byte) flags;
152-
}
153-
15493
public LineNumberTableAttribute getLineNumberTableAttribute() {
15594
for (Attribute attr : attributes) {
15695
if (attr.getName() == ParserNames.LineNumberTable) {

espresso/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/descriptors/ByteSequence.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.nio.ByteBuffer;
2727
import java.util.Objects;
2828

29-
import com.oracle.truffle.api.CompilerDirectives;
3029
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
3130
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3231

@@ -66,7 +65,6 @@ public static ByteSequence wrap(final byte[] underlyingBytes) {
6665

6766
public static ByteSequence wrap(final byte[] underlyingBytes, int offset, int length) {
6867
if ((length > 0 && offset >= underlyingBytes.length) || offset + (long) length > underlyingBytes.length || length < 0 || offset < 0) {
69-
CompilerDirectives.transferToInterpreterAndInvalidate();
7068
throw new IndexOutOfBoundsException("ByteSequence illegal bounds: offset: " + offset + " length: " + length + " bytes length: " + underlyingBytes.length);
7169
}
7270
return new ByteSequence(underlyingBytes, hashOfRange(underlyingBytes, offset, length)) {

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/Method.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@
3939
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.ALOAD_0;
4040
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.GETFIELD;
4141
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.GETSTATIC;
42+
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.INVOKEDYNAMIC;
43+
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.JSR;
44+
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.JSR_W;
45+
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.MONITORENTER;
46+
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.MONITOREXIT;
4247
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.PUTFIELD;
4348
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.PUTSTATIC;
49+
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.RET;
4450
import static com.oracle.truffle.espresso.classfile.bytecode.Bytecodes.RETURN;
4551

4652
import java.io.PrintStream;
@@ -1407,6 +1413,11 @@ public CallTarget getContinuableCallTarget(MethodVersion mv, int bci) {
14071413
* new MethodVersion object.
14081414
*/
14091415
public final class MethodVersion implements MethodRef, ModifiersProvider {
1416+
private static final int CODE_FLAGS_READY = 0x1;
1417+
private static final int CODE_FLAGS_HAS_JSR = 0x2;
1418+
private static final int CODE_FLAGS_USES_MONITORS = 0x4;
1419+
private static final int CODE_FLAGS_HAS_INDY = 0x8;
1420+
14101421
private final ObjectKlass.KlassVersion klassVersion;
14111422
private final RuntimeConstantPool pool;
14121423
private final LinkedMethod linkedMethod;
@@ -1421,6 +1432,7 @@ public final class MethodVersion implements MethodRef, ModifiersProvider {
14211432
@CompilationFinal private int itableIndex = -1;
14221433

14231434
@CompilationFinal private byte refKind;
1435+
@CompilationFinal private byte codeFlags;
14241436

14251437
@CompilationFinal(dimensions = 1) //
14261438
private ObjectKlass[] checkedExceptions;
@@ -1953,15 +1965,52 @@ public String toString() {
19531965

19541966
public boolean usesMonitors() {
19551967
// Whether we need to use an additional frame slot for monitor unlock on kill.
1956-
return isSynchronized() || codeAttribute != null && codeAttribute.usesMonitors();
1968+
return isSynchronized() || (getCodeFlags() & CODE_FLAGS_USES_MONITORS) != 0;
19571969
}
19581970

1971+
/**
1972+
* Returns true if this method uses the JSR/RET bytecodes.
1973+
*/
19591974
public boolean hasJsr() {
1960-
return codeAttribute != null && codeAttribute.hasJsr();
1975+
return (getCodeFlags() & CODE_FLAGS_HAS_JSR) != 0;
19611976
}
19621977

19631978
public boolean usesIndy() {
1964-
return codeAttribute != null && codeAttribute.usesIndy();
1979+
return (getCodeFlags() & CODE_FLAGS_HAS_INDY) != 0;
1980+
}
1981+
1982+
private byte getCodeFlags() {
1983+
byte localFlags = codeFlags;
1984+
if (localFlags == 0) {
1985+
CompilerDirectives.transferToInterpreterAndInvalidate();
1986+
if (codeAttribute == null) {
1987+
localFlags = CODE_FLAGS_READY;
1988+
} else {
1989+
localFlags = computeFlags(codeAttribute.getOriginalCode());
1990+
}
1991+
assert localFlags != 0;
1992+
codeFlags = localFlags;
1993+
}
1994+
return localFlags;
1995+
}
1996+
1997+
private static byte computeFlags(byte[] code) {
1998+
BytecodeStream bs = new BytecodeStream(code);
1999+
int bci = 0;
2000+
int flags = CODE_FLAGS_READY;
2001+
while (bci < bs.endBCI()) {
2002+
int opcode = bs.opcode(bci);
2003+
switch (opcode) {
2004+
case JSR, JSR_W, RET ->
2005+
flags |= CODE_FLAGS_HAS_JSR;
2006+
case MONITORENTER, MONITOREXIT ->
2007+
flags |= CODE_FLAGS_USES_MONITORS;
2008+
case INVOKEDYNAMIC ->
2009+
flags |= CODE_FLAGS_HAS_INDY;
2010+
}
2011+
bci = bs.nextBCI(bci);
2012+
}
2013+
return (byte) flags;
19652014
}
19662015

19672016
public int getRefKind() {

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/meta/DynamicHubOffsets.java

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.lang.reflect.Field;
2828
import java.util.Arrays;
2929

30-
import jdk.graal.compiler.word.BarrieredAccess;
3130
import org.graalvm.nativeimage.AnnotationAccess;
3231
import org.graalvm.nativeimage.ImageSingletons;
3332
import org.graalvm.nativeimage.Platform;
@@ -41,54 +40,53 @@
4140
import com.oracle.svm.util.ReflectionUtil;
4241

4342
import jdk.graal.compiler.api.replacements.Fold;
43+
import jdk.graal.compiler.word.BarrieredAccess;
4444
import jdk.vm.ci.meta.MetaAccessProvider;
4545
import jdk.vm.ci.meta.ResolvedJavaField;
4646

4747
public class DynamicHubOffsets {
48+
private static final int UNINITIALIZED = -1;
4849
/* defining order in DynamicHub */
4950

5051
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
51-
private int nameOffset;
52+
private int nameOffset = UNINITIALIZED;
5253
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
53-
private int hubTypeOffset;
54+
private int hubTypeOffset = UNINITIALIZED;
5455
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
55-
private int referenceTypeOffset;
56+
private int referenceTypeOffset = UNINITIALIZED;
5657

5758
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
58-
private int layoutEncodingOffset;
59+
private int layoutEncodingOffset = UNINITIALIZED;
5960
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
60-
private int typeIDOffset;
61+
private int typeIDOffset = UNINITIALIZED;
6162
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
62-
private int typeIDDepthOffset;
63+
private int typeIDDepthOffset = UNINITIALIZED;
6364
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
64-
private int numClassTypesOffset;
65+
private int numClassTypesOffset = UNINITIALIZED;
6566

6667
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
67-
private int numInterfaceTypesOffset;
68+
private int numInterfaceTypesOffset = UNINITIALIZED;
6869
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
69-
private int openTypeWorldTypeCheckSlotsOffset;
70+
private int openTypeWorldTypeCheckSlotsOffset = UNINITIALIZED;
7071

7172
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
72-
private int monitorOffsetOffset;
73+
private int monitorOffsetOffset = UNINITIALIZED;
7374
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
74-
private int identityHashOffsetOffset;
75+
private int identityHashOffsetOffset = UNINITIALIZED;
7576

7677
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
77-
private int flagsOffset;
78+
private int flagsOffset = UNINITIALIZED;
7879

7980
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
80-
private int componentTypeOffset;
81+
private int componentTypeOffset = UNINITIALIZED;
8182

8283
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
83-
private int referenceMapIndexOffset;
84-
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
85-
private int layerIdOffset;
86-
84+
private int referenceMapIndexOffset = UNINITIALIZED;
8785
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
88-
private int companionOffset;
86+
private int layerIdOffset = UNINITIALIZED;
8987

9088
@UnknownPrimitiveField(availability = BuildPhaseProvider.ReadyForCompilation.class) //
91-
private int signatureOffset;
89+
private int companionOffset = UNINITIALIZED;
9290

9391
@Fold
9492
public static DynamicHubOffsets singleton() {
@@ -121,6 +119,18 @@ public void initializeOffsets(MetaAccessProvider metaAccess) {
121119
throw VMError.shouldNotReachHere(e);
122120
}
123121
}
122+
// Ensure the expected fields exist
123+
for (Field field : DynamicHubOffsets.class.getDeclaredFields()) {
124+
String name = field.getName();
125+
if (!name.endsWith("Offset")) {
126+
continue;
127+
}
128+
try {
129+
DynamicHub.class.getDeclaredField(name.substring(0, name.length() - "Offset".length()));
130+
} catch (NoSuchFieldException e) {
131+
throw VMError.shouldNotReachHere(e);
132+
}
133+
}
124134
}
125135

126136
public int getNameOffset() {
@@ -187,10 +197,6 @@ public int getCompanionOffset() {
187197
return companionOffset;
188198
}
189199

190-
public int getSignatureOffset() {
191-
return signatureOffset;
192-
}
193-
194200
public static void writeObject(DynamicHub hub, int offset, Object value) {
195201
if (offset < 0) {
196202
/* field removed by analysis */

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,6 @@ public static DynamicHub allocate(String name, DynamicHub superHub, DynamicHub c
516516

517517
writeObject(hub, dynamicHubOffsets.getCompanionOffset(), companion);
518518

519-
writeObject(hub, dynamicHubOffsets.getSignatureOffset(), signature);
520-
521519
FinalFieldBarrierNode.finalFieldBarrier(hub);
522520

523521
return hub;

0 commit comments

Comments
 (0)