Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/GetBytecodeTest.java
41153 views
/*1* Copyright (c) 2015, 2019, 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.hotspot33* jdk.internal.vm.ci/jdk.vm.ci.code34* 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* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI39* -XX:-UseJVMCICompiler40* compiler.jvmci.compilerToVM.GetBytecodeTest41*/4243package compiler.jvmci.compilerToVM;4445import compiler.jvmci.common.CTVMUtilities;46import compiler.jvmci.common.testcases.TestCase;47import jdk.internal.org.objectweb.asm.Opcodes;48import jdk.test.lib.Asserts;49import jdk.vm.ci.hotspot.CompilerToVMHelper;50import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;5152import java.lang.reflect.Executable;53import java.lang.reflect.Modifier;5455public class GetBytecodeTest {5657public static void main(String[] args) {58TestCase.getAllExecutables()59.forEach(GetBytecodeTest::runSanityTest);60}6162private static void runSanityTest(Executable aMethod) {63HotSpotResolvedJavaMethod method = CTVMUtilities64.getResolvedMethod(aMethod);65byte[] bytecode = CompilerToVMHelper.getBytecode(method);6667int mods = aMethod.getModifiers();68boolean shouldHasZeroLength = Modifier.isAbstract(mods)69|| Modifier.isNative(mods);70boolean correctLength = (bytecode.length == 0 && shouldHasZeroLength)71|| (bytecode.length > 0 && !shouldHasZeroLength);7273Asserts.assertTrue(correctLength, "Bytecode of '" + aMethod + "' has "74+ bytecode.length + " length");7576if (!shouldHasZeroLength) {77Asserts.assertTrue(containsReturn(bytecode), "Bytecode of '"78+ aMethod + "' doesn't have any return statement");79}80}8182private static boolean containsReturn(byte[] bytecode) {83for (byte b : bytecode) {84// cast unsigned byte to int85int value = (int) b & 0x000000FF;86switch (value) {87case Opcodes.RET:88case Opcodes.ARETURN:89case Opcodes.IRETURN:90case Opcodes.LRETURN:91case Opcodes.FRETURN:92case Opcodes.DRETURN:93case Opcodes.RETURN:94return true;95}96}97return false;98}99}100101102