hotspot/test/runtime/Unsafe/Reallocate.java
author tschatzl
Wed, 19 Aug 2015 13:47:40 +0200
changeset 32377 5ee15c417d02
parent 30604 b8d532cb6420
child 35922 64f3032d733c
permissions -rw-r--r--
8003237: G1: Reduce unnecessary (and failing) allocation attempts when handling an evacuation failure Summary: Remember for every generation whether the memory for that generation has already been exhausted. If so, do not try to get a new region for these generations. Further, if the last generation is full, early exit from copy_to_survivor_space. Reviewed-by: jmasa, brutisso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28470
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
     1
/*
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
     4
 *
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
     8
 *
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    13
 * accompanied this code).
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    14
 *
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    18
 *
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    21
 * questions.
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    22
 */
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    23
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    24
/*
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    25
 * @test
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    26
 * @bug 8058897
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    27
 * @library /testlibrary
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28473
diff changeset
    28
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28473
diff changeset
    29
 *          java.management
28473
cff666a4057d 8068733: [TESTBUG] runtime/Unsafe/Reallocate.java sometimes fails when running with -Xcomp
ctornqvi
parents: 28470
diff changeset
    30
 * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:MallocMaxTestWords=100m Reallocate
28470
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    31
 */
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    32
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    33
import jdk.test.lib.*;
28470
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    34
import sun.misc.Unsafe;
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29678
diff changeset
    35
import static jdk.test.lib.Asserts.*;
28470
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    36
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    37
public class Reallocate {
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    38
    public static void main(String args[]) throws Exception {
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    39
        Unsafe unsafe = Utils.getUnsafe();
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    40
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    41
        long address = unsafe.allocateMemory(1);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    42
        assertNotEquals(address, 0L);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    43
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    44
        // Make sure we reallocate correctly
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    45
        unsafe.putByte(address, Byte.MAX_VALUE);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    46
        address = unsafe.reallocateMemory(address, 2);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    47
        assertNotEquals(address, 0L);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    48
        assertEquals(unsafe.getByte(address), Byte.MAX_VALUE);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    49
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    50
        // Reallocating with a 0 size should return a null pointer
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    51
        address = unsafe.reallocateMemory(address, 0);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    52
        assertEquals(address, 0L);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    53
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    54
        // Reallocating with a null pointer should result in a normal allocation
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    55
        address = unsafe.reallocateMemory(0L, 1);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    56
        assertNotEquals(address, 0L);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    57
        unsafe.putByte(address, Byte.MAX_VALUE);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    58
        assertEquals(unsafe.getByte(address), Byte.MAX_VALUE);
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    59
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    60
        // Make sure we can throw an OOME when we fail to reallocate due to OOM
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    61
        try {
28473
cff666a4057d 8068733: [TESTBUG] runtime/Unsafe/Reallocate.java sometimes fails when running with -Xcomp
ctornqvi
parents: 28470
diff changeset
    62
            unsafe.reallocateMemory(address, 100 * 1024 * 1024 * 8);
28470
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    63
        } catch (OutOfMemoryError e) {
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    64
            // Expected
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    65
            return;
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    66
        }
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    67
        throw new RuntimeException("Did not get expected OOM");
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    68
    }
bf674dd8644e 8058897: Unsafe.reallocateMemory() ignores -XX:MallocMaxTestWords setting
ctornqvi
parents:
diff changeset
    69
}