Examples of Bytecode

This program produces a Code attribute including a bytecode sequence:

@see ConstPool @see CodeAttribute
  • objot.bytecode.Bytecode
  • org.hotswap.agent.javassist.bytecode.Bytecode
    tant pool table Bytecode b = new Bytecode(cp, 1, 0); b.addIconst(3); b.addReturn(CtClass.intType); CodeAttribute ca = b.toCodeAttribute();

    This program produces a Code attribute including a bytecode sequence:

    @see ConstPool @see CodeAttribute
  • org.jboss.forge.furnace.proxy.javassist.bytecode.Bytecode
    tant pool table Bytecode b = new Bytecode(cp, 1, 0); b.addIconst(3); b.addReturn(CtClass.intType); CodeAttribute ca = b.toCodeAttribute();

    This program produces a Code attribute including a bytecode sequence:

    @see ConstPool @see CodeAttribute

  • Examples of javassist.bytecode.Bytecode

        ConstPool cp = classfile.getConstPool();
        int target_type_index = cp.addClassInfo( this.targetBean.getName() );
        String desc = GET_SETTER_DESC;
        MethodInfo mi = new MethodInfo( cp, GENERATED_SETTER_NAME, desc );

        Bytecode code = new Bytecode( cp, 4, 6 );
        StackMapTable stackmap = null;
        /* | this | bean | args | i | raw bean | exception | */
        if ( setters.length > 0 ) {
          int start, end; // required to exception table
          // iconst_0 // i
          code.addIconst( 0 );
          // istore_3 // store i
          code.addIstore( 3 );
          // aload_1 // load the bean
          code.addAload( 1 );
          // checkcast // cast the bean into a raw bean
          code.addCheckcast( this.targetBean.getName() );
          // astore 4 // store the raw bean
          code.addAstore( 4 );
          /* current stack len = 0 */
          // start region to handling exception (BulkAccessorException)
          start = code.currentPc();
          int lastIndex = 0;
          for ( int i = 0; i < setters.length; ++i ) {
            if ( setters[i] != null ) {
              int diff = i - lastIndex;
              if ( diff > 0 ) {
                // iinc 3, 1
                code.addOpcode( Opcode.IINC );
                code.add( 3 );
                code.add( diff );
                lastIndex = i;
              }
            }
            /* current stack len = 0 */
            // aload 4 // load the raw bean
            code.addAload( 4 );
            // aload_2 // load the args
            code.addAload( 2 );
            // iconst_i
            code.addIconst( i );
            // aaload
            code.addOpcode( Opcode.AALOAD );
            // checkcast
            Class[] setterParamTypes = setters[i].getParameterTypes();
            Class setterParamType = setterParamTypes[0];
            if ( setterParamType.isPrimitive() ) {
              // checkcast (case of primitive type)
              // invokevirtual (case of primitive type)
              this.addUnwrapper( classfile, code, setterParamType );
            }
            else {
              // checkcast (case of reference type)
              code.addCheckcast( setterParamType.getName() );
            }
            /* current stack len = 2 */
            String rawSetterMethod_desc = RuntimeSupport.makeDescriptor( setters[i] );
            if ( !this.targetBean.isInterface() ) {
              // invokevirtual
              code.addInvokevirtual( target_type_index, setters[i].getName(), rawSetterMethod_desc );
            }
            else {
              // invokeinterface
              Class[] params = setters[i].getParameterTypes();
              int size;
              if ( params[0].equals( Double.TYPE ) || params[0].equals( Long.TYPE ) ) {
                size = 3;
              }
              else {
                size = 2;
              }

              code.addInvokeinterface( target_type_index, setters[i].getName(), rawSetterMethod_desc, size );
            }
          }

          // end region to handling exception (BulkAccessorException)
          end = code.currentPc();
          // return
          code.addOpcode( Opcode.RETURN );
          /* current stack len = 0 */
          // register in exception table
          int throwableType_index = cp.addClassInfo( THROWABLE_CLASS_NAME );
          int handler_pc = code.currentPc();
          code.addExceptionHandler( start, end, handler_pc, throwableType_index );
          // astore 5 // store exception
          code.addAstore( 5 );
          // new // BulkAccessorException
          code.addNew( BULKEXCEPTION_CLASS_NAME );
          // dup
          code.addOpcode( Opcode.DUP );
          // aload 5 // load exception
          code.addAload( 5 );
          // iload_3 // i
          code.addIload( 3 );
          // invokespecial // BulkAccessorException.<init>
          String cons_desc = "(Ljava/lang/Throwable;I)V";
          code.addInvokespecial( BULKEXCEPTION_CLASS_NAME, MethodInfo.nameInit, cons_desc );
          // athrow
          code.addOpcode( Opcode.ATHROW );
          StackMapTable.Writer writer = new StackMapTable.Writer(32);
          int[] localTags = { StackMapTable.OBJECT, StackMapTable.OBJECT, StackMapTable.OBJECT, StackMapTable.INTEGER };
          int[] localData = { cp.getThisClassInfo(), cp.addClassInfo("java/lang/Object"),
                              cp.addClassInfo("[Ljava/lang/Object;"), 0};
          int[] stackTags = { StackMapTable.OBJECT };
          int[] stackData = { throwableType_index };
          writer.fullFrame(handler_pc, localTags, localData, stackTags, stackData);
          stackmap = writer.toStackMapTable(cp);
        }
        else {
          // return
          code.addOpcode( Opcode.RETURN );
        }
        CodeAttribute ca = code.toCodeAttribute();
        if (stackmap != null) {
          ca.setAttribute(stackmap);
        }
        mi.setCodeAttribute( ca );
        mi.setAccessFlags( AccessFlag.PUBLIC );
    View Full Code Here

    Examples of javassist.bytecode.Bytecode

        ConstPool cp = classfile.getConstPool();
        int this_class_index = cp.getThisClassInfo();
        MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME,
                                          GETFIELDHANDLER_METHOD_DESCRIPTOR);
        /* local variable | this | */
        Bytecode code = new Bytecode(cp, 2, 1);
        // aload_0 // load this
        code.addAload(0);
        // getfield // get field "$JAVASSIST_CALLBACK" defined already
        code.addOpcode(Opcode.GETFIELD);
        int field_index = cp.addFieldrefInfo(this_class_index,
                                             HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
        code.addIndex(field_index);
        // areturn // return the value of the field
        code.addOpcode(Opcode.ARETURN);
        minfo.setCodeAttribute(code.toCodeAttribute());
        minfo.setAccessFlags(AccessFlag.PUBLIC);
        CodeAttribute codeAttribute = minfo.getCodeAttribute();
        if (codeAttribute != null) {
          StackMapTable smt = MapMaker.make(classPool, minfo);
          codeAttribute.setAttribute(smt);
    View Full Code Here

    Examples of javassist.bytecode.Bytecode

        ConstPool cp = classfile.getConstPool();
        int this_class_index = cp.getThisClassInfo();
        MethodInfo minfo = new MethodInfo(cp, SETFIELDHANDLER_METHOD_NAME,
                                          SETFIELDHANDLER_METHOD_DESCRIPTOR);
        /* local variables | this | callback | */
        Bytecode code = new Bytecode(cp, 3, 3);
        // aload_0 // load this
        code.addAload(0);
        // aload_1 // load callback
        code.addAload(1);
        // putfield // put field "$JAVASSIST_CALLBACK" defined already
        code.addOpcode(Opcode.PUTFIELD);
        int field_index = cp.addFieldrefInfo(this_class_index,
                                             HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
        code.addIndex(field_index);
        // return
        code.addOpcode(Opcode.RETURN);
        minfo.setCodeAttribute(code.toCodeAttribute());
        minfo.setAccessFlags(AccessFlag.PUBLIC);
        CodeAttribute codeAttribute = minfo.getCodeAttribute();
        if (codeAttribute != null) {
          StackMapTable smt = MapMaker.make(classPool, minfo);
          codeAttribute.setAttribute(smt);
    View Full Code Here

    Examples of javassist.bytecode.Bytecode

        int this_class_index = cp.getThisClassInfo();
        String desc = "()" + finfo.getDescriptor();
        MethodInfo minfo = new MethodInfo(cp, EACH_READ_METHOD_PREFIX
                                              + finfo.getName(), desc);
        /* local variables | target obj | each oldvalue | */
        Bytecode code = new Bytecode(cp, 5, 3);
        // aload_0
        code.addAload(0);
        // getfield // get each field
        code.addOpcode(Opcode.GETFIELD);
        int base_field_index = cp.addFieldrefInfo(this_class_index, finfo
            .getName(), finfo.getDescriptor());
        code.addIndex(base_field_index);
        // aload_0
        code.addAload(0);
        // invokeinterface // invoke Enabled.getInterceptFieldCallback()
        int enabled_class_index = cp.addClassInfo(FIELD_HANDLED_TYPE_NAME);
        code.addInvokeinterface(enabled_class_index,
                                GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
                                1);
        // ifnonnull
        code.addOpcode(Opcode.IFNONNULL);
        code.addIndex(4);
        // *return // each type
        addTypeDependDataReturn(code, finfo.getDescriptor());
        // *store_1 // each type
        addTypeDependDataStore(code, finfo.getDescriptor(), 1);
        // aload_0
        code.addAload(0);
        // invokeinterface // invoke Enabled.getInterceptFieldCallback()
        code.addInvokeinterface(enabled_class_index,
                                GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
                                1);
        // aload_0
        code.addAload(0);
        // ldc // name of the field
        code.addLdc(finfo.getName());
        // *load_1 // each type
        addTypeDependDataLoad(code, finfo.getDescriptor(), 1);
        // invokeinterface // invoke Callback.read*() // each type
        addInvokeFieldHandlerMethod(classfile, code, finfo.getDescriptor(),
                                    true);
        // *return // each type
        addTypeDependDataReturn(code, finfo.getDescriptor());

        minfo.setCodeAttribute(code.toCodeAttribute());
        minfo.setAccessFlags(AccessFlag.PUBLIC);
        CodeAttribute codeAttribute = minfo.getCodeAttribute();
        if (codeAttribute != null) {
          StackMapTable smt = MapMaker.make(classPool, minfo);
          codeAttribute.setAttribute(smt);
    View Full Code Here

    Examples of javassist.bytecode.Bytecode

        int this_class_index = cp.getThisClassInfo();
        String desc = "(" + finfo.getDescriptor() + ")V";
        MethodInfo minfo = new MethodInfo(cp, EACH_WRITE_METHOD_PREFIX
                                              + finfo.getName(), desc);
        /* local variables | target obj | each oldvalue | */
        Bytecode code = new Bytecode(cp, 6, 3);
        // aload_0
        code.addAload(0);
        // invokeinterface // enabled.getInterceptFieldCallback()
        int enabled_class_index = cp.addClassInfo(FIELD_HANDLED_TYPE_NAME);
        code.addInvokeinterface(enabled_class_index,
                                GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
                                1);
        // ifnonnull (label1)
        code.addOpcode(Opcode.IFNONNULL);
        code.addIndex(9);
        // aload_0
        code.addAload(0);
        // *load_1
        addTypeDependDataLoad(code, finfo.getDescriptor(), 1);
        // putfield
        code.addOpcode(Opcode.PUTFIELD);
        int base_field_index = cp.addFieldrefInfo(this_class_index, finfo
            .getName(), finfo.getDescriptor());
        code.addIndex(base_field_index);
        code.growStack(-Descriptor.dataSize(finfo.getDescriptor()));
        // return ;
        code.addOpcode(Opcode.RETURN);
        // aload_0
        code.addAload(0);
        // dup
        code.addOpcode(Opcode.DUP);
        // invokeinterface // enabled.getInterceptFieldCallback()
        code.addInvokeinterface(enabled_class_index,
                                GETFIELDHANDLER_METHOD_NAME, GETFIELDHANDLER_METHOD_DESCRIPTOR,
                                1);
        // aload_0
        code.addAload(0);
        // ldc // field name
        code.addLdc(finfo.getName());
        // aload_0
        code.addAload(0);
        // getfield // old value of the field
        code.addOpcode(Opcode.GETFIELD);
        code.addIndex(base_field_index);
        code.growStack(Descriptor.dataSize(finfo.getDescriptor()) - 1);
        // *load_1
        addTypeDependDataLoad(code, finfo.getDescriptor(), 1);
        // invokeinterface // callback.write*(..)
        addInvokeFieldHandlerMethod(classfile, code, finfo.getDescriptor(),
                                    false);
        // putfield // new value of the field
        code.addOpcode(Opcode.PUTFIELD);
        code.addIndex(base_field_index);
        code.growStack(-Descriptor.dataSize(finfo.getDescriptor()));
        // return
        code.addOpcode(Opcode.RETURN);

        minfo.setCodeAttribute(code.toCodeAttribute());
        minfo.setAccessFlags(AccessFlag.PUBLIC);
        CodeAttribute codeAttribute = minfo.getCodeAttribute();
        if (codeAttribute != null) {
          StackMapTable smt = MapMaker.make(classPool, minfo);
          codeAttribute.setAttribute(smt);
    View Full Code Here

    Examples of javassist.bytecode.Bytecode

            if (clinit != null)
                return clinit;

            checkModify();
            ClassFile cf = getClassFile2();
            Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
            modifyClassConstructor(cf, code, 0, 0);
            return getClassInitializer();
        }
    View Full Code Here

    Examples of javassist.bytecode.Bytecode

            throws CannotCompileException, NotFoundException
        {
            if (fieldInitializers == null)
                return;

            Bytecode code = new Bytecode(cf.getConstPool(), 0, 0);
            Javac jv = new Javac(code, this);
            int stacksize = 0;
            boolean doInit = false;
            for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) {
                CtField f = fi.field;
    View Full Code Here

    Examples of javassist.bytecode.Bytecode

                MethodInfo minfo = (MethodInfo)list.get(i);
                if (minfo.isConstructor()) {
                    CodeAttribute codeAttr = minfo.getCodeAttribute();
                    if (codeAttr != null)
                        try {
                            Bytecode init = new Bytecode(cp, 0,
                                                    codeAttr.getMaxLocals());
                            CtClass[] params
                                = Descriptor.getParameterTypes(
                                                    minfo.getDescriptor(),
                                                    classPool);
    View Full Code Here

    Examples of javassist.bytecode.Bytecode

         *
         * @param thisClass         the class that a compiled method/field
         *                          belongs to.
         */
        public Javac(CtClass thisClass) {
            this(new Bytecode(thisClass.getClassFile2().getConstPool(), 0, 0),
                 thisClass);
        }
    View Full Code Here

    Examples of javassist.bytecode.Bytecode

        ConstPool cp = classfile.getConstPool();
        int this_class_index = cp.getThisClassInfo();
        MethodInfo minfo = new MethodInfo(cp, GETFIELDHANDLER_METHOD_NAME,
                                          GETFIELDHANDLER_METHOD_DESCRIPTOR);
        /* local variable | this | */
        Bytecode code = new Bytecode(cp, 2, 1);
        // aload_0 // load this
        code.addAload(0);
        // getfield // get field "$JAVASSIST_CALLBACK" defined already
        code.addOpcode(Opcode.GETFIELD);
        int field_index = cp.addFieldrefInfo(this_class_index,
                                             HANDLER_FIELD_NAME, HANDLER_FIELD_DESCRIPTOR);
        code.addIndex(field_index);
        // areturn // return the value of the field
        code.addOpcode(Opcode.ARETURN);
        minfo.setCodeAttribute(code.toCodeAttribute());
        minfo.setAccessFlags(AccessFlag.PUBLIC);
        classfile.addMethod(minfo);
      }
    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.