changeset 53266:57d8566a2732

8214816: os::read() should not transition to _thread_blocked with safepoint check on Solaris Reviewed-by: jiangli, mgronlun
author dholmes
date Sun, 13 Jan 2019 16:54:01 -0500
parents febc37adfe80
children 0b6d6db878b6
files src/hotspot/os/aix/os_aix.cpp src/hotspot/os/aix/os_aix.inline.hpp src/hotspot/os/bsd/os_bsd.cpp src/hotspot/os/bsd/os_bsd.inline.hpp src/hotspot/os/linux/os_linux.cpp src/hotspot/os/linux/os_linux.inline.hpp src/hotspot/os/posix/os_posix.cpp src/hotspot/os/solaris/os_solaris.cpp src/hotspot/os/windows/os_windows.cpp src/hotspot/os/windows/os_windows.inline.hpp src/hotspot/share/compiler/directivesParser.cpp src/hotspot/share/runtime/arguments.cpp src/hotspot/share/runtime/os.hpp src/hotspot/share/runtime/os.inline.hpp
diffstat 14 files changed, 24 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/os/aix/os_aix.cpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/aix/os_aix.cpp	Sun Jan 13 16:54:01 2019 -0500
@@ -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 (c) 2012, 2018 SAP SE. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
@@ -2594,14 +2594,6 @@
   return addr;
 }
 
-size_t os::read(int fd, void *buf, unsigned int nBytes) {
-  return ::read(fd, buf, nBytes);
-}
-
-size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
-  return ::pread(fd, buf, nBytes, offset);
-}
-
 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
 void os::infinite_sleep() {
   while (true) {    // sleep forever ...
--- a/src/hotspot/os/aix/os_aix.inline.hpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/aix/os_aix.inline.hpp	Sun Jan 13 16:54:01 2019 -0500
@@ -98,12 +98,6 @@
 inline bool os::numa_has_static_binding()   { ShouldNotReachHere(); return true; }
 inline bool os::numa_has_group_homing()     { ShouldNotReachHere(); return false;  }
 
-inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
-  size_t res;
-  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
-  return res;
-}
-
 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   size_t res;
   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
--- a/src/hotspot/os/bsd/os_bsd.cpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/bsd/os_bsd.cpp	Sun Jan 13 16:54:01 2019 -0500
@@ -2217,14 +2217,6 @@
   }
 }
 
-size_t os::read(int fd, void *buf, unsigned int nBytes) {
-  RESTARTABLE_RETURN_INT(::read(fd, buf, nBytes));
-}
-
-size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
-  RESTARTABLE_RETURN_INT(::pread(fd, buf, nBytes, offset));
-}
-
 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
 void os::infinite_sleep() {
   while (true) {    // sleep forever ...
--- a/src/hotspot/os/bsd/os_bsd.inline.hpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/bsd/os_bsd.inline.hpp	Sun Jan 13 16:54:01 2019 -0500
@@ -100,12 +100,6 @@
 inline bool os::numa_has_static_binding()   { return true; }
 inline bool os::numa_has_group_homing()     { return false;  }
 
-inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
-  size_t res;
-  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
-  return res;
-}
-
 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   size_t res;
   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
--- a/src/hotspot/os/linux/os_linux.cpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/linux/os_linux.cpp	Sun Jan 13 16:54:01 2019 -0500
@@ -4027,14 +4027,6 @@
   }
 }
 
-size_t os::read(int fd, void *buf, unsigned int nBytes) {
-  return ::read(fd, buf, nBytes);
-}
-
-size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
-  return ::pread(fd, buf, nBytes, offset);
-}
-
 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
 void os::infinite_sleep() {
   while (true) {    // sleep forever ...
--- a/src/hotspot/os/linux/os_linux.inline.hpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/linux/os_linux.inline.hpp	Sun Jan 13 16:54:01 2019 -0500
@@ -92,12 +92,6 @@
 inline bool os::numa_has_static_binding()   { return true; }
 inline bool os::numa_has_group_homing()     { return false;  }
 
-inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
-  size_t res;
-  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
-  return res;
-}
-
 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   size_t res;
   RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
--- a/src/hotspot/os/posix/os_posix.cpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/posix/os_posix.cpp	Sun Jan 13 16:54:01 2019 -0500
@@ -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
@@ -554,6 +554,10 @@
   return ::fdopen(fd, mode);
 }
 
+ssize_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
+  return ::pread(fd, buf, nBytes, offset);
+}
+
 void os::flockfile(FILE* fp) {
   ::flockfile(fp);
 }
--- a/src/hotspot/os/solaris/os_solaris.cpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/solaris/os_solaris.cpp	Sun Jan 13 16:54:01 2019 -0500
@@ -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
@@ -2844,33 +2844,6 @@
   return true;
 }
 
