Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.java
40951 views
1
/*
2
* Copyright (c) 2003, 2020, 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
/*
26
* @test
27
*
28
* @summary converted from VM Testbase nsk/jvmti/Allocate/alloc001.
29
* VM Testbase keywords: [jpda, jvmti, noras, nonconcurrent]
30
* VM Testbase readme:
31
* DESCRIPTION
32
* The test exercise JVMTI function Allocate(size, memPtr).
33
* The test checks the following:
34
* - if JVMTI_ERROR_NULL_POINTER is returned when memPtr is null
35
* - if allocated memory is available to access
36
* - if JVMTI_ERROR_OUT_OF_MEMORY is returned when there is
37
* insufficient memory available
38
* COMMENTS
39
* Ported from JVMDI.
40
*
41
* @library /vmTestbase
42
* /test/lib
43
*
44
* @comment Not run on AIX as it does not support ulimit -v
45
* @requires os.family != "aix"
46
* @run main/native nsk.jvmti.Allocate.alloc001.alloc001
47
*/
48
49
package nsk.jvmti.Allocate.alloc001;
50
51
import jdk.test.lib.Platform;
52
import jdk.test.lib.Utils;
53
import jdk.test.lib.process.ProcessTools;
54
import jtreg.SkippedException;
55
56
import java.io.File;
57
58
class Test {
59
static {
60
try {
61
System.loadLibrary("alloc001");
62
} catch (UnsatisfiedLinkError ule) {
63
System.err.println("Could not load alloc001 library");
64
System.err.println("java.library.path:" + System.getProperty("java.library.path"));
65
throw ule;
66
}
67
}
68
69
native static int check();
70
71
public static void main(String[] args) {
72
System.exit(alloc001.STATUS_BASE + check());
73
}
74
}
75
76
public class alloc001 {
77
public static final int STATUS_BASE = 95;
78
private static final int STATUS_PASSED = 0 + STATUS_BASE;
79
// FAILED_NO_OOM (as defined in alloc001.cpp) + STATUS_BASE
80
private static final int STATUS_NO_OOM = 3 + STATUS_BASE;
81
82
public static void main(String[] args) throws Throwable {
83
String cmd = ProcessTools.getCommandLine(ProcessTools.createTestJvm(
84
"-XX:MaxHeapSize=" + (Platform.is32bit() ? "256m" : "512m"),
85
"-Djava.library.path=" + Utils.TEST_NATIVE_PATH,
86
"-agentpath:" + Utils.TEST_NATIVE_PATH + File.separator + System.mapLibraryName("alloc001"),
87
"-XX:CompressedClassSpaceSize=64m",
88
Test.class.getName()
89
));
90
cmd = escapeCmd(cmd);
91
92
int ulimitV = Platform.is32bit() ? 1048576 : 4194303;
93
var pb = new ProcessBuilder(
94
"sh", "-c",
95
"ulimit -v " + ulimitV + "; " + cmd);
96
97
// lower MALLOC_ARENA_MAX b/c we limited virtual memory, see JDK-8043516
98
pb.environment().put("MALLOC_ARENA_MAX", "4");
99
100
var oa = ProcessTools.executeCommand(pb);
101
int exitCode = oa.getExitValue();
102
if (exitCode == STATUS_NO_OOM && (Platform.isWindows() || Platform.isOSX())) {
103
throw new SkippedException("Test did not get an OutOfMemory error");
104
}
105
oa.shouldHaveExitValue(STATUS_PASSED);
106
}
107
108
private static String escapeCmd(String cmd) {
109
if (Platform.isWindows()) {
110
return cmd.replace('\\', '/')
111
.replace(";", "\\;")
112
.replace("|", "\\|");
113
}
114
return cmd;
115
}
116
}
117
118