8218811: replace open by os::open in hotspot coding
authormbaesken
Mon, 18 Feb 2019 16:17:48 +0100
changeset 53911 65f2a401e0eb
parent 53910 072b382347db
child 53912 91f06b86c0da
8218811: replace open by os::open in hotspot coding Reviewed-by: dholmes, iklam, stuefe
src/hotspot/os/linux/os_perf_linux.cpp
src/hotspot/os/linux/perfMemory_linux.cpp
src/hotspot/os/solaris/os_perf_solaris.cpp
src/hotspot/os_cpu/linux_x86/gc/z/zBackingFile_linux_x86.cpp
src/hotspot/share/ci/ciEnv.cpp
src/hotspot/share/classfile/compactHashtable.cpp
src/hotspot/share/memory/filemap.cpp
src/hotspot/share/utilities/ostream.cpp
--- a/src/hotspot/os/linux/os_perf_linux.cpp	Sun Feb 24 16:10:52 2019 -0500
+++ b/src/hotspot/os/linux/os_perf_linux.cpp	Mon Feb 18 16:17:48 2019 +0100
@@ -1062,7 +1062,7 @@
 
   snprintf(buf, sizeof(buf), "/sys/class/net/%s/statistics/%s", iface, counter);
 
-  int fd = open(buf, O_RDONLY);
+  int fd = os::open(buf, O_RDONLY, 0);
   if (fd == -1) {
     return -1;
   }
--- a/src/hotspot/os/linux/perfMemory_linux.cpp	Sun Feb 24 16:10:52 2019 -0500
+++ b/src/hotspot/os/linux/perfMemory_linux.cpp	Mon Feb 18 16:17:48 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 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
@@ -97,8 +97,8 @@
 
   int result;
 
