aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-02-11 14:54:43 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2012-02-11 14:54:43 +0000
commitcbc67704adef11473329e901ec99f3563be78de4 (patch)
tree9b91e98f79ac775d8b281817ef0465f0bf161802 /src/test
parent0564d29d853bb18655c35405c74a421e2e550cef (diff)
downloadjavassist-cbc67704adef11473329e901ec99f3563be78de4.tar.gz
javassist-cbc67704adef11473329e901ec99f3563be78de4.zip
fixed JASSIST-150 (fixed a bug on WeakHashMap)
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@612 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src/test')
-rw-r--r--src/test/Jassist150.java110
-rw-r--r--src/test/javassist/JvstTest4.java27
2 files changed, 94 insertions, 43 deletions
diff --git a/src/test/Jassist150.java b/src/test/Jassist150.java
index 741add0c..1435e274 100644
--- a/src/test/Jassist150.java
+++ b/src/test/Jassist150.java
@@ -5,64 +5,88 @@ import javassist.CtMethod;
import javassist.NotFoundException;
public class Jassist150 {
-
- public static final String BASE_PATH="./";
- public static final String JAVASSIST_JAR=BASE_PATH+"javassist.jar";
- public static final String CLASSES_FOLDER=BASE_PATH+"build/classes";
- public static final String TEST_CLASSES_FOLDER=BASE_PATH+"build/test-classes";
+ public static final String BASE_PATH = "./";
+ public static final String JAVASSIST_JAR = BASE_PATH + "javassist.jar";
+ public static final String CLASSES_FOLDER = BASE_PATH + "build/classes";
+ public static final String TEST_CLASSES_FOLDER = BASE_PATH
+ + "build/test-classes";
public static class Inner1 {
- public static int get() {
- return 0;
- }
+ public static int get() {
+ return 0;
+ }
}
- public static void implTestClassTailCache() throws NotFoundException, CannotCompileException {
- ClassPool pool = new ClassPool(true);
- for(int paths=0; paths<50; paths++) {
- pool.appendClassPath(JAVASSIST_JAR);
- pool.appendClassPath(CLASSES_FOLDER);
- pool.appendClassPath(TEST_CLASSES_FOLDER);
- }
- CtClass cc = pool.get("Jassist150$Inner1");
- CtMethod ccGet = cc.getDeclaredMethod("get");
- String code1 = "{ int n1 = Integer.valueOf(1); " +
- " int n2 = Integer.valueOf(2); " +
- " int n3 = Integer.valueOf(3); " +
- " int n4 = Integer.valueOf(4); " +
- " int n5 = Integer.valueOf(5); " +
- " return n1+n2+n3+n4+n5; }";
- String code2 = "{ int n1 = java.lang.Integer.valueOf(1); " +
- " int n2 = java.lang.Integer.valueOf(2); " +
- " int n3 = java.lang.Integer.valueOf(3); " +
- " int n4 = java.lang.Integer.valueOf(4); " +
- " int n5 = java.lang.Integer.valueOf(5); " +
- " return n1+n2+n3+n4+n5; }";
- String code3 = "{ int n1 = java.lang.Integer#valueOf(1); " +
- " int n2 = java.lang.Integer#valueOf(2); " +
- " int n3 = java.lang.Integer#valueOf(3); " +
- " int n4 = java.lang.Integer#valueOf(4); " +
- " int n5 = java.lang.Integer#valueOf(5); " +
- " return n1+n2+n3+n4+n5; }";
- loop(cc, ccGet, code1);
+ public static void implTestClassTailCache() throws NotFoundException,
+ CannotCompileException {
+ ClassPool pool = new ClassPool(true);
+ for (int paths = 0; paths < 50; paths++) {
+ pool.appendClassPath(JAVASSIST_JAR);
+ pool.appendClassPath(CLASSES_FOLDER);
+ pool.appendClassPath(TEST_CLASSES_FOLDER);
+ }
+ CtClass cc = pool.get("Jassist150$Inner1");
+ CtMethod ccGet = cc.getDeclaredMethod("get");
+ String code1 = "{ int n1 = Integer.valueOf(1); "
+ + " int n2 = Integer.valueOf(2); "
+ + " int n3 = Integer.valueOf(3); "
+ + " int n4 = Integer.valueOf(4); "
+ + " int n5 = Integer.valueOf(5); "
+ + " return n1+n2+n3+n4+n5; }";
+ String code2 = "{ int n1 = java.lang.Integer.valueOf(1); "
+ + " int n2 = java.lang.Integer.valueOf(2); "
+ + " int n3 = java.lang.Integer.valueOf(3); "
+ + " int n4 = java.lang.Integer.valueOf(4); "
+ + " int n5 = java.lang.Integer.valueOf(5); "
+ + " return n1+n2+n3+n4+n5; }";
+ String code3 = "{ int n1 = java.lang.Integer#valueOf(1); "
+ + " int n2 = java.lang.Integer#valueOf(2); "
+ + " int n3 = java.lang.Integer#valueOf(3); "
+ + " int n4 = java.lang.Integer#valueOf(4); "
+ + " int n5 = java.lang.Integer#valueOf(5); "
+ + " return n1+n2+n3+n4+n5; }";
+ loop(cc, ccGet, code1);
}
- public static void loop(CtClass cc, CtMethod ccGet, String code) throws CannotCompileException {
+ public static void loop(CtClass cc, CtMethod ccGet, String code)
+ throws CannotCompileException {
long startTime = System.currentTimeMillis();
- for(int replace=0; replace<1000; replace++) {
+ for (int replace = 0; replace < 1000; replace++) {
ccGet.setBody(code);
}
long endTime = System.currentTimeMillis();
- System.out.println("Test: Time (ms) "+(endTime-startTime));
+ System.out.println("Test: Time (ms) " + (endTime - startTime));
+ }
+
+ public static void implTestClassTailCache2() throws NotFoundException,
+ CannotCompileException {
+ ClassPool pool = new ClassPool(true);
+ for (int paths = 0; paths < 50; paths++) {
+ pool.appendClassPath(JAVASSIST_JAR);
+ pool.appendClassPath(CLASSES_FOLDER);
+ pool.appendClassPath(TEST_CLASSES_FOLDER);
+ }
+ CtClass cc = pool.get("Jassist150$Inner1");
+ CtMethod ccGet = cc.getDeclaredMethod("get");
+ String code3 = "{ int n1 = java.lang.Integer#valueOf(1); "
+ + " int n2 = java.lang.Integer#valueOf(2); "
+ + " int n3 = java.lang.Integer#valueOf(3); "
+ + " int n4 = java.lang.Integer#valueOf(4); "
+ + " int n5 = java.lang.Integer#valueOf(5); "
+ + " return n1+n2+n3+n4+n5; }";
+ ccGet.setBody(code3);
}
public static void main(String[] args) {
- for (int loop = 0; loop < 5; loop++) {
- try {
+ for (int loop = 0; loop < 5; loop++) {
+ try {
implTestClassTailCache();
+ for (int i = 0; i < 100; i++)
+ implTestClassTailCache2();
} catch (Exception e) {
e.printStackTrace();
}
+ }
+ System.out.println("size: " + javassist.compiler.MemberResolver.getInvalidMapSize());
}
- }
-} \ No newline at end of file
+}
diff --git a/src/test/javassist/JvstTest4.java b/src/test/javassist/JvstTest4.java
index 3a2dca55..54e24584 100644
--- a/src/test/javassist/JvstTest4.java
+++ b/src/test/javassist/JvstTest4.java
@@ -657,4 +657,31 @@ public class JvstTest4 extends JvstTestRoot {
assertTrue(t2 < t1 * 2);
assertTrue(t3 < t1 * 2);
}
+
+ public void testJIRA150b() throws Exception {
+ int N = 100;
+ for (int k = 0; k < N; k++) {
+ ClassPool pool = new ClassPool(true);
+ for(int paths=0; paths<50; paths++) {
+ pool.appendClassPath(JAVASSIST_JAR);
+ pool.appendClassPath(CLASSES_FOLDER);
+ pool.appendClassPath(TEST_CLASSES_FOLDER);
+ }
+ CtClass cc = pool.get("Jassist150$Inner1");
+ CtMethod ccGet = cc.getDeclaredMethod("get");
+ for(int replace=0; replace < 5; replace++) {
+ ccGet.setBody(
+ "{ int n1 = java.lang.Integer#valueOf(1); " +
+ " int n2 = java.lang.Integer#valueOf(2); " +
+ " int n3 = java.lang.Integer#valueOf(3); " +
+ " int n4 = java.lang.Integer#valueOf(4); " +
+ " int n5 = java.lang.Integer#valueOf(5); " +
+ " return n1+n2+n3+n4+n5; }");
+ }
+ }
+ System.gc();
+ int size = javassist.compiler.MemberResolver.getInvalidMapSize();
+ System.out.println("JIRA150b " + size);
+ assertTrue(size < N - 10);
+ }
}