src/cpu/x86/vm/sharedRuntime_x86_64.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "asm/macroAssembler.hpp"
aoqi@0 27 #include "asm/macroAssembler.inline.hpp"
aoqi@0 28 #include "code/debugInfoRec.hpp"
aoqi@0 29 #include "code/icBuffer.hpp"
aoqi@0 30 #include "code/vtableStubs.hpp"
aoqi@0 31 #include "interpreter/interpreter.hpp"
aoqi@0 32 #include "oops/compiledICHolder.hpp"
aoqi@0 33 #include "prims/jvmtiRedefineClassesTrace.hpp"
aoqi@0 34 #include "runtime/sharedRuntime.hpp"
aoqi@0 35 #include "runtime/vframeArray.hpp"
aoqi@0 36 #include "vmreg_x86.inline.hpp"
aoqi@0 37 #ifdef COMPILER1
aoqi@0 38 #include "c1/c1_Runtime1.hpp"
aoqi@0 39 #endif
aoqi@0 40 #ifdef COMPILER2
aoqi@0 41 #include "opto/runtime.hpp"
aoqi@0 42 #endif
aoqi@0 43
aoqi@0 44 #define __ masm->
aoqi@0 45
aoqi@0 46 const int StackAlignmentInSlots = StackAlignmentInBytes / VMRegImpl::stack_slot_size;
aoqi@0 47
aoqi@0 48 class SimpleRuntimeFrame {
aoqi@0 49
aoqi@0 50 public:
aoqi@0 51
aoqi@0 52 // Most of the runtime stubs have this simple frame layout.
aoqi@0 53 // This class exists to make the layout shared in one place.
aoqi@0 54 // Offsets are for compiler stack slots, which are jints.
aoqi@0 55 enum layout {
aoqi@0 56 // The frame sender code expects that rbp will be in the "natural" place and
aoqi@0 57 // will override any oopMap setting for it. We must therefore force the layout
aoqi@0 58 // so that it agrees with the frame sender code.
aoqi@0 59 rbp_off = frame::arg_reg_save_area_bytes/BytesPerInt,
aoqi@0 60 rbp_off2,
aoqi@0 61 return_off, return_off2,
aoqi@0 62 framesize
aoqi@0 63 };
aoqi@0 64 };
aoqi@0 65
aoqi@0 66 class RegisterSaver {
aoqi@0 67 // Capture info about frame layout. Layout offsets are in jint
aoqi@0 68 // units because compiler frame slots are jints.
aoqi@0 69 #define DEF_XMM_OFFS(regnum) xmm ## regnum ## _off = xmm_off + (regnum)*16/BytesPerInt, xmm ## regnum ## H_off
aoqi@0 70 enum layout {
aoqi@0 71 fpu_state_off = frame::arg_reg_save_area_bytes/BytesPerInt, // fxsave save area
aoqi@0 72 xmm_off = fpu_state_off + 160/BytesPerInt, // offset in fxsave save area
aoqi@0 73 DEF_XMM_OFFS(0),
aoqi@0 74 DEF_XMM_OFFS(1),
aoqi@0 75 DEF_XMM_OFFS(2),
aoqi@0 76 DEF_XMM_OFFS(3),
aoqi@0 77 DEF_XMM_OFFS(4),
aoqi@0 78 DEF_XMM_OFFS(5),
aoqi@0 79 DEF_XMM_OFFS(6),
aoqi@0 80 DEF_XMM_OFFS(7),
aoqi@0 81 DEF_XMM_OFFS(8),
aoqi@0 82 DEF_XMM_OFFS(9),
aoqi@0 83 DEF_XMM_OFFS(10),
aoqi@0 84 DEF_XMM_OFFS(11),
aoqi@0 85 DEF_XMM_OFFS(12),
aoqi@0 86 DEF_XMM_OFFS(13),
aoqi@0 87 DEF_XMM_OFFS(14),
aoqi@0 88 DEF_XMM_OFFS(15),
aoqi@0 89 fpu_state_end = fpu_state_off + ((FPUStateSizeInWords-1)*wordSize / BytesPerInt),
aoqi@0 90 fpu_stateH_end,
aoqi@0 91 r15_off, r15H_off,
aoqi@0 92 r14_off, r14H_off,
aoqi@0 93 r13_off, r13H_off,
aoqi@0 94 r12_off, r12H_off,
aoqi@0 95 r11_off, r11H_off,
aoqi@0 96 r10_off, r10H_off,
aoqi@0 97 r9_off, r9H_off,
aoqi@0 98 r8_off, r8H_off,
aoqi@0 99 rdi_off, rdiH_off,
aoqi@0 100 rsi_off, rsiH_off,
aoqi@0 101 ignore_off, ignoreH_off, // extra copy of rbp
aoqi@0 102 rsp_off, rspH_off,
aoqi@0 103 rbx_off, rbxH_off,
aoqi@0 104 rdx_off, rdxH_off,
aoqi@0 105 rcx_off, rcxH_off,
aoqi@0 106 rax_off, raxH_off,
aoqi@0 107 // 16-byte stack alignment fill word: see MacroAssembler::push/pop_IU_state
aoqi@0 108 align_off, alignH_off,
aoqi@0 109 flags_off, flagsH_off,
aoqi@0 110 // The frame sender code expects that rbp will be in the "natural" place and
aoqi@0 111 // will override any oopMap setting for it. We must therefore force the layout
aoqi@0 112 // so that it agrees with the frame sender code.
aoqi@0 113 rbp_off, rbpH_off, // copy of rbp we will restore
aoqi@0 114 return_off, returnH_off, // slot for return address
aoqi@0 115 reg_save_size // size in compiler stack slots
aoqi@0 116 };
aoqi@0 117
aoqi@0 118 public:
aoqi@0 119 static OopMap* save_live_registers(MacroAssembler* masm, int additional_frame_words, int* total_frame_words, bool save_vectors = false);
aoqi@0 120 static void restore_live_registers(MacroAssembler* masm, bool restore_vectors = false);
aoqi@0 121
aoqi@0 122 // Offsets into the register save area
aoqi@0 123 // Used by deoptimization when it is managing result register
aoqi@0 124 // values on its own
aoqi@0 125
aoqi@0 126 static int rax_offset_in_bytes(void) { return BytesPerInt * rax_off; }
aoqi@0 127 static int rdx_offset_in_bytes(void) { return BytesPerInt * rdx_off; }
aoqi@0 128 static int rbx_offset_in_bytes(void) { return BytesPerInt * rbx_off; }
aoqi@0 129 static int xmm0_offset_in_bytes(void) { return BytesPerInt * xmm0_off; }
aoqi@0 130 static int return_offset_in_bytes(void) { return BytesPerInt * return_off; }
aoqi@0 131
aoqi@0 132 // During deoptimization only the result registers need to be restored,
aoqi@0 133 // all the other values have already been extracted.
aoqi@0 134 static void restore_result_registers(MacroAssembler* masm);
aoqi@0 135 };
aoqi@0 136
aoqi@0 137 OopMap* RegisterSaver::save_live_registers(MacroAssembler* masm, int additional_frame_words, int* total_frame_words, bool save_vectors) {
aoqi@0 138 int vect_words = 0;
aoqi@0 139 #ifdef COMPILER2
aoqi@0 140 if (save_vectors) {
aoqi@0 141 assert(UseAVX > 0, "256bit vectors are supported only with AVX");
aoqi@0 142 assert(MaxVectorSize == 32, "only 256bit vectors are supported now");
aoqi@0 143 // Save upper half of YMM registes
aoqi@0 144 vect_words = 16 * 16 / wordSize;
aoqi@0 145 additional_frame_words += vect_words;
aoqi@0 146 }
aoqi@0 147 #else
aoqi@0 148 assert(!save_vectors, "vectors are generated only by C2");
aoqi@0 149 #endif
aoqi@0 150
aoqi@0 151 // Always make the frame size 16-byte aligned
aoqi@0 152 int frame_size_in_bytes = round_to(additional_frame_words*wordSize +
aoqi@0 153 reg_save_size*BytesPerInt, 16);
aoqi@0 154 // OopMap frame size is in compiler stack slots (jint's) not bytes or words
aoqi@0 155 int frame_size_in_slots = frame_size_in_bytes / BytesPerInt;
aoqi@0 156 // The caller will allocate additional_frame_words
aoqi@0 157 int additional_frame_slots = additional_frame_words*wordSize / BytesPerInt;
aoqi@0 158 // CodeBlob frame size is in words.
aoqi@0 159 int frame_size_in_words = frame_size_in_bytes / wordSize;
aoqi@0 160 *total_frame_words = frame_size_in_words;
aoqi@0 161
aoqi@0 162 // Save registers, fpu state, and flags.
aoqi@0 163 // We assume caller has already pushed the return address onto the
aoqi@0 164 // stack, so rsp is 8-byte aligned here.
aoqi@0 165 // We push rpb twice in this sequence because we want the real rbp
aoqi@0 166 // to be under the return like a normal enter.
aoqi@0 167
aoqi@0 168 __ enter(); // rsp becomes 16-byte aligned here
aoqi@0 169 __ push_CPU_state(); // Push a multiple of 16 bytes
aoqi@0 170
aoqi@0 171 if (vect_words > 0) {
aoqi@0 172 assert(vect_words*wordSize == 256, "");
aoqi@0 173 __ subptr(rsp, 256); // Save upper half of YMM registes
aoqi@0 174 __ vextractf128h(Address(rsp, 0),xmm0);
aoqi@0 175 __ vextractf128h(Address(rsp, 16),xmm1);
aoqi@0 176 __ vextractf128h(Address(rsp, 32),xmm2);
aoqi@0 177 __ vextractf128h(Address(rsp, 48),xmm3);
aoqi@0 178 __ vextractf128h(Address(rsp, 64),xmm4);
aoqi@0 179 __ vextractf128h(Address(rsp, 80),xmm5);
aoqi@0 180 __ vextractf128h(Address(rsp, 96),xmm6);
aoqi@0 181 __ vextractf128h(Address(rsp,112),xmm7);
aoqi@0 182 __ vextractf128h(Address(rsp,128),xmm8);
aoqi@0 183 __ vextractf128h(Address(rsp,144),xmm9);
aoqi@0 184 __ vextractf128h(Address(rsp,160),xmm10);
aoqi@0 185 __ vextractf128h(Address(rsp,176),xmm11);
aoqi@0 186 __ vextractf128h(Address(rsp,192),xmm12);
aoqi@0 187 __ vextractf128h(Address(rsp,208),xmm13);
aoqi@0 188 __ vextractf128h(Address(rsp,224),xmm14);
aoqi@0 189 __ vextractf128h(Address(rsp,240),xmm15);
aoqi@0 190 }
aoqi@0 191 if (frame::arg_reg_save_area_bytes != 0) {
aoqi@0 192 // Allocate argument register save area
aoqi@0 193 __ subptr(rsp, frame::arg_reg_save_area_bytes);
aoqi@0 194 }
aoqi@0 195
aoqi@0 196 // Set an oopmap for the call site. This oopmap will map all
aoqi@0 197 // oop-registers and debug-info registers as callee-saved. This
aoqi@0 198 // will allow deoptimization at this safepoint to find all possible
aoqi@0 199 // debug-info recordings, as well as let GC find all oops.
aoqi@0 200
aoqi@0 201 OopMapSet *oop_maps = new OopMapSet();
aoqi@0 202 OopMap* map = new OopMap(frame_size_in_slots, 0);
aoqi@0 203
aoqi@0 204 #define STACK_OFFSET(x) VMRegImpl::stack2reg((x) + additional_frame_slots)
aoqi@0 205
aoqi@0 206 map->set_callee_saved(STACK_OFFSET( rax_off ), rax->as_VMReg());
aoqi@0 207 map->set_callee_saved(STACK_OFFSET( rcx_off ), rcx->as_VMReg());
aoqi@0 208 map->set_callee_saved(STACK_OFFSET( rdx_off ), rdx->as_VMReg());
aoqi@0 209 map->set_callee_saved(STACK_OFFSET( rbx_off ), rbx->as_VMReg());
aoqi@0 210 // rbp location is known implicitly by the frame sender code, needs no oopmap
aoqi@0 211 // and the location where rbp was saved by is ignored
aoqi@0 212 map->set_callee_saved(STACK_OFFSET( rsi_off ), rsi->as_VMReg());
aoqi@0 213 map->set_callee_saved(STACK_OFFSET( rdi_off ), rdi->as_VMReg());
aoqi@0 214 map->set_callee_saved(STACK_OFFSET( r8_off ), r8->as_VMReg());
aoqi@0 215 map->set_callee_saved(STACK_OFFSET( r9_off ), r9->as_VMReg());
aoqi@0 216 map->set_callee_saved(STACK_OFFSET( r10_off ), r10->as_VMReg());
aoqi@0 217 map->set_callee_saved(STACK_OFFSET( r11_off ), r11->as_VMReg());
aoqi@0 218 map->set_callee_saved(STACK_OFFSET( r12_off ), r12->as_VMReg());
aoqi@0 219 map->set_callee_saved(STACK_OFFSET( r13_off ), r13->as_VMReg());
aoqi@0 220 map->set_callee_saved(STACK_OFFSET( r14_off ), r14->as_VMReg());
aoqi@0 221 map->set_callee_saved(STACK_OFFSET( r15_off ), r15->as_VMReg());
aoqi@0 222 map->set_callee_saved(STACK_OFFSET(xmm0_off ), xmm0->as_VMReg());
aoqi@0 223 map->set_callee_saved(STACK_OFFSET(xmm1_off ), xmm1->as_VMReg());
aoqi@0 224 map->set_callee_saved(STACK_OFFSET(xmm2_off ), xmm2->as_VMReg());
aoqi@0 225 map->set_callee_saved(STACK_OFFSET(xmm3_off ), xmm3->as_VMReg());
aoqi@0 226 map->set_callee_saved(STACK_OFFSET(xmm4_off ), xmm4->as_VMReg());
aoqi@0 227 map->set_callee_saved(STACK_OFFSET(xmm5_off ), xmm5->as_VMReg());
aoqi@0 228 map->set_callee_saved(STACK_OFFSET(xmm6_off ), xmm6->as_VMReg());
aoqi@0 229 map->set_callee_saved(STACK_OFFSET(xmm7_off ), xmm7->as_VMReg());
aoqi@0 230 map->set_callee_saved(STACK_OFFSET(xmm8_off ), xmm8->as_VMReg());
aoqi@0 231 map->set_callee_saved(STACK_OFFSET(xmm9_off ), xmm9->as_VMReg());
aoqi@0 232 map->set_callee_saved(STACK_OFFSET(xmm10_off), xmm10->as_VMReg());
aoqi@0 233 map->set_callee_saved(STACK_OFFSET(xmm11_off), xmm11->as_VMReg());
aoqi@0 234 map->set_callee_saved(STACK_OFFSET(xmm12_off), xmm12->as_VMReg());
aoqi@0 235 map->set_callee_saved(STACK_OFFSET(xmm13_off), xmm13->as_VMReg());
aoqi@0 236 map->set_callee_saved(STACK_OFFSET(xmm14_off), xmm14->as_VMReg());
aoqi@0 237 map->set_callee_saved(STACK_OFFSET(xmm15_off), xmm15->as_VMReg());
aoqi@0 238
aoqi@0 239 // %%% These should all be a waste but we'll keep things as they were for now
aoqi@0 240 if (true) {
aoqi@0 241 map->set_callee_saved(STACK_OFFSET( raxH_off ), rax->as_VMReg()->next());
aoqi@0 242 map->set_callee_saved(STACK_OFFSET( rcxH_off ), rcx->as_VMReg()->next());
aoqi@0 243 map->set_callee_saved(STACK_OFFSET( rdxH_off ), rdx->as_VMReg()->next());
aoqi@0 244 map->set_callee_saved(STACK_OFFSET( rbxH_off ), rbx->as_VMReg()->next());
aoqi@0 245 // rbp location is known implicitly by the frame sender code, needs no oopmap
aoqi@0 246 map->set_callee_saved(STACK_OFFSET( rsiH_off ), rsi->as_VMReg()->next());
aoqi@0 247 map->set_callee_saved(STACK_OFFSET( rdiH_off ), rdi->as_VMReg()->next());
aoqi@0 248 map->set_callee_saved(STACK_OFFSET( r8H_off ), r8->as_VMReg()->next());
aoqi@0 249 map->set_callee_saved(STACK_OFFSET( r9H_off ), r9->as_VMReg()->next());
aoqi@0 250 map->set_callee_saved(STACK_OFFSET( r10H_off ), r10->as_VMReg()->next());
aoqi@0 251 map->set_callee_saved(STACK_OFFSET( r11H_off ), r11->as_VMReg()->next());
aoqi@0 252 map->set_callee_saved(STACK_OFFSET( r12H_off ), r12->as_VMReg()->next());
aoqi@0 253 map->set_callee_saved(STACK_OFFSET( r13H_off ), r13->as_VMReg()->next());
aoqi@0 254 map->set_callee_saved(STACK_OFFSET( r14H_off ), r14->as_VMReg()->next());
aoqi@0 255 map->set_callee_saved(STACK_OFFSET( r15H_off ), r15->as_VMReg()->next());
aoqi@0 256 map->set_callee_saved(STACK_OFFSET(xmm0H_off ), xmm0->as_VMReg()->next());
aoqi@0 257 map->set_callee_saved(STACK_OFFSET(xmm1H_off ), xmm1->as_VMReg()->next());
aoqi@0 258 map->set_callee_saved(STACK_OFFSET(xmm2H_off ), xmm2->as_VMReg()->next());
aoqi@0 259 map->set_callee_saved(STACK_OFFSET(xmm3H_off ), xmm3->as_VMReg()->next());
aoqi@0 260 map->set_callee_saved(STACK_OFFSET(xmm4H_off ), xmm4->as_VMReg()->next());
aoqi@0 261 map->set_callee_saved(STACK_OFFSET(xmm5H_off ), xmm5->as_VMReg()->next());
aoqi@0 262 map->set_callee_saved(STACK_OFFSET(xmm6H_off ), xmm6->as_VMReg()->next());
aoqi@0 263 map->set_callee_saved(STACK_OFFSET(xmm7H_off ), xmm7->as_VMReg()->next());
aoqi@0 264 map->set_callee_saved(STACK_OFFSET(xmm8H_off ), xmm8->as_VMReg()->next());
aoqi@0 265 map->set_callee_saved(STACK_OFFSET(xmm9H_off ), xmm9->as_VMReg()->next());
aoqi@0 266 map->set_callee_saved(STACK_OFFSET(xmm10H_off), xmm10->as_VMReg()->next());
aoqi@0 267 map->set_callee_saved(STACK_OFFSET(xmm11H_off), xmm11->as_VMReg()->next());
aoqi@0 268 map->set_callee_saved(STACK_OFFSET(xmm12H_off), xmm12->as_VMReg()->next());
aoqi@0 269 map->set_callee_saved(STACK_OFFSET(xmm13H_off), xmm13->as_VMReg()->next());
aoqi@0 270 map->set_callee_saved(STACK_OFFSET(xmm14H_off), xmm14->as_VMReg()->next());
aoqi@0 271 map->set_callee_saved(STACK_OFFSET(xmm15H_off), xmm15->as_VMReg()->next());
aoqi@0 272 }
aoqi@0 273
aoqi@0 274 return map;
aoqi@0 275 }
aoqi@0 276
aoqi@0 277 void RegisterSaver::restore_live_registers(MacroAssembler* masm, bool restore_vectors) {
aoqi@0 278 if (frame::arg_reg_save_area_bytes != 0) {
aoqi@0 279 // Pop arg register save area
aoqi@0 280 __ addptr(rsp, frame::arg_reg_save_area_bytes);
aoqi@0 281 }
aoqi@0 282 #ifdef COMPILER2
aoqi@0 283 if (restore_vectors) {
aoqi@0 284 // Restore upper half of YMM registes.
aoqi@0 285 assert(UseAVX > 0, "256bit vectors are supported only with AVX");
aoqi@0 286 assert(MaxVectorSize == 32, "only 256bit vectors are supported now");
aoqi@0 287 __ vinsertf128h(xmm0, Address(rsp, 0));
aoqi@0 288 __ vinsertf128h(xmm1, Address(rsp, 16));
aoqi@0 289 __ vinsertf128h(xmm2, Address(rsp, 32));
aoqi@0 290 __ vinsertf128h(xmm3, Address(rsp, 48));
aoqi@0 291 __ vinsertf128h(xmm4, Address(rsp, 64));
aoqi@0 292 __ vinsertf128h(xmm5, Address(rsp, 80));
aoqi@0 293 __ vinsertf128h(xmm6, Address(rsp, 96));
aoqi@0 294 __ vinsertf128h(xmm7, Address(rsp,112));
aoqi@0 295 __ vinsertf128h(xmm8, Address(rsp,128));
aoqi@0 296 __ vinsertf128h(xmm9, Address(rsp,144));
aoqi@0 297 __ vinsertf128h(xmm10, Address(rsp,160));
aoqi@0 298 __ vinsertf128h(xmm11, Address(rsp,176));
aoqi@0 299 __ vinsertf128h(xmm12, Address(rsp,192));
aoqi@0 300 __ vinsertf128h(xmm13, Address(rsp,208));
aoqi@0 301 __ vinsertf128h(xmm14, Address(rsp,224));
aoqi@0 302 __ vinsertf128h(xmm15, Address(rsp,240));
aoqi@0 303 __ addptr(rsp, 256);
aoqi@0 304 }
aoqi@0 305 #else
aoqi@0 306 assert(!restore_vectors, "vectors are generated only by C2");
aoqi@0 307 #endif
aoqi@0 308 // Recover CPU state
aoqi@0 309 __ pop_CPU_state();
aoqi@0 310 // Get the rbp described implicitly by the calling convention (no oopMap)
aoqi@0 311 __ pop(rbp);
aoqi@0 312 }
aoqi@0 313
aoqi@0 314 void RegisterSaver::restore_result_registers(MacroAssembler* masm) {
aoqi@0 315
aoqi@0 316 // Just restore result register. Only used by deoptimization. By
aoqi@0 317 // now any callee save register that needs to be restored to a c2
aoqi@0 318 // caller of the deoptee has been extracted into the vframeArray
aoqi@0 319 // and will be stuffed into the c2i adapter we create for later
aoqi@0 320 // restoration so only result registers need to be restored here.
aoqi@0 321
aoqi@0 322 // Restore fp result register
aoqi@0 323 __ movdbl(xmm0, Address(rsp, xmm0_offset_in_bytes()));
aoqi@0 324 // Restore integer result register
aoqi@0 325 __ movptr(rax, Address(rsp, rax_offset_in_bytes()));
aoqi@0 326 __ movptr(rdx, Address(rsp, rdx_offset_in_bytes()));
aoqi@0 327
aoqi@0 328 // Pop all of the register save are off the stack except the return address
aoqi@0 329 __ addptr(rsp, return_offset_in_bytes());
aoqi@0 330 }
aoqi@0 331
aoqi@0 332 // Is vector's size (in bytes) bigger than a size saved by default?
aoqi@0 333 // 16 bytes XMM registers are saved by default using fxsave/fxrstor instructions.
aoqi@0 334 bool SharedRuntime::is_wide_vector(int size) {
aoqi@0 335 return size > 16;
aoqi@0 336 }
aoqi@0 337
aoqi@0 338 // The java_calling_convention describes stack locations as ideal slots on
aoqi@0 339 // a frame with no abi restrictions. Since we must observe abi restrictions
aoqi@0 340 // (like the placement of the register window) the slots must be biased by
aoqi@0 341 // the following value.
aoqi@0 342 static int reg2offset_in(VMReg r) {
aoqi@0 343 // Account for saved rbp and return address
aoqi@0 344 // This should really be in_preserve_stack_slots
aoqi@0 345 return (r->reg2stack() + 4) * VMRegImpl::stack_slot_size;
aoqi@0 346 }
aoqi@0 347
aoqi@0 348 static int reg2offset_out(VMReg r) {
aoqi@0 349 return (r->reg2stack() + SharedRuntime::out_preserve_stack_slots()) * VMRegImpl::stack_slot_size;
aoqi@0 350 }
aoqi@0 351
aoqi@0 352 // ---------------------------------------------------------------------------
aoqi@0 353 // Read the array of BasicTypes from a signature, and compute where the
aoqi@0 354 // arguments should go. Values in the VMRegPair regs array refer to 4-byte
aoqi@0 355 // quantities. Values less than VMRegImpl::stack0 are registers, those above
aoqi@0 356 // refer to 4-byte stack slots. All stack slots are based off of the stack pointer
aoqi@0 357 // as framesizes are fixed.
aoqi@0 358 // VMRegImpl::stack0 refers to the first slot 0(sp).
aoqi@0 359 // and VMRegImpl::stack0+1 refers to the memory word 4-byes higher. Register
aoqi@0 360 // up to RegisterImpl::number_of_registers) are the 64-bit
aoqi@0 361 // integer registers.
aoqi@0 362
aoqi@0 363 // Note: the INPUTS in sig_bt are in units of Java argument words, which are
aoqi@0 364 // either 32-bit or 64-bit depending on the build. The OUTPUTS are in 32-bit
aoqi@0 365 // units regardless of build. Of course for i486 there is no 64 bit build
aoqi@0 366
aoqi@0 367 // The Java calling convention is a "shifted" version of the C ABI.
aoqi@0 368 // By skipping the first C ABI register we can call non-static jni methods
aoqi@0 369 // with small numbers of arguments without having to shuffle the arguments
aoqi@0 370 // at all. Since we control the java ABI we ought to at least get some
aoqi@0 371 // advantage out of it.
aoqi@0 372
aoqi@0 373 int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
aoqi@0 374 VMRegPair *regs,
aoqi@0 375 int total_args_passed,
aoqi@0 376 int is_outgoing) {
aoqi@0 377
aoqi@0 378 // Create the mapping between argument positions and
aoqi@0 379 // registers.
aoqi@0 380 static const Register INT_ArgReg[Argument::n_int_register_parameters_j] = {
aoqi@0 381 j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5
aoqi@0 382 };
aoqi@0 383 static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_j] = {
aoqi@0 384 j_farg0, j_farg1, j_farg2, j_farg3,
aoqi@0 385 j_farg4, j_farg5, j_farg6, j_farg7
aoqi@0 386 };
aoqi@0 387
aoqi@0 388
aoqi@0 389 uint int_args = 0;
aoqi@0 390 uint fp_args = 0;
aoqi@0 391 uint stk_args = 0; // inc by 2 each time
aoqi@0 392
aoqi@0 393 for (int i = 0; i < total_args_passed; i++) {
aoqi@0 394 switch (sig_bt[i]) {
aoqi@0 395 case T_BOOLEAN:
aoqi@0 396 case T_CHAR:
aoqi@0 397 case T_BYTE:
aoqi@0 398 case T_SHORT:
aoqi@0 399 case T_INT:
aoqi@0 400 if (int_args < Argument::n_int_register_parameters_j) {
aoqi@0 401 regs[i].set1(INT_ArgReg[int_args++]->as_VMReg());
aoqi@0 402 } else {
aoqi@0 403 regs[i].set1(VMRegImpl::stack2reg(stk_args));
aoqi@0 404 stk_args += 2;
aoqi@0 405 }
aoqi@0 406 break;
aoqi@0 407 case T_VOID:
aoqi@0 408 // halves of T_LONG or T_DOUBLE
aoqi@0 409 assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half");
aoqi@0 410 regs[i].set_bad();
aoqi@0 411 break;
aoqi@0 412 case T_LONG:
aoqi@0 413 assert(sig_bt[i + 1] == T_VOID, "expecting half");
aoqi@0 414 // fall through
aoqi@0 415 case T_OBJECT:
aoqi@0 416 case T_ARRAY:
aoqi@0 417 case T_ADDRESS:
aoqi@0 418 if (int_args < Argument::n_int_register_parameters_j) {
aoqi@0 419 regs[i].set2(INT_ArgReg[int_args++]->as_VMReg());
aoqi@0 420 } else {
aoqi@0 421 regs[i].set2(VMRegImpl::stack2reg(stk_args));
aoqi@0 422 stk_args += 2;
aoqi@0 423 }
aoqi@0 424 break;
aoqi@0 425 case T_FLOAT:
aoqi@0 426 if (fp_args < Argument::n_float_register_parameters_j) {
aoqi@0 427 regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg());
aoqi@0 428 } else {
aoqi@0 429 regs[i].set1(VMRegImpl::stack2reg(stk_args));
aoqi@0 430 stk_args += 2;
aoqi@0 431 }
aoqi@0 432 break;
aoqi@0 433 case T_DOUBLE:
aoqi@0 434 assert(sig_bt[i + 1] == T_VOID, "expecting half");
aoqi@0 435 if (fp_args < Argument::n_float_register_parameters_j) {
aoqi@0 436 regs[i].set2(FP_ArgReg[fp_args++]->as_VMReg());
aoqi@0 437 } else {
aoqi@0 438 regs[i].set2(VMRegImpl::stack2reg(stk_args));
aoqi@0 439 stk_args += 2;
aoqi@0 440 }
aoqi@0 441 break;
aoqi@0 442 default:
aoqi@0 443 ShouldNotReachHere();
aoqi@0 444 break;
aoqi@0 445 }
aoqi@0 446 }
aoqi@0 447
aoqi@0 448 return round_to(stk_args, 2);
aoqi@0 449 }
aoqi@0 450
aoqi@0 451 // Patch the callers callsite with entry to compiled code if it exists.
aoqi@0 452 static void patch_callers_callsite(MacroAssembler *masm) {
aoqi@0 453 Label L;
aoqi@0 454 __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), (int32_t)NULL_WORD);
aoqi@0 455 __ jcc(Assembler::equal, L);
aoqi@0 456
aoqi@0 457 // Save the current stack pointer
aoqi@0 458 __ mov(r13, rsp);
aoqi@0 459 // Schedule the branch target address early.
aoqi@0 460 // Call into the VM to patch the caller, then jump to compiled callee
aoqi@0 461 // rax isn't live so capture return address while we easily can
aoqi@0 462 __ movptr(rax, Address(rsp, 0));
aoqi@0 463
aoqi@0 464 // align stack so push_CPU_state doesn't fault
aoqi@0 465 __ andptr(rsp, -(StackAlignmentInBytes));
aoqi@0 466 __ push_CPU_state();
aoqi@0 467
aoqi@0 468 // VM needs caller's callsite
aoqi@0 469 // VM needs target method
aoqi@0 470 // This needs to be a long call since we will relocate this adapter to
aoqi@0 471 // the codeBuffer and it may not reach
aoqi@0 472
aoqi@0 473 // Allocate argument register save area
aoqi@0 474 if (frame::arg_reg_save_area_bytes != 0) {
aoqi@0 475 __ subptr(rsp, frame::arg_reg_save_area_bytes);
aoqi@0 476 }
aoqi@0 477 __ mov(c_rarg0, rbx);
aoqi@0 478 __ mov(c_rarg1, rax);
aoqi@0 479 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite)));
aoqi@0 480
aoqi@0 481 // De-allocate argument register save area
aoqi@0 482 if (frame::arg_reg_save_area_bytes != 0) {
aoqi@0 483 __ addptr(rsp, frame::arg_reg_save_area_bytes);
aoqi@0 484 }
aoqi@0 485
aoqi@0 486 __ pop_CPU_state();
aoqi@0 487 // restore sp
aoqi@0 488 __ mov(rsp, r13);
aoqi@0 489 __ bind(L);
aoqi@0 490 }
aoqi@0 491
aoqi@0 492
aoqi@0 493 static void gen_c2i_adapter(MacroAssembler *masm,
aoqi@0 494 int total_args_passed,
aoqi@0 495 int comp_args_on_stack,
aoqi@0 496 const BasicType *sig_bt,
aoqi@0 497 const VMRegPair *regs,
aoqi@0 498 Label& skip_fixup) {
aoqi@0 499 // Before we get into the guts of the C2I adapter, see if we should be here
aoqi@0 500 // at all. We've come from compiled code and are attempting to jump to the
aoqi@0 501 // interpreter, which means the caller made a static call to get here
aoqi@0 502 // (vcalls always get a compiled target if there is one). Check for a
aoqi@0 503 // compiled target. If there is one, we need to patch the caller's call.
aoqi@0 504 patch_callers_callsite(masm);
aoqi@0 505
aoqi@0 506 __ bind(skip_fixup);
aoqi@0 507
aoqi@0 508 // Since all args are passed on the stack, total_args_passed *
aoqi@0 509 // Interpreter::stackElementSize is the space we need. Plus 1 because
aoqi@0 510 // we also account for the return address location since
aoqi@0 511 // we store it first rather than hold it in rax across all the shuffling
aoqi@0 512
aoqi@0 513 int extraspace = (total_args_passed * Interpreter::stackElementSize) + wordSize;
aoqi@0 514
aoqi@0 515 // stack is aligned, keep it that way
aoqi@0 516 extraspace = round_to(extraspace, 2*wordSize);
aoqi@0 517
aoqi@0 518 // Get return address
aoqi@0 519 __ pop(rax);
aoqi@0 520
aoqi@0 521 // set senderSP value
aoqi@0 522 __ mov(r13, rsp);
aoqi@0 523
aoqi@0 524 __ subptr(rsp, extraspace);
aoqi@0 525
aoqi@0 526 // Store the return address in the expected location
aoqi@0 527 __ movptr(Address(rsp, 0), rax);
aoqi@0 528
aoqi@0 529 // Now write the args into the outgoing interpreter space
aoqi@0 530 for (int i = 0; i < total_args_passed; i++) {
aoqi@0 531 if (sig_bt[i] == T_VOID) {
aoqi@0 532 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half");
aoqi@0 533 continue;
aoqi@0 534 }
aoqi@0 535
aoqi@0 536 // offset to start parameters
aoqi@0 537 int st_off = (total_args_passed - i) * Interpreter::stackElementSize;
aoqi@0 538 int next_off = st_off - Interpreter::stackElementSize;
aoqi@0 539
aoqi@0 540 // Say 4 args:
aoqi@0 541 // i st_off
aoqi@0 542 // 0 32 T_LONG
aoqi@0 543 // 1 24 T_VOID
aoqi@0 544 // 2 16 T_OBJECT
aoqi@0 545 // 3 8 T_BOOL
aoqi@0 546 // - 0 return address
aoqi@0 547 //
aoqi@0 548 // However to make thing extra confusing. Because we can fit a long/double in
aoqi@0 549 // a single slot on a 64 bt vm and it would be silly to break them up, the interpreter
aoqi@0 550 // leaves one slot empty and only stores to a single slot. In this case the
aoqi@0 551 // slot that is occupied is the T_VOID slot. See I said it was confusing.
aoqi@0 552
aoqi@0 553 VMReg r_1 = regs[i].first();
aoqi@0 554 VMReg r_2 = regs[i].second();
aoqi@0 555 if (!r_1->is_valid()) {
aoqi@0 556 assert(!r_2->is_valid(), "");
aoqi@0 557 continue;
aoqi@0 558 }
aoqi@0 559 if (r_1->is_stack()) {
aoqi@0 560 // memory to memory use rax
aoqi@0 561 int ld_off = r_1->reg2stack() * VMRegImpl::stack_slot_size + extraspace;
aoqi@0 562 if (!r_2->is_valid()) {
aoqi@0 563 // sign extend??
aoqi@0 564 __ movl(rax, Address(rsp, ld_off));
aoqi@0 565 __ movptr(Address(rsp, st_off), rax);
aoqi@0 566
aoqi@0 567 } else {
aoqi@0 568
aoqi@0 569 __ movq(rax, Address(rsp, ld_off));
aoqi@0 570
aoqi@0 571 // Two VMREgs|OptoRegs can be T_OBJECT, T_ADDRESS, T_DOUBLE, T_LONG
aoqi@0 572 // T_DOUBLE and T_LONG use two slots in the interpreter
aoqi@0 573 if ( sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
aoqi@0 574 // ld_off == LSW, ld_off+wordSize == MSW
aoqi@0 575 // st_off == MSW, next_off == LSW
aoqi@0 576 __ movq(Address(rsp, next_off), rax);
aoqi@0 577 #ifdef ASSERT
aoqi@0 578 // Overwrite the unused slot with known junk
aoqi@0 579 __ mov64(rax, CONST64(0xdeadffffdeadaaaa));
aoqi@0 580 __ movptr(Address(rsp, st_off), rax);
aoqi@0 581 #endif /* ASSERT */
aoqi@0 582 } else {
aoqi@0 583 __ movq(Address(rsp, st_off), rax);
aoqi@0 584 }
aoqi@0 585 }
aoqi@0 586 } else if (r_1->is_Register()) {
aoqi@0 587 Register r = r_1->as_Register();
aoqi@0 588 if (!r_2->is_valid()) {
aoqi@0 589 // must be only an int (or less ) so move only 32bits to slot
aoqi@0 590 // why not sign extend??
aoqi@0 591 __ movl(Address(rsp, st_off), r);
aoqi@0 592 } else {
aoqi@0 593 // Two VMREgs|OptoRegs can be T_OBJECT, T_ADDRESS, T_DOUBLE, T_LONG
aoqi@0 594 // T_DOUBLE and T_LONG use two slots in the interpreter
aoqi@0 595 if ( sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
aoqi@0 596 // long/double in gpr
aoqi@0 597 #ifdef ASSERT
aoqi@0 598 // Overwrite the unused slot with known junk
aoqi@0 599 __ mov64(rax, CONST64(0xdeadffffdeadaaab));
aoqi@0 600 __ movptr(Address(rsp, st_off), rax);
aoqi@0 601 #endif /* ASSERT */
aoqi@0 602 __ movq(Address(rsp, next_off), r);
aoqi@0 603 } else {
aoqi@0 604 __ movptr(Address(rsp, st_off), r);
aoqi@0 605 }
aoqi@0 606 }
aoqi@0 607 } else {
aoqi@0 608 assert(r_1->is_XMMRegister(), "");
aoqi@0 609 if (!r_2->is_valid()) {
aoqi@0 610 // only a float use just part of the slot
aoqi@0 611 __ movflt(Address(rsp, st_off), r_1->as_XMMRegister());
aoqi@0 612 } else {
aoqi@0 613 #ifdef ASSERT
aoqi@0 614 // Overwrite the unused slot with known junk
aoqi@0 615 __ mov64(rax, CONST64(0xdeadffffdeadaaac));
aoqi@0 616 __ movptr(Address(rsp, st_off), rax);
aoqi@0 617 #endif /* ASSERT */
aoqi@0 618 __ movdbl(Address(rsp, next_off), r_1->as_XMMRegister());
aoqi@0 619 }
aoqi@0 620 }
aoqi@0 621 }
aoqi@0 622
aoqi@0 623 // Schedule the branch target address early.
aoqi@0 624 __ movptr(rcx, Address(rbx, in_bytes(Method::interpreter_entry_offset())));
aoqi@0 625 __ jmp(rcx);
aoqi@0 626 }
aoqi@0 627
aoqi@0 628 static void range_check(MacroAssembler* masm, Register pc_reg, Register temp_reg,
aoqi@0 629 address code_start, address code_end,
aoqi@0 630 Label& L_ok) {
aoqi@0 631 Label L_fail;
aoqi@0 632 __ lea(temp_reg, ExternalAddress(code_start));
aoqi@0 633 __ cmpptr(pc_reg, temp_reg);
aoqi@0 634 __ jcc(Assembler::belowEqual, L_fail);
aoqi@0 635 __ lea(temp_reg, ExternalAddress(code_end));
aoqi@0 636 __ cmpptr(pc_reg, temp_reg);
aoqi@0 637 __ jcc(Assembler::below, L_ok);
aoqi@0 638 __ bind(L_fail);
aoqi@0 639 }
aoqi@0 640
aoqi@0 641 static void gen_i2c_adapter(MacroAssembler *masm,
aoqi@0 642 int total_args_passed,
aoqi@0 643 int comp_args_on_stack,
aoqi@0 644 const BasicType *sig_bt,
aoqi@0 645 const VMRegPair *regs) {
aoqi@0 646
aoqi@0 647 // Note: r13 contains the senderSP on entry. We must preserve it since
aoqi@0 648 // we may do a i2c -> c2i transition if we lose a race where compiled
aoqi@0 649 // code goes non-entrant while we get args ready.
aoqi@0 650 // In addition we use r13 to locate all the interpreter args as
aoqi@0 651 // we must align the stack to 16 bytes on an i2c entry else we
aoqi@0 652 // lose alignment we expect in all compiled code and register
aoqi@0 653 // save code can segv when fxsave instructions find improperly
aoqi@0 654 // aligned stack pointer.
aoqi@0 655
aoqi@0 656 // Adapters can be frameless because they do not require the caller
aoqi@0 657 // to perform additional cleanup work, such as correcting the stack pointer.
aoqi@0 658 // An i2c adapter is frameless because the *caller* frame, which is interpreted,
aoqi@0 659 // routinely repairs its own stack pointer (from interpreter_frame_last_sp),
aoqi@0 660 // even if a callee has modified the stack pointer.
aoqi@0 661 // A c2i adapter is frameless because the *callee* frame, which is interpreted,
aoqi@0 662 // routinely repairs its caller's stack pointer (from sender_sp, which is set
aoqi@0 663 // up via the senderSP register).
aoqi@0 664 // In other words, if *either* the caller or callee is interpreted, we can
aoqi@0 665 // get the stack pointer repaired after a call.
aoqi@0 666 // This is why c2i and i2c adapters cannot be indefinitely composed.
aoqi@0 667 // In particular, if a c2i adapter were to somehow call an i2c adapter,
aoqi@0 668 // both caller and callee would be compiled methods, and neither would
aoqi@0 669 // clean up the stack pointer changes performed by the two adapters.
aoqi@0 670 // If this happens, control eventually transfers back to the compiled
aoqi@0 671 // caller, but with an uncorrected stack, causing delayed havoc.
aoqi@0 672
aoqi@0 673 // Pick up the return address
aoqi@0 674 __ movptr(rax, Address(rsp, 0));
aoqi@0 675
aoqi@0 676 if (VerifyAdapterCalls &&
aoqi@0 677 (Interpreter::code() != NULL || StubRoutines::code1() != NULL)) {
aoqi@0 678 // So, let's test for cascading c2i/i2c adapters right now.
aoqi@0 679 // assert(Interpreter::contains($return_addr) ||
aoqi@0 680 // StubRoutines::contains($return_addr),
aoqi@0 681 // "i2c adapter must return to an interpreter frame");
aoqi@0 682 __ block_comment("verify_i2c { ");
aoqi@0 683 Label L_ok;
aoqi@0 684 if (Interpreter::code() != NULL)
aoqi@0 685 range_check(masm, rax, r11,
aoqi@0 686 Interpreter::code()->code_start(), Interpreter::code()->code_end(),
aoqi@0 687 L_ok);
aoqi@0 688 if (StubRoutines::code1() != NULL)
aoqi@0 689 range_check(masm, rax, r11,
aoqi@0 690 StubRoutines::code1()->code_begin(), StubRoutines::code1()->code_end(),
aoqi@0 691 L_ok);
aoqi@0 692 if (StubRoutines::code2() != NULL)
aoqi@0 693 range_check(masm, rax, r11,
aoqi@0 694 StubRoutines::code2()->code_begin(), StubRoutines::code2()->code_end(),
aoqi@0 695 L_ok);
aoqi@0 696 const char* msg = "i2c adapter must return to an interpreter frame";
aoqi@0 697 __ block_comment(msg);
aoqi@0 698 __ stop(msg);
aoqi@0 699 __ bind(L_ok);
aoqi@0 700 __ block_comment("} verify_i2ce ");
aoqi@0 701 }
aoqi@0 702
aoqi@0 703 // Must preserve original SP for loading incoming arguments because
aoqi@0 704 // we need to align the outgoing SP for compiled code.
aoqi@0 705 __ movptr(r11, rsp);
aoqi@0 706
aoqi@0 707 // Cut-out for having no stack args. Since up to 2 int/oop args are passed
aoqi@0 708 // in registers, we will occasionally have no stack args.
aoqi@0 709 int comp_words_on_stack = 0;
aoqi@0 710 if (comp_args_on_stack) {
aoqi@0 711 // Sig words on the stack are greater-than VMRegImpl::stack0. Those in
aoqi@0 712 // registers are below. By subtracting stack0, we either get a negative
aoqi@0 713 // number (all values in registers) or the maximum stack slot accessed.
aoqi@0 714
aoqi@0 715 // Convert 4-byte c2 stack slots to words.
aoqi@0 716 comp_words_on_stack = round_to(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord;
aoqi@0 717 // Round up to miminum stack alignment, in wordSize
aoqi@0 718 comp_words_on_stack = round_to(comp_words_on_stack, 2);
aoqi@0 719 __ subptr(rsp, comp_words_on_stack * wordSize);
aoqi@0 720 }
aoqi@0 721
aoqi@0 722
aoqi@0 723 // Ensure compiled code always sees stack at proper alignment
aoqi@0 724 __ andptr(rsp, -16);
aoqi@0 725
aoqi@0 726 // push the return address and misalign the stack that youngest frame always sees
aoqi@0 727 // as far as the placement of the call instruction
aoqi@0 728 __ push(rax);
aoqi@0 729
aoqi@0 730 // Put saved SP in another register
aoqi@0 731 const Register saved_sp = rax;
aoqi@0 732 __ movptr(saved_sp, r11);
aoqi@0 733
aoqi@0 734 // Will jump to the compiled code just as if compiled code was doing it.
aoqi@0 735 // Pre-load the register-jump target early, to schedule it better.
aoqi@0 736 __ movptr(r11, Address(rbx, in_bytes(Method::from_compiled_offset())));
aoqi@0 737
aoqi@0 738 // Now generate the shuffle code. Pick up all register args and move the
aoqi@0 739 // rest through the floating point stack top.
aoqi@0 740 for (int i = 0; i < total_args_passed; i++) {
aoqi@0 741 if (sig_bt[i] == T_VOID) {
aoqi@0 742 // Longs and doubles are passed in native word order, but misaligned
aoqi@0 743 // in the 32-bit build.
aoqi@0 744 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half");
aoqi@0 745 continue;
aoqi@0 746 }
aoqi@0 747
aoqi@0 748 // Pick up 0, 1 or 2 words from SP+offset.
aoqi@0 749
aoqi@0 750 assert(!regs[i].second()->is_valid() || regs[i].first()->next() == regs[i].second(),
aoqi@0 751 "scrambled load targets?");
aoqi@0 752 // Load in argument order going down.
aoqi@0 753 int ld_off = (total_args_passed - i)*Interpreter::stackElementSize;
aoqi@0 754 // Point to interpreter value (vs. tag)
aoqi@0 755 int next_off = ld_off - Interpreter::stackElementSize;
aoqi@0 756 //
aoqi@0 757 //
aoqi@0 758 //
aoqi@0 759 VMReg r_1 = regs[i].first();
aoqi@0 760 VMReg r_2 = regs[i].second();
aoqi@0 761 if (!r_1->is_valid()) {
aoqi@0 762 assert(!r_2->is_valid(), "");
aoqi@0 763 continue;
aoqi@0 764 }
aoqi@0 765 if (r_1->is_stack()) {
aoqi@0 766 // Convert stack slot to an SP offset (+ wordSize to account for return address )
aoqi@0 767 int st_off = regs[i].first()->reg2stack()*VMRegImpl::stack_slot_size + wordSize;
aoqi@0 768
aoqi@0 769 // We can use r13 as a temp here because compiled code doesn't need r13 as an input
aoqi@0 770 // and if we end up going thru a c2i because of a miss a reasonable value of r13
aoqi@0 771 // will be generated.
aoqi@0 772 if (!r_2->is_valid()) {
aoqi@0 773 // sign extend???
aoqi@0 774 __ movl(r13, Address(saved_sp, ld_off));
aoqi@0 775 __ movptr(Address(rsp, st_off), r13);
aoqi@0 776 } else {
aoqi@0 777 //
aoqi@0 778 // We are using two optoregs. This can be either T_OBJECT, T_ADDRESS, T_LONG, or T_DOUBLE
aoqi@0 779 // the interpreter allocates two slots but only uses one for thr T_LONG or T_DOUBLE case
aoqi@0 780 // So we must adjust where to pick up the data to match the interpreter.
aoqi@0 781 //
aoqi@0 782 // Interpreter local[n] == MSW, local[n+1] == LSW however locals
aoqi@0 783 // are accessed as negative so LSW is at LOW address
aoqi@0 784
aoqi@0 785 // ld_off is MSW so get LSW
aoqi@0 786 const int offset = (sig_bt[i]==T_LONG||sig_bt[i]==T_DOUBLE)?
aoqi@0 787 next_off : ld_off;
aoqi@0 788 __ movq(r13, Address(saved_sp, offset));
aoqi@0 789 // st_off is LSW (i.e. reg.first())
aoqi@0 790 __ movq(Address(rsp, st_off), r13);
aoqi@0 791 }
aoqi@0 792 } else if (r_1->is_Register()) { // Register argument
aoqi@0 793 Register r = r_1->as_Register();
aoqi@0 794 assert(r != rax, "must be different");
aoqi@0 795 if (r_2->is_valid()) {
aoqi@0 796 //
aoqi@0 797 // We are using two VMRegs. This can be either T_OBJECT, T_ADDRESS, T_LONG, or T_DOUBLE
aoqi@0 798 // the interpreter allocates two slots but only uses one for thr T_LONG or T_DOUBLE case
aoqi@0 799 // So we must adjust where to pick up the data to match the interpreter.
aoqi@0 800
aoqi@0 801 const int offset = (sig_bt[i]==T_LONG||sig_bt[i]==T_DOUBLE)?
aoqi@0 802 next_off : ld_off;
aoqi@0 803
aoqi@0 804 // this can be a misaligned move
aoqi@0 805 __ movq(r, Address(saved_sp, offset));
aoqi@0 806 } else {
aoqi@0 807 // sign extend and use a full word?
aoqi@0 808 __ movl(r, Address(saved_sp, ld_off));
aoqi@0 809 }
aoqi@0 810 } else {
aoqi@0 811 if (!r_2->is_valid()) {
aoqi@0 812 __ movflt(r_1->as_XMMRegister(), Address(saved_sp, ld_off));
aoqi@0 813 } else {
aoqi@0 814 __ movdbl(r_1->as_XMMRegister(), Address(saved_sp, next_off));
aoqi@0 815 }
aoqi@0 816 }
aoqi@0 817 }
aoqi@0 818
aoqi@0 819 // 6243940 We might end up in handle_wrong_method if
aoqi@0 820 // the callee is deoptimized as we race thru here. If that
aoqi@0 821 // happens we don't want to take a safepoint because the
aoqi@0 822 // caller frame will look interpreted and arguments are now
aoqi@0 823 // "compiled" so it is much better to make this transition
aoqi@0 824 // invisible to the stack walking code. Unfortunately if
aoqi@0 825 // we try and find the callee by normal means a safepoint
aoqi@0 826 // is possible. So we stash the desired callee in the thread
aoqi@0 827 // and the vm will find there should this case occur.
aoqi@0 828
aoqi@0 829 __ movptr(Address(r15_thread, JavaThread::callee_target_offset()), rbx);
aoqi@0 830
aoqi@0 831 // put Method* where a c2i would expect should we end up there
aoqi@0 832 // only needed becaus eof c2 resolve stubs return Method* as a result in
aoqi@0 833 // rax
aoqi@0 834 __ mov(rax, rbx);
aoqi@0 835 __ jmp(r11);
aoqi@0 836 }
aoqi@0 837
aoqi@0 838 // ---------------------------------------------------------------
aoqi@0 839 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
aoqi@0 840 int total_args_passed,
aoqi@0 841 int comp_args_on_stack,
aoqi@0 842 const BasicType *sig_bt,
aoqi@0 843 const VMRegPair *regs,
aoqi@0 844 AdapterFingerPrint* fingerprint) {
aoqi@0 845 address i2c_entry = __ pc();
aoqi@0 846
aoqi@0 847 gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
aoqi@0 848
aoqi@0 849 // -------------------------------------------------------------------------
aoqi@0 850 // Generate a C2I adapter. On entry we know rbx holds the Method* during calls
aoqi@0 851 // to the interpreter. The args start out packed in the compiled layout. They
aoqi@0 852 // need to be unpacked into the interpreter layout. This will almost always
aoqi@0 853 // require some stack space. We grow the current (compiled) stack, then repack
aoqi@0 854 // the args. We finally end in a jump to the generic interpreter entry point.
aoqi@0 855 // On exit from the interpreter, the interpreter will restore our SP (lest the
aoqi@0 856 // compiled code, which relys solely on SP and not RBP, get sick).
aoqi@0 857
aoqi@0 858 address c2i_unverified_entry = __ pc();
aoqi@0 859 Label skip_fixup;
aoqi@0 860 Label ok;
aoqi@0 861
aoqi@0 862 Register holder = rax;
aoqi@0 863 Register receiver = j_rarg0;
aoqi@0 864 Register temp = rbx;
aoqi@0 865
aoqi@0 866 {
aoqi@0 867 __ load_klass(temp, receiver);
aoqi@0 868 __ cmpptr(temp, Address(holder, CompiledICHolder::holder_klass_offset()));
aoqi@0 869 __ movptr(rbx, Address(holder, CompiledICHolder::holder_method_offset()));
aoqi@0 870 __ jcc(Assembler::equal, ok);
aoqi@0 871 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
aoqi@0 872
aoqi@0 873 __ bind(ok);
aoqi@0 874 // Method might have been compiled since the call site was patched to
aoqi@0 875 // interpreted if that is the case treat it as a miss so we can get
aoqi@0 876 // the call site corrected.
aoqi@0 877 __ cmpptr(Address(rbx, in_bytes(Method::code_offset())), (int32_t)NULL_WORD);
aoqi@0 878 __ jcc(Assembler::equal, skip_fixup);
aoqi@0 879 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
aoqi@0 880 }
aoqi@0 881
aoqi@0 882 address c2i_entry = __ pc();
aoqi@0 883
aoqi@0 884 gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
aoqi@0 885
aoqi@0 886 __ flush();
aoqi@0 887 return AdapterHandlerLibrary::new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
aoqi@0 888 }
aoqi@0 889
aoqi@0 890 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
aoqi@0 891 VMRegPair *regs,
aoqi@0 892 VMRegPair *regs2,
aoqi@0 893 int total_args_passed) {
aoqi@0 894 assert(regs2 == NULL, "not needed on x86");
aoqi@0 895 // We return the amount of VMRegImpl stack slots we need to reserve for all
aoqi@0 896 // the arguments NOT counting out_preserve_stack_slots.
aoqi@0 897
aoqi@0 898 // NOTE: These arrays will have to change when c1 is ported
aoqi@0 899 #ifdef _WIN64
aoqi@0 900 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
aoqi@0 901 c_rarg0, c_rarg1, c_rarg2, c_rarg3
aoqi@0 902 };
aoqi@0 903 static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
aoqi@0 904 c_farg0, c_farg1, c_farg2, c_farg3
aoqi@0 905 };
aoqi@0 906 #else
aoqi@0 907 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
aoqi@0 908 c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, c_rarg5
aoqi@0 909 };
aoqi@0 910 static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
aoqi@0 911 c_farg0, c_farg1, c_farg2, c_farg3,
aoqi@0 912 c_farg4, c_farg5, c_farg6, c_farg7
aoqi@0 913 };
aoqi@0 914 #endif // _WIN64
aoqi@0 915
aoqi@0 916
aoqi@0 917 uint int_args = 0;
aoqi@0 918 uint fp_args = 0;
aoqi@0 919 uint stk_args = 0; // inc by 2 each time
aoqi@0 920
aoqi@0 921 for (int i = 0; i < total_args_passed; i++) {
aoqi@0 922 switch (sig_bt[i]) {
aoqi@0 923 case T_BOOLEAN:
aoqi@0 924 case T_CHAR:
aoqi@0 925 case T_BYTE:
aoqi@0 926 case T_SHORT:
aoqi@0 927 case T_INT:
aoqi@0 928 if (int_args < Argument::n_int_register_parameters_c) {
aoqi@0 929 regs[i].set1(INT_ArgReg[int_args++]->as_VMReg());
aoqi@0 930 #ifdef _WIN64
aoqi@0 931 fp_args++;
aoqi@0 932 // Allocate slots for callee to stuff register args the stack.
aoqi@0 933 stk_args += 2;
aoqi@0 934 #endif
aoqi@0 935 } else {
aoqi@0 936 regs[i].set1(VMRegImpl::stack2reg(stk_args));
aoqi@0 937 stk_args += 2;
aoqi@0 938 }
aoqi@0 939 break;
aoqi@0 940 case T_LONG:
aoqi@0 941 assert(sig_bt[i + 1] == T_VOID, "expecting half");
aoqi@0 942 // fall through
aoqi@0 943 case T_OBJECT:
aoqi@0 944 case T_ARRAY:
aoqi@0 945 case T_ADDRESS:
aoqi@0 946 case T_METADATA:
aoqi@0 947 if (int_args < Argument::n_int_register_parameters_c) {
aoqi@0 948 regs[i].set2(INT_ArgReg[int_args++]->as_VMReg());
aoqi@0 949 #ifdef _WIN64
aoqi@0 950 fp_args++;
aoqi@0 951 stk_args += 2;
aoqi@0 952 #endif
aoqi@0 953 } else {
aoqi@0 954 regs[i].set2(VMRegImpl::stack2reg(stk_args));
aoqi@0 955 stk_args += 2;
aoqi@0 956 }
aoqi@0 957 break;
aoqi@0 958 case T_FLOAT:
aoqi@0 959 if (fp_args < Argument::n_float_register_parameters_c) {
aoqi@0 960 regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg());
aoqi@0 961 #ifdef _WIN64
aoqi@0 962 int_args++;
aoqi@0 963 // Allocate slots for callee to stuff register args the stack.
aoqi@0 964 stk_args += 2;
aoqi@0 965 #endif
aoqi@0 966 } else {
aoqi@0 967 regs[i].set1(VMRegImpl::stack2reg(stk_args));
aoqi@0 968 stk_args += 2;
aoqi@0 969 }
aoqi@0 970 break;
aoqi@0 971 case T_DOUBLE:
aoqi@0 972 assert(sig_bt[i + 1] == T_VOID, "expecting half");
aoqi@0 973 if (fp_args < Argument::n_float_register_parameters_c) {
aoqi@0 974 regs[i].set2(FP_ArgReg[fp_args++]->as_VMReg());
aoqi@0 975 #ifdef _WIN64
aoqi@0 976 int_args++;
aoqi@0 977 // Allocate slots for callee to stuff register args the stack.
aoqi@0 978 stk_args += 2;
aoqi@0 979 #endif
aoqi@0 980 } else {
aoqi@0 981 regs[i].set2(VMRegImpl::stack2reg(stk_args));
aoqi@0 982 stk_args += 2;
aoqi@0 983 }
aoqi@0 984 break;
aoqi@0 985 case T_VOID: // Halves of longs and doubles
aoqi@0 986 assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half");
aoqi@0 987 regs[i].set_bad();
aoqi@0 988 break;
aoqi@0 989 default:
aoqi@0 990 ShouldNotReachHere();
aoqi@0 991 break;
aoqi@0 992 }
aoqi@0 993 }
aoqi@0 994 #ifdef _WIN64
aoqi@0 995 // windows abi requires that we always allocate enough stack space
aoqi@0 996 // for 4 64bit registers to be stored down.
aoqi@0 997 if (stk_args < 8) {
aoqi@0 998 stk_args = 8;
aoqi@0 999 }
aoqi@0 1000 #endif // _WIN64
aoqi@0 1001
aoqi@0 1002 return stk_args;
aoqi@0 1003 }
aoqi@0 1004
aoqi@0 1005 // On 64 bit we will store integer like items to the stack as
aoqi@0 1006 // 64 bits items (sparc abi) even though java would only store
aoqi@0 1007 // 32bits for a parameter. On 32bit it will simply be 32 bits
aoqi@0 1008 // So this routine will do 32->32 on 32bit and 32->64 on 64bit
aoqi@0 1009 static void move32_64(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
aoqi@0 1010 if (src.first()->is_stack()) {
aoqi@0 1011 if (dst.first()->is_stack()) {
aoqi@0 1012 // stack to stack
aoqi@0 1013 __ movslq(rax, Address(rbp, reg2offset_in(src.first())));
aoqi@0 1014 __ movq(Address(rsp, reg2offset_out(dst.first())), rax);
aoqi@0 1015 } else {
aoqi@0 1016 // stack to reg
aoqi@0 1017 __ movslq(dst.first()->as_Register(), Address(rbp, reg2offset_in(src.first())));
aoqi@0 1018 }
aoqi@0 1019 } else if (dst.first()->is_stack()) {
aoqi@0 1020 // reg to stack
aoqi@0 1021 // Do we really have to sign extend???
aoqi@0 1022 // __ movslq(src.first()->as_Register(), src.first()->as_Register());
aoqi@0 1023 __ movq(Address(rsp, reg2offset_out(dst.first())), src.first()->as_Register());
aoqi@0 1024 } else {
aoqi@0 1025 // Do we really have to sign extend???
aoqi@0 1026 // __ movslq(dst.first()->as_Register(), src.first()->as_Register());
aoqi@0 1027 if (dst.first() != src.first()) {
aoqi@0 1028 __ movq(dst.first()->as_Register(), src.first()->as_Register());
aoqi@0 1029 }
aoqi@0 1030 }
aoqi@0 1031 }
aoqi@0 1032
aoqi@0 1033 static void move_ptr(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
aoqi@0 1034 if (src.first()->is_stack()) {
aoqi@0 1035 if (dst.first()->is_stack()) {
aoqi@0 1036 // stack to stack
aoqi@0 1037 __ movq(rax, Address(rbp, reg2offset_in(src.first())));
aoqi@0 1038 __ movq(Address(rsp, reg2offset_out(dst.first())), rax);
aoqi@0 1039 } else {
aoqi@0 1040 // stack to reg
aoqi@0 1041 __ movq(dst.first()->as_Register(), Address(rbp, reg2offset_in(src.first())));
aoqi@0 1042 }
aoqi@0 1043 } else if (dst.first()->is_stack()) {
aoqi@0 1044 // reg to stack
aoqi@0 1045 __ movq(Address(rsp, reg2offset_out(dst.first())), src.first()->as_Register());
aoqi@0 1046 } else {
aoqi@0 1047 if (dst.first() != src.first()) {
aoqi@0 1048 __ movq(dst.first()->as_Register(), src.first()->as_Register());
aoqi@0 1049 }
aoqi@0 1050 }
aoqi@0 1051 }
aoqi@0 1052
aoqi@0 1053 // An oop arg. Must pass a handle not the oop itself
aoqi@0 1054 static void object_move(MacroAssembler* masm,
aoqi@0 1055 OopMap* map,
aoqi@0 1056 int oop_handle_offset,
aoqi@0 1057 int framesize_in_slots,
aoqi@0 1058 VMRegPair src,
aoqi@0 1059 VMRegPair dst,
aoqi@0 1060 bool is_receiver,
aoqi@0 1061 int* receiver_offset) {
aoqi@0 1062
aoqi@0 1063 // must pass a handle. First figure out the location we use as a handle
aoqi@0 1064
aoqi@0 1065 Register rHandle = dst.first()->is_stack() ? rax : dst.first()->as_Register();
aoqi@0 1066
aoqi@0 1067 // See if oop is NULL if it is we need no handle
aoqi@0 1068
aoqi@0 1069 if (src.first()->is_stack()) {
aoqi@0 1070
aoqi@0 1071 // Oop is already on the stack as an argument
aoqi@0 1072 int offset_in_older_frame = src.first()->reg2stack() + SharedRuntime::out_preserve_stack_slots();
aoqi@0 1073 map->set_oop(VMRegImpl::stack2reg(offset_in_older_frame + framesize_in_slots));
aoqi@0 1074 if (is_receiver) {
aoqi@0 1075 *receiver_offset = (offset_in_older_frame + framesize_in_slots) * VMRegImpl::stack_slot_size;
aoqi@0 1076 }
aoqi@0 1077
aoqi@0 1078 __ cmpptr(Address(rbp, reg2offset_in(src.first())), (int32_t)NULL_WORD);
aoqi@0 1079 __ lea(rHandle, Address(rbp, reg2offset_in(src.first())));
aoqi@0 1080 // conditionally move a NULL
aoqi@0 1081 __ cmovptr(Assembler::equal, rHandle, Address(rbp, reg2offset_in(src.first())));
aoqi@0 1082 } else {
aoqi@0 1083
aoqi@0 1084 // Oop is in an a register we must store it to the space we reserve
aoqi@0 1085 // on the stack for oop_handles and pass a handle if oop is non-NULL
aoqi@0 1086
aoqi@0 1087 const Register rOop = src.first()->as_Register();
aoqi@0 1088 int oop_slot;
aoqi@0 1089 if (rOop == j_rarg0)
aoqi@0 1090 oop_slot = 0;
aoqi@0 1091 else if (rOop == j_rarg1)
aoqi@0 1092 oop_slot = 1;
aoqi@0 1093 else if (rOop == j_rarg2)
aoqi@0 1094 oop_slot = 2;
aoqi@0 1095 else if (rOop == j_rarg3)
aoqi@0 1096 oop_slot = 3;
aoqi@0 1097 else if (rOop == j_rarg4)
aoqi@0 1098 oop_slot = 4;
aoqi@0 1099 else {
aoqi@0 1100 assert(rOop == j_rarg5, "wrong register");
aoqi@0 1101 oop_slot = 5;
aoqi@0 1102 }
aoqi@0 1103
aoqi@0 1104 oop_slot = oop_slot * VMRegImpl::slots_per_word + oop_handle_offset;
aoqi@0 1105 int offset = oop_slot*VMRegImpl::stack_slot_size;
aoqi@0 1106
aoqi@0 1107 map->set_oop(VMRegImpl::stack2reg(oop_slot));
aoqi@0 1108 // Store oop in handle area, may be NULL
aoqi@0 1109 __ movptr(Address(rsp, offset), rOop);
aoqi@0 1110 if (is_receiver) {
aoqi@0 1111 *receiver_offset = offset;
aoqi@0 1112 }
aoqi@0 1113
aoqi@0 1114 __ cmpptr(rOop, (int32_t)NULL_WORD);
aoqi@0 1115 __ lea(rHandle, Address(rsp, offset));
aoqi@0 1116 // conditionally move a NULL from the handle area where it was just stored
aoqi@0 1117 __ cmovptr(Assembler::equal, rHandle, Address(rsp, offset));
aoqi@0 1118 }
aoqi@0 1119
aoqi@0 1120 // If arg is on the stack then place it otherwise it is already in correct reg.
aoqi@0 1121 if (dst.first()->is_stack()) {
aoqi@0 1122 __ movptr(Address(rsp, reg2offset_out(dst.first())), rHandle);
aoqi@0 1123 }
aoqi@0 1124 }
aoqi@0 1125
aoqi@0 1126 // A float arg may have to do float reg int reg conversion
aoqi@0 1127 static void float_move(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
aoqi@0 1128 assert(!src.second()->is_valid() && !dst.second()->is_valid(), "bad float_move");
aoqi@0 1129
aoqi@0 1130 // The calling conventions assures us that each VMregpair is either
aoqi@0 1131 // all really one physical register or adjacent stack slots.
aoqi@0 1132 // This greatly simplifies the cases here compared to sparc.
aoqi@0 1133
aoqi@0 1134 if (src.first()->is_stack()) {
aoqi@0 1135 if (dst.first()->is_stack()) {
aoqi@0 1136 __ movl(rax, Address(rbp, reg2offset_in(src.first())));
aoqi@0 1137 __ movptr(Address(rsp, reg2offset_out(dst.first())), rax);
aoqi@0 1138 } else {
aoqi@0 1139 // stack to reg
aoqi@0 1140 assert(dst.first()->is_XMMRegister(), "only expect xmm registers as parameters");
aoqi@0 1141 __ movflt(dst.first()->as_XMMRegister(), Address(rbp, reg2offset_in(src.first())));
aoqi@0 1142 }
aoqi@0 1143 } else if (dst.first()->is_stack()) {
aoqi@0 1144 // reg to stack
aoqi@0 1145 assert(src.first()->is_XMMRegister(), "only expect xmm registers as parameters");
aoqi@0 1146 __ movflt(Address(rsp, reg2offset_out(dst.first())), src.first()->as_XMMRegister());
aoqi@0 1147 } else {
aoqi@0 1148 // reg to reg
aoqi@0 1149 // In theory these overlap but the ordering is such that this is likely a nop
aoqi@0 1150 if ( src.first() != dst.first()) {
aoqi@0 1151 __ movdbl(dst.first()->as_XMMRegister(), src.first()->as_XMMRegister());
aoqi@0 1152 }
aoqi@0 1153 }
aoqi@0 1154 }
aoqi@0 1155
aoqi@0 1156 // A long move
aoqi@0 1157 static void long_move(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
aoqi@0 1158
aoqi@0 1159 // The calling conventions assures us that each VMregpair is either
aoqi@0 1160 // all really one physical register or adjacent stack slots.
aoqi@0 1161 // This greatly simplifies the cases here compared to sparc.
aoqi@0 1162
aoqi@0 1163 if (src.is_single_phys_reg() ) {
aoqi@0 1164 if (dst.is_single_phys_reg()) {
aoqi@0 1165 if (dst.first() != src.first()) {
aoqi@0 1166 __ mov(dst.first()->as_Register(), src.first()->as_Register());
aoqi@0 1167 }
aoqi@0 1168 } else {
aoqi@0 1169 assert(dst.is_single_reg(), "not a stack pair");
aoqi@0 1170 __ movq(Address(rsp, reg2offset_out(dst.first())), src.first()->as_Register());
aoqi@0 1171 }
aoqi@0 1172 } else if (dst.is_single_phys_reg()) {
aoqi@0 1173 assert(src.is_single_reg(), "not a stack pair");
aoqi@0 1174 __ movq(dst.first()->as_Register(), Address(rbp, reg2offset_out(src.first())));
aoqi@0 1175 } else {
aoqi@0 1176 assert(src.is_single_reg() && dst.is_single_reg(), "not stack pairs");
aoqi@0 1177 __ movq(rax, Address(rbp, reg2offset_in(src.first())));
aoqi@0 1178 __ movq(Address(rsp, reg2offset_out(dst.first())), rax);
aoqi@0 1179 }
aoqi@0 1180 }
aoqi@0 1181
aoqi@0 1182 // A double move
aoqi@0 1183 static void double_move(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
aoqi@0 1184
aoqi@0 1185 // The calling conventions assures us that each VMregpair is either
aoqi@0 1186 // all really one physical register or adjacent stack slots.
aoqi@0 1187 // This greatly simplifies the cases here compared to sparc.
aoqi@0 1188
aoqi@0 1189 if (src.is_single_phys_reg() ) {
aoqi@0 1190 if (dst.is_single_phys_reg()) {
aoqi@0 1191 // In theory these overlap but the ordering is such that this is likely a nop
aoqi@0 1192 if ( src.first() != dst.first()) {
aoqi@0 1193 __ movdbl(dst.first()->as_XMMRegister(), src.first()->as_XMMRegister());
aoqi@0 1194 }
aoqi@0 1195 } else {
aoqi@0 1196 assert(dst.is_single_reg(), "not a stack pair");
aoqi@0 1197 __ movdbl(Address(rsp, reg2offset_out(dst.first())), src.first()->as_XMMRegister());
aoqi@0 1198 }
aoqi@0 1199 } else if (dst.is_single_phys_reg()) {
aoqi@0 1200 assert(src.is_single_reg(), "not a stack pair");
aoqi@0 1201 __ movdbl(dst.first()->as_XMMRegister(), Address(rbp, reg2offset_out(src.first())));
aoqi@0 1202 } else {
aoqi@0 1203 assert(src.is_single_reg() && dst.is_single_reg(), "not stack pairs");
aoqi@0 1204 __ movq(rax, Address(rbp, reg2offset_in(src.first())));
aoqi@0 1205 __ movq(Address(rsp, reg2offset_out(dst.first())), rax);
aoqi@0 1206 }
aoqi@0 1207 }
aoqi@0 1208
aoqi@0 1209
aoqi@0 1210 void SharedRuntime::save_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) {
aoqi@0 1211 // We always ignore the frame_slots arg and just use the space just below frame pointer
aoqi@0 1212 // which by this time is free to use
aoqi@0 1213 switch (ret_type) {
aoqi@0 1214 case T_FLOAT:
aoqi@0 1215 __ movflt(Address(rbp, -wordSize), xmm0);
aoqi@0 1216 break;
aoqi@0 1217 case T_DOUBLE:
aoqi@0 1218 __ movdbl(Address(rbp, -wordSize), xmm0);
aoqi@0 1219 break;
aoqi@0 1220 case T_VOID: break;
aoqi@0 1221 default: {
aoqi@0 1222 __ movptr(Address(rbp, -wordSize), rax);
aoqi@0 1223 }
aoqi@0 1224 }
aoqi@0 1225 }
aoqi@0 1226
aoqi@0 1227 void SharedRuntime::restore_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) {
aoqi@0 1228 // We always ignore the frame_slots arg and just use the space just below frame pointer
aoqi@0 1229 // which by this time is free to use
aoqi@0 1230 switch (ret_type) {
aoqi@0 1231 case T_FLOAT:
aoqi@0 1232 __ movflt(xmm0, Address(rbp, -wordSize));
aoqi@0 1233 break;
aoqi@0 1234 case T_DOUBLE:
aoqi@0 1235 __ movdbl(xmm0, Address(rbp, -wordSize));
aoqi@0 1236 break;
aoqi@0 1237 case T_VOID: break;
aoqi@0 1238 default: {
aoqi@0 1239 __ movptr(rax, Address(rbp, -wordSize));
aoqi@0 1240 }
aoqi@0 1241 }
aoqi@0 1242 }
aoqi@0 1243
aoqi@0 1244 static void save_args(MacroAssembler *masm, int arg_count, int first_arg, VMRegPair *args) {
aoqi@0 1245 for ( int i = first_arg ; i < arg_count ; i++ ) {
aoqi@0 1246 if (args[i].first()->is_Register()) {
aoqi@0 1247 __ push(args[i].first()->as_Register());
aoqi@0 1248 } else if (args[i].first()->is_XMMRegister()) {
aoqi@0 1249 __ subptr(rsp, 2*wordSize);
aoqi@0 1250 __ movdbl(Address(rsp, 0), args[i].first()->as_XMMRegister());
aoqi@0 1251 }
aoqi@0 1252 }
aoqi@0 1253 }
aoqi@0 1254
aoqi@0 1255 static void restore_args(MacroAssembler *masm, int arg_count, int first_arg, VMRegPair *args) {
aoqi@0 1256 for ( int i = arg_count - 1 ; i >= first_arg ; i-- ) {
aoqi@0 1257 if (args[i].first()->is_Register()) {
aoqi@0 1258 __ pop(args[i].first()->as_Register());
aoqi@0 1259 } else if (args[i].first()->is_XMMRegister()) {
aoqi@0 1260 __ movdbl(args[i].first()->as_XMMRegister(), Address(rsp, 0));
aoqi@0 1261 __ addptr(rsp, 2*wordSize);
aoqi@0 1262 }
aoqi@0 1263 }
aoqi@0 1264 }
aoqi@0 1265
aoqi@0 1266
aoqi@0 1267 static void save_or_restore_arguments(MacroAssembler* masm,
aoqi@0 1268 const int stack_slots,
aoqi@0 1269 const int total_in_args,
aoqi@0 1270 const int arg_save_area,
aoqi@0 1271 OopMap* map,
aoqi@0 1272 VMRegPair* in_regs,
aoqi@0 1273 BasicType* in_sig_bt) {
aoqi@0 1274 // if map is non-NULL then the code should store the values,
aoqi@0 1275 // otherwise it should load them.
aoqi@0 1276 int slot = arg_save_area;
aoqi@0 1277 // Save down double word first
aoqi@0 1278 for ( int i = 0; i < total_in_args; i++) {
aoqi@0 1279 if (in_regs[i].first()->is_XMMRegister() && in_sig_bt[i] == T_DOUBLE) {
aoqi@0 1280 int offset = slot * VMRegImpl::stack_slot_size;
aoqi@0 1281 slot += VMRegImpl::slots_per_word;
aoqi@0 1282 assert(slot <= stack_slots, "overflow");
aoqi@0 1283 if (map != NULL) {
aoqi@0 1284 __ movdbl(Address(rsp, offset), in_regs[i].first()->as_XMMRegister());
aoqi@0 1285 } else {
aoqi@0 1286 __ movdbl(in_regs[i].first()->as_XMMRegister(), Address(rsp, offset));
aoqi@0 1287 }
aoqi@0 1288 }
aoqi@0 1289 if (in_regs[i].first()->is_Register() &&
aoqi@0 1290 (in_sig_bt[i] == T_LONG || in_sig_bt[i] == T_ARRAY)) {
aoqi@0 1291 int offset = slot * VMRegImpl::stack_slot_size;
aoqi@0 1292 if (map != NULL) {
aoqi@0 1293 __ movq(Address(rsp, offset), in_regs[i].first()->as_Register());
aoqi@0 1294 if (in_sig_bt[i] == T_ARRAY) {
aoqi@0 1295 map->set_oop(VMRegImpl::stack2reg(slot));;
aoqi@0 1296 }
aoqi@0 1297 } else {
aoqi@0 1298 __ movq(in_regs[i].first()->as_Register(), Address(rsp, offset));
aoqi@0 1299 }
aoqi@0 1300 slot += VMRegImpl::slots_per_word;
aoqi@0 1301 }
aoqi@0 1302 }
aoqi@0 1303 // Save or restore single word registers
aoqi@0 1304 for ( int i = 0; i < total_in_args; i++) {
aoqi@0 1305 if (in_regs[i].first()->is_Register()) {
aoqi@0 1306 int offset = slot * VMRegImpl::stack_slot_size;
aoqi@0 1307 slot++;
aoqi@0 1308 assert(slot <= stack_slots, "overflow");
aoqi@0 1309
aoqi@0 1310 // Value is in an input register pass we must flush it to the stack
aoqi@0 1311 const Register reg = in_regs[i].first()->as_Register();
aoqi@0 1312 switch (in_sig_bt[i]) {
aoqi@0 1313 case T_BOOLEAN:
aoqi@0 1314 case T_CHAR:
aoqi@0 1315 case T_BYTE:
aoqi@0 1316 case T_SHORT:
aoqi@0 1317 case T_INT:
aoqi@0 1318 if (map != NULL) {
aoqi@0 1319 __ movl(Address(rsp, offset), reg);
aoqi@0 1320 } else {
aoqi@0 1321 __ movl(reg, Address(rsp, offset));
aoqi@0 1322 }
aoqi@0 1323 break;
aoqi@0 1324 case T_ARRAY:
aoqi@0 1325 case T_LONG:
aoqi@0 1326 // handled above
aoqi@0 1327 break;
aoqi@0 1328 case T_OBJECT:
aoqi@0 1329 default: ShouldNotReachHere();
aoqi@0 1330 }
aoqi@0 1331 } else if (in_regs[i].first()->is_XMMRegister()) {
aoqi@0 1332 if (in_sig_bt[i] == T_FLOAT) {
aoqi@0 1333 int offset = slot * VMRegImpl::stack_slot_size;
aoqi@0 1334 slot++;
aoqi@0 1335 assert(slot <= stack_slots, "overflow");
aoqi@0 1336 if (map != NULL) {
aoqi@0 1337 __ movflt(Address(rsp, offset), in_regs[i].first()->as_XMMRegister());
aoqi@0 1338 } else {
aoqi@0 1339 __ movflt(in_regs[i].first()->as_XMMRegister(), Address(rsp, offset));
aoqi@0 1340 }
aoqi@0 1341 }
aoqi@0 1342 } else if (in_regs[i].first()->is_stack()) {
aoqi@0 1343 if (in_sig_bt[i] == T_ARRAY && map != NULL) {
aoqi@0 1344 int offset_in_older_frame = in_regs[i].first()->reg2stack() + SharedRuntime::out_preserve_stack_slots();
aoqi@0 1345 map->set_oop(VMRegImpl::stack2reg(offset_in_older_frame + stack_slots));
aoqi@0 1346 }
aoqi@0 1347 }
aoqi@0 1348 }
aoqi@0 1349 }
aoqi@0 1350
aoqi@0 1351
aoqi@0 1352 // Check GC_locker::needs_gc and enter the runtime if it's true. This
aoqi@0 1353 // keeps a new JNI critical region from starting until a GC has been
aoqi@0 1354 // forced. Save down any oops in registers and describe them in an
aoqi@0 1355 // OopMap.
aoqi@0 1356 static void check_needs_gc_for_critical_native(MacroAssembler* masm,
aoqi@0 1357 int stack_slots,
aoqi@0 1358 int total_c_args,
aoqi@0 1359 int total_in_args,
aoqi@0 1360 int arg_save_area,
aoqi@0 1361 OopMapSet* oop_maps,
aoqi@0 1362 VMRegPair* in_regs,
aoqi@0 1363 BasicType* in_sig_bt) {
aoqi@0 1364 __ block_comment("check GC_locker::needs_gc");
aoqi@0 1365 Label cont;
aoqi@0 1366 __ cmp8(ExternalAddress((address)GC_locker::needs_gc_address()), false);
aoqi@0 1367 __ jcc(Assembler::equal, cont);
aoqi@0 1368
aoqi@0 1369 // Save down any incoming oops and call into the runtime to halt for a GC
aoqi@0 1370
aoqi@0 1371 OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/);
aoqi@0 1372 save_or_restore_arguments(masm, stack_slots, total_in_args,
aoqi@0 1373 arg_save_area, map, in_regs, in_sig_bt);
aoqi@0 1374
aoqi@0 1375 address the_pc = __ pc();
aoqi@0 1376 oop_maps->add_gc_map( __ offset(), map);
aoqi@0 1377 __ set_last_Java_frame(rsp, noreg, the_pc);
aoqi@0 1378
aoqi@0 1379 __ block_comment("block_for_jni_critical");
aoqi@0 1380 __ movptr(c_rarg0, r15_thread);
aoqi@0 1381 __ mov(r12, rsp); // remember sp
aoqi@0 1382 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
aoqi@0 1383 __ andptr(rsp, -16); // align stack as required by ABI
aoqi@0 1384 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::block_for_jni_critical)));
aoqi@0 1385 __ mov(rsp, r12); // restore sp
aoqi@0 1386 __ reinit_heapbase();
aoqi@0 1387
aoqi@0 1388 __ reset_last_Java_frame(false, true);
aoqi@0 1389
aoqi@0 1390 save_or_restore_arguments(masm, stack_slots, total_in_args,
aoqi@0 1391 arg_save_area, NULL, in_regs, in_sig_bt);
aoqi@0 1392
aoqi@0 1393 __ bind(cont);
aoqi@0 1394 #ifdef ASSERT
aoqi@0 1395 if (StressCriticalJNINatives) {
aoqi@0 1396 // Stress register saving
aoqi@0 1397 OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/);
aoqi@0 1398 save_or_restore_arguments(masm, stack_slots, total_in_args,
aoqi@0 1399 arg_save_area, map, in_regs, in_sig_bt);
aoqi@0 1400 // Destroy argument registers
aoqi@0 1401 for (int i = 0; i < total_in_args - 1; i++) {
aoqi@0 1402 if (in_regs[i].first()->is_Register()) {
aoqi@0 1403 const Register reg = in_regs[i].first()->as_Register();
aoqi@0 1404 __ xorptr(reg, reg);
aoqi@0 1405 } else if (in_regs[i].first()->is_XMMRegister()) {
aoqi@0 1406 __ xorpd(in_regs[i].first()->as_XMMRegister(), in_regs[i].first()->as_XMMRegister());
aoqi@0 1407 } else if (in_regs[i].first()->is_FloatRegister()) {
aoqi@0 1408 ShouldNotReachHere();
aoqi@0 1409 } else if (in_regs[i].first()->is_stack()) {
aoqi@0 1410 // Nothing to do
aoqi@0 1411 } else {
aoqi@0 1412 ShouldNotReachHere();
aoqi@0 1413 }
aoqi@0 1414 if (in_sig_bt[i] == T_LONG || in_sig_bt[i] == T_DOUBLE) {
aoqi@0 1415 i++;
aoqi@0 1416 }
aoqi@0 1417 }
aoqi@0 1418
aoqi@0 1419 save_or_restore_arguments(masm, stack_slots, total_in_args,
aoqi@0 1420 arg_save_area, NULL, in_regs, in_sig_bt);
aoqi@0 1421 }
aoqi@0 1422 #endif
aoqi@0 1423 }
aoqi@0 1424
aoqi@0 1425 // Unpack an array argument into a pointer to the body and the length
aoqi@0 1426 // if the array is non-null, otherwise pass 0 for both.
aoqi@0 1427 static void unpack_array_argument(MacroAssembler* masm, VMRegPair reg, BasicType in_elem_type, VMRegPair body_arg, VMRegPair length_arg) {
aoqi@0 1428 Register tmp_reg = rax;
aoqi@0 1429 assert(!body_arg.first()->is_Register() || body_arg.first()->as_Register() != tmp_reg,
aoqi@0 1430 "possible collision");
aoqi@0 1431 assert(!length_arg.first()->is_Register() || length_arg.first()->as_Register() != tmp_reg,
aoqi@0 1432 "possible collision");
aoqi@0 1433
aoqi@0 1434 __ block_comment("unpack_array_argument {");
aoqi@0 1435
aoqi@0 1436 // Pass the length, ptr pair
aoqi@0 1437 Label is_null, done;
aoqi@0 1438 VMRegPair tmp;
aoqi@0 1439 tmp.set_ptr(tmp_reg->as_VMReg());
aoqi@0 1440 if (reg.first()->is_stack()) {
aoqi@0 1441 // Load the arg up from the stack
aoqi@0 1442 move_ptr(masm, reg, tmp);
aoqi@0 1443 reg = tmp;
aoqi@0 1444 }
aoqi@0 1445 __ testptr(reg.first()->as_Register(), reg.first()->as_Register());
aoqi@0 1446 __ jccb(Assembler::equal, is_null);
aoqi@0 1447 __ lea(tmp_reg, Address(reg.first()->as_Register(), arrayOopDesc::base_offset_in_bytes(in_elem_type)));
aoqi@0 1448 move_ptr(masm, tmp, body_arg);
aoqi@0 1449 // load the length relative to the body.
aoqi@0 1450 __ movl(tmp_reg, Address(tmp_reg, arrayOopDesc::length_offset_in_bytes() -
aoqi@0 1451 arrayOopDesc::base_offset_in_bytes(in_elem_type)));
aoqi@0 1452 move32_64(masm, tmp, length_arg);
aoqi@0 1453 __ jmpb(done);
aoqi@0 1454 __ bind(is_null);
aoqi@0 1455 // Pass zeros
aoqi@0 1456 __ xorptr(tmp_reg, tmp_reg);
aoqi@0 1457 move_ptr(masm, tmp, body_arg);
aoqi@0 1458 move32_64(masm, tmp, length_arg);
aoqi@0 1459 __ bind(done);
aoqi@0 1460
aoqi@0 1461 __ block_comment("} unpack_array_argument");
aoqi@0 1462 }
aoqi@0 1463
aoqi@0 1464
aoqi@0 1465 // Different signatures may require very different orders for the move
aoqi@0 1466 // to avoid clobbering other arguments. There's no simple way to
aoqi@0 1467 // order them safely. Compute a safe order for issuing stores and
aoqi@0 1468 // break any cycles in those stores. This code is fairly general but
aoqi@0 1469 // it's not necessary on the other platforms so we keep it in the
aoqi@0 1470 // platform dependent code instead of moving it into a shared file.
aoqi@0 1471 // (See bugs 7013347 & 7145024.)
aoqi@0 1472 // Note that this code is specific to LP64.
aoqi@0 1473 class ComputeMoveOrder: public StackObj {
aoqi@0 1474 class MoveOperation: public ResourceObj {
aoqi@0 1475 friend class ComputeMoveOrder;
aoqi@0 1476 private:
aoqi@0 1477 VMRegPair _src;
aoqi@0 1478 VMRegPair _dst;
aoqi@0 1479 int _src_index;
aoqi@0 1480 int _dst_index;
aoqi@0 1481 bool _processed;
aoqi@0 1482 MoveOperation* _next;
aoqi@0 1483 MoveOperation* _prev;
aoqi@0 1484
aoqi@0 1485 static int get_id(VMRegPair r) {
aoqi@0 1486 return r.first()->value();
aoqi@0 1487 }
aoqi@0 1488
aoqi@0 1489 public:
aoqi@0 1490 MoveOperation(int src_index, VMRegPair src, int dst_index, VMRegPair dst):
aoqi@0 1491 _src(src)
aoqi@0 1492 , _src_index(src_index)
aoqi@0 1493 , _dst(dst)
aoqi@0 1494 , _dst_index(dst_index)
aoqi@0 1495 , _next(NULL)
aoqi@0 1496 , _prev(NULL)
aoqi@0 1497 , _processed(false) {
aoqi@0 1498 }
aoqi@0 1499
aoqi@0 1500 VMRegPair src() const { return _src; }
aoqi@0 1501 int src_id() const { return get_id(src()); }
aoqi@0 1502 int src_index() const { return _src_index; }
aoqi@0 1503 VMRegPair dst() const { return _dst; }
aoqi@0 1504 void set_dst(int i, VMRegPair dst) { _dst_index = i, _dst = dst; }
aoqi@0 1505 int dst_index() const { return _dst_index; }
aoqi@0 1506 int dst_id() const { return get_id(dst()); }
aoqi@0 1507 MoveOperation* next() const { return _next; }
aoqi@0 1508 MoveOperation* prev() const { return _prev; }
aoqi@0 1509 void set_processed() { _processed = true; }
aoqi@0 1510 bool is_processed() const { return _processed; }
aoqi@0 1511
aoqi@0 1512 // insert
aoqi@0 1513 void break_cycle(VMRegPair temp_register) {
aoqi@0 1514 // create a new store following the last store
aoqi@0 1515 // to move from the temp_register to the original
aoqi@0 1516 MoveOperation* new_store = new MoveOperation(-1, temp_register, dst_index(), dst());
aoqi@0 1517
aoqi@0 1518 // break the cycle of links and insert new_store at the end
aoqi@0 1519 // break the reverse link.
aoqi@0 1520 MoveOperation* p = prev();
aoqi@0 1521 assert(p->next() == this, "must be");
aoqi@0 1522 _prev = NULL;
aoqi@0 1523 p->_next = new_store;
aoqi@0 1524 new_store->_prev = p;
aoqi@0 1525
aoqi@0 1526 // change the original store to save it's value in the temp.
aoqi@0 1527 set_dst(-1, temp_register);
aoqi@0 1528 }
aoqi@0 1529
aoqi@0 1530 void link(GrowableArray<MoveOperation*>& killer) {
aoqi@0 1531 // link this store in front the store that it depends on
aoqi@0 1532 MoveOperation* n = killer.at_grow(src_id(), NULL);
aoqi@0 1533 if (n != NULL) {
aoqi@0 1534 assert(_next == NULL && n->_prev == NULL, "shouldn't have been set yet");
aoqi@0 1535 _next = n;
aoqi@0 1536 n->_prev = this;
aoqi@0 1537 }
aoqi@0 1538 }
aoqi@0 1539 };
aoqi@0 1540
aoqi@0 1541 private:
aoqi@0 1542 GrowableArray<MoveOperation*> edges;
aoqi@0 1543
aoqi@0 1544 public:
aoqi@0 1545 ComputeMoveOrder(int total_in_args, VMRegPair* in_regs, int total_c_args, VMRegPair* out_regs,
aoqi@0 1546 BasicType* in_sig_bt, GrowableArray<int>& arg_order, VMRegPair tmp_vmreg) {
aoqi@0 1547 // Move operations where the dest is the stack can all be
aoqi@0 1548 // scheduled first since they can't interfere with the other moves.
aoqi@0 1549 for (int i = total_in_args - 1, c_arg = total_c_args - 1; i >= 0; i--, c_arg--) {
aoqi@0 1550 if (in_sig_bt[i] == T_ARRAY) {
aoqi@0 1551 c_arg--;
aoqi@0 1552 if (out_regs[c_arg].first()->is_stack() &&
aoqi@0 1553 out_regs[c_arg + 1].first()->is_stack()) {
aoqi@0 1554 arg_order.push(i);
aoqi@0 1555 arg_order.push(c_arg);
aoqi@0 1556 } else {
aoqi@0 1557 if (out_regs[c_arg].first()->is_stack() ||
aoqi@0 1558 in_regs[i].first() == out_regs[c_arg].first()) {
aoqi@0 1559 add_edge(i, in_regs[i].first(), c_arg, out_regs[c_arg + 1]);
aoqi@0 1560 } else {
aoqi@0 1561 add_edge(i, in_regs[i].first(), c_arg, out_regs[c_arg]);
aoqi@0 1562 }
aoqi@0 1563 }
aoqi@0 1564 } else if (in_sig_bt[i] == T_VOID) {
aoqi@0 1565 arg_order.push(i);
aoqi@0 1566 arg_order.push(c_arg);
aoqi@0 1567 } else {
aoqi@0 1568 if (out_regs[c_arg].first()->is_stack() ||
aoqi@0 1569 in_regs[i].first() == out_regs[c_arg].first()) {
aoqi@0 1570 arg_order.push(i);
aoqi@0 1571 arg_order.push(c_arg);
aoqi@0 1572 } else {
aoqi@0 1573 add_edge(i, in_regs[i].first(), c_arg, out_regs[c_arg]);
aoqi@0 1574 }
aoqi@0 1575 }
aoqi@0 1576 }
aoqi@0 1577 // Break any cycles in the register moves and emit the in the
aoqi@0 1578 // proper order.
aoqi@0 1579 GrowableArray<MoveOperation*>* stores = get_store_order(tmp_vmreg);
aoqi@0 1580 for (int i = 0; i < stores->length(); i++) {
aoqi@0 1581 arg_order.push(stores->at(i)->src_index());
aoqi@0 1582 arg_order.push(stores->at(i)->dst_index());
aoqi@0 1583 }
aoqi@0 1584 }
aoqi@0 1585
aoqi@0 1586 // Collected all the move operations
aoqi@0 1587 void add_edge(int src_index, VMRegPair src, int dst_index, VMRegPair dst) {
aoqi@0 1588 if (src.first() == dst.first()) return;
aoqi@0 1589 edges.append(new MoveOperation(src_index, src, dst_index, dst));
aoqi@0 1590 }
aoqi@0 1591
aoqi@0 1592 // Walk the edges breaking cycles between moves. The result list
aoqi@0 1593 // can be walked in order to produce the proper set of loads
aoqi@0 1594 GrowableArray<MoveOperation*>* get_store_order(VMRegPair temp_register) {
aoqi@0 1595 // Record which moves kill which values
aoqi@0 1596 GrowableArray<MoveOperation*> killer;
aoqi@0 1597 for (int i = 0; i < edges.length(); i++) {
aoqi@0 1598 MoveOperation* s = edges.at(i);
aoqi@0 1599 assert(killer.at_grow(s->dst_id(), NULL) == NULL, "only one killer");
aoqi@0 1600 killer.at_put_grow(s->dst_id(), s, NULL);
aoqi@0 1601 }
aoqi@0 1602 assert(killer.at_grow(MoveOperation::get_id(temp_register), NULL) == NULL,
aoqi@0 1603 "make sure temp isn't in the registers that are killed");
aoqi@0 1604
aoqi@0 1605 // create links between loads and stores
aoqi@0 1606 for (int i = 0; i < edges.length(); i++) {
aoqi@0 1607 edges.at(i)->link(killer);
aoqi@0 1608 }
aoqi@0 1609
aoqi@0 1610 // at this point, all the move operations are chained together
aoqi@0 1611 // in a doubly linked list. Processing it backwards finds
aoqi@0 1612 // the beginning of the chain, forwards finds the end. If there's
aoqi@0 1613 // a cycle it can be broken at any point, so pick an edge and walk
aoqi@0 1614 // backward until the list ends or we end where we started.
aoqi@0 1615 GrowableArray<MoveOperation*>* stores = new GrowableArray<MoveOperation*>();
aoqi@0 1616 for (int e = 0; e < edges.length(); e++) {
aoqi@0 1617 MoveOperation* s = edges.at(e);
aoqi@0 1618 if (!s->is_processed()) {
aoqi@0 1619 MoveOperation* start = s;
aoqi@0 1620 // search for the beginning of the chain or cycle
aoqi@0 1621 while (start->prev() != NULL && start->prev() != s) {
aoqi@0 1622 start = start->prev();
aoqi@0 1623 }
aoqi@0 1624 if (start->prev() == s) {
aoqi@0 1625 start->break_cycle(temp_register);
aoqi@0 1626 }
aoqi@0 1627 // walk the chain forward inserting to store list
aoqi@0 1628 while (start != NULL) {
aoqi@0 1629 stores->append(start);
aoqi@0 1630 start->set_processed();
aoqi@0 1631 start = start->next();
aoqi@0 1632 }
aoqi@0 1633 }
aoqi@0 1634 }
aoqi@0 1635 return stores;
aoqi@0 1636 }
aoqi@0 1637 };
aoqi@0 1638
aoqi@0 1639 static void verify_oop_args(MacroAssembler* masm,
aoqi@0 1640 methodHandle method,
aoqi@0 1641 const BasicType* sig_bt,
aoqi@0 1642 const VMRegPair* regs) {
aoqi@0 1643 Register temp_reg = rbx; // not part of any compiled calling seq
aoqi@0 1644 if (VerifyOops) {
aoqi@0 1645 for (int i = 0; i < method->size_of_parameters(); i++) {
aoqi@0 1646 if (sig_bt[i] == T_OBJECT ||
aoqi@0 1647 sig_bt[i] == T_ARRAY) {
aoqi@0 1648 VMReg r = regs[i].first();
aoqi@0 1649 assert(r->is_valid(), "bad oop arg");
aoqi@0 1650 if (r->is_stack()) {
aoqi@0 1651 __ movptr(temp_reg, Address(rsp, r->reg2stack() * VMRegImpl::stack_slot_size + wordSize));
aoqi@0 1652 __ verify_oop(temp_reg);
aoqi@0 1653 } else {
aoqi@0 1654 __ verify_oop(r->as_Register());
aoqi@0 1655 }
aoqi@0 1656 }
aoqi@0 1657 }
aoqi@0 1658 }
aoqi@0 1659 }
aoqi@0 1660
aoqi@0 1661 static void gen_special_dispatch(MacroAssembler* masm,
aoqi@0 1662 methodHandle method,
aoqi@0 1663 const BasicType* sig_bt,
aoqi@0 1664 const VMRegPair* regs) {
aoqi@0 1665 verify_oop_args(masm, method, sig_bt, regs);
aoqi@0 1666 vmIntrinsics::ID iid = method->intrinsic_id();
aoqi@0 1667
aoqi@0 1668 // Now write the args into the outgoing interpreter space
aoqi@0 1669 bool has_receiver = false;
aoqi@0 1670 Register receiver_reg = noreg;
aoqi@0 1671 int member_arg_pos = -1;
aoqi@0 1672 Register member_reg = noreg;
aoqi@0 1673 int ref_kind = MethodHandles::signature_polymorphic_intrinsic_ref_kind(iid);
aoqi@0 1674 if (ref_kind != 0) {
aoqi@0 1675 member_arg_pos = method->size_of_parameters() - 1; // trailing MemberName argument
aoqi@0 1676 member_reg = rbx; // known to be free at this point
aoqi@0 1677 has_receiver = MethodHandles::ref_kind_has_receiver(ref_kind);
aoqi@0 1678 } else if (iid == vmIntrinsics::_invokeBasic) {
aoqi@0 1679 has_receiver = true;
aoqi@0 1680 } else {
aoqi@0 1681 fatal(err_msg_res("unexpected intrinsic id %d", iid));
aoqi@0 1682 }
aoqi@0 1683
aoqi@0 1684 if (member_reg != noreg) {
aoqi@0 1685 // Load the member_arg into register, if necessary.
aoqi@0 1686 SharedRuntime::check_member_name_argument_is_last_argument(method, sig_bt, regs);
aoqi@0 1687 VMReg r = regs[member_arg_pos].first();
aoqi@0 1688 if (r->is_stack()) {
aoqi@0 1689 __ movptr(member_reg, Address(rsp, r->reg2stack() * VMRegImpl::stack_slot_size + wordSize));
aoqi@0 1690 } else {
aoqi@0 1691 // no data motion is needed
aoqi@0 1692 member_reg = r->as_Register();
aoqi@0 1693 }
aoqi@0 1694 }
aoqi@0 1695
aoqi@0 1696 if (has_receiver) {
aoqi@0 1697 // Make sure the receiver is loaded into a register.
aoqi@0 1698 assert(method->size_of_parameters() > 0, "oob");
aoqi@0 1699 assert(sig_bt[0] == T_OBJECT, "receiver argument must be an object");
aoqi@0 1700 VMReg r = regs[0].first();
aoqi@0 1701 assert(r->is_valid(), "bad receiver arg");
aoqi@0 1702 if (r->is_stack()) {
aoqi@0 1703 // Porting note: This assumes that compiled calling conventions always
aoqi@0 1704 // pass the receiver oop in a register. If this is not true on some
aoqi@0 1705 // platform, pick a temp and load the receiver from stack.
aoqi@0 1706 fatal("receiver always in a register");
aoqi@0 1707 receiver_reg = j_rarg0; // known to be free at this point
aoqi@0 1708 __ movptr(receiver_reg, Address(rsp, r->reg2stack() * VMRegImpl::stack_slot_size + wordSize));
aoqi@0 1709 } else {
aoqi@0 1710 // no data motion is needed
aoqi@0 1711 receiver_reg = r->as_Register();
aoqi@0 1712 }
aoqi@0 1713 }
aoqi@0 1714
aoqi@0 1715 // Figure out which address we are really jumping to:
aoqi@0 1716 MethodHandles::generate_method_handle_dispatch(masm, iid,
aoqi@0 1717 receiver_reg, member_reg, /*for_compiler_entry:*/ true);
aoqi@0 1718 }
aoqi@0 1719
aoqi@0 1720 // ---------------------------------------------------------------------------
aoqi@0 1721 // Generate a native wrapper for a given method. The method takes arguments
aoqi@0 1722 // in the Java compiled code convention, marshals them to the native
aoqi@0 1723 // convention (handlizes oops, etc), transitions to native, makes the call,
aoqi@0 1724 // returns to java state (possibly blocking), unhandlizes any result and
aoqi@0 1725 // returns.
aoqi@0 1726 //
aoqi@0 1727 // Critical native functions are a shorthand for the use of
aoqi@0 1728 // GetPrimtiveArrayCritical and disallow the use of any other JNI
aoqi@0 1729 // functions. The wrapper is expected to unpack the arguments before
aoqi@0 1730 // passing them to the callee and perform checks before and after the
aoqi@0 1731 // native call to ensure that they GC_locker
aoqi@0 1732 // lock_critical/unlock_critical semantics are followed. Some other
aoqi@0 1733 // parts of JNI setup are skipped like the tear down of the JNI handle
aoqi@0 1734 // block and the check for pending exceptions it's impossible for them
aoqi@0 1735 // to be thrown.
aoqi@0 1736 //
aoqi@0 1737 // They are roughly structured like this:
aoqi@0 1738 // if (GC_locker::needs_gc())
aoqi@0 1739 // SharedRuntime::block_for_jni_critical();
aoqi@0 1740 // tranistion to thread_in_native
aoqi@0 1741 // unpack arrray arguments and call native entry point
aoqi@0 1742 // check for safepoint in progress
aoqi@0 1743 // check if any thread suspend flags are set
aoqi@0 1744 // call into JVM and possible unlock the JNI critical
aoqi@0 1745 // if a GC was suppressed while in the critical native.
aoqi@0 1746 // transition back to thread_in_Java
aoqi@0 1747 // return to caller
aoqi@0 1748 //
aoqi@0 1749 nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
aoqi@0 1750 methodHandle method,
aoqi@0 1751 int compile_id,
aoqi@0 1752 BasicType* in_sig_bt,
aoqi@0 1753 VMRegPair* in_regs,
aoqi@0 1754 BasicType ret_type) {
aoqi@0 1755 if (method->is_method_handle_intrinsic()) {
aoqi@0 1756 vmIntrinsics::ID iid = method->intrinsic_id();
aoqi@0 1757 intptr_t start = (intptr_t)__ pc();
aoqi@0 1758 int vep_offset = ((intptr_t)__ pc()) - start;
aoqi@0 1759 gen_special_dispatch(masm,
aoqi@0 1760 method,
aoqi@0 1761 in_sig_bt,
aoqi@0 1762 in_regs);
aoqi@0 1763 int frame_complete = ((intptr_t)__ pc()) - start; // not complete, period
aoqi@0 1764 __ flush();
aoqi@0 1765 int stack_slots = SharedRuntime::out_preserve_stack_slots(); // no out slots at all, actually
aoqi@0 1766 return nmethod::new_native_nmethod(method,
aoqi@0 1767 compile_id,
aoqi@0 1768 masm->code(),
aoqi@0 1769 vep_offset,
aoqi@0 1770 frame_complete,
aoqi@0 1771 stack_slots / VMRegImpl::slots_per_word,
aoqi@0 1772 in_ByteSize(-1),
aoqi@0 1773 in_ByteSize(-1),
aoqi@0 1774 (OopMapSet*)NULL);
aoqi@0 1775 }
aoqi@0 1776 bool is_critical_native = true;
aoqi@0 1777 address native_func = method->critical_native_function();
aoqi@0 1778 if (native_func == NULL) {
aoqi@0 1779 native_func = method->native_function();
aoqi@0 1780 is_critical_native = false;
aoqi@0 1781 }
aoqi@0 1782 assert(native_func != NULL, "must have function");
aoqi@0 1783
aoqi@0 1784 // An OopMap for lock (and class if static)
aoqi@0 1785 OopMapSet *oop_maps = new OopMapSet();
aoqi@0 1786 intptr_t start = (intptr_t)__ pc();
aoqi@0 1787
aoqi@0 1788 // We have received a description of where all the java arg are located
aoqi@0 1789 // on entry to the wrapper. We need to convert these args to where
aoqi@0 1790 // the jni function will expect them. To figure out where they go
aoqi@0 1791 // we convert the java signature to a C signature by inserting
aoqi@0 1792 // the hidden arguments as arg[0] and possibly arg[1] (static method)
aoqi@0 1793
aoqi@0 1794 const int total_in_args = method->size_of_parameters();
aoqi@0 1795 int total_c_args = total_in_args;
aoqi@0 1796 if (!is_critical_native) {
aoqi@0 1797 total_c_args += 1;
aoqi@0 1798 if (method->is_static()) {
aoqi@0 1799 total_c_args++;
aoqi@0 1800 }
aoqi@0 1801 } else {
aoqi@0 1802 for (int i = 0; i < total_in_args; i++) {
aoqi@0 1803 if (in_sig_bt[i] == T_ARRAY) {
aoqi@0 1804 total_c_args++;
aoqi@0 1805 }
aoqi@0 1806 }
aoqi@0 1807 }
aoqi@0 1808
aoqi@0 1809 BasicType* out_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_c_args);
aoqi@0 1810 VMRegPair* out_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_c_args);
aoqi@0 1811 BasicType* in_elem_bt = NULL;
aoqi@0 1812
aoqi@0 1813 int argc = 0;
aoqi@0 1814 if (!is_critical_native) {
aoqi@0 1815 out_sig_bt[argc++] = T_ADDRESS;
aoqi@0 1816 if (method->is_static()) {
aoqi@0 1817 out_sig_bt[argc++] = T_OBJECT;
aoqi@0 1818 }
aoqi@0 1819
aoqi@0 1820 for (int i = 0; i < total_in_args ; i++ ) {
aoqi@0 1821 out_sig_bt[argc++] = in_sig_bt[i];
aoqi@0 1822 }
aoqi@0 1823 } else {
aoqi@0 1824 Thread* THREAD = Thread::current();
aoqi@0 1825 in_elem_bt = NEW_RESOURCE_ARRAY(BasicType, total_in_args);
aoqi@0 1826 SignatureStream ss(method->signature());
aoqi@0 1827 for (int i = 0; i < total_in_args ; i++ ) {
aoqi@0 1828 if (in_sig_bt[i] == T_ARRAY) {
aoqi@0 1829 // Arrays are passed as int, elem* pair
aoqi@0 1830 out_sig_bt[argc++] = T_INT;
aoqi@0 1831 out_sig_bt[argc++] = T_ADDRESS;
aoqi@0 1832 Symbol* atype = ss.as_symbol(CHECK_NULL);
aoqi@0 1833 const char* at = atype->as_C_string();
aoqi@0 1834 if (strlen(at) == 2) {
aoqi@0 1835 assert(at[0] == '[', "must be");
aoqi@0 1836 switch (at[1]) {
aoqi@0 1837 case 'B': in_elem_bt[i] = T_BYTE; break;
aoqi@0 1838 case 'C': in_elem_bt[i] = T_CHAR; break;
aoqi@0 1839 case 'D': in_elem_bt[i] = T_DOUBLE; break;
aoqi@0 1840 case 'F': in_elem_bt[i] = T_FLOAT; break;
aoqi@0 1841 case 'I': in_elem_bt[i] = T_INT; break;
aoqi@0 1842 case 'J': in_elem_bt[i] = T_LONG; break;
aoqi@0 1843 case 'S': in_elem_bt[i] = T_SHORT; break;
aoqi@0 1844 case 'Z': in_elem_bt[i] = T_BOOLEAN; break;
aoqi@0 1845 default: ShouldNotReachHere();
aoqi@0 1846 }
aoqi@0 1847 }
aoqi@0 1848 } else {
aoqi@0 1849 out_sig_bt[argc++] = in_sig_bt[i];
aoqi@0 1850 in_elem_bt[i] = T_VOID;
aoqi@0 1851 }
aoqi@0 1852 if (in_sig_bt[i] != T_VOID) {
aoqi@0 1853 assert(in_sig_bt[i] == ss.type(), "must match");
aoqi@0 1854 ss.next();
aoqi@0 1855 }
aoqi@0 1856 }
aoqi@0 1857 }
aoqi@0 1858
aoqi@0 1859 // Now figure out where the args must be stored and how much stack space
aoqi@0 1860 // they require.
aoqi@0 1861 int out_arg_slots;
aoqi@0 1862 out_arg_slots = c_calling_convention(out_sig_bt, out_regs, NULL, total_c_args);
aoqi@0 1863
aoqi@0 1864 // Compute framesize for the wrapper. We need to handlize all oops in
aoqi@0 1865 // incoming registers
aoqi@0 1866
aoqi@0 1867 // Calculate the total number of stack slots we will need.
aoqi@0 1868
aoqi@0 1869 // First count the abi requirement plus all of the outgoing args
aoqi@0 1870 int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
aoqi@0 1871
aoqi@0 1872 // Now the space for the inbound oop handle area
aoqi@0 1873 int total_save_slots = 6 * VMRegImpl::slots_per_word; // 6 arguments passed in registers
aoqi@0 1874 if (is_critical_native) {
aoqi@0 1875 // Critical natives may have to call out so they need a save area
aoqi@0 1876 // for register arguments.
aoqi@0 1877 int double_slots = 0;
aoqi@0 1878 int single_slots = 0;
aoqi@0 1879 for ( int i = 0; i < total_in_args; i++) {
aoqi@0 1880 if (in_regs[i].first()->is_Register()) {
aoqi@0 1881 const Register reg = in_regs[i].first()->as_Register();
aoqi@0 1882 switch (in_sig_bt[i]) {
aoqi@0 1883 case T_BOOLEAN:
aoqi@0 1884 case T_BYTE:
aoqi@0 1885 case T_SHORT:
aoqi@0 1886 case T_CHAR:
aoqi@0 1887 case T_INT: single_slots++; break;
aoqi@0 1888 case T_ARRAY: // specific to LP64 (7145024)
aoqi@0 1889 case T_LONG: double_slots++; break;
aoqi@0 1890 default: ShouldNotReachHere();
aoqi@0 1891 }
aoqi@0 1892 } else if (in_regs[i].first()->is_XMMRegister()) {
aoqi@0 1893 switch (in_sig_bt[i]) {
aoqi@0 1894 case T_FLOAT: single_slots++; break;
aoqi@0 1895 case T_DOUBLE: double_slots++; break;
aoqi@0 1896 default: ShouldNotReachHere();
aoqi@0 1897 }
aoqi@0 1898 } else if (in_regs[i].first()->is_FloatRegister()) {
aoqi@0 1899 ShouldNotReachHere();
aoqi@0 1900 }
aoqi@0 1901 }
aoqi@0 1902 total_save_slots = double_slots * 2 + single_slots;
aoqi@0 1903 // align the save area
aoqi@0 1904 if (double_slots != 0) {
aoqi@0 1905 stack_slots = round_to(stack_slots, 2);
aoqi@0 1906 }
aoqi@0 1907 }
aoqi@0 1908
aoqi@0 1909 int oop_handle_offset = stack_slots;
aoqi@0 1910 stack_slots += total_save_slots;
aoqi@0 1911
aoqi@0 1912 // Now any space we need for handlizing a klass if static method
aoqi@0 1913
aoqi@0 1914 int klass_slot_offset = 0;
aoqi@0 1915 int klass_offset = -1;
aoqi@0 1916 int lock_slot_offset = 0;
aoqi@0 1917 bool is_static = false;
aoqi@0 1918
aoqi@0 1919 if (method->is_static()) {
aoqi@0 1920 klass_slot_offset = stack_slots;
aoqi@0 1921 stack_slots += VMRegImpl::slots_per_word;
aoqi@0 1922 klass_offset = klass_slot_offset * VMRegImpl::stack_slot_size;
aoqi@0 1923 is_static = true;
aoqi@0 1924 }
aoqi@0 1925
aoqi@0 1926 // Plus a lock if needed
aoqi@0 1927
aoqi@0 1928 if (method->is_synchronized()) {
aoqi@0 1929 lock_slot_offset = stack_slots;
aoqi@0 1930 stack_slots += VMRegImpl::slots_per_word;
aoqi@0 1931 }
aoqi@0 1932
aoqi@0 1933 // Now a place (+2) to save return values or temp during shuffling
aoqi@0 1934 // + 4 for return address (which we own) and saved rbp
aoqi@0 1935 stack_slots += 6;
aoqi@0 1936
aoqi@0 1937 // Ok The space we have allocated will look like:
aoqi@0 1938 //
aoqi@0 1939 //
aoqi@0 1940 // FP-> | |
aoqi@0 1941 // |---------------------|
aoqi@0 1942 // | 2 slots for moves |
aoqi@0 1943 // |---------------------|
aoqi@0 1944 // | lock box (if sync) |
aoqi@0 1945 // |---------------------| <- lock_slot_offset
aoqi@0 1946 // | klass (if static) |
aoqi@0 1947 // |---------------------| <- klass_slot_offset
aoqi@0 1948 // | oopHandle area |
aoqi@0 1949 // |---------------------| <- oop_handle_offset (6 java arg registers)
aoqi@0 1950 // | outbound memory |
aoqi@0 1951 // | based arguments |
aoqi@0 1952 // | |
aoqi@0 1953 // |---------------------|
aoqi@0 1954 // | |
aoqi@0 1955 // SP-> | out_preserved_slots |
aoqi@0 1956 //
aoqi@0 1957 //
aoqi@0 1958
aoqi@0 1959
aoqi@0 1960 // Now compute actual number of stack words we need rounding to make
aoqi@0 1961 // stack properly aligned.
aoqi@0 1962 stack_slots = round_to(stack_slots, StackAlignmentInSlots);
aoqi@0 1963
aoqi@0 1964 int stack_size = stack_slots * VMRegImpl::stack_slot_size;
aoqi@0 1965
aoqi@0 1966 // First thing make an ic check to see if we should even be here
aoqi@0 1967
aoqi@0 1968 // We are free to use all registers as temps without saving them and
aoqi@0 1969 // restoring them except rbp. rbp is the only callee save register
aoqi@0 1970 // as far as the interpreter and the compiler(s) are concerned.
aoqi@0 1971
aoqi@0 1972
aoqi@0 1973 const Register ic_reg = rax;
aoqi@0 1974 const Register receiver = j_rarg0;
aoqi@0 1975
aoqi@0 1976 Label hit;
aoqi@0 1977 Label exception_pending;
aoqi@0 1978
aoqi@0 1979 assert_different_registers(ic_reg, receiver, rscratch1);
aoqi@0 1980 __ verify_oop(receiver);
aoqi@0 1981 __ load_klass(rscratch1, receiver);
aoqi@0 1982 __ cmpq(ic_reg, rscratch1);
aoqi@0 1983 __ jcc(Assembler::equal, hit);
aoqi@0 1984
aoqi@0 1985 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
aoqi@0 1986
aoqi@0 1987 // Verified entry point must be aligned
aoqi@0 1988 __ align(8);
aoqi@0 1989
aoqi@0 1990 __ bind(hit);
aoqi@0 1991
aoqi@0 1992 int vep_offset = ((intptr_t)__ pc()) - start;
aoqi@0 1993
aoqi@0 1994 // The instruction at the verified entry point must be 5 bytes or longer
aoqi@0 1995 // because it can be patched on the fly by make_non_entrant. The stack bang
aoqi@0 1996 // instruction fits that requirement.
aoqi@0 1997
aoqi@0 1998 // Generate stack overflow check
aoqi@0 1999
aoqi@0 2000 if (UseStackBanging) {
aoqi@0 2001 __ bang_stack_with_offset(StackShadowPages*os::vm_page_size());
aoqi@0 2002 } else {
aoqi@0 2003 // need a 5 byte instruction to allow MT safe patching to non-entrant
aoqi@0 2004 __ fat_nop();
aoqi@0 2005 }
aoqi@0 2006
aoqi@0 2007 // Generate a new frame for the wrapper.
aoqi@0 2008 __ enter();
aoqi@0 2009 // -2 because return address is already present and so is saved rbp
aoqi@0 2010 __ subptr(rsp, stack_size - 2*wordSize);
aoqi@0 2011
aoqi@0 2012 // Frame is now completed as far as size and linkage.
aoqi@0 2013 int frame_complete = ((intptr_t)__ pc()) - start;
aoqi@0 2014
aoqi@0 2015 if (UseRTMLocking) {
aoqi@0 2016 // Abort RTM transaction before calling JNI
aoqi@0 2017 // because critical section will be large and will be
aoqi@0 2018 // aborted anyway. Also nmethod could be deoptimized.
aoqi@0 2019 __ xabort(0);
aoqi@0 2020 }
aoqi@0 2021
aoqi@0 2022 #ifdef ASSERT
aoqi@0 2023 {
aoqi@0 2024 Label L;
aoqi@0 2025 __ mov(rax, rsp);
aoqi@0 2026 __ andptr(rax, -16); // must be 16 byte boundary (see amd64 ABI)
aoqi@0 2027 __ cmpptr(rax, rsp);
aoqi@0 2028 __ jcc(Assembler::equal, L);
aoqi@0 2029 __ stop("improperly aligned stack");
aoqi@0 2030 __ bind(L);
aoqi@0 2031 }
aoqi@0 2032 #endif /* ASSERT */
aoqi@0 2033
aoqi@0 2034
aoqi@0 2035 // We use r14 as the oop handle for the receiver/klass
aoqi@0 2036 // It is callee save so it survives the call to native
aoqi@0 2037
aoqi@0 2038 const Register oop_handle_reg = r14;
aoqi@0 2039
aoqi@0 2040 if (is_critical_native) {
aoqi@0 2041 check_needs_gc_for_critical_native(masm, stack_slots, total_c_args, total_in_args,
aoqi@0 2042 oop_handle_offset, oop_maps, in_regs, in_sig_bt);
aoqi@0 2043 }
aoqi@0 2044
aoqi@0 2045 //
aoqi@0 2046 // We immediately shuffle the arguments so that any vm call we have to
aoqi@0 2047 // make from here on out (sync slow path, jvmti, etc.) we will have
aoqi@0 2048 // captured the oops from our caller and have a valid oopMap for
aoqi@0 2049 // them.
aoqi@0 2050
aoqi@0 2051 // -----------------
aoqi@0 2052 // The Grand Shuffle
aoqi@0 2053
aoqi@0 2054 // The Java calling convention is either equal (linux) or denser (win64) than the
aoqi@0 2055 // c calling convention. However the because of the jni_env argument the c calling
aoqi@0 2056 // convention always has at least one more (and two for static) arguments than Java.
aoqi@0 2057 // Therefore if we move the args from java -> c backwards then we will never have
aoqi@0 2058 // a register->register conflict and we don't have to build a dependency graph
aoqi@0 2059 // and figure out how to break any cycles.
aoqi@0 2060 //
aoqi@0 2061
aoqi@0 2062 // Record esp-based slot for receiver on stack for non-static methods
aoqi@0 2063 int receiver_offset = -1;
aoqi@0 2064
aoqi@0 2065 // This is a trick. We double the stack slots so we can claim
aoqi@0 2066 // the oops in the caller's frame. Since we are sure to have
aoqi@0 2067 // more args than the caller doubling is enough to make
aoqi@0 2068 // sure we can capture all the incoming oop args from the
aoqi@0 2069 // caller.
aoqi@0 2070 //
aoqi@0 2071 OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/);
aoqi@0 2072
aoqi@0 2073 // Mark location of rbp (someday)
aoqi@0 2074 // map->set_callee_saved(VMRegImpl::stack2reg( stack_slots - 2), stack_slots * 2, 0, vmreg(rbp));
aoqi@0 2075
aoqi@0 2076 // Use eax, ebx as temporaries during any memory-memory moves we have to do
aoqi@0 2077 // All inbound args are referenced based on rbp and all outbound args via rsp.
aoqi@0 2078
aoqi@0 2079
aoqi@0 2080 #ifdef ASSERT
aoqi@0 2081 bool reg_destroyed[RegisterImpl::number_of_registers];
aoqi@0 2082 bool freg_destroyed[XMMRegisterImpl::number_of_registers];
aoqi@0 2083 for ( int r = 0 ; r < RegisterImpl::number_of_registers ; r++ ) {
aoqi@0 2084 reg_destroyed[r] = false;
aoqi@0 2085 }
aoqi@0 2086 for ( int f = 0 ; f < XMMRegisterImpl::number_of_registers ; f++ ) {
aoqi@0 2087 freg_destroyed[f] = false;
aoqi@0 2088 }
aoqi@0 2089
aoqi@0 2090 #endif /* ASSERT */
aoqi@0 2091
aoqi@0 2092 // This may iterate in two different directions depending on the
aoqi@0 2093 // kind of native it is. The reason is that for regular JNI natives
aoqi@0 2094 // the incoming and outgoing registers are offset upwards and for
aoqi@0 2095 // critical natives they are offset down.
aoqi@0 2096 GrowableArray<int> arg_order(2 * total_in_args);
aoqi@0 2097 VMRegPair tmp_vmreg;
aoqi@0 2098 tmp_vmreg.set1(rbx->as_VMReg());
aoqi@0 2099
aoqi@0 2100 if (!is_critical_native) {
aoqi@0 2101 for (int i = total_in_args - 1, c_arg = total_c_args - 1; i >= 0; i--, c_arg--) {
aoqi@0 2102 arg_order.push(i);
aoqi@0 2103 arg_order.push(c_arg);
aoqi@0 2104 }
aoqi@0 2105 } else {
aoqi@0 2106 // Compute a valid move order, using tmp_vmreg to break any cycles
aoqi@0 2107 ComputeMoveOrder cmo(total_in_args, in_regs, total_c_args, out_regs, in_sig_bt, arg_order, tmp_vmreg);
aoqi@0 2108 }
aoqi@0 2109
aoqi@0 2110 int temploc = -1;
aoqi@0 2111 for (int ai = 0; ai < arg_order.length(); ai += 2) {
aoqi@0 2112 int i = arg_order.at(ai);
aoqi@0 2113 int c_arg = arg_order.at(ai + 1);
aoqi@0 2114 __ block_comment(err_msg("move %d -> %d", i, c_arg));
aoqi@0 2115 if (c_arg == -1) {
aoqi@0 2116 assert(is_critical_native, "should only be required for critical natives");
aoqi@0 2117 // This arg needs to be moved to a temporary
aoqi@0 2118 __ mov(tmp_vmreg.first()->as_Register(), in_regs[i].first()->as_Register());
aoqi@0 2119 in_regs[i] = tmp_vmreg;
aoqi@0 2120 temploc = i;
aoqi@0 2121 continue;
aoqi@0 2122 } else if (i == -1) {
aoqi@0 2123 assert(is_critical_native, "should only be required for critical natives");
aoqi@0 2124 // Read from the temporary location
aoqi@0 2125 assert(temploc != -1, "must be valid");
aoqi@0 2126 i = temploc;
aoqi@0 2127 temploc = -1;
aoqi@0 2128 }
aoqi@0 2129 #ifdef ASSERT
aoqi@0 2130 if (in_regs[i].first()->is_Register()) {
aoqi@0 2131 assert(!reg_destroyed[in_regs[i].first()->as_Register()->encoding()], "destroyed reg!");
aoqi@0 2132 } else if (in_regs[i].first()->is_XMMRegister()) {
aoqi@0 2133 assert(!freg_destroyed[in_regs[i].first()->as_XMMRegister()->encoding()], "destroyed reg!");
aoqi@0 2134 }
aoqi@0 2135 if (out_regs[c_arg].first()->is_Register()) {
aoqi@0 2136 reg_destroyed[out_regs[c_arg].first()->as_Register()->encoding()] = true;
aoqi@0 2137 } else if (out_regs[c_arg].first()->is_XMMRegister()) {
aoqi@0 2138 freg_destroyed[out_regs[c_arg].first()->as_XMMRegister()->encoding()] = true;
aoqi@0 2139 }
aoqi@0 2140 #endif /* ASSERT */
aoqi@0 2141 switch (in_sig_bt[i]) {
aoqi@0 2142 case T_ARRAY:
aoqi@0 2143 if (is_critical_native) {
aoqi@0 2144 unpack_array_argument(masm, in_regs[i], in_elem_bt[i], out_regs[c_arg + 1], out_regs[c_arg]);
aoqi@0 2145 c_arg++;
aoqi@0 2146 #ifdef ASSERT
aoqi@0 2147 if (out_regs[c_arg].first()->is_Register()) {
aoqi@0 2148 reg_destroyed[out_regs[c_arg].first()->as_Register()->encoding()] = true;
aoqi@0 2149 } else if (out_regs[c_arg].first()->is_XMMRegister()) {
aoqi@0 2150 freg_destroyed[out_regs[c_arg].first()->as_XMMRegister()->encoding()] = true;
aoqi@0 2151 }
aoqi@0 2152 #endif
aoqi@0 2153 break;
aoqi@0 2154 }
aoqi@0 2155 case T_OBJECT:
aoqi@0 2156 assert(!is_critical_native, "no oop arguments");
aoqi@0 2157 object_move(masm, map, oop_handle_offset, stack_slots, in_regs[i], out_regs[c_arg],
aoqi@0 2158 ((i == 0) && (!is_static)),
aoqi@0 2159 &receiver_offset);
aoqi@0 2160 break;
aoqi@0 2161 case T_VOID:
aoqi@0 2162 break;
aoqi@0 2163
aoqi@0 2164 case T_FLOAT:
aoqi@0 2165 float_move(masm, in_regs[i], out_regs[c_arg]);
aoqi@0 2166 break;
aoqi@0 2167
aoqi@0 2168 case T_DOUBLE:
aoqi@0 2169 assert( i + 1 < total_in_args &&
aoqi@0 2170 in_sig_bt[i + 1] == T_VOID &&
aoqi@0 2171 out_sig_bt[c_arg+1] == T_VOID, "bad arg list");
aoqi@0 2172 double_move(masm, in_regs[i], out_regs[c_arg]);
aoqi@0 2173 break;
aoqi@0 2174
aoqi@0 2175 case T_LONG :
aoqi@0 2176 long_move(masm, in_regs[i], out_regs[c_arg]);
aoqi@0 2177 break;
aoqi@0 2178
aoqi@0 2179 case T_ADDRESS: assert(false, "found T_ADDRESS in java args");
aoqi@0 2180
aoqi@0 2181 default:
aoqi@0 2182 move32_64(masm, in_regs[i], out_regs[c_arg]);
aoqi@0 2183 }
aoqi@0 2184 }
aoqi@0 2185
aoqi@0 2186 int c_arg;
aoqi@0 2187
aoqi@0 2188 // Pre-load a static method's oop into r14. Used both by locking code and
aoqi@0 2189 // the normal JNI call code.
aoqi@0 2190 if (!is_critical_native) {
aoqi@0 2191 // point c_arg at the first arg that is already loaded in case we
aoqi@0 2192 // need to spill before we call out
aoqi@0 2193 c_arg = total_c_args - total_in_args;
aoqi@0 2194
aoqi@0 2195 if (method->is_static()) {
aoqi@0 2196
aoqi@0 2197 // load oop into a register
aoqi@0 2198 __ movoop(oop_handle_reg, JNIHandles::make_local(method->method_holder()->java_mirror()));
aoqi@0 2199
aoqi@0 2200 // Now handlize the static class mirror it's known not-null.
aoqi@0 2201 __ movptr(Address(rsp, klass_offset), oop_handle_reg);
aoqi@0 2202 map->set_oop(VMRegImpl::stack2reg(klass_slot_offset));
aoqi@0 2203
aoqi@0 2204 // Now get the handle
aoqi@0 2205 __ lea(oop_handle_reg, Address(rsp, klass_offset));
aoqi@0 2206 // store the klass handle as second argument
aoqi@0 2207 __ movptr(c_rarg1, oop_handle_reg);
aoqi@0 2208 // and protect the arg if we must spill
aoqi@0 2209 c_arg--;
aoqi@0 2210 }
aoqi@0 2211 } else {
aoqi@0 2212 // For JNI critical methods we need to save all registers in save_args.
aoqi@0 2213 c_arg = 0;
aoqi@0 2214 }
aoqi@0 2215
aoqi@0 2216 // Change state to native (we save the return address in the thread, since it might not
aoqi@0 2217 // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
aoqi@0 2218 // points into the right code segment. It does not have to be the correct return pc.
aoqi@0 2219 // We use the same pc/oopMap repeatedly when we call out
aoqi@0 2220
aoqi@0 2221 intptr_t the_pc = (intptr_t) __ pc();
aoqi@0 2222 oop_maps->add_gc_map(the_pc - start, map);
aoqi@0 2223
aoqi@0 2224 __ set_last_Java_frame(rsp, noreg, (address)the_pc);
aoqi@0 2225
aoqi@0 2226
aoqi@0 2227 // We have all of the arguments setup at this point. We must not touch any register
aoqi@0 2228 // argument registers at this point (what if we save/restore them there are no oop?
aoqi@0 2229
aoqi@0 2230 {
aoqi@0 2231 SkipIfEqual skip(masm, &DTraceMethodProbes, false);
aoqi@0 2232 // protect the args we've loaded
aoqi@0 2233 save_args(masm, total_c_args, c_arg, out_regs);
aoqi@0 2234 __ mov_metadata(c_rarg1, method());
aoqi@0 2235 __ call_VM_leaf(
aoqi@0 2236 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
aoqi@0 2237 r15_thread, c_rarg1);
aoqi@0 2238 restore_args(masm, total_c_args, c_arg, out_regs);
aoqi@0 2239 }
aoqi@0 2240
aoqi@0 2241 // RedefineClasses() tracing support for obsolete method entry
aoqi@0 2242 if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
aoqi@0 2243 // protect the args we've loaded
aoqi@0 2244 save_args(masm, total_c_args, c_arg, out_regs);
aoqi@0 2245 __ mov_metadata(c_rarg1, method());
aoqi@0 2246 __ call_VM_leaf(
aoqi@0 2247 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
aoqi@0 2248 r15_thread, c_rarg1);
aoqi@0 2249 restore_args(masm, total_c_args, c_arg, out_regs);
aoqi@0 2250 }
aoqi@0 2251
aoqi@0 2252 // Lock a synchronized method
aoqi@0 2253
aoqi@0 2254 // Register definitions used by locking and unlocking
aoqi@0 2255
aoqi@0 2256 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
aoqi@0 2257 const Register obj_reg = rbx; // Will contain the oop
aoqi@0 2258 const Register lock_reg = r13; // Address of compiler lock object (BasicLock)
aoqi@0 2259 const Register old_hdr = r13; // value of old header at unlock time
aoqi@0 2260
aoqi@0 2261 Label slow_path_lock;
aoqi@0 2262 Label lock_done;
aoqi@0 2263
aoqi@0 2264 if (method->is_synchronized()) {
aoqi@0 2265 assert(!is_critical_native, "unhandled");
aoqi@0 2266
aoqi@0 2267
aoqi@0 2268 const int mark_word_offset = BasicLock::displaced_header_offset_in_bytes();
aoqi@0 2269
aoqi@0 2270 // Get the handle (the 2nd argument)
aoqi@0 2271 __ mov(oop_handle_reg, c_rarg1);
aoqi@0 2272
aoqi@0 2273 // Get address of the box
aoqi@0 2274
aoqi@0 2275 __ lea(lock_reg, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
aoqi@0 2276
aoqi@0 2277 // Load the oop from the handle
aoqi@0 2278 __ movptr(obj_reg, Address(oop_handle_reg, 0));
aoqi@0 2279
aoqi@0 2280 if (UseBiasedLocking) {
aoqi@0 2281 __ biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, lock_done, &slow_path_lock);
aoqi@0 2282 }
aoqi@0 2283
aoqi@0 2284 // Load immediate 1 into swap_reg %rax
aoqi@0 2285 __ movl(swap_reg, 1);
aoqi@0 2286
aoqi@0 2287 // Load (object->mark() | 1) into swap_reg %rax
aoqi@0 2288 __ orptr(swap_reg, Address(obj_reg, 0));
aoqi@0 2289
aoqi@0 2290 // Save (object->mark() | 1) into BasicLock's displaced header
aoqi@0 2291 __ movptr(Address(lock_reg, mark_word_offset), swap_reg);
aoqi@0 2292
aoqi@0 2293 if (os::is_MP()) {
aoqi@0 2294 __ lock();
aoqi@0 2295 }
aoqi@0 2296
aoqi@0 2297 // src -> dest iff dest == rax else rax <- dest
aoqi@0 2298 __ cmpxchgptr(lock_reg, Address(obj_reg, 0));
aoqi@0 2299 __ jcc(Assembler::equal, lock_done);
aoqi@0 2300
aoqi@0 2301 // Hmm should this move to the slow path code area???
aoqi@0 2302
aoqi@0 2303 // Test if the oopMark is an obvious stack pointer, i.e.,
aoqi@0 2304 // 1) (mark & 3) == 0, and
aoqi@0 2305 // 2) rsp <= mark < mark + os::pagesize()
aoqi@0 2306 // These 3 tests can be done by evaluating the following
aoqi@0 2307 // expression: ((mark - rsp) & (3 - os::vm_page_size())),
aoqi@0 2308 // assuming both stack pointer and pagesize have their
aoqi@0 2309 // least significant 2 bits clear.
aoqi@0 2310 // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
aoqi@0 2311
aoqi@0 2312 __ subptr(swap_reg, rsp);
aoqi@0 2313 __ andptr(swap_reg, 3 - os::vm_page_size());
aoqi@0 2314
aoqi@0 2315 // Save the test result, for recursive case, the result is zero
aoqi@0 2316 __ movptr(Address(lock_reg, mark_word_offset), swap_reg);
aoqi@0 2317 __ jcc(Assembler::notEqual, slow_path_lock);
aoqi@0 2318
aoqi@0 2319 // Slow path will re-enter here
aoqi@0 2320
aoqi@0 2321 __ bind(lock_done);
aoqi@0 2322 }
aoqi@0 2323
aoqi@0 2324
aoqi@0 2325 // Finally just about ready to make the JNI call
aoqi@0 2326
aoqi@0 2327
aoqi@0 2328 // get JNIEnv* which is first argument to native
aoqi@0 2329 if (!is_critical_native) {
aoqi@0 2330 __ lea(c_rarg0, Address(r15_thread, in_bytes(JavaThread::jni_environment_offset())));
aoqi@0 2331 }
aoqi@0 2332
aoqi@0 2333 // Now set thread in native
aoqi@0 2334 __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_native);
aoqi@0 2335
aoqi@0 2336 __ call(RuntimeAddress(native_func));
aoqi@0 2337
aoqi@0 2338 // Verify or restore cpu control state after JNI call
aoqi@0 2339 __ restore_cpu_control_state_after_jni();
aoqi@0 2340
aoqi@0 2341 // Unpack native results.
aoqi@0 2342 switch (ret_type) {
aoqi@0 2343 case T_BOOLEAN: __ c2bool(rax); break;
aoqi@0 2344 case T_CHAR : __ movzwl(rax, rax); break;
aoqi@0 2345 case T_BYTE : __ sign_extend_byte (rax); break;
aoqi@0 2346 case T_SHORT : __ sign_extend_short(rax); break;
aoqi@0 2347 case T_INT : /* nothing to do */ break;
aoqi@0 2348 case T_DOUBLE :
aoqi@0 2349 case T_FLOAT :
aoqi@0 2350 // Result is in xmm0 we'll save as needed
aoqi@0 2351 break;
aoqi@0 2352 case T_ARRAY: // Really a handle
aoqi@0 2353 case T_OBJECT: // Really a handle
aoqi@0 2354 break; // can't de-handlize until after safepoint check
aoqi@0 2355 case T_VOID: break;
aoqi@0 2356 case T_LONG: break;
aoqi@0 2357 default : ShouldNotReachHere();
aoqi@0 2358 }
aoqi@0 2359
aoqi@0 2360 // Switch thread to "native transition" state before reading the synchronization state.
aoqi@0 2361 // This additional state is necessary because reading and testing the synchronization
aoqi@0 2362 // state is not atomic w.r.t. GC, as this scenario demonstrates:
aoqi@0 2363 // Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted.
aoqi@0 2364 // VM thread changes sync state to synchronizing and suspends threads for GC.
aoqi@0 2365 // Thread A is resumed to finish this native method, but doesn't block here since it
aoqi@0 2366 // didn't see any synchronization is progress, and escapes.
aoqi@0 2367 __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
aoqi@0 2368
aoqi@0 2369 if(os::is_MP()) {
aoqi@0 2370 if (UseMembar) {
aoqi@0 2371 // Force this write out before the read below
aoqi@0 2372 __ membar(Assembler::Membar_mask_bits(
aoqi@0 2373 Assembler::LoadLoad | Assembler::LoadStore |
aoqi@0 2374 Assembler::StoreLoad | Assembler::StoreStore));
aoqi@0 2375 } else {
aoqi@0 2376 // Write serialization page so VM thread can do a pseudo remote membar.
aoqi@0 2377 // We use the current thread pointer to calculate a thread specific
aoqi@0 2378 // offset to write to within the page. This minimizes bus traffic
aoqi@0 2379 // due to cache line collision.
aoqi@0 2380 __ serialize_memory(r15_thread, rcx);
aoqi@0 2381 }
aoqi@0 2382 }
aoqi@0 2383
aoqi@0 2384 Label after_transition;
aoqi@0 2385
aoqi@0 2386 // check for safepoint operation in progress and/or pending suspend requests
aoqi@0 2387 {
aoqi@0 2388 Label Continue;
aoqi@0 2389
aoqi@0 2390 __ cmp32(ExternalAddress((address)SafepointSynchronize::address_of_state()),
aoqi@0 2391 SafepointSynchronize::_not_synchronized);
aoqi@0 2392
aoqi@0 2393 Label L;
aoqi@0 2394 __ jcc(Assembler::notEqual, L);
aoqi@0 2395 __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0);
aoqi@0 2396 __ jcc(Assembler::equal, Continue);
aoqi@0 2397 __ bind(L);
aoqi@0 2398
aoqi@0 2399 // Don't use call_VM as it will see a possible pending exception and forward it
aoqi@0 2400 // and never return here preventing us from clearing _last_native_pc down below.
aoqi@0 2401 // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
aoqi@0 2402 // preserved and correspond to the bcp/locals pointers. So we do a runtime call
aoqi@0 2403 // by hand.
aoqi@0 2404 //
aoqi@0 2405 save_native_result(masm, ret_type, stack_slots);
aoqi@0 2406 __ mov(c_rarg0, r15_thread);
aoqi@0 2407 __ mov(r12, rsp); // remember sp
aoqi@0 2408 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
aoqi@0 2409 __ andptr(rsp, -16); // align stack as required by ABI
aoqi@0 2410 if (!is_critical_native) {
aoqi@0 2411 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
aoqi@0 2412 } else {
aoqi@0 2413 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans_and_transition)));
aoqi@0 2414 }
aoqi@0 2415 __ mov(rsp, r12); // restore sp
aoqi@0 2416 __ reinit_heapbase();
aoqi@0 2417 // Restore any method result value
aoqi@0 2418 restore_native_result(masm, ret_type, stack_slots);
aoqi@0 2419
aoqi@0 2420 if (is_critical_native) {
aoqi@0 2421 // The call above performed the transition to thread_in_Java so
aoqi@0 2422 // skip the transition logic below.
aoqi@0 2423 __ jmpb(after_transition);
aoqi@0 2424 }
aoqi@0 2425
aoqi@0 2426 __ bind(Continue);
aoqi@0 2427 }
aoqi@0 2428
aoqi@0 2429 // change thread state
aoqi@0 2430 __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_Java);
aoqi@0 2431 __ bind(after_transition);
aoqi@0 2432
aoqi@0 2433 Label reguard;
aoqi@0 2434 Label reguard_done;
aoqi@0 2435 __ cmpl(Address(r15_thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);
aoqi@0 2436 __ jcc(Assembler::equal, reguard);
aoqi@0 2437 __ bind(reguard_done);
aoqi@0 2438
aoqi@0 2439 // native result if any is live
aoqi@0 2440
aoqi@0 2441 // Unlock
aoqi@0 2442 Label unlock_done;
aoqi@0 2443 Label slow_path_unlock;
aoqi@0 2444 if (method->is_synchronized()) {
aoqi@0 2445
aoqi@0 2446 // Get locked oop from the handle we passed to jni
aoqi@0 2447 __ movptr(obj_reg, Address(oop_handle_reg, 0));
aoqi@0 2448
aoqi@0 2449 Label done;
aoqi@0 2450
aoqi@0 2451 if (UseBiasedLocking) {
aoqi@0 2452 __ biased_locking_exit(obj_reg, old_hdr, done);
aoqi@0 2453 }
aoqi@0 2454
aoqi@0 2455 // Simple recursive lock?
aoqi@0 2456
aoqi@0 2457 __ cmpptr(Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size), (int32_t)NULL_WORD);
aoqi@0 2458 __ jcc(Assembler::equal, done);
aoqi@0 2459
aoqi@0 2460 // Must save rax if if it is live now because cmpxchg must use it
aoqi@0 2461 if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
aoqi@0 2462 save_native_result(masm, ret_type, stack_slots);
aoqi@0 2463 }
aoqi@0 2464
aoqi@0 2465
aoqi@0 2466 // get address of the stack lock
aoqi@0 2467 __ lea(rax, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
aoqi@0 2468 // get old displaced header
aoqi@0 2469 __ movptr(old_hdr, Address(rax, 0));
aoqi@0 2470
aoqi@0 2471 // Atomic swap old header if oop still contains the stack lock
aoqi@0 2472 if (os::is_MP()) {
aoqi@0 2473 __ lock();
aoqi@0 2474 }
aoqi@0 2475 __ cmpxchgptr(old_hdr, Address(obj_reg, 0));
aoqi@0 2476 __ jcc(Assembler::notEqual, slow_path_unlock);
aoqi@0 2477
aoqi@0 2478 // slow path re-enters here
aoqi@0 2479 __ bind(unlock_done);
aoqi@0 2480 if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
aoqi@0 2481 restore_native_result(masm, ret_type, stack_slots);
aoqi@0 2482 }
aoqi@0 2483
aoqi@0 2484 __ bind(done);
aoqi@0 2485
aoqi@0 2486 }
aoqi@0 2487 {
aoqi@0 2488 SkipIfEqual skip(masm, &DTraceMethodProbes, false);
aoqi@0 2489 save_native_result(masm, ret_type, stack_slots);
aoqi@0 2490 __ mov_metadata(c_rarg1, method());
aoqi@0 2491 __ call_VM_leaf(
aoqi@0 2492 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
aoqi@0 2493 r15_thread, c_rarg1);
aoqi@0 2494 restore_native_result(masm, ret_type, stack_slots);
aoqi@0 2495 }
aoqi@0 2496
aoqi@0 2497 __ reset_last_Java_frame(false, true);
aoqi@0 2498
aoqi@0 2499 // Unpack oop result
aoqi@0 2500 if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
aoqi@0 2501 Label L;
aoqi@0 2502 __ testptr(rax, rax);
aoqi@0 2503 __ jcc(Assembler::zero, L);
aoqi@0 2504 __ movptr(rax, Address(rax, 0));
aoqi@0 2505 __ bind(L);
aoqi@0 2506 __ verify_oop(rax);
aoqi@0 2507 }
aoqi@0 2508
aoqi@0 2509 if (!is_critical_native) {
aoqi@0 2510 // reset handle block
aoqi@0 2511 __ movptr(rcx, Address(r15_thread, JavaThread::active_handles_offset()));
aoqi@0 2512 __ movl(Address(rcx, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);
aoqi@0 2513 }
aoqi@0 2514
aoqi@0 2515 // pop our frame
aoqi@0 2516
aoqi@0 2517 __ leave();
aoqi@0 2518
aoqi@0 2519 if (!is_critical_native) {
aoqi@0 2520 // Any exception pending?
aoqi@0 2521 __ cmpptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), (int32_t)NULL_WORD);
aoqi@0 2522 __ jcc(Assembler::notEqual, exception_pending);
aoqi@0 2523 }
aoqi@0 2524
aoqi@0 2525 // Return
aoqi@0 2526
aoqi@0 2527 __ ret(0);
aoqi@0 2528
aoqi@0 2529 // Unexpected paths are out of line and go here
aoqi@0 2530
aoqi@0 2531 if (!is_critical_native) {
aoqi@0 2532 // forward the exception
aoqi@0 2533 __ bind(exception_pending);
aoqi@0 2534
aoqi@0 2535 // and forward the exception
aoqi@0 2536 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@0 2537 }
aoqi@0 2538
aoqi@0 2539 // Slow path locking & unlocking
aoqi@0 2540 if (method->is_synchronized()) {
aoqi@0 2541
aoqi@0 2542 // BEGIN Slow path lock
aoqi@0 2543 __ bind(slow_path_lock);
aoqi@0 2544
aoqi@0 2545 // has last_Java_frame setup. No exceptions so do vanilla call not call_VM
aoqi@0 2546 // args are (oop obj, BasicLock* lock, JavaThread* thread)
aoqi@0 2547
aoqi@0 2548 // protect the args we've loaded
aoqi@0 2549 save_args(masm, total_c_args, c_arg, out_regs);
aoqi@0 2550
aoqi@0 2551 __ mov(c_rarg0, obj_reg);
aoqi@0 2552 __ mov(c_rarg1, lock_reg);
aoqi@0 2553 __ mov(c_rarg2, r15_thread);
aoqi@0 2554
aoqi@0 2555 // Not a leaf but we have last_Java_frame setup as we want
aoqi@0 2556 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_locking_C), 3);
aoqi@0 2557 restore_args(masm, total_c_args, c_arg, out_regs);
aoqi@0 2558
aoqi@0 2559 #ifdef ASSERT
aoqi@0 2560 { Label L;
aoqi@0 2561 __ cmpptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), (int32_t)NULL_WORD);
aoqi@0 2562 __ jcc(Assembler::equal, L);
aoqi@0 2563 __ stop("no pending exception allowed on exit from monitorenter");
aoqi@0 2564 __ bind(L);
aoqi@0 2565 }
aoqi@0 2566 #endif
aoqi@0 2567 __ jmp(lock_done);
aoqi@0 2568
aoqi@0 2569 // END Slow path lock
aoqi@0 2570
aoqi@0 2571 // BEGIN Slow path unlock
aoqi@0 2572 __ bind(slow_path_unlock);
aoqi@0 2573
aoqi@0 2574 // If we haven't already saved the native result we must save it now as xmm registers
aoqi@0 2575 // are still exposed.
aoqi@0 2576
aoqi@0 2577 if (ret_type == T_FLOAT || ret_type == T_DOUBLE ) {
aoqi@0 2578 save_native_result(masm, ret_type, stack_slots);
aoqi@0 2579 }
aoqi@0 2580
aoqi@0 2581 __ lea(c_rarg1, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
aoqi@0 2582
aoqi@0 2583 __ mov(c_rarg0, obj_reg);
aoqi@0 2584 __ mov(r12, rsp); // remember sp
aoqi@0 2585 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
aoqi@0 2586 __ andptr(rsp, -16); // align stack as required by ABI
aoqi@0 2587
aoqi@0 2588 // Save pending exception around call to VM (which contains an EXCEPTION_MARK)
aoqi@0 2589 // NOTE that obj_reg == rbx currently
aoqi@0 2590 __ movptr(rbx, Address(r15_thread, in_bytes(Thread::pending_exception_offset())));
aoqi@0 2591 __ movptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), (int32_t)NULL_WORD);
aoqi@0 2592
aoqi@0 2593 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C)));
aoqi@0 2594 __ mov(rsp, r12); // restore sp
aoqi@0 2595 __ reinit_heapbase();
aoqi@0 2596 #ifdef ASSERT
aoqi@0 2597 {
aoqi@0 2598 Label L;
aoqi@0 2599 __ cmpptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), (int)NULL_WORD);
aoqi@0 2600 __ jcc(Assembler::equal, L);
aoqi@0 2601 __ stop("no pending exception allowed on exit complete_monitor_unlocking_C");
aoqi@0 2602 __ bind(L);
aoqi@0 2603 }
aoqi@0 2604 #endif /* ASSERT */
aoqi@0 2605
aoqi@0 2606 __ movptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), rbx);
aoqi@0 2607
aoqi@0 2608 if (ret_type == T_FLOAT || ret_type == T_DOUBLE ) {
aoqi@0 2609 restore_native_result(masm, ret_type, stack_slots);
aoqi@0 2610 }
aoqi@0 2611 __ jmp(unlock_done);
aoqi@0 2612
aoqi@0 2613 // END Slow path unlock
aoqi@0 2614
aoqi@0 2615 } // synchronized
aoqi@0 2616
aoqi@0 2617 // SLOW PATH Reguard the stack if needed
aoqi@0 2618
aoqi@0 2619 __ bind(reguard);
aoqi@0 2620 save_native_result(masm, ret_type, stack_slots);
aoqi@0 2621 __ mov(r12, rsp); // remember sp
aoqi@0 2622 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
aoqi@0 2623 __ andptr(rsp, -16); // align stack as required by ABI
aoqi@0 2624 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
aoqi@0 2625 __ mov(rsp, r12); // restore sp
aoqi@0 2626 __ reinit_heapbase();
aoqi@0 2627 restore_native_result(masm, ret_type, stack_slots);
aoqi@0 2628 // and continue
aoqi@0 2629 __ jmp(reguard_done);
aoqi@0 2630
aoqi@0 2631
aoqi@0 2632
aoqi@0 2633 __ flush();
aoqi@0 2634
aoqi@0 2635 nmethod *nm = nmethod::new_native_nmethod(method,
aoqi@0 2636 compile_id,
aoqi@0 2637 masm->code(),
aoqi@0 2638 vep_offset,
aoqi@0 2639 frame_complete,
aoqi@0 2640 stack_slots / VMRegImpl::slots_per_word,
aoqi@0 2641 (is_static ? in_ByteSize(klass_offset) : in_ByteSize(receiver_offset)),
aoqi@0 2642 in_ByteSize(lock_slot_offset*VMRegImpl::stack_slot_size),
aoqi@0 2643 oop_maps);
aoqi@0 2644
aoqi@0 2645 if (is_critical_native) {
aoqi@0 2646 nm->set_lazy_critical_native(true);
aoqi@0 2647 }
aoqi@0 2648
aoqi@0 2649 return nm;
aoqi@0 2650
aoqi@0 2651 }
aoqi@0 2652
aoqi@0 2653 #ifdef HAVE_DTRACE_H
aoqi@0 2654 // ---------------------------------------------------------------------------
aoqi@0 2655 // Generate a dtrace nmethod for a given signature. The method takes arguments
aoqi@0 2656 // in the Java compiled code convention, marshals them to the native
aoqi@0 2657 // abi and then leaves nops at the position you would expect to call a native
aoqi@0 2658 // function. When the probe is enabled the nops are replaced with a trap
aoqi@0 2659 // instruction that dtrace inserts and the trace will cause a notification
aoqi@0 2660 // to dtrace.
aoqi@0 2661 //
aoqi@0 2662 // The probes are only able to take primitive types and java/lang/String as
aoqi@0 2663 // arguments. No other java types are allowed. Strings are converted to utf8
aoqi@0 2664 // strings so that from dtrace point of view java strings are converted to C
aoqi@0 2665 // strings. There is an arbitrary fixed limit on the total space that a method
aoqi@0 2666 // can use for converting the strings. (256 chars per string in the signature).
aoqi@0 2667 // So any java string larger then this is truncated.
aoqi@0 2668
aoqi@0 2669 static int fp_offset[ConcreteRegisterImpl::number_of_registers] = { 0 };
aoqi@0 2670 static bool offsets_initialized = false;
aoqi@0 2671
aoqi@0 2672
aoqi@0 2673 nmethod *SharedRuntime::generate_dtrace_nmethod(MacroAssembler *masm,
aoqi@0 2674 methodHandle method) {
aoqi@0 2675
aoqi@0 2676
aoqi@0 2677 // generate_dtrace_nmethod is guarded by a mutex so we are sure to
aoqi@0 2678 // be single threaded in this method.
aoqi@0 2679 assert(AdapterHandlerLibrary_lock->owned_by_self(), "must be");
aoqi@0 2680
aoqi@0 2681 if (!offsets_initialized) {
aoqi@0 2682 fp_offset[c_rarg0->as_VMReg()->value()] = -1 * wordSize;
aoqi@0 2683 fp_offset[c_rarg1->as_VMReg()->value()] = -2 * wordSize;
aoqi@0 2684 fp_offset[c_rarg2->as_VMReg()->value()] = -3 * wordSize;
aoqi@0 2685 fp_offset[c_rarg3->as_VMReg()->value()] = -4 * wordSize;
aoqi@0 2686 fp_offset[c_rarg4->as_VMReg()->value()] = -5 * wordSize;
aoqi@0 2687 fp_offset[c_rarg5->as_VMReg()->value()] = -6 * wordSize;
aoqi@0 2688
aoqi@0 2689 fp_offset[c_farg0->as_VMReg()->value()] = -7 * wordSize;
aoqi@0 2690 fp_offset[c_farg1->as_VMReg()->value()] = -8 * wordSize;
aoqi@0 2691 fp_offset[c_farg2->as_VMReg()->value()] = -9 * wordSize;
aoqi@0 2692 fp_offset[c_farg3->as_VMReg()->value()] = -10 * wordSize;
aoqi@0 2693 fp_offset[c_farg4->as_VMReg()->value()] = -11 * wordSize;
aoqi@0 2694 fp_offset[c_farg5->as_VMReg()->value()] = -12 * wordSize;
aoqi@0 2695 fp_offset[c_farg6->as_VMReg()->value()] = -13 * wordSize;
aoqi@0 2696 fp_offset[c_farg7->as_VMReg()->value()] = -14 * wordSize;
aoqi@0 2697
aoqi@0 2698 offsets_initialized = true;
aoqi@0 2699 }
aoqi@0 2700 // Fill in the signature array, for the calling-convention call.
aoqi@0 2701 int total_args_passed = method->size_of_parameters();
aoqi@0 2702
aoqi@0 2703 BasicType* in_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
aoqi@0 2704 VMRegPair *in_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
aoqi@0 2705
aoqi@0 2706 // The signature we are going to use for the trap that dtrace will see
aoqi@0 2707 // java/lang/String is converted. We drop "this" and any other object
aoqi@0 2708 // is converted to NULL. (A one-slot java/lang/Long object reference
aoqi@0 2709 // is converted to a two-slot long, which is why we double the allocation).
aoqi@0 2710 BasicType* out_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed * 2);
aoqi@0 2711 VMRegPair* out_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed * 2);
aoqi@0 2712
aoqi@0 2713 int i=0;
aoqi@0 2714 int total_strings = 0;
aoqi@0 2715 int first_arg_to_pass = 0;
aoqi@0 2716 int total_c_args = 0;
aoqi@0 2717
aoqi@0 2718 // Skip the receiver as dtrace doesn't want to see it
aoqi@0 2719 if( !method->is_static() ) {
aoqi@0 2720 in_sig_bt[i++] = T_OBJECT;
aoqi@0 2721 first_arg_to_pass = 1;
aoqi@0 2722 }
aoqi@0 2723
aoqi@0 2724 // We need to convert the java args to where a native (non-jni) function
aoqi@0 2725 // would expect them. To figure out where they go we convert the java
aoqi@0 2726 // signature to a C signature.
aoqi@0 2727
aoqi@0 2728 SignatureStream ss(method->signature());
aoqi@0 2729 for ( ; !ss.at_return_type(); ss.next()) {
aoqi@0 2730 BasicType bt = ss.type();
aoqi@0 2731 in_sig_bt[i++] = bt; // Collect remaining bits of signature
aoqi@0 2732 out_sig_bt[total_c_args++] = bt;
aoqi@0 2733 if( bt == T_OBJECT) {
aoqi@0 2734 Symbol* s = ss.as_symbol_or_null(); // symbol is created
aoqi@0 2735 if (s == vmSymbols::java_lang_String()) {
aoqi@0 2736 total_strings++;
aoqi@0 2737 out_sig_bt[total_c_args-1] = T_ADDRESS;
aoqi@0 2738 } else if (s == vmSymbols::java_lang_Boolean() ||
aoqi@0 2739 s == vmSymbols::java_lang_Character() ||
aoqi@0 2740 s == vmSymbols::java_lang_Byte() ||
aoqi@0 2741 s == vmSymbols::java_lang_Short() ||
aoqi@0 2742 s == vmSymbols::java_lang_Integer() ||
aoqi@0 2743 s == vmSymbols::java_lang_Float()) {
aoqi@0 2744 out_sig_bt[total_c_args-1] = T_INT;
aoqi@0 2745 } else if (s == vmSymbols::java_lang_Long() ||
aoqi@0 2746 s == vmSymbols::java_lang_Double()) {
aoqi@0 2747 out_sig_bt[total_c_args-1] = T_LONG;
aoqi@0 2748 out_sig_bt[total_c_args++] = T_VOID;
aoqi@0 2749 }
aoqi@0 2750 } else if ( bt == T_LONG || bt == T_DOUBLE ) {
aoqi@0 2751 in_sig_bt[i++] = T_VOID; // Longs & doubles take 2 Java slots
aoqi@0 2752 // We convert double to long
aoqi@0 2753 out_sig_bt[total_c_args-1] = T_LONG;
aoqi@0 2754 out_sig_bt[total_c_args++] = T_VOID;
aoqi@0 2755 } else if ( bt == T_FLOAT) {
aoqi@0 2756 // We convert float to int
aoqi@0 2757 out_sig_bt[total_c_args-1] = T_INT;
aoqi@0 2758 }
aoqi@0 2759 }
aoqi@0 2760
aoqi@0 2761 assert(i==total_args_passed, "validly parsed signature");
aoqi@0 2762
aoqi@0 2763 // Now get the compiled-Java layout as input arguments
aoqi@0 2764 int comp_args_on_stack;
aoqi@0 2765 comp_args_on_stack = SharedRuntime::java_calling_convention(
aoqi@0 2766 in_sig_bt, in_regs, total_args_passed, false);
aoqi@0 2767
aoqi@0 2768 // Now figure out where the args must be stored and how much stack space
aoqi@0 2769 // they require (neglecting out_preserve_stack_slots but space for storing
aoqi@0 2770 // the 1st six register arguments). It's weird see int_stk_helper.
aoqi@0 2771
aoqi@0 2772 int out_arg_slots;
aoqi@0 2773 out_arg_slots = c_calling_convention(out_sig_bt, out_regs, NULL, total_c_args);
aoqi@0 2774
aoqi@0 2775 // Calculate the total number of stack slots we will need.
aoqi@0 2776
aoqi@0 2777 // First count the abi requirement plus all of the outgoing args
aoqi@0 2778 int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
aoqi@0 2779
aoqi@0 2780 // Now space for the string(s) we must convert
aoqi@0 2781 int* string_locs = NEW_RESOURCE_ARRAY(int, total_strings + 1);
aoqi@0 2782 for (i = 0; i < total_strings ; i++) {
aoqi@0 2783 string_locs[i] = stack_slots;
aoqi@0 2784 stack_slots += max_dtrace_string_size / VMRegImpl::stack_slot_size;
aoqi@0 2785 }
aoqi@0 2786
aoqi@0 2787 // Plus the temps we might need to juggle register args
aoqi@0 2788 // regs take two slots each
aoqi@0 2789 stack_slots += (Argument::n_int_register_parameters_c +
aoqi@0 2790 Argument::n_float_register_parameters_c) * 2;
aoqi@0 2791
aoqi@0 2792
aoqi@0 2793 // + 4 for return address (which we own) and saved rbp,
aoqi@0 2794
aoqi@0 2795 stack_slots += 4;
aoqi@0 2796
aoqi@0 2797 // Ok The space we have allocated will look like:
aoqi@0 2798 //
aoqi@0 2799 //
aoqi@0 2800 // FP-> | |
aoqi@0 2801 // |---------------------|
aoqi@0 2802 // | string[n] |
aoqi@0 2803 // |---------------------| <- string_locs[n]
aoqi@0 2804 // | string[n-1] |
aoqi@0 2805 // |---------------------| <- string_locs[n-1]
aoqi@0 2806 // | ... |
aoqi@0 2807 // | ... |
aoqi@0 2808 // |---------------------| <- string_locs[1]
aoqi@0 2809 // | string[0] |
aoqi@0 2810 // |---------------------| <- string_locs[0]
aoqi@0 2811 // | outbound memory |
aoqi@0 2812 // | based arguments |
aoqi@0 2813 // | |
aoqi@0 2814 // |---------------------|
aoqi@0 2815 // | |
aoqi@0 2816 // SP-> | out_preserved_slots |
aoqi@0 2817 //
aoqi@0 2818 //
aoqi@0 2819
aoqi@0 2820 // Now compute actual number of stack words we need rounding to make
aoqi@0 2821 // stack properly aligned.
aoqi@0 2822 stack_slots = round_to(stack_slots, 4 * VMRegImpl::slots_per_word);
aoqi@0 2823
aoqi@0 2824 int stack_size = stack_slots * VMRegImpl::stack_slot_size;
aoqi@0 2825
aoqi@0 2826 intptr_t start = (intptr_t)__ pc();
aoqi@0 2827
aoqi@0 2828 // First thing make an ic check to see if we should even be here
aoqi@0 2829
aoqi@0 2830 // We are free to use all registers as temps without saving them and
aoqi@0 2831 // restoring them except rbp. rbp, is the only callee save register
aoqi@0 2832 // as far as the interpreter and the compiler(s) are concerned.
aoqi@0 2833
aoqi@0 2834 const Register ic_reg = rax;
aoqi@0 2835 const Register receiver = rcx;
aoqi@0 2836 Label hit;
aoqi@0 2837 Label exception_pending;
aoqi@0 2838
aoqi@0 2839
aoqi@0 2840 __ verify_oop(receiver);
aoqi@0 2841 __ cmpl(ic_reg, Address(receiver, oopDesc::klass_offset_in_bytes()));
aoqi@0 2842 __ jcc(Assembler::equal, hit);
aoqi@0 2843
aoqi@0 2844 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
aoqi@0 2845
aoqi@0 2846 // verified entry must be aligned for code patching.
aoqi@0 2847 // and the first 5 bytes must be in the same cache line
aoqi@0 2848 // if we align at 8 then we will be sure 5 bytes are in the same line
aoqi@0 2849 __ align(8);
aoqi@0 2850
aoqi@0 2851 __ bind(hit);
aoqi@0 2852
aoqi@0 2853 int vep_offset = ((intptr_t)__ pc()) - start;
aoqi@0 2854
aoqi@0 2855
aoqi@0 2856 // The instruction at the verified entry point must be 5 bytes or longer
aoqi@0 2857 // because it can be patched on the fly by make_non_entrant. The stack bang
aoqi@0 2858 // instruction fits that requirement.
aoqi@0 2859
aoqi@0 2860 // Generate stack overflow check
aoqi@0 2861
aoqi@0 2862 if (UseStackBanging) {
aoqi@0 2863 if (stack_size <= StackShadowPages*os::vm_page_size()) {
aoqi@0 2864 __ bang_stack_with_offset(StackShadowPages*os::vm_page_size());
aoqi@0 2865 } else {
aoqi@0 2866 __ movl(rax, stack_size);
aoqi@0 2867 __ bang_stack_size(rax, rbx);
aoqi@0 2868 }
aoqi@0 2869 } else {
aoqi@0 2870 // need a 5 byte instruction to allow MT safe patching to non-entrant
aoqi@0 2871 __ fat_nop();
aoqi@0 2872 }
aoqi@0 2873
aoqi@0 2874 assert(((uintptr_t)__ pc() - start - vep_offset) >= 5,
aoqi@0 2875 "valid size for make_non_entrant");
aoqi@0 2876
aoqi@0 2877 // Generate a new frame for the wrapper.
aoqi@0 2878 __ enter();
aoqi@0 2879
aoqi@0 2880 // -4 because return address is already present and so is saved rbp,
aoqi@0 2881 if (stack_size - 2*wordSize != 0) {
aoqi@0 2882 __ subq(rsp, stack_size - 2*wordSize);
aoqi@0 2883 }
aoqi@0 2884
aoqi@0 2885 // Frame is now completed as far a size and linkage.
aoqi@0 2886
aoqi@0 2887 int frame_complete = ((intptr_t)__ pc()) - start;
aoqi@0 2888
aoqi@0 2889 int c_arg, j_arg;
aoqi@0 2890
aoqi@0 2891 // State of input register args
aoqi@0 2892
aoqi@0 2893 bool live[ConcreteRegisterImpl::number_of_registers];
aoqi@0 2894
aoqi@0 2895 live[j_rarg0->as_VMReg()->value()] = false;
aoqi@0 2896 live[j_rarg1->as_VMReg()->value()] = false;
aoqi@0 2897 live[j_rarg2->as_VMReg()->value()] = false;
aoqi@0 2898 live[j_rarg3->as_VMReg()->value()] = false;
aoqi@0 2899 live[j_rarg4->as_VMReg()->value()] = false;
aoqi@0 2900 live[j_rarg5->as_VMReg()->value()] = false;
aoqi@0 2901
aoqi@0 2902 live[j_farg0->as_VMReg()->value()] = false;
aoqi@0 2903 live[j_farg1->as_VMReg()->value()] = false;
aoqi@0 2904 live[j_farg2->as_VMReg()->value()] = false;
aoqi@0 2905 live[j_farg3->as_VMReg()->value()] = false;
aoqi@0 2906 live[j_farg4->as_VMReg()->value()] = false;
aoqi@0 2907 live[j_farg5->as_VMReg()->value()] = false;
aoqi@0 2908 live[j_farg6->as_VMReg()->value()] = false;
aoqi@0 2909 live[j_farg7->as_VMReg()->value()] = false;
aoqi@0 2910
aoqi@0 2911
aoqi@0 2912 bool rax_is_zero = false;
aoqi@0 2913
aoqi@0 2914 // All args (except strings) destined for the stack are moved first
aoqi@0 2915 for (j_arg = first_arg_to_pass, c_arg = 0 ;
aoqi@0 2916 j_arg < total_args_passed ; j_arg++, c_arg++ ) {
aoqi@0 2917 VMRegPair src = in_regs[j_arg];
aoqi@0 2918 VMRegPair dst = out_regs[c_arg];
aoqi@0 2919
aoqi@0 2920 // Get the real reg value or a dummy (rsp)
aoqi@0 2921
aoqi@0 2922 int src_reg = src.first()->is_reg() ?
aoqi@0 2923 src.first()->value() :
aoqi@0 2924 rsp->as_VMReg()->value();
aoqi@0 2925
aoqi@0 2926 bool useless = in_sig_bt[j_arg] == T_ARRAY ||
aoqi@0 2927 (in_sig_bt[j_arg] == T_OBJECT &&
aoqi@0 2928 out_sig_bt[c_arg] != T_INT &&
aoqi@0 2929 out_sig_bt[c_arg] != T_ADDRESS &&
aoqi@0 2930 out_sig_bt[c_arg] != T_LONG);
aoqi@0 2931
aoqi@0 2932 live[src_reg] = !useless;
aoqi@0 2933
aoqi@0 2934 if (dst.first()->is_stack()) {
aoqi@0 2935
aoqi@0 2936 // Even though a string arg in a register is still live after this loop
aoqi@0 2937 // after the string conversion loop (next) it will be dead so we take
aoqi@0 2938 // advantage of that now for simpler code to manage live.
aoqi@0 2939
aoqi@0 2940 live[src_reg] = false;
aoqi@0 2941 switch (in_sig_bt[j_arg]) {
aoqi@0 2942
aoqi@0 2943 case T_ARRAY:
aoqi@0 2944 case T_OBJECT:
aoqi@0 2945 {
aoqi@0 2946 Address stack_dst(rsp, reg2offset_out(dst.first()));
aoqi@0 2947
aoqi@0 2948 if (out_sig_bt[c_arg] == T_INT || out_sig_bt[c_arg] == T_LONG) {
aoqi@0 2949 // need to unbox a one-word value
aoqi@0 2950 Register in_reg = rax;
aoqi@0 2951 if ( src.first()->is_reg() ) {
aoqi@0 2952 in_reg = src.first()->as_Register();
aoqi@0 2953 } else {
aoqi@0 2954 __ movq(rax, Address(rbp, reg2offset_in(src.first())));
aoqi@0 2955 rax_is_zero = false;
aoqi@0 2956 }
aoqi@0 2957 Label skipUnbox;
aoqi@0 2958 __ movptr(Address(rsp, reg2offset_out(dst.first())),
aoqi@0 2959 (int32_t)NULL_WORD);
aoqi@0 2960 __ testq(in_reg, in_reg);
aoqi@0 2961 __ jcc(Assembler::zero, skipUnbox);
aoqi@0 2962
aoqi@0 2963 BasicType bt = out_sig_bt[c_arg];
aoqi@0 2964 int box_offset = java_lang_boxing_object::value_offset_in_bytes(bt);
aoqi@0 2965 Address src1(in_reg, box_offset);
aoqi@0 2966 if ( bt == T_LONG ) {
aoqi@0 2967 __ movq(in_reg, src1);
aoqi@0 2968 __ movq(stack_dst, in_reg);
aoqi@0 2969 assert(out_sig_bt[c_arg+1] == T_VOID, "must be");
aoqi@0 2970 ++c_arg; // skip over T_VOID to keep the loop indices in sync
aoqi@0 2971 } else {
aoqi@0 2972 __ movl(in_reg, src1);
aoqi@0 2973 __ movl(stack_dst, in_reg);
aoqi@0 2974 }
aoqi@0 2975
aoqi@0 2976 __ bind(skipUnbox);
aoqi@0 2977 } else if (out_sig_bt[c_arg] != T_ADDRESS) {
aoqi@0 2978 // Convert the arg to NULL
aoqi@0 2979 if (!rax_is_zero) {
aoqi@0 2980 __ xorq(rax, rax);
aoqi@0 2981 rax_is_zero = true;
aoqi@0 2982 }
aoqi@0 2983 __ movq(stack_dst, rax);
aoqi@0 2984 }
aoqi@0 2985 }
aoqi@0 2986 break;
aoqi@0 2987
aoqi@0 2988 case T_VOID:
aoqi@0 2989 break;
aoqi@0 2990
aoqi@0 2991 case T_FLOAT:
aoqi@0 2992 // This does the right thing since we know it is destined for the
aoqi@0 2993 // stack
aoqi@0 2994 float_move(masm, src, dst);
aoqi@0 2995 break;
aoqi@0 2996
aoqi@0 2997 case T_DOUBLE:
aoqi@0 2998 // This does the right thing since we know it is destined for the
aoqi@0 2999 // stack
aoqi@0 3000 double_move(masm, src, dst);
aoqi@0 3001 break;
aoqi@0 3002
aoqi@0 3003 case T_LONG :
aoqi@0 3004 long_move(masm, src, dst);
aoqi@0 3005 break;
aoqi@0 3006
aoqi@0 3007 case T_ADDRESS: assert(false, "found T_ADDRESS in java args");
aoqi@0 3008
aoqi@0 3009 default:
aoqi@0 3010 move32_64(masm, src, dst);
aoqi@0 3011 }
aoqi@0 3012 }
aoqi@0 3013
aoqi@0 3014 }
aoqi@0 3015
aoqi@0 3016 // If we have any strings we must store any register based arg to the stack
aoqi@0 3017 // This includes any still live xmm registers too.
aoqi@0 3018
aoqi@0 3019 int sid = 0;
aoqi@0 3020
aoqi@0 3021 if (total_strings > 0 ) {
aoqi@0 3022 for (j_arg = first_arg_to_pass, c_arg = 0 ;
aoqi@0 3023 j_arg < total_args_passed ; j_arg++, c_arg++ ) {
aoqi@0 3024 VMRegPair src = in_regs[j_arg];
aoqi@0 3025 VMRegPair dst = out_regs[c_arg];
aoqi@0 3026
aoqi@0 3027 if (src.first()->is_reg()) {
aoqi@0 3028 Address src_tmp(rbp, fp_offset[src.first()->value()]);
aoqi@0 3029
aoqi@0 3030 // string oops were left untouched by the previous loop even if the
aoqi@0 3031 // eventual (converted) arg is destined for the stack so park them
aoqi@0 3032 // away now (except for first)
aoqi@0 3033
aoqi@0 3034 if (out_sig_bt[c_arg] == T_ADDRESS) {
aoqi@0 3035 Address utf8_addr = Address(
aoqi@0 3036 rsp, string_locs[sid++] * VMRegImpl::stack_slot_size);
aoqi@0 3037 if (sid != 1) {
aoqi@0 3038 // The first string arg won't be killed until after the utf8
aoqi@0 3039 // conversion
aoqi@0 3040 __ movq(utf8_addr, src.first()->as_Register());
aoqi@0 3041 }
aoqi@0 3042 } else if (dst.first()->is_reg()) {
aoqi@0 3043 if (in_sig_bt[j_arg] == T_FLOAT || in_sig_bt[j_arg] == T_DOUBLE) {
aoqi@0 3044
aoqi@0 3045 // Convert the xmm register to an int and store it in the reserved
aoqi@0 3046 // location for the eventual c register arg
aoqi@0 3047 XMMRegister f = src.first()->as_XMMRegister();
aoqi@0 3048 if (in_sig_bt[j_arg] == T_FLOAT) {
aoqi@0 3049 __ movflt(src_tmp, f);
aoqi@0 3050 } else {
aoqi@0 3051 __ movdbl(src_tmp, f);
aoqi@0 3052 }
aoqi@0 3053 } else {
aoqi@0 3054 // If the arg is an oop type we don't support don't bother to store
aoqi@0 3055 // it remember string was handled above.
aoqi@0 3056 bool useless = in_sig_bt[j_arg] == T_ARRAY ||
aoqi@0 3057 (in_sig_bt[j_arg] == T_OBJECT &&
aoqi@0 3058 out_sig_bt[c_arg] != T_INT &&
aoqi@0 3059 out_sig_bt[c_arg] != T_LONG);
aoqi@0 3060
aoqi@0 3061 if (!useless) {
aoqi@0 3062 __ movq(src_tmp, src.first()->as_Register());
aoqi@0 3063 }
aoqi@0 3064 }
aoqi@0 3065 }
aoqi@0 3066 }
aoqi@0 3067 if (in_sig_bt[j_arg] == T_OBJECT && out_sig_bt[c_arg] == T_LONG) {
aoqi@0 3068 assert(out_sig_bt[c_arg+1] == T_VOID, "must be");
aoqi@0 3069 ++c_arg; // skip over T_VOID to keep the loop indices in sync
aoqi@0 3070 }
aoqi@0 3071 }
aoqi@0 3072
aoqi@0 3073 // Now that the volatile registers are safe, convert all the strings
aoqi@0 3074 sid = 0;
aoqi@0 3075
aoqi@0 3076 for (j_arg = first_arg_to_pass, c_arg = 0 ;
aoqi@0 3077 j_arg < total_args_passed ; j_arg++, c_arg++ ) {
aoqi@0 3078 if (out_sig_bt[c_arg] == T_ADDRESS) {
aoqi@0 3079 // It's a string
aoqi@0 3080 Address utf8_addr = Address(
aoqi@0 3081 rsp, string_locs[sid++] * VMRegImpl::stack_slot_size);
aoqi@0 3082 // The first string we find might still be in the original java arg
aoqi@0 3083 // register
aoqi@0 3084
aoqi@0 3085 VMReg src = in_regs[j_arg].first();
aoqi@0 3086
aoqi@0 3087 // We will need to eventually save the final argument to the trap
aoqi@0 3088 // in the von-volatile location dedicated to src. This is the offset
aoqi@0 3089 // from fp we will use.
aoqi@0 3090 int src_off = src->is_reg() ?
aoqi@0 3091 fp_offset[src->value()] : reg2offset_in(src);
aoqi@0 3092
aoqi@0 3093 // This is where the argument will eventually reside
aoqi@0 3094 VMRegPair dst = out_regs[c_arg];
aoqi@0 3095
aoqi@0 3096 if (src->is_reg()) {
aoqi@0 3097 if (sid == 1) {
aoqi@0 3098 __ movq(c_rarg0, src->as_Register());
aoqi@0 3099 } else {
aoqi@0 3100 __ movq(c_rarg0, utf8_addr);
aoqi@0 3101 }
aoqi@0 3102 } else {
aoqi@0 3103 // arg is still in the original location
aoqi@0 3104 __ movq(c_rarg0, Address(rbp, reg2offset_in(src)));
aoqi@0 3105 }
aoqi@0 3106 Label done, convert;
aoqi@0 3107
aoqi@0 3108 // see if the oop is NULL
aoqi@0 3109 __ testq(c_rarg0, c_rarg0);
aoqi@0 3110 __ jcc(Assembler::notEqual, convert);
aoqi@0 3111
aoqi@0 3112 if (dst.first()->is_reg()) {
aoqi@0 3113 // Save the ptr to utf string in the origina src loc or the tmp
aoqi@0 3114 // dedicated to it
aoqi@0 3115 __ movq(Address(rbp, src_off), c_rarg0);
aoqi@0 3116 } else {
aoqi@0 3117 __ movq(Address(rsp, reg2offset_out(dst.first())), c_rarg0);
aoqi@0 3118 }
aoqi@0 3119 __ jmp(done);
aoqi@0 3120
aoqi@0 3121 __ bind(convert);
aoqi@0 3122
aoqi@0 3123 __ lea(c_rarg1, utf8_addr);
aoqi@0 3124 if (dst.first()->is_reg()) {
aoqi@0 3125 __ movq(Address(rbp, src_off), c_rarg1);
aoqi@0 3126 } else {
aoqi@0 3127 __ movq(Address(rsp, reg2offset_out(dst.first())), c_rarg1);
aoqi@0 3128 }
aoqi@0 3129 // And do the conversion
aoqi@0 3130 __ call(RuntimeAddress(
aoqi@0 3131 CAST_FROM_FN_PTR(address, SharedRuntime::get_utf)));
aoqi@0 3132
aoqi@0 3133 __ bind(done);
aoqi@0 3134 }
aoqi@0 3135 if (in_sig_bt[j_arg] == T_OBJECT && out_sig_bt[c_arg] == T_LONG) {
aoqi@0 3136 assert(out_sig_bt[c_arg+1] == T_VOID, "must be");
aoqi@0 3137 ++c_arg; // skip over T_VOID to keep the loop indices in sync
aoqi@0 3138 }
aoqi@0 3139 }
aoqi@0 3140 // The get_utf call killed all the c_arg registers
aoqi@0 3141 live[c_rarg0->as_VMReg()->value()] = false;
aoqi@0 3142 live[c_rarg1->as_VMReg()->value()] = false;
aoqi@0 3143 live[c_rarg2->as_VMReg()->value()] = false;
aoqi@0 3144 live[c_rarg3->as_VMReg()->value()] = false;
aoqi@0 3145 live[c_rarg4->as_VMReg()->value()] = false;
aoqi@0 3146 live[c_rarg5->as_VMReg()->value()] = false;
aoqi@0 3147
aoqi@0 3148 live[c_farg0->as_VMReg()->value()] = false;
aoqi@0 3149 live[c_farg1->as_VMReg()->value()] = false;
aoqi@0 3150 live[c_farg2->as_VMReg()->value()] = false;
aoqi@0 3151 live[c_farg3->as_VMReg()->value()] = false;
aoqi@0 3152 live[c_farg4->as_VMReg()->value()] = false;
aoqi@0 3153 live[c_farg5->as_VMReg()->value()] = false;
aoqi@0 3154 live[c_farg6->as_VMReg()->value()] = false;
aoqi@0 3155 live[c_farg7->as_VMReg()->value()] = false;
aoqi@0 3156 }
aoqi@0 3157
aoqi@0 3158 // Now we can finally move the register args to their desired locations
aoqi@0 3159
aoqi@0 3160 rax_is_zero = false;
aoqi@0 3161
aoqi@0 3162 for (j_arg = first_arg_to_pass, c_arg = 0 ;
aoqi@0 3163 j_arg < total_args_passed ; j_arg++, c_arg++ ) {
aoqi@0 3164
aoqi@0 3165 VMRegPair src = in_regs[j_arg];
aoqi@0 3166 VMRegPair dst = out_regs[c_arg];
aoqi@0 3167
aoqi@0 3168 // Only need to look for args destined for the interger registers (since we
aoqi@0 3169 // convert float/double args to look like int/long outbound)
aoqi@0 3170 if (dst.first()->is_reg()) {
aoqi@0 3171 Register r = dst.first()->as_Register();
aoqi@0 3172
aoqi@0 3173 // Check if the java arg is unsupported and thereofre useless
aoqi@0 3174 bool useless = in_sig_bt[j_arg] == T_ARRAY ||
aoqi@0 3175 (in_sig_bt[j_arg] == T_OBJECT &&
aoqi@0 3176 out_sig_bt[c_arg] != T_INT &&
aoqi@0 3177 out_sig_bt[c_arg] != T_ADDRESS &&
aoqi@0 3178 out_sig_bt[c_arg] != T_LONG);
aoqi@0 3179
aoqi@0 3180
aoqi@0 3181 // If we're going to kill an existing arg save it first
aoqi@0 3182 if (live[dst.first()->value()]) {
aoqi@0 3183 // you can't kill yourself
aoqi@0 3184 if (src.first() != dst.first()) {
aoqi@0 3185 __ movq(Address(rbp, fp_offset[dst.first()->value()]), r);
aoqi@0 3186 }
aoqi@0 3187 }
aoqi@0 3188 if (src.first()->is_reg()) {
aoqi@0 3189 if (live[src.first()->value()] ) {
aoqi@0 3190 if (in_sig_bt[j_arg] == T_FLOAT) {
aoqi@0 3191 __ movdl(r, src.first()->as_XMMRegister());
aoqi@0 3192 } else if (in_sig_bt[j_arg] == T_DOUBLE) {
aoqi@0 3193 __ movdq(r, src.first()->as_XMMRegister());
aoqi@0 3194 } else if (r != src.first()->as_Register()) {
aoqi@0 3195 if (!useless) {
aoqi@0 3196 __ movq(r, src.first()->as_Register());
aoqi@0 3197 }
aoqi@0 3198 }
aoqi@0 3199 } else {
aoqi@0 3200 // If the arg is an oop type we don't support don't bother to store
aoqi@0 3201 // it
aoqi@0 3202 if (!useless) {
aoqi@0 3203 if (in_sig_bt[j_arg] == T_DOUBLE ||
aoqi@0 3204 in_sig_bt[j_arg] == T_LONG ||
aoqi@0 3205 in_sig_bt[j_arg] == T_OBJECT ) {
aoqi@0 3206 __ movq(r, Address(rbp, fp_offset[src.first()->value()]));
aoqi@0 3207 } else {
aoqi@0 3208 __ movl(r, Address(rbp, fp_offset[src.first()->value()]));
aoqi@0 3209 }
aoqi@0 3210 }
aoqi@0 3211 }
aoqi@0 3212 live[src.first()->value()] = false;
aoqi@0 3213 } else if (!useless) {
aoqi@0 3214 // full sized move even for int should be ok
aoqi@0 3215 __ movq(r, Address(rbp, reg2offset_in(src.first())));
aoqi@0 3216 }
aoqi@0 3217
aoqi@0 3218 // At this point r has the original java arg in the final location
aoqi@0 3219 // (assuming it wasn't useless). If the java arg was an oop
aoqi@0 3220 // we have a bit more to do
aoqi@0 3221
aoqi@0 3222 if (in_sig_bt[j_arg] == T_ARRAY || in_sig_bt[j_arg] == T_OBJECT ) {
aoqi@0 3223 if (out_sig_bt[c_arg] == T_INT || out_sig_bt[c_arg] == T_LONG) {
aoqi@0 3224 // need to unbox a one-word value
aoqi@0 3225 Label skip;
aoqi@0 3226 __ testq(r, r);
aoqi@0 3227 __ jcc(Assembler::equal, skip);
aoqi@0 3228 BasicType bt = out_sig_bt[c_arg];
aoqi@0 3229 int box_offset = java_lang_boxing_object::value_offset_in_bytes(bt);
aoqi@0 3230 Address src1(r, box_offset);
aoqi@0 3231 if ( bt == T_LONG ) {
aoqi@0 3232 __ movq(r, src1);
aoqi@0 3233 } else {
aoqi@0 3234 __ movl(r, src1);
aoqi@0 3235 }
aoqi@0 3236 __ bind(skip);
aoqi@0 3237
aoqi@0 3238 } else if (out_sig_bt[c_arg] != T_ADDRESS) {
aoqi@0 3239 // Convert the arg to NULL
aoqi@0 3240 __ xorq(r, r);
aoqi@0 3241 }
aoqi@0 3242 }
aoqi@0 3243
aoqi@0 3244 // dst can longer be holding an input value
aoqi@0 3245 live[dst.first()->value()] = false;
aoqi@0 3246 }
aoqi@0 3247 if (in_sig_bt[j_arg] == T_OBJECT && out_sig_bt[c_arg] == T_LONG) {
aoqi@0 3248 assert(out_sig_bt[c_arg+1] == T_VOID, "must be");
aoqi@0 3249 ++c_arg; // skip over T_VOID to keep the loop indices in sync
aoqi@0 3250 }
aoqi@0 3251 }
aoqi@0 3252
aoqi@0 3253
aoqi@0 3254 // Ok now we are done. Need to place the nop that dtrace wants in order to
aoqi@0 3255 // patch in the trap
aoqi@0 3256 int patch_offset = ((intptr_t)__ pc()) - start;
aoqi@0 3257
aoqi@0 3258 __ nop();
aoqi@0 3259
aoqi@0 3260
aoqi@0 3261 // Return
aoqi@0 3262
aoqi@0 3263 __ leave();
aoqi@0 3264 __ ret(0);
aoqi@0 3265
aoqi@0 3266 __ flush();
aoqi@0 3267
aoqi@0 3268 nmethod *nm = nmethod::new_dtrace_nmethod(
aoqi@0 3269 method, masm->code(), vep_offset, patch_offset, frame_complete,
aoqi@0 3270 stack_slots / VMRegImpl::slots_per_word);
aoqi@0 3271 return nm;
aoqi@0 3272
aoqi@0 3273 }
aoqi@0 3274
aoqi@0 3275 #endif // HAVE_DTRACE_H
aoqi@0 3276
aoqi@0 3277 // this function returns the adjust size (in number of words) to a c2i adapter
aoqi@0 3278 // activation for use during deoptimization
aoqi@0 3279 int Deoptimization::last_frame_adjust(int callee_parameters, int callee_locals ) {
aoqi@0 3280 return (callee_locals - callee_parameters) * Interpreter::stackElementWords;
aoqi@0 3281 }
aoqi@0 3282
aoqi@0 3283
aoqi@0 3284 uint SharedRuntime::out_preserve_stack_slots() {
aoqi@0 3285 return 0;
aoqi@0 3286 }
aoqi@0 3287
aoqi@0 3288 //------------------------------generate_deopt_blob----------------------------
aoqi@0 3289 void SharedRuntime::generate_deopt_blob() {
aoqi@0 3290 // Allocate space for the code
aoqi@0 3291 ResourceMark rm;
aoqi@0 3292 // Setup code generation tools
aoqi@0 3293 CodeBuffer buffer("deopt_blob", 2048, 1024);
aoqi@0 3294 MacroAssembler* masm = new MacroAssembler(&buffer);
aoqi@0 3295 int frame_size_in_words;
aoqi@0 3296 OopMap* map = NULL;
aoqi@0 3297 OopMapSet *oop_maps = new OopMapSet();
aoqi@0 3298
aoqi@0 3299 // -------------
aoqi@0 3300 // This code enters when returning to a de-optimized nmethod. A return
aoqi@0 3301 // address has been pushed on the the stack, and return values are in
aoqi@0 3302 // registers.
aoqi@0 3303 // If we are doing a normal deopt then we were called from the patched
aoqi@0 3304 // nmethod from the point we returned to the nmethod. So the return
aoqi@0 3305 // address on the stack is wrong by NativeCall::instruction_size
aoqi@0 3306 // We will adjust the value so it looks like we have the original return
aoqi@0 3307 // address on the stack (like when we eagerly deoptimized).
aoqi@0 3308 // In the case of an exception pending when deoptimizing, we enter
aoqi@0 3309 // with a return address on the stack that points after the call we patched
aoqi@0 3310 // into the exception handler. We have the following register state from,
aoqi@0 3311 // e.g., the forward exception stub (see stubGenerator_x86_64.cpp).
aoqi@0 3312 // rax: exception oop
aoqi@0 3313 // rbx: exception handler
aoqi@0 3314 // rdx: throwing pc
aoqi@0 3315 // So in this case we simply jam rdx into the useless return address and
aoqi@0 3316 // the stack looks just like we want.
aoqi@0 3317 //
aoqi@0 3318 // At this point we need to de-opt. We save the argument return
aoqi@0 3319 // registers. We call the first C routine, fetch_unroll_info(). This
aoqi@0 3320 // routine captures the return values and returns a structure which
aoqi@0 3321 // describes the current frame size and the sizes of all replacement frames.
aoqi@0 3322 // The current frame is compiled code and may contain many inlined
aoqi@0 3323 // functions, each with their own JVM state. We pop the current frame, then
aoqi@0 3324 // push all the new frames. Then we call the C routine unpack_frames() to
aoqi@0 3325 // populate these frames. Finally unpack_frames() returns us the new target
aoqi@0 3326 // address. Notice that callee-save registers are BLOWN here; they have
aoqi@0 3327 // already been captured in the vframeArray at the time the return PC was
aoqi@0 3328 // patched.
aoqi@0 3329 address start = __ pc();
aoqi@0 3330 Label cont;
aoqi@0 3331
aoqi@0 3332 // Prolog for non exception case!
aoqi@0 3333
aoqi@0 3334 // Save everything in sight.
aoqi@0 3335 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
aoqi@0 3336
aoqi@0 3337 // Normal deoptimization. Save exec mode for unpack_frames.
aoqi@0 3338 __ movl(r14, Deoptimization::Unpack_deopt); // callee-saved
aoqi@0 3339 __ jmp(cont);
aoqi@0 3340
aoqi@0 3341 int reexecute_offset = __ pc() - start;
aoqi@0 3342
aoqi@0 3343 // Reexecute case
aoqi@0 3344 // return address is the pc describes what bci to do re-execute at
aoqi@0 3345
aoqi@0 3346 // No need to update map as each call to save_live_registers will produce identical oopmap
aoqi@0 3347 (void) RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
aoqi@0 3348
aoqi@0 3349 __ movl(r14, Deoptimization::Unpack_reexecute); // callee-saved
aoqi@0 3350 __ jmp(cont);
aoqi@0 3351
aoqi@0 3352 int exception_offset = __ pc() - start;
aoqi@0 3353
aoqi@0 3354 // Prolog for exception case
aoqi@0 3355
aoqi@0 3356 // all registers are dead at this entry point, except for rax, and
aoqi@0 3357 // rdx which contain the exception oop and exception pc
aoqi@0 3358 // respectively. Set them in TLS and fall thru to the
aoqi@0 3359 // unpack_with_exception_in_tls entry point.
aoqi@0 3360
aoqi@0 3361 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);
aoqi@0 3362 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), rax);
aoqi@0 3363
aoqi@0 3364 int exception_in_tls_offset = __ pc() - start;
aoqi@0 3365
aoqi@0 3366 // new implementation because exception oop is now passed in JavaThread
aoqi@0 3367
aoqi@0 3368 // Prolog for exception case
aoqi@0 3369 // All registers must be preserved because they might be used by LinearScan
aoqi@0 3370 // Exceptiop oop and throwing PC are passed in JavaThread
aoqi@0 3371 // tos: stack at point of call to method that threw the exception (i.e. only
aoqi@0 3372 // args are on the stack, no return address)
aoqi@0 3373
aoqi@0 3374 // make room on stack for the return address
aoqi@0 3375 // It will be patched later with the throwing pc. The correct value is not
aoqi@0 3376 // available now because loading it from memory would destroy registers.
aoqi@0 3377 __ push(0);
aoqi@0 3378
aoqi@0 3379 // Save everything in sight.
aoqi@0 3380 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
aoqi@0 3381
aoqi@0 3382 // Now it is safe to overwrite any register
aoqi@0 3383
aoqi@0 3384 // Deopt during an exception. Save exec mode for unpack_frames.
aoqi@0 3385 __ movl(r14, Deoptimization::Unpack_exception); // callee-saved
aoqi@0 3386
aoqi@0 3387 // load throwing pc from JavaThread and patch it as the return address
aoqi@0 3388 // of the current frame. Then clear the field in JavaThread
aoqi@0 3389
aoqi@0 3390 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
aoqi@0 3391 __ movptr(Address(rbp, wordSize), rdx);
aoqi@0 3392 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);
aoqi@0 3393
aoqi@0 3394 #ifdef ASSERT
aoqi@0 3395 // verify that there is really an exception oop in JavaThread
aoqi@0 3396 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
aoqi@0 3397 __ verify_oop(rax);
aoqi@0 3398
aoqi@0 3399 // verify that there is no pending exception
aoqi@0 3400 Label no_pending_exception;
aoqi@0 3401 __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset()));
aoqi@0 3402 __ testptr(rax, rax);
aoqi@0 3403 __ jcc(Assembler::zero, no_pending_exception);
aoqi@0 3404 __ stop("must not have pending exception here");
aoqi@0 3405 __ bind(no_pending_exception);
aoqi@0 3406 #endif
aoqi@0 3407
aoqi@0 3408 __ bind(cont);
aoqi@0 3409
aoqi@0 3410 // Call C code. Need thread and this frame, but NOT official VM entry
aoqi@0 3411 // crud. We cannot block on this call, no GC can happen.
aoqi@0 3412 //
aoqi@0 3413 // UnrollBlock* fetch_unroll_info(JavaThread* thread)
aoqi@0 3414
aoqi@0 3415 // fetch_unroll_info needs to call last_java_frame().
aoqi@0 3416
aoqi@0 3417 __ set_last_Java_frame(noreg, noreg, NULL);
aoqi@0 3418 #ifdef ASSERT
aoqi@0 3419 { Label L;
aoqi@0 3420 __ cmpptr(Address(r15_thread,
aoqi@0 3421 JavaThread::last_Java_fp_offset()),
aoqi@0 3422 (int32_t)0);
aoqi@0 3423 __ jcc(Assembler::equal, L);
aoqi@0 3424 __ stop("SharedRuntime::generate_deopt_blob: last_Java_fp not cleared");
aoqi@0 3425 __ bind(L);
aoqi@0 3426 }
aoqi@0 3427 #endif // ASSERT
aoqi@0 3428 __ mov(c_rarg0, r15_thread);
aoqi@0 3429 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::fetch_unroll_info)));
aoqi@0 3430
aoqi@0 3431 // Need to have an oopmap that tells fetch_unroll_info where to
aoqi@0 3432 // find any register it might need.
aoqi@0 3433 oop_maps->add_gc_map(__ pc() - start, map);
aoqi@0 3434
aoqi@0 3435 __ reset_last_Java_frame(false, false);
aoqi@0 3436
aoqi@0 3437 // Load UnrollBlock* into rdi
aoqi@0 3438 __ mov(rdi, rax);
aoqi@0 3439
aoqi@0 3440 Label noException;
aoqi@0 3441 __ cmpl(r14, Deoptimization::Unpack_exception); // Was exception pending?
aoqi@0 3442 __ jcc(Assembler::notEqual, noException);
aoqi@0 3443 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
aoqi@0 3444 // QQQ this is useless it was NULL above
aoqi@0 3445 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
aoqi@0 3446 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), (int32_t)NULL_WORD);
aoqi@0 3447 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);
aoqi@0 3448
aoqi@0 3449 __ verify_oop(rax);
aoqi@0 3450
aoqi@0 3451 // Overwrite the result registers with the exception results.
aoqi@0 3452 __ movptr(Address(rsp, RegisterSaver::rax_offset_in_bytes()), rax);
aoqi@0 3453 // I think this is useless
aoqi@0 3454 __ movptr(Address(rsp, RegisterSaver::rdx_offset_in_bytes()), rdx);
aoqi@0 3455
aoqi@0 3456 __ bind(noException);
aoqi@0 3457
aoqi@0 3458 // Only register save data is on the stack.
aoqi@0 3459 // Now restore the result registers. Everything else is either dead
aoqi@0 3460 // or captured in the vframeArray.
aoqi@0 3461 RegisterSaver::restore_result_registers(masm);
aoqi@0 3462
aoqi@0 3463 // All of the register save area has been popped of the stack. Only the
aoqi@0 3464 // return address remains.
aoqi@0 3465
aoqi@0 3466 // Pop all the frames we must move/replace.
aoqi@0 3467 //
aoqi@0 3468 // Frame picture (youngest to oldest)
aoqi@0 3469 // 1: self-frame (no frame link)
aoqi@0 3470 // 2: deopting frame (no frame link)
aoqi@0 3471 // 3: caller of deopting frame (could be compiled/interpreted).
aoqi@0 3472 //
aoqi@0 3473 // Note: by leaving the return address of self-frame on the stack
aoqi@0 3474 // and using the size of frame 2 to adjust the stack
aoqi@0 3475 // when we are done the return to frame 3 will still be on the stack.
aoqi@0 3476
aoqi@0 3477 // Pop deoptimized frame
aoqi@0 3478 __ movl(rcx, Address(rdi, Deoptimization::UnrollBlock::size_of_deoptimized_frame_offset_in_bytes()));
aoqi@0 3479 __ addptr(rsp, rcx);
aoqi@0 3480
aoqi@0 3481 // rsp should be pointing at the return address to the caller (3)
aoqi@0 3482
aoqi@0 3483 // Pick up the initial fp we should save
aoqi@0 3484 // restore rbp before stack bang because if stack overflow is thrown it needs to be pushed (and preserved)
aoqi@0 3485 __ movptr(rbp, Address(rdi, Deoptimization::UnrollBlock::initial_info_offset_in_bytes()));
aoqi@0 3486
aoqi@0 3487 #ifdef ASSERT
aoqi@0 3488 // Compilers generate code that bang the stack by as much as the
aoqi@0 3489 // interpreter would need. So this stack banging should never
aoqi@0 3490 // trigger a fault. Verify that it does not on non product builds.
aoqi@0 3491 if (UseStackBanging) {
aoqi@0 3492 __ movl(rbx, Address(rdi, Deoptimization::UnrollBlock::total_frame_sizes_offset_in_bytes()));
aoqi@0 3493 __ bang_stack_size(rbx, rcx);
aoqi@0 3494 }
aoqi@0 3495 #endif
aoqi@0 3496
aoqi@0 3497 // Load address of array of frame pcs into rcx
aoqi@0 3498 __ movptr(rcx, Address(rdi, Deoptimization::UnrollBlock::frame_pcs_offset_in_bytes()));
aoqi@0 3499
aoqi@0 3500 // Trash the old pc
aoqi@0 3501 __ addptr(rsp, wordSize);
aoqi@0 3502
aoqi@0 3503 // Load address of array of frame sizes into rsi
aoqi@0 3504 __ movptr(rsi, Address(rdi, Deoptimization::UnrollBlock::frame_sizes_offset_in_bytes()));
aoqi@0 3505
aoqi@0 3506 // Load counter into rdx
aoqi@0 3507 __ movl(rdx, Address(rdi, Deoptimization::UnrollBlock::number_of_frames_offset_in_bytes()));
aoqi@0 3508
aoqi@0 3509 // Now adjust the caller's stack to make up for the extra locals
aoqi@0 3510 // but record the original sp so that we can save it in the skeletal interpreter
aoqi@0 3511 // frame and the stack walking of interpreter_sender will get the unextended sp
aoqi@0 3512 // value and not the "real" sp value.
aoqi@0 3513
aoqi@0 3514 const Register sender_sp = r8;
aoqi@0 3515
aoqi@0 3516 __ mov(sender_sp, rsp);
aoqi@0 3517 __ movl(rbx, Address(rdi,
aoqi@0 3518 Deoptimization::UnrollBlock::
aoqi@0 3519 caller_adjustment_offset_in_bytes()));
aoqi@0 3520 __ subptr(rsp, rbx);
aoqi@0 3521
aoqi@0 3522 // Push interpreter frames in a loop
aoqi@0 3523 Label loop;
aoqi@0 3524 __ bind(loop);
aoqi@0 3525 __ movptr(rbx, Address(rsi, 0)); // Load frame size
aoqi@0 3526 #ifdef CC_INTERP
aoqi@0 3527 __ subptr(rbx, 4*wordSize); // we'll push pc and ebp by hand and
aoqi@0 3528 #ifdef ASSERT
aoqi@0 3529 __ push(0xDEADDEAD); // Make a recognizable pattern
aoqi@0 3530 __ push(0xDEADDEAD);
aoqi@0 3531 #else /* ASSERT */
aoqi@0 3532 __ subptr(rsp, 2*wordSize); // skip the "static long no_param"
aoqi@0 3533 #endif /* ASSERT */
aoqi@0 3534 #else
aoqi@0 3535 __ subptr(rbx, 2*wordSize); // We'll push pc and ebp by hand
aoqi@0 3536 #endif // CC_INTERP
aoqi@0 3537 __ pushptr(Address(rcx, 0)); // Save return address
aoqi@0 3538 __ enter(); // Save old & set new ebp
aoqi@0 3539 __ subptr(rsp, rbx); // Prolog
aoqi@0 3540 #ifdef CC_INTERP
aoqi@0 3541 __ movptr(Address(rbp,
aoqi@0 3542 -(sizeof(BytecodeInterpreter)) + in_bytes(byte_offset_of(BytecodeInterpreter, _sender_sp))),
aoqi@0 3543 sender_sp); // Make it walkable
aoqi@0 3544 #else /* CC_INTERP */
aoqi@0 3545 // This value is corrected by layout_activation_impl
aoqi@0 3546 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD );
aoqi@0 3547 __ movptr(Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize), sender_sp); // Make it walkable
aoqi@0 3548 #endif /* CC_INTERP */
aoqi@0 3549 __ mov(sender_sp, rsp); // Pass sender_sp to next frame
aoqi@0 3550 __ addptr(rsi, wordSize); // Bump array pointer (sizes)
aoqi@0 3551 __ addptr(rcx, wordSize); // Bump array pointer (pcs)
aoqi@0 3552 __ decrementl(rdx); // Decrement counter
aoqi@0 3553 __ jcc(Assembler::notZero, loop);
aoqi@0 3554 __ pushptr(Address(rcx, 0)); // Save final return address
aoqi@0 3555
aoqi@0 3556 // Re-push self-frame
aoqi@0 3557 __ enter(); // Save old & set new ebp
aoqi@0 3558
aoqi@0 3559 // Allocate a full sized register save area.
aoqi@0 3560 // Return address and rbp are in place, so we allocate two less words.
aoqi@0 3561 __ subptr(rsp, (frame_size_in_words - 2) * wordSize);
aoqi@0 3562
aoqi@0 3563 // Restore frame locals after moving the frame
aoqi@0 3564 __ movdbl(Address(rsp, RegisterSaver::xmm0_offset_in_bytes()), xmm0);
aoqi@0 3565 __ movptr(Address(rsp, RegisterSaver::rax_offset_in_bytes()), rax);
aoqi@0 3566
aoqi@0 3567 // Call C code. Need thread but NOT official VM entry
aoqi@0 3568 // crud. We cannot block on this call, no GC can happen. Call should
aoqi@0 3569 // restore return values to their stack-slots with the new SP.
aoqi@0 3570 //
aoqi@0 3571 // void Deoptimization::unpack_frames(JavaThread* thread, int exec_mode)
aoqi@0 3572
aoqi@0 3573 // Use rbp because the frames look interpreted now
aoqi@0 3574 // Save "the_pc" since it cannot easily be retrieved using the last_java_SP after we aligned SP.
aoqi@0 3575 // Don't need the precise return PC here, just precise enough to point into this code blob.
aoqi@0 3576 address the_pc = __ pc();
aoqi@0 3577 __ set_last_Java_frame(noreg, rbp, the_pc);
aoqi@0 3578
aoqi@0 3579 __ andptr(rsp, -(StackAlignmentInBytes)); // Fix stack alignment as required by ABI
aoqi@0 3580 __ mov(c_rarg0, r15_thread);
aoqi@0 3581 __ movl(c_rarg1, r14); // second arg: exec_mode
aoqi@0 3582 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames)));
aoqi@0 3583 // Revert SP alignment after call since we're going to do some SP relative addressing below
aoqi@0 3584 __ movptr(rsp, Address(r15_thread, JavaThread::last_Java_sp_offset()));
aoqi@0 3585
aoqi@0 3586 // Set an oopmap for the call site
aoqi@0 3587 // Use the same PC we used for the last java frame
aoqi@0 3588 oop_maps->add_gc_map(the_pc - start,
aoqi@0 3589 new OopMap( frame_size_in_words, 0 ));
aoqi@0 3590
aoqi@0 3591 // Clear fp AND pc
aoqi@0 3592 __ reset_last_Java_frame(true, true);
aoqi@0 3593
aoqi@0 3594 // Collect return values
aoqi@0 3595 __ movdbl(xmm0, Address(rsp, RegisterSaver::xmm0_offset_in_bytes()));
aoqi@0 3596 __ movptr(rax, Address(rsp, RegisterSaver::rax_offset_in_bytes()));
aoqi@0 3597 // I think this is useless (throwing pc?)
aoqi@0 3598 __ movptr(rdx, Address(rsp, RegisterSaver::rdx_offset_in_bytes()));
aoqi@0 3599
aoqi@0 3600 // Pop self-frame.
aoqi@0 3601 __ leave(); // Epilog
aoqi@0 3602
aoqi@0 3603 // Jump to interpreter
aoqi@0 3604 __ ret(0);
aoqi@0 3605
aoqi@0 3606 // Make sure all code is generated
aoqi@0 3607 masm->flush();
aoqi@0 3608
aoqi@0 3609 _deopt_blob = DeoptimizationBlob::create(&buffer, oop_maps, 0, exception_offset, reexecute_offset, frame_size_in_words);
aoqi@0 3610 _deopt_blob->set_unpack_with_exception_in_tls_offset(exception_in_tls_offset);
aoqi@0 3611 }
aoqi@0 3612
aoqi@0 3613 #ifdef COMPILER2
aoqi@0 3614 //------------------------------generate_uncommon_trap_blob--------------------
aoqi@0 3615 void SharedRuntime::generate_uncommon_trap_blob() {
aoqi@0 3616 // Allocate space for the code
aoqi@0 3617 ResourceMark rm;
aoqi@0 3618 // Setup code generation tools
aoqi@0 3619 CodeBuffer buffer("uncommon_trap_blob", 2048, 1024);
aoqi@0 3620 MacroAssembler* masm = new MacroAssembler(&buffer);
aoqi@0 3621
aoqi@0 3622 assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
aoqi@0 3623
aoqi@0 3624 address start = __ pc();
aoqi@0 3625
aoqi@0 3626 if (UseRTMLocking) {
aoqi@0 3627 // Abort RTM transaction before possible nmethod deoptimization.
aoqi@0 3628 __ xabort(0);
aoqi@0 3629 }
aoqi@0 3630
aoqi@0 3631 // Push self-frame. We get here with a return address on the
aoqi@0 3632 // stack, so rsp is 8-byte aligned until we allocate our frame.
aoqi@0 3633 __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog!
aoqi@0 3634
aoqi@0 3635 // No callee saved registers. rbp is assumed implicitly saved
aoqi@0 3636 __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
aoqi@0 3637
aoqi@0 3638 // compiler left unloaded_class_index in j_rarg0 move to where the
aoqi@0 3639 // runtime expects it.
aoqi@0 3640 __ movl(c_rarg1, j_rarg0);
aoqi@0 3641
aoqi@0 3642 __ set_last_Java_frame(noreg, noreg, NULL);
aoqi@0 3643
aoqi@0 3644 // Call C code. Need thread but NOT official VM entry
aoqi@0 3645 // crud. We cannot block on this call, no GC can happen. Call should
aoqi@0 3646 // capture callee-saved registers as well as return values.
aoqi@0 3647 // Thread is in rdi already.
aoqi@0 3648 //
aoqi@0 3649 // UnrollBlock* uncommon_trap(JavaThread* thread, jint unloaded_class_index);
aoqi@0 3650
aoqi@0 3651 __ mov(c_rarg0, r15_thread);
aoqi@0 3652 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::uncommon_trap)));
aoqi@0 3653
aoqi@0 3654 // Set an oopmap for the call site
aoqi@0 3655 OopMapSet* oop_maps = new OopMapSet();
aoqi@0 3656 OopMap* map = new OopMap(SimpleRuntimeFrame::framesize, 0);
aoqi@0 3657
aoqi@0 3658 // location of rbp is known implicitly by the frame sender code
aoqi@0 3659
aoqi@0 3660 oop_maps->add_gc_map(__ pc() - start, map);
aoqi@0 3661
aoqi@0 3662 __ reset_last_Java_frame(false, false);
aoqi@0 3663
aoqi@0 3664 // Load UnrollBlock* into rdi
aoqi@0 3665 __ mov(rdi, rax);
aoqi@0 3666
aoqi@0 3667 // Pop all the frames we must move/replace.
aoqi@0 3668 //
aoqi@0 3669 // Frame picture (youngest to oldest)
aoqi@0 3670 // 1: self-frame (no frame link)
aoqi@0 3671 // 2: deopting frame (no frame link)
aoqi@0 3672 // 3: caller of deopting frame (could be compiled/interpreted).
aoqi@0 3673
aoqi@0 3674 // Pop self-frame. We have no frame, and must rely only on rax and rsp.
aoqi@0 3675 __ addptr(rsp, (SimpleRuntimeFrame::framesize - 2) << LogBytesPerInt); // Epilog!
aoqi@0 3676
aoqi@0 3677 // Pop deoptimized frame (int)
aoqi@0 3678 __ movl(rcx, Address(rdi,
aoqi@0 3679 Deoptimization::UnrollBlock::
aoqi@0 3680 size_of_deoptimized_frame_offset_in_bytes()));
aoqi@0 3681 __ addptr(rsp, rcx);
aoqi@0 3682
aoqi@0 3683 // rsp should be pointing at the return address to the caller (3)
aoqi@0 3684
aoqi@0 3685 // Pick up the initial fp we should save
aoqi@0 3686 // restore rbp before stack bang because if stack overflow is thrown it needs to be pushed (and preserved)
aoqi@0 3687 __ movptr(rbp, Address(rdi, Deoptimization::UnrollBlock::initial_info_offset_in_bytes()));
aoqi@0 3688
aoqi@0 3689 #ifdef ASSERT
aoqi@0 3690 // Compilers generate code that bang the stack by as much as the
aoqi@0 3691 // interpreter would need. So this stack banging should never
aoqi@0 3692 // trigger a fault. Verify that it does not on non product builds.
aoqi@0 3693 if (UseStackBanging) {
aoqi@0 3694 __ movl(rbx, Address(rdi ,Deoptimization::UnrollBlock::total_frame_sizes_offset_in_bytes()));
aoqi@0 3695 __ bang_stack_size(rbx, rcx);
aoqi@0 3696 }
aoqi@0 3697 #endif
aoqi@0 3698
aoqi@0 3699 // Load address of array of frame pcs into rcx (address*)
aoqi@0 3700 __ movptr(rcx, Address(rdi, Deoptimization::UnrollBlock::frame_pcs_offset_in_bytes()));
aoqi@0 3701
aoqi@0 3702 // Trash the return pc
aoqi@0 3703 __ addptr(rsp, wordSize);
aoqi@0 3704
aoqi@0 3705 // Load address of array of frame sizes into rsi (intptr_t*)
aoqi@0 3706 __ movptr(rsi, Address(rdi, Deoptimization::UnrollBlock:: frame_sizes_offset_in_bytes()));
aoqi@0 3707
aoqi@0 3708 // Counter
aoqi@0 3709 __ movl(rdx, Address(rdi, Deoptimization::UnrollBlock:: number_of_frames_offset_in_bytes())); // (int)
aoqi@0 3710
aoqi@0 3711 // Now adjust the caller's stack to make up for the extra locals but
aoqi@0 3712 // record the original sp so that we can save it in the skeletal
aoqi@0 3713 // interpreter frame and the stack walking of interpreter_sender
aoqi@0 3714 // will get the unextended sp value and not the "real" sp value.
aoqi@0 3715
aoqi@0 3716 const Register sender_sp = r8;
aoqi@0 3717
aoqi@0 3718 __ mov(sender_sp, rsp);
aoqi@0 3719 __ movl(rbx, Address(rdi, Deoptimization::UnrollBlock:: caller_adjustment_offset_in_bytes())); // (int)
aoqi@0 3720 __ subptr(rsp, rbx);
aoqi@0 3721
aoqi@0 3722 // Push interpreter frames in a loop
aoqi@0 3723 Label loop;
aoqi@0 3724 __ bind(loop);
aoqi@0 3725 __ movptr(rbx, Address(rsi, 0)); // Load frame size
aoqi@0 3726 __ subptr(rbx, 2 * wordSize); // We'll push pc and rbp by hand
aoqi@0 3727 __ pushptr(Address(rcx, 0)); // Save return address
aoqi@0 3728 __ enter(); // Save old & set new rbp
aoqi@0 3729 __ subptr(rsp, rbx); // Prolog
aoqi@0 3730 #ifdef CC_INTERP
aoqi@0 3731 __ movptr(Address(rbp,
aoqi@0 3732 -(sizeof(BytecodeInterpreter)) + in_bytes(byte_offset_of(BytecodeInterpreter, _sender_sp))),
aoqi@0 3733 sender_sp); // Make it walkable
aoqi@0 3734 #else // CC_INTERP
aoqi@0 3735 __ movptr(Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize),
aoqi@0 3736 sender_sp); // Make it walkable
aoqi@0 3737 // This value is corrected by layout_activation_impl
aoqi@0 3738 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD );
aoqi@0 3739 #endif // CC_INTERP
aoqi@0 3740 __ mov(sender_sp, rsp); // Pass sender_sp to next frame
aoqi@0 3741 __ addptr(rsi, wordSize); // Bump array pointer (sizes)
aoqi@0 3742 __ addptr(rcx, wordSize); // Bump array pointer (pcs)
aoqi@0 3743 __ decrementl(rdx); // Decrement counter
aoqi@0 3744 __ jcc(Assembler::notZero, loop);
aoqi@0 3745 __ pushptr(Address(rcx, 0)); // Save final return address
aoqi@0 3746
aoqi@0 3747 // Re-push self-frame
aoqi@0 3748 __ enter(); // Save old & set new rbp
aoqi@0 3749 __ subptr(rsp, (SimpleRuntimeFrame::framesize - 4) << LogBytesPerInt);
aoqi@0 3750 // Prolog
aoqi@0 3751
aoqi@0 3752 // Use rbp because the frames look interpreted now
aoqi@0 3753 // Save "the_pc" since it cannot easily be retrieved using the last_java_SP after we aligned SP.
aoqi@0 3754 // Don't need the precise return PC here, just precise enough to point into this code blob.
aoqi@0 3755 address the_pc = __ pc();
aoqi@0 3756 __ set_last_Java_frame(noreg, rbp, the_pc);
aoqi@0 3757
aoqi@0 3758 // Call C code. Need thread but NOT official VM entry
aoqi@0 3759 // crud. We cannot block on this call, no GC can happen. Call should
aoqi@0 3760 // restore return values to their stack-slots with the new SP.
aoqi@0 3761 // Thread is in rdi already.
aoqi@0 3762 //
aoqi@0 3763 // BasicType unpack_frames(JavaThread* thread, int exec_mode);
aoqi@0 3764
aoqi@0 3765 __ andptr(rsp, -(StackAlignmentInBytes)); // Align SP as required by ABI
aoqi@0 3766 __ mov(c_rarg0, r15_thread);
aoqi@0 3767 __ movl(c_rarg1, Deoptimization::Unpack_uncommon_trap);
aoqi@0 3768 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames)));
aoqi@0 3769
aoqi@0 3770 // Set an oopmap for the call site
aoqi@0 3771 // Use the same PC we used for the last java frame
aoqi@0 3772 oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));
aoqi@0 3773
aoqi@0 3774 // Clear fp AND pc
aoqi@0 3775 __ reset_last_Java_frame(true, true);
aoqi@0 3776
aoqi@0 3777 // Pop self-frame.
aoqi@0 3778 __ leave(); // Epilog
aoqi@0 3779
aoqi@0 3780 // Jump to interpreter
aoqi@0 3781 __ ret(0);
aoqi@0 3782
aoqi@0 3783 // Make sure all code is generated
aoqi@0 3784 masm->flush();
aoqi@0 3785
aoqi@0 3786 _uncommon_trap_blob = UncommonTrapBlob::create(&buffer, oop_maps,
aoqi@0 3787 SimpleRuntimeFrame::framesize >> 1);
aoqi@0 3788 }
aoqi@0 3789 #endif // COMPILER2
aoqi@0 3790
aoqi@0 3791
aoqi@0 3792 //------------------------------generate_handler_blob------
aoqi@0 3793 //
aoqi@0 3794 // Generate a special Compile2Runtime blob that saves all registers,
aoqi@0 3795 // and setup oopmap.
aoqi@0 3796 //
aoqi@0 3797 SafepointBlob* SharedRuntime::generate_handler_blob(address call_ptr, int poll_type) {
aoqi@0 3798 assert(StubRoutines::forward_exception_entry() != NULL,
aoqi@0 3799 "must be generated before");
aoqi@0 3800
aoqi@0 3801 ResourceMark rm;
aoqi@0 3802 OopMapSet *oop_maps = new OopMapSet();
aoqi@0 3803 OopMap* map;
aoqi@0 3804
aoqi@0 3805 // Allocate space for the code. Setup code generation tools.
aoqi@0 3806 CodeBuffer buffer("handler_blob", 2048, 1024);
aoqi@0 3807 MacroAssembler* masm = new MacroAssembler(&buffer);
aoqi@0 3808
aoqi@0 3809 address start = __ pc();
aoqi@0 3810 address call_pc = NULL;
aoqi@0 3811 int frame_size_in_words;
aoqi@0 3812 bool cause_return = (poll_type == POLL_AT_RETURN);
aoqi@0 3813 bool save_vectors = (poll_type == POLL_AT_VECTOR_LOOP);
aoqi@0 3814
aoqi@0 3815 if (UseRTMLocking) {
aoqi@0 3816 // Abort RTM transaction before calling runtime
aoqi@0 3817 // because critical section will be large and will be
aoqi@0 3818 // aborted anyway. Also nmethod could be deoptimized.
aoqi@0 3819 __ xabort(0);
aoqi@0 3820 }
aoqi@0 3821
aoqi@0 3822 // Make room for return address (or push it again)
aoqi@0 3823 if (!cause_return) {
aoqi@0 3824 __ push(rbx);
aoqi@0 3825 }
aoqi@0 3826
aoqi@0 3827 // Save registers, fpu state, and flags
aoqi@0 3828 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words, save_vectors);
aoqi@0 3829
aoqi@0 3830 // The following is basically a call_VM. However, we need the precise
aoqi@0 3831 // address of the call in order to generate an oopmap. Hence, we do all the
aoqi@0 3832 // work outselves.
aoqi@0 3833
aoqi@0 3834 __ set_last_Java_frame(noreg, noreg, NULL);
aoqi@0 3835
aoqi@0 3836 // The return address must always be correct so that frame constructor never
aoqi@0 3837 // sees an invalid pc.
aoqi@0 3838
aoqi@0 3839 if (!cause_return) {
aoqi@0 3840 // overwrite the dummy value we pushed on entry
aoqi@0 3841 __ movptr(c_rarg0, Address(r15_thread, JavaThread::saved_exception_pc_offset()));
aoqi@0 3842 __ movptr(Address(rbp, wordSize), c_rarg0);
aoqi@0 3843 }
aoqi@0 3844
aoqi@0 3845 // Do the call
aoqi@0 3846 __ mov(c_rarg0, r15_thread);
aoqi@0 3847 __ call(RuntimeAddress(call_ptr));
aoqi@0 3848
aoqi@0 3849 // Set an oopmap for the call site. This oopmap will map all
aoqi@0 3850 // oop-registers and debug-info registers as callee-saved. This
aoqi@0 3851 // will allow deoptimization at this safepoint to find all possible
aoqi@0 3852 // debug-info recordings, as well as let GC find all oops.
aoqi@0 3853
aoqi@0 3854 oop_maps->add_gc_map( __ pc() - start, map);
aoqi@0 3855
aoqi@0 3856 Label noException;
aoqi@0 3857
aoqi@0 3858 __ reset_last_Java_frame(false, false);
aoqi@0 3859
aoqi@0 3860 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 3861 __ jcc(Assembler::equal, noException);
aoqi@0 3862
aoqi@0 3863 // Exception pending
aoqi@0 3864
aoqi@0 3865 RegisterSaver::restore_live_registers(masm, save_vectors);
aoqi@0 3866
aoqi@0 3867 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@0 3868
aoqi@0 3869 // No exception case
aoqi@0 3870 __ bind(noException);
aoqi@0 3871
aoqi@0 3872 // Normal exit, restore registers and exit.
aoqi@0 3873 RegisterSaver::restore_live_registers(masm, save_vectors);
aoqi@0 3874
aoqi@0 3875 __ ret(0);
aoqi@0 3876
aoqi@0 3877 // Make sure all code is generated
aoqi@0 3878 masm->flush();
aoqi@0 3879
aoqi@0 3880 // Fill-out other meta info
aoqi@0 3881 return SafepointBlob::create(&buffer, oop_maps, frame_size_in_words);
aoqi@0 3882 }
aoqi@0 3883
aoqi@0 3884 //
aoqi@0 3885 // generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss
aoqi@0 3886 //
aoqi@0 3887 // Generate a stub that calls into vm to find out the proper destination
aoqi@0 3888 // of a java call. All the argument registers are live at this point
aoqi@0 3889 // but since this is generic code we don't know what they are and the caller
aoqi@0 3890 // must do any gc of the args.
aoqi@0 3891 //
aoqi@0 3892 RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const char* name) {
aoqi@0 3893 assert (StubRoutines::forward_exception_entry() != NULL, "must be generated before");
aoqi@0 3894
aoqi@0 3895 // allocate space for the code
aoqi@0 3896 ResourceMark rm;
aoqi@0 3897
aoqi@0 3898 CodeBuffer buffer(name, 1000, 512);
aoqi@0 3899 MacroAssembler* masm = new MacroAssembler(&buffer);
aoqi@0 3900
aoqi@0 3901 int frame_size_in_words;
aoqi@0 3902
aoqi@0 3903 OopMapSet *oop_maps = new OopMapSet();
aoqi@0 3904 OopMap* map = NULL;
aoqi@0 3905
aoqi@0 3906 int start = __ offset();
aoqi@0 3907
aoqi@0 3908 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
aoqi@0 3909
aoqi@0 3910 int frame_complete = __ offset();
aoqi@0 3911
aoqi@0 3912 __ set_last_Java_frame(noreg, noreg, NULL);
aoqi@0 3913
aoqi@0 3914 __ mov(c_rarg0, r15_thread);
aoqi@0 3915
aoqi@0 3916 __ call(RuntimeAddress(destination));
aoqi@0 3917
aoqi@0 3918
aoqi@0 3919 // Set an oopmap for the call site.
aoqi@0 3920 // We need this not only for callee-saved registers, but also for volatile
aoqi@0 3921 // registers that the compiler might be keeping live across a safepoint.
aoqi@0 3922
aoqi@0 3923 oop_maps->add_gc_map( __ offset() - start, map);
aoqi@0 3924
aoqi@0 3925 // rax contains the address we are going to jump to assuming no exception got installed
aoqi@0 3926
aoqi@0 3927 // clear last_Java_sp
aoqi@0 3928 __ reset_last_Java_frame(false, false);
aoqi@0 3929 // check for pending exceptions
aoqi@0 3930 Label pending;
aoqi@0 3931 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 3932 __ jcc(Assembler::notEqual, pending);
aoqi@0 3933
aoqi@0 3934 // get the returned Method*
aoqi@0 3935 __ get_vm_result_2(rbx, r15_thread);
aoqi@0 3936 __ movptr(Address(rsp, RegisterSaver::rbx_offset_in_bytes()), rbx);
aoqi@0 3937
aoqi@0 3938 __ movptr(Address(rsp, RegisterSaver::rax_offset_in_bytes()), rax);
aoqi@0 3939
aoqi@0 3940 RegisterSaver::restore_live_registers(masm);
aoqi@0 3941
aoqi@0 3942 // We are back the the original state on entry and ready to go.
aoqi@0 3943
aoqi@0 3944 __ jmp(rax);
aoqi@0 3945
aoqi@0 3946 // Pending exception after the safepoint
aoqi@0 3947
aoqi@0 3948 __ bind(pending);
aoqi@0 3949
aoqi@0 3950 RegisterSaver::restore_live_registers(masm);
aoqi@0 3951
aoqi@0 3952 // exception pending => remove activation and forward to exception handler
aoqi@0 3953
aoqi@0 3954 __ movptr(Address(r15_thread, JavaThread::vm_result_offset()), (int)NULL_WORD);
aoqi@0 3955
aoqi@0 3956 __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset()));
aoqi@0 3957 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@0 3958
aoqi@0 3959 // -------------
aoqi@0 3960 // make sure all code is generated
aoqi@0 3961 masm->flush();
aoqi@0 3962
aoqi@0 3963 // return the blob
aoqi@0 3964 // frame_size_words or bytes??
aoqi@0 3965 return RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_in_words, oop_maps, true);
aoqi@0 3966 }
aoqi@0 3967
aoqi@0 3968
aoqi@0 3969 #ifdef COMPILER2
aoqi@0 3970 // This is here instead of runtime_x86_64.cpp because it uses SimpleRuntimeFrame
aoqi@0 3971 //
aoqi@0 3972 //------------------------------generate_exception_blob---------------------------
aoqi@0 3973 // creates exception blob at the end
aoqi@0 3974 // Using exception blob, this code is jumped from a compiled method.
aoqi@0 3975 // (see emit_exception_handler in x86_64.ad file)
aoqi@0 3976 //
aoqi@0 3977 // Given an exception pc at a call we call into the runtime for the
aoqi@0 3978 // handler in this method. This handler might merely restore state
aoqi@0 3979 // (i.e. callee save registers) unwind the frame and jump to the
aoqi@0 3980 // exception handler for the nmethod if there is no Java level handler
aoqi@0 3981 // for the nmethod.
aoqi@0 3982 //
aoqi@0 3983 // This code is entered with a jmp.
aoqi@0 3984 //
aoqi@0 3985 // Arguments:
aoqi@0 3986 // rax: exception oop
aoqi@0 3987 // rdx: exception pc
aoqi@0 3988 //
aoqi@0 3989 // Results:
aoqi@0 3990 // rax: exception oop
aoqi@0 3991 // rdx: exception pc in caller or ???
aoqi@0 3992 // destination: exception handler of caller
aoqi@0 3993 //
aoqi@0 3994 // Note: the exception pc MUST be at a call (precise debug information)
aoqi@0 3995 // Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
aoqi@0 3996 //
aoqi@0 3997
aoqi@0 3998 void OptoRuntime::generate_exception_blob() {
aoqi@0 3999 assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
aoqi@0 4000 assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
aoqi@0 4001 assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
aoqi@0 4002
aoqi@0 4003 assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
aoqi@0 4004
aoqi@0 4005 // Allocate space for the code
aoqi@0 4006 ResourceMark rm;
aoqi@0 4007 // Setup code generation tools
aoqi@0 4008 CodeBuffer buffer("exception_blob", 2048, 1024);
aoqi@0 4009 MacroAssembler* masm = new MacroAssembler(&buffer);
aoqi@0 4010
aoqi@0 4011
aoqi@0 4012 address start = __ pc();
aoqi@0 4013
aoqi@0 4014 // Exception pc is 'return address' for stack walker
aoqi@0 4015 __ push(rdx);
aoqi@0 4016 __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
aoqi@0 4017
aoqi@0 4018 // Save callee-saved registers. See x86_64.ad.
aoqi@0 4019
aoqi@0 4020 // rbp is an implicitly saved callee saved register (i.e. the calling
aoqi@0 4021 // convention will save restore it in prolog/epilog) Other than that
aoqi@0 4022 // there are no callee save registers now that adapter frames are gone.
aoqi@0 4023
aoqi@0 4024 __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
aoqi@0 4025
aoqi@0 4026 // Store exception in Thread object. We cannot pass any arguments to the
aoqi@0 4027 // handle_exception call, since we do not want to make any assumption
aoqi@0 4028 // about the size of the frame where the exception happened in.
aoqi@0 4029 // c_rarg0 is either rdi (Linux) or rcx (Windows).
aoqi@0 4030 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
aoqi@0 4031 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);
aoqi@0 4032
aoqi@0 4033 // This call does all the hard work. It checks if an exception handler
aoqi@0 4034 // exists in the method.
aoqi@0 4035 // If so, it returns the handler address.
aoqi@0 4036 // If not, it prepares for stack-unwinding, restoring the callee-save
aoqi@0 4037 // registers of the frame being removed.
aoqi@0 4038 //
aoqi@0 4039 // address OptoRuntime::handle_exception_C(JavaThread* thread)
aoqi@0 4040
aoqi@0 4041 // At a method handle call, the stack may not be properly aligned
aoqi@0 4042 // when returning with an exception.
aoqi@0 4043 address the_pc = __ pc();
aoqi@0 4044 __ set_last_Java_frame(noreg, noreg, the_pc);
aoqi@0 4045 __ mov(c_rarg0, r15_thread);
aoqi@0 4046 __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack
aoqi@0 4047 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
aoqi@0 4048
aoqi@0 4049 // Set an oopmap for the call site. This oopmap will only be used if we
aoqi@0 4050 // are unwinding the stack. Hence, all locations will be dead.
aoqi@0 4051 // Callee-saved registers will be the same as the frame above (i.e.,
aoqi@0 4052 // handle_exception_stub), since they were restored when we got the
aoqi@0 4053 // exception.
aoqi@0 4054
aoqi@0 4055 OopMapSet* oop_maps = new OopMapSet();
aoqi@0 4056
aoqi@0 4057 oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));
aoqi@0 4058
aoqi@0 4059 __ reset_last_Java_frame(false, true);
aoqi@0 4060
aoqi@0 4061 // Restore callee-saved registers
aoqi@0 4062
aoqi@0 4063 // rbp is an implicitly saved callee saved register (i.e. the calling
aoqi@0 4064 // convention will save restore it in prolog/epilog) Other than that
aoqi@0 4065 // there are no callee save registers no that adapter frames are gone.
aoqi@0 4066
aoqi@0 4067 __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
aoqi@0 4068
aoqi@0 4069 __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
aoqi@0 4070 __ pop(rdx); // No need for exception pc anymore
aoqi@0 4071
aoqi@0 4072 // rax: exception handler
aoqi@0 4073
aoqi@0 4074 // Restore SP from BP if the exception PC is a MethodHandle call site.
aoqi@0 4075 __ cmpl(Address(r15_thread, JavaThread::is_method_handle_return_offset()), 0);
aoqi@0 4076 __ cmovptr(Assembler::notEqual, rsp, rbp_mh_SP_save);
aoqi@0 4077
aoqi@0 4078 // We have a handler in rax (could be deopt blob).
aoqi@0 4079 __ mov(r8, rax);
aoqi@0 4080
aoqi@0 4081 // Get the exception oop
aoqi@0 4082 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
aoqi@0 4083 // Get the exception pc in case we are deoptimized
aoqi@0 4084 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
aoqi@0 4085 #ifdef ASSERT
aoqi@0 4086 __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), (int)NULL_WORD);
aoqi@0 4087 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), (int)NULL_WORD);
aoqi@0 4088 #endif
aoqi@0 4089 // Clear the exception oop so GC no longer processes it as a root.
aoqi@0 4090 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), (int)NULL_WORD);
aoqi@0 4091
aoqi@0 4092 // rax: exception oop
aoqi@0 4093 // r8: exception handler
aoqi@0 4094 // rdx: exception pc
aoqi@0 4095 // Jump to handler
aoqi@0 4096
aoqi@0 4097 __ jmp(r8);
aoqi@0 4098
aoqi@0 4099 // Make sure all code is generated
aoqi@0 4100 masm->flush();
aoqi@0 4101
aoqi@0 4102 // Set exception blob
aoqi@0 4103 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
aoqi@0 4104 }
aoqi@0 4105 #endif // COMPILER2

mercurial