1 #!/bin/bash
   2 # Copyright (c) 2008, 2019, 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 JAVA="$TESTJAVA/bin/java"
  24 JAVA_OPTS="$TESTJAVAOPTS $TESTVMOPTS -cp $TESTCLASSPATH -agentlib:alloc001"
  25 
  26 . ${TESTSRC}/../../../../../test_env.sh
  27 
  28 # Set virtual memory usage limit to be not 'unlimited' on unix platforms
  29 # This is workaround for 6683371.
  30 case $VM_OS in
  31 aix | bsd | linux)
  32     echo "Check virtual memory usage limits"
  33     soft_limit=`ulimit -S -v` || ""
  34     hard_limit=`ulimit -H -v` || ""
  35     echo "Virtual memory usage limit (hard): $hard_limit"
  36     echo "Virtual memory usage limit (soft): $soft_limit"
  37 
  38     # Need to set ulimit if currently unlimited or > 4GB (1GB on 32 bit)
  39     if [ $VM_BITS -eq 32 ]
  40     then
  41         max_ulimit=1048576
  42         max_heap=256m
  43     else
  44         # AIX requires a 32-bit value here.
  45         max_ulimit=4194303
  46         max_heap=512m
  47     fi
  48 
  49     should_update_ulimit=0
  50     if [ -n "$soft_limit" ]; then
  51         if [ "$soft_limit" = "unlimited" ]; then
  52             should_update_ulimit=1
  53         elif [ "$soft_limit" -gt "$max_ulimit" ]; then
  54             should_update_ulimit=1
  55         fi
  56     fi
  57 
  58     if [ "$should_update_ulimit" = "1" ]; then
  59         echo "Try to limit virtual memory usage to $max_ulimit"
  60         ulimit -S -v $max_ulimit || true
  61     fi
  62 
  63     # When we limit virtual memory then we need to also limit other GC args and MALLOC_ARENA_MAX.
  64     # Otherwise the JVM may not start. See JDK-8043516
  65     JAVA_OPTS="${JAVA_OPTS} -XX:MaxHeapSize=$max_heap -XX:CompressedClassSpaceSize=64m"
  66     export MALLOC_ARENA_MAX=4
  67     soft_limit=`ulimit -S -v`
  68     echo "Virtual memory usage limit (soft): $soft_limit"
  69     echo "New JAVA_OPTS: $JAVA_OPTS"
  70     echo "export MALLOC_ARENA_MAX=4"
  71     ;;
  72 *)
  73     ;;
  74 esac
  75 
  76 export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:$TESTNATIVEPATH
  77 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TESTNATIVEPATH
  78 export LIBPATH=$LIBPATH:$TESTNATIVEPATH
  79 export PATH=$PATH:$TESTNATIVEPATH
  80 
  81 echo $JAVA ${JAVA_OPTS} nsk.jvmti.Allocate.alloc001
  82 $JAVA ${JAVA_OPTS} nsk.jvmti.Allocate.alloc001
  83 exit=$?
  84 
  85 if [ $exit -ne 95 ]
  86 then
  87     exit $exit
  88 fi