Skip to content

Commit

Permalink
8343547: Restore accidentally removed annotations in LambdaForm from …
Browse files Browse the repository at this point in the history
…ClassFile API port
  • Loading branch information
liach committed Nov 4, 2024
1 parent d26412e commit 1cf45fc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/java.base/share/classes/java/lang/invoke/ClassSpecializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.lang.classfile.*;
import java.lang.classfile.attribute.ExceptionsAttribute;
import java.lang.classfile.attribute.RuntimeVisibleAnnotationsAttribute;
import java.lang.classfile.attribute.SourceFileAttribute;
import java.lang.constant.ClassDesc;
import java.lang.constant.MethodTypeDesc;
Expand Down Expand Up @@ -68,6 +69,9 @@ abstract class ClassSpecializer<T,K,S extends ClassSpecializer<T,K,S>.SpeciesDat

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

private final Class<T> topClass;
private final Class<K> keyType;
Expand Down Expand Up @@ -615,15 +619,21 @@ Class<? extends T> generateConcreteSpeciesCode(String className, ClassSpecialize
byte[] generateConcreteSpeciesCodeFile(String className0, ClassSpecializer<T,K,S>.SpeciesData speciesData) {
final ClassDesc classDesc = ClassDesc.of(className0);
final ClassDesc superClassDesc = classDesc(speciesData.deriveSuperClass());
return ClassFile.of().build(classDesc, new Consumer<ClassBuilder>() {
return ClassFile.of().build(classDesc, new Consumer<>() {
@Override
public void accept(ClassBuilder clb) {
clb.withFlags(ACC_FINAL | ACC_SUPER)
.withSuperclass(superClassDesc)
.with(SourceFileAttribute.of(classDesc.displayName()))

// emit static types and BMH_SPECIES fields
.withField(sdFieldName, CD_SPECIES_DATA, ACC_STATIC);
.withField(sdFieldName, CD_SPECIES_DATA, new Consumer<>() {
@Override
public void accept(FieldBuilder fb) {
fb.withFlags(ACC_STATIC)
.with(STABLE_ANNOTATION);
}
});

// handy holder for dealing with groups of typed values (ctor arguments and fields)
class Var {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@ private boolean checkActualReceiver(CodeBuilder cob) {
// Suppress method in backtraces displayed to the user, mark this method as
// a compiled LambdaForm, then either force or prohibit inlining.
public static final RuntimeVisibleAnnotationsAttribute LF_DONTINLINE_ANNOTATIONS = RuntimeVisibleAnnotationsAttribute.of(HIDDEN, LF_COMPILED, DONTINLINE);
public static final RuntimeVisibleAnnotationsAttribute LF_DONTINLINE_PROFILE_ANNOTATIONS = RuntimeVisibleAnnotationsAttribute.of(HIDDEN, LF_COMPILED, DONTINLINE, INJECTEDPROFILE);
public static final RuntimeVisibleAnnotationsAttribute LF_FORCEINLINE_ANNOTATIONS = RuntimeVisibleAnnotationsAttribute.of(HIDDEN, LF_COMPILED, FORCEINLINE);
public static final RuntimeVisibleAnnotationsAttribute LF_FORCEINLINE_PROFILE_ANNOTATIONS = RuntimeVisibleAnnotationsAttribute.of(HIDDEN, LF_COMPILED, FORCEINLINE, INJECTEDPROFILE);

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

0 comments on commit 1cf45fc

Please sign in to comment.