-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
8322726: C2: Unloaded signature class kills argument value
Reviewed-by: mbaesken Backport-of: fa02667d838f08cac7d41dfb4c3e8056ae6165cc
- Loading branch information
1 parent
43a6746
commit 541a284
Showing
5 changed files
with
181 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
test/hotspot/jtreg/compiler/runtime/unloaded/TestMHUnloaded.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 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. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* 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 8322726 | ||
* @library /test/lib | ||
* @modules java.base/jdk.internal.org.objectweb.asm | ||
* | ||
* @compile TestMHUnloaded.java TestMHUnloadedHelper.java | ||
* @run driver jdk.test.lib.helpers.ClassFileInstaller compiler.runtime.unloaded.TestMHUnloadedHelper | ||
* @run main/othervm -Xbootclasspath/a:. | ||
* -Xbatch -XX:-TieredCompilation -XX:CompileCommand=exclude,*::test | ||
* -XX:+UnlockDiagnosticVMOptions -XX:+PrintCompilation -XX:+PrintInlining | ||
* compiler.runtime.unloaded.TestMHUnloaded | ||
*/ | ||
|
||
package compiler.runtime.unloaded; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
public class TestMHUnloaded { | ||
public static void main(String[] args) { | ||
TestMHUnloadedHelper.test(MethodHandles.lookup()); // launch test in bootstrap loader context | ||
TestMHUnloadedHelper.testConstant(MethodHandles.lookup()); // launch test in bootstrap loader context | ||
System.out.println("TEST PASSED"); | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
test/hotspot/jtreg/compiler/runtime/unloaded/TestMHUnloadedHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 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. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* 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. | ||
*/ | ||
|
||
package compiler.runtime.unloaded; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.MethodType; | ||
import java.util.function.BiPredicate; | ||
import jdk.internal.org.objectweb.asm.ClassWriter; | ||
|
||
import static jdk.internal.org.objectweb.asm.Opcodes.*; | ||
|
||
// Operates in bootstrap loader context. | ||
public class TestMHUnloadedHelper { | ||
private static final MethodType METHOD_TYPE = MethodType.methodType(BiPredicate.class, | ||
BiPredicate.class, BiPredicate.class); | ||
|
||
static byte[] generateClassFile(Class<?> caller) { | ||
var cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); | ||
String name = caller.getName().replace('.', '/'); | ||
cw.visit(V17, ACC_PUBLIC | ACC_SUPER, name, null, "java/lang/Object", null); | ||
{ | ||
var mv = cw.visitMethod(ACC_PUBLIC | ACC_STATIC, "test", METHOD_TYPE.toMethodDescriptorString(), null, null); | ||
mv.visitCode(); | ||
mv.visitIntInsn(ALOAD, 1); | ||
mv.visitInsn(ARETURN); | ||
mv.visitMaxs(0, 0); | ||
} | ||
return cw.toByteArray(); | ||
} | ||
|
||
public static MethodHandle generateTest(MethodHandles.Lookup caller) { | ||
// Loaded in the caller context. | ||
byte[] classBytes = generateClassFile(caller.lookupClass()); | ||
try { | ||
MethodHandles.Lookup lookup = caller.defineHiddenClass(classBytes, true); | ||
MethodHandle test = lookup.findStatic(lookup.lookupClass(), "test", METHOD_TYPE); | ||
test = MethodHandles.permuteArguments(test, test.type(), 1, 0); // mix arguments | ||
return test; | ||
} catch (Throwable e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
|
||
static BiPredicate[] ps = new BiPredicate[] { (a, b) -> false, | ||
(a, b) -> true }; | ||
|
||
public static void test(MethodHandles.Lookup caller) { | ||
MethodHandle test = generateTest(caller); | ||
|
||
for (int i = 0; i < 20_000; i++) { | ||
try { | ||
BiPredicate pr = (BiPredicate)test.invokeExact(ps[1], ps[0]); | ||
if (pr != ps[1]) { | ||
throw new AssertionError("mismatch"); | ||
} | ||
} catch (Throwable e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
} | ||
|
||
public static void testConstant(MethodHandles.Lookup caller) { | ||
MethodHandle test = generateTest(caller); | ||
|
||
// testMH() { return test(ps2, ps1); } where test(a, b) { return b; }. | ||
test = test.bindTo(ps[1]).bindTo(ps[0]); // make argument concrete types visible to the JIT-compiler | ||
|
||
for (int i = 0; i < 20_000; i++) { | ||
try { | ||
BiPredicate pr = (BiPredicate)test.invokeExact(); | ||
if (pr != ps[1]) { | ||
throw new AssertionError("mismatch"); | ||
} | ||
} catch (Throwable e) { | ||
throw new AssertionError(e); | ||
} | ||
} | ||
} | ||
} |
541a284
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues