mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8294960: Convert java.base/java.lang.invoke package to use the Classfile API to generate lambdas and method handles
Co-authored-by: Claes Redestad <redestad@openjdk.org> Reviewed-by: redestad, liach
This commit is contained in:
parent
50bed6c67b
commit
01ee4241b7
11 changed files with 1286 additions and 1704 deletions
|
@ -25,10 +25,11 @@
|
|||
|
||||
package java.lang.invoke;
|
||||
|
||||
import jdk.internal.org.objectweb.asm.ClassWriter;
|
||||
import jdk.internal.org.objectweb.asm.Opcodes;
|
||||
import sun.invoke.util.Wrapper;
|
||||
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.classfile.attribute.SourceFileAttribute;
|
||||
import java.lang.constant.ClassDesc;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
@ -38,10 +39,10 @@ import java.util.TreeMap;
|
|||
import java.util.TreeSet;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.lang.classfile.ClassFile.*;
|
||||
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.*;
|
||||
import static java.lang.invoke.MethodTypeForm.*;
|
||||
|
||||
/**
|
||||
* Helper class to assist the GenerateJLIClassesPlugin to get access to
|
||||
|
@ -557,19 +558,14 @@ class GenerateJLIClassesHelper {
|
|||
* a class with a specified name.
|
||||
*/
|
||||
private static byte[] generateCodeBytesForLFs(String className, String[] names, LambdaForm[] forms) {
|
||||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
|
||||
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);
|
||||
|
||||
for (int i = 0; i < forms.length; i++) {
|
||||
InvokerBytecodeGenerator g
|
||||
= new InvokerBytecodeGenerator(className, names[i], forms[i], forms[i].methodType());
|
||||
g.setClassWriter(cw);
|
||||
g.addMethod();
|
||||
}
|
||||
|
||||
return cw.toByteArray();
|
||||
return ClassFile.of().build(ClassDesc.ofInternalName(className), clb -> {
|
||||
clb.withFlags(ACC_PRIVATE | ACC_FINAL | ACC_SUPER)
|
||||
.withSuperclass(InvokerBytecodeGenerator.INVOKER_SUPER_DESC)
|
||||
.with(SourceFileAttribute.of(className.substring(className.lastIndexOf('/') + 1)));
|
||||
for (int i = 0; i < forms.length; i++) {
|
||||
new InvokerBytecodeGenerator(className, names[i], forms[i], forms[i].methodType()).addMethod(clb);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static LambdaForm makeReinvokerFor(MethodType type) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue