Permalink
Browse files

initial copy

  • Loading branch information...
eliasnaur committed Sep 1, 2014
1 parent 384a7da commit 814193aba9565e9032c98a41ae1145c59c1e278f
Showing 1,750 changed files with 1,174,024 additions and 0 deletions.
View
@@ -0,0 +1,2 @@
.svn
build
View
@@ -0,0 +1,22 @@
<project name="all" basedir="." default="compile">
<macrodef name="iterate">
<attribute name="target"/>
<sequential>
<subant target="@{target}">
<fileset dir="." includes="*/build.xml"/>
</subant>
</sequential>
</macrodef>
<target name="clean">
<iterate target="clean"/>
</target>
<target name="mrproper">
<iterate target="mrproper"/>
</target>
<target name="compile">
<iterate target="compile"/>
</target>
</project>
View
@@ -0,0 +1,5 @@
<project name="common" basedir="." default="compile">
<import file="common.xml"/>
<property name="classpath" value="${lib}/javasvn.jar:${lib}/lwjgl.jar:${lib}/lwjgl_util.jar:${lib}/jorbis.jar:${lib}/commons-pool-1.2.jar:${lib}/commons-dbcp-1.2.1.jar:${lib}/commons-collections-3.1.jar"/>
</project>
@@ -0,0 +1,114 @@
package com.oddlabs.event;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public abstract strictfp class Deterministic {
protected final static int BUFFER_SIZE = 4096;
protected final static int DEFAULTS_SIZE = 2;
protected final static int MIN_DEFAULTS = Short.MIN_VALUE;
private final static long CHECKPOINT_SIGNATURE = 0xdeadbabecafebeefL;
private boolean enabled = true;
public final boolean log(boolean b) {
return log(b, false);
}
private final boolean log(boolean b, boolean def) {
assert enabled;
return log(b ? (byte)1 : (byte)0, def ? (byte)1 : (byte)0) != 0;
}
public final byte log(byte b) {
assert enabled;
return log(b, (byte)0);
}
protected abstract byte log(byte b, byte def);
public final char log(char c) {
assert enabled;
return log(c, (char)0);
}
protected abstract char log(char c, char def);
public final int log(int i) {
assert enabled;
return log(i, 0);
}
protected abstract int log(int i, int def);
public final long log(long l) {
assert enabled;
return log(l, 0);
}
protected abstract long log(long l, long def);
public final float log(float f) {
assert enabled;
return log(f, 0f);
}
protected abstract float log(float f, float def);
public final Object log(Object o) {
assert enabled;
return logObject(o);
}
protected abstract Object logObject(Object o);
public final void log(ByteBuffer o) {
assert enabled;
logBuffer(o);
}
protected abstract void logBuffer(ByteBuffer o);
public abstract void endLog();
public abstract boolean isPlayback();
public final void setEnabled(boolean enable) {
this.enabled = enable;
}
public final void checkpoint() {
checkpoint(CHECKPOINT_SIGNATURE);
}
public final void checkpoint(long value) {
long logged_value = log(value);
assert logged_value == value: logged_value + " != " + value;
// assert logged_value == value: "0x" + Long.toHexString(logged_value) + " != 0x" + Long.toHexString(value);
}
public final void checkpoint(boolean value) {
boolean logged_value = log(value);
assert logged_value == value: logged_value + " != " + value;
// assert logged_value == value: "0x" + Long.toHexString(logged_value) + " != 0x" + Long.toHexString(value);
}
public final void checkpoint(float value) {
float logged_value = log(value);
assert logged_value == value: logged_value + " != " + value;
// assert logged_value == value: "0x" + Long.toHexString(logged_value) + " != 0x" + Long.toHexString(value);
}
protected final static int getTraceId() {
Throwable t = new Throwable();
StackTraceElement[] stack_trace_elements = t.getStackTrace();
int hash = 0;
for (int i = 0; i < stack_trace_elements.length; i++) {
if (stack_trace_elements[i].getClassName().startsWith(Deterministic.class.getPackage().getName()))
continue;
hash += stack_trace_elements[i].getMethodName().hashCode();
}
return hash;
}
}
@@ -0,0 +1,186 @@
package com.oddlabs.event;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.util.zip.*;
public final strictfp class LoadDeterministic extends Deterministic {
private final ReadableByteChannel channel;
private final ByteBuffer buffer;
private final ByteBufferInputStream byte_buffer_input_stream = new ByteBufferInputStream();
private int total_bytes_read;
private int num_defaults = MIN_DEFAULTS;
public LoadDeterministic(File logging_file, boolean zipped) {
try {
buffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
if (zipped)
channel = Channels.newChannel(new GZIPInputStream(new FileInputStream(logging_file)));
else
channel = new FileInputStream(logging_file).getChannel();
buffer.limit(0);
System.out.println("Reading log from " + logging_file);
} catch (IOException e) {
throw new RuntimeException(e);
}
isDefault(0);
getDefaults();
}
public final boolean isPlayback() {
return true;
}
public final void endLog() {
// assert isEndOfLog();
try {
channel.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private final boolean isDefault(int num_bytes) {
if (num_defaults > MIN_DEFAULTS) {
num_defaults--;
if (isEndOfLog())
System.out.println("***** End of log ***** ");
return true;
} else {
fillBuffer(num_bytes);
return false;
}
}
private final void fillBuffer(int num_bytes) {
while (num_bytes > buffer.remaining()) {
fillBuffer();
}
}
private final void fillBuffer() {
if (tryFillBuffer())
throw new IllegalStateException("End of log reached, bytes read: " + total_bytes_read);
}
private final boolean tryFillBuffer() {
try {
buffer.compact();
int bytes_read;
int current_total = 0;
do {
bytes_read = channel.read(buffer);
if (bytes_read != -1) {
current_total += bytes_read;
}
} while (bytes_read != -1 && buffer.hasRemaining());
buffer.flip();
total_bytes_read += current_total;
return bytes_read == -1 && current_total == 0;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
private final boolean isEndOfLog() {
if (!buffer.hasRemaining() && num_defaults == MIN_DEFAULTS)
return tryFillBuffer();
else
return false;
}
private final void getDefaults() {
fillBuffer(DEFAULTS_SIZE);
num_defaults = buffer.getShort();
if (isEndOfLog())
System.out.println("***** End of log *****");
}
protected final byte log(byte b, byte def) {
if (isDefault(1))
return def;
else {
b = buffer.get();
getDefaults();
return b;
}
}
protected final char log(char c, char def) {
if (isDefault(2))
return def;
else {
c = buffer.getChar();
getDefaults();
return c;
}
}
protected final int log(int i, int def) {
if (isDefault(4))
return def;
else {
i = buffer.getInt();
getDefaults();
return i;
}
}
protected final long log(long l, long def) {
if (isDefault(8))
return def;
else {
l = buffer.getLong();
getDefaults();
return l;
}
}
protected final float log(float f, float def) {
if (isDefault(4))
return def;
else {
f = buffer.getFloat();
getDefaults();
return f;
}
}
protected final Object logObject(Object o) {
try {
ObjectInputStream object_input_stream = new ObjectInputStream(byte_buffer_input_stream);
o = object_input_stream.readObject();
object_input_stream.close();
return o;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
protected final void logBuffer(ByteBuffer b) {
boolean isdefault = isDefault(0);
assert !isdefault;
while (true) {
int old_limit = buffer.limit();
buffer.limit(old_limit - Math.max(0, buffer.remaining() - b.remaining()));
b.put(buffer);
buffer.limit(old_limit);
if (!b.hasRemaining())
break;
fillBuffer();
}
getDefaults();
}
public final strictfp class ByteBufferInputStream extends InputStream {
public final int read() throws IOException {
byte b = log((byte)0);
return ((int)b) & 0xFF;
}
}
}
@@ -0,0 +1,42 @@
package com.oddlabs.event;
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
public final strictfp class NotDeterministic extends Deterministic {
public final boolean isPlayback() {
return false;
}
public final void endLog() {
}
protected final byte log(byte b, byte def) {
return b;
}
protected final char log(char c, char def) {
return c;
}
protected final int log(int i, int def) {
return i;
}
protected final long log(long l, long def) {
return l;
}
protected final float log(float f, float def) {
return f;
}
protected final Object logObject(Object o) {
return o;
}
protected final void logBuffer(ByteBuffer b) {
b.position(b.limit());
}
}
Oops, something went wrong.

0 comments on commit 814193a

Please sign in to comment.