本文整理匯總了Java中org.objectweb.asm.commons.GeneratorAdapter.dup方法的典型用法代碼示例。如果您正苦於以下問題:Java GeneratorAdapter.dup方法的具體用法?Java GeneratorAdapter.dup怎麽用?Java GeneratorAdapter.dup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.objectweb.asm.commons.GeneratorAdapter
的用法示例。
在下文中一共展示了GeneratorAdapter.dup方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createClassArray
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
private static void createClassArray(GeneratorAdapter mv, List<Type> args) {
// create an array of objects capable of containing all the parameters and optionally the "this"
createLocals(mv, args);
// we need to maintain the stack index when loading parameters from, as for long and double
// values, it uses 2 stack elements, all others use only 1 stack element.
int stackIndex = 0;
for (int arrayIndex = 0; arrayIndex < args.size(); arrayIndex++) {
Type arg = args.get(arrayIndex);
// duplicate the array of objects reference, it will be used to store the value in.
mv.dup();
// index in the array of objects to store the boxed parameter.
mv.push(arrayIndex);
// Pushes the appropriate local variable on the stack
redirectLocal(mv, arg);
// mv.visitLdcInsn(Type.getType(arg.getDescriptor()));
// potentially box up intrinsic types.
// mv.box(arg);
mv.arrayStore(Type.getType(Class.class));
// stack index must progress according to the parameter type we just processed.
// stackIndex += arg.getSize();
}
}
示例2: loadVariableArray
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
* Given an array on the stack, it loads it with the values of the given variables stating at
* offset.
*/
static void loadVariableArray(
GeneratorAdapter mv,
List<LocalVariable> variables, int offset) {
// we need to maintain the stack index when loading parameters from, as for long and double
// values, it uses 2 stack elements, all others use only 1 stack element.
for (int i = offset; i < variables.size(); i++) {
LocalVariable variable = variables.get(i);
// duplicate the array of objects reference, it will be used to store the value in.
mv.dup();
// index in the array of objects to store the boxed parameter.
mv.push(i);
// Pushes the appropriate local variable on the stack
mv.visitVarInsn(variable.type.getOpcode(Opcodes.ILOAD), variable.var);
// potentially box up intrinsic types.
mv.box(variable.type);
// store it in the array
mv.arrayStore(Type.getType(Object.class));
}
}
示例3: writeMissingMessageWithHash
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
void writeMissingMessageWithHash(GeneratorAdapter mv, String visitedClassName) {
mv.newInstance(INSTANT_RELOAD_EXCEPTION_TYPE);
mv.dup();
mv.push("int switch could not find %d in %s");
mv.push(3);
mv.newArray(OBJECT_TYPE);
mv.dup();
mv.push(0);
visitInt();
mv.visitMethodInsn(
Opcodes.INVOKESTATIC,
"java/lang/Integer",
"valueOf",
"(I)Ljava/lang/Integer;", false);
mv.arrayStore(OBJECT_TYPE);
mv.dup();
mv.push(2);
mv.push(visitedClassName);
mv.arrayStore(OBJECT_TYPE);
mv.visitMethodInsn(
Opcodes.INVOKESTATIC,
"java/lang/String",
"format",
"(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", false);
mv.invokeConstructor(INSTANT_RELOAD_EXCEPTION_TYPE,
Method.getMethod("void <init> (String)"));
mv.throwException();
}
示例4: emit
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
//emitting a Fn means constructing an instance, feeding closed-overs from enclosing scope, if any
//objx arg is enclosing objx, not this
// getCompiledClass();
if(isDeftype())
{
gen.visitInsn(Opcodes.ACONST_NULL);
}
else
{
gen.newInstance(objtype);
gen.dup();
if(supportsMeta())
gen.visitInsn(Opcodes.ACONST_NULL);
for(ISeq s = RT.seq(closesExprs); s != null; s = s.next())
{
LocalBindingExpr lbe = (LocalBindingExpr) s.first();
LocalBinding lb = lbe.b;
if(lb.getPrimitiveType() != null)
objx.emitUnboxedLocal(gen, lb);
else
objx.emitLocal(gen, lb, lbe.shouldClear);
}
gen.invokeConstructor(objtype, new Method("<init>", Type.VOID_TYPE, ctorTypes()));
}
if(context == C.STATEMENT)
gen.pop();
}
示例5: createLocals
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Override
protected void createLocals(GeneratorAdapter mv, List<Type> args) {
super.createLocals(mv, args);
// Override the locals creation to keep a reference to it. We keep a reference to this
// array because we use it to receive the values of the local variables after the
// redirection is done.
locals = mv.newLocal(Type.getType("[Ljava/lang/Object;"));
mv.dup();
mv.storeLocal(locals);
}
示例6: writeMissingMessageWithHash
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
/**
* Generates a standard error exception with message similar to:
*
* String switch could not find 'equals.(Ljava/lang/Object;)Z' with hashcode 0
* in com/example/basic/GrandChild
*
* @param mv The generator adaptor used to emit the lookup switch code.
* @param visitedClassName The abstract string trie structure.
*/
void writeMissingMessageWithHash(GeneratorAdapter mv, String visitedClassName) {
mv.newInstance(INSTANT_RELOAD_EXCEPTION_TYPE);
mv.dup();
mv.push("String switch could not find '%s' with hashcode %s in %s");
mv.push(3);
mv.newArray(OBJECT_TYPE);
mv.dup();
mv.push(0);
visitString();
mv.arrayStore(OBJECT_TYPE);
mv.dup();
mv.push(1);
visitString();
visitHashMethod(mv);
mv.visitMethodInsn(
Opcodes.INVOKESTATIC,
"java/lang/Integer",
"valueOf",
"(I)Ljava/lang/Integer;", false);
mv.arrayStore(OBJECT_TYPE);
mv.dup();
mv.push(2);
mv.push(visitedClassName);
mv.arrayStore(OBJECT_TYPE);
mv.visitMethodInsn(
Opcodes.INVOKESTATIC,
"java/lang/String",
"format",
"(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", false);
mv.invokeConstructor(INSTANT_RELOAD_EXCEPTION_TYPE,
Method.getMethod("void <init> (String)"));
mv.throwException();
}
示例7: emitAssign
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void emitAssign(C context, ObjExpr objx, GeneratorAdapter gen,
Expr val){
val.emit(C.EXPRESSION, objx, gen);
gen.visitLineNumber(line, gen.mark());
gen.dup();
HostExpr.emitUnboxArg(objx, gen, field.getType());
gen.putStatic(Type.getType(c), fieldName, Type.getType(field.getType()));
if(context == C.STATEMENT)
gen.pop();
}
示例8: emitArgsAsArray
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
static void emitArgsAsArray(IPersistentVector args, ObjExpr objx, GeneratorAdapter gen){
gen.push(args.count());
gen.newArray(OBJECT_TYPE);
for(int i = 0; i < args.count(); i++)
{
gen.dup();
gen.push(i);
((Expr) args.nth(i)).emit(C.EXPRESSION, objx, gen);
gen.arrayStore(OBJECT_TYPE);
}
}
示例9: emitListAsObjectArray
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
void emitListAsObjectArray(Object value, GeneratorAdapter gen){
gen.push(((List) value).size());
gen.newArray(OBJECT_TYPE);
int i = 0;
for(Iterator it = ((List) value).iterator(); it.hasNext(); i++)
{
gen.dup();
gen.push(i);
emitValue(it.next(), gen);
gen.arrayStore(OBJECT_TYPE);
}
}
示例10: emitKeywordCallsites
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
private void emitKeywordCallsites(GeneratorAdapter clinitgen){
for(int i=0;i<keywordCallsites.count();i++)
{
Keyword k = (Keyword) keywordCallsites.nth(i);
clinitgen.newInstance(KEYWORD_LOOKUPSITE_TYPE);
clinitgen.dup();
emitValue(k,clinitgen);
clinitgen.invokeConstructor(KEYWORD_LOOKUPSITE_TYPE,
Method.getMethod("void <init>(clojure.lang.Keyword)"));
clinitgen.dup();
clinitgen.putStatic(objtype, siteNameStatic(i), KEYWORD_LOOKUPSITE_TYPE);
clinitgen.putStatic(objtype, thunkNameStatic(i), ILOOKUP_THUNK_TYPE);
}
}
示例11: doEmit
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void doEmit(C context, ObjExpr objx, GeneratorAdapter gen, boolean emitUnboxed){
Label nullLabel = gen.newLabel();
Label falseLabel = gen.newLabel();
Label endLabel = gen.newLabel();
gen.visitLineNumber(line, gen.mark());
if(testExpr instanceof StaticMethodExpr && ((StaticMethodExpr)testExpr).canEmitIntrinsicPredicate())
{
((StaticMethodExpr) testExpr).emitIntrinsicPredicate(C.EXPRESSION, objx, gen, falseLabel);
}
else if(maybePrimitiveType(testExpr) == boolean.class)
{
((MaybePrimitiveExpr) testExpr).emitUnboxed(C.EXPRESSION, objx, gen);
gen.ifZCmp(gen.EQ, falseLabel);
}
else
{
testExpr.emit(C.EXPRESSION, objx, gen);
gen.dup();
gen.ifNull(nullLabel);
gen.getStatic(BOOLEAN_OBJECT_TYPE, "FALSE", BOOLEAN_OBJECT_TYPE);
gen.visitJumpInsn(IF_ACMPEQ, falseLabel);
}
if(emitUnboxed)
((MaybePrimitiveExpr)thenExpr).emitUnboxed(context, objx, gen);
else
thenExpr.emit(context, objx, gen);
gen.goTo(endLabel);
gen.mark(nullLabel);
gen.pop();
gen.mark(falseLabel);
if(emitUnboxed)
((MaybePrimitiveExpr)elseExpr).emitUnboxed(context, objx, gen);
else
elseExpr.emit(context, objx, gen);
gen.mark(endLabel);
}
示例12: restore
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Override
protected void restore(GeneratorAdapter mv, List<Type> args) {
// At this point, init$args has been called and the result Object is on the stack.
// The value of that Object is Object[] with exactly n + 1 elements.
// The first element is a string with the qualified name of the constructor to call.
// The remaining elements are the constructtor arguments.
// Create a new local that holds the result of init$args call.
mv.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;");
int constructorArgs = mv.newLocal(Type.getType("[Ljava/lang/Object;"));
mv.storeLocal(constructorArgs);
// Reinstate local values
mv.loadLocal(locals);
int stackIndex = 0;
for (int arrayIndex = 0; arrayIndex < args.size(); arrayIndex++) {
Type arg = args.get(arrayIndex);
// Do not restore "this"
if (arrayIndex > 0) {
// duplicates the array
mv.dup();
// index in the array of objects to restore the boxed parameter.
mv.push(arrayIndex);
// get it from the array
mv.arrayLoad(Type.getType(Object.class));
// unbox the argument
ByteCodeUtils.unbox(mv, arg);
// restore the argument
mv.visitVarInsn(arg.getOpcode(Opcodes.ISTORE), stackIndex);
}
// stack index must progress according to the parameter type we just processed.
stackIndex += arg.getSize();
}
// pops the array
mv.pop();
// Push a null for the marker parameter.
mv.loadLocal(constructorArgs);
mv.visitInsn(Opcodes.ACONST_NULL);
// Invoke the constructor
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, thisClassName, "<init>", DISPATCHING_THIS_SIGNATURE, false);
mv.goTo(end.getLabel());
}
示例13: transform
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
@Override
@Unsafe(Unsafe.ASM_API)
public byte[] transform(String name, String transformedName, byte[] basicClass) {
String srgName = this.srgName;
if (!AlchemyEngine.isRuntimeDeobfuscationEnabled())
srgName = DeobfuscatingRemapper.instance().mapMethodName(transformedName, this.srgName, desc);
AlchemyTransformerManager.transform("<proxy>" + name + "|" + transformedName + "#" + proxyMethod.name + proxyMethod.signature
+ "\n-> " + target + "#" + srgName + desc);
ClassReader reader = new ClassReader(basicClass);
ClassWriter writer = ASMHelper.newClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
ClassNode node = new ClassNode(ASM5);
reader.accept(node, 0);
MethodNode oldMethod = null, newMethod = new MethodNode(proxyMethod.access, proxyMethod.name, proxyMethod.desc, proxyMethod.signature,
proxyMethod.exceptions.toArray(new String[proxyMethod.exceptions.size()]));
for (MethodNode method : node.methods)
if (method.name.equals(proxyMethod.name) && method.desc.equals(proxyMethod.desc)) {
oldMethod = method;
GeneratorAdapter adapter = new GeneratorAdapter(newMethod, method.access, method.name, method.desc);
Type owner = Type.getType(ASMHelper.getClassDesc(target));
Method targetMethod = new Method(srgName, desc);
switch (opcode) {
case INVOKESTATIC:
adapter.loadArgs();
adapter.invokeStatic(owner, targetMethod);
break;
case INVOKEVIRTUAL:
adapter.loadArgs();
adapter.invokeVirtual(owner, targetMethod);
break;
case INVOKESPECIAL:
adapter.invokeStatic(Type.getType(AlchemyEngine.class), new Method("lookup",
"()Ljava/lang/invoke/MethodHandles$Lookup;"));
adapter.push(srgName);
Type args[] = Type.getArgumentTypes(desc);
adapter.visitFieldInsn(GETSTATIC, "java/lang/Void", "TYPE", "Ljava/lang/Class;");
adapter.push(args.length);
adapter.newArray(Type.getType(Class.class));
for (Type arg : args) {
adapter.dup();
adapter.push(arg);
adapter.arrayStore(Type.getType(Class.class));
}
adapter.invokeStatic(Type.getType(MethodType.class), new Method("methodType",
"(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/invoke/MethodType;"));
adapter.push(owner);
adapter.dupX2();
adapter.invokeVirtual(Type.getType(MethodHandles.Lookup.class), new Method("findSpecial",
"(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/Class;)Ljava/lang/invoke/MethodHandle;"));
adapter.loadArgs();
adapter.invokeVirtual(Type.getType(MethodHandle.class), new Method("invoke", proxyMethod.desc));
break;
case INVOKEINTERFACE:
adapter.loadArgs();
adapter.invokeInterface(owner, targetMethod);
break;
default:
AlchemyRuntimeException.onException(new RuntimeException("Unsupported opcode: " + opcode));
}
adapter.returnValue();
adapter.endMethod();
break;
}
node.methods.remove(oldMethod);
node.methods.add(newMethod);
node.accept(writer);
return writer.toByteArray();
}
示例14: emitProto
import org.objectweb.asm.commons.GeneratorAdapter; //導入方法依賴的package包/類
public void emitProto(C context, ObjExpr objx, GeneratorAdapter gen){
Label onLabel = gen.newLabel();
Label callLabel = gen.newLabel();
Label endLabel = gen.newLabel();
Var v = ((VarExpr)fexpr).var;
Expr e = (Expr) args.nth(0);
e.emit(C.EXPRESSION, objx, gen);
gen.dup(); //target, target
gen.invokeStatic(UTIL_TYPE,Method.getMethod("Class classOf(Object)")); //target,class
gen.getStatic(objx.objtype, objx.cachedClassName(siteIndex),CLASS_TYPE); //target,class,cached-class
gen.visitJumpInsn(IF_ACMPEQ, callLabel); //target
if(protocolOn != null)
{
gen.dup(); //target, target
gen.instanceOf(Type.getType(protocolOn));
gen.ifZCmp(GeneratorAdapter.NE, onLabel);
}
gen.dup(); //target, target
gen.invokeStatic(UTIL_TYPE,Method.getMethod("Class classOf(Object)")); //target,class
gen.putStatic(objx.objtype, objx.cachedClassName(siteIndex),CLASS_TYPE); //target
gen.mark(callLabel); //target
objx.emitVar(gen, v);
gen.invokeVirtual(VAR_TYPE, Method.getMethod("Object getRawRoot()")); //target, proto-fn
gen.swap();
emitArgsAndCall(1, context,objx,gen);
gen.goTo(endLabel);
gen.mark(onLabel); //target
if(protocolOn != null)
{
MethodExpr.emitTypedArgs(objx, gen, onMethod.getParameterTypes(), RT.subvec(args,1,args.count()));
if(context == C.RETURN)
{
ObjMethod method = (ObjMethod) METHOD.deref();
method.emitClearLocals(gen);
}
Method m = new Method(onMethod.getName(), Type.getReturnType(onMethod), Type.getArgumentTypes(onMethod));
gen.invokeInterface(Type.getType(protocolOn), m);
HostExpr.emitBoxReturn(objx, gen, onMethod.getReturnType());
}
gen.mark(endLabel);
}