comparison src/cpu/zero/vm/frame_zero.cpp @ 1010:354d3184f6b2

6890308: integrate zero assembler hotspot changes Reviewed-by: never Contributed-by: gbenson@redhat.com
author never
date Tue, 13 Oct 2009 12:04:21 -0700
parents
children 8e7adf982378
comparison
equal deleted inserted replaced
1009:03b336640699 1010:354d3184f6b2
1 /*
2 * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * Copyright 2007, 2008, 2009 Red Hat, Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 */
25
26 #include "incls/_precompiled.incl"
27 #include "incls/_frame_zero.cpp.incl"
28
29 #ifdef ASSERT
30 void RegisterMap::check_location_valid() {
31 ShouldNotCallThis();
32 }
33 #endif
34
35 bool frame::is_interpreted_frame() const {
36 return zeroframe()->is_interpreter_frame();
37 }
38
39 bool frame::is_fake_stub_frame() const {
40 return zeroframe()->is_fake_stub_frame();
41 }
42
43 frame frame::sender_for_entry_frame(RegisterMap *map) const {
44 assert(map != NULL, "map must be set");
45 assert(!entry_frame_is_first(), "next Java fp must be non zero");
46 assert(entry_frame_call_wrapper()->anchor()->last_Java_sp() == sender_sp(),
47 "sender should be next Java frame");
48 map->clear();
49 assert(map->include_argument_oops(), "should be set by clear");
50 return frame(sender_sp(), sp() + 1);
51 }
52
53 frame frame::sender_for_interpreter_frame(RegisterMap *map) const {
54 return frame(sender_sp(), sp() + 1);
55 }
56
57 frame frame::sender_for_compiled_frame(RegisterMap *map) const {
58 return frame(sender_sp(), sp() + 1);
59 }
60
61 frame frame::sender_for_fake_stub_frame(RegisterMap *map) const {
62 return frame(sender_sp(), sp() + 1);
63 }
64
65 frame frame::sender(RegisterMap* map) const {
66 // Default is not to follow arguments; the various
67 // sender_for_xxx methods update this accordingly.
68 map->set_include_argument_oops(false);
69
70 if (is_entry_frame())
71 return sender_for_entry_frame(map);
72
73 if (is_interpreted_frame())
74 return sender_for_interpreter_frame(map);
75
76 if (is_compiled_frame())
77 return sender_for_compiled_frame(map);
78
79 if (is_fake_stub_frame())
80 return sender_for_fake_stub_frame(map);
81
82 ShouldNotReachHere();
83 }
84
85 #ifdef CC_INTERP
86 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
87 return get_interpreterState()->monitor_base();
88 }
89
90 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
91 return (BasicObjectLock*) get_interpreterState()->stack_base();
92 }
93 #endif // CC_INTERP
94
95 void frame::patch_pc(Thread* thread, address pc) {
96 // We borrow this call to set the thread pointer in the interpreter
97 // state; the hook to set up deoptimized frames isn't supplied it.
98 assert(pc == NULL, "should be");
99 get_interpreterState()->set_thread((JavaThread *) thread);
100 }
101
102 bool frame::safe_for_sender(JavaThread *thread) {
103 ShouldNotCallThis();
104 }
105
106 void frame::pd_gc_epilog() {
107 }
108
109 bool frame::is_interpreted_frame_valid(JavaThread *thread) const {
110 ShouldNotCallThis();
111 }
112
113 BasicType frame::interpreter_frame_result(oop* oop_result,
114 jvalue* value_result) {
115 assert(is_interpreted_frame(), "interpreted frame expected");
116 methodOop method = interpreter_frame_method();
117 BasicType type = method->result_type();
118 intptr_t* tos_addr = (intptr_t *) interpreter_frame_tos_address();
119 oop obj;
120
121 switch (type) {
122 case T_VOID:
123 break;
124 case T_BOOLEAN:
125 value_result->z = *(jboolean *) tos_addr;
126 break;
127 case T_BYTE:
128 value_result->b = *(jbyte *) tos_addr;
129 break;
130 case T_CHAR:
131 value_result->c = *(jchar *) tos_addr;
132 break;
133 case T_SHORT:
134 value_result->s = *(jshort *) tos_addr;
135 break;
136 case T_INT:
137 value_result->i = *(jint *) tos_addr;
138 break;
139 case T_LONG:
140 value_result->j = *(jlong *) tos_addr;
141 break;
142 case T_FLOAT:
143 value_result->f = *(jfloat *) tos_addr;
144 break;
145 case T_DOUBLE:
146 value_result->d = *(jdouble *) tos_addr;
147 break;
148
149 case T_OBJECT:
150 case T_ARRAY:
151 if (method->is_native()) {
152 obj = get_interpreterState()->oop_temp();
153 }
154 else {
155 oop* obj_p = (oop *) tos_addr;
156 obj = (obj_p == NULL) ? (oop) NULL : *obj_p;
157 }
158 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
159 *oop_result = obj;
160 break;
161
162 default:
163 ShouldNotReachHere();
164 }
165
166 return type;
167 }
168
169 int frame::frame_size(RegisterMap* map) const {
170 #ifdef PRODUCT
171 ShouldNotCallThis();
172 #else
173 return 0; // make javaVFrame::print_value work
174 #endif // PRODUCT
175 }
176
177 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
178 int index = (Interpreter::expr_offset_in_bytes(offset) / wordSize);
179 return &interpreter_frame_tos_address()[index];
180 }
181
182 void frame::zero_print_on_error(int frame_index,
183 outputStream* st,
184 char* buf,
185 int buflen) const {
186 // Divide the buffer between the field and the value
187 buflen >>= 1;
188 char *fieldbuf = buf;
189 char *valuebuf = buf + buflen;
190
191 // Print each word of the frame
192 for (intptr_t *addr = fp(); addr <= sp(); addr++) {
193 int offset = sp() - addr;
194
195 // Fill in default values, then try and improve them
196 snprintf(fieldbuf, buflen, "word[%d]", offset);
197 snprintf(valuebuf, buflen, PTR_FORMAT, *addr);
198 zeroframe()->identify_word(frame_index, offset, fieldbuf, valuebuf, buflen);
199 fieldbuf[buflen - 1] = '\0';
200 valuebuf[buflen - 1] = '\0';
201
202 // Print the result
203 st->print_cr(" " PTR_FORMAT ": %-21s = %s", addr, fieldbuf, valuebuf);
204 }
205 }
206
207 void ZeroFrame::identify_word(int frame_index,
208 int offset,
209 char* fieldbuf,
210 char* valuebuf,
211 int buflen) const {
212 switch (offset) {
213 case next_frame_off:
214 strncpy(fieldbuf, "next_frame", buflen);
215 break;
216
217 case frame_type_off:
218 strncpy(fieldbuf, "frame_type", buflen);
219 if (is_entry_frame())
220 strncpy(valuebuf, "ENTRY_FRAME", buflen);
221 else if (is_interpreter_frame())
222 strncpy(valuebuf, "INTERPRETER_FRAME", buflen);
223 else if (is_shark_frame())
224 strncpy(valuebuf, "SHARK_FRAME", buflen);
225 else if (is_fake_stub_frame())
226 strncpy(valuebuf, "FAKE_STUB_FRAME", buflen);
227 break;
228
229 default:
230 if (is_entry_frame()) {
231 as_entry_frame()->identify_word(
232 frame_index, offset, fieldbuf, valuebuf, buflen);
233 }
234 else if (is_interpreter_frame()) {
235 as_interpreter_frame()->identify_word(
236 frame_index, offset, fieldbuf, valuebuf, buflen);
237 }
238 else if (is_shark_frame()) {
239 as_shark_frame()->identify_word(
240 frame_index, offset, fieldbuf, valuebuf, buflen);
241 }
242 else if (is_fake_stub_frame()) {
243 as_fake_stub_frame()->identify_word(
244 frame_index, offset, fieldbuf, valuebuf, buflen);
245 }
246 }
247 }
248
249 void EntryFrame::identify_word(int frame_index,
250 int offset,
251 char* fieldbuf,
252 char* valuebuf,
253 int buflen) const {
254 switch (offset) {
255 case call_wrapper_off:
256 strncpy(fieldbuf, "call_wrapper", buflen);
257 break;
258
259 default:
260 snprintf(fieldbuf, buflen, "local[%d]", offset - 3);
261 }
262 }
263
264 void InterpreterFrame::identify_word(int frame_index,
265 int offset,
266 char* fieldbuf,
267 char* valuebuf,
268 int buflen) const {
269 interpreterState istate = interpreter_state();
270 bool is_valid = istate->self_link() == istate;
271 intptr_t *addr = addr_of_word(offset);
272
273 // Fixed part
274 if (addr >= (intptr_t *) istate) {
275 const char *field = istate->name_of_field_at_address((address) addr);
276 if (field) {
277 if (is_valid && !strcmp(field, "_method")) {
278 istate->method()->name_and_sig_as_C_string(valuebuf, buflen);
279 }
280 else if (is_valid && !strcmp(field, "_bcp") && istate->bcp()) {
281 snprintf(valuebuf, buflen, PTR_FORMAT " (bci %d)",
282 (intptr_t) istate->bcp(),
283 istate->method()->bci_from(istate->bcp()));
284 }
285 snprintf(fieldbuf, buflen, "%sistate->%s",
286 field[strlen(field) - 1] == ')' ? "(": "", field);
287 }
288 else if (addr == (intptr_t *) istate) {
289 strncpy(fieldbuf, "(vtable for istate)", buflen);
290 }
291 return;
292 }
293
294 // Variable part
295 if (!is_valid)
296 return;
297
298 // JNI stuff
299 if (istate->method()->is_native() && addr < istate->stack_base()) {
300 address hA = istate->method()->signature_handler();
301 if (hA != NULL) {
302 if (hA != (address) InterpreterRuntime::slow_signature_handler) {
303 InterpreterRuntime::SignatureHandler *handler =
304 InterpreterRuntime::SignatureHandler::from_handlerAddr(hA);
305
306 intptr_t *params = istate->stack_base() - handler->argument_count();
307 if (addr >= params) {
308 int param = addr - params;
309 const char *desc = "";
310 if (param == 0)
311 desc = " (JNIEnv)";
312 else if (param == 1) {
313 if (istate->method()->is_static())
314 desc = " (mirror)";
315 else
316 desc = " (this)";
317 }
318 snprintf(fieldbuf, buflen, "parameter[%d]%s", param, desc);
319 return;
320 }
321
322 for (int i = 0; i < handler->argument_count(); i++) {
323 if (params[i] == (intptr_t) addr) {
324 snprintf(fieldbuf, buflen, "unboxed parameter[%d]", i);
325 return;
326 }
327 }
328 }
329 }
330 return;
331 }
332
333 // Monitors and stack
334 identify_vp_word(frame_index, addr,
335 (intptr_t *) istate->monitor_base(),
336 istate->stack_base(),
337 fieldbuf, buflen);
338 }
339
340 void SharkFrame::identify_word(int frame_index,
341 int offset,
342 char* fieldbuf,
343 char* valuebuf,
344 int buflen) const {
345 // Fixed part
346 switch (offset) {
347 case pc_off:
348 strncpy(fieldbuf, "pc", buflen);
349 if (method()->is_oop()) {
350 nmethod *code = method()->code();
351 if (code && code->pc_desc_at(pc())) {
352 SimpleScopeDesc ssd(code, pc());
353 snprintf(valuebuf, buflen, PTR_FORMAT " (bci %d)",
354 (intptr_t) pc(), ssd.bci());
355 }
356 }
357 return;
358
359 case unextended_sp_off:
360 strncpy(fieldbuf, "unextended_sp", buflen);
361 return;
362
363 case method_off:
364 strncpy(fieldbuf, "method", buflen);
365 if (method()->is_oop()) {
366 method()->name_and_sig_as_C_string(valuebuf, buflen);
367 }
368 return;
369
370 case oop_tmp_off:
371 strncpy(fieldbuf, "oop_tmp", buflen);
372 return;
373 }
374
375 // Variable part
376 if (method()->is_oop()) {
377 identify_vp_word(frame_index, addr_of_word(offset),
378 addr_of_word(header_words + 1),
379 unextended_sp() + method()->max_stack(),
380 fieldbuf, buflen);
381 }
382 }
383
384 void ZeroFrame::identify_vp_word(int frame_index,
385 intptr_t* addr,
386 intptr_t* monitor_base,
387 intptr_t* stack_base,
388 char* fieldbuf,
389 int buflen) const {
390 // Monitors
391 if (addr >= stack_base && addr < monitor_base) {
392 int monitor_size = frame::interpreter_frame_monitor_size();
393 int last_index = (monitor_base - stack_base) / monitor_size - 1;
394 int index = last_index - (addr - stack_base) / monitor_size;
395 intptr_t monitor = (intptr_t) (
396 (BasicObjectLock *) monitor_base - 1 - index);
397 intptr_t offset = (intptr_t) addr - monitor;
398
399 if (offset == BasicObjectLock::obj_offset_in_bytes())
400 snprintf(fieldbuf, buflen, "monitor[%d]->_obj", index);
401 else if (offset == BasicObjectLock::lock_offset_in_bytes())
402 snprintf(fieldbuf, buflen, "monitor[%d]->_lock", index);
403
404 return;
405 }
406
407 // Expression stack
408 if (addr < stack_base) {
409 snprintf(fieldbuf, buflen, "%s[%d]",
410 frame_index == 0 ? "stack_word" : "local",
411 (int) (stack_base - addr - 1));
412 return;
413 }
414 }