Skip to content

Commit

Permalink
8294960: Convert java.base/java.lang.invoke package to use the Classf…
Browse files Browse the repository at this point in the history
…ile API to generate lambdas and method handles

Co-authored-by: Claes Redestad <[email protected]>
Reviewed-by: redestad, liach
  • Loading branch information
asotona and cl4es committed Jun 19, 2024
1 parent 50bed6c commit 01ee424
Show file tree
Hide file tree
Showing 11 changed files with 1,298 additions and 1,716 deletions.
502 changes: 219 additions & 283 deletions src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,10 +39,10 @@
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
Expand Down Expand Up @@ -557,19 +558,14 @@ static byte[] generateInvokersHolderClassBytes(String className,
* 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) {
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 01ee424

Please sign in to comment.