src/cpu/x86/vm/c1_Runtime1_x86.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7416
b5eb829bbce1
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 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/assembler.hpp"
aoqi@0 27 #include "c1/c1_Defs.hpp"
aoqi@0 28 #include "c1/c1_MacroAssembler.hpp"
aoqi@0 29 #include "c1/c1_Runtime1.hpp"
aoqi@0 30 #include "interpreter/interpreter.hpp"
aoqi@0 31 #include "nativeInst_x86.hpp"
aoqi@0 32 #include "oops/compiledICHolder.hpp"
aoqi@0 33 #include "oops/oop.inline.hpp"
aoqi@0 34 #include "prims/jvmtiExport.hpp"
aoqi@0 35 #include "register_x86.hpp"
aoqi@0 36 #include "runtime/sharedRuntime.hpp"
aoqi@0 37 #include "runtime/signature.hpp"
aoqi@0 38 #include "runtime/vframeArray.hpp"
aoqi@0 39 #include "utilities/macros.hpp"
aoqi@0 40 #include "vmreg_x86.inline.hpp"
aoqi@0 41 #if INCLUDE_ALL_GCS
aoqi@0 42 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
aoqi@0 43 #endif
aoqi@0 44
aoqi@0 45
aoqi@0 46 // Implementation of StubAssembler
aoqi@0 47
aoqi@0 48 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, int args_size) {
aoqi@0 49 // setup registers
aoqi@0 50 const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread); // is callee-saved register (Visual C++ calling conventions)
aoqi@0 51 assert(!(oop_result1->is_valid() || metadata_result->is_valid()) || oop_result1 != metadata_result, "registers must be different");
aoqi@0 52 assert(oop_result1 != thread && metadata_result != thread, "registers must be different");
aoqi@0 53 assert(args_size >= 0, "illegal args_size");
aoqi@0 54 bool align_stack = false;
aoqi@0 55 #ifdef _LP64
aoqi@0 56 // At a method handle call, the stack may not be properly aligned
aoqi@0 57 // when returning with an exception.
aoqi@0 58 align_stack = (stub_id() == Runtime1::handle_exception_from_callee_id);
aoqi@0 59 #endif
aoqi@0 60
aoqi@0 61 #ifdef _LP64
aoqi@0 62 mov(c_rarg0, thread);
aoqi@0 63 set_num_rt_args(0); // Nothing on stack
aoqi@0 64 #else
aoqi@0 65 set_num_rt_args(1 + args_size);
aoqi@0 66
aoqi@0 67 // push java thread (becomes first argument of C function)
aoqi@0 68 get_thread(thread);
aoqi@0 69 push(thread);
aoqi@0 70 #endif // _LP64
aoqi@0 71
aoqi@0 72 int call_offset;
aoqi@0 73 if (!align_stack) {
aoqi@0 74 set_last_Java_frame(thread, noreg, rbp, NULL);
aoqi@0 75 } else {
aoqi@0 76 address the_pc = pc();
aoqi@0 77 call_offset = offset();
aoqi@0 78 set_last_Java_frame(thread, noreg, rbp, the_pc);
aoqi@0 79 andptr(rsp, -(StackAlignmentInBytes)); // Align stack
aoqi@0 80 }
aoqi@0 81
aoqi@0 82 // do the call
aoqi@0 83 call(RuntimeAddress(entry));
aoqi@0 84 if (!align_stack) {
aoqi@0 85 call_offset = offset();
aoqi@0 86 }
aoqi@0 87 // verify callee-saved register
aoqi@0 88 #ifdef ASSERT
aoqi@0 89 guarantee(thread != rax, "change this code");
aoqi@0 90 push(rax);
aoqi@0 91 { Label L;
aoqi@0 92 get_thread(rax);
aoqi@0 93 cmpptr(thread, rax);
aoqi@0 94 jcc(Assembler::equal, L);
aoqi@0 95 int3();
aoqi@0 96 stop("StubAssembler::call_RT: rdi not callee saved?");
aoqi@0 97 bind(L);
aoqi@0 98 }
aoqi@0 99 pop(rax);
aoqi@0 100 #endif
aoqi@0 101 reset_last_Java_frame(thread, true, align_stack);
aoqi@0 102
aoqi@0 103 // discard thread and arguments
aoqi@0 104 NOT_LP64(addptr(rsp, num_rt_args()*BytesPerWord));
aoqi@0 105
aoqi@0 106 // check for pending exceptions
aoqi@0 107 { Label L;
aoqi@0 108 cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 109 jcc(Assembler::equal, L);
aoqi@0 110 // exception pending => remove activation and forward to exception handler
aoqi@0 111 movptr(rax, Address(thread, Thread::pending_exception_offset()));
aoqi@0 112 // make sure that the vm_results are cleared
aoqi@0 113 if (oop_result1->is_valid()) {
aoqi@0 114 movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);
aoqi@0 115 }
aoqi@0 116 if (metadata_result->is_valid()) {
aoqi@0 117 movptr(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD);
aoqi@0 118 }
aoqi@0 119 if (frame_size() == no_frame_size) {
aoqi@0 120 leave();
aoqi@0 121 jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
aoqi@0 122 } else if (_stub_id == Runtime1::forward_exception_id) {
aoqi@0 123 should_not_reach_here();
aoqi@0 124 } else {
aoqi@0 125 jump(RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));
aoqi@0 126 }
aoqi@0 127 bind(L);
aoqi@0 128 }
aoqi@0 129 // get oop results if there are any and reset the values in the thread
aoqi@0 130 if (oop_result1->is_valid()) {
aoqi@0 131 get_vm_result(oop_result1, thread);
aoqi@0 132 }
aoqi@0 133 if (metadata_result->is_valid()) {
aoqi@0 134 get_vm_result_2(metadata_result, thread);
aoqi@0 135 }
aoqi@0 136 return call_offset;
aoqi@0 137 }
aoqi@0 138
aoqi@0 139
aoqi@0 140 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1) {
aoqi@0 141 #ifdef _LP64
aoqi@0 142 mov(c_rarg1, arg1);
aoqi@0 143 #else
aoqi@0 144 push(arg1);
aoqi@0 145 #endif // _LP64
aoqi@0 146 return call_RT(oop_result1, metadata_result, entry, 1);
aoqi@0 147 }
aoqi@0 148
aoqi@0 149
aoqi@0 150 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2) {
aoqi@0 151 #ifdef _LP64
aoqi@0 152 if (c_rarg1 == arg2) {
aoqi@0 153 if (c_rarg2 == arg1) {
aoqi@0 154 xchgq(arg1, arg2);
aoqi@0 155 } else {
aoqi@0 156 mov(c_rarg2, arg2);
aoqi@0 157 mov(c_rarg1, arg1);
aoqi@0 158 }
aoqi@0 159 } else {
aoqi@0 160 mov(c_rarg1, arg1);
aoqi@0 161 mov(c_rarg2, arg2);
aoqi@0 162 }
aoqi@0 163 #else
aoqi@0 164 push(arg2);
aoqi@0 165 push(arg1);
aoqi@0 166 #endif // _LP64
aoqi@0 167 return call_RT(oop_result1, metadata_result, entry, 2);
aoqi@0 168 }
aoqi@0 169
aoqi@0 170
aoqi@0 171 int StubAssembler::call_RT(Register oop_result1, Register metadata_result, address entry, Register arg1, Register arg2, Register arg3) {
aoqi@0 172 #ifdef _LP64
aoqi@0 173 // if there is any conflict use the stack
aoqi@0 174 if (arg1 == c_rarg2 || arg1 == c_rarg3 ||
aoqi@0 175 arg2 == c_rarg1 || arg1 == c_rarg3 ||
aoqi@0 176 arg3 == c_rarg1 || arg1 == c_rarg2) {
aoqi@0 177 push(arg3);
aoqi@0 178 push(arg2);
aoqi@0 179 push(arg1);
aoqi@0 180 pop(c_rarg1);
aoqi@0 181 pop(c_rarg2);
aoqi@0 182 pop(c_rarg3);
aoqi@0 183 } else {
aoqi@0 184 mov(c_rarg1, arg1);
aoqi@0 185 mov(c_rarg2, arg2);
aoqi@0 186 mov(c_rarg3, arg3);
aoqi@0 187 }
aoqi@0 188 #else
aoqi@0 189 push(arg3);
aoqi@0 190 push(arg2);
aoqi@0 191 push(arg1);
aoqi@0 192 #endif // _LP64
aoqi@0 193 return call_RT(oop_result1, metadata_result, entry, 3);
aoqi@0 194 }
aoqi@0 195
aoqi@0 196
aoqi@0 197 // Implementation of StubFrame
aoqi@0 198
aoqi@0 199 class StubFrame: public StackObj {
aoqi@0 200 private:
aoqi@0 201 StubAssembler* _sasm;
aoqi@0 202
aoqi@0 203 public:
aoqi@0 204 StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments);
aoqi@0 205 void load_argument(int offset_in_words, Register reg);
aoqi@0 206
aoqi@0 207 ~StubFrame();
aoqi@0 208 };
aoqi@0 209
aoqi@0 210
aoqi@0 211 #define __ _sasm->
aoqi@0 212
aoqi@0 213 StubFrame::StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments) {
aoqi@0 214 _sasm = sasm;
aoqi@0 215 __ set_info(name, must_gc_arguments);
aoqi@0 216 __ enter();
aoqi@0 217 }
aoqi@0 218
aoqi@0 219 // load parameters that were stored with LIR_Assembler::store_parameter
aoqi@0 220 // Note: offsets for store_parameter and load_argument must match
aoqi@0 221 void StubFrame::load_argument(int offset_in_words, Register reg) {
aoqi@0 222 // rbp, + 0: link
aoqi@0 223 // + 1: return address
aoqi@0 224 // + 2: argument with offset 0
aoqi@0 225 // + 3: argument with offset 1
aoqi@0 226 // + 4: ...
aoqi@0 227
aoqi@0 228 __ movptr(reg, Address(rbp, (offset_in_words + 2) * BytesPerWord));
aoqi@0 229 }
aoqi@0 230
aoqi@0 231
aoqi@0 232 StubFrame::~StubFrame() {
aoqi@0 233 __ leave();
aoqi@0 234 __ ret(0);
aoqi@0 235 }
aoqi@0 236
aoqi@0 237 #undef __
aoqi@0 238
aoqi@0 239
aoqi@0 240 // Implementation of Runtime1
aoqi@0 241
aoqi@0 242 #define __ sasm->
aoqi@0 243
aoqi@0 244 const int float_regs_as_doubles_size_in_slots = pd_nof_fpu_regs_frame_map * 2;
aoqi@0 245 const int xmm_regs_as_doubles_size_in_slots = FrameMap::nof_xmm_regs * 2;
aoqi@0 246
aoqi@0 247 // Stack layout for saving/restoring all the registers needed during a runtime
aoqi@0 248 // call (this includes deoptimization)
aoqi@0 249 // Note: note that users of this frame may well have arguments to some runtime
aoqi@0 250 // while these values are on the stack. These positions neglect those arguments
aoqi@0 251 // but the code in save_live_registers will take the argument count into
aoqi@0 252 // account.
aoqi@0 253 //
aoqi@0 254 #ifdef _LP64
aoqi@0 255 #define SLOT2(x) x,
aoqi@0 256 #define SLOT_PER_WORD 2
aoqi@0 257 #else
aoqi@0 258 #define SLOT2(x)
aoqi@0 259 #define SLOT_PER_WORD 1
aoqi@0 260 #endif // _LP64
aoqi@0 261
aoqi@0 262 enum reg_save_layout {
aoqi@0 263 // 64bit needs to keep stack 16 byte aligned. So we add some alignment dummies to make that
aoqi@0 264 // happen and will assert if the stack size we create is misaligned
aoqi@0 265 #ifdef _LP64
aoqi@0 266 align_dummy_0, align_dummy_1,
aoqi@0 267 #endif // _LP64
aoqi@0 268 #ifdef _WIN64
aoqi@0 269 // Windows always allocates space for it's argument registers (see
aoqi@0 270 // frame::arg_reg_save_area_bytes).
aoqi@0 271 arg_reg_save_1, arg_reg_save_1H, // 0, 4
aoqi@0 272 arg_reg_save_2, arg_reg_save_2H, // 8, 12
aoqi@0 273 arg_reg_save_3, arg_reg_save_3H, // 16, 20
aoqi@0 274 arg_reg_save_4, arg_reg_save_4H, // 24, 28
aoqi@0 275 #endif // _WIN64
aoqi@0 276 xmm_regs_as_doubles_off, // 32
aoqi@0 277 float_regs_as_doubles_off = xmm_regs_as_doubles_off + xmm_regs_as_doubles_size_in_slots, // 160
aoqi@0 278 fpu_state_off = float_regs_as_doubles_off + float_regs_as_doubles_size_in_slots, // 224
aoqi@0 279 // fpu_state_end_off is exclusive
aoqi@0 280 fpu_state_end_off = fpu_state_off + (FPUStateSizeInWords / SLOT_PER_WORD), // 352
aoqi@0 281 marker = fpu_state_end_off, SLOT2(markerH) // 352, 356
aoqi@0 282 extra_space_offset, // 360
aoqi@0 283 #ifdef _LP64
aoqi@0 284 r15_off = extra_space_offset, r15H_off, // 360, 364
aoqi@0 285 r14_off, r14H_off, // 368, 372
aoqi@0 286 r13_off, r13H_off, // 376, 380
aoqi@0 287 r12_off, r12H_off, // 384, 388
aoqi@0 288 r11_off, r11H_off, // 392, 396
aoqi@0 289 r10_off, r10H_off, // 400, 404
aoqi@0 290 r9_off, r9H_off, // 408, 412
aoqi@0 291 r8_off, r8H_off, // 416, 420
aoqi@0 292 rdi_off, rdiH_off, // 424, 428
aoqi@0 293 #else
aoqi@0 294 rdi_off = extra_space_offset,
aoqi@0 295 #endif // _LP64
aoqi@0 296 rsi_off, SLOT2(rsiH_off) // 432, 436
aoqi@0 297 rbp_off, SLOT2(rbpH_off) // 440, 444
aoqi@0 298 rsp_off, SLOT2(rspH_off) // 448, 452
aoqi@0 299 rbx_off, SLOT2(rbxH_off) // 456, 460
aoqi@0 300 rdx_off, SLOT2(rdxH_off) // 464, 468
aoqi@0 301 rcx_off, SLOT2(rcxH_off) // 472, 476
aoqi@0 302 rax_off, SLOT2(raxH_off) // 480, 484
aoqi@0 303 saved_rbp_off, SLOT2(saved_rbpH_off) // 488, 492
aoqi@0 304 return_off, SLOT2(returnH_off) // 496, 500
aoqi@0 305 reg_save_frame_size // As noted: neglects any parameters to runtime // 504
aoqi@0 306 };
aoqi@0 307
aoqi@0 308
aoqi@0 309
aoqi@0 310 // Save off registers which might be killed by calls into the runtime.
aoqi@0 311 // Tries to smart of about FP registers. In particular we separate
aoqi@0 312 // saving and describing the FPU registers for deoptimization since we
aoqi@0 313 // have to save the FPU registers twice if we describe them and on P4
aoqi@0 314 // saving FPU registers which don't contain anything appears
aoqi@0 315 // expensive. The deopt blob is the only thing which needs to
aoqi@0 316 // describe FPU registers. In all other cases it should be sufficient
aoqi@0 317 // to simply save their current value.
aoqi@0 318
aoqi@0 319 static OopMap* generate_oop_map(StubAssembler* sasm, int num_rt_args,
aoqi@0 320 bool save_fpu_registers = true) {
aoqi@0 321
aoqi@0 322 // In 64bit all the args are in regs so there are no additional stack slots
aoqi@0 323 LP64_ONLY(num_rt_args = 0);
aoqi@0 324 LP64_ONLY(assert((reg_save_frame_size * VMRegImpl::stack_slot_size) % 16 == 0, "must be 16 byte aligned");)
aoqi@0 325 int frame_size_in_slots = reg_save_frame_size + num_rt_args; // args + thread
aoqi@0 326 sasm->set_frame_size(frame_size_in_slots / VMRegImpl::slots_per_word );
aoqi@0 327
aoqi@0 328 // record saved value locations in an OopMap
aoqi@0 329 // locations are offsets from sp after runtime call; num_rt_args is number of arguments in call, including thread
aoqi@0 330 OopMap* map = new OopMap(frame_size_in_slots, 0);
aoqi@0 331 map->set_callee_saved(VMRegImpl::stack2reg(rax_off + num_rt_args), rax->as_VMReg());
aoqi@0 332 map->set_callee_saved(VMRegImpl::stack2reg(rcx_off + num_rt_args), rcx->as_VMReg());
aoqi@0 333 map->set_callee_saved(VMRegImpl::stack2reg(rdx_off + num_rt_args), rdx->as_VMReg());
aoqi@0 334 map->set_callee_saved(VMRegImpl::stack2reg(rbx_off + num_rt_args), rbx->as_VMReg());
aoqi@0 335 map->set_callee_saved(VMRegImpl::stack2reg(rsi_off + num_rt_args), rsi->as_VMReg());
aoqi@0 336 map->set_callee_saved(VMRegImpl::stack2reg(rdi_off + num_rt_args), rdi->as_VMReg());
aoqi@0 337 #ifdef _LP64
aoqi@0 338 map->set_callee_saved(VMRegImpl::stack2reg(r8_off + num_rt_args), r8->as_VMReg());
aoqi@0 339 map->set_callee_saved(VMRegImpl::stack2reg(r9_off + num_rt_args), r9->as_VMReg());
aoqi@0 340 map->set_callee_saved(VMRegImpl::stack2reg(r10_off + num_rt_args), r10->as_VMReg());
aoqi@0 341 map->set_callee_saved(VMRegImpl::stack2reg(r11_off + num_rt_args), r11->as_VMReg());
aoqi@0 342 map->set_callee_saved(VMRegImpl::stack2reg(r12_off + num_rt_args), r12->as_VMReg());
aoqi@0 343 map->set_callee_saved(VMRegImpl::stack2reg(r13_off + num_rt_args), r13->as_VMReg());
aoqi@0 344 map->set_callee_saved(VMRegImpl::stack2reg(r14_off + num_rt_args), r14->as_VMReg());
aoqi@0 345 map->set_callee_saved(VMRegImpl::stack2reg(r15_off + num_rt_args), r15->as_VMReg());
aoqi@0 346
aoqi@0 347 // This is stupid but needed.
aoqi@0 348 map->set_callee_saved(VMRegImpl::stack2reg(raxH_off + num_rt_args), rax->as_VMReg()->next());
aoqi@0 349 map->set_callee_saved(VMRegImpl::stack2reg(rcxH_off + num_rt_args), rcx->as_VMReg()->next());
aoqi@0 350 map->set_callee_saved(VMRegImpl::stack2reg(rdxH_off + num_rt_args), rdx->as_VMReg()->next());
aoqi@0 351 map->set_callee_saved(VMRegImpl::stack2reg(rbxH_off + num_rt_args), rbx->as_VMReg()->next());
aoqi@0 352 map->set_callee_saved(VMRegImpl::stack2reg(rsiH_off + num_rt_args), rsi->as_VMReg()->next());
aoqi@0 353 map->set_callee_saved(VMRegImpl::stack2reg(rdiH_off + num_rt_args), rdi->as_VMReg()->next());
aoqi@0 354
aoqi@0 355 map->set_callee_saved(VMRegImpl::stack2reg(r8H_off + num_rt_args), r8->as_VMReg()->next());
aoqi@0 356 map->set_callee_saved(VMRegImpl::stack2reg(r9H_off + num_rt_args), r9->as_VMReg()->next());
aoqi@0 357 map->set_callee_saved(VMRegImpl::stack2reg(r10H_off + num_rt_args), r10->as_VMReg()->next());
aoqi@0 358 map->set_callee_saved(VMRegImpl::stack2reg(r11H_off + num_rt_args), r11->as_VMReg()->next());
aoqi@0 359 map->set_callee_saved(VMRegImpl::stack2reg(r12H_off + num_rt_args), r12->as_VMReg()->next());
aoqi@0 360 map->set_callee_saved(VMRegImpl::stack2reg(r13H_off + num_rt_args), r13->as_VMReg()->next());
aoqi@0 361 map->set_callee_saved(VMRegImpl::stack2reg(r14H_off + num_rt_args), r14->as_VMReg()->next());
aoqi@0 362 map->set_callee_saved(VMRegImpl::stack2reg(r15H_off + num_rt_args), r15->as_VMReg()->next());
aoqi@0 363 #endif // _LP64
aoqi@0 364
aoqi@0 365 if (save_fpu_registers) {
aoqi@0 366 if (UseSSE < 2) {
aoqi@0 367 int fpu_off = float_regs_as_doubles_off;
aoqi@0 368 for (int n = 0; n < FrameMap::nof_fpu_regs; n++) {
aoqi@0 369 VMReg fpu_name_0 = FrameMap::fpu_regname(n);
aoqi@0 370 map->set_callee_saved(VMRegImpl::stack2reg(fpu_off + num_rt_args), fpu_name_0);
aoqi@0 371 // %%% This is really a waste but we'll keep things as they were for now
aoqi@0 372 if (true) {
aoqi@0 373 map->set_callee_saved(VMRegImpl::stack2reg(fpu_off + 1 + num_rt_args), fpu_name_0->next());
aoqi@0 374 }
aoqi@0 375 fpu_off += 2;
aoqi@0 376 }
aoqi@0 377 assert(fpu_off == fpu_state_off, "incorrect number of fpu stack slots");
aoqi@0 378 }
aoqi@0 379
aoqi@0 380 if (UseSSE >= 2) {
aoqi@0 381 int xmm_off = xmm_regs_as_doubles_off;
aoqi@0 382 for (int n = 0; n < FrameMap::nof_xmm_regs; n++) {
aoqi@0 383 VMReg xmm_name_0 = as_XMMRegister(n)->as_VMReg();
aoqi@0 384 map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + num_rt_args), xmm_name_0);
aoqi@0 385 // %%% This is really a waste but we'll keep things as they were for now
aoqi@0 386 if (true) {
aoqi@0 387 map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + 1 + num_rt_args), xmm_name_0->next());
aoqi@0 388 }
aoqi@0 389 xmm_off += 2;
aoqi@0 390 }
aoqi@0 391 assert(xmm_off == float_regs_as_doubles_off, "incorrect number of xmm registers");
aoqi@0 392
aoqi@0 393 } else if (UseSSE == 1) {
aoqi@0 394 int xmm_off = xmm_regs_as_doubles_off;
aoqi@0 395 for (int n = 0; n < FrameMap::nof_xmm_regs; n++) {
aoqi@0 396 VMReg xmm_name_0 = as_XMMRegister(n)->as_VMReg();
aoqi@0 397 map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + num_rt_args), xmm_name_0);
aoqi@0 398 xmm_off += 2;
aoqi@0 399 }
aoqi@0 400 assert(xmm_off == float_regs_as_doubles_off, "incorrect number of xmm registers");
aoqi@0 401 }
aoqi@0 402 }
aoqi@0 403
aoqi@0 404 return map;
aoqi@0 405 }
aoqi@0 406
aoqi@0 407 static OopMap* save_live_registers(StubAssembler* sasm, int num_rt_args,
aoqi@0 408 bool save_fpu_registers = true) {
aoqi@0 409 __ block_comment("save_live_registers");
aoqi@0 410
aoqi@0 411 __ pusha(); // integer registers
aoqi@0 412
aoqi@0 413 // assert(float_regs_as_doubles_off % 2 == 0, "misaligned offset");
aoqi@0 414 // assert(xmm_regs_as_doubles_off % 2 == 0, "misaligned offset");
aoqi@0 415
aoqi@0 416 __ subptr(rsp, extra_space_offset * VMRegImpl::stack_slot_size);
aoqi@0 417
aoqi@0 418 #ifdef ASSERT
aoqi@0 419 __ movptr(Address(rsp, marker * VMRegImpl::stack_slot_size), (int32_t)0xfeedbeef);
aoqi@0 420 #endif
aoqi@0 421
aoqi@0 422 if (save_fpu_registers) {
aoqi@0 423 if (UseSSE < 2) {
aoqi@0 424 // save FPU stack
aoqi@0 425 __ fnsave(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size));
aoqi@0 426 __ fwait();
aoqi@0 427
aoqi@0 428 #ifdef ASSERT
aoqi@0 429 Label ok;
aoqi@0 430 __ cmpw(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size), StubRoutines::fpu_cntrl_wrd_std());
aoqi@0 431 __ jccb(Assembler::equal, ok);
aoqi@0 432 __ stop("corrupted control word detected");
aoqi@0 433 __ bind(ok);
aoqi@0 434 #endif
aoqi@0 435
aoqi@0 436 // Reset the control word to guard against exceptions being unmasked
aoqi@0 437 // since fstp_d can cause FPU stack underflow exceptions. Write it
aoqi@0 438 // into the on stack copy and then reload that to make sure that the
aoqi@0 439 // current and future values are correct.
aoqi@0 440 __ movw(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size), StubRoutines::fpu_cntrl_wrd_std());
aoqi@0 441 __ frstor(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size));
aoqi@0 442
aoqi@0 443 // Save the FPU registers in de-opt-able form
aoqi@0 444 __ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0));
aoqi@0 445 __ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8));
aoqi@0 446 __ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16));
aoqi@0 447 __ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24));
aoqi@0 448 __ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32));
aoqi@0 449 __ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40));
aoqi@0 450 __ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48));
aoqi@0 451 __ fstp_d(Address(rsp, float_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56));
aoqi@0 452 }
aoqi@0 453
aoqi@0 454 if (UseSSE >= 2) {
aoqi@0 455 // save XMM registers
aoqi@0 456 // XMM registers can contain float or double values, but this is not known here,
aoqi@0 457 // so always save them as doubles.
aoqi@0 458 // note that float values are _not_ converted automatically, so for float values
aoqi@0 459 // the second word contains only garbage data.
aoqi@0 460 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0), xmm0);
aoqi@0 461 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8), xmm1);
aoqi@0 462 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16), xmm2);
aoqi@0 463 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24), xmm3);
aoqi@0 464 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32), xmm4);
aoqi@0 465 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40), xmm5);
aoqi@0 466 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48), xmm6);
aoqi@0 467 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56), xmm7);
aoqi@0 468 #ifdef _LP64
aoqi@0 469 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 64), xmm8);
aoqi@0 470 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 72), xmm9);
aoqi@0 471 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 80), xmm10);
aoqi@0 472 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 88), xmm11);
aoqi@0 473 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 96), xmm12);
aoqi@0 474 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 104), xmm13);
aoqi@0 475 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 112), xmm14);
aoqi@0 476 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 120), xmm15);
aoqi@0 477 #endif // _LP64
aoqi@0 478 } else if (UseSSE == 1) {
aoqi@0 479 // save XMM registers as float because double not supported without SSE2
aoqi@0 480 __ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0), xmm0);
aoqi@0 481 __ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8), xmm1);
aoqi@0 482 __ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16), xmm2);
aoqi@0 483 __ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24), xmm3);
aoqi@0 484 __ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32), xmm4);
aoqi@0 485 __ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40), xmm5);
aoqi@0 486 __ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48), xmm6);
aoqi@0 487 __ movflt(Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56), xmm7);
aoqi@0 488 }
aoqi@0 489 }
aoqi@0 490
aoqi@0 491 // FPU stack must be empty now
aoqi@0 492 __ verify_FPU(0, "save_live_registers");
aoqi@0 493
aoqi@0 494 return generate_oop_map(sasm, num_rt_args, save_fpu_registers);
aoqi@0 495 }
aoqi@0 496
aoqi@0 497
aoqi@0 498 static void restore_fpu(StubAssembler* sasm, bool restore_fpu_registers = true) {
aoqi@0 499 if (restore_fpu_registers) {
aoqi@0 500 if (UseSSE >= 2) {
aoqi@0 501 // restore XMM registers
aoqi@0 502 __ movdbl(xmm0, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0));
aoqi@0 503 __ movdbl(xmm1, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8));
aoqi@0 504 __ movdbl(xmm2, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16));
aoqi@0 505 __ movdbl(xmm3, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24));
aoqi@0 506 __ movdbl(xmm4, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32));
aoqi@0 507 __ movdbl(xmm5, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40));
aoqi@0 508 __ movdbl(xmm6, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48));
aoqi@0 509 __ movdbl(xmm7, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56));
aoqi@0 510 #ifdef _LP64
aoqi@0 511 __ movdbl(xmm8, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 64));
aoqi@0 512 __ movdbl(xmm9, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 72));
aoqi@0 513 __ movdbl(xmm10, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 80));
aoqi@0 514 __ movdbl(xmm11, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 88));
aoqi@0 515 __ movdbl(xmm12, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 96));
aoqi@0 516 __ movdbl(xmm13, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 104));
aoqi@0 517 __ movdbl(xmm14, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 112));
aoqi@0 518 __ movdbl(xmm15, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 120));
aoqi@0 519 #endif // _LP64
aoqi@0 520 } else if (UseSSE == 1) {
aoqi@0 521 // restore XMM registers
aoqi@0 522 __ movflt(xmm0, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 0));
aoqi@0 523 __ movflt(xmm1, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 8));
aoqi@0 524 __ movflt(xmm2, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 16));
aoqi@0 525 __ movflt(xmm3, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 24));
aoqi@0 526 __ movflt(xmm4, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 32));
aoqi@0 527 __ movflt(xmm5, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 40));
aoqi@0 528 __ movflt(xmm6, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 48));
aoqi@0 529 __ movflt(xmm7, Address(rsp, xmm_regs_as_doubles_off * VMRegImpl::stack_slot_size + 56));
aoqi@0 530 }
aoqi@0 531
aoqi@0 532 if (UseSSE < 2) {
aoqi@0 533 __ frstor(Address(rsp, fpu_state_off * VMRegImpl::stack_slot_size));
aoqi@0 534 } else {
aoqi@0 535 // check that FPU stack is really empty
aoqi@0 536 __ verify_FPU(0, "restore_live_registers");
aoqi@0 537 }
aoqi@0 538
aoqi@0 539 } else {
aoqi@0 540 // check that FPU stack is really empty
aoqi@0 541 __ verify_FPU(0, "restore_live_registers");
aoqi@0 542 }
aoqi@0 543
aoqi@0 544 #ifdef ASSERT
aoqi@0 545 {
aoqi@0 546 Label ok;
aoqi@0 547 __ cmpptr(Address(rsp, marker * VMRegImpl::stack_slot_size), (int32_t)0xfeedbeef);
aoqi@0 548 __ jcc(Assembler::equal, ok);
aoqi@0 549 __ stop("bad offsets in frame");
aoqi@0 550 __ bind(ok);
aoqi@0 551 }
aoqi@0 552 #endif // ASSERT
aoqi@0 553
aoqi@0 554 __ addptr(rsp, extra_space_offset * VMRegImpl::stack_slot_size);
aoqi@0 555 }
aoqi@0 556
aoqi@0 557
aoqi@0 558 static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {
aoqi@0 559 __ block_comment("restore_live_registers");
aoqi@0 560
aoqi@0 561 restore_fpu(sasm, restore_fpu_registers);
aoqi@0 562 __ popa();
aoqi@0 563 }
aoqi@0 564
aoqi@0 565
aoqi@0 566 static void restore_live_registers_except_rax(StubAssembler* sasm, bool restore_fpu_registers = true) {
aoqi@0 567 __ block_comment("restore_live_registers_except_rax");
aoqi@0 568
aoqi@0 569 restore_fpu(sasm, restore_fpu_registers);
aoqi@0 570
aoqi@0 571 #ifdef _LP64
aoqi@0 572 __ movptr(r15, Address(rsp, 0));
aoqi@0 573 __ movptr(r14, Address(rsp, wordSize));
aoqi@0 574 __ movptr(r13, Address(rsp, 2 * wordSize));
aoqi@0 575 __ movptr(r12, Address(rsp, 3 * wordSize));
aoqi@0 576 __ movptr(r11, Address(rsp, 4 * wordSize));
aoqi@0 577 __ movptr(r10, Address(rsp, 5 * wordSize));
aoqi@0 578 __ movptr(r9, Address(rsp, 6 * wordSize));
aoqi@0 579 __ movptr(r8, Address(rsp, 7 * wordSize));
aoqi@0 580 __ movptr(rdi, Address(rsp, 8 * wordSize));
aoqi@0 581 __ movptr(rsi, Address(rsp, 9 * wordSize));
aoqi@0 582 __ movptr(rbp, Address(rsp, 10 * wordSize));
aoqi@0 583 // skip rsp
aoqi@0 584 __ movptr(rbx, Address(rsp, 12 * wordSize));
aoqi@0 585 __ movptr(rdx, Address(rsp, 13 * wordSize));
aoqi@0 586 __ movptr(rcx, Address(rsp, 14 * wordSize));
aoqi@0 587
aoqi@0 588 __ addptr(rsp, 16 * wordSize);
aoqi@0 589 #else
aoqi@0 590
aoqi@0 591 __ pop(rdi);
aoqi@0 592 __ pop(rsi);
aoqi@0 593 __ pop(rbp);
aoqi@0 594 __ pop(rbx); // skip this value
aoqi@0 595 __ pop(rbx);
aoqi@0 596 __ pop(rdx);
aoqi@0 597 __ pop(rcx);
aoqi@0 598 __ addptr(rsp, BytesPerWord);
aoqi@0 599 #endif // _LP64
aoqi@0 600 }
aoqi@0 601
aoqi@0 602
aoqi@0 603 void Runtime1::initialize_pd() {
aoqi@0 604 // nothing to do
aoqi@0 605 }
aoqi@0 606
aoqi@0 607
aoqi@0 608 // target: the entry point of the method that creates and posts the exception oop
aoqi@0 609 // has_argument: true if the exception needs an argument (passed on stack because registers must be preserved)
aoqi@0 610
aoqi@0 611 OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {
aoqi@0 612 // preserve all registers
aoqi@0 613 int num_rt_args = has_argument ? 2 : 1;
aoqi@0 614 OopMap* oop_map = save_live_registers(sasm, num_rt_args);
aoqi@0 615
aoqi@0 616 // now all registers are saved and can be used freely
aoqi@0 617 // verify that no old value is used accidentally
aoqi@0 618 __ invalidate_registers(true, true, true, true, true, true);
aoqi@0 619
aoqi@0 620 // registers used by this stub
aoqi@0 621 const Register temp_reg = rbx;
aoqi@0 622
aoqi@0 623 // load argument for exception that is passed as an argument into the stub
aoqi@0 624 if (has_argument) {
aoqi@0 625 #ifdef _LP64
aoqi@0 626 __ movptr(c_rarg1, Address(rbp, 2*BytesPerWord));
aoqi@0 627 #else
aoqi@0 628 __ movptr(temp_reg, Address(rbp, 2*BytesPerWord));
aoqi@0 629 __ push(temp_reg);
aoqi@0 630 #endif // _LP64
aoqi@0 631 }
aoqi@0 632 int call_offset = __ call_RT(noreg, noreg, target, num_rt_args - 1);
aoqi@0 633
aoqi@0 634 OopMapSet* oop_maps = new OopMapSet();
aoqi@0 635 oop_maps->add_gc_map(call_offset, oop_map);
aoqi@0 636
aoqi@0 637 __ stop("should not reach here");
aoqi@0 638
aoqi@0 639 return oop_maps;
aoqi@0 640 }
aoqi@0 641
aoqi@0 642
aoqi@0 643 OopMapSet* Runtime1::generate_handle_exception(StubID id, StubAssembler *sasm) {
aoqi@0 644 __ block_comment("generate_handle_exception");
aoqi@0 645
aoqi@0 646 // incoming parameters
aoqi@0 647 const Register exception_oop = rax;
aoqi@0 648 const Register exception_pc = rdx;
aoqi@0 649 // other registers used in this stub
aoqi@0 650 const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread);
aoqi@0 651
aoqi@0 652 // Save registers, if required.
aoqi@0 653 OopMapSet* oop_maps = new OopMapSet();
aoqi@0 654 OopMap* oop_map = NULL;
aoqi@0 655 switch (id) {
aoqi@0 656 case forward_exception_id:
aoqi@0 657 // We're handling an exception in the context of a compiled frame.
aoqi@0 658 // The registers have been saved in the standard places. Perform
aoqi@0 659 // an exception lookup in the caller and dispatch to the handler
aoqi@0 660 // if found. Otherwise unwind and dispatch to the callers
aoqi@0 661 // exception handler.
aoqi@0 662 oop_map = generate_oop_map(sasm, 1 /*thread*/);
aoqi@0 663
aoqi@0 664 // load and clear pending exception oop into RAX
aoqi@0 665 __ movptr(exception_oop, Address(thread, Thread::pending_exception_offset()));
aoqi@0 666 __ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
aoqi@0 667
aoqi@0 668 // load issuing PC (the return address for this stub) into rdx
aoqi@0 669 __ movptr(exception_pc, Address(rbp, 1*BytesPerWord));
aoqi@0 670
aoqi@0 671 // make sure that the vm_results are cleared (may be unnecessary)
aoqi@0 672 __ movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);
aoqi@0 673 __ movptr(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD);
aoqi@0 674 break;
aoqi@0 675 case handle_exception_nofpu_id:
aoqi@0 676 case handle_exception_id:
aoqi@0 677 // At this point all registers MAY be live.
iveresov@7416 678 oop_map = save_live_registers(sasm, 1 /*thread*/, id != handle_exception_nofpu_id);
aoqi@0 679 break;
aoqi@0 680 case handle_exception_from_callee_id: {
aoqi@0 681 // At this point all registers except exception oop (RAX) and
aoqi@0 682 // exception pc (RDX) are dead.
aoqi@0 683 const int frame_size = 2 /*BP, return address*/ NOT_LP64(+ 1 /*thread*/) WIN64_ONLY(+ frame::arg_reg_save_area_bytes / BytesPerWord);
aoqi@0 684 oop_map = new OopMap(frame_size * VMRegImpl::slots_per_word, 0);
aoqi@0 685 sasm->set_frame_size(frame_size);
aoqi@0 686 WIN64_ONLY(__ subq(rsp, frame::arg_reg_save_area_bytes));
aoqi@0 687 break;
aoqi@0 688 }
aoqi@0 689 default: ShouldNotReachHere();
aoqi@0 690 }
aoqi@0 691
aoqi@0 692 #ifdef TIERED
aoqi@0 693 // C2 can leave the fpu stack dirty
aoqi@0 694 if (UseSSE < 2) {
aoqi@0 695 __ empty_FPU_stack();
aoqi@0 696 }
aoqi@0 697 #endif // TIERED
aoqi@0 698
aoqi@0 699 // verify that only rax, and rdx is valid at this time
aoqi@0 700 __ invalidate_registers(false, true, true, false, true, true);
aoqi@0 701 // verify that rax, contains a valid exception
aoqi@0 702 __ verify_not_null_oop(exception_oop);
aoqi@0 703
aoqi@0 704 // load address of JavaThread object for thread-local data
aoqi@0 705 NOT_LP64(__ get_thread(thread);)
aoqi@0 706
aoqi@0 707 #ifdef ASSERT
aoqi@0 708 // check that fields in JavaThread for exception oop and issuing pc are
aoqi@0 709 // empty before writing to them
aoqi@0 710 Label oop_empty;
aoqi@0 711 __ cmpptr(Address(thread, JavaThread::exception_oop_offset()), (int32_t) NULL_WORD);
aoqi@0 712 __ jcc(Assembler::equal, oop_empty);
aoqi@0 713 __ stop("exception oop already set");
aoqi@0 714 __ bind(oop_empty);
aoqi@0 715
aoqi@0 716 Label pc_empty;
aoqi@0 717 __ cmpptr(Address(thread, JavaThread::exception_pc_offset()), 0);
aoqi@0 718 __ jcc(Assembler::equal, pc_empty);
aoqi@0 719 __ stop("exception pc already set");
aoqi@0 720 __ bind(pc_empty);
aoqi@0 721 #endif
aoqi@0 722
aoqi@0 723 // save exception oop and issuing pc into JavaThread
aoqi@0 724 // (exception handler will load it from here)
aoqi@0 725 __ movptr(Address(thread, JavaThread::exception_oop_offset()), exception_oop);
aoqi@0 726 __ movptr(Address(thread, JavaThread::exception_pc_offset()), exception_pc);
aoqi@0 727
aoqi@0 728 // patch throwing pc into return address (has bci & oop map)
aoqi@0 729 __ movptr(Address(rbp, 1*BytesPerWord), exception_pc);
aoqi@0 730
aoqi@0 731 // compute the exception handler.
aoqi@0 732 // the exception oop and the throwing pc are read from the fields in JavaThread
aoqi@0 733 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));
aoqi@0 734 oop_maps->add_gc_map(call_offset, oop_map);
aoqi@0 735
aoqi@0 736 // rax: handler address
aoqi@0 737 // will be the deopt blob if nmethod was deoptimized while we looked up
aoqi@0 738 // handler regardless of whether handler existed in the nmethod.
aoqi@0 739
aoqi@0 740 // only rax, is valid at this time, all other registers have been destroyed by the runtime call
aoqi@0 741 __ invalidate_registers(false, true, true, true, true, true);
aoqi@0 742
aoqi@0 743 // patch the return address, this stub will directly return to the exception handler
aoqi@0 744 __ movptr(Address(rbp, 1*BytesPerWord), rax);
aoqi@0 745
aoqi@0 746 switch (id) {
aoqi@0 747 case forward_exception_id:
aoqi@0 748 case handle_exception_nofpu_id:
aoqi@0 749 case handle_exception_id:
aoqi@0 750 // Restore the registers that were saved at the beginning.
iveresov@7416 751 restore_live_registers(sasm, id != handle_exception_nofpu_id);
aoqi@0 752 break;
aoqi@0 753 case handle_exception_from_callee_id:
aoqi@0 754 // WIN64_ONLY: No need to add frame::arg_reg_save_area_bytes to SP
aoqi@0 755 // since we do a leave anyway.
aoqi@0 756
aoqi@0 757 // Pop the return address since we are possibly changing SP (restoring from BP).
aoqi@0 758 __ leave();
aoqi@0 759 __ pop(rcx);
aoqi@0 760
aoqi@0 761 // Restore SP from BP if the exception PC is a method handle call site.
aoqi@0 762 NOT_LP64(__ get_thread(thread);)
aoqi@0 763 __ cmpl(Address(thread, JavaThread::is_method_handle_return_offset()), 0);
aoqi@0 764 __ cmovptr(Assembler::notEqual, rsp, rbp_mh_SP_save);
aoqi@0 765 __ jmp(rcx); // jump to exception handler
aoqi@0 766 break;
aoqi@0 767 default: ShouldNotReachHere();
aoqi@0 768 }
aoqi@0 769
aoqi@0 770 return oop_maps;
aoqi@0 771 }
aoqi@0 772
aoqi@0 773
aoqi@0 774 void Runtime1::generate_unwind_exception(StubAssembler *sasm) {
aoqi@0 775 // incoming parameters
aoqi@0 776 const Register exception_oop = rax;
aoqi@0 777 // callee-saved copy of exception_oop during runtime call
aoqi@0 778 const Register exception_oop_callee_saved = NOT_LP64(rsi) LP64_ONLY(r14);
aoqi@0 779 // other registers used in this stub
aoqi@0 780 const Register exception_pc = rdx;
aoqi@0 781 const Register handler_addr = rbx;
aoqi@0 782 const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread);
aoqi@0 783
aoqi@0 784 // verify that only rax, is valid at this time
aoqi@0 785 __ invalidate_registers(false, true, true, true, true, true);
aoqi@0 786
aoqi@0 787 #ifdef ASSERT
aoqi@0 788 // check that fields in JavaThread for exception oop and issuing pc are empty
aoqi@0 789 NOT_LP64(__ get_thread(thread);)
aoqi@0 790 Label oop_empty;
aoqi@0 791 __ cmpptr(Address(thread, JavaThread::exception_oop_offset()), 0);
aoqi@0 792 __ jcc(Assembler::equal, oop_empty);
aoqi@0 793 __ stop("exception oop must be empty");
aoqi@0 794 __ bind(oop_empty);
aoqi@0 795
aoqi@0 796 Label pc_empty;
aoqi@0 797 __ cmpptr(Address(thread, JavaThread::exception_pc_offset()), 0);
aoqi@0 798 __ jcc(Assembler::equal, pc_empty);
aoqi@0 799 __ stop("exception pc must be empty");
aoqi@0 800 __ bind(pc_empty);
aoqi@0 801 #endif
aoqi@0 802
aoqi@0 803 // clear the FPU stack in case any FPU results are left behind
aoqi@0 804 __ empty_FPU_stack();
aoqi@0 805
aoqi@0 806 // save exception_oop in callee-saved register to preserve it during runtime calls
aoqi@0 807 __ verify_not_null_oop(exception_oop);
aoqi@0 808 __ movptr(exception_oop_callee_saved, exception_oop);
aoqi@0 809
aoqi@0 810 NOT_LP64(__ get_thread(thread);)
aoqi@0 811 // Get return address (is on top of stack after leave).
aoqi@0 812 __ movptr(exception_pc, Address(rsp, 0));
aoqi@0 813
aoqi@0 814 // search the exception handler address of the caller (using the return address)
aoqi@0 815 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, exception_pc);
aoqi@0 816 // rax: exception handler address of the caller
aoqi@0 817
aoqi@0 818 // Only RAX and RSI are valid at this time, all other registers have been destroyed by the call.
aoqi@0 819 __ invalidate_registers(false, true, true, true, false, true);
aoqi@0 820
aoqi@0 821 // move result of call into correct register
aoqi@0 822 __ movptr(handler_addr, rax);
aoqi@0 823
aoqi@0 824 // Restore exception oop to RAX (required convention of exception handler).
aoqi@0 825 __ movptr(exception_oop, exception_oop_callee_saved);
aoqi@0 826
aoqi@0 827 // verify that there is really a valid exception in rax
aoqi@0 828 __ verify_not_null_oop(exception_oop);
aoqi@0 829
aoqi@0 830 // get throwing pc (= return address).
aoqi@0 831 // rdx has been destroyed by the call, so it must be set again
aoqi@0 832 // the pop is also necessary to simulate the effect of a ret(0)
aoqi@0 833 __ pop(exception_pc);
aoqi@0 834
aoqi@0 835 // Restore SP from BP if the exception PC is a method handle call site.
aoqi@0 836 NOT_LP64(__ get_thread(thread);)
aoqi@0 837 __ cmpl(Address(thread, JavaThread::is_method_handle_return_offset()), 0);
aoqi@0 838 __ cmovptr(Assembler::notEqual, rsp, rbp_mh_SP_save);
aoqi@0 839
aoqi@0 840 // continue at exception handler (return address removed)
aoqi@0 841 // note: do *not* remove arguments when unwinding the
aoqi@0 842 // activation since the caller assumes having
aoqi@0 843 // all arguments on the stack when entering the
aoqi@0 844 // runtime to determine the exception handler
aoqi@0 845 // (GC happens at call site with arguments!)
aoqi@0 846 // rax: exception oop
aoqi@0 847 // rdx: throwing pc
aoqi@0 848 // rbx: exception handler
aoqi@0 849 __ jmp(handler_addr);
aoqi@0 850 }
aoqi@0 851
aoqi@0 852
aoqi@0 853 OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {
aoqi@0 854 // use the maximum number of runtime-arguments here because it is difficult to
aoqi@0 855 // distinguish each RT-Call.
aoqi@0 856 // Note: This number affects also the RT-Call in generate_handle_exception because
aoqi@0 857 // the oop-map is shared for all calls.
aoqi@0 858 const int num_rt_args = 2; // thread + dummy
aoqi@0 859
aoqi@0 860 DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
aoqi@0 861 assert(deopt_blob != NULL, "deoptimization blob must have been created");
aoqi@0 862
aoqi@0 863 OopMap* oop_map = save_live_registers(sasm, num_rt_args);
aoqi@0 864
aoqi@0 865 #ifdef _LP64
aoqi@0 866 const Register thread = r15_thread;
aoqi@0 867 // No need to worry about dummy
aoqi@0 868 __ mov(c_rarg0, thread);
aoqi@0 869 #else
aoqi@0 870 __ push(rax); // push dummy
aoqi@0 871
aoqi@0 872 const Register thread = rdi; // is callee-saved register (Visual C++ calling conventions)
aoqi@0 873 // push java thread (becomes first argument of C function)
aoqi@0 874 __ get_thread(thread);
aoqi@0 875 __ push(thread);
aoqi@0 876 #endif // _LP64
aoqi@0 877 __ set_last_Java_frame(thread, noreg, rbp, NULL);
aoqi@0 878 // do the call
aoqi@0 879 __ call(RuntimeAddress(target));
aoqi@0 880 OopMapSet* oop_maps = new OopMapSet();
aoqi@0 881 oop_maps->add_gc_map(__ offset(), oop_map);
aoqi@0 882 // verify callee-saved register
aoqi@0 883 #ifdef ASSERT
aoqi@0 884 guarantee(thread != rax, "change this code");
aoqi@0 885 __ push(rax);
aoqi@0 886 { Label L;
aoqi@0 887 __ get_thread(rax);
aoqi@0 888 __ cmpptr(thread, rax);
aoqi@0 889 __ jcc(Assembler::equal, L);
aoqi@0 890 __ stop("StubAssembler::call_RT: rdi/r15 not callee saved?");
aoqi@0 891 __ bind(L);
aoqi@0 892 }
aoqi@0 893 __ pop(rax);
aoqi@0 894 #endif
aoqi@0 895 __ reset_last_Java_frame(thread, true, false);
aoqi@0 896 #ifndef _LP64
aoqi@0 897 __ pop(rcx); // discard thread arg
aoqi@0 898 __ pop(rcx); // discard dummy
aoqi@0 899 #endif // _LP64
aoqi@0 900
aoqi@0 901 // check for pending exceptions
aoqi@0 902 { Label L;
aoqi@0 903 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 904 __ jcc(Assembler::equal, L);
aoqi@0 905 // exception pending => remove activation and forward to exception handler
aoqi@0 906
aoqi@0 907 __ testptr(rax, rax); // have we deoptimized?
aoqi@0 908 __ jump_cc(Assembler::equal,
aoqi@0 909 RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));
aoqi@0 910
aoqi@0 911 // the deopt blob expects exceptions in the special fields of
aoqi@0 912 // JavaThread, so copy and clear pending exception.
aoqi@0 913
aoqi@0 914 // load and clear pending exception
aoqi@0 915 __ movptr(rax, Address(thread, Thread::pending_exception_offset()));
aoqi@0 916 __ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
aoqi@0 917
aoqi@0 918 // check that there is really a valid exception
aoqi@0 919 __ verify_not_null_oop(rax);
aoqi@0 920
aoqi@0 921 // load throwing pc: this is the return address of the stub
aoqi@0 922 __ movptr(rdx, Address(rsp, return_off * VMRegImpl::stack_slot_size));
aoqi@0 923
aoqi@0 924 #ifdef ASSERT
aoqi@0 925 // check that fields in JavaThread for exception oop and issuing pc are empty
aoqi@0 926 Label oop_empty;
aoqi@0 927 __ cmpptr(Address(thread, JavaThread::exception_oop_offset()), (int32_t)NULL_WORD);
aoqi@0 928 __ jcc(Assembler::equal, oop_empty);
aoqi@0 929 __ stop("exception oop must be empty");
aoqi@0 930 __ bind(oop_empty);
aoqi@0 931
aoqi@0 932 Label pc_empty;
aoqi@0 933 __ cmpptr(Address(thread, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);
aoqi@0 934 __ jcc(Assembler::equal, pc_empty);
aoqi@0 935 __ stop("exception pc must be empty");
aoqi@0 936 __ bind(pc_empty);
aoqi@0 937 #endif
aoqi@0 938
aoqi@0 939 // store exception oop and throwing pc to JavaThread
aoqi@0 940 __ movptr(Address(thread, JavaThread::exception_oop_offset()), rax);
aoqi@0 941 __ movptr(Address(thread, JavaThread::exception_pc_offset()), rdx);
aoqi@0 942
aoqi@0 943 restore_live_registers(sasm);
aoqi@0 944
aoqi@0 945 __ leave();
aoqi@0 946 __ addptr(rsp, BytesPerWord); // remove return address from stack
aoqi@0 947
aoqi@0 948 // Forward the exception directly to deopt blob. We can blow no
aoqi@0 949 // registers and must leave throwing pc on the stack. A patch may
aoqi@0 950 // have values live in registers so the entry point with the
aoqi@0 951 // exception in tls.
aoqi@0 952 __ jump(RuntimeAddress(deopt_blob->unpack_with_exception_in_tls()));
aoqi@0 953
aoqi@0 954 __ bind(L);
aoqi@0 955 }
aoqi@0 956
aoqi@0 957
aoqi@0 958 // Runtime will return true if the nmethod has been deoptimized during
aoqi@0 959 // the patching process. In that case we must do a deopt reexecute instead.
aoqi@0 960
aoqi@0 961 Label reexecuteEntry, cont;
aoqi@0 962
aoqi@0 963 __ testptr(rax, rax); // have we deoptimized?
aoqi@0 964 __ jcc(Assembler::equal, cont); // no
aoqi@0 965
aoqi@0 966 // Will reexecute. Proper return address is already on the stack we just restore
aoqi@0 967 // registers, pop all of our frame but the return address and jump to the deopt blob
aoqi@0 968 restore_live_registers(sasm);
aoqi@0 969 __ leave();
aoqi@0 970 __ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
aoqi@0 971
aoqi@0 972 __ bind(cont);
aoqi@0 973 restore_live_registers(sasm);
aoqi@0 974 __ leave();
aoqi@0 975 __ ret(0);
aoqi@0 976
aoqi@0 977 return oop_maps;
aoqi@0 978 }
aoqi@0 979
aoqi@0 980
aoqi@0 981 OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
aoqi@0 982
aoqi@0 983 // for better readability
aoqi@0 984 const bool must_gc_arguments = true;
aoqi@0 985 const bool dont_gc_arguments = false;
aoqi@0 986
aoqi@0 987 // default value; overwritten for some optimized stubs that are called from methods that do not use the fpu
aoqi@0 988 bool save_fpu_registers = true;
aoqi@0 989
aoqi@0 990 // stub code & info for the different stubs
aoqi@0 991 OopMapSet* oop_maps = NULL;
aoqi@0 992 switch (id) {
aoqi@0 993 case forward_exception_id:
aoqi@0 994 {
aoqi@0 995 oop_maps = generate_handle_exception(id, sasm);
aoqi@0 996 __ leave();
aoqi@0 997 __ ret(0);
aoqi@0 998 }
aoqi@0 999 break;
aoqi@0 1000
aoqi@0 1001 case new_instance_id:
aoqi@0 1002 case fast_new_instance_id:
aoqi@0 1003 case fast_new_instance_init_check_id:
aoqi@0 1004 {
aoqi@0 1005 Register klass = rdx; // Incoming
aoqi@0 1006 Register obj = rax; // Result
aoqi@0 1007
aoqi@0 1008 if (id == new_instance_id) {
aoqi@0 1009 __ set_info("new_instance", dont_gc_arguments);
aoqi@0 1010 } else if (id == fast_new_instance_id) {
aoqi@0 1011 __ set_info("fast new_instance", dont_gc_arguments);
aoqi@0 1012 } else {
aoqi@0 1013 assert(id == fast_new_instance_init_check_id, "bad StubID");
aoqi@0 1014 __ set_info("fast new_instance init check", dont_gc_arguments);
aoqi@0 1015 }
aoqi@0 1016
aoqi@0 1017 if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) &&
aoqi@0 1018 UseTLAB && FastTLABRefill) {
aoqi@0 1019 Label slow_path;
aoqi@0 1020 Register obj_size = rcx;
aoqi@0 1021 Register t1 = rbx;
aoqi@0 1022 Register t2 = rsi;
aoqi@0 1023 assert_different_registers(klass, obj, obj_size, t1, t2);
aoqi@0 1024
aoqi@0 1025 __ push(rdi);
aoqi@0 1026 __ push(rbx);
aoqi@0 1027
aoqi@0 1028 if (id == fast_new_instance_init_check_id) {
aoqi@0 1029 // make sure the klass is initialized
aoqi@0 1030 __ cmpb(Address(klass, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
aoqi@0 1031 __ jcc(Assembler::notEqual, slow_path);
aoqi@0 1032 }
aoqi@0 1033
aoqi@0 1034 #ifdef ASSERT
aoqi@0 1035 // assert object can be fast path allocated
aoqi@0 1036 {
aoqi@0 1037 Label ok, not_ok;
aoqi@0 1038 __ movl(obj_size, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1039 __ cmpl(obj_size, 0); // make sure it's an instance (LH > 0)
aoqi@0 1040 __ jcc(Assembler::lessEqual, not_ok);
aoqi@0 1041 __ testl(obj_size, Klass::_lh_instance_slow_path_bit);
aoqi@0 1042 __ jcc(Assembler::zero, ok);
aoqi@0 1043 __ bind(not_ok);
aoqi@0 1044 __ stop("assert(can be fast path allocated)");
aoqi@0 1045 __ should_not_reach_here();
aoqi@0 1046 __ bind(ok);
aoqi@0 1047 }
aoqi@0 1048 #endif // ASSERT
aoqi@0 1049
aoqi@0 1050 // if we got here then the TLAB allocation failed, so try
aoqi@0 1051 // refilling the TLAB or allocating directly from eden.
aoqi@0 1052 Label retry_tlab, try_eden;
aoqi@0 1053 const Register thread =
aoqi@0 1054 __ tlab_refill(retry_tlab, try_eden, slow_path); // does not destroy rdx (klass), returns rdi
aoqi@0 1055
aoqi@0 1056 __ bind(retry_tlab);
aoqi@0 1057
aoqi@0 1058 // get the instance size (size is postive so movl is fine for 64bit)
aoqi@0 1059 __ movl(obj_size, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1060
aoqi@0 1061 __ tlab_allocate(obj, obj_size, 0, t1, t2, slow_path);
aoqi@0 1062
aoqi@0 1063 __ initialize_object(obj, klass, obj_size, 0, t1, t2);
aoqi@0 1064 __ verify_oop(obj);
aoqi@0 1065 __ pop(rbx);
aoqi@0 1066 __ pop(rdi);
aoqi@0 1067 __ ret(0);
aoqi@0 1068
aoqi@0 1069 __ bind(try_eden);
aoqi@0 1070 // get the instance size (size is postive so movl is fine for 64bit)
aoqi@0 1071 __ movl(obj_size, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1072
aoqi@0 1073 __ eden_allocate(obj, obj_size, 0, t1, slow_path);
aoqi@0 1074 __ incr_allocated_bytes(thread, obj_size, 0);
aoqi@0 1075
aoqi@0 1076 __ initialize_object(obj, klass, obj_size, 0, t1, t2);
aoqi@0 1077 __ verify_oop(obj);
aoqi@0 1078 __ pop(rbx);
aoqi@0 1079 __ pop(rdi);
aoqi@0 1080 __ ret(0);
aoqi@0 1081
aoqi@0 1082 __ bind(slow_path);
aoqi@0 1083 __ pop(rbx);
aoqi@0 1084 __ pop(rdi);
aoqi@0 1085 }
aoqi@0 1086
aoqi@0 1087 __ enter();
aoqi@0 1088 OopMap* map = save_live_registers(sasm, 2);
aoqi@0 1089 int call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_instance), klass);
aoqi@0 1090 oop_maps = new OopMapSet();
aoqi@0 1091 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1092 restore_live_registers_except_rax(sasm);
aoqi@0 1093 __ verify_oop(obj);
aoqi@0 1094 __ leave();
aoqi@0 1095 __ ret(0);
aoqi@0 1096
aoqi@0 1097 // rax,: new instance
aoqi@0 1098 }
aoqi@0 1099
aoqi@0 1100 break;
aoqi@0 1101
aoqi@0 1102 case counter_overflow_id:
aoqi@0 1103 {
aoqi@0 1104 Register bci = rax, method = rbx;
aoqi@0 1105 __ enter();
aoqi@0 1106 OopMap* map = save_live_registers(sasm, 3);
aoqi@0 1107 // Retrieve bci
aoqi@0 1108 __ movl(bci, Address(rbp, 2*BytesPerWord));
aoqi@0 1109 // And a pointer to the Method*
aoqi@0 1110 __ movptr(method, Address(rbp, 3*BytesPerWord));
aoqi@0 1111 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, counter_overflow), bci, method);
aoqi@0 1112 oop_maps = new OopMapSet();
aoqi@0 1113 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1114 restore_live_registers(sasm);
aoqi@0 1115 __ leave();
aoqi@0 1116 __ ret(0);
aoqi@0 1117 }
aoqi@0 1118 break;
aoqi@0 1119
aoqi@0 1120 case new_type_array_id:
aoqi@0 1121 case new_object_array_id:
aoqi@0 1122 {
aoqi@0 1123 Register length = rbx; // Incoming
aoqi@0 1124 Register klass = rdx; // Incoming
aoqi@0 1125 Register obj = rax; // Result
aoqi@0 1126
aoqi@0 1127 if (id == new_type_array_id) {
aoqi@0 1128 __ set_info("new_type_array", dont_gc_arguments);
aoqi@0 1129 } else {
aoqi@0 1130 __ set_info("new_object_array", dont_gc_arguments);
aoqi@0 1131 }
aoqi@0 1132
aoqi@0 1133 #ifdef ASSERT
aoqi@0 1134 // assert object type is really an array of the proper kind
aoqi@0 1135 {
aoqi@0 1136 Label ok;
aoqi@0 1137 Register t0 = obj;
aoqi@0 1138 __ movl(t0, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1139 __ sarl(t0, Klass::_lh_array_tag_shift);
aoqi@0 1140 int tag = ((id == new_type_array_id)
aoqi@0 1141 ? Klass::_lh_array_tag_type_value
aoqi@0 1142 : Klass::_lh_array_tag_obj_value);
aoqi@0 1143 __ cmpl(t0, tag);
aoqi@0 1144 __ jcc(Assembler::equal, ok);
aoqi@0 1145 __ stop("assert(is an array klass)");
aoqi@0 1146 __ should_not_reach_here();
aoqi@0 1147 __ bind(ok);
aoqi@0 1148 }
aoqi@0 1149 #endif // ASSERT
aoqi@0 1150
aoqi@0 1151 if (UseTLAB && FastTLABRefill) {
aoqi@0 1152 Register arr_size = rsi;
aoqi@0 1153 Register t1 = rcx; // must be rcx for use as shift count
aoqi@0 1154 Register t2 = rdi;
aoqi@0 1155 Label slow_path;
aoqi@0 1156 assert_different_registers(length, klass, obj, arr_size, t1, t2);
aoqi@0 1157
aoqi@0 1158 // check that array length is small enough for fast path.
aoqi@0 1159 __ cmpl(length, C1_MacroAssembler::max_array_allocation_length);
aoqi@0 1160 __ jcc(Assembler::above, slow_path);
aoqi@0 1161
aoqi@0 1162 // if we got here then the TLAB allocation failed, so try
aoqi@0 1163 // refilling the TLAB or allocating directly from eden.
aoqi@0 1164 Label retry_tlab, try_eden;
aoqi@0 1165 const Register thread =
aoqi@0 1166 __ tlab_refill(retry_tlab, try_eden, slow_path); // preserves rbx & rdx, returns rdi
aoqi@0 1167
aoqi@0 1168 __ bind(retry_tlab);
aoqi@0 1169
aoqi@0 1170 // get the allocation size: round_up(hdr + length << (layout_helper & 0x1F))
aoqi@0 1171 // since size is positive movl does right thing on 64bit
aoqi@0 1172 __ movl(t1, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1173 // since size is postive movl does right thing on 64bit
aoqi@0 1174 __ movl(arr_size, length);
aoqi@0 1175 assert(t1 == rcx, "fixed register usage");
aoqi@0 1176 __ shlptr(arr_size /* by t1=rcx, mod 32 */);
aoqi@0 1177 __ shrptr(t1, Klass::_lh_header_size_shift);
aoqi@0 1178 __ andptr(t1, Klass::_lh_header_size_mask);
aoqi@0 1179 __ addptr(arr_size, t1);
aoqi@0 1180 __ addptr(arr_size, MinObjAlignmentInBytesMask); // align up
aoqi@0 1181 __ andptr(arr_size, ~MinObjAlignmentInBytesMask);
aoqi@0 1182
aoqi@0 1183 __ tlab_allocate(obj, arr_size, 0, t1, t2, slow_path); // preserves arr_size
aoqi@0 1184
aoqi@0 1185 __ initialize_header(obj, klass, length, t1, t2);
aoqi@0 1186 __ movb(t1, Address(klass, in_bytes(Klass::layout_helper_offset()) + (Klass::_lh_header_size_shift / BitsPerByte)));
aoqi@0 1187 assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");
aoqi@0 1188 assert(Klass::_lh_header_size_mask <= 0xFF, "bytewise");
aoqi@0 1189 __ andptr(t1, Klass::_lh_header_size_mask);
aoqi@0 1190 __ subptr(arr_size, t1); // body length
aoqi@0 1191 __ addptr(t1, obj); // body start
aoqi@0 1192 __ initialize_body(t1, arr_size, 0, t2);
aoqi@0 1193 __ verify_oop(obj);
aoqi@0 1194 __ ret(0);
aoqi@0 1195
aoqi@0 1196 __ bind(try_eden);
aoqi@0 1197 // get the allocation size: round_up(hdr + length << (layout_helper & 0x1F))
aoqi@0 1198 // since size is positive movl does right thing on 64bit
aoqi@0 1199 __ movl(t1, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1200 // since size is postive movl does right thing on 64bit
aoqi@0 1201 __ movl(arr_size, length);
aoqi@0 1202 assert(t1 == rcx, "fixed register usage");
aoqi@0 1203 __ shlptr(arr_size /* by t1=rcx, mod 32 */);
aoqi@0 1204 __ shrptr(t1, Klass::_lh_header_size_shift);
aoqi@0 1205 __ andptr(t1, Klass::_lh_header_size_mask);
aoqi@0 1206 __ addptr(arr_size, t1);
aoqi@0 1207 __ addptr(arr_size, MinObjAlignmentInBytesMask); // align up
aoqi@0 1208 __ andptr(arr_size, ~MinObjAlignmentInBytesMask);
aoqi@0 1209
aoqi@0 1210 __ eden_allocate(obj, arr_size, 0, t1, slow_path); // preserves arr_size
aoqi@0 1211 __ incr_allocated_bytes(thread, arr_size, 0);
aoqi@0 1212
aoqi@0 1213 __ initialize_header(obj, klass, length, t1, t2);
aoqi@0 1214 __ movb(t1, Address(klass, in_bytes(Klass::layout_helper_offset()) + (Klass::_lh_header_size_shift / BitsPerByte)));
aoqi@0 1215 assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");
aoqi@0 1216 assert(Klass::_lh_header_size_mask <= 0xFF, "bytewise");
aoqi@0 1217 __ andptr(t1, Klass::_lh_header_size_mask);
aoqi@0 1218 __ subptr(arr_size, t1); // body length
aoqi@0 1219 __ addptr(t1, obj); // body start
aoqi@0 1220 __ initialize_body(t1, arr_size, 0, t2);
aoqi@0 1221 __ verify_oop(obj);
aoqi@0 1222 __ ret(0);
aoqi@0 1223
aoqi@0 1224 __ bind(slow_path);
aoqi@0 1225 }
aoqi@0 1226
aoqi@0 1227 __ enter();
aoqi@0 1228 OopMap* map = save_live_registers(sasm, 3);
aoqi@0 1229 int call_offset;
aoqi@0 1230 if (id == new_type_array_id) {
aoqi@0 1231 call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_type_array), klass, length);
aoqi@0 1232 } else {
aoqi@0 1233 call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_object_array), klass, length);
aoqi@0 1234 }
aoqi@0 1235
aoqi@0 1236 oop_maps = new OopMapSet();
aoqi@0 1237 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1238 restore_live_registers_except_rax(sasm);
aoqi@0 1239
aoqi@0 1240 __ verify_oop(obj);
aoqi@0 1241 __ leave();
aoqi@0 1242 __ ret(0);
aoqi@0 1243
aoqi@0 1244 // rax,: new array
aoqi@0 1245 }
aoqi@0 1246 break;
aoqi@0 1247
aoqi@0 1248 case new_multi_array_id:
aoqi@0 1249 { StubFrame f(sasm, "new_multi_array", dont_gc_arguments);
aoqi@0 1250 // rax,: klass
aoqi@0 1251 // rbx,: rank
aoqi@0 1252 // rcx: address of 1st dimension
aoqi@0 1253 OopMap* map = save_live_registers(sasm, 4);
aoqi@0 1254 int call_offset = __ call_RT(rax, noreg, CAST_FROM_FN_PTR(address, new_multi_array), rax, rbx, rcx);
aoqi@0 1255
aoqi@0 1256 oop_maps = new OopMapSet();
aoqi@0 1257 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1258 restore_live_registers_except_rax(sasm);
aoqi@0 1259
aoqi@0 1260 // rax,: new multi array
aoqi@0 1261 __ verify_oop(rax);
aoqi@0 1262 }
aoqi@0 1263 break;
aoqi@0 1264
aoqi@0 1265 case register_finalizer_id:
aoqi@0 1266 {
aoqi@0 1267 __ set_info("register_finalizer", dont_gc_arguments);
aoqi@0 1268
aoqi@0 1269 // This is called via call_runtime so the arguments
aoqi@0 1270 // will be place in C abi locations
aoqi@0 1271
aoqi@0 1272 #ifdef _LP64
aoqi@0 1273 __ verify_oop(c_rarg0);
aoqi@0 1274 __ mov(rax, c_rarg0);
aoqi@0 1275 #else
aoqi@0 1276 // The object is passed on the stack and we haven't pushed a
aoqi@0 1277 // frame yet so it's one work away from top of stack.
aoqi@0 1278 __ movptr(rax, Address(rsp, 1 * BytesPerWord));
aoqi@0 1279 __ verify_oop(rax);
aoqi@0 1280 #endif // _LP64
aoqi@0 1281
aoqi@0 1282 // load the klass and check the has finalizer flag
aoqi@0 1283 Label register_finalizer;
aoqi@0 1284 Register t = rsi;
aoqi@0 1285 __ load_klass(t, rax);
aoqi@0 1286 __ movl(t, Address(t, Klass::access_flags_offset()));
aoqi@0 1287 __ testl(t, JVM_ACC_HAS_FINALIZER);
aoqi@0 1288 __ jcc(Assembler::notZero, register_finalizer);
aoqi@0 1289 __ ret(0);
aoqi@0 1290
aoqi@0 1291 __ bind(register_finalizer);
aoqi@0 1292 __ enter();
aoqi@0 1293 OopMap* oop_map = save_live_registers(sasm, 2 /*num_rt_args */);
aoqi@0 1294 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), rax);
aoqi@0 1295 oop_maps = new OopMapSet();
aoqi@0 1296 oop_maps->add_gc_map(call_offset, oop_map);
aoqi@0 1297
aoqi@0 1298 // Now restore all the live registers
aoqi@0 1299 restore_live_registers(sasm);
aoqi@0 1300
aoqi@0 1301 __ leave();
aoqi@0 1302 __ ret(0);
aoqi@0 1303 }
aoqi@0 1304 break;
aoqi@0 1305
aoqi@0 1306 case throw_range_check_failed_id:
aoqi@0 1307 { StubFrame f(sasm, "range_check_failed", dont_gc_arguments);
aoqi@0 1308 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);
aoqi@0 1309 }
aoqi@0 1310 break;
aoqi@0 1311
aoqi@0 1312 case throw_index_exception_id:
aoqi@0 1313 { StubFrame f(sasm, "index_range_check_failed", dont_gc_arguments);
aoqi@0 1314 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);
aoqi@0 1315 }
aoqi@0 1316 break;
aoqi@0 1317
aoqi@0 1318 case throw_div0_exception_id:
aoqi@0 1319 { StubFrame f(sasm, "throw_div0_exception", dont_gc_arguments);
aoqi@0 1320 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);
aoqi@0 1321 }
aoqi@0 1322 break;
aoqi@0 1323
aoqi@0 1324 case throw_null_pointer_exception_id:
aoqi@0 1325 { StubFrame f(sasm, "throw_null_pointer_exception", dont_gc_arguments);
aoqi@0 1326 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);
aoqi@0 1327 }
aoqi@0 1328 break;
aoqi@0 1329
aoqi@0 1330 case handle_exception_nofpu_id:
aoqi@0 1331 case handle_exception_id:
aoqi@0 1332 { StubFrame f(sasm, "handle_exception", dont_gc_arguments);
aoqi@0 1333 oop_maps = generate_handle_exception(id, sasm);
aoqi@0 1334 }
aoqi@0 1335 break;
aoqi@0 1336
aoqi@0 1337 case handle_exception_from_callee_id:
aoqi@0 1338 { StubFrame f(sasm, "handle_exception_from_callee", dont_gc_arguments);
aoqi@0 1339 oop_maps = generate_handle_exception(id, sasm);
aoqi@0 1340 }
aoqi@0 1341 break;
aoqi@0 1342
aoqi@0 1343 case unwind_exception_id:
aoqi@0 1344 { __ set_info("unwind_exception", dont_gc_arguments);
aoqi@0 1345 // note: no stubframe since we are about to leave the current
aoqi@0 1346 // activation and we are calling a leaf VM function only.
aoqi@0 1347 generate_unwind_exception(sasm);
aoqi@0 1348 }
aoqi@0 1349 break;
aoqi@0 1350
aoqi@0 1351 case throw_array_store_exception_id:
aoqi@0 1352 { StubFrame f(sasm, "throw_array_store_exception", dont_gc_arguments);
aoqi@0 1353 // tos + 0: link
aoqi@0 1354 // + 1: return address
aoqi@0 1355 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), true);
aoqi@0 1356 }
aoqi@0 1357 break;
aoqi@0 1358
aoqi@0 1359 case throw_class_cast_exception_id:
aoqi@0 1360 { StubFrame f(sasm, "throw_class_cast_exception", dont_gc_arguments);
aoqi@0 1361 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);
aoqi@0 1362 }
aoqi@0 1363 break;
aoqi@0 1364
aoqi@0 1365 case throw_incompatible_class_change_error_id:
aoqi@0 1366 { StubFrame f(sasm, "throw_incompatible_class_cast_exception", dont_gc_arguments);
aoqi@0 1367 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);
aoqi@0 1368 }
aoqi@0 1369 break;
aoqi@0 1370
aoqi@0 1371 case slow_subtype_check_id:
aoqi@0 1372 {
aoqi@0 1373 // Typical calling sequence:
aoqi@0 1374 // __ push(klass_RInfo); // object klass or other subclass
aoqi@0 1375 // __ push(sup_k_RInfo); // array element klass or other superclass
aoqi@0 1376 // __ call(slow_subtype_check);
aoqi@0 1377 // Note that the subclass is pushed first, and is therefore deepest.
aoqi@0 1378 // Previous versions of this code reversed the names 'sub' and 'super'.
aoqi@0 1379 // This was operationally harmless but made the code unreadable.
aoqi@0 1380 enum layout {
aoqi@0 1381 rax_off, SLOT2(raxH_off)
aoqi@0 1382 rcx_off, SLOT2(rcxH_off)
aoqi@0 1383 rsi_off, SLOT2(rsiH_off)
aoqi@0 1384 rdi_off, SLOT2(rdiH_off)
aoqi@0 1385 // saved_rbp_off, SLOT2(saved_rbpH_off)
aoqi@0 1386 return_off, SLOT2(returnH_off)
aoqi@0 1387 sup_k_off, SLOT2(sup_kH_off)
aoqi@0 1388 klass_off, SLOT2(superH_off)
aoqi@0 1389 framesize,
aoqi@0 1390 result_off = klass_off // deepest argument is also the return value
aoqi@0 1391 };
aoqi@0 1392
aoqi@0 1393 __ set_info("slow_subtype_check", dont_gc_arguments);
aoqi@0 1394 __ push(rdi);
aoqi@0 1395 __ push(rsi);
aoqi@0 1396 __ push(rcx);
aoqi@0 1397 __ push(rax);
aoqi@0 1398
aoqi@0 1399 // This is called by pushing args and not with C abi
aoqi@0 1400 __ movptr(rsi, Address(rsp, (klass_off) * VMRegImpl::stack_slot_size)); // subclass
aoqi@0 1401 __ movptr(rax, Address(rsp, (sup_k_off) * VMRegImpl::stack_slot_size)); // superclass
aoqi@0 1402
aoqi@0 1403 Label miss;
aoqi@0 1404 __ check_klass_subtype_slow_path(rsi, rax, rcx, rdi, NULL, &miss);
aoqi@0 1405
aoqi@0 1406 // fallthrough on success:
aoqi@0 1407 __ movptr(Address(rsp, (result_off) * VMRegImpl::stack_slot_size), 1); // result
aoqi@0 1408 __ pop(rax);
aoqi@0 1409 __ pop(rcx);
aoqi@0 1410 __ pop(rsi);
aoqi@0 1411 __ pop(rdi);
aoqi@0 1412 __ ret(0);
aoqi@0 1413
aoqi@0 1414 __ bind(miss);
aoqi@0 1415 __ movptr(Address(rsp, (result_off) * VMRegImpl::stack_slot_size), NULL_WORD); // result
aoqi@0 1416 __ pop(rax);
aoqi@0 1417 __ pop(rcx);
aoqi@0 1418 __ pop(rsi);
aoqi@0 1419 __ pop(rdi);
aoqi@0 1420 __ ret(0);
aoqi@0 1421 }
aoqi@0 1422 break;
aoqi@0 1423
aoqi@0 1424 case monitorenter_nofpu_id:
aoqi@0 1425 save_fpu_registers = false;
aoqi@0 1426 // fall through
aoqi@0 1427 case monitorenter_id:
aoqi@0 1428 {
aoqi@0 1429 StubFrame f(sasm, "monitorenter", dont_gc_arguments);
aoqi@0 1430 OopMap* map = save_live_registers(sasm, 3, save_fpu_registers);
aoqi@0 1431
aoqi@0 1432 // Called with store_parameter and not C abi
aoqi@0 1433
aoqi@0 1434 f.load_argument(1, rax); // rax,: object
aoqi@0 1435 f.load_argument(0, rbx); // rbx,: lock address
aoqi@0 1436
aoqi@0 1437 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), rax, rbx);
aoqi@0 1438
aoqi@0 1439 oop_maps = new OopMapSet();
aoqi@0 1440 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1441 restore_live_registers(sasm, save_fpu_registers);
aoqi@0 1442 }
aoqi@0 1443 break;
aoqi@0 1444
aoqi@0 1445 case monitorexit_nofpu_id:
aoqi@0 1446 save_fpu_registers = false;
aoqi@0 1447 // fall through
aoqi@0 1448 case monitorexit_id:
aoqi@0 1449 {
aoqi@0 1450 StubFrame f(sasm, "monitorexit", dont_gc_arguments);
aoqi@0 1451 OopMap* map = save_live_registers(sasm, 2, save_fpu_registers);
aoqi@0 1452
aoqi@0 1453 // Called with store_parameter and not C abi
aoqi@0 1454
aoqi@0 1455 f.load_argument(0, rax); // rax,: lock address
aoqi@0 1456
aoqi@0 1457 // note: really a leaf routine but must setup last java sp
aoqi@0 1458 // => use call_RT for now (speed can be improved by
aoqi@0 1459 // doing last java sp setup manually)
aoqi@0 1460 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), rax);
aoqi@0 1461
aoqi@0 1462 oop_maps = new OopMapSet();
aoqi@0 1463 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1464 restore_live_registers(sasm, save_fpu_registers);
aoqi@0 1465 }
aoqi@0 1466 break;
aoqi@0 1467
aoqi@0 1468 case deoptimize_id:
aoqi@0 1469 {
aoqi@0 1470 StubFrame f(sasm, "deoptimize", dont_gc_arguments);
aoqi@0 1471 const int num_rt_args = 1; // thread
aoqi@0 1472 OopMap* oop_map = save_live_registers(sasm, num_rt_args);
aoqi@0 1473 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize));
aoqi@0 1474 oop_maps = new OopMapSet();
aoqi@0 1475 oop_maps->add_gc_map(call_offset, oop_map);
aoqi@0 1476 restore_live_registers(sasm);
aoqi@0 1477 DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
aoqi@0 1478 assert(deopt_blob != NULL, "deoptimization blob must have been created");
aoqi@0 1479 __ leave();
aoqi@0 1480 __ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
aoqi@0 1481 }
aoqi@0 1482 break;
aoqi@0 1483
aoqi@0 1484 case access_field_patching_id:
aoqi@0 1485 { StubFrame f(sasm, "access_field_patching", dont_gc_arguments);
aoqi@0 1486 // we should set up register map
aoqi@0 1487 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));
aoqi@0 1488 }
aoqi@0 1489 break;
aoqi@0 1490
aoqi@0 1491 case load_klass_patching_id:
aoqi@0 1492 { StubFrame f(sasm, "load_klass_patching", dont_gc_arguments);
aoqi@0 1493 // we should set up register map
aoqi@0 1494 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));
aoqi@0 1495 }
aoqi@0 1496 break;
aoqi@0 1497
aoqi@0 1498 case load_mirror_patching_id:
aoqi@0 1499 { StubFrame f(sasm, "load_mirror_patching", dont_gc_arguments);
aoqi@0 1500 // we should set up register map
aoqi@0 1501 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_mirror_patching));
aoqi@0 1502 }
aoqi@0 1503 break;
aoqi@0 1504
aoqi@0 1505 case load_appendix_patching_id:
aoqi@0 1506 { StubFrame f(sasm, "load_appendix_patching", dont_gc_arguments);
aoqi@0 1507 // we should set up register map
aoqi@0 1508 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_appendix_patching));
aoqi@0 1509 }
aoqi@0 1510 break;
aoqi@0 1511
aoqi@0 1512 case dtrace_object_alloc_id:
aoqi@0 1513 { // rax,: object
aoqi@0 1514 StubFrame f(sasm, "dtrace_object_alloc", dont_gc_arguments);
aoqi@0 1515 // we can't gc here so skip the oopmap but make sure that all
aoqi@0 1516 // the live registers get saved.
aoqi@0 1517 save_live_registers(sasm, 1);
aoqi@0 1518
aoqi@0 1519 __ NOT_LP64(push(rax)) LP64_ONLY(mov(c_rarg0, rax));
aoqi@0 1520 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc)));
aoqi@0 1521 NOT_LP64(__ pop(rax));
aoqi@0 1522
aoqi@0 1523 restore_live_registers(sasm);
aoqi@0 1524 }
aoqi@0 1525 break;
aoqi@0 1526
aoqi@0 1527 case fpu2long_stub_id:
aoqi@0 1528 {
aoqi@0 1529 // rax, and rdx are destroyed, but should be free since the result is returned there
aoqi@0 1530 // preserve rsi,ecx
aoqi@0 1531 __ push(rsi);
aoqi@0 1532 __ push(rcx);
aoqi@0 1533 LP64_ONLY(__ push(rdx);)
aoqi@0 1534
aoqi@0 1535 // check for NaN
aoqi@0 1536 Label return0, do_return, return_min_jlong, do_convert;
aoqi@0 1537
aoqi@0 1538 Address value_high_word(rsp, wordSize + 4);
aoqi@0 1539 Address value_low_word(rsp, wordSize);
aoqi@0 1540 Address result_high_word(rsp, 3*wordSize + 4);
aoqi@0 1541 Address result_low_word(rsp, 3*wordSize);
aoqi@0 1542
aoqi@0 1543 __ subptr(rsp, 32); // more than enough on 32bit
aoqi@0 1544 __ fst_d(value_low_word);
aoqi@0 1545 __ movl(rax, value_high_word);
aoqi@0 1546 __ andl(rax, 0x7ff00000);
aoqi@0 1547 __ cmpl(rax, 0x7ff00000);
aoqi@0 1548 __ jcc(Assembler::notEqual, do_convert);
aoqi@0 1549 __ movl(rax, value_high_word);
aoqi@0 1550 __ andl(rax, 0xfffff);
aoqi@0 1551 __ orl(rax, value_low_word);
aoqi@0 1552 __ jcc(Assembler::notZero, return0);
aoqi@0 1553
aoqi@0 1554 __ bind(do_convert);
aoqi@0 1555 __ fnstcw(Address(rsp, 0));
aoqi@0 1556 __ movzwl(rax, Address(rsp, 0));
aoqi@0 1557 __ orl(rax, 0xc00);
aoqi@0 1558 __ movw(Address(rsp, 2), rax);
aoqi@0 1559 __ fldcw(Address(rsp, 2));
aoqi@0 1560 __ fwait();
aoqi@0 1561 __ fistp_d(result_low_word);
aoqi@0 1562 __ fldcw(Address(rsp, 0));
aoqi@0 1563 __ fwait();
aoqi@0 1564 // This gets the entire long in rax on 64bit
aoqi@0 1565 __ movptr(rax, result_low_word);
aoqi@0 1566 // testing of high bits
aoqi@0 1567 __ movl(rdx, result_high_word);
aoqi@0 1568 __ mov(rcx, rax);
aoqi@0 1569 // What the heck is the point of the next instruction???
aoqi@0 1570 __ xorl(rcx, 0x0);
aoqi@0 1571 __ movl(rsi, 0x80000000);
aoqi@0 1572 __ xorl(rsi, rdx);
aoqi@0 1573 __ orl(rcx, rsi);
aoqi@0 1574 __ jcc(Assembler::notEqual, do_return);
aoqi@0 1575 __ fldz();
aoqi@0 1576 __ fcomp_d(value_low_word);
aoqi@0 1577 __ fnstsw_ax();
aoqi@0 1578 #ifdef _LP64
aoqi@0 1579 __ testl(rax, 0x4100); // ZF & CF == 0
aoqi@0 1580 __ jcc(Assembler::equal, return_min_jlong);
aoqi@0 1581 #else
aoqi@0 1582 __ sahf();
aoqi@0 1583 __ jcc(Assembler::above, return_min_jlong);
aoqi@0 1584 #endif // _LP64
aoqi@0 1585 // return max_jlong
aoqi@0 1586 #ifndef _LP64
aoqi@0 1587 __ movl(rdx, 0x7fffffff);
aoqi@0 1588 __ movl(rax, 0xffffffff);
aoqi@0 1589 #else
aoqi@0 1590 __ mov64(rax, CONST64(0x7fffffffffffffff));
aoqi@0 1591 #endif // _LP64
aoqi@0 1592 __ jmp(do_return);
aoqi@0 1593
aoqi@0 1594 __ bind(return_min_jlong);
aoqi@0 1595 #ifndef _LP64
aoqi@0 1596 __ movl(rdx, 0x80000000);
aoqi@0 1597 __ xorl(rax, rax);
aoqi@0 1598 #else
aoqi@0 1599 __ mov64(rax, CONST64(0x8000000000000000));
aoqi@0 1600 #endif // _LP64
aoqi@0 1601 __ jmp(do_return);
aoqi@0 1602
aoqi@0 1603 __ bind(return0);
aoqi@0 1604 __ fpop();
aoqi@0 1605 #ifndef _LP64
aoqi@0 1606 __ xorptr(rdx,rdx);
aoqi@0 1607 __ xorptr(rax,rax);
aoqi@0 1608 #else
aoqi@0 1609 __ xorptr(rax, rax);
aoqi@0 1610 #endif // _LP64
aoqi@0 1611
aoqi@0 1612 __ bind(do_return);
aoqi@0 1613 __ addptr(rsp, 32);
aoqi@0 1614 LP64_ONLY(__ pop(rdx);)
aoqi@0 1615 __ pop(rcx);
aoqi@0 1616 __ pop(rsi);
aoqi@0 1617 __ ret(0);
aoqi@0 1618 }
aoqi@0 1619 break;
aoqi@0 1620
aoqi@0 1621 #if INCLUDE_ALL_GCS
aoqi@0 1622 case g1_pre_barrier_slow_id:
aoqi@0 1623 {
aoqi@0 1624 StubFrame f(sasm, "g1_pre_barrier", dont_gc_arguments);
aoqi@0 1625 // arg0 : previous value of memory
aoqi@0 1626
aoqi@0 1627 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@0 1628 if (bs->kind() != BarrierSet::G1SATBCTLogging) {
aoqi@0 1629 __ movptr(rax, (int)id);
aoqi@0 1630 __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), rax);
aoqi@0 1631 __ should_not_reach_here();
aoqi@0 1632 break;
aoqi@0 1633 }
aoqi@0 1634 __ push(rax);
aoqi@0 1635 __ push(rdx);
aoqi@0 1636
aoqi@0 1637 const Register pre_val = rax;
aoqi@0 1638 const Register thread = NOT_LP64(rax) LP64_ONLY(r15_thread);
aoqi@0 1639 const Register tmp = rdx;
aoqi@0 1640
aoqi@0 1641 NOT_LP64(__ get_thread(thread);)
aoqi@0 1642
aoqi@0 1643 Address in_progress(thread, in_bytes(JavaThread::satb_mark_queue_offset() +
aoqi@0 1644 PtrQueue::byte_offset_of_active()));
aoqi@0 1645
aoqi@0 1646 Address queue_index(thread, in_bytes(JavaThread::satb_mark_queue_offset() +
aoqi@0 1647 PtrQueue::byte_offset_of_index()));
aoqi@0 1648 Address buffer(thread, in_bytes(JavaThread::satb_mark_queue_offset() +
aoqi@0 1649 PtrQueue::byte_offset_of_buf()));
aoqi@0 1650
aoqi@0 1651
aoqi@0 1652 Label done;
aoqi@0 1653 Label runtime;
aoqi@0 1654
aoqi@0 1655 // Can we store original value in the thread's buffer?
aoqi@0 1656
aoqi@0 1657 #ifdef _LP64
aoqi@0 1658 __ movslq(tmp, queue_index);
aoqi@0 1659 __ cmpq(tmp, 0);
aoqi@0 1660 #else
aoqi@0 1661 __ cmpl(queue_index, 0);
aoqi@0 1662 #endif
aoqi@0 1663 __ jcc(Assembler::equal, runtime);
aoqi@0 1664 #ifdef _LP64
aoqi@0 1665 __ subq(tmp, wordSize);
aoqi@0 1666 __ movl(queue_index, tmp);
aoqi@0 1667 __ addq(tmp, buffer);
aoqi@0 1668 #else
aoqi@0 1669 __ subl(queue_index, wordSize);
aoqi@0 1670 __ movl(tmp, buffer);
aoqi@0 1671 __ addl(tmp, queue_index);
aoqi@0 1672 #endif
aoqi@0 1673
aoqi@0 1674 // prev_val (rax)
aoqi@0 1675 f.load_argument(0, pre_val);
aoqi@0 1676 __ movptr(Address(tmp, 0), pre_val);
aoqi@0 1677 __ jmp(done);
aoqi@0 1678
aoqi@0 1679 __ bind(runtime);
aoqi@0 1680 __ push(rcx);
aoqi@0 1681 #ifdef _LP64
aoqi@0 1682 __ push(r8);
aoqi@0 1683 __ push(r9);
aoqi@0 1684 __ push(r10);
aoqi@0 1685 __ push(r11);
aoqi@0 1686 # ifndef _WIN64
aoqi@0 1687 __ push(rdi);
aoqi@0 1688 __ push(rsi);
aoqi@0 1689 # endif
aoqi@0 1690 #endif
aoqi@0 1691 // load the pre-value
aoqi@0 1692 f.load_argument(0, rcx);
aoqi@0 1693 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), rcx, thread);
aoqi@0 1694 #ifdef _LP64
aoqi@0 1695 # ifndef _WIN64
aoqi@0 1696 __ pop(rsi);
aoqi@0 1697 __ pop(rdi);
aoqi@0 1698 # endif
aoqi@0 1699 __ pop(r11);
aoqi@0 1700 __ pop(r10);
aoqi@0 1701 __ pop(r9);
aoqi@0 1702 __ pop(r8);
aoqi@0 1703 #endif
aoqi@0 1704 __ pop(rcx);
aoqi@0 1705 __ bind(done);
aoqi@0 1706
aoqi@0 1707 __ pop(rdx);
aoqi@0 1708 __ pop(rax);
aoqi@0 1709 }
aoqi@0 1710 break;
aoqi@0 1711
aoqi@0 1712 case g1_post_barrier_slow_id:
aoqi@0 1713 {
aoqi@0 1714 StubFrame f(sasm, "g1_post_barrier", dont_gc_arguments);
aoqi@0 1715
aoqi@0 1716
aoqi@0 1717 // arg0: store_address
aoqi@0 1718 Address store_addr(rbp, 2*BytesPerWord);
aoqi@0 1719
aoqi@0 1720 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@0 1721 CardTableModRefBS* ct = (CardTableModRefBS*)bs;
aoqi@0 1722 assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
aoqi@0 1723
aoqi@0 1724 Label done;
aoqi@0 1725 Label runtime;
aoqi@0 1726
aoqi@0 1727 // At this point we know new_value is non-NULL and the new_value crosses regions.
aoqi@0 1728 // Must check to see if card is already dirty
aoqi@0 1729
aoqi@0 1730 const Register thread = NOT_LP64(rax) LP64_ONLY(r15_thread);
aoqi@0 1731
aoqi@0 1732 Address queue_index(thread, in_bytes(JavaThread::dirty_card_queue_offset() +
aoqi@0 1733 PtrQueue::byte_offset_of_index()));
aoqi@0 1734 Address buffer(thread, in_bytes(JavaThread::dirty_card_queue_offset() +
aoqi@0 1735 PtrQueue::byte_offset_of_buf()));
aoqi@0 1736
aoqi@0 1737 __ push(rax);
aoqi@0 1738 __ push(rcx);
aoqi@0 1739
aoqi@0 1740 const Register cardtable = rax;
aoqi@0 1741 const Register card_addr = rcx;
aoqi@0 1742
aoqi@0 1743 f.load_argument(0, card_addr);
aoqi@0 1744 __ shrptr(card_addr, CardTableModRefBS::card_shift);
aoqi@0 1745 // Do not use ExternalAddress to load 'byte_map_base', since 'byte_map_base' is NOT
aoqi@0 1746 // a valid address and therefore is not properly handled by the relocation code.
aoqi@0 1747 __ movptr(cardtable, (intptr_t)ct->byte_map_base);
aoqi@0 1748 __ addptr(card_addr, cardtable);
aoqi@0 1749
aoqi@0 1750 NOT_LP64(__ get_thread(thread);)
aoqi@0 1751
aoqi@0 1752 __ cmpb(Address(card_addr, 0), (int)G1SATBCardTableModRefBS::g1_young_card_val());
aoqi@0 1753 __ jcc(Assembler::equal, done);
aoqi@0 1754
aoqi@0 1755 __ membar(Assembler::Membar_mask_bits(Assembler::StoreLoad));
aoqi@0 1756 __ cmpb(Address(card_addr, 0), (int)CardTableModRefBS::dirty_card_val());
aoqi@0 1757 __ jcc(Assembler::equal, done);
aoqi@0 1758
aoqi@0 1759 // storing region crossing non-NULL, card is clean.
aoqi@0 1760 // dirty card and log.
aoqi@0 1761
aoqi@0 1762 __ movb(Address(card_addr, 0), (int)CardTableModRefBS::dirty_card_val());
aoqi@0 1763
aoqi@0 1764 __ cmpl(queue_index, 0);
aoqi@0 1765 __ jcc(Assembler::equal, runtime);
aoqi@0 1766 __ subl(queue_index, wordSize);
aoqi@0 1767
aoqi@0 1768 const Register buffer_addr = rbx;
aoqi@0 1769 __ push(rbx);
aoqi@0 1770
aoqi@0 1771 __ movptr(buffer_addr, buffer);
aoqi@0 1772
aoqi@0 1773 #ifdef _LP64
aoqi@0 1774 __ movslq(rscratch1, queue_index);
aoqi@0 1775 __ addptr(buffer_addr, rscratch1);
aoqi@0 1776 #else
aoqi@0 1777 __ addptr(buffer_addr, queue_index);
aoqi@0 1778 #endif
aoqi@0 1779 __ movptr(Address(buffer_addr, 0), card_addr);
aoqi@0 1780
aoqi@0 1781 __ pop(rbx);
aoqi@0 1782 __ jmp(done);
aoqi@0 1783
aoqi@0 1784 __ bind(runtime);
aoqi@0 1785 __ push(rdx);
aoqi@0 1786 #ifdef _LP64
aoqi@0 1787 __ push(r8);
aoqi@0 1788 __ push(r9);
aoqi@0 1789 __ push(r10);
aoqi@0 1790 __ push(r11);
aoqi@0 1791 # ifndef _WIN64
aoqi@0 1792 __ push(rdi);
aoqi@0 1793 __ push(rsi);
aoqi@0 1794 # endif
aoqi@0 1795 #endif
aoqi@0 1796 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), card_addr, thread);
aoqi@0 1797 #ifdef _LP64
aoqi@0 1798 # ifndef _WIN64
aoqi@0 1799 __ pop(rsi);
aoqi@0 1800 __ pop(rdi);
aoqi@0 1801 # endif
aoqi@0 1802 __ pop(r11);
aoqi@0 1803 __ pop(r10);
aoqi@0 1804 __ pop(r9);
aoqi@0 1805 __ pop(r8);
aoqi@0 1806 #endif
aoqi@0 1807 __ pop(rdx);
aoqi@0 1808 __ bind(done);
aoqi@0 1809
aoqi@0 1810 __ pop(rcx);
aoqi@0 1811 __ pop(rax);
aoqi@0 1812
aoqi@0 1813 }
aoqi@0 1814 break;
aoqi@0 1815 #endif // INCLUDE_ALL_GCS
aoqi@0 1816
aoqi@0 1817 case predicate_failed_trap_id:
aoqi@0 1818 {
aoqi@0 1819 StubFrame f(sasm, "predicate_failed_trap", dont_gc_arguments);
aoqi@0 1820
aoqi@0 1821 OopMap* map = save_live_registers(sasm, 1);
aoqi@0 1822
aoqi@0 1823 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, predicate_failed_trap));
aoqi@0 1824 oop_maps = new OopMapSet();
aoqi@0 1825 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1826 restore_live_registers(sasm);
aoqi@0 1827 __ leave();
aoqi@0 1828 DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
aoqi@0 1829 assert(deopt_blob != NULL, "deoptimization blob must have been created");
aoqi@0 1830
aoqi@0 1831 __ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
aoqi@0 1832 }
aoqi@0 1833 break;
aoqi@0 1834
aoqi@0 1835 default:
aoqi@0 1836 { StubFrame f(sasm, "unimplemented entry", dont_gc_arguments);
aoqi@0 1837 __ movptr(rax, (int)id);
aoqi@0 1838 __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), rax);
aoqi@0 1839 __ should_not_reach_here();
aoqi@0 1840 }
aoqi@0 1841 break;
aoqi@0 1842 }
aoqi@0 1843 return oop_maps;
aoqi@0 1844 }
aoqi@0 1845
aoqi@0 1846 #undef __
aoqi@0 1847
aoqi@0 1848 const char *Runtime1::pd_name_for_address(address entry) {
aoqi@0 1849 return "<unknown function>";
aoqi@0 1850 }

mercurial