1 /* 2 * Copyright (c) 2018 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 TestHumongousObjectsOnNvdimm 26 * @summary Check that humongous objects reside in nv-dimm 27 * @library /test/lib / 28 * @build sun.hotspot.WhiteBox 29 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 30 * @run main TestHumongousObjectsOnNvdimm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 31 * -XX:+WhiteBoxAPI 32 */ 33 34 import jdk.test.lib.process.OutputAnalyzer; 35 import jdk.test.lib.process.ProcessTools; 36 import jdk.test.lib.Asserts; 37 import sun.hotspot.WhiteBox; 38 39 import java.util.ArrayList; 40 import java.util.List; 41 import java.util.Collections; 42 import gc.testlibrary.Helpers; 43 44 /** 45 * Test spawns HumongousObjectTest in a separate VM and expects that it 46 * completes without a RuntimeException. 47 */ 48 public class TestHumongousObjectsOnNvdimm { 49 50 private static ArrayList<String> testOpts; 51 52 public static void main(String args[]) throws Exception { 53 testOpts = new ArrayList(); 54 55 String[] common_options = new String[] { 56 "-Xbootclasspath/a:.", 57 "-XX:+UnlockExperimentalVMOptions", 58 "-XX:+UnlockDiagnosticVMOptions", 59 "-XX:+WhiteBoxAPI", 60 "-XX:AllocateOldGenAt="+System.getProperty("test.dir", "."), 61 "-Xms10M", "-Xmx10M", 62 "-XX:G1HeapRegionSize=1m" 63 }; 64 65 String testVmOptsStr = System.getProperty("test.java.opts"); 66 if (!testVmOptsStr.isEmpty()) { 67 String[] testVmOpts = testVmOptsStr.split(" "); 68 Collections.addAll(testOpts, testVmOpts); 69 } 70 Collections.addAll(testOpts, common_options); 71 72 // Test with G1 GC 73 runTest("-XX:+UseG1GC"); 74 } 75 76 private static void runTest(String... extraFlags) throws Exception { 77 Collections.addAll(testOpts, extraFlags); 78 testOpts.add(HumongousObjectTest.class.getName()); 79 System.out.println(testOpts); 80 81 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(false, 82 testOpts.toArray(new String[testOpts.size()])); 83 84 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 85 System.out.println(output.getStdout()); 86 output.shouldHaveExitValue(0); 87 } 88 } 89 90 /** 91 * This class tests that a humongous object resides in NVDIMM. 92 */ 93 class HumongousObjectTest { 94 private static final WhiteBox WB = WhiteBox.getWhiteBox(); 95 96 private static void validateObject(Object o) { 97 Asserts.assertTrue(WB.isObjectInOldGen(o), 98 "Object is supposed to be in OldGen"); 99 100 long obj_addr = WB.getObjectAddress(o); 101 long nvdimm_heap_start = WB.g1NvdimmReservedStart(); 102 long nvdimm_heap_end = WB.g1NvdimmReservedEnd(); 103 104 Asserts.assertTrue(WB.g1BelongsToHumongousRegion(obj_addr), "Object address should be in Humongous set"); 105 Asserts.assertTrue(obj_addr >= nvdimm_heap_start && obj_addr < nvdimm_heap_end, 106 "Humongous object does not reside in NVDIMM"); 107 } 108 109 public static void main(String args[]) throws Exception { 110 // allocate an humongous object 111 int byteArrayMemoryOverhead = Helpers.detectByteArrayAllocationOverhead(); 112 int MinByteArrayHumongousSize = (WB.g1RegionSize() / 2) - byteArrayMemoryOverhead + 1; 113 byte[] obj = new byte[MinByteArrayHumongousSize]; 114 115 validateObject(obj); 116 } 117 }