diff --git a/src/hotspot/os/linux/attachListener_linux.cpp b/src/hotspot/os/linux/attachListener_linux.cpp index ac87c794774..63c5bfef125 100644 --- a/src/hotspot/os/linux/attachListener_linux.cpp +++ b/src/hotspot/os/linux/attachListener_linux.cpp @@ -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 @@ -83,7 +83,7 @@ class LinuxAttachListener: AllStatic { }; static void set_path(char* path) { - if (path == NULL) { + if (path == nullptr) { _path[0] = '\0'; _has_path = false; } else { @@ -146,7 +146,7 @@ class ArgumentIterator : public StackObj { if (_pos < _end) { _pos += 1; } - return NULL; + return nullptr; } char* res = _pos; char* next_pos = strchr(_pos, '\0'); @@ -171,7 +171,7 @@ extern "C" { } if (LinuxAttachListener::has_path()) { ::unlink(LinuxAttachListener::path()); - LinuxAttachListener::set_path(NULL); + LinuxAttachListener::set_path(nullptr); } } } @@ -275,7 +275,7 @@ LinuxAttachOperation* LinuxAttachListener::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 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) { char msg[32]; os::snprintf_checked(msg, sizeof(msg), "%d\n", ATTACH_ERROR_BADVERSION); write_fully(s, msg, strlen(msg)); - return NULL; + return nullptr; } } } @@ -303,7 +303,7 @@ LinuxAttachOperation* LinuxAttachListener::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 @@ LinuxAttachOperation* LinuxAttachListener::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; } LinuxAttachOperation* op = new LinuxAttachOperation(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 @@ LinuxAttachOperation* LinuxAttachListener::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 @@ LinuxAttachOperation* LinuxAttachListener::dequeue() { // peer credential look okay so we read the request LinuxAttachOperation* op = read_request(s); - if (op == NULL) { + if (op == nullptr) { ::close(s); continue; } else { @@ -548,7 +548,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) { diff --git a/src/hotspot/os/linux/cgroupSubsystem_linux.cpp b/src/hotspot/os/linux/cgroupSubsystem_linux.cpp index 1f3a6dfcaf6..9053e8eac30 100644 --- a/src/hotspot/os/linux/cgroupSubsystem_linux.cpp +++ b/src/hotspot/os/linux/cgroupSubsystem_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -39,11 +39,11 @@ static const char* cg_controller_name[] = { "cpu", "cpuset", "cpuacct", "memory", "pids" }; CgroupSubsystem* CgroupSubsystemFactory::create() { - CgroupV1MemoryController* memory = NULL; - CgroupV1Controller* cpuset = NULL; - CgroupV1Controller* cpu = NULL; - CgroupV1Controller* cpuacct = NULL; - CgroupV1Controller* pids = NULL; + CgroupV1MemoryController* memory = nullptr; + CgroupV1Controller* cpuset = nullptr; + CgroupV1Controller* cpu = nullptr; + CgroupV1Controller* cpuacct = nullptr; + CgroupV1Controller* pids = nullptr; CgroupInfo cg_infos[CG_INFO_LENGTH]; u1 cg_type_flags = INVALID_CGROUPS_GENERIC; const char* proc_cgroups = "/proc/cgroups"; @@ -54,7 +54,7 @@ CgroupSubsystem* CgroupSubsystemFactory::create() { if (!valid_cgroup) { // Could not detect cgroup type - return NULL; + return nullptr; } assert(is_valid_cgroup(&cg_type_flags), "Expected valid cgroup type"); @@ -128,7 +128,7 @@ void CgroupSubsystemFactory::set_controller_paths(CgroupInfo* cg_infos, const char* name, char* mount_path, char* root_path) { - if (cg_infos[controller]._mount_path != NULL) { + if (cg_infos[controller]._mount_path != nullptr) { // On some systems duplicate controllers get mounted in addition to // the main cgroup controllers most likely under /sys/fs/cgroup. In that // case pick the one under /sys/fs/cgroup and discard others. @@ -154,9 +154,9 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, const char* proc_self_cgroup, const char* proc_self_mountinfo, u1* flags) { - FILE *mntinfo = NULL; - FILE *cgroups = NULL; - FILE *cgroup = NULL; + FILE *mntinfo = nullptr; + FILE *cgroups = nullptr; + FILE *cgroup = nullptr; char buf[MAXPATHLEN+1]; char *p; bool is_cgroupsV2; @@ -174,13 +174,13 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, * controllers must have hierarchy ID 0 and the unified controller mounted. */ cgroups = os::fopen(proc_cgroups, "r"); - if (cgroups == NULL) { + if (cgroups == nullptr) { log_debug(os, container)("Can't open %s, %s", proc_cgroups, os::strerror(errno)); *flags = INVALID_CGROUPS_GENERIC; return false; } - while ((p = fgets(buf, MAXPATHLEN, cgroups)) != NULL) { + while ((p = fgets(buf, MAXPATHLEN, cgroups)) != nullptr) { char name[MAXPATHLEN+1]; int hierarchy_id; int enabled; @@ -242,7 +242,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, * the host mount point to the local one via /proc/self/mountinfo below. */ cgroup = os::fopen(proc_self_cgroup, "r"); - if (cgroup == NULL) { + if (cgroup == nullptr) { log_debug(os, container)("Can't open %s, %s", proc_self_cgroup, os::strerror(errno)); cleanup(cg_infos); @@ -250,7 +250,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, return false; } - while ((p = fgets(buf, MAXPATHLEN, cgroup)) != NULL) { + while ((p = fgets(buf, MAXPATHLEN, cgroup)) != nullptr) { char *controllers; char *token; char *hierarchy_id_str; @@ -263,11 +263,11 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, controllers = strsep(&p, ":"); cgroup_path = strsep(&p, "\n"); - if (controllers == NULL) { + if (controllers == nullptr) { continue; } - while (!is_cgroupsV2 && (token = strsep(&controllers, ",")) != NULL) { + while (!is_cgroupsV2 && (token = strsep(&controllers, ",")) != nullptr) { if (strcmp(token, "memory") == 0) { assert(hierarchy_id == cg_infos[MEMORY_IDX]._hierarchy_id, "/proc/cgroups and /proc/self/cgroup hierarchy mismatch for memory"); cg_infos[MEMORY_IDX]._cgroup_path = os::strdup(cgroup_path); @@ -293,7 +293,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, continue; } for (int i = 0; i < CG_INFO_LENGTH; i++) { - assert(cg_infos[i]._cgroup_path == NULL, "cgroup path must only be set once"); + assert(cg_infos[i]._cgroup_path == nullptr, "cgroup path must only be set once"); cg_infos[i]._cgroup_path = os::strdup(cgroup_path); } } @@ -303,7 +303,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 = os::fopen(proc_self_mountinfo, "r"); - if (mntinfo == NULL) { + if (mntinfo == nullptr) { log_debug(os, container)("Can't open %s, %s", proc_self_mountinfo, os::strerror(errno)); cleanup(cg_infos); @@ -313,7 +313,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, bool cgroupv2_mount_point_found = false; bool any_cgroup_mounts_found = false; - while ((p = fgets(buf, MAXPATHLEN, mntinfo)) != NULL) { + while ((p = fgets(buf, MAXPATHLEN, mntinfo)) != nullptr) { char tmp_fs_type[MAXPATHLEN+1]; char tmproot[MAXPATHLEN+1]; char tmpmount[MAXPATHLEN+1]; @@ -352,7 +352,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, // Skip cgroup2 fs lines on hybrid or unified hierarchy. continue; } - while ((token = strsep(&cptr, ",")) != NULL) { + while ((token = strsep(&cptr, ",")) != nullptr) { if (strcmp(token, "memory") == 0) { any_cgroup_mounts_found = true; set_controller_paths(cg_infos, MEMORY_IDX, token, tmpmount, tmproot); @@ -437,7 +437,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos, }; void CgroupSubsystemFactory::cleanup(CgroupInfo* cg_infos) { - assert(cg_infos != NULL, "Invariant"); + assert(cg_infos != nullptr, "Invariant"); for (int i = 0; i < CG_INFO_LENGTH; i++) { os::free(cg_infos[i]._name); os::free(cg_infos[i]._cgroup_path); @@ -557,7 +557,7 @@ jlong CgroupSubsystem::memory_limit_in_bytes() { } jlong CgroupSubsystem::limit_from_str(char* limit_str) { - if (limit_str == NULL) { + if (limit_str == nullptr) { return OSCONTAINER_ERROR; } // Unlimited memory in cgroups is the literal string 'max' for diff --git a/src/hotspot/os/linux/cgroupSubsystem_linux.hpp b/src/hotspot/os/linux/cgroupSubsystem_linux.hpp index 991f25b7172..ceb20ededdb 100644 --- a/src/hotspot/os/linux/cgroupSubsystem_linux.hpp +++ b/src/hotspot/os/linux/cgroupSubsystem_linux.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -90,11 +90,11 @@ template <typename T> int subsystem_file_line_contents(CgroupController* c, const char *scan_fmt, T returnval) { if (c == nullptr) { - log_debug(os, container)("subsystem_file_line_contents: CgroupController* is nullptr"); + log_debug(os, container)("subsystem_file_line_contents: CgroupController* is null"); return OSCONTAINER_ERROR; } if (c->subsystem_path() == nullptr) { - log_debug(os, container)("subsystem_file_line_contents: subsystem path is nullptr"); + log_debug(os, container)("subsystem_file_line_contents: subsystem path is null"); return OSCONTAINER_ERROR; } @@ -166,7 +166,7 @@ PRAGMA_DIAG_POP int err; \ err = subsystem_file_line_contents(subsystem, \ filename, \ - NULL, \ + nullptr, \ scan_fmt, \ &variable); \ if (err != 0) { \ @@ -184,11 +184,11 @@ PRAGMA_DIAG_POP int err; \ err = subsystem_file_line_contents(subsystem, \ filename, \ - NULL, \ + nullptr, \ scan_fmt, \ variable); \ if (err != 0) \ - return (return_type) NULL; \ + return (return_type) nullptr; \ \ log_trace(os, container)(logstring, variable); \ } @@ -293,13 +293,13 @@ class CgroupInfo : public StackObj { public: CgroupInfo() { - _name = NULL; + _name = nullptr; _hierarchy_id = -1; _enabled = false; _data_complete = false; - _cgroup_path = NULL; - _root_mount_path = NULL; - _mount_path = NULL; + _cgroup_path = nullptr; + _root_mount_path = nullptr; + _mount_path = nullptr; } }; diff --git a/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp b/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp index cfa8f516e3e..4ff77f47223 100644 --- a/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp +++ b/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -39,7 +39,7 @@ */ void CgroupV1Controller::set_subsystem_path(char *cgroup_path) { stringStream ss; - if (_root != NULL && cgroup_path != NULL) { + if (_root != nullptr && cgroup_path != nullptr) { if (strcmp(_root, "/") == 0) { ss.print_raw(_mount_point); if (strcmp(cgroup_path,"/") != 0) { @@ -52,7 +52,7 @@ void CgroupV1Controller::set_subsystem_path(char *cgroup_path) { _path = os::strdup(ss.base()); } else { char *p = strstr(cgroup_path, _root); - if (p != NULL && p == _root) { + if (p != nullptr && p == _root) { if (strlen(cgroup_path) > strlen(_root)) { ss.print_raw(_mount_point); const char* cg_path_sub = cgroup_path + strlen(_root); @@ -297,7 +297,7 @@ char* CgroupV1Subsystem::pids_max_val() { * OSCONTAINER_ERROR for not supported */ jlong CgroupV1Subsystem::pids_max() { - if (_pids == NULL) return OSCONTAINER_ERROR; + if (_pids == nullptr) return OSCONTAINER_ERROR; char * pidsmax_str = pids_max_val(); return limit_from_str(pidsmax_str); } @@ -311,7 +311,7 @@ jlong CgroupV1Subsystem::pids_max() { * OSCONTAINER_ERROR for not supported */ jlong CgroupV1Subsystem::pids_current() { - if (_pids == NULL) return OSCONTAINER_ERROR; + if (_pids == nullptr) return OSCONTAINER_ERROR; GET_CONTAINER_INFO(jlong, _pids, "/pids.current", "Current number of tasks is: " JLONG_FORMAT, JLONG_FORMAT, pids_current); return pids_current; diff --git a/src/hotspot/os/linux/cgroupV1Subsystem_linux.hpp b/src/hotspot/os/linux/cgroupV1Subsystem_linux.hpp index 07fac4a9461..3600ecaee67 100644 --- a/src/hotspot/os/linux/cgroupV1Subsystem_linux.hpp +++ b/src/hotspot/os/linux/cgroupV1Subsystem_linux.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -44,7 +44,7 @@ class CgroupV1Controller: public CgroupController { CgroupV1Controller(char *root, char *mountpoint) { _root = os::strdup(root); _mount_point = os::strdup(mountpoint); - _path = NULL; + _path = nullptr; } virtual void set_subsystem_path(char *cgroup_path); @@ -105,11 +105,11 @@ class CgroupV1Subsystem: public CgroupSubsystem { private: /* controllers */ - CachingCgroupController* _memory = NULL; - CgroupV1Controller* _cpuset = NULL; - CachingCgroupController* _cpu = NULL; - CgroupV1Controller* _cpuacct = NULL; - CgroupV1Controller* _pids = NULL; + CachingCgroupController* _memory = nullptr; + CgroupV1Controller* _cpuset = nullptr; + CachingCgroupController* _cpu = nullptr; + CgroupV1Controller* _cpuacct = nullptr; + CgroupV1Controller* _pids = nullptr; char * pids_max_val(); diff --git a/src/hotspot/os/linux/cgroupV2Subsystem_linux.hpp b/src/hotspot/os/linux/cgroupV2Subsystem_linux.hpp index bda5872bbbc..bb6b538c216 100644 --- a/src/hotspot/os/linux/cgroupV2Subsystem_linux.hpp +++ b/src/hotspot/os/linux/cgroupV2Subsystem_linux.hpp @@ -51,10 +51,10 @@ class CgroupV2Controller: public CgroupController { class CgroupV2Subsystem: public CgroupSubsystem { private: /* One unified controller */ - CgroupController* _unified = NULL; + CgroupController* _unified = nullptr; /* Caching wrappers for cpu/memory metrics */ - CachingCgroupController* _memory = NULL; - CachingCgroupController* _cpu = NULL; + CachingCgroupController* _memory = nullptr; + CachingCgroupController* _cpu = nullptr; char *mem_limit_val(); char *mem_swp_limit_val(); diff --git a/src/hotspot/os/linux/decoder_linux.cpp b/src/hotspot/os/linux/decoder_linux.cpp index c5c3c2b7d2c..26b435f69e1 100644 --- a/src/hotspot/os/linux/decoder_linux.cpp +++ b/src/hotspot/os/linux/decoder_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -44,7 +44,7 @@ bool ElfDecoder::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 ALLOW_C_FUNCTION(::free, ::free(result);) @@ -58,10 +58,10 @@ bool ElfDecoder::demangle(const char* symbol, char *buf, int buflen) { // Returns false if the elf file requires an executable stack, the stack flag // is not set at all, or if the file can not be read. bool ElfFile::specifies_noexecstack(const char* filepath) { - if (filepath == NULL) return true; + if (filepath == nullptr) return true; FILE* file = os::fopen(filepath, "r"); - if (file == NULL) return true; + if (file == nullptr) return true; // AARCH64 defaults to noexecstack. All others default to execstack. bool result = AARCH64_ONLY(true) NOT_AARCH64(false); diff --git a/src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp b/src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp index 527fdb043be..e24367219aa 100644 --- a/src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp +++ b/src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 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 @@ -37,7 +37,7 @@ #define PROC_SELF_MOUNTINFO "/proc/self/mountinfo" ZMountPoint::ZMountPoint(const char* filesystem, const char** preferred_mountpoints) { - if (AllocateHeapAt != NULL) { + if (AllocateHeapAt != nullptr) { // Use specified path _path = os::strdup(AllocateHeapAt, mtGC); } else { @@ -48,12 +48,12 @@ ZMountPoint::ZMountPoint(const char* filesystem, const char** preferred_mountpoi ZMountPoint::~ZMountPoint() { os::free(_path); - _path = NULL; + _path = nullptr; } char* ZMountPoint::get_mountpoint(const char* line, const char* filesystem) const { - char* line_mountpoint = NULL; - char* line_filesystem = NULL; + char* line_mountpoint = nullptr; + char* line_filesystem = nullptr; // Parse line and return a newly allocated string containing the mount point if // the line contains a matching filesystem and the mount point is accessible by @@ -64,7 +64,7 @@ char* ZMountPoint::get_mountpoint(const char* line, const char* filesystem) cons access(line_mountpoint, R_OK|W_OK|X_OK) != 0) { // Not a matching or accessible filesystem ALLOW_C_FUNCTION(::free, ::free(line_mountpoint);) - line_mountpoint = NULL; + line_mountpoint = nullptr; } ALLOW_C_FUNCTION(::free, ::free(line_filesystem);) @@ -74,18 +74,18 @@ char* ZMountPoint::get_mountpoint(const char* line, const char* filesystem) cons void ZMountPoint::get_mountpoints(const char* filesystem, ZArray<char*>* mountpoints) const { FILE* fd = os::fopen(PROC_SELF_MOUNTINFO, "r"); - if (fd == NULL) { + if (fd == nullptr) { ZErrno err; log_error_p(gc)("Failed to open %s: %s", PROC_SELF_MOUNTINFO, err.to_string()); return; } - char* line = NULL; + char* line = nullptr; size_t length = 0; while (getline(&line, &length, fd) != -1) { char* const mountpoint = get_mountpoint(line, filesystem); - if (mountpoint != NULL) { + if (mountpoint != nullptr) { mountpoints->append(mountpoint); } } @@ -109,7 +109,7 @@ char* ZMountPoint::find_preferred_mountpoint(const char* filesystem, // Find preferred mount point ZArrayIterator<char*> iter1(mountpoints); for (char* mountpoint; iter1.next(&mountpoint);) { - for (const char** preferred = preferred_mountpoints; *preferred != NULL; preferred++) { + for (const char** preferred = preferred_mountpoints; *preferred != nullptr; preferred++) { if (!strcmp(mountpoint, *preferred)) { // Preferred mount point found return os::strdup(mountpoint, mtGC); @@ -124,11 +124,11 @@ char* ZMountPoint::find_preferred_mountpoint(const char* filesystem, log_error_p(gc)(" %s", mountpoint); } - return NULL; + return nullptr; } char* ZMountPoint::find_mountpoint(const char* filesystem, const char** preferred_mountpoints) const { - char* path = NULL; + char* path = nullptr; ZArray<char*> mountpoints; get_mountpoints(filesystem, &mountpoints); diff --git a/src/hotspot/os/linux/gc/z/zNUMA_linux.cpp b/src/hotspot/os/linux/gc/z/zNUMA_linux.cpp index c5ba06ea8b7..3ae0c6ab719 100644 --- a/src/hotspot/os/linux/gc/z/zNUMA_linux.cpp +++ b/src/hotspot/os/linux/gc/z/zNUMA_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 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 @@ -60,7 +60,7 @@ uint32_t ZNUMA::memory_id(uintptr_t addr) { uint32_t id = (uint32_t)-1; - if (ZSyscall::get_mempolicy((int*)&id, NULL, 0, (void*)addr, MPOL_F_NODE | MPOL_F_ADDR) == -1) { + if (ZSyscall::get_mempolicy((int*)&id, nullptr, 0, (void*)addr, MPOL_F_NODE | MPOL_F_ADDR) == -1) { ZErrno err; fatal("Failed to get NUMA id for memory at " PTR_FORMAT " (%s)", addr, err.to_string()); } diff --git a/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp b/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp index 7eb9608aaa8..f2fff578176 100644 --- a/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp +++ b/src/hotspot/os/linux/gc/z/zPhysicalMemoryBacking_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -104,14 +104,14 @@ static const char* z_preferred_tmpfs_mountpoints[] = { "/dev/shm", "/run/shm", - NULL + nullptr }; // Preferred hugetlbfs mount points, ordered by priority static const char* z_preferred_hugetlbfs_mountpoints[] = { "/dev/hugepages", "/hugepages", - NULL + nullptr }; static int z_fallocate_hugetlbfs_attempts = 3; @@ -229,7 +229,7 @@ int ZPhysicalMemoryBacking::create_file_fd(const char* name) const { // Find mountpoint ZMountPoint mountpoint(filesystem, preferred_mountpoints); - if (mountpoint.get() == NULL) { + if (mountpoint.get() == nullptr) { log_error_p(gc)("Use -XX:AllocateHeapAt to specify the path to a %s filesystem", filesystem); return -1; } @@ -282,7 +282,7 @@ int ZPhysicalMemoryBacking::create_file_fd(const char* name) const { } int ZPhysicalMemoryBacking::create_fd(const char* name) const { - if (AllocateHeapAt == NULL) { + if (AllocateHeapAt == nullptr) { // If the path is not explicitly specified, then we first try to create a memfd file // instead of looking for a tmpfd/hugetlbfs mount point. Note that memfd_create() might // not be supported at all (requires kernel >= 3.17), or it might not support large @@ -331,7 +331,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 = os::fopen(filename, "r"); - if (file == NULL) { + if (file == nullptr) { // Failed to open file, skip check log_debug_p(gc, init)("Failed to open %s", filename); return; diff --git a/src/hotspot/os/linux/osContainer_linux.cpp b/src/hotspot/os/linux/osContainer_linux.cpp index 3bd96d0fb90..c70c96c678a 100644 --- a/src/hotspot/os/linux/osContainer_linux.cpp +++ b/src/hotspot/os/linux/osContainer_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -55,7 +55,7 @@ void OSContainer::init() { } cgroup_subsystem = CgroupSubsystemFactory::create(); - if (cgroup_subsystem == NULL) { + if (cgroup_subsystem == nullptr) { return; // Required subsystem files not found or other error } @@ -63,77 +63,77 @@ void OSContainer::init() { } const char * OSContainer::container_type() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->container_type(); } jlong OSContainer::memory_limit_in_bytes() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->memory_limit_in_bytes(); } jlong OSContainer::memory_and_swap_limit_in_bytes() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->memory_and_swap_limit_in_bytes(); } jlong OSContainer::memory_soft_limit_in_bytes() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->memory_soft_limit_in_bytes(); } jlong OSContainer::memory_usage_in_bytes() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->memory_usage_in_bytes(); } jlong OSContainer::memory_max_usage_in_bytes() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->memory_max_usage_in_bytes(); } void OSContainer::print_version_specific_info(outputStream* st) { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); cgroup_subsystem->print_version_specific_info(st); } char * OSContainer::cpu_cpuset_cpus() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->cpu_cpuset_cpus(); } char * OSContainer::cpu_cpuset_memory_nodes() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->cpu_cpuset_memory_nodes(); } int OSContainer::active_processor_count() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->active_processor_count(); } int OSContainer::cpu_quota() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->cpu_quota(); } int OSContainer::cpu_period() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->cpu_period(); } int OSContainer::cpu_shares() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->cpu_shares(); } jlong OSContainer::pids_max() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->pids_max(); } jlong OSContainer::pids_current() { - assert(cgroup_subsystem != NULL, "cgroup subsystem not available"); + assert(cgroup_subsystem != nullptr, "cgroup subsystem not available"); return cgroup_subsystem->pids_current(); } diff --git a/src/hotspot/os/linux/osThread_linux.cpp b/src/hotspot/os/linux/osThread_linux.cpp index b6365558da1..eb4d062511c 100644 --- a/src/hotspot/os/linux/osThread_linux.cpp +++ b/src/hotspot/os/linux/osThread_linux.cpp @@ -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,18 +30,18 @@ #include <signal.h> void OSThread::pd_initialize() { - assert(this != NULL, "check"); + assert(this != nullptr, "check"); _thread_id = 0; _pthread_id = 0; - _siginfo = NULL; - _ucontext = NULL; + _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"); } void OSThread::pd_destroy() { diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp index dbebaaaf8b4..3de725a950f 100644 --- a/src/hotspot/os/linux/os_linux.cpp +++ b/src/hotspot/os/linux/os_linux.cpp @@ -157,15 +157,15 @@ enum CoredumpFilterBit { // global variables julong os::Linux::_physical_memory = 0; -address os::Linux::_initial_thread_stack_bottom = NULL; +address os::Linux::_initial_thread_stack_bottom = nullptr; uintptr_t os::Linux::_initial_thread_stack_size = 0; -int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL; -int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL; +int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = nullptr; +int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = nullptr; pthread_t os::Linux::_main_thread; bool os::Linux::_supports_fast_thread_cpu_time = false; -const char * os::Linux::_libc_version = NULL; -const char * os::Linux::_libpthread_version = NULL; +const char * os::Linux::_libc_version = nullptr; +const char * os::Linux::_libpthread_version = nullptr; size_t os::Linux::_default_large_page_size = 0; #ifdef __GLIBC__ @@ -184,7 +184,7 @@ struct old_mallinfo { int keepcost; }; typedef struct old_mallinfo (*mallinfo_func_t)(void); -static mallinfo_func_t g_mallinfo = NULL; +static mallinfo_func_t g_mallinfo = nullptr; struct new_mallinfo { size_t arena; @@ -199,7 +199,7 @@ struct new_mallinfo { size_t keepcost; }; typedef struct new_mallinfo (*mallinfo2_func_t)(void); -static mallinfo2_func_t g_mallinfo2 = NULL; +static mallinfo2_func_t g_mallinfo2 = nullptr; #endif // __GLIBC__ static int clock_tics_per_sec = 100; @@ -284,7 +284,7 @@ bool os::Linux::get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu memset(pticks, 0, sizeof(CPUPerfTicks)); - if ((fh = os::fopen("/proc/stat", "r")) == NULL) { + if ((fh = os::fopen("/proc/stat", "r")) == nullptr) { return false; } @@ -387,7 +387,7 @@ void os::Linux::initialize_system_info() { char fname[32]; jio_snprintf(fname, sizeof(fname), "/proc/%d", pid); FILE *fp = os::fopen(fname, "r"); - if (fp == NULL) { + if (fp == nullptr) { unsafe_chroot_detected = true; } else { fclose(fp); @@ -460,24 +460,24 @@ void os::init_system_properties_values() { // Found the full path to libjvm.so. // Now cut the path to <java_home>/jre if we can. pslash = strrchr(buf, '/'); - if (pslash != NULL) { + if (pslash != nullptr) { *pslash = '\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 /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); } } @@ -497,7 +497,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'. size_t pathsize = strlen(v) + 1 + sizeof(SYS_EXT_DIR) + sizeof("/lib/") + sizeof(DEFAULT_LIBPATH) + 1; char *ld_library_path = NEW_C_HEAP_ARRAY(char, pathsize, mtInternal); @@ -544,13 +544,13 @@ void os::Linux::libpthread_init() { os::Linux::set_libc_version("musl - unknown"); os::Linux::set_libpthread_version("musl - unknown"); #else - size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0); + size_t n = confstr(_CS_GNU_LIBC_VERSION, nullptr, 0); assert(n > 0, "cannot retrieve glibc version"); char *str = (char *)malloc(n, mtInternal); confstr(_CS_GNU_LIBC_VERSION, str, n); os::Linux::set_libc_version(str); - n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0); + n = confstr(_CS_GNU_LIBPTHREAD_VERSION, nullptr, 0); assert(n > 0, "cannot retrieve pthread version"); str = (char *)malloc(n, mtInternal); confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n); @@ -647,7 +647,7 @@ static void NOINLINE _expand_stack_to(address bottom) { if (sp > bottom) { size = sp - bottom; p = (volatile char *)alloca(size); - assert(p != NULL && p <= (volatile char *)bottom, "alloca problem?"); + assert(p != nullptr && p <= (volatile char *)bottom, "alloca problem?"); p[0] = '\0'; } } @@ -657,7 +657,7 @@ void os::Linux::expand_stack_to(address bottom) { } bool os::Linux::manually_expand_stack(JavaThread * t, address addr) { - assert(t!=NULL, "just checking"); + assert(t!=nullptr, "just checking"); assert(t->osthread()->expanding_stack(), "expand should be set"); if (t->is_in_usable_stack(addr)) { @@ -665,7 +665,7 @@ bool os::Linux::manually_expand_stack(JavaThread * t, address addr) { sigfillset(&mask_all); pthread_sigmask(SIG_SETMASK, &mask_all, &old_sigset); _expand_stack_to(addr); - pthread_sigmask(SIG_SETMASK, &old_sigset, NULL); + pthread_sigmask(SIG_SETMASK, &old_sigset, nullptr); return true; } return false; @@ -738,7 +738,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()); @@ -763,13 +763,13 @@ static void *thread_native_entry(Thread *thread) { // controlled via AdjustStackSizeForTLS. typedef size_t (*GetMinStack)(const pthread_attr_t *attr); -GetMinStack _get_minstack_func = NULL; +GetMinStack _get_minstack_func = nullptr; static void get_minstack_init() { _get_minstack_func = (GetMinStack)dlsym(RTLD_DEFAULT, "__pthread_get_minstack"); log_info(os, thread)("Lookup of __pthread_get_minstack %s", - _get_minstack_func == NULL ? "failed" : "succeeded"); + _get_minstack_func == nullptr ? "failed" : "succeeded"); } // Returns the size of the static TLS area glibc puts on thread stacks. @@ -777,7 +777,7 @@ static void get_minstack_init() { // is created during VM initialization. static size_t get_static_tls_area_size(const pthread_attr_t *attr) { size_t tls_size = 0; - if (_get_minstack_func != NULL) { + if (_get_minstack_func != nullptr) { // Obtain the pthread minstack size by calling __pthread_get_minstack. size_t minstack_size = _get_minstack_func(attr); @@ -815,11 +815,11 @@ static size_t get_static_tls_area_size(const pthread_attr_t *attr) { 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; } @@ -872,7 +872,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type, log_warning(os, thread)("The %sthread stack size specified is invalid: " SIZE_FORMAT "k", (thr_type == compiler_thread) ? "compiler " : ((thr_type == java_thread) ? "" : "VM "), stack_size / K); - thread->set_osthread(NULL); + thread->set_osthread(nullptr); delete osthread; return false; } @@ -908,7 +908,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; } @@ -949,7 +949,7 @@ bool os::create_attached_thread(JavaThread* thread) { // Allocate the OSThread object OSThread* osthread = new OSThread(); - if (osthread == NULL) { + if (osthread == nullptr) { return false; } @@ -984,7 +984,7 @@ bool os::create_attached_thread(JavaThread* thread) { StackOverflow* overflow_state = thread->stack_overflow_state(); address addr = overflow_state->stack_reserved_zone_base(); - assert(addr != NULL, "initialization problem?"); + assert(addr != nullptr, "initialization problem?"); assert(overflow_state->stack_available(addr) > 0, "stack guard should not be enabled"); osthread->set_expanding_stack(); @@ -1014,7 +1014,7 @@ void os::pd_start_thread(Thread* thread) { // Free Linux 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. @@ -1024,13 +1024,13 @@ void os::free_thread(OSThread* osthread) { #ifdef ASSERT sigset_t current; sigemptyset(¤t); - pthread_sigmask(SIG_SETMASK, NULL, ¤t); + pthread_sigmask(SIG_SETMASK, nullptr, ¤t); assert(!sigismember(¤t, PosixSignals::SR_signum), "SR signal should not be blocked!"); #endif // 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; } @@ -1046,8 +1046,8 @@ bool os::is_primordial_thread(void) { char dummy; // If called before init complete, thread stack bottom will be null. // Can be called if fatal error occurs before initialization. - if (os::Linux::initial_thread_stack_bottom() == NULL) return false; - assert(os::Linux::initial_thread_stack_bottom() != NULL && + if (os::Linux::initial_thread_stack_bottom() == nullptr) return false; + assert(os::Linux::initial_thread_stack_bottom() != nullptr && os::Linux::initial_thread_stack_size() != 0, "os::init did not locate primordial thread's stack region"); if ((address)&dummy >= os::Linux::initial_thread_stack_bottom() && @@ -1352,11 +1352,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) { @@ -1370,21 +1370,21 @@ 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 (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; } // 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; @@ -1393,7 +1393,7 @@ bool os::dll_address_to_function_name(address addr, char *buf, } buf[0] = '\0'; - if (offset != NULL) *offset = -1; + if (offset != nullptr) *offset = -1; return false; } @@ -1433,7 +1433,7 @@ class VM_LinuxDllLoad: public VM_Operation { void *_lib; public: VM_LinuxDllLoad(const char *fn, char *ebuf, int ebuflen) : - _filename(fn), _ebuf(ebuf), _ebuflen(ebuflen), _lib(NULL) {} + _filename(fn), _ebuf(ebuf), _ebuflen(ebuflen), _lib(nullptr) {} VMOp_Type type() const { return VMOp_LinuxDllLoad; } void doit() { _lib = os::Linux::dll_load_in_vmthread(_filename, _ebuf, _ebuflen); @@ -1443,7 +1443,7 @@ class VM_LinuxDllLoad: public VM_Operation { }; void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { - void * result = NULL; + void * result = nullptr; bool load_attempted = false; log_info(os)("attempting shared library load of %s", filename); @@ -1501,7 +1501,7 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { result = os::Linux::dlopen_helper(filename, ebuf, ebuflen); } - if (result != NULL) { + if (result != nullptr) { // Successful loading return result; } @@ -1512,7 +1512,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; } @@ -1520,7 +1520,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= @@ -1530,13 +1530,13 @@ 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; } if (elf_head.e_ident[EI_DATA] != LITTLE_ENDIAN_ONLY(ELFDATA2LSB) BIG_ENDIAN_ONLY(ELFDATA2MSB)) { // handle invalid/out of range endianness values if (elf_head.e_ident[EI_DATA] == 0 || elf_head.e_ident[EI_DATA] > 2) { - return NULL; + return nullptr; } #if defined(VM_LITTLE_ENDIAN) @@ -1643,7 +1643,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++) { @@ -1661,11 +1661,11 @@ 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.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 .so on a %s platform)", lib_arch.name, arch_array[running_arch_index].name); @@ -1674,46 +1674,46 @@ void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { " (Possible cause: can't load this .so (machine code=0x%x) on a %s platform)", lib_arch.code, arch_array[running_arch_index].name); } - return NULL; + return nullptr; } if (lib_arch.endianness != arch_array[running_arch_index].endianness) { ::snprintf(diag_msg_buf, diag_msg_max_length-1, " (Possible cause: endianness mismatch)"); - return NULL; + return nullptr; } // ELF file class/capacity : 0 - invalid, 1 - 32bit, 2 - 64bit if (lib_arch.elf_class > 2 || lib_arch.elf_class < 1) { ::snprintf(diag_msg_buf, diag_msg_max_length-1, " (Possible cause: invalid ELF file class)"); - return NULL; + return nullptr; } 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, can't load %d-bit .so on a %d-bit platform)", (int) lib_arch.elf_class * 32, arch_array[running_arch_index].elf_class * 32); - return NULL; + return nullptr; } - return NULL; + return nullptr; } void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) { void * result = ::dlopen(filename, RTLD_LAZY); - if (result == NULL) { + if (result == nullptr) { 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) { ::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); } else { - Events::log_dll_message(NULL, "Loaded shared library %s", filename); + Events::log_dll_message(nullptr, "Loaded shared library %s", filename); log_info(os)("shared library load of %s was successful", filename); } return result; @@ -1721,7 +1721,7 @@ void * os::Linux::dlopen_helper(const char *filename, char *ebuf, void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, int ebuflen) { - void * result = NULL; + void * result = nullptr; if (LoadExecStackDllInVMThread) { result = dlopen_helper(filename, ebuf, ebuflen); } @@ -1751,8 +1751,8 @@ void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, const char* os::Linux::dll_path(void* lib) { struct link_map *lmap; - const char* l_path = NULL; - assert(lib != NULL, "dll_path parameter must not be NULL"); + const char* l_path = nullptr; + assert(lib != nullptr, "dll_path parameter must not be null"); int res_dli = ::dlinfo(lib, RTLD_DI_LINKMAP, &lmap); if (res_dli == 0) { @@ -1761,13 +1761,13 @@ const char* os::Linux::dll_path(void* lib) { return l_path; } -static bool _print_ascii_file(const char* filename, outputStream* st, const char* hdr = NULL) { +static bool _print_ascii_file(const char* filename, outputStream* st, const char* hdr = nullptr) { int fd = ::open(filename, O_RDONLY); if (fd == -1) { return false; } - if (hdr != NULL) { + if (hdr != nullptr) { st->print_cr("%s", hdr); } @@ -1809,25 +1809,25 @@ struct loaded_modules_info_param { }; static int dl_iterate_callback(struct dl_phdr_info *info, size_t size, void *data) { - if ((info->dlpi_name == NULL) || (*info->dlpi_name == '\0')) { + if ((info->dlpi_name == nullptr) || (*info->dlpi_name == '\0')) { return 0; } struct loaded_modules_info_param *callback_param = reinterpret_cast<struct loaded_modules_info_param *>(data); - address base = NULL; - address top = NULL; + address base = nullptr; + address top = nullptr; for (int idx = 0; idx < info->dlpi_phnum; idx++) { const ElfW(Phdr) *phdr = info->dlpi_phdr + idx; if (phdr->p_type == PT_LOAD) { address raw_phdr_base = reinterpret_cast<address>(info->dlpi_addr + phdr->p_vaddr); address phdr_base = align_down(raw_phdr_base, phdr->p_align); - if ((base == NULL) || (base > phdr_base)) { + if ((base == nullptr) || (base > phdr_base)) { base = phdr_base; } address phdr_top = align_up(raw_phdr_base + phdr->p_memsz, phdr->p_align); - if ((top == NULL) || (top < phdr_top)) { + if ((top == nullptr) || (top < phdr_top)) { top = phdr_top; } } @@ -1929,12 +1929,12 @@ const char* distro_files[] = { "/etc/angstrom-version", "/etc/system-release", "/etc/os-release", - NULL }; + nullptr }; void os::Linux::print_distro_info(outputStream* st) { for (int i = 0;; i++) { const char* file = distro_files[i]; - if (file == NULL) { + if (file == nullptr) { break; // done } // If file prints, we found it. @@ -1955,37 +1955,37 @@ static void parse_os_info_helper(FILE* fp, char* distro, size_t length, bool get char buf[256]; while (fgets(buf, sizeof(buf), fp)) { // Edit out extra stuff in expected format - if (strstr(buf, "DISTRIB_DESCRIPTION=") != NULL || strstr(buf, "PRETTY_NAME=") != NULL) { + if (strstr(buf, "DISTRIB_DESCRIPTION=") != nullptr || strstr(buf, "PRETTY_NAME=") != nullptr) { char* ptr = strstr(buf, "\""); // the name is in quotes - if (ptr != NULL) { + if (ptr != nullptr) { ptr++; // go beyond first quote char* nl = strchr(ptr, '\"'); - if (nl != NULL) *nl = '\0'; + if (nl != nullptr) *nl = '\0'; strncpy(distro, ptr, length); } else { ptr = strstr(buf, "="); ptr++; // go beyond equals then char* nl = strchr(ptr, '\n'); - if (nl != NULL) *nl = '\0'; + if (nl != nullptr) *nl = '\0'; strncpy(distro, ptr, length); } return; } else if (get_first_line) { char* nl = strchr(buf, '\n'); - if (nl != NULL) *nl = '\0'; + if (nl != nullptr) *nl = '\0'; strncpy(distro, buf, length); return; } } // print last line and close char* nl = strchr(buf, '\n'); - if (nl != NULL) *nl = '\0'; + if (nl != nullptr) *nl = '\0'; strncpy(distro, buf, length); } static void parse_os_info(char* distro, size_t length, const char* file) { FILE* fp = os::fopen(file, "r"); - if (fp != NULL) { + if (fp != nullptr) { // if suse format, print out first line bool get_first_line = (strcmp(file, "/etc/SuSE-release") == 0); parse_os_info_helper(fp, distro, length, get_first_line); @@ -1996,7 +1996,7 @@ static void parse_os_info(char* distro, size_t length, const char* file) { void os::get_summary_os_info(char* buf, size_t buflen) { for (int i = 0;; i++) { const char* file = distro_files[i]; - if (file == NULL) { + if (file == nullptr) { break; // ran out of distro_files } if (file_exists(file)) { @@ -2051,8 +2051,8 @@ bool os::Linux::query_process_memory_info(os::Linux::meminfo_t* info) { char buf[256]; info->vmsize = info->vmpeak = info->vmrss = info->vmhwm = info->vmswap = info->rssanon = info->rssfile = info->rssshmem = -1; - if (f != NULL) { - while (::fgets(buf, sizeof(buf), f) != NULL && num_found < num_values) { + if (f != nullptr) { + while (::fgets(buf, sizeof(buf), f) != nullptr && num_found < num_values) { if ( (info->vmsize == -1 && sscanf(buf, "VmSize: " SSIZE_FORMAT " kB", &info->vmsize) == 1) || (info->vmpeak == -1 && sscanf(buf, "VmPeak: " SSIZE_FORMAT " kB", &info->vmpeak) == 1) || (info->vmswap == -1 && sscanf(buf, "VmSwap: " SSIZE_FORMAT " kB", &info->vmswap) == 1) || @@ -2084,12 +2084,12 @@ static void print_glibc_malloc_tunables(outputStream* st) { "MALLOC_CHECK_", "MALLOC_TOP_PAD_", "MALLOC_PERTURB_", "MALLOC_MMAP_THRESHOLD_", "MALLOC_TRIM_THRESHOLD_", "MALLOC_MMAP_MAX_", "MALLOC_ARENA_TEST", "MALLOC_ARENA_MAX", - NULL}; + nullptr}; st->print("glibc malloc tunables: "); bool printed = false; - for (int i = 0; var[i] != NULL; i ++) { + for (int i = 0; var[i] != nullptr; i ++) { const char* const val = ::getenv(var[i]); - if (val != NULL) { + if (val != nullptr) { st->print("%s%s=%s", (printed ? ", " : ""), var[i], val); printed = true; } @@ -2167,14 +2167,14 @@ bool os::Linux::print_container_info(outputStream* st) { st->print_cr("container (cgroup) information:"); const char *p_ct = OSContainer::container_type(); - st->print_cr("container_type: %s", p_ct != NULL ? p_ct : "not supported"); + st->print_cr("container_type: %s", p_ct != nullptr ? p_ct : "not supported"); char *p = OSContainer::cpu_cpuset_cpus(); - st->print_cr("cpu_cpuset_cpus: %s", p != NULL ? p : "not supported"); + st->print_cr("cpu_cpuset_cpus: %s", p != nullptr ? p : "not supported"); free(p); p = OSContainer::cpu_cpuset_memory_nodes(); - st->print_cr("cpu_memory_nodes: %s", p != NULL ? p : "not supported"); + st->print_cr("cpu_memory_nodes: %s", p != nullptr ? p : "not supported"); free(p); int i = OSContainer::active_processor_count(); @@ -2296,7 +2296,7 @@ static bool print_model_name_and_flags(outputStream* st, char* buf, size_t bufle while (!feof(fp)) { if (fgets(buf, buflen, fp)) { // Assume model name comes before flags - if (strstr(buf, "model name") != NULL) { + if (strstr(buf, "model name") != nullptr) { if (!model_name_printed) { st->print_raw("CPU Model and flags from /proc/cpuinfo:\n"); st->print_raw(buf); @@ -2308,7 +2308,7 @@ static bool print_model_name_and_flags(outputStream* st, char* buf, size_t bufle } } // print the flags line too - if (strstr(buf, "flags") != NULL) { + if (strstr(buf, "flags") != nullptr) { st->print_raw(buf); fclose(fp); return true; @@ -2395,12 +2395,12 @@ 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 = os::fopen("/proc/cpuinfo", "r"); - if (fp != NULL) { + if (fp != nullptr) { while (!feof(fp)) { char buf[256]; if (fgets(buf, sizeof(buf), fp)) { char* start = strstr(buf, search_string); - if (start != NULL) { + if (start != nullptr) { char *ptr = start + strlen(search_string); char *end = buf + strlen(buf); while (ptr != end) { @@ -2413,7 +2413,7 @@ void os::get_summary_cpu_info(char* cpuinfo, size_t length) { if (ptr != end) { // reasonable string, get rid of newline and keep the rest char* nl = strchr(buf, '\n'); - if (nl != NULL) *nl = '\0'; + if (nl != nullptr) *nl = '\0'; strncpy(cpuinfo, ptr, length); fclose(fp); return; @@ -2470,13 +2470,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; } @@ -2497,19 +2497,19 @@ 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; // Check the current module name "libjvm.so". p = strrchr(buf, '/'); - if (p == NULL) { + if (p == nullptr) { return; } assert(strstr(p, "/libjvm") == p, "invalid library name"); rp = os::Posix::realpath(java_home_var, buf, buflen); - if (rp == NULL) { + if (rp == nullptr) { return; } @@ -2530,7 +2530,7 @@ void os::jvm_path(char *buf, jint buflen) { } else { // Go back to path of .so rp = os::Posix::realpath(dli_fname, buf, buflen); - if (rp == NULL) { + if (rp == nullptr) { return; } } @@ -2650,7 +2650,7 @@ bool os::pd_commit_memory(char* addr, size_t size, bool exec) { 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"); int err = os::Linux::commit_memory_impl(addr, size, exec); if (err != 0) { // the caller wants all commit errors to exit with the specified mesg: @@ -2695,7 +2695,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, size_t alignment_hint, bool exec, const char* mesg) { - assert(mesg != NULL, "mesg must be specified"); + assert(mesg != nullptr, "mesg must be specified"); int err = os::Linux::commit_memory_impl(addr, size, alignment_hint, exec); if (err != 0) { // the caller wants all commit errors to exit with the specified mesg: @@ -2766,7 +2766,7 @@ int os::numa_get_group_id_for_address(const void* address) { void** pages = const_cast<void**>(&address); int id = -1; - if (os::Linux::numa_move_pages(0, 1, pages, NULL, &id, 0) == -1) { + if (os::Linux::numa_move_pages(0, 1, pages, nullptr, &id, 0) == -1) { return -1; } if (id < 0) { @@ -2777,7 +2777,7 @@ int os::numa_get_group_id_for_address(const void* address) { bool os::numa_get_group_ids_for_range(const void** addresses, int* lgrp_ids, size_t count) { void** pages = const_cast<void**>(addresses); - return os::Linux::numa_move_pages(0, count, pages, NULL, lgrp_ids, 0) == 0; + return os::Linux::numa_move_pages(0, count, pages, nullptr, lgrp_ids, 0) == 0; } int os::Linux::get_existing_num_nodes() { @@ -2824,7 +2824,7 @@ int os::Linux::sched_getcpu_syscall(void) { #ifndef SYS_getcpu #define SYS_getcpu 318 #endif - retval = syscall(SYS_getcpu, &cpu, NULL, NULL); + retval = syscall(SYS_getcpu, &cpu, nullptr, nullptr); #elif defined(AMD64) // Unfortunately we have to bring all these macros here from vsyscall.h // to be able to compile on old linuxes. @@ -2834,7 +2834,7 @@ int os::Linux::sched_getcpu_syscall(void) { #define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr)) typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache); vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu); - retval = vgetcpu(&cpu, NULL, NULL); + retval = vgetcpu(&cpu, nullptr, nullptr); #endif return (retval == -1) ? retval : cpu; @@ -2864,14 +2864,14 @@ extern "C" JNIEXPORT void numa_error(char *where) { } // load symbol from base version instead. void* os::Linux::libnuma_dlsym(void* handle, const char *name) { void *f = dlvsym(handle, name, "libnuma_1.1"); - if (f == NULL) { + if (f == nullptr) { f = dlsym(handle, name); } return f; } // Handle request to load libnuma symbol version 1.2 (API v2) only. -// Return NULL if the symbol is not defined in this particular version. +// Return null if the symbol is not defined in this particular version. void* os::Linux::libnuma_v2_dlsym(void* handle, const char* name) { return dlvsym(handle, name, "libnuma_1.2"); } @@ -2885,7 +2885,7 @@ static bool numa_syscall_check() { // others like mbind would cause unexpected side effects. #ifdef SYS_get_mempolicy int dummy = 0; - if (syscall(SYS_get_mempolicy, &dummy, NULL, 0, (void*)&dummy, 3) == -1) { + if (syscall(SYS_get_mempolicy, &dummy, nullptr, 0, (void*)&dummy, 3) == -1) { return false; } #endif @@ -2897,7 +2897,7 @@ bool os::Linux::libnuma_init() { // Requires sched_getcpu() and numa dependent syscalls support if ((sched_getcpu() != -1) && numa_syscall_check()) { void *handle = dlopen("libnuma.so.1", RTLD_LAZY); - if (handle != NULL) { + if (handle != nullptr) { set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t, libnuma_dlsym(handle, "numa_node_to_cpus"))); set_numa_node_to_cpus_v2(CAST_TO_FN_PTR(numa_node_to_cpus_v2_func_t, @@ -3052,7 +3052,7 @@ void os::Linux::rebuild_cpu_to_node_map() { int os::Linux::numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) { // use the latest version of numa_node_to_cpus if available - if (_numa_node_to_cpus_v2 != NULL) { + if (_numa_node_to_cpus_v2 != nullptr) { // libnuma bitmask struct struct bitmask { @@ -3064,14 +3064,14 @@ int os::Linux::numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) mask.maskp = (unsigned long *)buffer; mask.size = bufferlen * 8; return _numa_node_to_cpus_v2(node, &mask); - } else if (_numa_node_to_cpus != NULL) { + } else if (_numa_node_to_cpus != nullptr) { return _numa_node_to_cpus(node, buffer, bufferlen); } return -1; } int os::Linux::get_node_by_cpu(int cpu_id) { - if (cpu_to_node() != NULL && cpu_id >= 0 && cpu_id < cpu_to_node()->length()) { + if (cpu_to_node() != nullptr && cpu_id >= 0 && cpu_id < cpu_to_node()->length()) { return cpu_to_node()->at(cpu_id); } return -1; @@ -3168,7 +3168,7 @@ bool os::committed_in_range(address start, size_t size, address& committed_start assert(is_aligned(start, page_sz), "Start address must be page aligned"); assert(is_aligned(size, page_sz), "Size must be page aligned"); - committed_start = NULL; + committed_start = nullptr; int loops = (pages + stripe - 1) / stripe; int committed_pages = 0; @@ -3196,13 +3196,13 @@ bool os::committed_in_range(address start, size_t size, address& committed_start for (int vecIdx = 0; vecIdx < pages_to_query; vecIdx ++) { if ((vec[vecIdx] & 0x01) == 0) { // not committed // End of current contiguous region - if (committed_start != NULL) { + if (committed_start != nullptr) { found_range = true; break; } } else { // committed // Start of region - if (committed_start == NULL) { + if (committed_start == nullptr) { committed_start = loop_base + page_sz * vecIdx; } committed_pages ++; @@ -3212,7 +3212,7 @@ bool os::committed_in_range(address start, size_t size, address& committed_start loop_base += pages_to_query * page_sz; } - if (committed_start != NULL) { + if (committed_start != nullptr) { assert(committed_pages > 0, "Must have committed region"); assert(committed_pages <= int(size / page_sz), "Can not commit more than it has"); assert(committed_start >= start && committed_start < start + size, "Out of range"); @@ -3295,7 +3295,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 Linux mmap(), this -// function returns NULL to indicate failure. +// function returns null to indicate failure. static char* anon_mmap(char* requested_addr, size_t bytes) { // MAP_FIXED is intentionally left out, to leave existing mappings intact. const int flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS; @@ -3305,29 +3305,29 @@ static char* anon_mmap(char* requested_addr, size_t bytes) { // 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; } // Allocate (using mmap, NO_RESERVE, with small pages) at either a given request address -// (req_addr != NULL) or with a given alignment. +// (req_addr != nullptr) or with a given alignment. // - bytes shall be a multiple of alignment. -// - req_addr can be NULL. If not NULL, it must be a multiple of alignment. +// - req_addr can be null. If not null, it must be a multiple of alignment. // - alignment sets the alignment at which memory shall be allocated. // It must be a multiple of allocation granularity. -// Returns address of memory or NULL. If req_addr was not NULL, will only return -// req_addr or NULL. +// Returns address of memory or null. If req_addr was not null, will only return +// req_addr or null. static char* anon_mmap_aligned(char* req_addr, size_t bytes, size_t alignment) { size_t extra_size = bytes; - if (req_addr == NULL && alignment > 0) { + if (req_addr == nullptr && alignment > 0) { extra_size += alignment; } char* start = anon_mmap(req_addr, extra_size); - if (start != NULL) { - if (req_addr != NULL) { + if (start != nullptr) { + if (req_addr != nullptr) { if (start != req_addr) { ::munmap(start, extra_size); - start = NULL; + start = nullptr; } } else { char* const start_aligned = align_up(start, alignment); @@ -3350,7 +3350,7 @@ static int anon_munmap(char * addr, size_t size) { } char* os::pd_reserve_memory(size_t bytes, bool exec) { - return anon_mmap(NULL, bytes); + return anon_mmap(nullptr, bytes); } bool os::pd_release_memory(char* addr, size_t size) { @@ -3378,7 +3378,7 @@ static bool linux_mprotect(char* addr, size_t size, int prot) { #ifdef CAN_SHOW_REGISTERS_ON_ASSERT if (addr != g_assert_poison) #endif - 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; } @@ -3409,7 +3409,7 @@ bool os::unguard_memory(char* addr, size_t size) { bool os::Linux::transparent_huge_pages_sanity_check(bool warn, size_t page_size) { bool result = false; - void *p = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE, + void *p = mmap(nullptr, page_size * 2, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); if (p != MAP_FAILED) { @@ -3437,7 +3437,7 @@ int os::Linux::hugetlbfs_page_size_flag(size_t page_size) { bool os::Linux::hugetlbfs_sanity_check(bool warn, size_t page_size) { // Include the page size flag to ensure we sanity check the correct page size. int flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB | hugetlbfs_page_size_flag(page_size); - void *p = mmap(NULL, page_size, PROT_READ|PROT_WRITE, flags, -1, 0); + void *p = mmap(nullptr, page_size, PROT_READ|PROT_WRITE, flags, -1, 0); if (p != MAP_FAILED) { // Mapping succeeded, sanity check passed. @@ -3452,7 +3452,7 @@ bool os::Linux::hugetlbfs_sanity_check(bool warn, size_t page_size) { page_size_ != (size_t)os::vm_page_size(); page_size_ = _page_sizes.next_smaller(page_size_)) { flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_HUGETLB | hugetlbfs_page_size_flag(page_size_); - p = mmap(NULL, page_size_, PROT_READ|PROT_WRITE, flags, -1, 0); + p = mmap(nullptr, page_size_, PROT_READ|PROT_WRITE, flags, -1, 0); if (p != MAP_FAILED) { // Mapping succeeded, sanity check passed. munmap(p, page_size_); @@ -3491,7 +3491,7 @@ bool os::Linux::shm_hugetlbfs_sanity_check(bool warn, size_t page_size) { return false; } // Managed to create a segment, now delete it. - shmctl(shmid, IPC_RMID, NULL); + shmctl(shmid, IPC_RMID, nullptr); return true; } @@ -3512,7 +3512,7 @@ static void set_coredump_filter(CoredumpFilterBit bit) { FILE *f; long cdm; - if ((f = os::fopen("/proc/self/coredump_filter", "r+")) == NULL) { + if ((f = os::fopen("/proc/self/coredump_filter", "r+")) == nullptr) { return; } @@ -3585,7 +3585,7 @@ static os::PageSizes scan_multiple_page_support() { struct dirent *entry; size_t page_size; - while ((entry = readdir(dir)) != NULL) { + while ((entry = readdir(dir)) != nullptr) { if (entry->d_type == DT_DIR && sscanf(entry->d_name, "hugepages-%zukB", &page_size) == 1) { // The kernel is using kB, hotspot uses bytes @@ -3779,17 +3779,17 @@ static char* shmat_with_alignment(int shmid, size_t bytes, size_t alignment) { if (!is_aligned(alignment, SHMLBA)) { assert(false, "Code below assumes that alignment is at least SHMLBA aligned"); - return NULL; + return nullptr; } // To ensure that we get 'alignment' aligned memory from shmat, // we pre-reserve aligned virtual memory and then attach to that. - char* pre_reserved_addr = anon_mmap_aligned(NULL /* req_addr */, bytes, alignment); - if (pre_reserved_addr == NULL) { + char* pre_reserved_addr = anon_mmap_aligned(nullptr /* req_addr */, bytes, alignment); + if (pre_reserved_addr == nullptr) { // Couldn't pre-reserve aligned memory. shm_warning("Failed to pre-reserve aligned memory for shmat."); - return NULL; + return nullptr; } // SHM_REMAP is needed to allow shmat to map over an existing mapping. @@ -3806,7 +3806,7 @@ static char* shmat_with_alignment(int shmid, size_t bytes, size_t alignment) { // Since we don't know if the kernel unmapped the pre-reserved memory area // we can't unmap it, since that would potentially unmap memory that was // mapped from other threads. - return NULL; + return nullptr; } return addr; @@ -3815,14 +3815,14 @@ static char* shmat_with_alignment(int shmid, size_t bytes, size_t alignment) { static char* shmat_at_address(int shmid, char* req_addr) { if (!is_aligned(req_addr, SHMLBA)) { assert(false, "Requested address needs to be SHMLBA aligned"); - return NULL; + return nullptr; } char* addr = (char*)shmat(shmid, req_addr, 0); if ((intptr_t)addr == -1) { shm_warning_with_errno("Failed to attach shared memory."); - return NULL; + return nullptr; } return addr; @@ -3830,21 +3830,21 @@ static char* shmat_at_address(int shmid, char* req_addr) { static char* shmat_large_pages(int shmid, size_t bytes, size_t alignment, char* req_addr) { // If a req_addr has been provided, we assume that the caller has already aligned the address. - if (req_addr != NULL) { + if (req_addr != nullptr) { assert(is_aligned(req_addr, os::large_page_size()), "Must be divisible by the large page size"); assert(is_aligned(req_addr, alignment), "Must be divisible by given alignment"); return shmat_at_address(shmid, req_addr); } // Since shmid has been setup with SHM_HUGETLB, shmat will automatically - // return large page size aligned memory addresses when req_addr == NULL. + // return large page size aligned memory addresses when req_addr == nullptr. // However, if the alignment is larger than the large page size, we have // to manually ensure that the memory returned is 'alignment' aligned. if (alignment > os::large_page_size()) { assert(is_aligned(alignment, os::large_page_size()), "Must be divisible by the large page size"); return shmat_with_alignment(shmid, bytes, alignment); } else { - return shmat_at_address(shmid, NULL); + return shmat_at_address(shmid, nullptr); } } @@ -3857,7 +3857,7 @@ char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment, assert(is_aligned(req_addr, alignment), "Unaligned address"); if (!is_aligned(bytes, os::large_page_size())) { - return NULL; // Fallback to small pages. + return nullptr; // Fallback to small pages. } // Create a large shared memory region to attach to based on size. @@ -3881,7 +3881,7 @@ char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment, // coalesce into large pages. Try to reserve large pages when // the system is still "fresh". shm_warning_with_errno("Failed to reserve shared memory."); - return NULL; + return nullptr; } // Attach to the region. @@ -3891,7 +3891,7 @@ char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment, // will be deleted when it's detached by shmdt() or when the process // terminates. If shmat() is not successful this will remove the shared // segment immediately. - shmctl(shmid, IPC_RMID, NULL); + shmctl(shmid, IPC_RMID, nullptr); return addr; } @@ -3913,7 +3913,7 @@ bool os::Linux::commit_memory_special(size_t bytes, assert(UseLargePages && UseHugeTLBFS, "Should only get here when HugeTLBFS large pages are used"); assert(is_aligned(bytes, page_size), "Unaligned size"); assert(is_aligned(req_addr, page_size), "Unaligned address"); - assert(req_addr != NULL, "Must have a requested address for special mappings"); + assert(req_addr != nullptr, "Must have a requested address for special mappings"); int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE; int flags = MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED; @@ -3962,8 +3962,8 @@ char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes, // The larger of the two will be used. size_t required_alignment = MAX(page_size, alignment); char* const aligned_start = anon_mmap_aligned(req_addr, bytes, required_alignment); - if (aligned_start == NULL) { - return NULL; + if (aligned_start == nullptr) { + return nullptr; } // First commit using large pages. @@ -3983,7 +3983,7 @@ char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes, // Failed to commit large pages, so we need to unmap the // reminder of the orinal reservation. ::munmap(small_start, small_size); - return NULL; + return nullptr; } // Commit the remaining bytes using small pages. @@ -3992,7 +3992,7 @@ char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes, // Failed to commit the remaining size, need to unmap // the large pages part of the reservation. ::munmap(aligned_start, large_bytes); - return NULL; + return nullptr; } return aligned_start; } @@ -4010,7 +4010,7 @@ char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, size_t page_ addr = os::Linux::reserve_memory_special_huge_tlbfs(bytes, alignment, page_size, req_addr, exec); } - if (addr != NULL) { + if (addr != nullptr) { if (UseNUMAInterleaving) { numa_make_global(addr, bytes); } @@ -4063,8 +4063,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")); } } @@ -4092,12 +4092,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 @@ -4257,7 +4257,7 @@ static void check_pax(void) { #ifndef ZERO size_t size = os::vm_page_size(); - void* p = ::mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + void* p = ::mmap(nullptr, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if (p == MAP_FAILED) { log_debug(os)("os_linux.cpp: check_pax: mmap failed (%s)" , os::strerror(errno)); vm_exit_out_of_memory(size, OOM_MMAP_ERROR, "failed to allocate memory for PaX check."); @@ -4410,7 +4410,7 @@ void os::Linux::numa_init() { * @see JDK-8023956 */ static void workaround_expand_exec_shield_cs_limit() { - assert(os::Linux::initial_thread_stack_bottom() != NULL, "sanity"); + assert(os::Linux::initial_thread_stack_bottom() != nullptr, "sanity"); size_t page_size = os::vm_page_size(); /* @@ -4453,7 +4453,7 @@ static void workaround_expand_exec_shield_cs_limit() { (StackOverflow::stack_guard_zone_size() + page_size)); char* codebuf = os::attempt_reserve_memory_at(hint, page_size); - if (codebuf == NULL) { + if (codebuf == nullptr) { // JDK-8197429: There may be a stack gap of one megabyte between // the limit of the stack and the nearest memory region: this is a // Linux kernel workaround for CVE-2017-1000364. If we failed to @@ -4462,7 +4462,7 @@ static void workaround_expand_exec_shield_cs_limit() { codebuf = os::attempt_reserve_memory_at(hint, page_size); } - if ((codebuf == NULL) || (!os::commit_memory(codebuf, page_size, true))) { + if ((codebuf == nullptr) || (!os::commit_memory(codebuf, page_size, true))) { return; // No matter, we tried, best effort. } @@ -4631,7 +4631,7 @@ static int get_active_processor_count() { UseCpuAllocPath ? "(forced) " : "", configured_cpus); cpus_p = CPU_ALLOC(configured_cpus); - if (cpus_p != NULL) { + if (cpus_p != nullptr) { cpus_size = CPU_ALLOC_SIZE(configured_cpus); // zero it just to be safe CPU_ZERO_S(cpus_size, cpus_p); @@ -4782,18 +4782,18 @@ bool os::find(address addr, outputStream* st) { memset(&dlinfo, 0, sizeof(dlinfo)); if (dladdr(addr, &dlinfo) != 0) { st->print(PTR_FORMAT ": ", p2i(addr)); - if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) { + if (dlinfo.dli_sname != nullptr && dlinfo.dli_saddr != nullptr) { st->print("%s+" PTR_FORMAT, dlinfo.dli_sname, p2i(addr) - p2i(dlinfo.dli_saddr)); - } else if (dlinfo.dli_fbase != NULL) { + } else if (dlinfo.dli_fbase != nullptr) { st->print("<offset " PTR_FORMAT ">", p2i(addr) - p2i(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 " PTR_FORMAT, p2i(dlinfo.dli_fbase)); } st->cr(); @@ -4942,14 +4942,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; } @@ -5043,7 +5043,7 @@ static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { snprintf(proc_name, 64, "/proc/self/task/%d/stat", tid); fp = os::fopen(proc_name, "r"); - if (fp == NULL) return -1; + if (fp == nullptr) return -1; statlen = fread(stat, 1, 2047, fp); stat[statlen] = '\0'; fclose(fp); @@ -5055,7 +5055,7 @@ static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { // We don't really need to know the command string, just find the last // occurrence of ")" and then start parsing from there. See bug 4726580. s = strrchr(stat, ')'); - if (s == NULL) return -1; + if (s == nullptr) return -1; // Skip blank chars do { s++; } while (s && isspace(*s)); @@ -5127,11 +5127,11 @@ int os::get_core_path(char* buffer, size_t bufferSize) { // only if the pattern doesn't start with "|", and we support only one %p in // the pattern. char *pid_pos = strstr(core_pattern, "%p"); - const char* tail = (pid_pos != NULL) ? (pid_pos + 2) : ""; // skip over the "%p" + const char* tail = (pid_pos != nullptr) ? (pid_pos + 2) : ""; // skip over the "%p" int written; if (core_pattern[0] == '/') { - if (pid_pos != NULL) { + if (pid_pos != nullptr) { *pid_pos = '\0'; written = jio_snprintf(buffer, bufferSize, "%s%d%s", core_pattern, current_process_id(), tail); @@ -5142,7 +5142,7 @@ int os::get_core_path(char* buffer, size_t bufferSize) { char cwd[PATH_MAX]; const char* p = get_current_directory(cwd, PATH_MAX); - if (p == NULL) { + if (p == nullptr) { return -1; } @@ -5150,7 +5150,7 @@ int os::get_core_path(char* buffer, size_t bufferSize) { written = jio_snprintf(buffer, bufferSize, "\"%s\" (or dumping to %s/core.%d)", &core_pattern[1], p, current_process_id()); - } else if (pid_pos != NULL) { + } else if (pid_pos != nullptr) { *pid_pos = '\0'; written = jio_snprintf(buffer, bufferSize, "%s/%s%d%s", p, core_pattern, current_process_id(), tail); @@ -5163,7 +5163,7 @@ int os::get_core_path(char* buffer, size_t bufferSize) { return -1; } - if (((size_t)written < bufferSize) && (pid_pos == NULL) && (core_pattern[0] != '|')) { + if (((size_t)written < bufferSize) && (pid_pos == nullptr) && (core_pattern[0] != '|')) { int core_uses_pid_file = ::open("/proc/sys/kernel/core_uses_pid", O_RDONLY); if (core_uses_pid_file != -1) { @@ -5329,7 +5329,7 @@ void os::print_memory_mappings(char* addr, size_t bytes, outputStream* st) { unsigned long long end = start + bytes; FILE* f = os::fopen("/proc/self/maps", "r"); int num_found = 0; - if (f != NULL) { + if (f != nullptr) { st->print_cr("Range [%llx-%llx) contains: ", start, end); char line[512]; while(fgets(line, sizeof(line), f) == line) { diff --git a/src/hotspot/os/linux/os_linux.hpp b/src/hotspot/os/linux/os_linux.hpp index b6670ec5152..045fca04c44 100644 --- a/src/hotspot/os/linux/os_linux.hpp +++ b/src/hotspot/os/linux/os_linux.hpp @@ -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 @@ -252,8 +252,8 @@ class os::Linux { static void set_numa_move_pages(numa_move_pages_func_t func) { _numa_move_pages = func; } static void set_numa_set_preferred(numa_set_preferred_func_t func) { _numa_set_preferred = func; } static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; } - static void set_numa_all_nodes_ptr(struct bitmask **ptr) { _numa_all_nodes_ptr = (ptr == NULL ? NULL : *ptr); } - static void set_numa_nodes_ptr(struct bitmask **ptr) { _numa_nodes_ptr = (ptr == NULL ? NULL : *ptr); } + static void set_numa_all_nodes_ptr(struct bitmask **ptr) { _numa_all_nodes_ptr = (ptr == nullptr ? nullptr : *ptr); } + static void set_numa_nodes_ptr(struct bitmask **ptr) { _numa_nodes_ptr = (ptr == nullptr ? nullptr : *ptr); } static void set_numa_interleave_bitmask(struct bitmask* ptr) { _numa_interleave_bitmask = ptr ; } static void set_numa_membind_bitmask(struct bitmask* ptr) { _numa_membind_bitmask = ptr ; } static int sched_getcpu_syscall(void); @@ -266,15 +266,15 @@ class os::Linux { static NumaAllocationPolicy _current_numa_policy; 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); - static int numa_max_node() { return _numa_max_node != NULL ? _numa_max_node() : -1; } + static int numa_max_node() { return _numa_max_node != nullptr ? _numa_max_node() : -1; } static int numa_num_configured_nodes() { - return _numa_num_configured_nodes != NULL ? _numa_num_configured_nodes() : -1; + return _numa_num_configured_nodes != nullptr ? _numa_num_configured_nodes() : -1; } - static int numa_available() { return _numa_available != NULL ? _numa_available() : -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 bool is_running_in_interleave_mode() { @@ -296,46 +296,46 @@ class os::Linux { static void numa_interleave_memory(void *start, size_t size) { // Prefer v2 API - if (_numa_interleave_memory_v2 != NULL) { + if (_numa_interleave_memory_v2 != nullptr) { if (is_running_in_interleave_mode()) { _numa_interleave_memory_v2(start, size, _numa_interleave_bitmask); - } else if (_numa_membind_bitmask != NULL) { + } else if (_numa_membind_bitmask != nullptr) { _numa_interleave_memory_v2(start, size, _numa_membind_bitmask); } - } else if (_numa_interleave_memory != NULL) { + } else if (_numa_interleave_memory != nullptr) { _numa_interleave_memory(start, size, _numa_all_nodes); } } static void numa_set_preferred(int node) { - if (_numa_set_preferred != NULL) { + if (_numa_set_preferred != nullptr) { _numa_set_preferred(node); } } static void numa_set_bind_policy(int policy) { - if (_numa_set_bind_policy != NULL) { + if (_numa_set_bind_policy != nullptr) { _numa_set_bind_policy(policy); } } static int numa_distance(int node1, int node2) { - return _numa_distance != NULL ? _numa_distance(node1, node2) : -1; + return _numa_distance != nullptr ? _numa_distance(node1, node2) : -1; } static long numa_move_pages(int pid, unsigned long count, void **pages, const int *nodes, int *status, int flags) { - return _numa_move_pages != NULL ? _numa_move_pages(pid, count, pages, nodes, status, flags) : -1; + return _numa_move_pages != nullptr ? _numa_move_pages(pid, count, pages, nodes, status, flags) : -1; } static int get_node_by_cpu(int cpu_id); static int get_existing_num_nodes(); // Check if numa node is configured (non-zero memory node). static bool is_node_in_configured_nodes(unsigned int n) { - if (_numa_bitmask_isbitset != NULL && _numa_all_nodes_ptr != NULL) { + if (_numa_bitmask_isbitset != nullptr && _numa_all_nodes_ptr != nullptr) { return _numa_bitmask_isbitset(_numa_all_nodes_ptr, n); } else return false; } // Check if numa node exists in the system (including zero memory nodes). static bool is_node_in_existing_nodes(unsigned int n) { - if (_numa_bitmask_isbitset != NULL && _numa_nodes_ptr != NULL) { + if (_numa_bitmask_isbitset != nullptr && _numa_nodes_ptr != nullptr) { return _numa_bitmask_isbitset(_numa_nodes_ptr, n); - } else if (_numa_bitmask_isbitset != NULL && _numa_all_nodes_ptr != NULL) { + } else if (_numa_bitmask_isbitset != nullptr && _numa_all_nodes_ptr != nullptr) { // Not all libnuma API v2 implement numa_nodes_ptr, so it's not possible // to trust the API version for checking its absence. On the other hand, // numa_nodes_ptr found in libnuma 2.0.9 and above is the only way to get @@ -352,11 +352,11 @@ class os::Linux { } // Check if node is in bound node set. static bool is_node_in_bound_nodes(int node) { - if (_numa_bitmask_isbitset != NULL) { + if (_numa_bitmask_isbitset != nullptr) { if (is_running_in_interleave_mode()) { return _numa_bitmask_isbitset(_numa_interleave_bitmask, node); } else { - return _numa_membind_bitmask != NULL ? _numa_bitmask_isbitset(_numa_membind_bitmask, node) : false; + return _numa_membind_bitmask != nullptr ? _numa_bitmask_isbitset(_numa_membind_bitmask, node) : false; } } return false; @@ -368,7 +368,7 @@ class os::Linux { unsigned int node = 0; unsigned int highest_node_number = 0; - if (_numa_membind_bitmask != NULL && _numa_max_node != NULL && _numa_bitmask_isbitset != NULL) { + if (_numa_membind_bitmask != nullptr && _numa_max_node != nullptr && _numa_bitmask_isbitset != nullptr) { highest_node_number = _numa_max_node(); } else { return false; diff --git a/src/hotspot/os/linux/os_perf_linux.cpp b/src/hotspot/os/linux/os_perf_linux.cpp index 851434fb324..ff416d47eb0 100644 --- a/src/hotspot/os/linux/os_perf_linux.cpp +++ b/src/hotspot/os/linux/os_perf_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022, 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 @@ -235,7 +235,7 @@ static int SCANF_ARGS(2, 0) vread_statdata(const char* procfile, _SCANFMT_ const int n; char buf[2048]; - if ((f = os::fopen(procfile, "r")) == NULL) { + if ((f = os::fopen(procfile, "r")) == nullptr) { return -1; } @@ -244,7 +244,7 @@ static int SCANF_ARGS(2, 0) vread_statdata(const char* procfile, _SCANFMT_ const buf[n-1] = '\0'; /** skip through pid and exec name. */ - if ((tmp = strrchr(buf, ')')) != NULL) { + if ((tmp = strrchr(buf, ')')) != nullptr) { // skip the ')' and the following space // but check that buffer is long enough tmp += 2; @@ -272,7 +272,7 @@ static int SCANF_ARGS(2, 3) read_statdata(const char* procfile, _SCANFMT_ const static FILE* open_statfile(void) { FILE *f; - if ((f = os::fopen("/proc/stat", "r")) == NULL) { + if ((f = os::fopen("/proc/stat", "r")) == nullptr) { static int haveWarned = 0; if (!haveWarned) { haveWarned = 1; @@ -290,7 +290,7 @@ static int get_systemtype(void) { } // Check whether we have a task subdirectory - if ((taskDir = opendir("/proc/self/task")) == NULL) { + if ((taskDir = opendir("/proc/self/task")) == nullptr) { procEntriesType = UNDETECTABLE; } else { // The task subdirectory exists; we're on a Linux >= 2.6 system @@ -400,13 +400,13 @@ static int SCANF_ARGS(1, 2) parse_stat(_SCANFMT_ const char* fmt, ...) { va_start(args, fmt); - if ((f = open_statfile()) == NULL) { + if ((f = open_statfile()) == nullptr) { va_end(args); return OS_ERR; } for (;;) { char line[80]; - if (fgets(line, sizeof(line), f) != NULL) { + if (fgets(line, sizeof(line), f) != nullptr) { if (vsscanf(line, fmt, args) == 1) { fclose(f); va_end(args); @@ -515,7 +515,7 @@ class CPUPerformanceInterface::CPUPerformance : public CHeapObj<mtInternal> { CPUPerformanceInterface::CPUPerformance::CPUPerformance() { _counters.nProcs = os::active_processor_count(); - _counters.cpus = NULL; + _counters.cpus = nullptr; } bool CPUPerformanceInterface::CPUPerformance::initialize() { @@ -542,7 +542,7 @@ bool CPUPerformanceInterface::CPUPerformance::initialize() { } CPUPerformanceInterface::CPUPerformance::~CPUPerformance() { - if (_counters.cpus != NULL) { + if (_counters.cpus != nullptr) { FREE_C_HEAP_ARRAY(char, _counters.cpus); } } @@ -573,9 +573,9 @@ int CPUPerformanceInterface::CPUPerformance::cpu_load_total_process(double* cpu_ int CPUPerformanceInterface::CPUPerformance::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) { double u, s, t; - assert(pjvmUserLoad != NULL, "pjvmUserLoad not inited"); - assert(pjvmKernelLoad != NULL, "pjvmKernelLoad not inited"); - assert(psystemTotalLoad != NULL, "psystemTotalLoad not inited"); + assert(pjvmUserLoad != nullptr, "pjvmUserLoad not inited"); + assert(pjvmKernelLoad != nullptr, "pjvmKernelLoad not inited"); + assert(psystemTotalLoad != nullptr, "psystemTotalLoad not inited"); u = get_cpu_load(-1, &_counters, &s, CPU_LOAD_VM_ONLY); if (u < 0) { @@ -603,7 +603,7 @@ int CPUPerformanceInterface::CPUPerformance::context_switch_rate(double* rate) { } CPUPerformanceInterface::CPUPerformanceInterface() { - _impl = NULL; + _impl = nullptr; } bool CPUPerformanceInterface::initialize() { @@ -612,7 +612,7 @@ bool CPUPerformanceInterface::initialize() { } CPUPerformanceInterface::~CPUPerformanceInterface() { - if (_impl != NULL) { + if (_impl != nullptr) { delete _impl; } } @@ -685,7 +685,7 @@ bool SystemProcessInterface::SystemProcesses::ProcessIterator::is_dir(const char } int SystemProcessInterface::SystemProcesses::ProcessIterator::fsize(const char* name, uint64_t& size) const { - assert(name != NULL, "name pointer is NULL!"); + assert(name != nullptr, "name pointer is null!"); size = 0; struct stat fbuf; @@ -723,15 +723,15 @@ 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 = os::fopen(buffer, "r")) != NULL) { - if (fgets(buffer, PATH_MAX, fp) != NULL) { + if ((fp = os::fopen(buffer, "r")) != nullptr) { + if (fgets(buffer, PATH_MAX, fp) != nullptr) { char* start, *end; // exe-name is between the first pair of ( and ) start = strchr(buffer, '('); - if (start != NULL && start[1] != '\0') { + if (start != nullptr && start[1] != '\0') { start++; end = strrchr(start, ')'); - if (end != NULL) { + if (end != nullptr) { size_t len; len = MIN2<size_t>(end - start, sizeof(_exeName) - 1); memcpy(_exeName, start, len); @@ -747,11 +747,11 @@ void SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_name() { char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_cmdline() { FILE* fp; char buffer[PATH_MAX]; - char* cmdline = NULL; + char* cmdline = nullptr; jio_snprintf(buffer, PATH_MAX, "/proc/%s/cmdline", _entry->d_name); buffer[PATH_MAX - 1] = '\0'; - if ((fp = os::fopen(buffer, "r")) != NULL) { + if ((fp = os::fopen(buffer, "r")) != nullptr) { size_t size = 0; char dummy; @@ -790,10 +790,10 @@ char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_exe_path() { } char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const { - if (str != NULL) { + if (str != nullptr) { return os::strdup_check_oom(str, mtInternal); } - return NULL; + return nullptr; } int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProcess* process_info) { @@ -806,13 +806,13 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProc get_exe_name(); process_info->set_name(allocate_string(_exeName)); - if (get_exe_path() != NULL) { + if (get_exe_path() != nullptr) { process_info->set_path(allocate_string(_exePath)); } - char* cmdline = NULL; + char* cmdline = nullptr; cmdline = get_cmdline(); - if (cmdline != NULL) { + if (cmdline != nullptr) { process_info->set_command_line(allocate_string(cmdline)); FREE_C_HEAP_ARRAY(char, cmdline); } @@ -827,7 +827,7 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() { do { _entry = os::readdir(_dir); - if (_entry == NULL) { + if (_entry == nullptr) { // Error or reached end. Could use errno to distinguish those cases. _valid = false; return OS_ERR; @@ -839,14 +839,14 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() { } SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() { - _dir = NULL; - _entry = NULL; + _dir = nullptr; + _entry = nullptr; _valid = false; } bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() { _dir = os::opendir("/proc"); - _entry = NULL; + _entry = nullptr; _valid = true; next_process(); @@ -854,13 +854,13 @@ bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() { } SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() { - if (_dir != NULL) { + if (_dir != nullptr) { os::closedir(_dir); } } SystemProcessInterface::SystemProcesses::SystemProcesses() { - _iterator = NULL; + _iterator = nullptr; } bool SystemProcessInterface::SystemProcesses::initialize() { @@ -869,26 +869,26 @@ bool SystemProcessInterface::SystemProcesses::initialize() { } SystemProcessInterface::SystemProcesses::~SystemProcesses() { - if (_iterator != NULL) { + if (_iterator != nullptr) { delete _iterator; } } 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 pointers is NULL!"); - assert(_iterator != NULL, "iterator is NULL!"); + assert(system_processes != nullptr, "system_processes pointer is null!"); + assert(no_of_sys_processes != nullptr, "system_processes counter pointers is null!"); + assert(_iterator != nullptr, "iterator is null!"); // initialize pointers *no_of_sys_processes = 0; - *system_processes = NULL; + *system_processes = nullptr; while (_iterator->is_valid()) { SystemProcess* tmp = new SystemProcess(); _iterator->current(tmp); //if already existing head - if (*system_processes != NULL) { + if (*system_processes != nullptr) { //move "first to second" tmp->set_next(*system_processes); } @@ -907,7 +907,7 @@ int SystemProcessInterface::system_processes(SystemProcess** system_procs, int* } SystemProcessInterface::SystemProcessInterface() { - _impl = NULL; + _impl = nullptr; } bool SystemProcessInterface::initialize() { @@ -916,13 +916,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() { @@ -937,23 +937,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 (_cpu_info == NULL) { + if (_cpu_info == nullptr) { return OS_ERR; } @@ -1000,7 +1000,7 @@ int64_t NetworkPerformanceInterface::NetworkPerformance::read_counter(const char } buf[num_bytes] = '\0'; - int64_t value = strtoll(buf, NULL, 10); + int64_t value = strtoll(buf, nullptr, 10); return value; } @@ -1014,9 +1014,9 @@ int NetworkPerformanceInterface::NetworkPerformance::network_utilization(Network return OS_ERR; } - NetworkInterface* ret = NULL; - for (cur_address = addresses; cur_address != NULL; cur_address = cur_address->ifa_next) { - if ((cur_address->ifa_addr == NULL) || (cur_address->ifa_addr->sa_family != AF_PACKET)) { + NetworkInterface* ret = nullptr; + for (cur_address = addresses; cur_address != nullptr; cur_address = cur_address->ifa_next) { + if ((cur_address->ifa_addr == nullptr) || (cur_address->ifa_addr->sa_family != AF_PACKET)) { continue; } @@ -1034,11 +1034,11 @@ int NetworkPerformanceInterface::NetworkPerformance::network_utilization(Network } NetworkPerformanceInterface::NetworkPerformanceInterface() { - _impl = NULL; + _impl = nullptr; } NetworkPerformanceInterface::~NetworkPerformanceInterface() { - if (_impl != NULL) { + if (_impl != nullptr) { delete _impl; } } diff --git a/src/hotspot/os/linux/trimCHeapDCmd.hpp b/src/hotspot/os/linux/trimCHeapDCmd.hpp index 4c5b5cc2219..32a49798ea8 100644 --- a/src/hotspot/os/linux/trimCHeapDCmd.hpp +++ b/src/hotspot/os/linux/trimCHeapDCmd.hpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2021 SAP SE. All rights reserved. - * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 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 @@ -43,7 +43,7 @@ public: return "Low"; } static const JavaPermission permission() { - JavaPermission p = { "java.lang.management.ManagementPermission", "control", NULL }; + JavaPermission p = { "java.lang.management.ManagementPermission", "control", nullptr }; return p; } virtual void execute(DCmdSource source, TRAPS); diff --git a/src/hotspot/os/linux/waitBarrier_linux.cpp b/src/hotspot/os/linux/waitBarrier_linux.cpp index 4c4db78bd40..0399f7b7a44 100644 --- a/src/hotspot/os/linux/waitBarrier_linux.cpp +++ b/src/hotspot/os/linux/waitBarrier_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 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 @@ -46,7 +46,7 @@ #endif static int futex(volatile int *addr, int futex_op, int op_arg) { - return syscall(SYS_futex, addr, futex_op, op_arg, NULL, NULL, 0); + return syscall(SYS_futex, addr, futex_op, op_arg, nullptr, nullptr, 0); } void LinuxWaitBarrier::arm(int barrier_tag) {