hotspot/test/runtime/modules/ImageFile/ImageGetDataAddressTest.java
author lana
Fri, 18 Sep 2015 14:20:39 -0700
changeset 32685 05623c1ebc99
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 accessing the data address of a jimage. This only makes sense when the
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    26
 * entire jimage is mapped into memory.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    27
 * @test ImageGetDataAddressTest
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    28
 * @summary Unit test for JVM_ImageGetDataAddress() method
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    29
 * @library /testlibrary /../../test/lib
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    30
 * @build ImageGetDataAddressTest
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    31
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    32
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    33
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:+MemoryMapImage ImageGetDataAddressTest +
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    34
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-MemoryMapImage ImageGetDataAddressTest -
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    35
 */
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    36
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    37
import java.io.File;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    38
import java.nio.ByteOrder;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    39
import sun.hotspot.WhiteBox;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    40
import static jdk.test.lib.Asserts.*;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    41
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    42
public class ImageGetDataAddressTest {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    43
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    44
    public static final WhiteBox wb = WhiteBox.getWhiteBox();
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    45
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    46
    public static void main(String... args) throws Exception {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    47
        String javaHome = System.getProperty("java.home");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    48
        String imageFile = javaHome + File.separator + "lib" + File.separator
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    49
                + "modules" + File.separator + "bootmodules.jimage";
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    50
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    51
        if (!(new File(imageFile)).exists()) {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    52
            System.out.printf("Test skipped.");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    53
            return;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    54
        }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    55
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    56
        boolean isMMap = args[0].equals("+");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    57
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    58
        boolean bigEndian = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    59
        long id = wb.imageOpenImage(imageFile, bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    60
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    61
        // get data for valid id
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    62
        long dataAddr = wb.imageGetDataAddress(id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    63
        assertFalse((dataAddr == 0) && isMMap, "Failed. Data address is " + dataAddr + " for valid id\n");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    64
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    65
        // get data for invalid id == 0
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    66
        dataAddr = wb.imageGetDataAddress(0);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    67
        assertTrue(dataAddr == 0, "Failed. Data address is " + dataAddr + " for zero id\n");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    68
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    69
        wb.imageCloseImage(id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    70
    }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    71
}