Skip to content
Permalink
Browse files
8270949: Make dynamically generated classes with the class file versi…
…on of the current release

Reviewed-by: alanb
  • Loading branch information
Mandy Chung committed Jul 21, 2021
1 parent b7245c6 commit ddce47cd3cc44504984633cb2f21979b30f5a7fe
Showing 8 changed files with 20 additions and 7 deletions.
@@ -621,7 +621,7 @@ byte[] generateConcreteSpeciesCodeFile(String className0, ClassSpecializer<T,K,S

final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
final int NOT_ACC_PUBLIC = 0; // not ACC_PUBLIC
cw.visit(V1_6, NOT_ACC_PUBLIC + ACC_FINAL + ACC_SUPER, className, null, superClassName, null);
cw.visit(CLASSFILE_VERSION, NOT_ACC_PUBLIC + ACC_FINAL + ACC_SUPER, className, null, superClassName, null);

final String sourceFile = className.substring(className.lastIndexOf('.')+1);
cw.visitSource(sourceFile, null);
@@ -39,6 +39,7 @@
import java.util.stream.Stream;

import static java.lang.invoke.LambdaForm.BasicType.*;
import static java.lang.invoke.MethodHandleStatics.CLASSFILE_VERSION;
import static java.lang.invoke.MethodTypeForm.*;
import static java.lang.invoke.LambdaForm.Kind.*;

@@ -504,7 +505,7 @@ static byte[] generateInvokersHolderClassBytes(String className,
*/
private static byte[] generateCodeBytesForLFs(String className, String[] names, LambdaForm[] forms) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
cw.visit(Opcodes.V1_8, Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
cw.visit(CLASSFILE_VERSION, Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
className, null, InvokerBytecodeGenerator.INVOKER_SUPER_NAME, null);
cw.visitSource(className.substring(className.lastIndexOf('/') + 1), null);

@@ -26,6 +26,7 @@
package java.lang.invoke;

import jdk.internal.misc.CDS;
import jdk.internal.misc.VM;
import jdk.internal.org.objectweb.asm.*;
import sun.invoke.util.BytecodeDescriptor;
import sun.invoke.util.VerifyAccess;
@@ -56,7 +57,7 @@
* @see LambdaMetafactory
*/
/* package */ final class InnerClassLambdaMetafactory extends AbstractValidatingLambdaMetafactory {
private static final int CLASSFILE_VERSION = 59;
private static final int CLASSFILE_VERSION = VM.classFileVersion();
private static final String METHOD_DESCRIPTOR_VOID = Type.getMethodDescriptor(Type.VOID_TYPE);
private static final String JAVA_LANG_OBJECT = "java/lang/Object";
private static final String NAME_CTOR = "<init>";
@@ -340,7 +340,7 @@ private ClassWriter classFilePrologue() {
final int NOT_ACC_PUBLIC = 0; // not ACC_PUBLIC
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
setClassWriter(cw);
cw.visit(Opcodes.V1_8, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
cw.visit(CLASSFILE_VERSION, NOT_ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
className, null, INVOKER_SUPER_NAME, null);
cw.visitSource(SOURCE_PREFIX + name, null);
return cw;
@@ -1156,7 +1156,7 @@ private static byte[] generateInvokerTemplate() {
// return vamh.invokeExact(args);
// }
// }
cw.visit(52, ACC_PRIVATE | ACC_SUPER, "InjectedInvoker", null, "java/lang/Object", null);
cw.visit(CLASSFILE_VERSION, ACC_PRIVATE | ACC_SUPER, "InjectedInvoker", null, "java/lang/Object", null);

MethodVisitor mv = cw.visitMethod(ACC_STATIC, "invoke_V",
"(Ljava/lang/invoke/MethodHandle;[Ljava/lang/Object;)Ljava/lang/Object;",
@@ -27,6 +27,7 @@

import jdk.internal.misc.CDS;
import jdk.internal.misc.Unsafe;
import jdk.internal.misc.VM;
import sun.security.action.GetPropertyAction;

import java.util.Properties;
@@ -46,6 +47,7 @@ class MethodHandleStatics {
private MethodHandleStatics() { } // do not instantiate

static final Unsafe UNSAFE = Unsafe.getUnsafe();
static final int CLASSFILE_VERSION = VM.classFileVersion();

static final boolean DEBUG_METHOD_HANDLE_NAMES;
static final boolean DUMP_CLASS_FILES;
@@ -25,6 +25,7 @@

package java.lang.reflect;

import jdk.internal.misc.VM;
import jdk.internal.org.objectweb.asm.ClassWriter;
import jdk.internal.org.objectweb.asm.Label;
import jdk.internal.org.objectweb.asm.MethodVisitor;
@@ -55,7 +56,7 @@
* "generateProxyClass" method.
*/
final class ProxyGenerator extends ClassWriter {

private static final int CLASSFILE_VERSION = VM.classFileVersion();
private static final String JL_CLASS = "java/lang/Class";
private static final String JL_OBJECT = "java/lang/Object";
private static final String JL_THROWABLE = "java/lang/Throwable";
@@ -455,7 +456,7 @@ protected ClassLoader getClassLoader() {
* class file generation process.
*/
private byte[] generateClassFile() {
visit(V14, accessFlags, dotToSlash(className), null,
visit(CLASSFILE_VERSION, accessFlags, dotToSlash(className), null,
JLR_PROXY, typeNames(interfaces));

/*
@@ -151,6 +151,14 @@ public static boolean isDirectMemoryPageAligned() {
private static int classFileMinorVersion;
private static final int PREVIEW_MINOR_VERSION = 65535;

/**
* Returns the class file version of the current release.
* @jvms 4.1 Table 4.1-A. class file format major versions
*/
public static int classFileVersion() {
return classFileMajorVersion;
}

/**
* Tests if the given version is a supported {@code class}
* file version.

1 comment on commit ddce47c

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on ddce47c Jul 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.