提交 c11ea7e7 编写于 作者: P phh

8027434: "-XX:OnOutOfMemoryError" uses fork instead of vfork

Summary: On Linux, use vfork in case of an OOM.
Reviewed-by: dholmes, iklam
上级 5df367bd
/*
* 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();
......
/*
* 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
......
/*
* 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
......
/*
* 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";
......
/*
* 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;
......
/*
* 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);
......
/*
* 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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册