List of usage examples for org.objectweb.asm Opcodes F_SAME
int F_SAME
To view the source code for org.objectweb.asm Opcodes F_SAME.
Click Source Link
From source file:com.microsoft.applicationinsights.agent.internal.agent.sql.PreparedStatementSetMethod.java
License:Open Source License
@Override protected void onMethodEnter() { if (!"setInt".equals(methodName)) { return;/*from ww w . j a v a 2s .c o m*/ } if (!"setShort".equals(methodName)) { return; } if (!"setBoolean".equals(methodName)) { return; } localIndex = this.newLocal(Type.INT_TYPE); tmpArrayIndex = this.newLocal(Type.getType(Object.class)); System.out.println("index: " + methodName + " " + localIndex + " " + tmpArrayIndex); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;"); Label l0 = new Label(); mv.visitJumpInsn(IFNONNULL, l0); mv.visitVarInsn(ILOAD, 1); mv.visitInsn(ICONST_1); mv.visitInsn(IADD); mv.visitVarInsn(ISTORE, localIndex); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 3); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitFieldInsn(PUTFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;"); Label l1 = new Label(); mv.visitJumpInsn(GOTO, l1); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;"); mv.visitInsn(ARRAYLENGTH); mv.visitVarInsn(ISTORE, localIndex); mv.visitVarInsn(ILOAD, localIndex); mv.visitVarInsn(ILOAD, 1); mv.visitJumpInsn(IF_ICMPGE, l1); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;"); mv.visitVarInsn(ASTORE, tmpArrayIndex); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ILOAD, 1); mv.visitTypeInsn(ANEWARRAY, "java/lang/Object"); mv.visitFieldInsn(PUTFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;"); mv.visitVarInsn(ALOAD, tmpArrayIndex); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;"); mv.visitInsn(ICONST_0); mv.visitVarInsn(ALOAD, tmpArrayIndex); mv.visitInsn(ARRAYLENGTH); mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "arraycopy", "(Ljava/lang/Object;ILjava/lang/Object;II)V", false); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, owner, SqlConstants.AI_SDK_ARGS_ARRAY, "[Ljava/lang/Object;"); mv.visitVarInsn(ILOAD, 1); addArgument(); mv.visitInsn(AASTORE); }
From source file:com.mogujie.instantrun.IncrementalChangeVisitor.java
License:Apache License
public void addSupportMethod() { int access = Opcodes.ACC_PUBLIC; Method m = new Method("isSupport", "(I)Z"); MethodVisitor mv = super.visitMethod(access, m.getName(), m.getDescriptor(), null, null); mv.visitCode();/*www . j a v a2 s.c om*/ mv.visitVarInsn(Opcodes.ALOAD, 1); // mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false); int[] hashArray = new int[fixMtds.size()]; Label[] labelArray = new Label[fixMtds.size()]; Label l0 = new Label(); Label l1 = new Label(); for (int i = 0; i < fixMtds.size(); i++) { hashArray[i] = AcesoProguardMap.instance().getClassData(visitedClassName).getMtdIndex(fixMtds.get(i)); labelArray[i] = l0; } mv.visitLookupSwitchInsn(l1, hashArray, labelArray); mv.visitLabel(l0); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ICONST_1); mv.visitInsn(Opcodes.IRETURN); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(1, 2); mv.visitEnd(); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:com.peergreen.jartransformer.adapter.expiration.ExpirationDateMethodAdapter.java
License:Apache License
/** * Adds instruction just after the start of the method code. *//* w w w .ja v a 2 s . c o m*/ @Override public void visitCode() { // Adds the following code // static { // if (System.currentTimeMillis() < "NOW" || System.currentTimeMillis() > 1364376812157L) { // throw new IllegalStateException("This Peergreen Server has expired. Please download a new version on http://www.peergreen.com"); // } // } mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J"); mv.visitLdcInsn(System.currentTimeMillis()); mv.visitInsn(LCMP); Label l1 = new Label(); mv.visitJumpInsn(IFLT, l1); mv.visitMethodInsn(INVOKESTATIC, "java/lang/System", "currentTimeMillis", "()J"); mv.visitLdcInsn(Long.valueOf(expirationDate)); mv.visitInsn(LCMP); Label l2 = new Label(); mv.visitJumpInsn(IFLE, l2); mv.visitLabel(l1); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitTypeInsn(NEW, "java/lang/IllegalStateException"); mv.visitInsn(DUP); mv.visitLdcInsn( "The Peergreen Server has expired. Please download a new version on http://www.peergreen.com"); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V"); mv.visitInsn(ATHROW); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); super.visitCode(); }
From source file:com.sun.fortress.compiler.asmbytecodeoptimizer.VisitFrame.java
License:Open Source License
public String toString() { String result = "VisitFrame: type = "; switch (type) { case Opcodes.F_NEW: result = result + " F_NEW "; break;/*from ww w . j a va 2 s. c o m*/ case Opcodes.F_FULL: result = result + " F_FULL "; break; case Opcodes.F_APPEND: result = result + " F_APPEND "; break; case Opcodes.F_CHOP: result = result + " F_CHOP "; break; case Opcodes.F_SAME: result = result + " F_SAME "; break; case Opcodes.F_SAME1: result = result + " F_SAME1 "; break; default: throw new RuntimeException("Unknown Frame Type " + type); } result = result + "locals = ["; for (int i = 0; i < nLocal; i++) result = result + local[i] + " "; result = result + "] Stack = ["; for (int i = 0; i < nStack; i++) result = result + stack[i] + " "; result = result + "]"; return result; }
From source file:com.sun.fortress.compiler.codegen.CodeGen.java
License:Open Source License
private void RttiClassAndInterface(TraitObjectDecl tod, ClassNameBundle cnb, Naming.XlationData xldata) { TraitTypeHeader header = tod.getHeader(); IdOrOpOrAnonymousName name = header.getName(); List<StaticParam> sparams = header.getStaticParams(); HashMap<Id, TraitIndex> transitive_extends = STypesUtil.allSupertraits(tod, typeAnalyzer); HashMap<String, Tuple2<TraitIndex, List<StaticArg>>> transitive_extends_opr_tagged = oprTagSupertraitsAndArgs( STypesUtil.allSupertraitsAndStaticArgs(tod, typeAnalyzer)); HashMap<String, Tuple2<TraitIndex, List<StaticArg>>> direct_extends_opr_tagged = oprTagSupertraitsAndArgs( STypesUtil.immediateSupertraitsAndStaticArgs(tod, typeAnalyzer)); HashMap<Id, TraitIndex> direct_extends = STypesUtil.immediateSupertraits(tod, typeAnalyzer); HashMap<Id, List<StaticArg>> direct_extends_args = STypesUtil.immediateSupertraitsStaticArgs(tod, typeAnalyzer);//from w ww . j a va2s . c om int d_e_size = direct_extends.size(); CodeGenClassWriter prev = cw; cw = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES, prev); /* * x$RTTIi * extends y$RTTIi for each y in extend_s * for each static parameter of x, declares method "asX"#number * x$RTTIc * implements x$RTTIi * fields * for each y in extend_s, one field, initially null, type y$RttiClass * for each z in static parameters, one field, init in constructor * constructor (init method) * parameters for static parameters, if any. * * if no static parameters, then a static field initialized to the * single value of the type. * if static parameters, then a static field initialized to a map of * some sort, plus a factory receiving static parameters, that checks * the map, and allocates the type as necessary. * lazy_init method * for each y in extend_s, field = new y$RTTIc(type parameters). * type parameters need thinking about how we put them together. * If extends A[B[T]], should be new A$RTTIc(new B$RTTIc(T)) * Seems like a factory would be appropriate, to avoid senseless * duplication of type parameters. * methods * for each static parameter #N of each type T in transitive_extends, * there needs to be a method as"T"#N. For all non-self types, the * method will check lazy_init, and then delegate to the first type * in extend_s that has T in its own transitive_extends. For T=self, * return the value of the appropriate static parameter. */ /* * x$RTTIi * extends y$RTTIi for each y in extend_s */ Naming.XlationData original_xldata = xldata; List<String> opr_params = oprsFromKindParamList(xldata.staticParameterKindNamePairs()); xldata = opr_params.size() == 0 ? null : xlationData(Naming.RTTI_GENERIC_TAG); for (String opr_param : opr_params) xldata.addKindAndNameToStaticParams(Naming.XL_OPR, opr_param); String stemClassName = Naming.oprArgAnnotatedRTTI(cnb.stemClassName, opr_params); String rttiInterfaceName = Naming.stemInterfaceToRTTIinterface(stemClassName); String rttiInterfaceFileName = opr_params.size() == 0 ? rttiInterfaceName : Naming.stemInterfaceToRTTIinterface(Naming.fileForOprTaggedGeneric(cnb.stemClassName)); String[] superInterfaces = new String[d_e_size]; Id[] direct_extends_keys = new Id[d_e_size]; // will use in lazyInit { int i = 0; for (Id extendee : direct_extends.keySet()) { List<StaticArg> ti_args = direct_extends_args.get(extendee); String extendeeIlk = oprTaggedGenericStemNameSA(extendee, ti_args); // String extendeeIlk = // NamingCzar.jvmClassForToplevelTypeDecl(extendee,"", // packageAndClassName); direct_extends_keys[i] = extendee; superInterfaces[i++] = Naming.stemInterfaceToRTTIinterface(extendeeIlk); } } cw.visitSource(NodeUtil.getSpan(tod).begin.getFileName(), null); cw.visit(InstantiatingClassloader.JVM_BYTECODE_VERSION, ACC_PUBLIC | ACC_ABSTRACT | ACC_INTERFACE, rttiInterfaceName, null, NamingCzar.internalObject, superInterfaces); /* * for each static parameter of x, declares method "asX"#number */ { int i = Naming.STATIC_PARAMETER_ORIGIN; for (StaticParam sp : sparams) { if (!(sp.getKind() instanceof KindOp)) { String method_name = Naming.staticParameterGetterName(stemClassName, i); mv = cw.visitCGMethod(ACC_ABSTRACT + ACC_PUBLIC, method_name, Naming.STATIC_PARAMETER_GETTER_SIG, null, null); mv.visitMaxs(Naming.ignoredMaxsParameter, Naming.ignoredMaxsParameter); mv.visitEnd(); i++; } } } cw.dumpClass(rttiInterfaceFileName, xldata); cw = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES, prev); /* * x$RTTIc * implements x$RTTIi */ superInterfaces = new String[1]; superInterfaces[0] = rttiInterfaceName; String rttiClassName = Naming.stemClassToRTTIclass(stemClassName); String rttiClassFileName = opr_params.size() == 0 ? rttiClassName : Naming.stemClassToRTTIclass(Naming.fileForOprTaggedGeneric(cnb.stemClassName)); cw.visitSource(NodeUtil.getSpan(tod).begin.getFileName(), null); cw.visit(InstantiatingClassloader.JVM_BYTECODE_VERSION, ACC_PUBLIC, rttiClassName, null, Naming.RTTI_CONTAINER_TYPE, superInterfaces); /* * fields * for each y in extend_s, one field, initially null, type y$RttiClass * for each z in static parameters, one field, init in constructor */ for (Id extendee : direct_extends.keySet()) { // This yutch is repeated below in lazyInit; needs cleanup. List<StaticArg> ti_args = direct_extends_args.get(extendee); String extendeeIlk = oprTaggedGenericStemNameSA(extendee, ti_args); // note fields are volatile because of double-checked locking below cw.visitField(ACC_PRIVATE + ACC_VOLATILE, extendeeIlk, Naming.RTTI_CONTAINER_DESC, null, null); } // Fields and Getters for static parameters int count_non_opr_sparams; { int i = Naming.STATIC_PARAMETER_ORIGIN; for (StaticParam sp : sparams) { if (!(sp.getKind() instanceof KindOp)) { String spn = sp.getName().getText(); String stem_name = stemClassName; InstantiatingClassloader.fieldAndGetterForStaticParameter(cw, stem_name, spn, i); i++; } } count_non_opr_sparams = i - Naming.STATIC_PARAMETER_ORIGIN; } /* * constructor (init method) * parameters for static parameters, if any. */ final int sparams_size = count_non_opr_sparams; { // Variant of this code in InstantiatingClassloader String init_sig = InstantiatingClassloader.jvmSignatureForOnePlusNTypes("java/lang/Class", sparams_size, Naming.RTTI_CONTAINER_TYPE, "V"); mv = cw.visitCGMethod(ACC_PUBLIC, "<init>", init_sig, null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); // this mv.visitVarInsn(ALOAD, 1); // class mv.visitMethodInsn(INVOKESPECIAL, Naming.RTTI_CONTAINER_TYPE, "<init>", "(Ljava/lang/Class;)V"); int pno = 2; // 1 is java class for (StaticParam sp : sparams) { if (!(sp.getKind() instanceof KindOp)) { String spn = sp.getName().getText(); // not yet this; sp.getKind(); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, pno); mv.visitFieldInsn(PUTFIELD, rttiClassName, spn, Naming.RTTI_CONTAINER_DESC); pno++; } } voidEpilogue(); } cw.visitField(ACC_PRIVATE + ACC_VOLATILE, "initFlag", "Ljava/lang/Object;", null, null); /* * static singleton or static map + factory. */ if (sparams_size == 0) { // static, initialized to single instance of self cw.visitField(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, Naming.RTTI_SINGLETON, Naming.RTTI_CONTAINER_DESC, null, null); mv = cw.visitCGMethod(ACC_STATIC, "<clinit>", "()V", null, null); mv.visitCode(); // new mv.visitTypeInsn(NEW, rttiClassName); // init mv.visitInsn(DUP); mv.visitLdcInsn(org.objectweb.asm.Type.getType(cnb.classDesc)); mv.visitMethodInsn(INVOKESPECIAL, rttiClassName, "<init>", "(Ljava/lang/Class;)V"); // store mv.visitFieldInsn(PUTSTATIC, rttiClassName, Naming.RTTI_SINGLETON, Naming.RTTI_CONTAINER_DESC); voidEpilogue(); } else { InstantiatingClassloader.emitDictionaryAndFactoryForGenericRTTIclass(cw, rttiClassName, sparams_size, original_xldata); } /* * lazy_init method * for each y in extend_s, field = new y$RTTIc(type parameters). * type parameters need thinking about how we put them together. * If extends A[B[T]], should be new A$RTTIc(new B$RTTIc(T)) * Seems like a factory would be appropriate, to avoid senseless * duplication of type parameters. */ if (d_e_size > 0) { mv = cw.visitCGMethod(ACC_PUBLIC, "lazyInit", "()V", null, null); mv.visitCode(); Label do_ret = new Label(); Label do_monitor_ret = new Label(); //debugging - catch exceptions thrown inside the monitor Label debugTryStart = new Label(); Label debugTryEnd = new Label(); Label debugHandler = new Label(); mv.visitTryCatchBlock(debugTryStart, debugTryEnd, debugHandler, "java/lang/Throwable"); mv.visitLabel(debugTryStart); //end debugging - more below // Double-checked locking. mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, rttiClassName, "initFlag", "Ljava/lang/Object;"); mv.visitJumpInsn(IFNONNULL, do_ret); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(MONITORENTER); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, rttiClassName, "initFlag", "Ljava/lang/Object;"); mv.visitJumpInsn(IFNONNULL, do_monitor_ret); HashSet<String> spns = new HashSet<String>(); for (StaticParam sp : sparams) { IdOrOp spn = sp.getName(); String s = spn.getText(); spns.add(s); } // Do the initialization. // Push all the type parameters for (Id extendee : direct_extends_keys) { TraitIndex ti = direct_extends.get(extendee); List<StaticArg> ti_args = direct_extends_args.get(extendee); String extendeeIlk = oprTaggedGenericStemNameSA(extendee, ti_args); mv.visitVarInsn(ALOAD, 0); // this ptr for store. // invoke factory method for value to store. generateTypeReference(mv, rttiClassName, extendee, ti_args, spns); mv.visitFieldInsn(PUTFIELD, rttiClassName, extendeeIlk, Naming.RTTI_CONTAINER_DESC); } // Mark as inited. Just store a self-pointer and be done with it. mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(PUTFIELD, rttiClassName, "initFlag", "Ljava/lang/Object;"); //more debugging mv.visitLabel(debugTryEnd); Label debugPassCatch = new Label(); mv.visitJumpInsn(GOTO, debugPassCatch); mv.visitLabel(debugHandler); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitVarInsn(ASTORE, 0); Label debugInternal = new Label(); mv.visitLabel(debugInternal); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESTATIC, "com/sun/fortress/runtimeSystem/InstantiatingClassloader", "eep", "(Ljava/lang/Throwable;)V"); mv.visitLabel(debugPassCatch); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); //end more debugging mv.visitLabel(do_monitor_ret); mv.visitVarInsn(ALOAD, 0); mv.visitInsn(MONITOREXIT); mv.visitLabel(do_ret); voidEpilogue(); } /* * methods * for each static parameter #N of each type T in transitive_extends, * there needs to be a method as"T"#N. For all non-self types, the * method will check lazy_init, and then delegate to the first type * in extend_s that has T in its own transitive_extends. For T=self, * return the value of the appropriate static parameter. */ /* * First map extends to what they transitively extend for delegation * The keys of this map are the members of the extends list; * the values, for each car, are those things that further * transitively extend that extender. Each static-parameter-probing * method for the type (T) whose RTTI is being generated, will either * return a field (static parameter) of T, or will delegate to one * of the types extending T. */ HashMap<String, Map<String, Tuple2<TraitIndex, List<StaticArg>>>> transitive_extends_from_extends = new HashMap<String, Map<String, Tuple2<TraitIndex, List<StaticArg>>>>(); for (Map.Entry<Id, TraitIndex> entry : direct_extends.entrySet()) { Id te_id = entry.getKey(); TraitIndex te_ti = entry.getValue(); HashMap<Id, Tuple2<TraitIndex, List<StaticArg>>> extends_transitive_extends_tmp = STypesUtil .allSupertraitsAndStaticArgs(te_ti.ast(), typeAnalyzer); Tuple2<TraitIndex, List<StaticArg>> te_pair = new Tuple2<TraitIndex, List<StaticArg>>(te_ti, direct_extends_args.get(te_id)); extends_transitive_extends_tmp.put(te_id, te_pair); // put self in set. HashMap<String, Tuple2<TraitIndex, List<StaticArg>>> extends_transitive_extends = oprTagSupertraitsAndArgs( extends_transitive_extends_tmp); String te_id_stem = oprTaggedGenericStemNameSA(te_id, direct_extends_args.get(te_id)); transitive_extends_from_extends.put(te_id_stem, extends_transitive_extends); } // Future opt: sort by transitive_extends, use largest as class ancestor // For each type in extends list, emit forwarding functions (delegates) // remove traits from transitive_extends as they are dealt with. for (Map.Entry<Id, TraitIndex> entry : direct_extends.entrySet()) { if (transitive_extends.size() == 0) break; Id de_id = entry.getKey(); String de_id_stem = oprTaggedGenericStemNameSA(de_id, direct_extends_args.get(de_id)); TraitIndex de_ti = entry.getValue(); // iterate over all traits transitively extended by delegate (de_) Map<String, Tuple2<TraitIndex, List<StaticArg>>> extends_transitive_extends = transitive_extends_from_extends .get(de_id_stem); Set<Map.Entry<String, Tuple2<TraitIndex, List<StaticArg>>>> entryset = extends_transitive_extends .entrySet(); for (Map.Entry<String, Tuple2<TraitIndex, List<StaticArg>>> extends_entry : entryset) { // delegate for extended te_id, if not already done. String te_id = extends_entry.getKey(); if (!transitive_extends_opr_tagged.containsKey(te_id)) continue; // already done. else transitive_extends_opr_tagged.remove(te_id); Tuple2<TraitIndex, List<StaticArg>> te_ti = extends_entry.getValue(); List<StaticParam> te_sp = te_ti._1.staticParameters(); if (te_sp.size() == 0) continue; // no static parameters to delegate for. String te_stem = te_id; // emit delegates here // asX#number int i = Naming.STATIC_PARAMETER_ORIGIN; for (StaticParam a_sparam : te_sp) { StaticParamKind spk = a_sparam.getKind(); if (spk instanceof KindOp) continue; String method_name = Naming.staticParameterGetterName(te_stem, i); mv = cw.visitCGMethod(ACC_PUBLIC, method_name, Naming.STATIC_PARAMETER_GETTER_SIG, null, null); mv.visitCode(); // lazyInit(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, rttiClassName, "lazyInit", "()V"); String delegate_id = null; // invoke delegate -- work in progress here if (direct_extends_opr_tagged.containsKey(te_id) || te_id.equals(name)) { delegate_id = te_id; } else { //need to find a direct extend that extends the trait we're looking for for (String direct_extend_id : direct_extends_opr_tagged.keySet()) { if (transitive_extends_from_extends.get(direct_extend_id).containsKey(te_id)) { delegate_id = direct_extend_id; break; } } } if (delegate_id == null) throw new CompilerError( "Could not find directly extended trait that transitively extends" + te_id); mv.visitVarInsn(ALOAD, 0); getExtendeeField(rttiClassName, delegate_id); String extendeeIlk = delegate_id; // NamingCzar.jvmClassForToplevelTypeDecl(delegate_id,"",packageAndClassName); String field_type = Naming.stemClassToRTTIclass(extendeeIlk); mv.visitMethodInsn(INVOKEVIRTUAL, field_type, method_name, Naming.STATIC_PARAMETER_GETTER_SIG); areturnEpilogue(); i++; } } } cw.dumpClass(rttiClassFileName, xldata); cw = prev; }
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
private static byte[] instantiateAnyConcreteTuple(String dename, List<String> parameters) { /*/*from w ww.j av a2s. c om*/ * Single parameter, N, which is the arity of the tuple. * * extends Ljava/util/AbstractList; * implements LAnyTuple[\N\]; * int size() { return N; } * Object get(int n) { * if (n >= N || n < 0) { * throw new IndexOutOfBoundsException(); * } else { * // binary search tree returning o1 ... oN * } * } */ ManglingClassWriter cw = new ManglingClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); final String super_type = "java/lang/Object"; final int n = Integer.parseInt(parameters.get(0)); final String any_tuple_n = ANY_TUPLE + Naming.LEFT_OXFORD + n + Naming.RIGHT_OXFORD; String[] superInterfaces = { any_tuple_n }; cw.visit(JVM_BYTECODE_VERSION, Opcodes.ACC_PUBLIC | Opcodes.ACC_ABSTRACT, dename, null, super_type, superInterfaces); simpleInitMethod(cw, super_type); { // size method MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "size", "()I", null, null); mv.visitCode(); mv.visitIntInsn(BIPUSH, n); mv.visitInsn(IRETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } { // get method final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "get", "(I)Ljava/lang/Object;", null, null); mv.visitCode(); mv.visitVarInsn(ILOAD, 1); mv.visitIntInsn(BIPUSH, n); Label l1 = new Label(); mv.visitJumpInsn(IF_ICMPGE, l1); mv.visitVarInsn(ILOAD, 1); Label l2 = new Label(); mv.visitJumpInsn(IFGE, l2); mv.visitLabel(l1); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitTypeInsn(NEW, "java/lang/IndexOutOfBoundsException"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IndexOutOfBoundsException", "<init>", "()V"); mv.visitInsn(ATHROW); FnVoidVoid geti = new FnVoidVoid() { @Override public void apply() { mv.visitVarInsn(ILOAD, 1); } }; FnVoid<Integer> leaf = new FnVoid<Integer>() { @Override public void apply(Integer x) { mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEINTERFACE, any_tuple_n, TUPLE_OBJECT_ELT_PFX + (Naming.TUPLE_ORIGIN + x), UNTYPED_GETTER_SIG); mv.visitInsn(ARETURN); } }; visitBinaryTree(mv, 0, n - 1, l2, geti, leaf); mv.visitMaxs(2, 2); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
/** * Generates a binary search tree for integers in the range [lo,hi] * (INCLUSIVE!). Target, if not null, is to be attached to the generated code. * geti pushes the integer in question onto the top of the stack. * leaf handles the leaf case where lo=hi. * //from w w w . j a v a2 s .com * Cases are generated into ascending order, just because. * * @param mv * @param lo * @param hi * @param target * @param geti * @param leaf */ static void visitBinaryTree(MethodVisitor mv, int lo, int hi, Label target, FnVoidVoid geti, FnVoid<Integer> leaf) { if (target != null) mv.visitLabel(target); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); if (lo == hi) { leaf.apply(lo); } else { /* * 0,1 -> 0,0; 1,1 * 0,2 -> 0,1; 2,2 */ int mid = (lo + hi) / 2; Label small = null; Label large = new Label(); geti.apply(); mv.visitIntInsn(BIPUSH, mid); mv.visitJumpInsn(IF_ICMPGT, large); visitBinaryTree(mv, lo, mid, small, geti, leaf); visitBinaryTree(mv, mid + 1, hi, large, geti, leaf); } }
From source file:de.dynamicfiles.projects.gradle.plugins.javafx.tasks.internal.MonkeyPatcher.java
License:Apache License
private static void doMonkeyPatchFileHandleLeak(ClassReader classReader, ClassWriter classWriter) { classReader.accept(new ClassVisitor(Opcodes.ASM5, classWriter) { @Override/*from w w w. jav a 2 s. c om*/ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { if (!(name.equals(METHOD_TO_MONKEY_PATCH) && desc.equals(METHOD_SIGNATURE_TO_MONKEY_PATCH))) { return super.visitMethod(access, name, desc, signature, exceptions); } // helpful source: http://web.cs.ucla.edu/~msb/cs239-tutorial/ // "We will do this using the Adapter Pattern. Adapters wrap an object, overriding some of its methods, and delegating to the others." // ugly adapter-pattern ... took me more time than I really can tell here <.< return getMonkeyPatchedFileHandleLeakMethodVisitor(access, name, desc, signature, exceptions); } private MethodVisitor getMonkeyPatchedFileHandleLeakMethodVisitor(int access, String name, String desc, String signature, String[] exceptions) { return new MethodVisitor(Opcodes.ASM5, super.visitMethod(access, name, desc, signature, exceptions)) { /* TODO improve detection of lambda-positions, numbers might vary on different compile-versions */ @Override public void visitCode() { // This mostly got generated from ASM itself, except some adjustments for lambda-IDs and removed "visitMaxs()"-call String javalangThrowable = "java/lang/Throwable"; String javaioFile = "java/io/File"; String javalangString = "java/lang/String"; Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, javalangThrowable); Label l3 = new Label(); Label l4 = new Label(); Label l5 = new Label(); mv.visitTryCatchBlock(l3, l4, l5, javalangThrowable); Label l6 = new Label(); mv.visitTryCatchBlock(l3, l4, l6, null); Label l7 = new Label(); Label l8 = new Label(); Label l9 = new Label(); mv.visitTryCatchBlock(l7, l8, l9, javalangThrowable); Label l10 = new Label(); mv.visitTryCatchBlock(l5, l10, l6, null); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitVarInsn(Opcodes.ALOAD, 2); Label l11 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l11); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javaioFile, "isDirectory", "()Z", false); Label l12 = new Label(); mv.visitJumpInsn(Opcodes.IFNE, l12); mv.visitLabel(l11); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { javalangString }, 0, null); mv.visitTypeInsn(Opcodes.NEW, javaioFile); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("java.home"); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "getProperty", "(Ljava/lang/String;)Ljava/lang/String;", false); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, javaioFile, "<init>", "(Ljava/lang/String;)V", false); mv.visitVarInsn(Opcodes.ASTORE, 2); mv.visitLabel(l12); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitFieldInsn(Opcodes.GETSTATIC, "com/oracle/tools/packager/windows/WinAppBundler", "VS_VERS", "[Ljava/lang/String;"); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitInsn(Opcodes.ARRAYLENGTH); mv.visitVarInsn(Opcodes.ISTORE, 5); mv.visitInsn(Opcodes.ICONST_0); mv.visitVarInsn(Opcodes.ISTORE, 6); Label l13 = new Label(); mv.visitLabel(l13); mv.visitFrame(Opcodes.F_APPEND, 3, new Object[] { "[Ljava/lang/String;", Opcodes.INTEGER, Opcodes.INTEGER }, 0, null); mv.visitVarInsn(Opcodes.ILOAD, 6); mv.visitVarInsn(Opcodes.ILOAD, 5); Label l14 = new Label(); mv.visitJumpInsn(Opcodes.IF_ICMPGE, l14); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitVarInsn(Opcodes.ILOAD, 6); mv.visitInsn(Opcodes.AALOAD); mv.visitVarInsn(Opcodes.ASTORE, 7); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "com/oracle/tools/packager/windows/WinAppBundler", "copyMSVCDLLs", "(Ljava/io/File;Ljava/lang/String;)Z", false); Label l15 = new Label(); mv.visitJumpInsn(Opcodes.IFEQ, l15); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitVarInsn(Opcodes.ASTORE, 3); mv.visitJumpInsn(Opcodes.GOTO, l14); mv.visitLabel(l15); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitIincInsn(6, 1); mv.visitJumpInsn(Opcodes.GOTO, l13); mv.visitLabel(l14); mv.visitFrame(Opcodes.F_CHOP, 3, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 3); Label l16 = new Label(); mv.visitJumpInsn(Opcodes.IFNONNULL, l16); mv.visitTypeInsn(Opcodes.NEW, "java/lang/RuntimeException"); mv.visitInsn(Opcodes.DUP); mv.visitLdcInsn("Not found MSVC dlls"); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l16); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitTypeInsn(Opcodes.NEW, "java/util/concurrent/atomic/AtomicReference"); mv.visitInsn(Opcodes.DUP); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/util/concurrent/atomic/AtomicReference", "<init>", "()V", false); mv.visitVarInsn(Opcodes.ASTORE, 4); mv.visitVarInsn(Opcodes.ALOAD, 3); mv.visitVarInsn(Opcodes.ASTORE, 5); mv.visitVarInsn(Opcodes.ALOAD, 2); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javaioFile, "toPath", "()Ljava/nio/file/Path;", false); mv.visitLdcInsn("bin"); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/nio/file/Path", "resolve", "(Ljava/lang/String;)Ljava/nio/file/Path;", true); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/nio/file/Files", "list", "(Ljava/nio/file/Path;)Ljava/util/stream/Stream;", false); mv.visitVarInsn(Opcodes.ASTORE, 6); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ASTORE, 7); mv.visitLabel(l3); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitInvokeDynamicInsn("test", "()Ljava/util/function/Predicate;", new Handle( Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"), new Object[] { Type.getType("(Ljava/lang/Object;)Z"), new Handle(Opcodes.H_INVOKESTATIC, "com/oracle/tools/packager/windows/WinAppBundler", "lambda$copyMSVCDLLs$261", "(Ljava/nio/file/Path;)Z"), Type.getType("(Ljava/nio/file/Path;)Z") }); // modified lambda-name mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "filter", "(Ljava/util/function/Predicate;)Ljava/util/stream/Stream;", true); mv.visitVarInsn(Opcodes.ALOAD, 5); mv.visitInvokeDynamicInsn("test", "(Ljava/lang/String;)Ljava/util/function/Predicate;", new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"), new Object[] { Type.getType("(Ljava/lang/Object;)Z"), new Handle( Opcodes.H_INVOKESTATIC, "com/oracle/tools/packager/windows/WinAppBundler", "lambda$copyMSVCDLLs$262", "(Ljava/lang/String;Ljava/nio/file/Path;)Z"), Type.getType("(Ljava/nio/file/Path;)Z") }); // modified lambda-name mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "filter", "(Ljava/util/function/Predicate;)Ljava/util/stream/Stream;", true); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitInvokeDynamicInsn("accept", "(Ljava/io/File;Ljava/util/concurrent/atomic/AtomicReference;)Ljava/util/function/Consumer;", new Handle(Opcodes.H_INVOKESTATIC, "java/lang/invoke/LambdaMetafactory", "metafactory", "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;"), new Object[] { Type.getType("(Ljava/lang/Object;)V"), new Handle( Opcodes.H_INVOKESTATIC, "com/oracle/tools/packager/windows/WinAppBundler", "lambda$copyMSVCDLLs$263", "(Ljava/io/File;Ljava/util/concurrent/atomic/AtomicReference;Ljava/nio/file/Path;)V"), Type.getType("(Ljava/nio/file/Path;)V") }); // modified lambda-name mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "forEach", "(Ljava/util/function/Consumer;)V", true); mv.visitLabel(l4); mv.visitVarInsn(Opcodes.ALOAD, 6); Label l17 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l17); mv.visitVarInsn(Opcodes.ALOAD, 7); Label l18 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l18); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V", true); mv.visitLabel(l1); mv.visitJumpInsn(Opcodes.GOTO, l17); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_FULL, 8, new Object[] { "com/oracle/tools/packager/windows/WinAppBundler", javaioFile, javaioFile, javalangString, "java/util/concurrent/atomic/AtomicReference", javalangString, "java/util/stream/Stream", javalangThrowable }, 1, new Object[] { javalangThrowable }); mv.visitVarInsn(Opcodes.ASTORE, 8); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitVarInsn(Opcodes.ALOAD, 8); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javalangThrowable, "addSuppressed", "(Ljava/lang/Throwable;)V", false); mv.visitJumpInsn(Opcodes.GOTO, l17); mv.visitLabel(l18); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V", true); mv.visitJumpInsn(Opcodes.GOTO, l17); mv.visitLabel(l5); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { javalangThrowable }); mv.visitVarInsn(Opcodes.ASTORE, 8); mv.visitVarInsn(Opcodes.ALOAD, 8); mv.visitVarInsn(Opcodes.ASTORE, 7); mv.visitVarInsn(Opcodes.ALOAD, 8); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l6); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { javalangThrowable }); mv.visitVarInsn(Opcodes.ASTORE, 9); mv.visitLabel(l10); mv.visitVarInsn(Opcodes.ALOAD, 6); Label l19 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l19); mv.visitVarInsn(Opcodes.ALOAD, 7); Label l20 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l20); mv.visitLabel(l7); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V", true); mv.visitLabel(l8); mv.visitJumpInsn(Opcodes.GOTO, l19); mv.visitLabel(l9); mv.visitFrame(Opcodes.F_FULL, 10, new Object[] { "com/oracle/tools/packager/windows/WinAppBundler", javaioFile, javaioFile, javalangString, "java/util/concurrent/atomic/AtomicReference", javalangString, "java/util/stream/Stream", javalangThrowable, Opcodes.TOP, javalangThrowable }, 1, new Object[] { javalangThrowable }); mv.visitVarInsn(Opcodes.ASTORE, 10); mv.visitVarInsn(Opcodes.ALOAD, 7); mv.visitVarInsn(Opcodes.ALOAD, 10); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, javalangThrowable, "addSuppressed", "(Ljava/lang/Throwable;)V", false); mv.visitJumpInsn(Opcodes.GOTO, l19); mv.visitLabel(l20); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/stream/Stream", "close", "()V", true); mv.visitLabel(l19); mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null); mv.visitVarInsn(Opcodes.ALOAD, 9); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l17); mv.visitFrame(Opcodes.F_FULL, 6, new Object[] { "com/oracle/tools/packager/windows/WinAppBundler", javaioFile, javaioFile, javalangString, "java/util/concurrent/atomic/AtomicReference", javalangString }, 0, new Object[] {}); mv.visitVarInsn(Opcodes.ALOAD, 4); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/util/concurrent/atomic/AtomicReference", "get", "()Ljava/lang/Object;", false); mv.visitTypeInsn(Opcodes.CHECKCAST, "java/io/IOException"); mv.visitVarInsn(Opcodes.ASTORE, 6); mv.visitVarInsn(Opcodes.ALOAD, 6); Label l21 = new Label(); mv.visitJumpInsn(Opcodes.IFNULL, l21); mv.visitVarInsn(Opcodes.ALOAD, 6); mv.visitInsn(Opcodes.ATHROW); mv.visitLabel(l21); mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] { "java/io/IOException" }, 0, null); mv.visitInsn(Opcodes.RETURN); } }; } }, ClassReader.EXPAND_FRAMES); // ClassReader.EXPAND_FRAMES required for Java 8 }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static MethodNode injectMethodSetCustomArmorItem() { MethodNode method = ASMHelper.getMethodNode(Opcodes.ACC_PRIVATE, ASMNames.MD_SAP_SET_CUSTOM_ARMOR_ITEM); method.visitCode();/* w w w . java 2s.c o m*/ Label l0 = new Label(); method.visitLabel(l0); method.visitVarInsn(Opcodes.ALOAD, 1); Label l1 = new Label(); method.visitJumpInsn(Opcodes.IFNONNULL, l1); method.visitTypeInsn(Opcodes.NEW, ASMNames.CL_ITEM_STACK); method.visitInsn(Opcodes.DUP); ASMHelper.visitFieldInsn(method, Opcodes.GETSTATIC, ASMNames.FD_ITEMS_IRON_SHOVEL); method.visitInsn(Opcodes.ICONST_0); ASMHelper.visitMethodInsn(method, Opcodes.INVOKESPECIAL, ASMNames.MD_ITEMSTACK_INIT, false); method.visitVarInsn(Opcodes.ASTORE, 1); method.visitLabel(l1); method.visitFrame(Opcodes.F_SAME, 0, null, 0, null); method.visitVarInsn(Opcodes.ALOAD, 0); ASMHelper.visitFieldInsn(method, Opcodes.GETFIELD, ASMNames.FD_HORSE_DATAWATCHER); method.visitIntInsn(Opcodes.BIPUSH, 23); method.visitVarInsn(Opcodes.ALOAD, 1); ASMHelper.visitMethodInsn(method, Opcodes.INVOKEVIRTUAL, ASMNames.MD_DATAWATCHER_UPDATE_OBJ, false); Label l3 = new Label(); method.visitLabel(l3); method.visitInsn(Opcodes.RETURN); Label l4 = new Label(); method.visitLabel(l4); method.visitLocalVariable("this", ASMNames.CL_T_ENTITY_HORSE, null, l0, l3, 0); method.visitLocalVariable("stack", ASMNames.CL_T_ITEM_STACK, null, l0, l3, 1); method.visitMaxs(5, 2); method.visitEnd(); return method; }
From source file:de.sanandrew.core.manpack.transformer.TransformHorseArmor.java
License:Creative Commons License
private static void transformInteract(MethodNode method) { InsnList needle = new InsnList(); needle.add(ASMHelper.getFieldInsnNode(Opcodes.GETSTATIC, ASMNames.FD_ITEMS_DIAMOND_HORSE_ARMOR)); needle.add(new JumpInsnNode(Opcodes.IF_ACMPNE, new LabelNode())); needle.add(new LabelNode()); needle.add(new LineNumberNode(-1, new LabelNode())); needle.add(new InsnNode(Opcodes.ICONST_3)); needle.add(new VarInsnNode(Opcodes.ISTORE, 4)); needle.add(new LabelNode()); needle.add(new LineNumberNode(-1, new LabelNode())); needle.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null)); AbstractInsnNode node = ASMHelper.findLastNodeFromNeedle(method.instructions, needle); InsnList newInstr = new InsnList(); newInstr.add(new LabelNode()); newInstr.add(new VarInsnNode(Opcodes.ALOAD, 2)); newInstr.add(ASMHelper.getMethodInsnNode(Opcodes.INVOKEVIRTUAL, ASMNames.MD_ITEMSTACK_GET_ITEM, false)); newInstr.add(new TypeInsnNode(Opcodes.INSTANCEOF, ASMNames.CL_ITEM_HORSE_ARMOR)); LabelNode l8 = new LabelNode(); newInstr.add(new JumpInsnNode(Opcodes.IFEQ, l8)); newInstr.add(new LabelNode()); newInstr.add(new InsnNode(Opcodes.ICONST_4)); newInstr.add(new VarInsnNode(Opcodes.ISTORE, 4)); newInstr.add(l8);/*w ww. j av a 2 s . c o m*/ newInstr.add(new FrameNode(Opcodes.F_SAME, 0, null, 0, null)); method.instructions.insert(node, newInstr); }