public static int getStackSize(Type[] types) { int size = 0; for (int i = 0; i < types.length; i++) { size += types[i].getSize(); } return size; }
private int skipArgs(int numArgs) { int amount = 0; for (int i = 0; i < numArgs; i++) { amount += state.argumentTypes[i].getSize(); } return amount; }
private int newLocal(Type type) { final int myIndex = nextLocalIndex; nextLocalIndex += type.getSize(); return myIndex; }
public static int getStackSize(Type[] types) { int size = 0; for (int i = 0; i < types.length; i++) { size += types[i].getSize(); } return size; }
private int skipArgs(int numArgs) { int amount = 0; for (int i = 0; i < numArgs; i++) { amount += state.argumentTypes[i].getSize(); } return amount; }
private int countSignatureVariables(String desc) { int count = 1; for (Type paramType : Type.getArgumentTypes(desc)) { count += paramType.getSize(); } return count; }
private static int parameterTypeUnsafe(MethodVisitor methodVisitor, Class<?> parameterType, boolean write) { parameterType = parameterType.isPrimitive() ? parameterType : Object.class; Type type = Type.getType(parameterType); String boolDescriptor = parameterType == boolean.class ? "Ljava/lang/Object;" : ""; methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Unsafe.class), (write ? "put" : "get") + Character.toUpperCase(type.getClassName().charAt(0)) + type.getClassName().substring(1), write ? ("(" + boolDescriptor + "J" + type.getDescriptor() + ")V") : ("(" + boolDescriptor + "J)" + type.getDescriptor()), false); return type.getSize(); }
public LocalVariablesSorter( final int access, final String desc, final MethodVisitor mv) { super(Constants.ASM_API, mv); state = new State(); Type[] args = Type.getArgumentTypes(desc); state.nextLocal = ((Opcodes.ACC_STATIC & access) != 0) ? 0 : 1; for (int i = 0; i < args.length; i++) { state.nextLocal += args[i].getSize(); } firstLocal = state.nextLocal; }
public LocalVariablesSorter( final int access, final String desc, final MethodVisitor mv) { super(Constants.ASM_API, mv); state = new State(); Type[] args = Type.getArgumentTypes(desc); state.nextLocal = ((Opcodes.ACC_STATIC & access) != 0) ? 0 : 1; for (int i = 0; i < args.length; i++) { state.nextLocal += args[i].getSize(); } firstLocal = state.nextLocal; }
public static int getIdxByType(int access, String desc, Type type) { Type[] t = Type.getArgumentTypes(desc); int sidx = (AsmUtil.isStatic(access) ? 0 : 1); for (int i = 0; t != null && i < t.length; i++) { if (type.equals(t[i])) { return sidx; } sidx += t[i].getSize(); } return -1; }
public void load_args(int fromArg, int count) { int pos = state.localOffset + skipArgs(fromArg); for (int i = 0; i < count; i++) { Type t = state.argumentTypes[fromArg + i]; load_local(t, pos); pos += t.getSize(); } }
public Local make_local(Type type) { return new Local(newLocal(type.getSize()), type); }
public void load_args(int fromArg, int count) { int pos = state.localOffset + skipArgs(fromArg); for (int i = 0; i < count; i++) { Type t = state.argumentTypes[fromArg + i]; load_local(t, pos); pos += t.getSize(); } }
public Local make_local(Type type) { return new Local(newLocal(type.getSize()), type); }
@Override public void visitCode() { AsmUtil.PUSH(mv, methodName); boolean flag = false; int sidx = isStatic ? 0 : 1; for (int i = 0; i < paramTypes.length; i++) { Type tp = paramTypes[i]; if ("java/lang/String".equals(tp.getInternalName())) { mv.visitVarInsn(Opcodes.ALOAD, sidx); flag = true; break; } sidx += tp.getSize(); } if (flag == false) { AsmUtil.PUSH(mv, ""); } mv.visitMethodInsn(Opcodes.INVOKESTATIC, CLASS, METHOD, SIGNATURE, false); super.visitCode(); } }
static void box(final Type type, ListIterator<AbstractInsnNode> instructions) { if (type.getSort() == OBJECT || type.getSort() == ARRAY) { return; } if (Type.VOID_TYPE.equals(type)) { instructions.add(new InsnNode(Opcodes.ACONST_NULL)); } else { Type boxed = getBoxedType(type); instructions.add(new TypeInsnNode(Opcodes.NEW, boxed.getInternalName())); if (type.getSize() == 2) { // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o instructions.add(new InsnNode(Opcodes.DUP_X2)); instructions.add(new InsnNode(Opcodes.DUP_X2)); instructions.add(new InsnNode(Opcodes.POP)); } else { // p -> po -> opo -> oop -> o instructions.add(new InsnNode(Opcodes.DUP_X1)); instructions.add(new InsnNode(Opcodes.SWAP)); } instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, boxed.getInternalName(), "<init>", "(" + type.getDescriptor() + ")V", false)); } }
return null; } else { return b(Type.getReturnType(mi.desc).getSize(), v);
/** * If the argument is a primitive class, replaces the primitive value * on the top of the stack with the wrapped (Object) equivalent. For * example, char -> Character. * If the class is Void, a null is pushed onto the stack instead. * @param type the class indicating the current type of the top stack value */ public void box(Type type) { if (TypeUtils.isPrimitive(type)) { if (type == Type.VOID_TYPE) { aconst_null(); } else { Type boxed = TypeUtils.getBoxedType(type); new_instance(boxed); if (type.getSize() == 2) { // Pp -> Ppo -> oPpo -> ooPpo -> ooPp -> o dup_x2(); dup_x2(); pop(); } else { // p -> po -> opo -> oop -> o dup_x1(); swap(); } invoke_constructor(boxed, new Signature(Constants.CONSTRUCTOR_NAME, Type.VOID_TYPE, new Type[]{ type })); } } }