Mon, 25 Feb 2019 21:38:45 +0000
8027434: "-XX:OnOutOfMemoryError" uses fork instead of vfork
Summary: On Linux, use vfork in case of an OOM.
Reviewed-by: dholmes, iklam
1.1 --- a/src/os/aix/vm/os_aix.cpp Mon Nov 26 17:35:35 2018 +0100 1.2 +++ b/src/os/aix/vm/os_aix.cpp Mon Feb 25 21:38:45 2019 +0000 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. 1.7 * Copyright 2012, 2014 SAP AG. All rights reserved. 1.8 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.9 * 1.10 @@ -5142,7 +5142,7 @@ 1.11 // or -1 on failure (e.g. can't fork a new process). 1.12 // Unlike system(), this function can be called from signal handler. It 1.13 // doesn't block SIGINT et al. 1.14 -int os::fork_and_exec(char* cmd) { 1.15 +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { 1.16 char * argv[4] = {"sh", "-c", cmd, NULL}; 1.17 1.18 pid_t pid = fork();
2.1 --- a/src/os/bsd/vm/os_bsd.cpp Mon Nov 26 17:35:35 2018 +0100 2.2 +++ b/src/os/bsd/vm/os_bsd.cpp Mon Feb 25 21:38:45 2019 +0000 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. 2.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.8 * 2.9 * This code is free software; you can redistribute it and/or modify it 2.10 @@ -4716,7 +4716,7 @@ 2.11 // or -1 on failure (e.g. can't fork a new process). 2.12 // Unlike system(), this function can be called from signal handler. It 2.13 // doesn't block SIGINT et al. 2.14 -int os::fork_and_exec(char* cmd) { 2.15 +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { 2.16 const char * argv[4] = {"sh", "-c", cmd, NULL}; 2.17 2.18 // fork() in BsdThreads/NPTL is not async-safe. It needs to run
3.1 --- a/src/os/linux/vm/os_linux.cpp Mon Nov 26 17:35:35 2018 +0100 3.2 +++ b/src/os/linux/vm/os_linux.cpp Mon Feb 25 21:38:45 2019 +0000 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -6337,10 +6337,16 @@ 3.11 // or -1 on failure (e.g. can't fork a new process). 3.12 // Unlike system(), this function can be called from signal handler. It 3.13 // doesn't block SIGINT et al. 3.14 -int os::fork_and_exec(char* cmd) { 3.15 +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { 3.16 const char * argv[4] = {"sh", "-c", cmd, NULL}; 3.17 3.18 - pid_t pid = fork(); 3.19 + pid_t pid ; 3.20 + 3.21 + if (use_vfork_if_available) { 3.22 + pid = vfork(); 3.23 + } else { 3.24 + pid = fork(); 3.25 + } 3.26 3.27 if (pid < 0) { 3.28 // fork failed
4.1 --- a/src/os/solaris/vm/os_solaris.cpp Mon Nov 26 17:35:35 2018 +0100 4.2 +++ b/src/os/solaris/vm/os_solaris.cpp Mon Feb 25 21:38:45 2019 +0000 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -6153,7 +6153,7 @@ 4.11 // or -1 on failure (e.g. can't fork a new process). 4.12 // Unlike system(), this function can be called from signal handler. It 4.13 // doesn't block SIGINT et al. 4.14 -int os::fork_and_exec(char* cmd) { 4.15 +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { 4.16 char * argv[4]; 4.17 argv[0] = (char *)"sh"; 4.18 argv[1] = (char *)"-c";
5.1 --- a/src/os/windows/vm/os_windows.cpp Mon Nov 26 17:35:35 2018 +0100 5.2 +++ b/src/os/windows/vm/os_windows.cpp Mon Feb 25 21:38:45 2019 +0000 5.3 @@ -1,5 +1,5 @@ 5.4 /* 5.5 - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 5.6 + * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. 5.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.8 * 5.9 * This code is free software; you can redistribute it and/or modify it 5.10 @@ -5034,7 +5034,7 @@ 5.11 5.12 // Run the specified command in a separate process. Return its exit value, 5.13 // or -1 on failure (e.g. can't create a new process). 5.14 -int os::fork_and_exec(char* cmd) { 5.15 +int os::fork_and_exec(char* cmd, bool use_vfork_if_available) { 5.16 STARTUPINFO si; 5.17 PROCESS_INFORMATION pi; 5.18
6.1 --- a/src/share/vm/runtime/os.hpp Mon Nov 26 17:35:35 2018 +0100 6.2 +++ b/src/share/vm/runtime/os.hpp Mon Feb 25 21:38:45 2019 +0000 6.3 @@ -1,5 +1,5 @@ 6.4 /* 6.5 - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 6.6 + * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. 6.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 * 6.9 * This code is free software; you can redistribute it and/or modify it 6.10 @@ -527,7 +527,7 @@ 6.11 static char* do_you_want_to_debug(const char* message); 6.12 6.13 // run cmd in a separate process and return its exit code; or -1 on failures 6.14 - static int fork_and_exec(char *cmd); 6.15 + static int fork_and_exec(char *cmd, bool use_vfork_if_available = false); 6.16 6.17 // os::exit() is merged with vm_exit() 6.18 // static void exit(int num);
7.1 --- a/src/share/vm/utilities/vmError.cpp Mon Nov 26 17:35:35 2018 +0100 7.2 +++ b/src/share/vm/utilities/vmError.cpp Mon Feb 25 21:38:45 2019 +0000 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. 7.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 * 7.9 * This code is free software; you can redistribute it and/or modify it 7.10 @@ -1060,7 +1060,7 @@ 7.11 out.print_raw (cmd); 7.12 out.print_raw_cr("\" ..."); 7.13 7.14 - if (os::fork_and_exec(cmd) < 0) { 7.15 + if (os::fork_and_exec(cmd, true) < 0) { 7.16 out.print_cr("os::fork_and_exec failed: %s (%d)", strerror(errno), errno); 7.17 } 7.18 }