src/share/vm/runtime/vframe.cpp

Thu, 24 May 2018 20:03:11 +0800

author
aoqi
date
Thu, 24 May 2018 20:03:11 +0800
changeset 8868
91ddc23482a4
parent 8604
04d83ba48607
permissions
-rw-r--r--

Increase MaxHeapSize for better performance on MIPS

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

mercurial