63 ticks_safepoint = -10
64 };
65
66 #if INCLUDE_JVMTI
67
68 //-------------------------------------------------------
69
70 // Native interfaces for use by Forte tools.
71
72
73 #if !defined(IA64) && !defined(PPC64)
74
75 class vframeStreamForte : public vframeStreamCommon {
76 public:
77 // constructor that starts with sender of frame fr (top_frame)
78 vframeStreamForte(JavaThread *jt, frame fr, bool stop_at_java_call_stub);
79 void forte_next();
80 };
81
82
83 static bool is_decipherable_compiled_frame(JavaThread* thread, frame* fr, nmethod* nm);
84 static bool is_decipherable_interpreted_frame(JavaThread* thread,
85 frame* fr,
86 Method** method_p,
87 int* bci_p);
88
89
90
91
92 vframeStreamForte::vframeStreamForte(JavaThread *jt,
93 frame fr,
94 bool stop_at_java_call_stub) : vframeStreamCommon(jt) {
95
96 _stop_at_java_call_stub = stop_at_java_call_stub;
97 _frame = fr;
98
99 // We must always have a valid frame to start filling
100
101 bool filled_in = fill_from_frame();
102
103 assert(filled_in, "invariant");
127
128
129 do {
130
131 loop_count++;
132
133 // By the time we get here we should never see unsafe but better
134 // safe then segv'd
135
136 if (loop_count > loop_max || !_frame.safe_for_sender(_thread)) {
137 _mode = at_end_mode;
138 return;
139 }
140
141 _frame = _frame.sender(&_reg_map);
142
143 } while (!fill_from_frame());
144 }
145
146 // Determine if 'fr' is a decipherable compiled frame. We are already
147 // assured that fr is for a java nmethod.
148
149 static bool is_decipherable_compiled_frame(JavaThread* thread, frame* fr, nmethod* nm) {
150 assert(nm->is_java_method(), "invariant");
151
152 if (thread->has_last_Java_frame() && thread->last_Java_pc() == fr->pc()) {
153 // We're stopped at a call into the JVM so look for a PcDesc with
154 // the actual pc reported by the frame.
155 PcDesc* pc_desc = nm->pc_desc_at(fr->pc());
156
157 // Did we find a useful PcDesc?
158 if (pc_desc != NULL &&
159 pc_desc->scope_decode_offset() != DebugInformationRecorder::serialized_null) {
160 return true;
161 }
162 }
163
164 // We're at some random pc in the nmethod so search for the PcDesc
165 // whose pc is greater than the current PC. It's done this way
166 // because the extra PcDescs that are recorded for improved debug
167 // info record the end of the region covered by the ScopeDesc
168 // instead of the beginning.
169 PcDesc* pc_desc = nm->pc_desc_near(fr->pc() + 1);
170
171 // Now do we have a useful PcDesc?
172 if (pc_desc == NULL ||
173 pc_desc->scope_decode_offset() == DebugInformationRecorder::serialized_null) {
174 // No debug information is available for this PC.
175 //
176 // vframeStreamCommon::fill_from_frame() will decode the frame depending
177 // on the state of the thread.
178 //
179 // Case #1: If the thread is in Java (state == _thread_in_Java), then
180 // the vframeStreamCommon object will be filled as if the frame were a native
181 // compiled frame. Therefore, no debug information is needed.
182 //
183 // Case #2: If the thread is in any other state, then two steps will be performed:
184 // - if asserts are enabled, found_bad_method_frame() will be called and
282 // A frame is considered to be decipherable:
283 //
284 // - if the frame is a compiled frame and a PCDesc is available;
285 //
286 // - if the frame is an interpreter frame that is valid or the thread is
287 // state (_thread_in_native || state == _thread_in_vm || state == _thread_blocked).
288 //
289 // Note that find_initial_Java_frame() can return false even if an initial
290 // Java method was found (e.g., there is no PCDesc available for the method).
291 //
292 // If 'method_p' is NULL, it was not possible to find a Java frame when
293 // walking the stack starting from 'fr'. In this case find_initial_Java_frame
294 // returns false.
295
296 static bool find_initial_Java_frame(JavaThread* thread,
297 frame* fr,
298 frame* initial_frame_p,
299 Method** method_p,
300 int* bci_p) {
301
302 // It is possible that for a frame containing an nmethod
303 // we can capture the method but no bci. If we get no
304 // bci the frame isn't walkable but the method is usable.
305 // Therefore we init the returned Method* to NULL so the
306 // caller can make the distinction.
307
308 *method_p = NULL;
309
310 // On the initial call to this method the frame we get may not be
311 // recognizable to us. This should only happen if we are in a JRT_LEAF
312 // or something called by a JRT_LEAF method.
313
314 frame candidate = *fr;
315
316 // If the starting frame we were given has no codeBlob associated with
317 // it see if we can find such a frame because only frames with codeBlobs
318 // are possible Java frames.
319
320 if (fr->cb() == NULL) {
321
322 // See if we can find a useful frame
343 if (candidate.is_entry_frame()) {
344 // jcw is NULL if the java call wrapper couldn't be found
345 JavaCallWrapper *jcw = candidate.entry_frame_call_wrapper_if_safe(thread);
346 // If initial frame is frame from StubGenerator and there is no
347 // previous anchor, there are no java frames associated with a method
348 if (jcw == NULL || jcw->is_first_frame()) {
349 return false;
350 }
351 }
352
353 if (candidate.is_interpreted_frame()) {
354 if (is_decipherable_interpreted_frame(thread, &candidate, method_p, bci_p)) {
355 *initial_frame_p = candidate;
356 return true;
357 }
358
359 // Hopefully we got some data
360 return false;
361 }
362
363 if (candidate.cb()->is_nmethod()) {
364
365 nmethod* nm = (nmethod*) candidate.cb();
366 *method_p = nm->method();
367
368 // If the frame is not decipherable, then the value of -1
369 // for the BCI is used to signal that no BCI is available.
370 // Furthermore, the method returns false in this case.
371 //
372 // If a decipherable frame is available, the BCI value will
373 // not be used.
374
375 *bci_p = -1;
376
377 *initial_frame_p = candidate;
378
379 // Native wrapper code is trivial to decode by vframeStream
380
381 if (nm->is_native_method()) return true;
382
383 // If the frame is not decipherable, then a PC was found
384 // that does not have a PCDesc from which a BCI can be obtained.
385 // Nevertheless, a Method was found.
|
63 ticks_safepoint = -10
64 };
65
66 #if INCLUDE_JVMTI
67
68 //-------------------------------------------------------
69
70 // Native interfaces for use by Forte tools.
71
72
73 #if !defined(IA64) && !defined(PPC64)
74
75 class vframeStreamForte : public vframeStreamCommon {
76 public:
77 // constructor that starts with sender of frame fr (top_frame)
78 vframeStreamForte(JavaThread *jt, frame fr, bool stop_at_java_call_stub);
79 void forte_next();
80 };
81
82
83 static bool is_decipherable_compiled_frame(JavaThread* thread, frame* fr, CompiledMethod* nm);
84 static bool is_decipherable_interpreted_frame(JavaThread* thread,
85 frame* fr,
86 Method** method_p,
87 int* bci_p);
88
89
90
91
92 vframeStreamForte::vframeStreamForte(JavaThread *jt,
93 frame fr,
94 bool stop_at_java_call_stub) : vframeStreamCommon(jt) {
95
96 _stop_at_java_call_stub = stop_at_java_call_stub;
97 _frame = fr;
98
99 // We must always have a valid frame to start filling
100
101 bool filled_in = fill_from_frame();
102
103 assert(filled_in, "invariant");
127
128
129 do {
130
131 loop_count++;
132
133 // By the time we get here we should never see unsafe but better
134 // safe then segv'd
135
136 if (loop_count > loop_max || !_frame.safe_for_sender(_thread)) {
137 _mode = at_end_mode;
138 return;
139 }
140
141 _frame = _frame.sender(&_reg_map);
142
143 } while (!fill_from_frame());
144 }
145
146 // Determine if 'fr' is a decipherable compiled frame. We are already
147 // assured that fr is for a java compiled method.
148
149 static bool is_decipherable_compiled_frame(JavaThread* thread, frame* fr, CompiledMethod* nm) {
150 assert(nm->is_java_method(), "invariant");
151
152 if (thread->has_last_Java_frame() && thread->last_Java_pc() == fr->pc()) {
153 // We're stopped at a call into the JVM so look for a PcDesc with
154 // the actual pc reported by the frame.
155 PcDesc* pc_desc = nm->pc_desc_at(fr->pc());
156
157 // Did we find a useful PcDesc?
158 if (pc_desc != NULL &&
159 pc_desc->scope_decode_offset() != DebugInformationRecorder::serialized_null) {
160 return true;
161 }
162 }
163
164 // We're at some random pc in the compiled method so search for the PcDesc
165 // whose pc is greater than the current PC. It's done this way
166 // because the extra PcDescs that are recorded for improved debug
167 // info record the end of the region covered by the ScopeDesc
168 // instead of the beginning.
169 PcDesc* pc_desc = nm->pc_desc_near(fr->pc() + 1);
170
171 // Now do we have a useful PcDesc?
172 if (pc_desc == NULL ||
173 pc_desc->scope_decode_offset() == DebugInformationRecorder::serialized_null) {
174 // No debug information is available for this PC.
175 //
176 // vframeStreamCommon::fill_from_frame() will decode the frame depending
177 // on the state of the thread.
178 //
179 // Case #1: If the thread is in Java (state == _thread_in_Java), then
180 // the vframeStreamCommon object will be filled as if the frame were a native
181 // compiled frame. Therefore, no debug information is needed.
182 //
183 // Case #2: If the thread is in any other state, then two steps will be performed:
184 // - if asserts are enabled, found_bad_method_frame() will be called and
282 // A frame is considered to be decipherable:
283 //
284 // - if the frame is a compiled frame and a PCDesc is available;
285 //
286 // - if the frame is an interpreter frame that is valid or the thread is
287 // state (_thread_in_native || state == _thread_in_vm || state == _thread_blocked).
288 //
289 // Note that find_initial_Java_frame() can return false even if an initial
290 // Java method was found (e.g., there is no PCDesc available for the method).
291 //
292 // If 'method_p' is NULL, it was not possible to find a Java frame when
293 // walking the stack starting from 'fr'. In this case find_initial_Java_frame
294 // returns false.
295
296 static bool find_initial_Java_frame(JavaThread* thread,
297 frame* fr,
298 frame* initial_frame_p,
299 Method** method_p,
300 int* bci_p) {
301
302 // It is possible that for a frame containing a compiled method
303 // we can capture the method but no bci. If we get no
304 // bci the frame isn't walkable but the method is usable.
305 // Therefore we init the returned Method* to NULL so the
306 // caller can make the distinction.
307
308 *method_p = NULL;
309
310 // On the initial call to this method the frame we get may not be
311 // recognizable to us. This should only happen if we are in a JRT_LEAF
312 // or something called by a JRT_LEAF method.
313
314 frame candidate = *fr;
315
316 // If the starting frame we were given has no codeBlob associated with
317 // it see if we can find such a frame because only frames with codeBlobs
318 // are possible Java frames.
319
320 if (fr->cb() == NULL) {
321
322 // See if we can find a useful frame
343 if (candidate.is_entry_frame()) {
344 // jcw is NULL if the java call wrapper couldn't be found
345 JavaCallWrapper *jcw = candidate.entry_frame_call_wrapper_if_safe(thread);
346 // If initial frame is frame from StubGenerator and there is no
347 // previous anchor, there are no java frames associated with a method
348 if (jcw == NULL || jcw->is_first_frame()) {
349 return false;
350 }
351 }
352
353 if (candidate.is_interpreted_frame()) {
354 if (is_decipherable_interpreted_frame(thread, &candidate, method_p, bci_p)) {
355 *initial_frame_p = candidate;
356 return true;
357 }
358
359 // Hopefully we got some data
360 return false;
361 }
362
363 if (candidate.cb()->is_compiled()) {
364
365 CompiledMethod* nm = candidate.cb()->as_compiled_method();
366 *method_p = nm->method();
367
368 // If the frame is not decipherable, then the value of -1
369 // for the BCI is used to signal that no BCI is available.
370 // Furthermore, the method returns false in this case.
371 //
372 // If a decipherable frame is available, the BCI value will
373 // not be used.
374
375 *bci_p = -1;
376
377 *initial_frame_p = candidate;
378
379 // Native wrapper code is trivial to decode by vframeStream
380
381 if (nm->is_native_method()) return true;
382
383 // If the frame is not decipherable, then a PC was found
384 // that does not have a PCDesc from which a BCI can be obtained.
385 // Nevertheless, a Method was found.
|