/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
javaVFrame* vframe::java_sender() const {
vframe* f = sender(); while (f != NULL) { if (f->is_vthread_entry()) break; if (f->is_java_frame() && !javaVFrame::cast(f)->method()->is_continuation_enter_intrinsic()) return javaVFrame::cast(f);
f = f->sender();
} return NULL;
}
// ------------- javaVFrame --------------
GrowableArray<MonitorInfo*>* javaVFrame::locked_monitors() {
assert(SafepointSynchronize::is_at_safepoint() || JavaThread::current() == thread(), "must be at safepoint or it's a java frame of the current thread");
GrowableArray<MonitorInfo*>* mons = monitors();
GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(mons->length()); if (mons->is_empty()) return result;
bool found_first_monitor = false; // The ObjectMonitor* can't be async deflated since we are either // at a safepoint or the calling thread is operating on itself so // it cannot exit the ObjectMonitor so it remains busy.
ObjectMonitor *waiting_monitor = thread()->current_waiting_monitor();
ObjectMonitor *pending_monitor = NULL; if (waiting_monitor == NULL) {
pending_monitor = thread()->current_pending_monitor();
}
oop pending_obj = (pending_monitor != NULL ? pending_monitor->object() : (oop) NULL);
oop waiting_obj = (waiting_monitor != NULL ? waiting_monitor->object() : (oop) NULL);
for (int index = (mons->length()-1); index >= 0; index--) {
MonitorInfo* monitor = mons->at(index); if (monitor->eliminated() && is_compiled_frame()) continue; // skip eliminated monitor
oop obj = monitor->owner(); if (obj == NULL) continue; // skip unowned monitor // // Skip the monitor that the thread is blocked to enter or waiting on // if (!found_first_monitor && (obj == pending_obj || obj == waiting_obj)) { continue;
}
found_first_monitor = true;
result->append(monitor);
} return result;
}
void javaVFrame::print_lock_info_on(outputStream* st, int frame_count) {
Thread* current = Thread::current();
ResourceMark rm(current);
HandleMark hm(current);
// If this is the first frame and it is java.lang.Object.wait(...) // then print out the receiver. Locals are not always available, // e.g., compiled native frames have no scope so there are no locals. if (frame_count == 0) { if (method()->name() == vmSymbols::wait_name() &&
method()->method_holder()->name() == vmSymbols::java_lang_Object()) { constchar *wait_state = "waiting on"; // assume we are waiting // If earlier in the output we reported java.lang.Thread.State == // "WAITING (on object monitor)" and now we report "waiting on", then // we are still waiting for notification or timeout. Otherwise if // we earlier reported java.lang.Thread.State == "BLOCKED (on object // monitor)", then we are actually waiting to re-lock the monitor.
StackValueCollection* locs = locals(); if (!locs->is_empty()) {
StackValue* sv = locs->at(0); if (sv->type() == T_OBJECT) {
Handle o = locs->at(0)->get_obj(); if (java_lang_Thread::get_thread_status(thread()->threadObj()) ==
JavaThreadStatus::BLOCKED_ON_MONITOR_ENTER) {
wait_state = "waiting to re-lock in wait()";
}
print_locked_object_class_name(st, o, wait_state);
}
} else {
st->print_cr("\t- %s ", wait_state);
}
} elseif (thread()->current_park_blocker() != NULL) {
oop obj = thread()->current_park_blocker();
Klass* k = obj->klass();
st->print_cr("\t- %s <" INTPTR_FORMAT "> (a %s)", "parking to wait for ", p2i(obj), k->external_name());
} elseif (thread()->osthread()->get_state() == CONDVAR_WAIT) { // We are waiting on the native class initialization monitor.
InstanceKlass* k = thread()->class_to_be_initialized(); if (k != NULL) {
st->print_cr("\t- waiting on the Class initialization monitor for %s", k->external_name());
}
}
}
// Print out all monitors that we have locked, or are trying to lock, // including re-locking after being notified or timing out in a wait().
GrowableArray<MonitorInfo*>* mons = monitors(); if (!mons->is_empty()) { bool found_first_monitor = false; for (int index = (mons->length()-1); index >= 0; index--) {
MonitorInfo* monitor = mons->at(index); if (monitor->eliminated() && is_compiled_frame()) { // Eliminated in compiled code if (monitor->owner_is_scalar_replaced()) {
Klass* k = java_lang_Class::as_Klass(monitor->owner_klass());
st->print_cr("\t- eliminated (a %s)", k->external_name());
} else {
Handle obj(current, monitor->owner()); if (obj() != NULL) {
print_locked_object_class_name(st, obj, "eliminated");
}
} continue;
} if (monitor->owner() != NULL) { // the monitor is associated with an object, i.e., it is locked
constchar *lock_state = "locked"; // assume we have the monitor locked if (!found_first_monitor && frame_count == 0) { // If this is the first frame and we haven't found an owned // monitor before, then we need to see if we have completed // the lock or if we are blocked trying to acquire it. Only // an inflated monitor that is first on the monitor list in // the first frame can block us on a monitor enter.
markWord mark = monitor->owner()->mark(); // The first stage of async deflation does not affect any field // used by this comparison so the ObjectMonitor* is usable here. if (mark.has_monitor() &&
( // we have marked ourself as pending on this monitor
mark.monitor() == thread()->current_pending_monitor() || // we are not the owner of this monitor
!mark.monitor()->is_entered(thread())
)) {
lock_state = "waiting to lock";
}
}
print_locked_object_class_name(st, Handle(current, monitor->owner()), lock_state);
intptr_t* interpretedVFrame::locals_addr_at(int offset) const {
assert(stack_chunk() == NULL, "Not supported for heap frames"); // unsupported for now because seems to be unused
assert(fr().is_interpreted_frame(), "frame should be an interpreted frame"); return fr().interpreter_frame_local_at(offset);
}
GrowableArray<MonitorInfo*>* interpretedVFrame::monitors() const {
GrowableArray<MonitorInfo*>* result = new GrowableArray<MonitorInfo*>(5); if (stack_chunk() == NULL) { // no monitors in continuations for (BasicObjectLock* current = (fr().previous_monitor_in_interpreter_frame(fr().interpreter_frame_monitor_begin()));
current >= fr().interpreter_frame_monitor_end();
current = fr().previous_monitor_in_interpreter_frame(current)) {
result->push(new MonitorInfo(current->obj(), current->lock(), false, false));
}
} return result;
}
int interpretedVFrame::bci() const { return method()->bci_from(bcp());
}
// Ensure to be 'inside' the expression stack (i.e., addr >= sp for Intel). // In case of exceptions, the expression stack is invalid and the sp // will be reset to express this condition. if (frame::interpreter_frame_expression_stack_direction() > 0) { return addr <= fr.interpreter_frame_tos_address();
}
/* * Worker routine for fetching references and/or values * for a particular bci in the interpretedVFrame. * * Returns data for either "locals" or "expressions", * using bci relative oop_map (oop_mask) information. * * @param expressions bool switch controlling what data to return (false == locals / true == expression) *
*/
StackValueCollection* interpretedVFrame::stack_data(bool expressions) const {
// If the method is native, method()->max_locals() is not telling the truth. // For our purposes, max locals instead equals the size of parameters. constint max_locals = method()->is_native() ?
method()->size_of_parameters() : method()->max_locals();
// If the method is native, max_locals is not telling the truth. // maxlocals then equals the size of parameters constint max_locals = method()->is_native() ?
method()->size_of_parameters() : method()->max_locals();
assert(max_locals == values->size(), "Mismatch between actual stack format and supplied data");
// handle locals for (int i = 0; i < max_locals; i++) { // Find stack location
intptr_t *addr = locals_addr_at(i);
// Depending on oop/int put it in the right package const StackValue* const sv = values->at(i);
assert(sv != NULL, "sanity check"); if (sv->type() == T_OBJECT) {
*(oop *) addr = (sv->get_obj())();
} else { // integer
*addr = sv->get_int();
}
}
}
#ifdef ASSERT void vframeStreamCommon::found_bad_method_frame() const { // 6379830 Cut point for an assertion that occasionally fires when // we are using the performance analyzer. // Disable this assert when testing the analyzer with fastdebug. // -XX:SuppressErrorAt=vframe.cpp:XXX (XXX=following line number)
fatal("invalid bci or invalid scope desc");
} #endif
// Step back n frames, skip any pseudo frames in between. // This function is used in Class.forName, Class.newInstance, Method.Invoke, // AccessController.doPrivileged. void vframeStreamCommon::security_get_caller_frame(int depth) {
assert(depth >= 0, "invalid depth: %d", depth); for (int n = 0; !at_end(); security_next()) { if (!method()->is_ignored_by_security_stack_walk()) { if (n == depth) { // We have reached the desired depth; return. return;
}
n++; // this is a non-skipped frame; count it against the depth
}
} // NOTE: At this point there were not enough frames on the stack // to walk to depth. Callers of this method have to check for at_end.
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.