[RFA/JDWP] Event basics

Cedric Berger cedric@berger.to
Wed Jun 22 19:56:00 GMT 2005


Hi Keith,

Here is just a little (or big) comment about that code: I don't
know if performance is an issue or not in your code, but if
performance is an issue, then I think that the code as written
is very inefficient:

+  /**
+   * Converts this event into to a JDWP packet
+   *
+   * @param  requestId  the request id that wanted this event (or 0)
+   * @returns a <code>JdwpPacket</code> of the events or <code>null</code>
+   */
+  public JdwpPacket toPacket (int requestId, byte suspendPolicy)
+  {
+    JdwpPacket pkt;
+    try
+      {
+	ByteArrayOutputStream data = new ByteArrayOutputStream ();
+	DataOutputStream outStream = new DataOutputStream (data);
+
+	outStream.writeByte (suspendPolicy);
+	outStream.writeInt (1);
+	outStream.writeByte (_eventKind);
+	outStream.writeInt (requestId);
+	_writeData (outStream);
+
+	pkt = new JdwpCommandPacket (JdwpConstants.CommandSet.Event.value,
+				     JdwpConstants.CommandSet.Event.Composite);
+	pkt.setData (data.toByteArray ());
+      }
+    catch (IOException ioe)
+      {
+	pkt = null;
+      }
+
+    return pkt;
+  }


You allocate here a lot of different object (data, outStream, pkt - 
which each allocate
internal objects) just to generate a "JdwpPacket ", which will finally 
be written to a
socket I guess (?). I think that you could rewrite the code to allocate 
much less
objects during serialization/deserialization, and perform much less 
copy. Actually,
if you wanted, you could use java.nio and allocate almost NO objects.

Feel free to ignore me if I'm out of context here :)
Cedric



More information about the Java-patches mailing list