Commit 7a0fabce authored by Lukáš Marek's avatar Lukáš Marek

Fixed some problems in JBBuffer

dispatch2 test now reports time
parent 24a94e9b
......@@ -1650,6 +1650,8 @@ static void jb_object_tagging(JNIEnv * jni_env, process_buffs * pb,
exit_critical_section(jvmti_env, tagging_lock);
}
// TODO !! buffers are not sorted correctly - buffer id needed for each thread
static void * jb_worker_loop(void * obj) {
// TODO ! local references ???
......
......@@ -5,103 +5,112 @@ import java.io.IOException;
// goal of this class is to mimic the buffering of the native agent
public final class JBBuffer {
// TODO ! JB - replace with extensible arrays and number of analysis
private static final int ONE_K = 1024;
private static final int THRESHOLD = 50 * ONE_K;
private static final int MAX_SIZE = THRESHOLD + 2 * ONE_K;
// TODO ! JB - add constant from server
private static final byte ANALYSIS_MSG_NUM = 1;
private Long ownerThread;
private UglyByteArrayOutputStream uos = new UglyByteArrayOutputStream(MAX_SIZE);
private DataOutputStream dos = new DataOutputStream(uos);
private int requestCount;
private int requestCountPos;
private int requestLenPos;
private TagBuffer objectTB = new TagBuffer(MAX_SIZE);
public void init() {
ownerThread = Thread.currentThread().getId();
}
public void reset() {
uos.reset();
objectTB.reset();
ownerThread = null;
}
public long getOwnerThread() { return ownerThread; }
public byte[] getDataAsArray() {
return uos.getBuffer();
}
public int sizeInBytes() {
private Long ownerThread;
private UglyByteArrayOutputStream uos = new UglyByteArrayOutputStream(
MAX_SIZE);
private DataOutputStream dos = new DataOutputStream(uos);
private int requestCount;
private int requestCountPos;
private int requestLenPos;
private TagBuffer objectTB = new TagBuffer(MAX_SIZE);
public void init() {
ownerThread = Thread.currentThread().getId();
}
public void reset() {
uos.reset();
objectTB.reset();
ownerThread = null;
requestCount = 0;
requestCountPos = -1;
requestLenPos = -1;
}
public long getOwnerThread() {
return ownerThread;
}
public byte[] getDataAsArray() {
return uos.getBuffer();
}
public int sizeInBytes() {
return uos.size();
}
public TagBuffer getObjectTB() {
return objectTB;
}
public void analysisStart(short analysisMethodId) {
// initialize buffer
if(requestCount == 0) {
// msg type
putByte(ANALYSIS_MSG_NUM);
// TODO ! JB - this number is non-negative - problem with total order buffers
// thread id
putLong(ownerThread);
requestCountPos = sizeInBytes();
// request count space init
putInt(requestCount);
}
// analysis method id
putShort(analysisMethodId);
requestLenPos = sizeInBytes();
// request len space init
putShort((short) 0);
}
// indicates whether buffer is full
public boolean analysisEnd() {
// update the length of analysis request
int requestLen = sizeInBytes() - requestCountPos - (Short.SIZE / Byte.SIZE);
uos.setPosition(requestLenPos);
putShort((short) requestLen);
uos.resetPosition();
++requestCount;
uos.setPosition(requestCountPos);
putInt(requestCount);
uos.resetPosition();
// send the buffer
if(sizeInBytes() > THRESHOLD) {
return true;
}
return false;
}
public TagBuffer getObjectTB() {
return objectTB;
}
public void analysisStart(short analysisMethodId) {
// initialize buffer
if (requestCount == 0) {
// msg type
putByte(ANALYSIS_MSG_NUM);
// TODO ! JB - this number is non-negative - problem with total
// order buffers
// thread id
putLong(ownerThread);
requestCountPos = sizeInBytes();
// request count space init
putInt(requestCount);
}
// analysis method id
putShort(analysisMethodId);
requestLenPos = sizeInBytes();
// request len space init
putShort((short) 0);
}
// indicates whether buffer is full
public boolean analysisEnd() {
// update the length of analysis request
int requestLen = sizeInBytes() - requestLenPos
- (Short.SIZE / Byte.SIZE);
uos.setPosition(requestLenPos);
putShort((short) requestLen);
uos.resetPosition();
++requestCount;
uos.setPosition(requestCountPos);
putInt(requestCount);
uos.resetPosition();
// send the buffer
if (sizeInBytes() > THRESHOLD) {
return true;
}
return false;
}
public void putBoolean(boolean toPut) {
try {
dos.writeBoolean(toPut);
......@@ -134,14 +143,14 @@ public final class JBBuffer {
}
}
public void putInt(int toPut) {
try {
public void putInt(int toPut) {
try {
dos.writeInt(toPut);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
public void putLong(long toPut) {
try {
dos.writeLong(toPut);
......@@ -156,7 +165,7 @@ public final class JBBuffer {
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void putDouble(long toPut) {
......@@ -165,14 +174,14 @@ public final class JBBuffer {
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void putObject(Object toPut) {
objectTB.add(toPut, sizeInBytes());
// net reference type is long
// net reference type is long
putLong(0);
}
}
}
......@@ -3,6 +3,8 @@ public class TargetClass {
public static void main(String[] args) throws InterruptedException {
long start = System.nanoTime();
int COUNT = 10000000;
TargetClass ta[] = new TargetClass[COUNT];
......@@ -13,6 +15,7 @@ public class TargetClass {
ta[i] = new TargetClass();
}
System.out.println("Sent " + i + " events");
System.out.println("Sent " + i + " events in "
+ (System.nanoTime() - start) / 1000000 + " ms");
}
}
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