Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gluon-bot committed Sep 2, 2023
2 parents 27867e2 + 4a1c182 commit 3f5fd41
Show file tree
Hide file tree
Showing 254 changed files with 578 additions and 599 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,39 @@ public static long unsafeSnippet23(long l1, short s1, float f1, byte[][] box, bo
return UNSAFE.getLong(t, getUnsafeByteArrayOffset(0));
}

public static long unsafeSnippet24(long l1, boolean c) {
byte[] t = new byte[8];
UNSAFE.putLong(t, getUnsafeByteArrayOffset(0), l1);
t[7] = (byte) 0xff;
sideEffect();
if (c) {
GraalDirectives.deoptimize();
}
return UNSAFE.getLong(t, getUnsafeByteArrayOffset(0));
}

public static long unsafeSnippet25(long l1, boolean c) {
byte[] t = new byte[8];
UNSAFE.putLong(t, getUnsafeByteArrayOffset(0), l1);
t[0] = (byte) 0xff;
sideEffect();
if (c) {
GraalDirectives.deoptimize();
}
return UNSAFE.getLong(t, getUnsafeByteArrayOffset(0));
}

public static long unsafeSnippet26(long l1, boolean c) {
byte[] t = new byte[8];
UNSAFE.putLong(t, getUnsafeByteArrayOffset(0), l1);
UNSAFE.putByte(t, getUnsafeByteArrayOffset(3), (byte) 0xff);
sideEffect();
if (c) {
GraalDirectives.deoptimize();
}
return UNSAFE.getLong(t, getUnsafeByteArrayOffset(0));
}

