Skip to content

8294960: Convert java.base/java.lang.invoke package to use the Classfile API to generate lambdas and method handles #17108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d193947
8294960: Convert java.base/java.lang.invoke package to use the Classf…
asotona Dec 13, 2023
57461c5
InvokerBytecodeGenerator::emit... improvements
asotona Dec 14, 2023
c1b413b
consolidation of descriptors handling
asotona Dec 14, 2023
52f08e1
performance improvements
asotona Dec 14, 2023
dc53d75
fixed InnerClassLambdaMetafactory for hidden caller classes
asotona Dec 15, 2023
0f356eb
added missing comment
asotona Dec 15, 2023
8fee456
Apply suggestions from code review
asotona Dec 18, 2023
098df10
Apply suggestions from code review
asotona Dec 18, 2023
1baa867
Merge branch 'master' into JDK-8294960-invoke
asotona Apr 4, 2024
500bb8f
Reversion of ClassBuilder changes
asotona Apr 4, 2024
9eade33
Merge branch 'master' into JDK-8294960-invoke
asotona Apr 17, 2024
304054b
applied suggested changes
asotona Apr 17, 2024
bae31c6
Merge branch 'master' into JDK-8294960-invoke
asotona Apr 18, 2024
d5cbbc6
Merge branch 'master' into JDK-8294960-invoke
asotona Apr 29, 2024
803c804
Deferred initialization of attributes map by moving into a holder class
asotona Apr 29, 2024
c2776be
Reduce init overhead of InvokeBytecodeGenerator and StackMapGenerator
cl4es Apr 29, 2024
ee3a70a
Remove stray MRE_LF_interpretWithArguments
cl4es Apr 29, 2024
75d4a09
Merge pull request #3 from cl4es/minor_init_improvements
asotona Apr 29, 2024
1717d0a
Only create box/unbox MethodRefEntries on request
cl4es Apr 29, 2024
1099de7
Merge pull request #4 from cl4es/boxunbox_holder
asotona Apr 29, 2024
107507b
Merge branch 'master' into JDK-8294960-invoke
asotona May 2, 2024
eea3652
fixed CodeBuilder use in j.l.invoke
asotona May 2, 2024
e1dbabc
Merge branch 'master' into JDK-8294960-invoke
asotona May 24, 2024
9360b0e
Merge branch 'master' into JDK-8294960-invoke
asotona Jun 5, 2024
019633b
Apply suggestions from code review
asotona Jun 6, 2024
902b02e
fixed imports
asotona Jun 6, 2024
e814749
use of jdk.internal.constant to improve performance
asotona Jun 6, 2024
c3d345c
fixed naming conventions
asotona Jun 6, 2024
f870a8d
reverted static initialization of ConstantPoolBuilder and CP entries
asotona Jun 6, 2024
9d10569
Update src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGe…
asotona Jun 17, 2024
cfd2d5a
applied suggested changes
asotona Jun 17, 2024
3aaf246
Merge branch 'master' into JDK-8294960-invoke
asotona Jun 17, 2024
80170d3
SerializationHostileMethod
cl4es Jun 18, 2024
9a63310
Inline Consumer<MethodBuilder> into generateSer.. method, move seldom…
cl4es Jun 18, 2024
1ce5360
Reduce gratuitous code movement
cl4es Jun 18, 2024
d336748
Merge pull request #8 from cl4es/serialization_hostile
asotona Jun 18, 2024
857b882
Inlined condy construction directly into CP entries
asotona Jun 18, 2024
ac20f1f
Update src/java.base/share/classes/java/lang/invoke/InnerClassLambdaM…
asotona Jun 19, 2024
257d66e
fixed sneaky completion typo
asotona Jun 19, 2024
16f6565
problem-listed runtime/ClassInitErrors/TestStackOverflowDuringInit.java
asotona Jun 19, 2024
6e851a5
removed empty line
asotona Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Choose a reason for hiding this comment

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

ACC_PRIVATE is not a valid access flag for a class, those only allow public or package access1:

Suggested change
clb.withFlags(ACC_PRIVATE | ACC_FINAL | ACC_SUPER)
clb.withFlags(ACC_FINAL | ACC_SUPER)

Footnotes

  1. See JVMS Table 4.1‑B

Copy link
Member

Choose a reason for hiding this comment

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

It has been there and also for injected invoker template. Can be safely ignored.

.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