author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
13668
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
1 |
/* |
30376
2ccf2cf7ea48
8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents:
13668
diff
changeset
|
2 |
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
13668
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
4 |
* |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
8 |
* |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
13 |
* accompanied this code). |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
14 |
* |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
18 |
* |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
21 |
* questions. |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
22 |
*/ |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
23 |
|
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
24 |
|
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
25 |
/* |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
26 |
* @test |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
27 |
* @bug 6853676 |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
28 |
* @summary On computers with more than 4 GB of memory, |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
29 |
* the GlobalMemoryStatus function can return incorrect information, |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
30 |
* reporting a value of -1 to indicate an overflow. |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
31 |
* |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
32 |
* @run main MemoryStatusOverflow |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
33 |
*/ |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
34 |
|
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
35 |
import java.lang.reflect.Method; |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
36 |
import java.util.Arrays; |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
37 |
import java.util.ArrayList; |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
38 |
import java.util.List; |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
39 |
import java.lang.management.ManagementFactory; |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
40 |
import com.sun.management.OperatingSystemMXBean; |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
41 |
|
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
42 |
public class MemoryStatusOverflow { |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
43 |
static final long MEMORYSTATUS_OVERFLOW = (1L << 32) - 1; // (DWORD) -1 |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
44 |
|
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
45 |
public static void main(String... args) throws Exception { |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
46 |
OperatingSystemMXBean bean = (OperatingSystemMXBean) |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
47 |
ManagementFactory.getOperatingSystemMXBean(); |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
48 |
List<String> failedGetterNames = new ArrayList<String>(); |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
49 |
List<String> testedGetterNames = Arrays.asList( |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
50 |
"getTotalSwapSpaceSize", "getFreeSwapSpaceSize", |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
51 |
"getTotalPhysicalMemorySize", "getFreePhysicalMemorySize"); |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
52 |
for (String getterName : testedGetterNames) { |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
53 |
Method getter = OperatingSystemMXBean.class.getMethod(getterName); |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
54 |
long value = (Long) getter.invoke(bean); |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
55 |
if (value == MEMORYSTATUS_OVERFLOW) { |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
56 |
failedGetterNames.add(getterName); |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
57 |
} |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
58 |
} |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
59 |
if (!failedGetterNames.isEmpty()) { |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
60 |
throw new AssertionError(failedGetterNames); |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
61 |
} |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
62 |
System.out.println("Test passed."); |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
63 |
} |
c85b9828f8ff
6853676: OperatingSystemMXBean.TotalPhysicalMemorySize has incorrect value
sla
parents:
diff
changeset
|
64 |
} |