8193258: Better usage of JDWP HEADER SIZE
authorclanger
Tue, 12 Dec 2017 09:16:12 +0100
changeset 48242 61e60548c0cf
parent 48241 18d487a1f933
child 48243 ddba406af760
8193258: Better usage of JDWP HEADER SIZE Reviewed-by: sspitsyn, cjplummer
src/jdk.jdi/share/native/libdt_shmem/SharedMemoryConnection.c
src/jdk.jdi/share/native/libdt_shmem/shmemBack.c
src/jdk.jdi/share/native/libdt_shmem/shmemBase.c
src/jdk.jdwp.agent/share/native/include/jdwpTransport.h
src/jdk.jdwp.agent/share/native/libdt_socket/socketTransport.c
src/jdk.jdwp.agent/share/native/libjdwp/inStream.c
src/jdk.jdwp.agent/share/native/libjdwp/inStream.h
src/jdk.jdwp.agent/share/native/libjdwp/outStream.c
--- a/src/jdk.jdi/share/native/libdt_shmem/SharedMemoryConnection.c	Mon Dec 11 19:56:44 2017 -0800
+++ b/src/jdk.jdi/share/native/libdt_shmem/SharedMemoryConnection.c	Tue Dec 12 09:16:12 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -111,7 +111,7 @@
     jint tmpInt;
 
     total_length = str->type.cmd.len;
-    data_length = total_length - 11;
+    data_length = total_length - JDWP_HEADER_SIZE;
 
     /* total packet length is header + data */
     array = (*env)->NewByteArray(env, total_length);
