diff --git a/src/os/aix/vm/os_aix.cpp b/src/os/aix/vm/os_aix.cpp index 8cd1f4e8f0f3581f7cfccb77bea7ce6716b8cafc..b03ce24586af21a97b9375a6399804ba78320f30 100644 --- a/src/os/aix/vm/os_aix.cpp +++ b/src/os/aix/vm/os_aix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright 2012, 2014 SAP AG. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -5142,7 +5142,7 @@ extern char** environ; // or -1 on failure (e.g. can't fork a new process). // Unlike system(), this function can be called from signal handler. It // doesn't block SIGINT et al. -int os::fork_and_exec(char* cmd) { +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { char * argv[4] = {"sh", "-c", cmd, NULL}; pid_t pid = fork(); diff --git a/src/os/bsd/vm/os_bsd.cpp b/src/os/bsd/vm/os_bsd.cpp index c377c7d9f0ae49a56eba196528272f8b9a8b8188..99a039988d12a63621274e2881b973761572daf1 100644 --- a/src/os/bsd/vm/os_bsd.cpp +++ b/src/os/bsd/vm/os_bsd.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2019, 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 @@ -4716,7 +4716,7 @@ extern char** environ; // or -1 on failure (e.g. can't fork a new process). // Unlike system(), this function can be called from signal handler. It // doesn't block SIGINT et al. -int os::fork_and_exec(char* cmd) { +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { const char * argv[4] = {"sh", "-c", cmd, NULL}; // fork() in BsdThreads/NPTL is not async-safe. It needs to run diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp index 4d4dad060343c897b73477de15d4096778ffed1c..a7b12483cdff147204eed0d18a282b7c20ec5fe3 100644 --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2019, 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 @@ -6337,10 +6337,16 @@ extern char** environ; // or -1 on failure (e.g. can't fork a new process). // Unlike system(), this function can be called from signal handler. It // doesn't block SIGINT et al. -int os::fork_and_exec(char* cmd) { +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { const char * argv[4] = {"sh", "-c", cmd, NULL}; - pid_t pid = fork(); + pid_t pid ; + + if (use_vfork_if_available) { + pid = vfork(); + } else { + pid = fork(); + } if (pid < 0) { // fork failed diff --git a/src/os/solaris/vm/os_solaris.cpp b/src/os/solaris/vm/os_solaris.cpp index 4a786cffbb6970bf414e0b8a212f972ffd3a1f5f..2a733a75e59d4c51004f8cba56bdab78923c32f0 100644 --- a/src/os/solaris/vm/os_solaris.cpp +++ b/src/os/solaris/vm/os_solaris.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2019, 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 @@ -6153,7 +6153,7 @@ extern char** environ; // or -1 on failure (e.g. can't fork a new process). // Unlike system(), this function can be called from signal handler. It // doesn't block SIGINT et al. -int os::fork_and_exec(char* cmd) { +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { char * argv[4]; argv[0] = (char *)"sh"; argv[1] = (char *)"-c"; diff --git a/src/os/windows/vm/os_windows.cpp b/src/os/windows/vm/os_windows.cpp index 4f550c90f76c22862f810c3f1bb222dd2d18b796..1baf45f2c54522d73d63802457a4bd88143a29f2 100644 --- a/src/os/windows/vm/os_windows.cpp +++ b/src/os/windows/vm/os_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2019, 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 @@ -5034,7 +5034,7 @@ void Parker::unpark() { // Run the specified command in a separate process. Return its exit value, // or -1 on failure (e.g. can't create a new process). -int os::fork_and_exec(char* cmd) { +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { STARTUPINFO si; PROCESS_INFORMATION pi; diff --git a/src/share/vm/runtime/os.hpp b/src/share/vm/runtime/os.hpp index 92553ab474f65f1231bfb0374d56c4f5c1312a90..931f4cb5b5898190f1bbe56e053c443830da33c8 100644 --- a/src/share/vm/runtime/os.hpp +++ b/src/share/vm/runtime/os.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2019, 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 @@ -527,7 +527,7 @@ class os: AllStatic { static char* do_you_want_to_debug(const char* message); // run cmd in a separate process and return its exit code; or -1 on failures - static int fork_and_exec(char *cmd); + static int fork_and_exec(char *cmd, bool use_vfork_if_available = false); // os::exit() is merged with vm_exit() // static void exit(int num); diff --git a/src/share/vm/utilities/vmError.cpp b/src/share/vm/utilities/vmError.cpp index 8939da9bb4ba8d2eb5dd05b6ecd15e02f6fe00f4..ef3bb5cee598dfff1fd37462bdf130e4a39b830f 100644 --- a/src/share/vm/utilities/vmError.cpp +++ b/src/share/vm/utilities/vmError.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2019, 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 @@ -1060,7 +1060,7 @@ void VMError::report_and_die() { out.print_raw (cmd); out.print_raw_cr("\" ..."); - if (os::fork_and_exec(cmd) < 0) { + if (os::fork_and_exec(cmd, true) < 0) { out.print_cr("os::fork_and_exec failed: %s (%d)", strerror(errno), errno); } }