hotspot/test/runtime/modules/ImageFile/ImageAttributeOffsetsTest.java
author jfdenise
Thu, 25 Jun 2015 18:25:19 +0200
changeset 31608 b5cb9a07591a
permissions -rw-r--r--
8080511: Refresh of jimage support Reviewed-by: alanb, mchung, psandoz, acorn, lfoltan, ctornqvi Contributed-by: james.laskey@oracle.com, jean-francois.denise@oracle.com, sundararajan.athijegannathan@oracle.com
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
 * Retrieves the array of offsets once with MemoryMapImage enabled once disabled.
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    26
 * @test ImageAttributeOffsetsTest
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    27
 * @summary Unit test for JVM_ImageAttributeOffsets() 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 ImageAttributeOffsetsTest
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 -XX:+MemoryMapImage ImageAttributeOffsetsTest
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    33
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-MemoryMapImage ImageAttributeOffsetsTest
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    34
 */
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    35
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    36
import java.io.File;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    37
import java.nio.ByteOrder;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    38
import sun.hotspot.WhiteBox;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    39
import static jdk.test.lib.Asserts.*;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    40
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    41
public class ImageAttributeOffsetsTest {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    42
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    43
    public static final WhiteBox wb = WhiteBox.getWhiteBox();
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    44
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    45
    public static void main(String... args) throws Exception {
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    46
        String javaHome = System.getProperty("java.home");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    47
        String imageFile = 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(imageFile)).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
        long id = wb.imageOpenImage(imageFile, bigEndian);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    57
        boolean passed = true;
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    58
        // Get offsets
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    59
        int[] array = wb.imageAttributeOffsets(id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    60
        assertNotNull(array, "Could not retrieve offsets of array");
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    61
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    62
        wb.imageCloseImage(id);
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    63
    }
b5cb9a07591a 8080511: Refresh of jimage support
jfdenise
parents:
diff changeset
    64
}