annotate hotspot/src/cpu/s390/vm/vtableStubs_s390.cpp @ 42065:6032b31e3719

8167673: [s390] The s390 port. Summary: template interpreter, C1, C2 Reviewed-by: kvn, simonis
author goetz
date Thu, 13 Oct 2016 14:49:34 +0200
parents
children 6eef3d367beb
rev   line source
goetz@42065 1 /*
goetz@42065 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
goetz@42065 3 * Copyright (c) 2016 SAP SE. All rights reserved.
goetz@42065 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
goetz@42065 5 *
goetz@42065 6 * This code is free software; you can redistribute it and/or modify it
goetz@42065 7 * under the terms of the GNU General Public License version 2 only, as
goetz@42065 8 * published by the Free Software Foundation.
goetz@42065 9 *
goetz@42065 10 * This code is distributed in the hope that it will be useful, but WITHOUT
goetz@42065 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
goetz@42065 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
goetz@42065 13 * version 2 for more details (a copy is included in the LICENSE file that
goetz@42065 14 * accompanied this code).
goetz@42065 15 *
goetz@42065 16 * You should have received a copy of the GNU General Public License version
goetz@42065 17 * 2 along with this work; if not, write to the Free Software Foundation,
goetz@42065 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
goetz@42065 19 *
goetz@42065 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
goetz@42065 21 * or visit www.oracle.com if you need additional information or have any
goetz@42065 22 * questions.
goetz@42065 23 *
goetz@42065 24 */
goetz@42065 25
goetz@42065 26 #include "precompiled.hpp"
goetz@42065 27 #include "asm/macroAssembler.inline.hpp"
goetz@42065 28 #include "code/vtableStubs.hpp"
goetz@42065 29 #include "interp_masm_s390.hpp"
goetz@42065 30 #include "memory/resourceArea.hpp"
goetz@42065 31 #include "oops/instanceKlass.hpp"
goetz@42065 32 #include "oops/klassVtable.hpp"
goetz@42065 33 #include "runtime/sharedRuntime.hpp"
goetz@42065 34 #include "vmreg_s390.inline.hpp"
goetz@42065 35 #ifdef COMPILER2
goetz@42065 36 #include "opto/runtime.hpp"
goetz@42065 37 #endif
goetz@42065 38
goetz@42065 39 // Machine-dependent part of VtableStubs: create vtableStub of correct
goetz@42065 40 // size and initialize its code.
goetz@42065 41
goetz@42065 42 #define __ masm->
goetz@42065 43
goetz@42065 44 #ifndef PRODUCT
goetz@42065 45 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index);
goetz@42065 46 #endif
goetz@42065 47
goetz@42065 48 // Used by compiler only; may use only caller saved, non-argument registers.
goetz@42065 49 VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
goetz@42065 50
goetz@42065 51 const int code_length = VtableStub::pd_code_size_limit(true);
goetz@42065 52 VtableStub *s = new(code_length) VtableStub(true, vtable_index);
goetz@42065 53 if (s == NULL) { // Indicates OOM In the code cache.
goetz@42065 54 return NULL;
goetz@42065 55 }
goetz@42065 56
goetz@42065 57 ResourceMark rm;
goetz@42065 58 CodeBuffer cb(s->entry_point(), code_length);
goetz@42065 59 MacroAssembler *masm = new MacroAssembler(&cb);
goetz@42065 60 address start_pc;
goetz@42065 61 int padding_bytes = 0;
goetz@42065 62
goetz@42065 63 #if (!defined(PRODUCT) && defined(COMPILER2))
goetz@42065 64 if (CountCompiledCalls) {
goetz@42065 65 // Count unused bytes
goetz@42065 66 // worst case actual size
goetz@42065 67 padding_bytes += __ load_const_size() - __ load_const_optimized_rtn_len(Z_R1_scratch, (long)SharedRuntime::nof_megamorphic_calls_addr(), true);
goetz@42065 68
goetz@42065 69 // Use generic emitter for direct memory increment.
goetz@42065 70 // Abuse Z_method as scratch register for generic emitter.
goetz@42065 71 // It is loaded further down anyway before it is first used.
goetz@42065 72 __ add2mem_32(Address(Z_R1_scratch), 1, Z_method);
goetz@42065 73 }
goetz@42065 74 #endif
goetz@42065 75
goetz@42065 76 assert(VtableStub::receiver_location() == Z_R2->as_VMReg(), "receiver expected in Z_ARG1");
goetz@42065 77
goetz@42065 78 // Get receiver klass.
goetz@42065 79 // Must do an explicit check if implicit checks are disabled.
goetz@42065 80 address npe_addr = __ pc(); // npe == NULL ptr exception
goetz@42065 81 __ null_check(Z_ARG1, Z_R1_scratch, oopDesc::klass_offset_in_bytes());
goetz@42065 82 const Register rcvr_klass = Z_R1_scratch;
goetz@42065 83 __ load_klass(rcvr_klass, Z_ARG1);
goetz@42065 84
goetz@42065 85 // Set method (in case of interpreted method), and destination address.
goetz@42065 86 int entry_offset = in_bytes(InstanceKlass::vtable_start_offset()) +
goetz@42065 87 vtable_index * vtableEntry::size_in_bytes();
goetz@42065 88
goetz@42065 89 #ifndef PRODUCT
goetz@42065 90 if (DebugVtables) {
goetz@42065 91 Label L;
goetz@42065 92 // Check offset vs vtable length.
goetz@42065 93 const Register vtable_idx = Z_R0_scratch;
goetz@42065 94
goetz@42065 95 // Count unused bytes.
goetz@42065 96 // worst case actual size
goetz@42065 97 padding_bytes += __ load_const_size() - __ load_const_optimized_rtn_len(vtable_idx, vtable_index*vtableEntry::size_in_bytes(), true);
goetz@42065 98
goetz@42065 99 assert(Immediate::is_uimm12(in_bytes(InstanceKlass::vtable_length_offset())), "disp to large");
goetz@42065 100 __ z_cl(vtable_idx, in_bytes(InstanceKlass::vtable_length_offset()), rcvr_klass);
goetz@42065 101 __ z_brl(L);
goetz@42065 102 __ z_lghi(Z_ARG3, vtable_index); // Debug code, don't optimize.
goetz@42065 103 __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), Z_ARG1, Z_ARG3, false);
goetz@42065 104 // Count unused bytes (assume worst case here).
goetz@42065 105 padding_bytes += 12;
goetz@42065 106 __ bind(L);
goetz@42065 107 }
goetz@42065 108 #endif
goetz@42065 109
goetz@42065 110 int v_off = entry_offset + vtableEntry::method_offset_in_bytes();
goetz@42065 111
goetz@42065 112 // Duplicate safety code from enc_class Java_Dynamic_Call_dynTOC.
goetz@42065 113 if (Displacement::is_validDisp(v_off)) {
goetz@42065 114 __ z_lg(Z_method/*method oop*/, v_off, rcvr_klass/*class oop*/);
goetz@42065 115 // Account for the load_const in the else path.
goetz@42065 116 padding_bytes += __ load_const_size();
goetz@42065 117 } else {
goetz@42065 118 // Worse case, offset does not fit in displacement field.
goetz@42065 119 __ load_const(Z_method, v_off); // Z_method temporarily holds the offset value.
goetz@42065 120 __ z_lg(Z_method/*method oop*/, 0, Z_method/*method offset*/, rcvr_klass/*class oop*/);
goetz@42065 121 }
goetz@42065 122
goetz@42065 123 #ifndef PRODUCT
goetz@42065 124 if (DebugVtables) {
goetz@42065 125 Label L;
goetz@42065 126 __ z_ltgr(Z_method, Z_method);
goetz@42065 127 __ z_brne(L);
goetz@42065 128 __ stop("Vtable entry is ZERO",102);
goetz@42065 129 __ bind(L);
goetz@42065 130 }
goetz@42065 131 #endif
goetz@42065 132
goetz@42065 133 address ame_addr = __ pc(); // ame = abstract method error
goetz@42065 134
goetz@42065 135 // Must do an explicit check if implicit checks are disabled.
goetz@42065 136 __ null_check(Z_method, Z_R1_scratch, in_bytes(Method::from_compiled_offset()));
goetz@42065 137 __ z_lg(Z_R1_scratch, in_bytes(Method::from_compiled_offset()), Z_method);
goetz@42065 138 __ z_br(Z_R1_scratch);
goetz@42065 139
goetz@42065 140 masm->flush();
goetz@42065 141
goetz@42065 142 s->set_exception_points(npe_addr, ame_addr);
goetz@42065 143
goetz@42065 144 return s;
goetz@42065 145 }
goetz@42065 146
goetz@42065 147 VtableStub* VtableStubs::create_itable_stub(int vtable_index) {
goetz@42065 148 const int code_length = VtableStub::pd_code_size_limit(false);
goetz@42065 149 VtableStub *s = new(code_length) VtableStub(false, vtable_index);
goetz@42065 150 if (s == NULL) { // Indicates OOM in the code cache.
goetz@42065 151 return NULL;
goetz@42065 152 }
goetz@42065 153
goetz@42065 154 ResourceMark rm;
goetz@42065 155 CodeBuffer cb(s->entry_point(), code_length);
goetz@42065 156 MacroAssembler *masm = new MacroAssembler(&cb);
goetz@42065 157 address start_pc;
goetz@42065 158 int padding_bytes = 0;
goetz@42065 159
goetz@42065 160 #if (!defined(PRODUCT) && defined(COMPILER2))
goetz@42065 161 if (CountCompiledCalls) {
goetz@42065 162 // Count unused bytes
goetz@42065 163 // worst case actual size
goetz@42065 164 padding_bytes += __ load_const_size() - __ load_const_optimized_rtn_len(Z_R1_scratch, (long)SharedRuntime::nof_megamorphic_calls_addr(), true);
goetz@42065 165
goetz@42065 166 // Use generic emitter for direct memory increment.
goetz@42065 167 // Use Z_tmp_1 as scratch register for generic emitter.
goetz@42065 168 __ add2mem_32((Z_R1_scratch), 1, Z_tmp_1);
goetz@42065 169 }
goetz@42065 170 #endif
goetz@42065 171
goetz@42065 172 assert(VtableStub::receiver_location() == Z_R2->as_VMReg(), "receiver expected in Z_ARG1");
goetz@42065 173
goetz@42065 174 // Entry arguments:
goetz@42065 175 // Z_method: Interface
goetz@42065 176 // Z_ARG1: Receiver
goetz@42065 177 const Register rcvr_klass = Z_tmp_1; // Used to compute itable_entry_addr.
goetz@42065 178 // Use extra reg to avoid re-load.
goetz@42065 179 const Register vtable_len = Z_tmp_2; // Used to compute itable_entry_addr.
goetz@42065 180 const Register itable_entry_addr = Z_R1_scratch;
goetz@42065 181 const Register itable_interface = Z_R0_scratch;
goetz@42065 182
goetz@42065 183 // Get receiver klass.
goetz@42065 184 // Must do an explicit check if implicit checks are disabled.
goetz@42065 185 address npe_addr = __ pc(); // npe == NULL ptr exception
goetz@42065 186 __ null_check(Z_ARG1, Z_R1_scratch, oopDesc::klass_offset_in_bytes());
goetz@42065 187 __ load_klass(rcvr_klass, Z_ARG1);
goetz@42065 188
goetz@42065 189 // Load start of itable entries into itable_entry.
goetz@42065 190 __ z_llgf(vtable_len, Address(rcvr_klass, InstanceKlass::vtable_length_offset()));
goetz@42065 191 __ z_sllg(vtable_len, vtable_len, exact_log2(vtableEntry::size_in_bytes()));
goetz@42065 192
goetz@42065 193 // Loop over all itable entries until desired interfaceOop(Rinterface) found.
goetz@42065 194 const int vtable_base_offset = in_bytes(InstanceKlass::vtable_start_offset());
goetz@42065 195 // Count unused bytes.
goetz@42065 196 start_pc = __ pc();
goetz@42065 197 __ add2reg_with_index(itable_entry_addr, vtable_base_offset + itableOffsetEntry::interface_offset_in_bytes(), rcvr_klass, vtable_len);
goetz@42065 198 padding_bytes += 20 - (__ pc() - start_pc);
goetz@42065 199
goetz@42065 200 const int itable_offset_search_inc = itableOffsetEntry::size() * wordSize;
goetz@42065 201 Label search;
goetz@42065 202 __ bind(search);
goetz@42065 203
goetz@42065 204 // Handle IncompatibleClassChangeError in itable stubs.
goetz@42065 205 // If the entry is NULL then we've reached the end of the table
goetz@42065 206 // without finding the expected interface, so throw an exception.
goetz@42065 207 NearLabel throw_icce;
goetz@42065 208 __ load_and_test_long(itable_interface, Address(itable_entry_addr));
goetz@42065 209 __ z_bre(throw_icce); // Throw the exception out-of-line.
goetz@42065 210 // Count unused bytes.
goetz@42065 211 start_pc = __ pc();
goetz@42065 212 __ add2reg(itable_entry_addr, itable_offset_search_inc);
goetz@42065 213 padding_bytes += 20 - (__ pc() - start_pc);
goetz@42065 214 __ z_cgr(itable_interface, Z_method);
goetz@42065 215 __ z_brne(search);
goetz@42065 216
goetz@42065 217 // Entry found. Itable_entry_addr points to the subsequent entry (itable_offset_search_inc too far).
goetz@42065 218 // Get offset of vtable for interface.
goetz@42065 219
goetz@42065 220 const Register vtable_offset = Z_R1_scratch;
goetz@42065 221 const Register itable_method = rcvr_klass; // Calculated before.
goetz@42065 222
goetz@42065 223 const int vtable_offset_offset = (itableOffsetEntry::offset_offset_in_bytes() -
goetz@42065 224 itableOffsetEntry::interface_offset_in_bytes()) -
goetz@42065 225 itable_offset_search_inc;
goetz@42065 226 __ z_llgf(vtable_offset, vtable_offset_offset, itable_entry_addr);
goetz@42065 227
goetz@42065 228 // Compute itableMethodEntry and get method and entry point for compiler.
goetz@42065 229 const int method_offset = (itableMethodEntry::size() * wordSize * vtable_index) +
goetz@42065 230 itableMethodEntry::method_offset_in_bytes();
goetz@42065 231
goetz@42065 232 __ z_lg(Z_method, method_offset, vtable_offset, itable_method);
goetz@42065 233
goetz@42065 234 #ifndef PRODUCT
goetz@42065 235 if (DebugVtables) {
goetz@42065 236 Label ok1;
goetz@42065 237 __ z_ltgr(Z_method, Z_method);
goetz@42065 238 __ z_brne(ok1);
goetz@42065 239 __ stop("method is null",103);
goetz@42065 240 __ bind(ok1);
goetz@42065 241 }
goetz@42065 242 #endif
goetz@42065 243
goetz@42065 244 address ame_addr = __ pc();
goetz@42065 245 // Must do an explicit check if implicit checks are disabled.
goetz@42065 246 if (!ImplicitNullChecks) {
goetz@42065 247 __ compare64_and_branch(Z_method, (intptr_t) 0, Assembler::bcondEqual, throw_icce);
goetz@42065 248 }
goetz@42065 249 __ z_lg(Z_R1_scratch, in_bytes(Method::from_compiled_offset()), Z_method);
goetz@42065 250 __ z_br(Z_R1_scratch);
goetz@42065 251
goetz@42065 252 // Handle IncompatibleClassChangeError in itable stubs.
goetz@42065 253 __ bind(throw_icce);
goetz@42065 254 // Count unused bytes
goetz@42065 255 // worst case actual size
goetz@42065 256 // We force resolving of the call site by jumping to
goetz@42065 257 // the "handle wrong method" stub, and so let the
goetz@42065 258 // interpreter runtime do all the dirty work.
goetz@42065 259 padding_bytes += __ load_const_size() - __ load_const_optimized_rtn_len(Z_R1_scratch, (long)SharedRuntime::get_handle_wrong_method_stub(), true);
goetz@42065 260 __ z_br(Z_R1_scratch);
goetz@42065 261
goetz@42065 262 masm->flush();
goetz@42065 263
goetz@42065 264 s->set_exception_points(npe_addr, ame_addr);
goetz@42065 265 return s;
goetz@42065 266 }
goetz@42065 267
goetz@42065 268 // In order to tune these parameters, run the JVM with VM options
goetz@42065 269 // +PrintMiscellaneous and +WizardMode to see information about
goetz@42065 270 // actual itable stubs. Run it with -Xmx31G -XX:+UseCompressedOops.
goetz@42065 271 int VtableStub::pd_code_size_limit(bool is_vtable_stub) {
goetz@42065 272 int size = DebugVtables ? 216 : 0;
goetz@42065 273 if (CountCompiledCalls) {
goetz@42065 274 size += 6 * 4;
goetz@42065 275 }
goetz@42065 276 if (is_vtable_stub) {
goetz@42065 277 size += 52;
goetz@42065 278 } else {
goetz@42065 279 size += 104;
goetz@42065 280 }
goetz@42065 281 if (Universe::narrow_klass_base() != NULL) {
goetz@42065 282 size += 16; // A guess.
goetz@42065 283 }
goetz@42065 284 return size;
goetz@42065 285 }
goetz@42065 286
goetz@42065 287 int VtableStub::pd_code_alignment() {
goetz@42065 288 const unsigned int icache_line_size = 32;
goetz@42065 289 return icache_line_size;
goetz@42065 290 }