GetCodeHeapEntriesTest.java revision 11833:1cbffa2beba6
1109998Smarkm/* 2296465Sdelphij * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. 3296465Sdelphij * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4296465Sdelphij * 5109998Smarkm * This code is free software; you can redistribute it and/or modify it 6109998Smarkm * under the terms of the GNU General Public License version 2 only, as 7109998Smarkm * published by the Free Software Foundation. 8109998Smarkm * 9109998Smarkm * This code is distributed in the hope that it will be useful, but WITHOUT 10109998Smarkm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11109998Smarkm * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12109998Smarkm * version 2 for more details (a copy is included in the LICENSE file that 13109998Smarkm * accompanied this code). 14296465Sdelphij * 15109998Smarkm * You should have received a copy of the GNU General Public License version 16109998Smarkm * 2 along with this work; if not, write to the Free Software Foundation, 17109998Smarkm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18109998Smarkm * 19109998Smarkm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20109998Smarkm * or visit www.oracle.com if you need additional information or have any 21109998Smarkm * questions. 22109998Smarkm * 23109998Smarkm */ 24109998Smarkm 25109998Smarkm/* 26109998Smarkm * @test GetCodeHeapEntriesTest 27109998Smarkm * @bug 8059624 28109998Smarkm * @summary testing of WB::getCodeHeapEntries() 29109998Smarkm * @library /test/lib / 30109998Smarkm * @modules java.base/jdk.internal.misc 31109998Smarkm * java.management 32109998Smarkm * @build sun.hotspot.WhiteBox 33109998Smarkm * @run driver ClassFileInstaller sun.hotspot.WhiteBox 34109998Smarkm * sun.hotspot.WhiteBox$WhiteBoxPermission 35109998Smarkm * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 36109998Smarkm * -XX:+WhiteBoxAPI -XX:-SegmentedCodeCache 37109998Smarkm * compiler.whitebox.GetCodeHeapEntriesTest 38109998Smarkm * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions 39109998Smarkm * -XX:+WhiteBoxAPI -XX:+SegmentedCodeCache 40109998Smarkm * compiler.whitebox.GetCodeHeapEntriesTest 41109998Smarkm */ 42109998Smarkm 43109998Smarkmpackage compiler.whitebox; 44109998Smarkm 45109998Smarkmimport jdk.test.lib.Asserts; 46109998Smarkmimport sun.hotspot.WhiteBox; 47109998Smarkmimport sun.hotspot.code.BlobType; 48109998Smarkmimport sun.hotspot.code.CodeBlob; 49109998Smarkm 50109998Smarkmimport java.util.Arrays; 51109998Smarkmimport java.util.EnumSet; 52109998Smarkm 53109998Smarkmpublic class GetCodeHeapEntriesTest { 54109998Smarkm private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 55109998Smarkm private static final int SIZE = 1024; 56109998Smarkm private static final String DUMMY_NAME = "WB::DummyBlob"; 57109998Smarkm private static EnumSet<BlobType> SEGMENTED_TYPES 58109998Smarkm = EnumSet.complementOf(EnumSet.of(BlobType.All)); 59109998Smarkm 60111147Snectar public static void main(String[] args) { 61111147Snectar EnumSet<BlobType> blobTypes = BlobType.getAvailable(); 62296465Sdelphij for (BlobType type : blobTypes) { 63296465Sdelphij new GetCodeHeapEntriesTest(type).test(); 64296465Sdelphij } 65296465Sdelphij } 66296465Sdelphij 67296465Sdelphij private final BlobType type; 68109998Smarkm private GetCodeHeapEntriesTest(BlobType type) { 69296465Sdelphij this.type = type; 70296465Sdelphij } 71109998Smarkm 72109998Smarkm private void test() { 73296465Sdelphij System.out.printf("type %s%n", type); 74296465Sdelphij long addr = WHITE_BOX.allocateCodeBlob(SIZE, type.id); 75296465Sdelphij Asserts.assertNE(0, addr, "allocation failed"); 76296465Sdelphij CodeBlob[] blobs = CodeBlob.getCodeBlobs(type); 77296465Sdelphij Asserts.assertNotNull(blobs); 78296465Sdelphij CodeBlob blob = Arrays.stream(blobs) 79109998Smarkm .filter(GetCodeHeapEntriesTest::filter) 80109998Smarkm .findAny() 81109998Smarkm .get(); 82160814Ssimon Asserts.assertNotNull(blob); 83109998Smarkm Asserts.assertEQ(blob.code_blob_type, type); 84296465Sdelphij Asserts.assertGTE(blob.size, SIZE); 85296465Sdelphij 86109998Smarkm WHITE_BOX.freeCodeBlob(addr); 87296465Sdelphij blobs = CodeBlob.getCodeBlobs(type); 88296465Sdelphij long count = Arrays.stream(blobs) 89296465Sdelphij .filter(GetCodeHeapEntriesTest::filter) 90296465Sdelphij .count(); 91296465Sdelphij Asserts.assertEQ(0L, count); 92296465Sdelphij } 93109998Smarkm 94167612Ssimon private static boolean filter(CodeBlob blob) { 95296465Sdelphij if (blob == null) { 96296465Sdelphij return false; 97296465Sdelphij } 98296465Sdelphij return DUMMY_NAME.equals(blob.name); 99296465Sdelphij } 100296465Sdelphij} 101109998Smarkm