Commit fbade743 authored by Eric Bruneton's avatar Eric Bruneton

Merge branch 'use-openjdk-codetools-to-avoid-testing-asm-with-itself' into 'master'

Use the OpenJDK codetools to avoid testing ASM with classes produced with ASM.

See merge request !205
parents cfbfe492 ec024899
Pipeline #2734 passed with stage
in 7 minutes and 28 seconds
......@@ -130,8 +130,7 @@ public abstract class AsmTest {
JDK9_MODULE("jdk9.module-info"),
JDK11_ALL_INSTRUCTIONS("jdk11.AllInstructions"),
JDK11_ALL_STRUCTURES("jdk11.AllStructures"),
JDK11_ALL_STRUCTURES_NESTED("jdk11.AllStructures$Nested"),
JDK11_LAMBDA_CONDY("jdk11.LambdaCondy");
JDK11_ALL_STRUCTURES_NESTED("jdk11.AllStructures$Nested");
private final String name;
......
......@@ -27,58 +27,74 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package jdk11;
import java.io.FileOutputStream;
import java.io.IOException;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
/**
* Generates classes with all the JDK11 specific class file features.
* A class with all the JDK11 specific instructions. A corresponding class file can be generated
* with the OpenJDK asmtools (https://wiki.openjdk.java.net/display/CodeTools/asmtools),
* version 7 or more. Usage:
*
* <p>TODO: remove this and use the JDK11 to compile equivalent classes, when it is released.
* java -jar asmtools.jar jasm AllInstructions.jasm
*
* @author Eric Bruneton
*/
public class DumpAllStructures implements Opcodes {
super public class AllInstructions
version 55:65535
{
public static void main(String[] args) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream("AllStructures.class");
fileOutputStream.write(dumpAllStructures());
fileOutputStream.close();
fileOutputStream = new FileOutputStream("AllStructures$Nested.class");
fileOutputStream.write(dumpAllStructuresNested());
fileOutputStream.close();
}
public Method "<init>":"()V"
stack 1 locals 1
{
aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}
private static byte[] dumpAllStructures() {
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
classWriter.visit(
V11, ACC_PUBLIC + ACC_SUPER, "jdk11/AllStructures", null, "java/lang/Object", null);
classWriter.visitNestMember("jdk11/AllStructures$Nested");
addDefaultConstructor(classWriter);
classWriter.visitEnd();
return classWriter.toByteArray();
}
public Method m:"()Ljava/lang/Object;"
stack 1 locals 1
{
ldc Dynamic REF_invokeStatic
:HandleOwner.handleField
:"(Ljava/lang/Object;)Ljava/lang/Object;"
:name
:"Ljava/lang/Object;" {
Dynamic REF_getStatic
:ArgumentHandleOwner.argumentHandleName
:"Ljava/lang/Object;"
:argumentName
:"Ljava/lang/Object;"
};
areturn;
}
private static byte[] dumpAllStructuresNested() {
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
classWriter.visit(
V11, ACC_PUBLIC + ACC_SUPER, "jdk11/AllStructures$Nested", null, "java/lang/Object", null);
classWriter.visitNestHost("jdk11/AllStructures");
addDefaultConstructor(classWriter);
classWriter.visitEnd();
return classWriter.toByteArray();
}
public static Method main:"([Ljava/lang/String;)V"
stack 1 locals 2
{
ldc Dynamic REF_invokeStatic
:java/lang/invoke/LambdaMetafactory.metafactory
:"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/Object;"
:run
:"Ljava/lang/Runnable;" {
MethodType "()V",
MethodHandle REF_invokeStatic:AllInstructions.lambda$main$0:"()V",
MethodType "()V"
};
astore_1;
aload_1;
invokeinterface InterfaceMethod java/lang/Runnable.run:"()V", 1;
return;
}
private static void addDefaultConstructor(final ClassWriter classWriter) {
MethodVisitor methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
methodVisitor.visitCode();
methodVisitor.visitVarInsn(ALOAD, 0);
methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
methodVisitor.visitInsn(RETURN);
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
}
private static synthetic Method lambda$main$0:"()V"
stack 2 locals 0
{
getstatic Field java/lang/System.out:"Ljava/io/PrintStream;";
ldc String "hello condy";
invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V";
return;
}
public static final InnerClass Lookup=
class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles;
} // end Class AllInstructions
......@@ -27,72 +27,27 @@
// THE POSSIBILITY OF SUCH DAMAGE.
package jdk11;
import java.io.FileOutputStream;
import java.io.IOException;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.ConstantDynamic;
import org.objectweb.asm.Handle;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
/**
* Generates classes with all the JDK11 specific instructions.
* A class with all the JDK11 specific class file features. A corresponding class file can be
* generated with the OpenJDK asmtools (https://wiki.openjdk.java.net/display/CodeTools/asmtools),
* version 7 or more. Usage:
*
* <p>TODO: remove this and use the JDK11 to compile equivalent classes, when it is released.
* java -jar asmtools.jar jasm AllStructures.jasm
*
* @author Eric Bruneton
*/
public class DumpAllInstructions implements Opcodes {
public static void main(String[] args) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream("AllInstructions.class");
fileOutputStream.write(dumpAllInstructions());
fileOutputStream.close();
}
private static byte[] dumpAllInstructions() {
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
classWriter.visit(
V11, ACC_PUBLIC + ACC_SUPER, "jdk11/AllInstructions", null, "java/lang/Object", null);
addDefaultConstructor(classWriter);
super public class AllStructures$Nested
version 55:0
{
MethodVisitor methodVisitor =
classWriter.visitMethod(ACC_PUBLIC, "m", "()Ljava/lang/Object;", null, null);
methodVisitor.visitCode();
methodVisitor.visitLdcInsn(
new ConstandDynamic(
"name",
"Ljava/lang/Object;",
new Handle(
H_INVOKESTATIC,
"HandleOwner",
"handleField",
"(Ljava/lang/Object;)Ljava/lang/Object;",
false),
new ConstantDynamic(
"argumentName",
"Ljava/lang/Object;",
new Handle(
H_GETSTATIC,
"ArgumentHandleOwner",
"argumentHandleName",
"Ljava/lang/Object;",
false))));
methodVisitor.visitInsn(ARETURN);
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
classWriter.visitEnd();
return classWriter.toByteArray();
}
private static void addDefaultConstructor(final ClassWriter classWriter) {
MethodVisitor methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
methodVisitor.visitCode();
methodVisitor.visitVarInsn(ALOAD, 0);
methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
methodVisitor.visitInsn(RETURN);
methodVisitor.visitMaxs(0, 0);
methodVisitor.visitEnd();
}
public Method "<init>":"()V"
stack 1 locals 1
{
aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}
NestHost AllStructures;
} // end Class AllStructures$Nested
......@@ -28,14 +28,26 @@
package jdk11;
/**
* By default with jdk 11, constant lambda are compiled using constant dynamic The classfile was
* generated with the amber (branch condy-folding) compiler.
* A class with JDK11 specific class file feature. A corresponding class file can be generated
with the OpenJDK asmtools (https://wiki.openjdk.java.net/display/CodeTools/asmtools),
* version 7 or more. Usage:
*
* <p>/usr/jdk/jdk-11/bin/javac -source 11 --enable-preview jdk11/LambdaCondy.java
* java -jar asmtools.jar jasm AllStructures.jasm
*
* @author Eric Bruneton
*/
public class LambdaCondy {
public static void main(String[] args) {
Runnable r = () -> System.out.println("hello condy");
r.run();
}
super public class AllStructures
version 55:0
{
public Method "<init>":"()V"
stack 1 locals 1
{
aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}
NestMembers AllStructures$Nested;
} // end Class AllStructures
// class version 55.0 (55)
// class version 55.65535 (-65481)
// access flags 0x21
public class jdk11/AllInstructions {
// compiled from: AllInstructions.jasm
// access flags 0x19
public final static INNERCLASS java/lang/invoke/MethodHandles$Lookup java/lang/invoke/MethodHandles Lookup
// access flags 0x1
public <init>()V
......@@ -13,8 +16,27 @@ public class jdk11/AllInstructions {
// access flags 0x1
public m()Ljava/lang/Object;
LDC name : Ljava/lang/Object; HandleOwner.handleField(Ljava/lang/Object;)Ljava/lang/Object; (6) [argumentName : Ljava/lang/Object; ArgumentHandleOwner.argumentHandleNameLjava/lang/Object; (2) []]
LDC name : Ljava/lang/Object; jdk11/HandleOwner.handleField(Ljava/lang/Object;)Ljava/lang/Object; (6) [argumentName : Ljava/lang/Object; jdk11/ArgumentHandleOwner.argumentHandleNameLjava/lang/Object; (2) []]
ARETURN
MAXSTACK = 1
MAXLOCALS = 1
// access flags 0x9
public static main([Ljava/lang/String;)V
LDC run : Ljava/lang/Runnable; java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/Object; (6) [()V, jdk11/AllInstructions.lambda$main$0()V (6), ()V]
ASTORE 1
ALOAD 1
INVOKEINTERFACE java/lang/Runnable.run ()V (itf)
RETURN
MAXSTACK = 1
MAXLOCALS = 2
// access flags 0x100A
private static synthetic lambda$main$0()V
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
LDC "hello condy"
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
RETURN
MAXSTACK = 2
MAXLOCALS = 0
}
......@@ -2,6 +2,7 @@
// access flags 0x21
public class jdk11/AllStructures$Nested {
// compiled from: AllStructures$Nested.jasm
NESTHOST jdk11/AllStructures
// access flags 0x1
......
......@@ -2,6 +2,7 @@
// access flags 0x21
public class jdk11/AllStructures {
// compiled from: AllStructures.jasm
NESTMEMBER jdk11/AllStructures$Nested
// access flags 0x1
......
// class version 55.65535 (-65481)
// access flags 0x21
public class jdk11/LambdaCondy {
// compiled from: LambdaCondy.java
// access flags 0x19
public final static INNERCLASS java/lang/invoke/MethodHandles$Lookup java/lang/invoke/MethodHandles Lookup
// access flags 0x1
public <init>()V
L0
LINENUMBER 36 L0
ALOAD 0
INVOKESPECIAL java/lang/Object.<init> ()V
RETURN
MAXSTACK = 1
MAXLOCALS = 1
// access flags 0x9
public static main([Ljava/lang/String;)V
L0
LINENUMBER 38 L0
LDC run : Ljava/lang/Runnable; java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/Object; (6) [()V, jdk11/LambdaCondy.lambda$main$0()V (6), ()V]
ASTORE 1
L1
LINENUMBER 39 L1
ALOAD 1
INVOKEINTERFACE java/lang/Runnable.run ()V (itf)
L2
LINENUMBER 40 L2
RETURN
MAXSTACK = 1
MAXLOCALS = 2
// access flags 0x100A
private static synthetic lambda$main$0()V
L0
LINENUMBER 38 L0
GETSTATIC java/lang/System.out : Ljava/io/PrintStream;
LDC "hello condy"
INVOKEVIRTUAL java/io/PrintStream.println (Ljava/lang/String;)V
RETURN
MAXSTACK = 2
MAXLOCALS = 0
}
......@@ -291,8 +291,7 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
.when(
classParameter.isMoreRecentThan(apiParameter)
&& classParameter != PrecompiledClass.JDK8_ARTIFICIAL_STRUCTURES
&& classParameter != PrecompiledClass.JDK11_ALL_INSTRUCTIONS
&& classParameter != PrecompiledClass.JDK11_LAMBDA_CONDY);
&& classParameter != PrecompiledClass.JDK11_ALL_INSTRUCTIONS);
}
/**
......@@ -430,7 +429,7 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
@Test
public void testPreviewMinorVersion() {
ClassReader classReader = new ClassReader(PrecompiledClass.JDK11_LAMBDA_CONDY.getBytes());
ClassReader classReader = new ClassReader(PrecompiledClass.JDK11_ALL_INSTRUCTIONS.getBytes());
classReader.accept(
new ClassVisitor(Opcodes.ASM7_EXPERIMENTAL) {
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment