--- old/src/hotspot/os/linux/os_linux.cpp 2018-09-27 17:30:59.833583944 +0530 +++ new/src/hotspot/os/linux/os_linux.cpp 2018-09-27 17:30:59.693583945 +0530 @@ -5720,7 +5720,13 @@ int os::fork_and_exec(char* cmd) { const char * argv[4] = {"sh", "-c", cmd, NULL}; - pid_t pid = fork(); + pid_t pid ; + + if (VMError::is_forkmode_vfork()) { + pid = vfork(); + } else { + pid = fork(); + } if (pid < 0) { // fork failed --- old/src/hotspot/share/utilities/vmError.cpp 2018-09-27 17:31:00.213583943 +0530 +++ new/src/hotspot/share/utilities/vmError.cpp 2018-09-27 17:31:00.089583943 +0530 @@ -58,6 +58,10 @@ #include #endif // PRODUCT +bool VMError::_vfork_mode = false; + +bool VMError::is_forkmode_vfork() { return _vfork_mode; } + bool VMError::_error_reported = false; // call this when the VM is dying--it might loosen some asserts @@ -1565,11 +1569,15 @@ #endif tty->print_cr("\"%s\"...", cmd); + VMError::_vfork_mode = true; + if (os::fork_and_exec(cmd) < 0) { tty->print_cr("os::fork_and_exec failed: %s (%s=%d)", os::strerror(errno), os::errno_name(errno), errno); } } + + VMError::_vfork_mode = false; } void VMError::report_java_out_of_memory(const char* message) { --- old/src/hotspot/share/utilities/vmError.hpp 2018-09-27 17:31:00.537583941 +0530 +++ new/src/hotspot/share/utilities/vmError.hpp 2018-09-27 17:31:00.417583942 +0530 @@ -88,6 +88,9 @@ static bool _error_reported; + // Whether fork and exec should call fork/vfork + static bool _vfork_mode; + public: // set signal handlers on Solaris/Linux or the default exception filter @@ -190,6 +193,8 @@ // Support for avoiding multiple asserts static bool is_error_reported(); + static bool is_forkmode_vfork(); + // Test vmassert(), fatal(), guarantee(), etc. NOT_PRODUCT(static void test_error_handler();) NOT_PRODUCT(static void controlled_crash(int how);)