src/cpu/x86/vm/c1_Runtime1_x86.cpp

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 10026
8c95980d0b66
parent 9448
73d689add964
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset d3b4d62f391f

aoqi@0 1 /*
mchinnathamb@9290 2 * Copyright (c) 1999, 2018, 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
kevinw@8877 101 reset_last_Java_frame(thread, true);
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
zmajo@7854 757 // Pop the return address.
aoqi@0 758 __ leave();
aoqi@0 759 __ pop(rcx);
aoqi@0 760 __ jmp(rcx); // jump to exception handler
aoqi@0 761 break;
aoqi@0 762 default: ShouldNotReachHere();
aoqi@0 763 }
aoqi@0 764
aoqi@0 765 return oop_maps;
aoqi@0 766 }
aoqi@0 767
aoqi@0 768
aoqi@0 769 void Runtime1::generate_unwind_exception(StubAssembler *sasm) {
aoqi@0 770 // incoming parameters
aoqi@0 771 const Register exception_oop = rax;
aoqi@0 772 // callee-saved copy of exception_oop during runtime call
aoqi@0 773 const Register exception_oop_callee_saved = NOT_LP64(rsi) LP64_ONLY(r14);
aoqi@0 774 // other registers used in this stub
aoqi@0 775 const Register exception_pc = rdx;
aoqi@0 776 const Register handler_addr = rbx;
aoqi@0 777 const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread);
aoqi@0 778
aoqi@0 779 // verify that only rax, is valid at this time
aoqi@0 780 __ invalidate_registers(false, true, true, true, true, true);
aoqi@0 781
aoqi@0 782 #ifdef ASSERT
aoqi@0 783 // check that fields in JavaThread for exception oop and issuing pc are empty
aoqi@0 784 NOT_LP64(__ get_thread(thread);)
aoqi@0 785 Label oop_empty;
aoqi@0 786 __ cmpptr(Address(thread, JavaThread::exception_oop_offset()), 0);
aoqi@0 787 __ jcc(Assembler::equal, oop_empty);
aoqi@0 788 __ stop("exception oop must be empty");
aoqi@0 789 __ bind(oop_empty);
aoqi@0 790
aoqi@0 791 Label pc_empty;
aoqi@0 792 __ cmpptr(Address(thread, JavaThread::exception_pc_offset()), 0);
aoqi@0 793 __ jcc(Assembler::equal, pc_empty);
aoqi@0 794 __ stop("exception pc must be empty");
aoqi@0 795 __ bind(pc_empty);
aoqi@0 796 #endif
aoqi@0 797
aoqi@0 798 // clear the FPU stack in case any FPU results are left behind
aoqi@0 799 __ empty_FPU_stack();
aoqi@0 800
aoqi@0 801 // save exception_oop in callee-saved register to preserve it during runtime calls
aoqi@0 802 __ verify_not_null_oop(exception_oop);
aoqi@0 803 __ movptr(exception_oop_callee_saved, exception_oop);
aoqi@0 804
aoqi@0 805 NOT_LP64(__ get_thread(thread);)
aoqi@0 806 // Get return address (is on top of stack after leave).
aoqi@0 807 __ movptr(exception_pc, Address(rsp, 0));
aoqi@0 808
aoqi@0 809 // search the exception handler address of the caller (using the return address)
aoqi@0 810 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, exception_pc);
aoqi@0 811 // rax: exception handler address of the caller
aoqi@0 812
aoqi@0 813 // Only RAX and RSI are valid at this time, all other registers have been destroyed by the call.
aoqi@0 814 __ invalidate_registers(false, true, true, true, false, true);
aoqi@0 815
aoqi@0 816 // move result of call into correct register
aoqi@0 817 __ movptr(handler_addr, rax);
aoqi@0 818
aoqi@0 819 // Restore exception oop to RAX (required convention of exception handler).
aoqi@0 820 __ movptr(exception_oop, exception_oop_callee_saved);
aoqi@0 821
aoqi@0 822 // verify that there is really a valid exception in rax
aoqi@0 823 __ verify_not_null_oop(exception_oop);
aoqi@0 824
aoqi@0 825 // get throwing pc (= return address).
aoqi@0 826 // rdx has been destroyed by the call, so it must be set again
aoqi@0 827 // the pop is also necessary to simulate the effect of a ret(0)
aoqi@0 828 __ pop(exception_pc);
aoqi@0 829
aoqi@0 830 // continue at exception handler (return address removed)
aoqi@0 831 // note: do *not* remove arguments when unwinding the
aoqi@0 832 // activation since the caller assumes having
aoqi@0 833 // all arguments on the stack when entering the
aoqi@0 834 // runtime to determine the exception handler
aoqi@0 835 // (GC happens at call site with arguments!)
aoqi@0 836 // rax: exception oop
aoqi@0 837 // rdx: throwing pc
aoqi@0 838 // rbx: exception handler
aoqi@0 839 __ jmp(handler_addr);
aoqi@0 840 }
aoqi@0 841
aoqi@0 842
aoqi@0 843 OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {
aoqi@0 844 // use the maximum number of runtime-arguments here because it is difficult to
aoqi@0 845 // distinguish each RT-Call.
aoqi@0 846 // Note: This number affects also the RT-Call in generate_handle_exception because
aoqi@0 847 // the oop-map is shared for all calls.
aoqi@0 848 const int num_rt_args = 2; // thread + dummy
aoqi@0 849
aoqi@0 850 DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
aoqi@0 851 assert(deopt_blob != NULL, "deoptimization blob must have been created");
aoqi@0 852
aoqi@0 853 OopMap* oop_map = save_live_registers(sasm, num_rt_args);
aoqi@0 854
aoqi@0 855 #ifdef _LP64
aoqi@0 856 const Register thread = r15_thread;
aoqi@0 857 // No need to worry about dummy
aoqi@0 858 __ mov(c_rarg0, thread);
aoqi@0 859 #else
aoqi@0 860 __ push(rax); // push dummy
aoqi@0 861
aoqi@0 862 const Register thread = rdi; // is callee-saved register (Visual C++ calling conventions)
aoqi@0 863 // push java thread (becomes first argument of C function)
aoqi@0 864 __ get_thread(thread);
aoqi@0 865 __ push(thread);
aoqi@0 866 #endif // _LP64
aoqi@0 867 __ set_last_Java_frame(thread, noreg, rbp, NULL);
aoqi@0 868 // do the call
aoqi@0 869 __ call(RuntimeAddress(target));
aoqi@0 870 OopMapSet* oop_maps = new OopMapSet();
aoqi@0 871 oop_maps->add_gc_map(__ offset(), oop_map);
aoqi@0 872 // verify callee-saved register
aoqi@0 873 #ifdef ASSERT
aoqi@0 874 guarantee(thread != rax, "change this code");
aoqi@0 875 __ push(rax);
aoqi@0 876 { Label L;
aoqi@0 877 __ get_thread(rax);
aoqi@0 878 __ cmpptr(thread, rax);
aoqi@0 879 __ jcc(Assembler::equal, L);
aoqi@0 880 __ stop("StubAssembler::call_RT: rdi/r15 not callee saved?");
aoqi@0 881 __ bind(L);
aoqi@0 882 }
aoqi@0 883 __ pop(rax);
aoqi@0 884 #endif
kevinw@8877 885 __ reset_last_Java_frame(thread, true);
aoqi@0 886 #ifndef _LP64
aoqi@0 887 __ pop(rcx); // discard thread arg
aoqi@0 888 __ pop(rcx); // discard dummy
aoqi@0 889 #endif // _LP64
aoqi@0 890
aoqi@0 891 // check for pending exceptions
aoqi@0 892 { Label L;
aoqi@0 893 __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
aoqi@0 894 __ jcc(Assembler::equal, L);
aoqi@0 895 // exception pending => remove activation and forward to exception handler
aoqi@0 896
aoqi@0 897 __ testptr(rax, rax); // have we deoptimized?
aoqi@0 898 __ jump_cc(Assembler::equal,
aoqi@0 899 RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));
aoqi@0 900
aoqi@0 901 // the deopt blob expects exceptions in the special fields of
aoqi@0 902 // JavaThread, so copy and clear pending exception.
aoqi@0 903
aoqi@0 904 // load and clear pending exception
aoqi@0 905 __ movptr(rax, Address(thread, Thread::pending_exception_offset()));
aoqi@0 906 __ movptr(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
aoqi@0 907
aoqi@0 908 // check that there is really a valid exception
aoqi@0 909 __ verify_not_null_oop(rax);
aoqi@0 910
aoqi@0 911 // load throwing pc: this is the return address of the stub
aoqi@0 912 __ movptr(rdx, Address(rsp, return_off * VMRegImpl::stack_slot_size));
aoqi@0 913
aoqi@0 914 #ifdef ASSERT
aoqi@0 915 // check that fields in JavaThread for exception oop and issuing pc are empty
aoqi@0 916 Label oop_empty;
aoqi@0 917 __ cmpptr(Address(thread, JavaThread::exception_oop_offset()), (int32_t)NULL_WORD);
aoqi@0 918 __ jcc(Assembler::equal, oop_empty);
aoqi@0 919 __ stop("exception oop must be empty");
aoqi@0 920 __ bind(oop_empty);
aoqi@0 921
aoqi@0 922 Label pc_empty;
aoqi@0 923 __ cmpptr(Address(thread, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);
aoqi@0 924 __ jcc(Assembler::equal, pc_empty);
aoqi@0 925 __ stop("exception pc must be empty");
aoqi@0 926 __ bind(pc_empty);
aoqi@0 927 #endif
aoqi@0 928
aoqi@0 929 // store exception oop and throwing pc to JavaThread
aoqi@0 930 __ movptr(Address(thread, JavaThread::exception_oop_offset()), rax);
aoqi@0 931 __ movptr(Address(thread, JavaThread::exception_pc_offset()), rdx);
aoqi@0 932
aoqi@0 933 restore_live_registers(sasm);
aoqi@0 934
aoqi@0 935 __ leave();
aoqi@0 936 __ addptr(rsp, BytesPerWord); // remove return address from stack
aoqi@0 937
aoqi@0 938 // Forward the exception directly to deopt blob. We can blow no
aoqi@0 939 // registers and must leave throwing pc on the stack. A patch may
aoqi@0 940 // have values live in registers so the entry point with the
aoqi@0 941 // exception in tls.
aoqi@0 942 __ jump(RuntimeAddress(deopt_blob->unpack_with_exception_in_tls()));
aoqi@0 943
aoqi@0 944 __ bind(L);
aoqi@0 945 }
aoqi@0 946
aoqi@0 947
aoqi@0 948 // Runtime will return true if the nmethod has been deoptimized during
aoqi@0 949 // the patching process. In that case we must do a deopt reexecute instead.
aoqi@0 950
aoqi@0 951 Label reexecuteEntry, cont;
aoqi@0 952
aoqi@0 953 __ testptr(rax, rax); // have we deoptimized?
aoqi@0 954 __ jcc(Assembler::equal, cont); // no
aoqi@0 955
aoqi@0 956 // Will reexecute. Proper return address is already on the stack we just restore
aoqi@0 957 // registers, pop all of our frame but the return address and jump to the deopt blob
aoqi@0 958 restore_live_registers(sasm);
aoqi@0 959 __ leave();
aoqi@0 960 __ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
aoqi@0 961
aoqi@0 962 __ bind(cont);
aoqi@0 963 restore_live_registers(sasm);
aoqi@0 964 __ leave();
aoqi@0 965 __ ret(0);
aoqi@0 966
aoqi@0 967 return oop_maps;
aoqi@0 968 }
aoqi@0 969
aoqi@0 970
aoqi@0 971 OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
aoqi@0 972
aoqi@0 973 // for better readability
aoqi@0 974 const bool must_gc_arguments = true;
aoqi@0 975 const bool dont_gc_arguments = false;
aoqi@0 976
aoqi@0 977 // default value; overwritten for some optimized stubs that are called from methods that do not use the fpu
aoqi@0 978 bool save_fpu_registers = true;
aoqi@0 979
aoqi@0 980 // stub code & info for the different stubs
aoqi@0 981 OopMapSet* oop_maps = NULL;
aoqi@0 982 switch (id) {
aoqi@0 983 case forward_exception_id:
aoqi@0 984 {
aoqi@0 985 oop_maps = generate_handle_exception(id, sasm);
aoqi@0 986 __ leave();
aoqi@0 987 __ ret(0);
aoqi@0 988 }
aoqi@0 989 break;
aoqi@0 990
aoqi@0 991 case new_instance_id:
aoqi@0 992 case fast_new_instance_id:
aoqi@0 993 case fast_new_instance_init_check_id:
aoqi@0 994 {
aoqi@0 995 Register klass = rdx; // Incoming
aoqi@0 996 Register obj = rax; // Result
aoqi@0 997
aoqi@0 998 if (id == new_instance_id) {
aoqi@0 999 __ set_info("new_instance", dont_gc_arguments);
aoqi@0 1000 } else if (id == fast_new_instance_id) {
aoqi@0 1001 __ set_info("fast new_instance", dont_gc_arguments);
aoqi@0 1002 } else {
aoqi@0 1003 assert(id == fast_new_instance_init_check_id, "bad StubID");
aoqi@0 1004 __ set_info("fast new_instance init check", dont_gc_arguments);
aoqi@0 1005 }
aoqi@0 1006
aoqi@0 1007 if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) &&
aoqi@0 1008 UseTLAB && FastTLABRefill) {
aoqi@0 1009 Label slow_path;
aoqi@0 1010 Register obj_size = rcx;
aoqi@0 1011 Register t1 = rbx;
aoqi@0 1012 Register t2 = rsi;
aoqi@0 1013 assert_different_registers(klass, obj, obj_size, t1, t2);
aoqi@0 1014
aoqi@0 1015 __ push(rdi);
aoqi@0 1016 __ push(rbx);
aoqi@0 1017
aoqi@0 1018 if (id == fast_new_instance_init_check_id) {
aoqi@0 1019 // make sure the klass is initialized
aoqi@0 1020 __ cmpb(Address(klass, InstanceKlass::init_state_offset()), InstanceKlass::fully_initialized);
aoqi@0 1021 __ jcc(Assembler::notEqual, slow_path);
aoqi@0 1022 }
aoqi@0 1023
aoqi@0 1024 #ifdef ASSERT
aoqi@0 1025 // assert object can be fast path allocated
aoqi@0 1026 {
aoqi@0 1027 Label ok, not_ok;
aoqi@0 1028 __ movl(obj_size, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1029 __ cmpl(obj_size, 0); // make sure it's an instance (LH > 0)
aoqi@0 1030 __ jcc(Assembler::lessEqual, not_ok);
aoqi@0 1031 __ testl(obj_size, Klass::_lh_instance_slow_path_bit);
aoqi@0 1032 __ jcc(Assembler::zero, ok);
aoqi@0 1033 __ bind(not_ok);
aoqi@0 1034 __ stop("assert(can be fast path allocated)");
aoqi@0 1035 __ should_not_reach_here();
aoqi@0 1036 __ bind(ok);
aoqi@0 1037 }
aoqi@0 1038 #endif // ASSERT
aoqi@0 1039
aoqi@0 1040 // if we got here then the TLAB allocation failed, so try
aoqi@0 1041 // refilling the TLAB or allocating directly from eden.
aoqi@0 1042 Label retry_tlab, try_eden;
aoqi@0 1043 const Register thread =
aoqi@0 1044 __ tlab_refill(retry_tlab, try_eden, slow_path); // does not destroy rdx (klass), returns rdi
aoqi@0 1045
aoqi@0 1046 __ bind(retry_tlab);
aoqi@0 1047
aoqi@0 1048 // get the instance size (size is postive so movl is fine for 64bit)
aoqi@0 1049 __ movl(obj_size, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1050
aoqi@0 1051 __ tlab_allocate(obj, obj_size, 0, t1, t2, slow_path);
aoqi@0 1052
aoqi@0 1053 __ initialize_object(obj, klass, obj_size, 0, t1, t2);
aoqi@0 1054 __ verify_oop(obj);
aoqi@0 1055 __ pop(rbx);
aoqi@0 1056 __ pop(rdi);
aoqi@0 1057 __ ret(0);
aoqi@0 1058
aoqi@0 1059 __ bind(try_eden);
aoqi@0 1060 // get the instance size (size is postive so movl is fine for 64bit)
aoqi@0 1061 __ movl(obj_size, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1062
aoqi@0 1063 __ eden_allocate(obj, obj_size, 0, t1, slow_path);
aoqi@0 1064 __ incr_allocated_bytes(thread, obj_size, 0);
aoqi@0 1065
aoqi@0 1066 __ initialize_object(obj, klass, obj_size, 0, t1, t2);
aoqi@0 1067 __ verify_oop(obj);
aoqi@0 1068 __ pop(rbx);
aoqi@0 1069 __ pop(rdi);
aoqi@0 1070 __ ret(0);
aoqi@0 1071
aoqi@0 1072 __ bind(slow_path);
aoqi@0 1073 __ pop(rbx);
aoqi@0 1074 __ pop(rdi);
aoqi@0 1075 }
aoqi@0 1076
aoqi@0 1077 __ enter();
aoqi@0 1078 OopMap* map = save_live_registers(sasm, 2);
aoqi@0 1079 int call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_instance), klass);
aoqi@0 1080 oop_maps = new OopMapSet();
aoqi@0 1081 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1082 restore_live_registers_except_rax(sasm);
aoqi@0 1083 __ verify_oop(obj);
aoqi@0 1084 __ leave();
aoqi@0 1085 __ ret(0);
aoqi@0 1086
aoqi@0 1087 // rax,: new instance
aoqi@0 1088 }
aoqi@0 1089
aoqi@0 1090 break;
aoqi@0 1091
aoqi@0 1092 case counter_overflow_id:
aoqi@0 1093 {
aoqi@0 1094 Register bci = rax, method = rbx;
aoqi@0 1095 __ enter();
aoqi@0 1096 OopMap* map = save_live_registers(sasm, 3);
aoqi@0 1097 // Retrieve bci
aoqi@0 1098 __ movl(bci, Address(rbp, 2*BytesPerWord));
aoqi@0 1099 // And a pointer to the Method*
aoqi@0 1100 __ movptr(method, Address(rbp, 3*BytesPerWord));
aoqi@0 1101 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, counter_overflow), bci, method);
aoqi@0 1102 oop_maps = new OopMapSet();
aoqi@0 1103 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1104 restore_live_registers(sasm);
aoqi@0 1105 __ leave();
aoqi@0 1106 __ ret(0);
aoqi@0 1107 }
aoqi@0 1108 break;
aoqi@0 1109
aoqi@0 1110 case new_type_array_id:
aoqi@0 1111 case new_object_array_id:
aoqi@0 1112 {
aoqi@0 1113 Register length = rbx; // Incoming
aoqi@0 1114 Register klass = rdx; // Incoming
aoqi@0 1115 Register obj = rax; // Result
aoqi@0 1116
aoqi@0 1117 if (id == new_type_array_id) {
aoqi@0 1118 __ set_info("new_type_array", dont_gc_arguments);
aoqi@0 1119 } else {
aoqi@0 1120 __ set_info("new_object_array", dont_gc_arguments);
aoqi@0 1121 }
aoqi@0 1122
aoqi@0 1123 #ifdef ASSERT
aoqi@0 1124 // assert object type is really an array of the proper kind
aoqi@0 1125 {
aoqi@0 1126 Label ok;
aoqi@0 1127 Register t0 = obj;
aoqi@0 1128 __ movl(t0, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1129 __ sarl(t0, Klass::_lh_array_tag_shift);
aoqi@0 1130 int tag = ((id == new_type_array_id)
aoqi@0 1131 ? Klass::_lh_array_tag_type_value
aoqi@0 1132 : Klass::_lh_array_tag_obj_value);
aoqi@0 1133 __ cmpl(t0, tag);
aoqi@0 1134 __ jcc(Assembler::equal, ok);
aoqi@0 1135 __ stop("assert(is an array klass)");
aoqi@0 1136 __ should_not_reach_here();
aoqi@0 1137 __ bind(ok);
aoqi@0 1138 }
aoqi@0 1139 #endif // ASSERT
aoqi@0 1140
aoqi@0 1141 if (UseTLAB && FastTLABRefill) {
aoqi@0 1142 Register arr_size = rsi;
aoqi@0 1143 Register t1 = rcx; // must be rcx for use as shift count
aoqi@0 1144 Register t2 = rdi;
aoqi@0 1145 Label slow_path;
aoqi@0 1146 assert_different_registers(length, klass, obj, arr_size, t1, t2);
aoqi@0 1147
aoqi@0 1148 // check that array length is small enough for fast path.
aoqi@0 1149 __ cmpl(length, C1_MacroAssembler::max_array_allocation_length);
aoqi@0 1150 __ jcc(Assembler::above, slow_path);
aoqi@0 1151
aoqi@0 1152 // if we got here then the TLAB allocation failed, so try
aoqi@0 1153 // refilling the TLAB or allocating directly from eden.
aoqi@0 1154 Label retry_tlab, try_eden;
aoqi@0 1155 const Register thread =
aoqi@0 1156 __ tlab_refill(retry_tlab, try_eden, slow_path); // preserves rbx & rdx, returns rdi
aoqi@0 1157
aoqi@0 1158 __ bind(retry_tlab);
aoqi@0 1159
aoqi@0 1160 // get the allocation size: round_up(hdr + length << (layout_helper & 0x1F))
aoqi@0 1161 // since size is positive movl does right thing on 64bit
aoqi@0 1162 __ movl(t1, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1163 // since size is postive movl does right thing on 64bit
aoqi@0 1164 __ movl(arr_size, length);
aoqi@0 1165 assert(t1 == rcx, "fixed register usage");
aoqi@0 1166 __ shlptr(arr_size /* by t1=rcx, mod 32 */);
aoqi@0 1167 __ shrptr(t1, Klass::_lh_header_size_shift);
aoqi@0 1168 __ andptr(t1, Klass::_lh_header_size_mask);
aoqi@0 1169 __ addptr(arr_size, t1);
aoqi@0 1170 __ addptr(arr_size, MinObjAlignmentInBytesMask); // align up
aoqi@0 1171 __ andptr(arr_size, ~MinObjAlignmentInBytesMask);
aoqi@0 1172
aoqi@0 1173 __ tlab_allocate(obj, arr_size, 0, t1, t2, slow_path); // preserves arr_size
aoqi@0 1174
aoqi@0 1175 __ initialize_header(obj, klass, length, t1, t2);
aoqi@0 1176 __ movb(t1, Address(klass, in_bytes(Klass::layout_helper_offset()) + (Klass::_lh_header_size_shift / BitsPerByte)));
aoqi@0 1177 assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");
aoqi@0 1178 assert(Klass::_lh_header_size_mask <= 0xFF, "bytewise");
aoqi@0 1179 __ andptr(t1, Klass::_lh_header_size_mask);
aoqi@0 1180 __ subptr(arr_size, t1); // body length
aoqi@0 1181 __ addptr(t1, obj); // body start
aoqi@0 1182 __ initialize_body(t1, arr_size, 0, t2);
aoqi@0 1183 __ verify_oop(obj);
aoqi@0 1184 __ ret(0);
aoqi@0 1185
aoqi@0 1186 __ bind(try_eden);
aoqi@0 1187 // get the allocation size: round_up(hdr + length << (layout_helper & 0x1F))
aoqi@0 1188 // since size is positive movl does right thing on 64bit
aoqi@0 1189 __ movl(t1, Address(klass, Klass::layout_helper_offset()));
aoqi@0 1190 // since size is postive movl does right thing on 64bit
aoqi@0 1191 __ movl(arr_size, length);
aoqi@0 1192 assert(t1 == rcx, "fixed register usage");
aoqi@0 1193 __ shlptr(arr_size /* by t1=rcx, mod 32 */);
aoqi@0 1194 __ shrptr(t1, Klass::_lh_header_size_shift);
aoqi@0 1195 __ andptr(t1, Klass::_lh_header_size_mask);
aoqi@0 1196 __ addptr(arr_size, t1);
aoqi@0 1197 __ addptr(arr_size, MinObjAlignmentInBytesMask); // align up
aoqi@0 1198 __ andptr(arr_size, ~MinObjAlignmentInBytesMask);
aoqi@0 1199
aoqi@0 1200 __ eden_allocate(obj, arr_size, 0, t1, slow_path); // preserves arr_size
aoqi@0 1201 __ incr_allocated_bytes(thread, arr_size, 0);
aoqi@0 1202
aoqi@0 1203 __ initialize_header(obj, klass, length, t1, t2);
aoqi@0 1204 __ movb(t1, Address(klass, in_bytes(Klass::layout_helper_offset()) + (Klass::_lh_header_size_shift / BitsPerByte)));
aoqi@0 1205 assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");
aoqi@0 1206 assert(Klass::_lh_header_size_mask <= 0xFF, "bytewise");
aoqi@0 1207 __ andptr(t1, Klass::_lh_header_size_mask);
aoqi@0 1208 __ subptr(arr_size, t1); // body length
aoqi@0 1209 __ addptr(t1, obj); // body start
aoqi@0 1210 __ initialize_body(t1, arr_size, 0, t2);
aoqi@0 1211 __ verify_oop(obj);
aoqi@0 1212 __ ret(0);
aoqi@0 1213
aoqi@0 1214 __ bind(slow_path);
aoqi@0 1215 }
aoqi@0 1216
aoqi@0 1217 __ enter();
aoqi@0 1218 OopMap* map = save_live_registers(sasm, 3);
aoqi@0 1219 int call_offset;
aoqi@0 1220 if (id == new_type_array_id) {
aoqi@0 1221 call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_type_array), klass, length);
aoqi@0 1222 } else {
aoqi@0 1223 call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_object_array), klass, length);
aoqi@0 1224 }
aoqi@0 1225
aoqi@0 1226 oop_maps = new OopMapSet();
aoqi@0 1227 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1228 restore_live_registers_except_rax(sasm);
aoqi@0 1229
aoqi@0 1230 __ verify_oop(obj);
aoqi@0 1231 __ leave();
aoqi@0 1232 __ ret(0);
aoqi@0 1233
aoqi@0 1234 // rax,: new array
aoqi@0 1235 }
aoqi@0 1236 break;
aoqi@0 1237
aoqi@0 1238 case new_multi_array_id:
aoqi@0 1239 { StubFrame f(sasm, "new_multi_array", dont_gc_arguments);
aoqi@0 1240 // rax,: klass
aoqi@0 1241 // rbx,: rank
aoqi@0 1242 // rcx: address of 1st dimension
aoqi@0 1243 OopMap* map = save_live_registers(sasm, 4);
aoqi@0 1244 int call_offset = __ call_RT(rax, noreg, CAST_FROM_FN_PTR(address, new_multi_array), rax, rbx, rcx);
aoqi@0 1245
aoqi@0 1246 oop_maps = new OopMapSet();
aoqi@0 1247 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1248 restore_live_registers_except_rax(sasm);
aoqi@0 1249
aoqi@0 1250 // rax,: new multi array
aoqi@0 1251 __ verify_oop(rax);
aoqi@0 1252 }
aoqi@0 1253 break;
aoqi@0 1254
aoqi@0 1255 case register_finalizer_id:
aoqi@0 1256 {
aoqi@0 1257 __ set_info("register_finalizer", dont_gc_arguments);
aoqi@0 1258
aoqi@0 1259 // This is called via call_runtime so the arguments
aoqi@0 1260 // will be place in C abi locations
aoqi@0 1261
aoqi@0 1262 #ifdef _LP64
aoqi@0 1263 __ verify_oop(c_rarg0);
aoqi@0 1264 __ mov(rax, c_rarg0);
aoqi@0 1265 #else
aoqi@0 1266 // The object is passed on the stack and we haven't pushed a
aoqi@0 1267 // frame yet so it's one work away from top of stack.
aoqi@0 1268 __ movptr(rax, Address(rsp, 1 * BytesPerWord));
aoqi@0 1269 __ verify_oop(rax);
aoqi@0 1270 #endif // _LP64
aoqi@0 1271
aoqi@0 1272 // load the klass and check the has finalizer flag
aoqi@0 1273 Label register_finalizer;
aoqi@0 1274 Register t = rsi;
aoqi@0 1275 __ load_klass(t, rax);
aoqi@0 1276 __ movl(t, Address(t, Klass::access_flags_offset()));
aoqi@0 1277 __ testl(t, JVM_ACC_HAS_FINALIZER);
aoqi@0 1278 __ jcc(Assembler::notZero, register_finalizer);
aoqi@0 1279 __ ret(0);
aoqi@0 1280
aoqi@0 1281 __ bind(register_finalizer);
aoqi@0 1282 __ enter();
aoqi@0 1283 OopMap* oop_map = save_live_registers(sasm, 2 /*num_rt_args */);
aoqi@0 1284 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), rax);
aoqi@0 1285 oop_maps = new OopMapSet();
aoqi@0 1286 oop_maps->add_gc_map(call_offset, oop_map);
aoqi@0 1287
aoqi@0 1288 // Now restore all the live registers
aoqi@0 1289 restore_live_registers(sasm);
aoqi@0 1290
aoqi@0 1291 __ leave();
aoqi@0 1292 __ ret(0);
aoqi@0 1293 }
aoqi@0 1294 break;
aoqi@0 1295
aoqi@0 1296 case throw_range_check_failed_id:
aoqi@0 1297 { StubFrame f(sasm, "range_check_failed", dont_gc_arguments);
aoqi@0 1298 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);
aoqi@0 1299 }
aoqi@0 1300 break;
aoqi@0 1301
aoqi@0 1302 case throw_index_exception_id:
aoqi@0 1303 { StubFrame f(sasm, "index_range_check_failed", dont_gc_arguments);
aoqi@0 1304 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);
aoqi@0 1305 }
aoqi@0 1306 break;
aoqi@0 1307
aoqi@0 1308 case throw_div0_exception_id:
aoqi@0 1309 { StubFrame f(sasm, "throw_div0_exception", dont_gc_arguments);
aoqi@0 1310 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);
aoqi@0 1311 }
aoqi@0 1312 break;
aoqi@0 1313
aoqi@0 1314 case throw_null_pointer_exception_id:
aoqi@0 1315 { StubFrame f(sasm, "throw_null_pointer_exception", dont_gc_arguments);
aoqi@0 1316 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);
aoqi@0 1317 }
aoqi@0 1318 break;
aoqi@0 1319
aoqi@0 1320 case handle_exception_nofpu_id:
aoqi@0 1321 case handle_exception_id:
aoqi@0 1322 { StubFrame f(sasm, "handle_exception", dont_gc_arguments);
aoqi@0 1323 oop_maps = generate_handle_exception(id, sasm);
aoqi@0 1324 }
aoqi@0 1325 break;
aoqi@0 1326
aoqi@0 1327 case handle_exception_from_callee_id:
aoqi@0 1328 { StubFrame f(sasm, "handle_exception_from_callee", dont_gc_arguments);
aoqi@0 1329 oop_maps = generate_handle_exception(id, sasm);
aoqi@0 1330 }
aoqi@0 1331 break;
aoqi@0 1332
aoqi@0 1333 case unwind_exception_id:
aoqi@0 1334 { __ set_info("unwind_exception", dont_gc_arguments);
aoqi@0 1335 // note: no stubframe since we are about to leave the current
aoqi@0 1336 // activation and we are calling a leaf VM function only.
aoqi@0 1337 generate_unwind_exception(sasm);
aoqi@0 1338 }
aoqi@0 1339 break;
aoqi@0 1340
aoqi@0 1341 case throw_array_store_exception_id:
aoqi@0 1342 { StubFrame f(sasm, "throw_array_store_exception", dont_gc_arguments);
aoqi@0 1343 // tos + 0: link
aoqi@0 1344 // + 1: return address
aoqi@0 1345 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), true);
aoqi@0 1346 }
aoqi@0 1347 break;
aoqi@0 1348
aoqi@0 1349 case throw_class_cast_exception_id:
aoqi@0 1350 { StubFrame f(sasm, "throw_class_cast_exception", dont_gc_arguments);
aoqi@0 1351 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);
aoqi@0 1352 }
aoqi@0 1353 break;
aoqi@0 1354
aoqi@0 1355 case throw_incompatible_class_change_error_id:
aoqi@0 1356 { StubFrame f(sasm, "throw_incompatible_class_cast_exception", dont_gc_arguments);
aoqi@0 1357 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);
aoqi@0 1358 }
aoqi@0 1359 break;
aoqi@0 1360
aoqi@0 1361 case slow_subtype_check_id:
aoqi@0 1362 {
aoqi@0 1363 // Typical calling sequence:
aoqi@0 1364 // __ push(klass_RInfo); // object klass or other subclass
aoqi@0 1365 // __ push(sup_k_RInfo); // array element klass or other superclass
aoqi@0 1366 // __ call(slow_subtype_check);
aoqi@0 1367 // Note that the subclass is pushed first, and is therefore deepest.
aoqi@0 1368 // Previous versions of this code reversed the names 'sub' and 'super'.
aoqi@0 1369 // This was operationally harmless but made the code unreadable.
aoqi@0 1370 enum layout {
aoqi@0 1371 rax_off, SLOT2(raxH_off)
aoqi@0 1372 rcx_off, SLOT2(rcxH_off)
aoqi@0 1373 rsi_off, SLOT2(rsiH_off)
aoqi@0 1374 rdi_off, SLOT2(rdiH_off)
aoqi@0 1375 // saved_rbp_off, SLOT2(saved_rbpH_off)
aoqi@0 1376 return_off, SLOT2(returnH_off)
aoqi@0 1377 sup_k_off, SLOT2(sup_kH_off)
aoqi@0 1378 klass_off, SLOT2(superH_off)
aoqi@0 1379 framesize,
aoqi@0 1380 result_off = klass_off // deepest argument is also the return value
aoqi@0 1381 };
aoqi@0 1382
aoqi@0 1383 __ set_info("slow_subtype_check", dont_gc_arguments);
aoqi@0 1384 __ push(rdi);
aoqi@0 1385 __ push(rsi);
aoqi@0 1386 __ push(rcx);
aoqi@0 1387 __ push(rax);
aoqi@0 1388
aoqi@0 1389 // This is called by pushing args and not with C abi
aoqi@0 1390 __ movptr(rsi, Address(rsp, (klass_off) * VMRegImpl::stack_slot_size)); // subclass
aoqi@0 1391 __ movptr(rax, Address(rsp, (sup_k_off) * VMRegImpl::stack_slot_size)); // superclass
aoqi@0 1392
aoqi@0 1393 Label miss;
aoqi@0 1394 __ check_klass_subtype_slow_path(rsi, rax, rcx, rdi, NULL, &miss);
aoqi@0 1395
aoqi@0 1396 // fallthrough on success:
aoqi@0 1397 __ movptr(Address(rsp, (result_off) * VMRegImpl::stack_slot_size), 1); // result
aoqi@0 1398 __ pop(rax);
aoqi@0 1399 __ pop(rcx);
aoqi@0 1400 __ pop(rsi);
aoqi@0 1401 __ pop(rdi);
aoqi@0 1402 __ ret(0);
aoqi@0 1403
aoqi@0 1404 __ bind(miss);
aoqi@0 1405 __ movptr(Address(rsp, (result_off) * VMRegImpl::stack_slot_size), NULL_WORD); // result
aoqi@0 1406 __ pop(rax);
aoqi@0 1407 __ pop(rcx);
aoqi@0 1408 __ pop(rsi);
aoqi@0 1409 __ pop(rdi);
aoqi@0 1410 __ ret(0);
aoqi@0 1411 }
aoqi@0 1412 break;
aoqi@0 1413
aoqi@0 1414 case monitorenter_nofpu_id:
aoqi@0 1415 save_fpu_registers = false;
aoqi@0 1416 // fall through
aoqi@0 1417 case monitorenter_id:
aoqi@0 1418 {
aoqi@0 1419 StubFrame f(sasm, "monitorenter", dont_gc_arguments);
aoqi@0 1420 OopMap* map = save_live_registers(sasm, 3, save_fpu_registers);
aoqi@0 1421
aoqi@0 1422 // Called with store_parameter and not C abi
aoqi@0 1423
aoqi@0 1424 f.load_argument(1, rax); // rax,: object
aoqi@0 1425 f.load_argument(0, rbx); // rbx,: lock address
aoqi@0 1426
aoqi@0 1427 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), rax, rbx);
aoqi@0 1428
aoqi@0 1429 oop_maps = new OopMapSet();
aoqi@0 1430 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1431 restore_live_registers(sasm, save_fpu_registers);
aoqi@0 1432 }
aoqi@0 1433 break;
aoqi@0 1434
aoqi@0 1435 case monitorexit_nofpu_id:
aoqi@0 1436 save_fpu_registers = false;
aoqi@0 1437 // fall through
aoqi@0 1438 case monitorexit_id:
aoqi@0 1439 {
aoqi@0 1440 StubFrame f(sasm, "monitorexit", dont_gc_arguments);
aoqi@0 1441 OopMap* map = save_live_registers(sasm, 2, save_fpu_registers);
aoqi@0 1442
aoqi@0 1443 // Called with store_parameter and not C abi
aoqi@0 1444
aoqi@0 1445 f.load_argument(0, rax); // rax,: lock address
aoqi@0 1446
aoqi@0 1447 // note: really a leaf routine but must setup last java sp
aoqi@0 1448 // => use call_RT for now (speed can be improved by
aoqi@0 1449 // doing last java sp setup manually)
aoqi@0 1450 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), rax);
aoqi@0 1451
aoqi@0 1452 oop_maps = new OopMapSet();
aoqi@0 1453 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1454 restore_live_registers(sasm, save_fpu_registers);
aoqi@0 1455 }
aoqi@0 1456 break;
aoqi@0 1457
aoqi@0 1458 case deoptimize_id:
aoqi@0 1459 {
aoqi@0 1460 StubFrame f(sasm, "deoptimize", dont_gc_arguments);
aoqi@0 1461 const int num_rt_args = 1; // thread
aoqi@0 1462 OopMap* oop_map = save_live_registers(sasm, num_rt_args);
aoqi@0 1463 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize));
aoqi@0 1464 oop_maps = new OopMapSet();
aoqi@0 1465 oop_maps->add_gc_map(call_offset, oop_map);
aoqi@0 1466 restore_live_registers(sasm);
aoqi@0 1467 DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
aoqi@0 1468 assert(deopt_blob != NULL, "deoptimization blob must have been created");
aoqi@0 1469 __ leave();
aoqi@0 1470 __ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
aoqi@0 1471 }
aoqi@0 1472 break;
aoqi@0 1473
aoqi@0 1474 case access_field_patching_id:
aoqi@0 1475 { StubFrame f(sasm, "access_field_patching", dont_gc_arguments);
aoqi@0 1476 // we should set up register map
aoqi@0 1477 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));
aoqi@0 1478 }
aoqi@0 1479 break;
aoqi@0 1480
aoqi@0 1481 case load_klass_patching_id:
aoqi@0 1482 { StubFrame f(sasm, "load_klass_patching", dont_gc_arguments);
aoqi@0 1483 // we should set up register map
aoqi@0 1484 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));
aoqi@0 1485 }
aoqi@0 1486 break;
aoqi@0 1487
aoqi@0 1488 case load_mirror_patching_id:
aoqi@0 1489 { StubFrame f(sasm, "load_mirror_patching", dont_gc_arguments);
aoqi@0 1490 // we should set up register map
aoqi@0 1491 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_mirror_patching));
aoqi@0 1492 }
aoqi@0 1493 break;
aoqi@0 1494
aoqi@0 1495 case load_appendix_patching_id:
aoqi@0 1496 { StubFrame f(sasm, "load_appendix_patching", dont_gc_arguments);
aoqi@0 1497 // we should set up register map
aoqi@0 1498 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_appendix_patching));
aoqi@0 1499 }
aoqi@0 1500 break;
aoqi@0 1501
aoqi@0 1502 case dtrace_object_alloc_id:
aoqi@0 1503 { // rax,: object
aoqi@0 1504 StubFrame f(sasm, "dtrace_object_alloc", dont_gc_arguments);
aoqi@0 1505 // we can't gc here so skip the oopmap but make sure that all
aoqi@0 1506 // the live registers get saved.
aoqi@0 1507 save_live_registers(sasm, 1);
aoqi@0 1508
aoqi@0 1509 __ NOT_LP64(push(rax)) LP64_ONLY(mov(c_rarg0, rax));
aoqi@0 1510 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc)));
aoqi@0 1511 NOT_LP64(__ pop(rax));
aoqi@0 1512
aoqi@0 1513 restore_live_registers(sasm);
aoqi@0 1514 }
aoqi@0 1515 break;
aoqi@0 1516
aoqi@0 1517 case fpu2long_stub_id:
aoqi@0 1518 {
aoqi@0 1519 // rax, and rdx are destroyed, but should be free since the result is returned there
aoqi@0 1520 // preserve rsi,ecx
aoqi@0 1521 __ push(rsi);
aoqi@0 1522 __ push(rcx);
aoqi@0 1523 LP64_ONLY(__ push(rdx);)
aoqi@0 1524
aoqi@0 1525 // check for NaN
aoqi@0 1526 Label return0, do_return, return_min_jlong, do_convert;
aoqi@0 1527
aoqi@0 1528 Address value_high_word(rsp, wordSize + 4);
aoqi@0 1529 Address value_low_word(rsp, wordSize);
aoqi@0 1530 Address result_high_word(rsp, 3*wordSize + 4);
aoqi@0 1531 Address result_low_word(rsp, 3*wordSize);
aoqi@0 1532
aoqi@0 1533 __ subptr(rsp, 32); // more than enough on 32bit
aoqi@0 1534 __ fst_d(value_low_word);
aoqi@0 1535 __ movl(rax, value_high_word);
aoqi@0 1536 __ andl(rax, 0x7ff00000);
aoqi@0 1537 __ cmpl(rax, 0x7ff00000);
aoqi@0 1538 __ jcc(Assembler::notEqual, do_convert);
aoqi@0 1539 __ movl(rax, value_high_word);
aoqi@0 1540 __ andl(rax, 0xfffff);
aoqi@0 1541 __ orl(rax, value_low_word);
aoqi@0 1542 __ jcc(Assembler::notZero, return0);
aoqi@0 1543
aoqi@0 1544 __ bind(do_convert);
aoqi@0 1545 __ fnstcw(Address(rsp, 0));
aoqi@0 1546 __ movzwl(rax, Address(rsp, 0));
aoqi@0 1547 __ orl(rax, 0xc00);
aoqi@0 1548 __ movw(Address(rsp, 2), rax);
aoqi@0 1549 __ fldcw(Address(rsp, 2));
aoqi@0 1550 __ fwait();
aoqi@0 1551 __ fistp_d(result_low_word);
aoqi@0 1552 __ fldcw(Address(rsp, 0));
aoqi@0 1553 __ fwait();
aoqi@0 1554 // This gets the entire long in rax on 64bit
aoqi@0 1555 __ movptr(rax, result_low_word);
aoqi@0 1556 // testing of high bits
aoqi@0 1557 __ movl(rdx, result_high_word);
aoqi@0 1558 __ mov(rcx, rax);
aoqi@0 1559 // What the heck is the point of the next instruction???
aoqi@0 1560 __ xorl(rcx, 0x0);
aoqi@0 1561 __ movl(rsi, 0x80000000);
aoqi@0 1562 __ xorl(rsi, rdx);
aoqi@0 1563 __ orl(rcx, rsi);
aoqi@0 1564 __ jcc(Assembler::notEqual, do_return);
aoqi@0 1565 __ fldz();
aoqi@0 1566 __ fcomp_d(value_low_word);
aoqi@0 1567 __ fnstsw_ax();
aoqi@0 1568 #ifdef _LP64
aoqi@0 1569 __ testl(rax, 0x4100); // ZF & CF == 0
aoqi@0 1570 __ jcc(Assembler::equal, return_min_jlong);
aoqi@0 1571 #else
aoqi@0 1572 __ sahf();
aoqi@0 1573 __ jcc(Assembler::above, return_min_jlong);
aoqi@0 1574 #endif // _LP64
aoqi@0 1575 // return max_jlong
aoqi@0 1576 #ifndef _LP64
aoqi@0 1577 __ movl(rdx, 0x7fffffff);
aoqi@0 1578 __ movl(rax, 0xffffffff);
aoqi@0 1579 #else
aoqi@0 1580 __ mov64(rax, CONST64(0x7fffffffffffffff));
aoqi@0 1581 #endif // _LP64
aoqi@0 1582 __ jmp(do_return);
aoqi@0 1583
aoqi@0 1584 __ bind(return_min_jlong);
aoqi@0 1585 #ifndef _LP64
aoqi@0 1586 __ movl(rdx, 0x80000000);
aoqi@0 1587 __ xorl(rax, rax);
aoqi@0 1588 #else
aoqi@0 1589 __ mov64(rax, CONST64(0x8000000000000000));
aoqi@0 1590 #endif // _LP64
aoqi@0 1591 __ jmp(do_return);
aoqi@0 1592
aoqi@0 1593 __ bind(return0);
aoqi@0 1594 __ fpop();
aoqi@0 1595 #ifndef _LP64
aoqi@0 1596 __ xorptr(rdx,rdx);
aoqi@0 1597 __ xorptr(rax,rax);
aoqi@0 1598 #else
aoqi@0 1599 __ xorptr(rax, rax);
aoqi@0 1600 #endif // _LP64
aoqi@0 1601
aoqi@0 1602 __ bind(do_return);
aoqi@0 1603 __ addptr(rsp, 32);
aoqi@0 1604 LP64_ONLY(__ pop(rdx);)
aoqi@0 1605 __ pop(rcx);
aoqi@0 1606 __ pop(rsi);
aoqi@0 1607 __ ret(0);
aoqi@0 1608 }
aoqi@0 1609 break;
aoqi@0 1610
aoqi@0 1611 #if INCLUDE_ALL_GCS
aoqi@0 1612 case g1_pre_barrier_slow_id:
aoqi@0 1613 {
aoqi@0 1614 StubFrame f(sasm, "g1_pre_barrier", dont_gc_arguments);
aoqi@0 1615 // arg0 : previous value of memory
aoqi@0 1616
aoqi@0 1617 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@0 1618 if (bs->kind() != BarrierSet::G1SATBCTLogging) {
aoqi@0 1619 __ movptr(rax, (int)id);
aoqi@0 1620 __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), rax);
aoqi@0 1621 __ should_not_reach_here();
aoqi@0 1622 break;
aoqi@0 1623 }
aoqi@0 1624 __ push(rax);
aoqi@0 1625 __ push(rdx);
aoqi@0 1626
aoqi@0 1627 const Register pre_val = rax;
aoqi@0 1628 const Register thread = NOT_LP64(rax) LP64_ONLY(r15_thread);
aoqi@0 1629 const Register tmp = rdx;
aoqi@0 1630
aoqi@0 1631 NOT_LP64(__ get_thread(thread);)
aoqi@0 1632
aoqi@0 1633 Address in_progress(thread, in_bytes(JavaThread::satb_mark_queue_offset() +
aoqi@0 1634 PtrQueue::byte_offset_of_active()));
aoqi@0 1635
aoqi@0 1636 Address queue_index(thread, in_bytes(JavaThread::satb_mark_queue_offset() +
aoqi@0 1637 PtrQueue::byte_offset_of_index()));
aoqi@0 1638 Address buffer(thread, in_bytes(JavaThread::satb_mark_queue_offset() +
aoqi@0 1639 PtrQueue::byte_offset_of_buf()));
aoqi@0 1640
aoqi@0 1641
aoqi@0 1642 Label done;
aoqi@0 1643 Label runtime;
aoqi@0 1644
aoqi@0 1645 // Can we store original value in the thread's buffer?
aoqi@0 1646
aoqi@0 1647 #ifdef _LP64
aoqi@0 1648 __ movslq(tmp, queue_index);
aoqi@0 1649 __ cmpq(tmp, 0);
aoqi@0 1650 #else
aoqi@0 1651 __ cmpl(queue_index, 0);
aoqi@0 1652 #endif
aoqi@0 1653 __ jcc(Assembler::equal, runtime);
aoqi@0 1654 #ifdef _LP64
aoqi@0 1655 __ subq(tmp, wordSize);
aoqi@0 1656 __ movl(queue_index, tmp);
aoqi@0 1657 __ addq(tmp, buffer);
aoqi@0 1658 #else
aoqi@0 1659 __ subl(queue_index, wordSize);
aoqi@0 1660 __ movl(tmp, buffer);
aoqi@0 1661 __ addl(tmp, queue_index);
aoqi@0 1662 #endif
aoqi@0 1663
aoqi@0 1664 // prev_val (rax)
aoqi@0 1665 f.load_argument(0, pre_val);
aoqi@0 1666 __ movptr(Address(tmp, 0), pre_val);
aoqi@0 1667 __ jmp(done);
aoqi@0 1668
aoqi@0 1669 __ bind(runtime);
mchinnathamb@9290 1670
mchinnathamb@9290 1671 save_live_registers(sasm, 3);
mchinnathamb@9290 1672
aoqi@0 1673 // load the pre-value
aoqi@0 1674 f.load_argument(0, rcx);
aoqi@0 1675 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_pre), rcx, thread);
mchinnathamb@9290 1676
mchinnathamb@9290 1677 restore_live_registers(sasm);
mchinnathamb@9290 1678
aoqi@0 1679 __ bind(done);
aoqi@0 1680
aoqi@0 1681 __ pop(rdx);
aoqi@0 1682 __ pop(rax);
aoqi@0 1683 }
aoqi@0 1684 break;
aoqi@0 1685
aoqi@0 1686 case g1_post_barrier_slow_id:
aoqi@0 1687 {
aoqi@0 1688 StubFrame f(sasm, "g1_post_barrier", dont_gc_arguments);
aoqi@0 1689
aoqi@0 1690
aoqi@0 1691 // arg0: store_address
aoqi@0 1692 Address store_addr(rbp, 2*BytesPerWord);
aoqi@0 1693
aoqi@0 1694 BarrierSet* bs = Universe::heap()->barrier_set();
aoqi@0 1695 CardTableModRefBS* ct = (CardTableModRefBS*)bs;
aoqi@0 1696 assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code");
aoqi@0 1697
aoqi@0 1698 Label done;
aoqi@0 1699 Label runtime;
aoqi@0 1700
aoqi@0 1701 // At this point we know new_value is non-NULL and the new_value crosses regions.
aoqi@0 1702 // Must check to see if card is already dirty
aoqi@0 1703
aoqi@0 1704 const Register thread = NOT_LP64(rax) LP64_ONLY(r15_thread);
aoqi@0 1705
aoqi@0 1706 Address queue_index(thread, in_bytes(JavaThread::dirty_card_queue_offset() +
aoqi@0 1707 PtrQueue::byte_offset_of_index()));
aoqi@0 1708 Address buffer(thread, in_bytes(JavaThread::dirty_card_queue_offset() +
aoqi@0 1709 PtrQueue::byte_offset_of_buf()));
aoqi@0 1710
aoqi@0 1711 __ push(rax);
aoqi@0 1712 __ push(rcx);
aoqi@0 1713
aoqi@0 1714 const Register cardtable = rax;
aoqi@0 1715 const Register card_addr = rcx;
aoqi@0 1716
aoqi@0 1717 f.load_argument(0, card_addr);
aoqi@0 1718 __ shrptr(card_addr, CardTableModRefBS::card_shift);
aoqi@0 1719 // Do not use ExternalAddress to load 'byte_map_base', since 'byte_map_base' is NOT
aoqi@0 1720 // a valid address and therefore is not properly handled by the relocation code.
aoqi@0 1721 __ movptr(cardtable, (intptr_t)ct->byte_map_base);
aoqi@0 1722 __ addptr(card_addr, cardtable);
aoqi@0 1723
aoqi@0 1724 NOT_LP64(__ get_thread(thread);)
aoqi@0 1725
aoqi@0 1726 __ cmpb(Address(card_addr, 0), (int)G1SATBCardTableModRefBS::g1_young_card_val());
aoqi@0 1727 __ jcc(Assembler::equal, done);
aoqi@0 1728
aoqi@0 1729 __ membar(Assembler::Membar_mask_bits(Assembler::StoreLoad));
aoqi@0 1730 __ cmpb(Address(card_addr, 0), (int)CardTableModRefBS::dirty_card_val());
aoqi@0 1731 __ jcc(Assembler::equal, done);
aoqi@0 1732
aoqi@0 1733 // storing region crossing non-NULL, card is clean.
aoqi@0 1734 // dirty card and log.
aoqi@0 1735
aoqi@0 1736 __ movb(Address(card_addr, 0), (int)CardTableModRefBS::dirty_card_val());
aoqi@0 1737
aoqi@0 1738 __ cmpl(queue_index, 0);
aoqi@0 1739 __ jcc(Assembler::equal, runtime);
aoqi@0 1740 __ subl(queue_index, wordSize);
aoqi@0 1741
aoqi@0 1742 const Register buffer_addr = rbx;
aoqi@0 1743 __ push(rbx);
aoqi@0 1744
aoqi@0 1745 __ movptr(buffer_addr, buffer);
aoqi@0 1746
aoqi@0 1747 #ifdef _LP64
aoqi@0 1748 __ movslq(rscratch1, queue_index);
aoqi@0 1749 __ addptr(buffer_addr, rscratch1);
aoqi@0 1750 #else
aoqi@0 1751 __ addptr(buffer_addr, queue_index);
aoqi@0 1752 #endif
aoqi@0 1753 __ movptr(Address(buffer_addr, 0), card_addr);
aoqi@0 1754
aoqi@0 1755 __ pop(rbx);
aoqi@0 1756 __ jmp(done);
aoqi@0 1757
aoqi@0 1758 __ bind(runtime);
aoqi@0 1759 __ push(rdx);
mchinnathamb@9290 1760
mchinnathamb@9290 1761 save_live_registers(sasm, 3);
mchinnathamb@9290 1762
aoqi@0 1763 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::g1_wb_post), card_addr, thread);
mchinnathamb@9290 1764
mchinnathamb@9290 1765 restore_live_registers(sasm);
mchinnathamb@9290 1766
aoqi@0 1767 __ pop(rdx);
aoqi@0 1768 __ bind(done);
aoqi@0 1769
aoqi@0 1770 __ pop(rcx);
aoqi@0 1771 __ pop(rax);
aoqi@0 1772
aoqi@0 1773 }
aoqi@0 1774 break;
aoqi@0 1775 #endif // INCLUDE_ALL_GCS
aoqi@0 1776
aoqi@0 1777 case predicate_failed_trap_id:
aoqi@0 1778 {
aoqi@0 1779 StubFrame f(sasm, "predicate_failed_trap", dont_gc_arguments);
aoqi@0 1780
aoqi@0 1781 OopMap* map = save_live_registers(sasm, 1);
aoqi@0 1782
aoqi@0 1783 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, predicate_failed_trap));
aoqi@0 1784 oop_maps = new OopMapSet();
aoqi@0 1785 oop_maps->add_gc_map(call_offset, map);
aoqi@0 1786 restore_live_registers(sasm);
aoqi@0 1787 __ leave();
aoqi@0 1788 DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
aoqi@0 1789 assert(deopt_blob != NULL, "deoptimization blob must have been created");
aoqi@0 1790
aoqi@0 1791 __ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
aoqi@0 1792 }
aoqi@0 1793 break;
aoqi@0 1794
aoqi@0 1795 default:
aoqi@0 1796 { StubFrame f(sasm, "unimplemented entry", dont_gc_arguments);
aoqi@0 1797 __ movptr(rax, (int)id);
aoqi@0 1798 __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), rax);
aoqi@0 1799 __ should_not_reach_here();
aoqi@0 1800 }
aoqi@0 1801 break;
aoqi@0 1802 }
aoqi@0 1803 return oop_maps;
aoqi@0 1804 }
aoqi@0 1805
aoqi@0 1806 #undef __
aoqi@0 1807
aoqi@0 1808 const char *Runtime1::pd_name_for_address(address entry) {
aoqi@0 1809 return "<unknown function>";
aoqi@0 1810 }

mercurial