Skip to content

Commit

Permalink
8206179: com/sun/management/OperatingSystemMXBean/GetCommittedVirtual…
Browse files Browse the repository at this point in the history
…MemorySize.java fails with Committed virtual memory size illegal value

Reviewed-by: andrew, phh
Backport-of: 1ea3869a926003cd3cebd3d8ecf9657646bdbda3
  • Loading branch information
Ben Taylor authored and Paul Hohensee committed Aug 30, 2023
1 parent 6c67bf6 commit bbc068f
Showing 1 changed file with 4 additions and 15 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2019, 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
Expand Down Expand Up @@ -56,8 +56,7 @@ public class GetCommittedVirtualMemorySize {

// Careful with these values.
private static final long MIN_SIZE_FOR_PASS = 1;
// Max size for pass dynamically determined below
private static long max_size_for_pass = Long.MAX_VALUE;
private static long MAX_SIZE_FOR_PASS = Long.MAX_VALUE;

private static boolean trace = false;

Expand All @@ -66,16 +65,6 @@ public static void main(String args[]) throws Exception {
trace = true;
}

// 4934082: On Linux, VM size *can* be larger than total swap
// size. Linux might not reserve swap memory immediately when
// a page is mmaped. This means that the reported committed
// memory size can grow beyond the swap limit.
long max_size = mbean.getTotalSwapSpaceSize() +
mbean.getTotalPhysicalMemorySize();

if (max_size > 0) {
max_size_for_pass = max_size;
}
long size = mbean.getCommittedVirtualMemorySize();
if (size == -1) {
System.out.println("getCommittedVirtualMemorySize() is not supported");
Expand All @@ -87,11 +76,11 @@ public static void main(String args[]) throws Exception {
size);
}

if (size < MIN_SIZE_FOR_PASS || size > max_size_for_pass) {
if (size < MIN_SIZE_FOR_PASS || size > MAX_SIZE_FOR_PASS) {
throw new RuntimeException("Committed virtual memory size " +
"illegal value: " + size + " bytes " +
"(MIN = " + MIN_SIZE_FOR_PASS + "; " +
"MAX = " + max_size_for_pass + ")");
"MAX = " + MAX_SIZE_FOR_PASS + ")");
}

System.out.println("Test passed.");
Expand Down

1 comment on commit bbc068f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.