1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8275868
* @library / /test/lib
* @summary Testing that ciReplay inlining does not fail with unresolved signature classes.
* @requires vm.flightRecorder != true & vm.compMode != "Xint" & vm.compMode != "Xcomp" & vm.debug == true & vm.compiler2.enabled
* @modules java.base/jdk.internal.misc
* @build jdk.test.whitebox.WhiteBox
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
* compiler.ciReplay.TestInliningProtectionDomain
*/
package compiler.ciReplay;
import jdk.test.lib.Asserts;
import java.util.List;
public class TestInliningProtectionDomain extends InliningBase {
public static void main(String[] args) {
new TestInliningProtectionDomain(ProtectionDomainTestCompiledBefore.class, true);
new TestInliningProtectionDomain(ProtectionDomainTestNoOtherCompilationPublic.class, false);
new TestInliningProtectionDomain(ProtectionDomainTestNoOtherCompilationPrivate.class, false);
new TestInliningProtectionDomain(ProtectionDomainTestNoOtherCompilationPrivateString.class, false);
}
public TestInliningProtectionDomain(Class<?> testClass, boolean compileBar) {
super(testClass);
if (compileBar) {
commandLineNormal.add("-XX:CompileCommand=compileonly," + testClass.getName() + "::bar");
}
runTest();
}
@Override
public void testAction() {
positiveTest(commandLineReplay);
String entryString = getTestClass() + " " + "test";
boolean inlineFails = testClass == ProtectionDomainTestNoOtherCompilationPrivate.class;
int inlineeCount = inlineFails ? 1 : 5;
List<InlineEntry> inlineesNormal = parseLogFile(LOG_FILE_NORMAL, entryString, "compile_id='" + getCompileIdFromFile(getReplayFileName()) + "'", inlineeCount);
List<InlineEntry> inlineesReplay = parseLogFile(LOG_FILE_REPLAY, entryString, "test ()V", inlineeCount);
verifyLists(inlineesNormal, inlineesReplay, inlineeCount);
if (inlineFails) {
Asserts.assertTrue(inlineesNormal.get(0).compare("compiler.ciReplay.ProtectionDomainTestNoOtherCompilationPrivate", "bar", inlineesNormal.get(0).isUnloadedSignatureClasses()));
Asserts.assertTrue(inlineesReplay.get(0).compare("compiler.ciReplay.ProtectionDomainTestNoOtherCompilationPrivate", "bar", inlineesReplay.get(0).isDisallowedByReplay()));
} else {
Asserts.assertTrue(inlineesNormal.get(4).compare("compiler.ciReplay.InliningBar", "bar2", inlineesNormal.get(4).isNormalInline()));
Asserts.assertTrue(inlineesReplay.get(4).compare("compiler.ciReplay.InliningBar", "bar2", inlineesReplay.get(4).isForcedByReplay() || inlineesReplay.get(4).isForcedIncrementalInlineByReplay()));
}
}
}
class ProtectionDomainTestCompiledBefore {
public static void main(String[] args) {
for (int i = 0; i < 10000; i++) {
bar(); // Ensure that bar() was compiled
}
for (int i = 0; i < 10000; i++) {
test();
}
}
public static void test() {
bar();
}
// Integer should be resolved for the protection domain of this class because the separate compilation of bar() in
// the normal run will resolve all classes in the signature. Inlining succeeds.
private static Integer bar() {
InliningFoo.foo();
return null;
}
}
class ProtectionDomainTestNoOtherCompilationPublic {
public static void main(String[] args) {
for (int i = 0; i < 10000; i++) {
test();
}
}
public static void test() {
bar(); // Not compiled before separately
}
// Integer should be resolved for the protection domain of this class because getDeclaredMethods is called in normal run
// when validating main() method. In this process, all public methods of this class are visited and its signature classes
// are resolved. Inlining of bar() succeeds.
public static Integer bar() {
InliningFoo.foo();
return null;
}
}
class ProtectionDomainTestNoOtherCompilationPrivate {
public static void main(String[] args) {
for (int i = 0; i < 10000; i++) {
test();
}
}
public static void test() {
bar(); // Not compiled before separately
}
// Integer should be unresolved for the protection domain of this class even though getDeclaredMethods is called in normal
// run when validating main() method. In this process, only public methods of this class are visited and its signature
// classes are resolved. Since this method is private, the signature classes are not resolved for this protection domain.
// Inlining of bar() should fail in normal run with "unresolved signature classes". Therefore, replay compilation should
// also not inline bar().
private static Integer bar() {
InliningFoo.foo();
return null;
}
}
class ProtectionDomainTestNoOtherCompilationPrivateString {
public static void main(String[] args) {
for (int i = 0; i < 10000; i++) {
test();
}
}
public static void test() {
bar(); // Not compiled before separately
}
// Integer should be resovled for the protection domain of this class because getDeclaredMethods is called in normal run
// when validating main() method. In this process, public methods of this class are visited and its signature classes
// are resolved. bar() is private and not visited in this process (i.e. no resolution of String). But since main()
// has String[] as parameter, the String class will be resolved for this protection domain. Inlining of bar() succeeds.
private static String bar() {
InliningFoo.foo();
return null;
}
}
class InliningFoo {
public static void foo() {
foo2();
}
private static void foo2() {
InliningBar.bar();
}
}
class InliningBar {
public static void bar() {
bar2();
}
private static void bar2() {}
}
|