8144723: MethodHandleImpl.initStatics is no longer needed
Reviewed-by: vlivanov, mhaupt, forax
This commit is contained in:
parent
fd27d80dbd
commit
4e062cde34
@ -83,7 +83,6 @@ private static CallSite bootstrapDynamic(MethodHandles.Lookup caller, String nam
|
|||||||
*/
|
*/
|
||||||
abstract
|
abstract
|
||||||
public class CallSite {
|
public class CallSite {
|
||||||
static { MethodHandleImpl.initStatics(); }
|
|
||||||
|
|
||||||
// The actual payload of this call site:
|
// The actual payload of this call site:
|
||||||
/*package-private*/
|
/*package-private*/
|
||||||
|
@ -1073,11 +1073,6 @@ import java.util.Objects;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static {
|
|
||||||
// System.out.println("Hello world! My methods are:");
|
|
||||||
// System.out.println(Factory.INSTANCE.getMethods(MemberName.class, true, null));
|
|
||||||
// }
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// Allow privileged classes outside of java.lang
|
// Allow privileged classes outside of java.lang
|
||||||
jdk.internal.misc.SharedSecrets.setJavaLangInvokeAccess(new jdk.internal.misc.JavaLangInvokeAccess() {
|
jdk.internal.misc.SharedSecrets.setJavaLangInvokeAccess(new jdk.internal.misc.JavaLangInvokeAccess() {
|
||||||
|
@ -420,7 +420,6 @@ mh.invokeExact(System.out, "Hello, world.");
|
|||||||
* @author John Rose, JSR 292 EG
|
* @author John Rose, JSR 292 EG
|
||||||
*/
|
*/
|
||||||
public abstract class MethodHandle {
|
public abstract class MethodHandle {
|
||||||
static { MethodHandleImpl.initStatics(); }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal marker interface which distinguishes (to the Java compiler)
|
* Internal marker interface which distinguishes (to the Java compiler)
|
||||||
|
@ -32,7 +32,6 @@ import java.util.Collections;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import sun.invoke.empty.Empty;
|
import sun.invoke.empty.Empty;
|
||||||
import sun.invoke.util.ValueConversions;
|
import sun.invoke.util.ValueConversions;
|
||||||
@ -65,11 +64,6 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
|||||||
|
|
||||||
/// Factory methods to create method handles:
|
/// Factory methods to create method handles:
|
||||||
|
|
||||||
static void initStatics() {
|
|
||||||
// Trigger selected static initializations.
|
|
||||||
MemberName.Factory.INSTANCE.getClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
static MethodHandle makeArrayElementAccessor(Class<?> arrayClass, boolean isSetter) {
|
static MethodHandle makeArrayElementAccessor(Class<?> arrayClass, boolean isSetter) {
|
||||||
if (arrayClass == Object[].class)
|
if (arrayClass == Object[].class)
|
||||||
return (isSetter ? ArrayAccessor.OBJECT_ARRAY_SETTER : ArrayAccessor.OBJECT_ARRAY_GETTER);
|
return (isSetter ? ArrayAccessor.OBJECT_ARRAY_SETTER : ArrayAccessor.OBJECT_ARRAY_GETTER);
|
||||||
@ -700,33 +694,43 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
|||||||
MethodHandle makeBlockInliningWrapper(MethodHandle target) {
|
MethodHandle makeBlockInliningWrapper(MethodHandle target) {
|
||||||
LambdaForm lform;
|
LambdaForm lform;
|
||||||
if (DONT_INLINE_THRESHOLD > 0) {
|
if (DONT_INLINE_THRESHOLD > 0) {
|
||||||
lform = PRODUCE_BLOCK_INLINING_FORM.apply(target);
|
lform = Makers.PRODUCE_BLOCK_INLINING_FORM.apply(target);
|
||||||
} else {
|
} else {
|
||||||
lform = PRODUCE_REINVOKER_FORM.apply(target);
|
lform = Makers.PRODUCE_REINVOKER_FORM.apply(target);
|
||||||
}
|
}
|
||||||
return new CountingWrapper(target, lform,
|
return new CountingWrapper(target, lform,
|
||||||
PRODUCE_BLOCK_INLINING_FORM, PRODUCE_REINVOKER_FORM,
|
Makers.PRODUCE_BLOCK_INLINING_FORM, Makers.PRODUCE_REINVOKER_FORM,
|
||||||
DONT_INLINE_THRESHOLD);
|
DONT_INLINE_THRESHOLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Constructs reinvoker lambda form which block inlining during JIT-compilation for a particular method handle */
|
private final static class Makers {
|
||||||
private static final Function<MethodHandle, LambdaForm> PRODUCE_BLOCK_INLINING_FORM = new Function<MethodHandle, LambdaForm>() {
|
/** Constructs reinvoker lambda form which block inlining during JIT-compilation for a particular method handle */
|
||||||
@Override
|
static final Function<MethodHandle, LambdaForm> PRODUCE_BLOCK_INLINING_FORM = new Function<MethodHandle, LambdaForm>() {
|
||||||
public LambdaForm apply(MethodHandle target) {
|
@Override
|
||||||
return DelegatingMethodHandle.makeReinvokerForm(target,
|
public LambdaForm apply(MethodHandle target) {
|
||||||
MethodTypeForm.LF_DELEGATE_BLOCK_INLINING, CountingWrapper.class, "reinvoker.dontInline", false,
|
return DelegatingMethodHandle.makeReinvokerForm(target,
|
||||||
DelegatingMethodHandle.NF_getTarget, CountingWrapper.NF_maybeStopCounting);
|
MethodTypeForm.LF_DELEGATE_BLOCK_INLINING, CountingWrapper.class, "reinvoker.dontInline", false,
|
||||||
}
|
DelegatingMethodHandle.NF_getTarget, CountingWrapper.NF_maybeStopCounting);
|
||||||
};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/** Constructs simple reinvoker lambda form for a particular method handle */
|
/** Constructs simple reinvoker lambda form for a particular method handle */
|
||||||
private static final Function<MethodHandle, LambdaForm> PRODUCE_REINVOKER_FORM = new Function<MethodHandle, LambdaForm>() {
|
static final Function<MethodHandle, LambdaForm> PRODUCE_REINVOKER_FORM = new Function<MethodHandle, LambdaForm>() {
|
||||||
@Override
|
@Override
|
||||||
public LambdaForm apply(MethodHandle target) {
|
public LambdaForm apply(MethodHandle target) {
|
||||||
return DelegatingMethodHandle.makeReinvokerForm(target,
|
return DelegatingMethodHandle.makeReinvokerForm(target,
|
||||||
MethodTypeForm.LF_DELEGATE, DelegatingMethodHandle.class, DelegatingMethodHandle.NF_getTarget);
|
MethodTypeForm.LF_DELEGATE, DelegatingMethodHandle.class, DelegatingMethodHandle.NF_getTarget);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Maker of type-polymorphic varargs */
|
||||||
|
static final ClassValue<MethodHandle[]> TYPED_COLLECTORS = new ClassValue<MethodHandle[]>() {
|
||||||
|
@Override
|
||||||
|
protected MethodHandle[] computeValue(Class<?> type) {
|
||||||
|
return new MethodHandle[MAX_JVM_ARITY + 1];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counting method handle. It has 2 states: counting and non-counting.
|
* Counting method handle. It has 2 states: counting and non-counting.
|
||||||
@ -1527,15 +1531,6 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
|||||||
return MethodHandles.collectArguments(rightFill, 0, midFill);
|
return MethodHandles.collectArguments(rightFill, 0, midFill);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Type-polymorphic version of varargs maker.
|
|
||||||
private static final ClassValue<MethodHandle[]> TYPED_COLLECTORS
|
|
||||||
= new ClassValue<MethodHandle[]>() {
|
|
||||||
@Override
|
|
||||||
protected MethodHandle[] computeValue(Class<?> type) {
|
|
||||||
return new MethodHandle[256];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
static final int MAX_JVM_ARITY = 255; // limit imposed by the JVM
|
static final int MAX_JVM_ARITY = 255; // limit imposed by the JVM
|
||||||
|
|
||||||
/** Return a method handle that takes the indicated number of
|
/** Return a method handle that takes the indicated number of
|
||||||
@ -1557,7 +1552,7 @@ import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP;
|
|||||||
if (elemType == Object.class)
|
if (elemType == Object.class)
|
||||||
return varargsArray(nargs);
|
return varargsArray(nargs);
|
||||||
// other cases: primitive arrays, subtypes of Object[]
|
// other cases: primitive arrays, subtypes of Object[]
|
||||||
MethodHandle cache[] = TYPED_COLLECTORS.get(elemType);
|
MethodHandle cache[] = Makers.TYPED_COLLECTORS.get(elemType);
|
||||||
MethodHandle mh = nargs < cache.length ? cache[nargs] : null;
|
MethodHandle mh = nargs < cache.length ? cache[nargs] : null;
|
||||||
if (mh != null) return mh;
|
if (mh != null) return mh;
|
||||||
if (nargs == 0) {
|
if (nargs == 0) {
|
||||||
|
@ -87,9 +87,6 @@ class MethodHandleNatives {
|
|||||||
private static native void registerNatives();
|
private static native void registerNatives();
|
||||||
static {
|
static {
|
||||||
registerNatives();
|
registerNatives();
|
||||||
|
|
||||||
// The JVM calls MethodHandleNatives.<clinit>. Cascade the <clinit> calls as needed:
|
|
||||||
MethodHandleImpl.initStatics();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +61,7 @@ public class MethodHandles {
|
|||||||
private MethodHandles() { } // do not instantiate
|
private MethodHandles() { } // do not instantiate
|
||||||
|
|
||||||
private static final MemberName.Factory IMPL_NAMES = MemberName.getFactory();
|
private static final MemberName.Factory IMPL_NAMES = MemberName.getFactory();
|
||||||
static { MethodHandleImpl.initStatics(); }
|
|
||||||
// See IMPL_LOOKUP below.
|
// See IMPL_LOOKUP below.
|
||||||
|
|
||||||
//// Method handle creation from ordinary methods.
|
//// Method handle creation from ordinary methods.
|
||||||
|
Loading…
Reference in New Issue
Block a user