31608
|
1 |
/*
|
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
/*
|
|
25 |
* Test image opening/closing
|
|
26 |
* @test ImageOpenTest
|
|
27 |
* @summary Unit test for JVM_ImageOpen() method
|
|
28 |
* @library /testlibrary /../../test/lib
|
|
29 |
* @build ImageOpenTest
|
|
30 |
* @run main ClassFileInstaller sun.hotspot.WhiteBox
|
|
31 |
* sun.hotspot.WhiteBox$WhiteBoxPermission
|
|
32 |
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ImageOpenTest
|
|
33 |
*/
|
|
34 |
|
|
35 |
import java.io.File;
|
|
36 |
import java.nio.ByteOrder;
|
|
37 |
import sun.hotspot.WhiteBox;
|
|
38 |
import static jdk.test.lib.Asserts.*;
|
|
39 |
|
|
40 |
public class ImageOpenTest {
|
|
41 |
|
|
42 |
public static final WhiteBox wb = WhiteBox.getWhiteBox();
|
|
43 |
|
|
44 |
public static void main(String... args) throws Exception {
|
|
45 |
String javaHome = System.getProperty("java.home");
|
|
46 |
String nonexistentImageFile = javaHome + "/lib/modules/nonexistent.jimage";
|
|
47 |
String bootmodulesImageFile = javaHome + File.separator + "lib" + File.separator
|
|
48 |
+ "modules" + File.separator + "bootmodules.jimage";
|
|
49 |
|
|
50 |
if (!(new File(bootmodulesImageFile)).exists()) {
|
|
51 |
System.out.printf("Test skipped.");
|
|
52 |
return;
|
|
53 |
}
|
|
54 |
|
|
55 |
boolean bigEndian = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
|
|
56 |
|
|
57 |
// open nonexistent image
|
|
58 |
long id = wb.imageOpenImage(nonexistentImageFile, bigEndian);
|
|
59 |
assertTrue(id == 0L, "Failed. Get id " + id + "instead of 0 on opening nonexistent file\n");
|
|
60 |
wb.imageCloseImage(id);
|
|
61 |
|
|
62 |
// open bootmodules image
|
|
63 |
id = wb.imageOpenImage(bootmodulesImageFile, bigEndian);
|
|
64 |
assertFalse(id == 0, "Failed. Get id 0 on opening bootmodules.jimage");
|
|
65 |
wb.imageCloseImage(id);
|
|
66 |
|
|
67 |
// non-native endian
|
|
68 |
id = wb.imageOpenImage(bootmodulesImageFile, !bigEndian);
|
|
69 |
assertFalse(id == 0, "Failed. Get id 0 on opening bootmodules.jimage with non-native endian");
|
|
70 |
wb.imageCloseImage(id);
|
|
71 |
|
|
72 |
//
|
|
73 |
// open several times
|
|
74 |
//
|
|
75 |
id = wb.imageOpenImage(bootmodulesImageFile, bigEndian);
|
|
76 |
long id1 = wb.imageOpenImage(bootmodulesImageFile, bigEndian);
|
|
77 |
long id2 = wb.imageOpenImage(bootmodulesImageFile, bigEndian);
|
|
78 |
assertTrue((id == id1) && (id == id2), "Failed. Open thee times with ids " + id + " " + id1 + " " + id1);
|
|
79 |
|
|
80 |
wb.imageCloseImage(id);
|
|
81 |
wb.imageCloseImage(id1);
|
|
82 |
wb.imageCloseImage(id2);
|
|
83 |
}
|
|
84 |
}
|