@Override public StackManipulation flipOver(TypeDefinition typeDefinition) { switch (typeDefinition.getStackSize()) { case SINGLE: return WithFlip.DOUBLE_SINGLE; case DOUBLE: return WithFlip.DOUBLE_DOUBLE; default: throw new IllegalArgumentException("Cannot flip: " + typeDefinition); } } };
@Override public StackManipulation flipOver(TypeDefinition typeDefinition) { switch (typeDefinition.getStackSize()) { case SINGLE: return WithFlip.SINGLE_SINGLE; case DOUBLE: return WithFlip.SINGLE_DOUBLE; default: throw new IllegalArgumentException("Cannot flip: " + typeDefinition); } } },
/** * Duplicates a value given its type. * * @param typeDefinition The type to be duplicated. * @return A stack manipulation that duplicates the given type. */ public static Duplication of(TypeDefinition typeDefinition) { switch (typeDefinition.getStackSize()) { case SINGLE: return SINGLE; case DOUBLE: return DOUBLE; case ZERO: return ZERO; default: throw new AssertionError("Unexpected type: " + typeDefinition); } }
/** * Removes a value from the operand stack dependant of its size. * * @param typeDefinition The type to remove from the stack. * @return A stack manipulation that represents the removal. */ public static StackManipulation of(TypeDefinition typeDefinition) { switch (typeDefinition.getStackSize()) { case SINGLE: return SINGLE; case DOUBLE: return DOUBLE; case ZERO: return ZERO; default: throw new AssertionError(); } }
/** * Computes the stack size of all supplied types. * * @param typeDefinitions The types for which to compute the size. * @return The total size of all types. */ public static int of(Collection<? extends TypeDefinition> typeDefinitions) { int size = 0; for (TypeDefinition typeDefinition : typeDefinitions) { size += typeDefinition.getStackSize().getSize(); } return size; }
/** * {@inheritDoc} */ public int argument(int offset) { return offset < instrumentedMethod.getStackSize() ? offset : offset + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize(); }
/** * {@inheritDoc} */ public int argument(int offset) { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize() + offset; }
/** * {@inheritDoc} */ public int returned() { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize(); }
/** * {@inheritDoc} */ public int returned() { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize(); }
/** * {@inheritDoc} */ public int enter() { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()); }
/** * {@inheritDoc} */ public int enter() { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()); }
/** * {@inheritDoc} */ public ParameterDescription.InDefinedShape get(int index) { int offset = methodDescription.isStatic() ? 0 : 1; for (int previous = 0; previous < index; previous++) { offset += typeDefinitions.get(previous).getStackSize().getSize(); } return new ParameterDescription.Latent(methodDescription, typeDefinitions.get(index).asGenericType(), index, offset); }
/** * {@inheritDoc} */ public int mapped(int offset) { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) - adviceMethod.getStackSize() + offset; } }
/** * {@inheritDoc} */ public int named(String name) { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.headMap(name).values()); }
/** * {@inheritDoc} */ public int thrown() { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize() + instrumentedMethod.getReturnType().getStackSize().getSize(); }
/** * {@inheritDoc} */ public int named(String name) { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.headMap(name).values()); }
/** * {@inheritDoc} */ public int thrown() { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize() + instrumentedMethod.getReturnType().getStackSize().getSize(); }
/** * {@inheritDoc} */ public int mapped(int offset) { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize() + instrumentedMethod.getReturnType().getStackSize().getSize() + throwableSize.getSize() - adviceMethod.getStackSize() + offset; } }
/** * {@inheritDoc} */ public void initialize() { for (Map.Entry<Integer, TypeDefinition> typeDefinition : resolveInitializationTypes(argumentHandler).entrySet()) { if (typeDefinition.getValue().represents(boolean.class) || typeDefinition.getValue().represents(byte.class) || typeDefinition.getValue().represents(short.class) || typeDefinition.getValue().represents(char.class) || typeDefinition.getValue().represents(int.class)) { methodVisitor.visitInsn(Opcodes.ICONST_0); methodVisitor.visitVarInsn(Opcodes.ISTORE, typeDefinition.getKey()); } else if (typeDefinition.getValue().represents(long.class)) { methodVisitor.visitInsn(Opcodes.LCONST_0); methodVisitor.visitVarInsn(Opcodes.LSTORE, typeDefinition.getKey()); } else if (typeDefinition.getValue().represents(float.class)) { methodVisitor.visitInsn(Opcodes.FCONST_0); methodVisitor.visitVarInsn(Opcodes.FSTORE, typeDefinition.getKey()); } else if (typeDefinition.getValue().represents(double.class)) { methodVisitor.visitInsn(Opcodes.DCONST_0); methodVisitor.visitVarInsn(Opcodes.DSTORE, typeDefinition.getKey()); } else { methodVisitor.visitInsn(Opcodes.ACONST_NULL); methodVisitor.visitVarInsn(Opcodes.ASTORE, typeDefinition.getKey()); } methodSizeHandler.requireStackSize(typeDefinition.getValue().getStackSize().getSize()); } }
/** * {@inheritDoc} */ public int prepare(MethodVisitor methodVisitor) { StackSize stackSize; if (!instrumentedMethod.isStatic()) { methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitVarInsn(Opcodes.ASTORE, instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize()); stackSize = StackSize.SINGLE; } else { stackSize = StackSize.ZERO; } for (ParameterDescription parameterDescription : instrumentedMethod.getParameters()) { Type type = Type.getType(parameterDescription.getType().asErasure().getDescriptor()); methodVisitor.visitVarInsn(type.getOpcode(Opcodes.ILOAD), parameterDescription.getOffset()); methodVisitor.visitVarInsn(type.getOpcode(Opcodes.ISTORE), instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) + enterType.getStackSize().getSize() + parameterDescription.getOffset()); stackSize = stackSize.maximum(parameterDescription.getType().getStackSize()); } return stackSize.getSize(); } }