From 979d5b79867ea3f6e1b6ae2c9ac23d725e2fe27d Mon Sep 17 00:00:00 2001
From: Daniil Titov <dtitov@openjdk.org>
Date: Fri, 2 Mar 2018 10:42:32 -0800
Subject: [PATCH] 8170541: serviceability/jdwp/AllModulesCommandTest.java fails
 intermittently on Windows and Solaris

Reviewed-by: sspitsyn, dholmes
---
 test/hotspot/jtreg/ProblemList.txt                 |  1 -
 .../jtreg/serviceability/jdwp/JdwpReply.java       | 14 ++++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt
index ee4e7050980..6447693d9e0 100644
--- a/test/hotspot/jtreg/ProblemList.txt
+++ b/test/hotspot/jtreg/ProblemList.txt
@@ -79,7 +79,6 @@ runtime/SharedArchiveFile/DefaultUseWithClient.java 8154204 generic-all
 
 # :hotspot_serviceability
 
-serviceability/jdwp/AllModulesCommandTest.java       8170541 generic-all
 serviceability/sa/TestRevPtrsForInvokeDynamic.java   8191270 generic-all
 serviceability/sa/sadebugd/SADebugDTest.java         8163805 generic-all
 
diff --git a/test/hotspot/jtreg/serviceability/jdwp/JdwpReply.java b/test/hotspot/jtreg/serviceability/jdwp/JdwpReply.java
index a3f95a5d509..392b55a8430 100644
--- a/test/hotspot/jtreg/serviceability/jdwp/JdwpReply.java
+++ b/test/hotspot/jtreg/serviceability/jdwp/JdwpReply.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, 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
@@ -47,7 +47,17 @@ public abstract class JdwpReply {
         int dataLength = length - HEADER_LEN;
         if (dataLength > 0) {
             data = new byte[dataLength];
-            ds.read(data, 0, dataLength);
+            int bytesRead = ds.read(data, 0, dataLength);
+            // For large data JDWP agent sends two packets: 1011 bytes in
+            // the first packet (1000 + HEADER_LEN) and the rest in the
+            // second packet.
+            if (bytesRead > 0 && bytesRead < dataLength) {
+                System.out.println("[" + getClass().getName() + "] Only " +
+                        bytesRead + " bytes of " + dataLength + " were " +
+                        "read in the first packet. Reading the rest...");
+                ds.read(data, bytesRead, dataLength - bytesRead);
+            }
+
             parseData(new DataInputStream(new ByteArrayInputStream(data)));
         }
     }