Wed, 15 Apr 2020 11:49:55 +0800
Merge
aoqi@0 | 1 | /* |
mdoerr@9034 | 2 | * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
mdoerr@9034 | 3 | * Copyright 2012, 2017 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" |
mdoerr@9034 | 32 | #include "oops/compiledICHolder.hpp" |
aoqi@0 | 33 | #include "oops/instanceKlass.hpp" |
aoqi@0 | 34 | #include "oops/klassVtable.hpp" |
aoqi@0 | 35 | #include "runtime/sharedRuntime.hpp" |
aoqi@0 | 36 | #include "vmreg_ppc.inline.hpp" |
aoqi@0 | 37 | #ifdef COMPILER2 |
aoqi@0 | 38 | #include "opto/runtime.hpp" |
aoqi@0 | 39 | #endif |
aoqi@0 | 40 | |
aoqi@0 | 41 | #define __ masm-> |
aoqi@0 | 42 | |
aoqi@0 | 43 | #ifdef PRODUCT |
aoqi@0 | 44 | #define BLOCK_COMMENT(str) // nothing |
aoqi@0 | 45 | #else |
aoqi@0 | 46 | #define BLOCK_COMMENT(str) __ block_comment(str) |
aoqi@0 | 47 | #endif |
aoqi@0 | 48 | #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") |
aoqi@0 | 49 | |
aoqi@0 | 50 | #ifndef PRODUCT |
aoqi@0 | 51 | extern "C" void bad_compiled_vtable_index(JavaThread* thread, oopDesc* receiver, int index); |
aoqi@0 | 52 | #endif |
aoqi@0 | 53 | |
aoqi@0 | 54 | // Used by compiler only; may use only caller saved, non-argument |
aoqi@0 | 55 | // registers. |
aoqi@0 | 56 | VtableStub* VtableStubs::create_vtable_stub(int vtable_index) { |
aoqi@0 | 57 | // PPC port: use fixed size. |
aoqi@0 | 58 | const int code_length = VtableStub::pd_code_size_limit(true); |
aoqi@0 | 59 | VtableStub* s = new (code_length) VtableStub(true, vtable_index); |
mdoerr@9034 | 60 | |
mdoerr@9034 | 61 | // Can be NULL if there is no free space in the code cache. |
mdoerr@9034 | 62 | if (s == NULL) { |
mdoerr@9034 | 63 | return NULL; |
mdoerr@9034 | 64 | } |
mdoerr@9034 | 65 | |
aoqi@0 | 66 | ResourceMark rm; |
aoqi@0 | 67 | CodeBuffer cb(s->entry_point(), code_length); |
aoqi@0 | 68 | MacroAssembler* masm = new MacroAssembler(&cb); |
aoqi@0 | 69 | |
aoqi@0 | 70 | #ifndef PRODUCT |
aoqi@0 | 71 | if (CountCompiledCalls) { |
mdoerr@9034 | 72 | int offs = __ load_const_optimized(R11_scratch1, SharedRuntime::nof_megamorphic_calls_addr(), R12_scratch2, true); |
mdoerr@9034 | 73 | __ lwz(R12_scratch2, offs, R11_scratch1); |
aoqi@0 | 74 | __ addi(R12_scratch2, R12_scratch2, 1); |
mdoerr@9034 | 75 | __ stw(R12_scratch2, offs, R11_scratch1); |
aoqi@0 | 76 | } |
aoqi@0 | 77 | #endif |
aoqi@0 | 78 | |
aoqi@0 | 79 | assert(VtableStub::receiver_location() == R3_ARG1->as_VMReg(), "receiver expected in R3_ARG1"); |
aoqi@0 | 80 | |
aoqi@0 | 81 | // Get receiver klass. |
aoqi@0 | 82 | const Register rcvr_klass = R11_scratch1; |
aoqi@0 | 83 | |
aoqi@0 | 84 | // We might implicit NULL fault here. |
aoqi@0 | 85 | address npe_addr = __ pc(); // npe = null pointer exception |
aoqi@0 | 86 | __ load_klass_with_trap_null_check(rcvr_klass, R3); |
aoqi@0 | 87 | |
aoqi@0 | 88 | // Set method (in case of interpreted method), and destination address. |
aoqi@0 | 89 | int entry_offset = InstanceKlass::vtable_start_offset() + vtable_index*vtableEntry::size(); |
aoqi@0 | 90 | |
aoqi@0 | 91 | #ifndef PRODUCT |
aoqi@0 | 92 | if (DebugVtables) { |
aoqi@0 | 93 | Label L; |
aoqi@0 | 94 | // Check offset vs vtable length. |
aoqi@0 | 95 | const Register vtable_len = R12_scratch2; |
aoqi@0 | 96 | __ lwz(vtable_len, InstanceKlass::vtable_length_offset()*wordSize, rcvr_klass); |
aoqi@0 | 97 | __ cmpwi(CCR0, vtable_len, vtable_index*vtableEntry::size()); |
aoqi@0 | 98 | __ bge(CCR0, L); |
aoqi@0 | 99 | __ li(R12_scratch2, vtable_index); |
aoqi@0 | 100 | __ call_VM(noreg, CAST_FROM_FN_PTR(address, bad_compiled_vtable_index), R3_ARG1, R12_scratch2, false); |
aoqi@0 | 101 | __ bind(L); |
aoqi@0 | 102 | } |
aoqi@0 | 103 | #endif |
aoqi@0 | 104 | |
aoqi@0 | 105 | int v_off = entry_offset*wordSize + vtableEntry::method_offset_in_bytes(); |
aoqi@0 | 106 | |
aoqi@0 | 107 | __ ld(R19_method, v_off, rcvr_klass); |
aoqi@0 | 108 | |
aoqi@0 | 109 | #ifndef PRODUCT |
aoqi@0 | 110 | if (DebugVtables) { |
aoqi@0 | 111 | Label L; |
aoqi@0 | 112 | __ cmpdi(CCR0, R19_method, 0); |
aoqi@0 | 113 | __ bne(CCR0, L); |
aoqi@0 | 114 | __ stop("Vtable entry is ZERO", 102); |
aoqi@0 | 115 | __ bind(L); |
aoqi@0 | 116 | } |
aoqi@0 | 117 | #endif |
aoqi@0 | 118 | |
aoqi@0 | 119 | // If the vtable entry is null, the method is abstract. |
aoqi@0 | 120 | address ame_addr = __ pc(); // ame = abstract method error |
aoqi@0 | 121 | |
aoqi@0 | 122 | __ load_with_trap_null_check(R12_scratch2, in_bytes(Method::from_compiled_offset()), R19_method); |
aoqi@0 | 123 | __ mtctr(R12_scratch2); |
aoqi@0 | 124 | __ bctr(); |
mdoerr@9034 | 125 | |
aoqi@0 | 126 | masm->flush(); |
aoqi@0 | 127 | |
aoqi@0 | 128 | guarantee(__ pc() <= s->code_end(), "overflowed buffer"); |
aoqi@0 | 129 | |
aoqi@0 | 130 | s->set_exception_points(npe_addr, ame_addr); |
aoqi@0 | 131 | |
aoqi@0 | 132 | return s; |
aoqi@0 | 133 | } |
aoqi@0 | 134 | |
mdoerr@9034 | 135 | VtableStub* VtableStubs::create_itable_stub(int itable_index) { |
aoqi@0 | 136 | // PPC port: use fixed size. |
aoqi@0 | 137 | const int code_length = VtableStub::pd_code_size_limit(false); |
mdoerr@9034 | 138 | VtableStub* s = new (code_length) VtableStub(false, itable_index); |
mdoerr@9034 | 139 | |
mdoerr@9034 | 140 | // Can be NULL if there is no free space in the code cache. |
mdoerr@9034 | 141 | if (s == NULL) { |
mdoerr@9034 | 142 | return NULL; |
mdoerr@9034 | 143 | } |
mdoerr@9034 | 144 | |
aoqi@0 | 145 | ResourceMark rm; |
aoqi@0 | 146 | CodeBuffer cb(s->entry_point(), code_length); |
aoqi@0 | 147 | MacroAssembler* masm = new MacroAssembler(&cb); |
aoqi@0 | 148 | address start_pc; |
aoqi@0 | 149 | |
aoqi@0 | 150 | #ifndef PRODUCT |
aoqi@0 | 151 | if (CountCompiledCalls) { |
mdoerr@9034 | 152 | int offs = __ load_const_optimized(R11_scratch1, SharedRuntime::nof_megamorphic_calls_addr(), R12_scratch2, true); |
mdoerr@9034 | 153 | __ lwz(R12_scratch2, offs, R11_scratch1); |
aoqi@0 | 154 | __ addi(R12_scratch2, R12_scratch2, 1); |
mdoerr@9034 | 155 | __ stw(R12_scratch2, offs, R11_scratch1); |
aoqi@0 | 156 | } |
aoqi@0 | 157 | #endif |
aoqi@0 | 158 | |
aoqi@0 | 159 | assert(VtableStub::receiver_location() == R3_ARG1->as_VMReg(), "receiver expected in R3_ARG1"); |
aoqi@0 | 160 | |
aoqi@0 | 161 | // Entry arguments: |
aoqi@0 | 162 | // R19_method: Interface |
aoqi@0 | 163 | // R3_ARG1: Receiver |
aoqi@0 | 164 | |
mdoerr@9034 | 165 | Label L_no_such_interface; |
mdoerr@9034 | 166 | const Register rcvr_klass = R11_scratch1, |
mdoerr@9034 | 167 | interface = R12_scratch2, |
mdoerr@9034 | 168 | tmp1 = R21_tmp1, |
mdoerr@9034 | 169 | tmp2 = R22_tmp2; |
aoqi@0 | 170 | |
aoqi@0 | 171 | address npe_addr = __ pc(); // npe = null pointer exception |
aoqi@0 | 172 | __ load_klass_with_trap_null_check(rcvr_klass, R3_ARG1); |
aoqi@0 | 173 | |
mdoerr@9034 | 174 | // Receiver subtype check against REFC. |
mdoerr@9034 | 175 | __ ld(interface, CompiledICHolder::holder_klass_offset(), R19_method); |
mdoerr@9034 | 176 | __ lookup_interface_method(rcvr_klass, interface, noreg, |
mdoerr@9034 | 177 | R0, tmp1, tmp2, |
mdoerr@9034 | 178 | L_no_such_interface, /*return_method=*/ false); |
aoqi@0 | 179 | |
mdoerr@9034 | 180 | // Get Method* and entrypoint for compiler |
mdoerr@9034 | 181 | __ ld(interface, CompiledICHolder::holder_metadata_offset(), R19_method); |
mdoerr@9034 | 182 | __ lookup_interface_method(rcvr_klass, interface, itable_index, |
mdoerr@9034 | 183 | R19_method, tmp1, tmp2, |
mdoerr@9034 | 184 | L_no_such_interface, /*return_method=*/ true); |
aoqi@0 | 185 | |
aoqi@0 | 186 | #ifndef PRODUCT |
aoqi@0 | 187 | if (DebugVtables) { |
aoqi@0 | 188 | Label ok; |
aoqi@0 | 189 | __ cmpd(CCR0, R19_method, 0); |
aoqi@0 | 190 | __ bne(CCR0, ok); |
aoqi@0 | 191 | __ stop("method is null", 103); |
aoqi@0 | 192 | __ bind(ok); |
aoqi@0 | 193 | } |
aoqi@0 | 194 | #endif |
aoqi@0 | 195 | |
aoqi@0 | 196 | // If the vtable entry is null, the method is abstract. |
aoqi@0 | 197 | address ame_addr = __ pc(); // ame = abstract method error |
aoqi@0 | 198 | |
aoqi@0 | 199 | // Must do an explicit check if implicit checks are disabled. |
aoqi@0 | 200 | assert(!MacroAssembler::needs_explicit_null_check(in_bytes(Method::from_compiled_offset())), "sanity"); |
aoqi@0 | 201 | if (!ImplicitNullChecks || !os::zero_page_read_protected()) { |
aoqi@0 | 202 | if (TrapBasedNullChecks) { |
aoqi@0 | 203 | __ trap_null_check(R19_method); |
aoqi@0 | 204 | } else { |
aoqi@0 | 205 | __ cmpdi(CCR0, R19_method, 0); |
mdoerr@9034 | 206 | __ beq(CCR0, L_no_such_interface); |
aoqi@0 | 207 | } |
aoqi@0 | 208 | } |
aoqi@0 | 209 | __ ld(R12_scratch2, in_bytes(Method::from_compiled_offset()), R19_method); |
aoqi@0 | 210 | __ mtctr(R12_scratch2); |
aoqi@0 | 211 | __ bctr(); |
aoqi@0 | 212 | |
aoqi@0 | 213 | // Handle IncompatibleClassChangeError in itable stubs. |
aoqi@0 | 214 | // More detailed error message. |
aoqi@0 | 215 | // We force resolving of the call site by jumping to the "handle |
aoqi@0 | 216 | // wrong method" stub, and so let the interpreter runtime do all the |
aoqi@0 | 217 | // dirty work. |
mdoerr@9034 | 218 | __ bind(L_no_such_interface); |
mdoerr@9034 | 219 | __ load_const_optimized(R11_scratch1, SharedRuntime::get_handle_wrong_method_stub(), R12_scratch2); |
aoqi@0 | 220 | __ mtctr(R11_scratch1); |
aoqi@0 | 221 | __ bctr(); |
aoqi@0 | 222 | |
aoqi@0 | 223 | masm->flush(); |
aoqi@0 | 224 | |
aoqi@0 | 225 | guarantee(__ pc() <= s->code_end(), "overflowed buffer"); |
aoqi@0 | 226 | |
aoqi@0 | 227 | s->set_exception_points(npe_addr, ame_addr); |
aoqi@0 | 228 | return s; |
aoqi@0 | 229 | } |
aoqi@0 | 230 | |
aoqi@0 | 231 | int VtableStub::pd_code_size_limit(bool is_vtable_stub) { |
aoqi@0 | 232 | if (TraceJumps || DebugVtables || CountCompiledCalls || VerifyOops) { |
aoqi@0 | 233 | return 1000; |
aoqi@0 | 234 | } |
mdoerr@9034 | 235 | int size = is_vtable_stub ? 20 + 8 : 164 + 20; // Plain + safety |
mdoerr@9034 | 236 | if (UseCompressedClassPointers) { |
mdoerr@9034 | 237 | size += MacroAssembler::instr_size_for_decode_klass_not_null(); |
mdoerr@9034 | 238 | } |
mdoerr@9034 | 239 | if (!ImplicitNullChecks || !os::zero_page_read_protected()) { |
mdoerr@9034 | 240 | size += is_vtable_stub ? 8 : 12; |
mdoerr@9034 | 241 | } |
mdoerr@9034 | 242 | return size; |
aoqi@0 | 243 | } |
aoqi@0 | 244 | |
aoqi@0 | 245 | int VtableStub::pd_code_alignment() { |
aoqi@0 | 246 | const unsigned int icache_line_size = 32; |
aoqi@0 | 247 | return icache_line_size; |
aoqi@0 | 248 | } |