Skip to content

Commit

Permalink
8247251: Assert (_pcs_length == 0 || last_pc()->pc_offset() < pc_offs…
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Rodriguez <never@openjdk.org>
Reviewed-by: never
  • Loading branch information
Vladimir Kozlov and Tom Rodriguez committed Sep 22, 2020
1 parent 3d5fea1 commit 24e12b3
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class LIRCompilerBackend {
public static <T extends CompilationResult> void emitBackEnd(StructuredGraph graph, Object stub, ResolvedJavaMethod installedCodeOwner, Backend backend, T compilationResult,
CompilationResultBuilderFactory factory, RegisterConfig registerConfig, LIRSuites lirSuites) {
DebugContext debug = graph.getDebug();
try (DebugContext.Scope s = debug.scope("BackEnd", graph.getLastSchedule()); DebugCloseable a = BackEnd.start(debug)) {
try (DebugContext.Scope s = debug.scope("BackEnd", graph, graph.getLastSchedule()); DebugCloseable a = BackEnd.start(debug)) {
LIRGenerationResult lirGen = null;
lirGen = emitLIR(backend, graph, stub, registerConfig, lirSuites);
try (DebugContext.Scope s2 = debug.scope("CodeGen", lirGen, lirGen.getLIR())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
import java.util.ArrayList;
import java.util.HashMap;

import org.graalvm.compiler.api.directives.GraalDirectives;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.replacements.arraycopy.ArrayCopySnippets;
import org.graalvm.compiler.nodes.DirectCallTargetNode;
import org.graalvm.compiler.nodes.Invoke;
import org.graalvm.compiler.nodes.LoweredCallTargetNode;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.replacements.arraycopy.ArrayCopySnippets;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -370,4 +371,22 @@ public void testObjectArrayExceptions() {
test("objectArraycopyCatchArrayStoreException", longSource, 4, integerDest, 2, 3);
test("objectArraycopyCatchArrayIndexException", new Integer[128], 0, new Integer[128], Integer.MAX_VALUE, 1);
}

@Test
public void testArraycopyDeoptWithSideEffect() {
ArgSupplier s = () -> new int[4];
int[] b = new int[]{1, 1, 1, 1};
int[] c = new int[]{2, 2, 2, 2};
test("arraycopyAndDeopt", s, b, c);
}

public static int[] arraycopyAndDeopt(int[] a, int[] b, int[] c) {
if (a[0] == 0) {
System.arraycopy(b, 0, a, 0, b.length);
GraalDirectives.deoptimize();
} else {
System.arraycopy(c, 0, a, 0, b.length);
}
return a;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.graalvm.compiler.debug.DebugDumpScope;
import org.graalvm.compiler.debug.DebugHandlersFactory;
import org.graalvm.compiler.debug.TimerKey;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.options.OptionKey;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
Expand Down Expand Up @@ -165,15 +166,17 @@ protected HotSpotCompilationRequestResult performCompilation(DebugContext debug)

final CompilationPrinter printer = CompilationPrinter.begin(debug.getOptions(), compilationId, method, entryBCI);

StructuredGraph graph;
try (DebugContext.Scope s = debug.scope("Compiling", new DebugDumpScope(getIdString(), true))) {
result = compiler.compile(method, entryBCI, useProfilingInfo, shouldRetainLocalVariables, compilationId, debug);
graph = compiler.createGraph(method, entryBCI, useProfilingInfo, compilationId, debug.getOptions(), debug);
result = compiler.compile(graph, method, entryBCI, useProfilingInfo, shouldRetainLocalVariables, compilationId, debug);
} catch (Throwable e) {
throw debug.handle(e);
}

if (result != null) {
try (DebugCloseable b = CodeInstallationTime.start(debug)) {
installMethod(debug, result);
installMethod(debug, graph, result);
}
// Installation is included in compilation time and memory usage reported by printer
printer.finish(result);
Expand Down Expand Up @@ -352,12 +355,12 @@ public HotSpotCompilationRequestResult runCompilation(DebugContext debug) {
}

@SuppressWarnings("try")
private void installMethod(DebugContext debug, final CompilationResult compResult) {
private void installMethod(DebugContext debug, StructuredGraph graph, final CompilationResult compResult) {
final CodeCacheProvider codeCache = jvmciRuntime.getHostJVMCIBackend().getCodeCache();
HotSpotBackend backend = compiler.getGraalRuntime().getHostBackend();
installedCode = null;
Object[] context = {new DebugDumpScope(getIdString(), true), codeCache, getMethod(), compResult};
try (DebugContext.Scope s = debug.scope("CodeInstall", context)) {
try (DebugContext.Scope s = debug.scope("CodeInstall", context, graph)) {
HotSpotCompilationRequest request = getRequest();
installedCode = (HotSpotInstalledCode) backend.createInstalledCode(debug,
request.getMethod(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ public CompilationResult compileHelper(CompilationResultBuilderFactory crbf, Com
return result;
}

public CompilationResult compile(ResolvedJavaMethod method,
public CompilationResult compile(StructuredGraph graph,
ResolvedJavaMethod method,
int entryBCI,
boolean useProfilingInfo,
boolean shouldRetainLocalVariables,
CompilationIdentifier compilationId,
DebugContext debug) {
StructuredGraph graph = createGraph(method, entryBCI, useProfilingInfo, compilationId, debug.getOptions(), debug);
CompilationResult result = new CompilationResult(compilationId);
return compileHelper(CompilationResultBuilderFactory.Default, result, graph, method, entryBCI, useProfilingInfo, shouldRetainLocalVariables, debug.getOptions());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,20 @@ protected EconomicMap<LoopExitNode, NodeStateAssignment> processLoop(LoopBeginNo
afterCount++;
}
}
NodeStateAssignment selected = null;
if (invalidCount > 0) {
stateMapping.put(loop, NodeStateAssignment.INVALID);
selected = NodeStateAssignment.INVALID;
} else {
if (afterCount > 0) {
stateMapping.put(loop, NodeStateAssignment.AFTER_BCI);
selected = NodeStateAssignment.AFTER_BCI;
} else {
stateMapping.put(loop, NodeStateAssignment.BEFORE_BCI);
selected = NodeStateAssignment.BEFORE_BCI;
}
}
stateMapping.put(loop, selected);
if (selected != initialState) {
for (LoopExitNode exit : loop.loopExits()) {
loopInfo.exitStates.put(exit, selected);
}
}
return loopInfo.exitStates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.graalvm.compiler.nodes.calc.IntegerConvertNode;
import org.graalvm.compiler.nodes.calc.LeftShiftNode;
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
import org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint;
import org.graalvm.compiler.nodes.memory.MemoryAccess;
import org.graalvm.compiler.nodes.memory.MemoryKill;
import org.graalvm.compiler.nodes.memory.SingleMemoryKill;
Expand All @@ -67,7 +68,7 @@
import jdk.vm.ci.meta.PrimitiveConstant;

@NodeInfo(allowedUsageTypes = {Memory}, cycles = CYCLES_UNKNOWN, size = SIZE_UNKNOWN)
public final class ArrayCopyCallNode extends FixedWithNextNode implements Lowerable, SingleMemoryKill, MemoryAccess, Canonicalizable {
public final class ArrayCopyCallNode extends AbstractMemoryCheckpoint implements Lowerable, SingleMemoryKill, MemoryAccess, Canonicalizable {

public static final NodeClass<ArrayCopyCallNode> TYPE = NodeClass.create(ArrayCopyCallNode.class);
@Input protected ValueNode src;
Expand Down Expand Up @@ -214,6 +215,11 @@ public LocationIdentity getKilledLocationIdentity() {
return killedLocationIdentity;
}

@Override
public boolean hasSideEffect() {
return !killedLocationIdentity.isInit();
}

@NodeIntrinsic(hasSideEffect = true)
private static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length, @ConstantNodeParameter JavaKind elementKind, @ConstantNodeParameter boolean aligned,
@ConstantNodeParameter boolean disjoint, @ConstantNodeParameter boolean uninitialized, @ConstantNodeParameter int heapWordSize);
Expand Down

1 comment on commit 24e12b3

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 24e12b3 Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.