comparison test/runtime/memory/ReserveMemory.java @ 10341:f54c85acc043

8013726: runtime/memory/ReserveMemory.java fails due to 'assert(bytes % os::vm_allocation_granularity() == 0) failed: reserve block size' Summary: Fix regression test to work on all platforms Reviewed-by: ctornqvi, dholmes
author mikael
date Tue, 21 May 2013 09:43:23 -0700
parents f32b6c267d2e
children cc4f5f8d885e
comparison
equal deleted inserted replaced
10314:bbddfb08190f 10341:f54c85acc043
32 * @run main ReserveMemory 32 * @run main ReserveMemory
33 */ 33 */
34 34
35 import com.oracle.java.testlibrary.*; 35 import com.oracle.java.testlibrary.*;
36 36
37 import java.lang.reflect.Field;
38 import sun.hotspot.WhiteBox; 37 import sun.hotspot.WhiteBox;
39 import sun.misc.Unsafe;
40 38
41 public class ReserveMemory { 39 public class ReserveMemory {
42 private static Unsafe getUnsafe() throws Exception {
43 Field f = Unsafe.class.getDeclaredField("theUnsafe");
44 f.setAccessible(true);
45 return (Unsafe)f.get(null);
46 }
47
48 private static boolean isWindows() { 40 private static boolean isWindows() {
49 return System.getProperty("os.name").toLowerCase().startsWith("win"); 41 return System.getProperty("os.name").toLowerCase().startsWith("win");
50 } 42 }
51 43
44 private static boolean isOsx() {
45 return System.getProperty("os.name").toLowerCase().startsWith("mac");
46 }
47
52 public static void main(String args[]) throws Exception { 48 public static void main(String args[]) throws Exception {
53 if (args.length > 0) { 49 if (args.length > 0) {
54 long address = WhiteBox.getWhiteBox().reserveMemory(4096); 50 WhiteBox.getWhiteBox().readReservedMemory();
55
56 System.out.println("Reserved memory at address: 0x" + Long.toHexString(address));
57 System.out.println("Will now read from the address, expecting a crash!");
58
59 int x = getUnsafe().getInt(address);
60 51
61 throw new Exception("Read of reserved/uncommitted memory unexpectedly succeeded, expected crash!"); 52 throw new Exception("Read of reserved/uncommitted memory unexpectedly succeeded, expected crash!");
62 } 53 }
63 54
64 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 55 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
69 "test"); 60 "test");
70 61
71 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 62 OutputAnalyzer output = new OutputAnalyzer(pb.start());
72 if (isWindows()) { 63 if (isWindows()) {
73 output.shouldContain("EXCEPTION_ACCESS_VIOLATION"); 64 output.shouldContain("EXCEPTION_ACCESS_VIOLATION");
65 } else if (isOsx()) {
66 output.shouldContain("SIGBUS");
74 } else { 67 } else {
75 output.shouldContain("SIGSEGV"); 68 output.shouldContain("SIGSEGV");
76 } 69 }
77 } 70 }
78 } 71 }