Examples of BranchInstruction


Examples of org.apache.bcel.generic.BranchInstruction

  if (hasNodeSetArgs() || hasReferenceArgs()) {
      translate(classGen, methodGen);
      desynthesize(classGen, methodGen);
  }
  else {
      BranchInstruction bi = null;
      final InstructionList il = methodGen.getInstructionList();

      _left.translate(classGen, methodGen);
      _right.translate(classGen, methodGen);
View Full Code Here

Examples of org.apache.bcel.generic.BranchInstruction

        String className = cf.getClassName();
        Type throwableType = _factory.getObjectType(Throwable.class.getName());

        mf.append(factory.createGetStatic(className, fieldName, _classType));

        BranchInstruction ifNotNullBI = new IFNONNULL(null);

        mf.append(ifNotNullBI);

        // Invoke Class.forName and store ther result.
        // Concern: will the class be visible to the right class loader?
        // May need to use alternate forName() and pass Thread's context class loader.

        mf.append(new PUSH(cf.getConstantPool(), _typeClassName));
        InstructionHandle tryStart =
            mf.append(
                factory.createInvoke(
                    "java.lang.Class",
                    "forName",
                    _classType,
                    new Type[] { Type.STRING },
                    Constants.INVOKESTATIC));
        mf.append(factory.createPutStatic(className, fieldName, _classType));

        GOTO jumpOut = new GOTO(null);

        InstructionHandle tryEnd = mf.append(jumpOut);

        String exceptionClassName = ApplicationRuntimeException.class.getName();

        InstructionHandle catchHandle = mf.append(factory.createNew(exceptionClassName));

        // This stuff can make my head spin, so let's map it out a little.
        // CCE = ClassCastException, ARE = ApplicationRuntimeException

        // Stack: CCE, ARE --> ARE, CCE, ARE

        mf.append(InstructionConstants.DUP_X1);

        // Stack: ARE, CCE, ARE -> ARE, ARE, CCE

        mf.append(InstructionConstants.SWAP);

        mf.append(
            factory.createInvoke(
                exceptionClassName,
                Constants.CONSTRUCTOR_NAME,
                Type.VOID,
                new Type[] { throwableType },
                Constants.INVOKESPECIAL));

        mf.append(InstructionConstants.ATHROW);

        mf.addExceptionHandler(
            tryStart,
            tryEnd,
            catchHandle,
            new ObjectType(ClassNotFoundException.class.getName()));

        InstructionHandle end = mf.append(InstructionConstants.NOP);

        ifNotNullBI.setTarget(end);
        jumpOut.setTarget(end);

        return fieldName;
    }
View Full Code Here

