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