First pass at serializble serializble log

Jonathan Bell [2012-08-09 01:46:47]
First pass at serializble serializble log
Filename
testcase-generation/src/edu/columbia/cs/psl/invivo/record/ExportedSerializableLog.java
testcase-generation/src/edu/columbia/cs/psl/invivo/record/MethodCall.java
testcase-generation/src/edu/columbia/cs/psl/invivo/record/SerializableLog.java
testcase-generation/src/edu/columbia/cs/psl/invivo/record/WallaceExportRunner.java
testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/CloningAdviceAdapter.java
testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingClassVisitor.java
testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingMethodVisitor.java
diff --git a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/ExportedSerializableLog.java b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/ExportedSerializableLog.java
new file mode 100644
index 0000000..12bcd76
--- /dev/null
+++ b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/ExportedSerializableLog.java
@@ -0,0 +1,30 @@
+package edu.columbia.cs.psl.invivo.record;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+public class ExportedSerializableLog implements Serializable {
+	public static Serializable[]	aLog	= new Serializable[Constants.DEFAULT_LOG_SIZE];
+
+	public static int				aLog_fill;
+	public static int				aLog_replayIndex;
+
+	public static void clearLog() {
+		aLog = new Serializable[Constants.DEFAULT_LOG_SIZE];
+		aLog_fill = 0;
+	}
+
+	private void writeObject(ObjectOutputStream oos) throws IOException {
+		oos.defaultWriteObject();
+		oos.writeInt(aLog_fill);
+		oos.writeObject(aLog);
+	}
+
+	private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
+		ois.defaultReadObject();
+		aLog_fill = ois.readInt();
+		aLog = (Serializable[]) ois.readObject();
+	}
+}
\ No newline at end of file
diff --git a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/MethodCall.java b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/MethodCall.java
index c8a1ad2..3a8c388 100644
--- a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/MethodCall.java
+++ b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/MethodCall.java
@@ -74,6 +74,17 @@ public class MethodCall {
 			return true;
 		return false;
 	}
+	public static String getLogClassName(Type t)
+	{
+		if(t.getSort() == Type.ARRAY)
+			return Type.getInternalName(SerializableLog.class);
+		else
+			return Type.getInternalName(Log.class);
+	}
+	public String getLogClassNmae()
+	{
+		return getLogClassName(Type.getReturnType(methodDesc));
+	}
 	public String getCapturePrefix()
 	{
 		String r = sourceMethodName.replace("<", "___").replace(">", "___")+"$$$$"+methodName.replace("<", "___").replace(">", "___")+"$$$$";
diff --git a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/SerializableLog.java b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/SerializableLog.java
new file mode 100644
index 0000000..ebd9b66
--- /dev/null
+++ b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/SerializableLog.java
@@ -0,0 +1,26 @@
+package edu.columbia.cs.psl.invivo.record;
+
+import java.io.Serializable;
+
+public class SerializableLog implements Serializable{
+
+	private static final long	serialVersionUID	= 4627796984904522647L;
+	public static Serializable[] aLog = new Serializable[Constants.DEFAULT_LOG_SIZE];
+	public static int logsize = 0;
+	public static int aLog_fill = 0;
+	public static void growaLog()
+	{
+		Serializable[] newA = new Serializable[(int) (aLog.length * Constants.LOG_GROWTH_RATE)];
+		System.arraycopy(aLog, 0, newA, 0, aLog.length);
+		aLog = newA;
+	}
+
+	public static void clearLog() {
+//		System.err.println("start cl");
+		aLog = new Serializable[Constants.DEFAULT_LOG_SIZE];
+		logsize = 0;
+//		System.err.println("starting gc");
+//		System.gc();
+//		System.err.println("Fin gc");
+	}
+}
diff --git a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/WallaceExportRunner.java b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/WallaceExportRunner.java
index 48dcc4d..07a24ed 100644
--- a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/WallaceExportRunner.java
+++ b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/WallaceExportRunner.java
@@ -1,7 +1,9 @@
 package edu.columbia.cs.psl.invivo.record;

 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.FileWriter;
+import java.io.ObjectOutputStream;
 import java.lang.reflect.Field;

 import com.thoughtworks.xstream.XStream;
@@ -43,6 +45,8 @@ public class WallaceExportRunner extends Thread {
 		} catch (InterruptedException e) {
 			if(shouldExport == 1)
 				export();
+			if(shouldExportSerializable == 1)
+				exportSerializable();
 		}
 				}
 	}
@@ -104,19 +108,49 @@ public class WallaceExportRunner extends Thread {
 		shouldExport = -1;
 	}

-	private static int	shouldExport	= -1;
+	private static ExportedSerializableLog logS = new ExportedSerializableLog();
+	public static void exportSerializable() {
+		shouldExportSerializable = 0;
+		try {
+
+			synchronized (Log.lock) {
+				ExportedSerializableLog.aLog = SerializableLog.aLog;
+				ExportedSerializableLog.aLog_fill = SerializableLog.aLog_fill;
+				SerializableLog.clearLog();
+			}
+				System.err.println("Serializing serializable");
+				File output = new File("wallace_serializable_" + System.currentTimeMillis() + ".log");

+				ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(output));
+				oos.writeObject(logS);
+				oos.flush();
+				oos.close();
+				System.err.println("Clearing serializable");
+				ExportedLog.clearLog();
+				System.err.println("Cleared serializable");
+
+		} catch (Exception exi) {
+//			System.err.println(exi.getMessage());
+		}
+		shouldExport = -1;
+	}
+
+	private static int	shouldExport	= -1;
+	private static int	shouldExportSerializable	= -1;
+	public static void _exportSerializable() {
+		if(shouldExportSerializable == -1)
+		{
+			shouldExportSerializable = 1;
+			inst.interrupt();
+		}
+	}
+
 	public static void _export() {
-//		System.err.println("flag export");
 		if(shouldExport == -1)
 		{
 			shouldExport = 1;
 			inst.interrupt();
 		}
-//		if(inst.isAlive())
-//			System.out.println("Alive still!");
-//		else
-//			System.out.println("Its dead");
 	}

 }