Examples of org.apache.bcel.generic.BranchInstruction

        int idxParam = 0;
        int idxStack = 0;

        int indexJoinPoint = parameterTypes.length * 2 + 1;

        BranchInstruction biIfNotNull = null;
        InstructionHandle ihIfNotNull = null;

        // Object joinPoint = ___jp.get();
        il.append(factory.createFieldAccess(
                cg.getClassName(),
                joinPoint.toString(),
                new ObjectType(TransformationUtil.THREAD_LOCAL_CLASS),
                Constants.GETSTATIC
        ));
        il.append(factory.createInvoke(
                TransformationUtil.THREAD_LOCAL_CLASS,
                "get",
                Type.OBJECT,
                Type.NO_ARGS,
                Constants.INVOKEVIRTUAL
        ));
        il.append(factory.createStore(Type.OBJECT, indexJoinPoint));

        // if (joinPoint == null) {
        il.append(factory.createLoad(Type.OBJECT, indexJoinPoint));
        biIfNotNull = factory.createBranchInstruction(Constants.IFNONNULL, null);
        il.append(biIfNotNull);

        // joinPoint = new StaticMethodJoinPoint(uuid, this, 10);
        il.append(factory.createNew(TransformationUtil.STATIC_METHOD_JOIN_POINT_CLASS));

        // loads the parameters (uuid, the class, the method id)
        il.append(InstructionConstants.DUP);
        il.append(new PUSH(cp, uuid));
        il.append(factory.createFieldAccess(
                cg.getClassName(),
                TransformationUtil.STATIC_CLASS_FIELD,
                new ObjectType("java.lang.Class"),
                Constants.GETSTATIC
        ));
        il.append(new PUSH(cp, methodId));
        il.append(new PUSH(cp, controllerClassName));

        // invokes the constructor
        il.append(factory.createInvoke(
                TransformationUtil.STATIC_METHOD_JOIN_POINT_CLASS,
                "<init>",
                Type.VOID,
                new Type[]{Type.STRING, new ObjectType("java.lang.Class"), Type.INT, Type.STRING},
                Constants.INVOKESPECIAL
        ));

        il.append(factory.createStore(Type.OBJECT, indexJoinPoint));

        // ___jp.set(joinPoint);
        il.append(factory.createFieldAccess(
                cg.getClassName(),
                joinPoint.toString(),
                new ObjectType(TransformationUtil.THREAD_LOCAL_CLASS),
                Constants.GETSTATIC
        ));
        il.append(factory.createLoad(Type.OBJECT, indexJoinPoint));
        il.append(factory.createInvoke(
                TransformationUtil.THREAD_LOCAL_CLASS,
                "set",
                Type.VOID,
                new Type[]{Type.OBJECT},
                Constants.INVOKEVIRTUAL
        ));

        ihIfNotNull = il.append(factory.createLoad(Type.OBJECT, indexJoinPoint));
        il.append(factory.createCheckCast(
                TransformationUtil.STATIC_METHOD_JOIN_POINT_TYPE));
        indexJoinPoint += 2;
        il.append(factory.createStore(Type.OBJECT, indexJoinPoint));

        biIfNotNull.setTarget(ihIfNotNull);

        // if we have parameters, wrap them up
        if (parameterTypes.length != 0) {

            // create and allocate the parameters array
View Full Code Here

Examples of org.apache.bcel.generic.BranchInstruction

        int indexParam = 1;
        int indexStack = 0;
        int indexJoinPoint = Type.getArgumentTypes(
                originalMethod.getSignature()).length * 2 + 1;

        BranchInstruction biIfNotNull = null;
        InstructionHandle ihIfNotNull = null;
        // Object joinPoint = ___jp.get();
        il.append(factory.createLoad(Type.OBJECT, 0));
        il.append(factory.createFieldAccess(
                cg.getClassName(),
                joinPoint.toString(),
                new ObjectType(TransformationUtil.THREAD_LOCAL_CLASS),
                Constants.GETFIELD
        ));
        il.append(factory.createInvoke(
                TransformationUtil.THREAD_LOCAL_CLASS,
                "get",
                Type.OBJECT,
                Type.NO_ARGS,
                Constants.INVOKEVIRTUAL
        ));
        il.append(factory.createStore(Type.OBJECT, indexJoinPoint));

        // if (joinPoint == null) {
        il.append(factory.createLoad(Type.OBJECT, indexJoinPoint));
        biIfNotNull = factory.createBranchInstruction(Constants.IFNONNULL, null);
        il.append(biIfNotNull);

        // joinPoint = new MemberMethodJoinPoint(uuid, this, "foo.bar.Baz", 10);
        il.append(factory.createNew(TransformationUtil.MEMBER_METHOD_JOIN_POINT_CLASS));
        il.append(InstructionConstants.DUP);

        il.append(new PUSH(cp, uuid));
        il.append(factory.createLoad(Type.OBJECT, 0));
        il.append(new PUSH(cp, cg.getClassName()));
        il.append(new PUSH(cp, methodId));
        il.append(new PUSH(cp, controllerClassName));

        il.append(factory.createInvoke(
                TransformationUtil.MEMBER_METHOD_JOIN_POINT_CLASS,
                "<init>",
                Type.VOID,
                new Type[]{Type.STRING, Type.OBJECT, Type.STRING, Type.INT, Type.STRING},
                Constants.INVOKESPECIAL
        ));
        il.append(factory.createStore(Type.OBJECT, indexJoinPoint));

        // ___jp.set(joinPoint);
        il.append(factory.createLoad(Type.OBJECT, 0));
        il.append(factory.createFieldAccess(
                cg.getClassName(),
                joinPoint.toString(),
                new ObjectType(TransformationUtil.THREAD_LOCAL_CLASS),
                Constants.GETFIELD
        ));
        il.append(factory.createLoad(Type.OBJECT, indexJoinPoint));
        il.append(factory.createInvoke(
                TransformationUtil.THREAD_LOCAL_CLASS,
                "set",
                Type.VOID,
                new Type[]{Type.OBJECT},
                Constants.INVOKEVIRTUAL
        ));

        ihIfNotNull = il.append(factory.createLoad(Type.OBJECT, indexJoinPoint));
        il.append(factory.createCheckCast(TransformationUtil.MEMBER_METHOD_JOIN_POINT_TYPE));
        indexJoinPoint += 2;
        il.append(factory.createStore(Type.OBJECT, indexJoinPoint));

        biIfNotNull.setTarget(ihIfNotNull);

        // if we have parameters, wrap them up
        if (Type.getArgumentTypes(originalMethod.getSignature()).length != 0) {

            // create and allocate the parameters array
View Full Code Here

Examples of org.apache.bcel.generic.BranchInstruction

            if (i > 0) {
                targetInstructions.add(ih);
            }

            il.append(new INSTANCEOF(cp.addClass(hierarchyTop)));
            BranchInstruction bi = InstructionFactory.createBranchInstruction(Constants.IFEQ,
                                                                              null);
            il.append(bi);
            branchInstructions.add(bi);

            il.append(InstructionFactory.createLoad(peType,
View Full Code Here

Examples of org.apache.bcel.generic.BranchInstruction

        il.append(InstructionConstants.ACONST_NULL);
        il.append(InstructionFactory.createStore(Type.OBJECT, 2));
        il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
        il.append(new INSTANCEOF(cp.addClass(new ObjectType(className))));
        BranchInstruction ifeq_6 = InstructionFactory.createBranchInstruction(Constants.IFEQ,
                                                                              null);
        il.append(ifeq_6);
        il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
        il.append(instFactory.createCheckCast(new ObjectType(className)));
        il.append(InstructionFactory.createStore(Type.OBJECT, 2));
        InstructionHandle ih_14 = il.append(InstructionFactory.createLoad(Type.OBJECT,
                                                                          2));
        il.append(new INSTANCEOF(cp.addClass(new ObjectType("java.lang.Cloneable"))));
        BranchInstruction ifne_18 = InstructionFactory.createBranchInstruction(Constants.IFNE,
                                                                               null);
        il.append(ifne_18);
        il.append(instFactory.createFieldAccess("java.lang.System",
                                                "out",
                                                new ObjectType("java.io.PrintStream"),
                                                Constants.GETSTATIC));
        il.append(new PUSH(cp, "Not cloneable!"));
        il.append(instFactory.createInvoke("java.io.PrintStream",
                                           "println",
                                           Type.VOID,
                                           new Type[] { Type.STRING },
                                           Constants.INVOKEVIRTUAL));
        il.append(InstructionConstants.ACONST_NULL);
        il.append(InstructionFactory.createReturn(Type.OBJECT));
        InstructionHandle ih_31 = il.append(InstructionFactory.createLoad(Type.OBJECT,
                                                                          2));
        il.append(instFactory.createInvoke(className,
                                           "clone",
                                           Type.OBJECT,
                                           Type.NO_ARGS,
                                           Constants.INVOKEVIRTUAL));
        il.append(InstructionFactory.createReturn(Type.OBJECT));
        ifeq_6.setTarget(ih_14);
        ifne_18.setTarget(ih_31);
        method.setMaxStack();
        method.setMaxLocals();
        cg.addMethod(method.getMethod());
        il.dispose();
View Full Code Here

Examples of org.apache.bcel.generic.BranchInstruction

            if (i > 0) {
                targetInstructions.add(ih);
            }

            il.append(new INSTANCEOF(cp.addClass(hierarchyTop)));
            BranchInstruction bi = InstructionFactory.createBranchInstruction(Constants.IFEQ,
                                                                              null);
            il.append(bi);
            branchInstructions.add(bi);

            il.append(InstructionFactory.createLoad(peType,
View Full Code Here

Examples of org.apache.bcel.generic.BranchInstruction

        il.append(InstructionConstants.ACONST_NULL);
        il.append(InstructionFactory.createStore(Type.OBJECT, 2));
        il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
        il.append(new INSTANCEOF(cp.addClass(new ObjectType(className))));
        BranchInstruction ifeq_6 = InstructionFactory.createBranchInstruction(Constants.IFEQ,
                                                                              null);
        il.append(ifeq_6);
        il.append(InstructionFactory.createLoad(Type.OBJECT, 1));
        il.append(instFactory.createCheckCast(new ObjectType(className)));
        il.append(InstructionFactory.createStore(Type.OBJECT, 2));
        InstructionHandle ih_14 = il.append(InstructionFactory.createLoad(Type.OBJECT,
                                                                          2));
        il.append(new INSTANCEOF(cp.addClass(new ObjectType("java.lang.Cloneable"))));
        BranchInstruction ifne_18 = InstructionFactory.createBranchInstruction(Constants.IFNE,
                                                                               null);
        il.append(ifne_18);
        il.append(instFactory.createFieldAccess("java.lang.System",
                                                "out",
                                                new ObjectType("java.io.PrintStream"),
                                                Constants.GETSTATIC));
        il.append(new PUSH(cp, "Not cloneable!"));
        il.append(instFactory.createInvoke("java.io.PrintStream",
                                           "println",
                                           Type.VOID,
                                           new Type[] { Type.STRING },
                                           Constants.INVOKEVIRTUAL));
        il.append(InstructionConstants.ACONST_NULL);
        il.append(InstructionFactory.createReturn(Type.OBJECT));
        InstructionHandle ih_31 = il.append(InstructionFactory.createLoad(Type.OBJECT,
                                                                          2));
        il.append(instFactory.createInvoke(className,
                                           "clone",
                                           Type.OBJECT,
                                           Type.NO_ARGS,
                                           Constants.INVOKEVIRTUAL));
        il.append(InstructionFactory.createReturn(Type.OBJECT));
        ifeq_6.setTarget(ih_14);
        ifne_18.setTarget(ih_31);
        method.setMaxStack();
        method.setMaxLocals();
        cg.addMethod(method.getMethod());
        il.dispose();
View Full Code Here

Examples of org.apache.bcel.generic.BranchInstruction

  @SuppressWarnings("unused")
  // Called using reflection
  private Instruction createInstructionGoto(Element inst)
  {
    int id= Integer.parseInt(inst.getAttributeValue("label"));
    BranchInstruction bi= new GOTO(null);
    instructionHandlerManager.registerBranchInstruction(bi, id);
    return bi;
  }
View Full Code Here

Examples of org.apache.bcel.generic.BranchInstruction

  @SuppressWarnings("unused")
  // Called using reflection
  private Instruction createInstructionIf_acmpne(Element inst)
  {
    int id= Integer.parseInt(inst.getAttributeValue("label"));
    BranchInstruction bi= new IF_ACMPNE(null);
    instructionHandlerManager.registerBranchInstruction(bi, id);
    return bi;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.