本文整理汇总了Java中jdk.nashorn.internal.lookup.MethodHandleFactory类的典型用法代码示例。如果您正苦于以下问题:Java MethodHandleFactory类的具体用法?Java MethodHandleFactory怎么用?Java MethodHandleFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodHandleFactory类属于jdk.nashorn.internal.lookup包,在下文中一共展示了MethodHandleFactory类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constantGetter
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private MethodHandle constantGetter(final Object c) {
final MethodHandle mh = staticConstantGetter(c);
if (log.isEnabled()) {
return MethodHandleFactory.addDebugPrintout(log, Level.FINEST, mh, "getting as constant");
}
return mh;
}
示例2: findOwnMH
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
try {
return MH.findStatic(MethodHandles.lookup(), LinkerCallSite.class, name, MH.type(rtype, types));
} catch (final MethodHandleFactory.LookupException e) {
return MH.findVirtual(MethodHandles.lookup(), LinkerCallSite.class, name, MH.type(rtype, types));
}
}
示例3: findMH
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private static MethodHandle findMH(final String name, final Class<?> target, final Class<?> rtype, final Class<?>... types) {
final MethodType mt = MH.type(rtype, types);
try {
return MH.findStatic(MethodHandles.lookup(), target, name, mt);
} catch (final MethodHandleFactory.LookupException e) {
return MH.findVirtual(MethodHandles.lookup(), target, name, mt);
}
}
示例4: debug
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private MethodHandle debug(final MethodHandle mh, final Class<?> forType, final Class<?> type, final String tag) {
if (DEBUG_FIELDS) {
return MethodHandleFactory.addDebugPrintout(
LOG,
mh,
tag + " '" + getKey() + "' (property="+ Debug.id(this) + ", forType=" + stripName(forType) + ", type=" + stripName(type) + ')');
}
return mh;
}
示例5: findOwnMH
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
final Class<?> own = ScriptObject.class;
final MethodType mt = MH.type(rtype, types);
try {
return MH.findStatic(MethodHandles.lookup(), own, name, mt);
} catch (final MethodHandleFactory.LookupException e) {
return MH.findVirtual(MethodHandles.lookup(), own, name, mt);
}
}
示例6: findOwnMH
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
final Class<?> own = ScriptFunction.class;
final MethodType mt = MH.type(rtype, types);
try {
return MH.findStatic(MethodHandles.lookup(), own, name, mt);
} catch (final MethodHandleFactory.LookupException e) {
return MH.findVirtual(MethodHandles.lookup(), own, name, mt);
}
}
示例7: findOwnMH
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
try {
return MH.findStatic(MethodHandles.lookup(), RuntimeCallSite.class, name, MH.type(rtype, types));
} catch (final MethodHandleFactory.LookupException e) {
return MH.findVirtual(MethodHandles.lookup(), RuntimeCallSite.class, name, MH.type(rtype, types));
}
}
示例8: findOwnMH
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) {
final Class<?> own = JSObjectLinker.class;
final MethodType mt = MH.type(rtype, types);
try {
return MH.findStatic(MethodHandles.lookup(), own, name, mt);
} catch (final MethodHandleFactory.LookupException e) {
return MH.findVirtual(MethodHandles.lookup(), own, name, mt);
}
}
示例9: findJSObjectMH
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private static MethodHandle findJSObjectMH(final String name, final Class<?> rtype, final Class<?>... types) {
final Class<?> own = JSObject.class;
final MethodType mt = MH.type(rtype, types);
try {
return MH.findVirtual(MethodHandles.publicLookup(), own, name, mt);
} catch (final MethodHandleFactory.LookupException e) {
return MH.findVirtual(MethodHandles.lookup(), own, name, mt);
}
}
示例10: findGetMethod
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
/**
* Try to turn a getter into a MethodHandle.constant, if possible
*
* @param find property lookup
* @param receiver receiver
* @param desc callsite descriptor
*
* @return resulting getter, or null if failed to create constant
*/
GuardedInvocation findGetMethod(final FindProperty find, final ScriptObject receiver, final CallSiteDescriptor desc) {
// Only use constant getter for fast scope access, because the receiver may change between invocations
// for slow-scope and non-scope callsites.
// Also return null for user accessor properties as they may have side effects.
if (invalidatedForever.get() || !NashornCallSiteDescriptor.isFastScope(desc)
|| (GLOBAL_ONLY && !find.getOwner().isGlobal())
|| find.getProperty() instanceof UserAccessorProperty) {
return null;
}
final boolean isOptimistic = NashornCallSiteDescriptor.isOptimistic(desc);
final int programPoint = isOptimistic ? getProgramPoint(desc) : INVALID_PROGRAM_POINT;
final Class<?> retType = desc.getMethodType().returnType();
final String name = desc.getNameToken(CallSiteDescriptor.NAME_OPERAND);
synchronized (this) {
final Access acc = getOrCreateSwitchPoint(name);
log.fine("Starting to look up object value " + name);
final Object c = find.getObjectValue();
if (log.isEnabled()) {
log.fine("Trying to link constant GETTER " + acc + " value = " + c);
}
if (acc.hasBeenInvalidated() || acc.guardFailed() || invalidatedForever.get()) {
if (log.isEnabled()) {
log.info("*** GET: Giving up on " + quote(name) + " - retry count has exceeded " + DynamicLinker.getLinkedCallSiteLocation());
}
return null;
}
final MethodHandle cmh = constantGetter(c);
MethodHandle mh;
MethodHandle guard;
if (isOptimistic) {
if (JSType.getAccessorTypeIndex(cmh.type().returnType()) <= JSType.getAccessorTypeIndex(retType)) {
//widen return type - this is pessimistic, so it will always work
mh = MH.asType(cmh, cmh.type().changeReturnType(retType));
} else {
//immediately invalidate - we asked for a too wide constant as a narrower one
mh = MH.dropArguments(MH.insertArguments(JSType.THROW_UNWARRANTED.methodHandle(), 0, c, programPoint), 0, Object.class);
}
} else {
//pessimistic return type filter
mh = Lookup.filterReturnType(cmh, retType);
}
if (find.getOwner().isGlobal()) {
guard = null;
} else {
guard = MH.insertArguments(RECEIVER_GUARD, 0, acc, receiver);
}
if (log.isEnabled()) {
log.info("Linked getter " + quote(name) + " as MethodHandle.constant() -> " + c + " " + acc.getSwitchPoint());
mh = MethodHandleFactory.addDebugPrintout(log, Level.FINE, mh, "get const " + acc);
}
return new GuardedInvocation(mh, guard, acc.getSwitchPoint(), null);
}
}
示例11: initLoggers
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
private void initLoggers() {
((Loggable)MethodHandleFactory.getFunctionality()).initLogger(this);
}
示例12: findGetMethod
import jdk.nashorn.internal.lookup.MethodHandleFactory; //导入依赖的package包/类
/**
* Try to turn a getter into a MethodHandle.constant, if possible
*
* @param find property lookup
* @param receiver receiver
* @param desc callsite descriptor
*
* @return resulting getter, or null if failed to create constant
*/
GuardedInvocation findGetMethod(final FindProperty find, final ScriptObject receiver, final CallSiteDescriptor desc) {
// Only use constant getter for fast scope access, because the receiver may change between invocations
// for slow-scope and non-scope callsites.
// Also return null for user accessor properties as they may have side effects.
if (invalidatedForever.get() || !NashornCallSiteDescriptor.isFastScope(desc)
|| (GLOBAL_ONLY && !find.getOwner().isGlobal())
|| find.getProperty() instanceof UserAccessorProperty) {
return null;
}
final boolean isOptimistic = NashornCallSiteDescriptor.isOptimistic(desc);
final int programPoint = isOptimistic ? getProgramPoint(desc) : INVALID_PROGRAM_POINT;
final Class<?> retType = desc.getMethodType().returnType();
final String name = NashornCallSiteDescriptor.getOperand(desc);
synchronized (this) {
final Access acc = getOrCreateSwitchPoint(name);
log.fine("Starting to look up object value " + name);
final Object c = find.getObjectValue();
if (log.isEnabled()) {
log.fine("Trying to link constant GETTER " + acc + " value = " + c);
}
if (acc.hasBeenInvalidated() || acc.guardFailed() || invalidatedForever.get()) {
if (log.isEnabled()) {
log.info("*** GET: Giving up on " + quote(name) + " - retry count has exceeded " + DynamicLinker.getLinkedCallSiteLocation());
}
return null;
}
final MethodHandle cmh = constantGetter(c);
MethodHandle mh;
MethodHandle guard;
if (isOptimistic) {
if (JSType.getAccessorTypeIndex(cmh.type().returnType()) <= JSType.getAccessorTypeIndex(retType)) {
//widen return type - this is pessimistic, so it will always work
mh = MH.asType(cmh, cmh.type().changeReturnType(retType));
} else {
//immediately invalidate - we asked for a too wide constant as a narrower one
mh = MH.dropArguments(MH.insertArguments(JSType.THROW_UNWARRANTED.methodHandle(), 0, c, programPoint), 0, Object.class);
}
} else {
//pessimistic return type filter
mh = Lookup.filterReturnType(cmh, retType);
}
if (find.getOwner().isGlobal()) {
guard = null;
} else {
guard = MH.insertArguments(RECEIVER_GUARD, 0, acc, receiver);
}
if (log.isEnabled()) {
log.info("Linked getter " + quote(name) + " as MethodHandle.constant() -> " + c + " " + acc.getSwitchPoint());
mh = MethodHandleFactory.addDebugPrintout(log, Level.FINE, mh, "get const " + acc);
}
return new GuardedInvocation(mh, guard, acc.getSwitchPoint(), null);
}
}