ctor.visitCode(); ctor.visitInsn(Opcodes.RETURN); ctor.visitEnd(); return removedInstructions;
@Override public void visitEnd() { super.visitEnd();
@Override public void visitEnd() { try { accept(inner); super.visitEnd(); } catch(Exception e){ Textifier t = new Textifier(); accept(new TraceMethodVisitor(t)); StringBuilderWriter sw = new StringBuilderWriter(); PrintWriter pw = new PrintWriter(sw); t.print(pw); pw.flush(); String bytecode = sw.getBuilder().toString(); logger.error(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e); throw new RuntimeException(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e); } } }
public static MethodNode generateGetter(String className, String methodName, String fieldName, String fieldType) { MethodNode mn = new MethodNode(ACC_PUBLIC, methodName, "()" + fieldType, null, null); mn.visitCode(); mn.visitVarInsn(ALOAD, 0); mn.visitFieldInsn(GETFIELD, className, fieldName, fieldType); int opCode; if (fieldType.equals("I") || fieldType.equals("Z")) { opCode = IRETURN; } else if (fieldType.equals("L")) { opCode = LRETURN; } else if (fieldType.equals("F")) { opCode = FRETURN; } else if (fieldType.equals("D")) { opCode = DRETURN; } else { opCode = ARETURN; } mn.visitInsn(opCode); mn.visitMaxs(1, 1); mn.visitEnd(); return mn; } }
public static MethodNode generateSetter(String className, String methodName, String fieldName, String fieldType) { MethodNode mn = new MethodNode(ACC_PUBLIC, methodName, "(" + fieldType + ")V", null, null); mn.visitCode(); mn.visitVarInsn(ALOAD, 0); int opCode; if (fieldType.equals("I") || fieldType.equals("Z")) { opCode = ILOAD; } else if (fieldType.equals("L")) { opCode = LLOAD; } else if (fieldType.equals("F")) { opCode = FLOAD; } else if (fieldType.equals("D")) { opCode = DLOAD; } else { opCode = ALOAD; } mn.visitVarInsn(opCode, 1); mn.visitFieldInsn(PUTFIELD, className, fieldName, fieldType); mn.visitInsn(RETURN); mn.visitMaxs(2, 2); mn.visitEnd(); return mn; }
public MethodNode createGetTranlocalMethod() { MethodNode m = new MethodNode( ACC_PUBLIC + ACC_SYNTHETIC, "getTranlocal", format("()%s", getDescriptor(AlphaTranlocal.class)), null, new String[]{}); m.visitVarInsn(ALOAD, 0); m.visitFieldInsn(GETFIELD, tranlocalSnapshotName, "___tranlocal", internalToDesc(tranlocalName)); m.visitInsn(ARETURN); m.visitMaxs(0, 0); m.visitEnd(); return m; }
/** * Just override the original super.createTakeSnapshotMethod if one exists. */ private MethodNode createTakeSnapshotMethod() { MethodNode m = new MethodNode( ACC_PUBLIC + ACC_SYNTHETIC, "takeSnapshot", format("()%s", getDescriptor(AlphaTranlocalSnapshot.class)), null, new String[]{}); m.visitTypeInsn(NEW, tranlocalSnapshotName); m.visitInsn(DUP); m.visitVarInsn(ALOAD, 0); String constructorDesc = format("(%s)V", internalToDesc(tranlocalName)); m.visitMethodInsn(INVOKESPECIAL, tranlocalSnapshotName, "<init>", constructorDesc); m.visitInsn(ARETURN); m.visitMaxs(0, 0);//value's don't matter, will be reculculated, but call is needed m.visitEnd(); return m; } }
ctor.visitCode(); ctor.visitInsn(RETURN); ctor.visitEnd(); return removedInstructions;
atomicClInit.visitEnd(); atomicClInit.accept(cv); } else {
private MethodNode generateIsBattleMode() { MethodNode mv = new MethodNode(ACC_PUBLIC, "isBattlemode", "()Z", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESTATIC, UTILITY_CLASS, "isPlayerInBattlemode", "(L" + entityPlayerClassName + ";)Z"); mv.visitInsn(IRETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", "L" + entityPlayerClassName + ";", null, l0, l1, 0); mv.visitMaxs(1, 1); mv.visitEnd(); return mv; }
private MethodNode generateAttackOffhandMethod() { MethodNode mv = new MethodNode(ACC_PUBLIC, "attackTargetEntityWithCurrentOffItem", "(L" + entityClassName + ";)V", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitMethodInsn(INVOKESTATIC, UTILITY_CLASS, "attackTargetEntityWithCurrentOffItem", "(L" + entityPlayerClassName + ";L" + entityClassName + ";)V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitInsn(RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", "L" + entityPlayerClassName + ";", null, l0, l2, 0); mv.visitLocalVariable("target", "L" + entityClassName + ";", null, l0, l2, 1); mv.visitMaxs(2, 2); mv.visitEnd(); return mv; }
private MethodNode createFreshConstructor() { MethodNode m = new MethodNode( ACC_PUBLIC + ACC_SYNTHETIC, "<init>", format("(%s)V", internalToDesc(clazz.name)), null, new String[]{}); //we need to call the no arg constructor of the AlphaTranlocal m.visitVarInsn(ALOAD, 0); m.visitMethodInsn(INVOKESPECIAL, alphaTranlocalName, "<init>", "()V"); //put the atomicobject m.visitVarInsn(ALOAD, 0); m.visitVarInsn(ALOAD, 1); m.visitFieldInsn(PUTFIELD, alphaTranlocalName, "___transactionalObject", alphaTransactionalObjectDesc); m.visitInsn(RETURN); m.visitMaxs(0, 0);//value's don't matter, will be reculculated, but call is needed m.visitEnd(); return m; }
method.visitInsn(RETURN); method.visitMaxs(3, 0); method.visitEnd();
@Override public void visitEnd() { super.visitEnd();
private MethodNode generateIsBlockingWithShield() { MethodNode mv = new MethodNode(ACC_PUBLIC, "isBlockingWithShield", "()Z", null, null); mv.visitCode(); Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESTATIC, UTILITY_CLASS, "canBlockWithShield", "(L" + entityPlayerClassName + ";)Z"); Label l1 = new Label(); mv.visitJumpInsn(IFEQ, l1); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, entityPlayerClassName, "isShielding", "Z"); mv.visitJumpInsn(IFEQ, l1); mv.visitInsn(ICONST_1); Label l2 = new Label(); mv.visitJumpInsn(GOTO, l2); mv.visitLabel(l1); mv.visitFrame(F_SAME, 0, null, 0, null); mv.visitInsn(ICONST_0); mv.visitLabel(l2); mv.visitFrame(F_SAME1, 0, null, 1, new Object[]{INTEGER}); mv.visitInsn(IRETURN); Label l3 = new Label(); mv.visitLabel(l3); mv.visitLocalVariable("this", "L" + entityPlayerClassName + ";", null, l0, l3, 0); mv.visitMaxs(1, 1); mv.visitEnd(); return mv; }
mv.visitLocalVariable("block", "Z", null, l0, l4, 1); mv.visitMaxs(2, 2); mv.visitEnd();
public MethodNode createConstructor() { MethodNode m = new MethodNode( ACC_PUBLIC + ACC_SYNTHETIC, "<init>", format("(%s)V", internalToDesc(tranlocalName)), null, new String[]{}); m.visitVarInsn(ALOAD, 0); m.visitMethodInsn(INVOKESPECIAL, getInternalName(AlphaTranlocalSnapshot.class), "<init>", "()V"); m.visitVarInsn(ALOAD, 0); m.visitVarInsn(ALOAD, 1); m.visitFieldInsn(PUTFIELD, tranlocalSnapshotName, "___tranlocal", internalToDesc(tranlocalName)); for (FieldNode fieldNode : (List<FieldNode>) classNode.fields) { FieldMetadata fieldMetadata = classMetadata.getFieldMetadata(fieldNode.name); if (fieldMetadata.isManagedField()) { m.visitVarInsn(ALOAD, 0); m.visitVarInsn(ALOAD, 1); m.visitFieldInsn(GETFIELD, tranlocalName, fieldNode.name, fieldNode.desc); m.visitFieldInsn(PUTFIELD, tranlocalSnapshotName, fieldNode.name, fieldNode.desc); } } m.visitInsn(RETURN); m.visitMaxs(0, 0); m.visitEnd(); return m; }
m.visitEnd(); return m;
m.visitEnd(); return m;