]> source.dussan.org Git - javassist.git/commitdiff
fixed a performance bug caused by many calls to CtBehavior#setBody()
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Thu, 3 Jul 2008 07:56:24 +0000 (07:56 +0000)
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>
Thu, 3 Jul 2008 07:56:24 +0000 (07:56 +0000)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@448 30ef5769-5b8d-40dd-aea6-55b5d6557bb3

Readme.html
build.xml
pom.xml
src/main/javassist/CtBehavior.java
src/main/javassist/CtClass.java
src/main/javassist/CtClassType.java

index a1255c4c2b26890fbb6a1298d5b24ed26edf51eb..a95a13d36b5da84e94e13595e4ab36d492125aab 100644 (file)
@@ -281,6 +281,11 @@ see javassist.Dump.
 
 <h2>Changes</h2>
 
+<p>-version 3.8.1
+<ul>
+       <li>CtClass.rebuildClassFile() has been added.
+</ul>
+
 <p>-version 3.8.0 on June 13, 2008
 <ul>
     <li>javassist.bytecode.analysis was implemented.
index 978f9b9dfb3a5a3619d76ad1757425bb0b55edb8..8b83224be60700d0cbc14708cb9ff0b07a8fd17d 100644 (file)
--- a/build.xml
+++ b/build.xml
@@ -180,14 +180,13 @@ Copyright (C) 1999-2008 Shigeru Chiba. All Rights Reserved.</i>]]></bottom>
     <delete file="${dist-version}.zip"/>
     <zip zipfile="${dist-version}.zip">
        <zipfileset dir="${basedir}" prefix="${dist-version}">
-          <include name="**"/>
-          <exclude name=".*"/>
-          <exclude name=".*/**"/>
-          <exclude name="build/**"/>
-                 <exclude name="local/**"/>
-                 <exclude name="eclipse-output/**"/>
-          <exclude name="${dist-version}.zip"/>
-          <exclude name="${target-src.jar}"/>
+                 <include name="html/**"/>
+                 <include name="sample/**"/>
+                 <include name="src/**"/>
+                 <include name="tutorial/**"/>
+                 <include name="*.html"/>
+                 <include name="*.xml"/>
+                 <include name="${target.jar}"/>
        </zipfileset>
     </zip>
   </target>
diff --git a/pom.xml b/pom.xml
index 56ac587cefc6e16f5d9d50f19f021d13b4992aee..678c0c7a8a2da47b4dfc036a72b7a1db04e396fe 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -1,13 +1,8 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>org.jboss</groupId>
-    <artifactId>jboss-parent</artifactId>
-    <version>3</version>
-  </parent>
   <modelVersion>4.0.0</modelVersion>
-  <groupId>org.jboss</groupId>
+  <groupId>javassist</groupId>
   <artifactId>javassist</artifactId>
   <packaging>jar</packaging>
   <description>Javassist (JAVA programming ASSISTant) makes Java bytecode manipulation
       </dependencies>
     </profile>
   </profiles>
-  <repositories>
-    <repository>
-      <id>repository.jboss.org</id>
-      <name>JBoss Inc. Repository</name>
-      <layout>default</layout>
-      <url>http://repository.jboss.org/maven2/</url>
-      <snapshots>
-        <enabled>false</enabled>
-      </snapshots>
-    </repository>
-  </repositories>
   <dependencies>
     <dependency>
       <groupId>junit</groupId>
