/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { Size size = IntegerConstant.forValue(stackManipulations.size()).apply(methodVisitor, implementationContext); // The array's construction does not alter the stack's size. size = size.aggregate(arrayCreator.apply(methodVisitor, implementationContext)); int index = 0; for (StackManipulation stackManipulation : stackManipulations) { methodVisitor.visitInsn(Opcodes.DUP); size = size.aggregate(StackSize.SINGLE.toIncreasingSize()); size = size.aggregate(IntegerConstant.forValue(index++).apply(methodVisitor, implementationContext)); size = size.aggregate(stackManipulation.apply(methodVisitor, implementationContext)); methodVisitor.visitInsn(arrayCreator.getStorageOpcode()); size = size.aggregate(sizeDecrease); } return size; } }
@Override public Size apply(final MethodVisitor mv, final Context implementationContext) { Size size = new Size(0, 0); Label proceed = new Label(); Label exit = new Label(); size = size.aggregate(condition.apply(mv, implementationContext)); mv.visitJumpInsn(Opcodes.IFEQ, proceed); size = size.aggregate(action.apply(mv, implementationContext)); mv.visitJumpInsn(Opcodes.GOTO, exit); mv.visitLabel(proceed); mv.visitFrame(Opcodes.F_FULL, frame.localSize(), frame.locals(), 0, null); size = size.aggregate(otherwise.apply(mv, implementationContext)); mv.visitLabel(exit); mv.visitFrame(Opcodes.F_FULL, 0, null, 0, null); return size; } }
@Override public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) { //initialize the stack with the array access with this as reference 0 and the array (first argument) as reference 1 StackManipulation compound = assignOperation(); StackManipulation.Size size = compound.apply(methodVisitor, implementationContext); //resolve the type to store in the array and retrieve the store command StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).store(); size = size.aggregate(store.apply(methodVisitor, implementationContext)); //set the return type (ALWAYS REMEMBER TO DO THIS) StackManipulation returnOp = MethodReturn.VOID; size = size.aggregate(returnOp.apply(methodVisitor, implementationContext)); return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize()); }
@Override public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) { //initialize the stack with the array access with this as reference 0 and the array (first argument) as reference 1 StackManipulation compound = assignOperation(); StackManipulation.Size size = compound.apply(methodVisitor, implementationContext); //resolve the type to store in the array and retrieve the store command StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).store(); size = size.aggregate(store.apply(methodVisitor, implementationContext)); return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize()); }
@Override public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) { //initialize the stack with the array access with this as reference 0 and the array (first argument) as reference 1 StackManipulation compound = assignOperation(); StackManipulation.Size size = compound.apply(methodVisitor, implementationContext); //resolve the type to store in the array and retrieve the store command StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).store(); size = size.aggregate(store.apply(methodVisitor, implementationContext)); return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize()); }
@Override public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext, MethodDescription instrumentedMethod) { //initialize the stack with the array access with this as reference 0 and the array (first argument) as reference 1 StackManipulation compound = assignOperation(); StackManipulation.Size size = compound.apply(methodVisitor, implementationContext); //resolve the type to store in the array and retrieve the load command StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).load(); size = size.aggregate(store.apply(methodVisitor, implementationContext)); return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize()); }
/** * Creates a new array factory with a given * {@link net.bytebuddy.implementation.bytecode.collection.ArrayFactory.ArrayCreator} * without inferring the type from the component type. Normally, * {@link net.bytebuddy.implementation.bytecode.collection.ArrayFactory#forType(net.bytebuddy.description.type.TypeDescription.Generic)} * should be used. * * @param componentType The component type of the array factory. * @param arrayCreator The array creator responsible for providing the correct byte code instructions. */ protected ArrayFactory(TypeDescription.Generic componentType, ArrayCreator arrayCreator) { this.componentType = componentType; this.arrayCreator = arrayCreator; // Size decreases by index and array reference (2) and array element (1, 2) after each element storage. sizeDecrease = StackSize.DOUBLE.toDecreasingSize().aggregate(componentType.getStackSize().toDecreasingSize()); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { Size size = new Size(0, 0); for (StackManipulation stackManipulation : stackManipulations) { size = size.aggregate(stackManipulation.apply(methodVisitor, implementationContext)); } return size; } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitInsn(storeOpcode); return stackSize.toDecreasingSize().aggregate(new Size(-2, 0)); } }
/** * Concatenates this size representation with another size representation in order to represent the size * change that is represented by both alterations of the operand stack size. * * @param other The other size representation. * @return A new size representation representing both stack size requirements. */ public Size aggregate(Size other) { return aggregate(other.sizeImpact, other.maximalSize); }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitInsn(loadOpcode); return stackSize.toIncreasingSize().aggregate(new Size(-2, 0)); } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { methodVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, wrapperType.getInternalName(), boxingMethodName, boxingMethodDescriptor, false); return size.aggregate(stackManipulation.apply(methodVisitor, implementationContext)); } }