Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
8304147: JVM crash during shutdown when dumping dynamic archive
Reviewed-by: ccheung, matsaave, coleenp
- Loading branch information
David Holmes
committed
Mar 27, 2023
1 parent
554bccf
commit 63ce88b
Showing
7 changed files
with
168 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/ExitRaceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2023, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 8304147 | ||
* @summary Test the exit race for dynamic dumping at exit | ||
* @requires vm.cds | ||
* @library /test/lib /test/hotspot/jtreg/runtime/cds/appcds /test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes | ||
* @build ExitRace jdk.test.whitebox.WhiteBox | ||
* @run driver jdk.test.lib.helpers.ClassFileInstaller -jar exitRace.jar ExitRace ExitRace$1 ExitRace$1$1 | ||
* @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox | ||
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. ExitRaceTest | ||
*/ | ||
|
||
import jdk.test.lib.helpers.ClassFileInstaller; | ||
|
||
public class ExitRaceTest extends DynamicArchiveTestBase { | ||
|
||
public static void main(String[] args) throws Exception { | ||
runTest(ExitRaceTest::test); | ||
} | ||
|
||
static void test() throws Exception { | ||
String topArchiveName = getNewArchiveName(); | ||
String appJar = ClassFileInstaller.getJarPath("exitRace.jar"); | ||
String mainClass = "ExitRace"; | ||
|
||
dump(topArchiveName, | ||
"-Xlog:cds+dynamic=debug", | ||
"-cp", appJar, mainClass) | ||
.assertNormalExit(output -> { | ||
output.shouldHaveExitValue(0) | ||
.shouldContain("Preparing for dynamic dump") | ||
.reportDiagnosticSummary(); | ||
}); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
test/hotspot/jtreg/runtime/cds/appcds/dynamicArchive/test-classes/ExitRace.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2023, 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
// Try to trigger concurrent dynamic-dump-at-exit processing by creating a race | ||
// between normal VM termination by the last non-daemon thread exiting, and a | ||
// call to Runtime.halt(). | ||
|
||
public class ExitRace { | ||
|
||
static volatile int terminationPhase = 0; | ||
|
||
public static void main(String [] args) { | ||
|
||
// Need to spawn a new non-daemon thread so the main thread will | ||
// have time to become the DestroyJavaVM thread. | ||
Thread runner = new Thread("Runner") { | ||
public void run() { | ||
// This thread will be the one to trigger normal VM termination | ||
// when it exits. We first create a daemon thread to call | ||
// Runtime.halt() and then wait for it to tell us to exit. | ||
|
||
Thread daemon = new Thread("Daemon") { | ||
public void run() { | ||
// Let main thread go | ||
terminationPhase = 1; | ||
// Spin until main thread is active again | ||
while (terminationPhase == 1) | ||
; | ||
Runtime.getRuntime().halt(0); // Normal exit code | ||
} | ||
}; | ||
daemon.setDaemon(true); | ||
daemon.start(); | ||
|
||
// Wait until daemon is ready | ||
while (terminationPhase == 0) { | ||
try { | ||
Thread.sleep(10); | ||
} catch (InterruptedException cantHappen) { | ||
} | ||
} | ||
|
||
// Release daemon thread | ||
terminationPhase++; | ||
// Normal exit | ||
} | ||
}; | ||
runner.start(); | ||
} | ||
} |
63ce88b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review
Issues