author | rprotacio |
Thu, 29 Sep 2016 13:32:17 -0400 | |
changeset 41664 | 07e88a4b405f |
parent 41307 | a89905798992 |
child 46271 | 979ebd346ecf |
child 43677 | 5228814c1da2 |
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" |
|
41664
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
29 |
#include "logging/log.hpp" |
34253 | 30 |
#include "memory/oopFactory.hpp" |
31 |
#include "oops/oop.inline.hpp" |
|
32 |
#include "oops/objArrayOop.inline.hpp" |
|
33 |
#include "prims/stackwalk.hpp" |
|
34 |
#include "runtime/globals.hpp" |
|
35 |
#include "runtime/handles.inline.hpp" |
|
36 |
#include "runtime/javaCalls.hpp" |
|
37 |
#include "runtime/vframe.hpp" |
|
38 |
#include "utilities/globalDefinitions.hpp" |
|
39 |
||
40 |
// setup and cleanup actions |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
41 |
void BaseFrameStream::setup_magic_on_entry(objArrayHandle frames_array) { |
37438 | 42 |
frames_array->obj_at_put(magic_pos, _thread->threadObj()); |
34253 | 43 |
_anchor = address_value(); |
37438 | 44 |
assert(check_magic(frames_array), "invalid magic"); |
34253 | 45 |
} |
46 |
||
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
47 |
bool BaseFrameStream::check_magic(objArrayHandle frames_array) { |
37438 | 48 |
oop m1 = frames_array->obj_at(magic_pos); |
34253 | 49 |
jlong m2 = _anchor; |
50 |
if (m1 == _thread->threadObj() && m2 == address_value()) return true; |
|
51 |
return false; |
|
52 |
} |
|
53 |
||
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
54 |
bool BaseFrameStream::cleanup_magic_on_exit(objArrayHandle frames_array) { |
37438 | 55 |
bool ok = check_magic(frames_array); |
56 |
frames_array->obj_at_put(magic_pos, NULL); |
|
34253 | 57 |
_anchor = 0L; |
58 |
return ok; |
|
59 |
} |
|
60 |
||
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
61 |
JavaFrameStream::JavaFrameStream(JavaThread* thread, int mode) |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
62 |
: BaseFrameStream(thread), _vfst(thread) { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
63 |
_need_method_info = StackWalk::need_method_info(mode); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
64 |
} |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
65 |
|
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
66 |
// Returns the BaseFrameStream for the current stack being traversed. |
34253 | 67 |
// |
68 |
// Parameters: |
|
69 |
// thread Current Java thread. |
|
70 |
// magic Magic value used for each stack walking |
|
37438 | 71 |
// frames_array User-supplied buffers. The 0th element is reserved |
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
72 |
// for this BaseFrameStream to use |
34253 | 73 |
// |
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
74 |
BaseFrameStream* BaseFrameStream::from_current(JavaThread* thread, jlong magic, |
37438 | 75 |
objArrayHandle frames_array) |
34253 | 76 |
{ |
77 |
assert(thread != NULL && thread->is_Java_thread(), ""); |
|
37438 | 78 |
oop m1 = frames_array->obj_at(magic_pos); |
34253 | 79 |
if (m1 != thread->threadObj()) return NULL; |
80 |
if (magic == 0L) return NULL; |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
81 |
BaseFrameStream* stream = (BaseFrameStream*) (intptr_t) magic; |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
82 |
if (!stream->is_valid_in(thread, frames_array)) return NULL; |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
83 |
return stream; |
34253 | 84 |
} |
85 |
||
86 |
// Unpacks one or more frames into user-supplied buffers. |
|
87 |
// Updates the end index, and returns the number of unpacked frames. |
|
88 |
// Always start with the existing vfst.method and bci. |
|
89 |
// Do not call vfst.next to advance over the last returned value. |
|
90 |
// In other words, do not leave any stale data in the vfst. |
|
91 |
// |
|
92 |
// Parameters: |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
93 |
// mode Restrict which frames to be decoded. |
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
94 |
// BaseFrameStream stream of frames |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
95 |
// max_nframes Maximum number of frames to be filled. |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
96 |
// start_index Start index to the user-supplied buffers. |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
97 |
// 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
|
98 |
// frames array is a Class<?>[] array when only getting caller |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
99 |
// reference, and a StackFrameInfo[] array (or derivative) |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
100 |
// otherwise. It should never be null. |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
101 |
// end_index End index to the user-supplied buffers with unpacked frames. |
34253 | 102 |
// |
103 |
// Returns the number of frames whose information was transferred into the buffers. |
|
104 |
// |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
105 |
int StackWalk::fill_in_frames(jlong mode, BaseFrameStream& stream, |
34253 | 106 |
int max_nframes, int start_index, |
107 |
objArrayHandle frames_array, |
|
108 |
int& end_index, TRAPS) { |
|
41664
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
109 |
log_debug(stackwalk)("fill_in_frames limit=%d start=%d frames length=%d", |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
110 |
max_nframes, start_index, frames_array->length()); |
34253 | 111 |
assert(max_nframes > 0, "invalid max_nframes"); |
37438 | 112 |
assert(start_index + max_nframes <= frames_array->length(), "oob"); |
34253 | 113 |
|
114 |
int frames_decoded = 0; |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
115 |
for (; !stream.at_end(); stream.next()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
116 |
Method* method = stream.method(); |
34253 | 117 |
|
118 |
if (method == NULL) continue; |
|
41095
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
119 |
|
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
120 |
// 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
|
121 |
// not set) and when StackWalker::getCallerClass is called |
97cca074c2be
8157464: Disallow StackWalker.getCallerClass() be called by caller-sensitive method
mchung
parents:
40001
diff
changeset
|
122 |
if (!ShowHiddenFrames && (skip_hidden_frames(mode) || get_caller_class(mode))) { |
34253 | 123 |
if (method->is_hidden()) { |
41664
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
124 |
if (log_is_enabled(Debug, stackwalk)) { |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
125 |
ResourceMark rm(THREAD); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
126 |
outputStream* st = Log(stackwalk)::debug_stream(); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
127 |
st->print(" hidden method: "); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
128 |
method->print_short_name(st); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
129 |
st->cr(); |
34253 | 130 |
} |
131 |
continue; |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
int index = end_index++; |
|
41664
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
136 |
if (log_is_enabled(Debug, stackwalk)) { |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
137 |
ResourceMark rm(THREAD); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
138 |
outputStream* st = Log(stackwalk)::debug_stream(); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
139 |
st->print(" %d: frame method: ", index); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
140 |
method->print_short_name(st); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
141 |
st->print_cr(" bci=%d", stream.bci()); |
34253 | 142 |
} |
143 |
||
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
144 |
if (!need_method_info(mode) && get_caller_class(mode) && |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
145 |
index == start_index && method->caller_sensitive()) { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
146 |
ResourceMark rm(THREAD); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
147 |
THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
148 |
err_msg("StackWalker::getCallerClass called from @CallerSensitive %s method", |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
149 |
method->name_and_sig_as_C_string())); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
150 |
} |
34253 | 151 |
// fill in StackFrameInfo and initialize MemberName |
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
152 |
stream.fill_frame(index, frames_array, method, CHECK_0); |
34253 | 153 |
if (++frames_decoded >= max_nframes) break; |
154 |
} |
|
155 |
return frames_decoded; |
|
156 |
} |
|
157 |
||
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
158 |
// Fill in the LiveStackFrameInfo at the given index in frames_array |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
159 |
void LiveFrameStream::fill_frame(int index, objArrayHandle frames_array, |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
160 |
const methodHandle& method, TRAPS) { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
161 |
Handle stackFrame(THREAD, frames_array->obj_at(index)); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
162 |
fill_live_stackframe(stackFrame, method, CHECK); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
163 |
} |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
164 |
|
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
165 |
// Fill in the StackFrameInfo at the given index in frames_array |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
166 |
void JavaFrameStream::fill_frame(int index, objArrayHandle frames_array, |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
167 |
const methodHandle& method, TRAPS) { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
168 |
if (_need_method_info) { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
169 |
Handle stackFrame(THREAD, frames_array->obj_at(index)); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
170 |
fill_stackframe(stackFrame, method); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
171 |
} else { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
172 |
frames_array->obj_at_put(index, method->method_holder()->java_mirror()); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
173 |
} |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
174 |
} |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
175 |
|
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
176 |
oop LiveFrameStream::create_primitive_value_instance(StackValueCollection* values, int i, TRAPS) { |
34253 | 177 |
Klass* k = SystemDictionary::resolve_or_null(vmSymbols::java_lang_LiveStackFrameInfo(), CHECK_NULL); |
178 |
instanceKlassHandle ik (THREAD, k); |
|
179 |
||
180 |
JavaValue result(T_OBJECT); |
|
181 |
JavaCallArguments args; |
|
182 |
Symbol* signature = NULL; |
|
183 |
||
184 |
// ## TODO: type is only available in LocalVariable table, if present. |
|
185 |
// ## StackValue type is T_INT or T_OBJECT. |
|
186 |
switch (values->at(i)->type()) { |
|
187 |
case T_INT: |
|
188 |
args.push_int(values->int_at(i)); |
|
189 |
signature = vmSymbols::asPrimitive_int_signature(); |
|
190 |
break; |
|
191 |
||
192 |
case T_LONG: |
|
193 |
args.push_long(values->long_at(i)); |
|
194 |
signature = vmSymbols::asPrimitive_long_signature(); |
|
195 |
break; |
|
196 |
||
197 |
case T_FLOAT: |
|
198 |
args.push_float(values->float_at(i)); |
|
199 |
signature = vmSymbols::asPrimitive_float_signature(); |
|
200 |
break; |
|
201 |
||
202 |
case T_DOUBLE: |
|
203 |
args.push_double(values->double_at(i)); |
|
204 |
signature = vmSymbols::asPrimitive_double_signature(); |
|
205 |
break; |
|
206 |
||
207 |
case T_BYTE: |
|
208 |
args.push_int(values->int_at(i)); |
|
209 |
signature = vmSymbols::asPrimitive_byte_signature(); |
|
210 |
break; |
|
211 |
||
212 |
case T_SHORT: |
|
213 |
args.push_int(values->int_at(i)); |
|
214 |
signature = vmSymbols::asPrimitive_short_signature(); |
|
215 |
break; |
|
216 |
||
217 |
case T_CHAR: |
|
218 |
args.push_int(values->int_at(i)); |
|
219 |
signature = vmSymbols::asPrimitive_char_signature(); |
|
220 |
break; |
|
221 |
||
222 |
case T_BOOLEAN: |
|
223 |
args.push_int(values->int_at(i)); |
|
224 |
signature = vmSymbols::asPrimitive_boolean_signature(); |
|
225 |
break; |
|
226 |
||
227 |
case T_OBJECT: |
|
228 |
return values->obj_at(i)(); |
|
229 |
||
230 |
case T_CONFLICT: |
|
231 |
// put a non-null slot |
|
232 |
args.push_int(0); |
|
233 |
signature = vmSymbols::asPrimitive_int_signature(); |
|
234 |
break; |
|
235 |
||
236 |
default: ShouldNotReachHere(); |
|
237 |
} |
|
238 |
JavaCalls::call_static(&result, |
|
239 |
ik, |
|
240 |
vmSymbols::asPrimitive_name(), |
|
241 |
signature, |
|
242 |
&args, |
|
243 |
CHECK_NULL); |
|
244 |
return (instanceOop) result.get_jobject(); |
|
245 |
} |
|
246 |
||
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
247 |
objArrayHandle LiveFrameStream::values_to_object_array(StackValueCollection* values, TRAPS) { |
34253 | 248 |
objArrayHandle empty; |
249 |
int length = values->size(); |
|
250 |
objArrayOop array_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), |
|
251 |
length, CHECK_(empty)); |
|
252 |
objArrayHandle array_h(THREAD, array_oop); |
|
253 |
for (int i = 0; i < values->size(); i++) { |
|
254 |
StackValue* st = values->at(i); |
|
255 |
oop obj = create_primitive_value_instance(values, i, CHECK_(empty)); |
|
256 |
if (obj != NULL) |
|
257 |
array_h->obj_at_put(i, obj); |
|
258 |
} |
|
259 |
return array_h; |
|
260 |
} |
|
261 |
||
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
262 |
objArrayHandle LiveFrameStream::monitors_to_object_array(GrowableArray<MonitorInfo*>* monitors, TRAPS) { |
34253 | 263 |
int length = monitors->length(); |
264 |
objArrayOop array_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), |
|
265 |
length, CHECK_(objArrayHandle())); |
|
266 |
objArrayHandle array_h(THREAD, array_oop); |
|
267 |
for (int i = 0; i < length; i++) { |
|
268 |
MonitorInfo* monitor = monitors->at(i); |
|
269 |
array_h->obj_at_put(i, monitor->owner()); |
|
270 |
} |
|
271 |
return array_h; |
|
272 |
} |
|
273 |
||
274 |
// Fill StackFrameInfo with declaringClass and bci and initialize memberName |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
275 |
void BaseFrameStream::fill_stackframe(Handle stackFrame, const methodHandle& method) { |
34253 | 276 |
java_lang_StackFrameInfo::set_declaringClass(stackFrame(), method->method_holder()->java_mirror()); |
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
277 |
java_lang_StackFrameInfo::set_method_and_bci(stackFrame(), method, bci()); |
34253 | 278 |
} |
279 |
||
280 |
// Fill LiveStackFrameInfo with locals, monitors, and expressions |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
281 |
void LiveFrameStream::fill_live_stackframe(Handle stackFrame, |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
282 |
const methodHandle& method, TRAPS) { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
283 |
fill_stackframe(stackFrame, method); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
284 |
if (_jvf != NULL) { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
285 |
StackValueCollection* locals = _jvf->locals(); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
286 |
StackValueCollection* expressions = _jvf->expressions(); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
287 |
GrowableArray<MonitorInfo*>* monitors = _jvf->monitors(); |
34253 | 288 |
|
289 |
if (!locals->is_empty()) { |
|
290 |
objArrayHandle locals_h = values_to_object_array(locals, CHECK); |
|
291 |
java_lang_LiveStackFrameInfo::set_locals(stackFrame(), locals_h()); |
|
292 |
} |
|
293 |
if (!expressions->is_empty()) { |
|
294 |
objArrayHandle expressions_h = values_to_object_array(expressions, CHECK); |
|
295 |
java_lang_LiveStackFrameInfo::set_operands(stackFrame(), expressions_h()); |
|
296 |
} |
|
297 |
if (monitors->length() > 0) { |
|
298 |
objArrayHandle monitors_h = monitors_to_object_array(monitors, CHECK); |
|
299 |
java_lang_LiveStackFrameInfo::set_monitors(stackFrame(), monitors_h()); |
|
300 |
} |
|
301 |
} |
|
302 |
} |
|
303 |
||
304 |
// Begins stack walking. |
|
305 |
// |
|
306 |
// Parameters: |
|
307 |
// stackStream StackStream object |
|
308 |
// mode Stack walking mode. |
|
309 |
// skip_frames Number of frames to be skipped. |
|
310 |
// frame_count Number of frames to be traversed. |
|
311 |
// start_index Start index to the user-supplied buffers. |
|
312 |
// frames_array Buffer to store StackFrame in, starting at start_index. |
|
37438 | 313 |
// frames array is a Class<?>[] array when only getting caller |
314 |
// reference, and a StackFrameInfo[] array (or derivative) |
|
315 |
// otherwise. It should never be null. |
|
34253 | 316 |
// |
317 |
// Returns Object returned from AbstractStackWalker::doStackWalk call. |
|
318 |
// |
|
319 |
oop StackWalk::walk(Handle stackStream, jlong mode, |
|
320 |
int skip_frames, int frame_count, int start_index, |
|
321 |
objArrayHandle frames_array, |
|
322 |
TRAPS) { |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
323 |
ResourceMark rm(THREAD); |
34253 | 324 |
JavaThread* jt = (JavaThread*)THREAD; |
41664
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
325 |
log_debug(stackwalk)("Start walking: mode " JLONG_FORMAT " skip %d frames batch size %d", |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
326 |
mode, skip_frames, frame_count); |
34253 | 327 |
|
37438 | 328 |
if (frames_array.is_null()) { |
329 |
THROW_MSG_(vmSymbols::java_lang_NullPointerException(), "frames_array is NULL", NULL); |
|
34253 | 330 |
} |
331 |
||
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
332 |
// Setup traversal onto my stack. |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
333 |
if (live_frame_info(mode)) { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
334 |
assert (use_frames_array(mode), "Bad mode for get live frame"); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
335 |
RegisterMap regMap(jt, true); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
336 |
LiveFrameStream stream(jt, ®Map); |
41307
a89905798992
8166501: compilation error in stackwalk.cpp on some gccs
bchristi
parents:
41280
diff
changeset
|
337 |
return fetchFirstBatch(stream, stackStream, mode, skip_frames, frame_count, |
a89905798992
8166501: compilation error in stackwalk.cpp on some gccs
bchristi
parents:
41280
diff
changeset
|
338 |
start_index, frames_array, THREAD); |
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
339 |
} else { |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
340 |
JavaFrameStream stream(jt, mode); |
41307
a89905798992
8166501: compilation error in stackwalk.cpp on some gccs
bchristi
parents:
41280
diff
changeset
|
341 |
return fetchFirstBatch(stream, stackStream, mode, skip_frames, frame_count, |
a89905798992
8166501: compilation error in stackwalk.cpp on some gccs
bchristi
parents:
41280
diff
changeset
|
342 |
start_index, frames_array, THREAD); |
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
343 |
} |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
344 |
} |
34253 | 345 |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
346 |
oop StackWalk::fetchFirstBatch(BaseFrameStream& stream, Handle stackStream, |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
347 |
jlong mode, int skip_frames, int frame_count, |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
348 |
int start_index, objArrayHandle frames_array, TRAPS) { |
34253 | 349 |
methodHandle m_doStackWalk(THREAD, Universe::do_stack_walk_method()); |
350 |
||
351 |
{ |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
352 |
Klass* stackWalker_klass = SystemDictionary::StackWalker_klass(); |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
353 |
Klass* abstractStackWalker_klass = SystemDictionary::AbstractStackWalker_klass(); |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
354 |
while (!stream.at_end()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
355 |
InstanceKlass* ik = stream.method()->method_holder(); |
37438 | 356 |
if (ik != stackWalker_klass && |
357 |
ik != abstractStackWalker_klass && ik->super() != abstractStackWalker_klass) { |
|
358 |
break; |
|
34253 | 359 |
} |
360 |
||
41664
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
361 |
if (log_is_enabled(Debug, stackwalk)) { |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
362 |
ResourceMark rm(THREAD); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
363 |
outputStream* st = Log(stackwalk)::debug_stream(); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
364 |
st->print(" skip "); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
365 |
stream.method()->print_short_name(st); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
366 |
st->cr(); |
34253 | 367 |
} |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
368 |
stream.next(); |
34253 | 369 |
} |
370 |
||
371 |
// stack frame has been traversed individually and resume stack walk |
|
372 |
// from the stack frame at depth == skip_frames. |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
373 |
for (int n=0; n < skip_frames && !stream.at_end(); stream.next(), n++) { |
41664
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
374 |
if (log_is_enabled(Debug, stackwalk)) { |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
375 |
ResourceMark rm(THREAD); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
376 |
outputStream* st = Log(stackwalk)::debug_stream(); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
377 |
st->print(" skip "); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
378 |
stream.method()->print_short_name(st); |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
379 |
st->cr(); |
34253 | 380 |
} |
381 |
} |
|
382 |
} |
|
383 |
||
384 |
int end_index = start_index; |
|
385 |
int numFrames = 0; |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
386 |
if (!stream.at_end()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
387 |
numFrames = fill_in_frames(mode, stream, frame_count, start_index, |
34253 | 388 |
frames_array, end_index, CHECK_NULL); |
389 |
if (numFrames < 1) { |
|
390 |
THROW_MSG_(vmSymbols::java_lang_InternalError(), "stack walk: decode failed", NULL); |
|
391 |
} |
|
392 |
} |
|
393 |
||
394 |
// JVM_CallStackWalk walks the stack and fills in stack frames, then calls to |
|
395 |
// Java method java.lang.StackStreamFactory.AbstractStackWalker::doStackWalk |
|
396 |
// which calls the implementation to consume the stack frames. |
|
397 |
// When JVM_CallStackWalk returns, it invalidates the stack stream. |
|
398 |
JavaValue result(T_OBJECT); |
|
399 |
JavaCallArguments args(stackStream); |
|
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
400 |
args.push_long(stream.address_value()); |
34253 | 401 |
args.push_int(skip_frames); |
402 |
args.push_int(frame_count); |
|
403 |
args.push_int(start_index); |
|
404 |
args.push_int(end_index); |
|
405 |
||
406 |
// 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
|
407 |
stream.setup_magic_on_entry(frames_array); |
34253 | 408 |
|
409 |
JavaCalls::call(&result, m_doStackWalk, &args, THREAD); |
|
410 |
||
411 |
// 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
|
412 |
bool ok = stream.cleanup_magic_on_exit(frames_array); |
34253 | 413 |
|
414 |
// Throw pending exception if we must |
|
415 |
(void) (CHECK_NULL); |
|
416 |
||
417 |
if (!ok) { |
|
418 |
THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: corrupted buffers on exit", NULL); |
|
419 |
} |
|
420 |
||
421 |
// Return normally |
|
422 |
return (oop)result.get_jobject(); |
|
423 |
} |
|
424 |
||
425 |
// Walk the next batch of stack frames |
|
426 |
// |
|
427 |
// Parameters: |
|
428 |
// stackStream StackStream object |
|
429 |
// mode Stack walking mode. |
|
430 |
// magic Must be valid value to continue the stack walk |
|
431 |
// frame_count Number of frames to be decoded. |
|
432 |
// start_index Start index to the user-supplied buffers. |
|
433 |
// frames_array Buffer to store StackFrame in, starting at start_index. |
|
434 |
// |
|
435 |
// Returns the end index of frame filled in the buffer. |
|
436 |
// |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
437 |
jint StackWalk::fetchNextBatch(Handle stackStream, jlong mode, jlong magic, |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
438 |
int frame_count, int start_index, |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
439 |
objArrayHandle frames_array, |
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
440 |
TRAPS) |
34253 | 441 |
{ |
442 |
JavaThread* jt = (JavaThread*)THREAD; |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
443 |
BaseFrameStream* existing_stream = BaseFrameStream::from_current(jt, magic, frames_array); |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
444 |
if (existing_stream == NULL) { |
34253 | 445 |
THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: corrupted buffers", 0L); |
446 |
} |
|
447 |
||
37438 | 448 |
if (frames_array.is_null()) { |
34253 | 449 |
THROW_MSG_(vmSymbols::java_lang_NullPointerException(), "frames_array is NULL", 0L); |
450 |
} |
|
451 |
||
41664
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
452 |
log_debug(stackwalk)("StackWalk::fetchNextBatch frame_count %d existing_stream " |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
453 |
PTR_FORMAT " start %d frames %d", |
07e88a4b405f
8160064: StackWalker implementation added logging option without using UL
rprotacio
parents:
41307
diff
changeset
|
454 |
frame_count, p2i(existing_stream), start_index, frames_array->length()); |
34253 | 455 |
int end_index = start_index; |
456 |
if (frame_count <= 0) { |
|
457 |
return end_index; // No operation. |
|
458 |
} |
|
459 |
||
460 |
int count = frame_count + start_index; |
|
37438 | 461 |
assert (frames_array->length() >= count, "not enough space in buffers"); |
34253 | 462 |
|
41280
74b314ad1e9a
8165372: StackWalker performance regression following JDK-8147039
bchristi
parents:
41095
diff
changeset
|
463 |
BaseFrameStream& stream = (*existing_stream); |
38213
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
464 |
if (!stream.at_end()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
465 |
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
|
466 |
if (!stream.at_end()) { |
2f32787e31b1
8147039: Incorrect locals and operands in compiled frames
bchristi
parents:
37438
diff
changeset
|
467 |
int n = fill_in_frames(mode, stream, frame_count, start_index, |
34253 | 468 |
frames_array, end_index, CHECK_0); |
469 |
if (n < 1) { |
|
470 |
THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: later decode failed", 0L); |
|
471 |
} |
|
472 |
return end_index; |
|
473 |
} |
|
474 |
} |
|
475 |
return end_index; |
|
476 |
} |