aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/javassist/CtClassType.java
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2007-07-03 15:31:19 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2007-07-03 15:31:19 +0000
commitd133f96da4ac7bb312ddddbc00cbcd19e94cd412 (patch)
treee118f996b1998b3366a5a8cac448afe7878c88e3 /src/main/javassist/CtClassType.java
parent92fae275e595a2b25c69e43f4a1898fe66a4da68 (diff)
downloadjavassist-d133f96da4ac7bb312ddddbc00cbcd19e94cd412.tar.gz
javassist-d133f96da4ac7bb312ddddbc00cbcd19e94cd412.zip
for reducing memory footprint
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@393 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/main/javassist/CtClassType.java')
-rw-r--r--src/main/javassist/CtClassType.java76
1 files changed, 31 insertions, 45 deletions
diff --git a/src/main/javassist/CtClassType.java b/src/main/javassist/CtClassType.java
index f3106b9e..859b3af3 100644
--- a/src/main/javassist/CtClassType.java
+++ b/src/main/javassist/CtClassType.java
@@ -25,7 +25,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
@@ -73,10 +72,8 @@ class CtClassType extends CtClass {
private int uniqueNumberSeed;
private boolean doPruning = ClassPool.doPruning;
- int getCounter;
- private static int readCounter = 0;
- private static final int READ_THRESHOLD = 100; // see getClassFile2()
- private static final int GET_THRESHOLD = 2; // see releaseClassFiles()
+ private int getCount;
+ private static final int GET_THRESHOLD = 2; // see compress()
CtClassType(String name, ClassPool cp) {
super(name);
@@ -89,7 +86,7 @@ class CtClassType extends CtClass {
fieldInitializers = null;
hiddenMethods = null;
uniqueNumberSeed = 0;
- getCounter = 0;
+ getCount = 0;
}
CtClassType(InputStream ins, ClassPool cp) throws IOException {
@@ -169,17 +166,13 @@ class CtClassType extends CtClass {
if (cfile != null)
return cfile;
- if (readCounter++ > READ_THRESHOLD) {
- releaseClassFiles();
- readCounter = 0;
- }
-
+ classPool.compress();
if (rawClassfile != null) {
try {
classfile = new ClassFile(new DataInputStream(
new ByteArrayInputStream(rawClassfile)));
rawClassfile = null;
- getCounter = GET_THRESHOLD;
+ getCount = GET_THRESHOLD;
return classfile;
}
catch (IOException e) {
@@ -218,11 +211,33 @@ class CtClassType extends CtClass {
}
}
- /**
+ /* Inherited from CtClass. Called by get() in ClassPool.
+ *
+ * @see javassist.CtClass#incGetCounter()
+ * @see #toBytecode(DataOutputStream)
+ */
+ final void incGetCounter() { ++getCount; }
+
+ /**
+ * Invoked from ClassPool#compress().
+ * It releases the class files that have not been recently used
+ * if they are unmodified.
+ */
+ void compress() {
+ if (getCount < GET_THRESHOLD)
+ if (!isModified() && ClassPool.releaseUnmodifiedClassFile)
+ removeClassFile();
+ else if (isFrozen() && !wasPruned)
+ saveClassFile();
+
+ getCount = 0;
+ }
+
+ /**
* Converts a ClassFile object into a byte array
* for saving memory space.
*/
- public synchronized void saveClassFile() {
+ private synchronized void saveClassFile() {
/* getMembers() and releaseClassFile() are also synchronized.
*/
if (classfile == null || hasMemberCache() != null)
@@ -239,40 +254,11 @@ class CtClassType extends CtClass {
catch (IOException e) {}
}
- public synchronized void releaseClassFile() {
+ private synchronized void removeClassFile() {
if (classfile != null && !isModified() && hasMemberCache() == null)
classfile = null;
}
- /* Inherited from CtClass. Called by get() in ClassPool.
- *
- * @see javassist.CtClass#incGetCounter()
- * @see #toBytecode(DataOutputStream)
- */
- void incGetCounter() { ++getCounter; }
-
- /**
- * Releases the class files
- * of the CtClasses that have not been recently used
- * if they are unmodified.
- */
- public void releaseClassFiles() {
- Enumeration e = classPool.classes.elements();
- while (e.hasMoreElements()) {
- Object obj = e.nextElement();
- if (obj instanceof CtClassType) {
- CtClassType cct = (CtClassType)obj;
- if (cct.getCounter < GET_THRESHOLD)
- if (!cct.isModified() && ClassPool.releaseUnmodifiedClassFile)
- cct.releaseClassFile();
- else if (cct.isFrozen() && !cct.wasPruned)
- cct.saveClassFile();
-
- cct.getCounter = 0;
- }
- }
- }
-
public ClassPool getClassPool() { return classPool; }
void setClassPool(ClassPool cp) { classPool = cp; }
@@ -1344,7 +1330,7 @@ class CtClassType extends CtClass {
// classfile = null;
}
- getCounter = 0;
+ getCount = 0;
wasFrozen = true;
}
catch (NotFoundException e) {