From c91cd2814baa8dee2af8af0fecf9185d4a0a44cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sj=C3=B6len?= Date: Fri, 17 Feb 2023 09:41:12 +0000 Subject: [PATCH] 8301481: Replace NULL with nullptr in os/windows Reviewed-by: coleenp, dholmes --- .../os/windows/attachListener_windows.cpp | 44 +- .../os/windows/gc/z/zMapper_windows.cpp | 24 +- .../gc/z/zPhysicalMemoryBacking_windows.cpp | 4 +- .../os/windows/gc/z/zSyscall_windows.cpp | 12 +- .../os/windows/gc/z/zUtils_windows.cpp | 4 +- .../windows/gc/z/zVirtualMemory_windows.cpp | 8 +- src/hotspot/os/windows/iphlp_interface.cpp | 26 +- src/hotspot/os/windows/osThread_windows.cpp | 10 +- src/hotspot/os/windows/os_perf_windows.cpp | 312 ++++++------ src/hotspot/os/windows/os_windows.cpp | 478 +++++++++--------- src/hotspot/os/windows/park_windows.hpp | 10 +- src/hotspot/os/windows/pdh_interface.cpp | 82 +-- src/hotspot/os/windows/perfMemory_windows.cpp | 174 +++---- src/hotspot/os/windows/semaphore_windows.cpp | 8 +- src/hotspot/os/windows/symbolengine.cpp | 34 +- src/hotspot/os/windows/symbolengine.hpp | 6 +- .../windows/threadCrashProtection_windows.cpp | 10 +- .../windows/threadCrashProtection_windows.hpp | 4 +- .../os/windows/threadCritical_windows.cpp | 8 +- src/hotspot/os/windows/vmError_windows.cpp | 6 +- src/hotspot/os/windows/windbghelp.cpp | 40 +- 21 files changed, 652 insertions(+), 652 deletions(-) diff --git a/src/hotspot/os/windows/attachListener_windows.cpp b/src/hotspot/os/windows/attachListener_windows.cpp index 8543c784ee4..8cd4d8d6715 100644 --- a/src/hotspot/os/windows/attachListener_windows.cpp +++ b/src/hotspot/os/windows/attachListener_windows.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 @@ -150,7 +150,7 @@ class Win32AttachOperation: public AttachOperation { // noarg constructor as operation is preallocated Win32AttachOperation() : AttachOperation("") { set_pipe(""); - set_next(NULL); + set_next(nullptr); } public: @@ -160,15 +160,15 @@ class Win32AttachOperation: public AttachOperation { // Preallocate the maximum number of operations that can be enqueued. int Win32AttachListener::init() { - _mutex = (void*)::CreateMutex(NULL, FALSE, NULL); - guarantee(_mutex != (HANDLE)NULL, "mutex creation failed"); + _mutex = (void*)::CreateMutex(nullptr, FALSE, nullptr); + guarantee(_mutex != (HANDLE)nullptr, "mutex creation failed"); - _enqueued_ops_semaphore = ::CreateSemaphore(NULL, 0, max_enqueued_operations, NULL); - guarantee(_enqueued_ops_semaphore != (HANDLE)NULL, "semaphore creation failed"); + _enqueued_ops_semaphore = ::CreateSemaphore(nullptr, 0, max_enqueued_operations, nullptr); + guarantee(_enqueued_ops_semaphore != (HANDLE)nullptr, "semaphore creation failed"); - set_head(NULL); - set_tail(NULL); - set_available(NULL); + set_head(nullptr); + set_tail(nullptr); + set_available(nullptr); for (int i=0; inext()); // add to end (tail) of list - op->set_next(NULL); - if (tail() == NULL) { + op->set_next(nullptr); + if (tail() == nullptr) { set_head(op); } else { tail()->set_next(op); @@ -233,12 +233,12 @@ int Win32AttachListener::enqueue(char* cmd, char* arg0, char* arg1, char* arg2, // Side effect: Semaphore will be signaled and will release // any blocking waiters (i.e. the AttachListener thread). BOOL not_exceeding_semaphore_maximum_count = - ::ReleaseSemaphore(enqueued_ops_semaphore(), 1, NULL); + ::ReleaseSemaphore(enqueued_ops_semaphore(), 1, nullptr); guarantee(not_exceeding_semaphore_maximum_count, "invariant"); } ::ReleaseMutex(mutex()); - return (op != NULL) ? 0 : ATTACH_ERROR_RESOURCE; + return (op != nullptr) ? 0 : ATTACH_ERROR_RESOURCE; } @@ -254,15 +254,15 @@ Win32AttachOperation* Win32AttachListener::dequeue() { guarantee(res == WAIT_OBJECT_0, "wait failed"); Win32AttachOperation* op = head(); - if (op != NULL) { + if (op != nullptr) { set_head(op->next()); - if (head() == NULL) { // list is empty - set_tail(NULL); + if (head() == nullptr) { // list is empty + set_tail(nullptr); } } ::ReleaseMutex(mutex()); - if (op != NULL) { + if (op != nullptr) { return op; } } @@ -274,10 +274,10 @@ HANDLE Win32AttachOperation::open_pipe() { HANDLE hPipe = ::CreateFile( pipe(), // pipe name GENERIC_WRITE, // write only 0, // no sharing - NULL, // default security attributes + nullptr, // default security attributes OPEN_EXISTING, // opens existing pipe 0, // default attributes - NULL); // no template file + nullptr); // no template file return hPipe; } @@ -290,7 +290,7 @@ BOOL Win32AttachOperation::write_pipe(HANDLE hPipe, char* buf, int len) { (LPCVOID)buf, // message (DWORD)len, // message length &nwrote, // bytes written - NULL); // not overlapped + nullptr); // not overlapped if (!fSuccess) { return fSuccess; } @@ -392,7 +392,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/windows/gc/z/zMapper_windows.cpp b/src/hotspot/os/windows/gc/z/zMapper_windows.cpp index 94fe83c10b4..95a2dc07bae 100644 --- a/src/hotspot/os/windows/gc/z/zMapper_windows.cpp +++ b/src/hotspot/os/windows/gc/z/zMapper_windows.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 @@ -66,7 +66,7 @@ uintptr_t ZMapper::reserve(uintptr_t addr, size_t size) { size, // Size MEM_RESERVE | MEM_RESERVE_PLACEHOLDER, // AllocationType PAGE_NOACCESS, // PageProtection - NULL, // ExtendedParameters + nullptr, // ExtendedParameters 0 // ParameterCount ); @@ -101,11 +101,11 @@ HANDLE ZMapper::create_paging_file_mapping(size_t size) { HANDLE const res = ZSyscall::CreateFileMappingW( INVALID_HANDLE_VALUE, // hFile - NULL, // lpFileMappingAttribute + nullptr, // lpFileMappingAttribute PAGE_READWRITE | SEC_RESERVE, // flProtect size >> 32, // dwMaximumSizeHigh size & 0xFFFFFFFF, // dwMaximumSizeLow - NULL // lpName + nullptr // lpName ); // Caller responsible for error handling @@ -133,12 +133,12 @@ uintptr_t ZMapper::map_view_no_placeholder(HANDLE file_handle, uintptr_t file_of void* const res = ZSyscall::MapViewOfFile3( file_handle, // FileMapping GetCurrentProcess(), // ProcessHandle - NULL, // BaseAddress + nullptr, // BaseAddress file_offset, // Offset size, // ViewSize 0, // AllocationType PAGE_NOACCESS, // PageProtection - NULL, // ExtendedParameters + nullptr, // ExtendedParameters 0 // ParameterCount ); @@ -165,7 +165,7 @@ uintptr_t ZMapper::commit(uintptr_t addr, size_t size) { size, // Size MEM_COMMIT, // AllocationType PAGE_NOACCESS, // PageProtection - NULL, // ExtendedParameters + nullptr, // ExtendedParameters 0 // ParameterCount ); @@ -206,17 +206,17 @@ HANDLE ZMapper::create_shared_awe_section() { HANDLE section = ZSyscall::CreateFileMapping2( INVALID_HANDLE_VALUE, // File - NULL, // SecurityAttributes + nullptr, // SecurityAttributes SECTION_MAP_READ | SECTION_MAP_WRITE, // DesiredAccess PAGE_READWRITE, // PageProtection SEC_RESERVE | SEC_LARGE_PAGES, // AllocationAttributes 0, // MaximumSize - NULL, // Name + nullptr, // Name ¶meter, // ExtendedParameters 1 // ParameterCount ); - if (section == NULL) { + if (section == nullptr) { fatal("Could not create shared AWE section (%d)", GetLastError()); } @@ -288,11 +288,11 @@ void ZMapper::map_view_replace_placeholder(HANDLE file_handle, uintptr_t file_of size, // ViewSize MEM_REPLACE_PLACEHOLDER, // AllocationType PAGE_READWRITE, // PageProtection - NULL, // ExtendedParameters + nullptr, // ExtendedParameters 0 // ParameterCount ); - if (res == NULL) { + if (res == nullptr) { fatal_error("Failed to map memory", addr, size); } } diff --git a/src/hotspot/os/windows/gc/z/zPhysicalMemoryBacking_windows.cpp b/src/hotspot/os/windows/gc/z/zPhysicalMemoryBacking_windows.cpp index 90c487a37e0..fc7105ad8a3 100644 --- a/src/hotspot/os/windows/gc/z/zPhysicalMemoryBacking_windows.cpp +++ b/src/hotspot/os/windows/gc/z/zPhysicalMemoryBacking_windows.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 @@ -195,7 +195,7 @@ public: void unmap(uintptr_t addr, size_t size) const { const size_t npages = size >> ZGranuleSizeShift; - const bool res = MapUserPhysicalPages((char*)addr, npages, NULL); + const bool res = MapUserPhysicalPages((char*)addr, npages, nullptr); if (!res) { fatal("Failed to unmap view " PTR_FORMAT " " SIZE_FORMAT "M (%d)", addr, size / M, GetLastError()); diff --git a/src/hotspot/os/windows/gc/z/zSyscall_windows.cpp b/src/hotspot/os/windows/gc/z/zSyscall_windows.cpp index 7fcc150602e..68ebee5e655 100644 --- a/src/hotspot/os/windows/gc/z/zSyscall_windows.cpp +++ b/src/hotspot/os/windows/gc/z/zSyscall_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 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 @@ -38,7 +38,7 @@ static void* lookup_kernelbase_library() { const char* const name = "KernelBase"; char ebuf[1024]; void* const handle = os::dll_load(name, ebuf, sizeof(ebuf)); - if (handle == NULL) { + if (handle == nullptr) { log_error_p(gc)("Failed to load library: %s", name); } return handle; @@ -46,14 +46,14 @@ static void* lookup_kernelbase_library() { static void* lookup_kernelbase_symbol(const char* name) { static void* const handle = lookup_kernelbase_library(); - if (handle == NULL) { - return NULL; + if (handle == nullptr) { + return nullptr; } return os::dll_lookup(handle, name); } static bool has_kernelbase_symbol(const char* name) { - return lookup_kernelbase_symbol(name) != NULL; + return lookup_kernelbase_symbol(name) != nullptr; } template @@ -64,7 +64,7 @@ static void install_kernelbase_symbol(Fn*& fn, const char* name) { template static void install_kernelbase_1803_symbol_or_exit(Fn*& fn, const char* name) { install_kernelbase_symbol(fn, name); - if (fn == NULL) { + if (fn == nullptr) { log_error_p(gc)("Failed to lookup symbol: %s", name); vm_exit_during_initialization("ZGC requires Windows version 1803 or later"); } diff --git a/src/hotspot/os/windows/gc/z/zUtils_windows.cpp b/src/hotspot/os/windows/gc/z/zUtils_windows.cpp index 633727b6f73..29f7f55e2d1 100644 --- a/src/hotspot/os/windows/gc/z/zUtils_windows.cpp +++ b/src/hotspot/os/windows/gc/z/zUtils_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 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 @@ -30,7 +30,7 @@ uintptr_t ZUtils::alloc_aligned(size_t alignment, size_t size) { void* const res = _aligned_malloc(size, alignment); - if (res == NULL) { + if (res == nullptr) { fatal("_aligned_malloc failed"); } diff --git a/src/hotspot/os/windows/gc/z/zVirtualMemory_windows.cpp b/src/hotspot/os/windows/gc/z/zVirtualMemory_windows.cpp index df106a7881e..de31b49d940 100644 --- a/src/hotspot/os/windows/gc/z/zVirtualMemory_windows.cpp +++ b/src/hotspot/os/windows/gc/z/zVirtualMemory_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 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 @@ -139,7 +139,7 @@ private: virtual bool reserve(uintptr_t addr, size_t size) { const uintptr_t res = ZMapper::reserve(addr, size); - assert(res == addr || res == NULL, "Should not reserve other memory than requested"); + assert(res == addr || res == 0, "Should not reserve other memory than requested"); return res == addr; } @@ -162,7 +162,7 @@ private: virtual bool reserve(uintptr_t addr, size_t size) { const uintptr_t res = ZMapper::reserve_for_shared_awe(ZAWESection, addr, size); - assert(res == addr || res == NULL, "Should not reserve other memory than requested"); + assert(res == addr || res == 0, "Should not reserve other memory than requested"); return res == addr; } @@ -171,7 +171,7 @@ private: } }; -static ZVirtualMemoryManagerImpl* _impl = NULL; +static ZVirtualMemoryManagerImpl* _impl = nullptr; void ZVirtualMemoryManager::pd_initialize_before_reserve() { if (ZLargePages::is_enabled()) { diff --git a/src/hotspot/os/windows/iphlp_interface.cpp b/src/hotspot/os/windows/iphlp_interface.cpp index 0f55ee17b23..0d6a08b0bd0 100644 --- a/src/hotspot/os/windows/iphlp_interface.cpp +++ b/src/hotspot/os/windows/iphlp_interface.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 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 @@ -32,18 +32,18 @@ typedef DWORD(WINAPI *GetIfTable2_Fn)(PMIB_IF_TABLE2*); typedef DWORD(WINAPI *FreeMibTable_Fn)(PVOID); // IPHLP statics -GetIfTable2_Fn IphlpDll::_GetIfTable2 = NULL; -FreeMibTable_Fn IphlpDll::_FreeMibTable = NULL; +GetIfTable2_Fn IphlpDll::_GetIfTable2 = nullptr; +FreeMibTable_Fn IphlpDll::_FreeMibTable = nullptr; LONG IphlpDll::_critical_section = 0; LONG IphlpDll::_initialized = 0; LONG IphlpDll::_iphlp_reference_count = 0; -HMODULE IphlpDll::_hModule = NULL; +HMODULE IphlpDll::_hModule = nullptr; void IphlpDll::initialize(void) { - _hModule = os::win32::load_Windows_dll("iphlpapi.dll", NULL, 0); + _hModule = os::win32::load_Windows_dll("iphlpapi.dll", nullptr, 0); - if (NULL == _hModule) { + if (nullptr == _hModule) { return; } @@ -60,12 +60,12 @@ bool IphlpDll::IphlpDetach(void) { BOOL ret = false; if (1 == prev_ref_count) { - if (_initialized && _hModule != NULL) { + if (_initialized && _hModule != nullptr) { ret = FreeLibrary(_hModule); if (ret) { - _hModule = NULL; - _GetIfTable2 = NULL; - _FreeMibTable = NULL; + _hModule = nullptr; + _GetIfTable2 = nullptr; + _FreeMibTable = nullptr; InterlockedExchange(&_initialized, 0); } } @@ -88,18 +88,18 @@ bool IphlpDll::IphlpAttach(void) { while (InterlockedCompareExchange(&_critical_section, 0, 1) == 0); - return (_GetIfTable2 != NULL && _FreeMibTable != NULL); + return (_GetIfTable2 != nullptr && _FreeMibTable != nullptr); } DWORD IphlpDll::GetIfTable2(PMIB_IF_TABLE2* Table) { - assert(_initialized && _GetIfTable2 != NULL, + assert(_initialized && _GetIfTable2 != nullptr, "IphlpAttach() not yet called"); return _GetIfTable2(Table); } DWORD IphlpDll::FreeMibTable(PVOID Memory) { - assert(_initialized && _FreeMibTable != NULL, + assert(_initialized && _FreeMibTable != nullptr, "IphlpAttach() not yet called"); return _FreeMibTable(Memory); diff --git a/src/hotspot/os/windows/osThread_windows.cpp b/src/hotspot/os/windows/osThread_windows.cpp index eafc98de7b6..5f369bb7aa0 100644 --- a/src/hotspot/os/windows/osThread_windows.cpp +++ b/src/hotspot/os/windows/osThread_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -27,13 +27,13 @@ #include "runtime/osThread.hpp" void OSThread::pd_initialize() { - set_thread_handle(NULL); - set_thread_id(NULL); - set_interrupt_event(NULL); + set_thread_handle(nullptr); + set_thread_id(0); + set_interrupt_event(nullptr); } void OSThread::pd_destroy() { - if (_interrupt_event != NULL) { + if (_interrupt_event != nullptr) { CloseHandle(_interrupt_event); } } diff --git a/src/hotspot/os/windows/os_perf_windows.cpp b/src/hotspot/os/windows/os_perf_windows.cpp index 7c74420eef4..57dcd2710c8 100644 --- a/src/hotspot/os/windows/os_perf_windows.cpp +++ b/src/hotspot/os/windows/os_perf_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -87,9 +87,9 @@ static const char* const PROCESS_OBJECT_WITH_INSTANCES_WILDCARD_FMT = "\\%s(%s*) static const size_t PROCESS_OBJECT_WITH_INSTANCES_WILDCARD_FMT_LEN = 5; /* pdh string constants built up from fmts on initialization */ -static const char* process_image_name = NULL; // e.g. "java" but could have another image name -static char* pdh_process_instance_IDProcess_counter_fmt = NULL; // "\Process(java#%d)\ID Process" */ -static char* pdh_process_instance_wildcard_IDProcess_counter = NULL; // "\Process(java*)\ID Process" */ +static const char* process_image_name = nullptr; // e.g. "java" but could have another image name +static char* pdh_process_instance_IDProcess_counter_fmt = nullptr; // "\Process(java#%d)\ID Process" */ +static char* pdh_process_instance_wildcard_IDProcess_counter = nullptr; // "\Process(java*)\ID Process" */ /* * Structs for PDH queries. @@ -125,7 +125,7 @@ typedef struct { } ProcessQueryS, *ProcessQueryP; static int open_query(HQUERY* pdh_query_handle) { - return PdhDll::PdhOpenQuery(NULL, 0, pdh_query_handle) != ERROR_SUCCESS ? OS_ERR : OS_OK; + return PdhDll::PdhOpenQuery(nullptr, 0, pdh_query_handle) != ERROR_SUCCESS ? OS_ERR : OS_OK; } static int open_query(UpdateQueryP query) { @@ -138,21 +138,21 @@ static int open_query(QueryP query) { } static void close_query(HQUERY* const pdh_query_handle, HCOUNTER* const counter) { - if (counter != NULL && *counter != NULL) { + if (counter != nullptr && *counter != nullptr) { PdhDll::PdhRemoveCounter(*counter); - *counter = NULL; + *counter = nullptr; } - if (pdh_query_handle != NULL && *pdh_query_handle != NULL) { + if (pdh_query_handle != nullptr && *pdh_query_handle != nullptr) { PdhDll::PdhCloseQuery(*pdh_query_handle); - *pdh_query_handle = NULL; + *pdh_query_handle = nullptr; } } static void close_query(MultiCounterQueryP query) { for (int i = 0; i < query->noOfCounters; ++i) { - close_query(NULL, &query->counters[i]); + close_query(nullptr, &query->counters[i]); } - close_query(&query->query.pdh_query_handle, NULL); + close_query(&query->query.pdh_query_handle, nullptr); query->initialized = false; } @@ -169,18 +169,18 @@ static MultiCounterQueryP create_multi_counter_query() { } static void destroy(CounterQueryP query) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); close_query(&query->query.pdh_query_handle, &query->counter); FREE_C_HEAP_OBJ(query); } static void destroy(MultiCounterQueryP query) { - if (query != NULL) { + if (query != nullptr) { for (int i = 0; i < query->noOfCounters; ++i) { - close_query(NULL, &query->counters[i]); + close_query(nullptr, &query->counters[i]); } FREE_C_HEAP_ARRAY(char, query->counters); - close_query(&query->query.pdh_query_handle, NULL); + close_query(&query->query.pdh_query_handle, nullptr); FREE_C_HEAP_ARRAY(MultiCounterQueryS, query); } } @@ -188,10 +188,10 @@ static void destroy(MultiCounterQueryP query) { static void destroy_query_set(MultiCounterQuerySetP query_set) { for (int i = 0; i < query_set->size; i++) { for (int j = 0; j < query_set->queries[i].noOfCounters; ++j) { - close_query(NULL, &query_set->queries[i].counters[j]); + close_query(nullptr, &query_set->queries[i].counters[j]); } FREE_C_HEAP_ARRAY(char, query_set->queries[i].counters); - close_query(&query_set->queries[i].query.pdh_query_handle, NULL); + close_query(&query_set->queries[i].query.pdh_query_handle, nullptr); } FREE_C_HEAP_ARRAY(MultiCounterQueryS, query_set->queries); } @@ -207,17 +207,17 @@ static void destroy(ProcessQueryP query) { } static void allocate_counters(MultiCounterQueryP query, size_t nofCounters) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); assert(!query->initialized, "invariant"); assert(0 == query->noOfCounters, "invariant"); - assert(query->counters == NULL, "invariant"); + assert(query->counters == nullptr, "invariant"); query->counters = NEW_C_HEAP_ARRAY(HCOUNTER, nofCounters, mtInternal); memset(query->counters, 0, nofCounters * sizeof(HCOUNTER)); query->noOfCounters = (int)nofCounters; } static void allocate_counters(MultiCounterQuerySetP query, size_t nofCounters) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); assert(!query->initialized, "invariant"); for (int i = 0; i < query->size; ++i) { allocate_counters(&query->queries[i], nofCounters); @@ -225,26 +225,26 @@ static void allocate_counters(MultiCounterQuerySetP query, size_t nofCounters) { } static void allocate_counters(ProcessQueryP query, size_t nofCounters) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); allocate_counters(&query->set, nofCounters); } static void deallocate_counters(MultiCounterQueryP query) { FREE_C_HEAP_ARRAY(char, query->counters); - query->counters = NULL; + query->counters = nullptr; query->noOfCounters = 0; } static OSReturn add_counter(UpdateQueryP query, HCOUNTER* counter, const char* counter_path, bool first_sample_on_init) { - assert(query != NULL, "invariant"); - assert(counter != NULL, "invariant"); - assert(counter_path != NULL, "invariant"); - if (query->pdh_query_handle == NULL) { + assert(query != nullptr, "invariant"); + assert(counter != nullptr, "invariant"); + assert(counter_path != nullptr, "invariant"); + if (query->pdh_query_handle == nullptr) { if (open_query(query) != OS_OK) { return OS_ERR; } } - assert(query->pdh_query_handle != NULL, "invariant"); + assert(query->pdh_query_handle != nullptr, "invariant"); PDH_STATUS status = PdhDll::PdhAddCounter(query->pdh_query_handle, counter_path, 0, counter); if (PDH_CSTATUS_NO_OBJECT == status || PDH_CSTATUS_NO_COUNTER == status) { return OS_ERR; @@ -268,9 +268,9 @@ static OSReturn add_counter(UpdateQueryP query, HCOUNTER* counter, const char* c template static OSReturn add_counter(QueryP query, HCOUNTER* counter, const char* counter_path, bool first_sample_on_init) { - assert(query != NULL, "invariant"); - assert(counter != NULL, "invariant"); - assert(counter_path != NULL, "invariant"); + assert(query != nullptr, "invariant"); + assert(counter != nullptr, "invariant"); + assert(counter_path != nullptr, "invariant"); return add_counter(&query->query, counter, counter_path, first_sample_on_init); } @@ -280,9 +280,9 @@ static OSReturn add_counter(CounterQueryP query, const char* counter_path, bool } static OSReturn add_counter(MultiCounterQueryP query, int counter_idx, const char* counter_path, bool first_sample_on_init) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); assert(counter_idx < query->noOfCounters, "invariant"); - assert(query->counters[counter_idx] == NULL, "invariant"); + assert(query->counters[counter_idx] == nullptr, "invariant"); return add_counter(query, &query->counters[counter_idx], counter_path, first_sample_on_init); } @@ -292,7 +292,7 @@ static OSReturn add_counter(MultiCounterQueryP query, int counter_idx, const cha static const int min_update_interval_millis = 500; static int collect(UpdateQueryP query) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); const s8 now = os::javaTimeNanos(); if (nanos_to_millis(now - query->lastUpdate) > min_update_interval_millis) { if (PdhDll::PdhCollectQueryData(query->pdh_query_handle) != ERROR_SUCCESS) { @@ -305,31 +305,31 @@ static int collect(UpdateQueryP query) { template static int collect(QueryP query) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); return collect(&query->query); } static int formatted_counter_value(HCOUNTER counter, DWORD format, PDH_FMT_COUNTERVALUE* const value) { - assert(value != NULL, "invariant"); - return PdhDll::PdhGetFormattedCounterValue(counter, format, NULL, value) != ERROR_SUCCESS ? OS_ERR : OS_OK; + assert(value != nullptr, "invariant"); + return PdhDll::PdhGetFormattedCounterValue(counter, format, nullptr, value) != ERROR_SUCCESS ? OS_ERR : OS_OK; } static int read_counter(CounterQueryP query, DWORD format, PDH_FMT_COUNTERVALUE* const value) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); return formatted_counter_value(query->counter, format, value); } static int read_counter(MultiCounterQueryP query, int counter_idx, DWORD format, PDH_FMT_COUNTERVALUE* const value) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); assert(counter_idx < query->noOfCounters, "invariant"); - assert(query->counters[counter_idx] != NULL, "invariant"); + assert(query->counters[counter_idx] != nullptr, "invariant"); return formatted_counter_value(query->counters[counter_idx], format, value); } static int read_counter(ProcessQueryP query, int counter_idx, DWORD format, PDH_FMT_COUNTERVALUE* const value) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); MultiCounterQueryP const current_query = &query->set.queries[query->process_idx]; - assert(current_query != NULL, "invariant"); + assert(current_query != nullptr, "invariant"); return read_counter(current_query, counter_idx, format, value); } @@ -339,17 +339,17 @@ static int read_counter(ProcessQueryP query, int counter_idx, DWORD format, PDH_ * A tally of this list is returned to the caller. */ static int number_of_live_process_instances() { - char* buffer = NULL; + char* buffer = nullptr; DWORD size = 0; // determine size - PDH_STATUS status = PdhDll::PdhExpandWildCardPath(NULL, + PDH_STATUS status = PdhDll::PdhExpandWildCardPath(nullptr, pdh_process_instance_wildcard_IDProcess_counter, buffer, &size, PDH_NOEXPANDCOUNTERS); while (status == PDH_MORE_DATA) { buffer = NEW_RESOURCE_ARRAY(char, size); - status = PdhDll::PdhExpandWildCardPath(NULL, + status = PdhDll::PdhExpandWildCardPath(nullptr, pdh_process_instance_wildcard_IDProcess_counter, buffer, &size, @@ -367,11 +367,11 @@ static int number_of_live_process_instances() { } static PDH_STATUS pdh_process_idx_to_pid(HQUERY& pdh_query_handle, int idx, LONG* pid) { - assert(pid != NULL, "invariant"); + assert(pid != nullptr, "invariant"); char counter_path[PDH_MAX_COUNTER_PATH]; jio_snprintf(counter_path, sizeof(counter_path) - 1, pdh_process_instance_IDProcess_counter_fmt, idx); assert(strlen(counter_path) < sizeof(counter_path), "invariant"); - HCOUNTER counter = NULL; + HCOUNTER counter = nullptr; PDH_STATUS status = PdhDll::PdhAddCounter(pdh_query_handle, counter_path, 0, &counter); if (status != ERROR_SUCCESS) { close_query(&pdh_query_handle, &counter); @@ -379,7 +379,7 @@ static PDH_STATUS pdh_process_idx_to_pid(HQUERY& pdh_query_handle, int idx, LONG } status = PdhDll::PdhCollectQueryData(pdh_query_handle); if (status != ERROR_SUCCESS) { - close_query(NULL, &counter); + close_query(nullptr, &counter); return PDH_NO_DATA; } PDH_FMT_COUNTERVALUE counter_value; @@ -389,7 +389,7 @@ static PDH_STATUS pdh_process_idx_to_pid(HQUERY& pdh_query_handle, int idx, LONG return status; } *pid = counter_value.longValue; - close_query(NULL, &counter); + close_query(nullptr, &counter); return ERROR_SUCCESS; } @@ -451,10 +451,10 @@ static int max_process_query_idx = 0; static int current_process_query_index(int previous_query_idx = 0) { assert(max_process_query_idx >= 0, "invariant"); assert(max_process_query_idx >= previous_query_idx, "invariant"); - assert(process_image_name != NULL, "invariant"); - assert(pdh_process_instance_IDProcess_counter_fmt != NULL, "invariant"); + assert(process_image_name != nullptr, "invariant"); + assert(pdh_process_instance_IDProcess_counter_fmt != nullptr, "invariant"); int result = OS_ERR; - HQUERY tmp_pdh_query_handle = NULL; + HQUERY tmp_pdh_query_handle = nullptr; if (open_query(&tmp_pdh_query_handle) != OS_OK) { return OS_ERR; } @@ -480,12 +480,12 @@ static int current_process_query_index(int previous_query_idx = 0) { break; } } - close_query(&tmp_pdh_query_handle, NULL); + close_query(&tmp_pdh_query_handle, nullptr); return result; } static int ensure_current_process_query_index(ProcessQueryP query) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); const int previous_query_idx = query->process_idx; if (previous_query_idx == 0) { return previous_query_idx; @@ -508,18 +508,18 @@ static int ensure_current_process_query_index(ProcessQueryP query) { } static MultiCounterQueryP current_process_query(ProcessQueryP query) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); if (ensure_current_process_query_index(query) == OS_ERR) { - return NULL; + return nullptr; } assert(query->process_idx < query->set.size, "invariant"); return &query->set.queries[query->process_idx]; } static int collect(ProcessQueryP query) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); MultiCounterQueryP current_query = current_process_query(query); - return current_query != NULL ? collect(current_query) : OS_ERR; + return current_query != nullptr ? collect(current_query) : OS_ERR; } /* @@ -537,10 +537,10 @@ static int collect(ProcessQueryP query) { */ static const char* make_fully_qualified_counter_path(const char* object_name, const char* counter_name, - const char* image_name = NULL, - const char* instance = NULL) { - assert(object_name != NULL, "invariant"); - assert(counter_name != NULL, "invariant"); + const char* image_name = nullptr, + const char* instance = nullptr) { + assert(object_name != nullptr, "invariant"); + assert(counter_name != nullptr, "invariant"); size_t counter_path_len = strlen(object_name) + strlen(counter_name); char* counter_path; @@ -562,7 +562,7 @@ static const char* make_fully_qualified_counter_path(const char* object_name, * * Examples: "\Process(java#0)", \Process(java#1"), ... */ - assert(instance != NULL, "invariant"); + assert(instance != nullptr, "invariant"); counter_path_len += strlen(instance); counter_path = NEW_RESOURCE_ARRAY(char, counter_path_len + 1); jio_snprintf_result = jio_snprintf(counter_path, @@ -620,7 +620,7 @@ static void log_invalid_pdh_index(DWORD index) { static bool is_valid_pdh_index(DWORD index) { DWORD dummy = 0; - if (PdhDll::PdhLookupPerfNameByIndex(NULL, index, NULL, &dummy) != PDH_MORE_DATA) { + if (PdhDll::PdhLookupPerfNameByIndex(nullptr, index, nullptr, &dummy) != PDH_MORE_DATA) { log_invalid_pdh_index(index); return false; } @@ -637,19 +637,19 @@ static bool is_valid_pdh_index(DWORD index) { * @return OS_OK if successful, OS_ERR on failure. */ static OSReturn lookup_name_by_index(DWORD index, char** p_string) { - assert(p_string != NULL, "invariant"); + assert(p_string != nullptr, "invariant"); if (!is_valid_pdh_index(index)) { return OS_ERR; } // determine size needed DWORD size = 0; - PDH_STATUS status = PdhDll::PdhLookupPerfNameByIndex(NULL, index, NULL, &size); + PDH_STATUS status = PdhDll::PdhLookupPerfNameByIndex(nullptr, index, nullptr, &size); assert(status == PDH_MORE_DATA, "invariant"); *p_string = NEW_RESOURCE_ARRAY(char, size); - if (PdhDll::PdhLookupPerfNameByIndex(NULL, index, *p_string, &size) != ERROR_SUCCESS) { + if (PdhDll::PdhLookupPerfNameByIndex(nullptr, index, *p_string, &size) != ERROR_SUCCESS) { return OS_ERR; } - if (0 == size || *p_string == NULL) { + if (0 == size || *p_string == nullptr) { return OS_ERR; } // windows vista does not null-terminate the string (although the docs says it will) @@ -658,7 +658,7 @@ static OSReturn lookup_name_by_index(DWORD index, char** p_string) { } static const char* copy_string_to_c_heap(const char* string) { - assert(string != NULL, "invariant"); + assert(string != nullptr, "invariant"); const size_t len = strlen(string); char* const cheap_allocated_string = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); strncpy(cheap_allocated_string, string, len + 1); @@ -671,13 +671,13 @@ static const char* copy_string_to_c_heap(const char* string) { * Caller will need a ResourceMark. * * @param pdh_artifact_idx the counter index as specified in the registry -* @return localized pdh artifact string if successful, NULL on failure. +* @return localized pdh artifact string if successful, null on failure. */ static const char* pdh_localized_artifact(DWORD pdh_artifact_idx) { - char* pdh_localized_artifact_string = NULL; + char* pdh_localized_artifact_string = nullptr; // get localized name for the pdh artifact idx if (lookup_name_by_index(pdh_artifact_idx, &pdh_localized_artifact_string) != OS_OK) { - return NULL; + return nullptr; } return pdh_localized_artifact_string; } @@ -691,17 +691,17 @@ static const char* pdh_localized_artifact(DWORD pdh_artifact_idx) { * * Caller needs ResourceMark. * - * @return the process image string description, NULL if the call failed. + * @return the process image string description, null if the call failed. */ static const char* pdh_process_image_name() { char* module_name = NEW_RESOURCE_ARRAY(char, MAX_PATH); // Find our module name and use it to extract the image name used by PDH - DWORD getmfn_return = GetModuleFileName(NULL, module_name, MAX_PATH); + DWORD getmfn_return = GetModuleFileName(nullptr, module_name, MAX_PATH); if (getmfn_return >= MAX_PATH || 0 == getmfn_return) { - return NULL; + return nullptr; } if (os::get_last_error() == ERROR_INSUFFICIENT_BUFFER) { - return NULL; + return nullptr; } char* process_image_name = strrchr(module_name, '\\'); //drop path process_image_name++; //skip slash @@ -712,28 +712,28 @@ static const char* pdh_process_image_name() { static void deallocate_pdh_constants() { FREE_C_HEAP_ARRAY(char, process_image_name); - process_image_name = NULL; + process_image_name = nullptr; FREE_C_HEAP_ARRAY(char, pdh_process_instance_IDProcess_counter_fmt); - pdh_process_instance_IDProcess_counter_fmt = NULL; + pdh_process_instance_IDProcess_counter_fmt = nullptr; FREE_C_HEAP_ARRAY(char, pdh_process_instance_wildcard_IDProcess_counter); - pdh_process_instance_wildcard_IDProcess_counter = NULL; + pdh_process_instance_wildcard_IDProcess_counter = nullptr; } static OSReturn allocate_pdh_constants() { - assert(process_image_name == NULL, "invariant"); + assert(process_image_name == nullptr, "invariant"); const char* pdh_image_name = pdh_process_image_name(); - if (pdh_image_name == NULL) { + if (pdh_image_name == nullptr) { return OS_ERR; } process_image_name = copy_string_to_c_heap(pdh_image_name); const char* pdh_localized_process_object = pdh_localized_artifact(PDH_PROCESS_IDX); - if (pdh_localized_process_object == NULL) { + if (pdh_localized_process_object == nullptr) { return OS_ERR; } const char* pdh_localized_IDProcess_counter = pdh_localized_artifact(PDH_ID_PROCESS_IDX); - if (pdh_localized_IDProcess_counter == NULL) { + if (pdh_localized_IDProcess_counter == nullptr) { return OS_ERR; } @@ -745,7 +745,7 @@ static OSReturn allocate_pdh_constants() { PROCESS_OBJECT_WITH_INSTANCES_COUNTER_FMT_LEN + 2; // "%d" - assert(pdh_process_instance_IDProcess_counter_fmt == NULL, "invariant"); + assert(pdh_process_instance_IDProcess_counter_fmt == nullptr, "invariant"); pdh_process_instance_IDProcess_counter_fmt = NEW_C_HEAP_ARRAY(char, pdh_IDProcess_counter_fmt_len + 1, mtInternal); /* "\Process(java#%d)\ID Process" */ @@ -757,14 +757,14 @@ static OSReturn allocate_pdh_constants() { "%d", pdh_localized_IDProcess_counter); - assert(pdh_process_instance_IDProcess_counter_fmt != NULL, "invariant"); + assert(pdh_process_instance_IDProcess_counter_fmt != nullptr, "invariant"); assert(len == pdh_IDProcess_counter_fmt_len, "invariant"); const size_t pdh_IDProcess_wildcard_fmt_len = id_process_base_length + PROCESS_OBJECT_WITH_INSTANCES_WILDCARD_FMT_LEN; - assert(pdh_process_instance_wildcard_IDProcess_counter == NULL, "invariant"); + assert(pdh_process_instance_wildcard_IDProcess_counter == nullptr, "invariant"); pdh_process_instance_wildcard_IDProcess_counter = NEW_C_HEAP_ARRAY(char, pdh_IDProcess_wildcard_fmt_len + 1, mtInternal); /* "\Process(java*)\ID Process" */ @@ -775,7 +775,7 @@ static OSReturn allocate_pdh_constants() { process_image_name, pdh_localized_IDProcess_counter); - assert(pdh_process_instance_wildcard_IDProcess_counter != NULL, "invariant"); + assert(pdh_process_instance_wildcard_IDProcess_counter != nullptr, "invariant"); assert(len == pdh_IDProcess_wildcard_fmt_len, "invariant"); return OS_OK; } @@ -784,44 +784,44 @@ static OSReturn allocate_pdh_constants() { * Enuerate the Processor PDH object and returns a buffer containing the enumerated instances. * Caller needs ResourceMark; * - * @return buffer if successful, NULL on failure. + * @return buffer if successful, null on failure. */ static const char* enumerate_cpu_instances() { char* processor; //'Processor' == PDH_PROCESSOR_IDX if (lookup_name_by_index(PDH_PROCESSOR_IDX, &processor) != OS_OK) { - return NULL; + return nullptr; } DWORD c_size = 0; DWORD i_size = 0; // enumerate all processors. - PDH_STATUS pdhStat = PdhDll::PdhEnumObjectItems(NULL, // reserved - NULL, // local machine + PDH_STATUS pdhStat = PdhDll::PdhEnumObjectItems(nullptr, // reserved + nullptr, // local machine processor, // object to enumerate - NULL, + nullptr, &c_size, - NULL, // instance buffer is NULL and + nullptr, // instance buffer is null and &i_size, // pass 0 length in order to get the required size PERF_DETAIL_WIZARD, // counter detail level 0); if (PdhDll::PdhStatusFail((pdhStat))) { - return NULL; + return nullptr; } char* const instances = NEW_RESOURCE_ARRAY(char, i_size); c_size = 0; - pdhStat = PdhDll::PdhEnumObjectItems(NULL, // reserved - NULL, // local machine + pdhStat = PdhDll::PdhEnumObjectItems(nullptr, // reserved + nullptr, // local machine processor, // object to enumerate - NULL, + nullptr, &c_size, instances, // now instance buffer is allocated to be filled in &i_size, // and the required size is known PERF_DETAIL_WIZARD, // counter detail level 0); - return PdhDll::PdhStatusFail(pdhStat) ? NULL : instances; + return PdhDll::PdhStatusFail(pdhStat) ? nullptr : instances; } static int count_logical_cpus(const char* instances) { - assert(instances != NULL, "invariant"); + assert(instances != nullptr, "invariant"); // count logical instances. DWORD count; char* tmp; @@ -835,7 +835,7 @@ static int number_of_logical_cpus() { static int numberOfCPUS = 0; if (numberOfCPUS == 0) { const char* instances = enumerate_cpu_instances(); - if (instances == NULL) { + if (instances == nullptr) { return OS_ERR; } numberOfCPUS = count_logical_cpus(instances); @@ -860,22 +860,22 @@ static void log_error_message_on_no_PDH_artifact(const char* counter_path) { } static int initialize_cpu_query_counters(MultiCounterQueryP query, DWORD pdh_counter_idx) { - assert(query != NULL, "invariant"); - assert(query->counters != NULL, "invariant"); + assert(query != nullptr, "invariant"); + assert(query->counters != nullptr, "invariant"); char* processor; //'Processor' == PDH_PROCESSOR_IDX if (lookup_name_by_index(PDH_PROCESSOR_IDX, &processor) != OS_OK) { return OS_ERR; } - char* counter_name = NULL; + char* counter_name = nullptr; if (lookup_name_by_index(pdh_counter_idx, &counter_name) != OS_OK) { return OS_ERR; } - if (query->query.pdh_query_handle == NULL) { + if (query->query.pdh_query_handle == nullptr) { if (open_query(query) != OS_OK) { return OS_ERR; } } - assert(query->query.pdh_query_handle != NULL, "invariant"); + assert(query->query.pdh_query_handle != nullptr, "invariant"); size_t counter_len = strlen(processor); counter_len += strlen(counter_name); counter_len += OBJECT_WITH_INSTANCES_COUNTER_FMT_LEN; // "\\%s(%s)\\%s" @@ -904,7 +904,7 @@ static int initialize_cpu_query_counters(MultiCounterQueryP query, DWORD pdh_cou } static int initialize_cpu_query(MultiCounterQueryP query) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); assert(!query->initialized, "invariant"); const int logical_cpu_count = number_of_logical_cpus(); assert(logical_cpu_count >= os::processor_count(), "invariant"); @@ -919,17 +919,17 @@ static int initialize_cpu_query(MultiCounterQueryP query) { } static int initialize_query(CounterQueryP query, DWORD pdh_object_idx, DWORD pdh_counter_idx) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); assert(!query->initialized, "invariant"); if (!((is_valid_pdh_index(pdh_object_idx) && is_valid_pdh_index(pdh_counter_idx)))) { return OS_ERR; } const char* object = pdh_localized_artifact(pdh_object_idx); - assert(object != NULL, "invariant"); + assert(object != nullptr, "invariant"); const char* counter = pdh_localized_artifact(pdh_counter_idx); - assert(counter != NULL, "invariant"); + assert(counter != nullptr, "invariant"); const char* counter_path = make_fully_qualified_counter_path(object, counter); - assert(counter_path != NULL, "invariant"); + assert(counter_path != nullptr, "invariant"); if (add_counter(query, counter_path, true) != OS_OK) { return OS_ERR; } @@ -944,7 +944,7 @@ static int initialize_context_switches_query(CounterQueryP query) { static ProcessQueryP create_process_query() { const int current_process_query_idx = current_process_query_index(); if (current_process_query_idx == OS_ERR) { - return NULL; + return nullptr; } ProcessQueryP const query = NEW_C_HEAP_OBJ(ProcessQueryS, mtInternal); memset(query, 0, sizeof(ProcessQueryS)); @@ -961,19 +961,19 @@ static int initialize_process_counter(ProcessQueryP process_query, int counter_i if (lookup_name_by_index(PDH_PROCESS_IDX, &localized_process_object) != OS_OK) { return OS_ERR; } - assert(localized_process_object != NULL, "invariant"); + assert(localized_process_object != nullptr, "invariant"); char* localized_counter_name; if (lookup_name_by_index(pdh_counter_idx, &localized_counter_name) != OS_OK) { return OS_ERR; } - assert(localized_counter_name != NULL, "invariant"); + assert(localized_counter_name != nullptr, "invariant"); for (int i = 0; i < process_query->set.size; ++i) { char instanceIndexBuffer[32]; const char* counter_path = make_fully_qualified_counter_path(localized_process_object, localized_counter_name, process_image_name, itoa(i, instanceIndexBuffer, 10)); - assert(counter_path != NULL, "invariant"); + assert(counter_path != nullptr, "invariant"); MultiCounterQueryP const query = &process_query->set.queries[i]; if (add_counter(query, counter_idx, counter_path, true) != OS_OK) { return OS_ERR; @@ -987,7 +987,7 @@ static int initialize_process_counter(ProcessQueryP process_query, int counter_i } static int initialize_process_query(ProcessQueryP query) { - assert(query != NULL, "invariant"); + assert(query != nullptr, "invariant"); assert(!query->set.initialized, "invariant"); allocate_counters(query, 2); if (initialize_process_counter(query, 0, PDH_PROCESSOR_TIME_IDX) != OS_OK) { @@ -1093,20 +1093,20 @@ class CPUPerformanceInterface::CPUPerformance : public CHeapObj { bool initialize(); }; -CPUPerformanceInterface::CPUPerformance::CPUPerformance() : _context_switches(NULL), _process_cpu_load(NULL), _machine_cpu_load(NULL) {} +CPUPerformanceInterface::CPUPerformance::CPUPerformance() : _context_switches(nullptr), _process_cpu_load(nullptr), _machine_cpu_load(nullptr) {} bool CPUPerformanceInterface::CPUPerformance::initialize() { if (pdh_acquire() != OS_OK) { return false; } _context_switches = create_counter_query(); - assert(_context_switches != NULL, "invariant"); + assert(_context_switches != nullptr, "invariant"); if (initialize_context_switches_query(_context_switches) != OS_OK) { return false; } assert(_context_switches->initialized, "invariant"); _process_cpu_load = create_process_query(); - if (_process_cpu_load == NULL) { + if (_process_cpu_load == nullptr) { return false; } if (initialize_process_query(_process_cpu_load) != OS_OK) { @@ -1114,7 +1114,7 @@ bool CPUPerformanceInterface::CPUPerformance::initialize() { } assert(_process_cpu_load->set.initialized, "invariant"); _machine_cpu_load = create_multi_counter_query(); - assert(_machine_cpu_load != NULL, "invariant"); + assert(_machine_cpu_load != nullptr, "invariant"); if (initialize_cpu_query(_machine_cpu_load) != OS_OK) { return false; } @@ -1123,22 +1123,22 @@ bool CPUPerformanceInterface::CPUPerformance::initialize() { } CPUPerformanceInterface::CPUPerformance::~CPUPerformance() { - if (_context_switches != NULL) { + if (_context_switches != nullptr) { destroy(_context_switches); - _context_switches = NULL; + _context_switches = nullptr; } - if (_process_cpu_load != NULL) { + if (_process_cpu_load != nullptr) { destroy(_process_cpu_load); - _process_cpu_load = NULL; + _process_cpu_load = nullptr; } - if (_machine_cpu_load != NULL) { + if (_machine_cpu_load != nullptr) { destroy(_machine_cpu_load); - _machine_cpu_load = NULL; + _machine_cpu_load = nullptr; } pdh_release(); } -CPUPerformanceInterface::CPUPerformanceInterface() : _impl(NULL) {} +CPUPerformanceInterface::CPUPerformanceInterface() : _impl(nullptr) {} bool CPUPerformanceInterface::initialize() { _impl = new CPUPerformanceInterface::CPUPerformance(); @@ -1146,7 +1146,7 @@ bool CPUPerformanceInterface::initialize() { } CPUPerformanceInterface::~CPUPerformanceInterface() { - if (_impl != NULL) { + if (_impl != nullptr) { delete _impl; } } @@ -1171,7 +1171,7 @@ int CPUPerformanceInterface::cpu_loads_process(double* jvm_user_load, int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, double* cpu_load) { *cpu_load = .0; - if (_machine_cpu_load == NULL || !_machine_cpu_load->initialized) { + if (_machine_cpu_load == nullptr || !_machine_cpu_load->initialized) { return OS_ERR; } assert(which_logical_cpu < _machine_cpu_load->noOfCounters, "invariant"); @@ -1190,7 +1190,7 @@ int CPUPerformanceInterface::CPUPerformance::cpu_load(int which_logical_cpu, dou int CPUPerformanceInterface::CPUPerformance::cpu_load_total_process(double* cpu_load) { *cpu_load = .0; - if (_process_cpu_load == NULL || !_process_cpu_load->set.initialized) { + if (_process_cpu_load == nullptr || !_process_cpu_load->set.initialized) { return OS_ERR; } if (collect(_process_cpu_load) != OS_OK) { @@ -1210,14 +1210,14 @@ int CPUPerformanceInterface::CPUPerformance::cpu_load_total_process(double* cpu_ int CPUPerformanceInterface::CPUPerformance::cpu_loads_process(double* jvm_user_load, double* jvm_kernel_load, double* system_total_load) { - assert(jvm_user_load != NULL, "jvm_user_load is NULL!"); - assert(jvm_kernel_load != NULL, "jvm_kernel_load is NULL!"); - assert(system_total_load != NULL, "system_total_load is NULL!"); + assert(jvm_user_load != nullptr, "jvm_user_load is null!"); + assert(jvm_kernel_load != nullptr, "jvm_kernel_load is null!"); + assert(system_total_load != nullptr, "system_total_load is null!"); *jvm_user_load = .0; *jvm_kernel_load = .0; *system_total_load = .0; - if (_process_cpu_load == NULL || !_process_cpu_load->set.initialized) { + if (_process_cpu_load == nullptr || !_process_cpu_load->set.initialized) { return OS_ERR; } if (collect(_process_cpu_load) != OS_OK) { @@ -1263,9 +1263,9 @@ int CPUPerformanceInterface::CPUPerformance::cpu_loads_process(double* jvm_user_ } int CPUPerformanceInterface::CPUPerformance::context_switch_rate(double* rate) { - assert(rate != NULL, "invariant"); + assert(rate != nullptr, "invariant"); *rate = .0; - if (_context_switches == NULL || !_context_switches->initialized) { + if (_context_switches == nullptr || !_context_switches->initialized) { return OS_ERR; } if (collect(_context_switches) != OS_OK) { @@ -1338,10 +1338,10 @@ SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() { int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProcess* process_info) { assert(is_valid(), "no current process to be fetched!"); - assert(process_info != NULL, "process_info is NULL!"); - char* exePath = NULL; + assert(process_info != nullptr, "process_info is null!"); + char* exePath = nullptr; HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, _pe32.th32ProcessID); - if (hProcess != NULL) { + if (hProcess != nullptr) { HMODULE hMod; DWORD cbNeeded; if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded) != 0) { @@ -1358,7 +1358,7 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProc } char* SystemProcessInterface::SystemProcesses::ProcessIterator::allocate_string(const char* str) const { - return str != NULL ? os::strdup_check_oom(str, mtInternal) : NULL; + return str != nullptr ? os::strdup_check_oom(str, mtInternal) : nullptr; } int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() { @@ -1366,7 +1366,7 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() { return OS_OK; } -SystemProcessInterface::SystemProcesses::SystemProcesses() : _iterator(NULL) {} +SystemProcessInterface::SystemProcesses::SystemProcesses() : _iterator(nullptr) {} bool SystemProcessInterface::SystemProcesses::initialize() { _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator(); @@ -1374,20 +1374,20 @@ 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; // take process snapshot if (_iterator->snapshot() != OS_OK) { @@ -1399,7 +1399,7 @@ int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** sy _iterator->current(tmp); //if already existing head - if (*system_processes != NULL) { + if (*system_processes != nullptr) { //move "first to second" tmp->set_next(*system_processes); } @@ -1418,7 +1418,7 @@ int SystemProcessInterface::system_processes(SystemProcess** system_procs, return _impl->system_processes(system_procs, no_of_sys_processes); } -SystemProcessInterface::SystemProcessInterface() : _impl(NULL) {} +SystemProcessInterface::SystemProcessInterface() : _impl(nullptr) {} bool SystemProcessInterface::initialize() { _impl = new SystemProcessInterface::SystemProcesses(); @@ -1426,12 +1426,12 @@ bool SystemProcessInterface::initialize() { } SystemProcessInterface::~SystemProcessInterface() { - if (_impl != NULL) { + if (_impl != nullptr) { delete _impl; } } -CPUInformationInterface::CPUInformationInterface() : _cpu_info(NULL) {} +CPUInformationInterface::CPUInformationInterface() : _cpu_info(nullptr) {} bool CPUInformationInterface::initialize() { _cpu_info = new CPUInformation(); @@ -1445,17 +1445,17 @@ bool CPUInformationInterface::initialize() { } CPUInformationInterface::~CPUInformationInterface() { - if (_cpu_info != NULL) { + if (_cpu_info != nullptr) { FREE_C_HEAP_ARRAY(char, _cpu_info->cpu_name()); - _cpu_info->set_cpu_name(NULL); + _cpu_info->set_cpu_name(nullptr); FREE_C_HEAP_ARRAY(char, _cpu_info->cpu_description()); - _cpu_info->set_cpu_description(NULL); + _cpu_info->set_cpu_description(nullptr); delete _cpu_info; } } int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) { - if (NULL == _cpu_info) { + if (nullptr == _cpu_info) { return OS_ERR; } cpu_info = *_cpu_info; // shallow copy assignment @@ -1494,14 +1494,14 @@ int NetworkPerformanceInterface::NetworkPerformance::network_utilization(Network return OS_ERR; } - NetworkInterface* ret = NULL; + NetworkInterface* ret = nullptr; for (ULONG i = 0; i < table->NumEntries; ++i) { if (table->Table[i].InterfaceAndOperStatusFlags.FilterInterface) { continue; } char buf[256]; - if (WideCharToMultiByte(CP_UTF8, 0, table->Table[i].Description, -1, buf, sizeof(buf), NULL, NULL) == 0) { + if (WideCharToMultiByte(CP_UTF8, 0, table->Table[i].Description, -1, buf, sizeof(buf), nullptr, nullptr) == 0) { continue; } @@ -1515,10 +1515,10 @@ int NetworkPerformanceInterface::NetworkPerformance::network_utilization(Network return OS_OK; } -NetworkPerformanceInterface::NetworkPerformanceInterface() : _impl(NULL) {} +NetworkPerformanceInterface::NetworkPerformanceInterface() : _impl(nullptr) {} NetworkPerformanceInterface::~NetworkPerformanceInterface() { - if (_impl != NULL) { + if (_impl != nullptr) { delete _impl; } } diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 296f819f992..0998cb96b3b 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -131,8 +131,8 @@ static FILETIME process_kernel_time; #endif #if defined(USE_VECTORED_EXCEPTION_HANDLING) -PVOID topLevelVectoredExceptionHandler = NULL; -LPTOP_LEVEL_EXCEPTION_FILTER previousUnhandledExceptionFilter = NULL; +PVOID topLevelVectoredExceptionHandler = nullptr; +LPTOP_LEVEL_EXCEPTION_FILTER previousUnhandledExceptionFilter = nullptr; #endif // save DLL module handle, used by GetModuleFileName @@ -154,9 +154,9 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) { timeEndPeriod(1L); } #if defined(USE_VECTORED_EXCEPTION_HANDLING) - if (topLevelVectoredExceptionHandler != NULL) { + if (topLevelVectoredExceptionHandler != nullptr) { RemoveVectoredExceptionHandler(topLevelVectoredExceptionHandler); - topLevelVectoredExceptionHandler = NULL; + topLevelVectoredExceptionHandler = nullptr; } #endif break; @@ -190,10 +190,10 @@ struct PreserveLastError { // Logging wrapper for VirtualAlloc static LPVOID virtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) { LPVOID result = ::VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect); - if (result != NULL) { + if (result != nullptr) { log_trace(os)("VirtualAlloc(" PTR_FORMAT ", " SIZE_FORMAT ", %x, %x) returned " PTR_FORMAT "%s.", p2i(lpAddress), dwSize, flAllocationType, flProtect, p2i(result), - ((lpAddress != NULL && result != lpAddress) ? " " : "")); + ((lpAddress != nullptr && result != lpAddress) ? " " : "")); } else { PreserveLastError ple; log_info(os)("VirtualAlloc(" PTR_FORMAT ", " SIZE_FORMAT ", %x, %x) failed (%u).", @@ -220,10 +220,10 @@ static BOOL virtualFree(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType) { static LPVOID virtualAllocExNuma(HANDLE hProcess, LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect, DWORD nndPreferred) { LPVOID result = ::VirtualAllocExNuma(hProcess, lpAddress, dwSize, flAllocationType, flProtect, nndPreferred); - if (result != NULL) { + if (result != nullptr) { log_trace(os)("VirtualAllocExNuma(" PTR_FORMAT ", " SIZE_FORMAT ", %x, %x, %x) returned " PTR_FORMAT "%s.", p2i(lpAddress), dwSize, flAllocationType, flProtect, nndPreferred, p2i(result), - ((lpAddress != NULL && result != lpAddress) ? " " : "")); + ((lpAddress != nullptr && result != lpAddress) ? " " : "")); } else { PreserveLastError ple; log_info(os)("VirtualAllocExNuma(" PTR_FORMAT ", " SIZE_FORMAT ", %x, %x, %x) failed (%u).", @@ -237,10 +237,10 @@ static LPVOID mapViewOfFileEx(HANDLE hFileMappingObject, DWORD dwDesiredAccess, DWORD dwFileOffsetLow, SIZE_T dwNumberOfBytesToMap, LPVOID lpBaseAddress) { LPVOID result = ::MapViewOfFileEx(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap, lpBaseAddress); - if (result != NULL) { + if (result != nullptr) { log_trace(os)("MapViewOfFileEx(" PTR_FORMAT ", " SIZE_FORMAT ") returned " PTR_FORMAT "%s.", p2i(lpBaseAddress), dwNumberOfBytesToMap, p2i(result), - ((lpBaseAddress != NULL && result != lpBaseAddress) ? " " : "")); + ((lpBaseAddress != nullptr && result != lpBaseAddress) ? " " : "")); } else { PreserveLastError ple; log_info(os)("MapViewOfFileEx(" PTR_FORMAT ", " SIZE_FORMAT ") failed (%u).", @@ -277,7 +277,7 @@ void os::run_periodic_checks(outputStream* st) { } // previous UnhandledExceptionFilter, if there is one -static LPTOP_LEVEL_EXCEPTION_FILTER prev_uef_handler = NULL; +static LPTOP_LEVEL_EXCEPTION_FILTER prev_uef_handler = nullptr; LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo); @@ -291,7 +291,7 @@ void os::init_system_properties_values() { char home_dir[MAX_PATH + 1]; char *alt_home_dir = ::getenv("_ALT_JAVA_HOME_DIR"); - if (alt_home_dir != NULL) { + if (alt_home_dir != nullptr) { strncpy(home_dir, alt_home_dir, MAX_PATH + 1); home_dir[MAX_PATH] = '\0'; } else { @@ -300,10 +300,10 @@ void os::init_system_properties_values() { // Now cut the path to /jre if we can. *(strrchr(home_dir, '\\')) = '\0'; // get rid of \jvm.dll pslash = strrchr(home_dir, '\\'); - if (pslash != NULL) { + if (pslash != nullptr) { *pslash = '\0'; // get rid of \{client|server} pslash = strrchr(home_dir, '\\'); - if (pslash != NULL) { + if (pslash != nullptr) { *pslash = '\0'; // get rid of \bin } } @@ -322,7 +322,7 @@ void os::init_system_properties_values() { FREE_C_HEAP_ARRAY(char, dll_path); if (!set_boot_path('\\', ';')) { - vm_exit_during_initialization("Failed setting boot class path.", NULL); + vm_exit_during_initialization("Failed setting boot class path.", nullptr); } } @@ -349,7 +349,7 @@ void os::init_system_properties_values() { library_path[0] = '\0'; - GetModuleFileName(NULL, tmp, sizeof(tmp)); + GetModuleFileName(nullptr, tmp, sizeof(tmp)); *(strrchr(tmp, '\\')) = '\0'; strcat(library_path, tmp); @@ -414,9 +414,9 @@ extern "C" void breakpoint() { // only supported on Windows XP or later. // int os::get_native_stack(address* stack, int frames, int toSkip) { - int captured = RtlCaptureStackBackTrace(toSkip + 1, frames, (PVOID*)stack, NULL); + int captured = RtlCaptureStackBackTrace(toSkip + 1, frames, (PVOID*)stack, nullptr); for (int index = captured; index < frames; index ++) { - stack[index] = NULL; + stack[index] = nullptr; } return captured; } @@ -459,18 +459,18 @@ size_t os::current_stack_size() { bool os::committed_in_range(address start, size_t size, address& committed_start, size_t& committed_size) { MEMORY_BASIC_INFORMATION minfo; - committed_start = NULL; + committed_start = nullptr; committed_size = 0; address top = start + size; const address start_addr = start; while (start < top) { VirtualQuery(start, &minfo, sizeof(minfo)); if ((minfo.State & MEM_COMMIT) == 0) { // not committed - if (committed_start != NULL) { + if (committed_start != nullptr) { break; } } else { // committed - if (committed_start == NULL) { + if (committed_start == nullptr) { committed_start = start; } size_t offset = start - (address)minfo.BaseAddress; @@ -479,7 +479,7 @@ bool os::committed_in_range(address start, size_t size, address& committed_start start = (address)minfo.BaseAddress + minfo.RegionSize; } - if (committed_start == NULL) { + if (committed_start == nullptr) { assert(committed_size == 0, "Sanity"); return false; } else { @@ -492,20 +492,20 @@ bool os::committed_in_range(address start, size_t size, address& committed_start struct tm* os::localtime_pd(const time_t* clock, struct tm* res) { const struct tm* time_struct_ptr = localtime(clock); - if (time_struct_ptr != NULL) { + if (time_struct_ptr != nullptr) { *res = *time_struct_ptr; return res; } - return NULL; + return nullptr; } struct tm* os::gmtime_pd(const time_t* clock, struct tm* res) { const struct tm* time_struct_ptr = gmtime(clock); - if (time_struct_ptr != NULL) { + if (time_struct_ptr != nullptr) { *res = *time_struct_ptr; return res; } - return NULL; + return nullptr; } JNIEXPORT @@ -568,16 +568,16 @@ static OSThread* create_os_thread(Thread* thread, HANDLE thread_handle, int thread_id) { // Allocate the OSThread object OSThread* osthread = new OSThread(); - if (osthread == NULL) return NULL; + if (osthread == nullptr) return nullptr; // Initialize the JDK library's interrupt event. // This should really be done when OSThread is constructed, // but there is no way for a constructor to report failure to // allocate the event. - HANDLE interrupt_event = CreateEvent(NULL, true, false, NULL); - if (interrupt_event == NULL) { + HANDLE interrupt_event = CreateEvent(nullptr, true, false, nullptr); + if (interrupt_event == nullptr) { delete osthread; - return NULL; + return nullptr; } osthread->set_interrupt_event(interrupt_event); @@ -610,7 +610,7 @@ bool os::create_attached_thread(JavaThread* thread) { } OSThread* osthread = create_os_thread(thread, thread_h, (int)current_thread_id()); - if (osthread == NULL) { + if (osthread == nullptr) { return false; } @@ -631,9 +631,9 @@ bool os::create_main_thread(JavaThread* thread) { #ifdef ASSERT thread->verify_not_published(); #endif - if (_starting_thread == NULL) { + if (_starting_thread == nullptr) { _starting_thread = create_os_thread(thread, main_thread, main_thread_id); - if (_starting_thread == NULL) { + if (_starting_thread == nullptr) { return false; } } @@ -673,7 +673,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type, // Allocate the OSThread object OSThread* osthread = new OSThread(); - if (osthread == NULL) { + if (osthread == nullptr) { return false; } @@ -684,8 +684,8 @@ bool os::create_thread(Thread* thread, ThreadType thr_type, // This should really be done when OSThread is constructed, // but there is no way for a constructor to report failure to // allocate the event. - HANDLE interrupt_event = CreateEvent(NULL, true, false, NULL); - if (interrupt_event == NULL) { + HANDLE interrupt_event = CreateEvent(nullptr, true, false, nullptr); + if (interrupt_event == nullptr) { delete osthread; return false; } @@ -745,17 +745,17 @@ bool os::create_thread(Thread* thread, ThreadType thr_type, int limit = 3; do { thread_handle = - (HANDLE)_beginthreadex(NULL, + (HANDLE)_beginthreadex(nullptr, (unsigned)stack_size, &os::win32::thread_native_entry, thread, initflag, &thread_id); - } while (thread_handle == NULL && errno == EAGAIN && limit-- > 0); + } while (thread_handle == nullptr && errno == EAGAIN && limit-- > 0); ResourceMark rm; char buf[64]; - if (thread_handle != NULL) { + if (thread_handle != nullptr) { log_info(os, thread)("Thread \"%s\" started (tid: %u, attributes: %s)", thread->name(), thread_id, describe_beginthreadex_attributes(buf, sizeof(buf), stack_size, initflag)); @@ -768,9 +768,9 @@ bool os::create_thread(Thread* thread, ThreadType thr_type, os::print_memory_info(&st); } - if (thread_handle == NULL) { + if (thread_handle == nullptr) { // Need to clean up stuff we've allocated so far - thread->set_osthread(NULL); + thread->set_osthread(nullptr); delete osthread; return false; } @@ -789,7 +789,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type, // Free Win32 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. @@ -890,8 +890,8 @@ uint os::processor_id() { // For dynamic lookup of SetThreadDescription API typedef HRESULT (WINAPI *SetThreadDescriptionFnPtr)(HANDLE, PCWSTR); typedef HRESULT (WINAPI *GetThreadDescriptionFnPtr)(HANDLE, PWSTR*); -static SetThreadDescriptionFnPtr _SetThreadDescription = NULL; -DEBUG_ONLY(static GetThreadDescriptionFnPtr _GetThreadDescription = NULL;) +static SetThreadDescriptionFnPtr _SetThreadDescription = nullptr; +DEBUG_ONLY(static GetThreadDescriptionFnPtr _GetThreadDescription = nullptr;) // forward decl. static errno_t convert_to_unicode(char const* char_path, LPWSTR* unicode_path); @@ -902,7 +902,7 @@ void os::set_native_thread_name(const char *name) { // for setting the thread name/description: // https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreaddescription - if (_SetThreadDescription != NULL) { + if (_SetThreadDescription != nullptr) { // SetThreadDescription takes a PCWSTR but we have conversion routines that produce // LPWSTR. The only difference is that PCWSTR is a pointer to const WCHAR. LPWSTR unicode_name; @@ -1152,13 +1152,13 @@ void os::shutdown() { // Check for abort hook abort_hook_t abort_hook = Arguments::abort_hook(); - if (abort_hook != NULL) { + if (abort_hook != nullptr) { abort_hook(); } } -static HANDLE dumpFile = NULL; +static HANDLE dumpFile = nullptr; // Check if dump file can be created. void os::check_dump_limit(char* buffer, size_t buffsz) { @@ -1176,16 +1176,16 @@ void os::check_dump_limit(char* buffer, size_t buffsz) { #endif if (status) { - const char* cwd = get_current_directory(NULL, 0); + const char* cwd = get_current_directory(nullptr, 0); int pid = current_process_id(); - if (cwd != NULL) { + if (cwd != nullptr) { jio_snprintf(buffer, buffsz, "%s\\hs_err_pid%u.mdmp", cwd, pid); } else { jio_snprintf(buffer, buffsz, ".\\hs_err_pid%u.mdmp", pid); } - if (dumpFile == NULL && - (dumpFile = CreateFile(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) + if (dumpFile == nullptr && + (dumpFile = CreateFile(buffer, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)) == INVALID_HANDLE_VALUE) { jio_snprintf(buffer, buffsz, "Failed to create minidump file (0x%x).", GetLastError()); status = false; @@ -1204,8 +1204,8 @@ void os::abort(bool dump_core, void* siginfo, const void* context) { MINIDUMP_TYPE dumpType; shutdown(); - if (!dump_core || dumpFile == NULL) { - if (dumpFile != NULL) { + if (!dump_core || dumpFile == nullptr) { + if (dumpFile != nullptr) { CloseHandle(dumpFile); } win32::exit_process_or_thread(win32::EPT_PROCESS, 1); @@ -1214,7 +1214,7 @@ void os::abort(bool dump_core, void* siginfo, const void* context) { dumpType = (MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithHandleData | MiniDumpWithFullMemoryInfo | MiniDumpWithThreadInfo | MiniDumpWithUnloadedModules); - if (siginfo != NULL && context != NULL) { + if (siginfo != nullptr && context != nullptr) { ep.ContextRecord = (PCONTEXT) context; ep.ExceptionRecord = (PEXCEPTION_RECORD) siginfo; @@ -1222,13 +1222,13 @@ void os::abort(bool dump_core, void* siginfo, const void* context) { mei.ExceptionPointers = &ep; pmei = &mei; } else { - pmei = NULL; + pmei = nullptr; } // Older versions of dbghelp.dll (the one shipped with Win2003 for example) may not support all // the dump types we really want. If first call fails, lets fall back to just use MiniDumpWithFullMemory then. - if (!WindowsDbgHelp::miniDumpWriteDump(hProcess, processId, dumpFile, dumpType, pmei, NULL, NULL) && - !WindowsDbgHelp::miniDumpWriteDump(hProcess, processId, dumpFile, (MINIDUMP_TYPE)MiniDumpWithFullMemory, pmei, NULL, NULL)) { + if (!WindowsDbgHelp::miniDumpWriteDump(hProcess, processId, dumpFile, dumpType, pmei, nullptr, nullptr) && + !WindowsDbgHelp::miniDumpWriteDump(hProcess, processId, dumpFile, (MINIDUMP_TYPE)MiniDumpWithFullMemory, pmei, nullptr, nullptr)) { jio_fprintf(stderr, "Call to MiniDumpWriteDump() failed (Error 0x%x)\n", GetLastError()); } CloseHandle(dumpFile); @@ -1246,11 +1246,11 @@ void os::dll_unload(void *lib) { snprintf(name, MAX_PATH, ""); } if (::FreeLibrary((HMODULE)lib)) { - Events::log_dll_message(NULL, "Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib)); + Events::log_dll_message(nullptr, "Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib)); log_info(os)("Unloaded dll \"%s\" [" INTPTR_FORMAT "]", name, p2i(lib)); } else { const DWORD errcode = ::GetLastError(); - Events::log_dll_message(NULL, "Attempt to unload dll \"%s\" [" INTPTR_FORMAT "] failed (error code %d)", name, p2i(lib), errcode); + Events::log_dll_message(nullptr, "Attempt to unload dll \"%s\" [" INTPTR_FORMAT "] failed (error code %d)", name, p2i(lib), errcode); log_info(os)("Attempt to unload dll \"%s\" [" INTPTR_FORMAT "] failed (error code %d)", name, p2i(lib), errcode); } } @@ -1268,7 +1268,7 @@ void* os::dll_lookup(void *lib, const char *name) { // duplicate slashes and converts all instances of '/' into '\\'. DIR * os::opendir(const char *dirname) { - assert(dirname != NULL, "just checking"); // hotspot change + assert(dirname != nullptr, "just checking"); // hotspot change DIR *dirp = (DIR *)malloc(sizeof(DIR), mtInternal); DWORD fattr; // hotspot change char alt_dirname[4] = { 0, 0, 0, 0 }; @@ -1334,9 +1334,9 @@ DIR * os::opendir(const char *dirname) { } struct dirent * os::readdir(DIR *dirp) { - assert(dirp != NULL, "just checking"); // hotspot change + assert(dirp != nullptr, "just checking"); // hotspot change if (dirp->handle == INVALID_HANDLE_VALUE) { - return NULL; + return nullptr; } strcpy(dirp->dirent.d_name, dirp->find_data.cFileName); @@ -1344,7 +1344,7 @@ struct dirent * os::readdir(DIR *dirp) { if (!FindNextFile(dirp->handle, &dirp->find_data)) { if (GetLastError() == ERROR_INVALID_HANDLE) { errno = EBADF; - return NULL; + return nullptr; } FindClose(dirp->handle); dirp->handle = INVALID_HANDLE_VALUE; @@ -1354,7 +1354,7 @@ struct dirent * os::readdir(DIR *dirp) { } int os::closedir(DIR *dirp) { - assert(dirp != NULL, "just checking"); // hotspot change + assert(dirp != nullptr, "just checking"); // hotspot change if (dirp->handle != INVALID_HANDLE_VALUE) { if (!FindClose(dirp->handle)) { errno = EBADF; @@ -1398,7 +1398,7 @@ static bool _addr_in_ntdll(address addr) { MODULEINFO minfo; hmod = GetModuleHandle("NTDLL.DLL"); - if (hmod == NULL) return false; + if (hmod == nullptr) return false; if (!GetModuleInformation(GetCurrentProcess(), hmod, &minfo, sizeof(MODULEINFO))) { return false; @@ -1440,7 +1440,7 @@ static int _locate_module_by_addr(const char * mod_fname, address base_addr, bool os::dll_address_to_library_name(address addr, char* buf, int buflen, int* offset) { // buf is not optional, but offset is optional - assert(buf != NULL, "sanity check"); + assert(buf != nullptr, "sanity check"); // NOTE: the reason we don't use SymGetModuleInfo() is it doesn't always // return the full path to the DLL file, sometimes it returns path @@ -1466,12 +1466,12 @@ 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"); if (Decoder::decode(addr, buf, buflen, offset, demangle)) { return true; } - if (offset != NULL) *offset = -1; + if (offset != nullptr) *offset = -1; buf[0] = '\0'; return false; } @@ -1522,8 +1522,8 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) { log_info(os)("attempting shared library load of %s", name); void * result = LoadLibrary(name); - if (result != NULL) { - Events::log_dll_message(NULL, "Loaded shared library %s", name); + if (result != nullptr) { + Events::log_dll_message(nullptr, "Loaded shared library %s", name); // Recalculate pdb search path if a DLL was loaded successfully. SymbolEngine::recalc_search_path(); log_info(os)("shared library load of %s was successful", name); @@ -1534,13 +1534,13 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) { // It may or may not be overwritten below (in the for loop and just above) lasterror(ebuf, (size_t) ebuflen); ebuf[ebuflen - 1] = '\0'; - Events::log_dll_message(NULL, "Loading shared library %s failed, error code %lu", name, errcode); + Events::log_dll_message(nullptr, "Loading shared library %s failed, error code %lu", name, errcode); log_info(os)("shared library load of %s failed, error code %lu", name, errcode); if (errcode == ERROR_MOD_NOT_FOUND) { strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1); ebuf[ebuflen - 1] = '\0'; - return NULL; + return nullptr; } // Parsing dll below @@ -1550,7 +1550,7 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) { // else call os::lasterror to obtain system error message int fd = ::open(name, O_RDONLY | O_BINARY, 0); if (fd < 0) { - return NULL; + return nullptr; } uint32_t signature_offset; @@ -1576,7 +1576,7 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) { ::close(fd); if (failed_to_get_lib_arch) { // file i/o error - report os::lasterror(...) msg - return NULL; + return nullptr; } typedef struct { @@ -1604,7 +1604,7 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) { // Obtain a string for printf operation // lib_arch_str shall contain string what platform this .dll was built for // running_arch_str shall string contain what platform Hotspot was built for - char *running_arch_str = NULL, *lib_arch_str = NULL; + char *running_arch_str = nullptr, *lib_arch_str = nullptr; for (unsigned int i = 0; i < ARRAY_SIZE(arch_array); i++) { if (lib_arch == arch_array[i].arch_code) { lib_arch_str = arch_array[i].arch_name; @@ -1620,10 +1620,10 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) { // If the architecture is right // but some other error took place - report os::lasterror(...) msg if (lib_arch == running_arch) { - return NULL; + return nullptr; } - if (lib_arch_str != NULL) { + if (lib_arch_str != nullptr) { ::_snprintf(ebuf, ebuflen - 1, "Can't load %s-bit .dll on a %s-bit platform", lib_arch_str, running_arch_str); @@ -1634,7 +1634,7 @@ void * os::dll_load(const char *name, char *ebuf, int ebuflen) { lib_arch, running_arch_str); } - return NULL; + return nullptr; } void os::print_dll_info(outputStream *st) { @@ -1653,7 +1653,7 @@ int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *pa int pid = os::current_process_id(); hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); - if (hProcess == NULL) return 0; + if (hProcess == nullptr) return 0; DWORD size_needed; if (!EnumProcessModules(hProcess, modules, sizeof(modules), &size_needed)) { @@ -1672,7 +1672,7 @@ int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *pa MODULEINFO modinfo; if (!GetModuleInformation(hProcess, modules[i], &modinfo, sizeof(modinfo))) { - modinfo.lpBaseOfDll = NULL; + modinfo.lpBaseOfDll = nullptr; modinfo.SizeOfImage = 0; } @@ -1696,7 +1696,7 @@ void os::get_summary_os_info(char* buf, size_t buflen) { os::win32::print_windows_version(&sst); // chop off newline character char* nl = strchr(buf, '\n'); - if (nl != NULL) *nl = '\0'; + if (nl != nullptr) *nl = '\0'; } int os::vsnprintf(char* buf, size_t len, const char* fmt, va_list args) { @@ -1767,19 +1767,19 @@ void os::win32::print_windows_version(outputStream* st) { } strncat(kernel32_path, "\\kernel32.dll", MAX_PATH - ret); - DWORD version_size = GetFileVersionInfoSize(kernel32_path, NULL); + DWORD version_size = GetFileVersionInfoSize(kernel32_path, nullptr); if (version_size == 0) { st->print_cr("Call to GetFileVersionInfoSize failed"); return; } LPTSTR version_info = (LPTSTR)os::malloc(version_size, mtInternal); - if (version_info == NULL) { + if (version_info == nullptr) { st->print_cr("Failed to allocate version_info"); return; } - if (!GetFileVersionInfo(kernel32_path, NULL, version_size, version_info)) { + if (!GetFileVersionInfo(kernel32_path, 0, version_size, version_info)) { os::free(version_info); st->print_cr("Call to GetFileVersionInfo failed"); return; @@ -1886,7 +1886,7 @@ void os::get_summary_cpu_info(char* buf, size_t buflen) { "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &key); if (status == ERROR_SUCCESS) { DWORD size = (DWORD)buflen; - status = RegQueryValueEx(key, "ProcessorNameString", NULL, NULL, (byte*)buf, &size); + status = RegQueryValueEx(key, "ProcessorNameString", nullptr, nullptr, (byte*)buf, &size); if (status != ERROR_SUCCESS) { strncpy(buf, "## __CPU__", buflen); } else { @@ -1962,7 +1962,7 @@ void os::print_siginfo(outputStream *st, const void* siginfo) { st->print("siginfo:"); char tmp[64]; - if (os::exception_name(er->ExceptionCode, tmp, sizeof(tmp)) == NULL) { + if (os::exception_name(er->ExceptionCode, tmp, sizeof(tmp)) == nullptr) { strcpy(tmp, "EXCEPTION_??"); } st->print(" %s (0x%x)", tmp, er->ExceptionCode); @@ -2022,7 +2022,7 @@ void os::jvm_path(char *buf, jint buflen) { // looks like jvm.dll is installed there (append a fake suffix // hotspot/jvm.dll). 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 && strlen(java_home_var) < (size_t)buflen) { strncpy(buf, java_home_var, buflen); @@ -2070,12 +2070,12 @@ size_t os::lasterror(char* buf, size_t len) { // DOS error size_t n = (size_t)FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, + nullptr, errval, 0, buf, (DWORD)len, - NULL); + nullptr); if (n > 3) { // Drop final '.', CR, LF if (buf[n - 1] == '\n') n--; @@ -2112,7 +2112,7 @@ int os::get_last_error() { // a signal handler for SIGBREAK is installed then that signal handler // takes priority over the console control handler for CTRL_CLOSE_EVENT. // See bug 4416763. -static signal_handler_t sigbreakHandler = NULL; +static signal_handler_t sigbreakHandler = nullptr; static void UserHandler(int sig) { os::signal_notify(sig); @@ -2167,7 +2167,7 @@ static BOOL WINAPI consoleHandler(DWORD event) { return TRUE; break; case CTRL_BREAK_EVENT: - if (sigbreakHandler != NULL) { + if (sigbreakHandler != nullptr) { (*sigbreakHandler)(SIGBREAK); } return TRUE; @@ -2177,9 +2177,9 @@ static BOOL WINAPI consoleHandler(DWORD event) { // such as a service process. USEROBJECTFLAGS flags; HANDLE handle = GetProcessWindowStation(); - if (handle != NULL && + if (handle != nullptr && GetUserObjectInformation(handle, UOI_FLAGS, &flags, - sizeof(USEROBJECTFLAGS), NULL)) { + sizeof(USEROBJECTFLAGS), nullptr)) { // If it is a non-interactive session, let next handler to deal // with it. if ((flags.dwFlags & WSF_VISIBLE) == 0) { @@ -2209,7 +2209,7 @@ int os::sigexitnum_pd() { // a counter for each possible signal value, including signal_thread exit signal static volatile jint pending_signals[NSIG+1] = { 0 }; -static Semaphore* sig_sem = NULL; +static Semaphore* sig_sem = nullptr; static void jdk_misc_signal_init() { // Initialize signal structures @@ -2246,7 +2246,7 @@ static void jdk_misc_signal_init() { } void os::signal_notify(int sig) { - if (sig_sem != NULL) { + if (sig_sem != nullptr) { Atomic::inc(&pending_signals[sig]); sig_sem->signal(); } else { @@ -2373,7 +2373,7 @@ const char* os::exception_name(int exception_code, char *buf, size_t size) { } } - return NULL; + return nullptr; } //----------------------------------------------------------------------------- @@ -2447,7 +2447,7 @@ LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo) { } } - if (prev_uef_handler != NULL) { + if (prev_uef_handler != nullptr) { // We didn't handle this exception so pass it to the previous // UnhandledExceptionFilter. return (prev_uef_handler)(exceptionInfo); @@ -2580,7 +2580,7 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) { } #endif - if (t != NULL && t->is_Java_thread()) { + if (t != nullptr && t->is_Java_thread()) { JavaThread* thread = JavaThread::cast(t); bool in_java = thread->thread_state() == _thread_in_Java; bool in_native = thread->thread_state() == _thread_in_native; @@ -2632,7 +2632,7 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) { // We only expect null pointers in the stubs (vtable) // the rest are checked explicitly now. CodeBlob* cb = CodeCache::find_blob(pc); - if (cb != NULL) { + if (cb != nullptr) { if (SafepointMechanism::is_poll_address(addr)) { address stub = SharedRuntime::get_poll_stub(pc); return Handle_Exception(exceptionInfo, stub); @@ -2651,7 +2651,7 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) { // Null pointer exception. if (MacroAssembler::uses_implicit_null_check((void*)addr)) { address stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); - if (stub != NULL) return Handle_Exception(exceptionInfo, stub); + if (stub != nullptr) return Handle_Exception(exceptionInfo, stub); } report_error(t, exception_code, pc, exception_record, exceptionInfo->ContextRecord); @@ -2678,15 +2678,15 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) { // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if (exception_code == EXCEPTION_IN_PAGE_ERROR) { - CompiledMethod* nm = NULL; + CompiledMethod* nm = nullptr; if (in_java) { CodeBlob* cb = CodeCache::find_blob(pc); - nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL; + nm = (cb != nullptr) ? cb->as_compiled_method_or_null() : nullptr; } bool is_unsafe_arraycopy = (in_native || in_java) && UnsafeCopyMemory::contains_pc(pc); if (((in_vm || in_native || is_unsafe_arraycopy) && thread->doing_unsafe_access()) || - (nm != NULL && nm->has_unsafe_access())) { + (nm != nullptr && nm->has_unsafe_access())) { address next_pc = Assembler::locate_next_instruction(pc); if (is_unsafe_arraycopy) { next_pc = UnsafeCopyMemory::page_error_continue_pc(pc); @@ -2731,7 +2731,7 @@ LONG WINAPI topLevelExceptionFilter(struct _EXCEPTION_POINTERS* exceptionInfo) { // If it is, patch return address to be deopt handler. if (NativeDeoptInstruction::is_deopt_at(pc)) { CodeBlob* cb = CodeCache::find_blob(pc); - if (cb != NULL && cb->is_compiled()) { + if (cb != nullptr && cb->is_compiled()) { CompiledMethod* cm = cb->as_compiled_method(); frame fr = os::fetch_frame_from_context((void*)exceptionInfo->ContextRecord); address deopt = cm->is_method_handle_return(pc) ? @@ -2775,7 +2775,7 @@ LONG WINAPI topLevelVectoredExceptionFilter(struct _EXCEPTION_POINTERS* exceptio // If the exception occurred in the codeCache, pass control // to our normal exception handler. CodeBlob* cb = CodeCache::find_blob(pc); - if (cb != NULL) { + if (cb != nullptr) { return topLevelExceptionFilter(exceptionInfo); } @@ -2899,7 +2899,7 @@ class NUMANodeListHolder { public: NUMANodeListHolder() { _numa_used_node_count = 0; - _numa_used_node_list = NULL; + _numa_used_node_list = nullptr; // do rest of initialization in build routine (after function pointers are set up) } @@ -2940,11 +2940,11 @@ static bool request_lock_memory_privilege() { os::current_process_id()); bool success = false; - HANDLE hToken = NULL; + HANDLE hToken = nullptr; LUID luid; - if (hProcess != NULL && + if (hProcess != nullptr && OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken) && - LookupPrivilegeValue(NULL, "SeLockMemoryPrivilege", &luid)) { + LookupPrivilegeValue(nullptr, "SeLockMemoryPrivilege", &luid)) { TOKEN_PRIVILEGES tp; tp.PrivilegeCount = 1; @@ -2953,17 +2953,17 @@ static bool request_lock_memory_privilege() { // AdjustTokenPrivileges() may return TRUE even when it couldn't change the // privilege. Check GetLastError() too. See MSDN document. - if (AdjustTokenPrivileges(hToken, false, &tp, sizeof(tp), NULL, NULL) && + if (AdjustTokenPrivileges(hToken, false, &tp, sizeof(tp), nullptr, nullptr) && (GetLastError() == ERROR_SUCCESS)) { success = true; } } // Cleanup - if (hProcess != NULL) { + if (hProcess != nullptr) { CloseHandle(hProcess); } - if (hToken != NULL) { + if (hToken != nullptr) { CloseHandle(hToken); } @@ -3023,14 +3023,14 @@ static char* allocate_pages_individually(size_t bytes, char* addr, DWORD flags, const size_t size_of_reserve = bytes + chunk_size; if (bytes > size_of_reserve) { // Overflowed. - return NULL; + return nullptr; } p_buf = (char *) virtualAlloc(addr, size_of_reserve, // size of Reserve MEM_RESERVE, PAGE_READWRITE); - // If reservation failed, return NULL - if (p_buf == NULL) return NULL; + // If reservation failed, return null + if (p_buf == nullptr) return nullptr; MemTracker::record_virtual_memory_reserve((address)p_buf, size_of_reserve, CALLER_PC); os::release_memory(p_buf, bytes + chunk_size); @@ -3068,7 +3068,7 @@ static char* allocate_pages_individually(size_t bytes, char* addr, DWORD flags, #endif if (inject_error_now) { - p_new = NULL; + p_new = nullptr; } else { if (!UseNUMAInterleaving) { p_new = (char *) virtualAlloc(next_alloc_addr, @@ -3083,7 +3083,7 @@ static char* allocate_pages_individually(size_t bytes, char* addr, DWORD flags, } } - if (p_new == NULL) { + if (p_new == nullptr) { // Free any allocated pages if (next_alloc_addr > p_buf) { // Some memory was committed so release it. @@ -3100,7 +3100,7 @@ static char* allocate_pages_individually(size_t bytes, char* addr, DWORD flags, log_develop_debug(pagesize)("Reserving pages individually failed."); } #endif - return NULL; + return nullptr; } bytes_remaining -= bytes_to_rq; @@ -3173,7 +3173,7 @@ int os::create_file_for_heap(const char* dir) { size_t fullname_len = strlen(dir) + strlen(name_template); char *fullname = (char*)os::malloc(fullname_len + 1, mtInternal); - if (fullname == NULL) { + if (fullname == nullptr) { vm_exit_during_initialization(err_msg("Malloc failed during creation of backing file for heap (%s)", os::strerror(errno))); return -1; } @@ -3183,7 +3183,7 @@ int os::create_file_for_heap(const char* dir) { os::native_path(fullname); char *path = _mktemp(fullname); - if (path == NULL) { + if (path == nullptr) { warning("_mktemp could not create file name from template %s (%s)", fullname, os::strerror(errno)); os::free(fullname); return -1; @@ -3199,19 +3199,19 @@ int os::create_file_for_heap(const char* dir) { return fd; } -// If 'base' is not NULL, function will return NULL if it cannot get 'base' +// If 'base' is not null, function will return null if it cannot get 'base' char* os::map_memory_to_file(char* base, size_t size, int fd) { assert(fd != -1, "File descriptor is not valid"); HANDLE fh = (HANDLE)_get_osfhandle(fd); #ifdef _LP64 - HANDLE fileMapping = CreateFileMapping(fh, NULL, PAGE_READWRITE, - (DWORD)(size >> 32), (DWORD)(size & 0xFFFFFFFF), NULL); + HANDLE fileMapping = CreateFileMapping(fh, nullptr, PAGE_READWRITE, + (DWORD)(size >> 32), (DWORD)(size & 0xFFFFFFFF), nullptr); #else - HANDLE fileMapping = CreateFileMapping(fh, NULL, PAGE_READWRITE, - 0, (DWORD)size, NULL); + HANDLE fileMapping = CreateFileMapping(fh, nullptr, PAGE_READWRITE, + 0, (DWORD)size, nullptr); #endif - if (fileMapping == NULL) { + if (fileMapping == nullptr) { if (GetLastError() == ERROR_DISK_FULL) { vm_exit_during_initialization(err_msg("Could not allocate sufficient disk space for Java heap")); } @@ -3219,7 +3219,7 @@ char* os::map_memory_to_file(char* base, size_t size, int fd) { vm_exit_during_initialization(err_msg("Error in mapping Java heap at the given filesystem directory")); } - return NULL; + return nullptr; } LPVOID addr = mapViewOfFileEx(fileMapping, FILE_MAP_WRITE, 0, 0, size, base); @@ -3231,7 +3231,7 @@ char* os::map_memory_to_file(char* base, size_t size, int fd) { char* os::replace_existing_mapping_with_file_mapping(char* base, size_t size, int fd) { assert(fd != -1, "File descriptor is not valid"); - assert(base != NULL, "Base address cannot be NULL"); + assert(base != nullptr, "Base address cannot be null"); release_memory(base, size); return map_memory_to_file(base, size, fd); @@ -3248,14 +3248,14 @@ static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int fi size_t extra_size = size + alignment; assert(extra_size >= size, "overflow, size is too large to allow alignment"); - char* aligned_base = NULL; + char* aligned_base = nullptr; static const int max_attempts = 20; - for (int attempt = 0; attempt < max_attempts && aligned_base == NULL; attempt ++) { + for (int attempt = 0; attempt < max_attempts && aligned_base == nullptr; attempt ++) { char* extra_base = file_desc != -1 ? os::map_memory_to_file(extra_size, file_desc) : os::reserve_memory(extra_size); - if (extra_base == NULL) { - return NULL; + if (extra_base == nullptr) { + return nullptr; } // Do manual alignment aligned_base = align_up(extra_base, alignment); @@ -3264,7 +3264,7 @@ static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int fi os::release_memory(extra_base, extra_size); assert(rc, "release failed"); if (!rc) { - return NULL; + return nullptr; } // Attempt to map, into the just vacated space, the slightly smaller aligned area. @@ -3273,7 +3273,7 @@ static char* map_or_reserve_memory_aligned(size_t size, size_t alignment, int fi os::attempt_reserve_memory_at(aligned_base, size); } - assert(aligned_base != NULL, "Did not manage to re-map after %d attempts?", max_attempts); + assert(aligned_base != nullptr, "Did not manage to re-map after %d attempts?", max_attempts); return aligned_base; } @@ -3288,7 +3288,7 @@ char* os::map_memory_to_file_aligned(size_t size, size_t alignment, int fd) { } char* os::pd_reserve_memory(size_t bytes, bool exec) { - return pd_attempt_reserve_memory_at(NULL /* addr */, bytes, exec); + return pd_attempt_reserve_memory_at(nullptr /* addr */, bytes, exec); } // Reserve memory at an arbitrary address, only if that area is @@ -3309,7 +3309,7 @@ char* os::pd_attempt_reserve_memory_at(char* addr, size_t bytes, bool exec) { // in numa interleaving, we have to allocate pages individually // (well really chunks of NUMAInterleaveGranularity size) res = allocate_pages_individually(bytes, addr, MEM_RESERVE, PAGE_READWRITE); - if (res == NULL) { + if (res == nullptr) { warning("NUMA page allocation failed"); } if (Verbose && PrintMiscellaneous) { @@ -3318,7 +3318,7 @@ char* os::pd_attempt_reserve_memory_at(char* addr, size_t bytes, bool exec) { reserveTimer.milliseconds(), reserveTimer.ticks()); } } - assert(res == NULL || addr == NULL || addr == res, + assert(res == nullptr || addr == nullptr || addr == res, "Unexpected address from reserve."); return res; @@ -3351,7 +3351,7 @@ static char* reserve_large_pages_individually(size_t size, char* req_addr, bool const DWORD flags = MEM_RESERVE | MEM_COMMIT | MEM_LARGE_PAGES; char * p_buf = allocate_pages_individually(size, req_addr, flags, prot, LargePagesIndividualAllocationInjectError); - if (p_buf == NULL) { + if (p_buf == nullptr) { // give an appropriate warning message if (UseNUMAInterleaving) { warning("NUMA large page allocation failed, UseLargePages flag ignored"); @@ -3360,7 +3360,7 @@ static char* reserve_large_pages_individually(size_t size, char* req_addr, bool warning("Individually allocated large pages failed, " "use -XX:-UseLargePagesIndividualAllocation to turn off"); } - return NULL; + return nullptr; } return p_buf; } @@ -3387,7 +3387,7 @@ static char* reserve_large_pages(size_t size, char* req_addr, bool exec) { static char* find_aligned_address(size_t size, size_t alignment) { // Temporary reserve memory large enough to ensure we can get the requested // alignment and still fit the reservation. - char* addr = (char*) virtualAlloc(NULL, size + alignment, MEM_RESERVE, PAGE_NOACCESS); + char* addr = (char*) virtualAlloc(nullptr, size + alignment, MEM_RESERVE, PAGE_NOACCESS); // Align the address to the requested alignment. char* aligned_addr = align_up(addr, alignment); // Free the temporary reservation. @@ -3410,7 +3410,7 @@ static char* reserve_large_pages_aligned(size_t size, size_t alignment, bool exe // Try to do the large page reservation using the aligned address. aligned_address = reserve_large_pages(size, aligned_address, exec); - if (aligned_address != NULL) { + if (aligned_address != nullptr) { // Reservation at the aligned address succeeded. guarantee(is_aligned(aligned_address, alignment), "Must be aligned"); return aligned_address; @@ -3418,7 +3418,7 @@ static char* reserve_large_pages_aligned(size_t size, size_t alignment, bool exe } log_debug(pagesize)("Failed reserving large pages at aligned address"); - return NULL; + return nullptr; } char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, size_t page_size, char* addr, @@ -3430,14 +3430,14 @@ char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, size_t page_ if (!is_aligned(bytes, page_size)) { // Fallback to small pages, Windows does not support mixed mappings. - return NULL; + return nullptr; } // The requested alignment can be larger than the page size, for example with G1 // the alignment is bound to the heap region size. So this reservation needs to // ensure that the requested alignment is met. When there is a requested address // this solves it self, since it must be properly aligned already. - if (addr == NULL && alignment > page_size) { + if (addr == nullptr && alignment > page_size) { return reserve_large_pages_aligned(bytes, alignment, exec); } @@ -3446,7 +3446,7 @@ char* os::pd_reserve_memory_special(size_t bytes, size_t alignment, size_t page_ } bool os::pd_release_memory_special(char* base, size_t bytes) { - assert(base != NULL, "Sanity check"); + assert(base != nullptr, "Sanity check"); return pd_release_memory(base, bytes); } @@ -3473,7 +3473,7 @@ bool os::pd_commit_memory(char* addr, size_t bytes, bool exec) { // is always within a reserve covered by a single VirtualAlloc // in that case we can just do a single commit for the requested size if (!UseNUMAInterleaving) { - if (virtualAlloc(addr, bytes, MEM_COMMIT, PAGE_READWRITE) == NULL) { + if (virtualAlloc(addr, bytes, MEM_COMMIT, PAGE_READWRITE) == nullptr) { NOT_PRODUCT(warn_fail_commit_memory(addr, bytes, exec);) return false; } @@ -3499,7 +3499,7 @@ bool os::pd_commit_memory(char* addr, size_t bytes, bool exec) { VirtualQuery(next_alloc_addr, &alloc_info, sizeof(alloc_info)); size_t bytes_to_rq = MIN2(bytes_remaining, (size_t)alloc_info.RegionSize); if (virtualAlloc(next_alloc_addr, bytes_to_rq, MEM_COMMIT, - PAGE_READWRITE) == NULL) { + PAGE_READWRITE) == nullptr) { NOT_PRODUCT(warn_fail_commit_memory(next_alloc_addr, bytes_to_rq, exec);) return false; @@ -3529,7 +3529,7 @@ bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint, void os::pd_commit_memory_or_exit(char* addr, size_t size, bool exec, const char* mesg) { - assert(mesg != NULL, "mesg must be specified"); + assert(mesg != nullptr, "mesg must be specified"); if (!pd_commit_memory(addr, size, exec)) { warn_fail_commit_memory(addr, size, exec); vm_exit_out_of_memory(size, OOM_MMAP_ERROR, "%s", mesg); @@ -3566,7 +3566,7 @@ bool os::pd_release_memory(char* addr, size_t bytes) { do { // Find mapping and check it - const char* err = NULL; + const char* err = nullptr; if (!os::win32::find_mapping(p, &mi)) { err = "no mapping found"; } else { @@ -3588,7 +3588,7 @@ bool os::pd_release_memory(char* addr, size_t bytes) { } } // Handle mapping error. We assert in debug, unconditionally print a warning in release. - if (err != NULL) { + if (err != nullptr) { log_warning(os)("bad release: [" PTR_FORMAT "-" PTR_FORMAT "): %s", p2i(start), p2i(end), err); #ifdef ASSERT os::print_memory_mappings((char*)start, bytes, tty); @@ -3923,26 +3923,26 @@ HINSTANCE os::win32::load_Windows_dll(const char* name, char *ebuf, char path[MAX_PATH]; DWORD size; DWORD pathLen = (DWORD)sizeof(path); - HINSTANCE result = NULL; + HINSTANCE result = nullptr; // only allow library name without path component - assert(strchr(name, '\\') == NULL, "path not allowed"); - assert(strchr(name, ':') == NULL, "path not allowed"); - if (strchr(name, '\\') != NULL || strchr(name, ':') != NULL) { + assert(strchr(name, '\\') == nullptr, "path not allowed"); + assert(strchr(name, ':') == nullptr, "path not allowed"); + if (strchr(name, '\\') != nullptr || strchr(name, ':') != nullptr) { jio_snprintf(ebuf, ebuflen, "Invalid parameter while calling os::win32::load_windows_dll(): cannot take path: %s", name); - return NULL; + return nullptr; } // search system directory if ((size = GetSystemDirectory(path, pathLen)) > 0) { if (size >= pathLen) { - return NULL; // truncated + return nullptr; // truncated } if (jio_snprintf(path + size, pathLen - size, "\\%s", name) == -1) { - return NULL; // truncated + return nullptr; // truncated } - if ((result = (HINSTANCE)os::dll_load(path, ebuf, ebuflen)) != NULL) { + if ((result = (HINSTANCE)os::dll_load(path, ebuf, ebuflen)) != nullptr) { return result; } } @@ -3950,19 +3950,19 @@ HINSTANCE os::win32::load_Windows_dll(const char* name, char *ebuf, // try Windows directory if ((size = GetWindowsDirectory(path, pathLen)) > 0) { if (size >= pathLen) { - return NULL; // truncated + return nullptr; // truncated } if (jio_snprintf(path + size, pathLen - size, "\\%s", name) == -1) { - return NULL; // truncated + return nullptr; // truncated } - if ((result = (HINSTANCE)os::dll_load(path, ebuf, ebuflen)) != NULL) { + if ((result = (HINSTANCE)os::dll_load(path, ebuf, ebuflen)) != nullptr) { return result; } } jio_snprintf(ebuf, ebuflen, "os::win32::load_windows_dll() cannot load %s from system directories.", name); - return NULL; + return nullptr; } #define MAXIMUM_THREADS_TO_KEEP (16 * MAXIMUM_WAIT_OBJECTS) @@ -4002,7 +4002,7 @@ int os::win32::exit_process_or_thread(Ept what, int exit_code) { bool registered = false; // The first thread that reached this point, initializes the critical section. - if (!InitOnceExecuteOnce(&init_once_crit_sect, init_crit_sect_call, &crit_sect, NULL)) { + if (!InitOnceExecuteOnce(&init_once_crit_sect, init_crit_sect_call, &crit_sect, nullptr)) { warning("crit_sect initialization failed in %s: %d\n", __FILE__, __LINE__); } else if (Atomic::load_acquire(&process_exiting) == 0) { if (what != EPT_THREAD) { @@ -4171,7 +4171,7 @@ void os::wait_for_keypress_at_exit(void) { bool os::message_box(const char* title, const char* message) { - int result = MessageBox(NULL, message, title, + int result = MessageBox(nullptr, message, title, MB_YESNO | MB_ICONERROR | MB_SYSTEMMODAL | MB_DEFAULT_DESKTOP_ONLY); return result == IDYES; } @@ -4331,7 +4331,7 @@ jint os::init_2(void) { // Lookup SetThreadDescription - the docs state we must use runtime-linking of // kernelbase.dll, so that is what we do. HINSTANCE _kernelbase = LoadLibrary(TEXT("kernelbase.dll")); - if (_kernelbase != NULL) { + if (_kernelbase != nullptr) { _SetThreadDescription = reinterpret_cast( GetProcAddress(_kernelbase, @@ -4343,7 +4343,7 @@ jint os::init_2(void) { "GetThreadDescription")); #endif } - log_info(os, thread)("The SetThreadDescription API is%s available.", _SetThreadDescription == NULL ? " not" : ""); + log_info(os, thread)("The SetThreadDescription API is%s available.", _SetThreadDescription == nullptr ? " not" : ""); return JNI_OK; @@ -4379,7 +4379,7 @@ static errno_t convert_to_unicode(char const* char_path, LPWSTR* unicode_path) { int unicode_path_len = MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, char_path, -1, - NULL, 0); + nullptr, 0); if (unicode_path_len == 0) { return EINVAL; } @@ -4398,7 +4398,7 @@ static errno_t convert_to_unicode(char const* char_path, LPWSTR* unicode_path) { static errno_t get_full_path(LPCWSTR unicode_path, LPWSTR* full_path) { // Get required buffer size to convert to full path. The return // value INCLUDES the terminating null character. - DWORD full_path_len = GetFullPathNameW(unicode_path, 0, NULL, NULL); + DWORD full_path_len = GetFullPathNameW(unicode_path, 0, nullptr, nullptr); if (full_path_len == 0) { return EINVAL; } @@ -4407,7 +4407,7 @@ static errno_t get_full_path(LPCWSTR unicode_path, LPWSTR* full_path) { // When the buffer has sufficient size, the return value EXCLUDES the // terminating null character - DWORD result = GetFullPathNameW(unicode_path, full_path_len, *full_path, NULL); + DWORD result = GetFullPathNameW(unicode_path, full_path_len, *full_path, nullptr); assert(result <= full_path_len, "length already checked above"); return ERROR_SUCCESS; @@ -4432,15 +4432,15 @@ static void set_path_prefix(char* buf, LPCWSTR* prefix, int* prefix_off, bool* n } } -// Returns the given path as an absolute wide path in unc format. The returned path is NULL +// Returns the given path as an absolute wide path in unc format. The returned path is null // on error (with err being set accordingly) and should be freed via os::free() otherwise. // additional_space is the size of space, in wchar_t, the function will additionally add to // the allocation of return buffer (such that the size of the returned buffer is at least // wcslen(buf) + 1 + additional_space). static wchar_t* wide_abs_unc_path(char const* path, errno_t & err, int additional_space = 0) { - if ((path == NULL) || (path[0] == '\0')) { + if ((path == nullptr) || (path[0] == '\0')) { err = ENOENT; - return NULL; + return nullptr; } // Need to allocate at least room for 3 characters, since os::native_path transforms C: to C:. @@ -4449,27 +4449,27 @@ static wchar_t* wide_abs_unc_path(char const* path, errno_t & err, int additiona strncpy(buf, path, buf_len); os::native_path(buf); - LPCWSTR prefix = NULL; + LPCWSTR prefix = nullptr; int prefix_off = 0; bool needs_fullpath = true; set_path_prefix(buf, &prefix, &prefix_off, &needs_fullpath); - LPWSTR unicode_path = NULL; + LPWSTR unicode_path = nullptr; err = convert_to_unicode(buf, &unicode_path); FREE_C_HEAP_ARRAY(char, buf); if (err != ERROR_SUCCESS) { - return NULL; + return nullptr; } - LPWSTR converted_path = NULL; + LPWSTR converted_path = nullptr; if (needs_fullpath) { err = get_full_path(unicode_path, &converted_path); } else { converted_path = unicode_path; } - LPWSTR result = NULL; - if (converted_path != NULL) { + LPWSTR result = nullptr; + if (converted_path != nullptr) { size_t prefix_len = wcslen(prefix); size_t result_len = prefix_len - prefix_off + wcslen(converted_path) + additional_space + 1; result = NEW_C_HEAP_ARRAY(WCHAR, result_len, mtInternal); @@ -4495,7 +4495,7 @@ int os::stat(const char *path, struct stat *sbuf) { errno_t err; wchar_t* wide_path = wide_abs_unc_path(path, err); - if (wide_path == NULL) { + if (wide_path == nullptr) { errno = err; return -1; } @@ -4517,13 +4517,13 @@ static HANDLE create_read_only_file_handle(const char* file) { errno_t err; wchar_t* wide_path = wide_abs_unc_path(file, err); - if (wide_path == NULL) { + if (wide_path == nullptr) { errno = err; return INVALID_HANDLE_VALUE; } HANDLE handle = ::CreateFileW(wide_path, 0, FILE_SHARE_READ, - NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); os::free(wide_path); return handle; @@ -4531,11 +4531,11 @@ static HANDLE create_read_only_file_handle(const char* file) { bool os::same_files(const char* file1, const char* file2) { - if (file1 == NULL && file2 == NULL) { + if (file1 == nullptr && file2 == nullptr) { return true; } - if (file1 == NULL || file2 == NULL) { + if (file1 == nullptr || file2 == nullptr) { return false; } @@ -4695,7 +4695,7 @@ int os::open(const char *path, int oflag, int mode) { errno_t err; wchar_t* wide_path = wide_abs_unc_path(path, err); - if (wide_path == NULL) { + if (wide_path == nullptr) { errno = err; return -1; } @@ -4730,7 +4730,7 @@ bool os::dir_is_empty(const char* path) { errno_t err; wchar_t* wide_path = wide_abs_unc_path(path, err, 2); - if (wide_path == NULL) { + if (wide_path == nullptr) { errno = err; return false; } @@ -4818,7 +4818,7 @@ ssize_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) { // succeeds. char * os::native_path(char *path) { char *src = path, *dst = path, *end = path; - char *colon = NULL; // If a drive specifier is found, this will + char *colon = nullptr; // If a drive specifier is found, this will // point to the colon following the drive letter // Assumption: '/', '\\', ':', and drive letters are never lead bytes @@ -4952,19 +4952,19 @@ char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset, errno_t err; wchar_t* wide_path = wide_abs_unc_path(file_name, err); - if (wide_path == NULL) { - return NULL; + if (wide_path == nullptr) { + return nullptr; } HANDLE hFile; char* base; - hFile = CreateFileW(wide_path, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + hFile = CreateFileW(wide_path, GENERIC_READ, FILE_SHARE_READ, nullptr, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile == INVALID_HANDLE_VALUE) { log_info(os)("CreateFileW() failed: GetLastError->%ld.", GetLastError()); os::free(wide_path); - return NULL; + return nullptr; } os::free(wide_path); @@ -4981,9 +4981,9 @@ char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset, base = (char*) virtualAlloc(addr, bytes, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); - if (base == NULL) { + if (base == nullptr) { CloseHandle(hFile); - return NULL; + return nullptr; } // Record virtual memory allocation @@ -4993,7 +4993,7 @@ char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset, OVERLAPPED overlapped; overlapped.Offset = (DWORD)file_offset; overlapped.OffsetHigh = 0; - overlapped.hEvent = NULL; + overlapped.hEvent = nullptr; // ReadFile guarantees that if the return value is true, the requested // number of bytes were read before returning. bool res = ReadFile(hFile, base, (DWORD)bytes, &bytes_read, &overlapped) != 0; @@ -5001,24 +5001,24 @@ char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset, log_info(os)("ReadFile() failed: GetLastError->%ld.", GetLastError()); release_memory(base, bytes); CloseHandle(hFile); - return NULL; + return nullptr; } } else { - HANDLE hMap = CreateFileMapping(hFile, NULL, PAGE_WRITECOPY, 0, 0, - NULL /* file_name */); - if (hMap == NULL) { + HANDLE hMap = CreateFileMapping(hFile, nullptr, PAGE_WRITECOPY, 0, 0, + nullptr /* file_name */); + if (hMap == nullptr) { log_info(os)("CreateFileMapping() failed: GetLastError->%ld.", GetLastError()); CloseHandle(hFile); - return NULL; + return nullptr; } DWORD access = read_only ? FILE_MAP_READ : FILE_MAP_COPY; base = (char*)mapViewOfFileEx(hMap, access, 0, (DWORD)file_offset, (DWORD)bytes, addr); - if (base == NULL) { + if (base == nullptr) { CloseHandle(hMap); CloseHandle(hFile); - return NULL; + return nullptr; } if (CloseHandle(hMap) == 0) { @@ -5062,7 +5062,7 @@ char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset, // it in again with different protections, CDS archives are mapped RW // on windows, so this function isn't called. ShouldNotReachHere(); - return NULL; + return nullptr; } @@ -5133,7 +5133,7 @@ class HighResolutionInterval : public CHeapObj { // // 1: When a thread dies return the Event to the EventFreeList, clear the ParkHandle // field, and call CloseHandle() on the win32 event handle. Unpark() would -// need to be modified to tolerate finding a NULL (invalid) win32 event handle. +// need to be modified to tolerate finding a null (invalid) win32 event handle. // In addition, an unpark() operation might fetch the handle field, but the // event could recycle between the fetch and the SetEvent() operation. // SetEvent() would either fail because the handle was invalid, or inadvertently work, @@ -5197,7 +5197,7 @@ int PlatformEvent::park(jlong Millis) { // 1 => 0 : pass - return immediately // 0 => -1 : block; then set _Event to 0 before returning - guarantee(_ParkHandle != NULL , "Invariant"); + guarantee(_ParkHandle != nullptr , "Invariant"); guarantee(Millis > 0 , "Invariant"); // CONSIDER: defer assigning a CreateEvent() handle to the Event until @@ -5235,7 +5235,7 @@ int PlatformEvent::park(jlong Millis) { if (Millis > MAXTIMEOUT) { prd = MAXTIMEOUT; } - HighResolutionInterval *phri = NULL; + HighResolutionInterval *phri = nullptr; if (!ForceTimeHighResolution) { phri = new HighResolutionInterval(prd); } @@ -5244,7 +5244,7 @@ int PlatformEvent::park(jlong Millis) { if (rv == WAIT_TIMEOUT) { Millis -= prd; } - delete phri; // if it is NULL, harmless + delete phri; // if it is null, harmless } v = _Event; _Event = 0; @@ -5262,7 +5262,7 @@ void PlatformEvent::park() { // 1 => 0 : pass - return immediately // 0 => -1 : block; then set _Event to 0 before returning - guarantee(_ParkHandle != NULL, "Invariant"); + guarantee(_ParkHandle != nullptr, "Invariant"); // Invariant: Only the thread associated with the Event/PlatformEvent // may call park(). // Consider: use atomic decrement instead of CAS-loop @@ -5291,7 +5291,7 @@ void PlatformEvent::park() { } void PlatformEvent::unpark() { - guarantee(_ParkHandle != NULL, "Invariant"); + guarantee(_ParkHandle != nullptr, "Invariant"); // Transitions for _Event: // 0 => 1 : just return @@ -5321,7 +5321,7 @@ void PlatformEvent::unpark() { // use them directly. void Parker::park(bool isAbsolute, jlong time) { - guarantee(_ParkHandle != NULL, "invariant"); + guarantee(_ParkHandle != nullptr, "invariant"); // First, demultiplex/decode time arguments if (time < 0) { // don't wait return; @@ -5356,7 +5356,7 @@ void Parker::park(bool isAbsolute, jlong time) { } void Parker::unpark() { - guarantee(_ParkHandle != NULL, "invariant"); + guarantee(_ParkHandle != nullptr, "invariant"); SetEvent(_ParkHandle); } @@ -5394,7 +5394,7 @@ int os::fork_and_exec(const char* cmd) { const char * cmd_prefix = "cmd /C "; size_t len = strlen(cmd) + strlen(cmd_prefix) + 1; cmd_string = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtInternal); - if (cmd_string == NULL) { + if (cmd_string == nullptr) { return -1; } cmd_string[0] = '\0'; @@ -5403,21 +5403,21 @@ int os::fork_and_exec(const char* cmd) { // now replace all '\n' with '&' char * substring = cmd_string; - while ((substring = strchr(substring, '\n')) != NULL) { + while ((substring = strchr(substring, '\n')) != nullptr) { substring[0] = '&'; substring++; } memset(&si, 0, sizeof(si)); si.cb = sizeof(si); memset(&pi, 0, sizeof(pi)); - BOOL rslt = CreateProcess(NULL, // executable name - use command line + BOOL rslt = CreateProcess(nullptr, // executable name - use command line cmd_string, // command line - NULL, // process security attribute - NULL, // thread security attribute + nullptr, // process security attribute + nullptr, // thread security attribute TRUE, // inherits system handles 0, // no creation flags - NULL, // use parent's environment block - NULL, // use parent's starting directory + nullptr, // use parent's environment block + nullptr, // use parent's starting directory &si, // (in) startup information &pi); // (out) process information @@ -5509,7 +5509,7 @@ int os::raw_send(int fd, char* buf, size_t nBytes, uint flags) { // returns true if thread could be suspended, // false otherwise static bool do_suspend(HANDLE* h) { - if (h != NULL) { + if (h != nullptr) { if (SuspendThread(*h) != ~0) { return true; } @@ -5520,7 +5520,7 @@ static bool do_suspend(HANDLE* h) { // resume the thread // calling resume on an active thread is a no-op static void do_resume(HANDLE* h) { - if (h != NULL) { + if (h != nullptr) { ResumeThread(*h); } } @@ -5529,7 +5529,7 @@ static void do_resume(HANDLE* h) { // from the tid. Caller validates handle return value. void get_thread_handle_for_extended_context(HANDLE* h, OSThread::thread_id_t tid) { - if (h != NULL) { + if (h != nullptr) { *h = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, FALSE, tid); } } @@ -5538,13 +5538,13 @@ void get_thread_handle_for_extended_context(HANDLE* h, // void SuspendedThreadTask::internal_do_task() { CONTEXT ctxt; - HANDLE h = NULL; + HANDLE h = nullptr; // get context capable handle for thread get_thread_handle_for_extended_context(&h, _thread->osthread()->thread_id()); // sanity - if (h == NULL || h == INVALID_HANDLE_VALUE) { + if (h == nullptr || h == INVALID_HANDLE_VALUE) { return; } @@ -5591,7 +5591,7 @@ bool os::start_debugging(char *buf, int buflen) { } void* os::get_default_process_handle() { - return (void*)GetModuleHandle(NULL); + return (void*)GetModuleHandle(nullptr); } // Builds a platform dependent Agent_OnLoad_ function name @@ -5599,7 +5599,7 @@ void* os::get_default_process_handle() { // Additionally for windows, takes into account __stdcall names. // Parameters: // sym_name: Symbol in library we are looking for -// lib_name: Name of library to look in, NULL for shared libs. +// lib_name: Name of library to look in, null for shared libs. // is_absolute_path == true if lib_name is absolute path to agent // such as "C:/a/b/L.dll" // == false if only the base name of the library is passed in @@ -5613,33 +5613,33 @@ char* os::build_agent_function_name(const char *sym_name, const char *lib_name, size_t suffix_len = strlen(JNI_LIB_SUFFIX); const char *start; - if (lib_name != NULL) { + if (lib_name != nullptr) { len = name_len = strlen(lib_name); if (is_absolute_path) { // Need to strip path, prefix and suffix - if ((start = strrchr(lib_name, *os::file_separator())) != NULL) { + if ((start = strrchr(lib_name, *os::file_separator())) != nullptr) { lib_name = ++start; } else { // Need to check for drive prefix - if ((start = strchr(lib_name, ':')) != NULL) { + if ((start = strchr(lib_name, ':')) != nullptr) { lib_name = ++start; } } if (len <= (prefix_len + suffix_len)) { - return NULL; + return nullptr; } lib_name += prefix_len; name_len = strlen(lib_name) - suffix_len; } } - len = (lib_name != NULL ? name_len : 0) + strlen(sym_name) + 2; + len = (lib_name != nullptr ? name_len : 0) + strlen(sym_name) + 2; agent_entry_name = NEW_C_HEAP_ARRAY_RETURN_NULL(char, len, mtThread); - if (agent_entry_name == NULL) { - return NULL; + if (agent_entry_name == nullptr) { + return nullptr; } - if (lib_name != NULL) { + if (lib_name != nullptr) { const char *p = strrchr(sym_name, '@'); - if (p != NULL && p != sym_name) { + if (p != nullptr && p != sym_name) { // sym_name == _Agent_OnLoad@XX strncpy(agent_entry_name, sym_name, (p - sym_name)); agent_entry_name[(p-sym_name)] = '\0'; @@ -5703,7 +5703,7 @@ static void call_wrapper_dummy() {} // up the offset from FS of the thread pointer. void os::win32::initialize_thread_ptr_offset() { os::os_exception_wrapper((java_call_t)call_wrapper_dummy, - NULL, methodHandle(), NULL, NULL); + nullptr, methodHandle(), nullptr, nullptr); } bool os::supports_map_sync() { @@ -5714,7 +5714,7 @@ bool os::supports_map_sync() { static void check_meminfo(MEMORY_BASIC_INFORMATION* minfo) { assert(minfo->State == MEM_FREE || minfo->State == MEM_COMMIT || minfo->State == MEM_RESERVE, "Invalid state"); if (minfo->State != MEM_FREE) { - assert(minfo->AllocationBase != NULL && minfo->BaseAddress >= minfo->AllocationBase, "Invalid pointers"); + assert(minfo->AllocationBase != nullptr && minfo->BaseAddress >= minfo->AllocationBase, "Invalid pointers"); assert(minfo->RegionSize > 0, "Invalid region size"); } } @@ -5737,8 +5737,8 @@ bool os::win32::find_mapping(address addr, mapping_info_t* mi) { // query all regions, until we either find the next allocation or a free area. ZeroMemory(mi, sizeof(mapping_info_t)); MEMORY_BASIC_INFORMATION minfo; - address allocation_base = NULL; - address allocation_end = NULL; + address allocation_base = nullptr; + address allocation_end = nullptr; bool rc = false; if (checkedVirtualQuery(addr, &minfo)) { if (minfo.State != MEM_FREE) { @@ -5760,7 +5760,7 @@ bool os::win32::find_mapping(address addr, mapping_info_t* mi) { } allocation_end += region_size; } - if (allocation_base != NULL && allocation_end > allocation_base) { + if (allocation_base != nullptr && allocation_end > allocation_base) { mi->base = allocation_base; mi->size = allocation_end - allocation_base; rc = true; @@ -5883,7 +5883,7 @@ static address print_one_mapping(MEMORY_BASIC_INFORMATION* minfo, address start, } #undef IS_IN ShouldNotReachHere(); - return NULL; + return nullptr; } void os::print_memory_mappings(char* addr, size_t bytes, outputStream* st) { diff --git a/src/hotspot/os/windows/park_windows.hpp b/src/hotspot/os/windows/park_windows.hpp index b92a939238c..3754201799d 100644 --- a/src/hotspot/os/windows/park_windows.hpp +++ b/src/hotspot/os/windows/park_windows.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -41,8 +41,8 @@ class PlatformEvent : public CHeapObj { public: PlatformEvent() { _Event = 0 ; - _ParkHandle = CreateEvent (NULL, false, false, NULL) ; - guarantee (_ParkHandle != NULL, "invariant") ; + _ParkHandle = CreateEvent (nullptr, false, false, nullptr) ; + guarantee (_ParkHandle != nullptr, "invariant") ; } // Exercise caution using reset() and fired() - they may require MEMBARs @@ -61,8 +61,8 @@ class PlatformParker { public: PlatformParker() { - _ParkHandle = CreateEvent (NULL, true, false, NULL) ; - guarantee(_ParkHandle != NULL, "invariant") ; + _ParkHandle = CreateEvent (nullptr, true, false, nullptr) ; + guarantee(_ParkHandle != nullptr, "invariant") ; } ~PlatformParker() { CloseHandle(_ParkHandle); diff --git a/src/hotspot/os/windows/pdh_interface.cpp b/src/hotspot/os/windows/pdh_interface.cpp index 06ce39c86cd..3134dc3f24c 100644 --- a/src/hotspot/os/windows/pdh_interface.cpp +++ b/src/hotspot/os/windows/pdh_interface.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 @@ -40,25 +40,25 @@ typedef PDH_STATUS (WINAPI *PdhLookupPerfNameByIndex_Fn)(LPCSTR, DWORD, LPSTR, L typedef PDH_STATUS (WINAPI *PdhMakeCounterPath_Fn)(PDH_COUNTER_PATH_ELEMENTS*, LPTSTR, LPDWORD, DWORD); typedef PDH_STATUS (WINAPI *PdhExpandWildCardPath_Fn)(LPCSTR, LPCSTR, PZZSTR, LPDWORD, DWORD); -PdhAddCounter_Fn PdhDll::_PdhAddCounter = NULL; -PdhOpenQuery_Fn PdhDll::_PdhOpenQuery = NULL; -PdhCloseQuery_Fn PdhDll::_PdhCloseQuery = NULL; -PdhCollectQueryData_Fn PdhDll::_PdhCollectQueryData = NULL; -PdhGetFormattedCounterValue_Fn PdhDll::_PdhGetFormattedCounterValue = NULL; -PdhEnumObjectItems_Fn PdhDll::_PdhEnumObjectItems = NULL; -PdhRemoveCounter_Fn PdhDll::_PdhRemoveCounter = NULL; -PdhLookupPerfNameByIndex_Fn PdhDll::_PdhLookupPerfNameByIndex = NULL; -PdhMakeCounterPath_Fn PdhDll::_PdhMakeCounterPath = NULL; -PdhExpandWildCardPath_Fn PdhDll::_PdhExpandWildCardPath = NULL; +PdhAddCounter_Fn PdhDll::_PdhAddCounter = nullptr; +PdhOpenQuery_Fn PdhDll::_PdhOpenQuery = nullptr; +PdhCloseQuery_Fn PdhDll::_PdhCloseQuery = nullptr; +PdhCollectQueryData_Fn PdhDll::_PdhCollectQueryData = nullptr; +PdhGetFormattedCounterValue_Fn PdhDll::_PdhGetFormattedCounterValue = nullptr; +PdhEnumObjectItems_Fn PdhDll::_PdhEnumObjectItems = nullptr; +PdhRemoveCounter_Fn PdhDll::_PdhRemoveCounter = nullptr; +PdhLookupPerfNameByIndex_Fn PdhDll::_PdhLookupPerfNameByIndex = nullptr; +PdhMakeCounterPath_Fn PdhDll::_PdhMakeCounterPath = nullptr; +PdhExpandWildCardPath_Fn PdhDll::_PdhExpandWildCardPath = nullptr; LONG PdhDll::_critical_section = 0; LONG PdhDll::_initialized = 0; LONG PdhDll::_pdh_reference_count = 0; -HMODULE PdhDll::_hModule = NULL; +HMODULE PdhDll::_hModule = nullptr; void PdhDll::initialize(void) { - _hModule = os::win32::load_Windows_dll("pdh.dll", NULL, 0); - if (NULL == _hModule) { + _hModule = os::win32::load_Windows_dll("pdh.dll", nullptr, 0); + if (nullptr == _hModule) { return; } // The 'A' at the end means the ANSI (not the UNICODE) versions of the methods @@ -79,20 +79,20 @@ bool PdhDll::PdhDetach(void) { LONG prev_ref_count = InterlockedExchangeAdd(&_pdh_reference_count, -1); BOOL ret = false; if (1 == prev_ref_count) { - if (_initialized && _hModule != NULL) { + if (_initialized && _hModule != nullptr) { ret = FreeLibrary(_hModule); if (ret) { - _hModule = NULL; - _PdhAddCounter = NULL; - _PdhOpenQuery = NULL; - _PdhCloseQuery = NULL; - _PdhCollectQueryData = NULL; - _PdhGetFormattedCounterValue = NULL; - _PdhEnumObjectItems = NULL; - _PdhRemoveCounter = NULL; - _PdhLookupPerfNameByIndex = NULL; - _PdhMakeCounterPath = NULL; - _PdhExpandWildCardPath = NULL; + _hModule = nullptr; + _PdhAddCounter = nullptr; + _PdhOpenQuery = nullptr; + _PdhCloseQuery = nullptr; + _PdhCollectQueryData = nullptr; + _PdhGetFormattedCounterValue = nullptr; + _PdhEnumObjectItems = nullptr; + _PdhRemoveCounter = nullptr; + _PdhLookupPerfNameByIndex = nullptr; + _PdhMakeCounterPath = nullptr; + _PdhExpandWildCardPath = nullptr; InterlockedExchange(&_initialized, 0); } } @@ -110,63 +110,63 @@ bool PdhDll::PdhAttach(void) { initialize(); } while (InterlockedCompareExchange(&_critical_section, 0, 1) == 0); - return (_PdhAddCounter != NULL && _PdhOpenQuery != NULL - && _PdhCloseQuery != NULL && _PdhCollectQueryData != NULL - && _PdhGetFormattedCounterValue != NULL && _PdhEnumObjectItems != NULL - && _PdhRemoveCounter != NULL && _PdhLookupPerfNameByIndex != NULL - && _PdhMakeCounterPath != NULL && _PdhExpandWildCardPath != NULL); + return (_PdhAddCounter != nullptr && _PdhOpenQuery != nullptr + && _PdhCloseQuery != nullptr && _PdhCollectQueryData != nullptr + && _PdhGetFormattedCounterValue != nullptr && _PdhEnumObjectItems != nullptr + && _PdhRemoveCounter != nullptr && _PdhLookupPerfNameByIndex != nullptr + && _PdhMakeCounterPath != nullptr && _PdhExpandWildCardPath != nullptr); } PDH_STATUS PdhDll::PdhAddCounter(HQUERY hQuery, LPCSTR szFullCounterPath, DWORD dwUserData, HCOUNTER* phCounter) { - assert(_initialized && _PdhAddCounter != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhAddCounter != nullptr, "PdhAvailable() not yet called"); return _PdhAddCounter(hQuery, szFullCounterPath, dwUserData, phCounter); } PDH_STATUS PdhDll::PdhOpenQuery(LPCWSTR szDataSource, DWORD dwUserData, HQUERY* phQuery) { - assert(_initialized && _PdhOpenQuery != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhOpenQuery != nullptr, "PdhAvailable() not yet called"); return _PdhOpenQuery(szDataSource, dwUserData, phQuery); } DWORD PdhDll::PdhCloseQuery(HQUERY hQuery) { - assert(_initialized && _PdhCloseQuery != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhCloseQuery != nullptr, "PdhAvailable() not yet called"); return _PdhCloseQuery(hQuery); } PDH_STATUS PdhDll::PdhCollectQueryData(HQUERY hQuery) { - assert(_initialized && _PdhCollectQueryData != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhCollectQueryData != nullptr, "PdhAvailable() not yet called"); return _PdhCollectQueryData(hQuery); } DWORD PdhDll::PdhGetFormattedCounterValue(HCOUNTER hCounter, DWORD dwFormat, LPDWORD lpdwType, PPDH_FMT_COUNTERVALUE pValue) { - assert(_initialized && _PdhGetFormattedCounterValue != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhGetFormattedCounterValue != nullptr, "PdhAvailable() not yet called"); return _PdhGetFormattedCounterValue(hCounter, dwFormat, lpdwType, pValue); } PDH_STATUS PdhDll::PdhEnumObjectItems(LPCTSTR szDataSource, LPCTSTR szMachineName, LPCTSTR szObjectName, LPTSTR mszCounterList, LPDWORD pcchCounterListLength, LPTSTR mszInstanceList, LPDWORD pcchInstanceListLength, DWORD dwDetailLevel, DWORD dwFlags) { - assert(_initialized && _PdhEnumObjectItems != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhEnumObjectItems != nullptr, "PdhAvailable() not yet called"); return _PdhEnumObjectItems(szDataSource, szMachineName, szObjectName, mszCounterList, pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, dwFlags); } PDH_STATUS PdhDll::PdhRemoveCounter(HCOUNTER hCounter) { - assert(_initialized && _PdhRemoveCounter != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhRemoveCounter != nullptr, "PdhAvailable() not yet called"); return _PdhRemoveCounter(hCounter); } PDH_STATUS PdhDll::PdhLookupPerfNameByIndex(LPCSTR szMachineName, DWORD dwNameIndex, LPSTR szNameBuffer, LPDWORD pcchNameBufferSize) { - assert(_initialized && _PdhLookupPerfNameByIndex != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhLookupPerfNameByIndex != nullptr, "PdhAvailable() not yet called"); return _PdhLookupPerfNameByIndex(szMachineName, dwNameIndex, szNameBuffer, pcchNameBufferSize); } PDH_STATUS PdhDll::PdhMakeCounterPath(PDH_COUNTER_PATH_ELEMENTS* pCounterPathElements, LPTSTR szFullPathBuffer, LPDWORD pcchBufferSize, DWORD dwFlags) { - assert(_initialized && _PdhMakeCounterPath != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhMakeCounterPath != nullptr, "PdhAvailable() not yet called"); return _PdhMakeCounterPath(pCounterPathElements, szFullPathBuffer, pcchBufferSize, dwFlags); } PDH_STATUS PdhDll::PdhExpandWildCardPath(LPCSTR szDataSource, LPCSTR szWildCardPath, PZZSTR mszExpandedPathList, LPDWORD pcchPathListLength, DWORD dwFlags) { - assert(_initialized && _PdhExpandWildCardPath != NULL, "PdhAvailable() not yet called"); + assert(_initialized && _PdhExpandWildCardPath != nullptr, "PdhAvailable() not yet called"); return _PdhExpandWildCardPath(szDataSource, szWildCardPath, mszExpandedPathList, pcchPathListLength, dwFlags); } diff --git a/src/hotspot/os/windows/perfMemory_windows.cpp b/src/hotspot/os/windows/perfMemory_windows.cpp index 021f5aa9e78..404313f63e0 100644 --- a/src/hotspot/os/windows/perfMemory_windows.cpp +++ b/src/hotspot/os/windows/perfMemory_windows.cpp @@ -57,8 +57,8 @@ static char* create_standard_memory(size_t size) { // allocate an aligned chuck of memory char* mapAddress = os::reserve_memory(size); - if (mapAddress == NULL) { - return NULL; + if (mapAddress == nullptr) { + return nullptr; } // commit memory @@ -67,7 +67,7 @@ static char* create_standard_memory(size_t size) { warning("Could not commit PerfData memory\n"); } os::release_memory(mapAddress, size); - return NULL; + return nullptr; } return mapAddress; @@ -149,9 +149,9 @@ static void save_memory_to_file(char* addr, size_t size) { // os::get_temp_directory() in os_win32.cpp), control the location of the // user specific directory and the shared memory backing store file. -static HANDLE sharedmem_fileMapHandle = NULL; +static HANDLE sharedmem_fileMapHandle = nullptr; static HANDLE sharedmem_fileHandle = INVALID_HANDLE_VALUE; -static char* sharedmem_fileName = NULL; +static char* sharedmem_fileName = nullptr; // return the user specific temporary directory name. // @@ -185,7 +185,7 @@ static int filename_to_pid(const char* filename) { // check if file name can be converted to an integer without // any leftover characters. // - char* remainder = NULL; + char* remainder = nullptr; errno = 0; int pid = (int)strtol(filename, &remainder, 10); @@ -196,7 +196,7 @@ static int filename_to_pid(const char* filename) { // check for left over characters. If any, then the filename is // not a candidate for conversion. // - if (remainder != NULL && *remainder != '\0') { + if (remainder != nullptr && *remainder != '\0') { return 0; } @@ -277,12 +277,12 @@ static char* get_user_name() { char* user = getenv("USERNAME"); char buf[UNLEN+1]; DWORD buflen = sizeof(buf); - if (user == NULL || strlen(user) == 0) { + if (user == nullptr || strlen(user) == 0) { if (GetUserName(buf, &buflen)) { user = buf; } else { - return NULL; + return nullptr; } } @@ -303,15 +303,15 @@ static char* get_user_name() { static char* get_user_name_slow(int vmid) { // directory search - char* latest_user = NULL; + char* latest_user = nullptr; time_t latest_ctime = 0; const char* tmpdirname = os::get_temp_directory(); DIR* tmpdirp = os::opendir(tmpdirname); - if (tmpdirp == NULL) { - return NULL; + if (tmpdirp == nullptr) { + return nullptr; } // for each entry in the directory that matches the pattern hsperfdata_*, @@ -321,7 +321,7 @@ static char* get_user_name_slow(int vmid) { // struct dirent* dentry; errno = 0; - while ((dentry = os::readdir(tmpdirp)) != NULL) { + while ((dentry = os::readdir(tmpdirp)) != nullptr) { // check if the directory entry is a hsperfdata file if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { @@ -336,7 +336,7 @@ static char* get_user_name_slow(int vmid) { DIR* subdirp = os::opendir(usrdir_name); - if (subdirp == NULL) { + if (subdirp == nullptr) { FREE_C_HEAP_ARRAY(char, usrdir_name); continue; } @@ -355,7 +355,7 @@ static char* get_user_name_slow(int vmid) { struct dirent* udentry; errno = 0; - while ((udentry = os::readdir(subdirp)) != NULL) { + while ((udentry = os::readdir(subdirp)) != nullptr) { if (filename_to_pid(udentry->d_name) == vmid) { struct stat statbuf; @@ -514,7 +514,7 @@ static void remove_file(const char* dirname, const char* filename) { static bool is_alive(int pid) { HANDLE ph = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); - if (ph == NULL) { + if (ph == nullptr) { // the process does not exist. if (PrintMiscellaneous && Verbose) { DWORD lastError = GetLastError(); @@ -553,7 +553,7 @@ static bool is_filesystem_secure(const char* path) { } char* first_colon = strchr((char *)path, ':'); - if (first_colon == NULL) { + if (first_colon == nullptr) { if (PrintMiscellaneous && Verbose) { warning("expected device specifier in path: %s\n", path); } @@ -568,13 +568,13 @@ static bool is_filesystem_secure(const char* path) { // check that we have something like "C:\" or "AA:\" assert(strlen(root_path) >= 3, "device specifier too short"); - assert(strchr(root_path, ':') != NULL, "bad device specifier format"); - assert(strchr(root_path, '\\') != NULL, "bad device specifier format"); + assert(strchr(root_path, ':') != nullptr, "bad device specifier format"); + assert(strchr(root_path, '\\') != nullptr, "bad device specifier format"); DWORD maxpath; DWORD flags; - if (!GetVolumeInformation(root_path, NULL, 0, NULL, &maxpath, + if (!GetVolumeInformation(root_path, nullptr, 0, nullptr, &maxpath, &flags, fs_type, MAX_PATH)) { // we can't get information about the volume, so assume unsafe. if (PrintMiscellaneous && Verbose) { @@ -620,7 +620,7 @@ static void cleanup_sharedmem_resources(const char* dirname) { // open the user temp directory DIR* dirp = os::opendir(dirname); - if (dirp == NULL) { + if (dirp == nullptr) { // directory doesn't exist, so there is nothing to cleanup return; } @@ -641,7 +641,7 @@ static void cleanup_sharedmem_resources(const char* dirname) { // struct dirent* entry; errno = 0; - while ((entry = os::readdir(dirp)) != NULL) { + while ((entry = os::readdir(dirp)) != nullptr) { int pid = filename_to_pid(entry->d_name); @@ -691,7 +691,7 @@ static HANDLE create_file_mapping(const char* name, HANDLE fh, LPSECURITY_ATTRIB DWORD lowSize = (DWORD)size; DWORD highSize = 0; - HANDLE fmh = NULL; + HANDLE fmh = nullptr; // Create a file mapping object with the given name. This function // will grow the file to the specified size. @@ -704,11 +704,11 @@ static HANDLE create_file_mapping(const char* name, HANDLE fh, LPSECURITY_ATTRIB lowSize, /* DWORD Low word of max size */ name); /* LPCTSTR name for object */ - if (fmh == NULL) { + if (fmh == nullptr) { if (PrintMiscellaneous && Verbose) { warning("CreateFileMapping failed, lasterror = %d\n", GetLastError()); } - return NULL; + return nullptr; } if (GetLastError() == ERROR_ALREADY_EXISTS) { @@ -723,7 +723,7 @@ static HANDLE create_file_mapping(const char* name, HANDLE fh, LPSECURITY_ATTRIB } CloseHandle(fmh); - return NULL; + return nullptr; } return fmh; @@ -738,7 +738,7 @@ static void free_security_desc(PSECURITY_DESCRIPTOR pSD) { BOOL success, exists, isdefault; PACL pACL; - if (pSD != NULL) { + if (pSD != nullptr) { // get the access control list from the security descriptor success = GetSecurityDescriptorDacl(pSD, &exists, &pACL, &isdefault); @@ -746,7 +746,7 @@ static void free_security_desc(PSECURITY_DESCRIPTOR pSD) { // if an ACL existed and it was not a default acl, then it must // be an ACL we enlisted. free the resources. // - if (success && exists && pACL != NULL && !isdefault) { + if (success && exists && pACL != nullptr && !isdefault) { FREE_C_HEAP_ARRAY(char, pACL); } @@ -760,10 +760,10 @@ static void free_security_desc(PSECURITY_DESCRIPTOR pSD) { // static void free_security_attr(LPSECURITY_ATTRIBUTES lpSA) { - if (lpSA != NULL) { + if (lpSA != nullptr) { // free the contained security descriptor and the ACL free_security_desc(lpSA->lpSecurityDescriptor); - lpSA->lpSecurityDescriptor = NULL; + lpSA->lpSecurityDescriptor = nullptr; // free the security attributes structure FREE_C_HEAP_OBJ(lpSA); @@ -775,11 +775,11 @@ static void free_security_attr(LPSECURITY_ATTRIBUTES lpSA) { static PSID get_user_sid(HANDLE hProcess) { HANDLE hAccessToken; - PTOKEN_USER token_buf = NULL; + PTOKEN_USER token_buf = nullptr; DWORD rsize = 0; - if (hProcess == NULL) { - return NULL; + if (hProcess == nullptr) { + return nullptr; } // get the process token @@ -787,13 +787,13 @@ static PSID get_user_sid(HANDLE hProcess) { if (PrintMiscellaneous && Verbose) { warning("OpenProcessToken failure: lasterror = %d \n", GetLastError()); } - return NULL; + return nullptr; } // determine the size of the token structured needed to retrieve // the user token information from the access token. // - if (!GetTokenInformation(hAccessToken, TokenUser, NULL, rsize, &rsize)) { + if (!GetTokenInformation(hAccessToken, TokenUser, nullptr, rsize, &rsize)) { DWORD lasterror = GetLastError(); if (lasterror != ERROR_INSUFFICIENT_BUFFER) { if (PrintMiscellaneous && Verbose) { @@ -801,7 +801,7 @@ static PSID get_user_sid(HANDLE hProcess) { " rsize = %d\n", lasterror, rsize); } CloseHandle(hAccessToken); - return NULL; + return nullptr; } } @@ -815,7 +815,7 @@ static PSID get_user_sid(HANDLE hProcess) { } FREE_C_HEAP_ARRAY(char, token_buf); CloseHandle(hAccessToken); - return NULL; + return nullptr; } DWORD nbytes = GetLengthSid(token_buf->User.Sid); @@ -829,7 +829,7 @@ static PSID get_user_sid(HANDLE hProcess) { FREE_C_HEAP_ARRAY(char, token_buf); FREE_C_HEAP_ARRAY(char, pSID); CloseHandle(hAccessToken); - return NULL; + return nullptr; } // close the access token. @@ -856,10 +856,10 @@ typedef struct ace_data { static bool add_allow_aces(PSECURITY_DESCRIPTOR pSD, ace_data_t aces[], int ace_count) { - PACL newACL = NULL; - PACL oldACL = NULL; + PACL newACL = nullptr; + PACL oldACL = nullptr; - if (pSD == NULL) { + if (pSD == nullptr) { return false; } @@ -878,8 +878,8 @@ static bool add_allow_aces(PSECURITY_DESCRIPTOR pSD, ACL_SIZE_INFORMATION aclinfo; // GetSecurityDescriptorDacl may return true value for exists (lpbDaclPresent) - // while oldACL is NULL for some case. - if (oldACL == NULL) { + // while oldACL is null for some case. + if (oldACL == nullptr) { exists = FALSE; } @@ -893,7 +893,7 @@ static bool add_allow_aces(PSECURITY_DESCRIPTOR pSD, } } } else { - aclinfo.AceCount = 0; // assume NULL DACL + aclinfo.AceCount = 0; // assume null DACL aclinfo.AclBytesFree = 0; aclinfo.AclBytesInUse = sizeof(ACL); } @@ -1021,7 +1021,7 @@ static bool add_allow_aces(PSECURITY_DESCRIPTOR pSD, GetProcAddress(GetModuleHandle(TEXT("advapi32.dll")), "SetSecurityDescriptorControl"); - if (_SetSecurityDescriptorControl != NULL) { + if (_SetSecurityDescriptorControl != nullptr) { // We do not want to further propagate inherited DACLs, so making them // protected prevents that. if (!_SetSecurityDescriptorControl(pSD, SE_DACL_PROTECTED, @@ -1063,13 +1063,13 @@ static LPSECURITY_ATTRIBUTES make_security_attr(ace_data_t aces[], int count) { "lasterror = %d \n", GetLastError()); } free_security_desc(pSD); - return NULL; + return nullptr; } // add the access control entries if (!add_allow_aces(pSD, aces, count)) { free_security_desc(pSD); - return NULL; + return nullptr; } // allocate and initialize the security attributes structure and @@ -1104,10 +1104,10 @@ static LPSECURITY_ATTRIBUTES make_user_everybody_admin_security_attr( aces[0].mask = umask; if (aces[0].pSid == 0) - return NULL; + return nullptr; // get the well known SID for BUILTIN\Administrators - PSID administratorsSid = NULL; + PSID administratorsSid = nullptr; SID_IDENTIFIER_AUTHORITY SIDAuthAdministrators = SECURITY_NT_AUTHORITY; if (!AllocateAndInitializeSid( &SIDAuthAdministrators, 2, @@ -1119,7 +1119,7 @@ static LPSECURITY_ATTRIBUTES make_user_everybody_admin_security_attr( warning("AllocateAndInitializeSid failure: " "lasterror = %d \n", GetLastError()); } - return NULL; + return nullptr; } // initialize the ace data for administrator group @@ -1127,7 +1127,7 @@ static LPSECURITY_ATTRIBUTES make_user_everybody_admin_security_attr( aces[1].mask = amask; // get the well known SID for the universal Everybody - PSID everybodySid = NULL; + PSID everybodySid = nullptr; SID_IDENTIFIER_AUTHORITY SIDAuthEverybody = SECURITY_WORLD_SID_AUTHORITY; if (!AllocateAndInitializeSid( &SIDAuthEverybody, 1, SECURITY_WORLD_RID, @@ -1137,7 +1137,7 @@ static LPSECURITY_ATTRIBUTES make_user_everybody_admin_security_attr( warning("AllocateAndInitializeSid failure: " "lasterror = %d \n", GetLastError()); } - return NULL; + return nullptr; } // initialize the ace data for everybody else. @@ -1222,7 +1222,7 @@ static bool make_user_tmp_dir(const char* dirname) { LPSECURITY_ATTRIBUTES pDirSA = make_tmpdir_security_attr(); - if (pDirSA == NULL) { + if (pDirSA == nullptr) { return false; } @@ -1276,20 +1276,20 @@ static bool make_user_tmp_dir(const char* dirname) { static HANDLE create_sharedmem_resources(const char* dirname, const char* filename, const char* objectname, size_t size) { HANDLE fh = INVALID_HANDLE_VALUE; - HANDLE fmh = NULL; + HANDLE fmh = nullptr; // create the security attributes for the backing store file LPSECURITY_ATTRIBUTES lpFileSA = make_file_security_attr(); - if (lpFileSA == NULL) { - return NULL; + if (lpFileSA == nullptr) { + return nullptr; } // create the security attributes for the shared memory object LPSECURITY_ATTRIBUTES lpSmoSA = make_smo_security_attr(); - if (lpSmoSA == NULL) { + if (lpSmoSA == nullptr) { free_security_attr(lpFileSA); - return NULL; + return nullptr; } // create the user temporary directory @@ -1298,7 +1298,7 @@ static HANDLE create_sharedmem_resources(const char* dirname, const char* filena // was not secure free_security_attr(lpFileSA); free_security_attr(lpSmoSA); - return NULL; + return nullptr; } // Create the file - the FILE_FLAG_DELETE_ON_CLOSE flag allows the @@ -1320,7 +1320,7 @@ static HANDLE create_sharedmem_resources(const char* dirname, const char* filena */ FILE_FLAG_DELETE_ON_CLOSE, /* DWORD flags and attributes */ - NULL); /* HANDLE template file access */ + nullptr); /* HANDLE template file access */ free_security_attr(lpFileSA); @@ -1330,7 +1330,7 @@ static HANDLE create_sharedmem_resources(const char* dirname, const char* filena warning("could not create file %s: %d\n", filename, lasterror); } free_security_attr(lpSmoSA); - return NULL; + return nullptr; } // try to create the file mapping @@ -1338,15 +1338,15 @@ static HANDLE create_sharedmem_resources(const char* dirname, const char* filena free_security_attr(lpSmoSA); - if (fmh == NULL) { + if (fmh == nullptr) { // closing the file handle here will decrement the reference count // on the file. When all processes accessing the file close their // handle to it, the reference count will decrement to 0 and the // OS will delete the file. These semantics are requested by the // FILE_FLAG_DELETE_ON_CLOSE flag in CreateFile call above. CloseHandle(fh); - fh = NULL; - return NULL; + fh = nullptr; + return nullptr; } else { // We created the file mapping, but rarely the size of the // backing store file is reported as zero (0) which can cause @@ -1360,9 +1360,9 @@ static HANDLE create_sharedmem_resources(const char* dirname, const char* filena } CloseHandle(fmh); CloseHandle(fh); - fh = NULL; - fmh = NULL; - return NULL; + fh = nullptr; + fmh = nullptr; + return nullptr; } // We could always call FlushFileBuffers() but the Microsoft @@ -1375,9 +1375,9 @@ static HANDLE create_sharedmem_resources(const char* dirname, const char* filena } CloseHandle(fmh); CloseHandle(fh); - fh = NULL; - fmh = NULL; - return NULL; + fh = nullptr; + fmh = nullptr; + return nullptr; } } @@ -1401,7 +1401,7 @@ static HANDLE open_sharedmem_object(const char* objectname, DWORD ofm_access, TR FALSE, /* BOOL inherit flag - Do not allow inherit */ objectname); /* name for object */ - if (fmh == NULL) { + if (fmh == nullptr) { DWORD lasterror = GetLastError(); if (PrintMiscellaneous && Verbose) { warning("OpenFileMapping failed for shared memory object %s:" @@ -1437,8 +1437,8 @@ static char* mapping_create_shared(size_t size) { // get the name of the user associated with this process char* user = get_user_name(); - if (user == NULL) { - return NULL; + if (user == nullptr) { + return nullptr; } // construct the name of the user specific temporary directory @@ -1448,7 +1448,7 @@ static char* mapping_create_shared(size_t size) { if (!is_filesystem_secure(dirname)) { FREE_C_HEAP_ARRAY(char, dirname); FREE_C_HEAP_ARRAY(char, user); - return NULL; + return nullptr; } // create the names of the backing store files and for the @@ -1473,8 +1473,8 @@ static char* mapping_create_shared(size_t size) { FREE_C_HEAP_ARRAY(char, objectname); FREE_C_HEAP_ARRAY(char, dirname); - if (sharedmem_fileMapHandle == NULL) { - return NULL; + if (sharedmem_fileMapHandle == nullptr) { + return nullptr; } // map the file into the address space @@ -1485,13 +1485,13 @@ static char* mapping_create_shared(size_t size) { 0, /* DWORD Low word of offset */ (DWORD)size); /* DWORD Number of bytes to map */ - if (mapAddress == NULL) { + if (mapAddress == nullptr) { if (PrintMiscellaneous && Verbose) { warning("MapViewOfFile failed, lasterror = %d\n", GetLastError()); } CloseHandle(sharedmem_fileMapHandle); - sharedmem_fileMapHandle = NULL; - return NULL; + sharedmem_fileMapHandle = nullptr; + return nullptr; } // clear the shared memory region @@ -1521,9 +1521,9 @@ static void delete_file_mapping(char* addr, size_t size) { // by the OS as long as any other JVM processes has an open file mapping // handle or a mapped view of the file. // - if (sharedmem_fileMapHandle != NULL) { + if (sharedmem_fileMapHandle != nullptr) { CloseHandle(sharedmem_fileMapHandle); - sharedmem_fileMapHandle = NULL; + sharedmem_fileMapHandle = nullptr; } // close the file handle. This will decrement the reference count on the @@ -1581,7 +1581,7 @@ static void open_file_mapping(int vmid, char** addrp, size_t* sizep, TRAPS) { DWORD mv_access = FILE_MAP_READ; const char* luser = get_user_name(vmid); - if (luser == NULL) { + if (luser == nullptr) { THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Could not map vmid to user name"); } @@ -1639,7 +1639,7 @@ static void open_file_mapping(int vmid, char** addrp, size_t* sizep, TRAPS) { 0, /* DWORD Low word of offset */ size); /* DWORD Number of bytes to map */ - if (mapAddress == NULL) { + if (mapAddress == nullptr) { if (PrintMiscellaneous && Verbose) { warning("MapViewOfFile failed, lasterror = %d\n", GetLastError()); } @@ -1706,7 +1706,7 @@ void PerfMemory::create_memory_region(size_t size) { } else { _start = create_shared_memory(size); - if (_start == NULL) { + if (_start == nullptr) { // creation of the shared memory region failed, attempt // to create a contiguous, non-shared memory region instead. @@ -1719,7 +1719,7 @@ void PerfMemory::create_memory_region(size_t size) { } } - if (_start != NULL) _capacity = size; + if (_start != nullptr) _capacity = size; } @@ -1731,13 +1731,13 @@ void PerfMemory::create_memory_region(size_t size) { // void PerfMemory::delete_memory_region() { - assert((start() != NULL && capacity() > 0), "verify proper state"); + assert((start() != nullptr && capacity() > 0), "verify proper state"); // If user specifies PerfDataSaveFile, it will save the performance data // to the specified file name no matter whether PerfDataSaveToFile is specified // or not. In other word, -XX:PerfDataSaveFile=.. overrides flag // -XX:+PerfDataSaveToFile. - if (PerfDataSaveToFile || PerfDataSaveFile != NULL) { + if (PerfDataSaveToFile || PerfDataSaveFile != nullptr) { save_memory_to_file(start(), capacity()); } diff --git a/src/hotspot/os/windows/semaphore_windows.cpp b/src/hotspot/os/windows/semaphore_windows.cpp index 189184abd7b..22b06241841 100644 --- a/src/hotspot/os/windows/semaphore_windows.cpp +++ b/src/hotspot/os/windows/semaphore_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 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,9 +30,9 @@ #include WindowsSemaphore::WindowsSemaphore(uint value) { - _semaphore = ::CreateSemaphore(NULL, value, LONG_MAX, NULL); + _semaphore = ::CreateSemaphore(nullptr, value, LONG_MAX, nullptr); - guarantee(_semaphore != NULL, "CreateSemaphore failed with error code: %lu", GetLastError()); + guarantee(_semaphore != nullptr, "CreateSemaphore failed with error code: %lu", GetLastError()); } WindowsSemaphore::~WindowsSemaphore() { @@ -41,7 +41,7 @@ WindowsSemaphore::~WindowsSemaphore() { void WindowsSemaphore::signal(uint count) { if (count > 0) { - BOOL ret = ::ReleaseSemaphore(_semaphore, count, NULL); + BOOL ret = ::ReleaseSemaphore(_semaphore, count, nullptr); assert(ret != 0, "ReleaseSemaphore failed with error code: %lu", GetLastError()); } diff --git a/src/hotspot/os/windows/symbolengine.cpp b/src/hotspot/os/windows/symbolengine.cpp index 8a87b5af0d7..f178c3648b4 100644 --- a/src/hotspot/os/windows/symbolengine.cpp +++ b/src/hotspot/os/windows/symbolengine.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 @@ -91,7 +91,7 @@ class SimpleBufferWithFallback { public: SimpleBufferWithFallback () - : _p(NULL), _capacity(0) + : _p(nullptr), _capacity(0) {} // Note: no destructor because these buffers should, once @@ -101,10 +101,10 @@ public: // Note: We use raw ::malloc/::free here instead of os::malloc()/os::free // to prevent circularities or secondary crashes during error reporting. virtual void initialize () { - assert(_p == NULL && _capacity == 0, "Only call once."); + assert(_p == nullptr && _capacity == 0, "Only call once."); const size_t bytes = OPTIMAL_CAPACITY * sizeof(T); T* q = (T*) ::malloc(bytes); - if (q != NULL) { + if (q != nullptr) { _p = q; _capacity = OPTIMAL_CAPACITY; } else { @@ -206,7 +206,7 @@ public: // Search PDB path for a directory. Search is case insensitive. Returns // true if directory was found in the path, false otherwise. bool contains_directory(const char* directory) { - if (ptr() == NULL) { + if (ptr() == nullptr) { return false; } const size_t len = strlen(directory); @@ -216,7 +216,7 @@ public: char* p = ptr(); for(;;) { char* q = strchr(p, ';'); - if (q != NULL) { + if (q != nullptr) { if (len == (q - p)) { if (_strnicmp(p, directory, len) == 0) { return true; @@ -309,7 +309,7 @@ static struct { // For each loaded module, add the directory it is located in to the pdb search // path, but avoid duplicates. Prior search path content is preserved. // -// If p_search_path_was_updated is not NULL, points to a bool which, upon +// If p_search_path_was_updated is not null, points to a bool which, upon // successful return from the function, contains true if the search path // was updated, false if no update was needed because no new DLLs were // loaded or unloaded. @@ -386,7 +386,7 @@ static bool recalc_search_path_locked(bool* p_search_path_was_updated) { // Cut file name part off. char* last_slash = ::strrchr(filebuffer, '\\'); - if (last_slash == NULL) { + if (last_slash == nullptr) { last_slash = ::strrchr(filebuffer, '/'); } if (last_slash) { @@ -433,10 +433,10 @@ static bool decode_locked(const void* addr, char* buf, int buflen, int* offset, assert(g_buffers.decode_buffer.capacity() >= (sizeof(IMAGEHLP_SYMBOL64) + MINIMUM_SYMBOL_NAME_LEN), "Decode buffer too small."); - assert(buf != NULL && buflen > 0 && offset != NULL, "invalid output buffer."); + assert(buf != nullptr && buflen > 0 && offset != nullptr, "invalid output buffer."); DWORD64 displacement; - PIMAGEHLP_SYMBOL64 pSymbol = NULL; + PIMAGEHLP_SYMBOL64 pSymbol = nullptr; bool success = false; pSymbol = (PIMAGEHLP_SYMBOL64) g_buffers.decode_buffer.ptr(); @@ -492,7 +492,7 @@ static void initialize() { HANDLE hProcess = ::GetCurrentProcess(); WindowsDbgHelp::symSetOptions(SYMOPT_FAIL_CRITICAL_ERRORS | SYMOPT_DEFERRED_LOADS | SYMOPT_EXACT_SYMBOLS | SYMOPT_LOAD_LINES); - if (!WindowsDbgHelp::symInitialize(hProcess, NULL, TRUE)) { + if (!WindowsDbgHelp::symInitialize(hProcess, nullptr, TRUE)) { return; } @@ -500,7 +500,7 @@ static void initialize() { // usable enough. g_state = state_ready; - (void)recalc_search_path_locked(NULL); + (void)recalc_search_path_locked(nullptr); } @@ -533,11 +533,11 @@ void SymbolEngine::pre_initialize() { bool SymbolEngine::decode(const void* addr, char* buf, int buflen, int* offset, bool do_demangle) { - assert(buf != NULL && buflen > 0 && offset != NULL, "Argument error"); + assert(buf != nullptr && buflen > 0 && offset != nullptr, "Argument error"); buf[0] = '\0'; *offset = -1; - if (addr == NULL) { + if (addr == nullptr) { return false; } @@ -579,11 +579,11 @@ bool SymbolEngine::recalc_search_path(bool* p_search_path_was_updated) { bool SymbolEngine::get_source_info(const void* addr, char* buf, size_t buflen, int* line_no) { - assert(buf != NULL && buflen > 0 && line_no != NULL, "Argument error"); + assert(buf != nullptr && buflen > 0 && line_no != nullptr, "Argument error"); buf[0] = '\0'; *line_no = -1; - if (addr == NULL) { + if (addr == nullptr) { return false; } @@ -595,7 +595,7 @@ bool SymbolEngine::get_source_info(const void* addr, char* buf, size_t buflen, DWORD displacement; if (WindowsDbgHelp::symGetLineFromAddr64(::GetCurrentProcess(), (DWORD64)addr, &displacement, &lineinfo)) { - if (buf != NULL && buflen > 0 && lineinfo.FileName != NULL) { + if (buf != nullptr && buflen > 0 && lineinfo.FileName != nullptr) { // We only return the file name, not the whole path. char* p = lineinfo.FileName; char* q = strrchr(lineinfo.FileName, '\\'); diff --git a/src/hotspot/os/windows/symbolengine.hpp b/src/hotspot/os/windows/symbolengine.hpp index 87536226e63..af22131d04a 100644 --- a/src/hotspot/os/windows/symbolengine.hpp +++ b/src/hotspot/os/windows/symbolengine.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2017 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -42,12 +42,12 @@ namespace SymbolEngine { // to the current search path, unless they are already part of the search // path. Prior search path content is preserved, directories are only // added, never removed. - // If p_search_path_was_updated is not NULL, points to a bool which, upon + // If p_search_path_was_updated is not null, points to a bool which, upon // successful return from the function, contains true if the search path // was updated, false if no update was needed because no new DLLs were // loaded or unloaded. // Returns true for success, false for error. - bool recalc_search_path(bool* p_search_path_was_updated = NULL); + bool recalc_search_path(bool* p_search_path_was_updated = nullptr); // Print one liner describing state (if library loaded, which functions are // missing - if any, and the dbhelp API version) diff --git a/src/hotspot/os/windows/threadCrashProtection_windows.cpp b/src/hotspot/os/windows/threadCrashProtection_windows.cpp index bebf6efa443..b8caa7aff5e 100644 --- a/src/hotspot/os/windows/threadCrashProtection_windows.cpp +++ b/src/hotspot/os/windows/threadCrashProtection_windows.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 @@ -26,8 +26,8 @@ #include "runtime/thread.hpp" #include "runtime/threadCrashProtection.hpp" -Thread* ThreadCrashProtection::_protected_thread = NULL; -ThreadCrashProtection* ThreadCrashProtection::_crash_protection = NULL; +Thread* ThreadCrashProtection::_protected_thread = nullptr; +ThreadCrashProtection* ThreadCrashProtection::_crash_protection = nullptr; ThreadCrashProtection::ThreadCrashProtection() { _protected_thread = Thread::current(); @@ -49,7 +49,7 @@ bool ThreadCrashProtection::call(CrashProtectionCallback& cb) { // only for protection, nothing to do success = false; } - _crash_protection = NULL; - _protected_thread = NULL; + _crash_protection = nullptr; + _protected_thread = nullptr; return success; } diff --git a/src/hotspot/os/windows/threadCrashProtection_windows.hpp b/src/hotspot/os/windows/threadCrashProtection_windows.hpp index 29e42b91af2..9ce8a189471 100644 --- a/src/hotspot/os/windows/threadCrashProtection_windows.hpp +++ b/src/hotspot/os/windows/threadCrashProtection_windows.hpp @@ -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 @@ -41,7 +41,7 @@ class Thread; class ThreadCrashProtection : public StackObj { public: static bool is_crash_protected(Thread* thr) { - return _crash_protection != NULL && _protected_thread == thr; + return _crash_protection != nullptr && _protected_thread == thr; } ThreadCrashProtection(); diff --git a/src/hotspot/os/windows/threadCritical_windows.cpp b/src/hotspot/os/windows/threadCritical_windows.cpp index 105e0beb199..f781a422484 100644 --- a/src/hotspot/os/windows/threadCritical_windows.cpp +++ b/src/hotspot/os/windows/threadCritical_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -52,13 +52,13 @@ static DWORD lock_owner = 0; // static BOOL WINAPI initialize(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *Context) { - lock_event = CreateEvent(NULL, false, true, NULL); - assert(lock_event != NULL, "unexpected return value from CreateEvent"); + lock_event = CreateEvent(nullptr, false, true, nullptr); + assert(lock_event != nullptr, "unexpected return value from CreateEvent"); return true; } ThreadCritical::ThreadCritical() { - InitOnceExecuteOnce(&initialized, &initialize, NULL, NULL); + InitOnceExecuteOnce(&initialized, &initialize, nullptr, nullptr); DWORD current_thread = GetCurrentThreadId(); if (lock_owner != current_thread) { diff --git a/src/hotspot/os/windows/vmError_windows.cpp b/src/hotspot/os/windows/vmError_windows.cpp index 89f1e90ebd6..5ae2b9adae8 100644 --- a/src/hotspot/os/windows/vmError_windows.cpp +++ b/src/hotspot/os/windows/vmError_windows.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -31,7 +31,7 @@ LONG WINAPI crash_handler(struct _EXCEPTION_POINTERS* exceptionInfo) { DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode; - VMError::report_and_die(NULL, exception_code, NULL, exceptionInfo->ExceptionRecord, + VMError::report_and_die(nullptr, exception_code, nullptr, exceptionInfo->ExceptionRecord, exceptionInfo->ContextRecord); return EXCEPTION_CONTINUE_SEARCH; } @@ -49,7 +49,7 @@ void VMError::check_failing_cds_access(outputStream* st, const void* siginfo) { if (er->ExceptionCode == EXCEPTION_IN_PAGE_ERROR && er->NumberParameters >= 2) { const void* const fault_addr = (const void*) er->ExceptionInformation[1]; - if (fault_addr != NULL) { + if (fault_addr != nullptr) { if (MetaspaceShared::is_in_shared_metaspace(fault_addr)) { st->print("Error accessing class data sharing archive. " "Mapped file inaccessible during execution, possible disk/network problem."); diff --git a/src/hotspot/os/windows/windbghelp.cpp b/src/hotspot/os/windows/windbghelp.cpp index e55ecc1d5b3..db4538ccf0f 100644 --- a/src/hotspot/os/windows/windbghelp.cpp +++ b/src/hotspot/os/windows/windbghelp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 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 @@ -77,7 +77,7 @@ static pfn_##functionname g_pfn_##functionname; FOR_ALL_FUNCTIONS(DECLARE_FUNCTION_POINTER) -static HMODULE g_dll_handle = NULL; +static HMODULE g_dll_handle = nullptr; static DWORD g_dll_load_error = 0; static API_VERSION g_version = { 0, 0, 0, 0 }; @@ -93,7 +93,7 @@ static void initialize() { g_state = state_error; g_dll_handle = ::LoadLibrary("DBGHELP.DLL"); - if (g_dll_handle == NULL) { + if (g_dll_handle == nullptr) { g_dll_load_error = ::GetLastError(); } else { // Note: We loaded the DLL successfully. From here on we count @@ -146,7 +146,7 @@ void WindowsDbgHelp::pre_initialize() { DWORD WindowsDbgHelp::symSetOptions(DWORD arg) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_SymSetOptions != NULL) { + if (g_pfn_SymSetOptions != nullptr) { return g_pfn_SymSetOptions(arg); } return 0; @@ -154,7 +154,7 @@ DWORD WindowsDbgHelp::symSetOptions(DWORD arg) { DWORD WindowsDbgHelp::symGetOptions(void) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_SymGetOptions != NULL) { + if (g_pfn_SymGetOptions != nullptr) { return g_pfn_SymGetOptions(); } return 0; @@ -162,7 +162,7 @@ DWORD WindowsDbgHelp::symGetOptions(void) { BOOL WindowsDbgHelp::symInitialize(HANDLE hProcess, PCTSTR UserSearchPath, BOOL fInvadeProcess) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_SymInitialize != NULL) { + if (g_pfn_SymInitialize != nullptr) { return g_pfn_SymInitialize(hProcess, UserSearchPath, fInvadeProcess); } return FALSE; @@ -171,7 +171,7 @@ BOOL WindowsDbgHelp::symInitialize(HANDLE hProcess, PCTSTR UserSearchPath, BOOL BOOL WindowsDbgHelp::symGetSymFromAddr64(HANDLE hProcess, DWORD64 the_address, PDWORD64 Displacement, PIMAGEHLP_SYMBOL64 Symbol) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_SymGetSymFromAddr64 != NULL) { + if (g_pfn_SymGetSymFromAddr64 != nullptr) { return g_pfn_SymGetSymFromAddr64(hProcess, the_address, Displacement, Symbol); } return FALSE; @@ -180,10 +180,10 @@ BOOL WindowsDbgHelp::symGetSymFromAddr64(HANDLE hProcess, DWORD64 the_address, DWORD WindowsDbgHelp::unDecorateSymbolName(const char* DecoratedName, char* UnDecoratedName, DWORD UndecoratedLength, DWORD Flags) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_UnDecorateSymbolName != NULL) { + if (g_pfn_UnDecorateSymbolName != nullptr) { return g_pfn_UnDecorateSymbolName(DecoratedName, UnDecoratedName, UndecoratedLength, Flags); } - if (UnDecoratedName != NULL && UndecoratedLength > 0) { + if (UnDecoratedName != nullptr && UndecoratedLength > 0) { UnDecoratedName[0] = '\0'; } return 0; @@ -191,7 +191,7 @@ DWORD WindowsDbgHelp::unDecorateSymbolName(const char* DecoratedName, char* UnDe BOOL WindowsDbgHelp::symSetSearchPath(HANDLE hProcess, PCTSTR SearchPath) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_SymSetSearchPath != NULL) { + if (g_pfn_SymSetSearchPath != nullptr) { return g_pfn_SymSetSearchPath(hProcess, SearchPath); } return FALSE; @@ -199,7 +199,7 @@ BOOL WindowsDbgHelp::symSetSearchPath(HANDLE hProcess, PCTSTR SearchPath) { BOOL WindowsDbgHelp::symGetSearchPath(HANDLE hProcess, PTSTR SearchPath, int SearchPathLength) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_SymGetSearchPath != NULL) { + if (g_pfn_SymGetSearchPath != nullptr) { return g_pfn_SymGetSearchPath(hProcess, SearchPath, SearchPathLength); } return FALSE; @@ -211,13 +211,13 @@ BOOL WindowsDbgHelp::stackWalk64(DWORD MachineType, LPSTACKFRAME64 StackFrame, PVOID ContextRecord) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_StackWalk64 != NULL) { + if (g_pfn_StackWalk64 != nullptr) { return g_pfn_StackWalk64(MachineType, hProcess, hThread, StackFrame, ContextRecord, - NULL, // ReadMemoryRoutine + nullptr, // ReadMemoryRoutine g_pfn_SymFunctionTableAccess64, // FunctionTableAccessRoutine, g_pfn_SymGetModuleBase64, // GetModuleBaseRoutine - NULL // TranslateAddressRoutine + nullptr // TranslateAddressRoutine ); } return FALSE; @@ -225,15 +225,15 @@ BOOL WindowsDbgHelp::stackWalk64(DWORD MachineType, PVOID WindowsDbgHelp::symFunctionTableAccess64(HANDLE hProcess, DWORD64 AddrBase) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_SymFunctionTableAccess64 != NULL) { + if (g_pfn_SymFunctionTableAccess64 != nullptr) { return g_pfn_SymFunctionTableAccess64(hProcess, AddrBase); } - return NULL; + return nullptr; } DWORD64 WindowsDbgHelp::symGetModuleBase64(HANDLE hProcess, DWORD64 dwAddr) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_SymGetModuleBase64 != NULL) { + if (g_pfn_SymGetModuleBase64 != nullptr) { return g_pfn_SymGetModuleBase64(hProcess, dwAddr); } return 0; @@ -244,7 +244,7 @@ BOOL WindowsDbgHelp::miniDumpWriteDump(HANDLE hProcess, DWORD ProcessId, HANDLE PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, PMINIDUMP_CALLBACK_INFORMATION CallbackParam) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_MiniDumpWriteDump != NULL) { + if (g_pfn_MiniDumpWriteDump != nullptr) { return g_pfn_MiniDumpWriteDump(hProcess, ProcessId, hFile, DumpType, ExceptionParam, UserStreamParam, CallbackParam); } @@ -254,7 +254,7 @@ BOOL WindowsDbgHelp::miniDumpWriteDump(HANDLE hProcess, DWORD ProcessId, HANDLE BOOL WindowsDbgHelp::symGetLineFromAddr64(HANDLE hProcess, DWORD64 dwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line) { WindowsDbgHelpEntry entry_guard; - if (g_pfn_SymGetLineFromAddr64 != NULL) { + if (g_pfn_SymGetLineFromAddr64 != nullptr) { return g_pfn_SymGetLineFromAddr64(hProcess, dwAddr, pdwDisplacement, Line); } return FALSE; @@ -288,7 +288,7 @@ void WindowsDbgHelp::print_state_on(outputStream* st) { st->print(" - missing functions: "); #define CHECK_AND_PRINT_IF_NULL(functionname) \ - if (g_pfn_##functionname == NULL) { \ + if (g_pfn_##functionname == nullptr) { \ st->print("%s" #functionname, ((num_missing > 0) ? ", " : "")); \ num_missing ++; \ }