diff --git a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/CloningAdviceAdapter.java b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/CloningAdviceAdapter.java
index 6ffaa57..7fb457c 100644
--- a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/CloningAdviceAdapter.java
+++ b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/CloningAdviceAdapter.java
@@ -17,6 +17,7 @@ import edu.columbia.cs.psl.invivo.record.CloningUtils;
 import edu.columbia.cs.psl.invivo.record.Constants;
 import edu.columbia.cs.psl.invivo.record.Instrumenter;
 import edu.columbia.cs.psl.invivo.record.Log;
+import edu.columbia.cs.psl.invivo.record.SerializableLog;
 import edu.columbia.cs.psl.invivo.record.WallaceExportRunner;

 public class CloningAdviceAdapter extends GeneratorAdapter implements Opcodes {
@@ -291,10 +292,13 @@ public class CloningAdviceAdapter extends GeneratorAdapter implements Opcodes {
 //			super.visitInsn(ISUB);
 			super.visitJumpInsn(IF_ICMPLE, endLbl);
 //			super.ifCmp(Type.INT_TYPE, Opcodes.IFGE, endLbl);
-			super.visitMethodInsn(INVOKESTATIC, Type.getInternalName(WallaceExportRunner.class), "_export", "()V");
-
+			if(logFieldOwner.equals(Type.getInternalName(SerializableLog.class)))
+				super.visitMethodInsn(INVOKESTATIC, Type.getInternalName(WallaceExportRunner.class), "_exportSerializable", "()V");
+			else
+				super.visitMethodInsn(INVOKESTATIC, Type.getInternalName(WallaceExportRunner.class), "_export", "()V");
+
 			visitLabel(endLbl);
-			super.visitLocalVariable(logFieldName + "_monitor", "Ljava/lang/Object;", null, monitorStart, monitorEndLabel, monitorIndx);
+//			super.visitLocalVariable(logFieldName + "_monitor", "Ljava/lang/Object;", null, monitorStart, monitorEndLabel, monitorIndx);
 //		}

 	}
diff --git a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingClassVisitor.java b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingClassVisitor.java
index 17f442d..14c44f2 100644
--- a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingClassVisitor.java
+++ b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingClassVisitor.java
@@ -120,7 +120,7 @@ public class NonDeterministicLoggingClassVisitor extends ClassVisitor implements
 					if (args[i].getSort() == Type.ARRAY) {
 						caa.loadArg(i);
 						//- (mi.getOpcode() == Opcodes.INVOKESTATIC ? 0 : 1)
-						caa.logValueAtTopOfStackToArray(Constants.LOG_DUMP_CLASS, "aLog", "[Ljava/lang/Object;",
+						caa.logValueAtTopOfStackToArray(MethodCall.getLogClassName(args[i]), "aLog", "[Ljava/lang/Object;",
 								args[i], true, mi.owner+"."+mi.name+"->_"+i+"\t"+args[i].getDescriptor());
 						if (args[i].getSize() == 1)
 							caa.pop();
diff --git a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingMethodVisitor.java b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingMethodVisitor.java
index 0c17c19..a06ea68 100644
--- a/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingMethodVisitor.java
+++ b/testcase-generation/src/edu/columbia/cs/psl/invivo/record/visitor/NonDeterministicLoggingMethodVisitor.java
@@ -136,13 +136,13 @@ public class NonDeterministicLoggingMethodVisitor extends CloningAdviceAdapter i
 						captureDesc+=")"+Type.getReturnType(desc).getDescriptor();
 					}
 					mv.visitMethodInsn(invokeOpcode, classDesc, m.getCapturePrefix()+"_capture", captureDesc);
-					logValueAtTopOfStackToArray(Constants.LOG_DUMP_CLASS, m.getLogFieldName(), m.getLogFieldType().getDescriptor(), returnType, true,
+					logValueAtTopOfStackToArray(m.getLogClassNmae(), m.getLogFieldName(), m.getLogFieldType().getDescriptor(), returnType, true,
 							owner+"."+name + "\t" + desc);
 				}
 				else
 				{
 					mv.visitMethodInsn(opcode, owner, name, desc);
-					logValueAtTopOfStackToArray(Constants.LOG_DUMP_CLASS, m.getLogFieldName(), m.getLogFieldType().getDescriptor(), returnType, true,
+					logValueAtTopOfStackToArray(m.getLogClassNmae(), m.getLogFieldName(), m.getLogFieldType().getDescriptor(), returnType, true,
 							owner+"."+name + "\t" + desc);
 				}
 			}
@@ -150,7 +150,7 @@ public class NonDeterministicLoggingMethodVisitor extends CloningAdviceAdapter i
 					&& this.name.equals("<init>"))) {
 				super.visitMethodInsn(opcode, owner, name, desc);
 				if(analyzer.stack != null && analyzer.stack.size() > 0 && analyzer.stack.get(analyzer.stack.size()-1).equals(owner))
-					logValueAtTopOfStackToArray(Constants.LOG_DUMP_CLASS, "aLog", "[Ljava/lang/Object;", Type.getType("L"+owner+";"), true,
+					logValueAtTopOfStackToArray(MethodCall.getLogClassName(Type.getType("L"+owner+";")), "aLog", "[Ljava/lang/Object;", Type.getType("L"+owner+";"), true,
 							owner+"."+name + "\t" + desc);

 			}