src/cpu/ppc/vm/vtableStubs_ppc_64.cpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 6876
710a3c8b516e
child 9041
95a08233f46c
permissions
-rw-r--r--

merge

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

mercurial