8252402: rewrite vmTestbase/nsk/jvmti/Allocate/alloc001 shell test to Java
Reviewed-by: amenkov
This commit is contained in:
parent
4fe6a3da68
commit
ca3374253c
@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2003, 2018, 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
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package nsk.jvmti.Allocate;
|
|
||||||
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
public class alloc001 {
|
|
||||||
|
|
||||||
final static int JCK_STATUS_BASE = 95;
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
System.loadLibrary("alloc001");
|
|
||||||
} catch (UnsatisfiedLinkError ule) {
|
|
||||||
System.err.println("Could not load alloc001 library");
|
|
||||||
System.err.println("java.library.path:"
|
|
||||||
+ System.getProperty("java.library.path"));
|
|
||||||
throw ule;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
native static int check();
|
|
||||||
|
|
||||||
public static void main(String args[]) {
|
|
||||||
args = nsk.share.jvmti.JVMTITest.commonInit(args);
|
|
||||||
|
|
||||||
// produce JCK-like exit status.
|
|
||||||
System.exit(run(args, System.out) + JCK_STATUS_BASE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int run(String args[], PrintStream out) {
|
|
||||||
final int ERROR_CODE_NO_OOM = 3; // Error code "FAILED_NO_OOM" defined in alloc001.c
|
|
||||||
int errorCode = check();
|
|
||||||
|
|
||||||
if (errorCode == ERROR_CODE_NO_OOM) {
|
|
||||||
// The test failed because it did not get the expected OutOfMemory error.
|
|
||||||
// If we run on mac, that is quite expected since mac often ignores "ulimit -v"
|
|
||||||
final String os = System.getProperty("os.name").toLowerCase();
|
|
||||||
out.println("os=" + os);
|
|
||||||
if (os.indexOf("mac") >= 0 || os.indexOf("windows") >= 0) {
|
|
||||||
String msg = "Test did not get an OutOfMemory error. " +
|
|
||||||
"That is not surprising on mac or windows. " +
|
|
||||||
"Mac usually ignores 'ulimit -v', and windows does not have it. " +
|
|
||||||
"We consider this test as passed.";
|
|
||||||
out.println(msg);
|
|
||||||
errorCode = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return errorCode;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2018, 2020, 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
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Not run on AIX as it does not support ulimit -v.
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @test
|
|
||||||
*
|
|
||||||
* @summary converted from VM Testbase nsk/jvmti/Allocate/alloc001.
|
|
||||||
* VM Testbase keywords: [jpda, jvmti, noras, nonconcurrent]
|
|
||||||
* VM Testbase readme:
|
|
||||||
* DESCRIPTION
|
|
||||||
* The test exercise JVMTI function Allocate(size, memPtr).
|
|
||||||
* The test checks the following:
|
|
||||||
* - if JVMTI_ERROR_NULL_POINTER is returned when memPtr is null
|
|
||||||
* - if allocated memory is available to access
|
|
||||||
* - if JVMTI_ERROR_OUT_OF_MEMORY is returned when there is
|
|
||||||
* insufficient memory available
|
|
||||||
* COMMENTS
|
|
||||||
* Ported from JVMDI.
|
|
||||||
*
|
|
||||||
* @library /vmTestbase
|
|
||||||
* /test/lib
|
|
||||||
* @requires os.family != "aix"
|
|
||||||
* @build nsk.jvmti.Allocate.alloc001
|
|
||||||
* @run shell alloc001.sh
|
|
||||||
*/
|
|
||||||
|
|
@ -1,88 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Copyright (c) 2008, 2020, 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
|
|
||||||
# under the terms of the GNU General Public License version 2 only, as
|
|
||||||
# published by the Free Software Foundation.
|
|
||||||
#
|
|
||||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
# version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
# accompanied this code).
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License version
|
|
||||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
#
|
|
||||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
# or visit www.oracle.com if you need additional information or have any
|
|
||||||
# questions.
|
|
||||||
|
|
||||||
JAVA="$TESTJAVA/bin/java"
|
|
||||||
JAVA_OPTS="$TESTJAVAOPTS $TESTVMOPTS -cp $TESTCLASSPATH -agentlib:alloc001"
|
|
||||||
|
|
||||||
. ${TESTSRC}/../../../../../test_env.sh
|
|
||||||
|
|
||||||
# Set virtual memory usage limit to be not 'unlimited' on unix platforms
|
|
||||||
# This is workaround for 6683371.
|
|
||||||
case $VM_OS in
|
|
||||||
aix | bsd | linux)
|
|
||||||
echo "Check virtual memory usage limits"
|
|
||||||
soft_limit=`ulimit -S -v` || ""
|
|
||||||
hard_limit=`ulimit -H -v` || ""
|
|
||||||
echo "Virtual memory usage limit (hard): $hard_limit"
|
|
||||||
echo "Virtual memory usage limit (soft): $soft_limit"
|
|
||||||
|
|
||||||
# Need to set ulimit if currently unlimited or > 4GB (1GB on 32 bit)
|
|
||||||
if [ $VM_BITS -eq 32 ]
|
|
||||||
then
|
|
||||||
max_ulimit=1048576
|
|
||||||
max_heap=256m
|
|
||||||
else
|
|
||||||
# AIX requires a 32-bit value here.
|
|
||||||
max_ulimit=4194303
|
|
||||||
max_heap=512m
|
|
||||||
fi
|
|
||||||
|
|
||||||
should_update_ulimit=0
|
|
||||||
if [ -n "$soft_limit" ]; then
|
|
||||||
if [ "$soft_limit" = "unlimited" ]; then
|
|
||||||
should_update_ulimit=1
|
|
||||||
elif [ "$soft_limit" -gt "$max_ulimit" ]; then
|
|
||||||
should_update_ulimit=1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$should_update_ulimit" = "1" ]; then
|
|
||||||
echo "Try to limit virtual memory usage to $max_ulimit"
|
|
||||||
ulimit -S -v $max_ulimit || true
|
|
||||||
fi
|
|
||||||
|
|
||||||
# When we limit virtual memory then we need to also limit other GC args and MALLOC_ARENA_MAX.
|
|
||||||
# Otherwise the JVM may not start. See JDK-8043516
|
|
||||||
JAVA_OPTS="${JAVA_OPTS} -XX:MaxHeapSize=$max_heap -XX:CompressedClassSpaceSize=64m"
|
|
||||||
export MALLOC_ARENA_MAX=4
|
|
||||||
soft_limit=`ulimit -S -v`
|
|
||||||
echo "Virtual memory usage limit (soft): $soft_limit"
|
|
||||||
echo "New JAVA_OPTS: $JAVA_OPTS"
|
|
||||||
echo "export MALLOC_ARENA_MAX=4"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$TESTNATIVEPATH
|
|
||||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TESTNATIVEPATH
|
|
||||||
export LIBPATH=$LIBPATH:$TESTNATIVEPATH
|
|
||||||
export PATH=$PATH:$TESTNATIVEPATH
|
|
||||||
|
|
||||||
echo $JAVA ${JAVA_OPTS} nsk.jvmti.Allocate.alloc001
|
|
||||||
$JAVA ${JAVA_OPTS} nsk.jvmti.Allocate.alloc001
|
|
||||||
exit=$?
|
|
||||||
|
|
||||||
if [ $exit -ne 95 ]
|
|
||||||
then
|
|
||||||
exit $exit
|
|
||||||
fi
|
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -29,20 +29,19 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
|
|
||||||
#define PASSED 0
|
#define PASSED 0
|
||||||
#define STATUS_FAILED 2
|
#define STATUS_FAILED 2
|
||||||
#define FAILED_NO_OOM 3
|
#define FAILED_NO_OOM 3
|
||||||
#define MAX_CHUNK 1024*1024
|
|
||||||
|
#define MAX_CHUNK 1024 * 1024
|
||||||
|
|
||||||
// Limit total allocations to 8Gb.
|
// Limit total allocations to 8Gb.
|
||||||
// Without this check we will loop forever if the OS does not
|
// Without this check we will loop forever if the OS does not
|
||||||
// limit virtual memory (this usually happens on mac).
|
// limit virtual memory (this usually happens on mac).
|
||||||
#define MAX_CHUNK_COUNT 8*1024
|
#define MAX_CHUNK_COUNT 8 * 1024
|
||||||
|
|
||||||
static jvmtiEnv *jvmti = NULL;
|
static jvmtiEnv *jvmti = NULL;
|
||||||
static jint result = PASSED;
|
static jint result = PASSED;
|
||||||
static jboolean printdump = JNI_FALSE;
|
|
||||||
|
|
||||||
#ifdef STATIC_BUILD
|
#ifdef STATIC_BUILD
|
||||||
JNIEXPORT jint JNICALL Agent_OnLoad_alloc001(JavaVM *jvm, char *options, void *reserved) {
|
JNIEXPORT jint JNICALL Agent_OnLoad_alloc001(JavaVM *jvm, char *options, void *reserved) {
|
||||||
@ -55,13 +54,10 @@ JNIEXPORT jint JNI_OnLoad_alloc001(JavaVM *jvm, char *options, void *reserved) {
|
|||||||
return JNI_VERSION_1_8;
|
return JNI_VERSION_1_8;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
||||||
jint res;
|
jint res;
|
||||||
|
|
||||||
if (options != NULL && strcmp(options, "printdump") == 0) {
|
|
||||||
printdump = JNI_TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
|
res = jvm->GetEnv((void **) &jvmti, JVMTI_VERSION_1_1);
|
||||||
if (res != JNI_OK || jvmti == NULL) {
|
if (res != JNI_OK || jvmti == NULL) {
|
||||||
printf("Wrong result of a valid call to GetEnv!\n");
|
printf("Wrong result of a valid call to GetEnv!\n");
|
||||||
@ -72,7 +68,7 @@ jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL
|
JNIEXPORT jint JNICALL
|
||||||
Java_nsk_jvmti_Allocate_alloc001_check(JNIEnv *env, jclass cls) {
|
Java_nsk_jvmti_Allocate_alloc001_Test_check(JNIEnv *env, jclass cls) {
|
||||||
jvmtiError err;
|
jvmtiError err;
|
||||||
size_t size;
|
size_t size;
|
||||||
void *prev = NULL;
|
void *prev = NULL;
|
||||||
@ -84,22 +80,16 @@ Java_nsk_jvmti_Allocate_alloc001_check(JNIEnv *env, jclass cls) {
|
|||||||
return STATUS_FAILED;
|
return STATUS_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printdump == JNI_TRUE) {
|
printf(">>> Null pointer check ...\n");
|
||||||
printf(">>> Null pointer check ...\n");
|
|
||||||
}
|
|
||||||
err = jvmti->Allocate((jlong)1, NULL);
|
err = jvmti->Allocate((jlong)1, NULL);
|
||||||
if (err != JVMTI_ERROR_NULL_POINTER) {
|
if (err != JVMTI_ERROR_NULL_POINTER) {
|
||||||
printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n",
|
printf("Error expected: JVMTI_ERROR_NULL_POINTER, got: %s\n",
|
||||||
TranslateError(err));
|
TranslateError(err));
|
||||||
result = STATUS_FAILED;
|
result = STATUS_FAILED;
|
||||||
}
|
}
|
||||||
if (printdump == JNI_TRUE) {
|
printf(">>> ... done\n");
|
||||||
printf(">>> ... done\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (printdump == JNI_TRUE) {
|
printf(">>> Accessibility check ...\n");
|
||||||
printf(">>> Accessibility check ...\n");
|
|
||||||
}
|
|
||||||
for (size = sizeof(mem); size <= MAX_CHUNK; size <<= 1) {
|
for (size = sizeof(mem); size <= MAX_CHUNK; size <<= 1) {
|
||||||
err = jvmti->Allocate(size, (unsigned char **)&mem);
|
err = jvmti->Allocate(size, (unsigned char **)&mem);
|
||||||
if (err == JVMTI_ERROR_NONE) {
|
if (err == JVMTI_ERROR_NONE) {
|
||||||
@ -115,13 +105,9 @@ Java_nsk_jvmti_Allocate_alloc001_check(JNIEnv *env, jclass cls) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (printdump == JNI_TRUE) {
|
printf(">>> ... done\n");
|
||||||
printf(">>> ... done\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (printdump == JNI_TRUE) {
|
printf(">>> Out of memory check ...\n");
|
||||||
printf(">>> Out of memory check ...\n");
|
|
||||||
}
|
|
||||||
while (err != JVMTI_ERROR_OUT_OF_MEMORY) {
|
while (err != JVMTI_ERROR_OUT_OF_MEMORY) {
|
||||||
err = jvmti->Allocate((jlong)MAX_CHUNK, (unsigned char **)&mem);
|
err = jvmti->Allocate((jlong)MAX_CHUNK, (unsigned char **)&mem);
|
||||||
if (err == JVMTI_ERROR_NONE) {
|
if (err == JVMTI_ERROR_NONE) {
|
||||||
@ -142,17 +128,13 @@ Java_nsk_jvmti_Allocate_alloc001_check(JNIEnv *env, jclass cls) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (printdump == JNI_TRUE && (memCount % 50 == 0)) {
|
if (memCount % 50 == 0) {
|
||||||
printf(">>> ... done (%dMb)\n", memCount);
|
printf(">>> ... done (%dMb)\n", memCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (printdump == JNI_TRUE) {
|
printf(">>> ... done (%dMb)\n", memCount);
|
||||||
printf(">>> ... done (%dMb)\n", memCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (printdump == JNI_TRUE) {
|
printf(">>> Deallocation ...\n");
|
||||||
printf(">>> Deallocation ...\n");
|
|
||||||
}
|
|
||||||
while (prev != NULL) {
|
while (prev != NULL) {
|
||||||
mem = (void**) prev;
|
mem = (void**) prev;
|
||||||
prev = *mem;
|
prev = *mem;
|
||||||
@ -164,9 +146,7 @@ Java_nsk_jvmti_Allocate_alloc001_check(JNIEnv *env, jclass cls) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (printdump == JNI_TRUE) {
|
printf(">>> ... done\n");
|
||||||
printf(">>> ... done\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,116 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2003, 2020, 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
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
*
|
||||||
|
* @summary converted from VM Testbase nsk/jvmti/Allocate/alloc001.
|
||||||
|
* VM Testbase keywords: [jpda, jvmti, noras, nonconcurrent]
|
||||||
|
* VM Testbase readme:
|
||||||
|
* DESCRIPTION
|
||||||
|
* The test exercise JVMTI function Allocate(size, memPtr).
|
||||||
|
* The test checks the following:
|
||||||
|
* - if JVMTI_ERROR_NULL_POINTER is returned when memPtr is null
|
||||||
|
* - if allocated memory is available to access
|
||||||
|
* - if JVMTI_ERROR_OUT_OF_MEMORY is returned when there is
|
||||||
|
* insufficient memory available
|
||||||
|
* COMMENTS
|
||||||
|
* Ported from JVMDI.
|
||||||
|
*
|
||||||
|
* @library /vmTestbase
|
||||||
|
* /test/lib
|
||||||
|
*
|
||||||
|
* @comment Not run on AIX as it does not support ulimit -v
|
||||||
|
* @requires os.family != "aix"
|
||||||
|
* @run main/native nsk.jvmti.Allocate.alloc001.alloc001
|
||||||
|
*/
|
||||||
|
|
||||||
|
package nsk.jvmti.Allocate.alloc001;
|
||||||
|
|
||||||
|
import jdk.test.lib.Platform;
|
||||||
|
import jdk.test.lib.Utils;
|
||||||
|
import jdk.test.lib.process.ProcessTools;
|
||||||
|
import jtreg.SkippedException;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("alloc001");
|
||||||
|
} catch (UnsatisfiedLinkError ule) {
|
||||||
|
System.err.println("Could not load alloc001 library");
|
||||||
|
System.err.println("java.library.path:" + System.getProperty("java.library.path"));
|
||||||
|
throw ule;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
native static int check();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.exit(alloc001.STATUS_BASE + check());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class alloc001 {
|
||||||
|
public static final int STATUS_BASE = 95;
|
||||||
|
private static final int STATUS_PASSED = 0 + STATUS_BASE;
|
||||||
|
// FAILED_NO_OOM (as defined in alloc001.cpp) + STATUS_BASE
|
||||||
|
private static final int STATUS_NO_OOM = 3 + STATUS_BASE;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Throwable {
|
||||||
|
String cmd = ProcessTools.getCommandLine(ProcessTools.createTestJvm(
|
||||||
|
"-XX:MaxHeapSize=" + (Platform.is32bit() ? "256m" : "512m"),
|
||||||
|
"-Djava.library.path=" + Utils.TEST_NATIVE_PATH,
|
||||||
|
"-agentpath:" + Utils.TEST_NATIVE_PATH + File.separator + System.mapLibraryName("alloc001"),
|
||||||
|
"-XX:CompressedClassSpaceSize=64m",
|
||||||
|
Test.class.getName()
|
||||||
|
));
|
||||||
|
cmd = escapeCmd(cmd);
|
||||||
|
|
||||||
|
int ulimitV = Platform.is32bit() ? 1048576 : 4194303;
|
||||||
|
var pb = new ProcessBuilder(
|
||||||
|
"sh", "-c",
|
||||||
|
"ulimit -v " + ulimitV + "; " + cmd);
|
||||||
|
|
||||||
|
// lower MALLOC_ARENA_MAX b/c we limited virtual memory, see JDK-8043516
|
||||||
|
pb.environment().put("MALLOC_ARENA_MAX", "4");
|
||||||
|
|
||||||
|
var oa = ProcessTools.executeCommand(pb);
|
||||||
|
int exitCode = oa.getExitValue();
|
||||||
|
if (exitCode == STATUS_NO_OOM && (Platform.isWindows() || Platform.isOSX())) {
|
||||||
|
throw new SkippedException("Test did not get an OutOfMemory error");
|
||||||
|
}
|
||||||
|
oa.shouldHaveExitValue(STATUS_PASSED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String escapeCmd(String cmd) {
|
||||||
|
if (Platform.isWindows()) {
|
||||||
|
return cmd.replace('\\', '/')
|
||||||
|
.replace(";", "\\;")
|
||||||
|
.replace("|", "\\|");
|
||||||
|
}
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
}
|
@ -1,28 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Copyright (c) 2018, 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
|
|
||||||
# under the terms of the GNU General Public License version 2 only, as
|
|
||||||
# published by the Free Software Foundation.
|
|
||||||
#
|
|
||||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
# version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
# accompanied this code).
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License version
|
|
||||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
#
|
|
||||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
# or visit www.oracle.com if you need additional information or have any
|
|
||||||
# questions.
|
|
||||||
|
|
||||||
# as sh's ulimit works weirdly on solaris and jtreg doesn't gurantee what
|
|
||||||
# shell is used, have to use this file to be sure alloc001.bash is run by bash
|
|
||||||
|
|
||||||
: ${TESTSRC:=.}
|
|
||||||
|
|
||||||
bash ${TESTSRC}/alloc001.bash
|
|
Loading…
x
Reference in New Issue
Block a user