Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/Allocate/alloc001/alloc001.java
40951 views
/*1* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324/*25* @test26*27* @summary converted from VM Testbase nsk/jvmti/Allocate/alloc001.28* VM Testbase keywords: [jpda, jvmti, noras, nonconcurrent]29* VM Testbase readme:30* DESCRIPTION31* The test exercise JVMTI function Allocate(size, memPtr).32* The test checks the following:33* - if JVMTI_ERROR_NULL_POINTER is returned when memPtr is null34* - if allocated memory is available to access35* - if JVMTI_ERROR_OUT_OF_MEMORY is returned when there is36* insufficient memory available37* COMMENTS38* Ported from JVMDI.39*40* @library /vmTestbase41* /test/lib42*43* @comment Not run on AIX as it does not support ulimit -v44* @requires os.family != "aix"45* @run main/native nsk.jvmti.Allocate.alloc001.alloc00146*/4748package nsk.jvmti.Allocate.alloc001;4950import jdk.test.lib.Platform;51import jdk.test.lib.Utils;52import jdk.test.lib.process.ProcessTools;53import jtreg.SkippedException;5455import java.io.File;5657class Test {58static {59try {60System.loadLibrary("alloc001");61} catch (UnsatisfiedLinkError ule) {62System.err.println("Could not load alloc001 library");63System.err.println("java.library.path:" + System.getProperty("java.library.path"));64throw ule;65}66}6768native static int check();6970public static void main(String[] args) {71System.exit(alloc001.STATUS_BASE + check());72}73}7475public class alloc001 {76public static final int STATUS_BASE = 95;77private static final int STATUS_PASSED = 0 + STATUS_BASE;78// FAILED_NO_OOM (as defined in alloc001.cpp) + STATUS_BASE79private static final int STATUS_NO_OOM = 3 + STATUS_BASE;8081public static void main(String[] args) throws Throwable {82String cmd = ProcessTools.getCommandLine(ProcessTools.createTestJvm(83"-XX:MaxHeapSize=" + (Platform.is32bit() ? "256m" : "512m"),84"-Djava.library.path=" + Utils.TEST_NATIVE_PATH,85"-agentpath:" + Utils.TEST_NATIVE_PATH + File.separator + System.mapLibraryName("alloc001"),86"-XX:CompressedClassSpaceSize=64m",87Test.class.getName()88));89cmd = escapeCmd(cmd);9091int ulimitV = Platform.is32bit() ? 1048576 : 4194303;92var pb = new ProcessBuilder(93"sh", "-c",94"ulimit -v " + ulimitV + "; " + cmd);9596// lower MALLOC_ARENA_MAX b/c we limited virtual memory, see JDK-804351697pb.environment().put("MALLOC_ARENA_MAX", "4");9899var oa = ProcessTools.executeCommand(pb);100int exitCode = oa.getExitValue();101if (exitCode == STATUS_NO_OOM && (Platform.isWindows() || Platform.isOSX())) {102throw new SkippedException("Test did not get an OutOfMemory error");103}104oa.shouldHaveExitValue(STATUS_PASSED);105}106107private static String escapeCmd(String cmd) {108if (Platform.isWindows()) {109return cmd.replace('\\', '/')110.replace(";", "\\;")111.replace("|", "\\|");112}113return cmd;114}115}116117118