-// Read calls from inside the vm need to perform state transitions
-size_t os::read(int fd, void *buf, unsigned int nBytes) {
-  size_t res;
-  JavaThread* thread = (JavaThread*)Thread::current();
-  assert(thread->thread_state() == _thread_in_vm, "Assumed _thread_in_vm");
-  ThreadBlockInVM tbiv(thread);
-  RESTARTABLE(::read(fd, buf, (size_t) nBytes), res);
-  return res;
-}
-
-size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
-  size_t res;
-  JavaThread* thread = (JavaThread*)Thread::current();
-  assert(thread->thread_state() == _thread_in_vm, "Assumed _thread_in_vm");
-  ThreadBlockInVM tbiv(thread);
-  RESTARTABLE(::pread(fd, buf, (size_t) nBytes, offset), res);
-  return res;
-}
-
-size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
-  size_t res;
-  assert(((JavaThread*)Thread::current())->thread_state() == _thread_in_native,
-         "Assumed _thread_in_native");
-  RESTARTABLE(::read(fd, buf, (size_t) nBytes), res);
-  return res;
-}
-
 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
 void os::infinite_sleep() {
   while (true) {    // sleep forever ...
--- a/src/hotspot/os/windows/os_windows.cpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/windows/os_windows.cpp	Sun Jan 13 16:54:01 2019 -0500
@@ -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
@@ -4539,7 +4539,7 @@
   return (jlong) ::_lseeki64(fd, offset, whence);
 }
 
-size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
+ssize_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
   OVERLAPPED ov;
   DWORD nread;
   BOOL result;
--- a/src/hotspot/os/windows/os_windows.inline.hpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/os/windows/os_windows.inline.hpp	Sun Jan 13 16:54:01 2019 -0500
@@ -70,14 +70,6 @@
 inline bool os::numa_has_static_binding()   { return true;   }
 inline bool os::numa_has_group_homing()     { return false;  }
 
-inline size_t os::read(int fd, void *buf, unsigned int nBytes) {
-  return ::read(fd, buf, nBytes);
-}
-
-inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) {
-  return ::read(fd, buf, nBytes);
-}
-
 inline size_t os::write(int fd, const void *buf, unsigned int nBytes) {
   return ::write(fd, buf, nBytes);
 }
--- a/src/hotspot/share/compiler/directivesParser.cpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/share/compiler/directivesParser.cpp	Sun Jan 13 16:54:01 2019 -0500
@@ -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
@@ -94,11 +94,13 @@
     if (file_handle != -1) {
       // read contents into resource array
       char* buffer = NEW_RESOURCE_ARRAY(char, st.st_size+1);
-      size_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
-      buffer[num_read] = '\0';
-      // close file
-      os::close(file_handle);
-      return parse_string(buffer, stream) > 0;
+      ssize_t num_read = os::read(file_handle, (char*) buffer, st.st_size);
+      if (num_read >= 0) {
+        buffer[num_read] = '\0';
+        // close file
+        os::close(file_handle);
+        return parse_string(buffer, stream) > 0;
+      }
     }
   }
   return false;
--- a/src/hotspot/share/runtime/arguments.cpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/share/runtime/arguments.cpp	Sun Jan 13 16:54:01 2019 -0500
@@ -3283,11 +3283,7 @@
   memset(buf, 0, bytes_alloc);
 
   // Fill buffer
-  // Use ::read() instead of os::read because os::read()
-  // might do a thread state transition
-  // and it is too early for that here
-
-  ssize_t bytes_read = ::read(fd, (void *)buf, (unsigned)bytes_alloc);
+  ssize_t bytes_read = os::read(fd, (void *)buf, (unsigned)bytes_alloc);
   os::close(fd);
   if (bytes_read < 0) {
     FREE_C_HEAP_ARRAY(char, buf);
--- a/src/hotspot/share/runtime/os.hpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/share/runtime/os.hpp	Sun Jan 13 16:54:01 2019 -0500
@@ -539,9 +539,8 @@
 
   //File i/o operations
 
-  static size_t read(int fd, void *buf, unsigned int nBytes);
-  static size_t read_at(int fd, void *buf, unsigned int nBytes, jlong offset);
-  static size_t restartable_read(int fd, void *buf, unsigned int nBytes);
+  static ssize_t read(int fd, void *buf, unsigned int nBytes);
+  static ssize_t read_at(int fd, void *buf, unsigned int nBytes, jlong offset);
   static size_t write(int fd, const void *buf, unsigned int nBytes);
 
   // Reading directories.
--- a/src/hotspot/share/runtime/os.inline.hpp	Sun Jan 13 17:33:26 2019 +0100
+++ b/src/hotspot/share/runtime/os.inline.hpp	Sun Jan 13 16:54:01 2019 -0500
@@ -27,6 +27,10 @@
 
 #include "runtime/os.hpp"
 
+inline ssize_t os::read(int fd, void *buf, unsigned int nBytes) {
+  return ::read(fd, buf, nBytes);
+}
+
 #include OS_HEADER_INLINE(os)
 
 #endif // SHARE_RUNTIME_OS_INLINE_HPP