Browse files

Fix for Issue #17 thanks to ted stockwell.

From the issue page:
"The kilim.analysis.ClassWeaver class maintains a static list of state classes that have been generated. Therefore, when used in Eclipse, if kilim.S_L is generated once when one eclipse project is built, then it will not be generated again in a second eclipse project that requires it.
"

	modified:   src/kilim/analysis/ClassWeaver.java
  • Loading branch information...
1 parent 7d9351e commit d29e9f97c32a406edcda014c93e53d5b5081d1e3 @sriram-srinivasan sriram-srinivasan committed Nov 19, 2012
Showing with 29 additions and 23 deletions.
  1. +29 −23 src/kilim/analysis/ClassWeaver.java
View
52 src/kilim/analysis/ClassWeaver.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -41,7 +42,7 @@
public class ClassWeaver {
public ClassFlow classFlow;
List<ClassInfo> classInfoList = new LinkedList<ClassInfo>();
- static HashSet<String> stateClasses = new HashSet<String>();
+ static HashMap<String, ClassInfo> stateClasses = new HashMap<String, ClassInfo>();
public ClassWeaver(byte[] data) {
this(data, Detector.DEFAULT);
@@ -197,29 +198,34 @@ String createStateClass(ValInfoList valInfoList) {
numByType[vi.vmt]++;
}
String className = makeClassName(numByType);
- if (stateClasses.contains(className)) {
- return className;
- }
- stateClasses.add(className);
- ClassWriter cw = new ClassWriter(false);
- cw.visit(V1_1, ACC_PUBLIC | ACC_FINAL, className, null, "kilim/State", null);
+ ClassInfo classInfo= null;
+ synchronized (stateClasses) {
+ classInfo= stateClasses.get(className);
+ if (classInfo == null) {
+ ClassWriter cw = new ClassWriter(false);
+ cw.visit(V1_1, ACC_PUBLIC | ACC_FINAL, className, null, "kilim/State", null);
- // Create default constructor
- // <init>() {
- // super(); // call java/lang/Object.<init>()
- // }
- MethodVisitor mw = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
- mw.visitInsn(ALOAD_0);
- mw.visitMethodInsn(INVOKESPECIAL, STATE_CLASS, "<init>", "()V");
- mw.visitInsn(RETURN);
- // this code uses a maximum of one stack element and one local variable
- mw.visitMaxs(1, 1);
- mw.visitEnd();
- // create fields of the appropriate type.
- for (ValInfo vi : valInfoList) {
- cw.visitField(ACC_PUBLIC, vi.fieldName, vi.fieldDesc(), null, null);
- }
- addClassInfo(new ClassInfo(className, cw.toByteArray()));
+ // Create default constructor
+ // <init>() {
+ // super(); // call java/lang/Object.<init>()
+ // }
+ MethodVisitor mw = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
+ mw.visitInsn(ALOAD_0);
+ mw.visitMethodInsn(INVOKESPECIAL, STATE_CLASS, "<init>", "()V");
+ mw.visitInsn(RETURN);
+ // this code uses a maximum of one stack element and one local variable
+ mw.visitMaxs(1, 1);
+ mw.visitEnd();
+ // create fields of the appropriate type.
+ for (ValInfo vi : valInfoList) {
+ cw.visitField(ACC_PUBLIC, vi.fieldName, vi.fieldDesc(), null, null);
+ }
+ classInfo= new ClassInfo(className, cw.toByteArray());
+ stateClasses.put(className, classInfo);
+ }
+ }
+ if (!classInfoList.contains(classInfo))
+ addClassInfo(classInfo);
return className;
}

0 comments on commit d29e9f9

Please sign in to comment.