View | Details | Raw Unified | Return to bug 94452 | Differences between
and this patch

Collapse All | Expand All

(-)jdi/org/eclipse/jdi/internal/connect/PacketReceiveManager.java (-10 / +62 lines)
Lines 14-19 Link Here
14
import java.io.InterruptedIOException;
14
import java.io.InterruptedIOException;
15
import java.text.MessageFormat;
15
import java.text.MessageFormat;
16
import java.util.ArrayList;
16
import java.util.ArrayList;
17
import java.util.Iterator;
17
import java.util.LinkedList;
18
import java.util.LinkedList;
18
import java.util.ListIterator;
19
import java.util.ListIterator;
19
20
Lines 50-55 Link Here
50
    private ArrayList fTimedOutPackets;
51
    private ArrayList fTimedOutPackets;
51
    
52
    
52
    private VirtualMachineImpl fVM;
53
    private VirtualMachineImpl fVM;
54
    
55
    private int fRequestCount = 0;
56
    private long fTotalTime = 0L;
57
    private LinkedList fRequestsProcessed = new LinkedList();
53
58
54
    /**
59
    /**
55
     * Create a new thread that receives packets from the Virtual Machine.
60
     * Create a new thread that receives packets from the Virtual Machine.
Lines 133-140 Link Here
133
    /**
138
    /**
134
     * @return Returns a specified Reply Packet from the Virtual Machine.
139
     * @return Returns a specified Reply Packet from the Virtual Machine.
135
     */
140
     */
