Skip to content

Commit b8b9b97

Browse files
author
Doug Simon
committedOct 1, 2022
8294676: [JVMCI] InstalledCode.deoptimize(false) should not touch address field
Reviewed-by: never
1 parent fd59430 commit b8b9b97

File tree

7 files changed

+97
-72
lines changed

7 files changed

+97
-72
lines changed
 

‎src/hotspot/share/jvmci/jvmciEnv.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -1547,14 +1547,18 @@ void JVMCIEnv::invalidate_nmethod_mirror(JVMCIObject mirror, bool deoptimize, JV
15471547
if (!deoptimize) {
15481548
// Prevent future executions of the nmethod but let current executions complete.
15491549
nm->make_not_entrant();
1550-
} else {
1551-
// We want the nmethod to be deoptimized immediately.
1550+
1551+
// Do not clear the address field here as the Java code may still
1552+
// want to later call this method with deoptimize == true. That requires
1553+
// the address field to still be pointing at the nmethod.
1554+
} else {
1555+
// Deoptimize the nmethod immediately.
15521556
Deoptimization::deoptimize_all_marked(nm);
1553-
}
15541557

1555-
// A HotSpotNmethod instance can only reference a single nmethod
1556-
// during its lifetime so simply clear it here.
1557-
set_InstalledCode_address(mirror, 0);
1558+
// A HotSpotNmethod instance can only reference a single nmethod
1559+
// during its lifetime so simply clear it here.
1560+
set_InstalledCode_address(mirror, 0);
1561+
}
15581562
}
15591563

