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 { ...@@ -130,8 +130,7 @@ public abstract class AsmTest {
JDK9_MODULE("jdk9.module-info"), JDK9_MODULE("jdk9.module-info"),
JDK11_ALL_INSTRUCTIONS("jdk11.AllInstructions"), JDK11_ALL_INSTRUCTIONS("jdk11.AllInstructions"),
JDK11_ALL_STRUCTURES("jdk11.AllStructures"), JDK11_ALL_STRUCTURES("jdk11.AllStructures"),
JDK11_ALL_STRUCTURES_NESTED("jdk11.AllStructures$Nested"), JDK11_ALL_STRUCTURES_NESTED("jdk11.AllStructures$Nested");
JDK11_LAMBDA_CONDY("jdk11.LambdaCondy");
private final String name; private final String name;
......
...@@ -25,60 +25,76 @@ ...@@ -25,60 +25,76 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE. // THE POSSIBILITY OF SUCH DAMAGE.
package jdk11; 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),
* <p>TODO: remove this and use the JDK11 to compile equivalent classes, when it is released. * version 7 or more. Usage:
*
* java -jar asmtools.jar jasm AllInstructions.jasm
* *
* @author Eric Bruneton * @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"); public Method "<init>":"()V"
fileOutputStream.write(dumpAllStructuresNested()); stack 1 locals 1
fileOutputStream.close(); {
} aload_0;
invokespecial Method java/lang/Object."<init>":"()V";
return;
}
private static byte[] dumpAllStructures() { public Method m:"()Ljava/lang/Object;"
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); stack 1 locals 1
classWriter.visit( {
V11, ACC_PUBLIC + ACC_SUPER, "jdk11/AllStructures", null, "java/lang/Object", null); ldc Dynamic REF_invokeStatic
classWriter.visitNestMember("jdk11/AllStructures$Nested"); :HandleOwner.handleField
addDefaultConstructor(classWriter); :"(Ljava/lang/Object;)Ljava/lang/Object;"
classWriter.visitEnd(); :name
return classWriter.toByteArray(); :"Ljava/lang/Object;" {
} Dynamic REF_getStatic
:ArgumentHandleOwner.argumentHandleName
:"Ljava/lang/Object;"
:argumentName
:"Ljava/lang/Object;"
};
areturn;
}
private static byte[] dumpAllStructuresNested() { public static Method main:"([Ljava/lang/String;)V"
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); stack 1 locals 2
classWriter.visit( {
V11, ACC_PUBLIC + ACC_SUPER, "jdk11/AllStructures$Nested", null, "java/lang/Object", null); ldc Dynamic REF_invokeStatic
classWriter.visitNestHost("jdk11/AllStructures"); :java/lang/invoke/LambdaMetafactory.metafactory
addDefaultConstructor(classWriter); :"(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;"
classWriter.visitEnd(); :run
return classWriter.toByteArray(); :"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) { private static synthetic Method lambda$main$0:"()V"
MethodVisitor methodVisitor = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); stack 2 locals 0
methodVisitor.visitCode(); {
methodVisitor.visitVarInsn(ALOAD, 0); getstatic Field java/lang/System.out:"Ljava/io/PrintStream;";
methodVisitor.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); ldc String "hello condy";
methodVisitor.visitInsn(RETURN); invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V";
methodVisitor.visitMaxs(0, 0); return;
methodVisitor.visitEnd();
}
} }
public static final InnerClass Lookup=
class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles;
} // end Class AllInstructions
...@@ -25,74 +25,29 @@ ...@@ -25,74 +25,29 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE. // THE POSSIBILITY OF SUCH DAMAGE.
package jdk11; 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),
* <p>TODO: remove this and use the JDK11 to compile equivalent classes, when it is released. * version 7 or more. Usage:
*
* java -jar asmtools.jar jasm AllStructures.jasm
* *
* @author Eric Bruneton * @author Eric Bruneton
*/ */
public class DumpAllInstructions implements Opcodes { super public class AllStructures$Nested
version 55:0
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);
MethodVisitor methodVisitor = public Method "<init>":"()V"
classWriter.visitMethod(ACC_PUBLIC, "m", "()Ljava/lang/Object;", null, null); stack 1 locals 1
methodVisitor.visitCode(); {
methodVisitor.visitLdcInsn( aload_0;
new ConstandDynamic( invokespecial Method java/lang/Object."<init>":"()V";
"name", return;
"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();
}
} }
NestHost AllStructures;
} // end Class AllStructures$Nested
...@@ -25,17 +25,29 @@ ...@@ -25,17 +25,29 @@
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE. // THE POSSIBILITY OF SUCH DAMAGE.
package jdk11; package jdk11;
/** /**
* By default with jdk 11, constant lambda are compiled using constant dynamic The classfile was * A class with JDK11 specific class file feature. A corresponding class file can be generated
* generated with the amber (branch condy-folding) compiler. with the OpenJDK asmtools (https://wiki.openjdk.java.net/display/CodeTools/asmtools),
* version 7 or more. Usage:
*
* java -jar asmtools.jar jasm AllStructures.jasm
* *
* <p>/usr/jdk/jdk-11/bin/javac -source 11 --enable-preview jdk11/LambdaCondy.java * @author Eric Bruneton
*/ */
public class LambdaCondy { super public class AllStructures
public static void main(String[] args) { version 55:0
Runnable r = () -> System.out.println("hello condy"); {
r.run();
}
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 // access flags 0x21
public class jdk11/AllInstructions { 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 // access flags 0x1
public <init>()V public <init>()V
...@@ -13,8 +16,27 @@ public class jdk11/AllInstructions { ...@@ -13,8 +16,27 @@ public class jdk11/AllInstructions {
// access flags 0x1 // access flags 0x1
public m()Ljava/lang/Object; 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 ARETURN
MAXSTACK = 1 MAXSTACK = 1
MAXLOCALS = 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 @@ ...@@ -2,6 +2,7 @@
// access flags 0x21 // access flags 0x21
public class jdk11/AllStructures$Nested { public class jdk11/AllStructures$Nested {
// compiled from: AllStructures$Nested.jasm
NESTHOST jdk11/AllStructures NESTHOST jdk11/AllStructures
// access flags 0x1 // access flags 0x1
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// access flags 0x21 // access flags 0x21
public class jdk11/AllStructures { public class jdk11/AllStructures {
// compiled from: AllStructures.jasm
NESTMEMBER jdk11/AllStructures$Nested NESTMEMBER jdk11/AllStructures$Nested
// access flags 0x1 // 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 { ...@@ -291,8 +291,7 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
.when( .when(
classParameter.isMoreRecentThan(apiParameter) classParameter.isMoreRecentThan(apiParameter)
&& classParameter != PrecompiledClass.JDK8_ARTIFICIAL_STRUCTURES && classParameter != PrecompiledClass.JDK8_ARTIFICIAL_STRUCTURES
&& classParameter != PrecompiledClass.JDK11_ALL_INSTRUCTIONS && classParameter != PrecompiledClass.JDK11_ALL_INSTRUCTIONS);
&& classParameter != PrecompiledClass.JDK11_LAMBDA_CONDY);
} }
/** /**
...@@ -430,7 +429,7 @@ public class ClassReaderTest extends AsmTest implements Opcodes { ...@@ -430,7 +429,7 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
@Test @Test
public void testPreviewMinorVersion() { public void testPreviewMinorVersion() {
ClassReader classReader = new ClassReader(PrecompiledClass.JDK11_LAMBDA_CONDY.getBytes()); ClassReader classReader = new ClassReader(PrecompiledClass.JDK11_ALL_INSTRUCTIONS.getBytes());
classReader.accept( classReader.accept(
new ClassVisitor(Opcodes.ASM7_EXPERIMENTAL) { new ClassVisitor(Opcodes.ASM7_EXPERIMENTAL) {
@Override @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