Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/x86/vm/interp_masm_x86.cpp
32285 views
/*1* Copyright (c) 1997, 2016, 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*22*/2324#include "precompiled.hpp"25#include "interp_masm_x86.hpp"26#include "interpreter/interpreter.hpp"27#include "oops/methodData.hpp"282930// 8u does not have InterpreterMacroAssembler::load_earlyret_value here3132void InterpreterMacroAssembler::narrow(Register result) {3334// Get method->_constMethod->_result_type35movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));36movptr(rcx, Address(rcx, Method::const_offset()));37load_unsigned_byte(rcx, Address(rcx, ConstMethod::result_type_offset()));3839Label done, notBool, notByte, notChar;4041// common case first42cmpl(rcx, T_INT);43jcc(Assembler::equal, done);4445// mask integer result to narrower return type.46cmpl(rcx, T_BOOLEAN);47jcc(Assembler::notEqual, notBool);48andl(result, 0x1);49jmp(done);5051bind(notBool);52cmpl(rcx, T_BYTE);53jcc(Assembler::notEqual, notByte);54LP64_ONLY(movsbl(result, result);)55NOT_LP64(shll(result, 24);) // truncate upper 24 bits56NOT_LP64(sarl(result, 24);) // and sign-extend byte57jmp(done);5859bind(notByte);60cmpl(rcx, T_CHAR);61jcc(Assembler::notEqual, notChar);62LP64_ONLY(movzwl(result, result);)63NOT_LP64(andl(result, 0xFFFF);) // truncate upper 16 bits64jmp(done);6566bind(notChar);67// cmpl(rcx, T_SHORT); // all that's left68// jcc(Assembler::notEqual, done);69LP64_ONLY(movswl(result, result);)70NOT_LP64(shll(result, 16);) // truncate upper 16 bits71NOT_LP64(sarl(result, 16);) // and sign-extend short7273// Nothing to do for T_INT74bind(done);75}7677#ifndef CC_INTERP78void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {79Label update, next, none;8081verify_oop(obj);8283testptr(obj, obj);84jccb(Assembler::notZero, update);85orptr(mdo_addr, TypeEntries::null_seen);86jmpb(next);8788bind(update);89load_klass(obj, obj);9091xorptr(obj, mdo_addr);92testptr(obj, TypeEntries::type_klass_mask);93jccb(Assembler::zero, next); // klass seen before, nothing to94// do. The unknown bit may have been95// set already but no need to check.9697testptr(obj, TypeEntries::type_unknown);98jccb(Assembler::notZero, next); // already unknown. Nothing to do anymore.99100cmpptr(mdo_addr, 0);101jccb(Assembler::equal, none);102cmpptr(mdo_addr, TypeEntries::null_seen);103jccb(Assembler::equal, none);104// There is a chance that the checks above (re-reading profiling105// data from memory) fail if another thread has just set the106// profiling to this obj's klass107xorptr(obj, mdo_addr);108testptr(obj, TypeEntries::type_klass_mask);109jccb(Assembler::zero, next);110111// different than before. Cannot keep accurate profile.112orptr(mdo_addr, TypeEntries::type_unknown);113jmpb(next);114115bind(none);116// first time here. Set profile type.117movptr(mdo_addr, obj);118119bind(next);120}121122void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {123if (!ProfileInterpreter) {124return;125}126127if (MethodData::profile_arguments() || MethodData::profile_return()) {128Label profile_continue;129130test_method_data_pointer(mdp, profile_continue);131132int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());133134cmpb(Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start), is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);135jcc(Assembler::notEqual, profile_continue);136137if (MethodData::profile_arguments()) {138Label done;139int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());140addptr(mdp, off_to_args);141142for (int i = 0; i < TypeProfileArgsLimit; i++) {143if (i > 0 || MethodData::profile_return()) {144// If return value type is profiled we may have no argument to profile145movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));146subl(tmp, i*TypeStackSlotEntries::per_arg_count());147cmpl(tmp, TypeStackSlotEntries::per_arg_count());148jcc(Assembler::less, done);149}150movptr(tmp, Address(callee, Method::const_offset()));151load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));152// stack offset o (zero based) from the start of the argument153// list, for n arguments translates into offset n - o - 1 from154// the end of the argument list155subptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args));156subl(tmp, 1);157Address arg_addr = argument_address(tmp);158movptr(tmp, arg_addr);159160Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);161profile_obj_type(tmp, mdo_arg_addr);162163int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());164addptr(mdp, to_add);165off_to_args += to_add;166}167168if (MethodData::profile_return()) {169movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));170subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());171}172173bind(done);174175if (MethodData::profile_return()) {176// We're right after the type profile for the last177// argument. tmp is the number of cells left in the178// CallTypeData/VirtualCallTypeData to reach its end. Non null179// if there's a return to profile.180assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");181shll(tmp, exact_log2(DataLayout::cell_size));182addptr(mdp, tmp);183}184movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp);185} else {186assert(MethodData::profile_return(), "either profile call args or call ret");187update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));188}189190// mdp points right after the end of the191// CallTypeData/VirtualCallTypeData, right after the cells for the192// return value type if there's one193194bind(profile_continue);195}196}197198void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {199assert_different_registers(mdp, ret, tmp, _bcp_register);200if (ProfileInterpreter && MethodData::profile_return()) {201Label profile_continue, done;202203test_method_data_pointer(mdp, profile_continue);204205if (MethodData::profile_return_jsr292_only()) {206// If we don't profile all invoke bytecodes we must make sure207// it's a bytecode we indeed profile. We can't go back to the208// begining of the ProfileData we intend to update to check its209// type because we're right after it and we don't known its210// length211Label do_profile;212cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic);213jcc(Assembler::equal, do_profile);214cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle);215jcc(Assembler::equal, do_profile);216get_method(tmp);217cmpb(Address(tmp, Method::intrinsic_id_offset_in_bytes()), vmIntrinsics::_compiledLambdaForm);218jcc(Assembler::notEqual, profile_continue);219220bind(do_profile);221}222223Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));224mov(tmp, ret);225profile_obj_type(tmp, mdo_ret_addr);226227bind(profile_continue);228}229}230231void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {232if (ProfileInterpreter && MethodData::profile_parameters()) {233Label profile_continue, done;234235test_method_data_pointer(mdp, profile_continue);236237// Load the offset of the area within the MDO used for238// parameters. If it's negative we're not profiling any parameters239movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));240testl(tmp1, tmp1);241jcc(Assembler::negative, profile_continue);242243// Compute a pointer to the area for parameters from the offset244// and move the pointer to the slot for the last245// parameters. Collect profiling from last parameter down.246// mdo start + parameters offset + array length - 1247addptr(mdp, tmp1);248movptr(tmp1, Address(mdp, ArrayData::array_len_offset()));249decrement(tmp1, TypeStackSlotEntries::per_arg_count());250251Label loop;252bind(loop);253254int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));255int type_base = in_bytes(ParametersTypeData::type_offset(0));256Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);257Address arg_off(mdp, tmp1, per_arg_scale, off_base);258Address arg_type(mdp, tmp1, per_arg_scale, type_base);259260// load offset on the stack from the slot for this parameter261movptr(tmp2, arg_off);262negptr(tmp2);263// read the parameter from the local area264movptr(tmp2, Address(_locals_register, tmp2, Interpreter::stackElementScale()));265266// profile the parameter267profile_obj_type(tmp2, arg_type);268269// go to next parameter270decrement(tmp1, TypeStackSlotEntries::per_arg_count());271jcc(Assembler::positive, loop);272273bind(profile_continue);274}275}276#endif277278279