@Test
public void testUnsafePEA01() {
performTest("unsafeSnippet1", false, true, 1.0);
Expand Down Expand Up @@ -477,6 +510,21 @@ public void testUnsafePEA23() {
performTest("unsafeSnippet23", false, false, 0x0102030405060708L, (short) 0x0102, Float.intBitsToFloat(0x01020304), new byte[1][]);
}

@Test
public void testUnsafePEA24() {
performTest("unsafeSnippet24", false, false, 0x0102030405060708L);
}

@Test
public void testUnsafePEA25() {
performTest("unsafeSnippet25", false, false, 0x0102030405060708L);
}

@Test
public void testUnsafePEA26() {
performTest("unsafeSnippet26", false, false, 0x0102030405060708L);
}

private void performTest(String snippet, boolean shouldEscapeRead, boolean shouldEscapeWrite, Object... args) {
Object[] boolArgs = Arrays.copyOf(args, args.length + 1);
for (boolean b1 : FT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ private IntegerStamp(int bits, long lowerBound, long upperBound, long mustBeSet,
}

private boolean checkInvariants() {
final int allowedBitsMask = 1 | 8 | 16 | 32 | 64;
assert (getBits() & allowedBitsMask) == getBits() && CodeUtil.isPowerOf2(getBits()) : "unexpected bit size: " + getBits();
assert lowerBound >= CodeUtil.minValue(getBits()) : this;
assert upperBound <= CodeUtil.maxValue(getBits()) : this;
assert (mustBeSet & CodeUtil.mask(getBits())) == mustBeSet : this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ protected void updateStub(Stub stub, HotSpotLIRGenerationResult gen, FrameMap fr
while (cursor.advance()) {
SaveRegistersOp save = cursor.getValue();
save.remove(destroyedRegisters);
if (cursor.getKey() != LIRFrameState.NO_CALLEE_SAVE_INFO) {
if (cursor.getKey().hasDebugInfo()) {
cursor.getKey().debugInfo().setCalleeSaveInfo(save.getRegisterSaveLayout(frameMap));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state,
HotSpotLIRGenerationResult generationResult = getResult();
LIRFrameState key = currentRuntimeCallInfo;
if (key == null) {
key = LIRFrameState.NO_CALLEE_SAVE_INFO;
key = LIRFrameState.noCalleeSaveInfo();
}
assert !generationResult.getCalleeSaveInfo().containsKey(key);
generationResult.getCalleeSaveInfo().put(key, save);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state,
HotSpotLIRGenerationResult generationResult = getResult();
LIRFrameState key = currentRuntimeCallInfo;
if (key == null) {
key = LIRFrameState.NO_CALLEE_SAVE_INFO;
key = LIRFrameState.noCalleeSaveInfo();
}
assert !generationResult.getCalleeSaveInfo().containsKey(key);
generationResult.getCalleeSaveInfo().put(key, save);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
*/
public class LIRFrameState {

// A special marker denoting no callee save info.
public static final LIRFrameState NO_CALLEE_SAVE_INFO = new LIRFrameState(null, null, null, false);
// This is a sentinel value that's only suitable for use as a key.
public static LIRFrameState noCalleeSaveInfo() {
return new LIRFrameState(null, null, null, false);
}

public final BytecodeFrame topFrame;
private final VirtualObject[] virtualObjects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_8;

import org.graalvm.compiler.core.common.type.StampFactory;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.nodeinfo.InputType;
Expand Down Expand Up @@ -117,8 +118,12 @@ public void virtualize(VirtualizerTool tool) {
ResolvedJavaType componentType = virtual.type().getComponentType();
if (elementKind.isPrimitive() || StampTool.isPointerAlwaysNull(value) || componentType.isJavaLangObject() ||
(StampTool.typeReferenceOrNull(value) != null && componentType.isAssignableFrom(StampTool.typeOrNull(value)))) {
tool.setVirtualEntry(virtual, idx, value());
tool.delete();
boolean success = tool.setVirtualEntry(virtual, idx, value(), elementKind(), 0);
if (success) {
tool.delete();
} else {
GraalError.guarantee(virtual.isVirtualByteArray(tool.getMetaAccessExtensionProvider()), "only stores to virtual byte arrays can fail: %s", virtual);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
import org.graalvm.compiler.nodes.spi.CoreProviders;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.phases.BasePhase;
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
import org.graalvm.compiler.phases.common.DeadCodeEliminationPhase;
Expand Down Expand Up @@ -110,7 +111,7 @@ public boolean runAnalysis(StructuredGraph graph, CoreProvidersT context) {
}
boolean postTriggered = false;
try (DebugContext.Scope scheduleScope = debug.scope("EffectsPhaseWithSchedule", schedule)) {
Closure<?> closure = createEffectsClosure(context, schedule, cfg);
Closure<?> closure = createEffectsClosure(context, schedule, cfg, graph.getOptions());
ReentrantBlockIterator.apply(closure, cfg.getStartBlock());

if (closure.needsApplyEffects()) {
Expand Down Expand Up @@ -150,5 +151,5 @@ protected void postIteration(final StructuredGraph graph, final CoreProvidersT c
}
}

protected abstract Closure<?> createEffectsClosure(CoreProvidersT context, ScheduleResult schedule, ControlFlowGraph cfg);
protected abstract Closure<?> createEffectsClosure(CoreProvidersT context, ScheduleResult schedule, ControlFlowGraph cfg, OptionValues options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected void run(StructuredGraph graph, CoreProviders context) {
}

@Override
protected Closure<?> createEffectsClosure(CoreProviders context, ScheduleResult schedule, ControlFlowGraph cfg) {
protected Closure<?> createEffectsClosure(CoreProviders context, ScheduleResult schedule, ControlFlowGraph cfg, OptionValues options) {
for (VirtualObjectNode virtual : cfg.graph.getNodes(VirtualObjectNode.TYPE)) {
virtual.resetObjectId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult;
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
import org.graalvm.compiler.nodes.spi.CoreProviders;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.phases.common.CanonicalizerPhase;
import org.graalvm.compiler.phases.graph.ReentrantBlockIterator;
import org.graalvm.word.LocationIdentity;
Expand Down Expand Up @@ -93,7 +94,7 @@ protected void run(StructuredGraph graph, CoreProviders context) {
}

@Override
protected Closure<?> createEffectsClosure(CoreProviders context, ScheduleResult schedule, ControlFlowGraph cfg) {
protected Closure<?> createEffectsClosure(CoreProviders context, ScheduleResult schedule, ControlFlowGraph cfg, OptionValues options) {
assert schedule == null;
return new ReadEliminationClosure(cfg, considerGuards);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.List;

import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeSourcePosition;
import org.graalvm.compiler.nodes.ConstantNode;
Expand Down Expand Up @@ -120,6 +121,19 @@ public boolean setVirtualEntry(VirtualObjectNode virtual, int index, ValueNode v
ValueNode oldValue = getEntry(virtual, index);
boolean oldIsIllegal = oldValue.isIllegalConstant();
boolean canVirtualize = entryKind == accessKind || (entryKind == accessKind.getStackKind() && virtual instanceof VirtualInstanceNode);
if (canVirtualize && virtual.isVirtualByteArrayAccess(getMetaAccessExtensionProvider(), accessKind)) {
GraalError.guarantee(entryKind == JavaKind.Byte && accessKind == JavaKind.Byte, "expected byte kinds by canVirtualize condition");
/*
* Special case: An explicit byte write into a virtual byte array. We cannot virtualize
* this if it would overwrite part of a larger value. That is the case if the old value
* is either larger than a byte (indicating the first byte of the value) or illegal
* (indicating one of the following bytes of a preceding value).
*/
if (theAccessKind == JavaKind.Byte && // explicitly specified by the caller
(oldIsIllegal || ((VirtualArrayNode) virtual).byteArrayEntryByteCount(index, this) > 1)) {
canVirtualize = false;
}
}
if (!canVirtualize) {
assert entryKind != JavaKind.Long || newValue != null;
if (entryKind == JavaKind.Long && oldValue.getStackKind() == newValue.getStackKind() && oldValue.getStackKind().isPrimitive()) {
Expand Down Expand Up @@ -190,8 +204,11 @@ public boolean setVirtualEntry(VirtualObjectNode virtual, int index, ValueNode v
}
return true;
}
// Should only occur if there are mismatches between the entry and access kind
assert entryKind != accessKind;
/*
* Should only occur if there are mismatches between the entry and access kind, or we are
* clobbering a byte in a larger value.
*/
assert entryKind != accessKind || entryKind == JavaKind.Byte : "setVirtualEntry failed on entry kind " + entryKind + ", access kind " + accessKind;
return false;
}

Expand Down
2 changes: 0 additions & 2 deletions espresso/mx.espresso/mx_espresso.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ def _espresso_standalone_command(args, use_optimized_runtime=False, with_sulong=
+ mx.get_runtime_jvm_args(distributions, jdk=mx.get_jdk())
# We are not adding the truffle runtime
+ ['-Dpolyglot.engine.WarnInterpreterOnly=false']
# Workaround StaticShape generating classes in the unnamed module (GR-48132)
+ ['--add-exports=org.graalvm.espresso/com.oracle.truffle.espresso.runtime=ALL-UNNAMED']
+ [mx.distribution('ESPRESSO_LAUNCHER').mainClass] + args
)

Expand Down
15 changes: 3 additions & 12 deletions espresso/mx.espresso/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,6 @@
{
"name": "sulong",
"subdir": True,
"os_arch": {
"windows": {
"<others>": {
"ignore": True,
},
},
"<others>": {
"<others>": {
"ignore": False,
}
}
}
},
{
"name" : "java-benchmarks",
Expand Down Expand Up @@ -344,6 +332,9 @@
"ESPRESSO": {
"moduleInfo" : {
"name" : "org.graalvm.espresso",
"exports": [
"com.oracle.truffle.espresso.runtime.staticobject", # Workaround GR-48132
]
},
"description" : "Core module of the Java on Truffle (aka Espresso): a Java bytecode interpreter",
"subDir": "src",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public abstract class EspressoProcessor extends BaseProcessor {
* import com.oracle.truffle.espresso.substitutions.Collect;
*
* import com.oracle.truffle.espresso.substitutions.JavaSubstitution;
* import com.oracle.truffle.espresso.runtime.StaticObject;
* import com.oracle.truffle.espresso.runtime.staticobject.StaticObject;
* import com.oracle.truffle.espresso.substitutions.Target_java_lang_invoke_MethodHandleNatives.Resolve;
*
* /**
Expand Down Expand Up @@ -229,7 +229,7 @@ protected ClassBuilder generateAdditionalFactoryMethods(ClassBuilder factoryBuil
private static final String SUBSTITUTION_PROFILER = "com.oracle.truffle.espresso.substitutions.SubstitutionProfiler";

TypeElement staticObject;
private static final String STATIC_OBJECT = "com.oracle.truffle.espresso.runtime.StaticObject";
protected static final String STATIC_OBJECT = "com.oracle.truffle.espresso.runtime.staticobject.StaticObject";

TypeElement javaType;
private static final String JAVA_TYPE = "com.oracle.truffle.espresso.substitutions.JavaType";
Expand Down Expand Up @@ -258,11 +258,11 @@ protected ClassBuilder generateAdditionalFactoryMethods(ClassBuilder factoryBuil
static final String STATIC_OBJECT_NULL = "StaticObject.NULL";

static final String IMPORT_INTEROP_LIBRARY = "com.oracle.truffle.api.interop.InteropLibrary";
static final String IMPORT_STATIC_OBJECT = "com.oracle.truffle.espresso.runtime.StaticObject";
static final String IMPORT_STATIC_OBJECT = STATIC_OBJECT;
static final String IMPORT_TRUFFLE_OBJECT = "com.oracle.truffle.api.interop.TruffleObject";
static final String IMPORT_ESPRESSO_LANGUAGE = "com.oracle.truffle.espresso.EspressoLanguage";
static final String IMPORT_ESPRESSO_LANGUAGE = ESPRESSO_LANGUAGE;
static final String IMPORT_META = "com.oracle.truffle.espresso.meta.Meta";
static final String IMPORT_ESPRESSO_CONTEXT = "com.oracle.truffle.espresso.runtime.EspressoContext";
static final String IMPORT_ESPRESSO_CONTEXT = ESPRESSO_CONTEXT;
static final String IMPORT_PROFILE = "com.oracle.truffle.espresso.substitutions.SubstitutionProfiler";
static final String IMPORT_COLLECT = "com.oracle.truffle.espresso.substitutions.Collect";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,13 @@ public final class SubstitutionProcessor extends EspressoProcessor {
// InlinedMethodPredicate.class
private TypeElement noPredicate;

// StaticObject
private TypeElement staticObjectElement;

// region Various String constants.

private static final String SUBSTITUTION_PACKAGE = "com.oracle.truffle.espresso.substitutions";

private static final String ESPRESSO_SUBSTITUTIONS = SUBSTITUTION_PACKAGE + "." + "EspressoSubstitutions";
private static final String SUBSTITUTION = SUBSTITUTION_PACKAGE + "." + "Substitution";
private static final String INLINE_IN_BYTECODE = SUBSTITUTION_PACKAGE + "." + "InlineInBytecode";
private static final String STATIC_OBJECT = "com.oracle.truffle.espresso.runtime.StaticObject";
private static final String JAVA_TYPE = SUBSTITUTION_PACKAGE + "." + "JavaType";
private static final String NO_PROVIDER = SUBSTITUTION_PACKAGE + "." + "SubstitutionNamesProvider" + "." + "NoProvider";
private static final String NO_FILTER = SUBSTITUTION_PACKAGE + "." + "VersionFilter" + "." + "NoFilter";
Expand Down Expand Up @@ -184,7 +180,7 @@ private void checkParameterOrReturnType(String headerMessage, TypeMirror typeMir
}
} else if (typeMirror.getKind() != TypeKind.VOID) {
// Reference type.
if (!processingEnv.getTypeUtils().isSameType(typeMirror, staticObjectElement.asType())) {
if (!processingEnv.getTypeUtils().isSameType(typeMirror, staticObject.asType())) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
headerMessage + " is not of type StaticObject", element);
}
Expand Down Expand Up @@ -409,7 +405,7 @@ private List<String> getGuestTypes(ExecutableElement inner, boolean hasReceiver)
} else {
// @JavaType annotation not found -> primitive or j.l.Object
// All StaticObject(s) parameters must be annotated with @JavaType.
if (!isReceiver && processingEnv.getTypeUtils().isSameType(parameter.asType(), staticObjectElement.asType())) {
if (!isReceiver && processingEnv.getTypeUtils().isSameType(parameter.asType(), staticObject.asType())) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "non-receiver StaticObject parameters require the @JavaType annotation", parameter);
}
String arg = getInternalName(parameter.asType().toString());
Expand Down Expand Up @@ -565,7 +561,6 @@ void processImpl(RoundEnvironment env) {
// Set up the different annotations, along with their values, that we will need.
this.espressoSubstitutions = getTypeElement(ESPRESSO_SUBSTITUTIONS);
this.substitutionAnnotation = getTypeElement(SUBSTITUTION);
this.staticObjectElement = getTypeElement(STATIC_OBJECT);
this.inlineInBytecodeAnnotation = getTypeElement(INLINE_IN_BYTECODE);
this.javaType = getTypeElement(JAVA_TYPE);
this.noProvider = getTypeElement(NO_PROVIDER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# add-exports workaround for StaticShape generating classes in the unnamed module (GR-48132)
Args = --initialize-at-build-time=com.oracle.truffle.espresso \
--features=com.oracle.truffle.espresso.ref.FinalizationFeature \
--add-exports=org.graalvm.espresso/com.oracle.truffle.espresso.runtime=ALL-UNNAMED \
--add-exports=org.graalvm.espresso/com.oracle.truffle.espresso.impl=ALL-UNNAMED \
-H:MaxRuntimeCompileMethods=7000
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import com.oracle.truffle.espresso.nodes.commands.AddPathToBindingsNode;
import com.oracle.truffle.espresso.runtime.EspressoContext;
import com.oracle.truffle.espresso.runtime.EspressoException;
import com.oracle.truffle.espresso.runtime.StaticObject;
import com.oracle.truffle.espresso.runtime.staticobject.StaticObject;
import com.oracle.truffle.espresso.vm.InterpreterToVM;

/**
Expand Down
Loading

0 comments on commit 3f5fd41

Please sign in to comment.