Commit 54396d6c authored by Lubomir Bulej's avatar Lubomir Bulej

Fix race in "dispatchmp" test and repeatedly force GC

The race was in the code displaying the "So far received..." message.
After the check if the counter value modulo 1000000 was zero, the
value actually displayed was queried again, potentially obtaining a
different value (another thread might have incremented the counter).

To force the client to send notifications about garbage collected
objects, the client code forces the GC repeatedly and waits a bit
between the attempts.
parent 213e068b
package ch.usi.dag.disl.test.suite.dispatchmp.app;
import java.util.concurrent.TimeUnit;
public class TargetClass {
protected static int THREAD_COUNT = 3;
private static final int THREAD_COUNT = 3;
private static final int OBJECT_COUNT = 2_000_000;
public static class TCTask implements Runnable {
@Override
public void run() {
final int COUNT = 2000000;
final TargetClass ta[] = new TargetClass[COUNT];
final TargetClass ta[] = new TargetClass[OBJECT_COUNT];
for (int i = 0; i < COUNT; ++i) {
for (int i = 0; i < OBJECT_COUNT; i++) {
ta[i] = new TargetClass();
}
System.out.println("Allocated " + COUNT + " objects");
System.out.println("Allocated " + OBJECT_COUNT + " objects");
}
}
public static void main(final String[] args) throws InterruptedException {
final TCTask task = new TCTask();
for (int i = 0; i < THREAD_COUNT; ++i) {
new Thread(task).start();
final Thread[] threads = new Thread [THREAD_COUNT];
for (int i = 0; i < THREAD_COUNT; i++) {
threads [i] = new Thread(task, "TCTask "+ i);
}
for (Thread thread : threads) {
thread.start();
}
for (Thread thread : threads) {
thread.join();
}
// Force GC of allocated objects.
for (int i = 0; i < 5; i++) {
Runtime.getRuntime().gc();
TimeUnit.SECONDS.sleep(1);
}
}
......
......@@ -6,23 +6,16 @@ import ch.usi.dag.dislreserver.remoteanalysis.RemoteAnalysis;
import ch.usi.dag.dislreserver.shadow.ShadowObject;
// NOTE that this class is not static anymore
public class CodeExecuted extends RemoteAnalysis {
long startTime = 0;
public final class CodeExecuted extends RemoteAnalysis {
AtomicLong totalIntEvents = new AtomicLong();
AtomicLong totalObjEvents = new AtomicLong();
AtomicLong totalFreeEvents = new AtomicLong();
public void intEvent(final int number) {
if(startTime == 0) {
startTime = System.nanoTime();
}
if(totalIntEvents.incrementAndGet() % 1000000 == 0) {
System.out.println("So far received "
+ totalIntEvents + " events...");
final long count = totalIntEvents.incrementAndGet();
if ((count % 1_000_000) == 0) {
System.out.println("So far received "+ count +" events...");
}
}
......@@ -37,17 +30,8 @@ public class CodeExecuted extends RemoteAnalysis {
@Override
public void atExit() {
//System.out.println("Total transport time is "
// + ((System.nanoTime() - startTime) / 1000000) + " ms");
System.out.println("Total number of int events: "
+ totalIntEvents);
System.out.println("Total number of object events: "
+ totalObjEvents);
System.out.println("Total number of free events: "
+ totalFreeEvents);
System.out.println("Total number of int events: "+ totalIntEvents);
System.out.println("Total number of object events: "+ totalObjEvents);
System.out.println("Total number of free events: "+ totalFreeEvents);
}
}
......@@ -13,8 +13,6 @@ public class CodeExecutedRE {
private static short ieId = REDispatch.registerMethod(
"ch.usi.dag.disl.test.suite.dispatchmp.instr.CodeExecuted.intEvent");
private static short oeId = REDispatch.registerMethod(
"ch.usi.dag.disl.test.suite.dispatchmp.instr.CodeExecuted.objectEvent");
public static void intEvent(final int num) {
REDispatch.analysisStart(ieId);
......@@ -24,6 +22,10 @@ public class CodeExecutedRE {
REDispatch.analysisEnd();
}
private static short oeId = REDispatch.registerMethod(
"ch.usi.dag.disl.test.suite.dispatchmp.instr.CodeExecuted.objectEvent");
public static void objectEvent(final Object o) {
REDispatch.analysisStart(oeId);
......
......@@ -7,12 +7,12 @@ import ch.usi.dag.disl.marker.BytecodeMarker;
public class DiSLClass {
@Before(marker = BytecodeMarker.class, args= "aastore", scope = "*TCTask.*")
@Before(marker = BytecodeMarker.class, args= "aastore", scope = "*TCTask.run")
public static void invokedInstr(DynamicContext dc) {
CodeExecutedRE.intEvent(dc.getStackValue(1, int.class));
}
@Before(marker = BytecodeMarker.class, args= "aastore", scope = "*TCTask.*")
@Before(marker = BytecodeMarker.class, args= "aastore", scope = "*TCTask.run")
public static void testing(DynamicContext dc) {
CodeExecutedRE.objectEvent(dc.getStackValue(0, Object.class));
}
......
......@@ -6,4 +6,4 @@ So far received 5000000 events...
So far received 6000000 events...
Total number of int events: 6000000
Total number of object events: 6000000
Total number of free events: 0
Total number of free events: 6000000
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