author | mchung |
Wed, 14 Sep 2016 11:53:20 -0700 | |
changeset 41095 | 97cca074c2be |
parent 40001 | f37246e66d2b |
child 41280 | 74b314ad1e9a |
permissions | -rw-r--r-- |
34253 | 1 |
/* |
40001 | 2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
34253 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "precompiled.hpp" |
|
26 |
#include "classfile/javaClasses.hpp" |
|
27 |
#include "classfile/javaClasses.inline.hpp" |
|
28 |
#include "classfile/vmSymbols.hpp" |
|
29 |
#include "memory/oopFactory.hpp" |
|
30 |
#include "oops/oop.inline.hpp" |
|
31 |
#include "oops/objArrayOop.inline.hpp" |
|
32 |
#include "prims/stackwalk.hpp" |
|
33 |
#include "runtime/globals.hpp" |
|
34 |
#include "runtime/handles.inline.hpp" |
|
35 |
#include "runtime/javaCalls.hpp" |
|
36 |
#include "runtime/vframe.hpp" |
|
37 |
#include "utilities/globalDefinitions.hpp" |
|
38 |
||
39 |
// setup and cleanup actions |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
40 |
void JavaFrameStream::setup_magic_on_entry(objArrayHandle frames_array) { |
37438 | 41 |
frames_array->obj_at_put(magic_pos, _thread->threadObj()); |
34253 | 42 |
_anchor = address_value(); |
37438 | 43 |
assert(check_magic(frames_array), "invalid magic"); |
34253 | 44 |
} |
45 |
||
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
46 |
bool JavaFrameStream::check_magic(objArrayHandle frames_array) { |
37438 | 47 |
oop m1 = frames_array->obj_at(magic_pos); |
34253 | 48 |
jlong m2 = _anchor; |
49 |
if (m1 == _thread->threadObj() && m2 == address_value()) return true; |
|
50 |
return false; |
|
51 |
} |
|
52 |
||
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
53 |
bool JavaFrameStream::cleanup_magic_on_exit(objArrayHandle frames_array) { |
37438 | 54 |
bool ok = check_magic(frames_array); |
55 |
frames_array->obj_at_put(magic_pos, NULL); |
|
34253 | 56 |
_anchor = 0L; |
57 |
return ok; |
|
58 |
} |
|
59 |
||
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
60 |
// Returns JavaFrameStream for the current stack being traversed. |
34253 | 61 |
// |
62 |
// Parameters: |
|
63 |
// thread Current Java thread. |
|
64 |
// magic Magic value used for each stack walking |
|
37438 | 65 |
// frames_array User-supplied buffers. The 0th element is reserved |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
66 |
// to this JavaFrameStream to use |
34253 | 67 |
// |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
68 |
JavaFrameStream* JavaFrameStream::from_current(JavaThread* thread, jlong magic, |
37438 | 69 |
objArrayHandle frames_array) |
34253 | 70 |
{ |
71 |
assert(thread != NULL && thread->is_Java_thread(), ""); |
|
37438 | 72 |
oop m1 = frames_array->obj_at(magic_pos); |
34253 | 73 |
if (m1 != thread->threadObj()) return NULL; |
74 |
if (magic == 0L) return NULL; |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
75 |
JavaFrameStream* stream = (JavaFrameStream*) (intptr_t) magic; |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
76 |
if (!stream->is_valid_in(thread, frames_array)) return NULL; |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
77 |
return stream; |
34253 | 78 |
} |
79 |
||
80 |
// Unpacks one or more frames into user-supplied buffers. |
|
81 |
// Updates the end index, and returns the number of unpacked frames. |
|
82 |
// Always start with the existing vfst.method and bci. |
|
83 |
// Do not call vfst.next to advance over the last returned value. |
|
84 |
// In other words, do not leave any stale data in the vfst. |
|
85 |
// |
|
86 |
// Parameters: |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
87 |
// mode Restrict which frames to be decoded. |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
88 |
// JavaFrameStream stream of javaVFrames |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
89 |
// max_nframes Maximum number of frames to be filled. |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
90 |
// start_index Start index to the user-supplied buffers. |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
91 |
// frames_array Buffer to store Class or StackFrame in, starting at start_index. |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
92 |
// frames array is a Class<?>[] array when only getting caller |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
93 |
// reference, and a StackFrameInfo[] array (or derivative) |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
94 |
// otherwise. It should never be null. |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
95 |
// end_index End index to the user-supplied buffers with unpacked frames. |
34253 | 96 |
// |
97 |
// Returns the number of frames whose information was transferred into the buffers. |
|
98 |
// |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
99 |
int StackWalk::fill_in_frames(jlong mode, JavaFrameStream& stream, |
34253 | 100 |
int max_nframes, int start_index, |
101 |
objArrayHandle frames_array, |
|
102 |
int& end_index, TRAPS) { |
|
103 |
if (TraceStackWalk) { |
|
104 |
tty->print_cr("fill_in_frames limit=%d start=%d frames length=%d", |
|
37438 | 105 |
max_nframes, start_index, frames_array->length()); |
34253 | 106 |
} |
107 |
assert(max_nframes > 0, "invalid max_nframes"); |
|
37438 | 108 |
assert(start_index + max_nframes <= frames_array->length(), "oob"); |
34253 | 109 |
|
110 |
int frames_decoded = 0; |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
111 |
for (; !stream.at_end(); stream.next()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
112 |
Method* method = stream.method(); |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
113 |
int bci = stream.bci(); |
34253 | 114 |
|
115 |
if (method == NULL) continue; |
|
41095
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
116 |
|
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
117 |
// skip hidden frames for default StackWalker option (i.e. SHOW_HIDDEN_FRAMES |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
118 |
// not set) and when StackWalker::getCallerClass is called |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
119 |
if (!ShowHiddenFrames && (skip_hidden_frames(mode) || get_caller_class(mode))) { |
34253 | 120 |
if (method->is_hidden()) { |
121 |
if (TraceStackWalk) { |
|
122 |
tty->print(" hidden method: "); method->print_short_name(); |
|
123 |
tty->print("\n"); |
|
124 |
} |
|
125 |
continue; |
|
126 |
} |
|
127 |
} |
|
128 |
||
129 |
int index = end_index++; |
|
130 |
if (TraceStackWalk) { |
|
131 |
tty->print(" %d: frame method: ", index); method->print_short_name(); |
|
132 |
tty->print_cr(" bci=%d", bci); |
|
133 |
} |
|
134 |
||
135 |
// fill in StackFrameInfo and initialize MemberName |
|
136 |
if (live_frame_info(mode)) { |
|
37438 | 137 |
assert (use_frames_array(mode), "Bad mode for get live frame"); |
34253 | 138 |
Handle stackFrame(frames_array->obj_at(index)); |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
139 |
fill_live_stackframe(stackFrame, method, bci, stream.java_frame(), CHECK_0); |
34253 | 140 |
} else if (need_method_info(mode)) { |
37438 | 141 |
assert (use_frames_array(mode), "Bad mode for get stack frame"); |
34253 | 142 |
Handle stackFrame(frames_array->obj_at(index)); |
143 |
fill_stackframe(stackFrame, method, bci); |
|
37438 | 144 |
} else { |
41095
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
145 |
assert (use_frames_array(mode) == false, "Bad mode for filling in Class object"); |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
146 |
if (get_caller_class(mode) && index == start_index && method->caller_sensitive()) { |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
147 |
ResourceMark rm(THREAD); |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
148 |
THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
149 |
err_msg("StackWalker::getCallerClass called from @CallerSensitive %s method", |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
150 |
method->name_and_sig_as_C_string())); |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
151 |
} |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
152 |
|
37438 | 153 |
frames_array->obj_at_put(index, method->method_holder()->java_mirror()); |
34253 | 154 |
} |
155 |
if (++frames_decoded >= max_nframes) break; |
|
156 |
} |
|
157 |
return frames_decoded; |
|
158 |
} |
|
159 |
||
160 |
static oop create_primitive_value_instance(StackValueCollection* values, int i, TRAPS) { |
|
161 |
Klass* k = SystemDictionary::resolve_or_null(vmSymbols::java_lang_LiveStackFrameInfo(), CHECK_NULL); |
|
162 |
instanceKlassHandle ik (THREAD, k); |
|
163 |
||
164 |
JavaValue result(T_OBJECT); |
|
165 |
JavaCallArguments args; |
|
166 |
Symbol* signature = NULL; |
|
167 |
||
168 |
// ## TODO: type is only available in LocalVariable table, if present. |
|
169 |
// ## StackValue type is T_INT or T_OBJECT. |
|
170 |
switch (values->at(i)->type()) { |
|
171 |
case T_INT: |
|
172 |
args.push_int(values->int_at(i)); |
|
173 |
signature = vmSymbols::asPrimitive_int_signature(); |
|
174 |
break; |
|
175 |
||
176 |
case T_LONG: |
|
177 |
args.push_long(values->long_at(i)); |
|
178 |
signature = vmSymbols::asPrimitive_long_signature(); |
|
179 |
break; |
|
180 |
||
181 |
case T_FLOAT: |
|
182 |
args.push_float(values->float_at(i)); |
|
183 |
signature = vmSymbols::asPrimitive_float_signature(); |
|
184 |
break; |
|
185 |
||
186 |
case T_DOUBLE: |
|
187 |
args.push_double(values->double_at(i)); |
|
188 |
signature = vmSymbols::asPrimitive_double_signature(); |
|
189 |
break; |
|
190 |
||
191 |
case T_BYTE: |
|
192 |
args.push_int(values->int_at(i)); |
|
193 |
signature = vmSymbols::asPrimitive_byte_signature(); |
|
194 |
break; |
|
195 |
||
196 |
case T_SHORT: |
|
197 |
args.push_int(values->int_at(i)); |
|
198 |
signature = vmSymbols::asPrimitive_short_signature(); |
|
199 |
break; |
|
200 |
||
201 |
case T_CHAR: |
|
202 |
args.push_int(values->int_at(i)); |
|
203 |
signature = vmSymbols::asPrimitive_char_signature(); |
|
204 |
break; |
|
205 |
||
206 |
case T_BOOLEAN: |
|
207 |
args.push_int(values->int_at(i)); |
|
208 |
signature = vmSymbols::asPrimitive_boolean_signature(); |
|
209 |
break; |
|
210 |
||
211 |
case T_OBJECT: |
|
212 |
return values->obj_at(i)(); |
|
213 |
||
214 |
case T_CONFLICT: |
|
215 |
// put a non-null slot |
|
216 |
args.push_int(0); |
|
217 |
signature = vmSymbols::asPrimitive_int_signature(); |
|
218 |
break; |
|
219 |
||
220 |
default: ShouldNotReachHere(); |
|
221 |
} |
|
222 |
JavaCalls::call_static(&result, |
|
223 |
ik, |
|
224 |
vmSymbols::asPrimitive_name(), |
|
225 |
signature, |
|
226 |
&args, |
|
227 |
CHECK_NULL); |
|
228 |
return (instanceOop) result.get_jobject(); |
|
229 |
} |
|
230 |
||
231 |
static objArrayHandle values_to_object_array(StackValueCollection* values, TRAPS) { |
|
232 |
objArrayHandle empty; |
|
233 |
int length = values->size(); |
|
234 |
objArrayOop array_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), |
|
235 |
length, CHECK_(empty)); |
|
236 |
objArrayHandle array_h(THREAD, array_oop); |
|
237 |
for (int i = 0; i < values->size(); i++) { |
|
238 |
StackValue* st = values->at(i); |
|
239 |
oop obj = create_primitive_value_instance(values, i, CHECK_(empty)); |
|
240 |
if (obj != NULL) |
|
241 |
array_h->obj_at_put(i, obj); |
|
242 |
} |
|
243 |
return array_h; |
|
244 |
} |
|
245 |
||
246 |
static objArrayHandle monitors_to_object_array(GrowableArray<MonitorInfo*>* monitors, TRAPS) { |
|
247 |
int length = monitors->length(); |
|
248 |
objArrayOop array_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), |
|
249 |
length, CHECK_(objArrayHandle())); |
|
250 |
objArrayHandle array_h(THREAD, array_oop); |
|
251 |
for (int i = 0; i < length; i++) { |
|
252 |
MonitorInfo* monitor = monitors->at(i); |
|
253 |
array_h->obj_at_put(i, monitor->owner()); |
|
254 |
} |
|
255 |
return array_h; |
|
256 |
} |
|
257 |
||
258 |
// Fill StackFrameInfo with declaringClass and bci and initialize memberName |
|
259 |
void StackWalk::fill_stackframe(Handle stackFrame, const methodHandle& method, int bci) { |
|
260 |
java_lang_StackFrameInfo::set_declaringClass(stackFrame(), method->method_holder()->java_mirror()); |
|
261 |
java_lang_StackFrameInfo::set_method_and_bci(stackFrame(), method, bci); |
|
262 |
} |
|
263 |
||
264 |
// Fill LiveStackFrameInfo with locals, monitors, and expressions |
|
265 |
void StackWalk::fill_live_stackframe(Handle stackFrame, const methodHandle& method, |
|
266 |
int bci, javaVFrame* jvf, TRAPS) { |
|
267 |
fill_stackframe(stackFrame, method, bci); |
|
268 |
if (jvf != NULL) { |
|
269 |
StackValueCollection* locals = jvf->locals(); |
|
270 |
StackValueCollection* expressions = jvf->expressions(); |
|
271 |
GrowableArray<MonitorInfo*>* monitors = jvf->monitors(); |
|
272 |
||
273 |
if (!locals->is_empty()) { |
|
274 |
objArrayHandle locals_h = values_to_object_array(locals, CHECK); |
|
275 |
java_lang_LiveStackFrameInfo::set_locals(stackFrame(), locals_h()); |
|
276 |
} |
|
277 |
if (!expressions->is_empty()) { |
|
278 |
objArrayHandle expressions_h = values_to_object_array(expressions, CHECK); |
|
279 |
java_lang_LiveStackFrameInfo::set_operands(stackFrame(), expressions_h()); |
|
280 |
} |
|
281 |
if (monitors->length() > 0) { |
|
282 |
objArrayHandle monitors_h = monitors_to_object_array(monitors, CHECK); |
|
283 |
java_lang_LiveStackFrameInfo::set_monitors(stackFrame(), monitors_h()); |
|
284 |
} |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
// Begins stack walking. |
|
289 |
// |
|
290 |
// Parameters: |
|
291 |
// stackStream StackStream object |
|
292 |
// mode Stack walking mode. |
|
293 |
// skip_frames Number of frames to be skipped. |
|
294 |
// frame_count Number of frames to be traversed. |
|
295 |
// start_index Start index to the user-supplied buffers. |
|
296 |
// frames_array Buffer to store StackFrame in, starting at start_index. |
|
37438 | 297 |
// frames array is a Class<?>[] array when only getting caller |
298 |
// reference, and a StackFrameInfo[] array (or derivative) |
|
299 |
// otherwise. It should never be null. |
|
34253 | 300 |
// |
301 |
// Returns Object returned from AbstractStackWalker::doStackWalk call. |
|
302 |
// |
|
303 |
oop StackWalk::walk(Handle stackStream, jlong mode, |
|
304 |
int skip_frames, int frame_count, int start_index, |
|
305 |
objArrayHandle frames_array, |
|
306 |
TRAPS) { |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
307 |
ResourceMark rm(THREAD); |
34253 | 308 |
JavaThread* jt = (JavaThread*)THREAD; |
309 |
if (TraceStackWalk) { |
|
310 |
tty->print_cr("Start walking: mode " JLONG_FORMAT " skip %d frames batch size %d", |
|
311 |
mode, skip_frames, frame_count); |
|
312 |
} |
|
313 |
||
37438 | 314 |
if (frames_array.is_null()) { |
315 |
THROW_MSG_(vmSymbols::java_lang_NullPointerException(), "frames_array is NULL", NULL); |
|
34253 | 316 |
} |
317 |
||
318 |
Klass* stackWalker_klass = SystemDictionary::StackWalker_klass(); |
|
319 |
Klass* abstractStackWalker_klass = SystemDictionary::AbstractStackWalker_klass(); |
|
320 |
||
321 |
methodHandle m_doStackWalk(THREAD, Universe::do_stack_walk_method()); |
|
322 |
||
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
323 |
// Setup traversal onto my stack. |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
324 |
RegisterMap regMap(jt, true); |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
325 |
JavaFrameStream stream(jt, ®Map); |
34253 | 326 |
{ |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
327 |
while (!stream.at_end()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
328 |
InstanceKlass* ik = stream.method()->method_holder(); |
37438 | 329 |
if (ik != stackWalker_klass && |
330 |
ik != abstractStackWalker_klass && ik->super() != abstractStackWalker_klass) { |
|
331 |
break; |
|
34253 | 332 |
} |
333 |
||
37438 | 334 |
if (TraceStackWalk) { |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
335 |
tty->print(" skip "); stream.method()->print_short_name(); tty->print("\n"); |
34253 | 336 |
} |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
337 |
stream.next(); |
34253 | 338 |
} |
339 |
||
340 |
// stack frame has been traversed individually and resume stack walk |
|
341 |
// from the stack frame at depth == skip_frames. |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
342 |
for (int n=0; n < skip_frames && !stream.at_end(); stream.next(), n++) { |
34253 | 343 |
if (TraceStackWalk) { |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
344 |
tty->print(" skip "); stream.method()->print_short_name(); |
34253 | 345 |
tty->print_cr(" frame id: " PTR_FORMAT " pc: " PTR_FORMAT, |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
346 |
p2i(stream.java_frame()->fr().id()), |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
347 |
p2i(stream.java_frame()->fr().pc())); |
34253 | 348 |
} |
349 |
} |
|
350 |
} |
|
351 |
||
352 |
int end_index = start_index; |
|
353 |
int numFrames = 0; |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
354 |
if (!stream.at_end()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
355 |
numFrames = fill_in_frames(mode, stream, frame_count, start_index, |
34253 | 356 |
frames_array, end_index, CHECK_NULL); |
357 |
if (numFrames < 1) { |
|
358 |
THROW_MSG_(vmSymbols::java_lang_InternalError(), "stack walk: decode failed", NULL); |
|
359 |
} |
|
360 |
} |
|
361 |
||
362 |
// JVM_CallStackWalk walks the stack and fills in stack frames, then calls to |
|
363 |
// Java method java.lang.StackStreamFactory.AbstractStackWalker::doStackWalk |
|
364 |
// which calls the implementation to consume the stack frames. |
|
365 |
// When JVM_CallStackWalk returns, it invalidates the stack stream. |
|
366 |
JavaValue result(T_OBJECT); |
|
367 |
JavaCallArguments args(stackStream); |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
368 |
args.push_long(stream.address_value()); |
34253 | 369 |
args.push_int(skip_frames); |
370 |
args.push_int(frame_count); |
|
371 |
args.push_int(start_index); |
|
372 |
args.push_int(end_index); |
|
373 |
||
374 |
// Link the thread and vframe stream into the callee-visible object |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
375 |
stream.setup_magic_on_entry(frames_array); |
34253 | 376 |
|
377 |
JavaCalls::call(&result, m_doStackWalk, &args, THREAD); |
|
378 |
||
379 |
// Do this before anything else happens, to disable any lingering stream objects |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
380 |
bool ok = stream.cleanup_magic_on_exit(frames_array); |
34253 | 381 |
|
382 |
// Throw pending exception if we must |
|
383 |
(void) (CHECK_NULL); |
|
384 |
||
385 |
if (!ok) { |
|
386 |
THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: corrupted buffers on exit", NULL); |
|
387 |
} |
|
388 |
||
389 |
// Return normally |
|
390 |
return (oop)result.get_jobject(); |
|
391 |
} |
|
392 |
||
393 |
// Walk the next batch of stack frames |
|
394 |
// |
|
395 |
// Parameters: |
|
396 |
// stackStream StackStream object |
|
397 |
// mode Stack walking mode. |
|
398 |
// magic Must be valid value to continue the stack walk |
|
399 |
// frame_count Number of frames to be decoded. |
|
400 |
// start_index Start index to the user-supplied buffers. |
|
401 |
// frames_array Buffer to store StackFrame in, starting at start_index. |
|
402 |
// |
|
403 |
// Returns the end index of frame filled in the buffer. |
|
404 |
// |
|
405 |
jint StackWalk::moreFrames(Handle stackStream, jlong mode, jlong magic, |
|
406 |
int frame_count, int start_index, |
|
407 |
objArrayHandle frames_array, |
|
408 |
TRAPS) |
|
409 |
{ |
|
410 |
JavaThread* jt = (JavaThread*)THREAD; |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
411 |
JavaFrameStream* existing_stream = JavaFrameStream::from_current(jt, magic, frames_array); |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
412 |
if (existing_stream == NULL) { |
34253 | 413 |
THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: corrupted buffers", 0L); |
414 |
} |
|
415 |
||
37438 | 416 |
if (frames_array.is_null()) { |
34253 | 417 |
THROW_MSG_(vmSymbols::java_lang_NullPointerException(), "frames_array is NULL", 0L); |
418 |
} |
|
419 |
||
420 |
if (TraceStackWalk) { |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
421 |
tty->print_cr("StackWalk::moreFrames frame_count %d existing_stream " PTR_FORMAT " start %d frames %d", |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
422 |
frame_count, p2i(existing_stream), start_index, frames_array->length()); |
34253 | 423 |
} |
424 |
int end_index = start_index; |
|
425 |
if (frame_count <= 0) { |
|
426 |
return end_index; // No operation. |
|
427 |
} |
|
428 |
||
429 |
int count = frame_count + start_index; |
|
37438 | 430 |
assert (frames_array->length() >= count, "not enough space in buffers"); |
34253 | 431 |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
432 |
JavaFrameStream& stream = (*existing_stream); |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
433 |
if (!stream.at_end()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
434 |
stream.next(); // advance past the last frame decoded in previous batch |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
435 |
if (!stream.at_end()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
436 |
int n = fill_in_frames(mode, stream, frame_count, start_index, |
34253 | 437 |
frames_array, end_index, CHECK_0); |
438 |
if (n < 1) { |
|
439 |
THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: later decode failed", 0L); |
|
440 |
} |
|
441 |
return end_index; |
|
442 |
} |
|
443 |
} |
|
444 |
return end_index; |
|
445 |
} |