Skip to content

Commit 1cf45fc

Browse files
committed
8343547: Restore accidentally removed annotations in LambdaForm from ClassFile API port
1 parent d26412e commit 1cf45fc

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import java.lang.classfile.*;
2929
import java.lang.classfile.attribute.ExceptionsAttribute;
30+
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
3031
import java.lang.classfile.attribute.SourceFileAttribute;
3132
import java.lang.constant.ClassDesc;
3233
import java.lang.constant.MethodTypeDesc;
@@ -68,6 +69,9 @@ abstract class ClassSpecializer<T,K,S extends ClassSpecializer<T,K,S>.SpeciesDat
6869

6970
private static final ClassDesc CD_LambdaForm = ClassOrInterfaceDescImpl.ofValidated("Ljava/lang/invoke/LambdaForm;");
7071
private static final ClassDesc CD_BoundMethodHandle = ClassOrInterfaceDescImpl.ofValidated("Ljava/lang/invoke/BoundMethodHandle;");
72+
private static final RuntimeVisibleAnnotationsAttribute STABLE_ANNOTATION = RuntimeVisibleAnnotationsAttribute.of(
73+
Annotation.of(ConstantUtils.referenceClassDesc(Stable.class))
74+
);
7175

7276
private final Class<T> topClass;
7377
private final Class<K> keyType;
@@ -615,15 +619,21 @@ Class<? extends T> generateConcreteSpeciesCode(String className, ClassSpecialize
615619
byte[] generateConcreteSpeciesCodeFile(String className0, ClassSpecializer<T,K,S>.SpeciesData speciesData) {
616620
final ClassDesc classDesc = ClassDesc.of(className0);
617621
final ClassDesc superClassDesc = classDesc(speciesData.deriveSuperClass());
618-
return ClassFile.of().build(classDesc, new Consumer<ClassBuilder>() {
622+
return ClassFile.of().build(classDesc, new Consumer<>() {
619623
@Override
620624
public void accept(ClassBuilder clb) {
621625
clb.withFlags(ACC_FINAL | ACC_SUPER)
622626
.withSuperclass(superClassDesc)
623627
.with(SourceFileAttribute.of(classDesc.displayName()))
624628

625629
// emit static types and BMH_SPECIES fields
626-
.withField(sdFieldName, CD_SPECIES_DATA, ACC_STATIC);
630+
.withField(sdFieldName, CD_SPECIES_DATA, new Consumer<>() {
631+
@Override
632+
public void accept(FieldBuilder fb) {
633+
fb.withFlags(ACC_STATIC)
634+
.with(STABLE_ANNOTATION);
635+
}
636+
});
627637

628638
// handy holder for dealing with groups of typed values (ctor arguments and fields)
629639
class Var {

src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,9 @@ private boolean checkActualReceiver(CodeBuilder cob) {
526526
// Suppress method in backtraces displayed to the user, mark this method as
527527
// a compiled LambdaForm, then either force or prohibit inlining.
528528
public static final RuntimeVisibleAnnotationsAttribute LF_DONTINLINE_ANNOTATIONS = RuntimeVisibleAnnotationsAttribute.of(HIDDEN, LF_COMPILED, DONTINLINE);
529+
public static final RuntimeVisibleAnnotationsAttribute LF_DONTINLINE_PROFILE_ANNOTATIONS = RuntimeVisibleAnnotationsAttribute.of(HIDDEN, LF_COMPILED, DONTINLINE, INJECTEDPROFILE);
529530
public static final RuntimeVisibleAnnotationsAttribute LF_FORCEINLINE_ANNOTATIONS = RuntimeVisibleAnnotationsAttribute.of(HIDDEN, LF_COMPILED, FORCEINLINE);
531+
public static final RuntimeVisibleAnnotationsAttribute LF_FORCEINLINE_PROFILE_ANNOTATIONS = RuntimeVisibleAnnotationsAttribute.of(HIDDEN, LF_COMPILED, FORCEINLINE, INJECTEDPROFILE);
530532

531533
/**
532534
* Generate an invoker method for the passed {@link LambdaForm}.
@@ -586,7 +588,11 @@ public void accept(CodeBuilder cob) {
586588
if (PROFILE_GWT) {
587589
assert(name.arguments[0] instanceof Name n &&
588590
n.refersTo(MethodHandleImpl.class, "profileBoolean"));
589-
mb.with(RuntimeVisibleAnnotationsAttribute.of(List.of(INJECTEDPROFILE)));
591+
if (lambdaForm.forceInline) {
592+
mb.with(LF_FORCEINLINE_PROFILE_ANNOTATIONS);
593+
} else {
594+
mb.with(LF_DONTINLINE_PROFILE_ANNOTATIONS);
595+
}
590596
}
591597
onStack = emitSelectAlternative(cob, name, lambdaForm.names[i+1]);
592598
i++; // skip MH.invokeBasic of the selectAlternative result

0 commit comments

Comments
 (0)