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

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


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

  Modified:    src/main/javassist/bytecode   MethodInfo.java ClassFile.java
  Log:
  fixed bugs related to stack map tables.
  
  Revision  Changes    Path
  1.25      +36 -0     javassist/src/main/javassist/bytecode/MethodInfo.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: MethodInfo.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/bytecode/MethodInfo.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -b -r1.24 -r1.25
  --- MethodInfo.java	8 Mar 2007 13:05:47 -0000	1.24
  +++ MethodInfo.java	2 Jun 2007 14:12:35 -0000	1.25
  @@ -21,6 +21,8 @@
   import java.util.LinkedList;
   import java.util.List;
   import java.util.Map;
  +import javassist.ClassPool;
  +import javassist.bytecode.stackmap.MapMaker;
   
   /**
    * <code>method_info</code> structure.
  @@ -371,6 +373,40 @@
       }
   
       /**
  +     * Rebuilds a stack map table if the class file is for Java 6
  +     * or later.  Java 5 or older Java VMs do not recognize a stack
  +     * map table. 
  +     *
  +     * @param pool          used for making type hierarchy.
  +     * @param cf            rebuild if this class file is for Java 6 or later.
  +     * @see #rebuildStackMap(ClassPool)
  +     * @since 3.6
  +     */
  +    public void rebuildStackMapIf6(ClassPool pool, ClassFile cf)
  +        throws BadBytecode
  +    {
  +        if (cf.getMajorVersion() >= ClassFile.JAVA_6)
  +            rebuildStackMap(pool);
  +    }
  +
  +    /**
  +     * Rebuilds a stack map table.  If no stack map table is included,
  +     * a new one is created.  If this <code>MethodInfo</code> does not
  +     * include a code attribute, nothing happens.
  +     *
  +     * @param pool          used for making type hierarchy.
  +     * @see StackMapTable
  +     * @since 3.6
  +     */
  +    public void rebuildStackMap(ClassPool pool) throws BadBytecode {
  +        CodeAttribute ca = getCodeAttribute();
  +        if (ca != null) {
  +            StackMapTable smt = MapMaker.make(pool, this);
  +            ca.setAttribute(smt);
  +        }
  +    }
  +
  +    /**
        * Returns the line number of the source line corresponding to the specified
        * bytecode contained in this method.
        * 
  
  
  
  1.33      +47 -9     javassist/src/main/javassist/bytecode/ClassFile.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ClassFile.java
  ===================================================================
  RCS file: /cvsroot/jboss/javassist/src/main/javassist/bytecode/ClassFile.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -b -r1.32 -r1.33
  --- ClassFile.java	29 May 2007 09:33:52 -0000	1.32
  +++ ClassFile.java	2 Jun 2007 14:12:35 -0000	1.33
  @@ -46,10 +46,28 @@
       String cachedSuperclass;
   
       /**
  +     * The major version number of class files
  +     * for JDK 1.3.
  +     */
  +    public static final int JAVA_3 = 47;
  +
  +    /**
  +     * The major version number of class files
  +     * for JDK 1.5.
  +     */
  +    public static final int JAVA_5 = 49;
  +
  +    /**
  +     * The major version number of class files
  +     * for JDK 1.6.
  +     */
  +    public static final int JAVA_6 = 50;
  +
  +    /**
        * The major version number of class files created
        * from scratch.  The value is 47 (JDK 1.3).
        */
  -    public static final int MAJOR_VERSION = 47;
  +    public static final int MAJOR_VERSION = JAVA_3;
   
       /**
        * Constructs a class file from a byte stream.
  @@ -540,6 +558,8 @@
   
       /**
        * Appends a method to the class.
  +     * If there is a bridge method with the same name and signature,
  +     * then the bridge method is removed before a new method is added.
        *
        * @throws DuplicateMemberException         when the method is already included.
        */
  @@ -558,20 +578,38 @@
           String name = newMinfo.getName();
           String descriptor = newMinfo.getDescriptor();
           ListIterator it = methods.listIterator(0);
  -        while (it.hasNext()) {
  -            MethodInfo minfo = (MethodInfo)it.next();
  -            if (minfo.getName().equals(name)
  -                    && notBridgeMethod(minfo) && notBridgeMethod(newMinfo)
  -                    && Descriptor.eqParamTypes(minfo.getDescriptor(),
  -                                               descriptor))
  +        while (it.hasNext())
  +            if (isDuplicated(newMinfo, name, descriptor, (MethodInfo)it.next(), it))
                   throw new DuplicateMemberException("duplicate method: " + name
                                                    + " in " + this.getName());
           }
  +
  +    private static boolean isDuplicated(MethodInfo newMethod, String newName,
  +                                        String newDesc, MethodInfo minfo,
  +                                        ListIterator it)
  +    {
  +        if (!minfo.getName().equals(newName))
  +            return false;
  +
  +        String desc = minfo.getDescriptor();
  +        if (!Descriptor.eqParamTypes(desc, newDesc))
  +           return false;
  +
  +        if (desc.equals(newDesc)) {
  +            if (notBridgeMethod(minfo))
  +                return true;
  +            else {
  +                it.remove();
  +                return false;
  +            }
  +        }
  +        else
  +           return notBridgeMethod(minfo) && notBridgeMethod(newMethod);
       }
   
       /* For a bridge method, see Sec. 15.12.4.5 of JLS 3rd Ed.
        */
  -    private boolean notBridgeMethod(MethodInfo minfo) {
  +    private static boolean notBridgeMethod(MethodInfo minfo) {
           return (minfo.getAccessFlags() & AccessFlag.BRIDGE) == 0;
       }
   
  
  
  



More information about the jboss-cvs-commits mailing list