Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/management/MemoryPoolMXBean/LargeHeapThresholdTest.java
41152 views
1
/*
2
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6653214
27
* @requires os.simpleArch=="x64"
28
* @run main/othervm -Xmx3000M LargeHeapThresholdTest
29
* @summary MemoryPoolMXBean.setUsageThreshold() does not support large heap sizes
30
*
31
* Large is >= 2 gigabytes
32
* This test tries to find memory pools with maximum allowable size of at
33
* least 2 gigabytes and set their usage thresholds to this value. If tested
34
* Java implementation is defective
35
* "java.lang.IllegalArgumentException: Invalid threshold value > max value of size_t"
36
* will be thrown.
37
* If no pool with maximum allowable size of at least 2 gigabytes exists
38
* the test passes. There is a good chance that such pool will exist if JVM
39
* is started with '-Xmx3000M' command line switch.
40
*/
41
42
43
import java.lang.management.ManagementFactory;
44
import java.lang.management.MemoryPoolMXBean;
45
import java.util.List;
46
47
48
public class LargeHeapThresholdTest {
49
50
final static long TWO_G = ((long) Integer.MAX_VALUE + 1); // 2 gigabytes
51
52
public static void main(String[] args) {
53
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
54
boolean verified = false;
55
for (MemoryPoolMXBean i : pools) {
56
if ((i.getUsage().getMax() >= TWO_G)
57
&& i.isUsageThresholdSupported()) {
58
i.setUsageThreshold(TWO_G);
59
if(i.getUsageThreshold() != TWO_G)
60
throw new RuntimeException("Usage threshold for"
61
+ " pool '" + i.getName() + "' is " + i.getUsageThreshold()
62
+ " and not equal to 2GB");
63
verified = true;
64
}
65
}
66
System.out.println("Ability to use big heap thresholds has "
67
+ (verified ? "" : "NOT ") + "been verified");
68
}
69
}
70
71