// This class encapsulates various marks we need to deal with calling the // frame processing code from arbitrary points in the runtime. It is mostly // due to problems that we might want to eventually clean up inside of the // frame processing code, such as creating random handles even though there // is no safepoint to protect against, and fiddling around with exceptions. class StackWatermarkProcessingMark {
ResetNoHandleMark _rnhm;
HandleMark _hm;
PreserveExceptionMark _pem;
ResourceMark _rm;
#ifdef ASSERT void StackWatermark::assert_is_frame_safe(const frame& f) {
MutexLocker ml(&_lock, Mutex::_no_safepoint_check_flag);
assert(is_frame_safe(f), "Frame must be safe");
} #endif
// A frame is "safe" if it *and* its caller have been processed. This is the invariant // that allows exposing a frame, and for that frame to directly access its caller frame // without going through any hooks. bool StackWatermark::is_frame_safe(const frame& f) {
assert(_lock.owned_by_self(), "Must be locked");
uint32_t state = Atomic::load(&_state); if (!processing_started(state)) { returnfalse;
} if (processing_completed(state)) { returntrue;
} returnreinterpret_cast<uintptr_t>(f.sp()) < _iterator->caller();
}
void StackWatermark::start_processing_impl(void* context) {
log_info(stackbarrier)("Starting stack processing for tid %d",
_jt->osthread()->thread_id()); delete _iterator; if (_jt->has_last_Java_frame()) {
_iterator = new StackWatermarkFramesIterator(*this); // Always process three frames when starting an iteration. // // The three frames corresponds to: // 1) The callee frame // 2) The caller frame // This allows a callee to always be able to read state from its caller // without needing any special barriers. // // 3) An extra frame to deal with unwinding safepointing on the way out. // Sometimes, we also call into the runtime to on_unwind(), but then // hit a safepoint poll on the way out from the runtime.
_iterator->process_one(context);
_iterator->process_one(context);
_iterator->process_one(context);
} else {
_iterator = NULL;
}
update_watermark();
}
uintptr_t StackWatermark::last_processed() {
MutexLocker ml(&_lock, Mutex::_no_safepoint_check_flag); if (!processing_started()) { // Stale state; no last processed return0;
} if (processing_completed()) { // Already processed all; no last processed return0;
} return _iterator->caller();
}
// If the thread waking up from a safepoint expected certain other // stack watermarks (potentially from different threads) are processed, // then we have to perform processing of said linked watermarks here.
process_linked_watermarks();
}
void StackWatermark::start_processing() { if (!processing_started_acquire()) {
MutexLocker ml(&_lock, Mutex::_no_safepoint_check_flag); if (!processing_started()) {
start_processing_impl(NULL /* context */);
}
}
}
void StackWatermark::finish_processing(void* context) {
MutexLocker ml(&_lock, Mutex::_no_safepoint_check_flag); if (!processing_started()) {
start_processing_impl(context);
} if (!processing_completed()) {
_iterator->process_all(context);
update_watermark();
}
}
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 und die Messung sind noch experimentell.