DisassembleCodeBlobTest.java revision 9814:22fd02fad88b
1139749Simp/* 272016Scg * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 372016Scg * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 472016Scg * 572016Scg * This code is free software; you can redistribute it and/or modify it 672016Scg * under the terms of the GNU General Public License version 2 only, as 772016Scg * published by the Free Software Foundation. 872016Scg * 972016Scg * This code is distributed in the hope that it will be useful, but WITHOUT 1072016Scg * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1172016Scg * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1272016Scg * version 2 for more details (a copy is included in the LICENSE file that 1372016Scg * accompanied this code). 1472016Scg * 1572016Scg * You should have received a copy of the GNU General Public License version 1672016Scg * 2 along with this work; if not, write to the Free Software Foundation, 1772016Scg * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1872016Scg * 1972016Scg * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2072016Scg * or visit www.oracle.com if you need additional information or have any 2172016Scg * questions. 2272016Scg * 2372016Scg */ 2472016Scg 2572016Scg/* 2672016Scg * @test 2772016Scg * @bug 8136421 2872016Scg * @requires (os.simpleArch == "x64" | os.simpleArch == "sparcv9" | os.simpleArch == "aarch64") 2972016Scg * @library /testlibrary /test/lib / 3072016Scg * @ignore 8139700 3172016Scg * @compile ../common/CompilerToVMHelper.java 3272016Scg * @build sun.hotspot.WhiteBox 3372016Scg * compiler.jvmci.compilerToVM.DisassembleCodeBlobTest 3472016Scg * @run main ClassFileInstaller sun.hotspot.WhiteBox 3572016Scg * sun.hotspot.WhiteBox$WhiteBoxPermission 3672016Scg * jdk.vm.ci.hotspot.CompilerToVMHelper 3772016Scg * @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI 3872016Scg * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:. 3972016Scg * compiler.jvmci.compilerToVM.DisassembleCodeBlobTest 4072016Scg */ 4172016Scg 4272016Scgpackage compiler.jvmci.compilerToVM; 4372016Scg 4472016Scgimport jdk.vm.ci.hotspot.CompilerToVMHelper; 4572016Scgimport jdk.vm.ci.code.InstalledCode; 4672016Scgimport jdk.test.lib.Asserts; 4772016Scgimport sun.hotspot.code.NMethod; 4872016Scg 4972016Scgimport java.util.List; 5072016Scgimport jdk.test.lib.Utils; 5172016Scg 5272016Scgpublic class DisassembleCodeBlobTest { 5372016Scg 5472016Scg public static void main(String[] args) { 5572016Scg DisassembleCodeBlobTest test 5672016Scg = new DisassembleCodeBlobTest(); 5772016Scg List<CompileCodeTestCase> testCases 5872016Scg = CompileCodeTestCase.generate(/* bci = */ -1); 5972016Scg testCases.addAll(CompileCodeTestCase.generate(/* bci = */ 0)); 6072016Scg testCases.forEach(test::check); 6172016Scg testCases.stream().findAny().ifPresent(test::checkZero); 6272016Scg test.checkNull(); 6372016Scg } 6472016Scg 6572016Scg private void checkNull() { 6672016Scg Utils.runAndCheckException( 6772016Scg () -> CompilerToVMHelper.disassembleCodeBlob(null), 6872016Scg NullPointerException.class); 6972016Scg } 7072016Scg 7172016Scg private void checkZero(CompileCodeTestCase testCase) { 7272016Scg System.out.println("checkZero for " + testCase); 7372016Scg testCase.deoptimize(); 7472016Scg InstalledCode installedCode = testCase.toInstalledCode(); 7572016Scg String str = CompilerToVMHelper.disassembleCodeBlob(installedCode); 7672016Scg Asserts.assertNull(str, testCase 7772016Scg + " : non-null return value for invalid installCode"); 7872016Scg } 7972016Scg 8072016Scg private void check(CompileCodeTestCase testCase) { 8172016Scg System.out.println(testCase); 8272016Scg // to have a clean state 8372016Scg NMethod nMethod = testCase.deoptimizeAndCompile(); 8472016Scg if (nMethod == null) { 8572016Scg throw new Error(testCase + " : method is not compiled"); 8672016Scg } 8772016Scg InstalledCode installedCode = testCase.toInstalledCode(); 8872016Scg String str = CompilerToVMHelper.disassembleCodeBlob(installedCode); 8972016Scg if (str != null) { 9072016Scg Asserts.assertGT(str.length(), 0, 9172016Scg testCase + " : returned string has to be non-zero length"); 9272016Scg } 9372016Scg String str2 = CompilerToVMHelper.disassembleCodeBlob(installedCode); 9472016Scg Asserts.assertEQ(str, str2, 9572016Scg testCase + " : 2nd invocation returned different value"); 9672016Scg } 9772016Scg} 9872016Scg