Commit d2ea1487 authored by Lubomir Bulej's avatar Lubomir Bulej

NetReferenceHandler: fix wrong usage of SPEC_MASK.

suite/sendspecial: add dummy events before sending objects with data to force buffer flush in the agent.
suite/shadowstring: remove test as it is now subsumed by the sendspecial test.
parent 8b798750
......@@ -25,12 +25,13 @@ final class NetReferenceHelper {
* extra payload attached.
*/
private static final short SPEC_POS = 63;
private static final long SPEC_MASK = 1L << 63;
private static final long SPEC_MASK = (1L << 1) - 1;
//
static long getUniqueId (final long netReference) {
return netReference & ~SPEC_MASK;
// The mask used here needs to have an absolute position.
return netReference & ~(1L << SPEC_POS);
}
......
......@@ -30,6 +30,18 @@ public class TargetClass {
//
private static short __emptyEventId__ = REDispatch.registerMethod (
"ch.usi.dag.disl.test.suite.sendspecial.instr.Analysis.emptyEvent"
);
static void sendEmpty () {
REDispatch.analysisStart (__emptyEventId__);
REDispatch.analysisEnd ();
}
//
private static void __sendObject (final boolean isSpecial, final Object object) {
REDispatch.sendBoolean (isSpecial);
......@@ -45,10 +57,17 @@ public class TargetClass {
public static void main (final String [] args) throws InterruptedException {
final String string = "Hello, World!";
sendString (false, string);
sendString (true, string);
final Thread thread = new Thread ("Newly Thread");
thread.setDaemon (true);
sendThread (false, thread);
// Send a lot of empty events to force the agent to flush buffers.
for (int i = 0; i < 35000; i++) {
sendEmpty ();
}
sendString (true, string);
sendThread (true, thread);
}
......
......@@ -18,6 +18,12 @@ public class Analysis extends RemoteAnalysis {
}
public void emptyEvent () {
// Called to insert extra events into the client's buffer.
}
//
@Override
public void atExit () {
// do nothing
......@@ -25,7 +31,7 @@ public class Analysis extends RemoteAnalysis {
@Override
public void objectFree (final ShadowObject netRef) {
public void objectFree (final ShadowObject object) {
// do nothing
}
......
string, is special: false, value: Hello, World!
string, is special: false, value: null
thread, is special: false, name: null, daemon: false
string, is special: true, value: Hello, World!
thread, is special: false, name: Newly Thread, daemon: false
thread, is special: true, name: Newly Thread, daemon: false
thread, is special: true, name: Newly Thread, daemon: true
package ch.usi.dag.disl.test.suite.shadowstring.app;
public class TargetClass {
static void empty () {
}
public static void main(final String[] args) throws InterruptedException {
for (int i = 0; i< 20000; i ++) {
empty();
}
}
}
package ch.usi.dag.disl.test.suite.shadowstring.instr;
import ch.usi.dag.dislreserver.remoteanalysis.RemoteAnalysis;
import ch.usi.dag.dislreserver.shadow.ShadowObject;
import ch.usi.dag.dislreserver.shadow.ShadowString;
// NOTE that this class is not static anymore
public class CodeExecuted extends RemoteAnalysis {
public static void receiveObject (final ShadowObject o) {
if (o != null) {
System.out.println (o.toString ());
}
}
public static void receiveData (final ShadowString o) {
if (o != null) {
System.out.println (o.toString ());
}
}
public static void empty () {
}
@Override
public void atExit () {
}
@Override
public void objectFree (final ShadowObject netRef) {
}
}
package ch.usi.dag.disl.test.suite.shadowstring.instr;
import ch.usi.dag.dislre.REDispatch;
// Optimally, this class is automatically created on analysis machine
// and redefines during loading the CodeExecuted class on the client vm
// Even more optimally, this is automatically generated native class with same
// functionality
public class CodeExecutedRE {
private static short RO = REDispatch.registerMethod (
"ch.usi.dag.disl.test.suite.shadowstring.instr.CodeExecuted.receiveObject");
private static short RD = REDispatch.registerMethod (
"ch.usi.dag.disl.test.suite.shadowstring.instr.CodeExecuted.receiveData");
private static short EM = REDispatch.registerMethod (
"ch.usi.dag.disl.test.suite.shadowstring.instr.CodeExecuted.empty");
public static final String DATA = "shadowstring";
public static void sendObject () {
REDispatch.analysisStart (RO);
REDispatch.sendObject (DATA);
REDispatch.analysisEnd ();
}
public static void sendData () {
REDispatch.analysisStart (RD);
REDispatch.sendObjectPlusData (DATA);
REDispatch.analysisEnd ();
}
public static void empty () {
REDispatch.analysisStart (EM);
REDispatch.analysisEnd ();
}
}
package ch.usi.dag.disl.test.suite.shadowstring.instr;
import ch.usi.dag.disl.annotation.AfterReturning;
import ch.usi.dag.disl.annotation.Before;
import ch.usi.dag.disl.marker.BodyMarker;
public class DiSLClass {
@Before (marker = BodyMarker.class, scope = "TargetClass.main")
public static void onMethodEntrance () {
CodeExecutedRE.sendObject ();
}
@Before (marker = BodyMarker.class, scope = "TargetClass.empty")
public static void flush () {
CodeExecutedRE.empty ();
}
@AfterReturning (marker = BodyMarker.class, scope = "TargetClass.main")
public static void onMethodExit () {
CodeExecutedRE.sendData ();
}
}
package ch.usi.dag.disl.test.suite.shadowstring.junit;
import java.io.IOException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import ch.usi.dag.disl.test.suite.ShadowVmTest;
import ch.usi.dag.disl.test.utils.ClientServerEvaluationRunner;
@RunWith (JUnit4.class)
public class ShadowStringTest extends ShadowVmTest {
@Override
protected void _checkOutErr (
final ClientServerEvaluationRunner runner
) throws IOException {
runner.assertShadowOut ("evaluation.out.resource");
}
}
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