hotspot/test/runtime/modules/ImageFile/ImageCloseTest.java
author tschatzl
Wed, 19 Aug 2015 13:47:40 +0200
changeset 32377 5ee15c417d02
parent 31608 b5cb9a07591a
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:
31608
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
     1
/*
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
     4
 *
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
     8
 *
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    13
 * accompanied this code).
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    14
 *
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    18
 *
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    21
 * questions.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    22
 */
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    23
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    24
/*
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    25
 * Test closing image opened multiple time. Test closing mutiple time an image.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    26
 * @test ImageCloseTest
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    27
 * @summary Unit test for JVM_ImageClose() method
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    28
 * @library /testlibrary /../../test/lib
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    29
 * @build ImageCloseTest
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    30
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    31
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    32
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ImageCloseTest
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    33
 */
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    34
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    35
import java.io.File;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    36
import java.nio.ByteOrder;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    37
import sun.hotspot.WhiteBox;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    38
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    39
public class ImageCloseTest {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    40
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    41
    public static final WhiteBox wb = WhiteBox.getWhiteBox();
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    42
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    43
    public static void main(String... args) throws Exception {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    44
        String javaHome = System.getProperty("java.home");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    45
        String imageFile = javaHome + File.separator + "lib" + File.separator
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    46
                + "modules" + File.separator + "bootmodules.jimage";
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    47
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    48
        if (!(new File(imageFile)).exists()) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    49
            System.out.printf("Test skipped.");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    50
            return;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    51
        }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    52
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    53
        boolean bigEndian = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    54
        long id = 0;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    55
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    56
        // too many opens
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    57
        for (int i = 0; i < 100; i++) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    58
            id = wb.imageOpenImage(imageFile, bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    59
        }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    60
        wb.imageCloseImage(id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    61
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    62
        // too many closes
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    63
        id = wb.imageOpenImage(imageFile, bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    64
        for (int i = 0; i < 100; i++) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    65
            wb.imageCloseImage(id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    66
        }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    67
    }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    68
}