8238161: use os::fopen in HS code where possible

Reviewed-by: mbaesken, coleenp
This commit is contained in:
Harold Seigel 2022-01-12 13:11:16 +00:00
parent ff0cb98965
commit f54ce84474
20 changed files with 59 additions and 58 deletions

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.
* Copyright (c) 2012, 2020 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -435,7 +435,7 @@ void VM_Version::check_virtualizations() {
// system_type=...qemu indicates PowerKVM
// e.g. system_type=IBM pSeries (emulated by qemu)
char line[500];
FILE* fp = fopen(info_file, "r");
FILE* fp = os::fopen(info_file, "r");
if (fp == NULL) {
return;
}

View File

@ -239,7 +239,7 @@ static int SCANF_ARGS(2, 0) vread_statdata(const char* procfile, _SCANFMT_ const
int n;
char buf[2048];
if ((f = fopen(procfile, "r")) == NULL) {
if ((f = os::fopen(procfile, "r")) == NULL) {
return -1;
}
@ -662,7 +662,7 @@ void SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_name() {
jio_snprintf(buffer, PATH_MAX, "/proc/%s/stat", _entry->d_name);
buffer[PATH_MAX - 1] = '\0';
if ((fp = fopen(buffer, "r")) != NULL) {
if ((fp = os::fopen(buffer, "r")) != NULL) {
if (fgets(buffer, PATH_MAX, fp) != NULL) {
char* start, *end;
// exe-name is between the first pair of ( and )
@ -690,7 +690,7 @@ char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_cmdline() {
jio_snprintf(buffer, PATH_MAX, "/proc/%s/cmdline", _entry->d_name);
buffer[PATH_MAX - 1] = '\0';
if ((fp = fopen(buffer, "r")) != NULL) {
if ((fp = os::fopen(buffer, "r")) != NULL) {
size_t size = 0;
char dummy;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, 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
@ -146,7 +146,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
* Conversely, for cgroups v2 (unified hierarchy), cpu, cpuacct, cpuset, memory
* controllers must have hierarchy ID 0 and the unified controller mounted.
*/
cgroups = fopen(proc_cgroups, "r");
cgroups = os::fopen(proc_cgroups, "r");
if (cgroups == NULL) {
log_debug(os, container)("Can't open %s, %s", proc_cgroups, os::strerror(errno));
*flags = INVALID_CGROUPS_GENERIC;
@ -214,7 +214,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
* - on a cgroups v1 system, collect info for mapping
* the host mount point to the local one via /proc/self/mountinfo below.
*/
cgroup = fopen(proc_self_cgroup, "r");
cgroup = os::fopen(proc_self_cgroup, "r");
if (cgroup == NULL) {
log_debug(os, container)("Can't open %s, %s",
proc_self_cgroup, os::strerror(errno));
@ -269,7 +269,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
// Find various mount points by reading /proc/self/mountinfo
// mountinfo format is documented at https://www.kernel.org/doc/Documentation/filesystems/proc.txt
mntinfo = fopen(proc_self_mountinfo, "r");
mntinfo = os::fopen(proc_self_mountinfo, "r");
if (mntinfo == NULL) {
log_debug(os, container)("Can't open %s, %s",
proc_self_mountinfo, os::strerror(errno));

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, 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
@ -108,7 +108,7 @@ template <typename T> int subsystem_file_line_contents(CgroupController* c,
}
strncat(file, filename, MAXPATHLEN-filelen);
log_trace(os, container)("Path to %s is %s", filename, file);
fp = fopen(file, "r");
fp = os::fopen(file, "r");
if (fp != NULL) {
int err = 0;
while ((p = fgets(buf, MAXPATHLEN, fp)) != NULL) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -58,7 +58,7 @@ bool ElfDecoder::demangle(const char* symbol, char *buf, int buflen) {
bool ElfFile::specifies_noexecstack(const char* filepath) {
if (filepath == NULL) return true;
FILE* file = fopen(filepath, "r");
FILE* file = os::fopen(filepath, "r");
if (file == NULL) return true;
// AARCH64 defaults to noexecstack. All others default to execstack.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,6 +27,7 @@
#include "gc/z/zErrno.hpp"
#include "gc/z/zMountPoint_linux.hpp"
#include "runtime/globals.hpp"
#include "runtime/os.hpp"
#include <stdio.h>
#include <unistd.h>
@ -70,7 +71,7 @@ char* ZMountPoint::get_mountpoint(const char* line, const char* filesystem) cons
}
void ZMountPoint::get_mountpoints(const char* filesystem, ZArray<char*>* mountpoints) const {
FILE* fd = fopen(PROC_SELF_MOUNTINFO, "r");
FILE* fd = os::fopen(PROC_SELF_MOUNTINFO, "r");
if (fd == NULL) {
ZErrno err;
log_error_p(gc)("Failed to open %s: %s", PROC_SELF_MOUNTINFO, err.to_string());

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021, 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -329,7 +329,7 @@ void ZPhysicalMemoryBacking::warn_available_space(size_t max_capacity) const {
void ZPhysicalMemoryBacking::warn_max_map_count(size_t max_capacity) const {
const char* const filename = ZFILENAME_PROC_MAX_MAP_COUNT;
FILE* const file = fopen(filename, "r");
FILE* const file = os::fopen(filename, "r");
if (file == NULL) {
// Failed to open file, skip check
log_debug_p(gc, init)("Failed to open %s", filename);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -258,7 +258,7 @@ bool os::Linux::get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu
memset(pticks, 0, sizeof(CPUPerfTicks));
if ((fh = fopen("/proc/stat", "r")) == NULL) {
if ((fh = os::fopen("/proc/stat", "r")) == NULL) {
return false;
}
@ -352,7 +352,7 @@ void os::Linux::initialize_system_info() {
pid_t pid = os::Linux::gettid();
char fname[32];
jio_snprintf(fname, sizeof(fname), "/proc/%d", pid);
FILE *fp = fopen(fname, "r");
FILE *fp = os::fopen(fname, "r");
if (fp == NULL) {
unsafe_chroot_detected = true;
} else {
@ -1027,7 +1027,7 @@ bool os::is_primordial_thread(void) {
// Find the virtual memory area that contains addr
static bool find_vma(address addr, address* vma_low, address* vma_high) {
FILE *fp = fopen("/proc/self/maps", "r");
FILE *fp = os::fopen("/proc/self/maps", "r");
if (fp) {
address low, high;
while (!feof(fp)) {
@ -1139,7 +1139,7 @@ void os::Linux::capture_initial_stack(size_t max_size) {
char stat[2048];
int statlen;
fp = fopen("/proc/self/stat", "r");
fp = os::fopen("/proc/self/stat", "r");
if (fp) {
statlen = fread(stat, 1, 2047, fp);
stat[statlen] = '\0';
@ -2004,7 +2004,7 @@ static void parse_os_info_helper(FILE* fp, char* distro, size_t length, bool get
}
static void parse_os_info(char* distro, size_t length, const char* file) {
FILE* fp = fopen(file, "r");
FILE* fp = os::fopen(file, "r");
if (fp != NULL) {
// if suse format, print out first line
bool get_first_line = (strcmp(file, "/etc/SuSE-release") == 0);
@ -2065,7 +2065,7 @@ void os::Linux::print_system_memory_info(outputStream* st) {
}
bool os::Linux::query_process_memory_info(os::Linux::meminfo_t* info) {
FILE* f = ::fopen("/proc/self/status", "r");
FILE* f = os::fopen("/proc/self/status", "r");
const int num_values = sizeof(os::Linux::meminfo_t) / sizeof(size_t);
int num_found = 0;
char buf[256];
@ -2312,7 +2312,7 @@ void os::print_memory_info(outputStream* st) {
static bool print_model_name_and_flags(outputStream* st, char* buf, size_t buflen) {
#if defined(IA32) || defined(AMD64)
// Other platforms have less repetitive cpuinfo files
FILE *fp = fopen("/proc/cpuinfo", "r");
FILE *fp = os::fopen("/proc/cpuinfo", "r");
if (fp) {
bool model_name_printed = false;
while (!feof(fp)) {
@ -2416,7 +2416,7 @@ const char* search_string = "Processor";
// Parses the cpuinfo file for string representing the model name.
void os::get_summary_cpu_info(char* cpuinfo, size_t length) {
FILE* fp = fopen("/proc/cpuinfo", "r");
FILE* fp = os::fopen("/proc/cpuinfo", "r");
if (fp != NULL) {
while (!feof(fp)) {
char buf[256];
@ -3551,7 +3551,7 @@ static void set_coredump_filter(CoredumpFilterBit bit) {
FILE *f;
long cdm;
if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) {
if ((f = os::fopen("/proc/self/coredump_filter", "r+")) == NULL) {
return;
}
@ -3590,7 +3590,7 @@ static size_t scan_default_large_page_size() {
// If we can't determine the value (e.g. /proc is not mounted, or the text
// format has been changed), we'll set largest page size to 0
FILE *fp = fopen("/proc/meminfo", "r");
FILE *fp = os::fopen("/proc/meminfo", "r");
if (fp) {
while (!feof(fp)) {
int x = 0;
@ -4268,7 +4268,7 @@ int os::Linux::get_namespace_pid(int vmid) {
int retpid = -1;
snprintf(fname, sizeof(fname), "/proc/%d/status", vmid);
FILE *fp = fopen(fname, "r");
FILE *fp = os::fopen(fname, "r");
if (fp) {
int pid, nspid;
@ -5077,7 +5077,7 @@ static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
FILE *fp;
snprintf(proc_name, 64, "/proc/self/task/%d/stat", tid);
fp = fopen(proc_name, "r");
fp = os::fopen(proc_name, "r");
if (fp == NULL) return -1;
statlen = fread(stat, 1, 2047, fp);
stat[statlen] = '\0';
@ -5382,7 +5382,7 @@ bool os::supports_map_sync() {
void os::print_memory_mappings(char* addr, size_t bytes, outputStream* st) {
unsigned long long start = (unsigned long long)addr;
unsigned long long end = start + bytes;
FILE* f = ::fopen("/proc/self/maps", "r");
FILE* f = os::fopen("/proc/self/maps", "r");
int num_found = 0;
if (f != NULL) {
st->print("Range [%llx-%llx) contains: ", start, end);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, 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
@ -234,7 +234,7 @@ static int SCANF_ARGS(2, 0) vread_statdata(const char* procfile, _SCANFMT_ const
int n;
char buf[2048];
if ((f = fopen(procfile, "r")) == NULL) {
if ((f = os::fopen(procfile, "r")) == NULL) {
return -1;
}
@ -271,7 +271,7 @@ static int SCANF_ARGS(2, 3) read_statdata(const char* procfile, _SCANFMT_ const
static FILE* open_statfile(void) {
FILE *f;
if ((f = fopen("/proc/stat", "r")) == NULL) {
if ((f = os::fopen("/proc/stat", "r")) == NULL) {
static int haveWarned = 0;
if (!haveWarned) {
haveWarned = 1;
@ -722,7 +722,7 @@ void SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_name() {
jio_snprintf(buffer, PATH_MAX, "/proc/%s/stat", _entry->d_name);
buffer[PATH_MAX - 1] = '\0';
if ((fp = fopen(buffer, "r")) != NULL) {
if ((fp = os::fopen(buffer, "r")) != NULL) {
if (fgets(buffer, PATH_MAX, fp) != NULL) {
char* start, *end;
// exe-name is between the first pair of ( and )
@ -750,7 +750,7 @@ char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_cmdline() {
jio_snprintf(buffer, PATH_MAX, "/proc/%s/cmdline", _entry->d_name);
buffer[PATH_MAX - 1] = '\0';
if ((fp = fopen(buffer, "r")) != NULL) {
if ((fp = os::fopen(buffer, "r")) != NULL) {
size_t size = 0;
char dummy;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -143,7 +143,7 @@ void VM_Version::get_os_cpu_info() {
_zva_length = 4 << (dczid_el0 & 0xf);
}
if (FILE *f = fopen("/proc/cpuinfo", "r")) {
if (FILE *f = os::fopen("/proc/cpuinfo", "r")) {
// need a large buffer as the flags line may include lots of text
char buf[1024], *p;
while (fgets(buf, sizeof (buf), f) != NULL) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -462,7 +462,7 @@ juint os::cpu_microcode_revision() {
juint result = 0;
char data[2048] = {0}; // lines should fit in 2K buf
size_t len = sizeof(data);
FILE *fp = fopen("/proc/cpuinfo", "r");
FILE *fp = os::fopen("/proc/cpuinfo", "r");
if (fp) {
while (!feof(fp)) {
if (fgets(data, len, fp)) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -703,7 +703,7 @@ void Compilation::print_timers() {
#ifndef PRODUCT
void Compilation::compile_only_this_method() {
ResourceMark rm;
fileStream stream(fopen("c1_compile_only", "wt"));
fileStream stream(os::fopen("c1_compile_only", "wt"));
stream.print_cr("# c1 compile only directives");
compile_only_this_scope(&stream, hir()->top_scope());
}
@ -717,7 +717,7 @@ void Compilation::compile_only_this_scope(outputStream* st, IRScope* scope) {
}
void Compilation::exclude_this_method() {
fileStream stream(fopen(".hotspot_compiler", "at"));
fileStream stream(os::fopen(".hotspot_compiler", "at"));
stream.print("exclude ");
method()->holder()->name()->print_symbol_on(&stream);
stream.print(" ");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2022, 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
@ -145,7 +145,7 @@ class CompileReplay : public StackObj {
_protection_domain = Handle();
_protection_domain_initialized = false;
_stream = fopen(filename, "rt");
_stream = os::fopen(filename, "rt");
if (_stream == NULL) {
fprintf(stderr, "ERROR: Can't open replay file %s\n", filename);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -2003,7 +2003,7 @@ void CompileBroker::init_compiler_thread_log() {
os::file_separator(), thread_id, os::current_process_id());
}
fp = fopen(file_name, "wt");
fp = os::fopen(file_name, "wt");
if (fp != NULL) {
if (LogCompilation && Verbose) {
tty->print_cr("Opening compilation log %s", file_name);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2022, 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
@ -932,7 +932,7 @@ bool CompilerOracle::_quiet = false;
void CompilerOracle::parse_from_file() {
assert(has_command_file(), "command file must be specified");
FILE* stream = fopen(cc_file(), "rt");
FILE* stream = os::fopen(cc_file(), "rt");
if (stream == NULL) return;
char token[1024];

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2022, 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
@ -267,7 +267,7 @@ void decode_env::print_hook_comments(address pc, bool newline) {
_cached_src_lines = new (ResourceObj::C_HEAP, mtCode)GrowableArray<const char*>(0, mtCode);
}
if ((fp = fopen(file, "r")) == NULL) {
if ((fp = os::fopen(file, "r")) == NULL) {
_cached_src = NULL;
return;
}

View File

@ -318,7 +318,7 @@ void Abstract_VM_Version::insert_features_names(char* buf, size_t buflen, const
bool Abstract_VM_Version::print_matching_lines_from_file(const char* filename, outputStream* st, const char* keywords_to_match[]) {
char line[500];
FILE* fp = fopen(filename, "r");
FILE* fp = os::fopen(filename, "r");
if (fp == NULL) {
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.
*
* This code is free software; you can redistribute it and/or modify it
@ -1244,7 +1244,7 @@ bool Arguments::process_argument(const char* arg,
}
bool Arguments::process_settings_file(const char* file_name, bool should_exist, jboolean ignore_unrecognized) {
FILE* stream = fopen(file_name, "rb");
FILE* stream = os::fopen(file_name, "rb");
if (stream == NULL) {
if (should_exist) {
jio_fprintf(defaultStream::error_stream(),

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, 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.
*
* This code is free software; you can redistribute it and/or modify it
@ -168,7 +168,7 @@ void ElfFile::cleanup_tables() {
NullDecoder::decoder_status ElfFile::parse_elf(const char* filepath) {
assert(filepath, "null file path");
_file = fopen(filepath, "r");
_file = os::fopen(filepath, "r");
if (_file != NULL) {
return load_tables();
} else {

View File

@ -545,7 +545,7 @@ const char* make_log_name(const char* log_name, const char* force_directory) {
}
fileStream::fileStream(const char* file_name) {
_file = fopen(file_name, "w");
_file = os::fopen(file_name, "w");
if (_file != NULL) {
_need_close = true;
} else {
@ -555,7 +555,7 @@ fileStream::fileStream(const char* file_name) {
}
fileStream::fileStream(const char* file_name, const char* opentype) {
_file = fopen(file_name, opentype);
_file = os::fopen(file_name, opentype);
if (_file != NULL) {
_need_close = true;
} else {