Skip to content

Commit

Permalink
8273153: Consolidate file_exists into os:file_exists
Browse files Browse the repository at this point in the history
Backport-of: 9732fbe428c3b6a5422cc94e7295ba5482d1a7a9
  • Loading branch information
elifaslan1 authored and Paul Hohensee committed May 22, 2024
1 parent 95f8dc0 commit 6264c70
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
10 changes: 1 addition & 9 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1441,14 +1441,6 @@ const char* os::dll_file_extension() { return ".so"; }
// directory not the java application's temp directory, ala java.io.tmpdir.
const char* os::get_temp_directory() { return "/tmp"; }

static bool file_exists(const char* filename) {
struct stat statbuf;
if (filename == NULL || strlen(filename) == 0) {
return false;
}
return os::stat(filename, &statbuf) == 0;
}

// check if addr is inside libjvm.so
bool os::address_is_in_vm(address addr) {
static address libjvm_base_addr;
Expand Down Expand Up @@ -2516,7 +2508,7 @@ static void print_sys_devices_cpu_info(outputStream* st, char* buf, size_t bufle
snprintf(hbuf_type, 60, "/sys/devices/system/cpu/cpu0/cache/index%u/type", i);
snprintf(hbuf_size, 60, "/sys/devices/system/cpu/cpu0/cache/index%u/size", i);
snprintf(hbuf_coherency_line_size, 80, "/sys/devices/system/cpu/cpu0/cache/index%u/coherency_line_size", i);
if (file_exists(hbuf_level)) {
if (os::file_exists(hbuf_level)) {
_print_ascii_file_h("cache level", hbuf_level, st);
_print_ascii_file_h("cache type", hbuf_type, st);
_print_ascii_file_h("cache size", hbuf_size, st);
Expand Down
11 changes: 3 additions & 8 deletions src/hotspot/share/logging/logFileOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ static size_t parse_value(const char* value_str) {
return value;
}

static bool file_exists(const char* filename) {
struct stat dummy_stat;
return os::stat(filename, &dummy_stat) == 0;
}

static uint number_of_digits(uint number) {
return number < 10 ? 1 : (number < 100 ? 2 : 3);
}
Expand Down Expand Up @@ -139,7 +134,7 @@ static uint next_file_number(const char* filename,
assert(ret > 0 && static_cast<size_t>(ret) == len - 1,
"incorrect buffer length calculation");

if (file_exists(archive_name) && !is_regular_file(archive_name)) {
if (os::file_exists(archive_name) && !is_regular_file(archive_name)) {
// We've encountered something that's not a regular file among the
// possible file rotation targets. Fail immediately to prevent
// problems later.
Expand All @@ -150,7 +145,7 @@ static uint next_file_number(const char* filename,
}

// Stop looking if we find an unused file name
if (!file_exists(archive_name)) {
if (!os::file_exists(archive_name)) {
next_num = i;
found = true;
break;
Expand Down Expand Up @@ -233,7 +228,7 @@ bool LogFileOutput::initialize(const char* options, outputStream* errstream) {
return false;
}

bool file_exist = file_exists(_file_name);
bool file_exist = os::file_exists(_file_name);
if (file_exist && _is_default_file_count && is_fifo_file(_file_name)) {
_file_count = 0; // Prevent file rotation for fifo's such as named pipes.
}
Expand Down
8 changes: 8 additions & 0 deletions src/hotspot/share/runtime/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,14 @@ bool os::set_boot_path(char fileSep, char pathSep) {
return false;
}

bool os::file_exists(const char* filename) {
struct stat statbuf;
if (filename == NULL || strlen(filename) == 0) {
return false;
}
return os::stat(filename, &statbuf) == 0;
}

// Splits a path, based on its separator, the number of
// elements is returned back in "elements".
// file_name_length is used as a modifier for each path's
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/runtime/os.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ class os: AllStatic {
static FILE* fopen(const char* path, const char* mode);
static int close(int fd);
static jlong lseek(int fd, jlong offset, int whence);
static bool file_exists(const char* file);
// This function, on Windows, canonicalizes a given path (see os_windows.cpp for details).
// On Posix, this function is a noop: it does not change anything and just returns
// the input pointer.
Expand Down

1 comment on commit 6264c70

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.