本文整理汇总了Java中jdk.internal.org.objectweb.asm.commons.InstructionAdapter.iconst方法的典型用法代码示例。如果您正苦于以下问题:Java InstructionAdapter.iconst方法的具体用法?Java InstructionAdapter.iconst怎么用?Java InstructionAdapter.iconst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.internal.org.objectweb.asm.commons.InstructionAdapter
的用法示例。
在下文中一共展示了InstructionAdapter.iconst方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateOverridingConstructor
import jdk.internal.org.objectweb.asm.commons.InstructionAdapter; //导入方法依赖的package包/类
/**
* Generates a constructor for the instance adapter class. This constructor will take the same arguments as the supertype
* constructor passed as the argument here, and delegate to it. However, it will take an additional argument of
* either ScriptObject or ScriptFunction type (based on the value of the "fromFunction" parameter), and initialize
* all the method handle fields of the adapter instance with functions from the script object (or the script
* function itself, if that's what's passed). Additionally, it will create another constructor with an additional
* Object type parameter that can be used for ScriptObjectMirror objects.
* The constructor will also store the Nashorn global that was current at the constructor
* invocation time in a field named "global". The generated constructor will be public, regardless of whether the
* supertype constructor was public or protected. The generated constructor will not be variable arity, even if the
* supertype constructor was.
* @param ctor the supertype constructor that is serving as the base for the generated constructor.
* @param fromFunction true if we're generating a constructor that initializes SAM types from a single
* ScriptFunction passed to it, false if we're generating a constructor that initializes an arbitrary type from a
* ScriptObject passed to it.
*/
private void generateOverridingConstructor(final Constructor<?> ctor, final boolean fromFunction) {
final Type originalCtorType = Type.getType(ctor);
final Type[] originalArgTypes = originalCtorType.getArgumentTypes();
final int argLen = originalArgTypes.length;
final Type[] newArgTypes = new Type[argLen + 1];
// Insert ScriptFunction|ScriptObject as the last argument to the constructor
final Type extraArgumentType = fromFunction ? SCRIPT_FUNCTION_TYPE : SCRIPT_OBJECT_TYPE;
newArgTypes[argLen] = extraArgumentType;
System.arraycopy(originalArgTypes, 0, newArgTypes, 0, argLen);
// All constructors must be public, even if in the superclass they were protected.
// Existing super constructor <init>(this, args...) triggers generating <init>(this, args..., delegate).
// Any variable arity constructors become fixed-arity with explicit array arguments.
final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
mv.visitCode();
// First, invoke super constructor with original arguments.
final int extraArgOffset = emitSuperConstructorCall(mv, originalCtorType.getDescriptor());
// Assign "this.global = Context.getGlobal()"
mv.visitVarInsn(ALOAD, 0);
GET_NON_NULL_GLOBAL.invoke(mv);
mv.putfield(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
// Assign "this.delegate = delegate"
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, extraArgOffset);
mv.putfield(generatedClassName, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
if (fromFunction) {
// Assign "isFunction = true"
mv.visitVarInsn(ALOAD, 0);
mv.iconst(1);
mv.putfield(generatedClassName, IS_FUNCTION_FIELD_NAME, BOOLEAN_TYPE_DESCRIPTOR);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, extraArgOffset);
emitInitCallThis(mv);
}
endInitMethod(mv);
if (! fromFunction) {
newArgTypes[argLen] = OBJECT_TYPE;
final InstructionAdapter mv2 = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
generateOverridingConstructorWithObjectParam(mv2, originalCtorType.getDescriptor());
}
}
示例2: generateOverridingConstructorWithObjectParam
import jdk.internal.org.objectweb.asm.commons.InstructionAdapter; //导入方法依赖的package包/类
private void generateOverridingConstructorWithObjectParam(final InstructionAdapter mv, final String ctorDescriptor) {
mv.visitCode();
final int extraArgOffset = emitSuperConstructorCall(mv, ctorDescriptor);
// Check for ScriptObjectMirror
mv.visitVarInsn(ALOAD, extraArgOffset);
mv.instanceOf(SCRIPT_OBJECT_MIRROR_TYPE);
final Label notMirror = new Label();
mv.ifeq(notMirror);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, extraArgOffset);
mv.iconst(0);
UNWRAP_MIRROR.invoke(mv);
mv.putfield(generatedClassName, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, extraArgOffset);
mv.iconst(1);
UNWRAP_MIRROR.invoke(mv);
mv.putfield(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
final Label done = new Label();
if (samName != null) {
mv.visitVarInsn(ALOAD, 0);
mv.getfield(generatedClassName, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
mv.instanceOf(SCRIPT_FUNCTION_TYPE);
mv.ifeq(done);
// Assign "isFunction = true"
mv.visitVarInsn(ALOAD, 0);
mv.iconst(1);
mv.putfield(generatedClassName, IS_FUNCTION_FIELD_NAME, BOOLEAN_TYPE_DESCRIPTOR);
mv.visitVarInsn(ALOAD, 0);
mv.dup();
mv.getfield(generatedClassName, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
mv.checkcast(SCRIPT_FUNCTION_TYPE);
emitInitCallThis(mv);
mv.goTo(done);
}
mv.visitLabel(notMirror);
// Throw error if not a ScriptObject
mv.visitVarInsn(ALOAD, extraArgOffset);
NOT_AN_OBJECT.invoke(mv);
mv.visitLabel(done);
endInitMethod(mv);
}
示例3: generateOverridingConstructor
import jdk.internal.org.objectweb.asm.commons.InstructionAdapter; //导入方法依赖的package包/类
/**
* Generates a constructor for the instance adapter class. This constructor will take the same arguments as the supertype
* constructor passed as the argument here, and delegate to it. However, it will take an additional argument of
* either ScriptObject or ScriptFunction type (based on the value of the "fromFunction" parameter), and initialize
* all the method handle fields of the adapter instance with functions from the script object (or the script
* function itself, if that's what's passed). There is one method handle field in the adapter class for every method
* that can be implemented or overridden; the name of every field is same as the name of the method, with a number
* suffix that makes it unique in case of overloaded methods. The generated constructor will invoke
* {@link #getHandle(ScriptFunction, MethodType, boolean)} or {@link #getHandle(Object, String, MethodType,
* boolean)} to obtain the method handles; these methods make sure to add the necessary conversions and arity
* adjustments so that the resulting method handles can be invoked from generated methods using {@code invokeExact}.
* The constructor that takes a script function will only initialize the methods with the same name as the single
* abstract method. The constructor will also store the Nashorn global that was current at the constructor
* invocation time in a field named "global". The generated constructor will be public, regardless of whether the
* supertype constructor was public or protected. The generated constructor will not be variable arity, even if the
* supertype constructor was.
* @param ctor the supertype constructor that is serving as the base for the generated constructor.
* @param fromFunction true if we're generating a constructor that initializes SAM types from a single
* ScriptFunction passed to it, false if we're generating a constructor that initializes an arbitrary type from a
* ScriptObject passed to it.
*/
private void generateOverridingConstructor(final Constructor<?> ctor, final boolean fromFunction) {
final Type originalCtorType = Type.getType(ctor);
final Type[] originalArgTypes = originalCtorType.getArgumentTypes();
final int argLen = originalArgTypes.length;
final Type[] newArgTypes = new Type[argLen + 1];
// Insert ScriptFunction|ScriptObject as the last argument to the constructor
final Type extraArgumentType = fromFunction ? SCRIPT_FUNCTION_TYPE : SCRIPT_OBJECT_TYPE;
newArgTypes[argLen] = extraArgumentType;
System.arraycopy(originalArgTypes, 0, newArgTypes, 0, argLen);
// All constructors must be public, even if in the superclass they were protected.
// Existing super constructor <init>(this, args...) triggers generating <init>(this, args..., delegate).
// Any variable arity constructors become fixed-arity with explicit array arguments.
final InstructionAdapter mv = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
mv.visitCode();
// First, invoke super constructor with original arguments.
final int extraArgOffset = emitSuperConstructorCall(mv, originalCtorType.getDescriptor());
// Assign "this.global = Context.getGlobal()"
mv.visitVarInsn(ALOAD, 0);
GET_NON_NULL_GLOBAL.invoke(mv);
mv.putfield(generatedClassName, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
// Assign "this.delegate = delegate"
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, extraArgOffset);
mv.putfield(generatedClassName, DELEGATE_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR);
if (fromFunction) {
// Assign "isFunction = true"
mv.visitVarInsn(ALOAD, 0);
mv.iconst(1);
mv.putfield(generatedClassName, IS_FUNCTION_FIELD_NAME, BOOLEAN_TYPE_DESCRIPTOR);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, extraArgOffset);
emitInitCallThis(mv);
}
endInitMethod(mv);
if (! fromFunction) {
newArgTypes[argLen] = OBJECT_TYPE;
final InstructionAdapter mv2 = new InstructionAdapter(cw.visitMethod(ACC_PUBLIC, INIT,
Type.getMethodDescriptor(originalCtorType.getReturnType(), newArgTypes), null, null));
generateOverridingConstructorWithObjectParam(mv2, originalCtorType.getDescriptor());
}
}