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

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       CtBehavior.java CtConstructor.java
                        CtNewConstructor.java CtClassType.java
                        CtNewWrappedMethod.java CtMethod.java
  Log:
  fixed bugs related to stack map tables.
  
  Revision  Changes    Path
  1.36      +35 -11    javassist/src/main/javassist/CtBehavior.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CtBehavior.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtBehavior.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -b -r1.35 -r1.36
  --- CtBehavior.java	25 May 2007 07:45:07 -0000	1.35
  +++ CtBehavior.java	2 Jun 2007 14:12:36 -0000	1.36
  @@ -62,6 +62,7 @@
                           map.put(srcSuperName, destSuperName);
               }
   
  +            // a stack map table is copied from srcInfo.
               methodInfo = new MethodInfo(cp, srcInfo.getName(), srcInfo, map);
               if (isCons && patch)
                   methodInfo.setSuperclass(destSuperName);
  @@ -349,9 +350,10 @@
                           String delegateObj, String delegateMethod)
           throws CannotCompileException
       {
  -        declaringClass.checkModify();
  +        CtClass cc = declaringClass;
  +        cc.checkModify();
           try {
  -            Javac jv = new Javac(declaringClass);
  +            Javac jv = new Javac(cc);
               if (delegateMethod != null)
                   jv.recordProceed(delegateObj, delegateMethod);
   
  @@ -359,9 +361,12 @@
               methodInfo.setCodeAttribute(b.toCodeAttribute());
               methodInfo.setAccessFlags(methodInfo.getAccessFlags()
                                         & ~AccessFlag.ABSTRACT);
  +            methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
           }
           catch (CompileError e) {
               throw new CannotCompileException(e);
  +        } catch (BadBytecode e) {
  +            throw new CannotCompileException(e);
           }
       }
   
  @@ -380,6 +385,7 @@
                   ConstPool cp = destInfo.getConstPool();
                   CodeAttribute ca = (CodeAttribute)cattr.copy(cp, map);
                   destInfo.setCodeAttribute(ca);
  +                // a stack map table is copied to destInfo.
               }
           }
           catch (CodeAttribute.RuntimeCopyException e) {
  @@ -466,7 +472,7 @@
               CtField field = new CtField(type, fname, cc);
               field.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
               cc.addField(field, CtField.Initializer.byNew(type));
  -            insertBefore(fname + ".enter();");
  +            insertBefore(fname + ".enter();", false);
               String src = fname + ".exit();";
               insertAfter(src, true);
           }
  @@ -561,13 +567,20 @@
        * @see CtConstructor#insertBeforeBody(String)
        */
       public void insertBefore(String src) throws CannotCompileException {
  -        declaringClass.checkModify();
  +        insertBefore(src, true);
  +    }
  +
  +    private void insertBefore(String src, boolean rebuild)
  +        throws CannotCompileException
  +    {
  +        CtClass cc = declaringClass;
  +        cc.checkModify();
           CodeAttribute ca = methodInfo.getCodeAttribute();
           if (ca == null)
               throw new CannotCompileException("no method body");
   
           CodeIterator iterator = ca.iterator();
  -        Javac jv = new Javac(declaringClass);
  +        Javac jv = new Javac(cc);
           try {
               int nvars = jv.recordParams(getParameterTypes(),
                                           Modifier.isStatic(getModifiers()));
  @@ -586,6 +599,8 @@
   
               int pos = iterator.insertEx(b.get());
               iterator.insert(b.getExceptionTable(), pos);
  +            if (rebuild)
  +                methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
           }
           catch (NotFoundException e) {
               throw new CannotCompileException(e);
  @@ -627,7 +642,8 @@
       public void insertAfter(String src, boolean asFinally)
           throws CannotCompileException
       {
  -        declaringClass.checkModify();
  +        CtClass cc = declaringClass;
  +        cc.checkModify();
           ConstPool pool = methodInfo.getConstPool();
           CodeAttribute ca = methodInfo.getCodeAttribute();
           if (ca == null)
  @@ -637,7 +653,7 @@
           int retAddr = ca.getMaxLocals();
           Bytecode b = new Bytecode(pool, 0, retAddr + 1);
           b.setStackDepth(ca.getMaxStack() + 1);
  -        Javac jv = new Javac(b, declaringClass);
  +        Javac jv = new Javac(b, cc);
           try {
               int nvars = jv.recordParams(getParameterTypes(),
                                           Modifier.isStatic(getModifiers()));
  @@ -677,6 +693,8 @@
                       subr = iterator.getCodeLength() - gapLen;
                   }
               }
  +
  +            methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
           }
           catch (NotFoundException e) {
               throw new CannotCompileException(e);
  @@ -855,13 +873,14 @@
                            String exceptionName)
           throws CannotCompileException
       {
  -        declaringClass.checkModify();
  +        CtClass cc = declaringClass;
  +        cc.checkModify();
           ConstPool cp = methodInfo.getConstPool();
           CodeAttribute ca = methodInfo.getCodeAttribute();
           CodeIterator iterator = ca.iterator();
           Bytecode b = new Bytecode(cp, ca.getMaxStack(), ca.getMaxLocals());
           b.setStackDepth(1);
  -        Javac jv = new Javac(b, declaringClass);
  +        Javac jv = new Javac(b, cc);
           try {
               jv.recordParams(getParameterTypes(),
                               Modifier.isStatic(getModifiers()));
  @@ -883,12 +902,15 @@
               ca.getExceptionTable().add(getStartPosOfBody(ca), len, len,
                                          cp.addClassInfo(exceptionType));
               iterator.append(b.getExceptionTable(), pos);
  +            methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
           }
           catch (NotFoundException e) {
               throw new CannotCompileException(e);
           }
           catch (CompileError e) {
               throw new CannotCompileException(e);
  +        } catch (BadBytecode e) {
  +            throw new CannotCompileException(e);
           }
       }
   
  @@ -961,9 +983,10 @@
           if (!modify)
               return lineNum;
   
  -        declaringClass.checkModify();
  +        CtClass cc = declaringClass;
  +        cc.checkModify();
           CodeIterator iterator = ca.iterator();
  -        Javac jv = new Javac(declaringClass);
  +        Javac jv = new Javac(cc);
           try {
               jv.recordLocalVariables(ca, index);
               jv.recordParams(getParameterTypes(),
  @@ -983,6 +1006,7 @@
   
               iterator.insert(index, b.get());
               iterator.insert(b.getExceptionTable(), index);
  +            methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
               return lineNum;
           }
           catch (NotFoundException e) {
  
  
  
  1.19      +14 -4     javassist/src/main/javassist/CtConstructor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CtConstructor.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtConstructor.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -b -r1.18 -r1.19
  --- CtConstructor.java	23 Nov 2006 02:49:03 -0000	1.18
  +++ CtConstructor.java	2 Jun 2007 14:12:36 -0000	1.19
  @@ -44,7 +44,7 @@
        * must be added to a class with <code>CtClass.addConstructor()</code>.
        *
        * <p>The created constructor does not include a constructor body,
  -     * must be specified with <code>setBody()</code>.
  +     * which must be specified with <code>setBody()</code>.
        *
        * @param declaring         the class to which the created method is added.
        * @param parameters        a list of the parameter types
  @@ -244,7 +244,8 @@
        *                  It must be a single statement or block.
        */
       public void insertBeforeBody(String src) throws CannotCompileException {
  -        declaringClass.checkModify();
  +        CtClass cc = declaringClass;
  +        cc.checkModify();
           if (isClassInitializer())
               throw new CannotCompileException("class initializer");
   
  @@ -253,7 +254,7 @@
           Bytecode b = new Bytecode(methodInfo.getConstPool(),
                                     ca.getMaxStack(), ca.getMaxLocals());
           b.setStackDepth(ca.getMaxStack());
  -        Javac jv = new Javac(b, declaringClass);
  +        Javac jv = new Javac(b, cc);
           try {
               jv.recordParams(getParameterTypes(), false);
               jv.compileStmnt(src);
  @@ -262,6 +263,7 @@
               iterator.skipConstructor();
               int pos = iterator.insertEx(b.get());
               iterator.insert(b.getExceptionTable(), pos);
  +            methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
           }
           catch (NotFoundException e) {
               throw new CannotCompileException(e);
  @@ -346,8 +348,16 @@
           if (isConstructor()) {
               MethodInfo minfo = method.getMethodInfo2();
               CodeAttribute ca = minfo.getCodeAttribute();
  -            if (ca != null)
  +            if (ca != null) {
                   removeConsCall(ca);
  +                try {
  +                    methodInfo.rebuildStackMapIf6(declaring.getClassPool(),
  +                                                  declaring.getClassFile2());
  +                }
  +                catch (BadBytecode e) {
  +                    throw new CannotCompileException(e);
  +                }
  +            }
           }
   
           method.setName(name);
  
  
  
  1.11      +4 -1      javassist/src/main/javassist/CtNewConstructor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CtNewConstructor.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtNewConstructor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- CtNewConstructor.java	11 Jan 2006 06:45:54 -0000	1.10
  +++ CtNewConstructor.java	2 Jun 2007 14:12:36 -0000	1.11
  @@ -67,9 +67,11 @@
           Javac compiler = new Javac(declaring);
           try {
               CtMember obj = compiler.compile(src);
  -            if (obj instanceof CtConstructor)
  +            if (obj instanceof CtConstructor) {
  +                // a stack map table has been already created.
                   return (CtConstructor)obj;
           }
  +        }
           catch (CompileError e) {
               throw new CannotCompileException(e);
           }
  @@ -145,6 +147,7 @@
   
           code.add(Bytecode.RETURN);
   
  +        // no need to construct a stack map table.
           cons.getMethodInfo2().setCodeAttribute(code.toCodeAttribute());
           return cons;
       }
  
  
  
  1.55      +8 -0      javassist/src/main/javassist/CtClassType.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CtClassType.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtClassType.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -b -r1.54 -r1.55
  --- CtClassType.java	5 May 2007 03:47:52 -0000	1.54
  +++ CtClassType.java	2 Jun 2007 14:12:36 -0000	1.55
  @@ -1350,6 +1350,13 @@
                   throw new CannotCompileException(e);
               }
           }
  +
  +        try {
  +            m.rebuildStackMapIf6(classPool, cf);
  +        }
  +        catch (BadBytecode e) {
  +            throw new CannotCompileException(e);
  +        }
       }
   
       private void modifyConstructors(ClassFile cf)
  @@ -1375,6 +1382,7 @@
                                                   classPool);
                           int stacksize = makeFieldInitializer(init, params);
                           insertAuxInitializer(codeAttr, init, stacksize);
  +                        minfo.rebuildStackMapIf6(classPool, cf);
                       }
                       catch (BadBytecode e) {
                           throw new CannotCompileException(e);
  
  
  
  1.9       +4 -0      javassist/src/main/javassist/CtNewWrappedMethod.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CtNewWrappedMethod.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtNewWrappedMethod.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- CtNewWrappedMethod.java	11 Jan 2006 06:45:54 -0000	1.8
  +++ CtNewWrappedMethod.java	2 Jun 2007 14:12:36 -0000	1.9
  @@ -63,6 +63,9 @@
           return code;
       }
   
  +    /* The generated method body does not need a stack map table
  +     * because it does not contain a branch instruction.
  +     */
       protected static int makeBody0(CtClass clazz, ClassFile classfile,
                                      CtMethod wrappedBody,
                                      boolean isStatic, CtClass[] parameters,
  @@ -146,6 +149,7 @@
                                                map);
               int acc = body.getAccessFlags();
               body.setAccessFlags(AccessFlag.setPrivate(acc));
  +            // a stack map is copied.  rebuilding it is not needed. 
               classfile.addMethod(body);
               bodies.put(src, bodyname);
           }
  
  
  
  1.16      +1 -0      javassist/src/main/javassist/CtMethod.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CtMethod.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/CtMethod.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -b -r1.15 -r1.16
  --- CtMethod.java	23 Nov 2006 02:49:03 -0000	1.15
  +++ CtMethod.java	2 Jun 2007 14:12:36 -0000	1.16
  @@ -262,6 +262,7 @@
           methodInfo.setCodeAttribute(cattr);
           methodInfo.setAccessFlags(methodInfo.getAccessFlags()
                                     & ~AccessFlag.ABSTRACT);
  +        // rebuilding a stack map table is not needed.
       }
   
       // inner classes
  
  
  



More information about the jboss-cvs-commits mailing list