Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit e99595b

Browse files
author
Harold Seigel
committed
8263564: Consolidate POSIX code for runtime exit support: os::shutdown, os::abort and os::die
Reviewed-by: dholmes Backport-of: 554dd29fb67b9a25ad161920b57e238c06024938
1 parent 566703a commit e99595b

File tree

4 files changed

+58
-154
lines changed

4 files changed

+58
-154
lines changed

src/hotspot/os/aix/os_aix.cpp

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,54 +1064,6 @@ struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
10641064
return localtime_r(clock, res);
10651065
}
10661066

1067-
////////////////////////////////////////////////////////////////////////////////
1068-
// runtime exit support
1069-
1070-
// Note: os::shutdown() might be called very early during initialization, or
1071-
// called from signal handler. Before adding something to os::shutdown(), make
1072-
// sure it is async-safe and can handle partially initialized VM.
1073-
void os::shutdown() {
1074-
1075-
// allow PerfMemory to attempt cleanup of any persistent resources
1076-
perfMemory_exit();
1077-
1078-
// needs to remove object in file system
1079-
AttachListener::abort();
1080-
1081-
// flush buffered output, finish log files
1082-
ostream_abort();
1083-
1084-
// Check for abort hook
1085-
abort_hook_t abort_hook = Arguments::abort_hook();
1086-
if (abort_hook != NULL) {
1087-
abort_hook();
1088-
}
1089-
}
1090-
1091-
// Note: os::abort() might be called very early during initialization, or
1092-
// called from signal handler. Before adding something to os::abort(), make
1093-
// sure it is async-safe and can handle partially initialized VM.
1094-
void os::abort(bool dump_core, void* siginfo, const void* context) {
1095-
os::shutdown();
1096-
if (dump_core) {
1097-
::abort(); // dump core
1098-
}
1099-
1100-
::exit(1);
1101-
}
1102-
1103-
// Die immediately, no exit hook, no abort hook, no cleanup.
1104-
// Dump a core file, if possible, for debugging.
1105-
void os::die() {
1106-
if (TestUnresponsiveErrorHandler && !CreateCoredumpOnCrash) {
1107-
// For TimeoutInErrorHandlingTest.java, we just kill the VM
1108-
// and don't take the time to generate a core file.
1109-
os::signal_raise(SIGKILL);
1110-
} else {
1111-
::abort();
1112-
}
1113-
}
1114-
11151067
intx os::current_thread_id() {
11161068
return (intx)pthread_self();
11171069
}

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -929,56 +929,6 @@ struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
929929
return localtime_r(clock, res);
930930
}
931931

