Commit ecb10e24 authored by Ivo Anjo's avatar Ivo Anjo

Enhancements to Test5

parent 649413ed
package javartm;
// Due to issues with JIT, this test needs to be run with
// java -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=exclude,javartm/Test5,simpleTx javartm.Test5
public final class Test5 {
public static long x, y, z;
public static void simpleTx() {
if (Transaction.begin() == Transaction.STARTED) {
public static void simpleTx(int iter) {
int status = Transaction.begin();
if (status == Transaction.STARTED) {
x++;
y++;
z++;
Transaction.commit();
}
if (x > 9500 && x < 9505) {
System.out.println("Temp stats: " + "x: " + x + ", y: " + y + ", z: " + z);
}
// Register stats
TransactionStats.registerResult(status);
}
public static void main(String[] args) throws Throwable {
//Thread[] threads = new Thread[Runtime.getRuntime().availableProcessors()];
Thread[] threads = new Thread[1];
final int ITERS = 5000000;
Thread[] threads = new Thread[Runtime.getRuntime().availableProcessors()];
synchronized (Test5.class) {
for (int i = 0; i < threads.length; i++) {
System.out.println("Creating thread " + i);
final int myId = i;
threads[i] = new Thread() {
@Override
public void run() {
// Barreira dos pobres
@Override public void run() {
// Poor man's barrier
synchronized (Test5.class) { new Object(); }
int i;
for (i = 0; i < 1000000; i++) {
simpleTx();
}
for (int i = 0; i < ITERS; i++) simpleTx(i);
System.out.println("Thread " + myId + " done " + i);
System.out.println("Thread " + myId + " done " + ITERS);
}
};
threads[i].start();
......@@ -43,6 +43,12 @@ public final class Test5 {
for (Thread t : threads) t.join();
System.out.println("Final stats: " + "x: " + x + ", y: " + y + ", z: " + z);
if (x != y || y != z) throw new Error("Final values differ");
int total = ITERS * threads.length;
System.out.println("Final stats: " + x + " successful iters, " + total + " tried (" +
(x/((double) total) * 100) + "% commit rate)");
System.out.println(TransactionStats.getStats());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment