8294676: [JVMCI] InstalledCode.deoptimize(false) should not touch address field

Reviewed-by: never
This commit is contained in:
Doug Simon 2022-10-01 11:20:46 +00:00
parent fd594302f7
commit b8b9b97a1a
7 changed files with 98 additions and 73 deletions

View file

@ -1547,14 +1547,18 @@ void JVMCIEnv::invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimize, JV
if (!deoptimize) { if (!deoptimize) {
// Prevent future executions of the nmethod but let current executions complete. // Prevent future executions of the nmethod but let current executions complete.
nm->make_not_entrant(); nm->make_not_entrant();
} else {
// We want the nmethod to be deoptimized immediately.
Deoptimization::deoptimize_all_marked(nm);
}
// A HotSpotNmethod instance can only reference a single nmethod // Do not clear the address field here as the Java code may still
// during its lifetime so simply clear it here. // want to later call this method with deoptimize == true. That requires
set_InstalledCode_address(mirror, 0); // the address field to still be pointing at the nmethod.
} else {
// Deoptimize the nmethod immediately.
Deoptimization::deoptimize_all_marked(nm);
// A HotSpotNmethod instance can only reference a single nmethod
// during its lifetime so simply clear it here.
set_InstalledCode_address(mirror, 0);
}
} }
Klass* JVMCIEnv::asKlass(JVMCIObject obj) { Klass* JVMCIEnv::asKlass(JVMCIObject obj) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -21,7 +21,7 @@
* questions. * questions.
*/ */
package compiler.jvmci.errors; package compiler.jvmci.common;
import jdk.vm.ci.code.Architecture; import jdk.vm.ci.code.Architecture;
import jdk.vm.ci.code.CodeCacheProvider; import jdk.vm.ci.code.CodeCacheProvider;
@ -30,6 +30,7 @@ import jdk.vm.ci.code.RegisterArray;
import jdk.vm.ci.code.StackSlot; import jdk.vm.ci.code.StackSlot;
import jdk.vm.ci.code.site.DataPatch; import jdk.vm.ci.code.site.DataPatch;
import jdk.vm.ci.code.site.Site; import jdk.vm.ci.code.site.Site;
import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.hotspot.HotSpotCompiledCode; import jdk.vm.ci.hotspot.HotSpotCompiledCode;
import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment; import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
import jdk.vm.ci.hotspot.HotSpotCompiledNmethod; import jdk.vm.ci.hotspot.HotSpotCompiledNmethod;
@ -39,6 +40,7 @@ import jdk.vm.ci.meta.Assumptions.Assumption;
import jdk.vm.ci.meta.MetaAccessProvider; import jdk.vm.ci.meta.MetaAccessProvider;
import jdk.vm.ci.meta.PlatformKind; import jdk.vm.ci.meta.PlatformKind;
import jdk.vm.ci.meta.ResolvedJavaMethod; import jdk.vm.ci.meta.ResolvedJavaMethod;
import jdk.vm.ci.meta.SpeculationLog;
import jdk.vm.ci.runtime.JVMCI; import jdk.vm.ci.runtime.JVMCI;
import jdk.vm.ci.runtime.JVMCIBackend; import jdk.vm.ci.runtime.JVMCIBackend;
import org.junit.Assert; import org.junit.Assert;
@ -74,11 +76,44 @@ public class CodeInstallerTest {
dummyMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method); dummyMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method);
} }
protected void installEmptyCode(Site[] sites, Assumption[] assumptions, Comment[] comments, int dataSectionAlignment, DataPatch[] dataSectionPatches, StackSlot deoptRescueSlot) { protected InstalledCode installEmptyCode(Site[] sites,
HotSpotCompiledCode code = new HotSpotCompiledNmethod("dummyMethod", new byte[0], 0, sites, assumptions, new ResolvedJavaMethod[]{dummyMethod}, comments, new byte[8], dataSectionAlignment, Assumption[] assumptions,
dataSectionPatches, false, 0, deoptRescueSlot, Comment[] comments,
dummyMethod, 0, 1, 0L, false); int dataSectionAlignment,
codeCache.addCode(dummyMethod, code, null, null); DataPatch[] dataSectionPatches,
StackSlot deoptRescueSlot) {
ResolvedJavaMethod[] methods = {dummyMethod};
byte[] targetCode = {0};
int targetCodeSize = targetCode.length;
boolean isImmutablePIC = false;
int totalFrameSize = 0;
int entryBCI = 0;
int id = 1;
long compileState = 0L;
boolean hasUnsafeAccess = false;
HotSpotCompiledCode code =
new HotSpotCompiledNmethod("dummyMethod",
targetCode,
targetCodeSize,
sites,
assumptions,
methods,
comments,
new byte[8],
dataSectionAlignment,
dataSectionPatches,
isImmutablePIC,
totalFrameSize,
deoptRescueSlot,
dummyMethod,
entryBCI,
id,
compileState,
hasUnsafeAccess);
SpeculationLog log = null;
InstalledCode installedCode = null;
return codeCache.addCode(dummyMethod, code, log, installedCode);
} }
protected Register getRegister(PlatformKind kind, int index) { protected Register getRegister(PlatformKind kind, int index) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -243,8 +243,8 @@ public class CompilerToVMHelper {
CTVM.reprofile((HotSpotResolvedJavaMethodImpl)method); CTVM.reprofile((HotSpotResolvedJavaMethodImpl)method);
} }
public static void invalidateHotSpotNmethod(HotSpotNmethod nmethodMirror) { public static void invalidateHotSpotNmethod(HotSpotNmethod nmethodMirror, boolean deoptimize) {
CTVM.invalidateHotSpotNmethod(nmethodMirror, true); CTVM.invalidateHotSpotNmethod(nmethodMirror, deoptimize);
} }
public static long[] collectCounters() { public static long[] collectCounters() {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,20 +27,20 @@
* @requires vm.jvmci * @requires vm.jvmci
* @library /test/lib / * @library /test/lib /
* @library ../common/patches * @library ../common/patches
* @ignore 8249621
* @ignore 8163894
* @modules java.base/jdk.internal.misc * @modules java.base/jdk.internal.misc
* @modules java.base/jdk.internal.org.objectweb.asm * @modules java.base/jdk.internal.org.objectweb.asm
* java.base/jdk.internal.org.objectweb.asm.tree * java.base/jdk.internal.org.objectweb.asm.tree
* jdk.internal.vm.ci/jdk.vm.ci.hotspot * jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code * jdk.internal.vm.ci/jdk.vm.ci.code
* jdk.internal.vm.ci/jdk.vm.ci.code.site
* jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime * jdk.internal.vm.ci/jdk.vm.ci.runtime
* *
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper * @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
* @build compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest * jdk.test.whitebox.WhiteBox jdk.test.whitebox.parser.DiagnosticCommand
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. * jdk.test.whitebox.parser.DiagnosticCommand
* @run junit/othervm -Xbootclasspath/a:.
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI * -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest * compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest
@ -48,75 +48,58 @@
package compiler.jvmci.compilerToVM; package compiler.jvmci.compilerToVM;
import compiler.jvmci.common.CodeInstallerTest;
import compiler.jvmci.common.CTVMUtilities; import compiler.jvmci.common.CTVMUtilities;
import jdk.test.lib.Asserts; import jdk.test.lib.Asserts;
import jdk.test.lib.Utils; import jdk.test.lib.Utils;
import jdk.vm.ci.code.CodeCacheProvider;
import jdk.vm.ci.code.CompilationResult;
import jdk.vm.ci.code.InstalledCode; import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.code.site.Site;
import jdk.vm.ci.code.site.DataPatch;
import jdk.vm.ci.hotspot.CompilerToVMHelper; import jdk.vm.ci.hotspot.CompilerToVMHelper;
import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod; import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
import jdk.test.whitebox.code.NMethod; import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
import jdk.vm.ci.hotspot.HotSpotNmethod;
import jdk.vm.ci.meta.Assumptions.Assumption;
import java.util.List; import java.util.List;
import org.junit.Test;
public class InvalidateInstalledCodeTest { public class InvalidateInstalledCodeTest extends CodeInstallerTest {
private static final CodeCacheProvider CACHE_PROVIDER
= HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend()
.getCodeCache();
public static void main(String[] args) { @Test
InvalidateInstalledCodeTest test public void testInvalidation() {
= new InvalidateInstalledCodeTest();
List<CompileCodeTestCase> testCases List<CompileCodeTestCase> testCases
= CompileCodeTestCase.generate(/* bci = */ 0); = CompileCodeTestCase.generate(/* bci = */ 0);
testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1)); testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1));
testCases.forEach(test::check); testCases.forEach(t -> check(t));
test.checkNull(); checkNull();
} }
private void checkNull() { private void checkNull() {
Utils.runAndCheckException( Utils.runAndCheckException(
() -> CompilerToVMHelper.invalidateInstalledCode(null), () -> CompilerToVMHelper.invalidateHotSpotNmethod(null, true),
NullPointerException.class); NullPointerException.class);
} }
private void check(CompileCodeTestCase testCase) { private void check(CompileCodeTestCase testCase) {
System.out.println(testCase); HotSpotResolvedJavaMethod javaMethod = CTVMUtilities.getResolvedMethod(testCase.executable);
HotSpotResolvedJavaMethod javaMethod HotSpotNmethod nmethod = (HotSpotNmethod) installEmptyCode(new Site[0], new Assumption[0],
= CTVMUtilities.getResolvedMethod(testCase.executable); new Comment[0], 8, new DataPatch[0], null);
HotSpotCompilationRequest compRequest = new HotSpotCompilationRequest(
javaMethod, testCase.bci, /* jvmciEnv = */ 0L);
String name = testCase.executable.getName();
CompilationResult compResult = new CompilationResult(name);
// to pass sanity check of default -1
compResult.setTotalFrameSize(0);
compResult.close();
InstalledCode installedCode = CACHE_PROVIDER.installCode(
compRequest, compResult,
new InstalledCode(name), /* speculationLog = */ null,
/* isDefault = */ false);
Asserts.assertTrue(installedCode.isValid(), testCase
+ " : code is invalid even before invalidation");
NMethod beforeInvalidation = testCase.toNMethod(); Asserts.assertTrue(nmethod.isValid(), testCase + " : code is invalid even before invalidation");
if (beforeInvalidation != null) {
throw new Error("TESTBUG : " + testCase + " : nmethod isn't found"); Asserts.assertTrue(nmethod.isValid(), testCase + " : code is not valid, i = " + nmethod);
} Asserts.assertTrue(nmethod.isAlive(), testCase + " : code is not alive, i = " + nmethod);
// run twice to verify how it works if method is already invalidated
for (int i = 0; i < 2; ++i) { // Make nmethod non-entrant but still alive
CompilerToVMHelper.invalidateInstalledCode(installedCode); CompilerToVMHelper.invalidateHotSpotNmethod(nmethod, false);
Asserts.assertFalse(installedCode.isValid(), testCase Asserts.assertFalse(nmethod.isValid(), testCase + " : code is valid, i = " + nmethod);
+ " : code is valid after invalidation, i = " + i); Asserts.assertTrue(nmethod.isAlive(), testCase + " : code is not alive, i = " + nmethod);
NMethod afterInvalidation = testCase.toNMethod();
if (afterInvalidation != null) { // Deoptimize the nmethod and cut the link to it from the HotSpotNmethod
System.err.println("before: " + beforeInvalidation); CompilerToVMHelper.invalidateHotSpotNmethod(nmethod, true);
System.err.println("after: " + afterInvalidation); Asserts.assertFalse(nmethod.isValid(), testCase + " : code is valid, i = " + nmethod);
throw new AssertionError(testCase Asserts.assertFalse(nmethod.isAlive(), testCase + " : code is alive, i = " + nmethod);
+ " : method hasn't been invalidated, i = " + i);
}
}
} }
} }

