Index: jdi/org/eclipse/jdi/internal/connect/PacketReceiveManager.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/connect/PacketReceiveManager.java,v
retrieving revision 1.18
diff -u -r1.18 PacketReceiveManager.java
--- jdi/org/eclipse/jdi/internal/connect/PacketReceiveManager.java 16 May 2005 21:02:40 -0000 1.18
+++ jdi/org/eclipse/jdi/internal/connect/PacketReceiveManager.java 21 Jun 2005 20:53:45 -0000
@@ -14,6 +14,7 @@
import java.io.InterruptedIOException;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
@@ -50,6 +51,10 @@
private ArrayList fTimedOutPackets;
private VirtualMachineImpl fVM;
+
+ private int fRequestCount = 0;
+ private long fTotalTime = 0L;
+ private LinkedList fRequestsProcessed = new LinkedList();
/**
* Create a new thread that receives packets from the Virtual Machine.
@@ -133,8 +138,9 @@
/**
* @return Returns a specified Reply Packet from the Virtual Machine.
*/
- public JdwpReplyPacket getReply(int id, long timeToWait) {
+ public JdwpReplyPacket getReply(JdwpCommandPacket request, long timeToWait) {
JdwpReplyPacket packet = null;
+ int id = request.getId();
long remainingTime = timeToWait;
synchronized (fReplyPackets) {
@@ -159,6 +165,9 @@
if (packet == null) {
synchronized (fReplyPackets) {
packet = removeReplyPacket(id);
+ if (packet == null) {
+ handleTimeout(request);
+ }
}
}
@@ -169,11 +178,15 @@
// Check for a timeout.
if (packet == null) {
synchronized (fTimedOutPackets) {
- fTimedOutPackets.add(new Integer(id));
+ fTimedOutPackets.add(request);
}
throw new TimeoutException(MessageFormat.format(ConnectMessages.PacketReceiveManager_0, new String[] {id+""})); //$NON-NLS-1$
+
}
+ request.setReply(packet);
+ fRequestCount++;
+ fTotalTime += packet.getTimestamp() - request.getTimestamp();
return packet;
}
@@ -181,7 +194,10 @@
* @return Returns a specified Reply Packet from the Virtual Machine.
*/
public JdwpReplyPacket getReply(JdwpCommandPacket commandPacket) {
- return getReply(commandPacket.getId(), fVM.getRequestTimeout());
+ synchronized (fRequestsProcessed) {
+ fRequestsProcessed.add(commandPacket);
+ }
+ return getReply(commandPacket, fVM.getRequestTimeout());
}
/**
@@ -231,9 +247,6 @@
* Add a command packet to the command packet list.
*/
private void addCommandPacket(JdwpCommandPacket packet) {
- if (isTimedOut(packet)) {
- return; // already timed out. No need to keep this one
- }
synchronized (fCommandPackets) {
fCommandPackets.add(packet);
fCommandPackets.notifyAll();
@@ -246,14 +259,52 @@
* @param packet response packet
* @return whether the request for the given packet has already timed out
*/
- private boolean isTimedOut(JdwpPacket packet) {
+ private boolean isTimedOut(JdwpReplyPacket packet) {
synchronized (fTimedOutPackets) {
if (fTimedOutPackets.isEmpty()) {
return false;
}
- Integer id = new Integer(packet.getId());
- return fTimedOutPackets.remove(id);
- }
+ Iterator iterator = fTimedOutPackets.listIterator();
+ while (iterator.hasNext()) {
+ JdwpCommandPacket request = (JdwpCommandPacket) iterator.next();
+ if (request.getId() == packet.getId()) {
+ iterator.remove();
+ request.setReply(packet);
+ //
+ timeoutResponseReceived(request);
+ //
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * A request has timed out
+ *
+ * @param request
+ */
+ private void handleTimeout(JdwpCommandPacket request) {
+ System.out.println("Timeout: " + request.toString());
+ int index = fRequestsProcessed.indexOf(request);
+ for (int i = 0; i < 100; i++) {
+ index--;
+ if (i >= 0) {
+ JdwpCommandPacket prevRequest = (JdwpCommandPacket) fRequestsProcessed.get(index);
+ System.out.println("\t -" + (i + 1) + ": " + prevRequest.toString());
+ }
+ }
+
+
+ }
+
+ /**
+ * A request has timed out and a response was later received
+ * @param request
+ */
+ private void timeoutResponseReceived(JdwpCommandPacket request) {
+
}
/**
@@ -277,6 +328,7 @@
// Read a packet from the Input Stream.
byte[] bytes = getConnection().readPacket();
JdwpPacket packet = JdwpPacket.build(bytes);
+ packet.timestamp();
// Add packet to command or reply queue.
if (packet instanceof JdwpCommandPacket)
addCommandPacket((JdwpCommandPacket) packet);
Index: jdi/org/eclipse/jdi/internal/connect/PacketSendManager.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/connect/PacketSendManager.java,v
retrieving revision 1.13
diff -u -r1.13 PacketSendManager.java
--- jdi/org/eclipse/jdi/internal/connect/PacketSendManager.java 6 Apr 2005 21:10:48 -0000 1.13
+++ jdi/org/eclipse/jdi/internal/connect/PacketSendManager.java 21 Jun 2005 20:53:45 -0000
@@ -103,7 +103,8 @@
// Put available packets on Output Stream.
while (packetsToSend.size() > 0) {
// Note that only JdwpPackets are added to the list, so a ClassCastException can't occur.
- JdwpPacket packet = (JdwpPacket)packetsToSend.removeFirst();
+ JdwpPacket packet = (JdwpPacket)packetsToSend.removeFirst();
+ packet.timestamp();
byte[] bytes = packet.getPacketAsBytes();
getConnection().writePacket(bytes);
}
Index: jdi/org/eclipse/jdi/internal/jdwp/JdwpCommandPacket.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/jdwp/JdwpCommandPacket.java,v
retrieving revision 1.20
diff -u -r1.20 JdwpCommandPacket.java
--- jdi/org/eclipse/jdi/internal/jdwp/JdwpCommandPacket.java 16 May 2005 13:47:41 -0000 1.20
+++ jdi/org/eclipse/jdi/internal/jdwp/JdwpCommandPacket.java 21 Jun 2005 20:53:45 -0000
@@ -169,6 +169,8 @@
private static int fgNextId = 1;
/** Command, note that this field is 256 * JDWP CommandSet (unsigned) + JDWP Command. */
private int fCommand;
+
+ private JdwpReplyPacket fReply;
/**
* Creates new JdwpCommandPacket.
@@ -603,6 +605,30 @@
buffer.append(getCommand());
break;
}
+ JdwpReplyPacket reply = getReply();
+ if (reply != null) {
+ buffer.append("[");
+ buffer.append(reply.getTimestamp() - getTimestamp());
+ buffer.append("ms]");
+ }
return buffer.toString();
}
+
+ /**
+ * Sets the reply for this request.
+ *
+ * @param reply reply packet
+ */
+ public void setReply(JdwpReplyPacket reply) {
+ fReply = reply;
+ }
+
+ /**
+ * Returns the reply for this request, or null
if none.
+ *
+ * @return the reply for this request, or null
+ */
+ public JdwpReplyPacket getReply() {
+ return fReply;
+ }
}
Index: jdi/org/eclipse/jdi/internal/jdwp/JdwpPacket.java
===================================================================
RCS file: /home/eclipse/org.eclipse.jdt.debug/jdi/org/eclipse/jdi/internal/jdwp/JdwpPacket.java,v
retrieving revision 1.11
diff -u -r1.11 JdwpPacket.java
--- jdi/org/eclipse/jdi/internal/jdwp/JdwpPacket.java 24 Feb 2005 14:50:57 -0000 1.11
+++ jdi/org/eclipse/jdi/internal/jdwp/JdwpPacket.java 21 Jun 2005 20:53:46 -0000
@@ -35,6 +35,8 @@
protected byte fFlags = 0;
protected byte[] fDataBuf = null;
+ private long fTimestamp;
+
/**
* Set Id.
*/
@@ -236,4 +238,21 @@
getConstantMaps();
return fgFlagStrings;
}
+
+ /**
+ * Sets the timestamp of this packet to the current time.
+ */
+ public void timestamp() {
+ fTimestamp = System.currentTimeMillis();
+ }
+
+ /**
+ * Returns the current timestamp of this packet. The timestamp
+ * represents the time this packet was sent or received.
+ *
+ * @return the current timestamp of this packet
+ */
+ public long getTimestamp() {
+ return fTimestamp;
+ }
}