Fri, 06 Dec 2019 12:42:29 +0100
8235243: handle VS2017 15.9 and VS2019 in abstract_vm_version
8235325: build failure on Linux after 8235243
Reviewed-by: dholmes, mdoerr
duke@435 | 1 | /* |
drchase@7605 | 2 | * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/javaClasses.hpp" |
stefank@2314 | 27 | #include "classfile/systemDictionary.hpp" |
stefank@2314 | 28 | #include "classfile/vmSymbols.hpp" |
stefank@2314 | 29 | #include "code/codeCache.hpp" |
stefank@2314 | 30 | #include "code/debugInfoRec.hpp" |
stefank@2314 | 31 | #include "code/nmethod.hpp" |
stefank@2314 | 32 | #include "code/pcDesc.hpp" |
stefank@2314 | 33 | #include "code/scopeDesc.hpp" |
stefank@2314 | 34 | #include "interpreter/interpreter.hpp" |
stefank@2314 | 35 | #include "interpreter/oopMapCache.hpp" |
stefank@2314 | 36 | #include "memory/resourceArea.hpp" |
stefank@2314 | 37 | #include "oops/instanceKlass.hpp" |
stefank@2314 | 38 | #include "oops/oop.inline.hpp" |
stefank@2314 | 39 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 40 | #include "runtime/objectMonitor.hpp" |
stefank@2314 | 41 | #include "runtime/objectMonitor.inline.hpp" |
stefank@2314 | 42 | #include "runtime/signature.hpp" |
stefank@2314 | 43 | #include "runtime/stubRoutines.hpp" |
stefank@2314 | 44 | #include "runtime/synchronizer.hpp" |
stefank@2314 | 45 | #include "runtime/vframe.hpp" |
stefank@2314 | 46 | #include "runtime/vframeArray.hpp" |
stefank@2314 | 47 | #include "runtime/vframe_hp.hpp" |
duke@435 | 48 | |
drchase@6680 | 49 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
drchase@6680 | 50 | |
duke@435 | 51 | vframe::vframe(const frame* fr, const RegisterMap* reg_map, JavaThread* thread) |
duke@435 | 52 | : _reg_map(reg_map), _thread(thread) { |
duke@435 | 53 | assert(fr != NULL, "must have frame"); |
duke@435 | 54 | _fr = *fr; |
duke@435 | 55 | } |
duke@435 | 56 | |
duke@435 | 57 | vframe::vframe(const frame* fr, JavaThread* thread) |
duke@435 | 58 | : _reg_map(thread), _thread(thread) { |
duke@435 | 59 | assert(fr != NULL, "must have frame"); |
duke@435 | 60 | _fr = *fr; |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | vframe* vframe::new_vframe(const frame* f, const RegisterMap* reg_map, JavaThread* thread) { |
duke@435 | 64 | // Interpreter frame |
duke@435 | 65 | if (f->is_interpreted_frame()) { |
duke@435 | 66 | return new interpretedVFrame(f, reg_map, thread); |
duke@435 | 67 | } |
duke@435 | 68 | |
duke@435 | 69 | // Compiled frame |
duke@435 | 70 | CodeBlob* cb = f->cb(); |
duke@435 | 71 | if (cb != NULL) { |
duke@435 | 72 | if (cb->is_nmethod()) { |
duke@435 | 73 | nmethod* nm = (nmethod*)cb; |
duke@435 | 74 | return new compiledVFrame(f, reg_map, thread, nm); |
duke@435 | 75 | } |
duke@435 | 76 | |
duke@435 | 77 | if (f->is_runtime_frame()) { |
duke@435 | 78 | // Skip this frame and try again. |
duke@435 | 79 | RegisterMap temp_map = *reg_map; |
duke@435 | 80 | frame s = f->sender(&temp_map); |
duke@435 | 81 | return new_vframe(&s, &temp_map, thread); |
duke@435 | 82 | } |
duke@435 | 83 | } |
duke@435 | 84 | |
duke@435 | 85 | // External frame |
duke@435 | 86 | return new externalVFrame(f, reg_map, thread); |
duke@435 | 87 | } |
duke@435 | 88 | |
duke@435 | 89 | vframe* vframe::sender() const { |
duke@435 | 90 | RegisterMap temp_map = *register_map(); |
duke@435 | 91 | assert(is_top(), "just checking"); |
duke@435 | 92 | if (_fr.is_entry_frame() && _fr.is_first_frame()) return NULL; |
duke@435 | 93 | frame s = _fr.real_sender(&temp_map); |
duke@435 | 94 | if (s.is_first_frame()) return NULL; |
duke@435 | 95 | return vframe::new_vframe(&s, &temp_map, thread()); |
duke@435 | 96 | } |
duke@435 | 97 | |
duke@435 | 98 | vframe* vframe::top() const { |
duke@435 | 99 | vframe* vf = (vframe*) this; |
duke@435 | 100 | while (!vf->is_top()) vf = vf->sender(); |
duke@435 | 101 | return vf; |
duke@435 | 102 | } |
duke@435 | 103 | |
duke@435 | 104 | |
duke@435 | 105 | javaVFrame* vframe::java_sender() const { |
duke@435 | 106 | vframe* f = sender(); |
duke@435 | 107 | while (f != NULL) { |
duke@435 | 108 | if (f->is_java_frame()) return javaVFrame::cast(f); |
duke@435 | 109 | f = f->sender(); |
duke@435 | 110 | } |
duke@435 | 111 | return NULL; |
duke@435 | 112 | } |
duke@435 | 113 | |
duke@435 | 114 | // ------------- javaVFrame -------------- |
duke@435 | 115 | |
duke@435 | 116 | GrowableArray<MonitorInfo*>* javaVFrame::locked_monitors() { |
duke@435 | 117 | assert(SafepointSynchronize::is_at_safepoint() || JavaThread::current() == thread(), |
duke@435 | 118 | "must be at safepoint or it's a java frame of the current thread"); |
duke@435 | 119 | |
duke@435 | 120 | GrowableArray<MonitorInfo*>* mons = monitors(); |
duke@435 | 121 | GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(mons->length()); |
duke@435 | 122 | if (mons->is_empty()) return result; |
duke@435 | 123 | |
duke@435 | 124 | bool found_first_monitor = false; |
duke@435 | 125 | ObjectMonitor *pending_monitor = thread()->current_pending_monitor(); |
duke@435 | 126 | ObjectMonitor *waiting_monitor = thread()->current_waiting_monitor(); |
jcoomes@1902 | 127 | oop pending_obj = (pending_monitor != NULL ? (oop) pending_monitor->object() : (oop) NULL); |
jcoomes@1902 | 128 | oop waiting_obj = (waiting_monitor != NULL ? (oop) waiting_monitor->object() : (oop) NULL); |
duke@435 | 129 | |
duke@435 | 130 | for (int index = (mons->length()-1); index >= 0; index--) { |
duke@435 | 131 | MonitorInfo* monitor = mons->at(index); |
kvn@1253 | 132 | if (monitor->eliminated() && is_compiled_frame()) continue; // skip eliminated monitor |
duke@435 | 133 | oop obj = monitor->owner(); |
duke@435 | 134 | if (obj == NULL) continue; // skip unowned monitor |
duke@435 | 135 | // |
duke@435 | 136 | // Skip the monitor that the thread is blocked to enter or waiting on |
duke@435 | 137 | // |
duke@435 | 138 | if (!found_first_monitor && (obj == pending_obj || obj == waiting_obj)) { |
duke@435 | 139 | continue; |
duke@435 | 140 | } |
duke@435 | 141 | found_first_monitor = true; |
duke@435 | 142 | result->append(monitor); |
duke@435 | 143 | } |
duke@435 | 144 | return result; |
duke@435 | 145 | } |
duke@435 | 146 | |
duke@435 | 147 | static void print_locked_object_class_name(outputStream* st, Handle obj, const char* lock_state) { |
duke@435 | 148 | if (obj.not_null()) { |
duke@435 | 149 | st->print("\t- %s <" INTPTR_FORMAT "> ", lock_state, (address)obj()); |
never@1577 | 150 | if (obj->klass() == SystemDictionary::Class_klass()) { |
vkempik@8060 | 151 | st->print_cr("(a java.lang.Class for %s)", java_lang_Class::as_external_name(obj())); |
duke@435 | 152 | } else { |
hseigel@4278 | 153 | Klass* k = obj->klass(); |
duke@435 | 154 | st->print_cr("(a %s)", k->external_name()); |
duke@435 | 155 | } |
duke@435 | 156 | } |
duke@435 | 157 | } |
duke@435 | 158 | |
duke@435 | 159 | void javaVFrame::print_lock_info_on(outputStream* st, int frame_count) { |
duke@435 | 160 | ResourceMark rm; |
duke@435 | 161 | |
duke@435 | 162 | // If this is the first frame, and java.lang.Object.wait(...) then print out the receiver. |
duke@435 | 163 | if (frame_count == 0) { |
duke@435 | 164 | if (method()->name() == vmSymbols::wait_name() && |
coleenp@4251 | 165 | method()->method_holder()->name() == vmSymbols::java_lang_Object()) { |
duke@435 | 166 | StackValueCollection* locs = locals(); |
duke@435 | 167 | if (!locs->is_empty()) { |
duke@435 | 168 | StackValue* sv = locs->at(0); |
duke@435 | 169 | if (sv->type() == T_OBJECT) { |
duke@435 | 170 | Handle o = locs->at(0)->get_obj(); |
duke@435 | 171 | print_locked_object_class_name(st, o, "waiting on"); |
duke@435 | 172 | } |
duke@435 | 173 | } |
duke@435 | 174 | } else if (thread()->current_park_blocker() != NULL) { |
duke@435 | 175 | oop obj = thread()->current_park_blocker(); |
hseigel@4278 | 176 | Klass* k = obj->klass(); |
duke@435 | 177 | st->print_cr("\t- %s <" INTPTR_FORMAT "> (a %s)", "parking to wait for ", (address)obj, k->external_name()); |
duke@435 | 178 | } |
duke@435 | 179 | } |
duke@435 | 180 | |
duke@435 | 181 | |
duke@435 | 182 | // Print out all monitors that we have locked or are trying to lock |
duke@435 | 183 | GrowableArray<MonitorInfo*>* mons = monitors(); |
duke@435 | 184 | if (!mons->is_empty()) { |
duke@435 | 185 | bool found_first_monitor = false; |
duke@435 | 186 | for (int index = (mons->length()-1); index >= 0; index--) { |
duke@435 | 187 | MonitorInfo* monitor = mons->at(index); |
kvn@1253 | 188 | if (monitor->eliminated() && is_compiled_frame()) { // Eliminated in compiled code |
kvn@1253 | 189 | if (monitor->owner_is_scalar_replaced()) { |
coleenp@4037 | 190 | Klass* k = java_lang_Class::as_Klass(monitor->owner_klass()); |
drchase@7605 | 191 | // format below for lockbits matches this one. |
kvn@1253 | 192 | st->print("\t- eliminated <owner is scalar replaced> (a %s)", k->external_name()); |
kvn@1253 | 193 | } else { |
kvn@1253 | 194 | oop obj = monitor->owner(); |
kvn@1253 | 195 | if (obj != NULL) { |
kvn@1253 | 196 | print_locked_object_class_name(st, obj, "eliminated"); |
kvn@1253 | 197 | } |
kvn@1253 | 198 | } |
kvn@1253 | 199 | continue; |
kvn@1253 | 200 | } |
duke@435 | 201 | if (monitor->owner() != NULL) { |
dcubed@6708 | 202 | // the monitor is associated with an object, i.e., it is locked |
duke@435 | 203 | |
duke@435 | 204 | // First, assume we have the monitor locked. If we haven't found an |
duke@435 | 205 | // owned monitor before and this is the first frame, then we need to |
duke@435 | 206 | // see if we have completed the lock or we are blocked trying to |
duke@435 | 207 | // acquire it - we can only be blocked if the monitor is inflated |
duke@435 | 208 | |
drchase@7605 | 209 | markOop mark = NULL; |
duke@435 | 210 | const char *lock_state = "locked"; // assume we have the monitor locked |
duke@435 | 211 | if (!found_first_monitor && frame_count == 0) { |
drchase@7605 | 212 | mark = monitor->owner()->mark(); |
kvn@1253 | 213 | if (mark->has_monitor() && |
dcubed@6708 | 214 | ( // we have marked ourself as pending on this monitor |
dcubed@6708 | 215 | mark->monitor() == thread()->current_pending_monitor() || |
dcubed@6708 | 216 | // we are not the owner of this monitor |
dcubed@6708 | 217 | !mark->monitor()->is_entered(thread()) |
dcubed@6708 | 218 | )) { |
duke@435 | 219 | lock_state = "waiting to lock"; |
drchase@7605 | 220 | } else { |
drchase@7605 | 221 | mark = NULL; // Disable printing below |
kvn@1253 | 222 | } |
duke@435 | 223 | } |
drchase@7605 | 224 | print_locked_object_class_name(st, monitor->owner(), lock_state); |
drchase@7605 | 225 | if (Verbose && mark != NULL) { |
drchase@7605 | 226 | // match with format above, replacing "-" with " ". |
drchase@7605 | 227 | st->print("\t lockbits="); |
drchase@7605 | 228 | mark->print_on(st); |
drchase@7605 | 229 | st->cr(); |
drchase@7605 | 230 | } |
duke@435 | 231 | |
duke@435 | 232 | found_first_monitor = true; |
duke@435 | 233 | } |
duke@435 | 234 | } |
duke@435 | 235 | } |
duke@435 | 236 | } |
duke@435 | 237 | |
duke@435 | 238 | // ------------- interpretedVFrame -------------- |
duke@435 | 239 | |
duke@435 | 240 | u_char* interpretedVFrame::bcp() const { |
duke@435 | 241 | return fr().interpreter_frame_bcp(); |
duke@435 | 242 | } |
duke@435 | 243 | |
duke@435 | 244 | void interpretedVFrame::set_bcp(u_char* bcp) { |
duke@435 | 245 | fr().interpreter_frame_set_bcp(bcp); |
duke@435 | 246 | } |
duke@435 | 247 | |
duke@435 | 248 | intptr_t* interpretedVFrame::locals_addr_at(int offset) const { |
duke@435 | 249 | assert(fr().is_interpreted_frame(), "frame should be an interpreted frame"); |
duke@435 | 250 | return fr().interpreter_frame_local_at(offset); |
duke@435 | 251 | } |
duke@435 | 252 | |
duke@435 | 253 | |
duke@435 | 254 | GrowableArray<MonitorInfo*>* interpretedVFrame::monitors() const { |
duke@435 | 255 | GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(5); |
duke@435 | 256 | for (BasicObjectLock* current = (fr().previous_monitor_in_interpreter_frame(fr().interpreter_frame_monitor_begin())); |
duke@435 | 257 | current >= fr().interpreter_frame_monitor_end(); |
duke@435 | 258 | current = fr().previous_monitor_in_interpreter_frame(current)) { |
kvn@1253 | 259 | result->push(new MonitorInfo(current->obj(), current->lock(), false, false)); |
duke@435 | 260 | } |
duke@435 | 261 | return result; |
duke@435 | 262 | } |
duke@435 | 263 | |
duke@435 | 264 | int interpretedVFrame::bci() const { |
duke@435 | 265 | return method()->bci_from(bcp()); |
duke@435 | 266 | } |
duke@435 | 267 | |
coleenp@4037 | 268 | Method* interpretedVFrame::method() const { |
duke@435 | 269 | return fr().interpreter_frame_method(); |
duke@435 | 270 | } |
duke@435 | 271 | |
mgronlun@7215 | 272 | static StackValue* create_stack_value_from_oop_map(const InterpreterOopMap& oop_mask, |
mgronlun@7215 | 273 | int index, |
mgronlun@7215 | 274 | const intptr_t* const addr) { |
duke@435 | 275 | |
mgronlun@7215 | 276 | assert(index >= 0 && |
mgronlun@7215 | 277 | index < oop_mask.number_of_entries(), "invariant"); |
mgronlun@7215 | 278 | |
mgronlun@7215 | 279 | // categorize using oop_mask |
mgronlun@7215 | 280 | if (oop_mask.is_oop(index)) { |
mgronlun@7215 | 281 | // reference (oop) "r" |
mgronlun@7215 | 282 | Handle h(addr != NULL ? (*(oop*)addr) : (oop)NULL); |
mgronlun@7215 | 283 | return new StackValue(h); |
mgronlun@7215 | 284 | } |
mgronlun@7215 | 285 | // value (integer) "v" |
mgronlun@7215 | 286 | return new StackValue(addr != NULL ? *addr : 0); |
mgronlun@7215 | 287 | } |
mgronlun@7215 | 288 | |
mgronlun@7215 | 289 | static bool is_in_expression_stack(const frame& fr, const intptr_t* const addr) { |
mgronlun@7215 | 290 | assert(addr != NULL, "invariant"); |
mgronlun@7215 | 291 | |
mgronlun@7215 | 292 | // Ensure to be 'inside' the expresion stack (i.e., addr >= sp for Intel). |
mgronlun@7215 | 293 | // In case of exceptions, the expression stack is invalid and the sp |
mgronlun@7215 | 294 | // will be reset to express this condition. |
mgronlun@7215 | 295 | if (frame::interpreter_frame_expression_stack_direction() > 0) { |
mgronlun@7215 | 296 | return addr <= fr.interpreter_frame_tos_address(); |
duke@435 | 297 | } |
duke@435 | 298 | |
mgronlun@7215 | 299 | return addr >= fr.interpreter_frame_tos_address(); |
mgronlun@7215 | 300 | } |
duke@435 | 301 | |
mgronlun@7215 | 302 | static void stack_locals(StackValueCollection* result, |
mgronlun@7215 | 303 | int length, |
mgronlun@7215 | 304 | const InterpreterOopMap& oop_mask, |
mgronlun@7215 | 305 | const frame& fr) { |
mgronlun@7215 | 306 | |
mgronlun@7215 | 307 | assert(result != NULL, "invariant"); |
mgronlun@7215 | 308 | |
mgronlun@7215 | 309 | for (int i = 0; i < length; ++i) { |
mgronlun@7215 | 310 | const intptr_t* const addr = fr.interpreter_frame_local_at(i); |
mgronlun@7215 | 311 | assert(addr != NULL, "invariant"); |
mgronlun@7215 | 312 | assert(addr >= fr.sp(), "must be inside the frame"); |
mgronlun@7215 | 313 | |
mgronlun@7215 | 314 | StackValue* const sv = create_stack_value_from_oop_map(oop_mask, i, addr); |
mgronlun@7215 | 315 | assert(sv != NULL, "sanity check"); |
mgronlun@7215 | 316 | |
mgronlun@7215 | 317 | result->add(sv); |
mgronlun@7215 | 318 | } |
mgronlun@7215 | 319 | } |
mgronlun@7215 | 320 | |
mgronlun@7215 | 321 | static void stack_expressions(StackValueCollection* result, |
mgronlun@7215 | 322 | int length, |
mgronlun@7215 | 323 | int max_locals, |
mgronlun@7215 | 324 | const InterpreterOopMap& oop_mask, |
mgronlun@7215 | 325 | const frame& fr) { |
mgronlun@7215 | 326 | |
mgronlun@7215 | 327 | assert(result != NULL, "invariant"); |
mgronlun@7215 | 328 | |
mgronlun@7215 | 329 | for (int i = 0; i < length; ++i) { |
mgronlun@7215 | 330 | const intptr_t* addr = fr.interpreter_frame_expression_stack_at(i); |
mgronlun@7215 | 331 | assert(addr != NULL, "invariant"); |
mgronlun@7215 | 332 | if (!is_in_expression_stack(fr, addr)) { |
mgronlun@7215 | 333 | // Need to ensure no bogus escapes. |
mgronlun@7215 | 334 | addr = NULL; |
mgronlun@7215 | 335 | } |
mgronlun@7215 | 336 | |
mgronlun@7215 | 337 | StackValue* const sv = create_stack_value_from_oop_map(oop_mask, |
mgronlun@7215 | 338 | i + max_locals, |
mgronlun@7215 | 339 | addr); |
mgronlun@7215 | 340 | assert(sv != NULL, "sanity check"); |
mgronlun@7215 | 341 | |
mgronlun@7215 | 342 | result->add(sv); |
mgronlun@7215 | 343 | } |
mgronlun@7215 | 344 | } |
mgronlun@7215 | 345 | |
mgronlun@7215 | 346 | StackValueCollection* interpretedVFrame::locals() const { |
mgronlun@7215 | 347 | return stack_data(false); |
mgronlun@7215 | 348 | } |
mgronlun@7215 | 349 | |
mgronlun@7215 | 350 | StackValueCollection* interpretedVFrame::expressions() const { |
mgronlun@7215 | 351 | return stack_data(true); |
mgronlun@7215 | 352 | } |
mgronlun@7215 | 353 | |
mgronlun@7215 | 354 | /* |
mgronlun@7215 | 355 | * Worker routine for fetching references and/or values |
mgronlun@7215 | 356 | * for a particular bci in the interpretedVFrame. |
mgronlun@7215 | 357 | * |
mgronlun@7215 | 358 | * Returns data for either "locals" or "expressions", |
mgronlun@7215 | 359 | * using bci relative oop_map (oop_mask) information. |
mgronlun@7215 | 360 | * |
mgronlun@7215 | 361 | * @param expressions bool switch controlling what data to return |
mgronlun@7215 | 362 | (false == locals / true == expressions) |
mgronlun@7215 | 363 | * |
mgronlun@7215 | 364 | */ |
mgronlun@7215 | 365 | StackValueCollection* interpretedVFrame::stack_data(bool expressions) const { |
mgronlun@7215 | 366 | |
twisti@1861 | 367 | InterpreterOopMap oop_mask; |
mgronlun@7215 | 368 | // oopmap for current bci |
twisti@1861 | 369 | if (TraceDeoptimization && Verbose) { |
mgronlun@7215 | 370 | methodHandle m_h(Thread::current(), method()); |
twisti@1861 | 371 | OopMapCache::compute_one_oop_map(m_h, bci(), &oop_mask); |
twisti@1861 | 372 | } else { |
twisti@1861 | 373 | method()->mask_for(bci(), &oop_mask); |
twisti@1861 | 374 | } |
duke@435 | 375 | |
mgronlun@7215 | 376 | const int mask_len = oop_mask.number_of_entries(); |
mgronlun@7215 | 377 | |
mgronlun@7215 | 378 | // If the method is native, method()->max_locals() is not telling the truth. |
mgronlun@7215 | 379 | // For our purposes, max locals instead equals the size of parameters. |
mgronlun@7215 | 380 | const int max_locals = method()->is_native() ? |
mgronlun@7215 | 381 | method()->size_of_parameters() : method()->max_locals(); |
mgronlun@7215 | 382 | |
mgronlun@7215 | 383 | assert(mask_len >= max_locals, "invariant"); |
mgronlun@7215 | 384 | |
mgronlun@7215 | 385 | const int length = expressions ? mask_len - max_locals : max_locals; |
mgronlun@7215 | 386 | assert(length >= 0, "invariant"); |
mgronlun@7215 | 387 | |
mgronlun@7215 | 388 | StackValueCollection* const result = new StackValueCollection(length); |
mgronlun@7215 | 389 | |
mgronlun@7215 | 390 | if (0 == length) { |
mgronlun@7215 | 391 | return result; |
duke@435 | 392 | } |
mgronlun@7215 | 393 | |
mgronlun@7215 | 394 | if (expressions) { |
mgronlun@7215 | 395 | stack_expressions(result, length, max_locals, oop_mask, fr()); |
mgronlun@7215 | 396 | } else { |
mgronlun@7215 | 397 | stack_locals(result, length, oop_mask, fr()); |
mgronlun@7215 | 398 | } |
mgronlun@7215 | 399 | |
mgronlun@7215 | 400 | assert(length == result->size(), "invariant"); |
mgronlun@7215 | 401 | |
duke@435 | 402 | return result; |
duke@435 | 403 | } |
duke@435 | 404 | |
duke@435 | 405 | void interpretedVFrame::set_locals(StackValueCollection* values) const { |
duke@435 | 406 | if (values == NULL || values->size() == 0) return; |
duke@435 | 407 | |
mgronlun@7215 | 408 | // If the method is native, max_locals is not telling the truth. |
mgronlun@7215 | 409 | // maxlocals then equals the size of parameters |
mgronlun@7215 | 410 | const int max_locals = method()->is_native() ? |
mgronlun@7215 | 411 | method()->size_of_parameters() : method()->max_locals(); |
duke@435 | 412 | |
mgronlun@7215 | 413 | assert(max_locals == values->size(), "Mismatch between actual stack format and supplied data"); |
duke@435 | 414 | |
duke@435 | 415 | // handle locals |
mgronlun@7215 | 416 | for (int i = 0; i < max_locals; i++) { |
duke@435 | 417 | // Find stack location |
duke@435 | 418 | intptr_t *addr = locals_addr_at(i); |
duke@435 | 419 | |
duke@435 | 420 | // Depending on oop/int put it in the right package |
mgronlun@7215 | 421 | const StackValue* const sv = values->at(i); |
duke@435 | 422 | assert(sv != NULL, "sanity check"); |
duke@435 | 423 | if (sv->type() == T_OBJECT) { |
duke@435 | 424 | *(oop *) addr = (sv->get_obj())(); |
duke@435 | 425 | } else { // integer |
duke@435 | 426 | *addr = sv->get_int(); |
duke@435 | 427 | } |
duke@435 | 428 | } |
duke@435 | 429 | } |
duke@435 | 430 | |
duke@435 | 431 | // ------------- cChunk -------------- |
duke@435 | 432 | |
duke@435 | 433 | entryVFrame::entryVFrame(const frame* fr, const RegisterMap* reg_map, JavaThread* thread) |
duke@435 | 434 | : externalVFrame(fr, reg_map, thread) {} |
duke@435 | 435 | |
duke@435 | 436 | |
duke@435 | 437 | void vframeStreamCommon::found_bad_method_frame() { |
duke@435 | 438 | // 6379830 Cut point for an assertion that occasionally fires when |
duke@435 | 439 | // we are using the performance analyzer. |
duke@435 | 440 | // Disable this assert when testing the analyzer with fastdebug. |
duke@435 | 441 | // -XX:SuppressErrorAt=vframe.cpp:XXX (XXX=following line number) |
duke@435 | 442 | assert(false, "invalid bci or invalid scope desc"); |
duke@435 | 443 | } |
duke@435 | 444 | |
duke@435 | 445 | // top-frame will be skipped |
duke@435 | 446 | vframeStream::vframeStream(JavaThread* thread, frame top_frame, |
duke@435 | 447 | bool stop_at_java_call_stub) : vframeStreamCommon(thread) { |
duke@435 | 448 | _stop_at_java_call_stub = stop_at_java_call_stub; |
duke@435 | 449 | |
duke@435 | 450 | // skip top frame, as it may not be at safepoint |
duke@435 | 451 | _frame = top_frame.sender(&_reg_map); |
duke@435 | 452 | while (!fill_from_frame()) { |
duke@435 | 453 | _frame = _frame.sender(&_reg_map); |
duke@435 | 454 | } |
duke@435 | 455 | } |
duke@435 | 456 | |
duke@435 | 457 | |
duke@435 | 458 | // Step back n frames, skip any pseudo frames in between. |
duke@435 | 459 | // This function is used in Class.forName, Class.newInstance, Method.Invoke, |
duke@435 | 460 | // AccessController.doPrivileged. |
duke@435 | 461 | void vframeStreamCommon::security_get_caller_frame(int depth) { |
twisti@4866 | 462 | assert(depth >= 0, err_msg("invalid depth: %d", depth)); |
twisti@4866 | 463 | for (int n = 0; !at_end(); security_next()) { |
twisti@4866 | 464 | if (!method()->is_ignored_by_security_stack_walk()) { |
twisti@4866 | 465 | if (n == depth) { |
twisti@4866 | 466 | // We have reached the desired depth; return. |
twisti@4866 | 467 | return; |
twisti@4866 | 468 | } |
twisti@4866 | 469 | n++; // this is a non-skipped frame; count it against the depth |
twisti@4866 | 470 | } |
twisti@4866 | 471 | } |
twisti@4866 | 472 | // NOTE: At this point there were not enough frames on the stack |
twisti@4866 | 473 | // to walk to depth. Callers of this method have to check for at_end. |
twisti@4866 | 474 | } |
duke@435 | 475 | |
twisti@4866 | 476 | |
twisti@4866 | 477 | void vframeStreamCommon::security_next() { |
twisti@4866 | 478 | if (method()->is_prefixed_native()) { |
twisti@4866 | 479 | skip_prefixed_method_and_wrappers(); // calls next() |
twisti@4866 | 480 | } else { |
twisti@4866 | 481 | next(); |
duke@435 | 482 | } |
duke@435 | 483 | } |
duke@435 | 484 | |
duke@435 | 485 | |
duke@435 | 486 | void vframeStreamCommon::skip_prefixed_method_and_wrappers() { |
duke@435 | 487 | ResourceMark rm; |
duke@435 | 488 | HandleMark hm; |
duke@435 | 489 | |
duke@435 | 490 | int method_prefix_count = 0; |
duke@435 | 491 | char** method_prefixes = JvmtiExport::get_all_native_method_prefixes(&method_prefix_count); |
duke@435 | 492 | KlassHandle prefixed_klass(method()->method_holder()); |
duke@435 | 493 | const char* prefixed_name = method()->name()->as_C_string(); |
duke@435 | 494 | size_t prefixed_name_len = strlen(prefixed_name); |
duke@435 | 495 | int prefix_index = method_prefix_count-1; |
duke@435 | 496 | |
duke@435 | 497 | while (!at_end()) { |
duke@435 | 498 | next(); |
duke@435 | 499 | if (method()->method_holder() != prefixed_klass()) { |
duke@435 | 500 | break; // classes don't match, can't be a wrapper |
duke@435 | 501 | } |
duke@435 | 502 | const char* name = method()->name()->as_C_string(); |
duke@435 | 503 | size_t name_len = strlen(name); |
duke@435 | 504 | size_t prefix_len = prefixed_name_len - name_len; |
duke@435 | 505 | if (prefix_len <= 0 || strcmp(name, prefixed_name + prefix_len) != 0) { |
duke@435 | 506 | break; // prefixed name isn't prefixed version of method name, can't be a wrapper |
duke@435 | 507 | } |
duke@435 | 508 | for (; prefix_index >= 0; --prefix_index) { |
duke@435 | 509 | const char* possible_prefix = method_prefixes[prefix_index]; |
duke@435 | 510 | size_t possible_prefix_len = strlen(possible_prefix); |
duke@435 | 511 | if (possible_prefix_len == prefix_len && |
duke@435 | 512 | strncmp(possible_prefix, prefixed_name, prefix_len) == 0) { |
duke@435 | 513 | break; // matching prefix found |
duke@435 | 514 | } |
duke@435 | 515 | } |
duke@435 | 516 | if (prefix_index < 0) { |
duke@435 | 517 | break; // didn't find the prefix, can't be a wrapper |
duke@435 | 518 | } |
duke@435 | 519 | prefixed_name = name; |
duke@435 | 520 | prefixed_name_len = name_len; |
duke@435 | 521 | } |
duke@435 | 522 | } |
duke@435 | 523 | |
duke@435 | 524 | |
duke@435 | 525 | void vframeStreamCommon::skip_reflection_related_frames() { |
duke@435 | 526 | while (!at_end() && |
duke@435 | 527 | (JDK_Version::is_gte_jdk14x_version() && UseNewReflection && |
coleenp@4251 | 528 | (method()->method_holder()->is_subclass_of(SystemDictionary::reflect_MethodAccessorImpl_klass()) || |
coleenp@4251 | 529 | method()->method_holder()->is_subclass_of(SystemDictionary::reflect_ConstructorAccessorImpl_klass())))) { |
duke@435 | 530 | next(); |
duke@435 | 531 | } |
duke@435 | 532 | } |
duke@435 | 533 | |
duke@435 | 534 | |
duke@435 | 535 | #ifndef PRODUCT |
duke@435 | 536 | void vframe::print() { |
duke@435 | 537 | if (WizardMode) _fr.print_value_on(tty,NULL); |
duke@435 | 538 | } |
duke@435 | 539 | |
duke@435 | 540 | |
duke@435 | 541 | void vframe::print_value() const { |
duke@435 | 542 | ((vframe*)this)->print(); |
duke@435 | 543 | } |
duke@435 | 544 | |
duke@435 | 545 | |
duke@435 | 546 | void entryVFrame::print_value() const { |
duke@435 | 547 | ((entryVFrame*)this)->print(); |
duke@435 | 548 | } |
duke@435 | 549 | |
duke@435 | 550 | void entryVFrame::print() { |
duke@435 | 551 | vframe::print(); |
duke@435 | 552 | tty->print_cr("C Chunk inbetween Java"); |
duke@435 | 553 | tty->print_cr("C link " INTPTR_FORMAT, _fr.link()); |
duke@435 | 554 | } |
duke@435 | 555 | |
duke@435 | 556 | |
duke@435 | 557 | // ------------- javaVFrame -------------- |
duke@435 | 558 | |
duke@435 | 559 | static void print_stack_values(const char* title, StackValueCollection* values) { |
duke@435 | 560 | if (values->is_empty()) return; |
duke@435 | 561 | tty->print_cr("\t%s:", title); |
duke@435 | 562 | values->print(); |
duke@435 | 563 | } |
duke@435 | 564 | |
duke@435 | 565 | |
duke@435 | 566 | void javaVFrame::print() { |
duke@435 | 567 | ResourceMark rm; |
duke@435 | 568 | vframe::print(); |
duke@435 | 569 | tty->print("\t"); |
duke@435 | 570 | method()->print_value(); |
duke@435 | 571 | tty->cr(); |
duke@435 | 572 | tty->print_cr("\tbci: %d", bci()); |
duke@435 | 573 | |
duke@435 | 574 | print_stack_values("locals", locals()); |
duke@435 | 575 | print_stack_values("expressions", expressions()); |
duke@435 | 576 | |
duke@435 | 577 | GrowableArray<MonitorInfo*>* list = monitors(); |
duke@435 | 578 | if (list->is_empty()) return; |
duke@435 | 579 | tty->print_cr("\tmonitor list:"); |
duke@435 | 580 | for (int index = (list->length()-1); index >= 0; index--) { |
duke@435 | 581 | MonitorInfo* monitor = list->at(index); |
kvn@1253 | 582 | tty->print("\t obj\t"); |
kvn@1253 | 583 | if (monitor->owner_is_scalar_replaced()) { |
coleenp@4037 | 584 | Klass* k = java_lang_Class::as_Klass(monitor->owner_klass()); |
kvn@1253 | 585 | tty->print("( is scalar replaced %s)", k->external_name()); |
kvn@1253 | 586 | } else if (monitor->owner() == NULL) { |
kvn@1253 | 587 | tty->print("( null )"); |
kvn@1253 | 588 | } else { |
kvn@1253 | 589 | monitor->owner()->print_value(); |
drchase@7605 | 590 | tty->print("(owner=" INTPTR_FORMAT ")", (address)monitor->owner()); |
kvn@1253 | 591 | } |
drchase@7605 | 592 | if (monitor->eliminated()) { |
drchase@7605 | 593 | if(is_compiled_frame()) { |
drchase@7605 | 594 | tty->print(" ( lock is eliminated in compiled frame )"); |
drchase@7605 | 595 | } else { |
drchase@7605 | 596 | tty->print(" ( lock is eliminated, frame not compiled )"); |
drchase@7605 | 597 | } |
drchase@7605 | 598 | } |
duke@435 | 599 | tty->cr(); |
duke@435 | 600 | tty->print("\t "); |
duke@435 | 601 | monitor->lock()->print_on(tty); |
duke@435 | 602 | tty->cr(); |
duke@435 | 603 | } |
duke@435 | 604 | } |
duke@435 | 605 | |
duke@435 | 606 | |
duke@435 | 607 | void javaVFrame::print_value() const { |
coleenp@4037 | 608 | Method* m = method(); |
coleenp@4251 | 609 | InstanceKlass* k = m->method_holder(); |
duke@435 | 610 | tty->print_cr("frame( sp=" INTPTR_FORMAT ", unextended_sp=" INTPTR_FORMAT ", fp=" INTPTR_FORMAT ", pc=" INTPTR_FORMAT ")", |
duke@435 | 611 | _fr.sp(), _fr.unextended_sp(), _fr.fp(), _fr.pc()); |
hseigel@4278 | 612 | tty->print("%s.%s", k->internal_name(), m->name()->as_C_string()); |
duke@435 | 613 | |
duke@435 | 614 | if (!m->is_native()) { |
coleenp@4251 | 615 | Symbol* source_name = k->source_file_name(); |
duke@435 | 616 | int line_number = m->line_number_from_bci(bci()); |
duke@435 | 617 | if (source_name != NULL && (line_number != -1)) { |
duke@435 | 618 | tty->print("(%s:%d)", source_name->as_C_string(), line_number); |
duke@435 | 619 | } |
duke@435 | 620 | } else { |
duke@435 | 621 | tty->print("(Native Method)"); |
duke@435 | 622 | } |
duke@435 | 623 | // Check frame size and print warning if it looks suspiciously large |
duke@435 | 624 | if (fr().sp() != NULL) { |
cfang@1228 | 625 | RegisterMap map = *register_map(); |
cfang@1228 | 626 | uint size = fr().frame_size(&map); |
duke@435 | 627 | #ifdef _LP64 |
duke@435 | 628 | if (size > 8*K) warning("SUSPICIOUSLY LARGE FRAME (%d)", size); |
duke@435 | 629 | #else |
duke@435 | 630 | if (size > 4*K) warning("SUSPICIOUSLY LARGE FRAME (%d)", size); |
duke@435 | 631 | #endif |
duke@435 | 632 | } |
duke@435 | 633 | } |
duke@435 | 634 | |
duke@435 | 635 | |
duke@435 | 636 | bool javaVFrame::structural_compare(javaVFrame* other) { |
duke@435 | 637 | // Check static part |
duke@435 | 638 | if (method() != other->method()) return false; |
duke@435 | 639 | if (bci() != other->bci()) return false; |
duke@435 | 640 | |
duke@435 | 641 | // Check locals |
duke@435 | 642 | StackValueCollection *locs = locals(); |
duke@435 | 643 | StackValueCollection *other_locs = other->locals(); |
duke@435 | 644 | assert(locs->size() == other_locs->size(), "sanity check"); |
duke@435 | 645 | int i; |
duke@435 | 646 | for(i = 0; i < locs->size(); i++) { |
duke@435 | 647 | // it might happen the compiler reports a conflict and |
duke@435 | 648 | // the interpreter reports a bogus int. |
duke@435 | 649 | if ( is_compiled_frame() && locs->at(i)->type() == T_CONFLICT) continue; |
duke@435 | 650 | if (other->is_compiled_frame() && other_locs->at(i)->type() == T_CONFLICT) continue; |
duke@435 | 651 | |
duke@435 | 652 | if (!locs->at(i)->equal(other_locs->at(i))) |
duke@435 | 653 | return false; |
duke@435 | 654 | } |
duke@435 | 655 | |
duke@435 | 656 | // Check expressions |
duke@435 | 657 | StackValueCollection* exprs = expressions(); |
duke@435 | 658 | StackValueCollection* other_exprs = other->expressions(); |
duke@435 | 659 | assert(exprs->size() == other_exprs->size(), "sanity check"); |
duke@435 | 660 | for(i = 0; i < exprs->size(); i++) { |
duke@435 | 661 | if (!exprs->at(i)->equal(other_exprs->at(i))) |
duke@435 | 662 | return false; |
duke@435 | 663 | } |
duke@435 | 664 | |
duke@435 | 665 | return true; |
duke@435 | 666 | } |
duke@435 | 667 | |
duke@435 | 668 | |
duke@435 | 669 | void javaVFrame::print_activation(int index) const { |
duke@435 | 670 | // frame number and method |
duke@435 | 671 | tty->print("%2d - ", index); |
duke@435 | 672 | ((vframe*)this)->print_value(); |
duke@435 | 673 | tty->cr(); |
duke@435 | 674 | |
duke@435 | 675 | if (WizardMode) { |
duke@435 | 676 | ((vframe*)this)->print(); |
duke@435 | 677 | tty->cr(); |
duke@435 | 678 | } |
duke@435 | 679 | } |
duke@435 | 680 | |
duke@435 | 681 | |
duke@435 | 682 | void javaVFrame::verify() const { |
duke@435 | 683 | } |
duke@435 | 684 | |
duke@435 | 685 | |
duke@435 | 686 | void interpretedVFrame::verify() const { |
duke@435 | 687 | } |
duke@435 | 688 | |
duke@435 | 689 | |
duke@435 | 690 | // ------------- externalVFrame -------------- |
duke@435 | 691 | |
duke@435 | 692 | void externalVFrame::print() { |
duke@435 | 693 | _fr.print_value_on(tty,NULL); |
duke@435 | 694 | } |
duke@435 | 695 | |
duke@435 | 696 | |
duke@435 | 697 | void externalVFrame::print_value() const { |
duke@435 | 698 | ((vframe*)this)->print(); |
duke@435 | 699 | } |
duke@435 | 700 | #endif // PRODUCT |