136
    public JdwpReplyPacket getReply(int id, long timeToWait) {
141
    public JdwpReplyPacket getReply(JdwpCommandPacket request, long timeToWait) {
137
        JdwpReplyPacket packet = null;
142
        JdwpReplyPacket packet = null;
143
        int id = request.getId();
138
144
139
        long remainingTime = timeToWait;
145
        long remainingTime = timeToWait;
140
        synchronized (fReplyPackets) {
146
        synchronized (fReplyPackets) {
Lines 159-164 Link Here
159
        if (packet == null) {
165
        if (packet == null) {
160
            synchronized (fReplyPackets) {
166
            synchronized (fReplyPackets) {
161
                packet = removeReplyPacket(id);
167
                packet = removeReplyPacket(id);
168
                if (packet == null) {
169
                	handleTimeout(request);
170
                }
162
            }
171
            }
163
        }
172
        }
164
173
Lines 169-179 Link Here
169
        // Check for a timeout.
178
        // Check for a timeout.
170
        if (packet == null) {
179
        if (packet == null) {
171
            synchronized (fTimedOutPackets) {
180
            synchronized (fTimedOutPackets) {
172
                fTimedOutPackets.add(new Integer(id));
181
                fTimedOutPackets.add(request);
173
            }
182
            }
174
            throw new TimeoutException(MessageFormat.format(ConnectMessages.PacketReceiveManager_0, new String[] {id+""})); //$NON-NLS-1$
183
            throw new TimeoutException(MessageFormat.format(ConnectMessages.PacketReceiveManager_0, new String[] {id+""})); //$NON-NLS-1$
184
            
175
        }
185
        }
176
186
187
        request.setReply(packet);
188
        fRequestCount++;
189
        fTotalTime += packet.getTimestamp() - request.getTimestamp();
177
        return packet;
190
        return packet;
178
    }
191
    }
179
192
Lines 181-187 Link Here
181
     * @return Returns a specified Reply Packet from the Virtual Machine.
194
     * @return Returns a specified Reply Packet from the Virtual Machine.
182
     */
195
     */
183
    public JdwpReplyPacket getReply(JdwpCommandPacket commandPacket) {
196
    public JdwpReplyPacket getReply(JdwpCommandPacket commandPacket) {
184
        return getReply(commandPacket.getId(), fVM.getRequestTimeout());
197
    	synchronized (fRequestsProcessed) {	
198
    		fRequestsProcessed.add(commandPacket);
199
		}
200
        return getReply(commandPacket, fVM.getRequestTimeout());
185
    }
201
    }
186
202
187
    /**
203
    /**
Lines 231-239 Link Here
231
     * Add a command packet to the command packet list.
247
     * Add a command packet to the command packet list.
232
     */
248
     */
233
    private void addCommandPacket(JdwpCommandPacket packet) {
249
    private void addCommandPacket(JdwpCommandPacket packet) {
234
        if (isTimedOut(packet)) {
235
        	return; // already timed out. No need to keep this one
236
        }
237
        synchronized (fCommandPackets) {
250
        synchronized (fCommandPackets) {
238
            fCommandPackets.add(packet);
251
            fCommandPackets.add(packet);
239
            fCommandPackets.notifyAll();
252
            fCommandPackets.notifyAll();
Lines 246-259 Link Here
246
     * @param packet response packet
259
     * @param packet response packet
247
     * @return whether the request for the given packet has already timed out
260
     * @return whether the request for the given packet has already timed out
248
     */
261
     */
249
    private boolean isTimedOut(JdwpPacket packet) {
262
    private boolean isTimedOut(JdwpReplyPacket packet) {
250
        synchronized (fTimedOutPackets) {
263
        synchronized (fTimedOutPackets) {
251
        	if (fTimedOutPackets.isEmpty()) {
264
        	if (fTimedOutPackets.isEmpty()) {
252
        		return false;
265
        		return false;
253
        	}
266
        	}
254
            Integer id = new Integer(packet.getId());
267
        	Iterator iterator = fTimedOutPackets.listIterator();
255
            return fTimedOutPackets.remove(id);
268
        	while (iterator.hasNext()) {
256
        }    	
269
        		JdwpCommandPacket request = (JdwpCommandPacket) iterator.next();
270
        		if (request.getId() == packet.getId()) {
271
        			iterator.remove();
272
        			request.setReply(packet);
273
        			//
274
        			timeoutResponseReceived(request);
275
        			//
276
        			return true;
277
        		}
278
        	}
279
        }    
280
        return false;
281
    }
282
    
283
    /**
284
     * A request has timed out
285
     * 
286
     * @param request
287
     */
288
    private void handleTimeout(JdwpCommandPacket request) {
289
    	System.out.println("Timeout: " + request.toString());
290
    	int index = fRequestsProcessed.indexOf(request);
291
    	for (int i = 0; i < 100; i++) {
292
    		index--;
293
    		if (i >= 0) { 
294
    			JdwpCommandPacket prevRequest = (JdwpCommandPacket) fRequestsProcessed.get(index);
295
    			System.out.println("\t -" + (i + 1) + ": " + prevRequest.toString());
296
    		}
297
    	}
298
    	
299
    	
300
    }
301
    
302
    /**
303
     * A request has timed out and a response was later received
304
     * @param request
305
     */
306
    private void timeoutResponseReceived(JdwpCommandPacket request) {
307
    	
257
    }
308
    }
258
309
259
    /**
310
    /**
Lines 277-282 Link Here
277
        // Read a packet from the Input Stream.
328
        // Read a packet from the Input Stream.
278
        byte[] bytes = getConnection().readPacket();
329
        byte[] bytes = getConnection().readPacket();
279
        JdwpPacket packet = JdwpPacket.build(bytes);
330
        JdwpPacket packet = JdwpPacket.build(bytes);
331
        packet.timestamp();
280
        // Add packet to command or reply queue.
332
        // Add packet to command or reply queue.
281
        if (packet instanceof JdwpCommandPacket)
333
        if (packet instanceof JdwpCommandPacket)
282
            addCommandPacket((JdwpCommandPacket) packet);
334
            addCommandPacket((JdwpCommandPacket) packet);
(-)jdi/org/eclipse/jdi/internal/connect/PacketSendManager.java (-1 / +2 lines)
Lines 103-109 Link Here
103
		// Put available packets on Output Stream.
103
		// Put available packets on Output Stream.
104
		while (packetsToSend.size() > 0) {
104
		while (packetsToSend.size() > 0) {
105
			// Note that only JdwpPackets are added to the list, so a ClassCastException can't occur.
105
			// Note that only JdwpPackets are added to the list, so a ClassCastException can't occur.
106
			JdwpPacket packet = (JdwpPacket)packetsToSend.removeFirst();			
106
			JdwpPacket packet = (JdwpPacket)packetsToSend.removeFirst();
107
			packet.timestamp();
107
			byte[] bytes = packet.getPacketAsBytes();
108
			byte[] bytes = packet.getPacketAsBytes();
108
			getConnection().writePacket(bytes);
109
			getConnection().writePacket(bytes);
109
		}
110
		}
(-)jdi/org/eclipse/jdi/internal/jdwp/JdwpCommandPacket.java (+26 lines)
Lines 169-174 Link Here
169
	private static int fgNextId = 1;
169
	private static int fgNextId = 1;
170
	/** Command, note that this field is 256 * JDWP CommandSet (unsigned) + JDWP Command. */
170
	/** Command, note that this field is 256 * JDWP CommandSet (unsigned) + JDWP Command. */
171
	private int fCommand;
171
	private int fCommand;
172
	
173
	private JdwpReplyPacket fReply;
172
174
173
	/**
175
	/**
174
	 * Creates new JdwpCommandPacket.
176
	 * Creates new JdwpCommandPacket.
Lines 603-608 Link Here
603
			buffer.append(getCommand());
605
			buffer.append(getCommand());
604
			break;
606
			break;
605
		}
607
		}
608
		JdwpReplyPacket reply = getReply();
609
		if (reply != null) {
610
			buffer.append("[");
611
			buffer.append(reply.getTimestamp() - getTimestamp());
612
			buffer.append("ms]");
613
		}
606
		return buffer.toString();
614
		return buffer.toString();
607
	}
615
	}
616
	
617
	/**
618
	 * Sets the reply for this request.
619
	 * 
620
	 * @param reply reply packet
621
	 */
622
	public void setReply(JdwpReplyPacket reply) {
623
		fReply = reply;
624
	}
625
	
626
	/**
627
	 * Returns the reply for this request, or <code>null</code> if none.
628
	 * 
629
	 * @return the reply for this request, or <code>null</code>
630
	 */
631
	public JdwpReplyPacket getReply() {
632
		return fReply;
633
	}
608
}
634
}
(-)jdi/org/eclipse/jdi/internal/jdwp/JdwpPacket.java (+19 lines)
Lines 35-40 Link Here
35
	protected byte fFlags = 0;
35
	protected byte fFlags = 0;
36
	protected byte[] fDataBuf = null;
36
	protected byte[] fDataBuf = null;
37
	
37
	
38
	private long fTimestamp;
39
	
38
	/**
40
	/**
39
	 * Set Id.
41
	 * Set Id.
40
	 */
42
	 */
Lines 236-239 Link Here
236
		getConstantMaps();
238
		getConstantMaps();
237
		return fgFlagStrings;
239
		return fgFlagStrings;
238
	}
240
	}
241
	
242
	/**
243
	 * Sets the timestamp of this packet to the current time.
244
	 */
245
	public void timestamp() {
246
		fTimestamp = System.currentTimeMillis();
247
	}
248
	
249
	/**
250
	 * Returns the current timestamp of this packet. The timestamp
251
	 * represents the time this packet was sent or received.
252
	 * 
253
	 * @return the current timestamp of this packet
254
	 */
255
	public long getTimestamp() {
256
		return fTimestamp;
257
	}
239
}
258
}

Return to bug 94452