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

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 93b6525e3b82
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 1997-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/_frame_x86.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
29 void RegisterMap::check_location_valid() {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 }
a61af66fc99e Initial load
duke
parents:
diff changeset
31 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // Profiling/safepoint support
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36 bool frame::safe_for_sender(JavaThread *thread) {
a61af66fc99e Initial load
duke
parents:
diff changeset
37 address sp = (address)_sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 address fp = (address)_fp;
a61af66fc99e Initial load
duke
parents:
diff changeset
39 address unextended_sp = (address)_unextended_sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
40 bool sp_safe = (sp != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
41 (sp <= thread->stack_base()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
42 (sp >= thread->stack_base() - thread->stack_size()));
a61af66fc99e Initial load
duke
parents:
diff changeset
43 bool unextended_sp_safe = (unextended_sp != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
44 (unextended_sp <= thread->stack_base()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
45 (unextended_sp >= thread->stack_base() - thread->stack_size()));
a61af66fc99e Initial load
duke
parents:
diff changeset
46 bool fp_safe = (fp != NULL &&
a61af66fc99e Initial load
duke
parents:
diff changeset
47 (fp <= thread->stack_base()) &&
a61af66fc99e Initial load
duke
parents:
diff changeset
48 (fp >= thread->stack_base() - thread->stack_size()));
a61af66fc99e Initial load
duke
parents:
diff changeset
49 if (sp_safe && unextended_sp_safe && fp_safe) {
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // Unfortunately we can only check frame complete for runtime stubs and nmethod
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // other generic buffer blobs are more problematic so we just assume they are
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // ok. adapter blobs never have a frame complete and are never ok.
a61af66fc99e Initial load
duke
parents:
diff changeset
53 if (_cb != NULL && !_cb->is_frame_complete_at(_pc)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 }
a61af66fc99e Initial load
duke
parents:
diff changeset
58 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 // Note: fp == NULL is not really a prerequisite for this to be safe to
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // walk for c2. However we've modified the code such that if we get
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // a failure with fp != NULL that we then try with FP == NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // This is basically to mimic what a last_frame would look like if
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // c2 had generated it.
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if (sp_safe && unextended_sp_safe && fp == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // frame must be complete if fp == NULL as fp == NULL is only sensible
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // if we are looking at a nmethod and frame complete assures us of that.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 if (_cb != NULL && _cb->is_frame_complete_at(_pc) && _cb->is_compiled_by_c2()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 }
a61af66fc99e Initial load
duke
parents:
diff changeset
72 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 }
a61af66fc99e Initial load
duke
parents:
diff changeset
74
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 void frame::patch_pc(Thread* thread, address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 if (TracePcPatching) {
a61af66fc99e Initial load
duke
parents:
diff changeset
78 tty->print_cr("patch_pc at address 0x%x [0x%x -> 0x%x] ", &((address *)sp())[-1], ((address *)sp())[-1], pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 ((address *)sp())[-1] = pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 _cb = CodeCache::find_blob(pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
82 if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 address orig = (((nmethod*)_cb)->get_original_pc(this));
a61af66fc99e Initial load
duke
parents:
diff changeset
84 assert(orig == _pc, "expected original to be stored before patching");
a61af66fc99e Initial load
duke
parents:
diff changeset
85 _deopt_state = is_deoptimized;
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // leave _pc as is
a61af66fc99e Initial load
duke
parents:
diff changeset
87 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 _deopt_state = not_deoptimized;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 _pc = pc;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 bool frame::is_interpreted_frame() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return Interpreter::contains(pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 int frame::frame_size() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 RegisterMap map(JavaThread::current(), false);
a61af66fc99e Initial load
duke
parents:
diff changeset
99 frame sender = this->sender(&map);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 return sender.sp() - sp();
a61af66fc99e Initial load
duke
parents:
diff changeset
101 }
a61af66fc99e Initial load
duke
parents:
diff changeset
102
a61af66fc99e Initial load
duke
parents:
diff changeset
103 intptr_t* frame::entry_frame_argument_at(int offset) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // convert offset to index to deal with tsi
a61af66fc99e Initial load
duke
parents:
diff changeset
105 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // Entry frame's arguments are always in relation to unextended_sp()
a61af66fc99e Initial load
duke
parents:
diff changeset
107 return &unextended_sp()[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // sender_sp
a61af66fc99e Initial load
duke
parents:
diff changeset
111 #ifdef CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
112 intptr_t* frame::interpreter_frame_sender_sp() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 assert(is_interpreted_frame(), "interpreted frame expected");
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // QQQ why does this specialize method exist if frame::sender_sp() does same thing?
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // seems odd and if we always know interpreted vs. non then sender_sp() is really
a61af66fc99e Initial load
duke
parents:
diff changeset
116 // doing too much work.
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return get_interpreterState()->sender_sp();
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // monitor elements
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return get_interpreterState()->monitor_base();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 return (BasicObjectLock*) get_interpreterState()->stack_base();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 }
a61af66fc99e Initial load
duke
parents:
diff changeset
129
a61af66fc99e Initial load
duke
parents:
diff changeset
130 #else // CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 intptr_t* frame::interpreter_frame_sender_sp() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 assert(is_interpreted_frame(), "interpreted frame expected");
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return (intptr_t*) at(interpreter_frame_sender_sp_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
138 assert(is_interpreted_frame(), "interpreted frame expected");
a61af66fc99e Initial load
duke
parents:
diff changeset
139 ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // monitor elements
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
146 return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 // make sure the pointer points inside the frame
a61af66fc99e Initial load
duke
parents:
diff changeset
152 assert((intptr_t) fp() > (intptr_t) result, "result must < than frame pointer");
a61af66fc99e Initial load
duke
parents:
diff changeset
153 assert((intptr_t) sp() <= (intptr_t) result, "result must >= than stack pointer");
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return result;
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // Used by template based interpreter deoptimization
a61af66fc99e Initial load
duke
parents:
diff changeset
162 void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
163 *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
a61af66fc99e Initial load
duke
parents:
diff changeset
164 }
a61af66fc99e Initial load
duke
parents:
diff changeset
165 #endif // CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 frame frame::sender_for_entry_frame(RegisterMap* map) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 assert(map != NULL, "map must be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Java frame called from C; skip all C frames and return top C
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // frame of that chunk as the sender
a61af66fc99e Initial load
duke
parents:
diff changeset
171 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
a61af66fc99e Initial load
duke
parents:
diff changeset
172 assert(!entry_frame_is_first(), "next Java fp must be non zero");
a61af66fc99e Initial load
duke
parents:
diff changeset
173 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
a61af66fc99e Initial load
duke
parents:
diff changeset
174 map->clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
175 assert(map->include_argument_oops(), "should be set by clear");
a61af66fc99e Initial load
duke
parents:
diff changeset
176 if (jfa->last_Java_pc() != NULL ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
178 return fr;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp());
a61af66fc99e Initial load
duke
parents:
diff changeset
181 return fr;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183
a61af66fc99e Initial load
duke
parents:
diff changeset
184 frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
185 // sp is the raw sp from the sender after adapter or interpreter extension
a61af66fc99e Initial load
duke
parents:
diff changeset
186 intptr_t* sp = (intptr_t*) addr_at(sender_sp_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 // This is the sp before any possible extension (adapter/locals).
a61af66fc99e Initial load
duke
parents:
diff changeset
189 intptr_t* unextended_sp = interpreter_frame_sender_sp();
a61af66fc99e Initial load
duke
parents:
diff changeset
190
a61af66fc99e Initial load
duke
parents:
diff changeset
191 // The interpreter and compiler(s) always save EBP/RBP in a known
a61af66fc99e Initial load
duke
parents:
diff changeset
192 // location on entry. We must record where that location is
a61af66fc99e Initial load
duke
parents:
diff changeset
193 // so this if EBP/RBP was live on callout from c2 we can find
a61af66fc99e Initial load
duke
parents:
diff changeset
194 // the saved copy no matter what it called.
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // Since the interpreter always saves EBP/RBP if we record where it is then
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // we don't have to always save EBP/RBP on entry and exit to c2 compiled
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // code, on entry will be enough.
a61af66fc99e Initial load
duke
parents:
diff changeset
199 #ifdef COMPILER2
a61af66fc99e Initial load
duke
parents:
diff changeset
200 if (map->update_map()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 map->set_location(rbp->as_VMReg(), (address) addr_at(link_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
202 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // this is weird "H" ought to be at a higher address however the
a61af66fc99e Initial load
duke
parents:
diff changeset
204 // oopMaps seems to have the "H" regs at the same address and the
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // vanilla register.
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // XXXX make this go away
a61af66fc99e Initial load
duke
parents:
diff changeset
207 if (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
208 map->set_location(rbp->as_VMReg()->next(), (address)addr_at(link_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }
a61af66fc99e Initial load
duke
parents:
diff changeset
210 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
211 }
a61af66fc99e Initial load
duke
parents:
diff changeset
212 #endif /* COMPILER2 */
a61af66fc99e Initial load
duke
parents:
diff changeset
213 return frame(sp, unextended_sp, link(), sender_pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
214 }
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216
a61af66fc99e Initial load
duke
parents:
diff changeset
217 //------------------------------sender_for_compiled_frame-----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
218 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
219 assert(map != NULL, "map must be set");
a61af66fc99e Initial load
duke
parents:
diff changeset
220 const bool c1_compiled = _cb->is_compiled_by_c1();
a61af66fc99e Initial load
duke
parents:
diff changeset
221
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // frame owned by optimizing compiler
a61af66fc99e Initial load
duke
parents:
diff changeset
223 intptr_t* sender_sp = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 assert(_cb->frame_size() >= 0, "must have non-zero frame size");
a61af66fc99e Initial load
duke
parents:
diff changeset
226 sender_sp = unextended_sp() + _cb->frame_size();
a61af66fc99e Initial load
duke
parents:
diff changeset
227
a61af66fc99e Initial load
duke
parents:
diff changeset
228 // On Intel the return_address is always the word on the stack
a61af66fc99e Initial load
duke
parents:
diff changeset
229 address sender_pc = (address) *(sender_sp-1);
a61af66fc99e Initial load
duke
parents:
diff changeset
230
a61af66fc99e Initial load
duke
parents:
diff changeset
231 // This is the saved value of ebp which may or may not really be an fp.
a61af66fc99e Initial load
duke
parents:
diff changeset
232 // it is only an fp if the sender is an interpreter frame (or c1?)
a61af66fc99e Initial load
duke
parents:
diff changeset
233
a61af66fc99e Initial load
duke
parents:
diff changeset
234 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
235
a61af66fc99e Initial load
duke
parents:
diff changeset
236 if (map->update_map()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
237 // Tell GC to use argument oopmaps for some runtime stubs that need it.
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // For C1, the runtime stub might not have oop maps, so set this flag
a61af66fc99e Initial load
duke
parents:
diff changeset
239 // outside of update_register_map.
a61af66fc99e Initial load
duke
parents:
diff changeset
240 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
a61af66fc99e Initial load
duke
parents:
diff changeset
241 if (_cb->oop_maps() != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 OopMapSet::update_register_map(this, map);
a61af66fc99e Initial load
duke
parents:
diff changeset
243 }
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // Since the prolog does the save and restore of epb there is no oopmap
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // for it so we must fill in its location as if there was an oopmap entry
a61af66fc99e Initial load
duke
parents:
diff changeset
246 // since if our caller was compiled code there could be live jvm state in it.
a61af66fc99e Initial load
duke
parents:
diff changeset
247 map->set_location(rbp->as_VMReg(), (address) (sender_sp - frame::sender_sp_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
248 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // this is weird "H" ought to be at a higher address however the
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // oopMaps seems to have the "H" regs at the same address and the
a61af66fc99e Initial load
duke
parents:
diff changeset
251 // vanilla register.
a61af66fc99e Initial load
duke
parents:
diff changeset
252 // XXXX make this go away
a61af66fc99e Initial load
duke
parents:
diff changeset
253 if (true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 map->set_location(rbp->as_VMReg()->next(), (address) (sender_sp - frame::sender_sp_offset));
a61af66fc99e Initial load
duke
parents:
diff changeset
255 }
a61af66fc99e Initial load
duke
parents:
diff changeset
256 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258
a61af66fc99e Initial load
duke
parents:
diff changeset
259 assert(sender_sp != sp(), "must have changed");
a61af66fc99e Initial load
duke
parents:
diff changeset
260 return frame(sender_sp, saved_fp, sender_pc);
a61af66fc99e Initial load
duke
parents:
diff changeset
261 }
a61af66fc99e Initial load
duke
parents:
diff changeset
262
a61af66fc99e Initial load
duke
parents:
diff changeset
263 frame frame::sender(RegisterMap* map) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 // Default is we done have to follow them. The sender_for_xxx will
a61af66fc99e Initial load
duke
parents:
diff changeset
265 // update it accordingly
a61af66fc99e Initial load
duke
parents:
diff changeset
266 map->set_include_argument_oops(false);
a61af66fc99e Initial load
duke
parents:
diff changeset
267
a61af66fc99e Initial load
duke
parents:
diff changeset
268 if (is_entry_frame()) return sender_for_entry_frame(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
a61af66fc99e Initial load
duke
parents:
diff changeset
271
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if (_cb != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 return sender_for_compiled_frame(map);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 }
a61af66fc99e Initial load
duke
parents:
diff changeset
275 // Must be native-compiled frame, i.e. the marshaling code for native
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // methods that exists in the core system.
a61af66fc99e Initial load
duke
parents:
diff changeset
277 return frame(sender_sp(), link(), sender_pc());
a61af66fc99e Initial load
duke
parents:
diff changeset
278 }
a61af66fc99e Initial load
duke
parents:
diff changeset
279
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 bool frame::interpreter_frame_equals_unpacked_fp(intptr_t* fp) {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 assert(is_interpreted_frame(), "must be interpreter frame");
a61af66fc99e Initial load
duke
parents:
diff changeset
283 methodOop method = interpreter_frame_method();
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // When unpacking an optimized frame the frame pointer is
a61af66fc99e Initial load
duke
parents:
diff changeset
285 // adjusted with:
a61af66fc99e Initial load
duke
parents:
diff changeset
286 int diff = (method->max_locals() - method->size_of_parameters()) *
a61af66fc99e Initial load
duke
parents:
diff changeset
287 Interpreter::stackElementWords();
a61af66fc99e Initial load
duke
parents:
diff changeset
288 return _fp == (fp - diff);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 }
a61af66fc99e Initial load
duke
parents:
diff changeset
290
a61af66fc99e Initial load
duke
parents:
diff changeset
291 void frame::pd_gc_epilog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // nothing done here now
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 bool frame::is_interpreted_frame_valid() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // QQQ
a61af66fc99e Initial load
duke
parents:
diff changeset
297 #ifdef CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
298 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
299 assert(is_interpreted_frame(), "Not an interpreted frame");
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // These are reasonable sanity checks
a61af66fc99e Initial load
duke
parents:
diff changeset
301 if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
302 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
303 }
a61af66fc99e Initial load
duke
parents:
diff changeset
304 if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
305 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
306 }
a61af66fc99e Initial load
duke
parents:
diff changeset
307 if (fp() + interpreter_frame_initial_sp_offset < sp()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
308 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
309 }
a61af66fc99e Initial load
duke
parents:
diff changeset
310 // These are hacks to keep us out of trouble.
a61af66fc99e Initial load
duke
parents:
diff changeset
311 // The problem with these is that they mask other problems
a61af66fc99e Initial load
duke
parents:
diff changeset
312 if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
a61af66fc99e Initial load
duke
parents:
diff changeset
313 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
314 }
a61af66fc99e Initial load
duke
parents:
diff changeset
315 if (fp() - sp() > 4096) { // stack frames shouldn't be large.
a61af66fc99e Initial load
duke
parents:
diff changeset
316 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
318 #endif // CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
319 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321
a61af66fc99e Initial load
duke
parents:
diff changeset
322 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
a61af66fc99e Initial load
duke
parents:
diff changeset
323 #ifdef CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
324 // Needed for JVMTI. The result should always be in the interpreterState object
a61af66fc99e Initial load
duke
parents:
diff changeset
325 assert(false, "NYI");
a61af66fc99e Initial load
duke
parents:
diff changeset
326 interpreterState istate = get_interpreterState();
a61af66fc99e Initial load
duke
parents:
diff changeset
327 #endif // CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
328 assert(is_interpreted_frame(), "interpreted frame expected");
a61af66fc99e Initial load
duke
parents:
diff changeset
329 methodOop method = interpreter_frame_method();
a61af66fc99e Initial load
duke
parents:
diff changeset
330 BasicType type = method->result_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
331
a61af66fc99e Initial load
duke
parents:
diff changeset
332 intptr_t* tos_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 if (method->is_native()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
334 // Prior to calling into the runtime to report the method_exit the possible
a61af66fc99e Initial load
duke
parents:
diff changeset
335 // return value is pushed to the native stack. If the result is a jfloat/jdouble
a61af66fc99e Initial load
duke
parents:
diff changeset
336 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
a61af66fc99e Initial load
duke
parents:
diff changeset
337 tos_addr = (intptr_t*)sp();
a61af66fc99e Initial load
duke
parents:
diff changeset
338 if (type == T_FLOAT || type == T_DOUBLE) {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // QQQ seems like this code is equivalent on the two platforms
a61af66fc99e Initial load
duke
parents:
diff changeset
340 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // This is times two because we do a push(ltos) after pushing XMM0
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // and that takes two interpreter stack slots.
a61af66fc99e Initial load
duke
parents:
diff changeset
343 tos_addr += 2 * Interpreter::stackElementWords();
a61af66fc99e Initial load
duke
parents:
diff changeset
344 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
345 tos_addr += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
346 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
347 }
a61af66fc99e Initial load
duke
parents:
diff changeset
348 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 tos_addr = (intptr_t*)interpreter_frame_tos_address();
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351
a61af66fc99e Initial load
duke
parents:
diff changeset
352 switch (type) {
a61af66fc99e Initial load
duke
parents:
diff changeset
353 case T_OBJECT :
a61af66fc99e Initial load
duke
parents:
diff changeset
354 case T_ARRAY : {
a61af66fc99e Initial load
duke
parents:
diff changeset
355 oop obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
356 if (method->is_native()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
357 #ifdef CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
358 obj = istate->_oop_temp;
a61af66fc99e Initial load
duke
parents:
diff changeset
359 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
360 obj = (oop) at(interpreter_frame_oop_temp_offset);
a61af66fc99e Initial load
duke
parents:
diff changeset
361 #endif // CC_INTERP
a61af66fc99e Initial load
duke
parents:
diff changeset
362 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
363 oop* obj_p = (oop*)tos_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
a61af66fc99e Initial load
duke
parents:
diff changeset
365 }
a61af66fc99e Initial load
duke
parents:
diff changeset
366 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
a61af66fc99e Initial load
duke
parents:
diff changeset
367 *oop_result = obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
368 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
369 }
a61af66fc99e Initial load
duke
parents:
diff changeset
370 case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
371 case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
372 case T_CHAR : value_result->c = *(jchar*)tos_addr; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
373 case T_SHORT : value_result->s = *(jshort*)tos_addr; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 case T_INT : value_result->i = *(jint*)tos_addr; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
375 case T_LONG : value_result->j = *(jlong*)tos_addr; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
376 case T_FLOAT : {
a61af66fc99e Initial load
duke
parents:
diff changeset
377 #ifdef AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
378 value_result->f = *(jfloat*)tos_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
379 #else
a61af66fc99e Initial load
duke
parents:
diff changeset
380 if (method->is_native()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
381 jdouble d = *(jdouble*)tos_addr; // Result was in ST0 so need to convert to jfloat
a61af66fc99e Initial load
duke
parents:
diff changeset
382 value_result->f = (jfloat)d;
a61af66fc99e Initial load
duke
parents:
diff changeset
383 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
384 value_result->f = *(jfloat*)tos_addr;
a61af66fc99e Initial load
duke
parents:
diff changeset
385 }
a61af66fc99e Initial load
duke
parents:
diff changeset
386 #endif // AMD64
a61af66fc99e Initial load
duke
parents:
diff changeset
387 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
388 }
a61af66fc99e Initial load
duke
parents:
diff changeset
389 case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
a61af66fc99e Initial load
duke
parents:
diff changeset
390 case T_VOID : /* Nothing to do */ break;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 default : ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393
a61af66fc99e Initial load
duke
parents:
diff changeset
394 return type;
a61af66fc99e Initial load
duke
parents:
diff changeset
395 }
a61af66fc99e Initial load
duke
parents:
diff changeset
396
a61af66fc99e Initial load
duke
parents:
diff changeset
397
a61af66fc99e Initial load
duke
parents:
diff changeset
398 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
399 int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
400 return &interpreter_frame_tos_address()[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
401 }