8279936: Change shared code to use os:: system API's

Reviewed-by: dholmes, kbarrett
This commit is contained in:
Harold Seigel 2022-01-19 13:51:23 +00:00
parent cc2f474c18
commit 96114315cf
8 changed files with 23 additions and 22 deletions

View File

@ -1091,7 +1091,7 @@ public:
// First read the generic header so we know the exact size of the actual header. // First read the generic header so we know the exact size of the actual header.
GenericCDSFileMapHeader gen_header; GenericCDSFileMapHeader gen_header;
size_t size = sizeof(GenericCDSFileMapHeader); size_t size = sizeof(GenericCDSFileMapHeader);
lseek(fd, 0, SEEK_SET); os::lseek(fd, 0, SEEK_SET);
size_t n = os::read(fd, (void*)&gen_header, (unsigned int)size); size_t n = os::read(fd, (void*)&gen_header, (unsigned int)size);
if (n != size) { if (n != size) {
FileMapInfo::fail_continue("Unable to read generic CDS file map header from shared archive"); FileMapInfo::fail_continue("Unable to read generic CDS file map header from shared archive");
@ -1124,7 +1124,7 @@ public:
// Read the actual header and perform more checks // Read the actual header and perform more checks
size = gen_header._header_size; size = gen_header._header_size;
_header = (GenericCDSFileMapHeader*)NEW_C_HEAP_ARRAY(char, size, mtInternal); _header = (GenericCDSFileMapHeader*)NEW_C_HEAP_ARRAY(char, size, mtInternal);
lseek(fd, 0, SEEK_SET); os::lseek(fd, 0, SEEK_SET);
n = os::read(fd, (void*)_header, (unsigned int)size); n = os::read(fd, (void*)_header, (unsigned int)size);
if (n != size) { if (n != size) {
FileMapInfo::fail_continue("Unable to read actual CDS file map header from shared archive"); FileMapInfo::fail_continue("Unable to read actual CDS file map header from shared archive");
@ -1277,7 +1277,7 @@ bool FileMapInfo::init_from_file(int fd) {
} }
_header = (FileMapHeader*)os::malloc(gen_header->_header_size, mtInternal); _header = (FileMapHeader*)os::malloc(gen_header->_header_size, mtInternal);
lseek(fd, 0, SEEK_SET); // reset to begin of the archive os::lseek(fd, 0, SEEK_SET); // reset to begin of the archive
size_t size = gen_header->_header_size; size_t size = gen_header->_header_size;
size_t n = os::read(fd, (void*)_header, (unsigned int)size); size_t n = os::read(fd, (void*)_header, (unsigned int)size);
if (n != size) { if (n != size) {
@ -1327,7 +1327,7 @@ bool FileMapInfo::init_from_file(int fd) {
if (is_static()) { if (is_static()) {
// just checking the last region is sufficient since the archive is written // just checking the last region is sufficient since the archive is written
// in sequential order // in sequential order
size_t len = lseek(fd, 0, SEEK_END); size_t len = os::lseek(fd, 0, SEEK_END);
FileMapRegion* si = space_at(MetaspaceShared::last_valid_region); FileMapRegion* si = space_at(MetaspaceShared::last_valid_region);
// The last space might be empty // The last space might be empty
if (si->file_offset() > len || len - si->file_offset() < si->used()) { if (si->file_offset() > len || len - si->file_offset() < si->used()) {
@ -1340,7 +1340,7 @@ bool FileMapInfo::init_from_file(int fd) {
} }
void FileMapInfo::seek_to_position(size_t pos) { void FileMapInfo::seek_to_position(size_t pos) {
if (lseek(_fd, (long)pos, SEEK_SET) < 0) { if (os::lseek(_fd, (long)pos, SEEK_SET) < 0) {
fail_stop("Unable to seek to position " SIZE_FORMAT, pos); fail_stop("Unable to seek to position " SIZE_FORMAT, pos);
} }
} }
@ -1650,7 +1650,7 @@ void FileMapInfo::write_bytes_aligned(const void* buffer, size_t nbytes) {
void FileMapInfo::close() { void FileMapInfo::close() {
if (_file_open) { if (_file_open) {
if (::close(_fd) < 0) { if (os::close(_fd) < 0) {
fail_stop("Unable to close the shared archive file."); fail_stop("Unable to close the shared archive file.");
} }
_file_open = false; _file_open = false;
@ -1741,7 +1741,7 @@ bool FileMapInfo::read_region(int i, char* base, size_t size, bool do_commit) {
return false; return false;
} }
} }
if (lseek(_fd, (long)si->file_offset(), SEEK_SET) != (int)si->file_offset() || if (os::lseek(_fd, (long)si->file_offset(), SEEK_SET) != (int)si->file_offset() ||
read_bytes(base, size) != size) { read_bytes(base, size) != size) {
return false; return false;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -252,7 +252,7 @@ HashtableTextDump::HashtableTextDump(const char* filename) : _fd(-1) {
HashtableTextDump::~HashtableTextDump() { HashtableTextDump::~HashtableTextDump() {
os::unmap_memory((char*)_base, _size); os::unmap_memory((char*)_base, _size);
if (_fd >= 0) { if (_fd >= 0) {
close(_fd); os::close(_fd);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -225,7 +225,7 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen)
if (to_read < (julong)buflen) if (to_read < (julong)buflen)
nr = (size_t)to_read; nr = (size_t)to_read;
else nr = buflen; else nr = buflen;
bytes_read = read(partial_fd, buf, (int)nr); bytes_read = os::read(partial_fd, buf, (int)nr);
if (bytes_read <= 0) break; if (bytes_read <= 0) break;
nr = bytes_read; nr = bytes_read;
to_read -= (julong)nr; to_read -= (julong)nr;
@ -235,7 +235,7 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen)
// Copy any remaining data inside a quote: // Copy any remaining data inside a quote:
bool saw_slop = false; bool saw_slop = false;
int end_cdata = 0; // state machine [0..2] watching for too many "]]" int end_cdata = 0; // state machine [0..2] watching for too many "]]"
while ((bytes_read = read(partial_fd, buf, buflen-1)) > 0) { while ((bytes_read = os::read(partial_fd, buf, buflen-1)) > 0) {
nr = bytes_read; nr = bytes_read;
buf[buflen-1] = '\0'; buf[buflen-1] = '\0';
if (!saw_slop) { if (!saw_slop) {
@ -285,7 +285,7 @@ void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen)
file->print_raw_cr("</fragment>"); file->print_raw_cr("</fragment>");
} }
file->print_raw_cr("</compilation_log>"); file->print_raw_cr("</compilation_log>");
close(partial_fd); os::close(partial_fd);
} }
CompileLog* next_log = log->_next; CompileLog* next_log = log->_next;
delete log; // Removes partial file delete log; // Removes partial file

View File

@ -1654,7 +1654,7 @@ void VMError::report_and_die(int id, const char* message, const char* detail_fmt
_current_step_info = ""; _current_step_info = "";
if (fd_log > 3) { if (fd_log > 3) {
close(fd_log); os::close(fd_log);
fd_log = -1; fd_log = -1;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -138,8 +138,8 @@ static inline char* read_line(FILE* fp) {
static bool file_contains_substrings_in_order(const char* filename, const char* substrs[]) { static bool file_contains_substrings_in_order(const char* filename, const char* substrs[]) {
AsyncLogWriter::flush(); AsyncLogWriter::flush();
FILE* fp = fopen(filename, "r"); FILE* fp = os::fopen(filename, "r");
assert(fp != NULL, "error opening file %s: %s", filename, strerror(errno)); assert(fp != NULL, "error opening file %s: %s", filename, os::strerror(errno));
size_t idx = 0; size_t idx = 0;
while (substrs[idx] != NULL) { while (substrs[idx] != NULL) {

View File

@ -1,5 +1,6 @@
/* /*
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -85,7 +86,7 @@ LOG_LEVEL_LIST
// stdout/stderr support // stdout/stderr support
bool write_to_file(const std::string& output) { bool write_to_file(const std::string& output) {
FILE* f = fopen(TestLogFileName, "w"); FILE* f = os::fopen(TestLogFileName, "w");
if (f != NULL) { if (f != NULL) {
size_t sz = output.size(); size_t sz = output.size();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -60,7 +60,7 @@ TEST_VM_F(LogTest, large_message) {
AsyncLogWriter::flush(); AsyncLogWriter::flush();
ResourceMark rm; ResourceMark rm;
FILE* fp = fopen(TestLogFileName, "r"); FILE* fp = os::fopen(TestLogFileName, "r");
ASSERT_NE((void*)NULL, fp); ASSERT_NE((void*)NULL, fp);
char* output = read_line(fp); char* output = read_line(fp);
fclose(fp); fclose(fp);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -50,7 +50,7 @@ TEST_VM(LogTagSetDescriptions, describe) {
TEST_VM(LogTagSetDescriptions, command_line_help) { TEST_VM(LogTagSetDescriptions, command_line_help) {
ResourceMark rm; ResourceMark rm;
const char* filename = prepend_temp_dir("logtagset_descriptions"); const char* filename = prepend_temp_dir("logtagset_descriptions");
FILE* fp = fopen(filename, "w+"); FILE* fp = os::fopen(filename, "w+");
ASSERT_NE((void*)NULL, fp); ASSERT_NE((void*)NULL, fp);
fileStream stream(fp); fileStream stream(fp);
LogConfiguration::print_command_line_help(&stream); LogConfiguration::print_command_line_help(&stream);