List of usage examples for org.objectweb.asm Opcodes NEW
int NEW
To view the source code for org.objectweb.asm Opcodes NEW.
Click Source Link
From source file:org.spongepowered.asm.mixin.injection.callback.CallbackInjector.java
License:MIT License
/** * Generates a method which throws an error * //from w ww . ja va 2s . c o m * @param callback callback handle * @param errorClass error class to throw * @param message message for the error * @return generated method */ private MethodNode generateErrorMethod(Callback callback, String errorClass, String message) { MethodNode method = this.info.addMethod(this.methodNode.access, this.methodNode.name + "$missing", callback.getDescriptor()); method.maxLocals = ASMHelper.getFirstNonArgLocalIndex(Type.getArgumentTypes(callback.getDescriptor()), !this.isStatic); method.maxStack = 3; InsnList insns = method.instructions; insns.add(new TypeInsnNode(Opcodes.NEW, errorClass)); insns.add(new InsnNode(Opcodes.DUP)); insns.add(new LdcInsnNode(message)); insns.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, errorClass, "<init>", "(Ljava/lang/String;)V", false)); insns.add(new InsnNode(Opcodes.ATHROW)); return method; }
From source file:org.spongepowered.asm.mixin.injection.callback.CallbackInjector.java
License:MIT License
/** * @param callback callback handle/* w w w. j a v a 2 s .co m*/ */ private void createCallbackInfo(final Callback callback) { this.dupReturnValue(callback); callback.add(new TypeInsnNode(Opcodes.NEW, callback.target.callbackInfoClass), true, false); callback.add(new InsnNode(Opcodes.DUP), true, true); this.invokeCallbackInfoCtor(callback); callback.add(new VarInsnNode(Opcodes.ASTORE, callback.marshallVar)); }
From source file:org.spongepowered.asm.mixin.injection.points.BeforeNew.java
License:MIT License
@Override public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) { boolean found = false; int ordinal = 0; ListIterator<AbstractInsnNode> iter = insns.iterator(); while (iter.hasNext()) { AbstractInsnNode insn = iter.next(); if (insn instanceof TypeInsnNode && insn.getOpcode() == Opcodes.NEW && this.matchesOwner((TypeInsnNode) insn)) { if (this.ordinal == -1 || this.ordinal == ordinal) { nodes.add(insn);/*from www. j av a 2 s . c o m*/ found = true; } ordinal++; } } return found; }
From source file:org.springsource.loaded.test.infra.MethodPrinter.java
License:Apache License
public void visitTypeInsn(int opcode, String type) { if (opcode == Opcodes.NEW) { // 187 to.println(" NEW " + type); } else if (opcode == Opcodes.ANEWARRAY) { // 189 to.println(" ANEWARRAY " + type); } else if (opcode == Opcodes.CHECKCAST) { // 192 to.println(" CHECKCAST " + type); } else if (opcode == Opcodes.INSTANCEOF) { // 193 to.println(" INSTANCEOF " + type); } else {/* www.ja va 2s . co m*/ throw new IllegalStateException(":" + opcode); } }
From source file:org.springsource.loaded.TypeDiffComputer.java
License:Apache License
/** * Determine if there any differences between the methods supplied. A MethodDelta object is built to record any differences and * stored against the type delta./* w ww. j av a2 s .com*/ * * @param oMethod 'old' method * @param nMethod 'new' method * @param td the type delta where changes are currently being accumulated */ private static void computeAnyMethodDifferences(MethodNode oMethod, MethodNode nMethod, TypeDelta td) { MethodDelta md = new MethodDelta(oMethod.name, oMethod.desc); if (oMethod.access != nMethod.access) { md.setAccessChanged(oMethod.access, nMethod.access); } // TODO annotations InsnList oInstructions = oMethod.instructions; InsnList nInstructions = nMethod.instructions; if (oInstructions.size() != nInstructions.size()) { md.setInstructionsChanged(oInstructions.toArray(), nInstructions.toArray()); } else { // TODO Just interested in constructors right now - should add others if (oMethod.name.charAt(0) == '<') { String oInvokeSpecialDescriptor = null; String nInvokeSpecialDescriptor = null; int oUninitCount = 0; int nUninitCount = 0; boolean codeChange = false; for (int i = 0, max = oInstructions.size(); i < max; i++) { AbstractInsnNode oInstruction = oInstructions.get(i); AbstractInsnNode nInstruction = nInstructions.get(i); if (!codeChange) { if (!sameInstruction(oInstruction, nInstruction)) { codeChange = true; } } if (oInstruction.getType() == AbstractInsnNode.TYPE_INSN) { if (oInstruction.getOpcode() == Opcodes.NEW) { oUninitCount++; } } if (nInstruction.getType() == AbstractInsnNode.TYPE_INSN) { if (nInstruction.getOpcode() == Opcodes.NEW) { nUninitCount++; } } if (oInstruction.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode mi = (MethodInsnNode) oInstruction; if (mi.getOpcode() == INVOKESPECIAL && mi.name.equals("<init>")) { if (oUninitCount == 0) { // this is the one! oInvokeSpecialDescriptor = mi.desc; } else { oUninitCount--; } } } if (nInstruction.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode mi = (MethodInsnNode) nInstruction; if (mi.getOpcode() == INVOKESPECIAL && mi.name.equals("<init>")) { if (nUninitCount == 0) { // this is the one! nInvokeSpecialDescriptor = mi.desc; } else { nUninitCount--; } } } } // Has the invokespecial changed? if (oInvokeSpecialDescriptor == null) { if (nInvokeSpecialDescriptor != null) { md.setInvokespecialChanged(oInvokeSpecialDescriptor, nInvokeSpecialDescriptor); } } else { if (!oInvokeSpecialDescriptor.equals(nInvokeSpecialDescriptor)) { md.setInvokespecialChanged(oInvokeSpecialDescriptor, nInvokeSpecialDescriptor); } } if (codeChange) { md.setCodeChanged(oInstructions.toArray(), nInstructions.toArray()); } } } if (md.hasAnyChanges()) { // it needs recording td.addChangedMethod(md); } }
From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java
License:Apache License
private void buildForkMethod(ClassVisitor cv, String className) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "fork", "()" + Type.getDescriptor(Matcher.class), null, null);// w w w .j a v a2 s . c om mv.visitCode(); mv.visitTypeInsn(Opcodes.NEW, className); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, "<init>", "()V", false); mv.visitInsn(Opcodes.DUP); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, className, "domain", "I"); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "domain", "I"); mv.visitInsn(Opcodes.DUP); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, className, "state", "I"); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "state", "I"); mv.visitInsn(Opcodes.DUP); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitFieldInsn(Opcodes.GETFIELD, className, "index", "I"); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "index", "I"); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(2, 1); mv.visitEnd(); }
From source file:org.zoeey.ztpl.compiler.ByteCodeHelper.java
License:LGPL
/** * template//from www .j ava 2 s . c o m */ public void callClass(String className) { className = ZtplConstant.CLASS_URI + className; mv.visitTypeInsn(Opcodes.NEW, className); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, className, "<init>", "()V"); // mv.visitVarInsn(Opcodes.ALOAD, VAR_INDEX_WRITER); mv.visitVarInsn(Opcodes.ALOAD, VAR_INDEX_PARAMSMAP); mv.visitVarInsn(Opcodes.ALOAD, VAR_INDEX_ZTPL); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, ZtplConstant.TEMPLATE_INTERFACE// , "publish", "(Ljava/io/Writer;Ljava/util/Map;Lorg/zoeey/ztpl/Ztpl;)V"); }
From source file:org.zoeey.ztpl.compiler.ByteCodeHelper.java
License:LGPL
/** * /* w w w . jav a 2 s . c om*/ * @param className ?? * @param paramsPos ? * @param pos */ public void callFunction(String className, int paramsPos) { String classPath = className.replace('.', '/'); /** * ? */ mv.visitTypeInsn(Opcodes.NEW, classPath); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, classPath, "<init>", "()V"); // invoke call() mv.visitVarInsn(Opcodes.ALOAD, paramsPos); mv.visitVarInsn(Opcodes.ALOAD, VAR_INDEX_ZTPL); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, FunctionAble.class.getName().replace('.', '/'), "call", // "(Lorg/zoeey/ztpl/ParamsMap;Lorg/zoeey/ztpl/Ztpl;)Ljava/lang/String;"); }
From source file:org.zoeey.ztpl.compiler.ByteCodeHelper.java
License:LGPL
/** * ?<br />/*from www . j ava 2 s . c o m*/ * ? var paramsMap_* = new ParamsMap();<br /> * ex. {echo varA="a" varB="b"} <br /> * ?? map{"varA":"a","varB":"b"} * */ public int newMap() { int pos = tracker.next(); mv.visitTypeInsn(Opcodes.NEW, "org/zoeey/ztpl/ParamsMap"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "org/zoeey/ztpl/ParamsMap", "<init>", "()V"); mv.visitVarInsn(Opcodes.ASTORE, pos); return pos; }
From source file:pl.clareo.coroutines.core.ClassTransformer.java
License:Apache License
@SuppressWarnings("unchecked") private static InsnList createDebugFrame(MethodNode coroutine) { InsnList insn = new InsnList(); int nLocals = coroutine.maxLocals; String[] names = new String[nLocals]; List<LocalVariableNode> locals = coroutine.localVariables; fillVariableNames(names, locals);/*w ww.java2 s. c o m*/ insn.add(new TypeInsnNode(Opcodes.NEW, FRAME_NAME)); insn.add(new InsnNode(Opcodes.DUP)); insn.add(makeInt(nLocals)); insn.add(makeInt(nLocals)); insn.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/String")); for (LocalVariableNode local : locals) { int i = local.index; String name = names[i]; insn.add(new InsnNode(Opcodes.DUP)); insn.add(makeInt(i)); if (name != null) { insn.add(new LdcInsnNode(name)); } else { insn.add(new InsnNode(Opcodes.ACONST_NULL)); } insn.add(new InsnNode(Opcodes.AASTORE)); } insn.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, FRAME_NAME, "<init>", "(I[Ljava/lang/String;)V")); return insn; }