Package org.jboss.byteman.rule.exception

Examples of org.jboss.byteman.rule.exception.CompileException


        // modify the stack height to account for the removed exception and params
        compileContext.addStackCount(-(extraParams+1));

        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("ThrowExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expected));
        }
        // now create a ThrowException to wrap the user exception
        // create the thrown exception instance -- adds 1 to stack [UE] --> [UE, THE]
        exceptionClassName = "org/jboss/byteman/rule/exception/ThrowException";
        mv.visitTypeInsn(Opcodes.NEW, exceptionClassName);
        compileContext.addStackCount(1);
        // copy the ThrowException so we can init it [UE, THE] --> [THE, UE, THE]
        mv.visitInsn(Opcodes.DUP_X1);
        compileContext.addStackCount(1);
        // reverse the order of the top two words  [THE, UE, THE] --> [THE, THE, UE]
        mv.visitInsn(Opcodes.SWAP);
        // construct the exception [THE, THE, UE] --> [UE]
        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, exceptionClassName, "<init>", "(Ljava/lang/Throwable;)V");
        // we should now have just the ThrowException on the stack
        compileContext.addStackCount(-2);
        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("ThrowExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expected));
        }

        // now throw the exception and decrement the stack height

        mv.visitInsn(Opcodes.ATHROW);
View Full Code Here


                compileContext.addStackCount(1 - arrayDimDefinedCount);
            }
        }

        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("NewExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expected));
        }
    }
View Full Code Here

                    case MOD:
                        mv.visitInsn(Opcodes.IREM);
                        break;
                    default:
                        // should never happen
                        throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
                }
                // now coerce back to appropriate type
                if (type == type.B) {
                    mv.visitInsn(Opcodes.I2B);
                } else if (type == type.S) {
                    mv.visitInsn(Opcodes.I2S);
                } else if (type == type.C) {
                    mv.visitInsn(Opcodes.I2C);
                } // else if (type == type.I) { do nothing }
                // ok, we popped two bytes but added one
                compileContext.addStackCount(-1);
            else if (type == type.J) {

                expectedStack = 2;

                switch (oper)
                {
                    case MUL:
                        mv.visitInsn(Opcodes.LMUL);
                        break;
                    case DIV:
                        mv.visitInsn(Opcodes.LDIV);
                        break;
                    case PLUS:
                        mv.visitInsn(Opcodes.LADD);
                        break;
                    case MINUS:
                        mv.visitInsn(Opcodes.LSUB);
                        break;
                    case MOD:
                        mv.visitInsn(Opcodes.LREM);
                        break;
                    default:
                        // should never happen
                        throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
                }
                // ok, we popped four bytes but added two
                compileContext.addStackCount(-2);
            else if (type == type.F) {

                expectedStack = 1;

                switch (oper)
                {
                    case MUL:
                        mv.visitInsn(Opcodes.FMUL);
                        break;
                    case DIV:
                        mv.visitInsn(Opcodes.FDIV);
                        break;
                    case PLUS:
                        mv.visitInsn(Opcodes.FADD);
                        break;
                    case MINUS:
                        mv.visitInsn(Opcodes.FSUB);
                        break;
                    case MOD:
                        mv.visitInsn(Opcodes.FREM);
                        break;
                    default:
                        // should never happen
                        throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
                }
                // ok, we popped two bytes but added one
                compileContext.addStackCount(-1);
            else if (type == type.D) {

                expectedStack = 2;

                switch (oper)
                {
                    case MUL:
                        mv.visitInsn(Opcodes.DMUL);
                        break;
                    case DIV:
                        mv.visitInsn(Opcodes.DDIV);
                        break;
                    case PLUS:
                        mv.visitInsn(Opcodes.DADD);
                        break;
                    case MINUS:
                        mv.visitInsn(Opcodes.DSUB);
                        break;
                    case MOD:
                        mv.visitInsn(Opcodes.DREM);
                        break;
                    default:
                        // should never happen
                        throw new CompileException("ArithmeticExpression.compile : unexpected operator " + oper);
                }
                // ok, we popped four bytes but added two
                compileContext.addStackCount(-2);
            } else {
                throw new CompileException("ArithmeticExpression.compile : unexpected result type " + type.getName());
            }
        } catch (CompileException e) {
            throw e;
        } catch (Exception e) {
            throw new CompileException("ArithmeticExpression.compile : unexpected exception for operation " + token + getPos() + " in rule " + rule.getName(), e);
        }

        // check stack heights
        if (compileContext.getStackCount() != currentStack + expectedStack) {
            throw new CompileException("ArithmeticExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expectedStack));
        }
    }
View Full Code Here

        lhs.compileAssign(mv, compileContext);

        // ok, the stack height should be increased by the expecdted bytecount
        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("AssignExpression.compileAssignment : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expected));
        }
    }
View Full Code Here

        compileTypeConversion(oper1.getType(), type,  mv, compileContext);
        // plant a goto skipping over the else expression
        mv.visitJumpInsn(Opcodes.GOTO, endLabel);
        // check the stack height is what we expect, either 1 or 2 words depending upon the result type
        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("ConditionalEvalExpression.compile : invalid true branch stack height " + compileContext.getStackCount() + " expecting " + currentStack + expected);
        }
        // ok, now reset stack height for false branch
        compileContext.addStackCount(-expected);
        // else starts here
        mv.visitLabel(elseLabel);
        // compile the else branch
        oper2.compile(mv, compileContext);
        // make sure we type convert to our result type so that either branch stacks the same thing
        compileTypeConversion(oper2.getType(), type,  mv, compileContext);
        // the end is nigh
        mv.visitLabel(endLabel);

        // check the stack height is what we expect, either 1 or 2 words depending upon the result type
        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("ConditionalEvalExpression.compile : invalid false branch stack height " + compileContext.getStackCount() + " expecting " + currentStack + expected);
        }

        // no need to check max stack height as teh left and right expressions will have exceeded anything
        // we stacked inside this call
    }
View Full Code Here

        mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "concat", "(Ljava/lang/String;)Ljava/lang/String;");

        compileContext.addStackCount(-1);
       
        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("StringPlusExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + currentStack + expected);
        }
    }
View Full Code Here

            mv.visitInsn(Opcodes.DADD);
            compileContext.addStackCount(-2);
        }

        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("PlusExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expected));
        }
    }
View Full Code Here

        // check that the stack height is what we expect

        compileContext.addStackCount(expected);
       
        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("BitExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + currentStack + expected);
        }
    }
View Full Code Here

            compileContext.addStackCount(-1);
        }

        // ensure we have only increased the stack by the return value size
        if (compileContext.getStackCount() != currentStack + expected) {
            throw new CompileException("MethodExpression.compile : invalid stack height " + compileContext.getStackCount() + " expecting " + (currentStack + expected));
        }

        // no need to update max stack since compiling the  recipient or arguments will
        // have done so (and there will be no change if there was no such compile call)
    }
View Full Code Here

        // the call will remove 3 from the stack height
        compileContext.addStackCount(-3);

        // ok, the stack height should be as it was
        if (compileContext.getStackCount() != currentStack) {
            throw new CompileException("variable.compileAssignment : invalid stack height " + compileContext.getStackCount() + " expecting " + currentStack);
        }
    }
View Full Code Here

TOP

Related Classes of org.jboss.byteman.rule.exception.CompileException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.