diff options
author | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2008-07-03 07:56:24 +0000 |
---|---|---|
committer | chiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3> | 2008-07-03 07:56:24 +0000 |
commit | 50da9b9f3bbd626662d78ae5499ac112fbe816c6 (patch) | |
tree | 916b83eff38940894ef3b144af04e13ebca8e152 | |
parent | 6b4fd8d02d032fc6a49d99ad1a03b3c3c0b1c757 (diff) | |
download | javassist-50da9b9f3bbd626662d78ae5499ac112fbe816c6.tar.gz javassist-50da9b9f3bbd626662d78ae5499ac112fbe816c6.zip |
fixed a performance bug caused by many calls to CtBehavior#setBody()
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@448 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
-rw-r--r-- | Readme.html | 5 | ||||
-rw-r--r-- | build.xml | 15 | ||||
-rw-r--r-- | pom.xml | 18 | ||||
-rw-r--r-- | src/main/javassist/CtBehavior.java | 2 | ||||
-rw-r--r-- | src/main/javassist/CtClass.java | 17 | ||||
-rw-r--r-- | src/main/javassist/CtClassType.java | 16 |
6 files changed, 40 insertions, 33 deletions
diff --git a/Readme.html b/Readme.html index a1255c4c..a95a13d3 100644 --- a/Readme.html +++ b/Readme.html @@ -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. @@ -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> @@ -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 @@ -89,17 +84,6 @@ </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> diff --git a/src/main/javassist/CtBehavior.java b/src/main/javassist/CtBehavior.java index 4a699a90..798ecab1 100644 --- a/src/main/javassist/CtBehavior.java +++ b/src/main/javassist/CtBehavior.java @@ -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(); } /** diff --git a/src/main/javassist/CtClass.java b/src/main/javassist/CtClass.java index 9d6d7756..1666c71d 100644 --- a/src/main/javassist/CtClass.java +++ b/src/main/javassist/CtClass.java @@ -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. @@ -1192,6 +1192,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 * possible any more. diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java index 13a2b871..24735dbb 100644 --- a/src/main/javassist/CtClassType.java +++ b/src/main/javassist/CtClassType.java @@ -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); |