Skip to content

Commit 24e12b3

Browse files
Vladimir KozlovTom Rodriguez
Vladimir Kozlov
and
Tom Rodriguez
committed
8247251: Assert (_pcs_length == 0 || last_pc()->pc_offset() < pc_offs…
Co-authored-by: Tom Rodriguez <never@openjdk.org> Reviewed-by: never
1 parent 3d5fea1 commit 24e12b3

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/LIRCompilerBackend.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class LIRCompilerBackend {
7979
public static <T extends CompilationResult> void emitBackEnd(StructuredGraph graph, Object stub, ResolvedJavaMethod installedCodeOwner, Backend backend, T compilationResult,
8080
CompilationResultBuilderFactory factory, RegisterConfig registerConfig, LIRSuites lirSuites) {
8181
DebugContext debug = graph.getDebug();
82-
try (DebugContext.Scope s = debug.scope("BackEnd", graph.getLastSchedule()); DebugCloseable a = BackEnd.start(debug)) {
82+
try (DebugContext.Scope s = debug.scope("BackEnd", graph, graph.getLastSchedule()); DebugCloseable a = BackEnd.start(debug)) {
8383
LIRGenerationResult lirGen = null;
8484
lirGen = emitLIR(backend, graph, stub, registerConfig, lirSuites);
8585
try (DebugContext.Scope s2 = debug.scope("CodeGen", lirGen, lirGen.getLIR())) {

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.test/src/org/graalvm/compiler/hotspot/test/ArrayCopyIntrinsificationTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
import java.util.ArrayList;
2929
import java.util.HashMap;
3030

31+
import org.graalvm.compiler.api.directives.GraalDirectives;
3132
import org.graalvm.compiler.core.test.GraalCompilerTest;
3233
import org.graalvm.compiler.graph.Node;
33-
import org.graalvm.compiler.replacements.arraycopy.ArrayCopySnippets;
3434
import org.graalvm.compiler.nodes.DirectCallTargetNode;
3535
import org.graalvm.compiler.nodes.Invoke;
3636
import org.graalvm.compiler.nodes.LoweredCallTargetNode;
3737
import org.graalvm.compiler.nodes.StructuredGraph;
3838
import org.graalvm.compiler.options.OptionValues;
39+
import org.graalvm.compiler.replacements.arraycopy.ArrayCopySnippets;
3940
import org.junit.Assert;
4041
import org.junit.Test;
4142

@@ -370,4 +371,22 @@ public void testObjectArrayExceptions() {
370371
test("objectArraycopyCatchArrayStoreException", longSource, 4, integerDest, 2, 3);
371372
test("objectArraycopyCatchArrayIndexException", new Integer[128], 0, new Integer[128], Integer.MAX_VALUE, 1);
372373
}
374+
375+
@Test
376+
public void testArraycopyDeoptWithSideEffect() {
377+
ArgSupplier s = () -> new int[4];
378+
int[] b = new int[]{1, 1, 1, 1};
379+
int[] c = new int[]{2, 2, 2, 2};
380+
test("arraycopyAndDeopt", s, b, c);
381+
}
382+
383+
public static int[] arraycopyAndDeopt(int[] a, int[] b, int[] c) {
384+
if (a[0] == 0) {
385+
System.arraycopy(b, 0, a, 0, b.length);
386+
GraalDirectives.deoptimize();
387+
} else {
388+
System.arraycopy(c, 0, a, 0, b.length);
389+
}
390+
return a;
391+
}
373392
}

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/CompilationTask.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.graalvm.compiler.debug.DebugDumpScope;
4848
import org.graalvm.compiler.debug.DebugHandlersFactory;
4949
import org.graalvm.compiler.debug.TimerKey;
50+
import org.graalvm.compiler.nodes.StructuredGraph;
5051
import org.graalvm.compiler.options.OptionKey;
5152
import org.graalvm.compiler.options.OptionValues;
5253
import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
@@ -165,15 +166,17 @@ protected HotSpotCompilationRequestResult performCompilation(DebugContext debug)
165166

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

169+
StructuredGraph graph;
168170
try (DebugContext.Scope s = debug.scope("Compiling", new DebugDumpScope(getIdString(), true))) {
169-
result = compiler.compile(method, entryBCI, useProfilingInfo, shouldRetainLocalVariables, compilationId, debug);
171+
graph = compiler.createGraph(method, entryBCI, useProfilingInfo, compilationId, debug.getOptions(), debug);
172+
result = compiler.compile(graph, method, entryBCI, useProfilingInfo, shouldRetainLocalVariables, compilationId, debug);
170173
} catch (Throwable e) {
171174
throw debug.handle(e);
172175
}
173176

174177
if (result != null) {
175178
try (DebugCloseable b = CodeInstallationTime.start(debug)) {
176-
installMethod(debug, result);
179+
installMethod(debug, graph, result);
177180
}
178181
// Installation is included in compilation time and memory usage reported by printer
179182
printer.finish(result);
@@ -352,12 +355,12 @@ public HotSpotCompilationRequestResult runCompilation(DebugContext debug) {
352355
}
353356

354357
@SuppressWarnings("try")
355-
private void installMethod(DebugContext debug, final CompilationResult compResult) {
358+
private void installMethod(DebugContext debug, StructuredGraph graph, final CompilationResult compResult) {
356359
final CodeCacheProvider codeCache = jvmciRuntime.getHostJVMCIBackend().getCodeCache();
357360
HotSpotBackend backend = compiler.getGraalRuntime().getHostBackend();
358361
installedCode = null;
359362
Object[] context = {new DebugDumpScope(getIdString(), true), codeCache, getMethod(), compResult};
360-
try (DebugContext.Scope s = debug.scope("CodeInstall", context)) {
363+
try (DebugContext.Scope s = debug.scope("CodeInstall", context, graph)) {
361364
HotSpotCompilationRequest request = getRequest();
362365
installedCode = (HotSpotInstalledCode) backend.createInstalledCode(debug,
363366
request.getMethod(),

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotGraalCompiler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ public CompilationResult compileHelper(CompilationResultBuilderFactory crbf, Com
235235
return result;
236236
}
237237

238-
public CompilationResult compile(ResolvedJavaMethod method,
238+
public CompilationResult compile(StructuredGraph graph,
239+
ResolvedJavaMethod method,
239240
int entryBCI,
240241
boolean useProfilingInfo,
241242
boolean shouldRetainLocalVariables,
242243
CompilationIdentifier compilationId,
243244
DebugContext debug) {
244-
StructuredGraph graph = createGraph(method, entryBCI, useProfilingInfo, compilationId, debug.getOptions(), debug);
245245
CompilationResult result = new CompilationResult(compilationId);
246246
return compileHelper(CompilationResultBuilderFactory.Default, result, graph, method, entryBCI, useProfilingInfo, shouldRetainLocalVariables, debug.getOptions());
247247
}

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/SnippetFrameStateAssignment.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,20 @@ protected EconomicMap<LoopExitNode, NodeStateAssignment> processLoop(LoopBeginNo
216216
afterCount++;
217217
}
218218
}
219+
NodeStateAssignment selected = null;
219220
if (invalidCount > 0) {
220-
stateMapping.put(loop, NodeStateAssignment.INVALID);
221+
selected = NodeStateAssignment.INVALID;
221222
} else {
222223
if (afterCount > 0) {
223-
stateMapping.put(loop, NodeStateAssignment.AFTER_BCI);
224+
selected = NodeStateAssignment.AFTER_BCI;
224225
} else {
225-
stateMapping.put(loop, NodeStateAssignment.BEFORE_BCI);
226+
selected = NodeStateAssignment.BEFORE_BCI;
227+
}
228+
}
229+
stateMapping.put(loop, selected);
230+
if (selected != initialState) {
231+
for (LoopExitNode exit : loop.loopExits()) {
232+
loopInfo.exitStates.put(exit, selected);
226233
}
227234
}
228235
return loopInfo.exitStates;

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/arraycopy/ArrayCopyCallNode.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.graalvm.compiler.nodes.calc.IntegerConvertNode;
5252
import org.graalvm.compiler.nodes.calc.LeftShiftNode;
5353
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
54+
import org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint;
5455
import org.graalvm.compiler.nodes.memory.MemoryAccess;
5556
import org.graalvm.compiler.nodes.memory.MemoryKill;
5657
import org.graalvm.compiler.nodes.memory.SingleMemoryKill;
@@ -67,7 +68,7 @@
6768
import jdk.vm.ci.meta.PrimitiveConstant;
6869

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

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

218+
@Override
219+
public boolean hasSideEffect() {
220+
return !killedLocationIdentity.isInit();
221+
}
222+
217223
@NodeIntrinsic(hasSideEffect = true)
218224
private static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length, @ConstantNodeParameter JavaKind elementKind, @ConstantNodeParameter boolean aligned,
219225
@ConstantNodeParameter boolean disjoint, @ConstantNodeParameter boolean uninitialized, @ConstantNodeParameter int heapWordSize);

0 commit comments

Comments
 (0)