@@ -142,7 +142,7 @@
     /* finally the data */
 
     if (data_length > 0) {
-        (*env)->SetByteArrayRegion(env, array, 11,
+        (*env)->SetByteArrayRegion(env, array, JDWP_HEADER_SIZE,
                                    data_length, str->type.cmd.data);
         if ((*env)->ExceptionOccurred(env)) {
             return NULL;
@@ -168,7 +168,7 @@
 {
     jsize total_length, data_length;
     jbyte *data;
-    unsigned char pktHeader[11]; /* sizeof length + id + flags + cmdSet + cmd */
+    unsigned char pktHeader[JDWP_HEADER_SIZE];
 
     /*
      * Get the packet header
--- a/src/jdk.jdi/share/native/libdt_shmem/shmemBack.c	Mon Dec 11 19:56:44 2017 -0800
+++ b/src/jdk.jdi/share/native/libdt_shmem/shmemBack.c	Tue Dec 12 09:16:12 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -270,7 +270,7 @@
     if (packet == NULL) {
         RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, "packet is null");
     }
-    if (packet->type.cmd.len < 11) {
+    if (packet->type.cmd.len < JDWP_HEADER_SIZE) {
         RETURN_ERROR(JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT, "invalid length");
     }
     if (connection == NULL) {
--- a/src/jdk.jdi/share/native/libdt_shmem/shmemBase.c	Mon Dec 11 19:56:44 2017 -0800
+++ b/src/jdk.jdi/share/native/libdt_shmem/shmemBase.c	Tue Dec 12 09:16:12 2017 +0100
@@ -1049,7 +1049,7 @@
         CHECK_ERROR(sendBytes(connection, &packet->type.cmd.cmd, sizeof(jbyte)));
     }
 
-    data_length = packet->type.cmd.len - 11;
+    data_length = packet->type.cmd.len - JDWP_HEADER_SIZE;
     SHMEM_GUARANTEE(data_length >= 0);
     CHECK_ERROR(sendBytes(connection, &data_length, sizeof(jint)));
 
@@ -1125,10 +1125,10 @@
     if (data_length < 0) {
         return SYS_ERR;
     } else if (data_length == 0) {
-        packet->type.cmd.len = 11;
+        packet->type.cmd.len = JDWP_HEADER_SIZE;
         packet->type.cmd.data = NULL;
     } else {
-        packet->type.cmd.len = data_length + 11;
+        packet->type.cmd.len = data_length + JDWP_HEADER_SIZE;
         packet->type.cmd.data = (*callback->alloc)(data_length);
         if (packet->type.cmd.data == NULL) {
             return SYS_ERR;
--- a/src/jdk.jdwp.agent/share/native/include/jdwpTransport.h	Mon Dec 11 19:56:44 2017 -0800
+++ b/src/jdk.jdwp.agent/share/native/include/jdwpTransport.h	Tue Dec 12 09:16:12 2017 +0100
@@ -96,6 +96,8 @@
  * See: http://java.sun.com/j2se/1.5/docs/guide/jpda/jdwp-spec.html
  */
 
+#define JDWP_HEADER_SIZE 11
+
 enum {
     /*
      * If additional flags are added that apply to jdwpCmdPacket,
--- a/src/jdk.jdwp.agent/share/native/libdt_socket/socketTransport.c	Mon Dec 11 19:56:44 2017 -0800
+++ b/src/jdk.jdwp.agent/share/native/libdt_socket/socketTransport.c	Tue Dec 12 09:16:12 2017 +0100
@@ -70,7 +70,6 @@
             RETURN_IO_ERROR("recv error"); \
         }
 
-#define HEADER_SIZE     11
 #define MAX_DATA_SIZE 1000
 
 static jint recv_fully(int, char *, int);
@@ -790,7 +789,7 @@
     /*
      * room for header and up to MAX_DATA_SIZE data bytes
      */
-    char header[HEADER_SIZE + MAX_DATA_SIZE];
+    char header[JDWP_HEADER_SIZE + MAX_DATA_SIZE];
     jbyte *data;
 
     /* packet can't be null */
@@ -799,7 +798,7 @@
     }
 
     len = packet->type.cmd.len;         /* includes header */
-    data_len = len - HEADER_SIZE;
+    data_len = len - JDWP_HEADER_SIZE;
 
     /* bad packet */
     if (data_len < 0) {
@@ -825,15 +824,15 @@
     data = packet->type.cmd.data;
     /* Do one send for short packets, two for longer ones */
     if (data_len <= MAX_DATA_SIZE) {
-        memcpy(header + HEADER_SIZE, data, data_len);
-        if (send_fully(socketFD, (char *)&header, HEADER_SIZE + data_len) !=
-            HEADER_SIZE + data_len) {
+        memcpy(header + JDWP_HEADER_SIZE, data, data_len);
+        if (send_fully(socketFD, (char *)&header, JDWP_HEADER_SIZE + data_len) !=
+            JDWP_HEADER_SIZE + data_len) {
             RETURN_IO_ERROR("send failed");
         }
     } else {
-        memcpy(header + HEADER_SIZE, data, MAX_DATA_SIZE);
-        if (send_fully(socketFD, (char *)&header, HEADER_SIZE + MAX_DATA_SIZE) !=
-            HEADER_SIZE + MAX_DATA_SIZE) {
+        memcpy(header + JDWP_HEADER_SIZE, data, MAX_DATA_SIZE);
+        if (send_fully(socketFD, (char *)&header, JDWP_HEADER_SIZE + MAX_DATA_SIZE) !=
+            JDWP_HEADER_SIZE + MAX_DATA_SIZE) {
             RETURN_IO_ERROR("send failed");
         }
         /* Send the remaining data bytes right out of the data area. */
--- a/src/jdk.jdwp.agent/share/native/libjdwp/inStream.c	Mon Dec 11 19:56:44 2017 -0800
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/inStream.c	Tue Dec 12 09:16:12 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,7 +43,7 @@
 {
     stream->packet = packet;
     stream->error = JDWP_ERROR(NONE);
-    stream->left = packet.type.cmd.len;
+    stream->left = packet.type.cmd.len - JDWP_HEADER_SIZE;
     stream->current = packet.type.cmd.data;
     stream->refs = bagCreateBag(sizeof(jobject), INITIAL_REF_ALLOC);
     if (stream->refs == NULL) {
@@ -411,12 +411,6 @@
     return string;
 }
 
-jboolean
-inStream_endOfInput(PacketInputStream *stream)
-{
-    return (stream->left > 0);
-}
-
 jdwpError
 inStream_error(PacketInputStream *stream)
 {
@@ -424,7 +418,8 @@
 }
 
 void
-inStream_clearError(PacketInputStream *stream) {
+inStream_clearError(PacketInputStream *stream)
+{
     stream->error = JDWP_ERROR(NONE);
 }
 
--- a/src/jdk.jdwp.agent/share/native/libjdwp/inStream.h	Mon Dec 11 19:56:44 2017 -0800
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/inStream.h	Tue Dec 12 09:16:12 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -74,7 +74,6 @@
 
 jdwpError inStream_skipBytes(PacketInputStream *stream, jint count);
 
-jboolean inStream_endOfInput(PacketInputStream *stream);
 jdwpError inStream_error(PacketInputStream *stream);
 void inStream_clearError(PacketInputStream *stream);
 void inStream_destroy(PacketInputStream *stream);
--- a/src/jdk.jdwp.agent/share/native/libjdwp/outStream.c	Mon Dec 11 19:56:44 2017 -0800
+++ b/src/jdk.jdwp.agent/share/native/libjdwp/outStream.c	Tue Dec 12 09:16:12 2017 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -418,7 +418,7 @@
      * packet.
      */
     if (stream->firstSegment.next == NULL) {
-        stream->packet.type.cmd.len = 11 + stream->firstSegment.length;
+        stream->packet.type.cmd.len = JDWP_HEADER_SIZE + stream->firstSegment.length;
         stream->packet.type.cmd.data = stream->firstSegment.data;
         rc = transport_sendPacket(&stream->packet);
         return rc;
@@ -447,7 +447,7 @@
         segment = segment->next;
     }
 
-    stream->packet.type.cmd.len = 11 + len;
+    stream->packet.type.cmd.len = JDWP_HEADER_SIZE + len;
     stream->packet.type.cmd.data = data;
     rc = transport_sendPacket(&stream->packet);
     stream->packet.type.cmd.data = NULL;