jdk/test/java/nio/Buffer/LimitDirectMemory.sh
author bpb
Fri, 24 Jul 2015 11:52:30 -0700
changeset 31873 87b015c2cd36
parent 31673 135283550686
child 36511 9d0388c6b336
permissions -rw-r--r--
8065556: (bf) Buffer.position and other methods should include detail in IAE Summary: Add messages to IAEs which have none. Reviewed-by: alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     1
#!/bin/sh
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     2
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     3
#
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     4
# Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     5
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     6
#
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     7
# This code is free software; you can redistribute it and/or modify it
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     8
# under the terms of the GNU General Public License version 2 only, as
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     9
# published by the Free Software Foundation.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    10
#
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    11
# This code is distributed in the hope that it will be useful, but WITHOUT
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    13
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    14
# version 2 for more details (a copy is included in the LICENSE file that
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    15
# accompanied this code).
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    16
#
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    17
# You should have received a copy of the GNU General Public License version
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    18
# 2 along with this work; if not, write to the Free Software Foundation,
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    19
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    20
#
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    21
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    22
# or visit www.oracle.com if you need additional information or have any
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    23
# questions.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    24
#
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    25
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    26
# @test
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    27
# @bug 4627316 6743526
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    28
# @summary Test option to limit direct memory allocation
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    29
#
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    30
# @build LimitDirectMemory
31673
135283550686 8080511: Refresh of jimage support
jfdenise
parents: 14786
diff changeset
    31
# @ignore JDK-8129343
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    32
# @run shell LimitDirectMemory.sh
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    33
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    34
TMP1=tmp_$$
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    35
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    36
runTest() {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    37
  echo "Testing: $*"
14786
a9f61e0cbe61 8003890: corelibs test scripts should pass TESTVMOPTS
chegar
parents: 6902
diff changeset
    38
  ${TESTJAVA}/bin/java ${TESTVMOPTS} $*
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    39
  if [ $? -eq 0 ]
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    40
  then echo "--- passed as expected"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    41
  else
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    42
    echo "--- failed"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    43
    exit 1
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    44
  fi
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    45
}
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    46
14786
a9f61e0cbe61 8003890: corelibs test scripts should pass TESTVMOPTS
chegar
parents: 6902
diff changeset
    47
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    48
launchFail() {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    49
  echo "Testing: -XX:MaxDirectMemorySize=$* -cp ${TESTCLASSES} \
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    50
     LimitDirectMemory true DEFAULT DEFAULT+1M"
14786
a9f61e0cbe61 8003890: corelibs test scripts should pass TESTVMOPTS
chegar
parents: 6902
diff changeset
    51
  ${TESTJAVA}/bin/java ${TESTVMOPTS} -XX:MaxDirectMemorySize=$* -cp ${TESTCLASSES} \
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    52
     LimitDirectMemory true DEFAULT DEFAULT+1M > ${TMP1} 2>&1
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    53
  cat ${TMP1}
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    54
  cat ${TMP1} | grep -s "Unrecognized VM option: \'MaxDirectMemorySize="
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    55
  if [ $? -ne 0 ]
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    56
    then echo "--- failed as expected"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    57
  else
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    58
    echo "--- failed"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    59
    exit 1
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    60
  fi
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    61
}
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    62
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    63
# $java LimitDirectMemory throwp fill_direct_memory size_per_buffer
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    64
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    65
# Memory is properly limited using multiple buffers.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    66
runTest -XX:MaxDirectMemorySize=10 -cp ${TESTCLASSES} LimitDirectMemory true 10 1
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    67
runTest -XX:MaxDirectMemorySize=1k -cp ${TESTCLASSES} LimitDirectMemory true 1k 100
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    68
runTest -XX:MaxDirectMemorySize=10m -cp ${TESTCLASSES} LimitDirectMemory true 10m 10m
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    69
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    70
# We can increase the amount of available memory.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    71
runTest -XX:MaxDirectMemorySize=65M -cp ${TESTCLASSES} \
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    72
  LimitDirectMemory false 64M 65M
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    73
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    74
# Exactly the default amount of memory is available.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    75
runTest -cp ${TESTCLASSES} LimitDirectMemory false 10 1
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    76
runTest -Xmx64m -cp ${TESTCLASSES} LimitDirectMemory false 0 DEFAULT
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    77
runTest -Xmx64m -cp ${TESTCLASSES} LimitDirectMemory true 0 DEFAULT+1
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    78
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    79
# We should be able to eliminate direct memory allocation entirely.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    80
runTest -XX:MaxDirectMemorySize=0 -cp ${TESTCLASSES} LimitDirectMemory true 0 1
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    81
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    82
# Setting the system property should not work so we should be able to allocate
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    83
# the default amount.
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    84
runTest -Dsun.nio.MaxDirectMemorySize=1K -Xmx64m -cp ${TESTCLASSES} \
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    85
  LimitDirectMemory false DEFAULT-1 DEFAULT/2
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    86
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    87
# Various bad values fail to launch the VM.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    88
launchFail foo
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    89
launchFail 10kmt
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    90
launchFail -1
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    91
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    92
# Clean-up
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    93
rm ${TMP1}