-  RESTARTABLE(::open(destfile, O_CREAT|O_WRONLY|O_TRUNC, S_IREAD|S_IWRITE),
-              result);;
+  RESTARTABLE(os::open(destfile, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR),
+              result);
   if (result == OS_ERR) {
     if (PrintMiscellaneous && Verbose) {
       warning("Could not create Perfdata save file: %s: %s\n",
@@ -871,7 +871,7 @@
   // Cannot use O_TRUNC here; truncation of an existing file has to happen
   // after the is_file_secure() check below.
   int result;
-  RESTARTABLE(::open(filename, O_RDWR|O_CREAT|O_NOFOLLOW, S_IREAD|S_IWRITE), result);
+  RESTARTABLE(os::open(filename, O_RDWR|O_CREAT|O_NOFOLLOW, S_IRUSR|S_IWUSR), result);
   if (result == OS_ERR) {
     if (PrintMiscellaneous && Verbose) {
       if (errno == ELOOP) {
@@ -949,7 +949,7 @@
 
   // open the file
   int result;
-  RESTARTABLE(::open(filename, oflags), result);
+  RESTARTABLE(os::open(filename, oflags, 0), result);
   if (result == OS_ERR) {
     if (errno == ENOENT) {
       THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
--- a/src/hotspot/os/solaris/os_perf_solaris.cpp	Sun Feb 24 16:10:52 2019 -0500
+++ b/src/hotspot/os/solaris/os_perf_solaris.cpp	Mon Feb 18 16:17:48 2019 +0100
@@ -74,7 +74,7 @@
 
   int fd = -1;
 
-  if ((fd = open(path, O_RDONLY)) < 0) {
+  if ((fd = os::open(path, O_RDONLY, 0)) < 0) {
     return OS_ERR;
   }
   if (pread(fd, info, s, o) != s) {
--- a/src/hotspot/os_cpu/linux_x86/gc/z/zBackingFile_linux_x86.cpp	Sun Feb 24 16:10:52 2019 -0500
+++ b/src/hotspot/os_cpu/linux_x86/gc/z/zBackingFile_linux_x86.cpp	Mon Feb 18 16:17:48 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 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
@@ -191,7 +191,7 @@
 
   // Try to create an anonymous file using the O_TMPFILE flag. Note that this
   // flag requires kernel >= 3.11. If this fails we fall back to open/unlink.
-  const int fd_anon = open(path.get(), O_TMPFILE|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
+  const int fd_anon = os::open(path.get(), O_TMPFILE|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
   if (fd_anon == -1) {
     ZErrno err;
     log_debug(gc, init)("Failed to create anonymous file in %s (%s)", path.get(),
@@ -217,7 +217,7 @@
   snprintf(filename, sizeof(filename), "%s/%s.%d", path.get(), name, os::current_process_id());
 
   // Create file
-  const int fd = open(filename, O_CREAT|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
+  const int fd = os::open(filename, O_CREAT|O_EXCL|O_RDWR|O_CLOEXEC, S_IRUSR|S_IWUSR);
   if (fd == -1) {
     ZErrno err;
     log_error(gc, init)("Failed to create file %s (%s)", filename, err.to_string());
--- a/src/hotspot/share/ci/ciEnv.cpp	Sun Feb 24 16:10:52 2019 -0500
+++ b/src/hotspot/share/ci/ciEnv.cpp	Mon Feb 18 16:17:48 2019 +0100
@@ -1253,7 +1253,7 @@
   static char buffer[O_BUFLEN];
   int ret = jio_snprintf(buffer, O_BUFLEN, "replay_pid%p_compid%d.log", os::current_process_id(), compile_id);
   if (ret > 0) {
-    int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
+    int fd = os::open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
     if (fd != -1) {
       FILE* replay_data_file = os::open(fd, "w");
       if (replay_data_file != NULL) {
@@ -1271,7 +1271,7 @@
   static char buffer[O_BUFLEN];
   int ret = jio_snprintf(buffer, O_BUFLEN, "inline_pid%p_compid%d.log", os::current_process_id(), compile_id);
   if (ret > 0) {
-    int fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
+    int fd = os::open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666);
     if (fd != -1) {
       FILE* inline_data_file = os::open(fd, "w");
       if (inline_data_file != NULL) {
--- a/src/hotspot/share/classfile/compactHashtable.cpp	Sun Feb 24 16:10:52 2019 -0500
+++ b/src/hotspot/share/classfile/compactHashtable.cpp	Mon Feb 18 16:17:48 2019 +0100
@@ -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
@@ -198,7 +198,7 @@
     quit("Unable to get hashtable dump file size", filename);
   }
   _size = st.st_size;
-  _fd = open(filename, O_RDONLY | O_BINARY, 0);
+  _fd = os::open(filename, O_RDONLY | O_BINARY, 0);
   if (_fd < 0) {
     quit("Unable to open hashtable dump file", filename);
   }
--- a/src/hotspot/share/memory/filemap.cpp	Sun Feb 24 16:10:52 2019 -0500
+++ b/src/hotspot/share/memory/filemap.cpp	Mon Feb 18 16:17:48 2019 +0100
@@ -561,7 +561,7 @@
 // Read the FileMapInfo information from the file.
 bool FileMapInfo::open_for_read() {
   _full_path = Arguments::GetSharedArchivePath();
-  int fd = open(_full_path, O_RDONLY | O_BINARY, 0);
+  int fd = os::open(_full_path, O_RDONLY | O_BINARY, 0);
   if (fd < 0) {
     if (errno == ENOENT) {
       // Not locating the shared archive is ok.
@@ -596,7 +596,7 @@
   // Use remove() to delete the existing file because, on Unix, this will
   // allow processes that have it open continued access to the file.
   remove(_full_path);
-  int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
+  int fd = os::open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
   if (fd < 0) {
     fail_stop("Unable to create shared archive file %s: (%s).", _full_path,
               os::strerror(errno));
--- a/src/hotspot/share/utilities/ostream.cpp	Sun Feb 24 16:10:52 2019 -0500
+++ b/src/hotspot/share/utilities/ostream.cpp	Mon Feb 18 16:17:48 2019 +0100
@@ -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
@@ -559,11 +559,6 @@
   fflush(_file);
 }
 
-fdStream::fdStream(const char* file_name) {
-  _fd = open(file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666);
-  _need_close = true;
-}
-
 fdStream::~fdStream() {
   if (_fd != -1) {
     if (_need_close) close(_fd);