hotspot/test/runtime/modules/ImageFile/ImageOpenTest.java
author amurillo
Thu, 17 Sep 2015 09:19:40 -0700
changeset 32760 3851193a8c60
parent 31608 b5cb9a07591a
permissions -rw-r--r--
Merge
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 image opening/closing
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    26
 * @test ImageOpenTest
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    27
 * @summary Unit test for JVM_ImageOpen() 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 ImageOpenTest
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 ImageOpenTest
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
import static jdk.test.lib.Asserts.*;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    39
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    40
public class ImageOpenTest {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    41
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    42
    public static final WhiteBox wb = WhiteBox.getWhiteBox();
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    43
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    44
    public static void main(String... args) throws Exception {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    45
        String javaHome = System.getProperty("java.home");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    46
        String nonexistentImageFile = javaHome + "/lib/modules/nonexistent.jimage";
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    47
        String bootmodulesImageFile = javaHome + File.separator + "lib" + File.separator
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    48
                + "modules" + File.separator + "bootmodules.jimage";
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    49
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    50
        if (!(new File(bootmodulesImageFile)).exists()) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    51
            System.out.printf("Test skipped.");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    52
            return;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    53
        }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    54
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    55
        boolean bigEndian = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    56
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    57
        // open nonexistent image
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    58
        long id = wb.imageOpenImage(nonexistentImageFile, bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    59
        assertTrue(id == 0L, "Failed. Get id " + id + "instead of 0 on opening nonexistent file\n");
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
        // open bootmodules image
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    63
        id = wb.imageOpenImage(bootmodulesImageFile, bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    64
        assertFalse(id == 0, "Failed. Get id 0 on opening bootmodules.jimage");
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
        // non-native endian
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    68
        id = wb.imageOpenImage(bootmodulesImageFile, !bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    69
        assertFalse(id == 0, "Failed. Get id 0 on opening bootmodules.jimage with non-native endian");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    70
        wb.imageCloseImage(id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    71
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    72
        //
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    73
        // open several times
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    74
        //
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    75
        id = wb.imageOpenImage(bootmodulesImageFile, bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    76
        long id1 = wb.imageOpenImage(bootmodulesImageFile, bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    77
        long id2 = wb.imageOpenImage(bootmodulesImageFile, bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    78
        assertTrue((id == id1) && (id == id2), "Failed. Open thee times with ids " + id + " " + id1 + " " + id1);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    79
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    80
        wb.imageCloseImage(id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    81
        wb.imageCloseImage(id1);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    82
        wb.imageCloseImage(id2);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    83
    }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    84
}