changeset 51418:45d1f2ec5342

8207832: serviceability/sa/ClhsdbCDSCore.java failed with "Couldn't find core file location" Summary: Handle %p in /proc/sys/kernel/core_pattern Reviewed-by: dholmes, hseigel
author iklam
date Wed, 15 Aug 2018 19:22:46 -0700
parents b08c2a94cce1
children c11be049acb8
files src/hotspot/os/linux/os_linux.cpp test/hotspot/jtreg/ProblemList.txt test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java
diffstat 3 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/os/linux/os_linux.cpp	Tue Aug 14 20:46:46 2018 -0700
+++ b/src/hotspot/os/linux/os_linux.cpp	Wed Aug 15 19:22:46 2018 -0700
@@ -5793,11 +5793,21 @@
     core_pattern[ret] = '\0';
   }
 
+  // Replace the %p in the core pattern with the process id. NOTE: we do this
+  // only if the pattern doesn't start with "|", and we support only one %p in
+  // the pattern.
   char *pid_pos = strstr(core_pattern, "%p");
+  const char* tail = (pid_pos != NULL) ? (pid_pos + 2) : "";  // skip over the "%p"
   int written;
 
   if (core_pattern[0] == '/') {
-    written = jio_snprintf(buffer, bufferSize, "%s", core_pattern);
+    if (pid_pos != NULL) {
+      *pid_pos = '\0';
+      written = jio_snprintf(buffer, bufferSize, "%s%d%s", core_pattern,
+                             current_process_id(), tail);
+    } else {
+      written = jio_snprintf(buffer, bufferSize, "%s", core_pattern);
+    }
   } else {
     char cwd[PATH_MAX];
 
@@ -5810,6 +5820,10 @@
       written = jio_snprintf(buffer, bufferSize,
                              "\"%s\" (or dumping to %s/core.%d)",
                              &core_pattern[1], p, current_process_id());
+    } else if (pid_pos != NULL) {
+      *pid_pos = '\0';
+      written = jio_snprintf(buffer, bufferSize, "%s/%s%d%s", p, core_pattern,
+                             current_process_id(), tail);
     } else {
       written = jio_snprintf(buffer, bufferSize, "%s/%s", p, core_pattern);
     }
--- a/test/hotspot/jtreg/ProblemList.txt	Tue Aug 14 20:46:46 2018 -0700
+++ b/test/hotspot/jtreg/ProblemList.txt	Wed Aug 15 19:22:46 2018 -0700
@@ -88,7 +88,6 @@
 # :hotspot_serviceability
 
 serviceability/sa/ClhsdbAttach.java 8193639 solaris-all
-serviceability/sa/ClhsdbCDSCore.java 8207832 linux-x64
 serviceability/sa/ClhsdbCDSJstackPrintAll.java 8193639 solaris-all
 serviceability/sa/ClhsdbField.java 8193639 solaris-all
 serviceability/sa/ClhsdbFindPC.java 8193639 solaris-all
--- a/test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java	Tue Aug 14 20:46:46 2018 -0700
+++ b/test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java	Wed Aug 15 19:22:46 2018 -0700
@@ -201,6 +201,7 @@
             .get();
         stringWithLocation = stringWithLocation.substring(stringWithLocation
             .indexOf(LOCATIONS_STRING) + LOCATIONS_STRING.length());
+        System.out.println("getCoreFileLocation found stringWithLocation = " + stringWithLocation);
         String coreWithPid;
         if (stringWithLocation.contains("or ")) {
             Matcher m = Pattern.compile("or.* ([^ ]+[^\\)])\\)?").matcher(stringWithLocation);