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 Nov 1, 2023
2 parents 8b50348 + 9224944 commit bad7b12
Show file tree
Hide file tree
Showing 105 changed files with 942 additions and 688 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@

package jdk.graal.compiler.hotspot.amd64.test;

import static jdk.graal.compiler.core.common.spi.ForeignCallDescriptor.CallSideEffect.NO_SIDE_EFFECT;
import static jdk.graal.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.COMPUTES_REGISTERS_KILLED;
import static jdk.graal.compiler.lir.LIRInstruction.OperandFlag.REG;

import java.util.BitSet;

import jdk.graal.compiler.api.replacements.Snippet;
import jdk.graal.compiler.asm.amd64.AMD64Address;
import jdk.graal.compiler.asm.amd64.AMD64MacroAssembler;
Expand Down Expand Up @@ -75,8 +78,6 @@
import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.Value;

import java.util.BitSet;

public class StubAVXTest extends LIRTest {

@Before
Expand Down Expand Up @@ -239,9 +240,7 @@ public static int testStub() {
public void test() {
HotSpotProviders providers = (HotSpotProviders) getProviders();
HotSpotForeignCallsProviderImpl foreignCalls = providers.getForeignCalls();
HotSpotForeignCallLinkage linkage = foreignCalls.registerStubCall(TEST_STUB, HotSpotForeignCallDescriptor.Transition.LEAF_NO_VZERO,
HotSpotForeignCallDescriptor.Reexecutability.REEXECUTABLE,
COMPUTES_REGISTERS_KILLED);
HotSpotForeignCallLinkage linkage = foreignCalls.registerStubCall(TEST_STUB, HotSpotForeignCallDescriptor.Transition.LEAF_NO_VZERO, NO_SIDE_EFFECT, COMPUTES_REGISTERS_KILLED);
linkage.setCompiledStub(new TestStub(GraalCompilerTest.getInitialOptions(), providers, linkage));
runTest("testStub");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,29 @@
import static jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.BytecodeExceptionMode.CheckAll;

import java.io.IOException;
import java.lang.reflect.Array;
import java.util.EnumSet;

import jdk.graal.compiler.core.test.SubprocessTest;
import jdk.graal.compiler.hotspot.HotSpotBackend;
import jdk.graal.compiler.hotspot.meta.DefaultHotSpotLoweringProvider;
import jdk.graal.compiler.hotspot.stubs.CreateExceptionStub;
import jdk.graal.compiler.nodes.StructuredGraph;
import jdk.graal.compiler.nodes.extended.BytecodeExceptionNode;
import jdk.graal.compiler.nodes.extended.BytecodeExceptionNode.BytecodeExceptionKind;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.BytecodeExceptionMode;
import org.junit.Assume;
import org.junit.Test;

/**
* This test exercises the deoptimization in the {@link BytecodeExceptionMode} foreign call path.
* This test exercises the deoptimization in the {@link BytecodeExceptionNode} foreign call path.
*/
public class HotSpotDeoptExplicitExceptions extends SubprocessTest {

static class Fields {
Object a;
}

@Override
protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf) {
return super.editGraphBuilderConfiguration(conf).withBytecodeExceptionMode(CheckAll);
Expand All @@ -58,10 +67,69 @@ static String classCastSnippet(Object o) {
return (String) o;
}

static void aastoreSnippet(Object[] array, int index, Object value) {
array[index] = value;
}

static Object outOfBoundsSnippet(Object[] array, int index) {
return array[index];
}

static Object getFieldSnippet(Fields o) {
return o.a;
}

static void putFieldSnippet(Fields a, Object o) {
a.a = o;
}

static Object[] allocateSnippet(int length) {
return new Object[length];
}

static int arrayLengthSnippet(Object o) {
return Array.getLength(o);
}

static int intExactOverflowSnippet(int a, int b) {
return Math.addExact(a, b);
}

static long longExactOverflowSnippet(long a, long b) {
return Math.addExact(a, b);
}

/**
* These are the {@link BytecodeExceptionKind}s that are supported on HotSpot. Some kinds are
* only required for use in native image and any missing ones would result in lowering failures.
*/
private EnumSet<BytecodeExceptionKind> needsTesting = EnumSet.copyOf(DefaultHotSpotLoweringProvider.RuntimeCalls.runtimeCalls.keySet());

@Override
protected void checkHighTierGraph(StructuredGraph graph) {
for (BytecodeExceptionNode node : graph.getNodes().filter(BytecodeExceptionNode.class)) {
// Mark this kind as exercised by one of unit tests. The full set of tests will
// exercise some of these multiple times but we want to ensure they are exercised at
// least once.
needsTesting.remove(node.getExceptionKind());
}
super.checkHighTierGraph(graph);
}

void testBody() {
test("nullCheckSnippet", (Object) null);
test("divByZeroSnippet", 1, 0);
test("classCastSnippet", Boolean.TRUE);
test("aastoreSnippet", new String[1], 0, new Object());
test("outOfBoundsSnippet", new String[0], 0);
test("getFieldSnippet", (Object) null);
test("putFieldSnippet", null, null);
test("allocateSnippet", -1);
test("arrayLengthSnippet", "s");
test("intExactOverflowSnippet", Integer.MAX_VALUE, Integer.MAX_VALUE);
test("longExactOverflowSnippet", Long.MAX_VALUE, Long.MAX_VALUE);

assertTrue(needsTesting.isEmpty(), "missing tests for %s", needsTesting);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,43 @@
*/
public class ForeignCallDescriptor {

/**
* Constants specifying when a foreign call or stub call is re-executable.
*/
public enum CallSideEffect {
/**
* Denotes a call that cannot be re-executed. If an exception is raised, the call is
* deoptimized and the exception is passed on to be dispatched. If the call can throw an
* exception it needs to have a precise frame state.
*/
HAS_SIDE_EFFECT,

/**
* Denotes a call that can always be re-executed. If an exception is raised by the call it
* may be cleared, compiled code deoptimized and reexecuted. Since the call has no side
* effects it is assumed that the same exception will be thrown.
*/
NO_SIDE_EFFECT
}

protected final ForeignCallSignature signature;
protected final boolean isReexecutable;
protected final CallSideEffect callSideEffect;
protected final boolean canDeoptimize;
protected final boolean isGuaranteedSafepoint;
protected final LocationIdentity[] killedLocations;

public ForeignCallDescriptor(String name,
Class<?> resultType,
Class<?>[] argumentTypes,
boolean isReexecutable,
CallSideEffect callSideEffect,
LocationIdentity[] killedLocations,
boolean canDeoptimize,
boolean isGuaranteedSafepoint) {
this.isReexecutable = isReexecutable;
this.callSideEffect = callSideEffect;
this.killedLocations = killedLocations;
this.canDeoptimize = canDeoptimize;
this.isGuaranteedSafepoint = isGuaranteedSafepoint;
this.signature = new ForeignCallSignature(name, resultType, argumentTypes);

}

public ForeignCallSignature getSignature() {
Expand Down Expand Up @@ -95,8 +113,8 @@ public int hashCode() {
* Determines if a given foreign call is side-effect free. Deoptimization cannot return
* execution to a point before a foreign call that has a side effect.
*/
public boolean isReexecutable() {
return isReexecutable;
public CallSideEffect getSideEffect() {
return callSideEffect;
}

/**
Expand Down Expand Up @@ -125,7 +143,7 @@ public boolean isGuaranteedSafepoint() {
@Override
public String toString() {
return getClass().getSimpleName() + "{" + signature +
", isReexecutable=" + isReexecutable +
", callSideEffect=" + callSideEffect +
", canDeoptimize=" + canDeoptimize +
", isGuaranteedSafepoint=" + isGuaranteedSafepoint +
", killedLocations=" + Arrays.toString(killedLocations) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public LIRFrameState build(NodeWithState node, FrameState topState, LabelRef exc
current = current.outerFrameState();
} while (current != null);

assert verifyFrameState(node, topState);
verifyFrameState(node, topState);
BytecodeFrame frame = computeFrameForState(node, topState);

VirtualObject[] virtualObjectsArray = null;
Expand Down Expand Up @@ -252,10 +252,8 @@ protected JavaKind storageKind(JavaType type) {
*
* @param node the node using the state
* @param topState the state
* @return true if the validation succeeded
*/
protected boolean verifyFrameState(NodeWithState node, FrameState topState) {
return true;
protected void verifyFrameState(NodeWithState node, FrameState topState) {
}

protected BytecodeFrame computeFrameForState(NodeWithState node, FrameState state) {
Expand Down Expand Up @@ -294,7 +292,8 @@ protected BytecodeFrame computeFrameForState(NodeWithState node, FrameState stat
"not the same as the frame state method's code", ste);
}

return new BytecodeFrame(caller, state.getMethod(), state.bci, state.rethrowException(), state.duringCall(), values, slotKinds, numLocals, numStack, numLocks);
return new BytecodeFrame(caller, state.getMethod(), state.bci, state.getStackState().rethrowException, state.getStackState().duringCall, values, slotKinds, numLocals, numStack,
numLocks);
} catch (GraalError e) {
throw e.addContext("FrameState: ", state);
}
Expand Down
Loading

0 comments on commit bad7b12

Please sign in to comment.