Skip to content

Commit dc249be

Browse files
linzihao1999liach
authored andcommitted
8350462: MethodTypeForm.LF_INTERPRET can cache the MemberName instead
Reviewed-by: liach, jvernee
1 parent 799e5b3 commit dc249be

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

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

+7-14
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,6 @@ static LambdaForm create(int arity, Name[] names, boolean forceInline, Kind kind
371371
return create(arity, names, DEFAULT_RESULT, forceInline, DEFAULT_CUSTOMIZED, kind);
372372
}
373373

374-
private static LambdaForm createBlankForType(MethodType mt) {
375-
// Make a dummy blank lambda form.
376-
// It is used as a template for managing the invocation of similar forms that are non-empty.
377-
// Called only from getPreparedForm.
378-
LambdaForm form = new LambdaForm(0, 0, DEFAULT_FORCE_INLINE, DEFAULT_CUSTOMIZED, new Name[0], Kind.GENERIC);
379-
return form;
380-
}
381-
382374
private static int fixResult(int result, Name[] names) {
383375
if (result == LAST_RESULT)
384376
result = names.length - 1; // might still be void
@@ -785,14 +777,15 @@ public void prepare() {
785777
return;
786778
}
787779
MethodType mtype = methodType();
788-
LambdaForm prep = mtype.form().cachedLambdaForm(MethodTypeForm.LF_INTERPRET);
789-
if (prep == null) {
780+
MethodTypeForm form = mtype.form();
781+
782+
MemberName entry = form.cachedInterpretEntry();
783+
if (entry == null) {
790784
assert (isValidSignature(basicTypeSignature()));
791-
prep = LambdaForm.createBlankForType(mtype);
792-
prep.vmentry = InvokerBytecodeGenerator.generateLambdaFormInterpreterEntryPoint(mtype);
793-
prep = mtype.form().setCachedLambdaForm(MethodTypeForm.LF_INTERPRET, prep);
785+
entry = InvokerBytecodeGenerator.generateLambdaFormInterpreterEntryPoint(mtype);
786+
entry = form.setCachedInterpretEntry(entry);
794787
}
795-
this.vmentry = prep.vmentry;
788+
this.vmentry = entry;
796789
// TO DO: Maybe add invokeGeneric, invokeWithArguments
797790
}
798791

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ final class MethodTypeForm {
6464
// Cached lambda form information, for basic types only:
6565
private final Object[] lambdaForms;
6666

67+
private SoftReference<MemberName> interpretEntry;
68+
6769
// Indexes into lambdaForms:
6870
static final int
6971
LF_INVVIRTUAL = 0, // DMH invokeVirtual
@@ -72,7 +74,6 @@ final class MethodTypeForm {
7274
LF_NEWINVSPECIAL = 3,
7375
LF_INVINTERFACE = 4,
7476
LF_INVSTATIC_INIT = 5, // DMH invokeStatic with <clinit> barrier
75-
LF_INTERPRET = 6, // LF interpreter
7677
LF_REBIND = 7, // BoundMethodHandle
7778
LF_DELEGATE = 8, // DelegatingMethodHandle
7879
LF_DELEGATE_BLOCK_INLINING = 9, // Counting DelegatingMethodHandle w/ @DontInline
@@ -162,6 +163,19 @@ public synchronized LambdaForm setCachedLambdaForm(int which, LambdaForm form) {
162163
return form;
163164
}
164165

166+
public MemberName cachedInterpretEntry() {
167+
return (interpretEntry == null) ? null : interpretEntry.get();
168+
}
169+
170+
public synchronized MemberName setCachedInterpretEntry(MemberName mn) {
171+
MemberName prev = cachedInterpretEntry();
172+
if (prev != null) {
173+
return prev;
174+
}
175+
this.interpretEntry = new SoftReference<>(mn);
176+
return mn;
177+
}
178+
165179
/**
166180
* Build an MTF for a given type, which must have all references erased to Object.
167181
* This MTF will stand for that type and all un-erased variations.

0 commit comments

Comments
 (0)