Package javassist.bytecode

Examples of javassist.bytecode.CodeIterator


      }
      CodeAttribute codeAttr = minfo.getCodeAttribute();
      if (codeAttr == null) {
        return;
      }
      CodeIterator iter = codeAttr.iterator();
      while (iter.hasNext()) {
        try {
          int pos = iter.next();
          pos = transformInvokevirtualsIntoGetfields(classfile, iter, pos);
          pos = transformInvokevirtualsIntoPutfields(classfile, iter, pos);

        } catch (BadBytecode e) {
          throw new CannotCompileException(e);
View Full Code Here


      final CodeAttribute codeAttr = methodInfo.getCodeAttribute();
      if ( codeAttr == null ) {
        continue;
      }

      final CodeIterator iter = codeAttr.iterator();
      while ( iter.hasNext() ) {
        int pos = iter.next();
        pos = transformInvokevirtualsIntoGetfields( classfile, iter, pos );
        transformInvokevirtualsIntoPutfields( classfile, iter, pos );
      }
      final StackMapTable smt = MapMaker.make( classPool, methodInfo );
      codeAttr.setAttribute( smt );
View Full Code Here

      }
      CodeAttribute codeAttr = minfo.getCodeAttribute();
      if (codeAttr == null) {
        return;
      }
      CodeIterator iter = codeAttr.iterator();
      while (iter.hasNext()) {
        try {
          int pos = iter.next();
          pos = transformInvokevirtualsIntoGetfields(classfile, iter, pos);
          pos = transformInvokevirtualsIntoPutfields(classfile, iter, pos);

        } catch (BadBytecode e) {
          throw new CannotCompileException(e);
View Full Code Here

      }
      CodeAttribute codeAttr = minfo.getCodeAttribute();
      if (codeAttr == null) {
        continue;
      }
      CodeIterator iter = codeAttr.iterator();
      while (iter.hasNext()) {
        try {
          int pos = iter.next();
          pos = transformInvokevirtualsIntoGetfields(classfile, iter,
                                                     pos);
          pos = transformInvokevirtualsIntoPutfields(classfile, iter,
                                                     pos);
View Full Code Here

        // would indicate an abstract method, continue to next method
        continue;
      }

      try {
        final CodeIterator itr = codeAttr.iterator();
        while ( itr.hasNext() ) {
          final int index = itr.next();
          final int op = itr.byteAt( index );
          if ( op != Opcode.PUTFIELD && op != Opcode.GETFIELD ) {
            continue;
          }

          final int constIndex = itr.u16bitAt( index + 1 );

          final String fieldName = constPool.getFieldrefName( constIndex );
          final PersistentAttributeDescriptor attributeDescriptor = attributeDescriptorMap.get( fieldName );

          if ( attributeDescriptor == null ) {
            // its not a field we have enhanced for interception, so skip it
            continue;
          }

          log.tracef(
              "Transforming access to field [%s] from method [%s]",
              fieldName,
              methodName
          );

          if ( op == Opcode.GETFIELD ) {
            final int readMethodIndex = constPool.addMethodrefInfo(
                constPool.getThisClassInfo(),
                attributeDescriptor.getReader().getName(),
                attributeDescriptor.getReader().getSignature()
            );
            itr.writeByte( Opcode.INVOKESPECIAL, index );
            itr.write16bit( readMethodIndex, index + 1 );
          }
          else {
            final int writeMethodIndex = constPool.addMethodrefInfo(
                constPool.getThisClassInfo(),
                attributeDescriptor.getWriter().getName(),
                attributeDescriptor.getWriter().getSignature()
            );
            itr.writeByte( Opcode.INVOKESPECIAL, index );
            itr.write16bit( writeMethodIndex, index + 1 );
          }
        }

        final StackMapTable smt = MapMaker.make( classPool, methodInfo );
        methodInfo.getCodeAttribute().setAttribute( smt );
View Full Code Here

          bc.addAload(0);
          bc.addGetfield(cc, "_counter", "I");
          bc.add(Bytecode.ICONST_1);
          bc.add(Bytecode.IADD);
          bc.addPutfield(cc, "_counter", "I");
          CodeIterator iter = info.getCodeAttribute().iterator();
          iter.begin();
          iter.insert(bc.get());
        }
      }
    }
    return cc.toBytecode();
  }
View Full Code Here

                    //but we need a strong ref
                    Bytecode code = new Bytecode(file.getConstPool());
                    code.addAload(0);
                    code.addAload(beanArgument);
                    code.addInvokestatic(WeldClassChangeAware.class.getName(), "addProxyFactory", "(Lorg/jboss/weld/bean/proxy/ProxyFactory;)V");
                    CodeIterator it = method.getCodeAttribute().iterator();
                    try {
                        it.skipConstructor();
                        it.insert(code.get());
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            }
View Full Code Here

   public static void rewriteLDC(ConstPool constPool, MethodInfo method) throws BadBytecode
   {
      CodeAttribute code = method.getCodeAttribute();
      if (code == null)
         return;
      CodeIterator iterator = code.iterator();
      while (iterator.hasNext())
      {
         int index = iterator.next();
         int op = iterator.byteAt(index);

         if (op == Opcode.LDC || op == Opcode.LDC_W)
         {
            int index0 = iterator.byteAt(index + 1);
            int constIndex = index0;
            if (op == Opcode.LDC_W)
            {
               int index1 = iterator.byteAt(index + 2);
               constIndex = (index0 << 8) + index1;
            }
            if (7 == constPool.getTag(constIndex))
            {
               String className = constPool.getClassInfo(constIndex);
               int theClassName = constPool.addStringInfo(className.replace('/', '.'));
               if (op == Opcode.LDC_W)
               {
                  int b0 = theClassName >>> 8;
                  int b1 = theClassName & 0x0FF;
                  iterator.writeByte(b0, index + 1);
                  iterator.writeByte(b1, index + 2);
               }
               else
               {
                  iterator.writeByte(theClassName, index + 1);
               }
               int classClass = constPool.addClassInfo("java/lang/Class");
               int descriptor = constPool.addMethodrefInfo(classClass, "forName",
                     "(Ljava/lang/String;)Ljava/lang/Class;");
               iterator.insert(new byte[]
               {(byte) Opcode.INVOKESTATIC, (byte) (descriptor >>> 8), (byte) descriptor});
            }
         }
      }
   }
View Full Code Here

      }
      CodeAttribute codeAttr = minfo.getCodeAttribute();
      if (codeAttr == null) {
        continue;
      }
      CodeIterator iter = codeAttr.iterator();
      while (iter.hasNext()) {
        int pos = iter.next();
        pos = transformInvokevirtualsIntoGetfields(classfile, iter, pos);
        pos = transformInvokevirtualsIntoPutfields(classfile, iter, pos);
      }
      StackMapTable smt = MapMaker.make(classPool, minfo);
      codeAttr.setAttribute(smt);
View Full Code Here

         * if the attribute values were updated correctly, we would have to
         * detect it, and redo analysis, which is not cheap. Instead, we are
         * better off doing all changes in initialize() before everyone else has
         * a chance to muck things up.
         */
        CodeIterator iterator = minfo.getCodeAttribute().iterator();
        while (iterator.hasNext()) {
            try {
                int pos = iterator.next();
                int c = iterator.byteAt(pos);

                if (c == AALOAD)
                    initFrames(clazz, minfo);

                if (c == AALOAD || c == BALOAD || c == CALOAD || c == DALOAD
View Full Code Here

TOP

Related Classes of javassist.bytecode.CodeIterator

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.