index 4a699a90859ad5457c780a490c03d48752db5756..798ecab1f39b45bf9ef9d290a1569fdbd2f1b045 100644 (file)
@@ -362,6 +362,7 @@ public abstract class CtBehavior extends CtMember {
             methodInfo.setAccessFlags(methodInfo.getAccessFlags()
                                       & ~AccessFlag.ABSTRACT);
             methodInfo.rebuildStackMapIf6(cc.getClassPool(), cc.getClassFile2());
+            declaringClass.rebuildClassFile();
         }
         catch (CompileError e) {
             throw new CannotCompileException(e);
@@ -396,6 +397,7 @@ public abstract class CtBehavior extends CtMember {
 
         destInfo.setAccessFlags(destInfo.getAccessFlags()
                                 & ~AccessFlag.ABSTRACT);
+        destClass.rebuildClassFile();
     }
 
     /**
index 9d6d77569aa02413176037e34bada360a5b74a2b..1666c71dd46e2aaf225c818be4cd6ed7ef033f40 100644 (file)
@@ -1155,7 +1155,7 @@ public abstract class CtClass {
     public boolean stopPruning(boolean stop) { return true; }
 
     /**
-     * Discards unnecessary attributes, in particuar,
+     * Discards unnecessary attributes, in particular,
      * <code>CodeAttribute</code>s (method bodies) of the class,
      * to minimize the memory footprint.
      * After calling this method, the class is read only.
@@ -1191,6 +1191,21 @@ public abstract class CtClass {
      */
     void incGetCounter() {}
 
+    /**
+     * If this method is called, the class file will be
+     * rebuilt when it is finally generated by
+     * <code>toBytecode()</code> and <code>writeFile()</code>.
+     * For a performance reason, the symbol table of the
+     * class file may contain unused entries, for example,
+     * after a method or a filed is deleted.
+     * This method
+     * removes those unused entries.  This removal will
+     * minimize the size of the class file.
+     *
+     * @since 3.8.1
+     */
+    public void rebuildClassFile() {}
+
     /**
      * Converts this class to a class file.
      * Once this method is called, further modifications are not
index 13a2b8715079ba9aa20db4c5bee6ef0fab856087..24735dbbe89852dee4c7fca4727563a0ec05be61 100644 (file)
@@ -60,7 +60,7 @@ class CtClassType extends CtClass {
     boolean wasChanged;
     private boolean wasFrozen;
     boolean wasPruned;
-    boolean memberRemoved;
+    boolean gcConstPool;    // if true, the constant pool entries will be garbage collected. 
     ClassFile classfile;
     byte[] rawClassfile;    // backup storage
 
@@ -78,7 +78,7 @@ class CtClassType extends CtClass {
     CtClassType(String name, ClassPool cp) {
         super(name);
         classPool = cp;
-        wasChanged = wasFrozen = wasPruned = memberRemoved = false;
+        wasChanged = wasFrozen = wasPruned = gcConstPool = false;
         classfile = null;
         rawClassfile = null;
         memberCache = null;
@@ -1183,7 +1183,7 @@ class CtClassType extends CtClass {
         ClassFile cf = getClassFile2();
         if (cf.getFields().remove(fi)) {
             getMembers().remove(f);
-            memberRemoved = true;
+            gcConstPool = true;
         }
         else
             throw new NotFoundException(f.toString());
@@ -1220,7 +1220,7 @@ class CtClassType extends CtClass {
         ClassFile cf = getClassFile2();
         if (cf.getMethods().remove(mi)) {
             getMembers().remove(m);
-            memberRemoved = true;
+            gcConstPool = true;
         }
         else
             throw new NotFoundException(m.toString());
@@ -1243,7 +1243,7 @@ class CtClassType extends CtClass {
         ClassFile cf = getClassFile2();
         if (cf.getMethods().remove(mi)) {
             getMembers().remove(m);
-            memberRemoved = true;
+            gcConstPool = true;
         }
         else
             throw new NotFoundException(m.toString());
@@ -1302,6 +1302,8 @@ class CtClassType extends CtClass {
         getClassFile2().prune();
     }
 
+    public void rebuildClassFile() { gcConstPool = true; }
+
     public void toBytecode(DataOutputStream out)
         throws CannotCompileException, IOException
     {
@@ -1309,9 +1311,9 @@ class CtClassType extends CtClass {
             if (isModified()) {
                 checkPruned("toBytecode");
                 ClassFile cf = getClassFile2();
-                if (memberRemoved) {
+                if (gcConstPool) {
                     cf.compact();
-                    memberRemoved = false;
+                    gcConstPool = false;
                 }
 
                 modifyClassConstructor(cf);