Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/DisassembleCodeBlobTest.java
41153 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 813642126* @requires vm.jvmci27* @library /test/lib /28* @library ../common/patches29* @modules java.base/jdk.internal.misc30* @modules java.base/jdk.internal.org.objectweb.asm31* java.base/jdk.internal.org.objectweb.asm.tree32* jdk.internal.vm.ci/jdk.vm.ci.code33* jdk.internal.vm.ci/jdk.vm.ci.hotspot34* jdk.internal.vm.ci/jdk.vm.ci.meta35* jdk.internal.vm.ci/jdk.vm.ci.runtime36*37* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper38* @build sun.hotspot.WhiteBox39* compiler.jvmci.compilerToVM.DisassembleCodeBlobTest40* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox41* @run main/othervm -Xbootclasspath/a:.42* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI43* -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI44* -XX:-BackgroundCompilation45* compiler.jvmci.compilerToVM.DisassembleCodeBlobTest46*/4748package compiler.jvmci.compilerToVM;4950import jdk.test.lib.Asserts;51import jdk.test.lib.Utils;52import jdk.vm.ci.code.InstalledCode;53import jdk.vm.ci.hotspot.CompilerToVMHelper;54import sun.hotspot.code.NMethod;5556import java.util.List;5758public class DisassembleCodeBlobTest {5960public static void main(String[] args) {61DisassembleCodeBlobTest test62= new DisassembleCodeBlobTest();63List<CompileCodeTestCase> testCases64= CompileCodeTestCase.generate(/* bci = */ -1);65testCases.forEach(test::check);66testCases.stream().findAny().ifPresent(test::checkZero);67test.checkNull();68}6970private void checkNull() {71Utils.runAndCheckException(72() -> { CompilerToVMHelper.disassembleCodeBlob(null); },73NullPointerException.class);74}7576private void checkZero(CompileCodeTestCase testCase) {77System.out.println("checkZero for " + testCase);78testCase.deoptimize();79InstalledCode installedCode = testCase.toInstalledCode();80String str = CompilerToVMHelper.disassembleCodeBlob(installedCode);81Asserts.assertNull(str, testCase82+ " : non-null return value for invalid installCode");83}8485private void check(CompileCodeTestCase testCase) {86System.out.println(testCase);87// to have a clean state88NMethod nMethod = testCase.deoptimizeAndCompile();89if (nMethod == null) {90throw new Error(testCase + " : method is not compiled");91}92InstalledCode installedCode = testCase.toInstalledCode();93String str1 = CompilerToVMHelper.disassembleCodeBlob(installedCode);94if (str1 != null) {95Asserts.assertGT(str1.length(), 0,96testCase + " : returned string has to be non-zero length");97}98// The very first call to the disassembler contains a string specifying the99// architecture: [Disassembling for mach='i386:x86-64']100// Therefore compare strings 2 and 3.101String str2 = CompilerToVMHelper.disassembleCodeBlob(installedCode);102String str3 = CompilerToVMHelper.disassembleCodeBlob(installedCode);103Asserts.assertEQ(str2, str3,104testCase + " : 3nd invocation returned different value from 2nd");105}106}107108109