本文整理汇总了Java中jdk.nashorn.internal.lookup.Lookup类的典型用法代码示例。如果您正苦于以下问题:Java Lookup类的具体用法?Java Lookup怎么用?Java Lookup使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Lookup类属于jdk.nashorn.internal.lookup包,在下文中一共展示了Lookup类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContinuousElementGetter
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
/**
* Return element getter for a {@link ContinuousArrayData}
* @param clazz clazz for exact type guard
* @param getHas has getter
* @param returnType return type
* @param programPoint program point
* @return method handle for element setter
*/
protected MethodHandle getContinuousElementGetter(final Class<? extends ContinuousArrayData> clazz, final MethodHandle getHas, final Class<?> returnType, final int programPoint) {
final boolean isOptimistic = isValid(programPoint);
final int fti = getAccessorTypeIndex(getHas.type().returnType());
final int ti = getAccessorTypeIndex(returnType);
MethodHandle mh = getHas;
if (isOptimistic) {
if (ti < fti) {
mh = MH.insertArguments(ArrayData.THROW_UNWARRANTED.methodHandle(), 1, programPoint);
}
}
mh = MH.asType(mh, mh.type().changeReturnType(returnType).changeParameterType(0, clazz));
if (!isOptimistic) {
//for example a & array[17];
return Lookup.filterReturnType(mh, returnType);
}
return mh;
}
示例2: initGetterSetter
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
private void initGetterSetter(final Class<?> structure) {
final int slot = getSlot();
/*
* primitiveGetter and primitiveSetter are only used in dual fields mode. Setting them to null also
* works in dual field mode, it only means that the property never has a primitive
* representation.
*/
if (isParameter() && hasArguments()) {
//parameters are always stored in an object array, which may or may not be a good idea
final MethodHandle arguments = MH.getter(LOOKUP, structure, "arguments", ScriptObject.class);
objectGetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.GET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.GET_OBJECT_TYPE);
objectSetter = MH.asType(MH.insertArguments(MH.filterArguments(ScriptObject.SET_ARGUMENT.methodHandle(), 0, arguments), 1, slot), Lookup.SET_OBJECT_TYPE);
primitiveGetter = null;
primitiveSetter = null;
} else {
final Accessors gs = GETTERS_SETTERS.get(structure);
objectGetter = gs.objectGetters[slot];
primitiveGetter = gs.primitiveGetters[slot];
objectSetter = gs.objectSetters[slot];
primitiveSetter = gs.primitiveSetters[slot];
}
}
示例3: getElementGetter
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
@Override
public MethodHandle getElementGetter(final Class<?> returnType, final int programPoint) {
final MethodHandle getter = getContinuousElementGetter(getClass(), getGetElem(), returnType, programPoint);
if (getter != null) {
return Lookup.filterReturnType(getter, returnType);
}
return getter;
}
示例4: createEmptyGetter
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
private GuardedInvocation createEmptyGetter(final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final String name) {
if (NashornCallSiteDescriptor.isOptimistic(desc)) {
throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
}
return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()),
NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck), getProtoSwitchPoint(name, null),
explicitInstanceOfCheck ? null : ClassCastException.class);
}
示例5: createEmptyGetter
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
private GuardedInvocation createEmptyGetter(final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final String name) {
if (NashornCallSiteDescriptor.isOptimistic(desc)) {
throw new UnwarrantedOptimismException(UNDEFINED, NashornCallSiteDescriptor.getProgramPoint(desc), Type.OBJECT);
}
return new GuardedInvocation(Lookup.emptyGetter(desc.getMethodType().returnType()),
NashornGuards.getMapGuard(getMap(), explicitInstanceOfCheck), getProtoSwitchPoints(name, null),
explicitInstanceOfCheck ? null : ClassCastException.class);
}
示例6: getCalcHandle2
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
public static MethodHandle getCalcHandle2(Global global, Context context) {
EvalLoop.global = global;
EvalLoop.context = context;
return Lookup.MH.findStatic(
MethodHandles.lookup(),
EvalLoop.class, "calc",
Lookup.MH.type(Object.class, new Class[]{Object.class, String.class, Object.class}
));
}
示例7: GettersSetters
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
public GettersSetters(Class<?> structure) {
final int fieldCount = ObjectClassGenerator.getFieldCount(structure);
getters = new MethodHandle[fieldCount];
setters = new MethodHandle[fieldCount];
for(int i = 0; i < fieldCount; ++i) {
final String fieldName = ObjectClassGenerator.getFieldName(i, Type.OBJECT);
getters[i] = MH.asType(MH.getter(lookup, structure, fieldName, Type.OBJECT.getTypeClass()), Lookup.GET_OBJECT_TYPE);
setters[i] = MH.asType(MH.setter(lookup, structure, fieldName, Type.OBJECT.getTypeClass()), Lookup.SET_OBJECT_TYPE);
}
}
示例8: createNewFieldSetter
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
private SetMethod createNewFieldSetter() {
final PropertyMap oldMap = getMap();
final Property property = new AccessorProperty(getName(), 0, sobj.getClass(), oldMap.getFieldCount());
final PropertyMap newMap = oldMap.addProperty(property);
MethodHandle setter = MH.insertArguments(ScriptObject.SETFIELD, 0, desc, oldMap, newMap, property.getSetter(Object.class, newMap));
return new SetMethod(MH.asType(setter, Lookup.SET_OBJECT_TYPE), property);
}
示例9: getTypeErrorThrower
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
static synchronized ScriptFunction getTypeErrorThrower() {
if (typeErrorThrower == null) {
// use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3
final ScriptFunctionImpl func = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, false, false, false);
func.setPrototype(UNDEFINED);
// Non-constructor built-in functions do not have "prototype" property
func.deleteOwnProperty(func.getMap().findProperty("prototype"));
func.preventExtensions();
typeErrorThrower = func;
}
return typeErrorThrower;
}
示例10: getElementSetter
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
@Override
public MethodHandle getElementSetter(final Class<?> elementType) {
return getContinuousElementSetter(getClass(), Lookup.filterArgumentType(getSetElem(), 2, elementType), elementType);
}
示例11: getContinuousElementSetter
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
@Override
protected MethodHandle getContinuousElementSetter(final Class<? extends ContinuousArrayData> clazz, final MethodHandle setHas, final Class<?> elementType) {
final MethodHandle mh = Lookup.filterArgumentType(setHas, 2, elementType);
return MH.asType(mh, mh.type().changeParameterType(0, clazz));
}
示例12: findGetMethod
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的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);
}
}
示例13: getGetter
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的package包/类
@Override
public MethodHandle getGetter(final Class<?> type) {
//this returns a getter on the format (Accessors, Object receiver)
return Lookup.filterReturnType(INVOKE_OBJECT_GETTER, type);
}
示例14: findGetMethod
import jdk.nashorn.internal.lookup.Lookup; //导入依赖的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);
}
}