jdk/test/java/nio/Buffer/LimitDirectMemory.sh
author alanb
Mon, 18 Oct 2010 10:29:59 +0100
changeset 6902 3352f8839320
parent 6897 561a431cf238
child 14786 a9f61e0cbe61
permissions -rw-r--r--
4837564: (bf) Please make DirectByteBuffer performance enhancements Reviewed-by: chegar
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
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    31
# @run shell LimitDirectMemory.sh
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    32
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    33
TMP1=tmp_$$
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    34
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    35
runTest() {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    36
  echo "Testing: $*"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    37
  ${TESTJAVA}/bin/java $*
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    38
  if [ $? -eq 0 ]
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    39
  then echo "--- passed as expected"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    40
  else
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    41
    echo "--- failed"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    42
    exit 1
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    43
  fi
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    44
}
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
launchFail() {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    47
  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
    48
     LimitDirectMemory true DEFAULT DEFAULT+1M"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    49
  ${TESTJAVA}/bin/java -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 > ${TMP1} 2>&1
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    51
  cat ${TMP1}
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    52
  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
    53
  if [ $? -ne 0 ]
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    54
    then echo "--- failed as expected"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    55
  else
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    56
    echo "--- failed"
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    57
    exit 1
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    58
  fi
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    59
}
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    60
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    61
# $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
    62
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    63
# 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
    64
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
    65
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
    66
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
    67
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    68
# 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
    69
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
    70
  LimitDirectMemory false 64M 65M
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    71
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    72
# 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
    73
runTest -cp ${TESTCLASSES} LimitDirectMemory false 10 1
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    74
runTest -Xmx64m -cp ${TESTCLASSES} LimitDirectMemory false 0 DEFAULT
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    75
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
    76
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    77
# 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
    78
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
    79
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    80
# 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
    81
# the default amount.
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    82
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
    83
  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
    84
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    85
# 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
    86
launchFail foo
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    87
launchFail 10kmt
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    88
launchFail -1
6902
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    89
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    90
# Clean-up
3352f8839320 4837564: (bf) Please make DirectByteBuffer performance enhancements
alanb
parents: 6897
diff changeset
    91
rm ${TMP1}