annotate src/cpu/x86/vm/c1_Runtime1_x86.cpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children dc7f315e41f7 37f87013dfd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_c1_Runtime1_x86.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Implementation of StubAssembler
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, int args_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // setup registers
a61af66fc99e Initial load
duke
parents:
diff changeset
33 const Register thread = rdi; // is callee-saved register (Visual C++ calling conventions)
a61af66fc99e Initial load
duke
parents:
diff changeset
34 assert(!(oop_result1->is_valid() || oop_result2->is_valid()) || oop_result1 != oop_result2, "registers must be different");
a61af66fc99e Initial load
duke
parents:
diff changeset
35 assert(oop_result1 != thread && oop_result2 != thread, "registers must be different");
a61af66fc99e Initial load
duke
parents:
diff changeset
36 assert(args_size >= 0, "illegal args_size");
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 set_num_rt_args(1 + args_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // push java thread (becomes first argument of C function)
a61af66fc99e Initial load
duke
parents:
diff changeset
41 get_thread(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
42 pushl(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
43
a61af66fc99e Initial load
duke
parents:
diff changeset
44 set_last_Java_frame(thread, noreg, rbp, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // do the call
a61af66fc99e Initial load
duke
parents:
diff changeset
46 call(RuntimeAddress(entry));
a61af66fc99e Initial load
duke
parents:
diff changeset
47 int call_offset = offset();
a61af66fc99e Initial load
duke
parents:
diff changeset
48 // verify callee-saved register
a61af66fc99e Initial load
duke
parents:
diff changeset
49 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
50 guarantee(thread != rax, "change this code");
a61af66fc99e Initial load
duke
parents:
diff changeset
51 pushl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 { Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 get_thread(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 cmpl(thread, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 jcc(Assembler::equal, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
56 int3();
a61af66fc99e Initial load
duke
parents:
diff changeset
57 stop("StubAssembler::call_RT: rdi not callee saved?");
a61af66fc99e Initial load
duke
parents:
diff changeset
58 bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 popl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
62 reset_last_Java_frame(thread, true, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // discard thread and arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
65 addl(rsp, (1 + args_size)*BytesPerWord);
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // check for pending exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
68 { Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 cmpl(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 jcc(Assembler::equal, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // exception pending => remove activation and forward to exception handler
a61af66fc99e Initial load
duke
parents:
diff changeset
72 movl(rax, Address(thread, Thread::pending_exception_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // make sure that the vm_results are cleared
a61af66fc99e Initial load
duke
parents:
diff changeset
74 if (oop_result1->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 movl(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
76 }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (oop_result2->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 movl(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 if (frame_size() == no_frame_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
a61af66fc99e Initial load
duke
parents:
diff changeset
83 } else if (_stub_id == Runtime1::forward_exception_id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
84 should_not_reach_here();
a61af66fc99e Initial load
duke
parents:
diff changeset
85 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 jump(RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 // get oop results if there are any and reset the values in the thread
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if (oop_result1->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 movl(oop_result1, Address(thread, JavaThread::vm_result_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
93 movl(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
94 verify_oop(oop_result1);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96 if (oop_result2->is_valid()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
97 movl(oop_result2, Address(thread, JavaThread::vm_result_2_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
98 movl(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 verify_oop(oop_result2);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101 return call_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 }
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 pushl(arg1);
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return call_RT(oop_result1, oop_result2, entry, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1, Register arg2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 pushl(arg2);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 pushl(arg1);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 return call_RT(oop_result1, oop_result2, entry, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1, Register arg2, Register arg3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
119 pushl(arg3);
a61af66fc99e Initial load
duke
parents:
diff changeset
120 pushl(arg2);
a61af66fc99e Initial load
duke
parents:
diff changeset
121 pushl(arg1);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return call_RT(oop_result1, oop_result2, entry, 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // Implementation of StubFrame
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128 class StubFrame: public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
130 StubAssembler* _sasm;
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
133 StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 void load_argument(int offset_in_words, Register reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136 ~StubFrame();
a61af66fc99e Initial load
duke
parents:
diff changeset
137 };
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140 #define __ _sasm->
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 StubFrame::StubFrame(StubAssembler* sasm, const char* name, bool must_gc_arguments) {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 _sasm = sasm;
a61af66fc99e Initial load
duke
parents:
diff changeset
144 __ set_info(name, must_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 __ enter();
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // load parameters that were stored with LIR_Assembler::store_parameter
a61af66fc99e Initial load
duke
parents:
diff changeset
149 // Note: offsets for store_parameter and load_argument must match
a61af66fc99e Initial load
duke
parents:
diff changeset
150 void StubFrame::load_argument(int offset_in_words, Register reg) {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // rbp, + 0: link
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // + 1: return address
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // + 2: argument with offset 0
a61af66fc99e Initial load
duke
parents:
diff changeset
154 // + 3: argument with offset 1
a61af66fc99e Initial load
duke
parents:
diff changeset
155 // + 4: ...
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 __ movl(reg, Address(rbp, (offset_in_words + 2) * BytesPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 StubFrame::~StubFrame() {
a61af66fc99e Initial load
duke
parents:
diff changeset
162 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
163 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 #undef __
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Implementation of Runtime1
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 #define __ sasm->
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 const int float_regs_as_doubles_size_in_words = 16;
a61af66fc99e Initial load
duke
parents:
diff changeset
174 const int xmm_regs_as_doubles_size_in_words = 16;
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // Stack layout for saving/restoring all the registers needed during a runtime
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // call (this includes deoptimization)
a61af66fc99e Initial load
duke
parents:
diff changeset
178 // Note: note that users of this frame may well have arguments to some runtime
a61af66fc99e Initial load
duke
parents:
diff changeset
179 // while these values are on the stack. These positions neglect those arguments
a61af66fc99e Initial load
duke
parents:
diff changeset
180 // but the code in save_live_registers will take the argument count into
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // account.
a61af66fc99e Initial load
duke
parents:
diff changeset
182 //
a61af66fc99e Initial load
duke
parents:
diff changeset
183 enum reg_save_layout {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 dummy1,
a61af66fc99e Initial load
duke
parents:
diff changeset
185 dummy2,
a61af66fc99e Initial load
duke
parents:
diff changeset
186 // Two temps to be used as needed by users of save/restore callee registers
a61af66fc99e Initial load
duke
parents:
diff changeset
187 temp_2_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
188 temp_1_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
189 xmm_regs_as_doubles_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
190 float_regs_as_doubles_off = xmm_regs_as_doubles_off + xmm_regs_as_doubles_size_in_words,
a61af66fc99e Initial load
duke
parents:
diff changeset
191 fpu_state_off = float_regs_as_doubles_off + float_regs_as_doubles_size_in_words,
a61af66fc99e Initial load
duke
parents:
diff changeset
192 fpu_state_end_off = fpu_state_off + FPUStateSizeInWords,
a61af66fc99e Initial load
duke
parents:
diff changeset
193 marker = fpu_state_end_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
194 extra_space_offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
195 rdi_off = extra_space_offset,
a61af66fc99e Initial load
duke
parents:
diff changeset
196 rsi_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
197 rbp_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
198 rsp_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
199 rbx_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
200 rdx_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
201 rcx_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
202 rax_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
203 saved_rbp_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
204 return_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
205 reg_save_frame_size, // As noted: neglects any parameters to runtime
a61af66fc99e Initial load
duke
parents:
diff changeset
206
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // equates
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 // illegal instruction handler
a61af66fc99e Initial load
duke
parents:
diff changeset
210 continue_dest_off = temp_1_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
211
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // deoptimization equates
a61af66fc99e Initial load
duke
parents:
diff changeset
213 fp0_off = float_regs_as_doubles_off, // slot for java float/double return value
a61af66fc99e Initial load
duke
parents:
diff changeset
214 xmm0_off = xmm_regs_as_doubles_off, // slot for java float/double return value
a61af66fc99e Initial load
duke
parents:
diff changeset
215 deopt_type = temp_2_off, // slot for type of deopt in progress
a61af66fc99e Initial load
duke
parents:
diff changeset
216 ret_type = temp_1_off // slot for return type
a61af66fc99e Initial load
duke
parents:
diff changeset
217 };
a61af66fc99e Initial load
duke
parents:
diff changeset
218
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // Save off registers which might be killed by calls into the runtime.
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // Tries to smart of about FP registers. In particular we separate
a61af66fc99e Initial load
duke
parents:
diff changeset
223 // saving and describing the FPU registers for deoptimization since we
a61af66fc99e Initial load
duke
parents:
diff changeset
224 // have to save the FPU registers twice if we describe them and on P4
a61af66fc99e Initial load
duke
parents:
diff changeset
225 // saving FPU registers which don't contain anything appears
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // expensive. The deopt blob is the only thing which needs to
a61af66fc99e Initial load
duke
parents:
diff changeset
227 // describe FPU registers. In all other cases it should be sufficient
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // to simply save their current value.
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 static OopMap* generate_oop_map(StubAssembler* sasm, int num_rt_args,
a61af66fc99e Initial load
duke
parents:
diff changeset
231 bool save_fpu_registers = true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
232 int frame_size = reg_save_frame_size + num_rt_args; // args + thread
a61af66fc99e Initial load
duke
parents:
diff changeset
233 sasm->set_frame_size(frame_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
234
a61af66fc99e Initial load
duke
parents:
diff changeset
235 // record saved value locations in an OopMap
a61af66fc99e Initial load
duke
parents:
diff changeset
236 // locations are offsets from sp after runtime call; num_rt_args is number of arguments in call, including thread
a61af66fc99e Initial load
duke
parents:
diff changeset
237 OopMap* map = new OopMap(frame_size, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
238 map->set_callee_saved(VMRegImpl::stack2reg(rax_off + num_rt_args), rax->as_VMReg());
a61af66fc99e Initial load
duke
parents:
diff changeset
239 map->set_callee_saved(VMRegImpl::stack2reg(rcx_off + num_rt_args), rcx->as_VMReg());
a61af66fc99e Initial load
duke
parents:
diff changeset
240 map->set_callee_saved(VMRegImpl::stack2reg(rdx_off + num_rt_args), rdx->as_VMReg());
a61af66fc99e Initial load
duke
parents:
diff changeset
241 map->set_callee_saved(VMRegImpl::stack2reg(rbx_off + num_rt_args), rbx->as_VMReg());
a61af66fc99e Initial load
duke
parents:
diff changeset
242 map->set_callee_saved(VMRegImpl::stack2reg(rsi_off + num_rt_args), rsi->as_VMReg());
a61af66fc99e Initial load
duke
parents:
diff changeset
243 map->set_callee_saved(VMRegImpl::stack2reg(rdi_off + num_rt_args), rdi->as_VMReg());
a61af66fc99e Initial load
duke
parents:
diff changeset
244
a61af66fc99e Initial load
duke
parents:
diff changeset
245 if (save_fpu_registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
246 if (UseSSE < 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
247 int fpu_off = float_regs_as_doubles_off;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 for (int n = 0; n < FrameMap::nof_fpu_regs; n++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
249 VMReg fpu_name_0 = FrameMap::fpu_regname(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
250 map->set_callee_saved(VMRegImpl::stack2reg(fpu_off + num_rt_args), fpu_name_0);
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // %%% This is really a waste but we'll keep things as they were for now
a61af66fc99e Initial load
duke
parents:
diff changeset
252 if (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
253 map->set_callee_saved(VMRegImpl::stack2reg(fpu_off + 1 + num_rt_args), fpu_name_0->next());
a61af66fc99e Initial load
duke
parents:
diff changeset
254 }
a61af66fc99e Initial load
duke
parents:
diff changeset
255 fpu_off += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257 assert(fpu_off == fpu_state_off, "incorrect number of fpu stack slots");
a61af66fc99e Initial load
duke
parents:
diff changeset
258 }
a61af66fc99e Initial load
duke
parents:
diff changeset
259
a61af66fc99e Initial load
duke
parents:
diff changeset
260 if (UseSSE >= 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 int xmm_off = xmm_regs_as_doubles_off;
a61af66fc99e Initial load
duke
parents:
diff changeset
262 for (int n = 0; n < FrameMap::nof_xmm_regs; n++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 VMReg xmm_name_0 = as_XMMRegister(n)->as_VMReg();
a61af66fc99e Initial load
duke
parents:
diff changeset
264 map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + num_rt_args), xmm_name_0);
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // %%% This is really a waste but we'll keep things as they were for now
a61af66fc99e Initial load
duke
parents:
diff changeset
266 if (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
267 map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + 1 + num_rt_args), xmm_name_0->next());
a61af66fc99e Initial load
duke
parents:
diff changeset
268 }
a61af66fc99e Initial load
duke
parents:
diff changeset
269 xmm_off += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271 assert(xmm_off == float_regs_as_doubles_off, "incorrect number of xmm registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
272
a61af66fc99e Initial load
duke
parents:
diff changeset
273 } else if (UseSSE == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
274 int xmm_off = xmm_regs_as_doubles_off;
a61af66fc99e Initial load
duke
parents:
diff changeset
275 for (int n = 0; n < FrameMap::nof_xmm_regs; n++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 VMReg xmm_name_0 = as_XMMRegister(n)->as_VMReg();
a61af66fc99e Initial load
duke
parents:
diff changeset
277 map->set_callee_saved(VMRegImpl::stack2reg(xmm_off + num_rt_args), xmm_name_0);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 xmm_off += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 }
a61af66fc99e Initial load
duke
parents:
diff changeset
280 assert(xmm_off == float_regs_as_doubles_off, "incorrect number of xmm registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282 }
a61af66fc99e Initial load
duke
parents:
diff changeset
283
a61af66fc99e Initial load
duke
parents:
diff changeset
284 return map;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 }
a61af66fc99e Initial load
duke
parents:
diff changeset
286
a61af66fc99e Initial load
duke
parents:
diff changeset
287 static OopMap* save_live_registers(StubAssembler* sasm, int num_rt_args,
a61af66fc99e Initial load
duke
parents:
diff changeset
288 bool save_fpu_registers = true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
289 __ block_comment("save_live_registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 int frame_size = reg_save_frame_size + num_rt_args; // args + thread
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // frame_size = round_to(frame_size, 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
293 sasm->set_frame_size(frame_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 __ pushad(); // integer registers
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 // assert(float_regs_as_doubles_off % 2 == 0, "misaligned offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // assert(xmm_regs_as_doubles_off % 2 == 0, "misaligned offset");
a61af66fc99e Initial load
duke
parents:
diff changeset
299
a61af66fc99e Initial load
duke
parents:
diff changeset
300 __ subl(rsp, extra_space_offset * wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
303 __ movl(Address(rsp, marker * wordSize), 0xfeedbeef);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 if (save_fpu_registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (UseSSE < 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // save FPU stack
a61af66fc99e Initial load
duke
parents:
diff changeset
309 __ fnsave(Address(rsp, fpu_state_off * wordSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
310 __ fwait();
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
313 Label ok;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 __ cmpw(Address(rsp, fpu_state_off * wordSize), StubRoutines::fpu_cntrl_wrd_std());
a61af66fc99e Initial load
duke
parents:
diff changeset
315 __ jccb(Assembler::equal, ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 __ stop("corrupted control word detected");
a61af66fc99e Initial load
duke
parents:
diff changeset
317 __ bind(ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
319
a61af66fc99e Initial load
duke
parents:
diff changeset
320 // Reset the control word to guard against exceptions being unmasked
a61af66fc99e Initial load
duke
parents:
diff changeset
321 // since fstp_d can cause FPU stack underflow exceptions. Write it
a61af66fc99e Initial load
duke
parents:
diff changeset
322 // into the on stack copy and then reload that to make sure that the
a61af66fc99e Initial load
duke
parents:
diff changeset
323 // current and future values are correct.
a61af66fc99e Initial load
duke
parents:
diff changeset
324 __ movw(Address(rsp, fpu_state_off * wordSize), StubRoutines::fpu_cntrl_wrd_std());
a61af66fc99e Initial load
duke
parents:
diff changeset
325 __ frstor(Address(rsp, fpu_state_off * wordSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 // Save the FPU registers in de-opt-able form
a61af66fc99e Initial load
duke
parents:
diff changeset
328 __ fstp_d(Address(rsp, float_regs_as_doubles_off * BytesPerWord + 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
329 __ fstp_d(Address(rsp, float_regs_as_doubles_off * BytesPerWord + 8));
a61af66fc99e Initial load
duke
parents:
diff changeset
330 __ fstp_d(Address(rsp, float_regs_as_doubles_off * BytesPerWord + 16));
a61af66fc99e Initial load
duke
parents:
diff changeset
331 __ fstp_d(Address(rsp, float_regs_as_doubles_off * BytesPerWord + 24));
a61af66fc99e Initial load
duke
parents:
diff changeset
332 __ fstp_d(Address(rsp, float_regs_as_doubles_off * BytesPerWord + 32));
a61af66fc99e Initial load
duke
parents:
diff changeset
333 __ fstp_d(Address(rsp, float_regs_as_doubles_off * BytesPerWord + 40));
a61af66fc99e Initial load
duke
parents:
diff changeset
334 __ fstp_d(Address(rsp, float_regs_as_doubles_off * BytesPerWord + 48));
a61af66fc99e Initial load
duke
parents:
diff changeset
335 __ fstp_d(Address(rsp, float_regs_as_doubles_off * BytesPerWord + 56));
a61af66fc99e Initial load
duke
parents:
diff changeset
336 }
a61af66fc99e Initial load
duke
parents:
diff changeset
337
a61af66fc99e Initial load
duke
parents:
diff changeset
338 if (UseSSE >= 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // save XMM registers
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // XMM registers can contain float or double values, but this is not known here,
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // so always save them as doubles.
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // note that float values are _not_ converted automatically, so for float values
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // the second word contains only garbage data.
a61af66fc99e Initial load
duke
parents:
diff changeset
344 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * wordSize + 0), xmm0);
a61af66fc99e Initial load
duke
parents:
diff changeset
345 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * wordSize + 8), xmm1);
a61af66fc99e Initial load
duke
parents:
diff changeset
346 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * wordSize + 16), xmm2);
a61af66fc99e Initial load
duke
parents:
diff changeset
347 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * wordSize + 24), xmm3);
a61af66fc99e Initial load
duke
parents:
diff changeset
348 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * wordSize + 32), xmm4);
a61af66fc99e Initial load
duke
parents:
diff changeset
349 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * wordSize + 40), xmm5);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * wordSize + 48), xmm6);
a61af66fc99e Initial load
duke
parents:
diff changeset
351 __ movdbl(Address(rsp, xmm_regs_as_doubles_off * wordSize + 56), xmm7);
a61af66fc99e Initial load
duke
parents:
diff changeset
352 } else if (UseSSE == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 // save XMM registers as float because double not supported without SSE2
a61af66fc99e Initial load
duke
parents:
diff changeset
354 __ movflt(Address(rsp, xmm_regs_as_doubles_off * wordSize + 0), xmm0);
a61af66fc99e Initial load
duke
parents:
diff changeset
355 __ movflt(Address(rsp, xmm_regs_as_doubles_off * wordSize + 8), xmm1);
a61af66fc99e Initial load
duke
parents:
diff changeset
356 __ movflt(Address(rsp, xmm_regs_as_doubles_off * wordSize + 16), xmm2);
a61af66fc99e Initial load
duke
parents:
diff changeset
357 __ movflt(Address(rsp, xmm_regs_as_doubles_off * wordSize + 24), xmm3);
a61af66fc99e Initial load
duke
parents:
diff changeset
358 __ movflt(Address(rsp, xmm_regs_as_doubles_off * wordSize + 32), xmm4);
a61af66fc99e Initial load
duke
parents:
diff changeset
359 __ movflt(Address(rsp, xmm_regs_as_doubles_off * wordSize + 40), xmm5);
a61af66fc99e Initial load
duke
parents:
diff changeset
360 __ movflt(Address(rsp, xmm_regs_as_doubles_off * wordSize + 48), xmm6);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 __ movflt(Address(rsp, xmm_regs_as_doubles_off * wordSize + 56), xmm7);
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 }
a61af66fc99e Initial load
duke
parents:
diff changeset
364
a61af66fc99e Initial load
duke
parents:
diff changeset
365 // FPU stack must be empty now
a61af66fc99e Initial load
duke
parents:
diff changeset
366 __ verify_FPU(0, "save_live_registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 return generate_oop_map(sasm, num_rt_args, save_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371
a61af66fc99e Initial load
duke
parents:
diff changeset
372 static void restore_fpu(StubAssembler* sasm, bool restore_fpu_registers = true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
373 if (restore_fpu_registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
374 if (UseSSE >= 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
375 // restore XMM registers
a61af66fc99e Initial load
duke
parents:
diff changeset
376 __ movdbl(xmm0, Address(rsp, xmm_regs_as_doubles_off * wordSize + 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
377 __ movdbl(xmm1, Address(rsp, xmm_regs_as_doubles_off * wordSize + 8));
a61af66fc99e Initial load
duke
parents:
diff changeset
378 __ movdbl(xmm2, Address(rsp, xmm_regs_as_doubles_off * wordSize + 16));
a61af66fc99e Initial load
duke
parents:
diff changeset
379 __ movdbl(xmm3, Address(rsp, xmm_regs_as_doubles_off * wordSize + 24));
a61af66fc99e Initial load
duke
parents:
diff changeset
380 __ movdbl(xmm4, Address(rsp, xmm_regs_as_doubles_off * wordSize + 32));
a61af66fc99e Initial load
duke
parents:
diff changeset
381 __ movdbl(xmm5, Address(rsp, xmm_regs_as_doubles_off * wordSize + 40));
a61af66fc99e Initial load
duke
parents:
diff changeset
382 __ movdbl(xmm6, Address(rsp, xmm_regs_as_doubles_off * wordSize + 48));
a61af66fc99e Initial load
duke
parents:
diff changeset
383 __ movdbl(xmm7, Address(rsp, xmm_regs_as_doubles_off * wordSize + 56));
a61af66fc99e Initial load
duke
parents:
diff changeset
384 } else if (UseSSE == 1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
385 // restore XMM registers
a61af66fc99e Initial load
duke
parents:
diff changeset
386 __ movflt(xmm0, Address(rsp, xmm_regs_as_doubles_off * wordSize + 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
387 __ movflt(xmm1, Address(rsp, xmm_regs_as_doubles_off * wordSize + 8));
a61af66fc99e Initial load
duke
parents:
diff changeset
388 __ movflt(xmm2, Address(rsp, xmm_regs_as_doubles_off * wordSize + 16));
a61af66fc99e Initial load
duke
parents:
diff changeset
389 __ movflt(xmm3, Address(rsp, xmm_regs_as_doubles_off * wordSize + 24));
a61af66fc99e Initial load
duke
parents:
diff changeset
390 __ movflt(xmm4, Address(rsp, xmm_regs_as_doubles_off * wordSize + 32));
a61af66fc99e Initial load
duke
parents:
diff changeset
391 __ movflt(xmm5, Address(rsp, xmm_regs_as_doubles_off * wordSize + 40));
a61af66fc99e Initial load
duke
parents:
diff changeset
392 __ movflt(xmm6, Address(rsp, xmm_regs_as_doubles_off * wordSize + 48));
a61af66fc99e Initial load
duke
parents:
diff changeset
393 __ movflt(xmm7, Address(rsp, xmm_regs_as_doubles_off * wordSize + 56));
a61af66fc99e Initial load
duke
parents:
diff changeset
394 }
a61af66fc99e Initial load
duke
parents:
diff changeset
395
a61af66fc99e Initial load
duke
parents:
diff changeset
396 if (UseSSE < 2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
397 __ frstor(Address(rsp, fpu_state_off * wordSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
398 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 // check that FPU stack is really empty
a61af66fc99e Initial load
duke
parents:
diff changeset
400 __ verify_FPU(0, "restore_live_registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }
a61af66fc99e Initial load
duke
parents:
diff changeset
402
a61af66fc99e Initial load
duke
parents:
diff changeset
403 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
404 // check that FPU stack is really empty
a61af66fc99e Initial load
duke
parents:
diff changeset
405 __ verify_FPU(0, "restore_live_registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
406 }
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
409 {
a61af66fc99e Initial load
duke
parents:
diff changeset
410 Label ok;
a61af66fc99e Initial load
duke
parents:
diff changeset
411 __ cmpl(Address(rsp, marker * wordSize), 0xfeedbeef);
a61af66fc99e Initial load
duke
parents:
diff changeset
412 __ jcc(Assembler::equal, ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
413 __ stop("bad offsets in frame");
a61af66fc99e Initial load
duke
parents:
diff changeset
414 __ bind(ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
415 }
a61af66fc99e Initial load
duke
parents:
diff changeset
416 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
417
a61af66fc99e Initial load
duke
parents:
diff changeset
418 __ addl(rsp, extra_space_offset * wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420
a61af66fc99e Initial load
duke
parents:
diff changeset
421
a61af66fc99e Initial load
duke
parents:
diff changeset
422 static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
423 __ block_comment("restore_live_registers");
a61af66fc99e Initial load
duke
parents:
diff changeset
424
a61af66fc99e Initial load
duke
parents:
diff changeset
425 restore_fpu(sasm, restore_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
426 __ popad();
a61af66fc99e Initial load
duke
parents:
diff changeset
427 }
a61af66fc99e Initial load
duke
parents:
diff changeset
428
a61af66fc99e Initial load
duke
parents:
diff changeset
429
a61af66fc99e Initial load
duke
parents:
diff changeset
430 static void restore_live_registers_except_rax(StubAssembler* sasm, bool restore_fpu_registers = true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
431 __ block_comment("restore_live_registers_except_rax");
a61af66fc99e Initial load
duke
parents:
diff changeset
432
a61af66fc99e Initial load
duke
parents:
diff changeset
433 restore_fpu(sasm, restore_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
434
a61af66fc99e Initial load
duke
parents:
diff changeset
435 __ popl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
436 __ popl(rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
437 __ popl(rbp);
a61af66fc99e Initial load
duke
parents:
diff changeset
438 __ popl(rbx); // skip this value
a61af66fc99e Initial load
duke
parents:
diff changeset
439 __ popl(rbx);
a61af66fc99e Initial load
duke
parents:
diff changeset
440 __ popl(rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
441 __ popl(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 __ addl(rsp, 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
443 }
a61af66fc99e Initial load
duke
parents:
diff changeset
444
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 void Runtime1::initialize_pd() {
a61af66fc99e Initial load
duke
parents:
diff changeset
447 // nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
448 }
a61af66fc99e Initial load
duke
parents:
diff changeset
449
a61af66fc99e Initial load
duke
parents:
diff changeset
450
a61af66fc99e Initial load
duke
parents:
diff changeset
451 // target: the entry point of the method that creates and posts the exception oop
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // has_argument: true if the exception needs an argument (passed on stack because registers must be preserved)
a61af66fc99e Initial load
duke
parents:
diff changeset
453
a61af66fc99e Initial load
duke
parents:
diff changeset
454 OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) {
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // preserve all registers
a61af66fc99e Initial load
duke
parents:
diff changeset
456 int num_rt_args = has_argument ? 2 : 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
457 OopMap* oop_map = save_live_registers(sasm, num_rt_args);
a61af66fc99e Initial load
duke
parents:
diff changeset
458
a61af66fc99e Initial load
duke
parents:
diff changeset
459 // now all registers are saved and can be used freely
a61af66fc99e Initial load
duke
parents:
diff changeset
460 // verify that no old value is used accidentally
a61af66fc99e Initial load
duke
parents:
diff changeset
461 __ invalidate_registers(true, true, true, true, true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
462
a61af66fc99e Initial load
duke
parents:
diff changeset
463 // registers used by this stub
a61af66fc99e Initial load
duke
parents:
diff changeset
464 const Register temp_reg = rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
465
a61af66fc99e Initial load
duke
parents:
diff changeset
466 // load argument for exception that is passed as an argument into the stub
a61af66fc99e Initial load
duke
parents:
diff changeset
467 if (has_argument) {
a61af66fc99e Initial load
duke
parents:
diff changeset
468 __ movl(temp_reg, Address(rbp, 2*BytesPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
469 __ pushl(temp_reg);
a61af66fc99e Initial load
duke
parents:
diff changeset
470 }
a61af66fc99e Initial load
duke
parents:
diff changeset
471
a61af66fc99e Initial load
duke
parents:
diff changeset
472 int call_offset = __ call_RT(noreg, noreg, target, num_rt_args - 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
473
a61af66fc99e Initial load
duke
parents:
diff changeset
474 OopMapSet* oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
475 oop_maps->add_gc_map(call_offset, oop_map);
a61af66fc99e Initial load
duke
parents:
diff changeset
476
a61af66fc99e Initial load
duke
parents:
diff changeset
477 __ stop("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
478
a61af66fc99e Initial load
duke
parents:
diff changeset
479 return oop_maps;
a61af66fc99e Initial load
duke
parents:
diff changeset
480 }
a61af66fc99e Initial load
duke
parents:
diff changeset
481
a61af66fc99e Initial load
duke
parents:
diff changeset
482
a61af66fc99e Initial load
duke
parents:
diff changeset
483 void Runtime1::generate_handle_exception(StubAssembler *sasm, OopMapSet* oop_maps, OopMap* oop_map, bool save_fpu_registers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
484 // incoming parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
485 const Register exception_oop = rax;
a61af66fc99e Initial load
duke
parents:
diff changeset
486 const Register exception_pc = rdx;
a61af66fc99e Initial load
duke
parents:
diff changeset
487 // other registers used in this stub
a61af66fc99e Initial load
duke
parents:
diff changeset
488 const Register real_return_addr = rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
489 const Register thread = rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
490
a61af66fc99e Initial load
duke
parents:
diff changeset
491 __ block_comment("generate_handle_exception");
a61af66fc99e Initial load
duke
parents:
diff changeset
492
a61af66fc99e Initial load
duke
parents:
diff changeset
493 #ifdef TIERED
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // C2 can leave the fpu stack dirty
a61af66fc99e Initial load
duke
parents:
diff changeset
495 if (UseSSE < 2 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
496 __ empty_FPU_stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498 #endif // TIERED
a61af66fc99e Initial load
duke
parents:
diff changeset
499
a61af66fc99e Initial load
duke
parents:
diff changeset
500 // verify that only rax, and rdx is valid at this time
a61af66fc99e Initial load
duke
parents:
diff changeset
501 __ invalidate_registers(false, true, true, false, true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // verify that rax, contains a valid exception
a61af66fc99e Initial load
duke
parents:
diff changeset
503 __ verify_not_null_oop(exception_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
504
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // load address of JavaThread object for thread-local data
a61af66fc99e Initial load
duke
parents:
diff changeset
506 __ get_thread(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
507
a61af66fc99e Initial load
duke
parents:
diff changeset
508 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // check that fields in JavaThread for exception oop and issuing pc are
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // empty before writing to them
a61af66fc99e Initial load
duke
parents:
diff changeset
511 Label oop_empty;
a61af66fc99e Initial load
duke
parents:
diff changeset
512 __ cmpl(Address(thread, JavaThread::exception_oop_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
513 __ jcc(Assembler::equal, oop_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
514 __ stop("exception oop already set");
a61af66fc99e Initial load
duke
parents:
diff changeset
515 __ bind(oop_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
516
a61af66fc99e Initial load
duke
parents:
diff changeset
517 Label pc_empty;
a61af66fc99e Initial load
duke
parents:
diff changeset
518 __ cmpl(Address(thread, JavaThread::exception_pc_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
519 __ jcc(Assembler::equal, pc_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
520 __ stop("exception pc already set");
a61af66fc99e Initial load
duke
parents:
diff changeset
521 __ bind(pc_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
522 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
523
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // save exception oop and issuing pc into JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // (exception handler will load it from here)
a61af66fc99e Initial load
duke
parents:
diff changeset
526 __ movl(Address(thread, JavaThread::exception_oop_offset()), exception_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
527 __ movl(Address(thread, JavaThread::exception_pc_offset()), exception_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
528
a61af66fc99e Initial load
duke
parents:
diff changeset
529 // save real return address (pc that called this stub)
a61af66fc99e Initial load
duke
parents:
diff changeset
530 __ movl(real_return_addr, Address(rbp, 1*BytesPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
531 __ movl(Address(rsp, temp_1_off * BytesPerWord), real_return_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
532
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // patch throwing pc into return address (has bci & oop map)
a61af66fc99e Initial load
duke
parents:
diff changeset
534 __ movl(Address(rbp, 1*BytesPerWord), exception_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // compute the exception handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // the exception oop and the throwing pc are read from the fields in JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
538 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc));
a61af66fc99e Initial load
duke
parents:
diff changeset
539 oop_maps->add_gc_map(call_offset, oop_map);
a61af66fc99e Initial load
duke
parents:
diff changeset
540
a61af66fc99e Initial load
duke
parents:
diff changeset
541 // rax,: handler address or NULL if no handler exists
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // will be the deopt blob if nmethod was deoptimized while we looked up
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // handler regardless of whether handler existed in the nmethod.
a61af66fc99e Initial load
duke
parents:
diff changeset
544
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // only rax, is valid at this time, all other registers have been destroyed by the runtime call
a61af66fc99e Initial load
duke
parents:
diff changeset
546 __ invalidate_registers(false, true, true, true, true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 // Do we have an exception handler in the nmethod?
a61af66fc99e Initial load
duke
parents:
diff changeset
549 Label no_handler;
a61af66fc99e Initial load
duke
parents:
diff changeset
550 Label done;
a61af66fc99e Initial load
duke
parents:
diff changeset
551 __ testl(rax, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
552 __ jcc(Assembler::zero, no_handler);
a61af66fc99e Initial load
duke
parents:
diff changeset
553
a61af66fc99e Initial load
duke
parents:
diff changeset
554 // exception handler found
a61af66fc99e Initial load
duke
parents:
diff changeset
555 // patch the return address -> the stub will directly return to the exception handler
a61af66fc99e Initial load
duke
parents:
diff changeset
556 __ movl(Address(rbp, 1*BytesPerWord), rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 // restore registers
a61af66fc99e Initial load
duke
parents:
diff changeset
559 restore_live_registers(sasm, save_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
560
a61af66fc99e Initial load
duke
parents:
diff changeset
561 // return to exception handler
a61af66fc99e Initial load
duke
parents:
diff changeset
562 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
563 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
564
a61af66fc99e Initial load
duke
parents:
diff changeset
565 __ bind(no_handler);
a61af66fc99e Initial load
duke
parents:
diff changeset
566 // no exception handler found in this method, so the exception is
a61af66fc99e Initial load
duke
parents:
diff changeset
567 // forwarded to the caller (using the unwind code of the nmethod)
a61af66fc99e Initial load
duke
parents:
diff changeset
568 // there is no need to restore the registers
a61af66fc99e Initial load
duke
parents:
diff changeset
569
a61af66fc99e Initial load
duke
parents:
diff changeset
570 // restore the real return address that was saved before the RT-call
a61af66fc99e Initial load
duke
parents:
diff changeset
571 __ movl(real_return_addr, Address(rsp, temp_1_off * BytesPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
572 __ movl(Address(rbp, 1*BytesPerWord), real_return_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
573
a61af66fc99e Initial load
duke
parents:
diff changeset
574 // load address of JavaThread object for thread-local data
a61af66fc99e Initial load
duke
parents:
diff changeset
575 __ get_thread(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
576 // restore exception oop into rax, (convention for unwind code)
a61af66fc99e Initial load
duke
parents:
diff changeset
577 __ movl(exception_oop, Address(thread, JavaThread::exception_oop_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
578
a61af66fc99e Initial load
duke
parents:
diff changeset
579 // clear exception fields in JavaThread because they are no longer needed
a61af66fc99e Initial load
duke
parents:
diff changeset
580 // (fields must be cleared because they are processed by GC otherwise)
a61af66fc99e Initial load
duke
parents:
diff changeset
581 __ movl(Address(thread, JavaThread::exception_oop_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 __ movl(Address(thread, JavaThread::exception_pc_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
583
a61af66fc99e Initial load
duke
parents:
diff changeset
584 // pop the stub frame off
a61af66fc99e Initial load
duke
parents:
diff changeset
585 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
586
a61af66fc99e Initial load
duke
parents:
diff changeset
587 generate_unwind_exception(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
588 __ stop("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
590
a61af66fc99e Initial load
duke
parents:
diff changeset
591
a61af66fc99e Initial load
duke
parents:
diff changeset
592 void Runtime1::generate_unwind_exception(StubAssembler *sasm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
593 // incoming parameters
a61af66fc99e Initial load
duke
parents:
diff changeset
594 const Register exception_oop = rax;
a61af66fc99e Initial load
duke
parents:
diff changeset
595 // other registers used in this stub
a61af66fc99e Initial load
duke
parents:
diff changeset
596 const Register exception_pc = rdx;
a61af66fc99e Initial load
duke
parents:
diff changeset
597 const Register handler_addr = rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
598 const Register thread = rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
599
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // verify that only rax, is valid at this time
a61af66fc99e Initial load
duke
parents:
diff changeset
601 __ invalidate_registers(false, true, true, true, true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
602
a61af66fc99e Initial load
duke
parents:
diff changeset
603 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
604 // check that fields in JavaThread for exception oop and issuing pc are empty
a61af66fc99e Initial load
duke
parents:
diff changeset
605 __ get_thread(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
606 Label oop_empty;
a61af66fc99e Initial load
duke
parents:
diff changeset
607 __ cmpl(Address(thread, JavaThread::exception_oop_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
608 __ jcc(Assembler::equal, oop_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
609 __ stop("exception oop must be empty");
a61af66fc99e Initial load
duke
parents:
diff changeset
610 __ bind(oop_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
611
a61af66fc99e Initial load
duke
parents:
diff changeset
612 Label pc_empty;
a61af66fc99e Initial load
duke
parents:
diff changeset
613 __ cmpl(Address(thread, JavaThread::exception_pc_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
614 __ jcc(Assembler::equal, pc_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
615 __ stop("exception pc must be empty");
a61af66fc99e Initial load
duke
parents:
diff changeset
616 __ bind(pc_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
617 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
618
a61af66fc99e Initial load
duke
parents:
diff changeset
619 // clear the FPU stack in case any FPU results are left behind
a61af66fc99e Initial load
duke
parents:
diff changeset
620 __ empty_FPU_stack();
a61af66fc99e Initial load
duke
parents:
diff changeset
621
a61af66fc99e Initial load
duke
parents:
diff changeset
622 // leave activation of nmethod
a61af66fc99e Initial load
duke
parents:
diff changeset
623 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // store return address (is on top of stack after leave)
a61af66fc99e Initial load
duke
parents:
diff changeset
625 __ movl(exception_pc, Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
626
a61af66fc99e Initial load
duke
parents:
diff changeset
627 __ verify_oop(exception_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
628
a61af66fc99e Initial load
duke
parents:
diff changeset
629 // save exception oop from rax, to stack before call
a61af66fc99e Initial load
duke
parents:
diff changeset
630 __ pushl(exception_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
631
a61af66fc99e Initial load
duke
parents:
diff changeset
632 // search the exception handler address of the caller (using the return address)
a61af66fc99e Initial load
duke
parents:
diff changeset
633 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), exception_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
634 // rax,: exception handler address of the caller
a61af66fc99e Initial load
duke
parents:
diff changeset
635
a61af66fc99e Initial load
duke
parents:
diff changeset
636 // only rax, is valid at this time, all other registers have been destroyed by the call
a61af66fc99e Initial load
duke
parents:
diff changeset
637 __ invalidate_registers(false, true, true, true, true, true);
a61af66fc99e Initial load
duke
parents:
diff changeset
638
a61af66fc99e Initial load
duke
parents:
diff changeset
639 // move result of call into correct register
a61af66fc99e Initial load
duke
parents:
diff changeset
640 __ movl(handler_addr, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
641
a61af66fc99e Initial load
duke
parents:
diff changeset
642 // restore exception oop in rax, (required convention of exception handler)
a61af66fc99e Initial load
duke
parents:
diff changeset
643 __ popl(exception_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
644
a61af66fc99e Initial load
duke
parents:
diff changeset
645 __ verify_oop(exception_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
646
a61af66fc99e Initial load
duke
parents:
diff changeset
647 // get throwing pc (= return address).
a61af66fc99e Initial load
duke
parents:
diff changeset
648 // rdx has been destroyed by the call, so it must be set again
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // the pop is also necessary to simulate the effect of a ret(0)
a61af66fc99e Initial load
duke
parents:
diff changeset
650 __ popl(exception_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
651
a61af66fc99e Initial load
duke
parents:
diff changeset
652 // verify that that there is really a valid exception in rax,
a61af66fc99e Initial load
duke
parents:
diff changeset
653 __ verify_not_null_oop(exception_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
654
a61af66fc99e Initial load
duke
parents:
diff changeset
655 // continue at exception handler (return address removed)
a61af66fc99e Initial load
duke
parents:
diff changeset
656 // note: do *not* remove arguments when unwinding the
a61af66fc99e Initial load
duke
parents:
diff changeset
657 // activation since the caller assumes having
a61af66fc99e Initial load
duke
parents:
diff changeset
658 // all arguments on the stack when entering the
a61af66fc99e Initial load
duke
parents:
diff changeset
659 // runtime to determine the exception handler
a61af66fc99e Initial load
duke
parents:
diff changeset
660 // (GC happens at call site with arguments!)
a61af66fc99e Initial load
duke
parents:
diff changeset
661 // rax,: exception oop
a61af66fc99e Initial load
duke
parents:
diff changeset
662 // rdx: throwing pc
a61af66fc99e Initial load
duke
parents:
diff changeset
663 // rbx,: exception handler
a61af66fc99e Initial load
duke
parents:
diff changeset
664 __ jmp(handler_addr);
a61af66fc99e Initial load
duke
parents:
diff changeset
665 }
a61af66fc99e Initial load
duke
parents:
diff changeset
666
a61af66fc99e Initial load
duke
parents:
diff changeset
667
a61af66fc99e Initial load
duke
parents:
diff changeset
668 OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) {
a61af66fc99e Initial load
duke
parents:
diff changeset
669 // use the maximum number of runtime-arguments here because it is difficult to
a61af66fc99e Initial load
duke
parents:
diff changeset
670 // distinguish each RT-Call.
a61af66fc99e Initial load
duke
parents:
diff changeset
671 // Note: This number affects also the RT-Call in generate_handle_exception because
a61af66fc99e Initial load
duke
parents:
diff changeset
672 // the oop-map is shared for all calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
673 const int num_rt_args = 2; // thread + dummy
a61af66fc99e Initial load
duke
parents:
diff changeset
674
a61af66fc99e Initial load
duke
parents:
diff changeset
675 DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob();
a61af66fc99e Initial load
duke
parents:
diff changeset
676 assert(deopt_blob != NULL, "deoptimization blob must have been created");
a61af66fc99e Initial load
duke
parents:
diff changeset
677
a61af66fc99e Initial load
duke
parents:
diff changeset
678 OopMap* oop_map = save_live_registers(sasm, num_rt_args);
a61af66fc99e Initial load
duke
parents:
diff changeset
679
a61af66fc99e Initial load
duke
parents:
diff changeset
680 __ pushl(rax); // push dummy
a61af66fc99e Initial load
duke
parents:
diff changeset
681
a61af66fc99e Initial load
duke
parents:
diff changeset
682 const Register thread = rdi; // is callee-saved register (Visual C++ calling conventions)
a61af66fc99e Initial load
duke
parents:
diff changeset
683 // push java thread (becomes first argument of C function)
a61af66fc99e Initial load
duke
parents:
diff changeset
684 __ get_thread(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
685 __ pushl(thread);
a61af66fc99e Initial load
duke
parents:
diff changeset
686 __ set_last_Java_frame(thread, noreg, rbp, NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
687 // do the call
a61af66fc99e Initial load
duke
parents:
diff changeset
688 __ call(RuntimeAddress(target));
a61af66fc99e Initial load
duke
parents:
diff changeset
689 OopMapSet* oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
690 oop_maps->add_gc_map(__ offset(), oop_map);
a61af66fc99e Initial load
duke
parents:
diff changeset
691 // verify callee-saved register
a61af66fc99e Initial load
duke
parents:
diff changeset
692 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
693 guarantee(thread != rax, "change this code");
a61af66fc99e Initial load
duke
parents:
diff changeset
694 __ pushl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
695 { Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
696 __ get_thread(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
697 __ cmpl(thread, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
698 __ jcc(Assembler::equal, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
699 __ stop("StubAssembler::call_RT: rdi not callee saved?");
a61af66fc99e Initial load
duke
parents:
diff changeset
700 __ bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
701 }
a61af66fc99e Initial load
duke
parents:
diff changeset
702 __ popl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
703 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
704 __ reset_last_Java_frame(thread, true, false);
a61af66fc99e Initial load
duke
parents:
diff changeset
705 __ popl(rcx); // discard thread arg
a61af66fc99e Initial load
duke
parents:
diff changeset
706 __ popl(rcx); // discard dummy
a61af66fc99e Initial load
duke
parents:
diff changeset
707
a61af66fc99e Initial load
duke
parents:
diff changeset
708 // check for pending exceptions
a61af66fc99e Initial load
duke
parents:
diff changeset
709 { Label L;
a61af66fc99e Initial load
duke
parents:
diff changeset
710 __ cmpl(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
711 __ jcc(Assembler::equal, L);
a61af66fc99e Initial load
duke
parents:
diff changeset
712 // exception pending => remove activation and forward to exception handler
a61af66fc99e Initial load
duke
parents:
diff changeset
713
a61af66fc99e Initial load
duke
parents:
diff changeset
714 __ testl(rax, rax); // have we deoptimized?
a61af66fc99e Initial load
duke
parents:
diff changeset
715 __ jump_cc(Assembler::equal,
a61af66fc99e Initial load
duke
parents:
diff changeset
716 RuntimeAddress(Runtime1::entry_for(Runtime1::forward_exception_id)));
a61af66fc99e Initial load
duke
parents:
diff changeset
717
a61af66fc99e Initial load
duke
parents:
diff changeset
718 // the deopt blob expects exceptions in the special fields of
a61af66fc99e Initial load
duke
parents:
diff changeset
719 // JavaThread, so copy and clear pending exception.
a61af66fc99e Initial load
duke
parents:
diff changeset
720
a61af66fc99e Initial load
duke
parents:
diff changeset
721 // load and clear pending exception
a61af66fc99e Initial load
duke
parents:
diff changeset
722 __ movl(rax, Address(thread, Thread::pending_exception_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
723 __ movl(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
724
a61af66fc99e Initial load
duke
parents:
diff changeset
725 // check that there is really a valid exception
a61af66fc99e Initial load
duke
parents:
diff changeset
726 __ verify_not_null_oop(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
727
a61af66fc99e Initial load
duke
parents:
diff changeset
728 // load throwing pc: this is the return address of the stub
a61af66fc99e Initial load
duke
parents:
diff changeset
729 __ movl(rdx, Address(rsp, return_off * BytesPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
730
a61af66fc99e Initial load
duke
parents:
diff changeset
731 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
732 // check that fields in JavaThread for exception oop and issuing pc are empty
a61af66fc99e Initial load
duke
parents:
diff changeset
733 Label oop_empty;
a61af66fc99e Initial load
duke
parents:
diff changeset
734 __ cmpoop(Address(thread, JavaThread::exception_oop_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
735 __ jcc(Assembler::equal, oop_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
736 __ stop("exception oop must be empty");
a61af66fc99e Initial load
duke
parents:
diff changeset
737 __ bind(oop_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
738
a61af66fc99e Initial load
duke
parents:
diff changeset
739 Label pc_empty;
a61af66fc99e Initial load
duke
parents:
diff changeset
740 __ cmpl(Address(thread, JavaThread::exception_pc_offset()), 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
741 __ jcc(Assembler::equal, pc_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
742 __ stop("exception pc must be empty");
a61af66fc99e Initial load
duke
parents:
diff changeset
743 __ bind(pc_empty);
a61af66fc99e Initial load
duke
parents:
diff changeset
744 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
745
a61af66fc99e Initial load
duke
parents:
diff changeset
746 // store exception oop and throwing pc to JavaThread
a61af66fc99e Initial load
duke
parents:
diff changeset
747 __ movl(Address(thread, JavaThread::exception_oop_offset()), rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
748 __ movl(Address(thread, JavaThread::exception_pc_offset()), rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
749
a61af66fc99e Initial load
duke
parents:
diff changeset
750 restore_live_registers(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
751
a61af66fc99e Initial load
duke
parents:
diff changeset
752 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
753 __ addl(rsp, 4); // remove return address from stack
a61af66fc99e Initial load
duke
parents:
diff changeset
754
a61af66fc99e Initial load
duke
parents:
diff changeset
755 // Forward the exception directly to deopt blob. We can blow no
a61af66fc99e Initial load
duke
parents:
diff changeset
756 // registers and must leave throwing pc on the stack. A patch may
a61af66fc99e Initial load
duke
parents:
diff changeset
757 // have values live in registers so the entry point with the
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // exception in tls.
a61af66fc99e Initial load
duke
parents:
diff changeset
759 __ jump(RuntimeAddress(deopt_blob->unpack_with_exception_in_tls()));
a61af66fc99e Initial load
duke
parents:
diff changeset
760
a61af66fc99e Initial load
duke
parents:
diff changeset
761 __ bind(L);
a61af66fc99e Initial load
duke
parents:
diff changeset
762 }
a61af66fc99e Initial load
duke
parents:
diff changeset
763
a61af66fc99e Initial load
duke
parents:
diff changeset
764
a61af66fc99e Initial load
duke
parents:
diff changeset
765 // Runtime will return true if the nmethod has been deoptimized during
a61af66fc99e Initial load
duke
parents:
diff changeset
766 // the patching process. In that case we must do a deopt reexecute instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
767
a61af66fc99e Initial load
duke
parents:
diff changeset
768 Label reexecuteEntry, cont;
a61af66fc99e Initial load
duke
parents:
diff changeset
769
a61af66fc99e Initial load
duke
parents:
diff changeset
770 __ testl(rax, rax); // have we deoptimized?
a61af66fc99e Initial load
duke
parents:
diff changeset
771 __ jcc(Assembler::equal, cont); // no
a61af66fc99e Initial load
duke
parents:
diff changeset
772
a61af66fc99e Initial load
duke
parents:
diff changeset
773 // Will reexecute. Proper return address is already on the stack we just restore
a61af66fc99e Initial load
duke
parents:
diff changeset
774 // registers, pop all of our frame but the return address and jump to the deopt blob
a61af66fc99e Initial load
duke
parents:
diff changeset
775 restore_live_registers(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
776 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
777 __ jump(RuntimeAddress(deopt_blob->unpack_with_reexecution()));
a61af66fc99e Initial load
duke
parents:
diff changeset
778
a61af66fc99e Initial load
duke
parents:
diff changeset
779 __ bind(cont);
a61af66fc99e Initial load
duke
parents:
diff changeset
780 restore_live_registers(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
781 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
782 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
783
a61af66fc99e Initial load
duke
parents:
diff changeset
784 return oop_maps;
a61af66fc99e Initial load
duke
parents:
diff changeset
785
a61af66fc99e Initial load
duke
parents:
diff changeset
786 }
a61af66fc99e Initial load
duke
parents:
diff changeset
787
a61af66fc99e Initial load
duke
parents:
diff changeset
788
a61af66fc99e Initial load
duke
parents:
diff changeset
789 OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
790
a61af66fc99e Initial load
duke
parents:
diff changeset
791 // for better readability
a61af66fc99e Initial load
duke
parents:
diff changeset
792 const bool must_gc_arguments = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
793 const bool dont_gc_arguments = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
794
a61af66fc99e Initial load
duke
parents:
diff changeset
795 // default value; overwritten for some optimized stubs that are called from methods that do not use the fpu
a61af66fc99e Initial load
duke
parents:
diff changeset
796 bool save_fpu_registers = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
797
a61af66fc99e Initial load
duke
parents:
diff changeset
798 // stub code & info for the different stubs
a61af66fc99e Initial load
duke
parents:
diff changeset
799 OopMapSet* oop_maps = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
800 switch (id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
801 case forward_exception_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
802 {
a61af66fc99e Initial load
duke
parents:
diff changeset
803 // we're handling an exception in the context of a compiled
a61af66fc99e Initial load
duke
parents:
diff changeset
804 // frame. The registers have been saved in the standard
a61af66fc99e Initial load
duke
parents:
diff changeset
805 // places. Perform an exception lookup in the caller and
a61af66fc99e Initial load
duke
parents:
diff changeset
806 // dispatch to the handler if found. Otherwise unwind and
a61af66fc99e Initial load
duke
parents:
diff changeset
807 // dispatch to the callers exception handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
808
a61af66fc99e Initial load
duke
parents:
diff changeset
809 const Register thread = rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
810 const Register exception_oop = rax;
a61af66fc99e Initial load
duke
parents:
diff changeset
811 const Register exception_pc = rdx;
a61af66fc99e Initial load
duke
parents:
diff changeset
812
a61af66fc99e Initial load
duke
parents:
diff changeset
813 // load pending exception oop into rax,
a61af66fc99e Initial load
duke
parents:
diff changeset
814 __ movl(exception_oop, Address(thread, Thread::pending_exception_offset()));
a61af66fc99e Initial load
duke
parents:
diff changeset
815 // clear pending exception
a61af66fc99e Initial load
duke
parents:
diff changeset
816 __ movl(Address(thread, Thread::pending_exception_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
817
a61af66fc99e Initial load
duke
parents:
diff changeset
818 // load issuing PC (the return address for this stub) into rdx
a61af66fc99e Initial load
duke
parents:
diff changeset
819 __ movl(exception_pc, Address(rbp, 1*BytesPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
820
a61af66fc99e Initial load
duke
parents:
diff changeset
821 // make sure that the vm_results are cleared (may be unnecessary)
a61af66fc99e Initial load
duke
parents:
diff changeset
822 __ movl(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
823 __ movl(Address(thread, JavaThread::vm_result_2_offset()), NULL_WORD);
a61af66fc99e Initial load
duke
parents:
diff changeset
824
a61af66fc99e Initial load
duke
parents:
diff changeset
825 // verify that that there is really a valid exception in rax,
a61af66fc99e Initial load
duke
parents:
diff changeset
826 __ verify_not_null_oop(exception_oop);
a61af66fc99e Initial load
duke
parents:
diff changeset
827
a61af66fc99e Initial load
duke
parents:
diff changeset
828
a61af66fc99e Initial load
duke
parents:
diff changeset
829 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
830 OopMap* oop_map = generate_oop_map(sasm, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
831 generate_handle_exception(sasm, oop_maps, oop_map);
a61af66fc99e Initial load
duke
parents:
diff changeset
832 __ stop("should not reach here");
a61af66fc99e Initial load
duke
parents:
diff changeset
833 }
a61af66fc99e Initial load
duke
parents:
diff changeset
834 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
835
a61af66fc99e Initial load
duke
parents:
diff changeset
836 case new_instance_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
837 case fast_new_instance_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
838 case fast_new_instance_init_check_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
839 {
a61af66fc99e Initial load
duke
parents:
diff changeset
840 Register klass = rdx; // Incoming
a61af66fc99e Initial load
duke
parents:
diff changeset
841 Register obj = rax; // Result
a61af66fc99e Initial load
duke
parents:
diff changeset
842
a61af66fc99e Initial load
duke
parents:
diff changeset
843 if (id == new_instance_id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
844 __ set_info("new_instance", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
845 } else if (id == fast_new_instance_id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
846 __ set_info("fast new_instance", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
847 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
848 assert(id == fast_new_instance_init_check_id, "bad StubID");
a61af66fc99e Initial load
duke
parents:
diff changeset
849 __ set_info("fast new_instance init check", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
850 }
a61af66fc99e Initial load
duke
parents:
diff changeset
851
a61af66fc99e Initial load
duke
parents:
diff changeset
852 if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
853 UseTLAB && FastTLABRefill) {
a61af66fc99e Initial load
duke
parents:
diff changeset
854 Label slow_path;
a61af66fc99e Initial load
duke
parents:
diff changeset
855 Register obj_size = rcx;
a61af66fc99e Initial load
duke
parents:
diff changeset
856 Register t1 = rbx;
a61af66fc99e Initial load
duke
parents:
diff changeset
857 Register t2 = rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
858 assert_different_registers(klass, obj, obj_size, t1, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
859
a61af66fc99e Initial load
duke
parents:
diff changeset
860 __ pushl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
861 __ pushl(rbx);
a61af66fc99e Initial load
duke
parents:
diff changeset
862
a61af66fc99e Initial load
duke
parents:
diff changeset
863 if (id == fast_new_instance_init_check_id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
864 // make sure the klass is initialized
a61af66fc99e Initial load
duke
parents:
diff changeset
865 __ cmpl(Address(klass, instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc)), instanceKlass::fully_initialized);
a61af66fc99e Initial load
duke
parents:
diff changeset
866 __ jcc(Assembler::notEqual, slow_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
867 }
a61af66fc99e Initial load
duke
parents:
diff changeset
868
a61af66fc99e Initial load
duke
parents:
diff changeset
869 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
870 // assert object can be fast path allocated
a61af66fc99e Initial load
duke
parents:
diff changeset
871 {
a61af66fc99e Initial load
duke
parents:
diff changeset
872 Label ok, not_ok;
a61af66fc99e Initial load
duke
parents:
diff changeset
873 __ movl(obj_size, Address(klass, Klass::layout_helper_offset_in_bytes() + sizeof(oopDesc)));
a61af66fc99e Initial load
duke
parents:
diff changeset
874 __ cmpl(obj_size, 0); // make sure it's an instance (LH > 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
875 __ jcc(Assembler::lessEqual, not_ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
876 __ testl(obj_size, Klass::_lh_instance_slow_path_bit);
a61af66fc99e Initial load
duke
parents:
diff changeset
877 __ jcc(Assembler::zero, ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
878 __ bind(not_ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
879 __ stop("assert(can be fast path allocated)");
a61af66fc99e Initial load
duke
parents:
diff changeset
880 __ should_not_reach_here();
a61af66fc99e Initial load
duke
parents:
diff changeset
881 __ bind(ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
882 }
a61af66fc99e Initial load
duke
parents:
diff changeset
883 #endif // ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
884
a61af66fc99e Initial load
duke
parents:
diff changeset
885 // if we got here then the TLAB allocation failed, so try
a61af66fc99e Initial load
duke
parents:
diff changeset
886 // refilling the TLAB or allocating directly from eden.
a61af66fc99e Initial load
duke
parents:
diff changeset
887 Label retry_tlab, try_eden;
a61af66fc99e Initial load
duke
parents:
diff changeset
888 __ tlab_refill(retry_tlab, try_eden, slow_path); // does not destroy rdx (klass)
a61af66fc99e Initial load
duke
parents:
diff changeset
889
a61af66fc99e Initial load
duke
parents:
diff changeset
890 __ bind(retry_tlab);
a61af66fc99e Initial load
duke
parents:
diff changeset
891
a61af66fc99e Initial load
duke
parents:
diff changeset
892 // get the instance size
a61af66fc99e Initial load
duke
parents:
diff changeset
893 __ movl(obj_size, Address(klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
894 __ tlab_allocate(obj, obj_size, 0, t1, t2, slow_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
895 __ initialize_object(obj, klass, obj_size, 0, t1, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
896 __ verify_oop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
897 __ popl(rbx);
a61af66fc99e Initial load
duke
parents:
diff changeset
898 __ popl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
899 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
900
a61af66fc99e Initial load
duke
parents:
diff changeset
901 __ bind(try_eden);
a61af66fc99e Initial load
duke
parents:
diff changeset
902 // get the instance size
a61af66fc99e Initial load
duke
parents:
diff changeset
903 __ movl(obj_size, Address(klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
904 __ eden_allocate(obj, obj_size, 0, t1, slow_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
905 __ initialize_object(obj, klass, obj_size, 0, t1, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
906 __ verify_oop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
907 __ popl(rbx);
a61af66fc99e Initial load
duke
parents:
diff changeset
908 __ popl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
909 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
910
a61af66fc99e Initial load
duke
parents:
diff changeset
911 __ bind(slow_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
912 __ popl(rbx);
a61af66fc99e Initial load
duke
parents:
diff changeset
913 __ popl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
914 }
a61af66fc99e Initial load
duke
parents:
diff changeset
915
a61af66fc99e Initial load
duke
parents:
diff changeset
916 __ enter();
a61af66fc99e Initial load
duke
parents:
diff changeset
917 OopMap* map = save_live_registers(sasm, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
918 int call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_instance), klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
919 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
920 oop_maps->add_gc_map(call_offset, map);
a61af66fc99e Initial load
duke
parents:
diff changeset
921 restore_live_registers_except_rax(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
922 __ verify_oop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
923 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
924 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
925
a61af66fc99e Initial load
duke
parents:
diff changeset
926 // rax,: new instance
a61af66fc99e Initial load
duke
parents:
diff changeset
927 }
a61af66fc99e Initial load
duke
parents:
diff changeset
928
a61af66fc99e Initial load
duke
parents:
diff changeset
929 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
930
a61af66fc99e Initial load
duke
parents:
diff changeset
931 #ifdef TIERED
a61af66fc99e Initial load
duke
parents:
diff changeset
932 case counter_overflow_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
933 {
a61af66fc99e Initial load
duke
parents:
diff changeset
934 Register bci = rax;
a61af66fc99e Initial load
duke
parents:
diff changeset
935 __ enter();
a61af66fc99e Initial load
duke
parents:
diff changeset
936 OopMap* map = save_live_registers(sasm, 2);
a61af66fc99e Initial load
duke
parents:
diff changeset
937 // Retrieve bci
a61af66fc99e Initial load
duke
parents:
diff changeset
938 __ movl(bci, Address(rbp, 2*BytesPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
939 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, counter_overflow), bci);
a61af66fc99e Initial load
duke
parents:
diff changeset
940 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
941 oop_maps->add_gc_map(call_offset, map);
a61af66fc99e Initial load
duke
parents:
diff changeset
942 restore_live_registers(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
943 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
944 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
945 }
a61af66fc99e Initial load
duke
parents:
diff changeset
946 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
947 #endif // TIERED
a61af66fc99e Initial load
duke
parents:
diff changeset
948
a61af66fc99e Initial load
duke
parents:
diff changeset
949 case new_type_array_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
950 case new_object_array_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
951 {
a61af66fc99e Initial load
duke
parents:
diff changeset
952 Register length = rbx; // Incoming
a61af66fc99e Initial load
duke
parents:
diff changeset
953 Register klass = rdx; // Incoming
a61af66fc99e Initial load
duke
parents:
diff changeset
954 Register obj = rax; // Result
a61af66fc99e Initial load
duke
parents:
diff changeset
955
a61af66fc99e Initial load
duke
parents:
diff changeset
956 if (id == new_type_array_id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
957 __ set_info("new_type_array", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
958 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
959 __ set_info("new_object_array", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
960 }
a61af66fc99e Initial load
duke
parents:
diff changeset
961
a61af66fc99e Initial load
duke
parents:
diff changeset
962 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
963 // assert object type is really an array of the proper kind
a61af66fc99e Initial load
duke
parents:
diff changeset
964 {
a61af66fc99e Initial load
duke
parents:
diff changeset
965 Label ok;
a61af66fc99e Initial load
duke
parents:
diff changeset
966 Register t0 = obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
967 __ movl(t0, Address(klass, Klass::layout_helper_offset_in_bytes() + sizeof(oopDesc)));
a61af66fc99e Initial load
duke
parents:
diff changeset
968 __ sarl(t0, Klass::_lh_array_tag_shift);
a61af66fc99e Initial load
duke
parents:
diff changeset
969 int tag = ((id == new_type_array_id)
a61af66fc99e Initial load
duke
parents:
diff changeset
970 ? Klass::_lh_array_tag_type_value
a61af66fc99e Initial load
duke
parents:
diff changeset
971 : Klass::_lh_array_tag_obj_value);
a61af66fc99e Initial load
duke
parents:
diff changeset
972 __ cmpl(t0, tag);
a61af66fc99e Initial load
duke
parents:
diff changeset
973 __ jcc(Assembler::equal, ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
974 __ stop("assert(is an array klass)");
a61af66fc99e Initial load
duke
parents:
diff changeset
975 __ should_not_reach_here();
a61af66fc99e Initial load
duke
parents:
diff changeset
976 __ bind(ok);
a61af66fc99e Initial load
duke
parents:
diff changeset
977 }
a61af66fc99e Initial load
duke
parents:
diff changeset
978 #endif // ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
979
a61af66fc99e Initial load
duke
parents:
diff changeset
980 if (UseTLAB && FastTLABRefill) {
a61af66fc99e Initial load
duke
parents:
diff changeset
981 Register arr_size = rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
982 Register t1 = rcx; // must be rcx for use as shift count
a61af66fc99e Initial load
duke
parents:
diff changeset
983 Register t2 = rdi;
a61af66fc99e Initial load
duke
parents:
diff changeset
984 Label slow_path;
a61af66fc99e Initial load
duke
parents:
diff changeset
985 assert_different_registers(length, klass, obj, arr_size, t1, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
986
a61af66fc99e Initial load
duke
parents:
diff changeset
987 // check that array length is small enough for fast path.
a61af66fc99e Initial load
duke
parents:
diff changeset
988 __ cmpl(length, C1_MacroAssembler::max_array_allocation_length);
a61af66fc99e Initial load
duke
parents:
diff changeset
989 __ jcc(Assembler::above, slow_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
990
a61af66fc99e Initial load
duke
parents:
diff changeset
991 // if we got here then the TLAB allocation failed, so try
a61af66fc99e Initial load
duke
parents:
diff changeset
992 // refilling the TLAB or allocating directly from eden.
a61af66fc99e Initial load
duke
parents:
diff changeset
993 Label retry_tlab, try_eden;
a61af66fc99e Initial load
duke
parents:
diff changeset
994 __ tlab_refill(retry_tlab, try_eden, slow_path); // preserves rbx, & rdx
a61af66fc99e Initial load
duke
parents:
diff changeset
995
a61af66fc99e Initial load
duke
parents:
diff changeset
996 __ bind(retry_tlab);
a61af66fc99e Initial load
duke
parents:
diff changeset
997
a61af66fc99e Initial load
duke
parents:
diff changeset
998 // get the allocation size: round_up(hdr + length << (layout_helper & 0x1F))
a61af66fc99e Initial load
duke
parents:
diff changeset
999 __ movl(t1, Address(klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 __ movl(arr_size, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
1001 assert(t1 == rcx, "fixed register usage");
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 __ shll(arr_size /* by t1=rcx, mod 32 */);
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 __ shrl(t1, Klass::_lh_header_size_shift);
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 __ andl(t1, Klass::_lh_header_size_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 __ addl(arr_size, t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 __ addl(arr_size, MinObjAlignmentInBytesMask); // align up
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 __ andl(arr_size, ~MinObjAlignmentInBytesMask);
a61af66fc99e Initial load
duke
parents:
diff changeset
1008
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 __ tlab_allocate(obj, arr_size, 0, t1, t2, slow_path); // preserves arr_size
a61af66fc99e Initial load
duke
parents:
diff changeset
1010
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 __ initialize_header(obj, klass, length, t1, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 __ movb(t1, Address(klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes() + (Klass::_lh_header_size_shift / BitsPerByte)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 assert(Klass::_lh_header_size_mask <= 0xFF, "bytewise");
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 __ andl(t1, Klass::_lh_header_size_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
1016 __ subl(arr_size, t1); // body length
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 __ addl(t1, obj); // body start
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 __ initialize_body(t1, arr_size, 0, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1019 __ verify_oop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1021
a61af66fc99e Initial load
duke
parents:
diff changeset
1022 __ bind(try_eden);
a61af66fc99e Initial load
duke
parents:
diff changeset
1023 // get the allocation size: round_up(hdr + length << (layout_helper & 0x1F))
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 __ movl(t1, Address(klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1025 __ movl(arr_size, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 assert(t1 == rcx, "fixed register usage");
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 __ shll(arr_size /* by t1=rcx, mod 32 */);
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 __ shrl(t1, Klass::_lh_header_size_shift);
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 __ andl(t1, Klass::_lh_header_size_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 __ addl(arr_size, t1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 __ addl(arr_size, MinObjAlignmentInBytesMask); // align up
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 __ andl(arr_size, ~MinObjAlignmentInBytesMask);
a61af66fc99e Initial load
duke
parents:
diff changeset
1033
a61af66fc99e Initial load
duke
parents:
diff changeset
1034 __ eden_allocate(obj, arr_size, 0, t1, slow_path); // preserves arr_size
a61af66fc99e Initial load
duke
parents:
diff changeset
1035
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 __ initialize_header(obj, klass, length, t1, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1037 __ movb(t1, Address(klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes() + (Klass::_lh_header_size_shift / BitsPerByte)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1038 assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise");
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 assert(Klass::_lh_header_size_mask <= 0xFF, "bytewise");
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 __ andl(t1, Klass::_lh_header_size_mask);
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 __ subl(arr_size, t1); // body length
a61af66fc99e Initial load
duke
parents:
diff changeset
1042 __ addl(t1, obj); // body start
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 __ initialize_body(t1, arr_size, 0, t2);
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 __ verify_oop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1046
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 __ bind(slow_path);
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1049
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 __ enter();
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 OopMap* map = save_live_registers(sasm, 3);
a61af66fc99e Initial load
duke
parents:
diff changeset
1052 int call_offset;
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 if (id == new_type_array_id) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_type_array), klass, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 call_offset = __ call_RT(obj, noreg, CAST_FROM_FN_PTR(address, new_object_array), klass, length);
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1058
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 oop_maps->add_gc_map(call_offset, map);
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 restore_live_registers_except_rax(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1062
a61af66fc99e Initial load
duke
parents:
diff changeset
1063 __ verify_oop(obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
1064 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
1065 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1066
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 // rax,: new array
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1070
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 case new_multi_array_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 { StubFrame f(sasm, "new_multi_array", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 // rax,: klass
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 // rbx,: rank
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 // rcx: address of 1st dimension
a61af66fc99e Initial load
duke
parents:
diff changeset
1076 OopMap* map = save_live_registers(sasm, 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 int call_offset = __ call_RT(rax, noreg, CAST_FROM_FN_PTR(address, new_multi_array), rax, rbx, rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1078
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
1080 oop_maps->add_gc_map(call_offset, map);
a61af66fc99e Initial load
duke
parents:
diff changeset
1081 restore_live_registers_except_rax(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1082
a61af66fc99e Initial load
duke
parents:
diff changeset
1083 // rax,: new multi array
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 __ verify_oop(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1087
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 case register_finalizer_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 __ set_info("register_finalizer", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1091
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 // The object is passed on the stack and we haven't pushed a
a61af66fc99e Initial load
duke
parents:
diff changeset
1093 // frame yet so it's one work away from top of stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
1094 __ movl(rax, Address(rsp, 1 * BytesPerWord));
a61af66fc99e Initial load
duke
parents:
diff changeset
1095 __ verify_oop(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1096
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 // load the klass and check the has finalizer flag
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 Label register_finalizer;
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 Register t = rsi;
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 __ movl(t, Address(rax, oopDesc::klass_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 __ movl(t, Address(t, Klass::access_flags_offset_in_bytes() + sizeof(oopDesc)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 __ testl(t, JVM_ACC_HAS_FINALIZER);
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 __ jcc(Assembler::notZero, register_finalizer);
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1105
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 __ bind(register_finalizer);
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 __ enter();
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 OopMap* oop_map = save_live_registers(sasm, 2 /*num_rt_args */);
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 int call_offset = __ call_RT(noreg, noreg,
a61af66fc99e Initial load
duke
parents:
diff changeset
1110 CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 oop_maps->add_gc_map(call_offset, oop_map);
a61af66fc99e Initial load
duke
parents:
diff changeset
1113
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 // Now restore all the live registers
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 restore_live_registers(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1116
a61af66fc99e Initial load
duke
parents:
diff changeset
1117 __ leave();
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1121
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 case throw_range_check_failed_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 { StubFrame f(sasm, "range_check_failed", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1125 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1127
a61af66fc99e Initial load
duke
parents:
diff changeset
1128 case throw_index_exception_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 { StubFrame f(sasm, "index_range_check_failed", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1132 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1133
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 case throw_div0_exception_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 { StubFrame f(sasm, "throw_div0_exception", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1139
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 case throw_null_pointer_exception_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 { StubFrame f(sasm, "throw_null_pointer_exception", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1143 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1144 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1145
a61af66fc99e Initial load
duke
parents:
diff changeset
1146 case handle_exception_nofpu_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 save_fpu_registers = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
1149 case handle_exception_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1150 { StubFrame f(sasm, "handle_exception", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 OopMap* oop_map = save_live_registers(sasm, 1, save_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 generate_handle_exception(sasm, oop_maps, oop_map, save_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1156
a61af66fc99e Initial load
duke
parents:
diff changeset
1157 case unwind_exception_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 { __ set_info("unwind_exception", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 // note: no stubframe since we are about to leave the current
a61af66fc99e Initial load
duke
parents:
diff changeset
1160 // activation and we are calling a leaf VM function only.
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 generate_unwind_exception(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1163 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1164
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 case throw_array_store_exception_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 { StubFrame f(sasm, "throw_array_store_exception", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1167 // tos + 0: link
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 // + 1: return address
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1172
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 case throw_class_cast_exception_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 { StubFrame f(sasm, "throw_class_cast_exception", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true);
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1178
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 case throw_incompatible_class_change_error_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 { StubFrame f(sasm, "throw_incompatible_class_cast_exception", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
1182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1183 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1184
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 case slow_subtype_check_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 enum layout {
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 rax_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 rcx_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
1190 rsi_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 rdi_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 saved_rbp_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 return_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 sub_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 super_off,
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 framesize
a61af66fc99e Initial load
duke
parents:
diff changeset
1197 };
a61af66fc99e Initial load
duke
parents:
diff changeset
1198
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 __ set_info("slow_subtype_check", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1200 __ pushl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 __ pushl(rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 __ pushl(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 __ pushl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 __ movl(rsi, Address(rsp, (super_off - 1) * BytesPerWord)); // super
a61af66fc99e Initial load
duke
parents:
diff changeset
1205 __ movl(rax, Address(rsp, (sub_off - 1) * BytesPerWord)); // sub
a61af66fc99e Initial load
duke
parents:
diff changeset
1206
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 __ movl(rdi,Address(rsi,sizeof(oopDesc) + Klass::secondary_supers_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 __ movl(rcx,Address(rdi,arrayOopDesc::length_offset_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
1209 __ addl(rdi,arrayOopDesc::base_offset_in_bytes(T_OBJECT));
a61af66fc99e Initial load
duke
parents:
diff changeset
1210
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 Label miss;
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 __ repne_scan();
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 __ jcc(Assembler::notEqual, miss);
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 __ movl(Address(rsi,sizeof(oopDesc) + Klass::secondary_super_cache_offset_in_bytes()), rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 __ movl(Address(rsp, (super_off - 1) * BytesPerWord), 1); // result
a61af66fc99e Initial load
duke
parents:
diff changeset
1216 __ popl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 __ popl(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 __ popl(rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 __ popl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1221
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 __ bind(miss);
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 __ movl(Address(rsp, (super_off - 1) * BytesPerWord), 0); // result
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 __ popl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 __ popl(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 __ popl(rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 __ popl(rdi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1231
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 case monitorenter_nofpu_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1233 save_fpu_registers = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1234 // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
1235 case monitorenter_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 StubFrame f(sasm, "monitorenter", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 OopMap* map = save_live_registers(sasm, 3, save_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
1239
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 f.load_argument(1, rax); // rax,: object
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 f.load_argument(0, rbx); // rbx,: lock address
a61af66fc99e Initial load
duke
parents:
diff changeset
1242
a61af66fc99e Initial load
duke
parents:
diff changeset
1243 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), rax, rbx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1244
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 oop_maps->add_gc_map(call_offset, map);
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 restore_live_registers(sasm, save_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1250
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 case monitorexit_nofpu_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 save_fpu_registers = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 // fall through
a61af66fc99e Initial load
duke
parents:
diff changeset
1254 case monitorexit_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 StubFrame f(sasm, "monitorexit", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1257 OopMap* map = save_live_registers(sasm, 2, save_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
1258
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 f.load_argument(0, rax); // rax,: lock address
a61af66fc99e Initial load
duke
parents:
diff changeset
1260
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 // note: really a leaf routine but must setup last java sp
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 // => use call_RT for now (speed can be improved by
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 // doing last java sp setup manually)
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1265
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
1267 oop_maps->add_gc_map(call_offset, map);
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 restore_live_registers(sasm, save_fpu_registers);
a61af66fc99e Initial load
duke
parents:
diff changeset
1269
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1271 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1272
a61af66fc99e Initial load
duke
parents:
diff changeset
1273 case access_field_patching_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 { StubFrame f(sasm, "access_field_patching", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 // we should set up register map
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching));
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1279
a61af66fc99e Initial load
duke
parents:
diff changeset
1280 case load_klass_patching_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1281 { StubFrame f(sasm, "load_klass_patching", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1282 // we should set up register map
a61af66fc99e Initial load
duke
parents:
diff changeset
1283 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching));
a61af66fc99e Initial load
duke
parents:
diff changeset
1284 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1286
a61af66fc99e Initial load
duke
parents:
diff changeset
1287 case jvmti_exception_throw_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1288 { // rax,: exception oop
a61af66fc99e Initial load
duke
parents:
diff changeset
1289 StubFrame f(sasm, "jvmti_exception_throw", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 // Preserve all registers across this potentially blocking call
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 const int num_rt_args = 2; // thread, exception oop
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 OopMap* map = save_live_registers(sasm, num_rt_args);
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, Runtime1::post_jvmti_exception_throw), rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1294 oop_maps = new OopMapSet();
a61af66fc99e Initial load
duke
parents:
diff changeset
1295 oop_maps->add_gc_map(call_offset, map);
a61af66fc99e Initial load
duke
parents:
diff changeset
1296 restore_live_registers(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1299
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 case dtrace_object_alloc_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 { // rax,: object
a61af66fc99e Initial load
duke
parents:
diff changeset
1302 StubFrame f(sasm, "dtrace_object_alloc", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 // we can't gc here so skip the oopmap but make sure that all
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 // the live registers get saved.
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 save_live_registers(sasm, 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1306
a61af66fc99e Initial load
duke
parents:
diff changeset
1307 __ pushl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1308 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc)));
a61af66fc99e Initial load
duke
parents:
diff changeset
1309 __ popl(rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1310
a61af66fc99e Initial load
duke
parents:
diff changeset
1311 restore_live_registers(sasm);
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1314
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 case fpu2long_stub_id:
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1317 // rax, and rdx are destroyed, but should be free since the result is returned there
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 // preserve rsi,ecx
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 __ pushl(rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 __ pushl(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1321
a61af66fc99e Initial load
duke
parents:
diff changeset
1322 // check for NaN
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 Label return0, do_return, return_min_jlong, do_convert;
a61af66fc99e Initial load
duke
parents:
diff changeset
1324
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 Address value_high_word(rsp, 8);
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 Address value_low_word(rsp, 4);
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 Address result_high_word(rsp, 16);
a61af66fc99e Initial load
duke
parents:
diff changeset
1328 Address result_low_word(rsp, 12);
a61af66fc99e Initial load
duke
parents:
diff changeset
1329
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 __ subl(rsp, 20);
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 __ fst_d(value_low_word);
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 __ movl(rax, value_high_word);
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 __ andl(rax, 0x7ff00000);
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 __ cmpl(rax, 0x7ff00000);
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 __ jcc(Assembler::notEqual, do_convert);
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 __ movl(rax, value_high_word);
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 __ andl(rax, 0xfffff);
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 __ orl(rax, value_low_word);
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 __ jcc(Assembler::notZero, return0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1340
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 __ bind(do_convert);
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 __ fnstcw(Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 __ movzxw(rax, Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 __ orl(rax, 0xc00);
a61af66fc99e Initial load
duke
parents:
diff changeset
1345 __ movw(Address(rsp, 2), rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1346 __ fldcw(Address(rsp, 2));
a61af66fc99e Initial load
duke
parents:
diff changeset
1347 __ fwait();
a61af66fc99e Initial load
duke
parents:
diff changeset
1348 __ fistp_d(result_low_word);
a61af66fc99e Initial load
duke
parents:
diff changeset
1349 __ fldcw(Address(rsp, 0));
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 __ fwait();
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 __ movl(rax, result_low_word);
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 __ movl(rdx, result_high_word);
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 __ movl(rcx, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 // What the heck is the point of the next instruction???
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 __ xorl(rcx, 0x0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 __ movl(rsi, 0x80000000);
a61af66fc99e Initial load
duke
parents:
diff changeset
1357 __ xorl(rsi, rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 __ orl(rcx, rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 __ jcc(Assembler::notEqual, do_return);
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 __ fldz();
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 __ fcomp_d(value_low_word);
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 __ fnstsw_ax();
a61af66fc99e Initial load
duke
parents:
diff changeset
1363 __ sahf();
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 __ jcc(Assembler::above, return_min_jlong);
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 // return max_jlong
a61af66fc99e Initial load
duke
parents:
diff changeset
1366 __ movl(rdx, 0x7fffffff);
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 __ movl(rax, 0xffffffff);
a61af66fc99e Initial load
duke
parents:
diff changeset
1368 __ jmp(do_return);
a61af66fc99e Initial load
duke
parents:
diff changeset
1369
a61af66fc99e Initial load
duke
parents:
diff changeset
1370 __ bind(return_min_jlong);
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 __ movl(rdx, 0x80000000);
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 __ xorl(rax, rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 __ jmp(do_return);
a61af66fc99e Initial load
duke
parents:
diff changeset
1374
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 __ bind(return0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 __ fpop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1377 __ xorl(rdx,rdx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 __ xorl(rax,rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1379
a61af66fc99e Initial load
duke
parents:
diff changeset
1380 __ bind(do_return);
a61af66fc99e Initial load
duke
parents:
diff changeset
1381 __ addl(rsp, 20);
a61af66fc99e Initial load
duke
parents:
diff changeset
1382 __ popl(rcx);
a61af66fc99e Initial load
duke
parents:
diff changeset
1383 __ popl(rsi);
a61af66fc99e Initial load
duke
parents:
diff changeset
1384 __ ret(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1387
a61af66fc99e Initial load
duke
parents:
diff changeset
1388 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1389 { StubFrame f(sasm, "unimplemented entry", dont_gc_arguments);
a61af66fc99e Initial load
duke
parents:
diff changeset
1390 __ movl(rax, (int)id);
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), rax);
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 __ should_not_reach_here();
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1394 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 return oop_maps;
a61af66fc99e Initial load
duke
parents:
diff changeset
1397 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1398
a61af66fc99e Initial load
duke
parents:
diff changeset
1399 #undef __