1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/ppc/vm/sharedRuntime_ppc.cpp Fri Aug 02 16:46:45 2013 +0200 1.3 @@ -0,0 +1,3209 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2012, 2013 SAP AG. All rights reserved. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#include "precompiled.hpp" 1.30 +#include "asm/macroAssembler.inline.hpp" 1.31 +#include "code/debugInfoRec.hpp" 1.32 +#include "code/icBuffer.hpp" 1.33 +#include "code/vtableStubs.hpp" 1.34 +#include "interpreter/interpreter.hpp" 1.35 +#include "oops/compiledICHolder.hpp" 1.36 +#include "prims/jvmtiRedefineClassesTrace.hpp" 1.37 +#include "runtime/sharedRuntime.hpp" 1.38 +#include "runtime/vframeArray.hpp" 1.39 +#include "vmreg_ppc.inline.hpp" 1.40 +#ifdef COMPILER1 1.41 +#include "c1/c1_Runtime1.hpp" 1.42 +#endif 1.43 +#ifdef COMPILER2 1.44 +#include "opto/runtime.hpp" 1.45 +#endif 1.46 + 1.47 +#define __ masm-> 1.48 + 1.49 +#ifdef PRODUCT 1.50 +#define BLOCK_COMMENT(str) // nothing 1.51 +#else 1.52 +#define BLOCK_COMMENT(str) __ block_comment(str) 1.53 +#endif 1.54 + 1.55 +#define BIND(label) bind(label); BLOCK_COMMENT(#label ":") 1.56 + 1.57 + 1.58 +// Used by generate_deopt_blob. Defined in .ad file. 1.59 +extern uint size_deopt_handler(); 1.60 + 1.61 + 1.62 +class RegisterSaver { 1.63 + // Used for saving volatile registers. 1.64 + public: 1.65 + 1.66 + // Support different return pc locations. 1.67 + enum ReturnPCLocation { 1.68 + return_pc_is_lr, 1.69 + return_pc_is_r4, 1.70 + return_pc_is_thread_saved_exception_pc 1.71 + }; 1.72 + 1.73 + static OopMap* push_frame_abi112_and_save_live_registers(MacroAssembler* masm, 1.74 + int* out_frame_size_in_bytes, 1.75 + bool generate_oop_map, 1.76 + int return_pc_adjustment, 1.77 + ReturnPCLocation return_pc_location); 1.78 + static void restore_live_registers_and_pop_frame(MacroAssembler* masm, 1.79 + int frame_size_in_bytes, 1.80 + bool restore_ctr); 1.81 + 1.82 + static void push_frame_and_save_argument_registers(MacroAssembler* masm, 1.83 + Register r_temp, 1.84 + int frame_size, 1.85 + int total_args, 1.86 + const VMRegPair *regs, const VMRegPair *regs2 = NULL); 1.87 + static void restore_argument_registers_and_pop_frame(MacroAssembler*masm, 1.88 + int frame_size, 1.89 + int total_args, 1.90 + const VMRegPair *regs, const VMRegPair *regs2 = NULL); 1.91 + 1.92 + // During deoptimization only the result registers need to be restored 1.93 + // all the other values have already been extracted. 1.94 + static void restore_result_registers(MacroAssembler* masm, int frame_size_in_bytes); 1.95 + 1.96 + // Constants and data structures: 1.97 + 1.98 + typedef enum { 1.99 + int_reg = 0, 1.100 + float_reg = 1, 1.101 + special_reg = 2 1.102 + } RegisterType; 1.103 + 1.104 + typedef enum { 1.105 + reg_size = 8, 1.106 + half_reg_size = reg_size / 2, 1.107 + } RegisterConstants; 1.108 + 1.109 + typedef struct { 1.110 + RegisterType reg_type; 1.111 + int reg_num; 1.112 + VMReg vmreg; 1.113 + } LiveRegType; 1.114 +}; 1.115 + 1.116 + 1.117 +#define RegisterSaver_LiveSpecialReg(regname) \ 1.118 + { RegisterSaver::special_reg, regname->encoding(), regname->as_VMReg() } 1.119 + 1.120 +#define RegisterSaver_LiveIntReg(regname) \ 1.121 + { RegisterSaver::int_reg, regname->encoding(), regname->as_VMReg() } 1.122 + 1.123 +#define RegisterSaver_LiveFloatReg(regname) \ 1.124 + { RegisterSaver::float_reg, regname->encoding(), regname->as_VMReg() } 1.125 + 1.126 +static const RegisterSaver::LiveRegType RegisterSaver_LiveRegs[] = { 1.127 + // Live registers which get spilled to the stack. Register 1.128 + // positions in this array correspond directly to the stack layout. 1.129 + 1.130 + // 1.131 + // live special registers: 1.132 + // 1.133 + RegisterSaver_LiveSpecialReg(SR_CTR), 1.134 + // 1.135 + // live float registers: 1.136 + // 1.137 + RegisterSaver_LiveFloatReg( F0 ), 1.138 + RegisterSaver_LiveFloatReg( F1 ), 1.139 + RegisterSaver_LiveFloatReg( F2 ), 1.140 + RegisterSaver_LiveFloatReg( F3 ), 1.141 + RegisterSaver_LiveFloatReg( F4 ), 1.142 + RegisterSaver_LiveFloatReg( F5 ), 1.143 + RegisterSaver_LiveFloatReg( F6 ), 1.144 + RegisterSaver_LiveFloatReg( F7 ), 1.145 + RegisterSaver_LiveFloatReg( F8 ), 1.146 + RegisterSaver_LiveFloatReg( F9 ), 1.147 + RegisterSaver_LiveFloatReg( F10 ), 1.148 + RegisterSaver_LiveFloatReg( F11 ), 1.149 + RegisterSaver_LiveFloatReg( F12 ), 1.150 + RegisterSaver_LiveFloatReg( F13 ), 1.151 + RegisterSaver_LiveFloatReg( F14 ), 1.152 + RegisterSaver_LiveFloatReg( F15 ), 1.153 + RegisterSaver_LiveFloatReg( F16 ), 1.154 + RegisterSaver_LiveFloatReg( F17 ), 1.155 + RegisterSaver_LiveFloatReg( F18 ), 1.156 + RegisterSaver_LiveFloatReg( F19 ), 1.157 + RegisterSaver_LiveFloatReg( F20 ), 1.158 + RegisterSaver_LiveFloatReg( F21 ), 1.159 + RegisterSaver_LiveFloatReg( F22 ), 1.160 + RegisterSaver_LiveFloatReg( F23 ), 1.161 + RegisterSaver_LiveFloatReg( F24 ), 1.162 + RegisterSaver_LiveFloatReg( F25 ), 1.163 + RegisterSaver_LiveFloatReg( F26 ), 1.164 + RegisterSaver_LiveFloatReg( F27 ), 1.165 + RegisterSaver_LiveFloatReg( F28 ), 1.166 + RegisterSaver_LiveFloatReg( F29 ), 1.167 + RegisterSaver_LiveFloatReg( F30 ), 1.168 + RegisterSaver_LiveFloatReg( F31 ), 1.169 + // 1.170 + // live integer registers: 1.171 + // 1.172 + RegisterSaver_LiveIntReg( R0 ), 1.173 + //RegisterSaver_LiveIntReg( R1 ), // stack pointer 1.174 + RegisterSaver_LiveIntReg( R2 ), 1.175 + RegisterSaver_LiveIntReg( R3 ), 1.176 + RegisterSaver_LiveIntReg( R4 ), 1.177 + RegisterSaver_LiveIntReg( R5 ), 1.178 + RegisterSaver_LiveIntReg( R6 ), 1.179 + RegisterSaver_LiveIntReg( R7 ), 1.180 + RegisterSaver_LiveIntReg( R8 ), 1.181 + RegisterSaver_LiveIntReg( R9 ), 1.182 + RegisterSaver_LiveIntReg( R10 ), 1.183 + RegisterSaver_LiveIntReg( R11 ), 1.184 + RegisterSaver_LiveIntReg( R12 ), 1.185 + //RegisterSaver_LiveIntReg( R13 ), // system thread id 1.186 + RegisterSaver_LiveIntReg( R14 ), 1.187 + RegisterSaver_LiveIntReg( R15 ), 1.188 + RegisterSaver_LiveIntReg( R16 ), 1.189 + RegisterSaver_LiveIntReg( R17 ), 1.190 + RegisterSaver_LiveIntReg( R18 ), 1.191 + RegisterSaver_LiveIntReg( R19 ), 1.192 + RegisterSaver_LiveIntReg( R20 ), 1.193 + RegisterSaver_LiveIntReg( R21 ), 1.194 + RegisterSaver_LiveIntReg( R22 ), 1.195 + RegisterSaver_LiveIntReg( R23 ), 1.196 + RegisterSaver_LiveIntReg( R24 ), 1.197 + RegisterSaver_LiveIntReg( R25 ), 1.198 + RegisterSaver_LiveIntReg( R26 ), 1.199 + RegisterSaver_LiveIntReg( R27 ), 1.200 + RegisterSaver_LiveIntReg( R28 ), 1.201 + RegisterSaver_LiveIntReg( R29 ), 1.202 + RegisterSaver_LiveIntReg( R31 ), 1.203 + RegisterSaver_LiveIntReg( R30 ), // r30 must be the last register 1.204 +}; 1.205 + 1.206 +OopMap* RegisterSaver::push_frame_abi112_and_save_live_registers(MacroAssembler* masm, 1.207 + int* out_frame_size_in_bytes, 1.208 + bool generate_oop_map, 1.209 + int return_pc_adjustment, 1.210 + ReturnPCLocation return_pc_location) { 1.211 + // Push an abi112-frame and store all registers which may be live. 1.212 + // If requested, create an OopMap: Record volatile registers as 1.213 + // callee-save values in an OopMap so their save locations will be 1.214 + // propagated to the RegisterMap of the caller frame during 1.215 + // StackFrameStream construction (needed for deoptimization; see 1.216 + // compiledVFrame::create_stack_value). 1.217 + // If return_pc_adjustment != 0 adjust the return pc by return_pc_adjustment. 1.218 + 1.219 + int i; 1.220 + int offset; 1.221 + 1.222 + // calcualte frame size 1.223 + const int regstosave_num = sizeof(RegisterSaver_LiveRegs) / 1.224 + sizeof(RegisterSaver::LiveRegType); 1.225 + const int register_save_size = regstosave_num * reg_size; 1.226 + const int frame_size_in_bytes = round_to(register_save_size, frame::alignment_in_bytes) 1.227 + + frame::abi_112_size; 1.228 + *out_frame_size_in_bytes = frame_size_in_bytes; 1.229 + const int frame_size_in_slots = frame_size_in_bytes / sizeof(jint); 1.230 + const int register_save_offset = frame_size_in_bytes - register_save_size; 1.231 + 1.232 + // OopMap frame size is in c2 stack slots (sizeof(jint)) not bytes or words. 1.233 + OopMap* map = generate_oop_map ? new OopMap(frame_size_in_slots, 0) : NULL; 1.234 + 1.235 + BLOCK_COMMENT("push_frame_abi112_and_save_live_registers {"); 1.236 + 1.237 + // Save r30 in the last slot of the not yet pushed frame so that we 1.238 + // can use it as scratch reg. 1.239 + __ std(R30, -reg_size, R1_SP); 1.240 + assert(-reg_size == register_save_offset - frame_size_in_bytes + ((regstosave_num-1)*reg_size), 1.241 + "consistency check"); 1.242 + 1.243 + // save the flags 1.244 + // Do the save_LR_CR by hand and adjust the return pc if requested. 1.245 + __ mfcr(R30); 1.246 + __ std(R30, _abi(cr), R1_SP); 1.247 + switch (return_pc_location) { 1.248 + case return_pc_is_lr: __ mflr(R30); break; 1.249 + case return_pc_is_r4: __ mr(R30, R4); break; 1.250 + case return_pc_is_thread_saved_exception_pc: 1.251 + __ ld(R30, thread_(saved_exception_pc)); break; 1.252 + default: ShouldNotReachHere(); 1.253 + } 1.254 + if (return_pc_adjustment != 0) 1.255 + __ addi(R30, R30, return_pc_adjustment); 1.256 + __ std(R30, _abi(lr), R1_SP); 1.257 + 1.258 + // push a new frame 1.259 + __ push_frame(frame_size_in_bytes, R30); 1.260 + 1.261 + // save all registers (ints and floats) 1.262 + offset = register_save_offset; 1.263 + for (int i = 0; i < regstosave_num; i++) { 1.264 + int reg_num = RegisterSaver_LiveRegs[i].reg_num; 1.265 + int reg_type = RegisterSaver_LiveRegs[i].reg_type; 1.266 + 1.267 + switch (reg_type) { 1.268 + case RegisterSaver::int_reg: { 1.269 + if (reg_num != 30) { // We spilled R30 right at the beginning. 1.270 + __ std(as_Register(reg_num), offset, R1_SP); 1.271 + } 1.272 + break; 1.273 + } 1.274 + case RegisterSaver::float_reg: { 1.275 + __ stfd(as_FloatRegister(reg_num), offset, R1_SP); 1.276 + break; 1.277 + } 1.278 + case RegisterSaver::special_reg: { 1.279 + if (reg_num == SR_CTR_SpecialRegisterEnumValue) { 1.280 + __ mfctr(R30); 1.281 + __ std(R30, offset, R1_SP); 1.282 + } else { 1.283 + Unimplemented(); 1.284 + } 1.285 + break; 1.286 + } 1.287 + default: 1.288 + ShouldNotReachHere(); 1.289 + } 1.290 + 1.291 + if (generate_oop_map) { 1.292 + map->set_callee_saved(VMRegImpl::stack2reg(offset>>2), 1.293 + RegisterSaver_LiveRegs[i].vmreg); 1.294 + map->set_callee_saved(VMRegImpl::stack2reg((offset + half_reg_size)>>2), 1.295 + RegisterSaver_LiveRegs[i].vmreg->next()); 1.296 + } 1.297 + offset += reg_size; 1.298 + } 1.299 + 1.300 + BLOCK_COMMENT("} push_frame_abi112_and_save_live_registers"); 1.301 + 1.302 + // And we're done. 1.303 + return map; 1.304 +} 1.305 + 1.306 + 1.307 +// Pop the current frame and restore all the registers that we 1.308 +// saved. 1.309 +void RegisterSaver::restore_live_registers_and_pop_frame(MacroAssembler* masm, 1.310 + int frame_size_in_bytes, 1.311 + bool restore_ctr) { 1.312 + int i; 1.313 + int offset; 1.314 + const int regstosave_num = sizeof(RegisterSaver_LiveRegs) / 1.315 + sizeof(RegisterSaver::LiveRegType); 1.316 + const int register_save_size = regstosave_num * reg_size; 1.317 + const int register_save_offset = frame_size_in_bytes - register_save_size; 1.318 + 1.319 + BLOCK_COMMENT("restore_live_registers_and_pop_frame {"); 1.320 + 1.321 + // restore all registers (ints and floats) 1.322 + offset = register_save_offset; 1.323 + for (int i = 0; i < regstosave_num; i++) { 1.324 + int reg_num = RegisterSaver_LiveRegs[i].reg_num; 1.325 + int reg_type = RegisterSaver_LiveRegs[i].reg_type; 1.326 + 1.327 + switch (reg_type) { 1.328 + case RegisterSaver::int_reg: { 1.329 + if (reg_num != 30) // R30 restored at the end, it's the tmp reg! 1.330 + __ ld(as_Register(reg_num), offset, R1_SP); 1.331 + break; 1.332 + } 1.333 + case RegisterSaver::float_reg: { 1.334 + __ lfd(as_FloatRegister(reg_num), offset, R1_SP); 1.335 + break; 1.336 + } 1.337 + case RegisterSaver::special_reg: { 1.338 + if (reg_num == SR_CTR_SpecialRegisterEnumValue) { 1.339 + if (restore_ctr) { // Nothing to do here if ctr already contains the next address. 1.340 + __ ld(R30, offset, R1_SP); 1.341 + __ mtctr(R30); 1.342 + } 1.343 + } else { 1.344 + Unimplemented(); 1.345 + } 1.346 + break; 1.347 + } 1.348 + default: 1.349 + ShouldNotReachHere(); 1.350 + } 1.351 + offset += reg_size; 1.352 + } 1.353 + 1.354 + // pop the frame 1.355 + __ pop_frame(); 1.356 + 1.357 + // restore the flags 1.358 + __ restore_LR_CR(R30); 1.359 + 1.360 + // restore scratch register's value 1.361 + __ ld(R30, -reg_size, R1_SP); 1.362 + 1.363 + BLOCK_COMMENT("} restore_live_registers_and_pop_frame"); 1.364 +} 1.365 + 1.366 +void RegisterSaver::push_frame_and_save_argument_registers(MacroAssembler* masm, Register r_temp, 1.367 + int frame_size,int total_args, const VMRegPair *regs, 1.368 + const VMRegPair *regs2) { 1.369 + __ push_frame(frame_size, r_temp); 1.370 + int st_off = frame_size - wordSize; 1.371 + for (int i = 0; i < total_args; i++) { 1.372 + VMReg r_1 = regs[i].first(); 1.373 + VMReg r_2 = regs[i].second(); 1.374 + if (!r_1->is_valid()) { 1.375 + assert(!r_2->is_valid(), ""); 1.376 + continue; 1.377 + } 1.378 + if (r_1->is_Register()) { 1.379 + Register r = r_1->as_Register(); 1.380 + __ std(r, st_off, R1_SP); 1.381 + st_off -= wordSize; 1.382 + } else if (r_1->is_FloatRegister()) { 1.383 + FloatRegister f = r_1->as_FloatRegister(); 1.384 + __ stfd(f, st_off, R1_SP); 1.385 + st_off -= wordSize; 1.386 + } 1.387 + } 1.388 + if (regs2 != NULL) { 1.389 + for (int i = 0; i < total_args; i++) { 1.390 + VMReg r_1 = regs2[i].first(); 1.391 + VMReg r_2 = regs2[i].second(); 1.392 + if (!r_1->is_valid()) { 1.393 + assert(!r_2->is_valid(), ""); 1.394 + continue; 1.395 + } 1.396 + if (r_1->is_Register()) { 1.397 + Register r = r_1->as_Register(); 1.398 + __ std(r, st_off, R1_SP); 1.399 + st_off -= wordSize; 1.400 + } else if (r_1->is_FloatRegister()) { 1.401 + FloatRegister f = r_1->as_FloatRegister(); 1.402 + __ stfd(f, st_off, R1_SP); 1.403 + st_off -= wordSize; 1.404 + } 1.405 + } 1.406 + } 1.407 +} 1.408 + 1.409 +void RegisterSaver::restore_argument_registers_and_pop_frame(MacroAssembler*masm, int frame_size, 1.410 + int total_args, const VMRegPair *regs, 1.411 + const VMRegPair *regs2) { 1.412 + int st_off = frame_size - wordSize; 1.413 + for (int i = 0; i < total_args; i++) { 1.414 + VMReg r_1 = regs[i].first(); 1.415 + VMReg r_2 = regs[i].second(); 1.416 + if (r_1->is_Register()) { 1.417 + Register r = r_1->as_Register(); 1.418 + __ ld(r, st_off, R1_SP); 1.419 + st_off -= wordSize; 1.420 + } else if (r_1->is_FloatRegister()) { 1.421 + FloatRegister f = r_1->as_FloatRegister(); 1.422 + __ lfd(f, st_off, R1_SP); 1.423 + st_off -= wordSize; 1.424 + } 1.425 + } 1.426 + if (regs2 != NULL) 1.427 + for (int i = 0; i < total_args; i++) { 1.428 + VMReg r_1 = regs2[i].first(); 1.429 + VMReg r_2 = regs2[i].second(); 1.430 + if (r_1->is_Register()) { 1.431 + Register r = r_1->as_Register(); 1.432 + __ ld(r, st_off, R1_SP); 1.433 + st_off -= wordSize; 1.434 + } else if (r_1->is_FloatRegister()) { 1.435 + FloatRegister f = r_1->as_FloatRegister(); 1.436 + __ lfd(f, st_off, R1_SP); 1.437 + st_off -= wordSize; 1.438 + } 1.439 + } 1.440 + __ pop_frame(); 1.441 +} 1.442 + 1.443 +// Restore the registers that might be holding a result. 1.444 +void RegisterSaver::restore_result_registers(MacroAssembler* masm, int frame_size_in_bytes) { 1.445 + int i; 1.446 + int offset; 1.447 + const int regstosave_num = sizeof(RegisterSaver_LiveRegs) / 1.448 + sizeof(RegisterSaver::LiveRegType); 1.449 + const int register_save_size = regstosave_num * reg_size; 1.450 + const int register_save_offset = frame_size_in_bytes - register_save_size; 1.451 + 1.452 + // restore all result registers (ints and floats) 1.453 + offset = register_save_offset; 1.454 + for (int i = 0; i < regstosave_num; i++) { 1.455 + int reg_num = RegisterSaver_LiveRegs[i].reg_num; 1.456 + int reg_type = RegisterSaver_LiveRegs[i].reg_type; 1.457 + switch (reg_type) { 1.458 + case RegisterSaver::int_reg: { 1.459 + if (as_Register(reg_num)==R3_RET) // int result_reg 1.460 + __ ld(as_Register(reg_num), offset, R1_SP); 1.461 + break; 1.462 + } 1.463 + case RegisterSaver::float_reg: { 1.464 + if (as_FloatRegister(reg_num)==F1_RET) // float result_reg 1.465 + __ lfd(as_FloatRegister(reg_num), offset, R1_SP); 1.466 + break; 1.467 + } 1.468 + case RegisterSaver::special_reg: { 1.469 + // Special registers don't hold a result. 1.470 + break; 1.471 + } 1.472 + default: 1.473 + ShouldNotReachHere(); 1.474 + } 1.475 + offset += reg_size; 1.476 + } 1.477 +} 1.478 + 1.479 +// Is vector's size (in bytes) bigger than a size saved by default? 1.480 +bool SharedRuntime::is_wide_vector(int size) { 1.481 + ResourceMark rm; 1.482 + // Note, MaxVectorSize == 8 on PPC64. 1.483 + assert(size <= 8, err_msg_res("%d bytes vectors are not supported", size)); 1.484 + return size > 8; 1.485 +} 1.486 +#ifdef COMPILER2 1.487 +static int reg2slot(VMReg r) { 1.488 + return r->reg2stack() + SharedRuntime::out_preserve_stack_slots(); 1.489 +} 1.490 + 1.491 +static int reg2offset(VMReg r) { 1.492 + return (r->reg2stack() + SharedRuntime::out_preserve_stack_slots()) * VMRegImpl::stack_slot_size; 1.493 +} 1.494 +#endif 1.495 + 1.496 +// --------------------------------------------------------------------------- 1.497 +// Read the array of BasicTypes from a signature, and compute where the 1.498 +// arguments should go. Values in the VMRegPair regs array refer to 4-byte 1.499 +// quantities. Values less than VMRegImpl::stack0 are registers, those above 1.500 +// refer to 4-byte stack slots. All stack slots are based off of the stack pointer 1.501 +// as framesizes are fixed. 1.502 +// VMRegImpl::stack0 refers to the first slot 0(sp). 1.503 +// and VMRegImpl::stack0+1 refers to the memory word 4-bytes higher. Register 1.504 +// up to RegisterImpl::number_of_registers) are the 64-bit 1.505 +// integer registers. 1.506 + 1.507 +// Note: the INPUTS in sig_bt are in units of Java argument words, which are 1.508 +// either 32-bit or 64-bit depending on the build. The OUTPUTS are in 32-bit 1.509 +// units regardless of build. Of course for i486 there is no 64 bit build 1.510 + 1.511 +// The Java calling convention is a "shifted" version of the C ABI. 1.512 +// By skipping the first C ABI register we can call non-static jni methods 1.513 +// with small numbers of arguments without having to shuffle the arguments 1.514 +// at all. Since we control the java ABI we ought to at least get some 1.515 +// advantage out of it. 1.516 + 1.517 +const VMReg java_iarg_reg[8] = { 1.518 + R3->as_VMReg(), 1.519 + R4->as_VMReg(), 1.520 + R5->as_VMReg(), 1.521 + R6->as_VMReg(), 1.522 + R7->as_VMReg(), 1.523 + R8->as_VMReg(), 1.524 + R9->as_VMReg(), 1.525 + R10->as_VMReg() 1.526 +}; 1.527 + 1.528 +const VMReg java_farg_reg[13] = { 1.529 + F1->as_VMReg(), 1.530 + F2->as_VMReg(), 1.531 + F3->as_VMReg(), 1.532 + F4->as_VMReg(), 1.533 + F5->as_VMReg(), 1.534 + F6->as_VMReg(), 1.535 + F7->as_VMReg(), 1.536 + F8->as_VMReg(), 1.537 + F9->as_VMReg(), 1.538 + F10->as_VMReg(), 1.539 + F11->as_VMReg(), 1.540 + F12->as_VMReg(), 1.541 + F13->as_VMReg() 1.542 +}; 1.543 + 1.544 +const int num_java_iarg_registers = sizeof(java_iarg_reg) / sizeof(java_iarg_reg[0]); 1.545 +const int num_java_farg_registers = sizeof(java_farg_reg) / sizeof(java_farg_reg[0]); 1.546 + 1.547 +int SharedRuntime::java_calling_convention(const BasicType *sig_bt, 1.548 + VMRegPair *regs, 1.549 + int total_args_passed, 1.550 + int is_outgoing) { 1.551 + // C2c calling conventions for compiled-compiled calls. 1.552 + // Put 8 ints/longs into registers _AND_ 13 float/doubles into 1.553 + // registers _AND_ put the rest on the stack. 1.554 + 1.555 + const int inc_stk_for_intfloat = 1; // 1 slots for ints and floats 1.556 + const int inc_stk_for_longdouble = 2; // 2 slots for longs and doubles 1.557 + 1.558 + int i; 1.559 + VMReg reg; 1.560 + int stk = 0; 1.561 + int ireg = 0; 1.562 + int freg = 0; 1.563 + 1.564 + // We put the first 8 arguments into registers and the rest on the 1.565 + // stack, float arguments are already in their argument registers 1.566 + // due to c2c calling conventions (see calling_convention). 1.567 + for (int i = 0; i < total_args_passed; ++i) { 1.568 + switch(sig_bt[i]) { 1.569 + case T_BOOLEAN: 1.570 + case T_CHAR: 1.571 + case T_BYTE: 1.572 + case T_SHORT: 1.573 + case T_INT: 1.574 + if (ireg < num_java_iarg_registers) { 1.575 + // Put int/ptr in register 1.576 + reg = java_iarg_reg[ireg]; 1.577 + ++ireg; 1.578 + } else { 1.579 + // Put int/ptr on stack. 1.580 + reg = VMRegImpl::stack2reg(stk); 1.581 + stk += inc_stk_for_intfloat; 1.582 + } 1.583 + regs[i].set1(reg); 1.584 + break; 1.585 + case T_LONG: 1.586 + assert(sig_bt[i+1] == T_VOID, "expecting half"); 1.587 + if (ireg < num_java_iarg_registers) { 1.588 + // Put long in register. 1.589 + reg = java_iarg_reg[ireg]; 1.590 + ++ireg; 1.591 + } else { 1.592 + // Put long on stack. They must be aligned to 2 slots. 1.593 + if (stk & 0x1) ++stk; 1.594 + reg = VMRegImpl::stack2reg(stk); 1.595 + stk += inc_stk_for_longdouble; 1.596 + } 1.597 + regs[i].set2(reg); 1.598 + break; 1.599 + case T_OBJECT: 1.600 + case T_ARRAY: 1.601 + case T_ADDRESS: 1.602 + if (ireg < num_java_iarg_registers) { 1.603 + // Put ptr in register. 1.604 + reg = java_iarg_reg[ireg]; 1.605 + ++ireg; 1.606 + } else { 1.607 + // Put ptr on stack. Objects must be aligned to 2 slots too, 1.608 + // because "64-bit pointers record oop-ishness on 2 aligned 1.609 + // adjacent registers." (see OopFlow::build_oop_map). 1.610 + if (stk & 0x1) ++stk; 1.611 + reg = VMRegImpl::stack2reg(stk); 1.612 + stk += inc_stk_for_longdouble; 1.613 + } 1.614 + regs[i].set2(reg); 1.615 + break; 1.616 + case T_FLOAT: 1.617 + if (freg < num_java_farg_registers) { 1.618 + // Put float in register. 1.619 + reg = java_farg_reg[freg]; 1.620 + ++freg; 1.621 + } else { 1.622 + // Put float on stack. 1.623 + reg = VMRegImpl::stack2reg(stk); 1.624 + stk += inc_stk_for_intfloat; 1.625 + } 1.626 + regs[i].set1(reg); 1.627 + break; 1.628 + case T_DOUBLE: 1.629 + assert(sig_bt[i+1] == T_VOID, "expecting half"); 1.630 + if (freg < num_java_farg_registers) { 1.631 + // Put double in register. 1.632 + reg = java_farg_reg[freg]; 1.633 + ++freg; 1.634 + } else { 1.635 + // Put double on stack. They must be aligned to 2 slots. 1.636 + if (stk & 0x1) ++stk; 1.637 + reg = VMRegImpl::stack2reg(stk); 1.638 + stk += inc_stk_for_longdouble; 1.639 + } 1.640 + regs[i].set2(reg); 1.641 + break; 1.642 + case T_VOID: 1.643 + // Do not count halves. 1.644 + regs[i].set_bad(); 1.645 + break; 1.646 + default: 1.647 + ShouldNotReachHere(); 1.648 + } 1.649 + } 1.650 + return round_to(stk, 2); 1.651 +} 1.652 + 1.653 +#ifdef COMPILER2 1.654 +// Calling convention for calling C code. 1.655 +int SharedRuntime::c_calling_convention(const BasicType *sig_bt, 1.656 + VMRegPair *regs, 1.657 + VMRegPair *regs2, 1.658 + int total_args_passed) { 1.659 + // Calling conventions for C runtime calls and calls to JNI native methods. 1.660 + // 1.661 + // PPC64 convention: Hoist the first 8 int/ptr/long's in the first 8 1.662 + // int regs, leaving int regs undefined if the arg is flt/dbl. Hoist 1.663 + // the first 13 flt/dbl's in the first 13 fp regs but additionally 1.664 + // copy flt/dbl to the stack if they are beyond the 8th argument. 1.665 + 1.666 + const VMReg iarg_reg[8] = { 1.667 + R3->as_VMReg(), 1.668 + R4->as_VMReg(), 1.669 + R5->as_VMReg(), 1.670 + R6->as_VMReg(), 1.671 + R7->as_VMReg(), 1.672 + R8->as_VMReg(), 1.673 + R9->as_VMReg(), 1.674 + R10->as_VMReg() 1.675 + }; 1.676 + 1.677 + const VMReg farg_reg[13] = { 1.678 + F1->as_VMReg(), 1.679 + F2->as_VMReg(), 1.680 + F3->as_VMReg(), 1.681 + F4->as_VMReg(), 1.682 + F5->as_VMReg(), 1.683 + F6->as_VMReg(), 1.684 + F7->as_VMReg(), 1.685 + F8->as_VMReg(), 1.686 + F9->as_VMReg(), 1.687 + F10->as_VMReg(), 1.688 + F11->as_VMReg(), 1.689 + F12->as_VMReg(), 1.690 + F13->as_VMReg() 1.691 + }; 1.692 + 1.693 + const int num_iarg_registers = sizeof(iarg_reg) / sizeof(iarg_reg[0]); 1.694 + const int num_farg_registers = sizeof(farg_reg) / sizeof(farg_reg[0]); 1.695 + 1.696 + // The first 8 arguments are not passed on the stack. 1.697 + const int num_args_in_regs = 8; 1.698 +#define put_arg_in_reg(arg) ((arg) < num_args_in_regs) 1.699 + 1.700 + // Check calling conventions consistency. 1.701 + assert(num_iarg_registers == num_args_in_regs 1.702 + && num_iarg_registers == 8 1.703 + && num_farg_registers == 13, 1.704 + "consistency"); 1.705 + 1.706 + // `Stk' counts stack slots. Due to alignment, 32 bit values occupy 1.707 + // 2 such slots, like 64 bit values do. 1.708 + const int inc_stk_for_intfloat = 2; // 2 slots for ints and floats 1.709 + const int inc_stk_for_longdouble = 2; // 2 slots for longs and doubles 1.710 + 1.711 + int ill_i = 0; 1.712 + int ill_t = 0; 1.713 + int i; 1.714 + VMReg reg; 1.715 + // Leave room for C-compatible ABI_112. 1.716 + int stk = (frame::abi_112_size - frame::jit_out_preserve_size) / VMRegImpl::stack_slot_size; 1.717 + int arg = 0; 1.718 + int freg = 0; 1.719 + 1.720 + // Avoid passing C arguments in the wrong stack slots. 1.721 + assert((SharedRuntime::out_preserve_stack_slots() + stk) * VMRegImpl::stack_slot_size == 112, 1.722 + "passing C arguments in wrong stack slots"); 1.723 + 1.724 + // We fill-out regs AND regs2 if an argument must be passed in a 1.725 + // register AND in a stack slot. If regs2 is NULL in such a 1.726 + // situation, we bail-out with a fatal error. 1.727 + for (int i = 0; i < total_args_passed; ++i, ++arg) { 1.728 + // Initialize regs2 to BAD. 1.729 + if (regs2 != NULL) regs2[i].set_bad(); 1.730 + 1.731 + switch(sig_bt[i]) { 1.732 + case T_BOOLEAN: 1.733 + case T_CHAR: 1.734 + case T_BYTE: 1.735 + case T_SHORT: 1.736 + case T_INT: 1.737 + // We must cast ints to longs and use full 64 bit stack slots 1.738 + // here. We do the cast in GraphKit::gen_stub() and just guard 1.739 + // here against loosing that change. 1.740 + Unimplemented(); // TODO: PPC port 1.741 + /* 1.742 + assert(SharedRuntime::c_calling_convention_requires_ints_as_longs(), 1.743 + "argument of type int should be promoted to type long"); 1.744 + */ 1.745 + guarantee(i > 0 && sig_bt[i-1] == T_LONG, 1.746 + "argument of type (bt) should have been promoted to type (T_LONG,bt) for bt in " 1.747 + "{T_BOOLEAN, T_CHAR, T_BYTE, T_SHORT, T_INT}"); 1.748 + // Do not count halves. 1.749 + regs[i].set_bad(); 1.750 + --arg; 1.751 + break; 1.752 + case T_LONG: 1.753 + guarantee(sig_bt[i+1] == T_VOID || 1.754 + sig_bt[i+1] == T_BOOLEAN || sig_bt[i+1] == T_CHAR || 1.755 + sig_bt[i+1] == T_BYTE || sig_bt[i+1] == T_SHORT || 1.756 + sig_bt[i+1] == T_INT, 1.757 + "expecting type (T_LONG,half) or type (T_LONG,bt) with bt in {T_BOOLEAN, T_CHAR, T_BYTE, T_SHORT, T_INT}"); 1.758 + case T_OBJECT: 1.759 + case T_ARRAY: 1.760 + case T_ADDRESS: 1.761 + case T_METADATA: 1.762 + // Oops are already boxed if required (JNI). 1.763 + if (put_arg_in_reg(arg)) { 1.764 + reg = iarg_reg[arg]; 1.765 + } else { 1.766 + reg = VMRegImpl::stack2reg(stk); 1.767 + stk += inc_stk_for_longdouble; 1.768 + } 1.769 + regs[i].set2(reg); 1.770 + break; 1.771 + case T_FLOAT: 1.772 + if (put_arg_in_reg(arg)) { 1.773 + reg = farg_reg[freg]; 1.774 + } else { 1.775 + // Put float on stack 1.776 +# if defined(LINUX) 1.777 + reg = VMRegImpl::stack2reg(stk+1); 1.778 +# elif defined(AIX) 1.779 + reg = VMRegImpl::stack2reg(stk); 1.780 +# else 1.781 +# error "unknown OS" 1.782 +# endif 1.783 + stk += inc_stk_for_intfloat; 1.784 + } 1.785 + 1.786 + if (freg < num_farg_registers) { 1.787 + // There are still some float argument registers left. Put the 1.788 + // float in a register if not already done. 1.789 + if (reg != farg_reg[freg]) { 1.790 + guarantee(regs2 != NULL, "must pass float in register and stack slot"); 1.791 + VMReg reg2 = farg_reg[freg]; 1.792 + regs2[i].set1(reg2); 1.793 + } 1.794 + ++freg; 1.795 + } 1.796 + 1.797 + regs[i].set1(reg); 1.798 + break; 1.799 + case T_DOUBLE: 1.800 + assert(sig_bt[i+1] == T_VOID, "expecting half"); 1.801 + if (put_arg_in_reg(arg)) { 1.802 + reg = farg_reg[freg]; 1.803 + } else { 1.804 + // Put double on stack. 1.805 + reg = VMRegImpl::stack2reg(stk); 1.806 + stk += inc_stk_for_longdouble; 1.807 + } 1.808 + 1.809 + if (freg < num_farg_registers) { 1.810 + // There are still some float argument registers left. Put the 1.811 + // float in a register if not already done. 1.812 + if (reg != farg_reg[freg]) { 1.813 + guarantee(regs2 != NULL, "must pass float in register and stack slot"); 1.814 + VMReg reg2 = farg_reg[freg]; 1.815 + regs2[i].set2(reg2); 1.816 + } 1.817 + ++freg; 1.818 + } 1.819 + 1.820 + regs[i].set2(reg); 1.821 + break; 1.822 + case T_VOID: 1.823 + // Do not count halves. 1.824 + regs[i].set_bad(); 1.825 + --arg; 1.826 + break; 1.827 + default: 1.828 + ShouldNotReachHere(); 1.829 + } 1.830 + } 1.831 + 1.832 + return round_to(stk, 2); 1.833 +} 1.834 +#endif // COMPILER2 1.835 + 1.836 +static address gen_c2i_adapter(MacroAssembler *masm, 1.837 + int total_args_passed, 1.838 + int comp_args_on_stack, 1.839 + const BasicType *sig_bt, 1.840 + const VMRegPair *regs, 1.841 + Label& call_interpreter, 1.842 + const Register& ientry) { 1.843 + 1.844 + address c2i_entrypoint; 1.845 + 1.846 + const Register sender_SP = R21_sender_SP; // == R21_tmp1 1.847 + const Register code = R22_tmp2; 1.848 + //const Register ientry = R23_tmp3; 1.849 + const Register value_regs[] = { R24_tmp4, R25_tmp5, R26_tmp6 }; 1.850 + const int num_value_regs = sizeof(value_regs) / sizeof(Register); 1.851 + int value_regs_index = 0; 1.852 + 1.853 + const Register return_pc = R27_tmp7; 1.854 + const Register tmp = R28_tmp8; 1.855 + 1.856 + assert_different_registers(sender_SP, code, ientry, return_pc, tmp); 1.857 + 1.858 + // Adapter needs TOP_IJAVA_FRAME_ABI. 1.859 + const int adapter_size = frame::top_ijava_frame_abi_size + 1.860 + round_to(total_args_passed * wordSize, frame::alignment_in_bytes); 1.861 + 1.862 + 1.863 + // regular (verified) c2i entry point 1.864 + c2i_entrypoint = __ pc(); 1.865 + 1.866 + // Does compiled code exists? If yes, patch the caller's callsite. 1.867 + __ ld(code, method_(code)); 1.868 + __ cmpdi(CCR0, code, 0); 1.869 + __ ld(ientry, method_(interpreter_entry)); // preloaded 1.870 + __ beq(CCR0, call_interpreter); 1.871 + 1.872 + 1.873 + // Patch caller's callsite, method_(code) was not NULL which means that 1.874 + // compiled code exists. 1.875 + __ mflr(return_pc); 1.876 + __ std(return_pc, _abi(lr), R1_SP); 1.877 + RegisterSaver::push_frame_and_save_argument_registers(masm, tmp, adapter_size, total_args_passed, regs); 1.878 + 1.879 + __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite), R19_method, return_pc); 1.880 + 1.881 + RegisterSaver::restore_argument_registers_and_pop_frame(masm, adapter_size, total_args_passed, regs); 1.882 + __ ld(return_pc, _abi(lr), R1_SP); 1.883 + __ ld(ientry, method_(interpreter_entry)); // preloaded 1.884 + __ mtlr(return_pc); 1.885 + 1.886 + 1.887 + // call the interpreter 1.888 + __ BIND(call_interpreter); 1.889 + __ mtctr(ientry); 1.890 + 1.891 + // Get a copy of the current SP for loading caller's arguments. 1.892 + __ mr(sender_SP, R1_SP); 1.893 + 1.894 + // Add space for the adapter. 1.895 + __ resize_frame(-adapter_size, R12_scratch2); 1.896 + 1.897 + int st_off = adapter_size - wordSize; 1.898 + 1.899 + // Write the args into the outgoing interpreter space. 1.900 + for (int i = 0; i < total_args_passed; i++) { 1.901 + VMReg r_1 = regs[i].first(); 1.902 + VMReg r_2 = regs[i].second(); 1.903 + if (!r_1->is_valid()) { 1.904 + assert(!r_2->is_valid(), ""); 1.905 + continue; 1.906 + } 1.907 + if (r_1->is_stack()) { 1.908 + Register tmp_reg = value_regs[value_regs_index]; 1.909 + value_regs_index = (value_regs_index + 1) % num_value_regs; 1.910 + // The calling convention produces OptoRegs that ignore the out 1.911 + // preserve area (JIT's ABI). We must account for it here. 1.912 + int ld_off = (r_1->reg2stack() + SharedRuntime::out_preserve_stack_slots()) * VMRegImpl::stack_slot_size; 1.913 + if (!r_2->is_valid()) { 1.914 + __ lwz(tmp_reg, ld_off, sender_SP); 1.915 + } else { 1.916 + __ ld(tmp_reg, ld_off, sender_SP); 1.917 + } 1.918 + // Pretend stack targets were loaded into tmp_reg. 1.919 + r_1 = tmp_reg->as_VMReg(); 1.920 + } 1.921 + 1.922 + if (r_1->is_Register()) { 1.923 + Register r = r_1->as_Register(); 1.924 + if (!r_2->is_valid()) { 1.925 + __ stw(r, st_off, R1_SP); 1.926 + st_off-=wordSize; 1.927 + } else { 1.928 + // Longs are given 2 64-bit slots in the interpreter, but the 1.929 + // data is passed in only 1 slot. 1.930 + if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) { 1.931 + DEBUG_ONLY( __ li(tmp, 0); __ std(tmp, st_off, R1_SP); ) 1.932 + st_off-=wordSize; 1.933 + } 1.934 + __ std(r, st_off, R1_SP); 1.935 + st_off-=wordSize; 1.936 + } 1.937 + } else { 1.938 + assert(r_1->is_FloatRegister(), ""); 1.939 + FloatRegister f = r_1->as_FloatRegister(); 1.940 + if (!r_2->is_valid()) { 1.941 + __ stfs(f, st_off, R1_SP); 1.942 + st_off-=wordSize; 1.943 + } else { 1.944 + // In 64bit, doubles are given 2 64-bit slots in the interpreter, but the 1.945 + // data is passed in only 1 slot. 1.946 + // One of these should get known junk... 1.947 + DEBUG_ONLY( __ li(tmp, 0); __ std(tmp, st_off, R1_SP); ) 1.948 + st_off-=wordSize; 1.949 + __ stfd(f, st_off, R1_SP); 1.950 + st_off-=wordSize; 1.951 + } 1.952 + } 1.953 + } 1.954 + 1.955 + // Jump to the interpreter just as if interpreter was doing it. 1.956 + 1.957 + // load TOS 1.958 + __ addi(R17_tos, R1_SP, st_off); 1.959 + 1.960 + // Frame_manager expects initial_caller_sp (= SP without resize by c2i) in R21_tmp1. 1.961 + assert(sender_SP == R21_sender_SP, "passing initial caller's SP in wrong register"); 1.962 + __ bctr(); 1.963 + 1.964 + return c2i_entrypoint; 1.965 +} 1.966 + 1.967 +static void gen_i2c_adapter(MacroAssembler *masm, 1.968 + int total_args_passed, 1.969 + int comp_args_on_stack, 1.970 + const BasicType *sig_bt, 1.971 + const VMRegPair *regs) { 1.972 + 1.973 + // Load method's entry-point from methodOop. 1.974 + __ ld(R12_scratch2, in_bytes(Method::from_compiled_offset()), R19_method); 1.975 + __ mtctr(R12_scratch2); 1.976 + 1.977 + // We will only enter here from an interpreted frame and never from after 1.978 + // passing thru a c2i. Azul allowed this but we do not. If we lose the 1.979 + // race and use a c2i we will remain interpreted for the race loser(s). 1.980 + // This removes all sorts of headaches on the x86 side and also eliminates 1.981 + // the possibility of having c2i -> i2c -> c2i -> ... endless transitions. 1.982 + 1.983 + // Note: r13 contains the senderSP on entry. We must preserve it since 1.984 + // we may do a i2c -> c2i transition if we lose a race where compiled 1.985 + // code goes non-entrant while we get args ready. 1.986 + // In addition we use r13 to locate all the interpreter args as 1.987 + // we must align the stack to 16 bytes on an i2c entry else we 1.988 + // lose alignment we expect in all compiled code and register 1.989 + // save code can segv when fxsave instructions find improperly 1.990 + // aligned stack pointer. 1.991 + 1.992 + const Register ld_ptr = R17_tos; 1.993 + const Register value_regs[] = { R22_tmp2, R23_tmp3, R24_tmp4, R25_tmp5, R26_tmp6 }; 1.994 + const int num_value_regs = sizeof(value_regs) / sizeof(Register); 1.995 + int value_regs_index = 0; 1.996 + 1.997 + int ld_offset = total_args_passed*wordSize; 1.998 + 1.999 + // Cut-out for having no stack args. Since up to 2 int/oop args are passed 1.1000 + // in registers, we will occasionally have no stack args. 1.1001 + int comp_words_on_stack = 0; 1.1002 + if (comp_args_on_stack) { 1.1003 + // Sig words on the stack are greater-than VMRegImpl::stack0. Those in 1.1004 + // registers are below. By subtracting stack0, we either get a negative 1.1005 + // number (all values in registers) or the maximum stack slot accessed. 1.1006 + 1.1007 + // Convert 4-byte c2 stack slots to words. 1.1008 + comp_words_on_stack = round_to(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord; 1.1009 + // Round up to miminum stack alignment, in wordSize. 1.1010 + comp_words_on_stack = round_to(comp_words_on_stack, 2); 1.1011 + __ resize_frame(-comp_words_on_stack * wordSize, R11_scratch1); 1.1012 + } 1.1013 + 1.1014 + // Now generate the shuffle code. Pick up all register args and move the 1.1015 + // rest through register value=Z_R12. 1.1016 + BLOCK_COMMENT("Shuffle arguments"); 1.1017 + for (int i = 0; i < total_args_passed; i++) { 1.1018 + if (sig_bt[i] == T_VOID) { 1.1019 + assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half"); 1.1020 + continue; 1.1021 + } 1.1022 + 1.1023 + // Pick up 0, 1 or 2 words from ld_ptr. 1.1024 + assert(!regs[i].second()->is_valid() || regs[i].first()->next() == regs[i].second(), 1.1025 + "scrambled load targets?"); 1.1026 + VMReg r_1 = regs[i].first(); 1.1027 + VMReg r_2 = regs[i].second(); 1.1028 + if (!r_1->is_valid()) { 1.1029 + assert(!r_2->is_valid(), ""); 1.1030 + continue; 1.1031 + } 1.1032 + if (r_1->is_FloatRegister()) { 1.1033 + if (!r_2->is_valid()) { 1.1034 + __ lfs(r_1->as_FloatRegister(), ld_offset, ld_ptr); 1.1035 + ld_offset-=wordSize; 1.1036 + } else { 1.1037 + // Skip the unused interpreter slot. 1.1038 + __ lfd(r_1->as_FloatRegister(), ld_offset-wordSize, ld_ptr); 1.1039 + ld_offset-=2*wordSize; 1.1040 + } 1.1041 + } else { 1.1042 + Register r; 1.1043 + if (r_1->is_stack()) { 1.1044 + // Must do a memory to memory move thru "value". 1.1045 + r = value_regs[value_regs_index]; 1.1046 + value_regs_index = (value_regs_index + 1) % num_value_regs; 1.1047 + } else { 1.1048 + r = r_1->as_Register(); 1.1049 + } 1.1050 + if (!r_2->is_valid()) { 1.1051 + // Not sure we need to do this but it shouldn't hurt. 1.1052 + if (sig_bt[i] == T_OBJECT || sig_bt[i] == T_ADDRESS || sig_bt[i] == T_ARRAY) { 1.1053 + __ ld(r, ld_offset, ld_ptr); 1.1054 + ld_offset-=wordSize; 1.1055 + } else { 1.1056 + __ lwz(r, ld_offset, ld_ptr); 1.1057 + ld_offset-=wordSize; 1.1058 + } 1.1059 + } else { 1.1060 + // In 64bit, longs are given 2 64-bit slots in the interpreter, but the 1.1061 + // data is passed in only 1 slot. 1.1062 + if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) { 1.1063 + ld_offset-=wordSize; 1.1064 + } 1.1065 + __ ld(r, ld_offset, ld_ptr); 1.1066 + ld_offset-=wordSize; 1.1067 + } 1.1068 + 1.1069 + if (r_1->is_stack()) { 1.1070 + // Now store value where the compiler expects it 1.1071 + int st_off = (r_1->reg2stack() + SharedRuntime::out_preserve_stack_slots())*VMRegImpl::stack_slot_size; 1.1072 + 1.1073 + if (sig_bt[i] == T_INT || sig_bt[i] == T_FLOAT ||sig_bt[i] == T_BOOLEAN || 1.1074 + sig_bt[i] == T_SHORT || sig_bt[i] == T_CHAR || sig_bt[i] == T_BYTE) { 1.1075 + __ stw(r, st_off, R1_SP); 1.1076 + } else { 1.1077 + __ std(r, st_off, R1_SP); 1.1078 + } 1.1079 + } 1.1080 + } 1.1081 + } 1.1082 + 1.1083 + BLOCK_COMMENT("Store method oop"); 1.1084 + // Store method oop into thread->callee_target. 1.1085 + // We might end up in handle_wrong_method if the callee is 1.1086 + // deoptimized as we race thru here. If that happens we don't want 1.1087 + // to take a safepoint because the caller frame will look 1.1088 + // interpreted and arguments are now "compiled" so it is much better 1.1089 + // to make this transition invisible to the stack walking 1.1090 + // code. Unfortunately if we try and find the callee by normal means 1.1091 + // a safepoint is possible. So we stash the desired callee in the 1.1092 + // thread and the vm will find there should this case occur. 1.1093 + __ std(R19_method, thread_(callee_target)); 1.1094 + 1.1095 + // Jump to the compiled code just as if compiled code was doing it. 1.1096 + __ bctr(); 1.1097 +} 1.1098 + 1.1099 +AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm, 1.1100 + int total_args_passed, 1.1101 + int comp_args_on_stack, 1.1102 + const BasicType *sig_bt, 1.1103 + const VMRegPair *regs, 1.1104 + AdapterFingerPrint* fingerprint) { 1.1105 + address i2c_entry; 1.1106 + address c2i_unverified_entry; 1.1107 + address c2i_entry; 1.1108 + 1.1109 + 1.1110 + // entry: i2c 1.1111 + 1.1112 + __ align(CodeEntryAlignment); 1.1113 + i2c_entry = __ pc(); 1.1114 + gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs); 1.1115 + 1.1116 + 1.1117 + // entry: c2i unverified 1.1118 + 1.1119 + __ align(CodeEntryAlignment); 1.1120 + BLOCK_COMMENT("c2i unverified entry"); 1.1121 + c2i_unverified_entry = __ pc(); 1.1122 + 1.1123 + // inline_cache contains a compiledICHolder 1.1124 + const Register ic = R19_method; 1.1125 + const Register ic_klass = R11_scratch1; 1.1126 + const Register receiver_klass = R12_scratch2; 1.1127 + const Register code = R21_tmp1; 1.1128 + const Register ientry = R23_tmp3; 1.1129 + 1.1130 + assert_different_registers(ic, ic_klass, receiver_klass, R3_ARG1, code, ientry); 1.1131 + assert(R11_scratch1 == R11, "need prologue scratch register"); 1.1132 + 1.1133 + Label call_interpreter; 1.1134 + 1.1135 + assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), 1.1136 + "klass offset should reach into any page"); 1.1137 + // Check for NULL argument if we don't have implicit null checks. 1.1138 + if (!ImplicitNullChecks NOT_LINUX(|| true) /*!os::zero_page_read_protected()*/) { 1.1139 + if (TrapBasedNullChecks) { 1.1140 + __ trap_null_check(R3_ARG1); 1.1141 + } else { 1.1142 + Label valid; 1.1143 + __ cmpdi(CCR0, R3_ARG1, 0); 1.1144 + __ bne_predict_taken(CCR0, valid); 1.1145 + // We have a null argument, branch to ic_miss_stub. 1.1146 + __ b64_patchable((address)SharedRuntime::get_ic_miss_stub(), 1.1147 + relocInfo::runtime_call_type); 1.1148 + __ BIND(valid); 1.1149 + } 1.1150 + } 1.1151 + // Assume argument is not NULL, load klass from receiver. 1.1152 + __ load_klass(receiver_klass, R3_ARG1); 1.1153 + 1.1154 + __ ld(ic_klass, CompiledICHolder::holder_klass_offset(), ic); 1.1155 + 1.1156 + if (TrapBasedICMissChecks) { 1.1157 + __ trap_ic_miss_check(receiver_klass, ic_klass); 1.1158 + } else { 1.1159 + Label valid; 1.1160 + __ cmpd(CCR0, receiver_klass, ic_klass); 1.1161 + __ beq_predict_taken(CCR0, valid); 1.1162 + // We have an unexpected klass, branch to ic_miss_stub. 1.1163 + __ b64_patchable((address)SharedRuntime::get_ic_miss_stub(), 1.1164 + relocInfo::runtime_call_type); 1.1165 + __ BIND(valid); 1.1166 + } 1.1167 + 1.1168 + // Argument is valid and klass is as expected, continue. 1.1169 + 1.1170 + // Extract method from inline cache, verified entry point needs it. 1.1171 + __ ld(R19_method, CompiledICHolder::holder_method_offset(), ic); 1.1172 + assert(R19_method == ic, "the inline cache register is dead here"); 1.1173 + 1.1174 + __ ld(code, method_(code)); 1.1175 + __ cmpdi(CCR0, code, 0); 1.1176 + __ ld(ientry, method_(interpreter_entry)); // preloaded 1.1177 + __ beq_predict_taken(CCR0, call_interpreter); 1.1178 + 1.1179 + // Branch to ic_miss_stub. 1.1180 + __ b64_patchable((address)SharedRuntime::get_ic_miss_stub(), 1.1181 + relocInfo::runtime_call_type); 1.1182 + 1.1183 + // entry: c2i 1.1184 + 1.1185 + c2i_entry = gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, call_interpreter, ientry); 1.1186 + 1.1187 + return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry); 1.1188 +} 1.1189 + 1.1190 +#ifdef COMPILER2 1.1191 +// An oop arg. Must pass a handle not the oop itself. 1.1192 +static void object_move(MacroAssembler* masm, 1.1193 + int frame_size_in_slots, 1.1194 + OopMap* oop_map, int oop_handle_offset, 1.1195 + bool is_receiver, int* receiver_offset, 1.1196 + VMRegPair src, VMRegPair dst, 1.1197 + Register r_caller_sp, Register r_temp_1, Register r_temp_2) { 1.1198 + assert(!is_receiver || (is_receiver && (*receiver_offset == -1)), 1.1199 + "receiver has already been moved"); 1.1200 + 1.1201 + // We must pass a handle. First figure out the location we use as a handle. 1.1202 + 1.1203 + if (src.first()->is_stack()) { 1.1204 + // stack to stack or reg 1.1205 + 1.1206 + const Register r_handle = dst.first()->is_stack() ? r_temp_1 : dst.first()->as_Register(); 1.1207 + Label skip; 1.1208 + const int oop_slot_in_callers_frame = reg2slot(src.first()); 1.1209 + 1.1210 + guarantee(!is_receiver, "expecting receiver in register"); 1.1211 + oop_map->set_oop(VMRegImpl::stack2reg(oop_slot_in_callers_frame + frame_size_in_slots)); 1.1212 + 1.1213 + __ addi(r_handle, r_caller_sp, reg2offset(src.first())); 1.1214 + __ ld( r_temp_2, reg2offset(src.first()), r_caller_sp); 1.1215 + __ cmpdi(CCR0, r_temp_2, 0); 1.1216 + __ bne(CCR0, skip); 1.1217 + // Use a NULL handle if oop is NULL. 1.1218 + __ li(r_handle, 0); 1.1219 + __ bind(skip); 1.1220 + 1.1221 + if (dst.first()->is_stack()) { 1.1222 + // stack to stack 1.1223 + __ std(r_handle, reg2offset(dst.first()), R1_SP); 1.1224 + } else { 1.1225 + // stack to reg 1.1226 + // Nothing to do, r_handle is already the dst register. 1.1227 + } 1.1228 + } else { 1.1229 + // reg to stack or reg 1.1230 + const Register r_oop = src.first()->as_Register(); 1.1231 + const Register r_handle = dst.first()->is_stack() ? r_temp_1 : dst.first()->as_Register(); 1.1232 + const int oop_slot = (r_oop->encoding()-R3_ARG1->encoding()) * VMRegImpl::slots_per_word 1.1233 + + oop_handle_offset; // in slots 1.1234 + const int oop_offset = oop_slot * VMRegImpl::stack_slot_size; 1.1235 + Label skip; 1.1236 + 1.1237 + if (is_receiver) { 1.1238 + *receiver_offset = oop_offset; 1.1239 + } 1.1240 + oop_map->set_oop(VMRegImpl::stack2reg(oop_slot)); 1.1241 + 1.1242 + __ std( r_oop, oop_offset, R1_SP); 1.1243 + __ addi(r_handle, R1_SP, oop_offset); 1.1244 + 1.1245 + __ cmpdi(CCR0, r_oop, 0); 1.1246 + __ bne(CCR0, skip); 1.1247 + // Use a NULL handle if oop is NULL. 1.1248 + __ li(r_handle, 0); 1.1249 + __ bind(skip); 1.1250 + 1.1251 + if (dst.first()->is_stack()) { 1.1252 + // reg to stack 1.1253 + __ std(r_handle, reg2offset(dst.first()), R1_SP); 1.1254 + } else { 1.1255 + // reg to reg 1.1256 + // Nothing to do, r_handle is already the dst register. 1.1257 + } 1.1258 + } 1.1259 +} 1.1260 + 1.1261 +static void int_move(MacroAssembler*masm, 1.1262 + VMRegPair src, VMRegPair dst, 1.1263 + Register r_caller_sp, Register r_temp) { 1.1264 + assert(src.first()->is_valid() && src.second() == src.first()->next(), "incoming must be long-int"); 1.1265 + assert(dst.first()->is_valid() && dst.second() == dst.first()->next(), "outgoing must be long"); 1.1266 + 1.1267 + if (src.first()->is_stack()) { 1.1268 + if (dst.first()->is_stack()) { 1.1269 + // stack to stack 1.1270 + __ lwa(r_temp, reg2offset(src.first()), r_caller_sp); 1.1271 + __ std(r_temp, reg2offset(dst.first()), R1_SP); 1.1272 + } else { 1.1273 + // stack to reg 1.1274 + __ lwa(dst.first()->as_Register(), reg2offset(src.first()), r_caller_sp); 1.1275 + } 1.1276 + } else if (dst.first()->is_stack()) { 1.1277 + // reg to stack 1.1278 + __ extsw(r_temp, src.first()->as_Register()); 1.1279 + __ std(r_temp, reg2offset(dst.first()), R1_SP); 1.1280 + } else { 1.1281 + // reg to reg 1.1282 + __ extsw(dst.first()->as_Register(), src.first()->as_Register()); 1.1283 + } 1.1284 +} 1.1285 + 1.1286 +static void long_move(MacroAssembler*masm, 1.1287 + VMRegPair src, VMRegPair dst, 1.1288 + Register r_caller_sp, Register r_temp) { 1.1289 + assert(src.first()->is_valid() && src.second() == src.first()->next(), "incoming must be long"); 1.1290 + assert(dst.first()->is_valid() && dst.second() == dst.first()->next(), "outgoing must be long"); 1.1291 + 1.1292 + if (src.first()->is_stack()) { 1.1293 + if (dst.first()->is_stack()) { 1.1294 + // stack to stack 1.1295 + __ ld( r_temp, reg2offset(src.first()), r_caller_sp); 1.1296 + __ std(r_temp, reg2offset(dst.first()), R1_SP); 1.1297 + } else { 1.1298 + // stack to reg 1.1299 + __ ld(dst.first()->as_Register(), reg2offset(src.first()), r_caller_sp); 1.1300 + } 1.1301 + } else if (dst.first()->is_stack()) { 1.1302 + // reg to stack 1.1303 + __ std(src.first()->as_Register(), reg2offset(dst.first()), R1_SP); 1.1304 + } else { 1.1305 + // reg to reg 1.1306 + if (dst.first()->as_Register() != src.first()->as_Register()) 1.1307 + __ mr(dst.first()->as_Register(), src.first()->as_Register()); 1.1308 + } 1.1309 +} 1.1310 + 1.1311 +static void float_move(MacroAssembler*masm, 1.1312 + VMRegPair src, VMRegPair dst, 1.1313 + Register r_caller_sp, Register r_temp) { 1.1314 + assert(src.first()->is_valid() && !src.second()->is_valid(), "incoming must be float"); 1.1315 + assert(dst.first()->is_valid() && !dst.second()->is_valid(), "outgoing must be float"); 1.1316 + 1.1317 + if (src.first()->is_stack()) { 1.1318 + if (dst.first()->is_stack()) { 1.1319 + // stack to stack 1.1320 + __ lwz(r_temp, reg2offset(src.first()), r_caller_sp); 1.1321 + __ stw(r_temp, reg2offset(dst.first()), R1_SP); 1.1322 + } else { 1.1323 + // stack to reg 1.1324 + __ lfs(dst.first()->as_FloatRegister(), reg2offset(src.first()), r_caller_sp); 1.1325 + } 1.1326 + } else if (dst.first()->is_stack()) { 1.1327 + // reg to stack 1.1328 + __ stfs(src.first()->as_FloatRegister(), reg2offset(dst.first()), R1_SP); 1.1329 + } else { 1.1330 + // reg to reg 1.1331 + if (dst.first()->as_FloatRegister() != src.first()->as_FloatRegister()) 1.1332 + __ fmr(dst.first()->as_FloatRegister(), src.first()->as_FloatRegister()); 1.1333 + } 1.1334 +} 1.1335 + 1.1336 +static void double_move(MacroAssembler*masm, 1.1337 + VMRegPair src, VMRegPair dst, 1.1338 + Register r_caller_sp, Register r_temp) { 1.1339 + assert(src.first()->is_valid() && src.second() == src.first()->next(), "incoming must be double"); 1.1340 + assert(dst.first()->is_valid() && dst.second() == dst.first()->next(), "outgoing must be double"); 1.1341 + 1.1342 + if (src.first()->is_stack()) { 1.1343 + if (dst.first()->is_stack()) { 1.1344 + // stack to stack 1.1345 + __ ld( r_temp, reg2offset(src.first()), r_caller_sp); 1.1346 + __ std(r_temp, reg2offset(dst.first()), R1_SP); 1.1347 + } else { 1.1348 + // stack to reg 1.1349 + __ lfd(dst.first()->as_FloatRegister(), reg2offset(src.first()), r_caller_sp); 1.1350 + } 1.1351 + } else if (dst.first()->is_stack()) { 1.1352 + // reg to stack 1.1353 + __ stfd(src.first()->as_FloatRegister(), reg2offset(dst.first()), R1_SP); 1.1354 + } else { 1.1355 + // reg to reg 1.1356 + if (dst.first()->as_FloatRegister() != src.first()->as_FloatRegister()) 1.1357 + __ fmr(dst.first()->as_FloatRegister(), src.first()->as_FloatRegister()); 1.1358 + } 1.1359 +} 1.1360 + 1.1361 +void SharedRuntime::save_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) { 1.1362 + switch (ret_type) { 1.1363 + case T_BOOLEAN: 1.1364 + case T_CHAR: 1.1365 + case T_BYTE: 1.1366 + case T_SHORT: 1.1367 + case T_INT: 1.1368 + __ stw (R3_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); 1.1369 + break; 1.1370 + case T_ARRAY: 1.1371 + case T_OBJECT: 1.1372 + case T_LONG: 1.1373 + __ std (R3_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); 1.1374 + break; 1.1375 + case T_FLOAT: 1.1376 + __ stfs(F1_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); 1.1377 + break; 1.1378 + case T_DOUBLE: 1.1379 + __ stfd(F1_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); 1.1380 + break; 1.1381 + case T_VOID: 1.1382 + break; 1.1383 + default: 1.1384 + ShouldNotReachHere(); 1.1385 + break; 1.1386 + } 1.1387 +} 1.1388 + 1.1389 +void SharedRuntime::restore_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) { 1.1390 + switch (ret_type) { 1.1391 + case T_BOOLEAN: 1.1392 + case T_CHAR: 1.1393 + case T_BYTE: 1.1394 + case T_SHORT: 1.1395 + case T_INT: 1.1396 + __ lwz(R3_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); 1.1397 + break; 1.1398 + case T_ARRAY: 1.1399 + case T_OBJECT: 1.1400 + case T_LONG: 1.1401 + __ ld (R3_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); 1.1402 + break; 1.1403 + case T_FLOAT: 1.1404 + __ lfs(F1_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); 1.1405 + break; 1.1406 + case T_DOUBLE: 1.1407 + __ lfd(F1_RET, frame_slots*VMRegImpl::stack_slot_size, R1_SP); 1.1408 + break; 1.1409 + case T_VOID: 1.1410 + break; 1.1411 + default: 1.1412 + ShouldNotReachHere(); 1.1413 + break; 1.1414 + } 1.1415 +} 1.1416 + 1.1417 +static void save_or_restore_arguments(MacroAssembler* masm, 1.1418 + const int stack_slots, 1.1419 + const int total_in_args, 1.1420 + const int arg_save_area, 1.1421 + OopMap* map, 1.1422 + VMRegPair* in_regs, 1.1423 + BasicType* in_sig_bt) { 1.1424 + // If map is non-NULL then the code should store the values, 1.1425 + // otherwise it should load them. 1.1426 + int slot = arg_save_area; 1.1427 + // Save down double word first. 1.1428 + for (int i = 0; i < total_in_args; i++) { 1.1429 + if (in_regs[i].first()->is_FloatRegister() && in_sig_bt[i] == T_DOUBLE) { 1.1430 + int offset = slot * VMRegImpl::stack_slot_size; 1.1431 + slot += VMRegImpl::slots_per_word; 1.1432 + assert(slot <= stack_slots, "overflow (after DOUBLE stack slot)"); 1.1433 + if (map != NULL) { 1.1434 + __ stfd(in_regs[i].first()->as_FloatRegister(), offset, R1_SP); 1.1435 + } else { 1.1436 + __ lfd(in_regs[i].first()->as_FloatRegister(), offset, R1_SP); 1.1437 + } 1.1438 + } else if (in_regs[i].first()->is_Register() && 1.1439 + (in_sig_bt[i] == T_LONG || in_sig_bt[i] == T_ARRAY)) { 1.1440 + int offset = slot * VMRegImpl::stack_slot_size; 1.1441 + if (map != NULL) { 1.1442 + __ std(in_regs[i].first()->as_Register(), offset, R1_SP); 1.1443 + if (in_sig_bt[i] == T_ARRAY) { 1.1444 + map->set_oop(VMRegImpl::stack2reg(slot)); 1.1445 + } 1.1446 + } else { 1.1447 + __ ld(in_regs[i].first()->as_Register(), offset, R1_SP); 1.1448 + } 1.1449 + slot += VMRegImpl::slots_per_word; 1.1450 + assert(slot <= stack_slots, "overflow (after LONG/ARRAY stack slot)"); 1.1451 + } 1.1452 + } 1.1453 + // Save or restore single word registers. 1.1454 + for (int i = 0; i < total_in_args; i++) { 1.1455 + // PPC64: pass ints as longs: must only deal with floats here. 1.1456 + if (in_regs[i].first()->is_FloatRegister()) { 1.1457 + if (in_sig_bt[i] == T_FLOAT) { 1.1458 + int offset = slot * VMRegImpl::stack_slot_size; 1.1459 + slot++; 1.1460 + assert(slot <= stack_slots, "overflow (after FLOAT stack slot)"); 1.1461 + if (map != NULL) { 1.1462 + __ stfs(in_regs[i].first()->as_FloatRegister(), offset, R1_SP); 1.1463 + } else { 1.1464 + __ lfs(in_regs[i].first()->as_FloatRegister(), offset, R1_SP); 1.1465 + } 1.1466 + } 1.1467 + } else if (in_regs[i].first()->is_stack()) { 1.1468 + if (in_sig_bt[i] == T_ARRAY && map != NULL) { 1.1469 + int offset_in_older_frame = in_regs[i].first()->reg2stack() + SharedRuntime::out_preserve_stack_slots(); 1.1470 + map->set_oop(VMRegImpl::stack2reg(offset_in_older_frame + stack_slots)); 1.1471 + } 1.1472 + } 1.1473 + } 1.1474 +} 1.1475 + 1.1476 +// Check GC_locker::needs_gc and enter the runtime if it's true. This 1.1477 +// keeps a new JNI critical region from starting until a GC has been 1.1478 +// forced. Save down any oops in registers and describe them in an 1.1479 +// OopMap. 1.1480 +static void check_needs_gc_for_critical_native(MacroAssembler* masm, 1.1481 + const int stack_slots, 1.1482 + const int total_in_args, 1.1483 + const int arg_save_area, 1.1484 + OopMapSet* oop_maps, 1.1485 + VMRegPair* in_regs, 1.1486 + BasicType* in_sig_bt, 1.1487 + Register tmp_reg ) { 1.1488 + __ block_comment("check GC_locker::needs_gc"); 1.1489 + Label cont; 1.1490 + __ lbz(tmp_reg, (RegisterOrConstant)(intptr_t)GC_locker::needs_gc_address()); 1.1491 + __ cmplwi(CCR0, tmp_reg, 0); 1.1492 + __ beq(CCR0, cont); 1.1493 + 1.1494 + // Save down any values that are live in registers and call into the 1.1495 + // runtime to halt for a GC. 1.1496 + OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/); 1.1497 + save_or_restore_arguments(masm, stack_slots, total_in_args, 1.1498 + arg_save_area, map, in_regs, in_sig_bt); 1.1499 + 1.1500 + __ mr(R3_ARG1, R16_thread); 1.1501 + __ set_last_Java_frame(R1_SP, noreg); 1.1502 + 1.1503 + __ block_comment("block_for_jni_critical"); 1.1504 + address entry_point = CAST_FROM_FN_PTR(address, SharedRuntime::block_for_jni_critical); 1.1505 + __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, entry_point), relocInfo::runtime_call_type); 1.1506 + address start = __ pc() - __ offset(), 1.1507 + calls_return_pc = __ last_calls_return_pc(); 1.1508 + oop_maps->add_gc_map(calls_return_pc - start, map); 1.1509 + 1.1510 + __ reset_last_Java_frame(); 1.1511 + 1.1512 + // Reload all the register arguments. 1.1513 + save_or_restore_arguments(masm, stack_slots, total_in_args, 1.1514 + arg_save_area, NULL, in_regs, in_sig_bt); 1.1515 + 1.1516 + __ BIND(cont); 1.1517 + 1.1518 +#ifdef ASSERT 1.1519 + if (StressCriticalJNINatives) { 1.1520 + // Stress register saving. 1.1521 + OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/); 1.1522 + save_or_restore_arguments(masm, stack_slots, total_in_args, 1.1523 + arg_save_area, map, in_regs, in_sig_bt); 1.1524 + // Destroy argument registers. 1.1525 + for (int i = 0; i < total_in_args; i++) { 1.1526 + if (in_regs[i].first()->is_Register()) { 1.1527 + const Register reg = in_regs[i].first()->as_Register(); 1.1528 + __ neg(reg, reg); 1.1529 + } else if (in_regs[i].first()->is_FloatRegister()) { 1.1530 + __ fneg(in_regs[i].first()->as_FloatRegister(), in_regs[i].first()->as_FloatRegister()); 1.1531 + } 1.1532 + } 1.1533 + 1.1534 + save_or_restore_arguments(masm, stack_slots, total_in_args, 1.1535 + arg_save_area, NULL, in_regs, in_sig_bt); 1.1536 + } 1.1537 +#endif 1.1538 +} 1.1539 + 1.1540 +static void move_ptr(MacroAssembler* masm, VMRegPair src, VMRegPair dst, Register r_caller_sp, Register r_temp) { 1.1541 + if (src.first()->is_stack()) { 1.1542 + if (dst.first()->is_stack()) { 1.1543 + // stack to stack 1.1544 + __ ld(r_temp, reg2offset(src.first()), r_caller_sp); 1.1545 + __ std(r_temp, reg2offset(dst.first()), R1_SP); 1.1546 + } else { 1.1547 + // stack to reg 1.1548 + __ ld(dst.first()->as_Register(), reg2offset(src.first()), r_caller_sp); 1.1549 + } 1.1550 + } else if (dst.first()->is_stack()) { 1.1551 + // reg to stack 1.1552 + __ std(src.first()->as_Register(), reg2offset(dst.first()), R1_SP); 1.1553 + } else { 1.1554 + if (dst.first() != src.first()) { 1.1555 + __ mr(dst.first()->as_Register(), src.first()->as_Register()); 1.1556 + } 1.1557 + } 1.1558 +} 1.1559 + 1.1560 +// Unpack an array argument into a pointer to the body and the length 1.1561 +// if the array is non-null, otherwise pass 0 for both. 1.1562 +static void unpack_array_argument(MacroAssembler* masm, VMRegPair reg, BasicType in_elem_type, 1.1563 + VMRegPair body_arg, VMRegPair length_arg, Register r_caller_sp, 1.1564 + Register tmp_reg, Register tmp2_reg) { 1.1565 + assert(!body_arg.first()->is_Register() || body_arg.first()->as_Register() != tmp_reg, 1.1566 + "possible collision"); 1.1567 + assert(!length_arg.first()->is_Register() || length_arg.first()->as_Register() != tmp_reg, 1.1568 + "possible collision"); 1.1569 + 1.1570 + // Pass the length, ptr pair. 1.1571 + Label set_out_args; 1.1572 + VMRegPair tmp, tmp2; 1.1573 + tmp.set_ptr(tmp_reg->as_VMReg()); 1.1574 + tmp2.set_ptr(tmp2_reg->as_VMReg()); 1.1575 + if (reg.first()->is_stack()) { 1.1576 + // Load the arg up from the stack. 1.1577 + move_ptr(masm, reg, tmp, r_caller_sp, /*unused*/ R0); 1.1578 + reg = tmp; 1.1579 + } 1.1580 + __ li(tmp2_reg, 0); // Pass zeros if Array=null. 1.1581 + if (tmp_reg != reg.first()->as_Register()) __ li(tmp_reg, 0); 1.1582 + __ cmpdi(CCR0, reg.first()->as_Register(), 0); 1.1583 + __ beq(CCR0, set_out_args); 1.1584 + __ lwa(tmp2_reg, arrayOopDesc::length_offset_in_bytes(), reg.first()->as_Register()); 1.1585 + __ addi(tmp_reg, reg.first()->as_Register(), arrayOopDesc::base_offset_in_bytes(in_elem_type)); 1.1586 + __ bind(set_out_args); 1.1587 + move_ptr(masm, tmp, body_arg, r_caller_sp, /*unused*/ R0); 1.1588 + move_ptr(masm, tmp2, length_arg, r_caller_sp, /*unused*/ R0); // Same as move32_64 on PPC64. 1.1589 +} 1.1590 + 1.1591 +static void verify_oop_args(MacroAssembler* masm, 1.1592 + methodHandle method, 1.1593 + const BasicType* sig_bt, 1.1594 + const VMRegPair* regs) { 1.1595 + Register temp_reg = R19_method; // not part of any compiled calling seq 1.1596 + if (VerifyOops) { 1.1597 + for (int i = 0; i < method->size_of_parameters(); i++) { 1.1598 + if (sig_bt[i] == T_OBJECT || 1.1599 + sig_bt[i] == T_ARRAY) { 1.1600 + VMReg r = regs[i].first(); 1.1601 + assert(r->is_valid(), "bad oop arg"); 1.1602 + if (r->is_stack()) { 1.1603 + __ ld(temp_reg, reg2offset(r), R1_SP); 1.1604 + __ verify_oop(temp_reg); 1.1605 + } else { 1.1606 + __ verify_oop(r->as_Register()); 1.1607 + } 1.1608 + } 1.1609 + } 1.1610 + } 1.1611 +} 1.1612 + 1.1613 +static void gen_special_dispatch(MacroAssembler* masm, 1.1614 + methodHandle method, 1.1615 + const BasicType* sig_bt, 1.1616 + const VMRegPair* regs) { 1.1617 + verify_oop_args(masm, method, sig_bt, regs); 1.1618 + vmIntrinsics::ID iid = method->intrinsic_id(); 1.1619 + 1.1620 + // Now write the args into the outgoing interpreter space 1.1621 + bool has_receiver = false; 1.1622 + Register receiver_reg = noreg; 1.1623 + int member_arg_pos = -1; 1.1624 + Register member_reg = noreg; 1.1625 + int ref_kind = MethodHandles::signature_polymorphic_intrinsic_ref_kind(iid); 1.1626 + if (ref_kind != 0) { 1.1627 + member_arg_pos = method->size_of_parameters() - 1; // trailing MemberName argument 1.1628 + member_reg = R19_method; // known to be free at this point 1.1629 + has_receiver = MethodHandles::ref_kind_has_receiver(ref_kind); 1.1630 + } else if (iid == vmIntrinsics::_invokeBasic) { 1.1631 + has_receiver = true; 1.1632 + } else { 1.1633 + fatal(err_msg_res("unexpected intrinsic id %d", iid)); 1.1634 + } 1.1635 + 1.1636 + if (member_reg != noreg) { 1.1637 + // Load the member_arg into register, if necessary. 1.1638 + SharedRuntime::check_member_name_argument_is_last_argument(method, sig_bt, regs); 1.1639 + VMReg r = regs[member_arg_pos].first(); 1.1640 + if (r->is_stack()) { 1.1641 + __ ld(member_reg, reg2offset(r), R1_SP); 1.1642 + } else { 1.1643 + // no data motion is needed 1.1644 + member_reg = r->as_Register(); 1.1645 + } 1.1646 + } 1.1647 + 1.1648 + if (has_receiver) { 1.1649 + // Make sure the receiver is loaded into a register. 1.1650 + assert(method->size_of_parameters() > 0, "oob"); 1.1651 + assert(sig_bt[0] == T_OBJECT, "receiver argument must be an object"); 1.1652 + VMReg r = regs[0].first(); 1.1653 + assert(r->is_valid(), "bad receiver arg"); 1.1654 + if (r->is_stack()) { 1.1655 + // Porting note: This assumes that compiled calling conventions always 1.1656 + // pass the receiver oop in a register. If this is not true on some 1.1657 + // platform, pick a temp and load the receiver from stack. 1.1658 + fatal("receiver always in a register"); 1.1659 + receiver_reg = R11_scratch1; // TODO (hs24): is R11_scratch1 really free at this point? 1.1660 + __ ld(receiver_reg, reg2offset(r), R1_SP); 1.1661 + } else { 1.1662 + // no data motion is needed 1.1663 + receiver_reg = r->as_Register(); 1.1664 + } 1.1665 + } 1.1666 + 1.1667 + // Figure out which address we are really jumping to: 1.1668 + MethodHandles::generate_method_handle_dispatch(masm, iid, 1.1669 + receiver_reg, member_reg, /*for_compiler_entry:*/ true); 1.1670 +} 1.1671 + 1.1672 +#endif // COMPILER2 1.1673 + 1.1674 +// --------------------------------------------------------------------------- 1.1675 +// Generate a native wrapper for a given method. The method takes arguments 1.1676 +// in the Java compiled code convention, marshals them to the native 1.1677 +// convention (handlizes oops, etc), transitions to native, makes the call, 1.1678 +// returns to java state (possibly blocking), unhandlizes any result and 1.1679 +// returns. 1.1680 +// 1.1681 +// Critical native functions are a shorthand for the use of 1.1682 +// GetPrimtiveArrayCritical and disallow the use of any other JNI 1.1683 +// functions. The wrapper is expected to unpack the arguments before 1.1684 +// passing them to the callee and perform checks before and after the 1.1685 +// native call to ensure that they GC_locker 1.1686 +// lock_critical/unlock_critical semantics are followed. Some other 1.1687 +// parts of JNI setup are skipped like the tear down of the JNI handle 1.1688 +// block and the check for pending exceptions it's impossible for them 1.1689 +// to be thrown. 1.1690 +// 1.1691 +// They are roughly structured like this: 1.1692 +// if (GC_locker::needs_gc()) 1.1693 +// SharedRuntime::block_for_jni_critical(); 1.1694 +// tranistion to thread_in_native 1.1695 +// unpack arrray arguments and call native entry point 1.1696 +// check for safepoint in progress 1.1697 +// check if any thread suspend flags are set 1.1698 +// call into JVM and possible unlock the JNI critical 1.1699 +// if a GC was suppressed while in the critical native. 1.1700 +// transition back to thread_in_Java 1.1701 +// return to caller 1.1702 +// 1.1703 +nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm, 1.1704 + methodHandle method, 1.1705 + int compile_id, 1.1706 + BasicType *in_sig_bt, 1.1707 + VMRegPair *in_regs, 1.1708 + BasicType ret_type) { 1.1709 +#ifdef COMPILER2 1.1710 + if (method->is_method_handle_intrinsic()) { 1.1711 + vmIntrinsics::ID iid = method->intrinsic_id(); 1.1712 + intptr_t start = (intptr_t)__ pc(); 1.1713 + int vep_offset = ((intptr_t)__ pc()) - start; 1.1714 + gen_special_dispatch(masm, 1.1715 + method, 1.1716 + in_sig_bt, 1.1717 + in_regs); 1.1718 + int frame_complete = ((intptr_t)__ pc()) - start; // not complete, period 1.1719 + __ flush(); 1.1720 + int stack_slots = SharedRuntime::out_preserve_stack_slots(); // no out slots at all, actually 1.1721 + return nmethod::new_native_nmethod(method, 1.1722 + compile_id, 1.1723 + masm->code(), 1.1724 + vep_offset, 1.1725 + frame_complete, 1.1726 + stack_slots / VMRegImpl::slots_per_word, 1.1727 + in_ByteSize(-1), 1.1728 + in_ByteSize(-1), 1.1729 + (OopMapSet*)NULL); 1.1730 + } 1.1731 + 1.1732 + bool is_critical_native = true; 1.1733 + address native_func = method->critical_native_function(); 1.1734 + if (native_func == NULL) { 1.1735 + native_func = method->native_function(); 1.1736 + is_critical_native = false; 1.1737 + } 1.1738 + assert(native_func != NULL, "must have function"); 1.1739 + 1.1740 + // First, create signature for outgoing C call 1.1741 + // -------------------------------------------------------------------------- 1.1742 + 1.1743 + int total_in_args = method->size_of_parameters(); 1.1744 + // We have received a description of where all the java args are located 1.1745 + // on entry to the wrapper. We need to convert these args to where 1.1746 + // the jni function will expect them. To figure out where they go 1.1747 + // we convert the java signature to a C signature by inserting 1.1748 + // the hidden arguments as arg[0] and possibly arg[1] (static method) 1.1749 + // 1.1750 + // Additionally, on ppc64 we must convert integers to longs in the C 1.1751 + // signature. We do this in advance in order to have no trouble with 1.1752 + // indexes into the bt-arrays. 1.1753 + // So convert the signature and registers now, and adjust the total number 1.1754 + // of in-arguments accordingly. 1.1755 + int i2l_argcnt = convert_ints_to_longints_argcnt(total_in_args, in_sig_bt); // PPC64: pass ints as longs. 1.1756 + 1.1757 + // Calculate the total number of C arguments and create arrays for the 1.1758 + // signature and the outgoing registers. 1.1759 + // On ppc64, we have two arrays for the outgoing registers, because 1.1760 + // some floating-point arguments must be passed in registers _and_ 1.1761 + // in stack locations. 1.1762 + bool method_is_static = method->is_static(); 1.1763 + int total_c_args = i2l_argcnt; 1.1764 + 1.1765 + if (!is_critical_native) { 1.1766 + int n_hidden_args = method_is_static ? 2 : 1; 1.1767 + total_c_args += n_hidden_args; 1.1768 + } else { 1.1769 + // No JNIEnv*, no this*, but unpacked arrays (base+length). 1.1770 + for (int i = 0; i < total_in_args; i++) { 1.1771 + if (in_sig_bt[i] == T_ARRAY) { 1.1772 + total_c_args += 2; // PPC64: T_LONG, T_INT, T_ADDRESS (see convert_ints_to_longints and c_calling_convention) 1.1773 + } 1.1774 + } 1.1775 + } 1.1776 + 1.1777 + BasicType *out_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_c_args); 1.1778 + VMRegPair *out_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_c_args); 1.1779 + VMRegPair *out_regs2 = NEW_RESOURCE_ARRAY(VMRegPair, total_c_args); 1.1780 + BasicType* in_elem_bt = NULL; 1.1781 + 1.1782 + // Create the signature for the C call: 1.1783 + // 1) add the JNIEnv* 1.1784 + // 2) add the class if the method is static 1.1785 + // 3) copy the rest of the incoming signature (shifted by the number of 1.1786 + // hidden arguments). 1.1787 + 1.1788 + int argc = 0; 1.1789 + if (!is_critical_native) { 1.1790 + convert_ints_to_longints(i2l_argcnt, total_in_args, in_sig_bt, in_regs); // PPC64: pass ints as longs. 1.1791 + 1.1792 + out_sig_bt[argc++] = T_ADDRESS; 1.1793 + if (method->is_static()) { 1.1794 + out_sig_bt[argc++] = T_OBJECT; 1.1795 + } 1.1796 + 1.1797 + for (int i = 0; i < total_in_args ; i++ ) { 1.1798 + out_sig_bt[argc++] = in_sig_bt[i]; 1.1799 + } 1.1800 + } else { 1.1801 + Thread* THREAD = Thread::current(); 1.1802 + in_elem_bt = NEW_RESOURCE_ARRAY(BasicType, i2l_argcnt); 1.1803 + SignatureStream ss(method->signature()); 1.1804 + int o = 0; 1.1805 + for (int i = 0; i < total_in_args ; i++, o++) { 1.1806 + if (in_sig_bt[i] == T_ARRAY) { 1.1807 + // Arrays are passed as int, elem* pair 1.1808 + Symbol* atype = ss.as_symbol(CHECK_NULL); 1.1809 + const char* at = atype->as_C_string(); 1.1810 + if (strlen(at) == 2) { 1.1811 + assert(at[0] == '[', "must be"); 1.1812 + switch (at[1]) { 1.1813 + case 'B': in_elem_bt[o] = T_BYTE; break; 1.1814 + case 'C': in_elem_bt[o] = T_CHAR; break; 1.1815 + case 'D': in_elem_bt[o] = T_DOUBLE; break; 1.1816 + case 'F': in_elem_bt[o] = T_FLOAT; break; 1.1817 + case 'I': in_elem_bt[o] = T_INT; break; 1.1818 + case 'J': in_elem_bt[o] = T_LONG; break; 1.1819 + case 'S': in_elem_bt[o] = T_SHORT; break; 1.1820 + case 'Z': in_elem_bt[o] = T_BOOLEAN; break; 1.1821 + default: ShouldNotReachHere(); 1.1822 + } 1.1823 + } 1.1824 + } else { 1.1825 + in_elem_bt[o] = T_VOID; 1.1826 + switch(in_sig_bt[i]) { // PPC64: pass ints as longs. 1.1827 + case T_BOOLEAN: 1.1828 + case T_CHAR: 1.1829 + case T_BYTE: 1.1830 + case T_SHORT: 1.1831 + case T_INT: in_elem_bt[++o] = T_VOID; break; 1.1832 + default: break; 1.1833 + } 1.1834 + } 1.1835 + if (in_sig_bt[i] != T_VOID) { 1.1836 + assert(in_sig_bt[i] == ss.type(), "must match"); 1.1837 + ss.next(); 1.1838 + } 1.1839 + } 1.1840 + assert(i2l_argcnt==o, "must match"); 1.1841 + 1.1842 + convert_ints_to_longints(i2l_argcnt, total_in_args, in_sig_bt, in_regs); // PPC64: pass ints as longs. 1.1843 + 1.1844 + for (int i = 0; i < total_in_args ; i++ ) { 1.1845 + if (in_sig_bt[i] == T_ARRAY) { 1.1846 + // Arrays are passed as int, elem* pair. 1.1847 + out_sig_bt[argc++] = T_LONG; // PPC64: pass ints as longs. 1.1848 + out_sig_bt[argc++] = T_INT; 1.1849 + out_sig_bt[argc++] = T_ADDRESS; 1.1850 + } else { 1.1851 + out_sig_bt[argc++] = in_sig_bt[i]; 1.1852 + } 1.1853 + } 1.1854 + } 1.1855 + 1.1856 + 1.1857 + // Compute the wrapper's frame size. 1.1858 + // -------------------------------------------------------------------------- 1.1859 + 1.1860 + // Now figure out where the args must be stored and how much stack space 1.1861 + // they require. 1.1862 + // 1.1863 + // Compute framesize for the wrapper. We need to handlize all oops in 1.1864 + // incoming registers. 1.1865 + // 1.1866 + // Calculate the total number of stack slots we will need: 1.1867 + // 1) abi requirements 1.1868 + // 2) outgoing arguments 1.1869 + // 3) space for inbound oop handle area 1.1870 + // 4) space for handlizing a klass if static method 1.1871 + // 5) space for a lock if synchronized method 1.1872 + // 6) workspace for saving return values, int <-> float reg moves, etc. 1.1873 + // 7) alignment 1.1874 + // 1.1875 + // Layout of the native wrapper frame: 1.1876 + // (stack grows upwards, memory grows downwards) 1.1877 + // 1.1878 + // NW [ABI_112] <-- 1) R1_SP 1.1879 + // [outgoing arguments] <-- 2) R1_SP + out_arg_slot_offset 1.1880 + // [oopHandle area] <-- 3) R1_SP + oop_handle_offset (save area for critical natives) 1.1881 + // klass <-- 4) R1_SP + klass_offset 1.1882 + // lock <-- 5) R1_SP + lock_offset 1.1883 + // [workspace] <-- 6) R1_SP + workspace_offset 1.1884 + // [alignment] (optional) <-- 7) 1.1885 + // caller [JIT_TOP_ABI_48] <-- r_callers_sp 1.1886 + // 1.1887 + // - *_slot_offset Indicates offset from SP in number of stack slots. 1.1888 + // - *_offset Indicates offset from SP in bytes. 1.1889 + 1.1890 + int stack_slots = c_calling_convention(out_sig_bt, out_regs, out_regs2, total_c_args) // 1+2) 1.1891 + + SharedRuntime::out_preserve_stack_slots(); // See c_calling_convention. 1.1892 + 1.1893 + // Now the space for the inbound oop handle area. 1.1894 + int total_save_slots = num_java_iarg_registers * VMRegImpl::slots_per_word; 1.1895 + if (is_critical_native) { 1.1896 + // Critical natives may have to call out so they need a save area 1.1897 + // for register arguments. 1.1898 + int double_slots = 0; 1.1899 + int single_slots = 0; 1.1900 + for (int i = 0; i < total_in_args; i++) { 1.1901 + if (in_regs[i].first()->is_Register()) { 1.1902 + const Register reg = in_regs[i].first()->as_Register(); 1.1903 + switch (in_sig_bt[i]) { 1.1904 + case T_BOOLEAN: 1.1905 + case T_BYTE: 1.1906 + case T_SHORT: 1.1907 + case T_CHAR: 1.1908 + case T_INT: /*single_slots++;*/ break; // PPC64: pass ints as longs. 1.1909 + case T_ARRAY: 1.1910 + case T_LONG: double_slots++; break; 1.1911 + default: ShouldNotReachHere(); 1.1912 + } 1.1913 + } else if (in_regs[i].first()->is_FloatRegister()) { 1.1914 + switch (in_sig_bt[i]) { 1.1915 + case T_FLOAT: single_slots++; break; 1.1916 + case T_DOUBLE: double_slots++; break; 1.1917 + default: ShouldNotReachHere(); 1.1918 + } 1.1919 + } 1.1920 + } 1.1921 + total_save_slots = double_slots * 2 + round_to(single_slots, 2); // round to even 1.1922 + } 1.1923 + 1.1924 + int oop_handle_slot_offset = stack_slots; 1.1925 + stack_slots += total_save_slots; // 3) 1.1926 + 1.1927 + int klass_slot_offset = 0; 1.1928 + int klass_offset = -1; 1.1929 + if (method_is_static && !is_critical_native) { // 4) 1.1930 + klass_slot_offset = stack_slots; 1.1931 + klass_offset = klass_slot_offset * VMRegImpl::stack_slot_size; 1.1932 + stack_slots += VMRegImpl::slots_per_word; 1.1933 + } 1.1934 + 1.1935 + int lock_slot_offset = 0; 1.1936 + int lock_offset = -1; 1.1937 + if (method->is_synchronized()) { // 5) 1.1938 + lock_slot_offset = stack_slots; 1.1939 + lock_offset = lock_slot_offset * VMRegImpl::stack_slot_size; 1.1940 + stack_slots += VMRegImpl::slots_per_word; 1.1941 + } 1.1942 + 1.1943 + int workspace_slot_offset = stack_slots; // 6) 1.1944 + stack_slots += 2; 1.1945 + 1.1946 + // Now compute actual number of stack words we need. 1.1947 + // Rounding to make stack properly aligned. 1.1948 + stack_slots = round_to(stack_slots, // 7) 1.1949 + frame::alignment_in_bytes / VMRegImpl::stack_slot_size); 1.1950 + int frame_size_in_bytes = stack_slots * VMRegImpl::stack_slot_size; 1.1951 + 1.1952 + 1.1953 + // Now we can start generating code. 1.1954 + // -------------------------------------------------------------------------- 1.1955 + 1.1956 + intptr_t start_pc = (intptr_t)__ pc(); 1.1957 + intptr_t vep_start_pc; 1.1958 + intptr_t frame_done_pc; 1.1959 + intptr_t oopmap_pc; 1.1960 + 1.1961 + Label ic_miss; 1.1962 + Label handle_pending_exception; 1.1963 + 1.1964 + Register r_callers_sp = R21; 1.1965 + Register r_temp_1 = R22; 1.1966 + Register r_temp_2 = R23; 1.1967 + Register r_temp_3 = R24; 1.1968 + Register r_temp_4 = R25; 1.1969 + Register r_temp_5 = R26; 1.1970 + Register r_temp_6 = R27; 1.1971 + Register r_return_pc = R28; 1.1972 + 1.1973 + Register r_carg1_jnienv = noreg; 1.1974 + Register r_carg2_classorobject = noreg; 1.1975 + if (!is_critical_native) { 1.1976 + r_carg1_jnienv = out_regs[0].first()->as_Register(); 1.1977 + r_carg2_classorobject = out_regs[1].first()->as_Register(); 1.1978 + } 1.1979 + 1.1980 + 1.1981 + // Generate the Unverified Entry Point (UEP). 1.1982 + // -------------------------------------------------------------------------- 1.1983 + assert(start_pc == (intptr_t)__ pc(), "uep must be at start"); 1.1984 + 1.1985 + // Check ic: object class == cached class? 1.1986 + if (!method_is_static) { 1.1987 + Register ic = as_Register(Matcher::inline_cache_reg_encode()); 1.1988 + Register receiver_klass = r_temp_1; 1.1989 + 1.1990 + __ cmpdi(CCR0, R3_ARG1, 0); 1.1991 + __ beq(CCR0, ic_miss); 1.1992 + __ verify_oop(R3_ARG1); 1.1993 + __ load_klass(receiver_klass, R3_ARG1); 1.1994 + 1.1995 + __ cmpd(CCR0, receiver_klass, ic); 1.1996 + __ bne(CCR0, ic_miss); 1.1997 + } 1.1998 + 1.1999 + 1.2000 + // Generate the Verified Entry Point (VEP). 1.2001 + // -------------------------------------------------------------------------- 1.2002 + vep_start_pc = (intptr_t)__ pc(); 1.2003 + 1.2004 + __ save_LR_CR(r_temp_1); 1.2005 + __ generate_stack_overflow_check(frame_size_in_bytes); // Check before creating frame. 1.2006 + __ mr(r_callers_sp, R1_SP); // Remember frame pointer. 1.2007 + __ push_frame(frame_size_in_bytes, r_temp_1); // Push the c2n adapter's frame. 1.2008 + frame_done_pc = (intptr_t)__ pc(); 1.2009 + 1.2010 + // Native nmethod wrappers never take possesion of the oop arguments. 1.2011 + // So the caller will gc the arguments. 1.2012 + // The only thing we need an oopMap for is if the call is static. 1.2013 + // 1.2014 + // An OopMap for lock (and class if static), and one for the VM call itself. 1.2015 + OopMapSet *oop_maps = new OopMapSet(); 1.2016 + OopMap *oop_map = new OopMap(stack_slots * 2, 0 /* arg_slots*/); 1.2017 + 1.2018 + if (is_critical_native) { 1.2019 + check_needs_gc_for_critical_native(masm, stack_slots, total_in_args, oop_handle_slot_offset, oop_maps, in_regs, in_sig_bt, r_temp_1); 1.2020 + } 1.2021 + 1.2022 + // Move arguments from register/stack to register/stack. 1.2023 + // -------------------------------------------------------------------------- 1.2024 + // 1.2025 + // We immediately shuffle the arguments so that for any vm call we have 1.2026 + // to make from here on out (sync slow path, jvmti, etc.) we will have 1.2027 + // captured the oops from our caller and have a valid oopMap for them. 1.2028 + // 1.2029 + // Natives require 1 or 2 extra arguments over the normal ones: the JNIEnv* 1.2030 + // (derived from JavaThread* which is in R16_thread) and, if static, 1.2031 + // the class mirror instead of a receiver. This pretty much guarantees that 1.2032 + // register layout will not match. We ignore these extra arguments during 1.2033 + // the shuffle. The shuffle is described by the two calling convention 1.2034 + // vectors we have in our possession. We simply walk the java vector to 1.2035 + // get the source locations and the c vector to get the destinations. 1.2036 + 1.2037 + // Record sp-based slot for receiver on stack for non-static methods. 1.2038 + int receiver_offset = -1; 1.2039 + 1.2040 + // We move the arguments backward because the floating point registers 1.2041 + // destination will always be to a register with a greater or equal 1.2042 + // register number or the stack. 1.2043 + // in is the index of the incoming Java arguments 1.2044 + // out is the index of the outgoing C arguments 1.2045 + 1.2046 +#ifdef ASSERT 1.2047 + bool reg_destroyed[RegisterImpl::number_of_registers]; 1.2048 + bool freg_destroyed[FloatRegisterImpl::number_of_registers]; 1.2049 + for (int r = 0 ; r < RegisterImpl::number_of_registers ; r++) { 1.2050 + reg_destroyed[r] = false; 1.2051 + } 1.2052 + for (int f = 0 ; f < FloatRegisterImpl::number_of_registers ; f++) { 1.2053 + freg_destroyed[f] = false; 1.2054 + } 1.2055 +#endif // ASSERT 1.2056 + 1.2057 + for (int in = total_in_args - 1, out = total_c_args - 1; in >= 0 ; in--, out--) { 1.2058 + 1.2059 +#ifdef ASSERT 1.2060 + if (in_regs[in].first()->is_Register()) { 1.2061 + assert(!reg_destroyed[in_regs[in].first()->as_Register()->encoding()], "ack!"); 1.2062 + } else if (in_regs[in].first()->is_FloatRegister()) { 1.2063 + assert(!freg_destroyed[in_regs[in].first()->as_FloatRegister()->encoding()], "ack!"); 1.2064 + } 1.2065 + if (out_regs[out].first()->is_Register()) { 1.2066 + reg_destroyed[out_regs[out].first()->as_Register()->encoding()] = true; 1.2067 + } else if (out_regs[out].first()->is_FloatRegister()) { 1.2068 + freg_destroyed[out_regs[out].first()->as_FloatRegister()->encoding()] = true; 1.2069 + } 1.2070 + if (out_regs2[out].first()->is_Register()) { 1.2071 + reg_destroyed[out_regs2[out].first()->as_Register()->encoding()] = true; 1.2072 + } else if (out_regs2[out].first()->is_FloatRegister()) { 1.2073 + freg_destroyed[out_regs2[out].first()->as_FloatRegister()->encoding()] = true; 1.2074 + } 1.2075 +#endif // ASSERT 1.2076 + 1.2077 + switch (in_sig_bt[in]) { 1.2078 + case T_BOOLEAN: 1.2079 + case T_CHAR: 1.2080 + case T_BYTE: 1.2081 + case T_SHORT: 1.2082 + case T_INT: 1.2083 + guarantee(in > 0 && in_sig_bt[in-1] == T_LONG, 1.2084 + "expecting type (T_LONG,bt) for bt in {T_BOOLEAN, T_CHAR, T_BYTE, T_SHORT, T_INT}"); 1.2085 + break; 1.2086 + case T_LONG: 1.2087 + if (in_sig_bt[in+1] == T_VOID) { 1.2088 + long_move(masm, in_regs[in], out_regs[out], r_callers_sp, r_temp_1); 1.2089 + } else { 1.2090 + guarantee(in_sig_bt[in+1] == T_BOOLEAN || in_sig_bt[in+1] == T_CHAR || 1.2091 + in_sig_bt[in+1] == T_BYTE || in_sig_bt[in+1] == T_SHORT || 1.2092 + in_sig_bt[in+1] == T_INT, 1.2093 + "expecting type (T_LONG,bt) for bt in {T_BOOLEAN, T_CHAR, T_BYTE, T_SHORT, T_INT}"); 1.2094 + int_move(masm, in_regs[in], out_regs[out], r_callers_sp, r_temp_1); 1.2095 + } 1.2096 + break; 1.2097 + case T_ARRAY: 1.2098 + if (is_critical_native) { 1.2099 + int body_arg = out; 1.2100 + out -= 2; // Point to length arg. PPC64: pass ints as longs. 1.2101 + unpack_array_argument(masm, in_regs[in], in_elem_bt[in], out_regs[body_arg], out_regs[out], 1.2102 + r_callers_sp, r_temp_1, r_temp_2); 1.2103 + break; 1.2104 + } 1.2105 + case T_OBJECT: 1.2106 + assert(!is_critical_native, "no oop arguments"); 1.2107 + object_move(masm, stack_slots, 1.2108 + oop_map, oop_handle_slot_offset, 1.2109 + ((in == 0) && (!method_is_static)), &receiver_offset, 1.2110 + in_regs[in], out_regs[out], 1.2111 + r_callers_sp, r_temp_1, r_temp_2); 1.2112 + break; 1.2113 + case T_VOID: 1.2114 + break; 1.2115 + case T_FLOAT: 1.2116 + float_move(masm, in_regs[in], out_regs[out], r_callers_sp, r_temp_1); 1.2117 + if (out_regs2[out].first()->is_valid()) { 1.2118 + float_move(masm, in_regs[in], out_regs2[out], r_callers_sp, r_temp_1); 1.2119 + } 1.2120 + break; 1.2121 + case T_DOUBLE: 1.2122 + double_move(masm, in_regs[in], out_regs[out], r_callers_sp, r_temp_1); 1.2123 + if (out_regs2[out].first()->is_valid()) { 1.2124 + double_move(masm, in_regs[in], out_regs2[out], r_callers_sp, r_temp_1); 1.2125 + } 1.2126 + break; 1.2127 + case T_ADDRESS: 1.2128 + fatal("found type (T_ADDRESS) in java args"); 1.2129 + break; 1.2130 + default: 1.2131 + ShouldNotReachHere(); 1.2132 + break; 1.2133 + } 1.2134 + } 1.2135 + 1.2136 + // Pre-load a static method's oop into ARG2. 1.2137 + // Used both by locking code and the normal JNI call code. 1.2138 + if (method_is_static && !is_critical_native) { 1.2139 + __ set_oop_constant(JNIHandles::make_local(method->method_holder()->java_mirror()), 1.2140 + r_carg2_classorobject); 1.2141 + 1.2142 + // Now handlize the static class mirror in carg2. It's known not-null. 1.2143 + __ std(r_carg2_classorobject, klass_offset, R1_SP); 1.2144 + oop_map->set_oop(VMRegImpl::stack2reg(klass_slot_offset)); 1.2145 + __ addi(r_carg2_classorobject, R1_SP, klass_offset); 1.2146 + } 1.2147 + 1.2148 + // Get JNIEnv* which is first argument to native. 1.2149 + if (!is_critical_native) { 1.2150 + __ addi(r_carg1_jnienv, R16_thread, in_bytes(JavaThread::jni_environment_offset())); 1.2151 + } 1.2152 + 1.2153 + // NOTE: 1.2154 + // 1.2155 + // We have all of the arguments setup at this point. 1.2156 + // We MUST NOT touch any outgoing regs from this point on. 1.2157 + // So if we must call out we must push a new frame. 1.2158 + 1.2159 + // Get current pc for oopmap, and load it patchable relative to global toc. 1.2160 + oopmap_pc = (intptr_t) __ pc(); 1.2161 + __ calculate_address_from_global_toc(r_return_pc, (address)oopmap_pc, true, true, true, true); 1.2162 + 1.2163 + // We use the same pc/oopMap repeatedly when we call out. 1.2164 + oop_maps->add_gc_map(oopmap_pc - start_pc, oop_map); 1.2165 + 1.2166 + // r_return_pc now has the pc loaded that we will use when we finally call 1.2167 + // to native. 1.2168 + 1.2169 + // Make sure that thread is non-volatile; it crosses a bunch of VM calls below. 1.2170 + assert(R16_thread->is_nonvolatile(), "thread must be in non-volatile register"); 1.2171 + 1.2172 + 1.2173 +# if 0 1.2174 + // DTrace method entry 1.2175 +# endif 1.2176 + 1.2177 + // Lock a synchronized method. 1.2178 + // -------------------------------------------------------------------------- 1.2179 + 1.2180 + if (method->is_synchronized()) { 1.2181 + assert(!is_critical_native, "unhandled"); 1.2182 + ConditionRegister r_flag = CCR1; 1.2183 + Register r_oop = r_temp_4; 1.2184 + const Register r_box = r_temp_5; 1.2185 + Label done, locked; 1.2186 + 1.2187 + // Load the oop for the object or class. r_carg2_classorobject contains 1.2188 + // either the handlized oop from the incoming arguments or the handlized 1.2189 + // class mirror (if the method is static). 1.2190 + __ ld(r_oop, 0, r_carg2_classorobject); 1.2191 + 1.2192 + // Get the lock box slot's address. 1.2193 + __ addi(r_box, R1_SP, lock_offset); 1.2194 + 1.2195 +# ifdef ASSERT 1.2196 + if (UseBiasedLocking) { 1.2197 + // Making the box point to itself will make it clear it went unused 1.2198 + // but also be obviously invalid. 1.2199 + __ std(r_box, 0, r_box); 1.2200 + } 1.2201 +# endif // ASSERT 1.2202 + 1.2203 + // Try fastpath for locking. 1.2204 + // fast_lock kills r_temp_1, r_temp_2, r_temp_3. 1.2205 + __ compiler_fast_lock_object(r_flag, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3); 1.2206 + __ beq(r_flag, locked); 1.2207 + 1.2208 + // None of the above fast optimizations worked so we have to get into the 1.2209 + // slow case of monitor enter. Inline a special case of call_VM that 1.2210 + // disallows any pending_exception. 1.2211 + 1.2212 + // Save argument registers and leave room for C-compatible ABI_112. 1.2213 + int frame_size = frame::abi_112_size + 1.2214 + round_to(total_c_args * wordSize, frame::alignment_in_bytes); 1.2215 + __ mr(R11_scratch1, R1_SP); 1.2216 + RegisterSaver::push_frame_and_save_argument_registers(masm, R12_scratch2, frame_size, total_c_args, out_regs, out_regs2); 1.2217 + 1.2218 + // Do the call. 1.2219 + __ set_last_Java_frame(R11_scratch1, r_return_pc); 1.2220 + assert(r_return_pc->is_nonvolatile(), "expecting return pc to be in non-volatile register"); 1.2221 + __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_locking_C), r_oop, r_box, R16_thread); 1.2222 + __ reset_last_Java_frame(); 1.2223 + 1.2224 + RegisterSaver::restore_argument_registers_and_pop_frame(masm, frame_size, total_c_args, out_regs, out_regs2); 1.2225 + 1.2226 + __ asm_assert_mem8_is_zero(thread_(pending_exception), 1.2227 + "no pending exception allowed on exit from SharedRuntime::complete_monitor_locking_C", 0); 1.2228 + 1.2229 + __ bind(locked); 1.2230 + } 1.2231 + 1.2232 + 1.2233 + // Publish thread state 1.2234 + // -------------------------------------------------------------------------- 1.2235 + 1.2236 + // Use that pc we placed in r_return_pc a while back as the current frame anchor. 1.2237 + __ set_last_Java_frame(R1_SP, r_return_pc); 1.2238 + 1.2239 + // Transition from _thread_in_Java to _thread_in_native. 1.2240 + __ li(R0, _thread_in_native); 1.2241 + __ release(); 1.2242 + // TODO: PPC port assert(4 == JavaThread::sz_thread_state(), "unexpected field size"); 1.2243 + __ stw(R0, thread_(thread_state)); 1.2244 + if (UseMembar) { 1.2245 + __ fence(); 1.2246 + } 1.2247 + 1.2248 + 1.2249 + // The JNI call 1.2250 + // -------------------------------------------------------------------------- 1.2251 + 1.2252 + FunctionDescriptor* fd_native_method = (FunctionDescriptor*) native_func; 1.2253 + __ call_c(fd_native_method, relocInfo::runtime_call_type); 1.2254 + 1.2255 + 1.2256 + // Now, we are back from the native code. 1.2257 + 1.2258 + 1.2259 + // Unpack the native result. 1.2260 + // -------------------------------------------------------------------------- 1.2261 + 1.2262 + // For int-types, we do any needed sign-extension required. 1.2263 + // Care must be taken that the return values (R3_RET and F1_RET) 1.2264 + // will survive any VM calls for blocking or unlocking. 1.2265 + // An OOP result (handle) is done specially in the slow-path code. 1.2266 + 1.2267 + switch (ret_type) { 1.2268 + case T_VOID: break; // Nothing to do! 1.2269 + case T_FLOAT: break; // Got it where we want it (unless slow-path). 1.2270 + case T_DOUBLE: break; // Got it where we want it (unless slow-path). 1.2271 + case T_LONG: break; // Got it where we want it (unless slow-path). 1.2272 + case T_OBJECT: break; // Really a handle. 1.2273 + // Cannot de-handlize until after reclaiming jvm_lock. 1.2274 + case T_ARRAY: break; 1.2275 + 1.2276 + case T_BOOLEAN: { // 0 -> false(0); !0 -> true(1) 1.2277 + Label skip_modify; 1.2278 + __ cmpwi(CCR0, R3_RET, 0); 1.2279 + __ beq(CCR0, skip_modify); 1.2280 + __ li(R3_RET, 1); 1.2281 + __ bind(skip_modify); 1.2282 + break; 1.2283 + } 1.2284 + case T_BYTE: { // sign extension 1.2285 + __ extsb(R3_RET, R3_RET); 1.2286 + break; 1.2287 + } 1.2288 + case T_CHAR: { // unsigned result 1.2289 + __ andi(R3_RET, R3_RET, 0xffff); 1.2290 + break; 1.2291 + } 1.2292 + case T_SHORT: { // sign extension 1.2293 + __ extsh(R3_RET, R3_RET); 1.2294 + break; 1.2295 + } 1.2296 + case T_INT: // nothing to do 1.2297 + break; 1.2298 + default: 1.2299 + ShouldNotReachHere(); 1.2300 + break; 1.2301 + } 1.2302 + 1.2303 + 1.2304 + // Publish thread state 1.2305 + // -------------------------------------------------------------------------- 1.2306 + 1.2307 + // Switch thread to "native transition" state before reading the 1.2308 + // synchronization state. This additional state is necessary because reading 1.2309 + // and testing the synchronization state is not atomic w.r.t. GC, as this 1.2310 + // scenario demonstrates: 1.2311 + // - Java thread A, in _thread_in_native state, loads _not_synchronized 1.2312 + // and is preempted. 1.2313 + // - VM thread changes sync state to synchronizing and suspends threads 1.2314 + // for GC. 1.2315 + // - Thread A is resumed to finish this native method, but doesn't block 1.2316 + // here since it didn't see any synchronization in progress, and escapes. 1.2317 + 1.2318 + // Transition from _thread_in_native to _thread_in_native_trans. 1.2319 + __ li(R0, _thread_in_native_trans); 1.2320 + __ release(); 1.2321 + // TODO: PPC port assert(4 == JavaThread::sz_thread_state(), "unexpected field size"); 1.2322 + __ stw(R0, thread_(thread_state)); 1.2323 + 1.2324 + 1.2325 + // Must we block? 1.2326 + // -------------------------------------------------------------------------- 1.2327 + 1.2328 + // Block, if necessary, before resuming in _thread_in_Java state. 1.2329 + // In order for GC to work, don't clear the last_Java_sp until after blocking. 1.2330 + Label after_transition; 1.2331 + { 1.2332 + Label no_block, sync; 1.2333 + 1.2334 + if (os::is_MP()) { 1.2335 + if (UseMembar) { 1.2336 + // Force this write out before the read below. 1.2337 + __ fence(); 1.2338 + } else { 1.2339 + // Write serialization page so VM thread can do a pseudo remote membar. 1.2340 + // We use the current thread pointer to calculate a thread specific 1.2341 + // offset to write to within the page. This minimizes bus traffic 1.2342 + // due to cache line collision. 1.2343 + __ serialize_memory(R16_thread, r_temp_4, r_temp_5); 1.2344 + } 1.2345 + } 1.2346 + 1.2347 + Register sync_state_addr = r_temp_4; 1.2348 + Register sync_state = r_temp_5; 1.2349 + Register suspend_flags = r_temp_6; 1.2350 + 1.2351 + __ load_const(sync_state_addr, SafepointSynchronize::address_of_state(), /*temp*/ sync_state); 1.2352 + 1.2353 + // TODO: PPC port assert(4 == SafepointSynchronize::sz_state(), "unexpected field size"); 1.2354 + __ lwz(sync_state, 0, sync_state_addr); 1.2355 + 1.2356 + // TODO: PPC port assert(4 == Thread::sz_suspend_flags(), "unexpected field size"); 1.2357 + __ lwz(suspend_flags, thread_(suspend_flags)); 1.2358 + 1.2359 + __ acquire(); 1.2360 + 1.2361 + Label do_safepoint; 1.2362 + // No synchronization in progress nor yet synchronized. 1.2363 + __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized); 1.2364 + // Not suspended. 1.2365 + __ cmpwi(CCR1, suspend_flags, 0); 1.2366 + 1.2367 + __ bne(CCR0, sync); 1.2368 + __ beq(CCR1, no_block); 1.2369 + 1.2370 + // Block. Save any potential method result value before the operation and 1.2371 + // use a leaf call to leave the last_Java_frame setup undisturbed. Doing this 1.2372 + // lets us share the oopMap we used when we went native rather than create 1.2373 + // a distinct one for this pc. 1.2374 + __ bind(sync); 1.2375 + 1.2376 + address entry_point = is_critical_native 1.2377 + ? CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans_and_transition) 1.2378 + : CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans); 1.2379 + save_native_result(masm, ret_type, workspace_slot_offset); 1.2380 + __ call_VM_leaf(entry_point, R16_thread); 1.2381 + restore_native_result(masm, ret_type, workspace_slot_offset); 1.2382 + 1.2383 + if (is_critical_native) { 1.2384 + __ b(after_transition); // No thread state transition here. 1.2385 + } 1.2386 + __ bind(no_block); 1.2387 + } 1.2388 + 1.2389 + // Publish thread state. 1.2390 + // -------------------------------------------------------------------------- 1.2391 + 1.2392 + // Thread state is thread_in_native_trans. Any safepoint blocking has 1.2393 + // already happened so we can now change state to _thread_in_Java. 1.2394 + 1.2395 + // Transition from _thread_in_native_trans to _thread_in_Java. 1.2396 + __ li(R0, _thread_in_Java); 1.2397 + __ release(); 1.2398 + // TODO: PPC port assert(4 == JavaThread::sz_thread_state(), "unexpected field size"); 1.2399 + __ stw(R0, thread_(thread_state)); 1.2400 + if (UseMembar) { 1.2401 + __ fence(); 1.2402 + } 1.2403 + __ bind(after_transition); 1.2404 + 1.2405 + // Reguard any pages if necessary. 1.2406 + // -------------------------------------------------------------------------- 1.2407 + 1.2408 + Label no_reguard; 1.2409 + __ lwz(r_temp_1, thread_(stack_guard_state)); 1.2410 + __ cmpwi(CCR0, r_temp_1, JavaThread::stack_guard_yellow_disabled); 1.2411 + __ bne(CCR0, no_reguard); 1.2412 + 1.2413 + save_native_result(masm, ret_type, workspace_slot_offset); 1.2414 + __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)); 1.2415 + restore_native_result(masm, ret_type, workspace_slot_offset); 1.2416 + 1.2417 + __ bind(no_reguard); 1.2418 + 1.2419 + 1.2420 + // Unlock 1.2421 + // -------------------------------------------------------------------------- 1.2422 + 1.2423 + if (method->is_synchronized()) { 1.2424 + 1.2425 + ConditionRegister r_flag = CCR1; 1.2426 + const Register r_oop = r_temp_4; 1.2427 + const Register r_box = r_temp_5; 1.2428 + const Register r_exception = r_temp_6; 1.2429 + Label done; 1.2430 + 1.2431 + // Get oop and address of lock object box. 1.2432 + if (method_is_static) { 1.2433 + assert(klass_offset != -1, ""); 1.2434 + __ ld(r_oop, klass_offset, R1_SP); 1.2435 + } else { 1.2436 + assert(receiver_offset != -1, ""); 1.2437 + __ ld(r_oop, receiver_offset, R1_SP); 1.2438 + } 1.2439 + __ addi(r_box, R1_SP, lock_offset); 1.2440 + 1.2441 + // Try fastpath for unlocking. 1.2442 + __ compiler_fast_unlock_object(r_flag, r_oop, r_box, r_temp_1, r_temp_2, r_temp_3); 1.2443 + __ beq(r_flag, done); 1.2444 + 1.2445 + // Save and restore any potential method result value around the unlocking operation. 1.2446 + save_native_result(masm, ret_type, workspace_slot_offset); 1.2447 + 1.2448 + // Must save pending exception around the slow-path VM call. Since it's a 1.2449 + // leaf call, the pending exception (if any) can be kept in a register. 1.2450 + __ ld(r_exception, thread_(pending_exception)); 1.2451 + assert(r_exception->is_nonvolatile(), "exception register must be non-volatile"); 1.2452 + __ li(R0, 0); 1.2453 + __ std(R0, thread_(pending_exception)); 1.2454 + 1.2455 + // Slow case of monitor enter. 1.2456 + // Inline a special case of call_VM that disallows any pending_exception. 1.2457 + __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C), r_oop, r_box); 1.2458 + 1.2459 + __ asm_assert_mem8_is_zero(thread_(pending_exception), 1.2460 + "no pending exception allowed on exit from SharedRuntime::complete_monitor_unlocking_C", 0); 1.2461 + 1.2462 + restore_native_result(masm, ret_type, workspace_slot_offset); 1.2463 + 1.2464 + // Check_forward_pending_exception jump to forward_exception if any pending 1.2465 + // exception is set. The forward_exception routine expects to see the 1.2466 + // exception in pending_exception and not in a register. Kind of clumsy, 1.2467 + // since all folks who branch to forward_exception must have tested 1.2468 + // pending_exception first and hence have it in a register already. 1.2469 + __ std(r_exception, thread_(pending_exception)); 1.2470 + 1.2471 + __ bind(done); 1.2472 + } 1.2473 + 1.2474 +# if 0 1.2475 + // DTrace method exit 1.2476 +# endif 1.2477 + 1.2478 + // Clear "last Java frame" SP and PC. 1.2479 + // -------------------------------------------------------------------------- 1.2480 + 1.2481 + __ reset_last_Java_frame(); 1.2482 + 1.2483 + // Unpack oop result. 1.2484 + // -------------------------------------------------------------------------- 1.2485 + 1.2486 + if (ret_type == T_OBJECT || ret_type == T_ARRAY) { 1.2487 + Label skip_unboxing; 1.2488 + __ cmpdi(CCR0, R3_RET, 0); 1.2489 + __ beq(CCR0, skip_unboxing); 1.2490 + __ ld(R3_RET, 0, R3_RET); 1.2491 + __ bind(skip_unboxing); 1.2492 + __ verify_oop(R3_RET); 1.2493 + } 1.2494 + 1.2495 + 1.2496 + // Reset handle block. 1.2497 + // -------------------------------------------------------------------------- 1.2498 + if (!is_critical_native) { 1.2499 + __ ld(r_temp_1, thread_(active_handles)); 1.2500 + // TODO: PPC port assert(4 == JNIHandleBlock::top_size_in_bytes(), "unexpected field size"); 1.2501 + __ li(r_temp_2, 0); 1.2502 + __ stw(r_temp_2, JNIHandleBlock::top_offset_in_bytes(), r_temp_1); 1.2503 + 1.2504 + 1.2505 + // Check for pending exceptions. 1.2506 + // -------------------------------------------------------------------------- 1.2507 + __ ld(r_temp_2, thread_(pending_exception)); 1.2508 + __ cmpdi(CCR0, r_temp_2, 0); 1.2509 + __ bne(CCR0, handle_pending_exception); 1.2510 + } 1.2511 + 1.2512 + // Return 1.2513 + // -------------------------------------------------------------------------- 1.2514 + 1.2515 + __ pop_frame(); 1.2516 + __ restore_LR_CR(R11); 1.2517 + __ blr(); 1.2518 + 1.2519 + 1.2520 + // Handler for pending exceptions (out-of-line). 1.2521 + // -------------------------------------------------------------------------- 1.2522 + 1.2523 + // Since this is a native call, we know the proper exception handler 1.2524 + // is the empty function. We just pop this frame and then jump to 1.2525 + // forward_exception_entry. 1.2526 + if (!is_critical_native) { 1.2527 + __ align(InteriorEntryAlignment); 1.2528 + __ bind(handle_pending_exception); 1.2529 + 1.2530 + __ pop_frame(); 1.2531 + __ restore_LR_CR(R11); 1.2532 + __ b64_patchable((address)StubRoutines::forward_exception_entry(), 1.2533 + relocInfo::runtime_call_type); 1.2534 + } 1.2535 + 1.2536 + // Handler for a cache miss (out-of-line). 1.2537 + // -------------------------------------------------------------------------- 1.2538 + 1.2539 + if (!method_is_static) { 1.2540 + __ align(InteriorEntryAlignment); 1.2541 + __ bind(ic_miss); 1.2542 + 1.2543 + __ b64_patchable((address)SharedRuntime::get_ic_miss_stub(), 1.2544 + relocInfo::runtime_call_type); 1.2545 + } 1.2546 + 1.2547 + // Done. 1.2548 + // -------------------------------------------------------------------------- 1.2549 + 1.2550 + __ flush(); 1.2551 + 1.2552 + nmethod *nm = nmethod::new_native_nmethod(method, 1.2553 + compile_id, 1.2554 + masm->code(), 1.2555 + vep_start_pc-start_pc, 1.2556 + frame_done_pc-start_pc, 1.2557 + stack_slots / VMRegImpl::slots_per_word, 1.2558 + (method_is_static ? in_ByteSize(klass_offset) : in_ByteSize(receiver_offset)), 1.2559 + in_ByteSize(lock_offset), 1.2560 + oop_maps); 1.2561 + 1.2562 + if (is_critical_native) { 1.2563 + nm->set_lazy_critical_native(true); 1.2564 + } 1.2565 + 1.2566 + return nm; 1.2567 +#else 1.2568 + ShouldNotReachHere(); 1.2569 + return NULL; 1.2570 +#endif // COMPILER2 1.2571 +} 1.2572 + 1.2573 +// This function returns the adjust size (in number of words) to a c2i adapter 1.2574 +// activation for use during deoptimization. 1.2575 +int Deoptimization::last_frame_adjust(int callee_parameters, int callee_locals) { 1.2576 + return round_to((callee_locals - callee_parameters) * Interpreter::stackElementWords, frame::alignment_in_bytes); 1.2577 +} 1.2578 + 1.2579 +uint SharedRuntime::out_preserve_stack_slots() { 1.2580 +#ifdef COMPILER2 1.2581 + return frame::jit_out_preserve_size / VMRegImpl::stack_slot_size; 1.2582 +#else 1.2583 + return 0; 1.2584 +#endif 1.2585 +} 1.2586 + 1.2587 +#ifdef COMPILER2 1.2588 +// Frame generation for deopt and uncommon trap blobs. 1.2589 +static void push_skeleton_frame(MacroAssembler* masm, bool deopt, 1.2590 + /* Read */ 1.2591 + Register unroll_block_reg, 1.2592 + /* Update */ 1.2593 + Register frame_sizes_reg, 1.2594 + Register number_of_frames_reg, 1.2595 + Register pcs_reg, 1.2596 + /* Invalidate */ 1.2597 + Register frame_size_reg, 1.2598 + Register pc_reg) { 1.2599 + 1.2600 + __ ld(pc_reg, 0, pcs_reg); 1.2601 + __ ld(frame_size_reg, 0, frame_sizes_reg); 1.2602 + __ std(pc_reg, _abi(lr), R1_SP); 1.2603 + __ push_frame(frame_size_reg, R0/*tmp*/); 1.2604 + __ std(R1_SP, _parent_ijava_frame_abi(initial_caller_sp), R1_SP); 1.2605 + __ addi(number_of_frames_reg, number_of_frames_reg, -1); 1.2606 + __ addi(frame_sizes_reg, frame_sizes_reg, wordSize); 1.2607 + __ addi(pcs_reg, pcs_reg, wordSize); 1.2608 +} 1.2609 + 1.2610 +// Loop through the UnrollBlock info and create new frames. 1.2611 +static void push_skeleton_frames(MacroAssembler* masm, bool deopt, 1.2612 + /* read */ 1.2613 + Register unroll_block_reg, 1.2614 + /* invalidate */ 1.2615 + Register frame_sizes_reg, 1.2616 + Register number_of_frames_reg, 1.2617 + Register pcs_reg, 1.2618 + Register frame_size_reg, 1.2619 + Register pc_reg) { 1.2620 + Label loop; 1.2621 + 1.2622 + // _number_of_frames is of type int (deoptimization.hpp) 1.2623 + __ lwa(number_of_frames_reg, 1.2624 + Deoptimization::UnrollBlock::number_of_frames_offset_in_bytes(), 1.2625 + unroll_block_reg); 1.2626 + __ ld(pcs_reg, 1.2627 + Deoptimization::UnrollBlock::frame_pcs_offset_in_bytes(), 1.2628 + unroll_block_reg); 1.2629 + __ ld(frame_sizes_reg, 1.2630 + Deoptimization::UnrollBlock::frame_sizes_offset_in_bytes(), 1.2631 + unroll_block_reg); 1.2632 + 1.2633 + // stack: (caller_of_deoptee, ...). 1.2634 + 1.2635 + // At this point we either have an interpreter frame or a compiled 1.2636 + // frame on top of stack. If it is a compiled frame we push a new c2i 1.2637 + // adapter here 1.2638 + 1.2639 + // Memorize top-frame stack-pointer. 1.2640 + __ mr(frame_size_reg/*old_sp*/, R1_SP); 1.2641 + 1.2642 + // Resize interpreter top frame OR C2I adapter. 1.2643 + 1.2644 + // At this moment, the top frame (which is the caller of the deoptee) is 1.2645 + // an interpreter frame or a newly pushed C2I adapter or an entry frame. 1.2646 + // The top frame has a TOP_IJAVA_FRAME_ABI and the frame contains the 1.2647 + // outgoing arguments. 1.2648 + // 1.2649 + // In order to push the interpreter frame for the deoptee, we need to 1.2650 + // resize the top frame such that we are able to place the deoptee's 1.2651 + // locals in the frame. 1.2652 + // Additionally, we have to turn the top frame's TOP_IJAVA_FRAME_ABI 1.2653 + // into a valid PARENT_IJAVA_FRAME_ABI. 1.2654 + 1.2655 + __ lwa(R11_scratch1, 1.2656 + Deoptimization::UnrollBlock::caller_adjustment_offset_in_bytes(), 1.2657 + unroll_block_reg); 1.2658 + __ neg(R11_scratch1, R11_scratch1); 1.2659 + 1.2660 + // R11_scratch1 contains size of locals for frame resizing. 1.2661 + // R12_scratch2 contains top frame's lr. 1.2662 + 1.2663 + // Resize frame by complete frame size prevents TOC from being 1.2664 + // overwritten by locals. A more stack space saving way would be 1.2665 + // to copy the TOC to its location in the new abi. 1.2666 + __ addi(R11_scratch1, R11_scratch1, - frame::parent_ijava_frame_abi_size); 1.2667 + 1.2668 + // now, resize the frame 1.2669 + __ resize_frame(R11_scratch1, pc_reg/*tmp*/); 1.2670 + 1.2671 + // In the case where we have resized a c2i frame above, the optional 1.2672 + // alignment below the locals has size 32 (why?). 1.2673 + __ std(R12_scratch2, _abi(lr), R1_SP); 1.2674 + 1.2675 + // Initialize initial_caller_sp. 1.2676 + __ std(frame_size_reg/*old_sp*/, _parent_ijava_frame_abi(initial_caller_sp), R1_SP); 1.2677 + 1.2678 +#ifdef ASSERT 1.2679 + // Make sure that there is at least one entry in the array. 1.2680 + __ cmpdi(CCR0, number_of_frames_reg, 0); 1.2681 + __ asm_assert_ne("array_size must be > 0", 0x205); 1.2682 +#endif 1.2683 + 1.2684 + // Now push the new interpreter frames. 1.2685 + // 1.2686 + __ bind(loop); 1.2687 + // Allocate a new frame, fill in the pc. 1.2688 + push_skeleton_frame(masm, deopt, 1.2689 + unroll_block_reg, 1.2690 + frame_sizes_reg, 1.2691 + number_of_frames_reg, 1.2692 + pcs_reg, 1.2693 + frame_size_reg, 1.2694 + pc_reg); 1.2695 + __ cmpdi(CCR0, number_of_frames_reg, 0); 1.2696 + __ bne(CCR0, loop); 1.2697 + 1.2698 + // Get the return address pointing into the frame manager. 1.2699 + __ ld(R0, 0, pcs_reg); 1.2700 + // Store it in the top interpreter frame. 1.2701 + __ std(R0, _abi(lr), R1_SP); 1.2702 + // Initialize frame_manager_lr of interpreter top frame. 1.2703 + __ std(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP); 1.2704 +} 1.2705 +#endif 1.2706 + 1.2707 +void SharedRuntime::generate_deopt_blob() { 1.2708 + // Allocate space for the code 1.2709 + ResourceMark rm; 1.2710 + // Setup code generation tools 1.2711 + CodeBuffer buffer("deopt_blob", 2048, 1024); 1.2712 + InterpreterMacroAssembler* masm = new InterpreterMacroAssembler(&buffer); 1.2713 + Label exec_mode_initialized; 1.2714 + int frame_size_in_words; 1.2715 + OopMap* map = NULL; 1.2716 + OopMapSet *oop_maps = new OopMapSet(); 1.2717 + 1.2718 + // size of ABI112 plus spill slots for R3_RET and F1_RET. 1.2719 + const int frame_size_in_bytes = frame::abi_112_spill_size; 1.2720 + const int frame_size_in_slots = frame_size_in_bytes / sizeof(jint); 1.2721 + int first_frame_size_in_bytes = 0; // frame size of "unpack frame" for call to fetch_unroll_info. 1.2722 + 1.2723 + const Register exec_mode_reg = R21_tmp1; 1.2724 + 1.2725 + const address start = __ pc(); 1.2726 + 1.2727 +#ifdef COMPILER2 1.2728 + // -------------------------------------------------------------------------- 1.2729 + // Prolog for non exception case! 1.2730 + 1.2731 + // We have been called from the deopt handler of the deoptee. 1.2732 + // 1.2733 + // deoptee: 1.2734 + // ... 1.2735 + // call X 1.2736 + // ... 1.2737 + // deopt_handler: call_deopt_stub 1.2738 + // cur. return pc --> ... 1.2739 + // 1.2740 + // So currently SR_LR points behind the call in the deopt handler. 1.2741 + // We adjust it such that it points to the start of the deopt handler. 1.2742 + // The return_pc has been stored in the frame of the deoptee and 1.2743 + // will replace the address of the deopt_handler in the call 1.2744 + // to Deoptimization::fetch_unroll_info below. 1.2745 + // We can't grab a free register here, because all registers may 1.2746 + // contain live values, so let the RegisterSaver do the adjustment 1.2747 + // of the return pc. 1.2748 + const int return_pc_adjustment_no_exception = -size_deopt_handler(); 1.2749 + 1.2750 + // Push the "unpack frame" 1.2751 + // Save everything in sight. 1.2752 + map = RegisterSaver::push_frame_abi112_and_save_live_registers(masm, 1.2753 + &first_frame_size_in_bytes, 1.2754 + /*generate_oop_map=*/ true, 1.2755 + return_pc_adjustment_no_exception, 1.2756 + RegisterSaver::return_pc_is_lr); 1.2757 + assert(map != NULL, "OopMap must have been created"); 1.2758 + 1.2759 + __ li(exec_mode_reg, Deoptimization::Unpack_deopt); 1.2760 + // Save exec mode for unpack_frames. 1.2761 + __ b(exec_mode_initialized); 1.2762 + 1.2763 + // -------------------------------------------------------------------------- 1.2764 + // Prolog for exception case 1.2765 + 1.2766 + // An exception is pending. 1.2767 + // We have been called with a return (interpreter) or a jump (exception blob). 1.2768 + // 1.2769 + // - R3_ARG1: exception oop 1.2770 + // - R4_ARG2: exception pc 1.2771 + 1.2772 + int exception_offset = __ pc() - start; 1.2773 + 1.2774 + BLOCK_COMMENT("Prolog for exception case"); 1.2775 + 1.2776 + // The RegisterSaves doesn't need to adjust the return pc for this situation. 1.2777 + const int return_pc_adjustment_exception = 0; 1.2778 + 1.2779 + // Push the "unpack frame". 1.2780 + // Save everything in sight. 1.2781 + assert(R4 == R4_ARG2, "exception pc must be in r4"); 1.2782 + RegisterSaver::push_frame_abi112_and_save_live_registers(masm, 1.2783 + &first_frame_size_in_bytes, 1.2784 + /*generate_oop_map=*/ false, 1.2785 + return_pc_adjustment_exception, 1.2786 + RegisterSaver::return_pc_is_r4); 1.2787 + 1.2788 + // Deopt during an exception. Save exec mode for unpack_frames. 1.2789 + __ li(exec_mode_reg, Deoptimization::Unpack_exception); 1.2790 + 1.2791 + // Store exception oop and pc in thread (location known to GC). 1.2792 + // This is needed since the call to "fetch_unroll_info()" may safepoint. 1.2793 + __ std(R3_ARG1, in_bytes(JavaThread::exception_oop_offset()), R16_thread); 1.2794 + __ std(R4_ARG2, in_bytes(JavaThread::exception_pc_offset()), R16_thread); 1.2795 + 1.2796 + // fall through 1.2797 + 1.2798 + // -------------------------------------------------------------------------- 1.2799 + __ BIND(exec_mode_initialized); 1.2800 + 1.2801 + { 1.2802 + const Register unroll_block_reg = R22_tmp2; 1.2803 + 1.2804 + // We need to set `last_Java_frame' because `fetch_unroll_info' will 1.2805 + // call `last_Java_frame()'. The value of the pc in the frame is not 1.2806 + // particularly important. It just needs to identify this blob. 1.2807 + __ set_last_Java_frame(R1_SP, noreg); 1.2808 + 1.2809 + // With EscapeAnalysis turned on, this call may safepoint! 1.2810 + __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::fetch_unroll_info), R16_thread); 1.2811 + address calls_return_pc = __ last_calls_return_pc(); 1.2812 + // Set an oopmap for the call site that describes all our saved registers. 1.2813 + oop_maps->add_gc_map(calls_return_pc - start, map); 1.2814 + 1.2815 + __ reset_last_Java_frame(); 1.2816 + // Save the return value. 1.2817 + __ mr(unroll_block_reg, R3_RET); 1.2818 + 1.2819 + // Restore only the result registers that have been saved 1.2820 + // by save_volatile_registers(...). 1.2821 + RegisterSaver::restore_result_registers(masm, first_frame_size_in_bytes); 1.2822 + 1.2823 + // In excp_deopt_mode, restore and clear exception oop which we 1.2824 + // stored in the thread during exception entry above. The exception 1.2825 + // oop will be the return value of this stub. 1.2826 + Label skip_restore_excp; 1.2827 + __ cmpdi(CCR0, exec_mode_reg, Deoptimization::Unpack_exception); 1.2828 + __ bne(CCR0, skip_restore_excp); 1.2829 + __ ld(R3_RET, in_bytes(JavaThread::exception_oop_offset()), R16_thread); 1.2830 + __ ld(R4_ARG2, in_bytes(JavaThread::exception_pc_offset()), R16_thread); 1.2831 + __ li(R0, 0); 1.2832 + __ std(R0, in_bytes(JavaThread::exception_pc_offset()), R16_thread); 1.2833 + __ std(R0, in_bytes(JavaThread::exception_oop_offset()), R16_thread); 1.2834 + __ BIND(skip_restore_excp); 1.2835 + 1.2836 + // reload narrro_oop_base 1.2837 + if (UseCompressedOops && Universe::narrow_oop_base() != 0) { 1.2838 + __ load_const_optimized(R30, Universe::narrow_oop_base()); 1.2839 + } 1.2840 + 1.2841 + __ pop_frame(); 1.2842 + 1.2843 + // stack: (deoptee, optional i2c, caller of deoptee, ...). 1.2844 + 1.2845 + // pop the deoptee's frame 1.2846 + __ pop_frame(); 1.2847 + 1.2848 + // stack: (caller_of_deoptee, ...). 1.2849 + 1.2850 + // Loop through the `UnrollBlock' info and create interpreter frames. 1.2851 + push_skeleton_frames(masm, true/*deopt*/, 1.2852 + unroll_block_reg, 1.2853 + R23_tmp3, 1.2854 + R24_tmp4, 1.2855 + R25_tmp5, 1.2856 + R26_tmp6, 1.2857 + R27_tmp7); 1.2858 + 1.2859 + // stack: (skeletal interpreter frame, ..., optional skeletal 1.2860 + // interpreter frame, optional c2i, caller of deoptee, ...). 1.2861 + } 1.2862 + 1.2863 + // push an `unpack_frame' taking care of float / int return values. 1.2864 + __ push_frame(frame_size_in_bytes, R0/*tmp*/); 1.2865 + 1.2866 + // stack: (unpack frame, skeletal interpreter frame, ..., optional 1.2867 + // skeletal interpreter frame, optional c2i, caller of deoptee, 1.2868 + // ...). 1.2869 + 1.2870 + // Spill live volatile registers since we'll do a call. 1.2871 + __ std( R3_RET, _abi_112_spill(spill_ret), R1_SP); 1.2872 + __ stfd(F1_RET, _abi_112_spill(spill_fret), R1_SP); 1.2873 + 1.2874 + // Let the unpacker layout information in the skeletal frames just 1.2875 + // allocated. 1.2876 + __ get_PC_trash_LR(R3_RET); 1.2877 + __ set_last_Java_frame(/*sp*/R1_SP, /*pc*/R3_RET); 1.2878 + // This is a call to a LEAF method, so no oop map is required. 1.2879 + __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), 1.2880 + R16_thread/*thread*/, exec_mode_reg/*exec_mode*/); 1.2881 + __ reset_last_Java_frame(); 1.2882 + 1.2883 + // Restore the volatiles saved above. 1.2884 + __ ld( R3_RET, _abi_112_spill(spill_ret), R1_SP); 1.2885 + __ lfd(F1_RET, _abi_112_spill(spill_fret), R1_SP); 1.2886 + 1.2887 + // Pop the unpack frame. 1.2888 + __ pop_frame(); 1.2889 + __ restore_LR_CR(R0); 1.2890 + 1.2891 + // stack: (top interpreter frame, ..., optional interpreter frame, 1.2892 + // optional c2i, caller of deoptee, ...). 1.2893 + 1.2894 + // Initialize R14_state. 1.2895 + __ ld(R14_state, 0, R1_SP); 1.2896 + __ addi(R14_state, R14_state, 1.2897 + -frame::interpreter_frame_cinterpreterstate_size_in_bytes()); 1.2898 + // Also inititialize R15_prev_state. 1.2899 + __ restore_prev_state(); 1.2900 + 1.2901 + // Return to the interpreter entry point. 1.2902 + __ blr(); 1.2903 + __ flush(); 1.2904 +#else // COMPILER2 1.2905 + __ unimplemented("deopt blob needed only with compiler"); 1.2906 + int exception_offset = __ pc() - start; 1.2907 +#endif // COMPILER2 1.2908 + 1.2909 + _deopt_blob = DeoptimizationBlob::create(&buffer, oop_maps, 0, exception_offset, 0, first_frame_size_in_bytes / wordSize); 1.2910 +} 1.2911 + 1.2912 +#ifdef COMPILER2 1.2913 +void SharedRuntime::generate_uncommon_trap_blob() { 1.2914 + // Allocate space for the code. 1.2915 + ResourceMark rm; 1.2916 + // Setup code generation tools. 1.2917 + CodeBuffer buffer("uncommon_trap_blob", 2048, 1024); 1.2918 + InterpreterMacroAssembler* masm = new InterpreterMacroAssembler(&buffer); 1.2919 + address start = __ pc(); 1.2920 + 1.2921 + Register unroll_block_reg = R21_tmp1; 1.2922 + Register klass_index_reg = R22_tmp2; 1.2923 + Register unc_trap_reg = R23_tmp3; 1.2924 + 1.2925 + OopMapSet* oop_maps = new OopMapSet(); 1.2926 + int frame_size_in_bytes = frame::abi_112_size; 1.2927 + OopMap* map = new OopMap(frame_size_in_bytes / sizeof(jint), 0); 1.2928 + 1.2929 + // stack: (deoptee, optional i2c, caller_of_deoptee, ...). 1.2930 + 1.2931 + // Push a dummy `unpack_frame' and call 1.2932 + // `Deoptimization::uncommon_trap' to pack the compiled frame into a 1.2933 + // vframe array and return the `UnrollBlock' information. 1.2934 + 1.2935 + // Save LR to compiled frame. 1.2936 + __ save_LR_CR(R11_scratch1); 1.2937 + 1.2938 + // Push an "uncommon_trap" frame. 1.2939 + __ push_frame_abi112(0, R11_scratch1); 1.2940 + 1.2941 + // stack: (unpack frame, deoptee, optional i2c, caller_of_deoptee, ...). 1.2942 + 1.2943 + // Set the `unpack_frame' as last_Java_frame. 1.2944 + // `Deoptimization::uncommon_trap' expects it and considers its 1.2945 + // sender frame as the deoptee frame. 1.2946 + // Remember the offset of the instruction whose address will be 1.2947 + // moved to R11_scratch1. 1.2948 + address gc_map_pc = __ get_PC_trash_LR(R11_scratch1); 1.2949 + 1.2950 + __ set_last_Java_frame(/*sp*/R1_SP, /*pc*/R11_scratch1); 1.2951 + 1.2952 + __ mr(klass_index_reg, R3); 1.2953 + __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::uncommon_trap), 1.2954 + R16_thread, klass_index_reg); 1.2955 + 1.2956 + // Set an oopmap for the call site. 1.2957 + oop_maps->add_gc_map(gc_map_pc - start, map); 1.2958 + 1.2959 + __ reset_last_Java_frame(); 1.2960 + 1.2961 + // Pop the `unpack frame'. 1.2962 + __ pop_frame(); 1.2963 + 1.2964 + // stack: (deoptee, optional i2c, caller_of_deoptee, ...). 1.2965 + 1.2966 + // Save the return value. 1.2967 + __ mr(unroll_block_reg, R3_RET); 1.2968 + 1.2969 + // Pop the uncommon_trap frame. 1.2970 + __ pop_frame(); 1.2971 + 1.2972 + // stack: (caller_of_deoptee, ...). 1.2973 + 1.2974 + // Allocate new interpreter frame(s) and possibly a c2i adapter 1.2975 + // frame. 1.2976 + push_skeleton_frames(masm, false/*deopt*/, 1.2977 + unroll_block_reg, 1.2978 + R22_tmp2, 1.2979 + R23_tmp3, 1.2980 + R24_tmp4, 1.2981 + R25_tmp5, 1.2982 + R26_tmp6); 1.2983 + 1.2984 + // stack: (skeletal interpreter frame, ..., optional skeletal 1.2985 + // interpreter frame, optional c2i, caller of deoptee, ...). 1.2986 + 1.2987 + // Push a dummy `unpack_frame' taking care of float return values. 1.2988 + // Call `Deoptimization::unpack_frames' to layout information in the 1.2989 + // interpreter frames just created. 1.2990 + 1.2991 + // Push a simple "unpack frame" here. 1.2992 + __ push_frame_abi112(0, R11_scratch1); 1.2993 + 1.2994 + // stack: (unpack frame, skeletal interpreter frame, ..., optional 1.2995 + // skeletal interpreter frame, optional c2i, caller of deoptee, 1.2996 + // ...). 1.2997 + 1.2998 + // Set the "unpack_frame" as last_Java_frame. 1.2999 + __ get_PC_trash_LR(R11_scratch1); 1.3000 + __ set_last_Java_frame(/*sp*/R1_SP, /*pc*/R11_scratch1); 1.3001 + 1.3002 + // Indicate it is the uncommon trap case. 1.3003 + __ li(unc_trap_reg, Deoptimization::Unpack_uncommon_trap); 1.3004 + // Let the unpacker layout information in the skeletal frames just 1.3005 + // allocated. 1.3006 + __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames), 1.3007 + R16_thread, unc_trap_reg); 1.3008 + 1.3009 + __ reset_last_Java_frame(); 1.3010 + // Pop the `unpack frame'. 1.3011 + __ pop_frame(); 1.3012 + // Restore LR from top interpreter frame. 1.3013 + __ restore_LR_CR(R11_scratch1); 1.3014 + 1.3015 + // stack: (top interpreter frame, ..., optional interpreter frame, 1.3016 + // optional c2i, caller of deoptee, ...). 1.3017 + 1.3018 + // Initialize R14_state, ... 1.3019 + __ ld(R11_scratch1, 0, R1_SP); 1.3020 + __ addi(R14_state, R11_scratch1, 1.3021 + -frame::interpreter_frame_cinterpreterstate_size_in_bytes()); 1.3022 + // also initialize R15_prev_state. 1.3023 + __ restore_prev_state(); 1.3024 + // Return to the interpreter entry point. 1.3025 + __ blr(); 1.3026 + 1.3027 + masm->flush(); 1.3028 + 1.3029 + _uncommon_trap_blob = UncommonTrapBlob::create(&buffer, oop_maps, frame_size_in_bytes/wordSize); 1.3030 +} 1.3031 +#endif // COMPILER2 1.3032 + 1.3033 +// Generate a special Compile2Runtime blob that saves all registers, and setup oopmap. 1.3034 +SafepointBlob* SharedRuntime::generate_handler_blob(address call_ptr, int poll_type) { 1.3035 + assert(StubRoutines::forward_exception_entry() != NULL, 1.3036 + "must be generated before"); 1.3037 + 1.3038 + ResourceMark rm; 1.3039 + OopMapSet *oop_maps = new OopMapSet(); 1.3040 + OopMap* map; 1.3041 + 1.3042 + // Allocate space for the code. Setup code generation tools. 1.3043 + CodeBuffer buffer("handler_blob", 2048, 1024); 1.3044 + MacroAssembler* masm = new MacroAssembler(&buffer); 1.3045 + 1.3046 + address start = __ pc(); 1.3047 + int frame_size_in_bytes = 0; 1.3048 + 1.3049 + RegisterSaver::ReturnPCLocation return_pc_location; 1.3050 + bool cause_return = (poll_type == POLL_AT_RETURN); 1.3051 + if (cause_return) { 1.3052 + // Nothing to do here. The frame has already been popped in MachEpilogNode. 1.3053 + // Register LR already contains the return pc. 1.3054 + return_pc_location = RegisterSaver::return_pc_is_lr; 1.3055 + } else { 1.3056 + // Use thread()->saved_exception_pc() as return pc. 1.3057 + return_pc_location = RegisterSaver::return_pc_is_thread_saved_exception_pc; 1.3058 + } 1.3059 + 1.3060 + // Save registers, fpu state, and flags. 1.3061 + map = RegisterSaver::push_frame_abi112_and_save_live_registers(masm, 1.3062 + &frame_size_in_bytes, 1.3063 + /*generate_oop_map=*/ true, 1.3064 + /*return_pc_adjustment=*/0, 1.3065 + return_pc_location); 1.3066 + 1.3067 + // The following is basically a call_VM. However, we need the precise 1.3068 + // address of the call in order to generate an oopmap. Hence, we do all the 1.3069 + // work outselves. 1.3070 + __ set_last_Java_frame(/*sp=*/R1_SP, /*pc=*/noreg); 1.3071 + 1.3072 + // The return address must always be correct so that the frame constructor 1.3073 + // never sees an invalid pc. 1.3074 + 1.3075 + // Do the call 1.3076 + __ call_VM_leaf(call_ptr, R16_thread); 1.3077 + address calls_return_pc = __ last_calls_return_pc(); 1.3078 + 1.3079 + // Set an oopmap for the call site. This oopmap will map all 1.3080 + // oop-registers and debug-info registers as callee-saved. This 1.3081 + // will allow deoptimization at this safepoint to find all possible 1.3082 + // debug-info recordings, as well as let GC find all oops. 1.3083 + oop_maps->add_gc_map(calls_return_pc - start, map); 1.3084 + 1.3085 + Label noException; 1.3086 + 1.3087 + // Clear the last Java frame. 1.3088 + __ reset_last_Java_frame(); 1.3089 + 1.3090 + BLOCK_COMMENT(" Check pending exception."); 1.3091 + const Register pending_exception = R0; 1.3092 + __ ld(pending_exception, thread_(pending_exception)); 1.3093 + __ cmpdi(CCR0, pending_exception, 0); 1.3094 + __ beq(CCR0, noException); 1.3095 + 1.3096 + // Exception pending 1.3097 + RegisterSaver::restore_live_registers_and_pop_frame(masm, 1.3098 + frame_size_in_bytes, 1.3099 + /*restore_ctr=*/true); 1.3100 + 1.3101 + 1.3102 + BLOCK_COMMENT(" Jump to forward_exception_entry."); 1.3103 + // Jump to forward_exception_entry, with the issuing PC in LR 1.3104 + // so it looks like the original nmethod called forward_exception_entry. 1.3105 + __ b64_patchable(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); 1.3106 + 1.3107 + // No exception case. 1.3108 + __ BIND(noException); 1.3109 + 1.3110 + 1.3111 + // Normal exit, restore registers and exit. 1.3112 + RegisterSaver::restore_live_registers_and_pop_frame(masm, 1.3113 + frame_size_in_bytes, 1.3114 + /*restore_ctr=*/true); 1.3115 + 1.3116 + __ blr(); 1.3117 + 1.3118 + // Make sure all code is generated 1.3119 + masm->flush(); 1.3120 + 1.3121 + // Fill-out other meta info 1.3122 + // CodeBlob frame size is in words. 1.3123 + return SafepointBlob::create(&buffer, oop_maps, frame_size_in_bytes / wordSize); 1.3124 +} 1.3125 + 1.3126 +// generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss) 1.3127 +// 1.3128 +// Generate a stub that calls into the vm to find out the proper destination 1.3129 +// of a java call. All the argument registers are live at this point 1.3130 +// but since this is generic code we don't know what they are and the caller 1.3131 +// must do any gc of the args. 1.3132 +// 1.3133 +RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const char* name) { 1.3134 + 1.3135 + // allocate space for the code 1.3136 + ResourceMark rm; 1.3137 + 1.3138 + CodeBuffer buffer(name, 1000, 512); 1.3139 + MacroAssembler* masm = new MacroAssembler(&buffer); 1.3140 + 1.3141 + int frame_size_in_bytes; 1.3142 + 1.3143 + OopMapSet *oop_maps = new OopMapSet(); 1.3144 + OopMap* map = NULL; 1.3145 + 1.3146 + address start = __ pc(); 1.3147 + 1.3148 + map = RegisterSaver::push_frame_abi112_and_save_live_registers(masm, 1.3149 + &frame_size_in_bytes, 1.3150 + /*generate_oop_map*/ true, 1.3151 + /*return_pc_adjustment*/ 0, 1.3152 + RegisterSaver::return_pc_is_lr); 1.3153 + 1.3154 + // Use noreg as last_Java_pc, the return pc will be reconstructed 1.3155 + // from the physical frame. 1.3156 + __ set_last_Java_frame(/*sp*/R1_SP, noreg); 1.3157 + 1.3158 + int frame_complete = __ offset(); 1.3159 + 1.3160 + // Pass R19_method as 2nd (optional) argument, used by 1.3161 + // counter_overflow_stub. 1.3162 + __ call_VM_leaf(destination, R16_thread, R19_method); 1.3163 + address calls_return_pc = __ last_calls_return_pc(); 1.3164 + // Set an oopmap for the call site. 1.3165 + // We need this not only for callee-saved registers, but also for volatile 1.3166 + // registers that the compiler might be keeping live across a safepoint. 1.3167 + // Create the oopmap for the call's return pc. 1.3168 + oop_maps->add_gc_map(calls_return_pc - start, map); 1.3169 + 1.3170 + // R3_RET contains the address we are going to jump to assuming no exception got installed. 1.3171 + 1.3172 + // clear last_Java_sp 1.3173 + __ reset_last_Java_frame(); 1.3174 + 1.3175 + // Check for pending exceptions. 1.3176 + BLOCK_COMMENT("Check for pending exceptions."); 1.3177 + Label pending; 1.3178 + __ ld(R11_scratch1, thread_(pending_exception)); 1.3179 + __ cmpdi(CCR0, R11_scratch1, 0); 1.3180 + __ bne(CCR0, pending); 1.3181 + 1.3182 + __ mtctr(R3_RET); // Ctr will not be touched by restore_live_registers_and_pop_frame. 1.3183 + 1.3184 + RegisterSaver::restore_live_registers_and_pop_frame(masm, frame_size_in_bytes, /*restore_ctr*/ false); 1.3185 + 1.3186 + // Get the returned methodOop. 1.3187 + __ get_vm_result_2(R19_method); 1.3188 + 1.3189 + __ bctr(); 1.3190 + 1.3191 + 1.3192 + // Pending exception after the safepoint. 1.3193 + __ BIND(pending); 1.3194 + 1.3195 + RegisterSaver::restore_live_registers_and_pop_frame(masm, frame_size_in_bytes, /*restore_ctr*/ true); 1.3196 + 1.3197 + // exception pending => remove activation and forward to exception handler 1.3198 + 1.3199 + __ li(R11_scratch1, 0); 1.3200 + __ ld(R3_ARG1, thread_(pending_exception)); 1.3201 + __ std(R11_scratch1, in_bytes(JavaThread::vm_result_offset()), R16_thread); 1.3202 + __ b64_patchable(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); 1.3203 + 1.3204 + // ------------- 1.3205 + // Make sure all code is generated. 1.3206 + masm->flush(); 1.3207 + 1.3208 + // return the blob 1.3209 + // frame_size_words or bytes?? 1.3210 + return RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_in_bytes/wordSize, 1.3211 + oop_maps, true); 1.3212 +}