932-
////////////////////////////////////////////////////////////////////////////////
933-
// runtime exit support
934-
935-
// Note: os::shutdown() might be called very early during initialization, or
936-
// called from signal handler. Before adding something to os::shutdown(), make
937-
// sure it is async-safe and can handle partially initialized VM.
938-
void os::shutdown() {
939-
940-
// allow PerfMemory to attempt cleanup of any persistent resources
941-
perfMemory_exit();
942-
943-
// needs to remove object in file system
944-
AttachListener::abort();
945-
946-
// flush buffered output, finish log files
947-
ostream_abort();
948-
949-
// Check for abort hook
950-
abort_hook_t abort_hook = Arguments::abort_hook();
951-
if (abort_hook != NULL) {
952-
abort_hook();
953-
}
954-
955-
}
956-
957-
// Note: os::abort() might be called very early during initialization, or
958-
// called from signal handler. Before adding something to os::abort(), make
959-
// sure it is async-safe and can handle partially initialized VM.
960-
void os::abort(bool dump_core, void* siginfo, const void* context) {
961-
os::shutdown();
962-
if (dump_core) {
963-
::abort(); // dump core
964-
}
965-
966-
::exit(1);
967-
}
968-
969-
// Die immediately, no exit hook, no abort hook, no cleanup.
970-
// Dump a core file, if possible, for debugging.
971-
void os::die() {
972-
if (TestUnresponsiveErrorHandler && !CreateCoredumpOnCrash) {
973-
// For TimeoutInErrorHandlingTest.java, we just kill the VM
974-
// and don't take the time to generate a core file.
975-
os::signal_raise(SIGKILL);
976-
} else {
977-
// _exit() on BsdThreads only kills current thread
978-
::abort();
979-
}
980-
}
981-
982932
// Information of current thread in variety of formats
983933
pid_t os::Bsd::gettid() {
984934
int retval = -1;

src/hotspot/os/linux/os_linux.cpp

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, 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
@@ -24,7 +24,6 @@
2424

2525
// no precompiled headers
2626
#include "jvm.h"
27-
#include "classfile/classLoader.hpp"
2827
#include "classfile/systemDictionary.hpp"
2928
#include "classfile/vmSymbols.hpp"
3029
#include "code/icBuffer.hpp"
@@ -66,7 +65,6 @@
6665
#include "runtime/vm_version.hpp"
6766
#include "signals_posix.hpp"
6867
#include "semaphore_posix.hpp"
69-
#include "services/attachListener.hpp"
7068
#include "services/memTracker.hpp"
7169
#include "services/runtimeService.hpp"
7270
#include "utilities/align.hpp"
@@ -1429,58 +1427,6 @@ struct tm* os::localtime_pd(const time_t* clock, struct tm* res) {
14291427
return localtime_r(clock, res);
14301428
}
14311429

1432-
////////////////////////////////////////////////////////////////////////////////
1433-
// runtime exit support
1434-
1435-
// Note: os::shutdown() might be called very early during initialization, or
1436-
// called from signal handler. Before adding something to os::shutdown(), make
1437-
// sure it is async-safe and can handle partially initialized VM.
1438-
void os::shutdown() {
1439-
1440-
// allow PerfMemory to attempt cleanup of any persistent resources
1441-
perfMemory_exit();
1442-
1443-
// needs to remove object in file system
1444-
AttachListener::abort();
1445-
1446-
// flush buffered output, finish log files
1447-
ostream_abort();
1448-
1449-
// Check for abort hook
1450-
abort_hook_t abort_hook = Arguments::abort_hook();
1451-
if (abort_hook != NULL) {
1452-
abort_hook();
1453-
}
1454-
1455-
}
1456-
1457-
// Note: os::abort() might be called very early during initialization, or
1458-
// called from signal handler. Before adding something to os::abort(), make
1459-
// sure it is async-safe and can handle partially initialized VM.
1460-
void os::abort(bool dump_core, void* siginfo, const void* context) {
1461-
os::shutdown();
1462-
if (dump_core) {
1463-
if (DumpPrivateMappingsInCore) {
1464-
ClassLoader::close_jrt_image();
1465-
}
1466-
::abort(); // dump core
1467-
}
1468-
1469-
::exit(1);
1470-
}
1471-
1472-
// Die immediately, no exit hook, no abort hook, no cleanup.
1473-
// Dump a core file, if possible, for debugging.
1474-
void os::die() {
1475-
if (TestUnresponsiveErrorHandler && !CreateCoredumpOnCrash) {
1476-
// For TimeoutInErrorHandlingTest.java, we just kill the VM
1477-
// and don't take the time to generate a core file.
1478-
os::signal_raise(SIGKILL);
1479-
} else {
1480-
::abort();
1481-
}
1482-
}
1483-
14841430
// thread_id is kernel thread id (similar to Solaris LWP id)
14851431
intx os::current_thread_id() { return os::Linux::gettid(); }
14861432
int os::current_process_id() {

src/hotspot/os/posix/os_posix.cpp

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2021, 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
@@ -22,19 +22,26 @@
2222
*
2323
*/
2424

25+
2526
#include "jvm.h"
27+
#ifdef LINUX
28+
#include "classfile/classLoader.hpp"
29+
#endif
2630
#include "logging/log.hpp"
2731
#include "memory/allocation.inline.hpp"
2832
#include "os_posix.inline.hpp"
33+
#include "runtime/arguments.hpp"
2934
#include "runtime/globals_extension.hpp"
3035
#include "utilities/globalDefinitions.hpp"
3136
#include "runtime/frame.inline.hpp"
3237
#include "runtime/interfaceSupport.inline.hpp"
3338
#include "runtime/sharedRuntime.hpp"
39+
#include "services/attachListener.hpp"
3440
#include "services/memTracker.hpp"
3541
#include "runtime/atomic.hpp"
3642
#include "runtime/java.hpp"
3743
#include "runtime/orderAccess.hpp"
44+
#include "runtime/perfMemory.hpp"
3845
#include "utilities/align.hpp"
3946
#include "utilities/events.hpp"
4047
#include "utilities/formatBuffer.hpp"
@@ -1812,3 +1819,52 @@ int os::PlatformMonitor::wait(jlong millis) {
18121819
return OS_OK;
18131820
}
18141821
}
1822+
1823+
////////////////////////////////////////////////////////////////////////////////
1824+
// runtime exit support
1825+
1826+
// Note: os::shutdown() might be called very early during initialization, or
1827+
// called from signal handler. Before adding something to os::shutdown(), make
1828+
// sure it is async-safe and can handle partially initialized VM.
1829+
void os::shutdown() {
1830+
1831+
// allow PerfMemory to attempt cleanup of any persistent resources
1832+
perfMemory_exit();
1833+
1834+
// needs to remove object in file system
1835+
AttachListener::abort();
1836+
1837+
// flush buffered output, finish log files
1838+
ostream_abort();
1839+
1840+
// Check for abort hook
1841+
abort_hook_t abort_hook = Arguments::abort_hook();
1842+
if (abort_hook != NULL) {
1843+
abort_hook();
1844+
}
1845+
1846+
}
1847+
1848+
// Note: os::abort() might be called very early during initialization, or
1849+
// called from signal handler. Before adding something to os::abort(), make
1850+
// sure it is async-safe and can handle partially initialized VM.
1851+
void os::abort(bool dump_core, void* siginfo, const void* context) {
1852+
os::shutdown();
1853+
if (dump_core) {
1854+
LINUX_ONLY(if (DumpPrivateMappingsInCore) ClassLoader::close_jrt_image();)
1855+
::abort(); // dump core
1856+
}
1857+
::exit(1);
1858+
}
1859+
1860+
// Die immediately, no exit hook, no abort hook, no cleanup.
1861+
// Dump a core file, if possible, for debugging.
1862+
void os::die() {
1863+
if (TestUnresponsiveErrorHandler && !CreateCoredumpOnCrash) {
1864+
// For TimeoutInErrorHandlingTest.java, we just kill the VM
1865+
// and don't take the time to generate a core file.
1866+
os::signal_raise(SIGKILL);
1867+
} else {
1868+
::abort();
1869+
}
1870+
}

0 commit comments

Comments
 (0)