View file

@ -23,6 +23,7 @@
/** /**
* @test * @test
* @library /
* @requires vm.jvmci * @requires vm.jvmci
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot * @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code * jdk.internal.vm.ci/jdk.vm.ci.code
@ -30,13 +31,13 @@
* jdk.internal.vm.ci/jdk.vm.ci.meta * jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime * jdk.internal.vm.ci/jdk.vm.ci.runtime
* jdk.internal.vm.ci/jdk.vm.ci.common * jdk.internal.vm.ci/jdk.vm.ci.common
* @compile CodeInstallerTest.java
* @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI * @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidCompilationResult * -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidCompilationResult
*/ */
package compiler.jvmci.errors; package compiler.jvmci.errors;
import compiler.jvmci.common.CodeInstallerTest;
import jdk.vm.ci.code.StackSlot; import jdk.vm.ci.code.StackSlot;
import jdk.vm.ci.code.site.ConstantReference; import jdk.vm.ci.code.site.ConstantReference;
import jdk.vm.ci.code.site.DataPatch; import jdk.vm.ci.code.site.DataPatch;

View file

@ -23,6 +23,7 @@
/** /**
* @test * @test
* @library /
* @requires vm.jvmci * @requires vm.jvmci
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot * @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code * jdk.internal.vm.ci/jdk.vm.ci.code
@ -30,13 +31,13 @@
* jdk.internal.vm.ci/jdk.vm.ci.meta * jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime * jdk.internal.vm.ci/jdk.vm.ci.runtime
* jdk.internal.vm.ci/jdk.vm.ci.common * jdk.internal.vm.ci/jdk.vm.ci.common
* @compile CodeInstallerTest.java
* @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI * @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidDebugInfo * -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidDebugInfo
*/ */
package compiler.jvmci.errors; package compiler.jvmci.errors;
import compiler.jvmci.common.CodeInstallerTest;
import jdk.vm.ci.code.Architecture; import jdk.vm.ci.code.Architecture;
import jdk.vm.ci.code.BytecodeFrame; import jdk.vm.ci.code.BytecodeFrame;
import jdk.vm.ci.code.DebugInfo; import jdk.vm.ci.code.DebugInfo;

View file

@ -23,6 +23,7 @@
/** /**
* @test * @test
* @library /
* @requires vm.jvmci * @requires vm.jvmci
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot * @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot
* jdk.internal.vm.ci/jdk.vm.ci.code * jdk.internal.vm.ci/jdk.vm.ci.code
@ -30,13 +31,13 @@
* jdk.internal.vm.ci/jdk.vm.ci.meta * jdk.internal.vm.ci/jdk.vm.ci.meta
* jdk.internal.vm.ci/jdk.vm.ci.runtime * jdk.internal.vm.ci/jdk.vm.ci.runtime
* jdk.internal.vm.ci/jdk.vm.ci.common * jdk.internal.vm.ci/jdk.vm.ci.common
* @compile CodeInstallerTest.java
* @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI * @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
* -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidOopMap * -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidOopMap
*/ */
package compiler.jvmci.errors; package compiler.jvmci.errors;
import compiler.jvmci.common.CodeInstallerTest;
import jdk.vm.ci.code.BytecodePosition; import jdk.vm.ci.code.BytecodePosition;
import jdk.vm.ci.code.DebugInfo; import jdk.vm.ci.code.DebugInfo;
import jdk.vm.ci.code.Location; import jdk.vm.ci.code.Location;