src/cpu/ppc/vm/vtableStubs_ppc_64.cpp

Wed, 27 Nov 2013 16:16:21 -0800

author
goetz
date
Wed, 27 Nov 2013 16:16:21 -0800
changeset 6490
41b780b43b74
parent 6486
b0133e4187d3
child 6495
67fa91961822
permissions
-rw-r--r--

8029015: PPC64 (part 216): opto: trap based null and range checks
Summary: On PPC64 use tdi instruction that does a compare and raises SIGTRAP for NULL and range checks.
Reviewed-by: kvn

goetz@6458 1 /*
goetz@6458 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
goetz@6458 3 * Copyright 2012, 2013 SAP AG. All rights reserved.
goetz@6458 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
goetz@6458 5 *
goetz@6458 6 * This code is free software; you can redistribute it and/or modify it
goetz@6458 7 * under the terms of the GNU General Public License version 2 only, as
goetz@6458 8 * published by the Free Software Foundation.
goetz@6458 9 *
goetz@6458 10 * This code is distributed in the hope that it will be useful, but WITHOUT
goetz@6458 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
goetz@6458 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
goetz@6458 13 * version 2 for more details (a copy is included in the LICENSE file that
goetz@6458 14 * accompanied this code).
goetz@6458 15 *
goetz@6458 16 * You should have received a copy of the GNU General Public License version
goetz@6458 17 * 2 along with this work; if not, write to the Free Software Foundation,
goetz@6458 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
goetz@6458 19 *
goetz@6458 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
goetz@6458 21 * or visit www.oracle.com if you need additional information or have any
goetz@6458 22 * questions.
goetz@6458 23 *
goetz@6458 24 */
goetz@6458 25
goetz@6458 26 #include "precompiled.hpp"
goetz@6458 27 #include "asm/assembler.hpp"
goetz@6458 28 #include "asm/macroAssembler.inline.hpp"
goetz@6458 29 #include "code/vtableStubs.hpp"
goetz@6458 30 #include "interp_masm_ppc_64.hpp"
goetz@6458 31 #include "memory/resourceArea.hpp"
goetz@6458 32 #include "oops/instanceKlass.hpp"
goetz@6458 33 #include "oops/klassVtable.hpp"
goetz@6458 34 #include "runtime/sharedRuntime.hpp"
goetz@6458 35 #include "vmreg_ppc.inline.hpp"
goetz@6458 36 #ifdef COMPILER2
goetz@6458 37 #include "opto/runtime.hpp"
goetz@6458 38 #endif
goetz@6458 39
goetz@6458 40 #define __ masm->
goetz@6458 41
goetz@6458 42 #ifdef PRODUCT
goetz@6458 43 #define BLOCK_COMMENT(str) // nothing
goetz@6458 44 #else
goetz@6458 45 #define BLOCK_COMMENT(str) __ block_comment(str)
goetz@6458 46 #endif
goetz@6458 47 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
goetz@6458 48
goetz@6458 49 #ifndef PRODUCT
goetz@6458 50 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oopDesc* receiver, int index);
goetz@6458 51 #endif
goetz@6458 52
goetz@6458 53 // Used by compiler only; may use only caller saved, non-argument
goetz@6458 54 // registers.
goetz@6458 55 VtableStub* VtableStubs::create_vtable_stub(int vtable_index) {
goetz@6458 56 // PPC port: use fixed size.
goetz@6458 57 const int code_length = VtableStub::pd_code_size_limit(true);
goetz@6458 58 VtableStub* s = new (code_length) VtableStub(true, vtable_index);
goetz@6458 59 ResourceMark rm;
goetz@6458 60 CodeBuffer cb(s->entry_point(), code_length);
goetz@6458 61 MacroAssembler* masm = new MacroAssembler(&cb);
goetz@6458 62 address start_pc;
goetz@6458 63
goetz@6458 64 #ifndef PRODUCT
goetz@6458 65 if (CountCompiledCalls) {
goetz@6458 66 __ load_const(R11_scratch1, SharedRuntime::nof_megamorphic_calls_addr());
goetz@6458 67 __ lwz(R12_scratch2, 0, R11_scratch1);
goetz@6458 68 __ addi(R12_scratch2, R12_scratch2, 1);
goetz@6458 69 __ stw(R12_scratch2, 0, R11_scratch1);
goetz@6458 70 }
goetz@6458 71 #endif
goetz@6458 72
goetz@6458 73 assert(VtableStub::receiver_location() == R3_ARG1->as_VMReg(), "receiver expected in R3_ARG1");
goetz@6458 74
goetz@6458 75 // Get receiver klass.
goetz@6458 76 const Register rcvr_klass = R11_scratch1;
goetz@6458 77
goetz@6458 78 // We might implicit NULL fault here.
goetz@6458 79 address npe_addr = __ pc(); // npe = null pointer exception
goetz@6458 80 __ load_klass_with_trap_null_check(rcvr_klass, R3);
goetz@6458 81
goetz@6458 82 // Set methodOop (in case of interpreted method), and destination address.
goetz@6458 83 int entry_offset = InstanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size();
goetz@6458 84
goetz@6458 85 #ifndef PRODUCT
goetz@6458 86 if (DebugVtables) {
goetz@6458 87 Label L;
goetz@6458 88 // Check offset vs vtable length.
goetz@6458 89 const Register vtable_len = R12_scratch2;
goetz@6458 90 __ lwz(vtable_len, InstanceKlass::vtable_length_offset()*wordSize, rcvr_klass);
goetz@6458 91 __ cmpwi(CCR0, vtable_len, vtable_index*vtableEntry::size());
goetz@6458 92 __ bge(CCR0, L);
goetz@6458 93 __ li(R12_scratch2, vtable_index);
goetz@6458 94 __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), R3_ARG1, R12_scratch2, false);
goetz@6458 95 __ bind(L);
goetz@6458 96 }
goetz@6458 97 #endif
goetz@6458 98
goetz@6458 99 int v_off = entry_offset*wordSize + vtableEntry::method_offset_in_bytes();
goetz@6458 100
goetz@6458 101 __ ld(R19_method, v_off, rcvr_klass);
goetz@6458 102
goetz@6458 103 #ifndef PRODUCT
goetz@6458 104 if (DebugVtables) {
goetz@6458 105 Label L;
goetz@6458 106 __ cmpdi(CCR0, R19_method, 0);
goetz@6458 107 __ bne(CCR0, L);
goetz@6458 108 __ stop("Vtable entry is ZERO", 102);
goetz@6458 109 __ bind(L);
goetz@6458 110 }
goetz@6458 111 #endif
goetz@6458 112
goetz@6458 113 // If the vtable entry is null, the method is abstract.
goetz@6458 114 address ame_addr = __ pc(); // ame = abstract method error
goetz@6458 115
goetz@6458 116 __ ld_with_trap_null_check(R12_scratch2, in_bytes(Method::from_compiled_offset()), R19_method);
goetz@6458 117 __ mtctr(R12_scratch2);
goetz@6458 118 __ bctr();
goetz@6458 119 masm->flush();
goetz@6458 120
goetz@6458 121 guarantee(__ pc() <= s->code_end(), "overflowed buffer");
goetz@6458 122
goetz@6458 123 s->set_exception_points(npe_addr, ame_addr);
goetz@6458 124
goetz@6458 125 return s;
goetz@6458 126 }
goetz@6458 127
goetz@6458 128 VtableStub* VtableStubs::create_itable_stub(int vtable_index) {
goetz@6458 129 // PPC port: use fixed size.
goetz@6458 130 const int code_length = VtableStub::pd_code_size_limit(false);
goetz@6458 131 VtableStub* s = new (code_length) VtableStub(false, vtable_index);
goetz@6458 132 ResourceMark rm;
goetz@6458 133 CodeBuffer cb(s->entry_point(), code_length);
goetz@6458 134 MacroAssembler* masm = new MacroAssembler(&cb);
goetz@6458 135 address start_pc;
goetz@6458 136
goetz@6458 137 #ifndef PRODUCT
goetz@6458 138 if (CountCompiledCalls) {
goetz@6458 139 __ load_const(R11_scratch1, SharedRuntime::nof_megamorphic_calls_addr());
goetz@6458 140 __ lwz(R12_scratch2, 0, R11_scratch1);
goetz@6458 141 __ addi(R12_scratch2, R12_scratch2, 1);
goetz@6458 142 __ stw(R12_scratch2, 0, R11_scratch1);
goetz@6458 143 }
goetz@6458 144 #endif
goetz@6458 145
goetz@6458 146 assert(VtableStub::receiver_location() == R3_ARG1->as_VMReg(), "receiver expected in R3_ARG1");
goetz@6458 147
goetz@6458 148 // Entry arguments:
goetz@6458 149 // R19_method: Interface
goetz@6458 150 // R3_ARG1: Receiver
goetz@6458 151 //
goetz@6458 152
goetz@6458 153 const Register rcvr_klass = R11_scratch1;
goetz@6458 154 const Register vtable_len = R12_scratch2;
goetz@6458 155 const Register itable_entry_addr = R21_tmp1;
goetz@6458 156 const Register itable_interface = R22_tmp2;
goetz@6458 157
goetz@6458 158 // Get receiver klass.
goetz@6458 159
goetz@6458 160 // We might implicit NULL fault here.
goetz@6458 161 address npe_addr = __ pc(); // npe = null pointer exception
goetz@6458 162 __ load_klass_with_trap_null_check(rcvr_klass, R3_ARG1);
goetz@6458 163
goetz@6458 164 //__ ld(rcvr_klass, oopDesc::klass_offset_in_bytes(), R3_ARG1);
goetz@6458 165
goetz@6458 166 BLOCK_COMMENT("Load start of itable entries into itable_entry.");
goetz@6458 167 __ lwz(vtable_len, InstanceKlass::vtable_length_offset() * wordSize, rcvr_klass);
goetz@6458 168 __ slwi(vtable_len, vtable_len, exact_log2(vtableEntry::size() * wordSize));
goetz@6458 169 __ add(itable_entry_addr, vtable_len, rcvr_klass);
goetz@6458 170
goetz@6458 171 // Loop over all itable entries until desired interfaceOop(Rinterface) found.
goetz@6458 172 BLOCK_COMMENT("Increment itable_entry_addr in loop.");
goetz@6458 173 const int vtable_base_offset = InstanceKlass::vtable_start_offset() * wordSize;
goetz@6458 174 __ addi(itable_entry_addr, itable_entry_addr, vtable_base_offset + itableOffsetEntry::interface_offset_in_bytes());
goetz@6458 175
goetz@6458 176 const int itable_offset_search_inc = itableOffsetEntry::size() * wordSize;
goetz@6458 177 Label search;
goetz@6458 178 __ bind(search);
goetz@6458 179 __ ld(itable_interface, 0, itable_entry_addr);
goetz@6458 180
goetz@6458 181 // Handle IncompatibleClassChangeError in itable stubs.
goetz@6458 182 // If the entry is NULL then we've reached the end of the table
goetz@6458 183 // without finding the expected interface, so throw an exception.
goetz@6458 184 BLOCK_COMMENT("Handle IncompatibleClassChangeError in itable stubs.");
goetz@6458 185 Label throw_icce;
goetz@6458 186 __ cmpdi(CCR1, itable_interface, 0);
goetz@6458 187 __ cmpd(CCR0, itable_interface, R19_method);
goetz@6458 188 __ addi(itable_entry_addr, itable_entry_addr, itable_offset_search_inc);
goetz@6458 189 __ beq(CCR1, throw_icce);
goetz@6458 190 __ bne(CCR0, search);
goetz@6458 191
goetz@6458 192 // Entry found and itable_entry_addr points to it, get offset of vtable for interface.
goetz@6458 193
goetz@6458 194 const Register vtable_offset = R12_scratch2;
goetz@6458 195 const Register itable_method = R11_scratch1;
goetz@6458 196
goetz@6458 197 const int vtable_offset_offset = (itableOffsetEntry::offset_offset_in_bytes() -
goetz@6458 198 itableOffsetEntry::interface_offset_in_bytes()) -
goetz@6458 199 itable_offset_search_inc;
goetz@6458 200 __ lwz(vtable_offset, vtable_offset_offset, itable_entry_addr);
goetz@6458 201
goetz@6458 202 // Compute itableMethodEntry and get methodOop and entry point for compiler.
goetz@6458 203 const int method_offset = (itableMethodEntry::size() * wordSize * vtable_index) +
goetz@6458 204 itableMethodEntry::method_offset_in_bytes();
goetz@6458 205
goetz@6458 206 __ add(itable_method, rcvr_klass, vtable_offset);
goetz@6458 207 __ ld(R19_method, method_offset, itable_method);
goetz@6458 208
goetz@6458 209 #ifndef PRODUCT
goetz@6458 210 if (DebugVtables) {
goetz@6458 211 Label ok;
goetz@6458 212 __ cmpd(CCR0, R19_method, 0);
goetz@6458 213 __ bne(CCR0, ok);
goetz@6458 214 __ stop("methodOop is null", 103);
goetz@6458 215 __ bind(ok);
goetz@6458 216 }
goetz@6458 217 #endif
goetz@6458 218
goetz@6458 219 // If the vtable entry is null, the method is abstract.
goetz@6458 220 address ame_addr = __ pc(); // ame = abstract method error
goetz@6458 221
goetz@6458 222 // Must do an explicit check if implicit checks are disabled.
goetz@6458 223 assert(!MacroAssembler::needs_explicit_null_check(in_bytes(Method::from_compiled_offset())), "sanity");
goetz@6486 224 if (!ImplicitNullChecks || !os::zero_page_read_protected()) {
goetz@6458 225 if (TrapBasedNullChecks) {
goetz@6458 226 __ trap_null_check(R19_method);
goetz@6458 227 } else {
goetz@6458 228 __ cmpdi(CCR0, R19_method, 0);
goetz@6458 229 __ beq(CCR0, throw_icce);
goetz@6458 230 }
goetz@6458 231 }
goetz@6458 232 __ ld(R12_scratch2, in_bytes(Method::from_compiled_offset()), R19_method);
goetz@6458 233 __ mtctr(R12_scratch2);
goetz@6458 234 __ bctr();
goetz@6458 235
goetz@6458 236 // Handle IncompatibleClassChangeError in itable stubs.
goetz@6458 237 // More detailed error message.
goetz@6458 238 // We force resolving of the call site by jumping to the "handle
goetz@6458 239 // wrong method" stub, and so let the interpreter runtime do all the
goetz@6458 240 // dirty work.
goetz@6458 241 __ bind(throw_icce);
goetz@6458 242 __ load_const(R11_scratch1, SharedRuntime::get_handle_wrong_method_stub());
goetz@6458 243 __ mtctr(R11_scratch1);
goetz@6458 244 __ bctr();
goetz@6458 245
goetz@6458 246 masm->flush();
goetz@6458 247
goetz@6458 248 guarantee(__ pc() <= s->code_end(), "overflowed buffer");
goetz@6458 249
goetz@6458 250 s->set_exception_points(npe_addr, ame_addr);
goetz@6458 251 return s;
goetz@6458 252 }
goetz@6458 253
goetz@6458 254 int VtableStub::pd_code_size_limit(bool is_vtable_stub) {
goetz@6458 255 if (TraceJumps || DebugVtables || CountCompiledCalls || VerifyOops) {
goetz@6458 256 return 1000;
goetz@6458 257 } else {
goetz@6477 258 int decode_klass_size = MacroAssembler::instr_size_for_decode_klass_not_null();
goetz@6458 259 if (is_vtable_stub) {
goetz@6477 260 return 20 + decode_klass_size + 8 + 8; // Plain + cOops + Traps + safety
goetz@6458 261 } else {
goetz@6477 262 return 96 + decode_klass_size + 12 + 8; // Plain + cOops + Traps + safety
goetz@6458 263 }
goetz@6458 264 }
goetz@6458 265 }
goetz@6458 266
goetz@6458 267 int VtableStub::pd_code_alignment() {
goetz@6458 268 const unsigned int icache_line_size = 32;
goetz@6458 269 return icache_line_size;
goetz@6458 270 }

mercurial