8301478: Replace NULL with nullptr in os/bsd

Reviewed-by: coleenp, stuefe
This commit is contained in:
Johan Sjölen 2023-02-06 09:21:19 +00:00
parent ab528ce3cd
commit 716f1df609
6 changed files with 163 additions and 164 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2023, 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
@ -82,7 +82,7 @@ class BsdAttachListener: AllStatic {
};
static void set_path(char* path) {
if (path == NULL) {
if (path == nullptr) {
_path[0] = '\0';
_has_path = false;
} else {
@ -145,7 +145,7 @@ class ArgumentIterator : public StackObj {
if (_pos < _end) {
_pos += 1;
}
return NULL;
return nullptr;
}
char* res = _pos;
char* next_pos = strchr(_pos, '\0');
@ -170,7 +170,7 @@ extern "C" {
}
if (BsdAttachListener::has_path()) {
::unlink(BsdAttachListener::path());
BsdAttachListener::set_path(NULL);
BsdAttachListener::set_path(nullptr);
}
}
}
@ -275,7 +275,7 @@ BsdAttachOperation* BsdAttachListener::read_request(int s) {
assert(n <= left, "buffer was too small, impossible!");
buf[max_len - 1] = '\0';
if (n == -1) {
return NULL; // reset by peer or other error
return nullptr; // reset by peer or other error
}
if (n == 0) {
break;
@ -293,7 +293,7 @@ BsdAttachOperation* BsdAttachListener::read_request(int s) {
char msg[32];
int msg_len = os::snprintf_checked(msg, sizeof(msg), "%d\n", ATTACH_ERROR_BADVERSION);
write_fully(s, msg, msg_len);
return NULL;
return nullptr;
}
}
}
@ -303,7 +303,7 @@ BsdAttachOperation* BsdAttachListener::read_request(int s) {
} while (left > 0 && str_count < expected_str_count);
if (str_count != expected_str_count) {
return NULL; // incomplete request
return nullptr; // incomplete request
}
// parse request
@ -314,20 +314,20 @@ BsdAttachOperation* BsdAttachListener::read_request(int s) {
char* v = args.next();
char* name = args.next();
if (name == NULL || strlen(name) > AttachOperation::name_length_max) {
return NULL;
if (name == nullptr || strlen(name) > AttachOperation::name_length_max) {
return nullptr;
}
BsdAttachOperation* op = new BsdAttachOperation(name);
for (int i=0; i<AttachOperation::arg_count_max; i++) {
char* arg = args.next();
if (arg == NULL) {
op->set_arg(i, NULL);
if (arg == nullptr) {
op->set_arg(i, nullptr);
} else {
if (strlen(arg) > AttachOperation::arg_length_max) {
delete op;
return NULL;
return nullptr;
}
op->set_arg(i, arg);
}
@ -352,7 +352,7 @@ BsdAttachOperation* BsdAttachListener::dequeue() {
socklen_t len = sizeof(addr);
RESTARTABLE(::accept(listener(), &addr, &len), s);
if (s == -1) {
return NULL; // log a warning?
return nullptr; // log a warning?
}
// get the credentials of the peer and check the effective uid/guid
@ -373,7 +373,7 @@ BsdAttachOperation* BsdAttachListener::dequeue() {
// peer credential look okay so we read the request
BsdAttachOperation* op = read_request(s);
if (op == NULL) {
if (op == nullptr) {
::close(s);
continue;
} else {
@ -543,7 +543,7 @@ void AttachListener::pd_data_dump() {
}
AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* n) {
return NULL;
return nullptr;
}
jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2023, 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
@ -41,7 +41,7 @@ bool MachODecoder::demangle(const char* symbol, char *buf, int buflen) {
// Don't pass buf to __cxa_demangle. In case of the 'buf' is too small,
// __cxa_demangle will call system "realloc" for additional memory, which
// may use different malloc/realloc mechanism that allocates 'buf'.
if ((result = abi::__cxa_demangle(symbol, NULL, NULL, &status)) != NULL) {
if ((result = abi::__cxa_demangle(symbol, nullptr, nullptr, &status)) != nullptr) {
jio_snprintf(buf, buflen, "%s", result);
// call c library's free
::free(result);
@ -60,7 +60,7 @@ bool MachODecoder::decode(address addr, char *buf,
}
struct symtab_command * symt = (struct symtab_command *)
mach_find_command((struct mach_header_64 *)mach_base, LC_SYMTAB);
if (symt == NULL) {
if (symt == nullptr) {
DEBUG_ONLY(tty->print_cr("no symtab in mach file at 0x%lx", p2i(mach_base)));
return false;
}
@ -124,13 +124,13 @@ void* MachODecoder::mach_find_command(struct mach_header_64 * mach_base, uint32_
int cmdsize = this_cmd->cmdsize;
pos += cmdsize;
}
return NULL;
return nullptr;
}
char* MachODecoder::mach_find_in_stringtable(char *strtab, uint32_t tablesize, int strx_wanted) {
if (strx_wanted == 0) {
return NULL;
return nullptr;
}
char *strtab_end = strtab + tablesize;
@ -140,13 +140,13 @@ char* MachODecoder::mach_find_in_stringtable(char *strtab, uint32_t tablesize, i
strtab++;
if (*strtab != 0) {
DEBUG_ONLY(tty->print_cr("string table has leading space but no following zero."));
return NULL;
return nullptr;
}
strtab++;
} else {
if ((uint32_t) *strtab != 0) {
DEBUG_ONLY(tty->print_cr("string table without leading space or leading int of zero."));
return NULL;
return nullptr;
}
strtab+=4;
}
@ -164,7 +164,7 @@ char* MachODecoder::mach_find_in_stringtable(char *strtab, uint32_t tablesize, i
cur_strx++;
}
DEBUG_ONLY(tty->print_cr("string number %d not found.", strx_wanted));
return NULL;
return nullptr;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2023, 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
@ -30,23 +30,22 @@
#include <signal.h>
void OSThread::pd_initialize() {
assert(this != NULL, "check");
#ifdef __APPLE__
_thread_id = 0;
#else
_thread_id = NULL;
_thread_id = nullptr;
#endif
_unique_thread_id = 0;
_pthread_id = NULL;
_siginfo = NULL;
_ucontext = NULL;
_pthread_id = nullptr;
_siginfo = nullptr;
_ucontext = nullptr;
_expanding_stack = 0;
_alt_sig_stack = NULL;
_alt_sig_stack = nullptr;
sigemptyset(&_caller_sigmask);
_startThread_lock = new Monitor(Mutex::event, "startThread_lock");
assert(_startThread_lock !=NULL, "check");
assert(_startThread_lock !=nullptr, "check");
}
// Additional thread_id used to correlate threads in SA

View File

@ -164,9 +164,9 @@ void os::Bsd::print_uptime_info(outputStream* st) {
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
if (sysctl(mib, 2, &boottime, &len, NULL, 0) >= 0) {
if (sysctl(mib, 2, &boottime, &len, nullptr, 0) >= 0) {
time_t bootsec = boottime.tv_sec;
time_t currsec = time(NULL);
time_t currsec = time(nullptr);
os::print_dhm(st, "OS uptime:", (long) difftime(currsec, bootsec));
}
}
@ -212,7 +212,7 @@ void os::Bsd::initialize_system_info() {
mib[0] = CTL_HW;
mib[1] = HW_NCPU;
len = sizeof(cpu_val);
if (sysctl(mib, 2, &cpu_val, &len, NULL, 0) != -1 && cpu_val >= 1) {
if (sysctl(mib, 2, &cpu_val, &len, nullptr, 0) != -1 && cpu_val >= 1) {
assert(len == sizeof(cpu_val), "unexpected data size");
set_processor_count(cpu_val);
} else {
@ -241,7 +241,7 @@ void os::Bsd::initialize_system_info() {
#endif
len = sizeof(mem_val);
if (sysctl(mib, 2, &mem_val, &len, NULL, 0) != -1) {
if (sysctl(mib, 2, &mem_val, &len, nullptr, 0) != -1) {
assert(len == sizeof(mem_val), "unexpected data size");
_physical_memory = mem_val;
} else {
@ -262,9 +262,9 @@ void os::Bsd::initialize_system_info() {
#ifdef __APPLE__
static const char *get_home() {
const char *home_dir = ::getenv("HOME");
if ((home_dir == NULL) || (*home_dir == '\0')) {
if ((home_dir == nullptr) || (*home_dir == '\0')) {
struct passwd *passwd_info = getpwuid(geteuid());
if (passwd_info != NULL) {
if (passwd_info != nullptr) {
home_dir = passwd_info->pw_dir;
}
}
@ -337,24 +337,24 @@ void os::init_system_properties_values() {
// Now cut the path to <java_home>/jre if we can.
*(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
pslash = strrchr(buf, '/');
if (pslash != NULL) {
if (pslash != nullptr) {
*pslash = '\0'; // Get rid of /{client|server|hotspot}.
}
Arguments::set_dll_dir(buf);
if (pslash != NULL) {
if (pslash != nullptr) {
pslash = strrchr(buf, '/');
if (pslash != NULL) {
if (pslash != nullptr) {
*pslash = '\0'; // Get rid of /<arch>.
pslash = strrchr(buf, '/');
if (pslash != NULL) {
if (pslash != nullptr) {
*pslash = '\0'; // Get rid of /lib.
}
}
}
Arguments::set_java_home(buf);
if (!set_boot_path('/', ':')) {
vm_exit_during_initialization("Failed setting boot class path.", NULL);
vm_exit_during_initialization("Failed setting boot class path.", nullptr);
}
}
@ -374,7 +374,7 @@ void os::init_system_properties_values() {
// addressed).
const char *v = ::getenv("LD_LIBRARY_PATH");
const char *v_colon = ":";
if (v == NULL) { v = ""; v_colon = ""; }
if (v == nullptr) { v = ""; v_colon = ""; }
// That's +1 for the colon and +1 for the trailing '\0'.
const size_t ld_library_path_size = strlen(v) + 1 + sizeof(SYS_EXT_DIR) +
sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1;
@ -417,7 +417,7 @@ void os::init_system_properties_values() {
// Now cut the path to <java_home>/jre if we can.
*(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
pslash = strrchr(buf, '/');
if (pslash != NULL) {
if (pslash != nullptr) {
*pslash = '\0'; // Get rid of /{client|server|hotspot}.
}
#ifdef STATIC_BUILD
@ -426,15 +426,15 @@ void os::init_system_properties_values() {
Arguments::set_dll_dir(buf);
if (pslash != NULL) {
if (pslash != nullptr) {
pslash = strrchr(buf, '/');
if (pslash != NULL) {
if (pslash != nullptr) {
*pslash = '\0'; // Get rid of /lib.
}
}
Arguments::set_java_home(buf);
if (!set_boot_path('/', ':')) {
vm_exit_during_initialization("Failed setting boot class path.", NULL);
vm_exit_during_initialization("Failed setting boot class path.", nullptr);
}
}
@ -456,11 +456,11 @@ void os::init_system_properties_values() {
// can specify a directory inside an app wrapper
const char *l = ::getenv("JAVA_LIBRARY_PATH");
const char *l_colon = ":";
if (l == NULL) { l = ""; l_colon = ""; }
if (l == nullptr) { l = ""; l_colon = ""; }
const char *v = ::getenv("DYLD_LIBRARY_PATH");
const char *v_colon = ":";
if (v == NULL) { v = ""; v_colon = ""; }
if (v == nullptr) { v = ""; v_colon = ""; }
// Apple's Java6 has "." at the beginning of java.library.path.
// OpenJDK on Windows has "." at the end of java.library.path.
@ -519,7 +519,7 @@ extern "C" void breakpoint() {
#define OBJC_GCREGISTER "objc_registerThreadWithCollector"
typedef void (*objc_registerThreadWithCollector_t)();
extern "C" objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction;
objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction = NULL;
objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction = nullptr;
#endif
// Thread start routine for all newly created threads
@ -546,7 +546,7 @@ static void *thread_native_entry(Thread *thread) {
#ifdef __APPLE__
// register thread with objc gc
if (objc_registerThreadWithCollectorFunction != NULL) {
if (objc_registerThreadWithCollectorFunction != nullptr) {
objc_registerThreadWithCollectorFunction();
}
#endif
@ -573,7 +573,7 @@ static void *thread_native_entry(Thread *thread) {
// Note: at this point the thread object may already have deleted itself.
// Prevent dereferencing it from here on out.
thread = NULL;
thread = nullptr;
log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
os::current_thread_id(), (uintx) pthread_self());
@ -583,11 +583,11 @@ static void *thread_native_entry(Thread *thread) {
bool os::create_thread(Thread* thread, ThreadType thr_type,
size_t req_stack_size) {
assert(thread->osthread() == NULL, "caller responsible");
assert(thread->osthread() == nullptr, "caller responsible");
// Allocate the OSThread object
OSThread* osthread = new OSThread();
if (osthread == NULL) {
if (osthread == nullptr) {
return false;
}
@ -639,7 +639,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
if (ret != 0) {
// Need to clean up stuff we've allocated so far
thread->set_osthread(NULL);
thread->set_osthread(nullptr);
delete osthread;
return false;
}
@ -681,7 +681,7 @@ bool os::create_attached_thread(JavaThread* thread) {
// Allocate the OSThread object
OSThread* osthread = new OSThread();
if (osthread == NULL) {
if (osthread == nullptr) {
return false;
}
@ -724,7 +724,7 @@ void os::pd_start_thread(Thread* thread) {
// Free Bsd resources related to the OSThread
void os::free_thread(OSThread* osthread) {
assert(osthread != NULL, "osthread not set");
assert(osthread != nullptr, "osthread not set");
// We are told to free resources of the argument thread,
// but we can only really operate on the current thread.
@ -733,7 +733,7 @@ void os::free_thread(OSThread* osthread) {
// Restore caller's signal mask
sigset_t sigmask = osthread->caller_sigmask();
pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
pthread_sigmask(SIG_SETMASK, &sigmask, nullptr);
delete osthread;
}
@ -850,8 +850,8 @@ static int local_dladdr(const void* addr, Dl_info* info) {
// macosx has a secure per-user temporary directory
char temp_path_storage[PATH_MAX];
const char* os::get_temp_directory() {
static char *temp_path = NULL;
if (temp_path == NULL) {
static char *temp_path = nullptr;
if (temp_path == nullptr) {
int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, temp_path_storage, PATH_MAX);
if (pathSize == 0 || pathSize > PATH_MAX) {
strlcpy(temp_path_storage, "/tmp/", sizeof(temp_path_storage));
@ -869,11 +869,11 @@ bool os::address_is_in_vm(address addr) {
static address libjvm_base_addr;
Dl_info dlinfo;
if (libjvm_base_addr == NULL) {
if (libjvm_base_addr == nullptr) {
if (dladdr(CAST_FROM_FN_PTR(void *, os::address_is_in_vm), &dlinfo) != 0) {
libjvm_base_addr = (address)dlinfo.dli_fbase;
}
assert(libjvm_base_addr !=NULL, "Cannot obtain base address for libjvm");
assert(libjvm_base_addr !=nullptr, "Cannot obtain base address for libjvm");
}
if (dladdr((void *)addr, &dlinfo) != 0) {
@ -887,17 +887,17 @@ bool os::dll_address_to_function_name(address addr, char *buf,
int buflen, int *offset,
bool demangle) {
// buf is not optional, but offset is optional
assert(buf != NULL, "sanity check");
assert(buf != nullptr, "sanity check");
Dl_info dlinfo;
if (local_dladdr((void*)addr, &dlinfo) != 0) {
// see if we have a matching symbol
if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL) {
if (dlinfo.dli_saddr != nullptr && dlinfo.dli_sname != nullptr) {
if (!(demangle && Decoder::demangle(dlinfo.dli_sname, buf, buflen))) {
jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname);
}
if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
if (offset != nullptr) *offset = addr - (address)dlinfo.dli_saddr;
return true;
}
@ -909,7 +909,7 @@ bool os::dll_address_to_function_name(address addr, char *buf,
// each "file".
// no matching symbol so try for just file info
if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
if (dlinfo.dli_fname != nullptr && dlinfo.dli_fbase != nullptr) {
if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
buf, buflen, offset, dlinfo.dli_fname, demangle)) {
return true;
@ -921,7 +921,7 @@ bool os::dll_address_to_function_name(address addr, char *buf,
char localbuf[MACH_MAXSYMLEN];
// Handle non-dynamic manually:
if (dlinfo.dli_fbase != NULL &&
if (dlinfo.dli_fbase != nullptr &&
Decoder::decode(addr, localbuf, MACH_MAXSYMLEN, offset,
dlinfo.dli_fbase)) {
if (!(demangle && Decoder::demangle(localbuf, buf, buflen))) {
@ -934,22 +934,22 @@ bool os::dll_address_to_function_name(address addr, char *buf,
#endif // __APPLE__
}
buf[0] = '\0';
if (offset != NULL) *offset = -1;
if (offset != nullptr) *offset = -1;
return false;
}
bool os::dll_address_to_library_name(address addr, char* buf,
int buflen, int* offset) {
// buf is not optional, but offset is optional
assert(buf != NULL, "sanity check");
assert(buf != nullptr, "sanity check");
Dl_info dlinfo;
if (local_dladdr((void*)addr, &dlinfo) != 0) {
if (dlinfo.dli_fname != NULL) {
if (dlinfo.dli_fname != nullptr) {
jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
}
if (dlinfo.dli_fbase != NULL && offset != NULL) {
if (dlinfo.dli_fbase != nullptr && offset != nullptr) {
*offset = addr - (address)dlinfo.dli_fbase;
}
return true;
@ -972,26 +972,26 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
log_info(os)("attempting shared library load of %s", filename);
void * result= ::dlopen(filename, RTLD_LAZY);
if (result != NULL) {
Events::log_dll_message(NULL, "Loaded shared library %s", filename);
if (result != nullptr) {
Events::log_dll_message(nullptr, "Loaded shared library %s", filename);
// Successful loading
log_info(os)("shared library load of %s was successful", filename);
return result;
}
const char* error_report = ::dlerror();
if (error_report == NULL) {
if (error_report == nullptr) {
error_report = "dlerror returned no error description";
}
if (ebuf != NULL && ebuflen > 0) {
if (ebuf != nullptr && ebuflen > 0) {
// Read system error message into ebuf
::strncpy(ebuf, error_report, ebuflen-1);
ebuf[ebuflen-1]='\0';
}
Events::log_dll_message(NULL, "Loading shared library %s failed, %s", filename, error_report);
Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report);
log_info(os)("shared library load of %s failed, %s", filename, error_report);
return NULL;
return nullptr;
#endif // STATIC_BUILD
}
#else
@ -1001,8 +1001,8 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
#else
log_info(os)("attempting shared library load of %s", filename);
void * result= ::dlopen(filename, RTLD_LAZY);
if (result != NULL) {
Events::log_dll_message(NULL, "Loaded shared library %s", filename);
if (result != nullptr) {
Events::log_dll_message(nullptr, "Loaded shared library %s", filename);
// Successful loading
log_info(os)("shared library load of %s was successful", filename);
return result;
@ -1011,15 +1011,15 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
Elf32_Ehdr elf_head;
const char* const error_report = ::dlerror();
if (error_report == NULL) {
if (error_report == nullptr) {
error_report = "dlerror returned no error description";
}
if (ebuf != NULL && ebuflen > 0) {
if (ebuf != nullptr && ebuflen > 0) {
// Read system error message into ebuf
::strncpy(ebuf, error_report, ebuflen-1);
ebuf[ebuflen-1]='\0';
}
Events::log_dll_message(NULL, "Loading shared library %s failed, %s", filename, error_report);
Events::log_dll_message(nullptr, "Loading shared library %s failed, %s", filename, error_report);
log_info(os)("shared library load of %s failed, %s", filename, error_report);
int diag_msg_max_length=ebuflen-strlen(ebuf);
@ -1027,7 +1027,7 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
if (diag_msg_max_length==0) {
// No more space in ebuf for additional diagnostics message
return NULL;
return nullptr;
}
@ -1035,7 +1035,7 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
if (file_descriptor < 0) {
// Can't open library, report dlerror() message
return NULL;
return nullptr;
}
bool failed_to_read_elf_head=
@ -1045,7 +1045,7 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
::close(file_descriptor);
if (failed_to_read_elf_head) {
// file i/o error - report dlerror() msg
return NULL;
return nullptr;
}
typedef struct {
@ -1128,7 +1128,7 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
// Identify compatibility class for VM's architecture and library's architecture
// Obtain string descriptions for architectures
arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], nullptr};
int running_arch_index=-1;
for (unsigned int i=0; i < ARRAY_SIZE(arch_array); i++) {
@ -1146,23 +1146,23 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
if (running_arch_index == -1) {
// Even though running architecture detection failed
// we may still continue with reporting dlerror() message
return NULL;
return nullptr;
}
if (lib_arch.endianess != arch_array[running_arch_index].endianess) {
::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: endianness mismatch)");
return NULL;
return nullptr;
}
#ifndef S390
if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) {
::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)");
return NULL;
return nullptr;
}
#endif // !S390
if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) {
if (lib_arch.name!=NULL) {
if (lib_arch.name!=nullptr) {
::snprintf(diag_msg_buf, diag_msg_max_length-1,
" (Possible cause: can't load %s-bit .so on a %s-bit platform)",
lib_arch.name, arch_array[running_arch_index].name);
@ -1174,7 +1174,7 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
}
}
return NULL;
return nullptr;
#endif // STATIC_BUILD
}
#endif // !__APPLE__
@ -1200,23 +1200,23 @@ int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *pa
Link_map *p;
if (dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli) == 0 ||
dli.dli_fname == NULL) {
dli.dli_fname == nullptr) {
return 1;
}
handle = dlopen(dli.dli_fname, RTLD_LAZY);
if (handle == NULL) {
if (handle == nullptr) {
return 1;
}
dlinfo(handle, RTLD_DI_LINKMAP, &map);
if (map == NULL) {
if (map == nullptr) {
dlclose(handle);
return 1;
}
while (map->l_prev != NULL)
while (map->l_prev != nullptr)
map = map->l_prev;
while (map != NULL) {
while (map != nullptr) {
// Value for top_address is returned as 0 since we don't have any information about module size
if (callback(map->l_name, (address)map->l_addr, (address)0, param)) {
dlclose(handle);
@ -1245,7 +1245,7 @@ void os::get_summary_os_info(char* buf, size_t buflen) {
char os[100];
size_t size = sizeof(os);
int mib_kern[] = { CTL_KERN, KERN_OSTYPE };
if (sysctl(mib_kern, 2, os, &size, NULL, 0) < 0) {
if (sysctl(mib_kern, 2, os, &size, nullptr, 0) < 0) {
#ifdef __APPLE__
strncpy(os, "Darwin", sizeof(os));
#elif __OpenBSD__
@ -1258,7 +1258,7 @@ void os::get_summary_os_info(char* buf, size_t buflen) {
char release[100];
size = sizeof(release);
int mib_release[] = { CTL_KERN, KERN_OSRELEASE };
if (sysctl(mib_release, 2, release, &size, NULL, 0) < 0) {
if (sysctl(mib_release, 2, release, &size, nullptr, 0) < 0) {
// if error, leave blank
strncpy(release, "", sizeof(release));
}
@ -1266,12 +1266,12 @@ void os::get_summary_os_info(char* buf, size_t buflen) {
#ifdef __APPLE__
char osproductversion[100];
size_t sz = sizeof(osproductversion);
int ret = sysctlbyname("kern.osproductversion", osproductversion, &sz, NULL, 0);
int ret = sysctlbyname("kern.osproductversion", osproductversion, &sz, nullptr, 0);
if (ret == 0) {
char build[100];
size = sizeof(build);
int mib_build[] = { CTL_KERN, KERN_OSVERSION };
if (sysctl(mib_build, 2, build, &size, NULL, 0) < 0) {
if (sysctl(mib_build, 2, build, &size, nullptr, 0) < 0) {
snprintf(buf, buflen, "%s %s, macOS %s", os, release, osproductversion);
} else {
snprintf(buf, buflen, "%s %s, macOS %s (%s)", os, release, osproductversion, build);
@ -1307,7 +1307,7 @@ void os::get_summary_cpu_info(char* buf, size_t buflen) {
unsigned int mhz;
size_t size = sizeof(mhz);
int mib[] = { CTL_HW, HW_CPU_FREQ };
if (sysctl(mib, 2, &mhz, &size, NULL, 0) < 0) {
if (sysctl(mib, 2, &mhz, &size, nullptr, 0) < 0) {
mhz = 1; // looks like an error but can be divided by
} else {
mhz /= 1000000; // reported in millions
@ -1316,14 +1316,14 @@ void os::get_summary_cpu_info(char* buf, size_t buflen) {
char model[100];
size = sizeof(model);
int mib_model[] = { CTL_HW, HW_MODEL };
if (sysctl(mib_model, 2, model, &size, NULL, 0) < 0) {
if (sysctl(mib_model, 2, model, &size, nullptr, 0) < 0) {
strncpy(model, cpu_arch, sizeof(model));
}
char machine[100];
size = sizeof(machine);
int mib_machine[] = { CTL_HW, HW_MACHINE };
if (sysctl(mib_machine, 2, machine, &size, NULL, 0) < 0) {
if (sysctl(mib_machine, 2, machine, &size, nullptr, 0) < 0) {
strncpy(machine, "", sizeof(machine));
}
@ -1352,7 +1352,7 @@ void os::print_memory_info(outputStream* st) {
st->print("(" UINT64_FORMAT "k free)",
os::available_memory() >> 10);
if((sysctlbyname("vm.swapusage", &swap_usage, &size, NULL, 0) == 0) || (errno == ENOMEM)) {
if((sysctlbyname("vm.swapusage", &swap_usage, &size, nullptr, 0) == 0) || (errno == ENOMEM)) {
if (size >= offset_of(xsw_usage, xsu_used)) {
st->print(", swap " UINT64_FORMAT "k",
((julong) swap_usage.xsu_total) >> 10);
@ -1384,13 +1384,13 @@ void os::jvm_path(char *buf, jint buflen) {
dli_fname[0] = '\0';
bool ret = dll_address_to_library_name(
CAST_FROM_FN_PTR(address, os::jvm_path),
dli_fname, sizeof(dli_fname), NULL);
dli_fname, sizeof(dli_fname), nullptr);
assert(ret, "cannot locate libjvm");
char *rp = NULL;
char *rp = nullptr;
if (ret && dli_fname[0] != '\0') {
rp = os::Posix::realpath(dli_fname, buf, buflen);
}
if (rp == NULL) {
if (rp == nullptr) {
return;
}
@ -1412,7 +1412,7 @@ void os::jvm_path(char *buf, jint buflen) {
if (strncmp(p, "/jre/lib/", 9) != 0) {
// Look for JAVA_HOME in the environment.
char* java_home_var = ::getenv("JAVA_HOME");
if (java_home_var != NULL && java_home_var[0] != 0) {
if (java_home_var != nullptr && java_home_var[0] != 0) {
char* jrelib_p;
int len;
@ -1421,7 +1421,7 @@ void os::jvm_path(char *buf, jint buflen) {
assert(strstr(p, "/libjvm") == p, "invalid library name");
rp = os::Posix::realpath(java_home_var, buf, buflen);
if (rp == NULL) {
if (rp == nullptr) {
return;
}
@ -1455,7 +1455,7 @@ void os::jvm_path(char *buf, jint buflen) {
} else {
// Fall back to path of current library
rp = os::Posix::realpath(dli_fname, buf, buflen);
if (rp == NULL) {
if (rp == nullptr) {
return;
}
}
@ -1485,7 +1485,7 @@ bool os::pd_commit_memory(char* addr, size_t size, bool exec) {
int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
#if defined(__OpenBSD__)
// XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
Events::log(nullptr, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(addr), p2i(addr+size), prot);
if (::mprotect(addr, size, prot) == 0) {
return true;
}
@ -1525,7 +1525,7 @@ bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
void os::pd_commit_memory_or_exit(char* addr, size_t size, bool exec,
const char* mesg) {
assert(mesg != NULL, "mesg must be specified");
assert(mesg != nullptr, "mesg must be specified");
if (!pd_commit_memory(addr, size, exec)) {
// add extra info in product mode for vm_exit_out_of_memory():
PRODUCT_ONLY(warn_fail_commit_memory(addr, size, exec, errno);)
@ -1587,7 +1587,7 @@ char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info
bool os::pd_uncommit_memory(char* addr, size_t size, bool exec) {
#if defined(__OpenBSD__)
// XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with PROT_NONE", p2i(addr), p2i(addr+size));
Events::log(nullptr, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with PROT_NONE", p2i(addr), p2i(addr+size));
return ::mprotect(addr, size, PROT_NONE) == 0;
#elif defined(__APPLE__)
if (exec) {
@ -1619,7 +1619,7 @@ bool os::remove_stack_guard_pages(char* addr, size_t size) {
// 'requested_addr' is only treated as a hint, the return value may or
// may not start from the requested address. Unlike Bsd mmap(), this
// function returns NULL to indicate failure.
// function returns null to indicate failure.
static char* anon_mmap(char* requested_addr, size_t bytes, bool exec) {
// MAP_FIXED is intentionally left out, to leave existing mappings intact.
const int flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS
@ -1630,7 +1630,7 @@ static char* anon_mmap(char* requested_addr, size_t bytes, bool exec) {
// succeed if we have enough swap space to back the physical page.
char* addr = (char*)::mmap(requested_addr, bytes, PROT_NONE, flags, -1, 0);
return addr == MAP_FAILED ? NULL : addr;
return addr == MAP_FAILED ? nullptr : addr;
}
static int anon_munmap(char * addr, size_t size) {
@ -1638,7 +1638,7 @@ static int anon_munmap(char * addr, size_t size) {
}
char* os::pd_reserve_memory(size_t bytes, bool exec) {
return anon_mmap(NULL /* addr */, bytes, exec);
return anon_mmap(nullptr /* addr */, bytes, exec);
}
bool os::pd_release_memory(char* addr, size_t size) {
@ -1657,7 +1657,7 @@ static bool bsd_mprotect(char* addr, size_t size, int prot) {
assert(addr == bottom, "sanity check");
size = align_up(pointer_delta(addr, bottom, 1) + size, os::vm_page_size());
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
Events::log(nullptr, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
return ::mprotect(bottom, size, prot) == 0;
}
@ -1699,7 +1699,7 @@ void os::large_page_init() {
char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, size_t page_size, char* req_addr, bool exec) {
fatal("os::reserve_memory_special should not be called on BSD.");
return NULL;
return nullptr;
}
bool os::pd_release_memory_special(char* base, size_t bytes) {
@ -1724,8 +1724,8 @@ bool os::can_execute_large_page_memory() {
char* os::pd_attempt_map_memory_to_file_at(char* requested_addr, size_t bytes, int file_desc) {
assert(file_desc >= 0, "file_desc is not valid");
char* result = pd_attempt_reserve_memory_at(requested_addr, bytes, !ExecMem);
if (result != NULL) {
if (replace_existing_mapping_with_file_mapping(result, bytes, file_desc) == NULL) {
if (result != nullptr) {
if (replace_existing_mapping_with_file_mapping(result, bytes, file_desc) == nullptr) {
vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory"));
}
}
@ -1753,12 +1753,12 @@ char* os::pd_attempt_reserve_memory_at(char* requested_addr, size_t bytes, bool
return requested_addr;
}
if (addr != NULL) {
if (addr != nullptr) {
// mmap() is successful but it fails to reserve at the requested address
anon_munmap(addr, bytes);
}
return NULL;
return nullptr;
}
// Used to convert frequent JVM_Yield() to nops
@ -2006,7 +2006,7 @@ jint os::init_2(void) {
#ifdef __APPLE__
// dynamically link to objective c gc registration
void *handleLibObjc = dlopen(OBJC_LIB, RTLD_LAZY);
if (handleLibObjc != NULL) {
if (handleLibObjc != nullptr) {
objc_registerThreadWithCollectorFunction = (objc_registerThreadWithCollector_t) dlsym(handleLibObjc, OBJC_GCREGISTER);
}
#endif
@ -2069,7 +2069,7 @@ uint os::processor_id() {
void os::set_native_thread_name(const char *name) {
#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
// This is only supported in Snow Leopard and beyond
if (name != NULL) {
if (name != nullptr) {
// Add a "Java: " prefix to the name
char buf[MAXTHREADNAMESIZE];
snprintf(buf, sizeof(buf), "Java: %s", name);
@ -2086,18 +2086,18 @@ bool os::find(address addr, outputStream* st) {
memset(&dlinfo, 0, sizeof(dlinfo));
if (dladdr(addr, &dlinfo) != 0) {
st->print(INTPTR_FORMAT ": ", (intptr_t)addr);
if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
if (dlinfo.dli_sname != nullptr && dlinfo.dli_saddr != nullptr) {
st->print("%s+%#x", dlinfo.dli_sname,
(uint)((uintptr_t)addr - (uintptr_t)dlinfo.dli_saddr));
} else if (dlinfo.dli_fbase != NULL) {
} else if (dlinfo.dli_fbase != nullptr) {
st->print("<offset %#x>", (uint)((uintptr_t)addr - (uintptr_t)dlinfo.dli_fbase));
} else {
st->print("<absolute address>");
}
if (dlinfo.dli_fname != NULL) {
if (dlinfo.dli_fname != nullptr) {
st->print(" in %s", dlinfo.dli_fname);
}
if (dlinfo.dli_fbase != NULL) {
if (dlinfo.dli_fbase != nullptr) {
st->print(" at " INTPTR_FORMAT, (intptr_t)dlinfo.dli_fbase);
}
st->cr();
@ -2246,14 +2246,14 @@ char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
prot |= PROT_EXEC;
}
if (addr != NULL) {
if (addr != nullptr) {
flags |= MAP_FIXED;
}
char* mapped_address = (char*)mmap(addr, (size_t)bytes, prot, flags,
fd, file_offset);
if (mapped_address == MAP_FAILED) {
return NULL;
return nullptr;
}
return mapped_address;
}
@ -2372,13 +2372,13 @@ int os::get_core_path(char* buffer, size_t bufferSize) {
#ifdef __APPLE__
char coreinfo[MAX_PATH];
size_t sz = sizeof(coreinfo);
int ret = sysctlbyname("kern.corefile", coreinfo, &sz, NULL, 0);
int ret = sysctlbyname("kern.corefile", coreinfo, &sz, nullptr, 0);
if (ret == 0) {
char *pid_pos = strstr(coreinfo, "%P");
// skip over the "%P" to preserve any optional custom user pattern
const char* tail = (pid_pos != NULL) ? (pid_pos + 2) : "";
const char* tail = (pid_pos != nullptr) ? (pid_pos + 2) : "";
if (pid_pos != NULL) {
if (pid_pos != nullptr) {
*pid_pos = '\0';
n = jio_snprintf(buffer, bufferSize, "%s%d%s", coreinfo, os::current_process_id(), tail);
} else {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2023, 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
@ -97,17 +97,17 @@ class os::Bsd {
static void set_numa_interleave_memory(numa_interleave_memory_func_t func) { _numa_interleave_memory = func; }
static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; }
public:
static int sched_getcpu() { return _sched_getcpu != NULL ? _sched_getcpu() : -1; }
static int sched_getcpu() { return _sched_getcpu != nullptr ? _sched_getcpu() : -1; }
static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) {
return _numa_node_to_cpus != NULL ? _numa_node_to_cpus(node, buffer, bufferlen) : -1;
return _numa_node_to_cpus != nullptr ? _numa_node_to_cpus(node, buffer, bufferlen) : -1;
}
static int numa_max_node() { return _numa_max_node != NULL ? _numa_max_node() : -1; }
static int numa_available() { return _numa_available != NULL ? _numa_available() : -1; }
static int numa_max_node() { return _numa_max_node != nullptr ? _numa_max_node() : -1; }
static int numa_available() { return _numa_available != nullptr ? _numa_available() : -1; }
static int numa_tonode_memory(void *start, size_t size, int node) {
return _numa_tonode_memory != NULL ? _numa_tonode_memory(start, size, node) : -1;
return _numa_tonode_memory != nullptr ? _numa_tonode_memory(start, size, node) : -1;
}
static void numa_interleave_memory(void *start, size_t size) {
if (_numa_interleave_memory != NULL && _numa_all_nodes != NULL) {
if (_numa_interleave_memory != nullptr && _numa_all_nodes != nullptr) {
_numa_interleave_memory(start, size, _numa_all_nodes);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023, 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
@ -231,7 +231,7 @@ int CPUPerformanceInterface::CPUPerformance::context_switch_rate(double* rate) {
}
CPUPerformanceInterface::CPUPerformanceInterface() {
_impl = NULL;
_impl = nullptr;
}
bool CPUPerformanceInterface::initialize() {
@ -240,7 +240,7 @@ bool CPUPerformanceInterface::initialize() {
}
CPUPerformanceInterface::~CPUPerformanceInterface() {
if (_impl != NULL) {
if (_impl != nullptr) {
delete _impl;
}
}
@ -283,17 +283,17 @@ bool SystemProcessInterface::SystemProcesses::initialize() {
SystemProcessInterface::SystemProcesses::~SystemProcesses() {
}
int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
assert(system_processes != NULL, "system_processes pointer is NULL!");
assert(no_of_sys_processes != NULL, "system_processes counter pointer is NULL!");
assert(system_processes != nullptr, "system_processes pointer is null!");
assert(no_of_sys_processes != nullptr, "system_processes counter pointer is null!");
#ifdef __APPLE__
pid_t* pids = NULL;
pid_t* pids = nullptr;
int pid_count = 0;
ResourceMark rm;
int try_count = 0;
while (pids == NULL) {
while (pids == nullptr) {
// Find out buffer size
size_t pids_bytes = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0);
size_t pids_bytes = proc_listpids(PROC_ALL_PIDS, 0, nullptr, 0);
if (pids_bytes <= 0) {
return OS_ERR;
}
@ -305,7 +305,7 @@ int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** sy
if (pids_bytes <= 0) {
// couldn't fit buffer, retry.
FREE_RESOURCE_ARRAY(pid_t, pids, pid_count);
pids = NULL;
pids = nullptr;
try_count++;
if (try_count > 3) {
return OS_ERR;
@ -316,7 +316,7 @@ int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** sy
}
int process_count = 0;
SystemProcess* next = NULL;
SystemProcess* next = nullptr;
for (int i = 0; i < pid_count; i++) {
pid_t pid = pids[i];
if (pid != 0) {
@ -351,7 +351,7 @@ int SystemProcessInterface::system_processes(SystemProcess** system_procs, int*
}
SystemProcessInterface::SystemProcessInterface() {
_impl = NULL;
_impl = nullptr;
}
bool SystemProcessInterface::initialize() {
@ -360,13 +360,13 @@ bool SystemProcessInterface::initialize() {
}
SystemProcessInterface::~SystemProcessInterface() {
if (_impl != NULL) {
if (_impl != nullptr) {
delete _impl;
}
}
CPUInformationInterface::CPUInformationInterface() {
_cpu_info = NULL;
_cpu_info = nullptr;
}
bool CPUInformationInterface::initialize() {
@ -381,23 +381,23 @@ bool CPUInformationInterface::initialize() {
}
CPUInformationInterface::~CPUInformationInterface() {
if (_cpu_info != NULL) {
if (_cpu_info->cpu_name() != NULL) {
if (_cpu_info != nullptr) {
if (_cpu_info->cpu_name() != nullptr) {
const char* cpu_name = _cpu_info->cpu_name();
FREE_C_HEAP_ARRAY(char, cpu_name);
_cpu_info->set_cpu_name(NULL);
_cpu_info->set_cpu_name(nullptr);
}
if (_cpu_info->cpu_description() != NULL) {
if (_cpu_info->cpu_description() != nullptr) {
const char* cpu_desc = _cpu_info->cpu_description();
FREE_C_HEAP_ARRAY(char, cpu_desc);
_cpu_info->set_cpu_description(NULL);
_cpu_info->set_cpu_description(nullptr);
}
delete _cpu_info;
}
}
int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) {
if (NULL == _cpu_info) {
if (nullptr == _cpu_info) {
return OS_ERR;
}
@ -428,16 +428,16 @@ NetworkPerformanceInterface::NetworkPerformance::~NetworkPerformance() {
int NetworkPerformanceInterface::NetworkPerformance::network_utilization(NetworkInterface** network_interfaces) const {
size_t len;
int mib[] = {CTL_NET, PF_ROUTE, /* protocol number */ 0, /* address family */ 0, NET_RT_IFLIST2, /* NET_RT_FLAGS mask*/ 0};
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &len, NULL, 0) != 0) {
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), nullptr, &len, nullptr, 0) != 0) {
return OS_ERR;
}
uint8_t* buf = NEW_RESOURCE_ARRAY(uint8_t, len);
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &len, NULL, 0) != 0) {
if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), buf, &len, nullptr, 0) != 0) {
return OS_ERR;
}
size_t index = 0;
NetworkInterface* ret = NULL;
NetworkInterface* ret = nullptr;
while (index < len) {
if_msghdr* msghdr = reinterpret_cast<if_msghdr*>(buf + index);
index += msghdr->ifm_msglen;
@ -468,11 +468,11 @@ int NetworkPerformanceInterface::NetworkPerformance::network_utilization(Network
}
NetworkPerformanceInterface::NetworkPerformanceInterface() {
_impl = NULL;
_impl = nullptr;
}
NetworkPerformanceInterface::~NetworkPerformanceInterface() {
if (_impl != NULL) {
if (_impl != nullptr) {
delete _impl;
}
}