8050053: Improve caching of different invokers

Reviewed-by: vlivanov, psandoz
This commit is contained in:
John Rose 2014-09-10 19:19:48 +04:00 committed by Vladimir Ivanov
parent da56d3f6d1
commit 6a177f43fb
7 changed files with 168 additions and 140 deletions

View file

@ -102,7 +102,7 @@ public class CallSite {
*/
/*package-private*/
CallSite(MethodType type) {
target = type.invokers().uninitializedCallSite();
target = makeUninitializedCallSite(type);
}
/**
@ -217,21 +217,34 @@ public class CallSite {
}
private static final MethodHandle GET_TARGET;
private static final MethodHandle THROW_UCS;
static {
try {
GET_TARGET = IMPL_LOOKUP.
findVirtual(CallSite.class, "getTarget", MethodType.methodType(MethodHandle.class));
THROW_UCS = IMPL_LOOKUP.
findStatic(CallSite.class, "uninitializedCallSite", MethodType.methodType(Object.class, Object[].class));
} catch (ReflectiveOperationException e) {
throw newInternalError(e);
}
}
/** This guy is rolled into the default target if a MethodType is supplied to the constructor. */
/*package-private*/
static Empty uninitializedCallSite() {
private static Object uninitializedCallSite(Object... ignore) {
throw new IllegalStateException("uninitialized call site");
}
private MethodHandle makeUninitializedCallSite(MethodType targetType) {
MethodType basicType = targetType.basicType();
MethodHandle invoker = basicType.form().cachedMethodHandle(MethodTypeForm.MH_UNINIT_CS);
if (invoker == null) {
invoker = THROW_UCS.asType(basicType);
invoker = basicType.form().setCachedMethodHandle(MethodTypeForm.MH_UNINIT_CS, invoker);
}
// unchecked view is OK since no values will be received or returned
return invoker.viewAsType(targetType);
}
// unsafe stuff:
private static final long TARGET_OFFSET;
static {