src/cpu/x86/vm/interp_masm_x86.cpp

Fri, 16 Aug 2019 16:50:17 +0200

author
eosterlund
date
Fri, 16 Aug 2019 16:50:17 +0200
changeset 9834
bb1da64b0492
parent 8368
32b682649973
child 8604
04d83ba48607
permissions
-rw-r--r--

8229345: Memory leak due to vtable stubs not being shared on SPARC
Reviewed-by: mdoerr, dholmes, kvn

roland@5987 1 /*
kevinw@8368 2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
roland@5987 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
roland@5987 4 *
roland@5987 5 * This code is free software; you can redistribute it and/or modify it
roland@5987 6 * under the terms of the GNU General Public License version 2 only, as
roland@5987 7 * published by the Free Software Foundation.
roland@5987 8 *
roland@5987 9 * This code is distributed in the hope that it will be useful, but WITHOUT
roland@5987 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
roland@5987 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
roland@5987 12 * version 2 for more details (a copy is included in the LICENSE file that
roland@5987 13 * accompanied this code).
roland@5987 14 *
roland@5987 15 * You should have received a copy of the GNU General Public License version
roland@5987 16 * 2 along with this work; if not, write to the Free Software Foundation,
roland@5987 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
roland@5987 18 *
roland@5987 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
roland@5987 20 * or visit www.oracle.com if you need additional information or have any
roland@5987 21 * questions.
roland@5987 22 *
roland@5987 23 */
roland@5987 24
roland@5987 25 #include "precompiled.hpp"
roland@5987 26 #include "interp_masm_x86.hpp"
roland@5987 27 #include "interpreter/interpreter.hpp"
roland@5987 28 #include "oops/methodData.hpp"
roland@5987 29
kevinw@8368 30
kevinw@8368 31 // 8u does not have InterpreterMacroAssembler::load_earlyret_value here
kevinw@8368 32
kevinw@8368 33 void InterpreterMacroAssembler::narrow(Register result) {
kevinw@8368 34
kevinw@8368 35 // Get method->_constMethod->_result_type
kevinw@8368 36 movptr(rcx, Address(rbp, frame::interpreter_frame_method_offset * wordSize));
kevinw@8368 37 movptr(rcx, Address(rcx, Method::const_offset()));
kevinw@8368 38 load_unsigned_byte(rcx, Address(rcx, ConstMethod::result_type_offset()));
kevinw@8368 39
kevinw@8368 40 Label done, notBool, notByte, notChar;
kevinw@8368 41
kevinw@8368 42 // common case first
kevinw@8368 43 cmpl(rcx, T_INT);
kevinw@8368 44 jcc(Assembler::equal, done);
kevinw@8368 45
kevinw@8368 46 // mask integer result to narrower return type.
kevinw@8368 47 cmpl(rcx, T_BOOLEAN);
kevinw@8368 48 jcc(Assembler::notEqual, notBool);
kevinw@8368 49 andl(result, 0x1);
kevinw@8368 50 jmp(done);
kevinw@8368 51
kevinw@8368 52 bind(notBool);
kevinw@8368 53 cmpl(rcx, T_BYTE);
kevinw@8368 54 jcc(Assembler::notEqual, notByte);
kevinw@8368 55 LP64_ONLY(movsbl(result, result);)
kevinw@8368 56 NOT_LP64(shll(result, 24);) // truncate upper 24 bits
kevinw@8368 57 NOT_LP64(sarl(result, 24);) // and sign-extend byte
kevinw@8368 58 jmp(done);
kevinw@8368 59
kevinw@8368 60 bind(notByte);
kevinw@8368 61 cmpl(rcx, T_CHAR);
kevinw@8368 62 jcc(Assembler::notEqual, notChar);
kevinw@8368 63 LP64_ONLY(movzwl(result, result);)
kevinw@8368 64 NOT_LP64(andl(result, 0xFFFF);) // truncate upper 16 bits
kevinw@8368 65 jmp(done);
kevinw@8368 66
kevinw@8368 67 bind(notChar);
kevinw@8368 68 // cmpl(rcx, T_SHORT); // all that's left
kevinw@8368 69 // jcc(Assembler::notEqual, done);
kevinw@8368 70 LP64_ONLY(movswl(result, result);)
kevinw@8368 71 NOT_LP64(shll(result, 16);) // truncate upper 16 bits
kevinw@8368 72 NOT_LP64(sarl(result, 16);) // and sign-extend short
kevinw@8368 73
kevinw@8368 74 // Nothing to do for T_INT
kevinw@8368 75 bind(done);
kevinw@8368 76 }
kevinw@8368 77
roland@5987 78 #ifndef CC_INTERP
roland@5987 79 void InterpreterMacroAssembler::profile_obj_type(Register obj, const Address& mdo_addr) {
roland@5987 80 Label update, next, none;
roland@5987 81
roland@5987 82 verify_oop(obj);
roland@5987 83
roland@5987 84 testptr(obj, obj);
roland@5987 85 jccb(Assembler::notZero, update);
roland@5987 86 orptr(mdo_addr, TypeEntries::null_seen);
roland@5987 87 jmpb(next);
roland@5987 88
roland@5987 89 bind(update);
roland@5987 90 load_klass(obj, obj);
roland@5987 91
roland@5987 92 xorptr(obj, mdo_addr);
roland@5987 93 testptr(obj, TypeEntries::type_klass_mask);
roland@5987 94 jccb(Assembler::zero, next); // klass seen before, nothing to
roland@5987 95 // do. The unknown bit may have been
roland@5987 96 // set already but no need to check.
roland@5987 97
roland@5987 98 testptr(obj, TypeEntries::type_unknown);
roland@5987 99 jccb(Assembler::notZero, next); // already unknown. Nothing to do anymore.
roland@5987 100
roland@5987 101 cmpptr(mdo_addr, 0);
roland@5987 102 jccb(Assembler::equal, none);
roland@5987 103 cmpptr(mdo_addr, TypeEntries::null_seen);
roland@5987 104 jccb(Assembler::equal, none);
roland@5987 105 // There is a chance that the checks above (re-reading profiling
roland@5987 106 // data from memory) fail if another thread has just set the
roland@5987 107 // profiling to this obj's klass
roland@5987 108 xorptr(obj, mdo_addr);
roland@5987 109 testptr(obj, TypeEntries::type_klass_mask);
roland@5987 110 jccb(Assembler::zero, next);
roland@5987 111
roland@5987 112 // different than before. Cannot keep accurate profile.
roland@5987 113 orptr(mdo_addr, TypeEntries::type_unknown);
roland@5987 114 jmpb(next);
roland@5987 115
roland@5987 116 bind(none);
roland@5987 117 // first time here. Set profile type.
roland@5987 118 movptr(mdo_addr, obj);
roland@5987 119
roland@5987 120 bind(next);
roland@5987 121 }
roland@5987 122
roland@5987 123 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {
roland@5987 124 if (!ProfileInterpreter) {
roland@5987 125 return;
roland@5987 126 }
roland@5987 127
roland@5987 128 if (MethodData::profile_arguments() || MethodData::profile_return()) {
roland@5987 129 Label profile_continue;
roland@5987 130
roland@5987 131 test_method_data_pointer(mdp, profile_continue);
roland@5987 132
roland@5987 133 int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
roland@5987 134
roland@5987 135 cmpb(Address(mdp, in_bytes(DataLayout::tag_offset()) - off_to_start), is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
roland@5987 136 jcc(Assembler::notEqual, profile_continue);
roland@5987 137
roland@5987 138 if (MethodData::profile_arguments()) {
roland@5987 139 Label done;
roland@5987 140 int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
roland@5987 141 addptr(mdp, off_to_args);
roland@5987 142
roland@5987 143 for (int i = 0; i < TypeProfileArgsLimit; i++) {
roland@5987 144 if (i > 0 || MethodData::profile_return()) {
roland@5987 145 // If return value type is profiled we may have no argument to profile
roland@5987 146 movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
roland@5987 147 subl(tmp, i*TypeStackSlotEntries::per_arg_count());
roland@5987 148 cmpl(tmp, TypeStackSlotEntries::per_arg_count());
roland@5987 149 jcc(Assembler::less, done);
roland@5987 150 }
roland@5987 151 movptr(tmp, Address(callee, Method::const_offset()));
roland@5987 152 load_unsigned_short(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));
roland@5987 153 // stack offset o (zero based) from the start of the argument
roland@5987 154 // list, for n arguments translates into offset n - o - 1 from
roland@5987 155 // the end of the argument list
roland@5987 156 subptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args));
roland@5987 157 subl(tmp, 1);
roland@5987 158 Address arg_addr = argument_address(tmp);
roland@5987 159 movptr(tmp, arg_addr);
roland@5987 160
roland@5987 161 Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);
roland@5987 162 profile_obj_type(tmp, mdo_arg_addr);
roland@5987 163
roland@5987 164 int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
roland@5987 165 addptr(mdp, to_add);
roland@5987 166 off_to_args += to_add;
roland@5987 167 }
roland@5987 168
roland@5987 169 if (MethodData::profile_return()) {
roland@5987 170 movptr(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args));
roland@5987 171 subl(tmp, TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
roland@5987 172 }
roland@5987 173
roland@5987 174 bind(done);
roland@5987 175
roland@5987 176 if (MethodData::profile_return()) {
roland@5987 177 // We're right after the type profile for the last
roland@6223 178 // argument. tmp is the number of cells left in the
roland@5987 179 // CallTypeData/VirtualCallTypeData to reach its end. Non null
roland@5987 180 // if there's a return to profile.
roland@5987 181 assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");
roland@5987 182 shll(tmp, exact_log2(DataLayout::cell_size));
roland@5987 183 addptr(mdp, tmp);
roland@5987 184 }
roland@5987 185 movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp);
roland@5987 186 } else {
roland@5987 187 assert(MethodData::profile_return(), "either profile call args or call ret");
roland@6643 188 update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));
roland@5987 189 }
roland@5987 190
roland@5987 191 // mdp points right after the end of the
roland@5987 192 // CallTypeData/VirtualCallTypeData, right after the cells for the
roland@5987 193 // return value type if there's one
roland@5987 194
roland@5987 195 bind(profile_continue);
roland@5987 196 }
roland@5987 197 }
roland@5987 198
roland@5987 199 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {
roland@5987 200 assert_different_registers(mdp, ret, tmp, _bcp_register);
roland@5987 201 if (ProfileInterpreter && MethodData::profile_return()) {
roland@5987 202 Label profile_continue, done;
roland@5987 203
roland@5987 204 test_method_data_pointer(mdp, profile_continue);
roland@5987 205
roland@5987 206 if (MethodData::profile_return_jsr292_only()) {
roland@5987 207 // If we don't profile all invoke bytecodes we must make sure
roland@5987 208 // it's a bytecode we indeed profile. We can't go back to the
roland@5987 209 // begining of the ProfileData we intend to update to check its
roland@5987 210 // type because we're right after it and we don't known its
roland@5987 211 // length
roland@5987 212 Label do_profile;
roland@5987 213 cmpb(Address(_bcp_register, 0), Bytecodes::_invokedynamic);
roland@5987 214 jcc(Assembler::equal, do_profile);
roland@5987 215 cmpb(Address(_bcp_register, 0), Bytecodes::_invokehandle);
roland@5987 216 jcc(Assembler::equal, do_profile);
roland@5987 217 get_method(tmp);
roland@5987 218 cmpb(Address(tmp, Method::intrinsic_id_offset_in_bytes()), vmIntrinsics::_compiledLambdaForm);
roland@5987 219 jcc(Assembler::notEqual, profile_continue);
roland@5987 220
roland@5987 221 bind(do_profile);
roland@5987 222 }
roland@5987 223
roland@5987 224 Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));
roland@5987 225 mov(tmp, ret);
roland@5987 226 profile_obj_type(tmp, mdo_ret_addr);
roland@5987 227
roland@5987 228 bind(profile_continue);
roland@5987 229 }
roland@5987 230 }
roland@5987 231
roland@5987 232 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {
roland@5987 233 if (ProfileInterpreter && MethodData::profile_parameters()) {
roland@5987 234 Label profile_continue, done;
roland@5987 235
roland@5987 236 test_method_data_pointer(mdp, profile_continue);
roland@5987 237
roland@5987 238 // Load the offset of the area within the MDO used for
roland@5987 239 // parameters. If it's negative we're not profiling any parameters
roland@5987 240 movl(tmp1, Address(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())));
roland@5987 241 testl(tmp1, tmp1);
roland@5987 242 jcc(Assembler::negative, profile_continue);
roland@5987 243
roland@5987 244 // Compute a pointer to the area for parameters from the offset
roland@5987 245 // and move the pointer to the slot for the last
roland@5987 246 // parameters. Collect profiling from last parameter down.
roland@5987 247 // mdo start + parameters offset + array length - 1
roland@5987 248 addptr(mdp, tmp1);
roland@6223 249 movptr(tmp1, Address(mdp, ArrayData::array_len_offset()));
roland@5987 250 decrement(tmp1, TypeStackSlotEntries::per_arg_count());
roland@5987 251
roland@5987 252 Label loop;
roland@5987 253 bind(loop);
roland@5987 254
roland@5987 255 int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
roland@5987 256 int type_base = in_bytes(ParametersTypeData::type_offset(0));
roland@5987 257 Address::ScaleFactor per_arg_scale = Address::times(DataLayout::cell_size);
roland@5987 258 Address arg_off(mdp, tmp1, per_arg_scale, off_base);
roland@5987 259 Address arg_type(mdp, tmp1, per_arg_scale, type_base);
roland@5987 260
roland@5987 261 // load offset on the stack from the slot for this parameter
roland@5987 262 movptr(tmp2, arg_off);
roland@5987 263 negptr(tmp2);
roland@5987 264 // read the parameter from the local area
roland@5987 265 movptr(tmp2, Address(_locals_register, tmp2, Interpreter::stackElementScale()));
roland@5987 266
roland@5987 267 // profile the parameter
roland@5987 268 profile_obj_type(tmp2, arg_type);
roland@5987 269
roland@5987 270 // go to next parameter
roland@5987 271 decrement(tmp1, TypeStackSlotEntries::per_arg_count());
roland@5987 272 jcc(Assembler::positive, loop);
roland@5987 273
roland@5987 274 bind(profile_continue);
roland@5987 275 }
roland@5987 276 }
roland@5987 277 #endif

mercurial