8044638: Tidy up Nashorn codebase for code standards
Reviewed-by: lagergren, sundar
This commit is contained in:
parent
7898fee89e
commit
5ec014a881
@ -31,29 +31,29 @@ import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;
|
|||||||
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_STATIC;
|
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_STATIC;
|
||||||
import static jdk.internal.org.objectweb.asm.Opcodes.H_INVOKESTATIC;
|
import static jdk.internal.org.objectweb.asm.Opcodes.H_INVOKESTATIC;
|
||||||
import static jdk.internal.org.objectweb.asm.Opcodes.H_INVOKEVIRTUAL;
|
import static jdk.internal.org.objectweb.asm.Opcodes.H_INVOKEVIRTUAL;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ACCESSORPROPERTY_CREATE;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ACCESSORPROPERTY_CREATE_DESC;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ACCESSORPROPERTY_TYPE;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ARRAYLIST_INIT_DESC;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ARRAYLIST_TYPE;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.CLINIT;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.CLINIT;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTIONS_EMPTY_LIST;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTIONS_TYPE;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTION_ADD;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTION_ADD_DESC;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTION_TYPE;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.GETTER_PREFIX;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.GETTER_PREFIX;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.GET_CLASS_NAME;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.GET_CLASS_NAME;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.GET_CLASS_NAME_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.GET_CLASS_NAME_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ACCESSORPROPERTY_CREATE;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ACCESSORPROPERTY_CREATE_DESC;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ACCESSORPROPERTY_TYPE;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.LIST_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.LIST_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ARRAYLIST_TYPE;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.ARRAYLIST_INIT_DESC;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTION_TYPE;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTION_ADD;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTION_ADD_DESC;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTIONS_TYPE;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.COLLECTIONS_EMPTY_LIST;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION_SPECS_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION_SPECS_DESC;
|
||||||
|
@ -32,9 +32,9 @@ import static jdk.internal.org.objectweb.asm.Opcodes.V1_7;
|
|||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.CONSTRUCTOR_SUFFIX;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.CONSTRUCTOR_SUFFIX;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_TYPE;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_TYPE;
|
||||||
|
@ -31,9 +31,9 @@ import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER;
|
|||||||
import static jdk.internal.org.objectweb.asm.Opcodes.V1_7;
|
import static jdk.internal.org.objectweb.asm.Opcodes.V1_7;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.DEFAULT_INIT_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.INIT;
|
||||||
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_DESC;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_FIELD_NAME;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.OBJECT_DESC;
|
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_TYPE;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_TYPE;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPE_SUFFIX;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPE_SUFFIX;
|
||||||
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTOBJECT_INIT_DESC;
|
import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTOBJECT_INIT_DESC;
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
package jdk.nashorn.internal.tools.nasgen;
|
package jdk.nashorn.internal.tools.nasgen;
|
||||||
|
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import jdk.internal.org.objectweb.asm.Type;
|
import jdk.internal.org.objectweb.asm.Type;
|
||||||
|
@ -88,7 +88,6 @@ import java.lang.invoke.MethodHandles;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||||
import jdk.internal.dynalink.support.AbstractRelinkableCallSite;
|
import jdk.internal.dynalink.support.AbstractRelinkableCallSite;
|
||||||
import jdk.internal.dynalink.support.Lookup;
|
import jdk.internal.dynalink.support.Lookup;
|
||||||
@ -132,7 +131,7 @@ public class ChainedCallSite extends AbstractRelinkableCallSite {
|
|||||||
* Creates a new chained call site.
|
* Creates a new chained call site.
|
||||||
* @param descriptor the descriptor for the call site.
|
* @param descriptor the descriptor for the call site.
|
||||||
*/
|
*/
|
||||||
public ChainedCallSite(CallSiteDescriptor descriptor) {
|
public ChainedCallSite(final CallSiteDescriptor descriptor) {
|
||||||
super(descriptor);
|
super(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,16 +145,16 @@ public class ChainedCallSite extends AbstractRelinkableCallSite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void relink(GuardedInvocation guardedInvocation, MethodHandle fallback) {
|
public void relink(final GuardedInvocation guardedInvocation, final MethodHandle fallback) {
|
||||||
relinkInternal(guardedInvocation, fallback, false, false);
|
relinkInternal(guardedInvocation, fallback, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resetAndRelink(GuardedInvocation guardedInvocation, MethodHandle fallback) {
|
public void resetAndRelink(final GuardedInvocation guardedInvocation, final MethodHandle fallback) {
|
||||||
relinkInternal(guardedInvocation, fallback, true, false);
|
relinkInternal(guardedInvocation, fallback, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodHandle relinkInternal(GuardedInvocation invocation, MethodHandle relink, boolean reset, boolean removeCatches) {
|
private MethodHandle relinkInternal(final GuardedInvocation invocation, final MethodHandle relink, final boolean reset, final boolean removeCatches) {
|
||||||
final LinkedList<GuardedInvocation> currentInvocations = invocations.get();
|
final LinkedList<GuardedInvocation> currentInvocations = invocations.get();
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
final LinkedList<GuardedInvocation> newInvocations =
|
final LinkedList<GuardedInvocation> newInvocations =
|
||||||
@ -163,7 +162,7 @@ public class ChainedCallSite extends AbstractRelinkableCallSite {
|
|||||||
|
|
||||||
// First, prune the chain of invalidated switchpoints, we always do this
|
// First, prune the chain of invalidated switchpoints, we always do this
|
||||||
// We also remove any catches if the remove catches flag is set
|
// We also remove any catches if the remove catches flag is set
|
||||||
for(Iterator<GuardedInvocation> it = newInvocations.iterator(); it.hasNext();) {
|
for(final Iterator<GuardedInvocation> it = newInvocations.iterator(); it.hasNext();) {
|
||||||
final GuardedInvocation inv = it.next();
|
final GuardedInvocation inv = it.next();
|
||||||
if(inv.hasBeenInvalidated() || (removeCatches && inv.getException() != null)) {
|
if(inv.hasBeenInvalidated() || (removeCatches && inv.getException() != null)) {
|
||||||
it.remove();
|
it.remove();
|
||||||
@ -187,7 +186,7 @@ public class ChainedCallSite extends AbstractRelinkableCallSite {
|
|||||||
|
|
||||||
// Fold the new chain
|
// Fold the new chain
|
||||||
MethodHandle target = relink;
|
MethodHandle target = relink;
|
||||||
for(GuardedInvocation inv: newInvocations) {
|
for(final GuardedInvocation inv: newInvocations) {
|
||||||
target = inv.compose(target, pruneAndInvokeSwitchPoints, pruneAndInvokeCatches);
|
target = inv.compose(target, pruneAndInvokeSwitchPoints, pruneAndInvokeCatches);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +221,7 @@ public class ChainedCallSite extends AbstractRelinkableCallSite {
|
|||||||
* @param relink the ultimate fallback for the chain (the {@code DynamicLinker}'s relink).
|
* @param relink the ultimate fallback for the chain (the {@code DynamicLinker}'s relink).
|
||||||
* @return a method handle for prune-and-invoke
|
* @return a method handle for prune-and-invoke
|
||||||
*/
|
*/
|
||||||
private MethodHandle makePruneAndInvokeMethod(MethodHandle relink, MethodHandle prune) {
|
private MethodHandle makePruneAndInvokeMethod(final MethodHandle relink, final MethodHandle prune) {
|
||||||
// Bind prune to (this, relink)
|
// Bind prune to (this, relink)
|
||||||
final MethodHandle boundPrune = MethodHandles.insertArguments(prune, 0, this, relink);
|
final MethodHandle boundPrune = MethodHandles.insertArguments(prune, 0, this, relink);
|
||||||
// Make it ignore all incoming arguments
|
// Make it ignore all incoming arguments
|
||||||
@ -232,7 +231,7 @@ public class ChainedCallSite extends AbstractRelinkableCallSite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private MethodHandle prune(MethodHandle relink, final boolean catches) {
|
private MethodHandle prune(final MethodHandle relink, final boolean catches) {
|
||||||
return relinkInternal(null, relink, false, catches);
|
return relinkInternal(null, relink, false, catches);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ public class DefaultBootstrapper {
|
|||||||
* @param type the method signature at the call site
|
* @param type the method signature at the call site
|
||||||
* @return a new {@link MonomorphicCallSite} linked with the default dynamic linker.
|
* @return a new {@link MonomorphicCallSite} linked with the default dynamic linker.
|
||||||
*/
|
*/
|
||||||
public static CallSite bootstrap(MethodHandles.Lookup caller, String name, MethodType type) {
|
public static CallSite bootstrap(final MethodHandles.Lookup caller, final String name, final MethodType type) {
|
||||||
return bootstrapInternal(caller, name, type);
|
return bootstrapInternal(caller, name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,11 +133,11 @@ public class DefaultBootstrapper {
|
|||||||
* @param type the method signature at the call site
|
* @param type the method signature at the call site
|
||||||
* @return a new {@link MonomorphicCallSite} linked with the default dynamic linker.
|
* @return a new {@link MonomorphicCallSite} linked with the default dynamic linker.
|
||||||
*/
|
*/
|
||||||
public static CallSite publicBootstrap(MethodHandles.Lookup caller, String name, MethodType type) {
|
public static CallSite publicBootstrap(final MethodHandles.Lookup caller, final String name, final MethodType type) {
|
||||||
return bootstrapInternal(MethodHandles.publicLookup(), name, type);
|
return bootstrapInternal(MethodHandles.publicLookup(), name, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CallSite bootstrapInternal(MethodHandles.Lookup caller, String name, MethodType type) {
|
private static CallSite bootstrapInternal(final MethodHandles.Lookup caller, final String name, final MethodType type) {
|
||||||
return dynamicLinker.link(new MonomorphicCallSite(CallSiteDescriptorFactory.create(caller, name, type)));
|
return dynamicLinker.link(new MonomorphicCallSite(CallSiteDescriptorFactory.create(caller, name, type)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,8 +159,8 @@ public class DynamicLinker {
|
|||||||
* @param prelinkFilter see {@link DynamicLinkerFactory#setPrelinkFilter(GuardedInvocationFilter)}
|
* @param prelinkFilter see {@link DynamicLinkerFactory#setPrelinkFilter(GuardedInvocationFilter)}
|
||||||
* @param runtimeContextArgCount see {@link DynamicLinkerFactory#setRuntimeContextArgCount(int)}
|
* @param runtimeContextArgCount see {@link DynamicLinkerFactory#setRuntimeContextArgCount(int)}
|
||||||
*/
|
*/
|
||||||
DynamicLinker(LinkerServices linkerServices, GuardedInvocationFilter prelinkFilter, int runtimeContextArgCount,
|
DynamicLinker(final LinkerServices linkerServices, final GuardedInvocationFilter prelinkFilter, final int runtimeContextArgCount,
|
||||||
boolean syncOnRelink, int unstableRelinkThreshold) {
|
final boolean syncOnRelink, final int unstableRelinkThreshold) {
|
||||||
if(runtimeContextArgCount < 0) {
|
if(runtimeContextArgCount < 0) {
|
||||||
throw new IllegalArgumentException("runtimeContextArgCount < 0");
|
throw new IllegalArgumentException("runtimeContextArgCount < 0");
|
||||||
}
|
}
|
||||||
@ -201,7 +201,7 @@ public class DynamicLinker {
|
|||||||
private static final MethodHandle RELINK = Lookup.findOwnSpecial(MethodHandles.lookup(), RELINK_METHOD_NAME,
|
private static final MethodHandle RELINK = Lookup.findOwnSpecial(MethodHandles.lookup(), RELINK_METHOD_NAME,
|
||||||
MethodHandle.class, RelinkableCallSite.class, int.class, Object[].class);
|
MethodHandle.class, RelinkableCallSite.class, int.class, Object[].class);
|
||||||
|
|
||||||
private MethodHandle createRelinkAndInvokeMethod(final RelinkableCallSite callSite, int relinkCount) {
|
private MethodHandle createRelinkAndInvokeMethod(final RelinkableCallSite callSite, final int relinkCount) {
|
||||||
// Make a bound MH of invoke() for this linker and call site
|
// Make a bound MH of invoke() for this linker and call site
|
||||||
final MethodHandle boundRelinker = MethodHandles.insertArguments(RELINK, 0, this, callSite, Integer.valueOf(
|
final MethodHandle boundRelinker = MethodHandles.insertArguments(RELINK, 0, this, callSite, Integer.valueOf(
|
||||||
relinkCount));
|
relinkCount));
|
||||||
@ -221,7 +221,7 @@ public class DynamicLinker {
|
|||||||
* @throws Exception rethrows any exception thrown by the linkers
|
* @throws Exception rethrows any exception thrown by the linkers
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private MethodHandle relink(RelinkableCallSite callSite, int relinkCount, Object... arguments) throws Exception {
|
private MethodHandle relink(final RelinkableCallSite callSite, final int relinkCount, final Object... arguments) throws Exception {
|
||||||
final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
|
final CallSiteDescriptor callSiteDescriptor = callSite.getDescriptor();
|
||||||
final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
|
final boolean unstableDetectionEnabled = unstableRelinkThreshold > 0;
|
||||||
final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
|
final boolean callSiteUnstable = unstableDetectionEnabled && relinkCount >= unstableRelinkThreshold;
|
||||||
|
@ -137,7 +137,7 @@ public class DynamicLinkerFactory {
|
|||||||
*
|
*
|
||||||
* @param classLoader the class loader used for the autodiscovery of available linkers.
|
* @param classLoader the class loader used for the autodiscovery of available linkers.
|
||||||
*/
|
*/
|
||||||
public void setClassLoader(ClassLoader classLoader) {
|
public void setClassLoader(final ClassLoader classLoader) {
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
classLoaderExplicitlySet = true;
|
classLoaderExplicitlySet = true;
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ public class DynamicLinkerFactory {
|
|||||||
* @param prioritizedLinkers the list of prioritized linkers. Null can be passed to indicate no prioritized linkers
|
* @param prioritizedLinkers the list of prioritized linkers. Null can be passed to indicate no prioritized linkers
|
||||||
* (this is also the default value).
|
* (this is also the default value).
|
||||||
*/
|
*/
|
||||||
public void setPrioritizedLinkers(List<? extends GuardingDynamicLinker> prioritizedLinkers) {
|
public void setPrioritizedLinkers(final List<? extends GuardingDynamicLinker> prioritizedLinkers) {
|
||||||
this.prioritizedLinkers =
|
this.prioritizedLinkers =
|
||||||
prioritizedLinkers == null ? null : new ArrayList<>(prioritizedLinkers);
|
prioritizedLinkers == null ? null : new ArrayList<>(prioritizedLinkers);
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ public class DynamicLinkerFactory {
|
|||||||
*
|
*
|
||||||
* @param prioritizedLinkers a list of prioritized linkers.
|
* @param prioritizedLinkers a list of prioritized linkers.
|
||||||
*/
|
*/
|
||||||
public void setPrioritizedLinkers(GuardingDynamicLinker... prioritizedLinkers) {
|
public void setPrioritizedLinkers(final GuardingDynamicLinker... prioritizedLinkers) {
|
||||||
setPrioritizedLinkers(Arrays.asList(prioritizedLinkers));
|
setPrioritizedLinkers(Arrays.asList(prioritizedLinkers));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ public class DynamicLinkerFactory {
|
|||||||
* @param prioritizedLinker the single prioritized linker. Must not be null.
|
* @param prioritizedLinker the single prioritized linker. Must not be null.
|
||||||
* @throws IllegalArgumentException if null is passed.
|
* @throws IllegalArgumentException if null is passed.
|
||||||
*/
|
*/
|
||||||
public void setPrioritizedLinker(GuardingDynamicLinker prioritizedLinker) {
|
public void setPrioritizedLinker(final GuardingDynamicLinker prioritizedLinker) {
|
||||||
if(prioritizedLinker == null) {
|
if(prioritizedLinker == null) {
|
||||||
throw new IllegalArgumentException("prioritizedLinker == null");
|
throw new IllegalArgumentException("prioritizedLinker == null");
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ public class DynamicLinkerFactory {
|
|||||||
* @param fallbackLinkers the list of fallback linkers. Can be empty to indicate the caller wishes to set no
|
* @param fallbackLinkers the list of fallback linkers. Can be empty to indicate the caller wishes to set no
|
||||||
* fallback linkers.
|
* fallback linkers.
|
||||||
*/
|
*/
|
||||||
public void setFallbackLinkers(List<? extends GuardingDynamicLinker> fallbackLinkers) {
|
public void setFallbackLinkers(final List<? extends GuardingDynamicLinker> fallbackLinkers) {
|
||||||
this.fallbackLinkers = fallbackLinkers == null ? null : new ArrayList<>(fallbackLinkers);
|
this.fallbackLinkers = fallbackLinkers == null ? null : new ArrayList<>(fallbackLinkers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ public class DynamicLinkerFactory {
|
|||||||
* @param fallbackLinkers the list of fallback linkers. Can be empty to indicate the caller wishes to set no
|
* @param fallbackLinkers the list of fallback linkers. Can be empty to indicate the caller wishes to set no
|
||||||
* fallback linkers. If it is left as null, the standard fallback {@link BeansLinker} will be used.
|
* fallback linkers. If it is left as null, the standard fallback {@link BeansLinker} will be used.
|
||||||
*/
|
*/
|
||||||
public void setFallbackLinkers(GuardingDynamicLinker... fallbackLinkers) {
|
public void setFallbackLinkers(final GuardingDynamicLinker... fallbackLinkers) {
|
||||||
setFallbackLinkers(Arrays.asList(fallbackLinkers));
|
setFallbackLinkers(Arrays.asList(fallbackLinkers));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ public class DynamicLinkerFactory {
|
|||||||
*
|
*
|
||||||
* @param runtimeContextArgCount the number of language runtime context arguments in call sites.
|
* @param runtimeContextArgCount the number of language runtime context arguments in call sites.
|
||||||
*/
|
*/
|
||||||
public void setRuntimeContextArgCount(int runtimeContextArgCount) {
|
public void setRuntimeContextArgCount(final int runtimeContextArgCount) {
|
||||||
if(runtimeContextArgCount < 0) {
|
if(runtimeContextArgCount < 0) {
|
||||||
throw new IllegalArgumentException("runtimeContextArgCount < 0");
|
throw new IllegalArgumentException("runtimeContextArgCount < 0");
|
||||||
}
|
}
|
||||||
@ -229,7 +229,7 @@ public class DynamicLinkerFactory {
|
|||||||
* multithreaded execution of dynamically linked code.
|
* multithreaded execution of dynamically linked code.
|
||||||
* @param syncOnRelink true for invoking sync on relink, false otherwise.
|
* @param syncOnRelink true for invoking sync on relink, false otherwise.
|
||||||
*/
|
*/
|
||||||
public void setSyncOnRelink(boolean syncOnRelink) {
|
public void setSyncOnRelink(final boolean syncOnRelink) {
|
||||||
this.syncOnRelink = syncOnRelink;
|
this.syncOnRelink = syncOnRelink;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +240,7 @@ public class DynamicLinkerFactory {
|
|||||||
* call sites will never be considered unstable.
|
* call sites will never be considered unstable.
|
||||||
* @see LinkRequest#isCallSiteUnstable()
|
* @see LinkRequest#isCallSiteUnstable()
|
||||||
*/
|
*/
|
||||||
public void setUnstableRelinkThreshold(int unstableRelinkThreshold) {
|
public void setUnstableRelinkThreshold(final int unstableRelinkThreshold) {
|
||||||
if(unstableRelinkThreshold < 0) {
|
if(unstableRelinkThreshold < 0) {
|
||||||
throw new IllegalArgumentException("unstableRelinkThreshold < 0");
|
throw new IllegalArgumentException("unstableRelinkThreshold < 0");
|
||||||
}
|
}
|
||||||
@ -254,7 +254,7 @@ public class DynamicLinkerFactory {
|
|||||||
* When not set explicitly, {@link DefaultPrelinkFilter} will be used.
|
* When not set explicitly, {@link DefaultPrelinkFilter} will be used.
|
||||||
* @param prelinkFilter the pre-link filter for the dynamic linker.
|
* @param prelinkFilter the pre-link filter for the dynamic linker.
|
||||||
*/
|
*/
|
||||||
public void setPrelinkFilter(GuardedInvocationFilter prelinkFilter) {
|
public void setPrelinkFilter(final GuardedInvocationFilter prelinkFilter) {
|
||||||
this.prelinkFilter = prelinkFilter;
|
this.prelinkFilter = prelinkFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -289,7 +289,7 @@ public class DynamicLinkerFactory {
|
|||||||
// ... prioritized linkers, ...
|
// ... prioritized linkers, ...
|
||||||
linkers.addAll(prioritizedLinkers);
|
linkers.addAll(prioritizedLinkers);
|
||||||
// ... filtered discovered linkers, ...
|
// ... filtered discovered linkers, ...
|
||||||
for(GuardingDynamicLinker linker: discovered) {
|
for(final GuardingDynamicLinker linker: discovered) {
|
||||||
if(!knownLinkerClasses.contains(linker.getClass())) {
|
if(!knownLinkerClasses.contains(linker.getClass())) {
|
||||||
linkers.add(linker);
|
linkers.add(linker);
|
||||||
}
|
}
|
||||||
@ -314,7 +314,7 @@ public class DynamicLinkerFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final List<GuardingTypeConverterFactory> typeConverters = new LinkedList<>();
|
final List<GuardingTypeConverterFactory> typeConverters = new LinkedList<>();
|
||||||
for(GuardingDynamicLinker linker: linkers) {
|
for(final GuardingDynamicLinker linker: linkers) {
|
||||||
if(linker instanceof GuardingTypeConverterFactory) {
|
if(linker instanceof GuardingTypeConverterFactory) {
|
||||||
typeConverters.add((GuardingTypeConverterFactory)linker);
|
typeConverters.add((GuardingTypeConverterFactory)linker);
|
||||||
}
|
}
|
||||||
@ -337,9 +337,9 @@ public class DynamicLinkerFactory {
|
|||||||
}, ClassLoaderGetterContextProvider.GET_CLASS_LOADER_CONTEXT);
|
}, ClassLoaderGetterContextProvider.GET_CLASS_LOADER_CONTEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addClasses(Set<Class<? extends GuardingDynamicLinker>> knownLinkerClasses,
|
private static void addClasses(final Set<Class<? extends GuardingDynamicLinker>> knownLinkerClasses,
|
||||||
List<? extends GuardingDynamicLinker> linkers) {
|
final List<? extends GuardingDynamicLinker> linkers) {
|
||||||
for(GuardingDynamicLinker linker: linkers) {
|
for(final GuardingDynamicLinker linker: linkers) {
|
||||||
knownLinkerClasses.add(linker.getClass());
|
knownLinkerClasses.add(linker.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,17 +99,17 @@ public class MonomorphicCallSite extends AbstractRelinkableCallSite {
|
|||||||
* Creates a new call site with monomorphic inline caching strategy.
|
* Creates a new call site with monomorphic inline caching strategy.
|
||||||
* @param descriptor the descriptor for this call site
|
* @param descriptor the descriptor for this call site
|
||||||
*/
|
*/
|
||||||
public MonomorphicCallSite(CallSiteDescriptor descriptor) {
|
public MonomorphicCallSite(final CallSiteDescriptor descriptor) {
|
||||||
super(descriptor);
|
super(descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void relink(GuardedInvocation guardedInvocation, MethodHandle relink) {
|
public void relink(final GuardedInvocation guardedInvocation, final MethodHandle relink) {
|
||||||
setTarget(guardedInvocation.compose(relink));
|
setTarget(guardedInvocation.compose(relink));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resetAndRelink(GuardedInvocation guardedInvocation, MethodHandle relink) {
|
public void resetAndRelink(final GuardedInvocation guardedInvocation, final MethodHandle relink) {
|
||||||
relink(guardedInvocation, relink);
|
relink(guardedInvocation, relink);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public class NoSuchDynamicMethodException extends RuntimeException {
|
|||||||
* Creates a new NoSuchDynamicMethodException
|
* Creates a new NoSuchDynamicMethodException
|
||||||
* @param message the message of the exception.
|
* @param message the message of the exception.
|
||||||
*/
|
*/
|
||||||
public NoSuchDynamicMethodException(String message) {
|
public NoSuchDynamicMethodException(final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,18 +123,18 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
private final Map<String, DynamicMethod> propertySetters = new HashMap<>();
|
private final Map<String, DynamicMethod> propertySetters = new HashMap<>();
|
||||||
private final Map<String, DynamicMethod> methods = new HashMap<>();
|
private final Map<String, DynamicMethod> methods = new HashMap<>();
|
||||||
|
|
||||||
AbstractJavaLinker(Class<?> clazz, MethodHandle classGuard) {
|
AbstractJavaLinker(final Class<?> clazz, final MethodHandle classGuard) {
|
||||||
this(clazz, classGuard, classGuard);
|
this(clazz, classGuard, classGuard);
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractJavaLinker(Class<?> clazz, MethodHandle classGuard, MethodHandle assignableGuard) {
|
AbstractJavaLinker(final Class<?> clazz, final MethodHandle classGuard, final MethodHandle assignableGuard) {
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.classGuard = classGuard;
|
this.classGuard = classGuard;
|
||||||
this.assignableGuard = assignableGuard;
|
this.assignableGuard = assignableGuard;
|
||||||
|
|
||||||
final FacetIntrospector introspector = createFacetIntrospector();
|
final FacetIntrospector introspector = createFacetIntrospector();
|
||||||
// Add methods and properties
|
// Add methods and properties
|
||||||
for(Method method: introspector.getMethods()) {
|
for(final Method method: introspector.getMethods()) {
|
||||||
final String name = method.getName();
|
final String name = method.getName();
|
||||||
// Add method
|
// Add method
|
||||||
addMember(name, method, methods);
|
addMember(name, method, methods);
|
||||||
@ -153,7 +153,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add field getter/setters as property getters/setters.
|
// Add field getter/setters as property getters/setters.
|
||||||
for(Field field: introspector.getFields()) {
|
for(final Field field: introspector.getFields()) {
|
||||||
final String name = field.getName();
|
final String name = field.getName();
|
||||||
// Only add a property getter when one is not defined already as a getXxx()/isXxx() method.
|
// Only add a property getter when one is not defined already as a getXxx()/isXxx() method.
|
||||||
if(!propertyGetters.containsKey(name)) {
|
if(!propertyGetters.containsKey(name)) {
|
||||||
@ -166,7 +166,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add inner classes, but only those for which we don't hide a property with it
|
// Add inner classes, but only those for which we don't hide a property with it
|
||||||
for(Map.Entry<String, MethodHandle> innerClassSpec: introspector.getInnerClassGetters().entrySet()) {
|
for(final Map.Entry<String, MethodHandle> innerClassSpec: introspector.getInnerClassGetters().entrySet()) {
|
||||||
final String name = innerClassSpec.getKey();
|
final String name = innerClassSpec.getKey();
|
||||||
if(!propertyGetters.containsKey(name)) {
|
if(!propertyGetters.containsKey(name)) {
|
||||||
setPropertyGetter(name, innerClassSpec.getValue(), ValidationType.EXACT_CLASS);
|
setPropertyGetter(name, innerClassSpec.getValue(), ValidationType.EXACT_CLASS);
|
||||||
@ -174,7 +174,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String decapitalize(String str) {
|
private static String decapitalize(final String str) {
|
||||||
assert str != null;
|
assert str != null;
|
||||||
if(str.isEmpty()) {
|
if(str.isEmpty()) {
|
||||||
return str;
|
return str;
|
||||||
@ -209,7 +209,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
return getUnmodifiableKeys(methods);
|
return getUnmodifiableKeys(methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<String> getUnmodifiableKeys(Map<String, ?> m) {
|
private static Collection<String> getUnmodifiableKeys(final Map<String, ?> m) {
|
||||||
return Collections.unmodifiableCollection(m.keySet());
|
return Collections.unmodifiableCollection(m.keySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
* @param handle the method handle that implements the property getter
|
* @param handle the method handle that implements the property getter
|
||||||
* @param validationType the validation type for the property
|
* @param validationType the validation type for the property
|
||||||
*/
|
*/
|
||||||
private void setPropertyGetter(String name, SingleDynamicMethod handle, ValidationType validationType) {
|
private void setPropertyGetter(final String name, final SingleDynamicMethod handle, final ValidationType validationType) {
|
||||||
propertyGetters.put(name, new AnnotatedDynamicMethod(handle, validationType));
|
propertyGetters.put(name, new AnnotatedDynamicMethod(handle, validationType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
* @param prefixLen the getter prefix in the method name; should be 3 for getter names starting with "get" and 2 for
|
* @param prefixLen the getter prefix in the method name; should be 3 for getter names starting with "get" and 2 for
|
||||||
* names starting with "is".
|
* names starting with "is".
|
||||||
*/
|
*/
|
||||||
private void setPropertyGetter(Method getter, int prefixLen) {
|
private void setPropertyGetter(final Method getter, final int prefixLen) {
|
||||||
setPropertyGetter(decapitalize(getter.getName().substring(prefixLen)), createDynamicMethod(
|
setPropertyGetter(decapitalize(getter.getName().substring(prefixLen)), createDynamicMethod(
|
||||||
getMostGenericGetter(getter)), ValidationType.INSTANCE_OF);
|
getMostGenericGetter(getter)), ValidationType.INSTANCE_OF);
|
||||||
}
|
}
|
||||||
@ -246,15 +246,15 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
* @param handle the method handle that implements the property getter
|
* @param handle the method handle that implements the property getter
|
||||||
* @param validationType the validation type for the property
|
* @param validationType the validation type for the property
|
||||||
*/
|
*/
|
||||||
void setPropertyGetter(String name, MethodHandle handle, ValidationType validationType) {
|
void setPropertyGetter(final String name, final MethodHandle handle, final ValidationType validationType) {
|
||||||
setPropertyGetter(name, new SimpleDynamicMethod(handle, clazz, name), validationType);
|
setPropertyGetter(name, new SimpleDynamicMethod(handle, clazz, name), validationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMember(String name, AccessibleObject ao, Map<String, DynamicMethod> methodMap) {
|
private void addMember(final String name, final AccessibleObject ao, final Map<String, DynamicMethod> methodMap) {
|
||||||
addMember(name, createDynamicMethod(ao), methodMap);
|
addMember(name, createDynamicMethod(ao), methodMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addMember(String name, SingleDynamicMethod method, Map<String, DynamicMethod> methodMap) {
|
private void addMember(final String name, final SingleDynamicMethod method, final Map<String, DynamicMethod> methodMap) {
|
||||||
final DynamicMethod existingMethod = methodMap.get(name);
|
final DynamicMethod existingMethod = methodMap.get(name);
|
||||||
final DynamicMethod newMethod = mergeMethods(method, existingMethod, clazz, name);
|
final DynamicMethod newMethod = mergeMethods(method, existingMethod, clazz, name);
|
||||||
if(newMethod != existingMethod) {
|
if(newMethod != existingMethod) {
|
||||||
@ -270,9 +270,9 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
* @param name the common name of the reflective members.
|
* @param name the common name of the reflective members.
|
||||||
* @return a dynamic method representing all the specified reflective members.
|
* @return a dynamic method representing all the specified reflective members.
|
||||||
*/
|
*/
|
||||||
static DynamicMethod createDynamicMethod(Iterable<? extends AccessibleObject> members, Class<?> clazz, String name) {
|
static DynamicMethod createDynamicMethod(final Iterable<? extends AccessibleObject> members, final Class<?> clazz, final String name) {
|
||||||
DynamicMethod dynMethod = null;
|
DynamicMethod dynMethod = null;
|
||||||
for(AccessibleObject method: members) {
|
for(final AccessibleObject method: members) {
|
||||||
dynMethod = mergeMethods(createDynamicMethod(method), dynMethod, clazz, name);
|
dynMethod = mergeMethods(createDynamicMethod(method), dynMethod, clazz, name);
|
||||||
}
|
}
|
||||||
return dynMethod;
|
return dynMethod;
|
||||||
@ -285,7 +285,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
* @param m the reflective member
|
* @param m the reflective member
|
||||||
* @return the single dynamic method representing the reflective member
|
* @return the single dynamic method representing the reflective member
|
||||||
*/
|
*/
|
||||||
private static SingleDynamicMethod createDynamicMethod(AccessibleObject m) {
|
private static SingleDynamicMethod createDynamicMethod(final AccessibleObject m) {
|
||||||
if(CallerSensitiveDetector.isCallerSensitive(m)) {
|
if(CallerSensitiveDetector.isCallerSensitive(m)) {
|
||||||
return new CallerSensitiveDynamicMethod(m);
|
return new CallerSensitiveDynamicMethod(m);
|
||||||
}
|
}
|
||||||
@ -301,7 +301,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
* @param m the method or constructor
|
* @param m the method or constructor
|
||||||
* @return the method handle
|
* @return the method handle
|
||||||
*/
|
*/
|
||||||
private static MethodHandle unreflectSafely(AccessibleObject m) {
|
private static MethodHandle unreflectSafely(final AccessibleObject m) {
|
||||||
if(m instanceof Method) {
|
if(m instanceof Method) {
|
||||||
final Method reflMethod = (Method)m;
|
final Method reflMethod = (Method)m;
|
||||||
final MethodHandle handle = Lookup.PUBLIC.unreflect(reflMethod);
|
final MethodHandle handle = Lookup.PUBLIC.unreflect(reflMethod);
|
||||||
@ -313,7 +313,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
return StaticClassIntrospector.editConstructorMethodHandle(Lookup.PUBLIC.unreflectConstructor((Constructor<?>)m));
|
return StaticClassIntrospector.editConstructorMethodHandle(Lookup.PUBLIC.unreflectConstructor((Constructor<?>)m));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DynamicMethod mergeMethods(SingleDynamicMethod method, DynamicMethod existing, Class<?> clazz, String name) {
|
private static DynamicMethod mergeMethods(final SingleDynamicMethod method, final DynamicMethod existing, final Class<?> clazz, final String name) {
|
||||||
if(existing == null) {
|
if(existing == null) {
|
||||||
return method;
|
return method;
|
||||||
} else if(existing.contains(method)) {
|
} else if(existing.contains(method)) {
|
||||||
@ -331,7 +331,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation getGuardedInvocation(LinkRequest request, final LinkerServices linkerServices)
|
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final LinkRequest ncrequest = request.withoutRuntimeContext();
|
final LinkRequest ncrequest = request.withoutRuntimeContext();
|
||||||
// BeansLinker already checked that the name is at least 2 elements long and the first element is "dyn".
|
// BeansLinker already checked that the name is at least 2 elements long and the first element is "dyn".
|
||||||
@ -353,8 +353,8 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GuardedInvocationComponent getGuardedInvocationComponent(CallSiteDescriptor callSiteDescriptor,
|
protected GuardedInvocationComponent getGuardedInvocationComponent(final CallSiteDescriptor callSiteDescriptor,
|
||||||
LinkerServices linkerServices, List<String> operations) throws Exception {
|
final LinkerServices linkerServices, final List<String> operations) throws Exception {
|
||||||
if(operations.isEmpty()) {
|
if(operations.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -374,27 +374,27 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
static final <T> List<T> pop(List<T> l) {
|
static final <T> List<T> pop(final List<T> l) {
|
||||||
return l.subList(1, l.size());
|
return l.subList(1, l.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodHandle getClassGuard(CallSiteDescriptor desc) {
|
MethodHandle getClassGuard(final CallSiteDescriptor desc) {
|
||||||
return getClassGuard(desc.getMethodType());
|
return getClassGuard(desc.getMethodType());
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodHandle getClassGuard(MethodType type) {
|
MethodHandle getClassGuard(final MethodType type) {
|
||||||
return Guards.asType(classGuard, type);
|
return Guards.asType(classGuard, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuardedInvocationComponent getClassGuardedInvocationComponent(MethodHandle invocation, MethodType type) {
|
GuardedInvocationComponent getClassGuardedInvocationComponent(final MethodHandle invocation, final MethodType type) {
|
||||||
return new GuardedInvocationComponent(invocation, getClassGuard(type), clazz, ValidationType.EXACT_CLASS);
|
return new GuardedInvocationComponent(invocation, getClassGuard(type), clazz, ValidationType.EXACT_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodHandle getAssignableGuard(MethodType type) {
|
private MethodHandle getAssignableGuard(final MethodType type) {
|
||||||
return Guards.asType(assignableGuard, type);
|
return Guards.asType(assignableGuard, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GuardedInvocation getCallPropWithThis(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices) {
|
private GuardedInvocation getCallPropWithThis(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices) {
|
||||||
switch(callSiteDescriptor.getNameTokenCount()) {
|
switch(callSiteDescriptor.getNameTokenCount()) {
|
||||||
case 3: {
|
case 3: {
|
||||||
return createGuardedDynamicMethodInvocation(callSiteDescriptor, linkerServices,
|
return createGuardedDynamicMethodInvocation(callSiteDescriptor, linkerServices,
|
||||||
@ -406,25 +406,25 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private GuardedInvocation createGuardedDynamicMethodInvocation(CallSiteDescriptor callSiteDescriptor,
|
private GuardedInvocation createGuardedDynamicMethodInvocation(final CallSiteDescriptor callSiteDescriptor,
|
||||||
LinkerServices linkerServices, String methodName, Map<String, DynamicMethod> methodMap){
|
final LinkerServices linkerServices, final String methodName, final Map<String, DynamicMethod> methodMap){
|
||||||
final MethodHandle inv = getDynamicMethodInvocation(callSiteDescriptor, linkerServices, methodName, methodMap);
|
final MethodHandle inv = getDynamicMethodInvocation(callSiteDescriptor, linkerServices, methodName, methodMap);
|
||||||
return inv == null ? null : new GuardedInvocation(inv, getClassGuard(callSiteDescriptor.getMethodType()));
|
return inv == null ? null : new GuardedInvocation(inv, getClassGuard(callSiteDescriptor.getMethodType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle getDynamicMethodInvocation(CallSiteDescriptor callSiteDescriptor,
|
private static MethodHandle getDynamicMethodInvocation(final CallSiteDescriptor callSiteDescriptor,
|
||||||
LinkerServices linkerServices, String methodName, Map<String, DynamicMethod> methodMap) {
|
final LinkerServices linkerServices, final String methodName, final Map<String, DynamicMethod> methodMap) {
|
||||||
final DynamicMethod dynaMethod = getDynamicMethod(methodName, methodMap);
|
final DynamicMethod dynaMethod = getDynamicMethod(methodName, methodMap);
|
||||||
return dynaMethod != null ? dynaMethod.getInvocation(callSiteDescriptor, linkerServices) : null;
|
return dynaMethod != null ? dynaMethod.getInvocation(callSiteDescriptor, linkerServices) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DynamicMethod getDynamicMethod(String methodName, Map<String, DynamicMethod> methodMap) {
|
private static DynamicMethod getDynamicMethod(final String methodName, final Map<String, DynamicMethod> methodMap) {
|
||||||
final DynamicMethod dynaMethod = methodMap.get(methodName);
|
final DynamicMethod dynaMethod = methodMap.get(methodName);
|
||||||
return dynaMethod != null ? dynaMethod : getExplicitSignatureDynamicMethod(methodName, methodMap);
|
return dynaMethod != null ? dynaMethod : getExplicitSignatureDynamicMethod(methodName, methodMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SingleDynamicMethod getExplicitSignatureDynamicMethod(String methodName,
|
private static SingleDynamicMethod getExplicitSignatureDynamicMethod(final String methodName,
|
||||||
Map<String, DynamicMethod> methodsMap) {
|
final Map<String, DynamicMethod> methodsMap) {
|
||||||
// What's below is meant to support the "name(type, type, ...)" syntax that programmers can use in a method name
|
// What's below is meant to support the "name(type, type, ...)" syntax that programmers can use in a method name
|
||||||
// to manually pin down an exact overloaded variant. This is not usually required, as the overloaded method
|
// to manually pin down an exact overloaded variant. This is not usually required, as the overloaded method
|
||||||
// resolution works correctly in almost every situation. However, in presence of many language-specific
|
// resolution works correctly in almost every situation. However, in presence of many language-specific
|
||||||
@ -457,8 +457,8 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
private static final MethodHandle CONSTANT_NULL_DROP_METHOD_HANDLE = MethodHandles.dropArguments(
|
private static final MethodHandle CONSTANT_NULL_DROP_METHOD_HANDLE = MethodHandles.dropArguments(
|
||||||
MethodHandles.constant(Object.class, null), 0, MethodHandle.class);
|
MethodHandles.constant(Object.class, null), 0, MethodHandle.class);
|
||||||
|
|
||||||
private GuardedInvocationComponent getPropertySetter(CallSiteDescriptor callSiteDescriptor,
|
private GuardedInvocationComponent getPropertySetter(final CallSiteDescriptor callSiteDescriptor,
|
||||||
LinkerServices linkerServices, List<String> operations) throws Exception {
|
final LinkerServices linkerServices, final List<String> operations) throws Exception {
|
||||||
switch(callSiteDescriptor.getNameTokenCount()) {
|
switch(callSiteDescriptor.getNameTokenCount()) {
|
||||||
case 2: {
|
case 2: {
|
||||||
// Must have three arguments: target object, property name, and property value.
|
// Must have three arguments: target object, property name, and property value.
|
||||||
@ -547,8 +547,8 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
"getTarget", MethodType.methodType(MethodHandle.class, MethodHandles.Lookup.class));
|
"getTarget", MethodType.methodType(MethodHandle.class, MethodHandles.Lookup.class));
|
||||||
private static final MethodHandle GETTER_INVOKER = MethodHandles.invoker(MethodType.methodType(Object.class, Object.class));
|
private static final MethodHandle GETTER_INVOKER = MethodHandles.invoker(MethodType.methodType(Object.class, Object.class));
|
||||||
|
|
||||||
private GuardedInvocationComponent getPropertyGetter(CallSiteDescriptor callSiteDescriptor,
|
private GuardedInvocationComponent getPropertyGetter(final CallSiteDescriptor callSiteDescriptor,
|
||||||
LinkerServices linkerServices, List<String> ops) throws Exception {
|
final LinkerServices linkerServices, final List<String> ops) throws Exception {
|
||||||
switch(callSiteDescriptor.getNameTokenCount()) {
|
switch(callSiteDescriptor.getNameTokenCount()) {
|
||||||
case 2: {
|
case 2: {
|
||||||
// Since we can't know what kind of a getter we'll get back on different invocations, we'll just
|
// Since we can't know what kind of a getter we'll get back on different invocations, we'll just
|
||||||
@ -631,7 +631,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodHandle getGuard(ValidationType validationType, MethodType methodType) {
|
private MethodHandle getGuard(final ValidationType validationType, final MethodType methodType) {
|
||||||
switch(validationType) {
|
switch(validationType) {
|
||||||
case EXACT_CLASS: {
|
case EXACT_CLASS: {
|
||||||
return getClassGuard(methodType);
|
return getClassGuard(methodType);
|
||||||
@ -655,8 +655,8 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
MethodType.methodType(boolean.class, Object.class));
|
MethodType.methodType(boolean.class, Object.class));
|
||||||
private static final MethodHandle OBJECT_IDENTITY = MethodHandles.identity(Object.class);
|
private static final MethodHandle OBJECT_IDENTITY = MethodHandles.identity(Object.class);
|
||||||
|
|
||||||
private GuardedInvocationComponent getMethodGetter(CallSiteDescriptor callSiteDescriptor,
|
private GuardedInvocationComponent getMethodGetter(final CallSiteDescriptor callSiteDescriptor,
|
||||||
LinkerServices linkerServices, List<String> ops) throws Exception {
|
final LinkerServices linkerServices, final List<String> ops) throws Exception {
|
||||||
// The created method handle will always return a DynamicMethod (or null), but since we don't want that type to
|
// The created method handle will always return a DynamicMethod (or null), but since we don't want that type to
|
||||||
// be visible outside of this linker, declare it to return Object.
|
// be visible outside of this linker, declare it to return Object.
|
||||||
final MethodType type = callSiteDescriptor.getMethodType().changeReturnType(Object.class);
|
final MethodType type = callSiteDescriptor.getMethodType().changeReturnType(Object.class);
|
||||||
@ -730,7 +730,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static MethodPair matchReturnTypes(MethodHandle m1, MethodHandle m2) {
|
static MethodPair matchReturnTypes(final MethodHandle m1, final MethodHandle m2) {
|
||||||
final MethodType type1 = m1.type();
|
final MethodType type1 = m1.type();
|
||||||
final MethodType type2 = m2.type();
|
final MethodType type2 = m2.type();
|
||||||
final Class<?> commonRetType = TypeUtilities.getCommonLosslessConversionType(type1.returnType(),
|
final Class<?> commonRetType = TypeUtilities.getCommonLosslessConversionType(type1.returnType(),
|
||||||
@ -740,7 +740,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
m2.asType(type2.changeReturnType(commonRetType)));
|
m2.asType(type2.changeReturnType(commonRetType)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertParameterCount(CallSiteDescriptor descriptor, int paramCount) {
|
private static void assertParameterCount(final CallSiteDescriptor descriptor, final int paramCount) {
|
||||||
if(descriptor.getMethodType().parameterCount() != paramCount) {
|
if(descriptor.getMethodType().parameterCount() != paramCount) {
|
||||||
throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters.");
|
throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters.");
|
||||||
}
|
}
|
||||||
@ -755,7 +755,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
* @return the method handle for retrieving the property, or null if the property does not exist
|
* @return the method handle for retrieving the property, or null if the property does not exist
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private Object getPropertyGetterHandle(Object id) {
|
private Object getPropertyGetterHandle(final Object id) {
|
||||||
return propertyGetters.get(id);
|
return propertyGetters.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -769,8 +769,8 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
private final MethodHandle getPropertySetterHandle = GET_PROPERTY_SETTER_HANDLE.bindTo(this);
|
private final MethodHandle getPropertySetterHandle = GET_PROPERTY_SETTER_HANDLE.bindTo(this);
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private MethodHandle getPropertySetterHandle(CallSiteDescriptor setterDescriptor, LinkerServices linkerServices,
|
private MethodHandle getPropertySetterHandle(final CallSiteDescriptor setterDescriptor, final LinkerServices linkerServices,
|
||||||
Object id) {
|
final Object id) {
|
||||||
return getDynamicMethodInvocation(setterDescriptor, linkerServices, String.valueOf(id), propertySetters);
|
return getDynamicMethodInvocation(setterDescriptor, linkerServices, String.valueOf(id), propertySetters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -782,7 +782,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
// This method is marked to return Object instead of DynamicMethod as it's used as a linking component and we don't
|
// This method is marked to return Object instead of DynamicMethod as it's used as a linking component and we don't
|
||||||
// want to make the DynamicMethod type observable externally (e.g. as the return type of a MethodHandle returned for
|
// want to make the DynamicMethod type observable externally (e.g. as the return type of a MethodHandle returned for
|
||||||
// "dyn:getMethod" linking).
|
// "dyn:getMethod" linking).
|
||||||
private Object getDynamicMethod(Object name) {
|
private Object getDynamicMethod(final Object name) {
|
||||||
return getDynamicMethod(String.valueOf(name), methods);
|
return getDynamicMethod(String.valueOf(name), methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -793,7 +793,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
* @return the dynamic method (either {@link SimpleDynamicMethod} or {@link OverloadedDynamicMethod}, or null if the
|
* @return the dynamic method (either {@link SimpleDynamicMethod} or {@link OverloadedDynamicMethod}, or null if the
|
||||||
* method with the specified name does not exist.
|
* method with the specified name does not exist.
|
||||||
*/
|
*/
|
||||||
DynamicMethod getDynamicMethod(String name) {
|
DynamicMethod getDynamicMethod(final String name) {
|
||||||
return getDynamicMethod(name, methods);
|
return getDynamicMethod(name, methods);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -804,16 +804,16 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
* @param getter the getter
|
* @param getter the getter
|
||||||
* @return getter with same name, declared on the most generic superclass/interface of the declaring class
|
* @return getter with same name, declared on the most generic superclass/interface of the declaring class
|
||||||
*/
|
*/
|
||||||
private static Method getMostGenericGetter(Method getter) {
|
private static Method getMostGenericGetter(final Method getter) {
|
||||||
return getMostGenericGetter(getter.getName(), getter.getReturnType(), getter.getDeclaringClass());
|
return getMostGenericGetter(getter.getName(), getter.getReturnType(), getter.getDeclaringClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Method getMostGenericGetter(String name, Class<?> returnType, Class<?> declaringClass) {
|
private static Method getMostGenericGetter(final String name, final Class<?> returnType, final Class<?> declaringClass) {
|
||||||
if(declaringClass == null) {
|
if(declaringClass == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Prefer interfaces
|
// Prefer interfaces
|
||||||
for(Class<?> itf: declaringClass.getInterfaces()) {
|
for(final Class<?> itf: declaringClass.getInterfaces()) {
|
||||||
final Method itfGetter = getMostGenericGetter(name, returnType, itf);
|
final Method itfGetter = getMostGenericGetter(name, returnType, itf);
|
||||||
if(itfGetter != null) {
|
if(itfGetter != null) {
|
||||||
return itfGetter;
|
return itfGetter;
|
||||||
@ -826,7 +826,7 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
if(!CheckRestrictedPackage.isRestrictedClass(declaringClass)) {
|
if(!CheckRestrictedPackage.isRestrictedClass(declaringClass)) {
|
||||||
try {
|
try {
|
||||||
return declaringClass.getMethod(name);
|
return declaringClass.getMethod(name);
|
||||||
} catch(NoSuchMethodException e) {
|
} catch(final NoSuchMethodException e) {
|
||||||
// Intentionally ignored, meant to fall through
|
// Intentionally ignored, meant to fall through
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -837,18 +837,18 @@ abstract class AbstractJavaLinker implements GuardingDynamicLinker {
|
|||||||
private final SingleDynamicMethod method;
|
private final SingleDynamicMethod method;
|
||||||
/*private*/ final ValidationType validationType;
|
/*private*/ final ValidationType validationType;
|
||||||
|
|
||||||
AnnotatedDynamicMethod(SingleDynamicMethod method, ValidationType validationType) {
|
AnnotatedDynamicMethod(final SingleDynamicMethod method, final ValidationType validationType) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.validationType = validationType;
|
this.validationType = validationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodHandle getInvocation(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices) {
|
MethodHandle getInvocation(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices) {
|
||||||
return method.getInvocation(callSiteDescriptor, linkerServices);
|
return method.getInvocation(callSiteDescriptor, linkerServices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
MethodHandle getTarget(MethodHandles.Lookup lookup) {
|
MethodHandle getTarget(final MethodHandles.Lookup lookup) {
|
||||||
MethodHandle inv = method.getTarget(lookup);
|
final MethodHandle inv = method.getTarget(lookup);
|
||||||
assert inv != null;
|
assert inv != null;
|
||||||
return inv;
|
return inv;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ import java.util.Set;
|
|||||||
class AccessibleMembersLookup {
|
class AccessibleMembersLookup {
|
||||||
private final Map<MethodSignature, Method> methods;
|
private final Map<MethodSignature, Method> methods;
|
||||||
private final Set<Class<?>> innerClasses;
|
private final Set<Class<?>> innerClasses;
|
||||||
private boolean instance;
|
private final boolean instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a mapping for all accessible methods and inner classes on a class.
|
* Creates a mapping for all accessible methods and inner classes on a class.
|
||||||
@ -112,7 +112,7 @@ class AccessibleMembersLookup {
|
|||||||
* @param clazz the inspected class
|
* @param clazz the inspected class
|
||||||
* @param instance true to inspect instance methods, false to inspect static methods.
|
* @param instance true to inspect instance methods, false to inspect static methods.
|
||||||
*/
|
*/
|
||||||
AccessibleMembersLookup(final Class<?> clazz, boolean instance) {
|
AccessibleMembersLookup(final Class<?> clazz, final boolean instance) {
|
||||||
this.methods = new HashMap<>();
|
this.methods = new HashMap<>();
|
||||||
this.innerClasses = new LinkedHashSet<>();
|
this.innerClasses = new LinkedHashSet<>();
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
@ -153,7 +153,7 @@ class AccessibleMembersLookup {
|
|||||||
* @param name the name of the method this signature represents.
|
* @param name the name of the method this signature represents.
|
||||||
* @param args the argument types of the method.
|
* @param args the argument types of the method.
|
||||||
*/
|
*/
|
||||||
MethodSignature(String name, Class<?>[] args) {
|
MethodSignature(final String name, final Class<?>[] args) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ class AccessibleMembersLookup {
|
|||||||
|
|
||||||
if(!CheckRestrictedPackage.isRestrictedClass(clazz)) {
|
if(!CheckRestrictedPackage.isRestrictedClass(clazz)) {
|
||||||
searchSuperTypes = false;
|
searchSuperTypes = false;
|
||||||
for(Method method: clazz.getMethods()) {
|
for(final Method method: clazz.getMethods()) {
|
||||||
final boolean isStatic = Modifier.isStatic(method.getModifiers());
|
final boolean isStatic = Modifier.isStatic(method.getModifiers());
|
||||||
if(instance != isStatic) {
|
if(instance != isStatic) {
|
||||||
final MethodSignature sig = new MethodSignature(method);
|
final MethodSignature sig = new MethodSignature(method);
|
||||||
@ -237,7 +237,7 @@ class AccessibleMembersLookup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(Class<?> innerClass: clazz.getClasses()) {
|
for(final Class<?> innerClass: clazz.getClasses()) {
|
||||||
// Add both static and non-static classes, regardless of instance flag. StaticClassLinker will just
|
// Add both static and non-static classes, regardless of instance flag. StaticClassLinker will just
|
||||||
// expose non-static classes with explicit constructor outer class argument.
|
// expose non-static classes with explicit constructor outer class argument.
|
||||||
// NOTE: getting inner class objects through getClasses() does not resolve them, so if those classes
|
// NOTE: getting inner class objects through getClasses() does not resolve them, so if those classes
|
||||||
|
@ -108,7 +108,7 @@ class ApplicableOverloadedMethods {
|
|||||||
ApplicableOverloadedMethods(final List<SingleDynamicMethod> methods, final MethodType callSiteType,
|
ApplicableOverloadedMethods(final List<SingleDynamicMethod> methods, final MethodType callSiteType,
|
||||||
final ApplicabilityTest test) {
|
final ApplicabilityTest test) {
|
||||||
this.methods = new LinkedList<>();
|
this.methods = new LinkedList<>();
|
||||||
for(SingleDynamicMethod m: methods) {
|
for(final SingleDynamicMethod m: methods) {
|
||||||
if(test.isApplicable(callSiteType, m)) {
|
if(test.isApplicable(callSiteType, m)) {
|
||||||
this.methods.add(m);
|
this.methods.add(m);
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ class ApplicableOverloadedMethods {
|
|||||||
*/
|
*/
|
||||||
static final ApplicabilityTest APPLICABLE_BY_SUBTYPING = new ApplicabilityTest() {
|
static final ApplicabilityTest APPLICABLE_BY_SUBTYPING = new ApplicabilityTest() {
|
||||||
@Override
|
@Override
|
||||||
boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method) {
|
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
|
||||||
final MethodType methodType = method.getMethodType();
|
final MethodType methodType = method.getMethodType();
|
||||||
final int methodArity = methodType.parameterCount();
|
final int methodArity = methodType.parameterCount();
|
||||||
if(methodArity != callSiteType.parameterCount()) {
|
if(methodArity != callSiteType.parameterCount()) {
|
||||||
@ -165,7 +165,7 @@ class ApplicableOverloadedMethods {
|
|||||||
*/
|
*/
|
||||||
static final ApplicabilityTest APPLICABLE_BY_METHOD_INVOCATION_CONVERSION = new ApplicabilityTest() {
|
static final ApplicabilityTest APPLICABLE_BY_METHOD_INVOCATION_CONVERSION = new ApplicabilityTest() {
|
||||||
@Override
|
@Override
|
||||||
boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method) {
|
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
|
||||||
final MethodType methodType = method.getMethodType();
|
final MethodType methodType = method.getMethodType();
|
||||||
final int methodArity = methodType.parameterCount();
|
final int methodArity = methodType.parameterCount();
|
||||||
if(methodArity != callSiteType.parameterCount()) {
|
if(methodArity != callSiteType.parameterCount()) {
|
||||||
@ -188,7 +188,7 @@ class ApplicableOverloadedMethods {
|
|||||||
*/
|
*/
|
||||||
static final ApplicabilityTest APPLICABLE_BY_VARIABLE_ARITY = new ApplicabilityTest() {
|
static final ApplicabilityTest APPLICABLE_BY_VARIABLE_ARITY = new ApplicabilityTest() {
|
||||||
@Override
|
@Override
|
||||||
boolean isApplicable(MethodType callSiteType, SingleDynamicMethod method) {
|
boolean isApplicable(final MethodType callSiteType, final SingleDynamicMethod method) {
|
||||||
if(!method.isVarArgs()) {
|
if(!method.isVarArgs()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ import java.util.Collections;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
class BeanIntrospector extends FacetIntrospector {
|
class BeanIntrospector extends FacetIntrospector {
|
||||||
BeanIntrospector(Class<?> clazz) {
|
BeanIntrospector(final Class<?> clazz) {
|
||||||
super(clazz, true);
|
super(clazz, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ class BeanIntrospector extends FacetIntrospector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
MethodHandle editMethodHandle(MethodHandle mh) {
|
MethodHandle editMethodHandle(final MethodHandle mh) {
|
||||||
return mh;
|
return mh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ import jdk.internal.dynalink.support.TypeUtilities;
|
|||||||
* @author Attila Szegedi
|
* @author Attila Szegedi
|
||||||
*/
|
*/
|
||||||
class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicLinker {
|
class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicLinker {
|
||||||
BeanLinker(Class<?> clazz) {
|
BeanLinker(final Class<?> clazz) {
|
||||||
super(clazz, Guards.getClassGuard(clazz), Guards.getInstanceOfGuard(clazz));
|
super(clazz, Guards.getClassGuard(clazz), Guards.getInstanceOfGuard(clazz));
|
||||||
if(clazz.isArray()) {
|
if(clazz.isArray()) {
|
||||||
// Some languages won't have a notion of manipulating collections. Exposing "length" on arrays as an
|
// Some languages won't have a notion of manipulating collections. Exposing "length" on arrays as an
|
||||||
@ -119,7 +119,7 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canLinkType(Class<?> type) {
|
public boolean canLinkType(final Class<?> type) {
|
||||||
return type == clazz;
|
return type == clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,8 +129,8 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuardedInvocationComponent getGuardedInvocationComponent(CallSiteDescriptor callSiteDescriptor,
|
protected GuardedInvocationComponent getGuardedInvocationComponent(final CallSiteDescriptor callSiteDescriptor,
|
||||||
LinkerServices linkerServices, List<String> operations) throws Exception {
|
final LinkerServices linkerServices, final List<String> operations) throws Exception {
|
||||||
final GuardedInvocationComponent superGic = super.getGuardedInvocationComponent(callSiteDescriptor,
|
final GuardedInvocationComponent superGic = super.getGuardedInvocationComponent(callSiteDescriptor,
|
||||||
linkerServices, operations);
|
linkerServices, operations);
|
||||||
if(superGic != null) {
|
if(superGic != null) {
|
||||||
@ -166,7 +166,7 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
private static MethodHandle MAP_GUARD = Guards.getInstanceOfGuard(Map.class);
|
private static MethodHandle MAP_GUARD = Guards.getInstanceOfGuard(Map.class);
|
||||||
|
|
||||||
private GuardedInvocationComponent getElementGetter(final CallSiteDescriptor callSiteDescriptor,
|
private GuardedInvocationComponent getElementGetter(final CallSiteDescriptor callSiteDescriptor,
|
||||||
final LinkerServices linkerServices, List<String> operations) throws Exception {
|
final LinkerServices linkerServices, final List<String> operations) throws Exception {
|
||||||
final MethodType callSiteType = callSiteDescriptor.getMethodType();
|
final MethodType callSiteType = callSiteDescriptor.getMethodType();
|
||||||
final Class<?> declaredType = callSiteType.parameterType(0);
|
final Class<?> declaredType = callSiteType.parameterType(0);
|
||||||
final GuardedInvocationComponent nextComponent = getGuardedInvocationComponent(callSiteDescriptor,
|
final GuardedInvocationComponent nextComponent = getGuardedInvocationComponent(callSiteDescriptor,
|
||||||
@ -248,7 +248,7 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
CallSiteDescriptor.NAME_OPERAND);
|
CallSiteDescriptor.NAME_OPERAND);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Object convertKeyToInteger(String fixedKey, LinkerServices linkerServices) throws Exception {
|
private static Object convertKeyToInteger(final String fixedKey, final LinkerServices linkerServices) throws Exception {
|
||||||
try {
|
try {
|
||||||
if(linkerServices.canConvert(String.class, Number.class)) {
|
if(linkerServices.canConvert(String.class, Number.class)) {
|
||||||
try {
|
try {
|
||||||
@ -268,18 +268,18 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
return Integer.valueOf(intIndex);
|
return Integer.valueOf(intIndex);
|
||||||
} catch(Exception|Error e) {
|
} catch(Exception|Error e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch(Throwable t) {
|
} catch(final Throwable t) {
|
||||||
throw new RuntimeException(t);
|
throw new RuntimeException(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Integer.valueOf(fixedKey);
|
return Integer.valueOf(fixedKey);
|
||||||
} catch(NumberFormatException e) {
|
} catch(final NumberFormatException e) {
|
||||||
// key is not a number
|
// key is not a number
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle convertArgToInt(MethodHandle mh, LinkerServices ls, CallSiteDescriptor desc) {
|
private static MethodHandle convertArgToInt(final MethodHandle mh, final LinkerServices ls, final CallSiteDescriptor desc) {
|
||||||
final Class<?> sourceType = desc.getMethodType().parameterType(1);
|
final Class<?> sourceType = desc.getMethodType().parameterType(1);
|
||||||
if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) {
|
if(TypeUtilities.isMethodInvocationConvertible(sourceType, Number.class)) {
|
||||||
return mh;
|
return mh;
|
||||||
@ -302,21 +302,21 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
private final MethodType methodType;
|
private final MethodType methodType;
|
||||||
private final Object fixedKey;
|
private final Object fixedKey;
|
||||||
|
|
||||||
Binder(LinkerServices linkerServices, MethodType methodType, Object fixedKey) {
|
Binder(final LinkerServices linkerServices, final MethodType methodType, final Object fixedKey) {
|
||||||
this.linkerServices = linkerServices;
|
this.linkerServices = linkerServices;
|
||||||
this.methodType = fixedKey == null ? methodType : methodType.insertParameterTypes(1, fixedKey.getClass());
|
this.methodType = fixedKey == null ? methodType : methodType.insertParameterTypes(1, fixedKey.getClass());
|
||||||
this.fixedKey = fixedKey;
|
this.fixedKey = fixedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private*/ MethodHandle bind(MethodHandle handle) {
|
/*private*/ MethodHandle bind(final MethodHandle handle) {
|
||||||
return bindToFixedKey(linkerServices.asTypeLosslessReturn(handle, methodType));
|
return bindToFixedKey(linkerServices.asTypeLosslessReturn(handle, methodType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private*/ MethodHandle bindTest(MethodHandle handle) {
|
/*private*/ MethodHandle bindTest(final MethodHandle handle) {
|
||||||
return bindToFixedKey(Guards.asType(handle, methodType));
|
return bindToFixedKey(Guards.asType(handle, methodType));
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodHandle bindToFixedKey(MethodHandle handle) {
|
private MethodHandle bindToFixedKey(final MethodHandle handle) {
|
||||||
return fixedKey == null ? handle : MethodHandles.insertArguments(handle, 1, fixedKey);
|
return fixedKey == null ? handle : MethodHandles.insertArguments(handle, 1, fixedKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -326,12 +326,12 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
private static MethodHandle CONTAINS_MAP = Lookup.PUBLIC.findVirtual(Map.class, "containsKey",
|
private static MethodHandle CONTAINS_MAP = Lookup.PUBLIC.findVirtual(Map.class, "containsKey",
|
||||||
MethodType.methodType(boolean.class, Object.class));
|
MethodType.methodType(boolean.class, Object.class));
|
||||||
|
|
||||||
private static MethodHandle findRangeCheck(Class<?> collectionType) {
|
private static MethodHandle findRangeCheck(final Class<?> collectionType) {
|
||||||
return Lookup.findOwnStatic(MethodHandles.lookup(), "rangeCheck", boolean.class, collectionType, Object.class);
|
return Lookup.findOwnStatic(MethodHandles.lookup(), "rangeCheck", boolean.class, collectionType, Object.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static final boolean rangeCheck(Object array, Object index) {
|
private static final boolean rangeCheck(final Object array, final Object index) {
|
||||||
if(!(index instanceof Number)) {
|
if(!(index instanceof Number)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -348,7 +348,7 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static final boolean rangeCheck(List<?> list, Object index) {
|
private static final boolean rangeCheck(final List<?> list, final Object index) {
|
||||||
if(!(index instanceof Number)) {
|
if(!(index instanceof Number)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -370,8 +370,8 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
private static MethodHandle PUT_MAP_ELEMENT = Lookup.PUBLIC.findVirtual(Map.class, "put",
|
private static MethodHandle PUT_MAP_ELEMENT = Lookup.PUBLIC.findVirtual(Map.class, "put",
|
||||||
MethodType.methodType(Object.class, Object.class, Object.class));
|
MethodType.methodType(Object.class, Object.class, Object.class));
|
||||||
|
|
||||||
private GuardedInvocationComponent getElementSetter(CallSiteDescriptor callSiteDescriptor,
|
private GuardedInvocationComponent getElementSetter(final CallSiteDescriptor callSiteDescriptor,
|
||||||
LinkerServices linkerServices, List<String> operations) throws Exception {
|
final LinkerServices linkerServices, final List<String> operations) throws Exception {
|
||||||
final MethodType callSiteType = callSiteDescriptor.getMethodType();
|
final MethodType callSiteType = callSiteDescriptor.getMethodType();
|
||||||
final Class<?> declaredType = callSiteType.parameterType(0);
|
final Class<?> declaredType = callSiteType.parameterType(0);
|
||||||
|
|
||||||
@ -458,7 +458,7 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
|
|
||||||
private static MethodHandle COLLECTION_GUARD = Guards.getInstanceOfGuard(Collection.class);
|
private static MethodHandle COLLECTION_GUARD = Guards.getInstanceOfGuard(Collection.class);
|
||||||
|
|
||||||
private GuardedInvocationComponent getLengthGetter(CallSiteDescriptor callSiteDescriptor) {
|
private GuardedInvocationComponent getLengthGetter(final CallSiteDescriptor callSiteDescriptor) {
|
||||||
assertParameterCount(callSiteDescriptor, 1);
|
assertParameterCount(callSiteDescriptor, 1);
|
||||||
final MethodType callSiteType = callSiteDescriptor.getMethodType();
|
final MethodType callSiteType = callSiteDescriptor.getMethodType();
|
||||||
final Class<?> declaredType = callSiteType.parameterType(0);
|
final Class<?> declaredType = callSiteType.parameterType(0);
|
||||||
@ -488,7 +488,7 @@ class BeanLinker extends AbstractJavaLinker implements TypeBasedGuardingDynamicL
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assertParameterCount(CallSiteDescriptor descriptor, int paramCount) {
|
private static void assertParameterCount(final CallSiteDescriptor descriptor, final int paramCount) {
|
||||||
if(descriptor.getMethodType().parameterCount() != paramCount) {
|
if(descriptor.getMethodType().parameterCount() != paramCount) {
|
||||||
throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters.");
|
throw new BootstrapMethodError(descriptor.getName() + " must have exactly " + paramCount + " parameters.");
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ import jdk.internal.dynalink.linker.TypeBasedGuardingDynamicLinker;
|
|||||||
public class BeansLinker implements GuardingDynamicLinker {
|
public class BeansLinker implements GuardingDynamicLinker {
|
||||||
private static final ClassValue<TypeBasedGuardingDynamicLinker> linkers = new ClassValue<TypeBasedGuardingDynamicLinker>() {
|
private static final ClassValue<TypeBasedGuardingDynamicLinker> linkers = new ClassValue<TypeBasedGuardingDynamicLinker>() {
|
||||||
@Override
|
@Override
|
||||||
protected TypeBasedGuardingDynamicLinker computeValue(Class<?> clazz) {
|
protected TypeBasedGuardingDynamicLinker computeValue(final Class<?> clazz) {
|
||||||
// If ClassValue.put() were public, we could just pre-populate with these known mappings...
|
// If ClassValue.put() were public, we could just pre-populate with these known mappings...
|
||||||
return
|
return
|
||||||
clazz == Class.class ? new ClassLinker() :
|
clazz == Class.class ? new ClassLinker() :
|
||||||
@ -154,7 +154,7 @@ public class BeansLinker implements GuardingDynamicLinker {
|
|||||||
* @param clazz the class
|
* @param clazz the class
|
||||||
* @return a bean linker for that class
|
* @return a bean linker for that class
|
||||||
*/
|
*/
|
||||||
public static TypeBasedGuardingDynamicLinker getLinkerForClass(Class<?> clazz) {
|
public static TypeBasedGuardingDynamicLinker getLinkerForClass(final Class<?> clazz) {
|
||||||
return linkers.get(clazz);
|
return linkers.get(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,8 +173,8 @@ public class BeansLinker implements GuardingDynamicLinker {
|
|||||||
* @param clazz the class
|
* @param clazz the class
|
||||||
* @return a collection of names of all readable instance properties of a class.
|
* @return a collection of names of all readable instance properties of a class.
|
||||||
*/
|
*/
|
||||||
public static Collection<String> getReadableInstancePropertyNames(Class<?> clazz) {
|
public static Collection<String> getReadableInstancePropertyNames(final Class<?> clazz) {
|
||||||
TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
|
final TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
|
||||||
if(linker instanceof BeanLinker) {
|
if(linker instanceof BeanLinker) {
|
||||||
return ((BeanLinker)linker).getReadablePropertyNames();
|
return ((BeanLinker)linker).getReadablePropertyNames();
|
||||||
}
|
}
|
||||||
@ -186,8 +186,8 @@ public class BeansLinker implements GuardingDynamicLinker {
|
|||||||
* @param clazz the class
|
* @param clazz the class
|
||||||
* @return a collection of names of all writable instance properties of a class.
|
* @return a collection of names of all writable instance properties of a class.
|
||||||
*/
|
*/
|
||||||
public static Collection<String> getWritableInstancePropertyNames(Class<?> clazz) {
|
public static Collection<String> getWritableInstancePropertyNames(final Class<?> clazz) {
|
||||||
TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
|
final TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
|
||||||
if(linker instanceof BeanLinker) {
|
if(linker instanceof BeanLinker) {
|
||||||
return ((BeanLinker)linker).getWritablePropertyNames();
|
return ((BeanLinker)linker).getWritablePropertyNames();
|
||||||
}
|
}
|
||||||
@ -199,8 +199,8 @@ public class BeansLinker implements GuardingDynamicLinker {
|
|||||||
* @param clazz the class
|
* @param clazz the class
|
||||||
* @return a collection of names of all instance methods of a class.
|
* @return a collection of names of all instance methods of a class.
|
||||||
*/
|
*/
|
||||||
public static Collection<String> getInstanceMethodNames(Class<?> clazz) {
|
public static Collection<String> getInstanceMethodNames(final Class<?> clazz) {
|
||||||
TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
|
final TypeBasedGuardingDynamicLinker linker = getLinkerForClass(clazz);
|
||||||
if(linker instanceof BeanLinker) {
|
if(linker instanceof BeanLinker) {
|
||||||
return ((BeanLinker)linker).getMethodNames();
|
return ((BeanLinker)linker).getMethodNames();
|
||||||
}
|
}
|
||||||
@ -212,7 +212,7 @@ public class BeansLinker implements GuardingDynamicLinker {
|
|||||||
* @param clazz the class
|
* @param clazz the class
|
||||||
* @return a collection of names of all readable static properties of a class.
|
* @return a collection of names of all readable static properties of a class.
|
||||||
*/
|
*/
|
||||||
public static Collection<String> getReadableStaticPropertyNames(Class<?> clazz) {
|
public static Collection<String> getReadableStaticPropertyNames(final Class<?> clazz) {
|
||||||
return StaticClassLinker.getReadableStaticPropertyNames(clazz);
|
return StaticClassLinker.getReadableStaticPropertyNames(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ public class BeansLinker implements GuardingDynamicLinker {
|
|||||||
* @param clazz the class
|
* @param clazz the class
|
||||||
* @return a collection of names of all writable static properties of a class.
|
* @return a collection of names of all writable static properties of a class.
|
||||||
*/
|
*/
|
||||||
public static Collection<String> getWritableStaticPropertyNames(Class<?> clazz) {
|
public static Collection<String> getWritableStaticPropertyNames(final Class<?> clazz) {
|
||||||
return StaticClassLinker.getWritableStaticPropertyNames(clazz);
|
return StaticClassLinker.getWritableStaticPropertyNames(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,12 +230,12 @@ public class BeansLinker implements GuardingDynamicLinker {
|
|||||||
* @param clazz the class
|
* @param clazz the class
|
||||||
* @return a collection of names of all static methods of a class.
|
* @return a collection of names of all static methods of a class.
|
||||||
*/
|
*/
|
||||||
public static Collection<String> getStaticMethodNames(Class<?> clazz) {
|
public static Collection<String> getStaticMethodNames(final Class<?> clazz) {
|
||||||
return StaticClassLinker.getStaticMethodNames(clazz);
|
return StaticClassLinker.getStaticMethodNames(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation getGuardedInvocation(LinkRequest request, final LinkerServices linkerServices)
|
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final CallSiteDescriptor callSiteDescriptor = request.getCallSiteDescriptor();
|
final CallSiteDescriptor callSiteDescriptor = request.getCallSiteDescriptor();
|
||||||
final int l = callSiteDescriptor.getNameTokenCount();
|
final int l = callSiteDescriptor.getNameTokenCount();
|
||||||
|
@ -107,14 +107,14 @@ public class CallerSensitiveDetector {
|
|||||||
|
|
||||||
private static final DetectionStrategy DETECTION_STRATEGY = getDetectionStrategy();
|
private static final DetectionStrategy DETECTION_STRATEGY = getDetectionStrategy();
|
||||||
|
|
||||||
static boolean isCallerSensitive(AccessibleObject ao) {
|
static boolean isCallerSensitive(final AccessibleObject ao) {
|
||||||
return DETECTION_STRATEGY.isCallerSensitive(ao);
|
return DETECTION_STRATEGY.isCallerSensitive(ao);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DetectionStrategy getDetectionStrategy() {
|
private static DetectionStrategy getDetectionStrategy() {
|
||||||
try {
|
try {
|
||||||
return new PrivilegedDetectionStrategy();
|
return new PrivilegedDetectionStrategy();
|
||||||
} catch(Throwable t) {
|
} catch(final Throwable t) {
|
||||||
return new UnprivilegedDetectionStrategy();
|
return new UnprivilegedDetectionStrategy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ public class CallerSensitiveDetector {
|
|||||||
private static final Class<? extends Annotation> CALLER_SENSITIVE_ANNOTATION_CLASS = CallerSensitive.class;
|
private static final Class<? extends Annotation> CALLER_SENSITIVE_ANNOTATION_CLASS = CallerSensitive.class;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isCallerSensitive(AccessibleObject ao) {
|
boolean isCallerSensitive(final AccessibleObject ao) {
|
||||||
return ao.getAnnotation(CALLER_SENSITIVE_ANNOTATION_CLASS) != null;
|
return ao.getAnnotation(CALLER_SENSITIVE_ANNOTATION_CLASS) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,8 +136,8 @@ public class CallerSensitiveDetector {
|
|||||||
private static final String CALLER_SENSITIVE_ANNOTATION_STRING = "@sun.reflect.CallerSensitive()";
|
private static final String CALLER_SENSITIVE_ANNOTATION_STRING = "@sun.reflect.CallerSensitive()";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isCallerSensitive(AccessibleObject o) {
|
boolean isCallerSensitive(final AccessibleObject o) {
|
||||||
for(Annotation a: o.getAnnotations()) {
|
for(final Annotation a: o.getAnnotations()) {
|
||||||
if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
|
if(String.valueOf(a).equals(CALLER_SENSITIVE_ANNOTATION_STRING)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -107,13 +107,13 @@ class CallerSensitiveDynamicMethod extends SingleDynamicMethod {
|
|||||||
private final AccessibleObject target;
|
private final AccessibleObject target;
|
||||||
private final MethodType type;
|
private final MethodType type;
|
||||||
|
|
||||||
public CallerSensitiveDynamicMethod(AccessibleObject target) {
|
public CallerSensitiveDynamicMethod(final AccessibleObject target) {
|
||||||
super(getName(target));
|
super(getName(target));
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.type = getMethodType(target);
|
this.type = getMethodType(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getName(AccessibleObject target) {
|
private static String getName(final AccessibleObject target) {
|
||||||
final Member m = (Member)target;
|
final Member m = (Member)target;
|
||||||
return getMethodNameWithSignature(getMethodType(target), getClassAndMethodName(m.getDeclaringClass(),
|
return getMethodNameWithSignature(getMethodType(target), getClassAndMethodName(m.getDeclaringClass(),
|
||||||
m.getName()));
|
m.getName()));
|
||||||
@ -124,7 +124,7 @@ class CallerSensitiveDynamicMethod extends SingleDynamicMethod {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodType getMethodType(AccessibleObject ao) {
|
private static MethodType getMethodType(final AccessibleObject ao) {
|
||||||
final boolean isMethod = ao instanceof Method;
|
final boolean isMethod = ao instanceof Method;
|
||||||
final Class<?> rtype = isMethod ? ((Method)ao).getReturnType() : ((Constructor<?>)ao).getDeclaringClass();
|
final Class<?> rtype = isMethod ? ((Method)ao).getReturnType() : ((Constructor<?>)ao).getDeclaringClass();
|
||||||
final Class<?>[] ptypes = isMethod ? ((Method)ao).getParameterTypes() : ((Constructor<?>)ao).getParameterTypes();
|
final Class<?>[] ptypes = isMethod ? ((Method)ao).getParameterTypes() : ((Constructor<?>)ao).getParameterTypes();
|
||||||
@ -144,7 +144,7 @@ class CallerSensitiveDynamicMethod extends SingleDynamicMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
MethodHandle getTarget(MethodHandles.Lookup lookup) {
|
MethodHandle getTarget(final MethodHandles.Lookup lookup) {
|
||||||
if(target instanceof Method) {
|
if(target instanceof Method) {
|
||||||
final MethodHandle mh = Lookup.unreflect(lookup, (Method)target);
|
final MethodHandle mh = Lookup.unreflect(lookup, (Method)target);
|
||||||
if(Modifier.isStatic(((Member)target).getModifiers())) {
|
if(Modifier.isStatic(((Member)target).getModifiers())) {
|
||||||
|
@ -101,7 +101,7 @@ class CheckRestrictedPackage {
|
|||||||
* @param clazz the class to test
|
* @param clazz the class to test
|
||||||
* @return true if the class is either not public, or it resides in a package with restricted access.
|
* @return true if the class is either not public, or it resides in a package with restricted access.
|
||||||
*/
|
*/
|
||||||
static boolean isRestrictedClass(Class<?> clazz) {
|
static boolean isRestrictedClass(final Class<?> clazz) {
|
||||||
if(!Modifier.isPublic(clazz.getModifiers())) {
|
if(!Modifier.isPublic(clazz.getModifiers())) {
|
||||||
// Non-public classes are always restricted
|
// Non-public classes are always restricted
|
||||||
return true;
|
return true;
|
||||||
@ -126,7 +126,7 @@ class CheckRestrictedPackage {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, NO_PERMISSIONS_CONTEXT);
|
}, NO_PERMISSIONS_CONTEXT);
|
||||||
} catch(SecurityException e) {
|
} catch(final SecurityException e) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -104,16 +104,16 @@ final class ClassString {
|
|||||||
private final Class<?>[] classes;
|
private final Class<?>[] classes;
|
||||||
private int hashCode;
|
private int hashCode;
|
||||||
|
|
||||||
ClassString(Class<?>[] classes) {
|
ClassString(final Class<?>[] classes) {
|
||||||
this.classes = classes;
|
this.classes = classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassString(MethodType type) {
|
ClassString(final MethodType type) {
|
||||||
this(type.parameterArray());
|
this(type.parameterArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(final Object other) {
|
||||||
if(!(other instanceof ClassString)) {
|
if(!(other instanceof ClassString)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ final class ClassString {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MethodHandle> getMaximallySpecifics(List<MethodHandle> methods, LinkerServices linkerServices, boolean varArg) {
|
List<MethodHandle> getMaximallySpecifics(final List<MethodHandle> methods, final LinkerServices linkerServices, final boolean varArg) {
|
||||||
return MaximallySpecific.getMaximallySpecificMethodHandles(getApplicables(methods, linkerServices, varArg),
|
return MaximallySpecific.getMaximallySpecificMethodHandles(getApplicables(methods, linkerServices, varArg),
|
||||||
varArg, classes, linkerServices);
|
varArg, classes, linkerServices);
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ final class ClassString {
|
|||||||
/**
|
/**
|
||||||
* Returns all methods that are applicable to actual parameter classes represented by this ClassString object.
|
* Returns all methods that are applicable to actual parameter classes represented by this ClassString object.
|
||||||
*/
|
*/
|
||||||
LinkedList<MethodHandle> getApplicables(List<MethodHandle> methods, LinkerServices linkerServices, boolean varArg) {
|
LinkedList<MethodHandle> getApplicables(final List<MethodHandle> methods, final LinkerServices linkerServices, final boolean varArg) {
|
||||||
final LinkedList<MethodHandle> list = new LinkedList<>();
|
final LinkedList<MethodHandle> list = new LinkedList<>();
|
||||||
for(final MethodHandle member: methods) {
|
for(final MethodHandle member: methods) {
|
||||||
if(isApplicable(member, linkerServices, varArg)) {
|
if(isApplicable(member, linkerServices, varArg)) {
|
||||||
@ -173,7 +173,7 @@ final class ClassString {
|
|||||||
* object.
|
* object.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private boolean isApplicable(MethodHandle method, LinkerServices linkerServices, boolean varArg) {
|
private boolean isApplicable(final MethodHandle method, final LinkerServices linkerServices, final boolean varArg) {
|
||||||
final Class<?>[] formalTypes = method.type().parameterArray();
|
final Class<?>[] formalTypes = method.type().parameterArray();
|
||||||
final int cl = classes.length;
|
final int cl = classes.length;
|
||||||
final int fl = formalTypes.length - (varArg ? 1 : 0);
|
final int fl = formalTypes.length - (varArg ? 1 : 0);
|
||||||
@ -203,7 +203,7 @@ final class ClassString {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean canConvert(LinkerServices ls, Class<?> from, Class<?> to) {
|
private static boolean canConvert(final LinkerServices ls, final Class<?> from, final Class<?> to) {
|
||||||
if(from == NULL_CLASS) {
|
if(from == NULL_CLASS) {
|
||||||
return !to.isPrimitive();
|
return !to.isPrimitive();
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ import jdk.internal.dynalink.linker.LinkerServices;
|
|||||||
abstract class DynamicMethod {
|
abstract class DynamicMethod {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
DynamicMethod(String name) {
|
DynamicMethod(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +138,7 @@ abstract class DynamicMethod {
|
|||||||
*/
|
*/
|
||||||
abstract boolean contains(SingleDynamicMethod method);
|
abstract boolean contains(SingleDynamicMethod method);
|
||||||
|
|
||||||
static String getClassAndMethodName(Class<?> clazz, String name) {
|
static String getClassAndMethodName(final Class<?> clazz, final String name) {
|
||||||
final String clazzName = clazz.getCanonicalName();
|
final String clazzName = clazz.getCanonicalName();
|
||||||
return (clazzName == null ? clazz.getName() : clazzName) + "." + name;
|
return (clazzName == null ? clazz.getName() : clazzName) + "." + name;
|
||||||
}
|
}
|
||||||
|
@ -99,12 +99,12 @@ import jdk.internal.dynalink.support.Guards;
|
|||||||
*/
|
*/
|
||||||
class DynamicMethodLinker implements TypeBasedGuardingDynamicLinker {
|
class DynamicMethodLinker implements TypeBasedGuardingDynamicLinker {
|
||||||
@Override
|
@Override
|
||||||
public boolean canLinkType(Class<?> type) {
|
public boolean canLinkType(final Class<?> type) {
|
||||||
return DynamicMethod.class.isAssignableFrom(type);
|
return DynamicMethod.class.isAssignableFrom(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, LinkerServices linkerServices) {
|
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) {
|
||||||
final Object receiver = linkRequest.getReceiver();
|
final Object receiver = linkRequest.getReceiver();
|
||||||
if(!(receiver instanceof DynamicMethod)) {
|
if(!(receiver instanceof DynamicMethod)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -106,7 +106,7 @@ abstract class FacetIntrospector {
|
|||||||
|
|
||||||
protected final AccessibleMembersLookup membersLookup;
|
protected final AccessibleMembersLookup membersLookup;
|
||||||
|
|
||||||
FacetIntrospector(Class<?> clazz, boolean instance) {
|
FacetIntrospector(final Class<?> clazz, final boolean instance) {
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
this.instance = instance;
|
this.instance = instance;
|
||||||
isRestricted = CheckRestrictedPackage.isRestrictedClass(clazz);
|
isRestricted = CheckRestrictedPackage.isRestrictedClass(clazz);
|
||||||
@ -135,7 +135,7 @@ abstract class FacetIntrospector {
|
|||||||
|
|
||||||
final Field[] fields = clazz.getFields();
|
final Field[] fields = clazz.getFields();
|
||||||
final Collection<Field> cfields = new ArrayList<>(fields.length);
|
final Collection<Field> cfields = new ArrayList<>(fields.length);
|
||||||
for(Field field: fields) {
|
for(final Field field: fields) {
|
||||||
final boolean isStatic = Modifier.isStatic(field.getModifiers());
|
final boolean isStatic = Modifier.isStatic(field.getModifiers());
|
||||||
if(isStatic && clazz != field.getDeclaringClass()) {
|
if(isStatic && clazz != field.getDeclaringClass()) {
|
||||||
// ignore inherited static fields
|
// ignore inherited static fields
|
||||||
@ -149,7 +149,7 @@ abstract class FacetIntrospector {
|
|||||||
return cfields;
|
return cfields;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAccessible(Member m) {
|
boolean isAccessible(final Member m) {
|
||||||
final Class<?> declaring = m.getDeclaringClass();
|
final Class<?> declaring = m.getDeclaringClass();
|
||||||
// (declaring == clazz) is just an optimization - we're calling this only from code that operates on a
|
// (declaring == clazz) is just an optimization - we're calling this only from code that operates on a
|
||||||
// non-restriced class, so if the declaring class is identical to the class being inspected, then forego
|
// non-restriced class, so if the declaring class is identical to the class being inspected, then forego
|
||||||
@ -166,11 +166,11 @@ abstract class FacetIntrospector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MethodHandle unreflectGetter(Field field) {
|
MethodHandle unreflectGetter(final Field field) {
|
||||||
return editMethodHandle(Lookup.PUBLIC.unreflectGetter(field));
|
return editMethodHandle(Lookup.PUBLIC.unreflectGetter(field));
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodHandle unreflectSetter(Field field) {
|
MethodHandle unreflectSetter(final Field field) {
|
||||||
return editMethodHandle(Lookup.PUBLIC.unreflectSetter(field));
|
return editMethodHandle(Lookup.PUBLIC.unreflectSetter(field));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,38 +105,38 @@ class GuardedInvocationComponent {
|
|||||||
private final GuardedInvocation guardedInvocation;
|
private final GuardedInvocation guardedInvocation;
|
||||||
private final Validator validator;
|
private final Validator validator;
|
||||||
|
|
||||||
GuardedInvocationComponent(MethodHandle invocation) {
|
GuardedInvocationComponent(final MethodHandle invocation) {
|
||||||
this(invocation, null, ValidationType.NONE);
|
this(invocation, null, ValidationType.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuardedInvocationComponent(MethodHandle invocation, MethodHandle guard, ValidationType validationType) {
|
GuardedInvocationComponent(final MethodHandle invocation, final MethodHandle guard, final ValidationType validationType) {
|
||||||
this(invocation, guard, null, validationType);
|
this(invocation, guard, null, validationType);
|
||||||
}
|
}
|
||||||
|
|
||||||
GuardedInvocationComponent(MethodHandle invocation, MethodHandle guard, Class<?> validatorClass,
|
GuardedInvocationComponent(final MethodHandle invocation, final MethodHandle guard, final Class<?> validatorClass,
|
||||||
ValidationType validationType) {
|
final ValidationType validationType) {
|
||||||
this(invocation, guard, new Validator(validatorClass, validationType));
|
this(invocation, guard, new Validator(validatorClass, validationType));
|
||||||
}
|
}
|
||||||
|
|
||||||
GuardedInvocationComponent(GuardedInvocation guardedInvocation, Class<?> validatorClass,
|
GuardedInvocationComponent(final GuardedInvocation guardedInvocation, final Class<?> validatorClass,
|
||||||
ValidationType validationType) {
|
final ValidationType validationType) {
|
||||||
this(guardedInvocation, new Validator(validatorClass, validationType));
|
this(guardedInvocation, new Validator(validatorClass, validationType));
|
||||||
}
|
}
|
||||||
|
|
||||||
GuardedInvocationComponent replaceInvocation(MethodHandle newInvocation) {
|
GuardedInvocationComponent replaceInvocation(final MethodHandle newInvocation) {
|
||||||
return replaceInvocation(newInvocation, guardedInvocation.getGuard());
|
return replaceInvocation(newInvocation, guardedInvocation.getGuard());
|
||||||
}
|
}
|
||||||
|
|
||||||
GuardedInvocationComponent replaceInvocation(MethodHandle newInvocation, MethodHandle newGuard) {
|
GuardedInvocationComponent replaceInvocation(final MethodHandle newInvocation, final MethodHandle newGuard) {
|
||||||
return new GuardedInvocationComponent(guardedInvocation.replaceMethods(newInvocation,
|
return new GuardedInvocationComponent(guardedInvocation.replaceMethods(newInvocation,
|
||||||
newGuard), validator);
|
newGuard), validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GuardedInvocationComponent(MethodHandle invocation, MethodHandle guard, Validator validator) {
|
private GuardedInvocationComponent(final MethodHandle invocation, final MethodHandle guard, final Validator validator) {
|
||||||
this(new GuardedInvocation(invocation, guard), validator);
|
this(new GuardedInvocation(invocation, guard), validator);
|
||||||
}
|
}
|
||||||
|
|
||||||
private GuardedInvocationComponent(GuardedInvocation guardedInvocation, Validator validator) {
|
private GuardedInvocationComponent(final GuardedInvocation guardedInvocation, final Validator validator) {
|
||||||
this.guardedInvocation = guardedInvocation;
|
this.guardedInvocation = guardedInvocation;
|
||||||
this.validator = validator;
|
this.validator = validator;
|
||||||
}
|
}
|
||||||
@ -153,8 +153,8 @@ class GuardedInvocationComponent {
|
|||||||
return validator.validationType;
|
return validator.validationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
GuardedInvocationComponent compose(MethodHandle compositeInvocation, MethodHandle otherGuard,
|
GuardedInvocationComponent compose(final MethodHandle compositeInvocation, final MethodHandle otherGuard,
|
||||||
Class<?> otherValidatorClass, ValidationType otherValidationType) {
|
final Class<?> otherValidatorClass, final ValidationType otherValidationType) {
|
||||||
final Validator compositeValidator = validator.compose(new Validator(otherValidatorClass, otherValidationType));
|
final Validator compositeValidator = validator.compose(new Validator(otherValidatorClass, otherValidationType));
|
||||||
final MethodHandle compositeGuard = compositeValidator == validator ? guardedInvocation.getGuard() : otherGuard;
|
final MethodHandle compositeGuard = compositeValidator == validator ? guardedInvocation.getGuard() : otherGuard;
|
||||||
return new GuardedInvocationComponent(compositeInvocation, compositeGuard, compositeValidator);
|
return new GuardedInvocationComponent(compositeInvocation, compositeGuard, compositeValidator);
|
||||||
@ -164,12 +164,12 @@ class GuardedInvocationComponent {
|
|||||||
/*private*/ final Class<?> validatorClass;
|
/*private*/ final Class<?> validatorClass;
|
||||||
/*private*/ final ValidationType validationType;
|
/*private*/ final ValidationType validationType;
|
||||||
|
|
||||||
Validator(Class<?> validatorClass, ValidationType validationType) {
|
Validator(final Class<?> validatorClass, final ValidationType validationType) {
|
||||||
this.validatorClass = validatorClass;
|
this.validatorClass = validatorClass;
|
||||||
this.validationType = validationType;
|
this.validationType = validationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
Validator compose(Validator other) {
|
Validator compose(final Validator other) {
|
||||||
if(other.validationType == ValidationType.NONE) {
|
if(other.validationType == ValidationType.NONE) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ class GuardedInvocationComponent {
|
|||||||
throw new AssertionError("Incompatible composition " + this + " vs " + other);
|
throw new AssertionError("Incompatible composition " + this + " vs " + other);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAssignableFrom(Validator other) {
|
private boolean isAssignableFrom(final Validator other) {
|
||||||
return validatorClass.isAssignableFrom(other.validatorClass);
|
return validatorClass.isAssignableFrom(other.validatorClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ class MaximallySpecific {
|
|||||||
* @param varArgs whether to assume the methods are varargs
|
* @param varArgs whether to assume the methods are varargs
|
||||||
* @return the list of maximally specific methods.
|
* @return the list of maximally specific methods.
|
||||||
*/
|
*/
|
||||||
static List<SingleDynamicMethod> getMaximallySpecificMethods(List<SingleDynamicMethod> methods, boolean varArgs) {
|
static List<SingleDynamicMethod> getMaximallySpecificMethods(final List<SingleDynamicMethod> methods, final boolean varArgs) {
|
||||||
return getMaximallySpecificSingleDynamicMethods(methods, varArgs, null, null);
|
return getMaximallySpecificSingleDynamicMethods(methods, varArgs, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class MaximallySpecific {
|
|||||||
private static final MethodTypeGetter<MethodHandle> METHOD_HANDLE_TYPE_GETTER =
|
private static final MethodTypeGetter<MethodHandle> METHOD_HANDLE_TYPE_GETTER =
|
||||||
new MethodTypeGetter<MethodHandle>() {
|
new MethodTypeGetter<MethodHandle>() {
|
||||||
@Override
|
@Override
|
||||||
MethodType getMethodType(MethodHandle t) {
|
MethodType getMethodType(final MethodHandle t) {
|
||||||
return t.type();
|
return t.type();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -124,7 +124,7 @@ class MaximallySpecific {
|
|||||||
private static final MethodTypeGetter<SingleDynamicMethod> DYNAMIC_METHOD_TYPE_GETTER =
|
private static final MethodTypeGetter<SingleDynamicMethod> DYNAMIC_METHOD_TYPE_GETTER =
|
||||||
new MethodTypeGetter<SingleDynamicMethod>() {
|
new MethodTypeGetter<SingleDynamicMethod>() {
|
||||||
@Override
|
@Override
|
||||||
MethodType getMethodType(SingleDynamicMethod t) {
|
MethodType getMethodType(final SingleDynamicMethod t) {
|
||||||
return t.getMethodType();
|
return t.getMethodType();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -138,8 +138,8 @@ class MaximallySpecific {
|
|||||||
* @param argTypes concrete argument types for the invocation
|
* @param argTypes concrete argument types for the invocation
|
||||||
* @return the list of maximally specific method handles.
|
* @return the list of maximally specific method handles.
|
||||||
*/
|
*/
|
||||||
static List<MethodHandle> getMaximallySpecificMethodHandles(List<MethodHandle> methods, boolean varArgs,
|
static List<MethodHandle> getMaximallySpecificMethodHandles(final List<MethodHandle> methods, final boolean varArgs,
|
||||||
Class<?>[] argTypes, LinkerServices ls) {
|
final Class<?>[] argTypes, final LinkerServices ls) {
|
||||||
return getMaximallySpecificMethods(methods, varArgs, argTypes, ls, METHOD_HANDLE_TYPE_GETTER);
|
return getMaximallySpecificMethods(methods, varArgs, argTypes, ls, METHOD_HANDLE_TYPE_GETTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,8 +152,8 @@ class MaximallySpecific {
|
|||||||
* @param argTypes concrete argument types for the invocation
|
* @param argTypes concrete argument types for the invocation
|
||||||
* @return the list of maximally specific methods.
|
* @return the list of maximally specific methods.
|
||||||
*/
|
*/
|
||||||
static List<SingleDynamicMethod> getMaximallySpecificSingleDynamicMethods(List<SingleDynamicMethod> methods,
|
static List<SingleDynamicMethod> getMaximallySpecificSingleDynamicMethods(final List<SingleDynamicMethod> methods,
|
||||||
boolean varArgs, Class<?>[] argTypes, LinkerServices ls) {
|
final boolean varArgs, final Class<?>[] argTypes, final LinkerServices ls) {
|
||||||
return getMaximallySpecificMethods(methods, varArgs, argTypes, ls, DYNAMIC_METHOD_TYPE_GETTER);
|
return getMaximallySpecificMethods(methods, varArgs, argTypes, ls, DYNAMIC_METHOD_TYPE_GETTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,16 +166,16 @@ class MaximallySpecific {
|
|||||||
* @param argTypes concrete argument types for the invocation
|
* @param argTypes concrete argument types for the invocation
|
||||||
* @return the list of maximally specific methods.
|
* @return the list of maximally specific methods.
|
||||||
*/
|
*/
|
||||||
private static <T> List<T> getMaximallySpecificMethods(List<T> methods, boolean varArgs,
|
private static <T> List<T> getMaximallySpecificMethods(final List<T> methods, final boolean varArgs,
|
||||||
Class<?>[] argTypes, LinkerServices ls, MethodTypeGetter<T> methodTypeGetter) {
|
final Class<?>[] argTypes, final LinkerServices ls, final MethodTypeGetter<T> methodTypeGetter) {
|
||||||
if(methods.size() < 2) {
|
if(methods.size() < 2) {
|
||||||
return methods;
|
return methods;
|
||||||
}
|
}
|
||||||
final LinkedList<T> maximals = new LinkedList<>();
|
final LinkedList<T> maximals = new LinkedList<>();
|
||||||
for(T m: methods) {
|
for(final T m: methods) {
|
||||||
final MethodType methodType = methodTypeGetter.getMethodType(m);
|
final MethodType methodType = methodTypeGetter.getMethodType(m);
|
||||||
boolean lessSpecific = false;
|
boolean lessSpecific = false;
|
||||||
for(Iterator<T> maximal = maximals.iterator(); maximal.hasNext();) {
|
for(final Iterator<T> maximal = maximals.iterator(); maximal.hasNext();) {
|
||||||
final T max = maximal.next();
|
final T max = maximal.next();
|
||||||
switch(isMoreSpecific(methodType, methodTypeGetter.getMethodType(max), varArgs, argTypes, ls)) {
|
switch(isMoreSpecific(methodType, methodTypeGetter.getMethodType(max), varArgs, argTypes, ls)) {
|
||||||
case TYPE_1_BETTER: {
|
case TYPE_1_BETTER: {
|
||||||
@ -202,8 +202,8 @@ class MaximallySpecific {
|
|||||||
return maximals;
|
return maximals;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Comparison isMoreSpecific(MethodType t1, MethodType t2, boolean varArgs, Class<?>[] argTypes,
|
private static Comparison isMoreSpecific(final MethodType t1, final MethodType t2, final boolean varArgs, final Class<?>[] argTypes,
|
||||||
LinkerServices ls) {
|
final LinkerServices ls) {
|
||||||
final int pc1 = t1.parameterCount();
|
final int pc1 = t1.parameterCount();
|
||||||
final int pc2 = t2.parameterCount();
|
final int pc2 = t2.parameterCount();
|
||||||
assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
|
assert varArgs || (pc1 == pc2) && (argTypes == null || argTypes.length == pc1);
|
||||||
@ -241,7 +241,7 @@ class MaximallySpecific {
|
|||||||
return Comparison.INDETERMINATE;
|
return Comparison.INDETERMINATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Comparison compare(Class<?> c1, Class<?> c2, Class<?>[] argTypes, int i, LinkerServices cmp) {
|
private static Comparison compare(final Class<?> c1, final Class<?> c2, final Class<?>[] argTypes, final int i, final LinkerServices cmp) {
|
||||||
if(cmp != null) {
|
if(cmp != null) {
|
||||||
final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
|
final Comparison c = cmp.compareConversion(argTypes[i], c1, c2);
|
||||||
if(c != Comparison.INDETERMINATE) {
|
if(c != Comparison.INDETERMINATE) {
|
||||||
@ -256,7 +256,7 @@ class MaximallySpecific {
|
|||||||
return Comparison.INDETERMINATE;
|
return Comparison.INDETERMINATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> getParameterClass(MethodType t, int l, int i, boolean varArgs) {
|
private static Class<?> getParameterClass(final MethodType t, final int l, final int i, final boolean varArgs) {
|
||||||
return varArgs && i >= l - 1 ? t.parameterType(l - 1).getComponentType() : t.parameterType(i);
|
return varArgs && i >= l - 1 ? t.parameterType(l - 1).getComponentType() : t.parameterType(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,20 +115,20 @@ class OverloadedDynamicMethod extends DynamicMethod {
|
|||||||
* @param clazz the class this method belongs to
|
* @param clazz the class this method belongs to
|
||||||
* @param name the name of the method
|
* @param name the name of the method
|
||||||
*/
|
*/
|
||||||
OverloadedDynamicMethod(Class<?> clazz, String name) {
|
OverloadedDynamicMethod(final Class<?> clazz, final String name) {
|
||||||
this(new LinkedList<SingleDynamicMethod>(), clazz.getClassLoader(), getClassAndMethodName(clazz, name));
|
this(new LinkedList<SingleDynamicMethod>(), clazz.getClassLoader(), getClassAndMethodName(clazz, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
private OverloadedDynamicMethod(LinkedList<SingleDynamicMethod> methods, ClassLoader classLoader, String name) {
|
private OverloadedDynamicMethod(final LinkedList<SingleDynamicMethod> methods, final ClassLoader classLoader, final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
this.methods = methods;
|
this.methods = methods;
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
SingleDynamicMethod getMethodForExactParamTypes(String paramTypes) {
|
SingleDynamicMethod getMethodForExactParamTypes(final String paramTypes) {
|
||||||
final LinkedList<SingleDynamicMethod> matchingMethods = new LinkedList<>();
|
final LinkedList<SingleDynamicMethod> matchingMethods = new LinkedList<>();
|
||||||
for(SingleDynamicMethod method: methods) {
|
for(final SingleDynamicMethod method: methods) {
|
||||||
final SingleDynamicMethod matchingMethod = method.getMethodForExactParamTypes(paramTypes);
|
final SingleDynamicMethod matchingMethod = method.getMethodForExactParamTypes(paramTypes);
|
||||||
if(matchingMethod != null) {
|
if(matchingMethod != null) {
|
||||||
matchingMethods.add(matchingMethod);
|
matchingMethods.add(matchingMethod);
|
||||||
@ -217,7 +217,7 @@ class OverloadedDynamicMethod extends DynamicMethod {
|
|||||||
// has an already determined Lookup.
|
// has an already determined Lookup.
|
||||||
final List<MethodHandle> methodHandles = new ArrayList<>(invokables.size());
|
final List<MethodHandle> methodHandles = new ArrayList<>(invokables.size());
|
||||||
final MethodHandles.Lookup lookup = callSiteDescriptor.getLookup();
|
final MethodHandles.Lookup lookup = callSiteDescriptor.getLookup();
|
||||||
for(SingleDynamicMethod method: invokables) {
|
for(final SingleDynamicMethod method: invokables) {
|
||||||
methodHandles.add(method.getTarget(lookup));
|
methodHandles.add(method.getTarget(lookup));
|
||||||
}
|
}
|
||||||
return new OverloadedMethod(methodHandles, this, callSiteType, linkerServices).getInvoker();
|
return new OverloadedMethod(methodHandles, this, callSiteType, linkerServices).getInvoker();
|
||||||
@ -227,8 +227,8 @@ class OverloadedDynamicMethod extends DynamicMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(SingleDynamicMethod m) {
|
public boolean contains(final SingleDynamicMethod m) {
|
||||||
for(SingleDynamicMethod method: methods) {
|
for(final SingleDynamicMethod method: methods) {
|
||||||
if(method.contains(m)) {
|
if(method.contains(m)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -240,8 +240,8 @@ class OverloadedDynamicMethod extends DynamicMethod {
|
|||||||
return classLoader;
|
return classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isApplicableDynamically(LinkerServices linkerServices, MethodType callSiteType,
|
private static boolean isApplicableDynamically(final LinkerServices linkerServices, final MethodType callSiteType,
|
||||||
SingleDynamicMethod m) {
|
final SingleDynamicMethod m) {
|
||||||
final MethodType methodType = m.getMethodType();
|
final MethodType methodType = m.getMethodType();
|
||||||
final boolean varArgs = m.isVarArgs();
|
final boolean varArgs = m.isVarArgs();
|
||||||
final int fixedArgLen = methodType.parameterCount() - (varArgs ? 1 : 0);
|
final int fixedArgLen = methodType.parameterCount() - (varArgs ? 1 : 0);
|
||||||
@ -287,13 +287,13 @@ class OverloadedDynamicMethod extends DynamicMethod {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isApplicableDynamically(LinkerServices linkerServices, Class<?> callSiteType,
|
private static boolean isApplicableDynamically(final LinkerServices linkerServices, final Class<?> callSiteType,
|
||||||
Class<?> methodType) {
|
final Class<?> methodType) {
|
||||||
return TypeUtilities.isPotentiallyConvertible(callSiteType, methodType)
|
return TypeUtilities.isPotentiallyConvertible(callSiteType, methodType)
|
||||||
|| linkerServices.canConvert(callSiteType, methodType);
|
|| linkerServices.canConvert(callSiteType, methodType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApplicableOverloadedMethods getApplicables(MethodType callSiteType, ApplicabilityTest test) {
|
private ApplicableOverloadedMethods getApplicables(final MethodType callSiteType, final ApplicabilityTest test) {
|
||||||
return new ApplicableOverloadedMethods(methods, callSiteType, test);
|
return new ApplicableOverloadedMethods(methods, callSiteType, test);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +302,7 @@ class OverloadedDynamicMethod extends DynamicMethod {
|
|||||||
*
|
*
|
||||||
* @param method a method to add
|
* @param method a method to add
|
||||||
*/
|
*/
|
||||||
public void addMethod(SingleDynamicMethod method) {
|
public void addMethod(final SingleDynamicMethod method) {
|
||||||
methods.add(method);
|
methods.add(method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,8 +112,8 @@ class OverloadedMethod {
|
|||||||
private final ArrayList<MethodHandle> fixArgMethods;
|
private final ArrayList<MethodHandle> fixArgMethods;
|
||||||
private final ArrayList<MethodHandle> varArgMethods;
|
private final ArrayList<MethodHandle> varArgMethods;
|
||||||
|
|
||||||
OverloadedMethod(List<MethodHandle> methodHandles, OverloadedDynamicMethod parent, MethodType callSiteType,
|
OverloadedMethod(final List<MethodHandle> methodHandles, final OverloadedDynamicMethod parent, final MethodType callSiteType,
|
||||||
LinkerServices linkerServices) {
|
final LinkerServices linkerServices) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
final Class<?> commonRetType = getCommonReturnType(methodHandles);
|
final Class<?> commonRetType = getCommonReturnType(methodHandles);
|
||||||
this.callSiteType = callSiteType.changeReturnType(commonRetType);
|
this.callSiteType = callSiteType.changeReturnType(commonRetType);
|
||||||
@ -151,7 +151,7 @@ class OverloadedMethod {
|
|||||||
MethodHandle.class, Object[].class);
|
MethodHandle.class, Object[].class);
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private MethodHandle selectMethod(Object[] args) throws NoSuchMethodException {
|
private MethodHandle selectMethod(final Object[] args) throws NoSuchMethodException {
|
||||||
final Class<?>[] argTypes = new Class[args.length];
|
final Class<?>[] argTypes = new Class[args.length];
|
||||||
for(int i = 0; i < argTypes.length; ++i) {
|
for(int i = 0; i < argTypes.length; ++i) {
|
||||||
final Object arg = args[i];
|
final Object arg = args[i];
|
||||||
@ -188,7 +188,7 @@ class OverloadedMethod {
|
|||||||
return method;
|
return method;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodHandle getNoSuchMethodThrower(Class<?>[] argTypes) {
|
private MethodHandle getNoSuchMethodThrower(final Class<?>[] argTypes) {
|
||||||
return adaptThrower(MethodHandles.insertArguments(THROW_NO_SUCH_METHOD, 0, this, argTypes));
|
return adaptThrower(MethodHandles.insertArguments(THROW_NO_SUCH_METHOD, 0, this, argTypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ class OverloadedMethod {
|
|||||||
"throwNoSuchMethod", void.class, Class[].class);
|
"throwNoSuchMethod", void.class, Class[].class);
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private void throwNoSuchMethod(Class<?>[] argTypes) throws NoSuchMethodException {
|
private void throwNoSuchMethod(final Class<?>[] argTypes) throws NoSuchMethodException {
|
||||||
if(varArgMethods.isEmpty()) {
|
if(varArgMethods.isEmpty()) {
|
||||||
throw new NoSuchMethodException("None of the fixed arity signatures " + getSignatureList(fixArgMethods) +
|
throw new NoSuchMethodException("None of the fixed arity signatures " + getSignatureList(fixArgMethods) +
|
||||||
" of method " + parent.getName() + " match the argument types " + argTypesString(argTypes));
|
" of method " + parent.getName() + " match the argument types " + argTypesString(argTypes));
|
||||||
@ -206,11 +206,11 @@ class OverloadedMethod {
|
|||||||
parent.getName() + " match the argument types " + argTypesString(argTypes));
|
parent.getName() + " match the argument types " + argTypesString(argTypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodHandle getAmbiguousMethodThrower(Class<?>[] argTypes, List<MethodHandle> methods) {
|
private MethodHandle getAmbiguousMethodThrower(final Class<?>[] argTypes, final List<MethodHandle> methods) {
|
||||||
return adaptThrower(MethodHandles.insertArguments(THROW_AMBIGUOUS_METHOD, 0, this, argTypes, methods));
|
return adaptThrower(MethodHandles.insertArguments(THROW_AMBIGUOUS_METHOD, 0, this, argTypes, methods));
|
||||||
}
|
}
|
||||||
|
|
||||||
private MethodHandle adaptThrower(MethodHandle rawThrower) {
|
private MethodHandle adaptThrower(final MethodHandle rawThrower) {
|
||||||
return MethodHandles.dropArguments(rawThrower, 0, callSiteType.parameterList()).asType(callSiteType);
|
return MethodHandles.dropArguments(rawThrower, 0, callSiteType.parameterList()).asType(callSiteType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,20 +218,20 @@ class OverloadedMethod {
|
|||||||
"throwAmbiguousMethod", void.class, Class[].class, List.class);
|
"throwAmbiguousMethod", void.class, Class[].class, List.class);
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private void throwAmbiguousMethod(Class<?>[] argTypes, List<MethodHandle> methods) throws NoSuchMethodException {
|
private void throwAmbiguousMethod(final Class<?>[] argTypes, final List<MethodHandle> methods) throws NoSuchMethodException {
|
||||||
final String arity = methods.get(0).isVarargsCollector() ? "variable" : "fixed";
|
final String arity = methods.get(0).isVarargsCollector() ? "variable" : "fixed";
|
||||||
throw new NoSuchMethodException("Can't unambiguously select between " + arity + " arity signatures " +
|
throw new NoSuchMethodException("Can't unambiguously select between " + arity + " arity signatures " +
|
||||||
getSignatureList(methods) + " of the method " + parent.getName() + " for argument types " +
|
getSignatureList(methods) + " of the method " + parent.getName() + " for argument types " +
|
||||||
argTypesString(argTypes));
|
argTypesString(argTypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String argTypesString(Class<?>[] classes) {
|
private static String argTypesString(final Class<?>[] classes) {
|
||||||
final StringBuilder b = new StringBuilder().append('[');
|
final StringBuilder b = new StringBuilder().append('[');
|
||||||
appendTypes(b, classes, false);
|
appendTypes(b, classes, false);
|
||||||
return b.append(']').toString();
|
return b.append(']').toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getSignatureList(List<MethodHandle> methods) {
|
private static String getSignatureList(final List<MethodHandle> methods) {
|
||||||
final StringBuilder b = new StringBuilder().append('[');
|
final StringBuilder b = new StringBuilder().append('[');
|
||||||
final Iterator<MethodHandle> it = methods.iterator();
|
final Iterator<MethodHandle> it = methods.iterator();
|
||||||
if(it.hasNext()) {
|
if(it.hasNext()) {
|
||||||
@ -243,13 +243,13 @@ class OverloadedMethod {
|
|||||||
return b.append(']').toString();
|
return b.append(']').toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void appendSig(StringBuilder b, MethodHandle m) {
|
private static void appendSig(final StringBuilder b, final MethodHandle m) {
|
||||||
b.append('(');
|
b.append('(');
|
||||||
appendTypes(b, m.type().parameterArray(), m.isVarargsCollector());
|
appendTypes(b, m.type().parameterArray(), m.isVarargsCollector());
|
||||||
b.append(')');
|
b.append(')');
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void appendTypes(StringBuilder b, Class<?>[] classes, boolean varArg) {
|
private static void appendTypes(final StringBuilder b, final Class<?>[] classes, final boolean varArg) {
|
||||||
final int l = classes.length;
|
final int l = classes.length;
|
||||||
if(!varArg) {
|
if(!varArg) {
|
||||||
if(l > 1) {
|
if(l > 1) {
|
||||||
@ -266,7 +266,7 @@ class OverloadedMethod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> getCommonReturnType(List<MethodHandle> methodHandles) {
|
private static Class<?> getCommonReturnType(final List<MethodHandle> methodHandles) {
|
||||||
final Iterator<MethodHandle> it = methodHandles.iterator();
|
final Iterator<MethodHandle> it = methodHandles.iterator();
|
||||||
Class<?> retType = it.next().type().returnType();
|
Class<?> retType = it.next().type().returnType();
|
||||||
while(it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
|
@ -107,12 +107,12 @@ class SimpleDynamicMethod extends SingleDynamicMethod {
|
|||||||
* @param clazz the class declaring the method
|
* @param clazz the class declaring the method
|
||||||
* @param name the simple name of the method
|
* @param name the simple name of the method
|
||||||
*/
|
*/
|
||||||
SimpleDynamicMethod(MethodHandle target, Class<?> clazz, String name) {
|
SimpleDynamicMethod(final MethodHandle target, final Class<?> clazz, final String name) {
|
||||||
super(getName(target, clazz, name));
|
super(getName(target, clazz, name));
|
||||||
this.target = target;
|
this.target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getName(MethodHandle target, Class<?> clazz, String name) {
|
private static String getName(final MethodHandle target, final Class<?> clazz, final String name) {
|
||||||
return getMethodNameWithSignature(target.type(), getClassAndMethodName(clazz, name));
|
return getMethodNameWithSignature(target.type(), getClassAndMethodName(clazz, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ class SimpleDynamicMethod extends SingleDynamicMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
MethodHandle getTarget(Lookup lookup) {
|
MethodHandle getTarget(final Lookup lookup) {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ abstract class SingleDynamicMethod extends DynamicMethod {
|
|||||||
|
|
||||||
private static final MethodHandle CAN_CONVERT_TO = Lookup.findOwnStatic(MethodHandles.lookup(), "canConvertTo", boolean.class, LinkerServices.class, Class.class, Object.class);
|
private static final MethodHandle CAN_CONVERT_TO = Lookup.findOwnStatic(MethodHandles.lookup(), "canConvertTo", boolean.class, LinkerServices.class, Class.class, Object.class);
|
||||||
|
|
||||||
SingleDynamicMethod(String name) {
|
SingleDynamicMethod(final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,22 +128,22 @@ abstract class SingleDynamicMethod extends DynamicMethod {
|
|||||||
abstract MethodHandle getTarget(MethodHandles.Lookup lookup);
|
abstract MethodHandle getTarget(MethodHandles.Lookup lookup);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
MethodHandle getInvocation(CallSiteDescriptor callSiteDescriptor, LinkerServices linkerServices) {
|
MethodHandle getInvocation(final CallSiteDescriptor callSiteDescriptor, final LinkerServices linkerServices) {
|
||||||
return getInvocation(getTarget(callSiteDescriptor.getLookup()), callSiteDescriptor.getMethodType(),
|
return getInvocation(getTarget(callSiteDescriptor.getLookup()), callSiteDescriptor.getMethodType(),
|
||||||
linkerServices);
|
linkerServices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
SingleDynamicMethod getMethodForExactParamTypes(String paramTypes) {
|
SingleDynamicMethod getMethodForExactParamTypes(final String paramTypes) {
|
||||||
return typeMatchesDescription(paramTypes, getMethodType()) ? this : null;
|
return typeMatchesDescription(paramTypes, getMethodType()) ? this : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean contains(SingleDynamicMethod method) {
|
boolean contains(final SingleDynamicMethod method) {
|
||||||
return getMethodType().parameterList().equals(method.getMethodType().parameterList());
|
return getMethodType().parameterList().equals(method.getMethodType().parameterList());
|
||||||
}
|
}
|
||||||
|
|
||||||
static String getMethodNameWithSignature(MethodType type, String methodName) {
|
static String getMethodNameWithSignature(final MethodType type, final String methodName) {
|
||||||
final String typeStr = type.toString();
|
final String typeStr = type.toString();
|
||||||
final int retTypeIndex = typeStr.lastIndexOf(')') + 1;
|
final int retTypeIndex = typeStr.lastIndexOf(')') + 1;
|
||||||
int secondParamIndex = typeStr.indexOf(',') + 1;
|
int secondParamIndex = typeStr.indexOf(',') + 1;
|
||||||
@ -164,7 +164,7 @@ abstract class SingleDynamicMethod extends DynamicMethod {
|
|||||||
* @param linkerServices the linker services used for type conversions
|
* @param linkerServices the linker services used for type conversions
|
||||||
* @return the adapted method handle.
|
* @return the adapted method handle.
|
||||||
*/
|
*/
|
||||||
static MethodHandle getInvocation(MethodHandle target, MethodType callSiteType, LinkerServices linkerServices) {
|
static MethodHandle getInvocation(final MethodHandle target, final MethodType callSiteType, final LinkerServices linkerServices) {
|
||||||
final MethodType methodType = target.type();
|
final MethodType methodType = target.type();
|
||||||
final int paramsLen = methodType.parameterCount();
|
final int paramsLen = methodType.parameterCount();
|
||||||
final boolean varArgs = target.isVarargsCollector();
|
final boolean varArgs = target.isVarargsCollector();
|
||||||
@ -266,7 +266,7 @@ abstract class SingleDynamicMethod extends DynamicMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static boolean canConvertTo(final LinkerServices linkerServices, Class<?> to, Object obj) {
|
private static boolean canConvertTo(final LinkerServices linkerServices, final Class<?> to, final Object obj) {
|
||||||
return obj == null ? false : linkerServices.canConvert(obj.getClass(), to);
|
return obj == null ? false : linkerServices.canConvert(obj.getClass(), to);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ abstract class SingleDynamicMethod extends DynamicMethod {
|
|||||||
* @param parameterCount the total number of arguments in the new method handle
|
* @param parameterCount the total number of arguments in the new method handle
|
||||||
* @return a collecting method handle
|
* @return a collecting method handle
|
||||||
*/
|
*/
|
||||||
static MethodHandle collectArguments(MethodHandle target, final int parameterCount) {
|
static MethodHandle collectArguments(final MethodHandle target, final int parameterCount) {
|
||||||
final MethodType methodType = target.type();
|
final MethodType methodType = target.type();
|
||||||
final int fixParamsLen = methodType.parameterCount() - 1;
|
final int fixParamsLen = methodType.parameterCount() - 1;
|
||||||
final Class<?> arrayType = methodType.parameterType(fixParamsLen);
|
final Class<?> arrayType = methodType.parameterType(fixParamsLen);
|
||||||
@ -291,7 +291,7 @@ abstract class SingleDynamicMethod extends DynamicMethod {
|
|||||||
return linkerServices.asTypeLosslessReturn(sizedMethod, callSiteType);
|
return linkerServices.asTypeLosslessReturn(sizedMethod, callSiteType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean typeMatchesDescription(String paramTypes, MethodType type) {
|
private static boolean typeMatchesDescription(final String paramTypes, final MethodType type) {
|
||||||
final StringTokenizer tok = new StringTokenizer(paramTypes, ", ");
|
final StringTokenizer tok = new StringTokenizer(paramTypes, ", ");
|
||||||
for(int i = 1; i < type.parameterCount(); ++i) { // i = 1 as we ignore the receiver
|
for(int i = 1; i < type.parameterCount(); ++i) { // i = 1 as we ignore the receiver
|
||||||
if(!(tok.hasMoreTokens() && typeNameMatches(tok.nextToken(), type.parameterType(i)))) {
|
if(!(tok.hasMoreTokens() && typeNameMatches(tok.nextToken(), type.parameterType(i)))) {
|
||||||
@ -301,7 +301,7 @@ abstract class SingleDynamicMethod extends DynamicMethod {
|
|||||||
return !tok.hasMoreTokens();
|
return !tok.hasMoreTokens();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean typeNameMatches(String typeName, Class<?> type) {
|
private static boolean typeNameMatches(final String typeName, final Class<?> type) {
|
||||||
return typeName.equals(typeName.indexOf('.') == -1 ? type.getSimpleName() : type.getCanonicalName());
|
return typeName.equals(typeName.indexOf('.') == -1 ? type.getSimpleName() : type.getCanonicalName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ import java.io.Serializable;
|
|||||||
public class StaticClass implements Serializable {
|
public class StaticClass implements Serializable {
|
||||||
private static final ClassValue<StaticClass> staticClasses = new ClassValue<StaticClass>() {
|
private static final ClassValue<StaticClass> staticClasses = new ClassValue<StaticClass>() {
|
||||||
@Override
|
@Override
|
||||||
protected StaticClass computeValue(Class<?> type) {
|
protected StaticClass computeValue(final Class<?> type) {
|
||||||
return new StaticClass(type);
|
return new StaticClass(type);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -105,7 +105,7 @@ public class StaticClass implements Serializable {
|
|||||||
|
|
||||||
private final Class<?> clazz;
|
private final Class<?> clazz;
|
||||||
|
|
||||||
/*private*/ StaticClass(Class<?> clazz) {
|
/*private*/ StaticClass(final Class<?> clazz) {
|
||||||
clazz.getClass(); // NPE check
|
clazz.getClass(); // NPE check
|
||||||
this.clazz = clazz;
|
this.clazz = clazz;
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ public class StaticClass implements Serializable {
|
|||||||
* @param clazz the class for which the static facet is requested.
|
* @param clazz the class for which the static facet is requested.
|
||||||
* @return the {@link StaticClass} instance representing the specified class.
|
* @return the {@link StaticClass} instance representing the specified class.
|
||||||
*/
|
*/
|
||||||
public static StaticClass forClass(Class<?> clazz) {
|
public static StaticClass forClass(final Class<?> clazz) {
|
||||||
return staticClasses.get(clazz);
|
return staticClasses.get(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,14 +90,14 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
class StaticClassIntrospector extends FacetIntrospector {
|
class StaticClassIntrospector extends FacetIntrospector {
|
||||||
StaticClassIntrospector(Class<?> clazz) {
|
StaticClassIntrospector(final Class<?> clazz) {
|
||||||
super(clazz, false);
|
super(clazz, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Map<String, MethodHandle> getInnerClassGetters() {
|
Map<String, MethodHandle> getInnerClassGetters() {
|
||||||
final Map<String, MethodHandle> map = new HashMap<>();
|
final Map<String, MethodHandle> map = new HashMap<>();
|
||||||
for(Class<?> innerClass: membersLookup.getInnerClasses()) {
|
for(final Class<?> innerClass: membersLookup.getInnerClasses()) {
|
||||||
map.put(innerClass.getSimpleName(), editMethodHandle(MethodHandles.constant(StaticClass.class,
|
map.put(innerClass.getSimpleName(), editMethodHandle(MethodHandles.constant(StaticClass.class,
|
||||||
StaticClass.forClass(innerClass))));
|
StaticClass.forClass(innerClass))));
|
||||||
}
|
}
|
||||||
@ -105,15 +105,15 @@ class StaticClassIntrospector extends FacetIntrospector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
MethodHandle editMethodHandle(MethodHandle mh) {
|
MethodHandle editMethodHandle(final MethodHandle mh) {
|
||||||
return editStaticMethodHandle(mh);
|
return editStaticMethodHandle(mh);
|
||||||
}
|
}
|
||||||
|
|
||||||
static MethodHandle editStaticMethodHandle(MethodHandle mh) {
|
static MethodHandle editStaticMethodHandle(final MethodHandle mh) {
|
||||||
return dropReceiver(mh, Object.class);
|
return dropReceiver(mh, Object.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
static MethodHandle editConstructorMethodHandle(MethodHandle cmh) {
|
static MethodHandle editConstructorMethodHandle(final MethodHandle cmh) {
|
||||||
return dropReceiver(cmh, StaticClass.class);
|
return dropReceiver(cmh, StaticClass.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ import jdk.internal.dynalink.support.Lookup;
|
|||||||
class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
||||||
private static final ClassValue<SingleClassStaticsLinker> linkers = new ClassValue<SingleClassStaticsLinker>() {
|
private static final ClassValue<SingleClassStaticsLinker> linkers = new ClassValue<SingleClassStaticsLinker>() {
|
||||||
@Override
|
@Override
|
||||||
protected SingleClassStaticsLinker computeValue(Class<?> clazz) {
|
protected SingleClassStaticsLinker computeValue(final Class<?> clazz) {
|
||||||
return new SingleClassStaticsLinker(clazz);
|
return new SingleClassStaticsLinker(clazz);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -112,7 +112,7 @@ class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
|||||||
private static class SingleClassStaticsLinker extends AbstractJavaLinker {
|
private static class SingleClassStaticsLinker extends AbstractJavaLinker {
|
||||||
private final DynamicMethod constructor;
|
private final DynamicMethod constructor;
|
||||||
|
|
||||||
SingleClassStaticsLinker(Class<?> clazz) {
|
SingleClassStaticsLinker(final Class<?> clazz) {
|
||||||
super(clazz, IS_CLASS.bindTo(clazz));
|
super(clazz, IS_CLASS.bindTo(clazz));
|
||||||
// Map "staticClassObject.class" to StaticClass.getRepresentedClass(). Some adventurous soul could subclass
|
// Map "staticClassObject.class" to StaticClass.getRepresentedClass(). Some adventurous soul could subclass
|
||||||
// StaticClass, so we use INSTANCE_OF validation instead of EXACT_CLASS.
|
// StaticClass, so we use INSTANCE_OF validation instead of EXACT_CLASS.
|
||||||
@ -126,7 +126,7 @@ class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
|||||||
* @return a dynamic method containing all overloads of a class' public constructor. If the class has no public
|
* @return a dynamic method containing all overloads of a class' public constructor. If the class has no public
|
||||||
* constructors, returns null.
|
* constructors, returns null.
|
||||||
*/
|
*/
|
||||||
private static DynamicMethod createConstructorMethod(Class<?> clazz) {
|
private static DynamicMethod createConstructorMethod(final Class<?> clazz) {
|
||||||
if(clazz.isArray()) {
|
if(clazz.isArray()) {
|
||||||
final MethodHandle boundArrayCtor = ARRAY_CTOR.bindTo(clazz.getComponentType());
|
final MethodHandle boundArrayCtor = ARRAY_CTOR.bindTo(clazz.getComponentType());
|
||||||
return new SimpleDynamicMethod(StaticClassIntrospector.editConstructorMethodHandle(
|
return new SimpleDynamicMethod(StaticClassIntrospector.editConstructorMethodHandle(
|
||||||
@ -144,7 +144,7 @@ class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation getGuardedInvocation(LinkRequest request, LinkerServices linkerServices)
|
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final GuardedInvocation gi = super.getGuardedInvocation(request, linkerServices);
|
final GuardedInvocation gi = super.getGuardedInvocation(request, linkerServices);
|
||||||
if(gi != null) {
|
if(gi != null) {
|
||||||
@ -162,20 +162,20 @@ class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Collection<String> getReadableStaticPropertyNames(Class<?> clazz) {
|
static Collection<String> getReadableStaticPropertyNames(final Class<?> clazz) {
|
||||||
return linkers.get(clazz).getReadablePropertyNames();
|
return linkers.get(clazz).getReadablePropertyNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Collection<String> getWritableStaticPropertyNames(Class<?> clazz) {
|
static Collection<String> getWritableStaticPropertyNames(final Class<?> clazz) {
|
||||||
return linkers.get(clazz).getWritablePropertyNames();
|
return linkers.get(clazz).getWritablePropertyNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Collection<String> getStaticMethodNames(Class<?> clazz) {
|
static Collection<String> getStaticMethodNames(final Class<?> clazz) {
|
||||||
return linkers.get(clazz).getMethodNames();
|
return linkers.get(clazz).getMethodNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation getGuardedInvocation(LinkRequest request, LinkerServices linkerServices) throws Exception {
|
public GuardedInvocation getGuardedInvocation(final LinkRequest request, final LinkerServices linkerServices) throws Exception {
|
||||||
final Object receiver = request.getReceiver();
|
final Object receiver = request.getReceiver();
|
||||||
if(receiver instanceof StaticClass) {
|
if(receiver instanceof StaticClass) {
|
||||||
return linkers.get(((StaticClass)receiver).getRepresentedClass()).getGuardedInvocation(request,
|
return linkers.get(((StaticClass)receiver).getRepresentedClass()).getGuardedInvocation(request,
|
||||||
@ -185,7 +185,7 @@ class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canLinkType(Class<?> type) {
|
public boolean canLinkType(final Class<?> type) {
|
||||||
return type == StaticClass.class;
|
return type == StaticClass.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +201,7 @@ class StaticClassLinker implements TypeBasedGuardingDynamicLinker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static boolean isClass(Class<?> clazz, Object obj) {
|
private static boolean isClass(final Class<?> clazz, final Object obj) {
|
||||||
return obj instanceof StaticClass && ((StaticClass)obj).getRepresentedClass() == clazz;
|
return obj instanceof StaticClass && ((StaticClass)obj).getRepresentedClass() == clazz;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,6 @@ import java.lang.invoke.MethodType;
|
|||||||
import java.lang.invoke.SwitchPoint;
|
import java.lang.invoke.SwitchPoint;
|
||||||
import java.lang.invoke.WrongMethodTypeException;
|
import java.lang.invoke.WrongMethodTypeException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.internal.dynalink.CallSiteDescriptor;
|
import jdk.internal.dynalink.CallSiteDescriptor;
|
||||||
import jdk.internal.dynalink.support.Guards;
|
import jdk.internal.dynalink.support.Guards;
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ public interface LinkerServices {
|
|||||||
* @param fromType the passed type
|
* @param fromType the passed type
|
||||||
* @return the converted method handle, as per the {@code asTypeSafeReturn} semantics.
|
* @return the converted method handle, as per the {@code asTypeSafeReturn} semantics.
|
||||||
*/
|
*/
|
||||||
public static MethodHandle asTypeLosslessReturn(LinkerServices linkerServices, MethodHandle handle, MethodType fromType) {
|
public static MethodHandle asTypeLosslessReturn(final LinkerServices linkerServices, final MethodHandle handle, final MethodType fromType) {
|
||||||
final Class<?> handleReturnType = handle.type().returnType();
|
final Class<?> handleReturnType = handle.type().returnType();
|
||||||
return linkerServices.asType(handle, TypeUtilities.isConvertibleWithoutLoss(handleReturnType, fromType.returnType()) ?
|
return linkerServices.asType(handle, TypeUtilities.isConvertibleWithoutLoss(handleReturnType, fromType.returnType()) ?
|
||||||
fromType : fromType.changeReturnType(handleReturnType));
|
fromType : fromType.changeReturnType(handleReturnType));
|
||||||
|
@ -106,7 +106,7 @@ public abstract class AbstractCallSiteDescriptor implements CallSiteDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(final Object obj) {
|
||||||
return obj instanceof CallSiteDescriptor && equals((CallSiteDescriptor)obj);
|
return obj instanceof CallSiteDescriptor && equals((CallSiteDescriptor)obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ public abstract class AbstractCallSiteDescriptor implements CallSiteDescriptor {
|
|||||||
* @param csd the other call site descriptor.
|
* @param csd the other call site descriptor.
|
||||||
* @return true if they are equal.
|
* @return true if they are equal.
|
||||||
*/
|
*/
|
||||||
public boolean equals(CallSiteDescriptor csd) {
|
public boolean equals(final CallSiteDescriptor csd) {
|
||||||
if(csd == null) {
|
if(csd == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ public abstract class AbstractCallSiteDescriptor implements CallSiteDescriptor {
|
|||||||
return l + c - 1;
|
return l + c - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringBuilder appendName(StringBuilder b) {
|
private StringBuilder appendName(final StringBuilder b) {
|
||||||
b.append(getNameToken(0));
|
b.append(getNameToken(0));
|
||||||
final int c = getNameTokenCount();
|
final int c = getNameTokenCount();
|
||||||
for(int i = 1; i < c; ++i) {
|
for(int i = 1; i < c; ++i) {
|
||||||
@ -174,7 +174,7 @@ public abstract class AbstractCallSiteDescriptor implements CallSiteDescriptor {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean lookupsEqual(Lookup l1, Lookup l2) {
|
private static boolean lookupsEqual(final Lookup l1, final Lookup l2) {
|
||||||
if(l1 == l2) {
|
if(l1 == l2) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ public abstract class AbstractRelinkableCallSite extends MutableCallSite impleme
|
|||||||
* Creates a new relinkable call site.
|
* Creates a new relinkable call site.
|
||||||
* @param descriptor the descriptor for this call site
|
* @param descriptor the descriptor for this call site
|
||||||
*/
|
*/
|
||||||
protected AbstractRelinkableCallSite(CallSiteDescriptor descriptor) {
|
protected AbstractRelinkableCallSite(final CallSiteDescriptor descriptor) {
|
||||||
super(descriptor.getMethodType());
|
super(descriptor.getMethodType());
|
||||||
this.descriptor = descriptor;
|
this.descriptor = descriptor;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ public abstract class AbstractRelinkableCallSite extends MutableCallSite impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(MethodHandle relinkAndInvoke) {
|
public void initialize(final MethodHandle relinkAndInvoke) {
|
||||||
setTarget(relinkAndInvoke);
|
setTarget(relinkAndInvoke);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,14 +116,14 @@ public class AutoDiscovery {
|
|||||||
* @return a list of guarding dynamic linkers available through the specified class loader. Can be zero-length list
|
* @return a list of guarding dynamic linkers available through the specified class loader. Can be zero-length list
|
||||||
* but not null.
|
* but not null.
|
||||||
*/
|
*/
|
||||||
public static List<GuardingDynamicLinker> loadLinkers(ClassLoader cl) {
|
public static List<GuardingDynamicLinker> loadLinkers(final ClassLoader cl) {
|
||||||
return getLinkers(ServiceLoader.load(GuardingDynamicLinker.class, cl));
|
return getLinkers(ServiceLoader.load(GuardingDynamicLinker.class, cl));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I can't believe there's no Collections API for making a List given an Iterator...
|
* I can't believe there's no Collections API for making a List given an Iterator...
|
||||||
*/
|
*/
|
||||||
private static <T> List<T> getLinkers(ServiceLoader<T> loader) {
|
private static <T> List<T> getLinkers(final ServiceLoader<T> loader) {
|
||||||
final List<T> list = new LinkedList<>();
|
final List<T> list = new LinkedList<>();
|
||||||
for(final T linker: loader) {
|
for(final T linker: loader) {
|
||||||
list.add(linker);
|
list.add(linker);
|
||||||
|
@ -105,12 +105,12 @@ public class BottomGuardingDynamicLinker implements TypeBasedGuardingDynamicLink
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canLinkType(Class<?> type) {
|
public boolean canLinkType(final Class<?> type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, LinkerServices linkerServices) {
|
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
* @return a call site descriptor representing the input. Note that although the method name is "create", it will
|
* @return a call site descriptor representing the input. Note that although the method name is "create", it will
|
||||||
* in fact return a weakly-referenced canonical instance.
|
* in fact return a weakly-referenced canonical instance.
|
||||||
*/
|
*/
|
||||||
public static CallSiteDescriptor create(Lookup lookup, String name, MethodType methodType) {
|
public static CallSiteDescriptor create(final Lookup lookup, final String name, final MethodType methodType) {
|
||||||
name.getClass(); // NPE check
|
name.getClass(); // NPE check
|
||||||
methodType.getClass(); // NPE check
|
methodType.getClass(); // NPE check
|
||||||
lookup.getClass(); // NPE check
|
lookup.getClass(); // NPE check
|
||||||
@ -156,7 +156,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
return new WeakReference<>(desc);
|
return new WeakReference<>(desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CallSiteDescriptor createPublicCallSiteDescriptor(String[] tokenizedName, MethodType methodType) {
|
private static CallSiteDescriptor createPublicCallSiteDescriptor(final String[] tokenizedName, final MethodType methodType) {
|
||||||
final int l = tokenizedName.length;
|
final int l = tokenizedName.length;
|
||||||
if(l > 0 && tokenizedName[0] == "dyn") {
|
if(l > 0 && tokenizedName[0] == "dyn") {
|
||||||
if(l == 2) {
|
if(l == 2) {
|
||||||
@ -168,7 +168,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
return new DefaultCallSiteDescriptor(tokenizedName, methodType);
|
return new DefaultCallSiteDescriptor(tokenizedName, methodType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isPublicLookup(Lookup lookup) {
|
private static boolean isPublicLookup(final Lookup lookup) {
|
||||||
return lookup == MethodHandles.publicLookup();
|
return lookup == MethodHandles.publicLookup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,7 +179,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
* @param name the composite name consisting of colon-separated, possibly mangled tokens.
|
* @param name the composite name consisting of colon-separated, possibly mangled tokens.
|
||||||
* @return an array of tokens
|
* @return an array of tokens
|
||||||
*/
|
*/
|
||||||
public static String[] tokenizeName(String name) {
|
public static String[] tokenizeName(final String name) {
|
||||||
final StringTokenizer tok = new StringTokenizer(name, CallSiteDescriptor.TOKEN_DELIMITER);
|
final StringTokenizer tok = new StringTokenizer(name, CallSiteDescriptor.TOKEN_DELIMITER);
|
||||||
final String[] tokens = new String[tok.countTokens()];
|
final String[] tokens = new String[tok.countTokens()];
|
||||||
for(int i = 0; i < tokens.length; ++i) {
|
for(int i = 0; i < tokens.length; ++i) {
|
||||||
@ -198,7 +198,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
* @param desc the call site descriptor with the operation
|
* @param desc the call site descriptor with the operation
|
||||||
* @return a list of tokens
|
* @return a list of tokens
|
||||||
*/
|
*/
|
||||||
public static List<String> tokenizeOperators(CallSiteDescriptor desc) {
|
public static List<String> tokenizeOperators(final CallSiteDescriptor desc) {
|
||||||
final String ops = desc.getNameToken(CallSiteDescriptor.OPERATOR);
|
final String ops = desc.getNameToken(CallSiteDescriptor.OPERATOR);
|
||||||
final StringTokenizer tok = new StringTokenizer(ops, CallSiteDescriptor.OPERATOR_DELIMITER);
|
final StringTokenizer tok = new StringTokenizer(ops, CallSiteDescriptor.OPERATOR_DELIMITER);
|
||||||
final int count = tok.countTokens();
|
final int count = tok.countTokens();
|
||||||
@ -220,7 +220,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
* @param end index of the first parameter to not remove
|
* @param end index of the first parameter to not remove
|
||||||
* @return a new call site descriptor with modified method type
|
* @return a new call site descriptor with modified method type
|
||||||
*/
|
*/
|
||||||
public static CallSiteDescriptor dropParameterTypes(CallSiteDescriptor desc, int start, int end) {
|
public static CallSiteDescriptor dropParameterTypes(final CallSiteDescriptor desc, final int start, final int end) {
|
||||||
return desc.changeMethodType(desc.getMethodType().dropParameterTypes(start, end));
|
return desc.changeMethodType(desc.getMethodType().dropParameterTypes(start, end));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
* @param nptype the new parameter type
|
* @param nptype the new parameter type
|
||||||
* @return a new call site descriptor with modified method type
|
* @return a new call site descriptor with modified method type
|
||||||
*/
|
*/
|
||||||
public static CallSiteDescriptor changeParameterType(CallSiteDescriptor desc, int num, Class<?> nptype) {
|
public static CallSiteDescriptor changeParameterType(final CallSiteDescriptor desc, final int num, final Class<?> nptype) {
|
||||||
return desc.changeMethodType(desc.getMethodType().changeParameterType(num, nptype));
|
return desc.changeMethodType(desc.getMethodType().changeParameterType(num, nptype));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
* @param nrtype the new return type
|
* @param nrtype the new return type
|
||||||
* @return a new call site descriptor with modified method type
|
* @return a new call site descriptor with modified method type
|
||||||
*/
|
*/
|
||||||
public static CallSiteDescriptor changeReturnType(CallSiteDescriptor desc, Class<?> nrtype) {
|
public static CallSiteDescriptor changeReturnType(final CallSiteDescriptor desc, final Class<?> nrtype) {
|
||||||
return desc.changeMethodType(desc.getMethodType().changeReturnType(nrtype));
|
return desc.changeMethodType(desc.getMethodType().changeReturnType(nrtype));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
* @param ptypesToInsert the new types to insert
|
* @param ptypesToInsert the new types to insert
|
||||||
* @return a new call site descriptor with modified method type
|
* @return a new call site descriptor with modified method type
|
||||||
*/
|
*/
|
||||||
public static CallSiteDescriptor insertParameterTypes(CallSiteDescriptor desc, int num, Class<?>... ptypesToInsert) {
|
public static CallSiteDescriptor insertParameterTypes(final CallSiteDescriptor desc, final int num, final Class<?>... ptypesToInsert) {
|
||||||
return desc.changeMethodType(desc.getMethodType().insertParameterTypes(num, ptypesToInsert));
|
return desc.changeMethodType(desc.getMethodType().insertParameterTypes(num, ptypesToInsert));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ public class CallSiteDescriptorFactory {
|
|||||||
* @param ptypesToInsert the new types to insert
|
* @param ptypesToInsert the new types to insert
|
||||||
* @return a new call site descriptor with modified method type
|
* @return a new call site descriptor with modified method type
|
||||||
*/
|
*/
|
||||||
public static CallSiteDescriptor insertParameterTypes(CallSiteDescriptor desc, int num, List<Class<?>> ptypesToInsert) {
|
public static CallSiteDescriptor insertParameterTypes(final CallSiteDescriptor desc, final int num, final List<Class<?>> ptypesToInsert) {
|
||||||
return desc.changeMethodType(desc.getMethodType().insertParameterTypes(num, ptypesToInsert));
|
return desc.changeMethodType(desc.getMethodType().insertParameterTypes(num, ptypesToInsert));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ public abstract class ClassMap<T> {
|
|||||||
*
|
*
|
||||||
* @param classLoader the classloader that determines strong referenceability.
|
* @param classLoader the classloader that determines strong referenceability.
|
||||||
*/
|
*/
|
||||||
protected ClassMap(ClassLoader classLoader) {
|
protected ClassMap(final ClassLoader classLoader) {
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,16 +109,16 @@ public class CompositeGuardingDynamicLinker implements GuardingDynamicLinker, Se
|
|||||||
*
|
*
|
||||||
* @param linkers a list of component linkers.
|
* @param linkers a list of component linkers.
|
||||||
*/
|
*/
|
||||||
public CompositeGuardingDynamicLinker(Iterable<? extends GuardingDynamicLinker> linkers) {
|
public CompositeGuardingDynamicLinker(final Iterable<? extends GuardingDynamicLinker> linkers) {
|
||||||
final List<GuardingDynamicLinker> l = new LinkedList<>();
|
final List<GuardingDynamicLinker> l = new LinkedList<>();
|
||||||
for(GuardingDynamicLinker linker: linkers) {
|
for(final GuardingDynamicLinker linker: linkers) {
|
||||||
l.add(linker);
|
l.add(linker);
|
||||||
}
|
}
|
||||||
this.linkers = l.toArray(new GuardingDynamicLinker[l.size()]);
|
this.linkers = l.toArray(new GuardingDynamicLinker[l.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, final LinkerServices linkerServices)
|
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
for(final GuardingDynamicLinker linker: linkers) {
|
for(final GuardingDynamicLinker linker: linkers) {
|
||||||
final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices);
|
final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices);
|
||||||
|
@ -112,7 +112,7 @@ public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardin
|
|||||||
private final List<TypeBasedGuardingDynamicLinker>[] singletonLinkers;
|
private final List<TypeBasedGuardingDynamicLinker>[] singletonLinkers;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
ClassToLinker(TypeBasedGuardingDynamicLinker[] linkers) {
|
ClassToLinker(final TypeBasedGuardingDynamicLinker[] linkers) {
|
||||||
this.linkers = linkers;
|
this.linkers = linkers;
|
||||||
singletonLinkers = new List[linkers.length];
|
singletonLinkers = new List[linkers.length];
|
||||||
for(int i = 0; i < linkers.length; ++i) {
|
for(int i = 0; i < linkers.length; ++i) {
|
||||||
@ -121,7 +121,7 @@ public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardin
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<TypeBasedGuardingDynamicLinker> computeValue(Class<?> clazz) {
|
protected List<TypeBasedGuardingDynamicLinker> computeValue(final Class<?> clazz) {
|
||||||
List<TypeBasedGuardingDynamicLinker> list = NO_LINKER;
|
List<TypeBasedGuardingDynamicLinker> list = NO_LINKER;
|
||||||
for(int i = 0; i < linkers.length; ++i) {
|
for(int i = 0; i < linkers.length; ++i) {
|
||||||
final TypeBasedGuardingDynamicLinker linker = linkers[i];
|
final TypeBasedGuardingDynamicLinker linker = linkers[i];
|
||||||
@ -152,27 +152,27 @@ public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardin
|
|||||||
*
|
*
|
||||||
* @param linkers the component linkers
|
* @param linkers the component linkers
|
||||||
*/
|
*/
|
||||||
public CompositeTypeBasedGuardingDynamicLinker(Iterable<? extends TypeBasedGuardingDynamicLinker> linkers) {
|
public CompositeTypeBasedGuardingDynamicLinker(final Iterable<? extends TypeBasedGuardingDynamicLinker> linkers) {
|
||||||
final List<TypeBasedGuardingDynamicLinker> l = new LinkedList<>();
|
final List<TypeBasedGuardingDynamicLinker> l = new LinkedList<>();
|
||||||
for(TypeBasedGuardingDynamicLinker linker: linkers) {
|
for(final TypeBasedGuardingDynamicLinker linker: linkers) {
|
||||||
l.add(linker);
|
l.add(linker);
|
||||||
}
|
}
|
||||||
this.classToLinker = new ClassToLinker(l.toArray(new TypeBasedGuardingDynamicLinker[l.size()]));
|
this.classToLinker = new ClassToLinker(l.toArray(new TypeBasedGuardingDynamicLinker[l.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canLinkType(Class<?> type) {
|
public boolean canLinkType(final Class<?> type) {
|
||||||
return !classToLinker.get(type).isEmpty();
|
return !classToLinker.get(type).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest, final LinkerServices linkerServices)
|
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
final Object obj = linkRequest.getReceiver();
|
final Object obj = linkRequest.getReceiver();
|
||||||
if(obj == null) {
|
if(obj == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for(TypeBasedGuardingDynamicLinker linker: classToLinker.get(obj.getClass())) {
|
for(final TypeBasedGuardingDynamicLinker linker: classToLinker.get(obj.getClass())) {
|
||||||
final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices);
|
final GuardedInvocation invocation = linker.getGuardedInvocation(linkRequest, linkerServices);
|
||||||
if(invocation != null) {
|
if(invocation != null) {
|
||||||
return invocation;
|
return invocation;
|
||||||
@ -189,10 +189,10 @@ public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardin
|
|||||||
* @param linkers the list of linkers to optimize
|
* @param linkers the list of linkers to optimize
|
||||||
* @return the optimized list
|
* @return the optimized list
|
||||||
*/
|
*/
|
||||||
public static List<GuardingDynamicLinker> optimize(Iterable<? extends GuardingDynamicLinker> linkers) {
|
public static List<GuardingDynamicLinker> optimize(final Iterable<? extends GuardingDynamicLinker> linkers) {
|
||||||
final List<GuardingDynamicLinker> llinkers = new LinkedList<>();
|
final List<GuardingDynamicLinker> llinkers = new LinkedList<>();
|
||||||
final List<TypeBasedGuardingDynamicLinker> tblinkers = new LinkedList<>();
|
final List<TypeBasedGuardingDynamicLinker> tblinkers = new LinkedList<>();
|
||||||
for(GuardingDynamicLinker linker: linkers) {
|
for(final GuardingDynamicLinker linker: linkers) {
|
||||||
if(linker instanceof TypeBasedGuardingDynamicLinker) {
|
if(linker instanceof TypeBasedGuardingDynamicLinker) {
|
||||||
tblinkers.add((TypeBasedGuardingDynamicLinker)linker);
|
tblinkers.add((TypeBasedGuardingDynamicLinker)linker);
|
||||||
} else {
|
} else {
|
||||||
@ -204,8 +204,8 @@ public class CompositeTypeBasedGuardingDynamicLinker implements TypeBasedGuardin
|
|||||||
return llinkers;
|
return llinkers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addTypeBased(List<GuardingDynamicLinker> llinkers,
|
private static void addTypeBased(final List<GuardingDynamicLinker> llinkers,
|
||||||
List<TypeBasedGuardingDynamicLinker> tblinkers) {
|
final List<TypeBasedGuardingDynamicLinker> tblinkers) {
|
||||||
switch(tblinkers.size()) {
|
switch(tblinkers.size()) {
|
||||||
case 0: {
|
case 0: {
|
||||||
break;
|
break;
|
||||||
|
@ -98,7 +98,7 @@ class DefaultCallSiteDescriptor extends AbstractCallSiteDescriptor {
|
|||||||
private final String[] tokenizedName;
|
private final String[] tokenizedName;
|
||||||
private final MethodType methodType;
|
private final MethodType methodType;
|
||||||
|
|
||||||
DefaultCallSiteDescriptor(String[] tokenizedName, MethodType methodType) {
|
DefaultCallSiteDescriptor(final String[] tokenizedName, final MethodType methodType) {
|
||||||
this.tokenizedName = tokenizedName;
|
this.tokenizedName = tokenizedName;
|
||||||
this.methodType = methodType;
|
this.methodType = methodType;
|
||||||
}
|
}
|
||||||
@ -109,10 +109,10 @@ class DefaultCallSiteDescriptor extends AbstractCallSiteDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNameToken(int i) {
|
public String getNameToken(final int i) {
|
||||||
try {
|
try {
|
||||||
return tokenizedName[i];
|
return tokenizedName[i];
|
||||||
} catch(ArrayIndexOutOfBoundsException e) {
|
} catch(final ArrayIndexOutOfBoundsException e) {
|
||||||
throw new IllegalArgumentException(e.getMessage());
|
throw new IllegalArgumentException(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ class DefaultCallSiteDescriptor extends AbstractCallSiteDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallSiteDescriptor changeMethodType(MethodType newMethodType) {
|
public CallSiteDescriptor changeMethodType(final MethodType newMethodType) {
|
||||||
return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new DefaultCallSiteDescriptor(tokenizedName,
|
return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new DefaultCallSiteDescriptor(tokenizedName,
|
||||||
newMethodType));
|
newMethodType));
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ import jdk.internal.dynalink.linker.LinkerServices;
|
|||||||
*/
|
*/
|
||||||
public class DefaultPrelinkFilter implements GuardedInvocationFilter {
|
public class DefaultPrelinkFilter implements GuardedInvocationFilter {
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation filter(GuardedInvocation inv, LinkRequest request, LinkerServices linkerServices) {
|
public GuardedInvocation filter(final GuardedInvocation inv, final LinkRequest request, final LinkerServices linkerServices) {
|
||||||
return inv.asType(linkerServices, request.getCallSiteDescriptor().getMethodType());
|
return inv.asType(linkerServices, request.getCallSiteDescriptor().getMethodType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ public class Guards {
|
|||||||
* @return a method handle testing whether its first argument is of the specified class.
|
* @return a method handle testing whether its first argument is of the specified class.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("boxing")
|
@SuppressWarnings("boxing")
|
||||||
public static MethodHandle isOfClass(Class<?> clazz, MethodType type) {
|
public static MethodHandle isOfClass(final Class<?> clazz, final MethodType type) {
|
||||||
final Class<?> declaredType = type.parameterType(0);
|
final Class<?> declaredType = type.parameterType(0);
|
||||||
if(clazz == declaredType) {
|
if(clazz == declaredType) {
|
||||||
LOG.log(Level.WARNING, "isOfClassGuardAlwaysTrue", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() });
|
LOG.log(Level.WARNING, "isOfClassGuardAlwaysTrue", new Object[] { clazz.getName(), 0, type, DynamicLinker.getLinkedCallSiteLocation() });
|
||||||
@ -135,7 +135,7 @@ public class Guards {
|
|||||||
* @param type the method type
|
* @param type the method type
|
||||||
* @return a method handle testing whether its first argument is of the specified class or subclass.
|
* @return a method handle testing whether its first argument is of the specified class or subclass.
|
||||||
*/
|
*/
|
||||||
public static MethodHandle isInstance(Class<?> clazz, MethodType type) {
|
public static MethodHandle isInstance(final Class<?> clazz, final MethodType type) {
|
||||||
return isInstance(clazz, 0, type);
|
return isInstance(clazz, 0, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ public class Guards {
|
|||||||
* @return a method handle testing whether its first argument is of the specified class or subclass.
|
* @return a method handle testing whether its first argument is of the specified class or subclass.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("boxing")
|
@SuppressWarnings("boxing")
|
||||||
public static MethodHandle isInstance(Class<?> clazz, int pos, MethodType type) {
|
public static MethodHandle isInstance(final Class<?> clazz, final int pos, final MethodType type) {
|
||||||
final Class<?> declaredType = type.parameterType(pos);
|
final Class<?> declaredType = type.parameterType(pos);
|
||||||
if(clazz.isAssignableFrom(declaredType)) {
|
if(clazz.isAssignableFrom(declaredType)) {
|
||||||
LOG.log(Level.WARNING, "isInstanceGuardAlwaysTrue", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() });
|
LOG.log(Level.WARNING, "isInstanceGuardAlwaysTrue", new Object[] { clazz.getName(), pos, type, DynamicLinker.getLinkedCallSiteLocation() });
|
||||||
@ -172,7 +172,7 @@ public class Guards {
|
|||||||
* the arguments are ignored.
|
* the arguments are ignored.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("boxing")
|
@SuppressWarnings("boxing")
|
||||||
public static MethodHandle isArray(int pos, MethodType type) {
|
public static MethodHandle isArray(final int pos, final MethodType type) {
|
||||||
final Class<?> declaredType = type.parameterType(pos);
|
final Class<?> declaredType = type.parameterType(pos);
|
||||||
if(declaredType.isArray()) {
|
if(declaredType.isArray()) {
|
||||||
LOG.log(Level.WARNING, "isArrayGuardAlwaysTrue", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() });
|
LOG.log(Level.WARNING, "isArrayGuardAlwaysTrue", new Object[] { pos, type, DynamicLinker.getLinkedCallSiteLocation() });
|
||||||
@ -193,7 +193,7 @@ public class Guards {
|
|||||||
* @param referredLoader the referred class loader
|
* @param referredLoader the referred class loader
|
||||||
* @return true if it is safe to strongly reference the class
|
* @return true if it is safe to strongly reference the class
|
||||||
*/
|
*/
|
||||||
public static boolean canReferenceDirectly(ClassLoader referrerLoader, final ClassLoader referredLoader) {
|
public static boolean canReferenceDirectly(final ClassLoader referrerLoader, final ClassLoader referredLoader) {
|
||||||
if(referredLoader == null) {
|
if(referredLoader == null) {
|
||||||
// Can always refer directly to a system class
|
// Can always refer directly to a system class
|
||||||
return true;
|
return true;
|
||||||
@ -215,7 +215,7 @@ public class Guards {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle getClassBoundArgumentTest(MethodHandle test, Class<?> clazz, int pos, MethodType type) {
|
private static MethodHandle getClassBoundArgumentTest(final MethodHandle test, final Class<?> clazz, final int pos, final MethodType type) {
|
||||||
// Bind the class to the first argument of the test
|
// Bind the class to the first argument of the test
|
||||||
return asType(test.bindTo(clazz), pos, type);
|
return asType(test.bindTo(clazz), pos, type);
|
||||||
}
|
}
|
||||||
@ -227,7 +227,7 @@ public class Guards {
|
|||||||
* @param type the type to adapt the method handle to
|
* @param type the type to adapt the method handle to
|
||||||
* @return the adapted method handle
|
* @return the adapted method handle
|
||||||
*/
|
*/
|
||||||
public static MethodHandle asType(MethodHandle test, MethodType type) {
|
public static MethodHandle asType(final MethodHandle test, final MethodType type) {
|
||||||
return test.asType(getTestType(test, type));
|
return test.asType(getTestType(test, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,16 +239,16 @@ public class Guards {
|
|||||||
* @param type the type to adapt the method handle to
|
* @param type the type to adapt the method handle to
|
||||||
* @return the adapted method handle
|
* @return the adapted method handle
|
||||||
*/
|
*/
|
||||||
public static MethodHandle asType(LinkerServices linkerServices, MethodHandle test, MethodType type) {
|
public static MethodHandle asType(final LinkerServices linkerServices, final MethodHandle test, final MethodType type) {
|
||||||
return linkerServices.asType(test, getTestType(test, type));
|
return linkerServices.asType(test, getTestType(test, type));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodType getTestType(MethodHandle test, MethodType type) {
|
private static MethodType getTestType(final MethodHandle test, final MethodType type) {
|
||||||
return type.dropParameterTypes(test.type().parameterCount(),
|
return type.dropParameterTypes(test.type().parameterCount(),
|
||||||
type.parameterCount()).changeReturnType(boolean.class);
|
type.parameterCount()).changeReturnType(boolean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle asType(MethodHandle test, int pos, MethodType type) {
|
private static MethodHandle asType(final MethodHandle test, final int pos, final MethodType type) {
|
||||||
assert test != null;
|
assert test != null;
|
||||||
assert type != null;
|
assert type != null;
|
||||||
assert type.parameterCount() > 0;
|
assert type.parameterCount() > 0;
|
||||||
@ -283,7 +283,7 @@ public class Guards {
|
|||||||
* @param clazz the class to test for.
|
* @param clazz the class to test for.
|
||||||
* @return the desired guard method.
|
* @return the desired guard method.
|
||||||
*/
|
*/
|
||||||
public static MethodHandle getClassGuard(Class<?> clazz) {
|
public static MethodHandle getClassGuard(final Class<?> clazz) {
|
||||||
return IS_OF_CLASS.bindTo(clazz);
|
return IS_OF_CLASS.bindTo(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ public class Guards {
|
|||||||
* @param clazz the class to test for.
|
* @param clazz the class to test for.
|
||||||
* @return the desired guard method.
|
* @return the desired guard method.
|
||||||
*/
|
*/
|
||||||
public static MethodHandle getInstanceOfGuard(Class<?> clazz) {
|
public static MethodHandle getInstanceOfGuard(final Class<?> clazz) {
|
||||||
return IS_INSTANCE.bindTo(clazz);
|
return IS_INSTANCE.bindTo(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +301,7 @@ public class Guards {
|
|||||||
* @param obj the object used as referential identity test
|
* @param obj the object used as referential identity test
|
||||||
* @return the desired guard method.
|
* @return the desired guard method.
|
||||||
*/
|
*/
|
||||||
public static MethodHandle getIdentityGuard(Object obj) {
|
public static MethodHandle getIdentityGuard(final Object obj) {
|
||||||
return IS_IDENTICAL.bindTo(obj);
|
return IS_IDENTICAL.bindTo(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,39 +322,39 @@ public class Guards {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static boolean isNull(Object obj) {
|
private static boolean isNull(final Object obj) {
|
||||||
return obj == null;
|
return obj == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static boolean isNotNull(Object obj) {
|
private static boolean isNotNull(final Object obj) {
|
||||||
return obj != null;
|
return obj != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static boolean isArray(Object o) {
|
private static boolean isArray(final Object o) {
|
||||||
return o != null && o.getClass().isArray();
|
return o != null && o.getClass().isArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static boolean isOfClass(Class<?> c, Object o) {
|
private static boolean isOfClass(final Class<?> c, final Object o) {
|
||||||
return o != null && o.getClass() == c;
|
return o != null && o.getClass() == c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static boolean isIdentical(Object o1, Object o2) {
|
private static boolean isIdentical(final Object o1, final Object o2) {
|
||||||
return o1 == o2;
|
return o1 == o2;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle constantTrue(MethodType type) {
|
private static MethodHandle constantTrue(final MethodType type) {
|
||||||
return constantBoolean(Boolean.TRUE, type);
|
return constantBoolean(Boolean.TRUE, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle constantFalse(MethodType type) {
|
private static MethodHandle constantFalse(final MethodType type) {
|
||||||
return constantBoolean(Boolean.FALSE, type);
|
return constantBoolean(Boolean.FALSE, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle constantBoolean(Boolean value, MethodType type) {
|
private static MethodHandle constantBoolean(final Boolean value, final MethodType type) {
|
||||||
return MethodHandles.permuteArguments(MethodHandles.constant(Boolean.TYPE, value),
|
return MethodHandles.permuteArguments(MethodHandles.constant(Boolean.TYPE, value),
|
||||||
type.changeReturnType(Boolean.TYPE));
|
type.changeReturnType(Boolean.TYPE));
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ public class LinkRequestImpl implements LinkRequest {
|
|||||||
* @param callSiteUnstable true if the call site being linked is considered unstable
|
* @param callSiteUnstable true if the call site being linked is considered unstable
|
||||||
* @param arguments the arguments for the invocation
|
* @param arguments the arguments for the invocation
|
||||||
*/
|
*/
|
||||||
public LinkRequestImpl(CallSiteDescriptor callSiteDescriptor, Object callSiteToken, int linkCount, boolean callSiteUnstable, Object... arguments) {
|
public LinkRequestImpl(final CallSiteDescriptor callSiteDescriptor, final Object callSiteToken, final int linkCount, final boolean callSiteUnstable, final Object... arguments) {
|
||||||
this.callSiteDescriptor = callSiteDescriptor;
|
this.callSiteDescriptor = callSiteDescriptor;
|
||||||
this.callSiteToken = callSiteToken;
|
this.callSiteToken = callSiteToken;
|
||||||
this.linkCount = linkCount;
|
this.linkCount = linkCount;
|
||||||
@ -153,7 +153,7 @@ public class LinkRequestImpl implements LinkRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LinkRequest replaceArguments(CallSiteDescriptor newCallSiteDescriptor, Object[] newArguments) {
|
public LinkRequest replaceArguments(final CallSiteDescriptor newCallSiteDescriptor, final Object[] newArguments) {
|
||||||
return new LinkRequestImpl(newCallSiteDescriptor, callSiteToken, linkCount, callSiteUnstable, newArguments);
|
return new LinkRequestImpl(newCallSiteDescriptor, callSiteToken, linkCount, callSiteUnstable, newArguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,32 +117,32 @@ public class LinkerServicesImpl implements LinkerServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canConvert(Class<?> from, Class<?> to) {
|
public boolean canConvert(final Class<?> from, final Class<?> to) {
|
||||||
return typeConverterFactory.canConvert(from, to);
|
return typeConverterFactory.canConvert(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodHandle asType(MethodHandle handle, MethodType fromType) {
|
public MethodHandle asType(final MethodHandle handle, final MethodType fromType) {
|
||||||
return typeConverterFactory.asType(handle, fromType);
|
return typeConverterFactory.asType(handle, fromType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodHandle asTypeLosslessReturn(MethodHandle handle, MethodType fromType) {
|
public MethodHandle asTypeLosslessReturn(final MethodHandle handle, final MethodType fromType) {
|
||||||
return Implementation.asTypeLosslessReturn(this, handle, fromType);
|
return Implementation.asTypeLosslessReturn(this, handle, fromType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MethodHandle getTypeConverter(Class<?> sourceType, Class<?> targetType) {
|
public MethodHandle getTypeConverter(final Class<?> sourceType, final Class<?> targetType) {
|
||||||
return typeConverterFactory.getTypeConverter(sourceType, targetType);
|
return typeConverterFactory.getTypeConverter(sourceType, targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Comparison compareConversion(Class<?> sourceType, Class<?> targetType1, Class<?> targetType2) {
|
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
|
||||||
return typeConverterFactory.compareConversion(sourceType, targetType1, targetType2);
|
return typeConverterFactory.compareConversion(sourceType, targetType1, targetType2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuardedInvocation getGuardedInvocation(LinkRequest linkRequest) throws Exception {
|
public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest) throws Exception {
|
||||||
final LinkRequest prevLinkRequest = threadLinkRequest.get();
|
final LinkRequest prevLinkRequest = threadLinkRequest.get();
|
||||||
threadLinkRequest.set(linkRequest);
|
threadLinkRequest.set(linkRequest);
|
||||||
try {
|
try {
|
||||||
@ -159,7 +159,7 @@ public class LinkerServicesImpl implements LinkerServices {
|
|||||||
* permission.
|
* permission.
|
||||||
*/
|
*/
|
||||||
public static LinkRequest getCurrentLinkRequest() {
|
public static LinkRequest getCurrentLinkRequest() {
|
||||||
SecurityManager sm = System.getSecurityManager();
|
final SecurityManager sm = System.getSecurityManager();
|
||||||
if(sm != null) {
|
if(sm != null) {
|
||||||
sm.checkPermission(GET_CURRENT_LINK_REQUEST);
|
sm.checkPermission(GET_CURRENT_LINK_REQUEST);
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ public class Lookup {
|
|||||||
*
|
*
|
||||||
* @param lookup the {@link java.lang.invoke.MethodHandles.Lookup} it delegates to.
|
* @param lookup the {@link java.lang.invoke.MethodHandles.Lookup} it delegates to.
|
||||||
*/
|
*/
|
||||||
public Lookup(MethodHandles.Lookup lookup) {
|
public Lookup(final MethodHandles.Lookup lookup) {
|
||||||
this.lookup = lookup;
|
this.lookup = lookup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ public class Lookup {
|
|||||||
* @param m the method to unreflect
|
* @param m the method to unreflect
|
||||||
* @return the unreflected method handle.
|
* @return the unreflected method handle.
|
||||||
*/
|
*/
|
||||||
public MethodHandle unreflect(Method m) {
|
public MethodHandle unreflect(final Method m) {
|
||||||
return unreflect(lookup, m);
|
return unreflect(lookup, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,10 +132,10 @@ public class Lookup {
|
|||||||
* @param m the method to unreflect
|
* @param m the method to unreflect
|
||||||
* @return the unreflected method handle.
|
* @return the unreflected method handle.
|
||||||
*/
|
*/
|
||||||
public static MethodHandle unreflect(MethodHandles.Lookup lookup, Method m) {
|
public static MethodHandle unreflect(final MethodHandles.Lookup lookup, final Method m) {
|
||||||
try {
|
try {
|
||||||
return lookup.unreflect(m);
|
return lookup.unreflect(m);
|
||||||
} catch(IllegalAccessException e) {
|
} catch(final IllegalAccessException e) {
|
||||||
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect method " + m);
|
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect method " + m);
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
throw ee;
|
throw ee;
|
||||||
@ -149,10 +149,10 @@ public class Lookup {
|
|||||||
* @param f the field for which a getter is unreflected
|
* @param f the field for which a getter is unreflected
|
||||||
* @return the unreflected field getter handle.
|
* @return the unreflected field getter handle.
|
||||||
*/
|
*/
|
||||||
public MethodHandle unreflectGetter(Field f) {
|
public MethodHandle unreflectGetter(final Field f) {
|
||||||
try {
|
try {
|
||||||
return lookup.unreflectGetter(f);
|
return lookup.unreflectGetter(f);
|
||||||
} catch(IllegalAccessException e) {
|
} catch(final IllegalAccessException e) {
|
||||||
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect getter for field " + f);
|
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect getter for field " + f);
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
throw ee;
|
throw ee;
|
||||||
@ -171,15 +171,15 @@ public class Lookup {
|
|||||||
* @throws IllegalAccessError if the field is inaccessible.
|
* @throws IllegalAccessError if the field is inaccessible.
|
||||||
* @throws NoSuchFieldError if the field does not exist.
|
* @throws NoSuchFieldError if the field does not exist.
|
||||||
*/
|
*/
|
||||||
public MethodHandle findGetter(Class<?>refc, String name, Class<?> type) {
|
public MethodHandle findGetter(final Class<?>refc, final String name, final Class<?> type) {
|
||||||
try {
|
try {
|
||||||
return lookup.findGetter(refc, name, type);
|
return lookup.findGetter(refc, name, type);
|
||||||
} catch(IllegalAccessException e) {
|
} catch(final IllegalAccessException e) {
|
||||||
final IllegalAccessError ee = new IllegalAccessError("Failed to access getter for field " + refc.getName() +
|
final IllegalAccessError ee = new IllegalAccessError("Failed to access getter for field " + refc.getName() +
|
||||||
"." + name + " of type " + type.getName());
|
"." + name + " of type " + type.getName());
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
throw ee;
|
throw ee;
|
||||||
} catch(NoSuchFieldException e) {
|
} catch(final NoSuchFieldException e) {
|
||||||
final NoSuchFieldError ee = new NoSuchFieldError("Failed to find getter for field " + refc.getName() +
|
final NoSuchFieldError ee = new NoSuchFieldError("Failed to find getter for field " + refc.getName() +
|
||||||
"." + name + " of type " + type.getName());
|
"." + name + " of type " + type.getName());
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
@ -194,10 +194,10 @@ public class Lookup {
|
|||||||
* @param f the field for which a setter is unreflected
|
* @param f the field for which a setter is unreflected
|
||||||
* @return the unreflected field setter handle.
|
* @return the unreflected field setter handle.
|
||||||
*/
|
*/
|
||||||
public MethodHandle unreflectSetter(Field f) {
|
public MethodHandle unreflectSetter(final Field f) {
|
||||||
try {
|
try {
|
||||||
return lookup.unreflectSetter(f);
|
return lookup.unreflectSetter(f);
|
||||||
} catch(IllegalAccessException e) {
|
} catch(final IllegalAccessException e) {
|
||||||
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect setter for field " + f);
|
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect setter for field " + f);
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
throw ee;
|
throw ee;
|
||||||
@ -211,7 +211,7 @@ public class Lookup {
|
|||||||
* @param c the constructor to unreflect
|
* @param c the constructor to unreflect
|
||||||
* @return the unreflected constructor handle.
|
* @return the unreflected constructor handle.
|
||||||
*/
|
*/
|
||||||
public MethodHandle unreflectConstructor(Constructor<?> c) {
|
public MethodHandle unreflectConstructor(final Constructor<?> c) {
|
||||||
return unreflectConstructor(lookup, c);
|
return unreflectConstructor(lookup, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,10 +223,10 @@ public class Lookup {
|
|||||||
* @param c the constructor to unreflect
|
* @param c the constructor to unreflect
|
||||||
* @return the unreflected constructor handle.
|
* @return the unreflected constructor handle.
|
||||||
*/
|
*/
|
||||||
public static MethodHandle unreflectConstructor(MethodHandles.Lookup lookup, Constructor<?> c) {
|
public static MethodHandle unreflectConstructor(final MethodHandles.Lookup lookup, final Constructor<?> c) {
|
||||||
try {
|
try {
|
||||||
return lookup.unreflectConstructor(c);
|
return lookup.unreflectConstructor(c);
|
||||||
} catch(IllegalAccessException e) {
|
} catch(final IllegalAccessException e) {
|
||||||
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect constructor " + c);
|
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect constructor " + c);
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
throw ee;
|
throw ee;
|
||||||
@ -244,15 +244,15 @@ public class Lookup {
|
|||||||
* @throws IllegalAccessError if the method is inaccessible.
|
* @throws IllegalAccessError if the method is inaccessible.
|
||||||
* @throws NoSuchMethodError if the method does not exist.
|
* @throws NoSuchMethodError if the method does not exist.
|
||||||
*/
|
*/
|
||||||
public MethodHandle findSpecial(Class<?> declaringClass, String name, MethodType type) {
|
public MethodHandle findSpecial(final Class<?> declaringClass, final String name, final MethodType type) {
|
||||||
try {
|
try {
|
||||||
return lookup.findSpecial(declaringClass, name, type, declaringClass);
|
return lookup.findSpecial(declaringClass, name, type, declaringClass);
|
||||||
} catch(IllegalAccessException e) {
|
} catch(final IllegalAccessException e) {
|
||||||
final IllegalAccessError ee = new IllegalAccessError("Failed to access special method " + methodDescription(
|
final IllegalAccessError ee = new IllegalAccessError("Failed to access special method " + methodDescription(
|
||||||
declaringClass, name, type));
|
declaringClass, name, type));
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
throw ee;
|
throw ee;
|
||||||
} catch(NoSuchMethodException e) {
|
} catch(final NoSuchMethodException e) {
|
||||||
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find special method " + methodDescription(
|
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find special method " + methodDescription(
|
||||||
declaringClass, name, type));
|
declaringClass, name, type));
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
@ -260,7 +260,7 @@ public class Lookup {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String methodDescription(Class<?> declaringClass, String name, MethodType type) {
|
private static String methodDescription(final Class<?> declaringClass, final String name, final MethodType type) {
|
||||||
return declaringClass.getName() + "#" + name + type;
|
return declaringClass.getName() + "#" + name + type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,15 +275,15 @@ public class Lookup {
|
|||||||
* @throws IllegalAccessError if the method is inaccessible.
|
* @throws IllegalAccessError if the method is inaccessible.
|
||||||
* @throws NoSuchMethodError if the method does not exist.
|
* @throws NoSuchMethodError if the method does not exist.
|
||||||
*/
|
*/
|
||||||
public MethodHandle findStatic(Class<?> declaringClass, String name, MethodType type) {
|
public MethodHandle findStatic(final Class<?> declaringClass, final String name, final MethodType type) {
|
||||||
try {
|
try {
|
||||||
return lookup.findStatic(declaringClass, name, type);
|
return lookup.findStatic(declaringClass, name, type);
|
||||||
} catch(IllegalAccessException e) {
|
} catch(final IllegalAccessException e) {
|
||||||
final IllegalAccessError ee = new IllegalAccessError("Failed to access static method " + methodDescription(
|
final IllegalAccessError ee = new IllegalAccessError("Failed to access static method " + methodDescription(
|
||||||
declaringClass, name, type));
|
declaringClass, name, type));
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
throw ee;
|
throw ee;
|
||||||
} catch(NoSuchMethodException e) {
|
} catch(final NoSuchMethodException e) {
|
||||||
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find static method " + methodDescription(
|
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find static method " + methodDescription(
|
||||||
declaringClass, name, type));
|
declaringClass, name, type));
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
@ -302,15 +302,15 @@ public class Lookup {
|
|||||||
* @throws IllegalAccessError if the method is inaccessible.
|
* @throws IllegalAccessError if the method is inaccessible.
|
||||||
* @throws NoSuchMethodError if the method does not exist.
|
* @throws NoSuchMethodError if the method does not exist.
|
||||||
*/
|
*/
|
||||||
public MethodHandle findVirtual(Class<?> declaringClass, String name, MethodType type) {
|
public MethodHandle findVirtual(final Class<?> declaringClass, final String name, final MethodType type) {
|
||||||
try {
|
try {
|
||||||
return lookup.findVirtual(declaringClass, name, type);
|
return lookup.findVirtual(declaringClass, name, type);
|
||||||
} catch(IllegalAccessException e) {
|
} catch(final IllegalAccessException e) {
|
||||||
final IllegalAccessError ee = new IllegalAccessError("Failed to access virtual method " + methodDescription(
|
final IllegalAccessError ee = new IllegalAccessError("Failed to access virtual method " + methodDescription(
|
||||||
declaringClass, name, type));
|
declaringClass, name, type));
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
throw ee;
|
throw ee;
|
||||||
} catch(NoSuchMethodException e) {
|
} catch(final NoSuchMethodException e) {
|
||||||
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find virtual method " + methodDescription(
|
final NoSuchMethodError ee = new NoSuchMethodError("Failed to find virtual method " + methodDescription(
|
||||||
declaringClass, name, type));
|
declaringClass, name, type));
|
||||||
ee.initCause(e);
|
ee.initCause(e);
|
||||||
@ -327,7 +327,7 @@ public class Lookup {
|
|||||||
* @param ptypes the parameter types of the method
|
* @param ptypes the parameter types of the method
|
||||||
* @return the method handle for the method
|
* @return the method handle for the method
|
||||||
*/
|
*/
|
||||||
public static MethodHandle findOwnSpecial(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes) {
|
public static MethodHandle findOwnSpecial(final MethodHandles.Lookup lookup, final String name, final Class<?> rtype, final Class<?>... ptypes) {
|
||||||
return new Lookup(lookup).findOwnSpecial(name, rtype, ptypes);
|
return new Lookup(lookup).findOwnSpecial(name, rtype, ptypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ public class Lookup {
|
|||||||
* @param ptypes the parameter types of the method
|
* @param ptypes the parameter types of the method
|
||||||
* @return the method handle for the method
|
* @return the method handle for the method
|
||||||
*/
|
*/
|
||||||
public MethodHandle findOwnSpecial(String name, Class<?> rtype, Class<?>... ptypes) {
|
public MethodHandle findOwnSpecial(final String name, final Class<?> rtype, final Class<?>... ptypes) {
|
||||||
return findSpecial(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes));
|
return findSpecial(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ public class Lookup {
|
|||||||
* @param ptypes the parameter types of the method
|
* @param ptypes the parameter types of the method
|
||||||
* @return the method handle for the method
|
* @return the method handle for the method
|
||||||
*/
|
*/
|
||||||
public static MethodHandle findOwnStatic(MethodHandles.Lookup lookup, String name, Class<?> rtype, Class<?>... ptypes) {
|
public static MethodHandle findOwnStatic(final MethodHandles.Lookup lookup, final String name, final Class<?> rtype, final Class<?>... ptypes) {
|
||||||
return new Lookup(lookup).findOwnStatic(name, rtype, ptypes);
|
return new Lookup(lookup).findOwnStatic(name, rtype, ptypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +368,7 @@ public class Lookup {
|
|||||||
* @param ptypes the parameter types of the method
|
* @param ptypes the parameter types of the method
|
||||||
* @return the method handle for the method
|
* @return the method handle for the method
|
||||||
*/
|
*/
|
||||||
public MethodHandle findOwnStatic(String name, Class<?> rtype, Class<?>... ptypes) {
|
public MethodHandle findOwnStatic(final String name, final Class<?> rtype, final Class<?>... ptypes) {
|
||||||
return findStatic(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes));
|
return findStatic(lookup.lookupClass(), name, MethodType.methodType(rtype, ptypes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ import jdk.internal.dynalink.CallSiteDescriptor;
|
|||||||
* @author Attila Szegedi
|
* @author Attila Szegedi
|
||||||
*/
|
*/
|
||||||
class LookupCallSiteDescriptor extends DefaultCallSiteDescriptor {
|
class LookupCallSiteDescriptor extends DefaultCallSiteDescriptor {
|
||||||
private Lookup lookup;
|
private final Lookup lookup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new call site descriptor from explicit information.
|
* Create a new call site descriptor from explicit information.
|
||||||
@ -100,7 +100,7 @@ class LookupCallSiteDescriptor extends DefaultCallSiteDescriptor {
|
|||||||
* @param methodType the method type
|
* @param methodType the method type
|
||||||
* @param lookup the lookup
|
* @param lookup the lookup
|
||||||
*/
|
*/
|
||||||
LookupCallSiteDescriptor(String[] tokenizedName, MethodType methodType, Lookup lookup) {
|
LookupCallSiteDescriptor(final String[] tokenizedName, final MethodType methodType, final Lookup lookup) {
|
||||||
super(tokenizedName, methodType);
|
super(tokenizedName, methodType);
|
||||||
this.lookup = lookup;
|
this.lookup = lookup;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ class LookupCallSiteDescriptor extends DefaultCallSiteDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallSiteDescriptor changeMethodType(MethodType newMethodType) {
|
public CallSiteDescriptor changeMethodType(final MethodType newMethodType) {
|
||||||
return new LookupCallSiteDescriptor(getTokenizedName(), newMethodType, lookup);
|
return new LookupCallSiteDescriptor(getTokenizedName(), newMethodType, lookup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ public class NameCodec {
|
|||||||
* @param name the symbolic name to mangle
|
* @param name the symbolic name to mangle
|
||||||
* @return the mangled form of the symbolic name.
|
* @return the mangled form of the symbolic name.
|
||||||
*/
|
*/
|
||||||
public static String encode(String name) {
|
public static String encode(final String name) {
|
||||||
final int l = name.length();
|
final int l = name.length();
|
||||||
if(l == 0) {
|
if(l == 0) {
|
||||||
return EMPTY_NAME;
|
return EMPTY_NAME;
|
||||||
@ -176,7 +176,7 @@ public class NameCodec {
|
|||||||
* @param name the symbolic name to demangle
|
* @param name the symbolic name to demangle
|
||||||
* @return the demangled form of the symbolic name.
|
* @return the demangled form of the symbolic name.
|
||||||
*/
|
*/
|
||||||
public static String decode(String name) {
|
public static String decode(final String name) {
|
||||||
if(name.charAt(0) != ESCAPE_CHAR) {
|
if(name.charAt(0) != ESCAPE_CHAR) {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -184,11 +184,11 @@ public class NameCodec {
|
|||||||
if(l == 2 && name.charAt(1) == EMPTY_CHAR) {
|
if(l == 2 && name.charAt(1) == EMPTY_CHAR) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
StringBuilder b = new StringBuilder(name.length());
|
final StringBuilder b = new StringBuilder(name.length());
|
||||||
int lastEscape = -2;
|
int lastEscape = -2;
|
||||||
int lastBackslash = -1;
|
int lastBackslash = -1;
|
||||||
for(;;) {
|
for(;;) {
|
||||||
int nextBackslash = name.indexOf(ESCAPE_CHAR, lastBackslash + 1);
|
final int nextBackslash = name.indexOf(ESCAPE_CHAR, lastBackslash + 1);
|
||||||
if(nextBackslash == -1 || nextBackslash == l - 1) {
|
if(nextBackslash == -1 || nextBackslash == l - 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -211,7 +211,7 @@ public class NameCodec {
|
|||||||
return b.toString();
|
return b.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addEncoding(char from, char to) {
|
private static void addEncoding(final char from, final char to) {
|
||||||
ENCODING[from - MIN_ENCODING] = to;
|
ENCODING[from - MIN_ENCODING] = to;
|
||||||
DECODING[to - MIN_DECODING] = from;
|
DECODING[to - MIN_DECODING] = from;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ import jdk.internal.dynalink.CallSiteDescriptor;
|
|||||||
class NamedDynCallSiteDescriptor extends UnnamedDynCallSiteDescriptor {
|
class NamedDynCallSiteDescriptor extends UnnamedDynCallSiteDescriptor {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
NamedDynCallSiteDescriptor(String op, String name, MethodType methodType) {
|
NamedDynCallSiteDescriptor(final String op, final String name, final MethodType methodType) {
|
||||||
super(op, methodType);
|
super(op, methodType);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ class NamedDynCallSiteDescriptor extends UnnamedDynCallSiteDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNameToken(int i) {
|
public String getNameToken(final int i) {
|
||||||
switch(i) {
|
switch(i) {
|
||||||
case 0: return "dyn";
|
case 0: return "dyn";
|
||||||
case 1: return getOp();
|
case 1: return getOp();
|
||||||
@ -110,7 +110,7 @@ class NamedDynCallSiteDescriptor extends UnnamedDynCallSiteDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallSiteDescriptor changeMethodType(MethodType newMethodType) {
|
public CallSiteDescriptor changeMethodType(final MethodType newMethodType) {
|
||||||
return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new NamedDynCallSiteDescriptor(getOp(), name,
|
return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new NamedDynCallSiteDescriptor(getOp(), name,
|
||||||
newMethodType));
|
newMethodType));
|
||||||
}
|
}
|
||||||
|
@ -109,8 +109,8 @@ public class RuntimeContextLinkRequestImpl extends LinkRequestImpl {
|
|||||||
* runtime specific context arguments.
|
* runtime specific context arguments.
|
||||||
* @throws IllegalArgumentException if runtimeContextArgCount is less than 1.
|
* @throws IllegalArgumentException if runtimeContextArgCount is less than 1.
|
||||||
*/
|
*/
|
||||||
public RuntimeContextLinkRequestImpl(CallSiteDescriptor callSiteDescriptor, Object callSiteToken,
|
public RuntimeContextLinkRequestImpl(final CallSiteDescriptor callSiteDescriptor, final Object callSiteToken,
|
||||||
int linkCount, boolean callSiteUnstable, Object[] arguments, int runtimeContextArgCount) {
|
final int linkCount, final boolean callSiteUnstable, final Object[] arguments, final int runtimeContextArgCount) {
|
||||||
super(callSiteDescriptor, callSiteToken, linkCount, callSiteUnstable, arguments);
|
super(callSiteDescriptor, callSiteToken, linkCount, callSiteUnstable, arguments);
|
||||||
if(runtimeContextArgCount < 1) {
|
if(runtimeContextArgCount < 1) {
|
||||||
throw new IllegalArgumentException("runtimeContextArgCount < 1");
|
throw new IllegalArgumentException("runtimeContextArgCount < 1");
|
||||||
@ -129,7 +129,7 @@ public class RuntimeContextLinkRequestImpl extends LinkRequestImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LinkRequest replaceArguments(CallSiteDescriptor callSiteDescriptor, Object[] arguments) {
|
public LinkRequest replaceArguments(final CallSiteDescriptor callSiteDescriptor, final Object[] arguments) {
|
||||||
return new RuntimeContextLinkRequestImpl(callSiteDescriptor, getCallSiteToken(), getLinkCount(), isCallSiteUnstable(), arguments,
|
return new RuntimeContextLinkRequestImpl(callSiteDescriptor, getCallSiteToken(), getLinkCount(), isCallSiteUnstable(), arguments,
|
||||||
runtimeContextArgCount);
|
runtimeContextArgCount);
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,6 @@ import java.security.AccessController;
|
|||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.internal.dynalink.linker.ConversionComparator;
|
import jdk.internal.dynalink.linker.ConversionComparator;
|
||||||
import jdk.internal.dynalink.linker.ConversionComparator.Comparison;
|
import jdk.internal.dynalink.linker.ConversionComparator.Comparison;
|
||||||
import jdk.internal.dynalink.linker.GuardedInvocation;
|
import jdk.internal.dynalink.linker.GuardedInvocation;
|
||||||
@ -116,12 +115,12 @@ public class TypeConverterFactory {
|
|||||||
protected ClassMap<MethodHandle> computeValue(final Class<?> sourceType) {
|
protected ClassMap<MethodHandle> computeValue(final Class<?> sourceType) {
|
||||||
return new ClassMap<MethodHandle>(getClassLoader(sourceType)) {
|
return new ClassMap<MethodHandle>(getClassLoader(sourceType)) {
|
||||||
@Override
|
@Override
|
||||||
protected MethodHandle computeValue(Class<?> targetType) {
|
protected MethodHandle computeValue(final Class<?> targetType) {
|
||||||
try {
|
try {
|
||||||
return createConverter(sourceType, targetType);
|
return createConverter(sourceType, targetType);
|
||||||
} catch (RuntimeException e) {
|
} catch (final RuntimeException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +133,7 @@ public class TypeConverterFactory {
|
|||||||
protected ClassMap<MethodHandle> computeValue(final Class<?> sourceType) {
|
protected ClassMap<MethodHandle> computeValue(final Class<?> sourceType) {
|
||||||
return new ClassMap<MethodHandle>(getClassLoader(sourceType)) {
|
return new ClassMap<MethodHandle>(getClassLoader(sourceType)) {
|
||||||
@Override
|
@Override
|
||||||
protected MethodHandle computeValue(Class<?> targetType) {
|
protected MethodHandle computeValue(final Class<?> targetType) {
|
||||||
if(!canAutoConvert(sourceType, targetType)) {
|
if(!canAutoConvert(sourceType, targetType)) {
|
||||||
final MethodHandle converter = getCacheableTypeConverter(sourceType, targetType);
|
final MethodHandle converter = getCacheableTypeConverter(sourceType, targetType);
|
||||||
if(converter != IDENTITY_CONVERSION) {
|
if(converter != IDENTITY_CONVERSION) {
|
||||||
@ -152,12 +151,12 @@ public class TypeConverterFactory {
|
|||||||
protected ClassMap<Boolean> computeValue(final Class<?> sourceType) {
|
protected ClassMap<Boolean> computeValue(final Class<?> sourceType) {
|
||||||
return new ClassMap<Boolean>(getClassLoader(sourceType)) {
|
return new ClassMap<Boolean>(getClassLoader(sourceType)) {
|
||||||
@Override
|
@Override
|
||||||
protected Boolean computeValue(Class<?> targetType) {
|
protected Boolean computeValue(final Class<?> targetType) {
|
||||||
try {
|
try {
|
||||||
return getTypeConverterNull(sourceType, targetType) != null;
|
return getTypeConverterNull(sourceType, targetType) != null;
|
||||||
} catch (RuntimeException e) {
|
} catch (final RuntimeException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,10 +178,10 @@ public class TypeConverterFactory {
|
|||||||
*
|
*
|
||||||
* @param factories the {@link GuardingTypeConverterFactory} instances to compose.
|
* @param factories the {@link GuardingTypeConverterFactory} instances to compose.
|
||||||
*/
|
*/
|
||||||
public TypeConverterFactory(Iterable<? extends GuardingTypeConverterFactory> factories) {
|
public TypeConverterFactory(final Iterable<? extends GuardingTypeConverterFactory> factories) {
|
||||||
final List<GuardingTypeConverterFactory> l = new LinkedList<>();
|
final List<GuardingTypeConverterFactory> l = new LinkedList<>();
|
||||||
final List<ConversionComparator> c = new LinkedList<>();
|
final List<ConversionComparator> c = new LinkedList<>();
|
||||||
for(GuardingTypeConverterFactory factory: factories) {
|
for(final GuardingTypeConverterFactory factory: factories) {
|
||||||
l.add(factory);
|
l.add(factory);
|
||||||
if(factory instanceof ConversionComparator) {
|
if(factory instanceof ConversionComparator) {
|
||||||
c.add((ConversionComparator)factory);
|
c.add((ConversionComparator)factory);
|
||||||
@ -207,7 +206,7 @@ public class TypeConverterFactory {
|
|||||||
* {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)} with
|
* {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)} with
|
||||||
* {@link GuardingTypeConverterFactory} produced type converters as filters.
|
* {@link GuardingTypeConverterFactory} produced type converters as filters.
|
||||||
*/
|
*/
|
||||||
public MethodHandle asType(MethodHandle handle, final MethodType fromType) {
|
public MethodHandle asType(final MethodHandle handle, final MethodType fromType) {
|
||||||
MethodHandle newHandle = handle;
|
MethodHandle newHandle = handle;
|
||||||
final MethodType toType = newHandle.type();
|
final MethodType toType = newHandle.type();
|
||||||
final int l = toType.parameterCount();
|
final int l = toType.parameterCount();
|
||||||
@ -251,7 +250,7 @@ public class TypeConverterFactory {
|
|||||||
return newHandle.asType(fromType);
|
return newHandle.asType(fromType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MethodHandle applyConverters(MethodHandle handle, int pos, List<MethodHandle> converters) {
|
private static MethodHandle applyConverters(final MethodHandle handle, final int pos, final List<MethodHandle> converters) {
|
||||||
if(converters.isEmpty()) {
|
if(converters.isEmpty()) {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
@ -286,8 +285,8 @@ public class TypeConverterFactory {
|
|||||||
* @return one of Comparison constants that establish which - if any - of the target types is preferable for the
|
* @return one of Comparison constants that establish which - if any - of the target types is preferable for the
|
||||||
* conversion.
|
* conversion.
|
||||||
*/
|
*/
|
||||||
public Comparison compareConversion(Class<?> sourceType, Class<?> targetType1, Class<?> targetType2) {
|
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
|
||||||
for(ConversionComparator comparator: comparators) {
|
for(final ConversionComparator comparator: comparators) {
|
||||||
final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
|
final Comparison result = comparator.compareConversion(sourceType, targetType1, targetType2);
|
||||||
if(result != Comparison.INDETERMINATE) {
|
if(result != Comparison.INDETERMINATE) {
|
||||||
return result;
|
return result;
|
||||||
@ -314,20 +313,20 @@ public class TypeConverterFactory {
|
|||||||
return TypeUtilities.isMethodInvocationConvertible(fromType, toType);
|
return TypeUtilities.isMethodInvocationConvertible(fromType, toType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private*/ MethodHandle getCacheableTypeConverterNull(Class<?> sourceType, Class<?> targetType) {
|
/*private*/ MethodHandle getCacheableTypeConverterNull(final Class<?> sourceType, final Class<?> targetType) {
|
||||||
final MethodHandle converter = getCacheableTypeConverter(sourceType, targetType);
|
final MethodHandle converter = getCacheableTypeConverter(sourceType, targetType);
|
||||||
return converter == IDENTITY_CONVERSION ? null : converter;
|
return converter == IDENTITY_CONVERSION ? null : converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private*/ MethodHandle getTypeConverterNull(Class<?> sourceType, Class<?> targetType) {
|
/*private*/ MethodHandle getTypeConverterNull(final Class<?> sourceType, final Class<?> targetType) {
|
||||||
try {
|
try {
|
||||||
return getCacheableTypeConverterNull(sourceType, targetType);
|
return getCacheableTypeConverterNull(sourceType, targetType);
|
||||||
} catch(NotCacheableConverter e) {
|
} catch(final NotCacheableConverter e) {
|
||||||
return e.converter;
|
return e.converter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private*/ MethodHandle getCacheableTypeConverter(Class<?> sourceType, Class<?> targetType) {
|
/*private*/ MethodHandle getCacheableTypeConverter(final Class<?> sourceType, final Class<?> targetType) {
|
||||||
return converterMap.get(sourceType).get(targetType);
|
return converterMap.get(sourceType).get(targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,15 +339,15 @@ public class TypeConverterFactory {
|
|||||||
* @param targetType the type to convert to
|
* @param targetType the type to convert to
|
||||||
* @return a method handle performing the conversion.
|
* @return a method handle performing the conversion.
|
||||||
*/
|
*/
|
||||||
public MethodHandle getTypeConverter(Class<?> sourceType, Class<?> targetType) {
|
public MethodHandle getTypeConverter(final Class<?> sourceType, final Class<?> targetType) {
|
||||||
try {
|
try {
|
||||||
return converterIdentityMap.get(sourceType).get(targetType);
|
return converterIdentityMap.get(sourceType).get(targetType);
|
||||||
} catch(NotCacheableConverter e) {
|
} catch(final NotCacheableConverter e) {
|
||||||
return e.converter;
|
return e.converter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*private*/ MethodHandle createConverter(Class<?> sourceType, Class<?> targetType) throws Exception {
|
/*private*/ MethodHandle createConverter(final Class<?> sourceType, final Class<?> targetType) throws Exception {
|
||||||
final MethodType type = MethodType.methodType(targetType, sourceType);
|
final MethodType type = MethodType.methodType(targetType, sourceType);
|
||||||
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
|
final MethodHandle identity = IDENTITY_CONVERSION.asType(type);
|
||||||
MethodHandle last = identity;
|
MethodHandle last = identity;
|
||||||
|
@ -115,7 +115,7 @@ public class TypeUtilities {
|
|||||||
* unrelated superinterfaces as their most specific common type, or the types themselves are completely
|
* unrelated superinterfaces as their most specific common type, or the types themselves are completely
|
||||||
* unrelated interfaces, {@link java.lang.Object} is returned.
|
* unrelated interfaces, {@link java.lang.Object} is returned.
|
||||||
*/
|
*/
|
||||||
public static Class<?> getCommonLosslessConversionType(Class<?> c1, Class<?> c2) {
|
public static Class<?> getCommonLosslessConversionType(final Class<?> c1, final Class<?> c2) {
|
||||||
if(c1 == c2) {
|
if(c1 == c2) {
|
||||||
return c1;
|
return c1;
|
||||||
} else if(isConvertibleWithoutLoss(c2, c1)) {
|
} else if(isConvertibleWithoutLoss(c2, c1)) {
|
||||||
@ -144,11 +144,11 @@ public class TypeUtilities {
|
|||||||
return getMostSpecificCommonTypeUnequalNonprimitives(c1, c2);
|
return getMostSpecificCommonTypeUnequalNonprimitives(c1, c2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class<?> getMostSpecificCommonTypeUnequalNonprimitives(Class<?> c1, Class<?> c2) {
|
private static Class<?> getMostSpecificCommonTypeUnequalNonprimitives(final Class<?> c1, final Class<?> c2) {
|
||||||
final Class<?> npc1 = c1.isPrimitive() ? getWrapperType(c1) : c1;
|
final Class<?> npc1 = c1.isPrimitive() ? getWrapperType(c1) : c1;
|
||||||
final Class<?> npc2 = c2.isPrimitive() ? getWrapperType(c2) : c2;
|
final Class<?> npc2 = c2.isPrimitive() ? getWrapperType(c2) : c2;
|
||||||
Set<Class<?>> a1 = getAssignables(npc1, npc2);
|
final Set<Class<?>> a1 = getAssignables(npc1, npc2);
|
||||||
Set<Class<?>> a2 = getAssignables(npc2, npc1);
|
final Set<Class<?>> a2 = getAssignables(npc2, npc1);
|
||||||
a1.retainAll(a2);
|
a1.retainAll(a2);
|
||||||
if(a1.isEmpty()) {
|
if(a1.isEmpty()) {
|
||||||
// Can happen when at least one of the arguments is an interface,
|
// Can happen when at least one of the arguments is an interface,
|
||||||
@ -159,10 +159,10 @@ public class TypeUtilities {
|
|||||||
// thank to interfaces. I.e., if you call this method for String.class
|
// thank to interfaces. I.e., if you call this method for String.class
|
||||||
// and Number.class, you'll have Comparable, Serializable, and Object
|
// and Number.class, you'll have Comparable, Serializable, and Object
|
||||||
// as maximal elements.
|
// as maximal elements.
|
||||||
List<Class<?>> max = new ArrayList<>();
|
final List<Class<?>> max = new ArrayList<>();
|
||||||
outer: for(Class<?> clazz: a1) {
|
outer: for(final Class<?> clazz: a1) {
|
||||||
for(Iterator<Class<?>> maxiter = max.iterator(); maxiter.hasNext();) {
|
for(final Iterator<Class<?>> maxiter = max.iterator(); maxiter.hasNext();) {
|
||||||
Class<?> maxClazz = maxiter.next();
|
final Class<?> maxClazz = maxiter.next();
|
||||||
if(isSubtype(maxClazz, clazz)) {
|
if(isSubtype(maxClazz, clazz)) {
|
||||||
// It can't be maximal, if there's already a more specific
|
// It can't be maximal, if there's already a more specific
|
||||||
// maximal than it.
|
// maximal than it.
|
||||||
@ -184,21 +184,21 @@ public class TypeUtilities {
|
|||||||
return max.get(0);
|
return max.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<Class<?>> getAssignables(Class<?> c1, Class<?> c2) {
|
private static Set<Class<?>> getAssignables(final Class<?> c1, final Class<?> c2) {
|
||||||
Set<Class<?>> s = new HashSet<>();
|
final Set<Class<?>> s = new HashSet<>();
|
||||||
collectAssignables(c1, c2, s);
|
collectAssignables(c1, c2, s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void collectAssignables(Class<?> c1, Class<?> c2, Set<Class<?>> s) {
|
private static void collectAssignables(final Class<?> c1, final Class<?> c2, final Set<Class<?>> s) {
|
||||||
if(c1.isAssignableFrom(c2)) {
|
if(c1.isAssignableFrom(c2)) {
|
||||||
s.add(c1);
|
s.add(c1);
|
||||||
}
|
}
|
||||||
Class<?> sc = c1.getSuperclass();
|
final Class<?> sc = c1.getSuperclass();
|
||||||
if(sc != null) {
|
if(sc != null) {
|
||||||
collectAssignables(sc, c2, s);
|
collectAssignables(sc, c2, s);
|
||||||
}
|
}
|
||||||
Class<?>[] itf = c1.getInterfaces();
|
final Class<?>[] itf = c1.getInterfaces();
|
||||||
for(int i = 0; i < itf.length; ++i) {
|
for(int i = 0; i < itf.length; ++i) {
|
||||||
collectAssignables(itf[i], c2, s);
|
collectAssignables(itf[i], c2, s);
|
||||||
}
|
}
|
||||||
@ -221,17 +221,17 @@ public class TypeUtilities {
|
|||||||
return Collections.unmodifiableMap(wrapperTypes);
|
return Collections.unmodifiableMap(wrapperTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Map<String, Class<?>> createClassNameMapping(Collection<Class<?>> classes) {
|
private static Map<String, Class<?>> createClassNameMapping(final Collection<Class<?>> classes) {
|
||||||
final Map<String, Class<?>> map = new HashMap<>();
|
final Map<String, Class<?>> map = new HashMap<>();
|
||||||
for(Class<?> clazz: classes) {
|
for(final Class<?> clazz: classes) {
|
||||||
map.put(clazz.getName(), clazz);
|
map.put(clazz.getName(), clazz);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <K, V> Map<V, K> invertMap(Map<K, V> map) {
|
private static <K, V> Map<V, K> invertMap(final Map<K, V> map) {
|
||||||
final Map<V, K> inverted = new IdentityHashMap<>(map.size());
|
final Map<V, K> inverted = new IdentityHashMap<>(map.size());
|
||||||
for(Map.Entry<K, V> entry: map.entrySet()) {
|
for(final Map.Entry<K, V> entry: map.entrySet()) {
|
||||||
inverted.put(entry.getValue(), entry.getKey());
|
inverted.put(entry.getValue(), entry.getKey());
|
||||||
}
|
}
|
||||||
return Collections.unmodifiableMap(inverted);
|
return Collections.unmodifiableMap(inverted);
|
||||||
@ -247,7 +247,7 @@ public class TypeUtilities {
|
|||||||
* @param targetType the parameter type being converted to (method type for parameter types, call site type for return types)
|
* @param targetType the parameter type being converted to (method type for parameter types, call site type for return types)
|
||||||
* @return true if source type is method invocation convertible to target type.
|
* @return true if source type is method invocation convertible to target type.
|
||||||
*/
|
*/
|
||||||
public static boolean isMethodInvocationConvertible(Class<?> sourceType, Class<?> targetType) {
|
public static boolean isMethodInvocationConvertible(final Class<?> sourceType, final Class<?> targetType) {
|
||||||
if(targetType.isAssignableFrom(sourceType)) {
|
if(targetType.isAssignableFrom(sourceType)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ public class TypeUtilities {
|
|||||||
* @param targetType the target type
|
* @param targetType the target type
|
||||||
* @return true if lossess conversion is possible
|
* @return true if lossess conversion is possible
|
||||||
*/
|
*/
|
||||||
public static boolean isConvertibleWithoutLoss(Class<?> sourceType, Class<?> targetType) {
|
public static boolean isConvertibleWithoutLoss(final Class<?> sourceType, final Class<?> targetType) {
|
||||||
if(targetType.isAssignableFrom(sourceType)) {
|
if(targetType.isAssignableFrom(sourceType)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -310,7 +310,7 @@ public class TypeUtilities {
|
|||||||
* @param methodType the parameter type in the method declaration
|
* @param methodType the parameter type in the method declaration
|
||||||
* @return true if callSiteType is potentially convertible to the methodType.
|
* @return true if callSiteType is potentially convertible to the methodType.
|
||||||
*/
|
*/
|
||||||
public static boolean isPotentiallyConvertible(Class<?> callSiteType, Class<?> methodType) {
|
public static boolean isPotentiallyConvertible(final Class<?> callSiteType, final Class<?> methodType) {
|
||||||
// Widening or narrowing reference conversion
|
// Widening or narrowing reference conversion
|
||||||
if(areAssignable(callSiteType, methodType)) {
|
if(areAssignable(callSiteType, methodType)) {
|
||||||
return true;
|
return true;
|
||||||
@ -338,7 +338,7 @@ public class TypeUtilities {
|
|||||||
* @param c2 another one of the types
|
* @param c2 another one of the types
|
||||||
* @return true if either c1 is assignable from c2 or c2 is assignable from c1.
|
* @return true if either c1 is assignable from c2 or c2 is assignable from c1.
|
||||||
*/
|
*/
|
||||||
public static boolean areAssignable(Class<?> c1, Class<?> c2) {
|
public static boolean areAssignable(final Class<?> c1, final Class<?> c2) {
|
||||||
return c1.isAssignableFrom(c2) || c2.isAssignableFrom(c1);
|
return c1.isAssignableFrom(c2) || c2.isAssignableFrom(c1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -353,7 +353,7 @@ public class TypeUtilities {
|
|||||||
* @return true if subType can be converted by identity conversion, widening primitive conversion, or widening
|
* @return true if subType can be converted by identity conversion, widening primitive conversion, or widening
|
||||||
* reference conversion to superType.
|
* reference conversion to superType.
|
||||||
*/
|
*/
|
||||||
public static boolean isSubtype(Class<?> subType, Class<?> superType) {
|
public static boolean isSubtype(final Class<?> subType, final Class<?> superType) {
|
||||||
// Covers both JLS 4.10.2 "Subtyping among Class and Interface Types"
|
// Covers both JLS 4.10.2 "Subtyping among Class and Interface Types"
|
||||||
// and JLS 4.10.3 "Subtyping among Array Types", as well as primitive
|
// and JLS 4.10.3 "Subtyping among Array Types", as well as primitive
|
||||||
// type identity.
|
// type identity.
|
||||||
@ -384,7 +384,7 @@ public class TypeUtilities {
|
|||||||
* @param superType the supposed supertype
|
* @param superType the supposed supertype
|
||||||
* @return true if subType is a proper (not identical to) primitive subtype of the superType
|
* @return true if subType is a proper (not identical to) primitive subtype of the superType
|
||||||
*/
|
*/
|
||||||
private static boolean isProperPrimitiveSubtype(Class<?> subType, Class<?> superType) {
|
private static boolean isProperPrimitiveSubtype(final Class<?> subType, final Class<?> superType) {
|
||||||
if(superType == boolean.class || subType == boolean.class) {
|
if(superType == boolean.class || subType == boolean.class) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -418,7 +418,7 @@ public class TypeUtilities {
|
|||||||
* @return true if subType is a proper (not identical to) primitive subtype of the superType that can be represented
|
* @return true if subType is a proper (not identical to) primitive subtype of the superType that can be represented
|
||||||
* by the supertype without no precision loss.
|
* by the supertype without no precision loss.
|
||||||
*/
|
*/
|
||||||
private static boolean isProperPrimitiveLosslessSubtype(Class<?> subType, Class<?> superType) {
|
private static boolean isProperPrimitiveLosslessSubtype(final Class<?> subType, final Class<?> superType) {
|
||||||
if(superType == boolean.class || subType == boolean.class) {
|
if(superType == boolean.class || subType == boolean.class) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -471,13 +471,13 @@ public class TypeUtilities {
|
|||||||
return classes.keySet();
|
return classes.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addClassHierarchy(Map<Class<?>, Class<?>> map, Class<?> clazz) {
|
private static void addClassHierarchy(final Map<Class<?>, Class<?>> map, final Class<?> clazz) {
|
||||||
if(clazz == null) {
|
if(clazz == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
map.put(clazz, clazz);
|
map.put(clazz, clazz);
|
||||||
addClassHierarchy(map, clazz.getSuperclass());
|
addClassHierarchy(map, clazz.getSuperclass());
|
||||||
for(Class<?> itf: clazz.getInterfaces()) {
|
for(final Class<?> itf: clazz.getInterfaces()) {
|
||||||
addClassHierarchy(map, itf);
|
addClassHierarchy(map, itf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,7 +489,7 @@ public class TypeUtilities {
|
|||||||
* @return true if the class can be assigned from any boxed primitive. Basically, it is true if the class is any
|
* @return true if the class can be assigned from any boxed primitive. Basically, it is true if the class is any
|
||||||
* primitive wrapper class, or a superclass or superinterface of any primitive wrapper class.
|
* primitive wrapper class, or a superclass or superinterface of any primitive wrapper class.
|
||||||
*/
|
*/
|
||||||
private static boolean isAssignableFromBoxedPrimitive(Class<?> clazz) {
|
private static boolean isAssignableFromBoxedPrimitive(final Class<?> clazz) {
|
||||||
return PRIMITIVE_WRAPPER_TYPES.contains(clazz);
|
return PRIMITIVE_WRAPPER_TYPES.contains(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,7 +500,7 @@ public class TypeUtilities {
|
|||||||
* @return the class representing the primitive type, or null if the name does not correspond to a primitive type
|
* @return the class representing the primitive type, or null if the name does not correspond to a primitive type
|
||||||
* or is "void".
|
* or is "void".
|
||||||
*/
|
*/
|
||||||
public static Class<?> getPrimitiveTypeByName(String name) {
|
public static Class<?> getPrimitiveTypeByName(final String name) {
|
||||||
return PRIMITIVE_TYPES_BY_NAME.get(name);
|
return PRIMITIVE_TYPES_BY_NAME.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,7 +511,7 @@ public class TypeUtilities {
|
|||||||
* @param wrapperType the class object representing a wrapper for a primitive type
|
* @param wrapperType the class object representing a wrapper for a primitive type
|
||||||
* @return the class object representing the primitive type, or null if the passed class is not a primitive wrapper.
|
* @return the class object representing the primitive type, or null if the passed class is not a primitive wrapper.
|
||||||
*/
|
*/
|
||||||
public static Class<?> getPrimitiveType(Class<?> wrapperType) {
|
public static Class<?> getPrimitiveType(final Class<?> wrapperType) {
|
||||||
return WRAPPER_TO_PRIMITIVE_TYPES.get(wrapperType);
|
return WRAPPER_TO_PRIMITIVE_TYPES.get(wrapperType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,7 +523,7 @@ public class TypeUtilities {
|
|||||||
* @param primitiveType the class object representing a primitive type
|
* @param primitiveType the class object representing a primitive type
|
||||||
* @return the class object representing the wrapper type, or null if the passed class is not a primitive.
|
* @return the class object representing the wrapper type, or null if the passed class is not a primitive.
|
||||||
*/
|
*/
|
||||||
public static Class<?> getWrapperType(Class<?> primitiveType) {
|
public static Class<?> getWrapperType(final Class<?> primitiveType) {
|
||||||
return WRAPPER_TYPES.get(primitiveType);
|
return WRAPPER_TYPES.get(primitiveType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ class UnnamedDynCallSiteDescriptor extends AbstractCallSiteDescriptor {
|
|||||||
private final MethodType methodType;
|
private final MethodType methodType;
|
||||||
private final String op;
|
private final String op;
|
||||||
|
|
||||||
UnnamedDynCallSiteDescriptor(String op, MethodType methodType) {
|
UnnamedDynCallSiteDescriptor(final String op, final MethodType methodType) {
|
||||||
this.op = op;
|
this.op = op;
|
||||||
this.methodType = methodType;
|
this.methodType = methodType;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ class UnnamedDynCallSiteDescriptor extends AbstractCallSiteDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNameToken(int i) {
|
public String getNameToken(final int i) {
|
||||||
switch(i) {
|
switch(i) {
|
||||||
case 0: return "dyn";
|
case 0: return "dyn";
|
||||||
case 1: return op;
|
case 1: return op;
|
||||||
@ -119,7 +119,7 @@ class UnnamedDynCallSiteDescriptor extends AbstractCallSiteDescriptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallSiteDescriptor changeMethodType(MethodType newMethodType) {
|
public CallSiteDescriptor changeMethodType(final MethodType newMethodType) {
|
||||||
return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new UnnamedDynCallSiteDescriptor(op,
|
return CallSiteDescriptorFactory.getCanonicalPublicDescriptor(new UnnamedDynCallSiteDescriptor(op,
|
||||||
newMethodType));
|
newMethodType));
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,8 @@ final class Formatter {
|
|||||||
|
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
int index = index(m.group(1));
|
int index = index(m.group(1));
|
||||||
boolean previous = isPreviousArgument(m.group(2));
|
final boolean previous = isPreviousArgument(m.group(2));
|
||||||
char conversion = m.group(6).charAt(0);
|
final char conversion = m.group(6).charAt(0);
|
||||||
|
|
||||||
// skip over some formats
|
// skip over some formats
|
||||||
if (index < 0 || previous
|
if (index < 0 || previous
|
||||||
@ -85,7 +85,7 @@ final class Formatter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// current argument
|
// current argument
|
||||||
Object arg = args[index - 1];
|
final Object arg = args[index - 1];
|
||||||
|
|
||||||
// for date we convert double to long
|
// for date we convert double to long
|
||||||
if (m.group(5) != null) {
|
if (m.group(5) != null) {
|
||||||
|
@ -281,7 +281,7 @@ public final class NashornScriptEngine extends AbstractScriptEngine implements C
|
|||||||
private static Source makeSource(final Reader reader, final ScriptContext ctxt) throws ScriptException {
|
private static Source makeSource(final Reader reader, final ScriptContext ctxt) throws ScriptException {
|
||||||
try {
|
try {
|
||||||
return sourceFor(getScriptName(ctxt), reader);
|
return sourceFor(getScriptName(ctxt), reader);
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new ScriptException(e);
|
throw new ScriptException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,13 +43,13 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import javax.script.Bindings;
|
import javax.script.Bindings;
|
||||||
import jdk.nashorn.internal.objects.Global;
|
import jdk.nashorn.internal.objects.Global;
|
||||||
import jdk.nashorn.internal.runtime.arrays.ArrayData;
|
|
||||||
import jdk.nashorn.internal.runtime.ConsString;
|
import jdk.nashorn.internal.runtime.ConsString;
|
||||||
import jdk.nashorn.internal.runtime.Context;
|
import jdk.nashorn.internal.runtime.Context;
|
||||||
import jdk.nashorn.internal.runtime.JSType;
|
import jdk.nashorn.internal.runtime.JSType;
|
||||||
import jdk.nashorn.internal.runtime.ScriptFunction;
|
import jdk.nashorn.internal.runtime.ScriptFunction;
|
||||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||||
|
import jdk.nashorn.internal.runtime.arrays.ArrayData;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mirror object that wraps a given Nashorn Script object.
|
* Mirror object that wraps a given Nashorn Script object.
|
||||||
@ -735,7 +735,7 @@ public final class ScriptObjectMirror extends AbstractJSObject implements Bindin
|
|||||||
return global;
|
return global;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Object translateUndefined(Object obj) {
|
static Object translateUndefined(final Object obj) {
|
||||||
return (obj == ScriptRuntime.UNDEFINED)? null : obj;
|
return (obj == ScriptRuntime.UNDEFINED)? null : obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +28,11 @@ package jdk.nashorn.api.scripting;
|
|||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import jdk.internal.dynalink.beans.StaticClass;
|
import jdk.internal.dynalink.beans.StaticClass;
|
||||||
import jdk.internal.dynalink.linker.LinkerServices;
|
import jdk.internal.dynalink.linker.LinkerServices;
|
||||||
import jdk.nashorn.internal.runtime.linker.Bootstrap;
|
|
||||||
import jdk.nashorn.internal.runtime.Context;
|
import jdk.nashorn.internal.runtime.Context;
|
||||||
import jdk.nashorn.internal.runtime.ScriptFunction;
|
import jdk.nashorn.internal.runtime.ScriptFunction;
|
||||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||||
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
import jdk.nashorn.internal.runtime.ScriptRuntime;
|
||||||
|
import jdk.nashorn.internal.runtime.linker.Bootstrap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utilities that are to be called from script code.
|
* Utilities that are to be called from script code.
|
||||||
|
@ -81,7 +81,7 @@ public final class URLReader extends Reader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read(char cbuf[], int off, int len) throws IOException {
|
public int read(final char cbuf[], final int off, final int len) throws IOException {
|
||||||
return getReader().read(cbuf, off, len);
|
return getReader().read(cbuf, off, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,6 @@ import java.util.Deque;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import jdk.nashorn.internal.ir.AccessNode;
|
import jdk.nashorn.internal.ir.AccessNode;
|
||||||
import jdk.nashorn.internal.ir.CallNode;
|
import jdk.nashorn.internal.ir.CallNode;
|
||||||
import jdk.nashorn.internal.ir.Expression;
|
import jdk.nashorn.internal.ir.Expression;
|
||||||
|
@ -48,7 +48,6 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import jdk.internal.dynalink.support.NameCodec;
|
import jdk.internal.dynalink.support.NameCodec;
|
||||||
import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
|
import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
|
@ -369,7 +369,7 @@ public enum CompilerConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(MethodVisitor mv) {
|
public void invoke(final MethodVisitor mv) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, name, desc, false);
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, name, desc, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -408,7 +408,7 @@ public enum CompilerConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(MethodVisitor mv) {
|
public void invoke(final MethodVisitor mv) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, name, desc, false);
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, name, desc, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -448,7 +448,7 @@ public enum CompilerConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(MethodVisitor mv) {
|
public void invoke(final MethodVisitor mv) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, name, descriptor, false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, name, descriptor, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -473,7 +473,7 @@ public enum CompilerConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(MethodVisitor mv) {
|
public void invoke(final MethodVisitor mv) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, className, name, descriptor, true);
|
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, className, name, descriptor, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -574,7 +574,7 @@ public enum CompilerConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(MethodVisitor mv) {
|
public void invoke(final MethodVisitor mv) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, name, descriptor, false);
|
mv.visitMethodInsn(Opcodes.INVOKESTATIC, className, name, descriptor, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -599,7 +599,7 @@ public enum CompilerConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(MethodVisitor mv) {
|
public void invoke(final MethodVisitor mv) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, name, descriptor, false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, name, descriptor, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -625,7 +625,7 @@ public enum CompilerConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(MethodVisitor mv) {
|
public void invoke(final MethodVisitor mv) {
|
||||||
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, name, descriptor, false);
|
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, name, descriptor, false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -28,15 +28,14 @@ package jdk.nashorn.internal.codegen;
|
|||||||
import static jdk.nashorn.internal.codegen.CompilerConstants.ARGUMENTS;
|
import static jdk.nashorn.internal.codegen.CompilerConstants.ARGUMENTS;
|
||||||
import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup;
|
import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup;
|
||||||
import static jdk.nashorn.internal.codegen.CompilerConstants.typeDescriptor;
|
import static jdk.nashorn.internal.codegen.CompilerConstants.typeDescriptor;
|
||||||
|
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.PRIMITIVE_FIELD_TYPE;
|
||||||
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.getFieldName;
|
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.getFieldName;
|
||||||
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.getPaddedFieldCount;
|
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.getPaddedFieldCount;
|
||||||
import static jdk.nashorn.internal.codegen.ObjectClassGenerator.PRIMITIVE_FIELD_TYPE;
|
|
||||||
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndex;
|
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndex;
|
||||||
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
|
import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
import jdk.nashorn.internal.ir.Symbol;
|
import jdk.nashorn.internal.ir.Symbol;
|
||||||
import jdk.nashorn.internal.runtime.Context;
|
import jdk.nashorn.internal.runtime.Context;
|
||||||
|
@ -30,7 +30,6 @@ import java.util.BitSet;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +35,7 @@ public class LocalStateRestorationInfo {
|
|||||||
private final Type[] localVariableTypes;
|
private final Type[] localVariableTypes;
|
||||||
private final int[] stackLoads;
|
private final int[] stackLoads;
|
||||||
|
|
||||||
LocalStateRestorationInfo(Type[] localVariableTypes, final int[] stackLoads) {
|
LocalStateRestorationInfo(final Type[] localVariableTypes, final int[] stackLoads) {
|
||||||
this.localVariableTypes = localVariableTypes;
|
this.localVariableTypes = localVariableTypes;
|
||||||
this.stackLoads = stackLoads;
|
this.stackLoads = stackLoads;
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
package jdk.nashorn.internal.codegen;
|
package jdk.nashorn.internal.codegen;
|
||||||
|
|
||||||
import static jdk.nashorn.internal.codegen.CompilerConstants.SCOPE;
|
import static jdk.nashorn.internal.codegen.CompilerConstants.SCOPE;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
import jdk.nashorn.internal.runtime.PropertyMap;
|
import jdk.nashorn.internal.runtime.PropertyMap;
|
||||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||||
|
@ -55,7 +55,7 @@ public class SplitMethodEmitter extends MethodEmitter {
|
|||||||
*/
|
*/
|
||||||
private final List<BreakableNode> externalTargetNodes = new ArrayList<>();
|
private final List<BreakableNode> externalTargetNodes = new ArrayList<>();
|
||||||
|
|
||||||
SplitMethodEmitter(final ClassEmitter classEmitter, final MethodVisitor mv, SplitNode splitNode) {
|
SplitMethodEmitter(final ClassEmitter classEmitter, final MethodVisitor mv, final SplitNode splitNode) {
|
||||||
super(classEmitter, mv);
|
super(classEmitter, mv);
|
||||||
this.splitNode = splitNode;
|
this.splitNode = splitNode;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jdk.nashorn.internal.ir.Block;
|
import jdk.nashorn.internal.ir.Block;
|
||||||
import jdk.nashorn.internal.ir.FunctionNode;
|
import jdk.nashorn.internal.ir.FunctionNode;
|
||||||
import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
|
import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
|
||||||
|
@ -29,7 +29,6 @@ import java.lang.invoke.MethodType;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
import jdk.nashorn.internal.ir.FunctionNode;
|
import jdk.nashorn.internal.ir.FunctionNode;
|
||||||
import jdk.nashorn.internal.runtime.ScriptFunction;
|
import jdk.nashorn.internal.runtime.ScriptFunction;
|
||||||
|
@ -101,7 +101,7 @@ final class WeighNodes extends NodeOperatorVisitor<LexicalContext> {
|
|||||||
*
|
*
|
||||||
* @param weightCache cache of already calculated block weights
|
* @param weightCache cache of already calculated block weights
|
||||||
*/
|
*/
|
||||||
private WeighNodes(FunctionNode topFunction, final Map<Node, Long> weightCache) {
|
private WeighNodes(final FunctionNode topFunction, final Map<Node, Long> weightCache) {
|
||||||
super(new LexicalContext());
|
super(new LexicalContext());
|
||||||
this.topFunction = topFunction;
|
this.topFunction = topFunction;
|
||||||
this.weightCache = weightCache;
|
this.weightCache = weightCache;
|
||||||
|
@ -102,7 +102,7 @@ public final class BooleanType extends Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type loadForcedInitializer(MethodVisitor method) {
|
public Type loadForcedInitializer(final MethodVisitor method) {
|
||||||
method.visitInsn(ICONST_0);
|
method.visitInsn(ICONST_0);
|
||||||
return BOOLEAN;
|
return BOOLEAN;
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ class IntType extends BitwiseType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type loadForcedInitializer(MethodVisitor method) {
|
public Type loadForcedInitializer(final MethodVisitor method) {
|
||||||
method.visitInsn(ICONST_0);
|
method.visitInsn(ICONST_0);
|
||||||
return INT;
|
return INT;
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,7 @@ class LongType extends BitwiseType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type loadForcedInitializer(MethodVisitor method) {
|
public Type loadForcedInitializer(final MethodVisitor method) {
|
||||||
method.visitInsn(LCONST_0);
|
method.visitInsn(LCONST_0);
|
||||||
return LONG;
|
return LONG;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ class NumberType extends NumericType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type loadForcedInitializer(MethodVisitor method) {
|
public Type loadForcedInitializer(final MethodVisitor method) {
|
||||||
method.visitInsn(DCONST_0);
|
method.visitInsn(DCONST_0);
|
||||||
return NUMBER;
|
return NUMBER;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ class ObjectType extends Type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type loadForcedInitializer(MethodVisitor method) {
|
public Type loadForcedInitializer(final MethodVisitor method) {
|
||||||
method.visitInsn(ACONST_NULL);
|
method.visitInsn(ACONST_NULL);
|
||||||
// TODO: do we need a special type for null, e.g. Type.NULL? It should be assignable to any other object type
|
// TODO: do we need a special type for null, e.g. Type.NULL? It should be assignable to any other object type
|
||||||
// without a checkast in convert.
|
// without a checkast in convert.
|
||||||
|
@ -1004,7 +1004,7 @@ public abstract class Type implements Comparable<Type>, BytecodeOps {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static <T extends Type> T putInCache(T type) {
|
private static <T extends Type> T putInCache(final T type) {
|
||||||
cache.put(type.getTypeClass(), type);
|
cache.put(type.getTypeClass(), type);
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
@ -40,14 +40,14 @@ import java.util.List;
|
|||||||
public class BlockLexicalContext extends LexicalContext {
|
public class BlockLexicalContext extends LexicalContext {
|
||||||
/** statement stack, each block on the lexical context maintains one of these, which is
|
/** statement stack, each block on the lexical context maintains one of these, which is
|
||||||
* committed to the block on pop */
|
* committed to the block on pop */
|
||||||
private Deque<List<Statement>> sstack = new ArrayDeque<>();
|
private final Deque<List<Statement>> sstack = new ArrayDeque<>();
|
||||||
|
|
||||||
/** Last non debug statement emitted in this context */
|
/** Last non debug statement emitted in this context */
|
||||||
protected Statement lastStatement;
|
protected Statement lastStatement;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends LexicalContextNode> T push(final T node) {
|
public <T extends LexicalContextNode> T push(final T node) {
|
||||||
T pushed = super.push(node);
|
final T pushed = super.push(node);
|
||||||
if (node instanceof Block) {
|
if (node instanceof Block) {
|
||||||
sstack.push(new ArrayList<Statement>());
|
sstack.push(new ArrayList<Statement>());
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ public class BlockLexicalContext extends LexicalContext {
|
|||||||
* @param block the block to operate on
|
* @param block the block to operate on
|
||||||
* @return a modified block.
|
* @return a modified block.
|
||||||
*/
|
*/
|
||||||
protected Block afterSetStatements(Block block) {
|
protected Block afterSetStatements(final Block block) {
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ package jdk.nashorn.internal.ir;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.Label;
|
import jdk.nashorn.internal.codegen.Label;
|
||||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
package jdk.nashorn.internal.ir;
|
package jdk.nashorn.internal.ir;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
|
import jdk.nashorn.internal.runtime.UnwarrantedOptimismException;
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.CompileUnit;
|
import jdk.nashorn.internal.codegen.CompileUnit;
|
||||||
import jdk.nashorn.internal.codegen.Compiler;
|
import jdk.nashorn.internal.codegen.Compiler;
|
||||||
import jdk.nashorn.internal.codegen.CompilerConstants;
|
import jdk.nashorn.internal.codegen.CompilerConstants;
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
package jdk.nashorn.internal.ir;
|
package jdk.nashorn.internal.ir;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.Label;
|
import jdk.nashorn.internal.codegen.Label;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,15 +29,15 @@ import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
|||||||
|
|
||||||
abstract class LexicalContextExpression extends Expression implements LexicalContextNode {
|
abstract class LexicalContextExpression extends Expression implements LexicalContextNode {
|
||||||
|
|
||||||
LexicalContextExpression(LexicalContextExpression expr) {
|
LexicalContextExpression(final LexicalContextExpression expr) {
|
||||||
super(expr);
|
super(expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
LexicalContextExpression(long token, int start, int finish) {
|
LexicalContextExpression(final long token, final int start, final int finish) {
|
||||||
super(token, start, finish);
|
super(token, start, finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
LexicalContextExpression(long token, int finish) {
|
LexicalContextExpression(final long token, final int finish) {
|
||||||
super(token, finish);
|
super(token, finish);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.CompileUnit;
|
import jdk.nashorn.internal.codegen.CompileUnit;
|
||||||
import jdk.nashorn.internal.codegen.types.ArrayType;
|
import jdk.nashorn.internal.codegen.types.ArrayType;
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
|
@ -28,7 +28,6 @@ package jdk.nashorn.internal.ir;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.Label;
|
import jdk.nashorn.internal.codegen.Label;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +27,6 @@ package jdk.nashorn.internal.ir;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||||
import jdk.nashorn.internal.parser.Token;
|
import jdk.nashorn.internal.parser.Token;
|
||||||
import jdk.nashorn.internal.parser.TokenType;
|
import jdk.nashorn.internal.parser.TokenType;
|
||||||
|
@ -28,7 +28,6 @@ package jdk.nashorn.internal.ir;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||||
|
@ -116,7 +116,7 @@ public class OptimisticLexicalContext extends LexicalContext {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T extends LexicalContextNode> T pop(final T node) {
|
public <T extends LexicalContextNode> T pop(final T node) {
|
||||||
T popped = super.pop(node);
|
final T popped = super.pop(node);
|
||||||
if (isEnabled) {
|
if (isEnabled) {
|
||||||
if(node instanceof FunctionNode) {
|
if(node instanceof FunctionNode) {
|
||||||
optimisticAssumptions.pop();
|
optimisticAssumptions.pop();
|
||||||
|
@ -27,6 +27,7 @@ package jdk.nashorn.internal.ir;
|
|||||||
|
|
||||||
import static jdk.nashorn.internal.parser.TokenType.RETURN;
|
import static jdk.nashorn.internal.parser.TokenType.RETURN;
|
||||||
import static jdk.nashorn.internal.parser.TokenType.YIELD;
|
import static jdk.nashorn.internal.parser.TokenType.YIELD;
|
||||||
|
|
||||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.CompileUnit;
|
import jdk.nashorn.internal.codegen.CompileUnit;
|
||||||
import jdk.nashorn.internal.codegen.Label;
|
import jdk.nashorn.internal.codegen.Label;
|
||||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||||
|
@ -28,7 +28,6 @@ package jdk.nashorn.internal.ir;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.Label;
|
import jdk.nashorn.internal.codegen.Label;
|
||||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
package jdk.nashorn.internal.ir;
|
package jdk.nashorn.internal.ir;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||||
|
@ -28,7 +28,6 @@ package jdk.nashorn.internal.ir;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||||
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ import java.util.Arrays;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
import jdk.nashorn.internal.codegen.types.Type;
|
import jdk.nashorn.internal.codegen.types.Type;
|
||||||
import jdk.nashorn.internal.ir.annotations.Ignore;
|
import jdk.nashorn.internal.ir.annotations.Ignore;
|
||||||
import jdk.nashorn.internal.ir.annotations.Immutable;
|
import jdk.nashorn.internal.ir.annotations.Immutable;
|
||||||
|
@ -105,7 +105,7 @@ public final class ASTWriter {
|
|||||||
|
|
||||||
final boolean isReference = field != null && field.isAnnotationPresent(Reference.class);
|
final boolean isReference = field != null && field.isAnnotationPresent(Reference.class);
|
||||||
|
|
||||||
Class<?> clazz = node.getClass();
|
final Class<?> clazz = node.getClass();
|
||||||
String type = clazz.getName();
|
String type = clazz.getName();
|
||||||
|
|
||||||
type = type.substring(type.lastIndexOf('.') + 1, type.length());
|
type = type.substring(type.lastIndexOf('.') + 1, type.length());
|
||||||
|
@ -29,7 +29,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import jdk.internal.org.objectweb.asm.Attribute;
|
import jdk.internal.org.objectweb.asm.Attribute;
|
||||||
import jdk.internal.org.objectweb.asm.ClassReader;
|
import jdk.internal.org.objectweb.asm.ClassReader;
|
||||||
import jdk.internal.org.objectweb.asm.ClassVisitor;
|
import jdk.internal.org.objectweb.asm.ClassVisitor;
|
||||||
@ -58,27 +57,27 @@ public class NashornClassReader extends ClassReader {
|
|||||||
return labelMap.get(key);
|
return labelMap.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int readByte(final byte[] bytecode, int index) {
|
private static int readByte(final byte[] bytecode, final int index) {
|
||||||
return (byte)(bytecode[index] & 0xff);
|
return (byte)(bytecode[index] & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int readShort(final byte[] bytecode, int index) {
|
private static int readShort(final byte[] bytecode, final int index) {
|
||||||
return (short)((bytecode[index] & 0xff) << 8) | (bytecode[index + 1] & 0xff);
|
return (short)((bytecode[index] & 0xff) << 8) | (bytecode[index + 1] & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int readInt(final byte[] bytecode, int index) {
|
private static int readInt(final byte[] bytecode, final int index) {
|
||||||
return ((bytecode[index] & 0xff) << 24) | ((bytecode[index + 1] & 0xff) << 16) | ((bytecode[index + 2] & 0xff) << 8) | (bytecode[index + 3] & 0xff);
|
return ((bytecode[index] & 0xff) << 24) | ((bytecode[index + 1] & 0xff) << 16) | ((bytecode[index + 2] & 0xff) << 8) | (bytecode[index + 3] & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long readLong(final byte[] bytecode, int index) {
|
private static long readLong(final byte[] bytecode, final int index) {
|
||||||
int hi = readInt(bytecode, index);
|
final int hi = readInt(bytecode, index);
|
||||||
int lo = readInt(bytecode, index + 4);
|
final int lo = readInt(bytecode, index + 4);
|
||||||
return ((long)hi << 32) | lo;
|
return ((long)hi << 32) | lo;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String readUTF(int index, final int utfLen, final byte[] bytecode) {
|
private static String readUTF(final int index, final int utfLen, final byte[] bytecode) {
|
||||||
int endIndex = index + utfLen;
|
final int endIndex = index + utfLen;
|
||||||
char buf[] = new char[utfLen * 2];
|
final char buf[] = new char[utfLen * 2];
|
||||||
int strLen = 0;
|
int strLen = 0;
|
||||||
int c;
|
int c;
|
||||||
int st = 0;
|
int st = 0;
|
||||||
@ -123,7 +122,7 @@ public class NashornClassReader extends ClassReader {
|
|||||||
|
|
||||||
int u = 0;
|
int u = 0;
|
||||||
|
|
||||||
int magic = readInt(bytecode, u);
|
final int magic = readInt(bytecode, u);
|
||||||
u += 4; //magic
|
u += 4; //magic
|
||||||
assert magic == 0xcafebabe : Integer.toHexString(magic);
|
assert magic == 0xcafebabe : Integer.toHexString(magic);
|
||||||
readShort(bytecode, u); //minor
|
readShort(bytecode, u); //minor
|
||||||
@ -131,9 +130,9 @@ public class NashornClassReader extends ClassReader {
|
|||||||
readShort(bytecode, u); //major
|
readShort(bytecode, u); //major
|
||||||
u += 2; //minor
|
u += 2; //minor
|
||||||
|
|
||||||
int cpc = readShort(bytecode, u);
|
final int cpc = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
ArrayList<Constant> cp = new ArrayList<>(cpc);
|
final ArrayList<Constant> cp = new ArrayList<>(cpc);
|
||||||
cp.add(null);
|
cp.add(null);
|
||||||
|
|
||||||
for (int i = 1; i < cpc; i++) {
|
for (int i = 1; i < cpc; i++) {
|
||||||
@ -180,7 +179,7 @@ public class NashornClassReader extends ClassReader {
|
|||||||
u += 4;
|
u += 4;
|
||||||
break;
|
break;
|
||||||
case 1: //utf8
|
case 1: //utf8
|
||||||
int len = readShort(bytecode, u);
|
final int len = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
cp.add(new DirectInfo<>(cp, tag, readUTF(u, len, bytecode)));
|
cp.add(new DirectInfo<>(cp, tag, readUTF(u, len, bytecode)));
|
||||||
u += len;
|
u += len;
|
||||||
@ -200,7 +199,7 @@ public class NashornClassReader extends ClassReader {
|
|||||||
u += 4;
|
u += 4;
|
||||||
break;
|
break;
|
||||||
case 15: //methodhandle
|
case 15: //methodhandle
|
||||||
int kind = readByte(bytecode, u);
|
final int kind = readByte(bytecode, u);
|
||||||
assert kind >= 1 && kind <= 9 : kind;
|
assert kind >= 1 && kind <= 9 : kind;
|
||||||
cp.add(new IndexInfo2(cp, tag, kind, readShort(bytecode, u + 1)) {
|
cp.add(new IndexInfo2(cp, tag, kind, readShort(bytecode, u + 1)) {
|
||||||
@Override
|
@Override
|
||||||
@ -219,16 +218,16 @@ public class NashornClassReader extends ClassReader {
|
|||||||
|
|
||||||
readShort(bytecode, u); //access flags
|
readShort(bytecode, u); //access flags
|
||||||
u += 2; //access
|
u += 2; //access
|
||||||
int cls = readShort(bytecode, u);
|
final int cls = readShort(bytecode, u);
|
||||||
u += 2; //this_class
|
u += 2; //this_class
|
||||||
thisClassName = cp.get(cls).toString();
|
thisClassName = cp.get(cls).toString();
|
||||||
u += 2; //super
|
u += 2; //super
|
||||||
|
|
||||||
int ifc = readShort(bytecode, u);
|
final int ifc = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
u += ifc * 2;
|
u += ifc * 2;
|
||||||
|
|
||||||
int fc = readShort(bytecode, u);
|
final int fc = readShort(bytecode, u);
|
||||||
u += 2; //fields
|
u += 2; //fields
|
||||||
|
|
||||||
for (int i = 0 ; i < fc ; i++) {
|
for (int i = 0 ; i < fc ; i++) {
|
||||||
@ -236,41 +235,41 @@ public class NashornClassReader extends ClassReader {
|
|||||||
readShort(bytecode, u); //fieldname
|
readShort(bytecode, u); //fieldname
|
||||||
u += 2; //name
|
u += 2; //name
|
||||||
u += 2; //descriptor
|
u += 2; //descriptor
|
||||||
int ac = readShort(bytecode, u);
|
final int ac = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
//field attributes
|
//field attributes
|
||||||
for (int j = 0; j < ac; j++) {
|
for (int j = 0; j < ac; j++) {
|
||||||
u += 2; //attribute name
|
u += 2; //attribute name
|
||||||
int len = readInt(bytecode, u);
|
final int len = readInt(bytecode, u);
|
||||||
u += 4;
|
u += 4;
|
||||||
u += len;
|
u += len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int mc = readShort(bytecode, u);
|
final int mc = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
for (int i = 0 ; i < mc ; i++) {
|
for (int i = 0 ; i < mc ; i++) {
|
||||||
readShort(bytecode, u);
|
readShort(bytecode, u);
|
||||||
u += 2; //access
|
u += 2; //access
|
||||||
|
|
||||||
int methodNameIndex = readShort(bytecode, u);
|
final int methodNameIndex = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
final String methodName = cp.get(methodNameIndex).toString();
|
final String methodName = cp.get(methodNameIndex).toString();
|
||||||
|
|
||||||
int methodDescIndex = readShort(bytecode, u);
|
final int methodDescIndex = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
final String methodDesc = cp.get(methodDescIndex).toString();
|
final String methodDesc = cp.get(methodDescIndex).toString();
|
||||||
|
|
||||||
int ac = readShort(bytecode, u);
|
final int ac = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
|
|
||||||
//method attributes
|
//method attributes
|
||||||
for (int j = 0; j < ac; j++) {
|
for (int j = 0; j < ac; j++) {
|
||||||
int nameIndex = readShort(bytecode, u);
|
final int nameIndex = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
String attrName = cp.get(nameIndex).toString();
|
final String attrName = cp.get(nameIndex).toString();
|
||||||
|
|
||||||
int attrLen = readInt(bytecode, u);
|
final int attrLen = readInt(bytecode, u);
|
||||||
u += 4;
|
u += 4;
|
||||||
|
|
||||||
if ("Code".equals(attrName)) {
|
if ("Code".equals(attrName)) {
|
||||||
@ -278,20 +277,20 @@ public class NashornClassReader extends ClassReader {
|
|||||||
u += 2; //max stack
|
u += 2; //max stack
|
||||||
readShort(bytecode, u);
|
readShort(bytecode, u);
|
||||||
u += 2; //max locals
|
u += 2; //max locals
|
||||||
int len = readInt(bytecode, u);
|
final int len = readInt(bytecode, u);
|
||||||
u += 4;
|
u += 4;
|
||||||
parseCode(bytecode, u, len, fullyQualifiedName(thisClassName, methodName, methodDesc));
|
parseCode(bytecode, u, len, fullyQualifiedName(thisClassName, methodName, methodDesc));
|
||||||
u += len;
|
u += len;
|
||||||
int elen = readShort(bytecode, u); //exception table length
|
final int elen = readShort(bytecode, u); //exception table length
|
||||||
u += 2;
|
u += 2;
|
||||||
u += elen * 8;
|
u += elen * 8;
|
||||||
|
|
||||||
//method attributes
|
//method attributes
|
||||||
int ac2 = readShort(bytecode, u);
|
final int ac2 = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
for (int k = 0; k < ac2; k++) {
|
for (int k = 0; k < ac2; k++) {
|
||||||
u += 2; //name;
|
u += 2; //name;
|
||||||
int aclen = readInt(bytecode, u);
|
final int aclen = readInt(bytecode, u);
|
||||||
u += 4; //length
|
u += 4; //length
|
||||||
u += aclen; //bytes;
|
u += aclen; //bytes;
|
||||||
}
|
}
|
||||||
@ -301,13 +300,13 @@ public class NashornClassReader extends ClassReader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ac = readShort(bytecode, u);
|
final int ac = readShort(bytecode, u);
|
||||||
u += 2;
|
u += 2;
|
||||||
//other attributes
|
//other attributes
|
||||||
for (int i = 0 ; i < ac ; i++) {
|
for (int i = 0 ; i < ac ; i++) {
|
||||||
readShort(bytecode, u); //name index
|
readShort(bytecode, u); //name index
|
||||||
u += 2;
|
u += 2;
|
||||||
int len = readInt(bytecode, u);
|
final int len = readInt(bytecode, u);
|
||||||
u += 4;
|
u += 4;
|
||||||
u += len;
|
u += len;
|
||||||
//attribute
|
//attribute
|
||||||
@ -327,7 +326,7 @@ public class NashornClassReader extends ClassReader {
|
|||||||
boolean wide = false;
|
boolean wide = false;
|
||||||
|
|
||||||
for (int i = index; i < index + len;) {
|
for (int i = index; i < index + len;) {
|
||||||
int opcode = bytecode[i];
|
final int opcode = bytecode[i];
|
||||||
labels.add(new NashornLabel(opcode, i - index));
|
labels.add(new NashornLabel(opcode, i - index));
|
||||||
|
|
||||||
switch (opcode & 0xff) {
|
switch (opcode & 0xff) {
|
||||||
@ -345,7 +344,7 @@ public class NashornClassReader extends ClassReader {
|
|||||||
}
|
}
|
||||||
readInt(bytecode, i);
|
readInt(bytecode, i);
|
||||||
i += 4; //defaultbyte
|
i += 4; //defaultbyte
|
||||||
int npairs = readInt(bytecode, i);
|
final int npairs = readInt(bytecode, i);
|
||||||
i += 4;
|
i += 4;
|
||||||
i += 8 * npairs;
|
i += 8 * npairs;
|
||||||
break;
|
break;
|
||||||
@ -356,9 +355,9 @@ public class NashornClassReader extends ClassReader {
|
|||||||
}
|
}
|
||||||
readInt(bytecode, i); //default
|
readInt(bytecode, i); //default
|
||||||
i += 4;
|
i += 4;
|
||||||
int lo = readInt(bytecode, i);
|
final int lo = readInt(bytecode, i);
|
||||||
i += 4;
|
i += 4;
|
||||||
int hi = readInt(bytecode, i);
|
final int hi = readInt(bytecode, i);
|
||||||
i += 4;
|
i += 4;
|
||||||
i += 4 * (hi - lo + 1);
|
i += 4 * (hi - lo + 1);
|
||||||
break;
|
break;
|
||||||
@ -437,13 +436,13 @@ public class NashornClassReader extends ClassReader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(final ClassVisitor classVisitor, Attribute[] attrs, final int flags) {
|
public void accept(final ClassVisitor classVisitor, final Attribute[] attrs, final int flags) {
|
||||||
super.accept(classVisitor, attrs, flags);
|
super.accept(classVisitor, attrs, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Label readLabel(final int offset, final Label[] labels) {
|
protected Label readLabel(final int offset, final Label[] labels) {
|
||||||
Label label = super.readLabel(offset, labels);
|
final Label label = super.readLabel(offset, labels);
|
||||||
label.info = (int)offset;
|
label.info = (int)offset;
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
@ -451,7 +450,7 @@ public class NashornClassReader extends ClassReader {
|
|||||||
private abstract static class Constant {
|
private abstract static class Constant {
|
||||||
protected ArrayList<Constant> cp;
|
protected ArrayList<Constant> cp;
|
||||||
protected int tag;
|
protected int tag;
|
||||||
protected Constant(final ArrayList<Constant> cp, int tag) {
|
protected Constant(final ArrayList<Constant> cp, final int tag) {
|
||||||
this.cp = cp;
|
this.cp = cp;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
}
|
}
|
||||||
@ -469,7 +468,7 @@ public class NashornClassReader extends ClassReader {
|
|||||||
private static class IndexInfo extends Constant {
|
private static class IndexInfo extends Constant {
|
||||||
protected final int index;
|
protected final int index;
|
||||||
|
|
||||||
IndexInfo(final ArrayList<Constant> cp, int tag, int index) {
|
IndexInfo(final ArrayList<Constant> cp, final int tag, final int index) {
|
||||||
super(cp, tag);
|
super(cp, tag);
|
||||||
this.index = index;
|
this.index = index;
|
||||||
}
|
}
|
||||||
@ -483,7 +482,7 @@ public class NashornClassReader extends ClassReader {
|
|||||||
private static class IndexInfo2 extends IndexInfo {
|
private static class IndexInfo2 extends IndexInfo {
|
||||||
protected final int index2;
|
protected final int index2;
|
||||||
|
|
||||||
IndexInfo2(final ArrayList<Constant> cp, int tag, int index, int index2) {
|
IndexInfo2(final ArrayList<Constant> cp, final int tag, final int index, final int index2) {
|
||||||
super(cp, tag, index);
|
super(cp, tag, index);
|
||||||
this.index2 = index2;
|
this.index2 = index2;
|
||||||
}
|
}
|
||||||
@ -497,7 +496,7 @@ public class NashornClassReader extends ClassReader {
|
|||||||
private static class DirectInfo<T> extends Constant {
|
private static class DirectInfo<T> extends Constant {
|
||||||
protected final T info;
|
protected final T info;
|
||||||
|
|
||||||
DirectInfo(final ArrayList<Constant> cp, int tag, T info) {
|
DirectInfo(final ArrayList<Constant> cp, final int tag, final T info) {
|
||||||
super(cp, tag);
|
super(cp, tag);
|
||||||
this.info = info;
|
this.info = info;
|
||||||
}
|
}
|
||||||
|
@ -494,7 +494,7 @@ public final class NashornTextifier extends Printer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) {
|
public void visitInvokeDynamicInsn(final String name, final String desc, final Handle bsm, final Object... bsmArgs) {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
appendOpcode(sb, Opcodes.INVOKEDYNAMIC).append(' ');
|
appendOpcode(sb, Opcodes.INVOKEDYNAMIC).append(' ');
|
||||||
@ -1005,7 +1005,7 @@ public final class NashornTextifier extends Printer {
|
|||||||
private static final String COLOR_DEFAULT = "\"#99bb99\"";
|
private static final String COLOR_DEFAULT = "\"#99bb99\"";
|
||||||
private static final String COLOR_LOCALVARS = "\"#999999\"";
|
private static final String COLOR_LOCALVARS = "\"#999999\"";
|
||||||
|
|
||||||
Graph(String name) {
|
Graph(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.nodes = new LinkedHashSet<>();
|
this.nodes = new LinkedHashSet<>();
|
||||||
this.contents = new HashMap<>();
|
this.contents = new HashMap<>();
|
||||||
@ -1016,7 +1016,7 @@ public final class NashornTextifier extends Printer {
|
|||||||
this.exceptionMap = new HashMap<>();
|
this.exceptionMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void addEdge(String from, String to) {
|
void addEdge(final String from, final String to) {
|
||||||
Set<String> edgeSet = edges.get(from);
|
Set<String> edgeSet = edges.get(from);
|
||||||
if (edgeSet == null) {
|
if (edgeSet == null) {
|
||||||
edgeSet = new LinkedHashSet<>();
|
edgeSet = new LinkedHashSet<>();
|
||||||
@ -1026,7 +1026,7 @@ public final class NashornTextifier extends Printer {
|
|||||||
hasPreds.add(to);
|
hasPreds.add(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTryCatch(String tryNode, String catchNode) {
|
void addTryCatch(final String tryNode, final String catchNode) {
|
||||||
Set<String> tryNodes = exceptionMap.get(catchNode);
|
Set<String> tryNodes = exceptionMap.get(catchNode);
|
||||||
if (tryNodes == null) {
|
if (tryNodes == null) {
|
||||||
tryNodes = new HashSet<>();
|
tryNodes = new HashSet<>();
|
||||||
@ -1038,20 +1038,20 @@ public final class NashornTextifier extends Printer {
|
|||||||
tryNodes.add(tryNode);
|
tryNodes.add(tryNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addNode(String node) {
|
void addNode(final String node) {
|
||||||
assert !nodes.contains(node);
|
assert !nodes.contains(node);
|
||||||
nodes.add(node);
|
nodes.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNoFallThru(String node) {
|
void setNoFallThru(final String node) {
|
||||||
noFallThru.add(node);
|
noFallThru.add(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isNoFallThru(String node) {
|
boolean isNoFallThru(final String node) {
|
||||||
return noFallThru.contains(node);
|
return noFallThru.contains(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setIsCatch(String node, String exception) {
|
void setIsCatch(final String node, final String exception) {
|
||||||
catches.put(node, exception);
|
catches.put(node, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1187,47 +1187,47 @@ public final class NashornTextifier extends Printer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Printer visitClassAnnotation(String arg0, boolean arg1) {
|
public Printer visitClassAnnotation(final String arg0, final boolean arg1) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitClassAttribute(Attribute arg0) {
|
public void visitClassAttribute(final Attribute arg0) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Printer visitFieldAnnotation(String arg0, boolean arg1) {
|
public Printer visitFieldAnnotation(final String arg0, final boolean arg1) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitFieldAttribute(Attribute arg0) {
|
public void visitFieldAttribute(final Attribute arg0) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Printer visitMethodAnnotation(String arg0, boolean arg1) {
|
public Printer visitMethodAnnotation(final String arg0, final boolean arg1) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitMethodAttribute(Attribute arg0) {
|
public void visitMethodAttribute(final Attribute arg0) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Printer visitParameterAnnotation(int arg0, String arg1, boolean arg2) {
|
public Printer visitParameterAnnotation(final int arg0, final String arg1, final boolean arg2) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(String arg0, Object arg1) {
|
public void visit(final String arg0, final Object arg1) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Printer visitAnnotation(String arg0, String arg1) {
|
public Printer visitAnnotation(final String arg0, final String arg1) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1237,17 +1237,17 @@ public final class NashornTextifier extends Printer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Printer visitArray(String arg0) {
|
public Printer visitArray(final String arg0) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitEnum(String arg0, String arg1, String arg2) {
|
public void visitEnum(final String arg0, final String arg1, final String arg2) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitInnerClass(String arg0, String arg1, String arg2, int arg3) {
|
public void visitInnerClass(final String arg0, final String arg1, final String arg2, final int arg3) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,14 +36,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import jdk.nashorn.internal.runtime.ConsString;
|
import jdk.nashorn.internal.runtime.ConsString;
|
||||||
import jdk.nashorn.internal.runtime.Context;
|
import jdk.nashorn.internal.runtime.Context;
|
||||||
import jdk.nashorn.internal.runtime.Debug;
|
import jdk.nashorn.internal.runtime.Debug;
|
||||||
|
import jdk.nashorn.internal.runtime.ScriptObject;
|
||||||
import jdk.nashorn.internal.runtime.logging.DebugLogger;
|
import jdk.nashorn.internal.runtime.logging.DebugLogger;
|
||||||
import jdk.nashorn.internal.runtime.logging.Loggable;
|
import jdk.nashorn.internal.runtime.logging.Loggable;
|
||||||
import jdk.nashorn.internal.runtime.logging.Logger;
|
import jdk.nashorn.internal.runtime.logging.Logger;
|
||||||
import jdk.nashorn.internal.runtime.ScriptObject;
|
|
||||||
import jdk.nashorn.internal.runtime.options.Options;
|
import jdk.nashorn.internal.runtime.options.Options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +30,6 @@ import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
|
|||||||
import static jdk.nashorn.internal.runtime.ScriptRuntime.sameValue;
|
import static jdk.nashorn.internal.runtime.ScriptRuntime.sameValue;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import jdk.nashorn.internal.objects.annotations.Property;
|
import jdk.nashorn.internal.objects.annotations.Property;
|
||||||
import jdk.nashorn.internal.objects.annotations.ScriptClass;
|
import jdk.nashorn.internal.objects.annotations.ScriptClass;
|
||||||
import jdk.nashorn.internal.runtime.JSType;
|
import jdk.nashorn.internal.runtime.JSType;
|
||||||
|
@ -38,7 +38,7 @@ import jdk.nashorn.internal.runtime.ScriptRuntime;
|
|||||||
final class BoundScriptFunctionImpl extends ScriptFunctionImpl {
|
final class BoundScriptFunctionImpl extends ScriptFunctionImpl {
|
||||||
private final ScriptFunction targetFunction;
|
private final ScriptFunction targetFunction;
|
||||||
|
|
||||||
BoundScriptFunctionImpl(ScriptFunctionData data, ScriptFunction targetFunction) {
|
BoundScriptFunctionImpl(final ScriptFunctionData data, final ScriptFunction targetFunction) {
|
||||||
super(data, Global.instance());
|
super(data, Global.instance());
|
||||||
setPrototype(ScriptRuntime.UNDEFINED);
|
setPrototype(ScriptRuntime.UNDEFINED);
|
||||||
this.targetFunction = targetFunction;
|
this.targetFunction = targetFunction;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user