Skip to content

Commit fbceea9

Browse files
committed
8357086: Addressed reviewer's comments
1 parent a3898f4 commit fbceea9

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

src/hotspot/os/linux/os_linux.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ bool os::Linux::free_memory(size_t& value) {
294294
bool os::total_swap_space(size_t& value) {
295295
if (OSContainer::is_containerized() && OSContainer::memory_and_swap_limit_in_bytes() > 0) {
296296
if (OSContainer::memory_limit_in_bytes() > 0) {
297-
value = static_cast<size_t>(OSContainer::memory_and_swap_limit_in_bytes() - OSContainer::memory_limit_in_bytes());
297+
jlong memory_and_swap_limit_in_bytes = OSContainer::memory_and_swap_limit_in_bytes();
298+
jlong memory_limit_in_bytes = OSContainer::memory_limit_in_bytes();
299+
value = static_cast<size_t>(memory_and_swap_limit_in_bytes - memory_limit_in_bytes);
298300
return true;
299301
}
300302
} // fallback to the host swap space if the container did return the unbound value of -1

src/hotspot/os/windows/os_windows.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -862,35 +862,41 @@ bool os::win32::available_memory(size_t& value) {
862862
MEMORYSTATUSEX ms;
863863
ms.dwLength = sizeof(ms);
864864
BOOL res = GlobalMemoryStatusEx(&ms);
865-
if (res) {
865+
if (res == TRUE) {
866866
value = static_cast<size_t>(ms.ullAvailPhys);
867867
return true;
868868
} else {
869-
return false;
869+
errno = ::GetLastError();
870+
log_debug(os)("available_memory() failed to GlobalMemoryStatusEx: GetLastError->%ld.", errno);
871+
return res == TRUE;
870872
}
871873
}
872874

873875
bool os::total_swap_space(size_t& value) {
874876
MEMORYSTATUSEX ms;
875877
ms.dwLength = sizeof(ms);
876878
BOOL res = GlobalMemoryStatusEx(&ms);
877-
if (res) {
879+
if (res == TRUE) {
878880
value = static_cast<size_t>(ms.ullTotalPageFile);
879881
return true;
880882
} else {
881-
return false;
883+
errno = ::GetLastError();
884+
log_debug(os)("total_swap_space() failed to GlobalMemoryStatusEx: GetLastError->%ld.", errno);
885+
return res == TRUE;
882886
}
883887
}
884888

885889
bool os::free_swap_space(size_t& value) {
886890
MEMORYSTATUSEX ms;
887891
ms.dwLength = sizeof(ms);
888892
BOOL res = GlobalMemoryStatusEx(&ms);
889-
if (res) {
893+
if (res == TRUE) {
890894
value = static_cast<size_t>(ms.ullAvailPageFile);
891895
return true;
892896
} else {
893-
return false;
897+
errno = ::GetLastError();
898+
log_debug(os)("free_swap_space() failed to GlobalMemoryStatusEx: GetLastError->%ld.", errno);
899+
return res == TRUE;
894900
}
895901
}
896902

src/hotspot/share/jfr/jni/jfrJniMethod.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ JVM_ENTRY_NO_ENV(jlong, jfr_host_total_memory(JNIEnv* env, jclass jvm))
414414
// os::physical_memory() would return the container limit.
415415
return os::Linux::physical_memory();
416416
#else
417-
size_t phys_mem = os::physical_memory();
418-
return static_cast<jlong>(phys_mem);
417+
return static_cast<jlong>(os::physical_memory());
419418
#endif
420419
JVM_END
421420

src/hotspot/share/jfr/periodic/jfrPeriodic.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,11 @@ TRACE_REQUEST_FUNC(ThreadAllocationStatistics) {
528528
* the total memory reported is the amount of memory configured for the guest OS by the hypervisor.
529529
*/
530530
TRACE_REQUEST_FUNC(PhysicalMemory) {
531-
size_t phys_mem = os::physical_memory();
532-
u8 totalPhysicalMemory = static_cast<u8>(phys_mem);
531+
u8 totalPhysicalMemory = static_cast<u8>(os::physical_memory());
533532
EventPhysicalMemory event;
534533
event.set_totalSize(totalPhysicalMemory);
535534
size_t avail_mem = 0;
535+
// Return value ignored - defaulting to 0 on failure.
536536
(void)os::available_memory(avail_mem);
537537
event.set_usedSize(totalPhysicalMemory - static_cast<u8>(avail_mem));
538538
event.commit();
@@ -541,9 +541,11 @@ TRACE_REQUEST_FUNC(PhysicalMemory) {
541541
TRACE_REQUEST_FUNC(SwapSpace) {
542542
EventSwapSpace event;
543543
size_t total_swap_space = 0;
544+
// Return value ignored - defaulting to 0 on failure.
544545
(void)os::total_swap_space(total_swap_space);
545546
event.set_totalSize(static_cast<s8>(total_swap_space));
546547
size_t free_swap_space = 0;
548+
// Return value ignored - defaulting to 0 on failure.
547549
(void)os::free_swap_space(free_swap_space);
548550
event.set_freeSize(static_cast<s8>(free_swap_space));
549551
event.commit();

src/hotspot/share/prims/jvmtiRedefineClasses.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,7 @@ jvmtiError VM_RedefineClasses::load_new_class_versions() {
13591359
HandleMark hm(current);
13601360
InstanceKlass* the_class = get_ik(_class_defs[i].klass);
13611361
size_t avail_mem = 0;
1362+
// Return value ignored - defaulting to 0 on failure.
13621363
(void)os::available_memory(avail_mem);
13631364
log_debug(redefine, class, load)
13641365
("loading name=%s kind=%d (avail_mem=%zuK)",
@@ -1526,6 +1527,7 @@ jvmtiError VM_RedefineClasses::load_new_class_versions() {
15261527
return JVMTI_ERROR_INTERNAL;
15271528
}
15281529
}
1530+
// Return value ignored - defaulting to 0 on failure.
15291531
(void)os::available_memory(avail_mem);
15301532
log_debug(redefine, class, load)
15311533
("loaded name=%s (avail_mem=%zuK)", the_class->external_name(), avail_mem >> 10);
@@ -4437,6 +4439,7 @@ void VM_RedefineClasses::redefine_single_class(Thread* current, jclass the_jclas
44374439
// increment the classRedefinedCount field in the_class and in any
44384440
// direct and indirect subclasses of the_class
44394441
size_t avail_mem = 0;
4442+
// Return value ignored - defaulting to 0 on failure.
44404443
(void)os::available_memory(avail_mem);
44414444
log_info(redefine, class, load)
44424445
("redefined name=%s, count=%d (avail_mem=%zuK)",

src/hotspot/share/prims/whitebox.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,8 +2512,7 @@ WB_END
25122512
// Physical memory of the host machine (including containers)
25132513
WB_ENTRY(jlong, WB_HostPhysicalMemory(JNIEnv* env, jobject o))
25142514
LINUX_ONLY(return static_cast<jlong>(os::Linux::physical_memory());)
2515-
size_t phys_mem = os::physical_memory();
2516-
return static_cast<jlong>(phys_mem);
2515+
return static_cast<jlong>(os::physical_memory());
25172516
WB_END
25182517

25192518
// Available memory of the host machine (container-aware)

src/hotspot/share/services/heapDumper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,7 @@ int HeapDumper::dump(const char* path, outputStream* out, int compression, bool
26132613
// For the OOM handling we may already be limited in memory.
26142614
// Lets ensure we have at least 20MB per thread.
26152615
size_t free_memory = 0;
2616+
// Return value ignored - defaulting to 0 on failure.
26162617
(void)os::free_memory(free_memory);
26172618
julong max_threads = free_memory / (20 * M);
26182619
if (num_dump_threads > max_threads) {

0 commit comments

Comments
 (0)