11/*
2- * Copyright (c) 2020, 2023 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2020, 2025 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -203,6 +203,7 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
203203
204204 private static final String CORE_PATTERN_FILE_NAME = "/proc/sys/kernel/core_pattern" ;
205205 private static final String LOCATION_STRING = "location: " ;
206+ private static final String ALT_LOCATION_STRING = "alternatively, falling back to" ;
206207
207208 private static String parseCoreFileLocationFromOutput (String crashOutputString ) {
208209 System .out .println ("crashOutputString = [" + crashOutputString + "]" );
@@ -220,12 +221,25 @@ private static String parseCoreFileLocationFromOutput(String crashOutputString)
220221
221222 // Find the core file name in the output.
222223 String coreWithPid ;
223- if (stringWithLocation .contains ("or " ) && !Platform .isWindows ()) {
224- Matcher m = Pattern .compile ("or.* ([^ ]+[^\\ )])\\ )?" ).matcher (stringWithLocation );
224+ if (Platform .isLinux () && stringWithLocation .contains (ALT_LOCATION_STRING )) {
225+ /*
226+ * If hotspot detects that /proc/sys/kernel/core_pattern starts with a "|",
227+ * it generates a messages something like the following:
228+ * # Core dump will be written. Default location: Determined by the following:
229+ * "/var/bin/core.sh %p" (alternatively, falling back to
230+ * /ws/jdk/build/linux-x64/test-support/jtreg_open_test_hotspot_jtreg_serviceability_sa_ClhsdbFindPC_java/scratch/2/core.10353)
231+ * We try to detect this and glean this alternative path from the message. The
232+ * hope here is that either this is where the core file actually ends up, or that
233+ * the script referenced by the core_pattern is just zipping the core file, in
234+ * which case a call to unzipCores() will have already unzipped the core file
235+ * into this path.
236+ */
237+ Matcher m = Pattern .compile (ALT_LOCATION_STRING + ".* ([^ ]+[^\\ )])\\ )?" ).matcher (stringWithLocation );
225238 if (!m .find ()) {
226239 throw new RuntimeException ("Couldn't find path to core inside location string" );
227240 }
228241 coreWithPid = m .group (1 );
242+ System .out .println ("getCoreFileLocation found alt coreWithPid = " + coreWithPid );
229243 } else {
230244 coreWithPid = stringWithLocation .trim ();
231245 }
0 commit comments