15601564
Klass* JVMCIEnv::asKlass(JVMCIObject obj) {

‎test/hotspot/jtreg/compiler/jvmci/errors/CodeInstallerTest.java ‎test/hotspot/jtreg/compiler/jvmci/common/CodeInstallerTest.java

+42-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,7 +21,7 @@
2121
* questions.
2222
*/
2323

24-
package compiler.jvmci.errors;
24+
package compiler.jvmci.common;
2525

2626
import jdk.vm.ci.code.Architecture;
2727
import jdk.vm.ci.code.CodeCacheProvider;
@@ -30,6 +30,7 @@
3030
import jdk.vm.ci.code.StackSlot;
3131
import jdk.vm.ci.code.site.DataPatch;
3232
import jdk.vm.ci.code.site.Site;
33+
import jdk.vm.ci.code.InstalledCode;
3334
import jdk.vm.ci.hotspot.HotSpotCompiledCode;
3435
import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
3536
import jdk.vm.ci.hotspot.HotSpotCompiledNmethod;
@@ -39,6 +40,7 @@
3940
import jdk.vm.ci.meta.MetaAccessProvider;
4041
import jdk.vm.ci.meta.PlatformKind;
4142
import jdk.vm.ci.meta.ResolvedJavaMethod;
43+
import jdk.vm.ci.meta.SpeculationLog;
4244
import jdk.vm.ci.runtime.JVMCI;
4345
import jdk.vm.ci.runtime.JVMCIBackend;
4446
import org.junit.Assert;
@@ -74,11 +76,44 @@ protected CodeInstallerTest() {
7476
dummyMethod = (HotSpotResolvedJavaMethod) metaAccess.lookupJavaMethod(method);
7577
}
7678

77-
protected void installEmptyCode(Site[] sites, Assumption[] assumptions, Comment[] comments, int dataSectionAlignment, DataPatch[] dataSectionPatches, StackSlot deoptRescueSlot) {
78-
HotSpotCompiledCode code = new HotSpotCompiledNmethod("dummyMethod", new byte[0], 0, sites, assumptions, new ResolvedJavaMethod[]{dummyMethod}, comments, new byte[8], dataSectionAlignment,
79-
dataSectionPatches, false, 0, deoptRescueSlot,
80-
dummyMethod, 0, 1, 0L, false);
81-
codeCache.addCode(dummyMethod, code, null, null);
79+
protected InstalledCode installEmptyCode(Site[] sites,
80+
Assumption[] assumptions,
81+
Comment[] comments,
82+
int dataSectionAlignment,
83+
DataPatch[] dataSectionPatches,
84+
StackSlot deoptRescueSlot) {
85+
ResolvedJavaMethod[] methods = {dummyMethod};
86+
byte[] targetCode = {0};
87+
int targetCodeSize = targetCode.length;
88+
boolean isImmutablePIC = false;
89+
int totalFrameSize = 0;
90+
int entryBCI = 0;
91+
int id = 1;
92+
long compileState = 0L;
93+
boolean hasUnsafeAccess = false;
94+
95+
HotSpotCompiledCode code =
96+
new HotSpotCompiledNmethod("dummyMethod",
97+
targetCode,
98+
targetCodeSize,
99+
sites,
100+
assumptions,
101+
methods,
102+
comments,
103+
new byte[8],
104+
dataSectionAlignment,
105+
dataSectionPatches,
106+
isImmutablePIC,
107+
totalFrameSize,
108+
deoptRescueSlot,
109+
dummyMethod,
110+
entryBCI,
111+
id,
112+
compileState,
113+
hasUnsafeAccess);
114+
SpeculationLog log = null;
115+
InstalledCode installedCode = null;
116+
return codeCache.addCode(dummyMethod, code, log, installedCode);
82117
}
83118

84119
protected Register getRegister(PlatformKind kind, int index) {

‎test/hotspot/jtreg/compiler/jvmci/common/patches/jdk.internal.vm.ci/jdk/vm/ci/hotspot/CompilerToVMHelper.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -243,8 +243,8 @@ public static void reprofile(HotSpotResolvedJavaMethod method) {
243243
CTVM.reprofile((HotSpotResolvedJavaMethodImpl)method);
244244
}
245245

246-
public static void invalidateHotSpotNmethod(HotSpotNmethod nmethodMirror) {
247-
CTVM.invalidateHotSpotNmethod(nmethodMirror, true);
246+
public static void invalidateHotSpotNmethod(HotSpotNmethod nmethodMirror, boolean deoptimize) {
247+
CTVM.invalidateHotSpotNmethod(nmethodMirror, deoptimize);
248248
}
249249

250250
public static long[] collectCounters() {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,96 +27,79 @@
2727
* @requires vm.jvmci
2828
* @library /test/lib /
2929
* @library ../common/patches
30-
* @ignore 8249621
31-
* @ignore 8163894
3230
* @modules java.base/jdk.internal.misc
3331
* @modules java.base/jdk.internal.org.objectweb.asm
3432
* java.base/jdk.internal.org.objectweb.asm.tree
3533
* jdk.internal.vm.ci/jdk.vm.ci.hotspot
3634
* jdk.internal.vm.ci/jdk.vm.ci.code
35+
* jdk.internal.vm.ci/jdk.vm.ci.code.site
36+
* jdk.internal.vm.ci/jdk.vm.ci.meta
3737
* jdk.internal.vm.ci/jdk.vm.ci.runtime
3838
*
3939
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper
40-
* @build compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest
41-
* @build jdk.test.whitebox.WhiteBox
40+
* jdk.test.whitebox.WhiteBox jdk.test.whitebox.parser.DiagnosticCommand
4241
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
43-
* @run main/othervm -Xbootclasspath/a:.
42+
* jdk.test.whitebox.parser.DiagnosticCommand
43+
* @run junit/othervm -Xbootclasspath/a:.
4444
* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
4545
* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
4646
* compiler.jvmci.compilerToVM.InvalidateInstalledCodeTest
4747
*/
4848

4949
package compiler.jvmci.compilerToVM;
5050

51+
import compiler.jvmci.common.CodeInstallerTest;
5152
import compiler.jvmci.common.CTVMUtilities;
5253
import jdk.test.lib.Asserts;
5354
import jdk.test.lib.Utils;
54-
import jdk.vm.ci.code.CodeCacheProvider;
55-
import jdk.vm.ci.code.CompilationResult;
5655
import jdk.vm.ci.code.InstalledCode;
56+
import jdk.vm.ci.code.site.Site;
57+
import jdk.vm.ci.code.site.DataPatch;
5758
import jdk.vm.ci.hotspot.CompilerToVMHelper;
58-
import jdk.vm.ci.hotspot.HotSpotCompilationRequest;
5959
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
6060
import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
61-
import jdk.test.whitebox.code.NMethod;
61+
import jdk.vm.ci.hotspot.HotSpotCompiledCode.Comment;
62+
import jdk.vm.ci.hotspot.HotSpotNmethod;
63+
import jdk.vm.ci.meta.Assumptions.Assumption;
6264

6365
import java.util.List;
66+
import org.junit.Test;
6467

65-
public class InvalidateInstalledCodeTest {
66-
private static final CodeCacheProvider CACHE_PROVIDER
67-
= HotSpotJVMCIRuntime.runtime().getHostJVMCIBackend()
68-
.getCodeCache();
68+
public class InvalidateInstalledCodeTest extends CodeInstallerTest {
6969

70-
public static void main(String[] args) {
71-
InvalidateInstalledCodeTest test
72-
= new InvalidateInstalledCodeTest();
70+
@Test
71+
public void testInvalidation() {
7372
List<CompileCodeTestCase> testCases
7473
= CompileCodeTestCase.generate(/* bci = */ 0);
7574
testCases.addAll(CompileCodeTestCase.generate(/* bci = */ -1));
76-
testCases.forEach(test::check);
77-
test.checkNull();
75+
testCases.forEach(t -> check(t));
76+
checkNull();
7877
}
7978

8079
private void checkNull() {
8180
Utils.runAndCheckException(
82-
() -> CompilerToVMHelper.invalidateInstalledCode(null),
81+
() -> CompilerToVMHelper.invalidateHotSpotNmethod(null, true),
8382
NullPointerException.class);
8483
}
8584

8685
private void check(CompileCodeTestCase testCase) {
87-
System.out.println(testCase);
88-
HotSpotResolvedJavaMethod javaMethod
89-
= CTVMUtilities.getResolvedMethod(testCase.executable);
90-
HotSpotCompilationRequest compRequest = new HotSpotCompilationRequest(
91-
javaMethod, testCase.bci, /* jvmciEnv = */ 0L);
92-
String name = testCase.executable.getName();
93-
CompilationResult compResult = new CompilationResult(name);
94-
// to pass sanity check of default -1
95-
compResult.setTotalFrameSize(0);
96-
compResult.close();
97-
InstalledCode installedCode = CACHE_PROVIDER.installCode(
98-
compRequest, compResult,
99-
new InstalledCode(name), /* speculationLog = */ null,
100-
/* isDefault = */ false);
101-
Asserts.assertTrue(installedCode.isValid(), testCase
102-
+ " : code is invalid even before invalidation");
86+
HotSpotResolvedJavaMethod javaMethod = CTVMUtilities.getResolvedMethod(testCase.executable);
87+
HotSpotNmethod nmethod = (HotSpotNmethod) installEmptyCode(new Site[0], new Assumption[0],
88+
new Comment[0], 8, new DataPatch[0], null);
10389

104-
NMethod beforeInvalidation = testCase.toNMethod();
105-
if (beforeInvalidation != null) {
106-
throw new Error("TESTBUG : " + testCase + " : nmethod isn't found");
107-
}
108-
// run twice to verify how it works if method is already invalidated
109-
for (int i = 0; i < 2; ++i) {
110-
CompilerToVMHelper.invalidateInstalledCode(installedCode);
111-
Asserts.assertFalse(installedCode.isValid(), testCase
112-
+ " : code is valid after invalidation, i = " + i);
113-
NMethod afterInvalidation = testCase.toNMethod();
114-
if (afterInvalidation != null) {
115-
System.err.println("before: " + beforeInvalidation);
116-
System.err.println("after: " + afterInvalidation);
117-
throw new AssertionError(testCase
118-
+ " : method hasn't been invalidated, i = " + i);
119-
}
120-
}
90+
Asserts.assertTrue(nmethod.isValid(), testCase + " : code is invalid even before invalidation");
91+
92+
Asserts.assertTrue(nmethod.isValid(), testCase + " : code is not valid, i = " + nmethod);
93+
Asserts.assertTrue(nmethod.isAlive(), testCase + " : code is not alive, i = " + nmethod);
94+
95+
// Make nmethod non-entrant but still alive
96+
CompilerToVMHelper.invalidateHotSpotNmethod(nmethod, false);
97+
Asserts.assertFalse(nmethod.isValid(), testCase + " : code is valid, i = " + nmethod);
98+
Asserts.assertTrue(nmethod.isAlive(), testCase + " : code is not alive, i = " + nmethod);
99+
100+
// Deoptimize the nmethod and cut the link to it from the HotSpotNmethod
101+
CompilerToVMHelper.invalidateHotSpotNmethod(nmethod, true);
102+
Asserts.assertFalse(nmethod.isValid(), testCase + " : code is valid, i = " + nmethod);
103+
Asserts.assertFalse(nmethod.isAlive(), testCase + " : code is alive, i = " + nmethod);
121104
}
122105
}

‎test/hotspot/jtreg/compiler/jvmci/errors/TestInvalidCompilationResult.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@
2323

2424
/**
2525
* @test
26+
* @library /
2627
* @requires vm.jvmci
2728
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot
2829
* jdk.internal.vm.ci/jdk.vm.ci.code
2930
* jdk.internal.vm.ci/jdk.vm.ci.code.site
3031
* jdk.internal.vm.ci/jdk.vm.ci.meta
3132
* jdk.internal.vm.ci/jdk.vm.ci.runtime
3233
* jdk.internal.vm.ci/jdk.vm.ci.common
33-
* @compile CodeInstallerTest.java
3434
* @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
3535
* -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidCompilationResult
3636
*/
3737

3838
package compiler.jvmci.errors;
3939

40+
import compiler.jvmci.common.CodeInstallerTest;
4041
import jdk.vm.ci.code.StackSlot;
4142
import jdk.vm.ci.code.site.ConstantReference;
4243
import jdk.vm.ci.code.site.DataPatch;

‎test/hotspot/jtreg/compiler/jvmci/errors/TestInvalidDebugInfo.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@
2323

2424
/**
2525
* @test
26+
* @library /
2627
* @requires vm.jvmci
2728
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot
2829
* jdk.internal.vm.ci/jdk.vm.ci.code
2930
* jdk.internal.vm.ci/jdk.vm.ci.code.site
3031
* jdk.internal.vm.ci/jdk.vm.ci.meta
3132
* jdk.internal.vm.ci/jdk.vm.ci.runtime
3233
* jdk.internal.vm.ci/jdk.vm.ci.common
33-
* @compile CodeInstallerTest.java
3434
* @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
3535
* -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidDebugInfo
3636
*/
3737

3838
package compiler.jvmci.errors;
3939

40+
import compiler.jvmci.common.CodeInstallerTest;
4041
import jdk.vm.ci.code.Architecture;
4142
import jdk.vm.ci.code.BytecodeFrame;
4243
import jdk.vm.ci.code.DebugInfo;

‎test/hotspot/jtreg/compiler/jvmci/errors/TestInvalidOopMap.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@
2323

2424
/**
2525
* @test
26+
* @library /
2627
* @requires vm.jvmci
2728
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot
2829
* jdk.internal.vm.ci/jdk.vm.ci.code
2930
* jdk.internal.vm.ci/jdk.vm.ci.code.site
3031
* jdk.internal.vm.ci/jdk.vm.ci.meta
3132
* jdk.internal.vm.ci/jdk.vm.ci.runtime
3233
* jdk.internal.vm.ci/jdk.vm.ci.common
33-
* @compile CodeInstallerTest.java
3434
* @run junit/othervm -da:jdk.vm.ci... -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI
3535
* -XX:-UseJVMCICompiler compiler.jvmci.errors.TestInvalidOopMap
3636
*/
3737

3838
package compiler.jvmci.errors;
3939

40+
import compiler.jvmci.common.CodeInstallerTest;
4041
import jdk.vm.ci.code.BytecodePosition;
4142
import jdk.vm.ci.code.DebugInfo;
4243
import jdk.vm.ci.code.Location;

0 commit comments

Comments
 (0)
Please sign in to comment.