# HG changeset patch # User dholmes # Date 1547416441 18000 # Node ID 57d8566a2732c9f71a3b68143105aeed1fe9af5b # Parent febc37adfe80b92a1187195b2c3f57c23267b43c 8214816: os::read() should not transition to _thread_blocked with safepoint check on Solaris Reviewed-by: jiangli, mgronlun diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/aix/os_aix.cpp --- 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 ... diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/aix/os_aix.inline.hpp --- 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); diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/bsd/os_bsd.cpp --- 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 ... diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/bsd/os_bsd.inline.hpp --- 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); diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/linux/os_linux.cpp --- 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 ... diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/linux/os_linux.inline.hpp --- 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); diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/posix/os_posix.cpp --- 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); } diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/solaris/os_solaris.cpp --- 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 ... diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/windows/os_windows.cpp --- 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; diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/os/windows/os_windows.inline.hpp --- 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); } diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/share/compiler/directivesParser.cpp --- 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; diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/share/runtime/arguments.cpp --- 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); diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/share/runtime/os.hpp --- 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. diff -r febc37adfe80 -r 57d8566a2732 src/hotspot/share/runtime/os.inline.hpp --- 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