Package javassist.bytecode

Examples of javassist.bytecode.CodeIterator


/*     */   public boolean callsSuper()
/*     */     throws CannotCompileException
/*     */   {
/* 185 */     CodeAttribute codeAttr = this.methodInfo.getCodeAttribute();
/* 186 */     if (codeAttr != null) {
/* 187 */       CodeIterator it = codeAttr.iterator();
/*     */       try {
/* 189 */         int index = it.skipSuperConstructor();
/* 190 */         return index >= 0;
/*     */       }
/*     */       catch (BadBytecode e) {
/* 193 */         throw new CannotCompileException(e);
/*     */       }
View Full Code Here


/* 248 */     cc.checkModify();
/* 249 */     if (isClassInitializer()) {
/* 250 */       throw new CannotCompileException("class initializer");
/*     */     }
/* 252 */     CodeAttribute ca = this.methodInfo.getCodeAttribute();
/* 253 */     CodeIterator iterator = ca.iterator();
/* 254 */     Bytecode b = new Bytecode(this.methodInfo.getConstPool(), ca.getMaxStack(), ca.getMaxLocals());
/*     */
/* 256 */     b.setStackDepth(ca.getMaxStack());
/* 257 */     Javac jv = new Javac(b, cc);
/*     */     try {
/* 259 */       jv.recordParams(getParameterTypes(), false);
/* 260 */       jv.compileStmnt(src);
/* 261 */       ca.setMaxStack(b.getMaxStack());
/* 262 */       ca.setMaxLocals(b.getMaxLocals());
/* 263 */       iterator.skipConstructor();
/* 264 */       int pos = iterator.insertEx(b.get());
/* 265 */       iterator.insert(b.getExceptionTable(), pos);
/* 266 */       this.methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
/*     */     }
/*     */     catch (NotFoundException e) {
/* 269 */       throw new CannotCompileException(e);
/*     */     }
View Full Code Here

/*     */   }
/*     */
/*     */   int getStartPosOfBody(CodeAttribute ca)
/*     */     throws CannotCompileException
/*     */   {
/* 283 */     CodeIterator ci = ca.iterator();
/*     */     try {
/* 285 */       ci.skipConstructor();
/* 286 */       return ci.next();
/*     */     } catch (BadBytecode e) {
/*     */     }
/* 289 */     throw new CannotCompileException(e);
/*     */   }
View Full Code Here

/*     */   }
/*     */
/*     */   private static void removeConsCall(CodeAttribute ca)
/*     */     throws CannotCompileException
/*     */   {
/* 374 */     CodeIterator iterator = ca.iterator();
/*     */     try {
/* 376 */       int pos = iterator.skipConstructor();
/* 377 */       if (pos >= 0) {
/* 378 */         int mref = iterator.u16bitAt(pos + 1);
/* 379 */         String desc = ca.getConstPool().getMethodrefType(mref);
/* 380 */         int num = Descriptor.numOfParameters(desc) + 1;
/* 381 */         if (num > 3) {
/* 382 */           pos = iterator.insertGapAt(pos, num - 3, false).position;
/*     */         }
/* 384 */         iterator.writeByte(87, pos++);
/* 385 */         iterator.writeByte(0, pos);
/* 386 */         iterator.writeByte(0, pos + 1);
/* 387 */         Descriptor.Iterator it = new Descriptor.Iterator(desc);
/*     */         while (true) {
/* 389 */           it.next();
/* 390 */           if (!it.isParameter()) break;
/* 391 */           iterator.writeByte(it.is2byte() ? 88 : 87, pos++);
/*     */         }
/*     */
/*     */       }
/*     */
/*     */     }
View Full Code Here

/*     */   }
/*     */
/*     */   public void initialize(ConstPool cp, CtClass clazz, MethodInfo minfo)
/*     */     throws CannotCompileException
/*     */   {
/*  62 */     CodeIterator iterator = minfo.getCodeAttribute().iterator();
/*  63 */     while (iterator.hasNext())
/*     */       try {
/*  65 */         int pos = iterator.next();
/*  66 */         int c = iterator.byteAt(pos);
/*     */
/*  68 */         if (c == 50) {
/*  69 */           initFrames(clazz, minfo);
/*     */         }
/*  71 */         if ((c == 50) || (c == 51) || (c == 52) || (c == 49) || (c == 48) || (c == 46) || (c == 47) || (c == 53))
View Full Code Here

/* 1489 */       CodeAttribute codeAttr = m.getCodeAttribute();
/* 1490 */       if (codeAttr == null)
/* 1491 */         throw new CannotCompileException("empty <clinit>");
/*      */       try
/*      */       {
/* 1494 */         CodeIterator it = codeAttr.iterator();
/* 1495 */         int pos = it.insertEx(code.get());
/* 1496 */         it.insert(code.getExceptionTable(), pos);
/* 1497 */         int maxstack = codeAttr.getMaxStack();
/* 1498 */         if (maxstack < stacksize) {
/* 1499 */           codeAttr.setMaxStack(stacksize);
/*      */         }
/* 1501 */         int maxlocals = codeAttr.getMaxLocals();
View Full Code Here

/*      */   }
/*      */
/*      */   private static void insertAuxInitializer(CodeAttribute codeAttr, Bytecode initializer, int stacksize)
/*      */     throws BadBytecode
/*      */   {
/* 1555 */     CodeIterator it = codeAttr.iterator();
/* 1556 */     int index = it.skipSuperConstructor();
/* 1557 */     if (index < 0) {
/* 1558 */       index = it.skipThisConstructor();
/* 1559 */       if (index >= 0) {
/* 1560 */         return;
/*      */       }
/*      */
/*      */     }
/*      */
/* 1565 */     int pos = it.insertEx(initializer.get());
/* 1566 */     it.insert(initializer.getExceptionTable(), pos);
/* 1567 */     int maxstack = codeAttr.getMaxStack();
/* 1568 */     if (maxstack < stacksize)
/* 1569 */       codeAttr.setMaxStack(stacksize);
/*      */   }
View Full Code Here

        Frame frame = frames[pos];
        assertEquals("java.lang.Object", frame.getLocal(2).getCtClass().getName());
    }

    private static int findOpcode(MethodInfo info, int opcode) throws BadBytecode {
        CodeIterator iter = info.getCodeAttribute().iterator();

        // find return
        int pos = 0;
        while (iter.hasNext()) {
            pos = iter.next();
            if (iter.byteAt(pos) == opcode)
                break;
        }
        return pos;
    }
View Full Code Here

    }


    private static void verifyReturn(CtMethod method, String expected) throws BadBytecode {
        MethodInfo info = method.getMethodInfo2();
        CodeIterator iter = info.getCodeAttribute().iterator();

        // find areturn
        int pos = 0;
        while (iter.hasNext()) {
            pos = iter.next();
            if (iter.byteAt(pos) == Opcode.ARETURN)
                break;
        }

        Analyzer analyzer = new Analyzer();
        Frame[] frames = analyzer.analyze(method.getDeclaringClass(), info);
View Full Code Here

    }

    private static void verifyArrayLoad(CtClass clazz, CtMethod method, String component)
            throws BadBytecode {
        MethodInfo info = method.getMethodInfo2();
        CodeIterator iter = info.getCodeAttribute().iterator();

        // find aaload
        int pos = 0;
        while (iter.hasNext()) {
            pos = iter.next();
            if (iter.byteAt(pos) == Opcode.AALOAD)
                break;
        }

        Analyzer analyzer = new Analyzer();
        Frame[] frames = analyzer.analyze(clazz, info);
        assertNotNull(frames);
        Frame frame = frames[pos];
        assertNotNull(frame);

        Type type = frame.getStack(frame.getTopIndex() - 1);
        assertEquals(component + "[]", type.getCtClass().getName());

        pos = iter.next();
        frame = frames[pos];
        assertNotNull(frame);

        type = frame.getStack(frame.getTopIndex());
        assertEquals(component, type.getCtClass().getName());
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.