[jboss-cvs] javassist/src/main/javassist/compiler ...

Shigeru Chiba chiba at is.titech.ac.jp
Sat Jun 2 10:12:36 EDT 2007


  User: chiba   
  Date: 07/06/02 10:12:36

  Modified:    src/main/javassist/compiler    Javac.java CodeGen.java
                        MemberCodeGen.java
  Log:
  fixed bugs related to stack map tables.
  
  Revision  Changes    Path
  1.19      +13 -3     javassist/src/main/javassist/compiler/Javac.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Javac.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/compiler/Javac.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -b -r1.18 -r1.19
  --- Javac.java	11 Jan 2006 06:45:55 -0000	1.18
  +++ Javac.java	2 Jun 2007 14:12:36 -0000	1.19
  @@ -27,6 +27,7 @@
   import javassist.bytecode.Bytecode;
   import javassist.bytecode.CodeAttribute;
   import javassist.bytecode.LocalVariableAttribute;
  +import javassist.bytecode.BadBytecode;
   import javassist.bytecode.Opcode;
   import javassist.NotFoundException;
   
  @@ -89,8 +90,17 @@
           try {
               if (mem instanceof FieldDecl)
                   return compileField((FieldDecl)mem);
  -            else
  -                return compileMethod(p, (MethodDecl)mem);
  +            else {
  +                CtBehavior cb = compileMethod(p, (MethodDecl)mem);
  +                CtClass decl = cb.getDeclaringClass();
  +                cb.getMethodInfo2()
  +                  .rebuildStackMapIf6(decl.getClassPool(),
  +                                      decl.getClassFile2());
  +                return cb;
  +            }
  +        }
  +        catch (BadBytecode bb) {
  +            throw new CompileError(bb.getMessage());
           }
           catch (CannotCompileException e) {
               throw new CompileError(e.getMessage());
  @@ -128,7 +138,7 @@
           return f;
       }
   
  -    private CtMember compileMethod(Parser p, MethodDecl md)
  +    private CtBehavior compileMethod(Parser p, MethodDecl md)
           throws CompileError
       {
           int mod = MemberResolver.getModifiers(md.getModifiers());
  
  
  
  1.31      +20 -7     javassist/src/main/javassist/compiler/CodeGen.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CodeGen.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/compiler/CodeGen.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -b -r1.30 -r1.31
  --- CodeGen.java	12 May 2007 14:45:10 -0000	1.30
  +++ CodeGen.java	2 Jun 2007 14:12:36 -0000	1.31
  @@ -53,7 +53,13 @@
        */
       protected static abstract class ReturnHook {
           ReturnHook next;
  -        protected abstract void doit(Bytecode b, int opcode);
  +
  +        /**
  +         * Returns true if the generated code ends with return,
  +         * throw, or goto. 
  +         */
  +        protected abstract boolean doit(Bytecode b, int opcode);
  +
           protected ReturnHook(CodeGen gen) {
               next = gen.returnHooks;
               gen.returnHooks = this;
  @@ -607,7 +613,10 @@
           }
   
           for (ReturnHook har = returnHooks; har != null; har = har.next)
  -            har.doit(bytecode, op);
  +            if (har.doit(bytecode, op)) {
  +                hasReturned = true;
  +                return;
  +            }
   
           bytecode.addOpcode(op);
           hasReturned = true;
  @@ -645,9 +654,10 @@
           bc.addOpcode(MONITORENTER);
   
           ReturnHook rh = new ReturnHook(this) {
  -            protected void doit(Bytecode b, int opcode) {
  +            protected boolean doit(Bytecode b, int opcode) {
                   b.addAload(var);
                   b.addOpcode(MONITOREXIT);
  +                return false;
               }
           };
   
  @@ -665,10 +675,13 @@
               bc.addIndex(0);
           }
   
  +        if (pc < pc2) {         // if the body is not empty
           int pc4 = bc.currentPc();
           rh.doit(bc, 0);         // the 2nd arg is ignored.
           bc.addOpcode(ATHROW);
           bc.addExceptionHandler(pc, pc2, pc4, 0);
  +        }
  +
           if (!hasReturned)
               bc.write16bit(pc3, bc.currentPc() - pc3 + 1);
   
  
  
  
  1.30      +48 -6     javassist/src/main/javassist/compiler/MemberCodeGen.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MemberCodeGen.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/compiler/MemberCodeGen.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -b -r1.29 -r1.30
  --- MemberCodeGen.java	29 May 2007 09:33:53 -0000	1.29
  +++ MemberCodeGen.java	2 Jun 2007 14:12:36 -0000	1.30
  @@ -24,8 +24,6 @@
   /* Code generator methods depending on javassist.* classes.
    */
   public class MemberCodeGen extends CodeGen {
  -    public static final int JAVA5_VER = 49;
  -
       protected MemberResolver resolver;
       protected CtClass   thisClass;
       protected MethodInfo thisMethod;
  @@ -106,11 +104,11 @@
   
           private void jsrJmp(Bytecode b) {
               b.addOpcode(Opcode.GOTO);
  -            jsrList.add(new Integer(b.currentPc()));
  +            jsrList.add(new int[] {b.currentPc(), var});
               b.addIndex(0);
           }
   
  -        protected void doit(Bytecode b, int opcode) {
  +        protected boolean doit(Bytecode b, int opcode) {
               switch (opcode) {
               case Opcode.RETURN :
                   jsrJmp(b);
  @@ -143,6 +141,47 @@
               default :
                   throw new RuntimeException("fatal");
               }
  +
  +            return false;
  +        }
  +    }
  +
  +    static class JsrHook2 extends ReturnHook {
  +        int var;
  +        int target;
  +
  +        JsrHook2(CodeGen gen, int[] retTarget) {
  +            super(gen);
  +            target = retTarget[0];
  +            var = retTarget[1];
  +        }
  +
  +        protected boolean doit(Bytecode b, int opcode) {
  +            switch (opcode) {
  +            case Opcode.RETURN :
  +                break;
  +            case ARETURN :
  +                b.addAstore(var);
  +                break;
  +            case IRETURN :
  +                b.addIstore(var);
  +                break;
  +            case LRETURN :
  +                b.addLstore(var);
  +                break;
  +            case DRETURN :
  +                b.addDstore(var);
  +                break;
  +            case FRETURN :
  +                b.addFstore(var);
  +                break;
  +            default :
  +                throw new RuntimeException("fatal");
  +            }
  +
  +            b.addOpcode(Opcode.GOTO);
  +            b.addIndex(target - b.currentPc() + 3);
  +            return true;
           }
       }
   
  @@ -236,9 +275,12 @@
           Bytecode bc = bytecode;
           int n = returnList.size();
           for (int i = 0; i < n; ++i) {
  -            int pc = ((Integer)returnList.get(i)).intValue();
  +            final int[] ret = (int[])returnList.get(i);
  +            int pc = ret[0];
               bc.write16bit(pc, bc.currentPc() - pc + 1);
  +            ReturnHook hook = new JsrHook2(this, ret);
               finallyBlock.accept(this);
  +            hook.remove(this);
               if (!hasReturned) {
                   bc.addOpcode(Opcode.GOTO);
                   bc.addIndex(pc + 3 - bc.currentPc());
  @@ -923,7 +965,7 @@
       }
   
       protected void atClassObject2(String cname) throws CompileError {
  -        if (getMajorVersion() < JAVA5_VER)
  +        if (getMajorVersion() < ClassFile.JAVA_5)
               super.atClassObject2(cname);
           else
               bytecode.addLdc(bytecode.getConstPool().addClassInfo(cname));
  
  
  



More information about the jboss-cvs-commits mailing list