Commit 4023cf5a authored by Remi Forax's avatar Remi Forax

Merge branch 'add-a-condy-test' into 'master'

recognize a preview features class (the class minor versopn should be V_PREVIEW) and add a test class

See merge request asm/asm!174
parents 0c4423ba 57b046dd
......@@ -131,7 +131,8 @@ 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_ALL_STRUCTURES_NESTED("jdk11.AllStructures$Nested"),
JDK11_LAMBDA_CONDY("jdk11.LambdaCondy");
private final String name;
......
// ASM: a very small and fast Java bytecode manipulation framework
// Copyright (c) 2000-2011 INRIA, France Telecom
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holders nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
// THE POSSIBILITY OF SUCH DAMAGE.
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.
*
* /usr/jdk/jdk-11/bin/javac -source 11 --enable-preview jdk11/LambdaCondy.java
*/
public class LambdaCondy {
public static void main(String[] args) {
Runnable r = () -> System.out.println("hello condy");
r.run();
}
}
// 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
}
......@@ -54,7 +54,8 @@ public interface Opcodes {
*/
@Deprecated int ASM7_EXPERIMENTAL = 1 << 24 | 7 << 16 | 0 << 8;
// Java ClassFile versions (the minor version is stored in the 16 most significant bits, and the
// Java ClassFile versions (the minor version is stored in the 16 most
// significant bits, and the
// major version in the 16 least significant bits).
int V1_1 = 3 << 16 | 45;
......@@ -69,10 +70,21 @@ public interface Opcodes {
int V10 = 0 << 16 | 54;
int V11 = 0 << 16 | 55;
/**
* Version flag indicating that the class is using 'preview' features.
*
* <p>{@code version & V_PREVIEW == V_PREVIEW} tests if a version is flagged with {@code
* V_PREVIEW}.
*/
int V_PREVIEW = 0xFFFF0000;
// Access flags values, defined in
// - https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.1-200-E.1
// - https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.5-200-A.1
// - https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.6-200-A.1
// -
// https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.1-200-E.1
// -
// https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.5-200-A.1
// -
// https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.6-200-A.1
// - https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.25
int ACC_PUBLIC = 0x0001; // class, field, method
......@@ -100,14 +112,17 @@ public interface Opcodes {
int ACC_MODULE = 0x8000; // class
// ASM specific access flags.
// WARNING: the 16 least significant bits must NOT be used, to avoid conflicts with standard
// access flags, and also to make sure that these flags are automatically filtered out when
// WARNING: the 16 least significant bits must NOT be used, to avoid conflicts
// with standard
// access flags, and also to make sure that these flags are automatically
// filtered out when
// written in class files (because access flags are stored using 16 bits only).
int ACC_DEPRECATED = 0x20000; // class, field, method
// Possible values for the type operand of the NEWARRAY instruction.
// See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html#jvms-6.5.newarray.
// See
// https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html#jvms-6.5.newarray.
int T_BOOLEAN = 4;
int T_CHAR = 5;
......@@ -118,8 +133,10 @@ public interface Opcodes {
int T_INT = 10;
int T_LONG = 11;
// Possible values for the reference_kind field of CONSTANT_MethodHandle_info structures.
// See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.4.8.
// Possible values for the reference_kind field of CONSTANT_MethodHandle_info
// structures.
// See
// https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.4.8.
int H_GETFIELD = 1;
int H_GETSTATIC = 2;
......@@ -162,7 +179,8 @@ public interface Opcodes {
*/
int F_SAME1 = 4;
// Standard stack map frame element types, used in {@link ClassVisitor#visitFrame}.
// Standard stack map frame element types, used in {@link
// ClassVisitor#visitFrame}.
Integer TOP = Frame.ITEM_TOP;
Integer INTEGER = Frame.ITEM_INTEGER;
......@@ -172,7 +190,8 @@ public interface Opcodes {
Integer NULL = Frame.ITEM_NULL;
Integer UNINITIALIZED_THIS = Frame.ITEM_UNINITIALIZED_THIS;
// The JVM opcode values (with the MethodVisitor method name used to visit them in comment, and
// The JVM opcode values (with the MethodVisitor method name used to visit them
// in comment, and
// where '-' means 'same method name as on the previous line').
// See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html.
......
......@@ -285,13 +285,14 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
ClassVisitor classVisitor = new EmptyClassVisitor(apiParameter.value());
// jdk8.ArtificialStructures contains structures which require ASM5, but only inside the method
// code. Here we skip the code, so this class can be read with ASM4. Likewise for
// jdk11.AllInstructions.
// jdk11.AllInstructions and jdk11.LambdaCondy.
assertThat(() -> classReader.accept(classVisitor, ClassReader.SKIP_CODE))
.succeedsOrThrows(RuntimeException.class)
.when(
classParameter.isMoreRecentThan(apiParameter)
&& classParameter != PrecompiledClass.JDK8_ARTIFICIAL_STRUCTURES
&& classParameter != PrecompiledClass.JDK11_ALL_INSTRUCTIONS);
&& classParameter != PrecompiledClass.JDK11_ALL_INSTRUCTIONS
&& classParameter != PrecompiledClass.JDK11_LAMBDA_CONDY);
}
/**
......@@ -427,6 +428,25 @@ public class ClassReaderTest extends AsmTest implements Opcodes {
assertTrue(success.get());
}
@Test
public void testPreviewMinorVersion() {
ClassReader classReader = new ClassReader(PrecompiledClass.JDK11_LAMBDA_CONDY.getBytes());
classReader.accept(
new ClassVisitor(Opcodes.ASM7_EXPERIMENTAL) {
@Override
public void visit(
int version,
int access,
String name,
String signature,
String superName,
String[] interfaces) {
assertTrue((version & Opcodes.V_PREVIEW) == Opcodes.V_PREVIEW);
}
},
0);
}
/** Tests that reading an invalid class throws an exception. */
@ParameterizedTest
@EnumSource(InvalidClass.class)
......
......@@ -67,6 +67,7 @@ public class ConstantsTest {
assertFalse(asmVersions.contains(field.getInt(null)));
asmVersions.add(field.getInt(null));
break;
case "V_PREVIEW":
case "V1_1":
case "V1_2":
case "V1_3":
......
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