Browse files

Support "resetting" the stateClasses cache, so that we can run the we…

…aver multiple times (and in multiple threads).
  • Loading branch information...
1 parent 3ddb058 commit 5b37b3794106d60b113307e37e19df9be373d8d6 @krestenkrab committed May 6, 2010
Showing with 13 additions and 3 deletions.
  1. +13 −3 src/kilim/analysis/ClassWeaver.java
View
16 src/kilim/analysis/ClassWeaver.java
@@ -29,7 +29,16 @@
public class ClassWeaver {
ClassFlow classFlow;
List<ClassInfo> classInfoList = new LinkedList<ClassInfo>();
- static HashSet<String> stateClasses = new HashSet<String>();
+
+ static ThreadLocal<HashSet<String>> stateClasses = new ThreadLocal<HashSet<String>>() {
+ protected java.util.HashSet<String> initialValue() {
+ return new HashSet<String>();
+ }
+ };
+
+ public static void reset() {
+ stateClasses.set(new HashSet<String>());
+ }
public ClassWeaver(byte[] data, Detector detector) {
classFlow = new ClassFlow(data, detector);
@@ -183,10 +192,11 @@ String createStateClass(ValInfoList valInfoList) {
numByType[vi.vmt]++;
}
String className = makeClassName(numByType);
- if (stateClasses.contains(className)) {
+ HashSet<String> classes = stateClasses.get();
+ if (classes.contains(className)) {
return className;
}
- stateClasses.add(className);
+ classes.add(className);
ClassWriter cw = new ClassWriter(false);
cw.visit(V1_1, ACC_PUBLIC | ACC_FINAL, className, null, "kilim/State", null);

0 comments on commit 5b37b37

Please sign in to comment.