jdk/test/java/nio/Buffer/LimitDirectMemory.java
author amlu
Wed, 31 May 2017 14:00:55 +0800
changeset 45289 d56bca4fdf8f
parent 37913 3cc95b690353
permissions -rw-r--r--
8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java Reviewed-by: bchristi, psandoz, rriggs
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
/*
45289
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
     2
 * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     3
 * 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
     4
 *
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     5
 * 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
     6
 * 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
     7
 * 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
     8
 *
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
     9
 * 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
    10
 * 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
    11
 * 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
    12
 * 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
    13
 * accompanied this code).
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    14
 *
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    15
 * 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
    16
 * 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
    17
 * 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
    18
 *
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    19
 * 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
    20
 * 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
    21
 * questions.
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    22
 */
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    23
45289
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    24
/*
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    25
 * @test
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    26
 * @bug 4627316 6743526
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    27
 * @summary Test option to limit direct memory allocation
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    28
 * @requires (os.arch == "x86_64") | (os.arch == "amd64") | (os.arch == "sparcv9")
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    29
 * @library /test/lib
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    30
 *
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    31
 * @summary Test: memory is properly limited using multiple buffers
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    32
 * @run main/othervm -XX:MaxDirectMemorySize=10 LimitDirectMemory true 10 1
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    33
 * @run main/othervm -XX:MaxDirectMemorySize=1k LimitDirectMemory true 1k 100
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    34
 * @run main/othervm -XX:MaxDirectMemorySize=10m LimitDirectMemory true 10m 10m
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    35
 *
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    36
 * @summary Test: We can increase the amount of available memory
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    37
 * @run main/othervm -XX:MaxDirectMemorySize=65M LimitDirectMemory false 64M 65M
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    38
 *
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    39
 * @summary Test: Exactly the default amount of memory is available
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    40
 * @run main/othervm LimitDirectMemory false 10 1
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    41
 * @run main/othervm -Xmx64m LimitDirectMemory false 0 DEFAULT
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    42
 * @run main/othervm -Xmx64m LimitDirectMemory true 0 DEFAULT+1
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    43
 *
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    44
 * @summary Test: We should be able to eliminate direct memory allocation entirely
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    45
 * @run main/othervm -XX:MaxDirectMemorySize=0 LimitDirectMemory true 0 1
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    46
 *
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    47
 * @summary Test: Setting the system property should not work so we should be able
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    48
 *                to allocate the default amount
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    49
 * @run main/othervm -Dsun.nio.MaxDirectMemorySize=1K -Xmx64m
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    50
 *                   LimitDirectMemory false DEFAULT-1 DEFAULT/2
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    51
 */
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    52
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    53
import java.nio.ByteBuffer;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    54
import java.util.Properties;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    55
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    56
public class LimitDirectMemory {
37913
3cc95b690353 8156931: java.nio.Buffer tests cleanup
prappo
parents: 6897
diff changeset
    57
    private static final int K = 1024;
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    58
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    59
    public static void main(String [] args) throws Exception {
45289
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    60
        if (args.length < 2) {
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    61
            throw new IllegalArgumentException("Usage: "
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    62
                    + "java LimitDirectMemory"
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    63
                    + " <OOME_expected(true|false)>"
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    64
                    + " <fill_direct_memory>"
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    65
                    + " <size_per_buffer>");
d56bca4fdf8f 8181126: Refactor shell test java/nio/Buffer/LimitDirectMemory.sh to java
amlu
parents: 37913
diff changeset
    66
        }
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    67
        boolean throwp = parseThrow(args[0]);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    68
        int size = parseSize(args[1]);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    69
        int incr = (args.length > 2 ? parseSize(args[2]) : size);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    70
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    71
        Properties p = System.getProperties();
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    72
        if (p.getProperty("sun.nio.MaxDirectMemorySize") != null)
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    73
            throw new RuntimeException("sun.nio.MaxDirectMemorySize defined");
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    74
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    75
        ByteBuffer [] b = new ByteBuffer[K];
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
        // Fill up most/all of the direct memory
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    78
        int i = 0;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    79
        while (size >= incr) {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    80
            b[i++] = ByteBuffer.allocateDirect(incr);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    81
            size -= incr;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    82
        }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    83
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    84
        if (throwp) {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    85
            try {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    86
                b[i] = ByteBuffer.allocateDirect(incr);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    87
                throw new RuntimeException("OutOfMemoryError not thrown: "
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    88
                                           + incr);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    89
            } catch (OutOfMemoryError e) {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    90
                e.printStackTrace(System.out);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    91
                System.out.println("OK - Error thrown as expected ");
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    92
            }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    93
        } else {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    94
            b[i] = ByteBuffer.allocateDirect(incr);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    95
            System.out.println("OK - Error not thrown");
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    96
        }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    97
    }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    98
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
    99
    private static boolean parseThrow(String s) {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   100
        if (s.equals("true"))  return true;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   101
        if (s.equals("false")) return false;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   102
        throw new RuntimeException("Unrecognized expectation: " + s);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   103
    }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   104
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   105
    private static int parseSize(String size) throws Exception {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   106
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   107
        if (size.equals("DEFAULT"))
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   108
            return (int)Runtime.getRuntime().maxMemory();
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   109
        if (size.equals("DEFAULT+1"))
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   110
            return (int)Runtime.getRuntime().maxMemory() + 1;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   111
        if (size.equals("DEFAULT+1M"))
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   112
            return (int)Runtime.getRuntime().maxMemory() + (1 << 20);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   113
        if (size.equals("DEFAULT-1"))
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   114
            return (int)Runtime.getRuntime().maxMemory() - 1;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   115
        if (size.equals("DEFAULT/2"))
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   116
            return (int)Runtime.getRuntime().maxMemory() / 2;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   117
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   118
        int idx = 0, len = size.length();
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   119
37913
3cc95b690353 8156931: java.nio.Buffer tests cleanup
prappo
parents: 6897
diff changeset
   120
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   121
        for (int i = 0; i < len; i++) {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   122
            if (Character.isDigit(size.charAt(i))) idx++;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   123
            else break;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   124
        }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   125
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   126
        if (idx == 0)
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   127
            throw new RuntimeException("No digits detected: " + size);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   128
37913
3cc95b690353 8156931: java.nio.Buffer tests cleanup
prappo
parents: 6897
diff changeset
   129
        int result = Integer.parseInt(size.substring(0, idx));
6897
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   130
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   131
        if (idx < len) {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   132
            for (int i = idx; i < len; i++) {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   133
                switch(size.charAt(i)) {
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   134
                case 'T': case 't': result *= K; // fall through
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   135
                case 'G': case 'g': result *= K; // fall through
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   136
                case 'M': case 'm': result *= K; // fall through
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   137
                case 'K': case 'k': result *= K;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   138
                    break;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   139
                default:
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   140
                    throw new RuntimeException("Unrecognized size: " + size);
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   141
                }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   142
            }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   143
        }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   144
        return result;
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   145
    }
561a431cf238 6743526: (bf) -XX:MaxDirectMemorySize=<size> limits memory usage rather than total capacity as intended
alanb
parents:
diff changeset
   146
}