aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2008-07-03 07:56:24 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2008-07-03 07:56:24 +0000
commit50da9b9f3bbd626662d78ae5499ac112fbe816c6 (patch)
tree916b83eff38940894ef3b144af04e13ebca8e152 /src
parent6b4fd8d02d032fc6a49d99ad1a03b3c3c0b1c757 (diff)
downloadjavassist-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
Diffstat (limited to 'src')
-rw-r--r--src/main/javassist/CtBehavior.java2
-rw-r--r--src/main/javassist/CtClass.java17
-rw-r--r--src/main/javassist/CtClassType.java16
3 files changed, 27 insertions, 8 deletions
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);