Java Code Examples for net.bytebuddy.implementation.bytecode.StackSize#getSize()

The following examples show how to use net.bytebuddy.implementation.bytecode.StackSize#getSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StackAwareMethodVisitor.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Drains the stack to only contain the top value. For this, the value on top of the stack is temporarily stored
 * in the local variable array until all values on the stack are popped off. Subsequently, the top value is pushed
 * back onto the operand stack.
 *
 * @param store The opcode used for storing the top value.
 * @param load  The opcode used for loading the top value.
 * @param size  The size of the value on top of the operand stack.
 * @return The minimal size of the local variable array that is required to perform the operation.
 */
public int drainStack(int store, int load, StackSize size) {
    int difference = current.get(current.size() - 1).getSize() - size.getSize();
    if (current.size() == 1 && difference == 0) {
        return 0;
    } else {
        super.visitVarInsn(store, freeIndex);
        if (difference == 1) {
            super.visitInsn(Opcodes.POP);
        } else if (difference != 0) {
            throw new IllegalStateException("Unexpected remainder on the operand stack: " + difference);
        }
        doDrain(current.subList(0, current.size() - 1));
        super.visitVarInsn(load, freeIndex);
        return freeIndex + size.getSize();
    }
}
 
Example 2
Source File: FieldAccess.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Override
protected Size resolveSize(StackSize fieldSize) {
    int sizeChange = fieldSize.getSize() - targetSizeChange;
    return new Size(sizeChange, sizeChange);
}
 
Example 3
Source File: FieldAccess.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Override
protected Size resolveSize(StackSize fieldSize) {
    return new Size(-1 * (fieldSize.getSize() + targetSizeChange), 0);
}
 
Example 4
Source File: MethodInvocationTest.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
public MethodInvocationTest(StackSize stackSize) {
    this.stackSize = stackSize;
    this.expectedSize = stackSize.getSize() - ARGUMENT_STACK_SIZE;
}