1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/x86/vm/interp_masm_x86.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,229 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "interp_masm_x86.hpp" 1.30 +#include "interpreter/interpreter.hpp" 1.31 +#include "oops/methodData.hpp" 1.32 + 1.33 +#ifndef CC_INTERP 1.34 +void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) { 1.35 + Label update, next, none; 1.36 + 1.37 + verify_oop(obj); 1.38 + 1.39 + testptr(obj, obj); 1.40 + jccb(Assembler::notZero, update); 1.41 + orptr(mdo_addr, TypeEntries::null_seen); 1.42 + jmpb(next); 1.43 + 1.44 + bind(update); 1.45 + load_klass(obj, obj); 1.46 + 1.47 + xorptr(obj, mdo_addr); 1.48 + testptr(obj, TypeEntries::type_klass_mask); 1.49 + jccb(Assembler::zero, next); // klass seen before, nothing to 1.50 + // do. The unknown bit may have been 1.51 + // set already but no need to check. 1.52 + 1.53 + testptr(obj, TypeEntries::type_unknown); 1.54 + jccb(Assembler::notZero, next); // already unknown. Nothing to do anymore. 1.55 + 1.56 + cmpptr(mdo_addr, 0); 1.57 + jccb(Assembler::equal, none); 1.58 + cmpptr(mdo_addr, TypeEntries::null_seen); 1.59 + jccb(Assembler::equal, none); 1.60 + // There is a chance that the checks above (re-reading profiling 1.61 + // data from memory) fail if another thread has just set the 1.62 + // profiling to this obj's klass 1.63 + xorptr(obj, mdo_addr); 1.64 + testptr(obj, TypeEntries::type_klass_mask); 1.65 + jccb(Assembler::zero, next); 1.66 + 1.67 + // different than before. Cannot keep accurate profile. 1.68 + orptr(mdo_addr, TypeEntries::type_unknown); 1.69 + jmpb(next); 1.70 + 1.71 + bind(none); 1.72 + // first time here. Set profile type. 1.73 + movptr(mdo_addr, obj); 1.74 + 1.75 + bind(next); 1.76 +} 1.77 + 1.78 +void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) { 1.79 + if (!ProfileInterpreter) { 1.80 + return; 1.81 + } 1.82 + 1.83 + if (MethodData::profile_arguments() || MethodData::profile_return()) { 1.84 + Label profile_continue; 1.85 + 1.86 + test_method_data_pointer(mdp, profile_continue); 1.87 + 1.88 + int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size()); 1.89 + 1.90 + cmpb(Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start), is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag); 1.91 + jcc(Assembler::notEqual, profile_continue); 1.92 + 1.93 + if (MethodData::profile_arguments()) { 1.94 + Label done; 1.95 + int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset()); 1.96 + addptr(mdp, off_to_args); 1.97 + 1.98 + for (int i = 0; i < TypeProfileArgsLimit; i++) { 1.99 + if (i > 0 || MethodData::profile_return()) { 1.100 + // If return value type is profiled we may have no argument to profile 1.101 + movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args)); 1.102 + subl(tmp, i*TypeStackSlotEntries::per_arg_count()); 1.103 + cmpl(tmp, TypeStackSlotEntries::per_arg_count()); 1.104 + jcc(Assembler::less, done); 1.105 + } 1.106 + movptr(tmp, Address(callee, Method::const_offset())); 1.107 + load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset())); 1.108 + // stack offset o (zero based) from the start of the argument 1.109 + // list, for n arguments translates into offset n - o - 1 from 1.110 + // the end of the argument list 1.111 + subptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args)); 1.112 + subl(tmp, 1); 1.113 + Address arg_addr = argument_address(tmp); 1.114 + movptr(tmp, arg_addr); 1.115 + 1.116 + Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args); 1.117 + profile_obj_type(tmp, mdo_arg_addr); 1.118 + 1.119 + int to_add = in_bytes(TypeStackSlotEntries::per_arg_size()); 1.120 + addptr(mdp, to_add); 1.121 + off_to_args += to_add; 1.122 + } 1.123 + 1.124 + if (MethodData::profile_return()) { 1.125 + movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args)); 1.126 + subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count()); 1.127 + } 1.128 + 1.129 + bind(done); 1.130 + 1.131 + if (MethodData::profile_return()) { 1.132 + // We're right after the type profile for the last 1.133 + // argument. tmp is the number of cells left in the 1.134 + // CallTypeData/VirtualCallTypeData to reach its end. Non null 1.135 + // if there's a return to profile. 1.136 + assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type"); 1.137 + shll(tmp, exact_log2(DataLayout::cell_size)); 1.138 + addptr(mdp, tmp); 1.139 + } 1.140 + movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp); 1.141 + } else { 1.142 + assert(MethodData::profile_return(), "either profile call args or call ret"); 1.143 + update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size())); 1.144 + } 1.145 + 1.146 + // mdp points right after the end of the 1.147 + // CallTypeData/VirtualCallTypeData, right after the cells for the 1.148 + // return value type if there's one 1.149 + 1.150 + bind(profile_continue); 1.151 + } 1.152 +} 1.153 + 1.154 +void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) { 1.155 + assert_different_registers(mdp, ret, tmp, _bcp_register); 1.156 + if (ProfileInterpreter && MethodData::profile_return()) { 1.157 + Label profile_continue, done; 1.158 + 1.159 + test_method_data_pointer(mdp, profile_continue); 1.160 + 1.161 + if (MethodData::profile_return_jsr292_only()) { 1.162 + // If we don't profile all invoke bytecodes we must make sure 1.163 + // it's a bytecode we indeed profile. We can't go back to the 1.164 + // begining of the ProfileData we intend to update to check its 1.165 + // type because we're right after it and we don't known its 1.166 + // length 1.167 + Label do_profile; 1.168 + cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic); 1.169 + jcc(Assembler::equal, do_profile); 1.170 + cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle); 1.171 + jcc(Assembler::equal, do_profile); 1.172 + get_method(tmp); 1.173 + cmpb(Address(tmp, Method::intrinsic_id_offset_in_bytes()), vmIntrinsics::_compiledLambdaForm); 1.174 + jcc(Assembler::notEqual, profile_continue); 1.175 + 1.176 + bind(do_profile); 1.177 + } 1.178 + 1.179 + Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size())); 1.180 + mov(tmp, ret); 1.181 + profile_obj_type(tmp, mdo_ret_addr); 1.182 + 1.183 + bind(profile_continue); 1.184 + } 1.185 +} 1.186 + 1.187 +void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) { 1.188 + if (ProfileInterpreter && MethodData::profile_parameters()) { 1.189 + Label profile_continue, done; 1.190 + 1.191 + test_method_data_pointer(mdp, profile_continue); 1.192 + 1.193 + // Load the offset of the area within the MDO used for 1.194 + // parameters. If it's negative we're not profiling any parameters 1.195 + movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()))); 1.196 + testl(tmp1, tmp1); 1.197 + jcc(Assembler::negative, profile_continue); 1.198 + 1.199 + // Compute a pointer to the area for parameters from the offset 1.200 + // and move the pointer to the slot for the last 1.201 + // parameters. Collect profiling from last parameter down. 1.202 + // mdo start + parameters offset + array length - 1 1.203 + addptr(mdp, tmp1); 1.204 + movptr(tmp1, Address(mdp, ArrayData::array_len_offset())); 1.205 + decrement(tmp1, TypeStackSlotEntries::per_arg_count()); 1.206 + 1.207 + Label loop; 1.208 + bind(loop); 1.209 + 1.210 + int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0)); 1.211 + int type_base = in_bytes(ParametersTypeData::type_offset(0)); 1.212 + Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size); 1.213 + Address arg_off(mdp, tmp1, per_arg_scale, off_base); 1.214 + Address arg_type(mdp, tmp1, per_arg_scale, type_base); 1.215 + 1.216 + // load offset on the stack from the slot for this parameter 1.217 + movptr(tmp2, arg_off); 1.218 + negptr(tmp2); 1.219 + // read the parameter from the local area 1.220 + movptr(tmp2, Address(_locals_register, tmp2, Interpreter::stackElementScale())); 1.221 + 1.222 + // profile the parameter 1.223 + profile_obj_type(tmp2, arg_type); 1.224 + 1.225 + // go to next parameter 1.226 + decrement(tmp1, TypeStackSlotEntries::per_arg_count()); 1.227 + jcc(Assembler::positive, loop); 1.228 + 1.229 + bind(profile_continue); 1.230 + } 1.231 +} 1.232 +#endif