25
#include "precompiled.hpp"
26
#include "code/codeCache.hpp"
27
#include "code/nmethod.hpp"
28
#include "code/pcDesc.hpp"
29
#include "code/scopeDesc.hpp"
30
#include "compiler/compilationPolicy.hpp"
31
#include "gc/shared/collectedHeap.hpp"
32
#include "gc/shared/gcLocker.hpp"
33
#include "gc/shared/oopStorage.hpp"
34
#include "gc/shared/strongRootsScope.hpp"
35
#include "gc/shared/workerThread.hpp"
36
#include "gc/shared/workerUtils.hpp"
37
#include "interpreter/interpreter.hpp"
38
#include "jfr/jfrEvents.hpp"
39
#include "logging/log.hpp"
40
#include "logging/logStream.hpp"
41
#include "memory/resourceArea.hpp"
42
#include "memory/universe.hpp"
43
#include "oops/oop.inline.hpp"
44
#include "oops/symbol.hpp"
45
#include "runtime/atomic.hpp"
46
#include "runtime/deoptimization.hpp"
47
#include "runtime/frame.inline.hpp"
48
#include "runtime/globals.hpp"
49
#include "runtime/handles.inline.hpp"
50
#include "runtime/interfaceSupport.inline.hpp"
51
#include "runtime/javaThread.inline.hpp"
52
#include "runtime/mutexLocker.hpp"
53
#include "runtime/orderAccess.hpp"
54
#include "runtime/osThread.hpp"
55
#include "runtime/safepoint.hpp"
56
#include "runtime/safepointMechanism.inline.hpp"
57
#include "runtime/signature.hpp"
58
#include "runtime/stackWatermarkSet.inline.hpp"
59
#include "runtime/stubCodeGenerator.hpp"
60
#include "runtime/stubRoutines.hpp"
61
#include "runtime/synchronizer.hpp"
62
#include "runtime/threads.hpp"
63
#include "runtime/threadSMR.hpp"
64
#include "runtime/threadWXSetters.inline.hpp"
65
#include "runtime/timerTrace.hpp"
66
#include "services/runtimeService.hpp"
67
#include "utilities/events.hpp"
68
#include "utilities/macros.hpp"
69
#include "utilities/systemMemoryBarrier.hpp"
71
static void post_safepoint_begin_event(EventSafepointBegin& event,
72
uint64_t safepoint_id,
74
int critical_thread_count) {
75
if (event.should_commit()) {
76
event.set_safepointId(safepoint_id);
77
event.set_totalThreadCount(thread_count);
78
event.set_jniCriticalThreadCount(critical_thread_count);
84
static void post_safepoint_synchronize_event(EventSafepointStateSynchronization& event,
85
uint64_t safepoint_id,
86
int initial_number_of_threads,
87
int threads_waiting_to_block,
89
if (event.should_commit()) {
90
event.set_safepointId(safepoint_id);
91
event.set_initialThreadCount(initial_number_of_threads);
92
event.set_runningThreadCount(threads_waiting_to_block);
93
event.set_iterations(checked_cast<u4>(iterations));
98
static void post_safepoint_end_event(EventSafepointEnd& event, uint64_t safepoint_id) {
99
if (event.should_commit()) {
100
event.set_safepointId(safepoint_id);
106
SafepointStateTracker::SafepointStateTracker(uint64_t safepoint_id, bool at_safepoint)
107
: _safepoint_id(safepoint_id), _at_safepoint(at_safepoint) {}
109
bool SafepointStateTracker::safepoint_state_changed() {
110
return _safepoint_id != SafepointSynchronize::safepoint_id() ||
111
_at_safepoint != SafepointSynchronize::is_at_safepoint();
117
SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized;
118
int SafepointSynchronize::_waiting_to_block = 0;
119
volatile uint64_t SafepointSynchronize::_safepoint_counter = 0;
120
uint64_t SafepointSynchronize::_safepoint_id = 0;
121
const uint64_t SafepointSynchronize::InactiveSafepointCounter = 0;
122
int SafepointSynchronize::_current_jni_active_count = 0;
124
WaitBarrier* SafepointSynchronize::_wait_barrier;
126
static bool timeout_error_printed = false;
129
static jlong _safepoint_begin_time = 0;
130
static volatile int _nof_threads_hit_polling_page = 0;
132
void SafepointSynchronize::init(Thread* vmthread) {
135
_wait_barrier = new WaitBarrier(vmthread);
136
SafepointTracing::init();
139
void SafepointSynchronize::increment_jni_active_count() {
140
assert(Thread::current()->is_VM_thread(), "Only VM thread may increment");
141
++_current_jni_active_count;
144
void SafepointSynchronize::decrement_waiting_to_block() {
145
assert(_waiting_to_block > 0, "sanity check");
146
assert(Thread::current()->is_VM_thread(), "Only VM thread may decrement");
150
bool SafepointSynchronize::thread_not_running(ThreadSafepointState *cur_state) {
151
if (!cur_state->is_running()) {
153
LogTarget(Error, safepoint) lt;
154
if (lt.is_enabled()) {
157
ls.print("Illegal initial state detected: ");
158
cur_state->print_on(&ls);
162
cur_state->examine_state_of_thread(SafepointSynchronize::safepoint_counter());
163
if (!cur_state->is_running()) {
166
LogTarget(Trace, safepoint) lt;
167
if (lt.is_enabled()) {
170
cur_state->print_on(&ls);
176
static void assert_list_is_valid(const ThreadSafepointState* tss_head, int still_running) {
178
const ThreadSafepointState *tmp_tss = tss_head;
179
while (tmp_tss != nullptr) {
181
assert(tmp_tss->is_running(), "Illegal initial state");
182
tmp_tss = tmp_tss->get_next();
184
assert(a == still_running, "Must be the same");
188
static void back_off(int64_t start_time) {
191
if (os::javaTimeNanos() - start_time < NANOSECS_PER_MILLISEC) {
192
os::naked_short_nanosleep(10 * (NANOUNITS / MICROUNITS));
194
os::naked_short_sleep(1);
198
int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running)
200
JavaThreadIteratorWithHandle jtiwh;
203
for (; JavaThread *cur = jtiwh.next(); ) {
204
assert(cur->safepoint_state()->is_running(), "Illegal initial state");
210
int still_running = nof_threads;
211
ThreadSafepointState *tss_head = nullptr;
212
ThreadSafepointState **p_prev = &tss_head;
213
for (; JavaThread *cur = jtiwh.next(); ) {
214
ThreadSafepointState *cur_tss = cur->safepoint_state();
215
assert(cur_tss->get_next() == nullptr, "Must be null");
216
if (thread_not_running(cur_tss)) {
220
p_prev = cur_tss->next_ptr();
225
DEBUG_ONLY(assert_list_is_valid(tss_head, still_running);)
227
*initial_running = still_running;
230
if (still_running <= 0) {
231
assert(tss_head == nullptr, "Must be empty");
236
int64_t start_time = os::javaTimeNanos();
240
if (SafepointTimeout && safepoint_limit_time < os::javaTimeNanos()) {
241
print_safepoint_timeout();
245
ThreadSafepointState *cur_tss = tss_head;
246
while (cur_tss != nullptr) {
247
assert(cur_tss->is_running(), "Illegal initial state");
248
if (thread_not_running(cur_tss)) {
251
ThreadSafepointState *tmp = cur_tss;
252
cur_tss = cur_tss->get_next();
253
tmp->set_next(nullptr);
256
p_prev = cur_tss->next_ptr();
257
cur_tss = cur_tss->get_next();
261
DEBUG_ONLY(assert_list_is_valid(tss_head, still_running);)
263
if (still_running > 0) {
264
back_off(start_time);
268
} while (still_running > 0);
270
assert(tss_head == nullptr, "Must be empty");
275
void SafepointSynchronize::arm_safepoint() {
307
_wait_barrier->arm(static_cast<int>(_safepoint_counter + 1));
309
assert((_safepoint_counter & 0x1) == 0, "must be even");
311
Atomic::release_store(&_safepoint_counter, _safepoint_counter + 1);
314
OrderAccess::storestore();
315
_state = _synchronizing;
318
log_trace(safepoint)("Setting thread local yield flag for threads");
319
OrderAccess::storestore();
320
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur = jtiwh.next(); ) {
322
SafepointMechanism::arm_local_poll(cur);
324
if (UseSystemMemoryBarrier) {
325
SystemMemoryBarrier::emit();
327
OrderAccess::fence();
332
void SafepointSynchronize::begin() {
333
assert(Thread::current()->is_VM_thread(), "Only VM thread may execute a safepoint");
335
EventSafepointBegin begin_event;
336
SafepointTracing::begin(VMThread::vm_op_type());
338
Universe::heap()->safepoint_synchronize_begin();
342
Threads_lock->lock();
344
assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state");
346
int nof_threads = Threads::number_of_threads();
348
_nof_threads_hit_polling_page = 0;
350
log_debug(safepoint)("Safepoint synchronization initiated using %s wait barrier. (%d threads)", _wait_barrier->description(), nof_threads);
353
_current_jni_active_count = 0;
356
_waiting_to_block = nof_threads;
358
jlong safepoint_limit_time = 0;
359
if (SafepointTimeout) {
362
safepoint_limit_time = SafepointTracing::start_of_safepoint() + (jlong)(SafepointTimeoutDelay * NANOSECS_PER_MILLISEC);
363
timeout_error_printed = false;
366
EventSafepointStateSynchronization sync_event;
367
int initial_running = 0;
373
int iterations = synchronize_threads(safepoint_limit_time, nof_threads, &initial_running);
374
assert(_waiting_to_block == 0, "No thread should be running");
378
if (VerifyCrossModifyFence) {
379
JavaThreadIteratorWithHandle jtiwh;
380
for (; JavaThread *cur = jtiwh.next(); ) {
381
cur->set_requires_cross_modify_fence(true);
385
if (safepoint_limit_time != 0) {
386
jlong current_time = os::javaTimeNanos();
387
if (safepoint_limit_time < current_time) {
388
log_warning(safepoint)("# SafepointSynchronize: Finished after "
389
INT64_FORMAT_W(6) " ms",
390
(int64_t)(current_time - SafepointTracing::start_of_safepoint()) / (NANOUNITS / MILLIUNITS));
395
assert(Threads_lock->owned_by_self(), "must hold Threads_lock");
398
_state = _synchronized;
400
OrderAccess::fence();
407
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur = jtiwh.next(); ) {
408
assert(cur->was_visited_for_critical_count(_safepoint_counter), "missed a thread");
413
GCLocker::set_jni_lock_count(_current_jni_active_count);
415
post_safepoint_synchronize_event(sync_event,
418
_waiting_to_block, iterations);
420
SafepointTracing::synchronized(nof_threads, initial_running, _nof_threads_hit_polling_page);
422
post_safepoint_begin_event(begin_event, _safepoint_id, nof_threads, _current_jni_active_count);
425
void SafepointSynchronize::disarm_safepoint() {
426
uint64_t active_safepoint_counter = _safepoint_counter;
428
JavaThreadIteratorWithHandle jtiwh;
433
for (; JavaThread *cur = jtiwh.next(); ) {
434
assert (!(cur->has_pending_exception() &&
435
cur->safepoint_state()->is_at_poll_safepoint()),
436
"safepoint installed a pending exception");
440
OrderAccess::fence();
441
assert(_state == _synchronized, "must be synchronized before ending safepoint synchronization");
445
_state = _not_synchronized;
448
assert((_safepoint_counter & 0x1) == 1, "must be odd");
449
Atomic::release_store(&_safepoint_counter, _safepoint_counter + 1);
451
OrderAccess::fence();
454
for (; JavaThread *current = jtiwh.next(); ) {
456
DEBUG_ONLY(current->reset_visited_for_critical_count(active_safepoint_counter);)
457
ThreadSafepointState* cur_state = current->safepoint_state();
458
assert(!cur_state->is_running(), "Thread not suspended at safepoint");
459
cur_state->restart();
460
assert(cur_state->is_running(), "safepoint state has not been reset");
465
Threads_lock->unlock();
468
_wait_barrier->disarm();
473
void SafepointSynchronize::end() {
474
assert(Threads_lock->owned_by_self(), "must hold Threads_lock");
475
EventSafepointEnd event;
476
assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint");
480
Universe::heap()->safepoint_synchronize_end();
482
SafepointTracing::end();
484
post_safepoint_end_event(event, safepoint_id());
492
bool SafepointSynchronize::try_stable_load_state(JavaThreadState *state, JavaThread *thread, uint64_t safepoint_count) {
493
assert((safepoint_count != InactiveSafepointCounter &&
494
Thread::current() == (Thread*)VMThread::vm_thread() &&
495
SafepointSynchronize::_state != _not_synchronized)
496
|| safepoint_count == InactiveSafepointCounter, "Invalid check");
510
*state = thread->thread_state();
511
OrderAccess::loadload();
512
uint64_t sid = thread->safepoint_state()->get_safepoint_id();
513
if (sid != InactiveSafepointCounter && sid != safepoint_count) {
517
return *state == thread->thread_state();
520
static bool safepoint_safe_with(JavaThread *thread, JavaThreadState state) {
522
case _thread_in_native:
524
return !thread->has_last_Java_frame() || thread->frame_anchor()->walkable();
526
case _thread_blocked:
529
assert(!thread->has_last_Java_frame() || thread->frame_anchor()->walkable(), "blocked and not walkable");
537
bool SafepointSynchronize::handshake_safe(JavaThread *thread) {
538
if (thread->is_terminated()) {
541
JavaThreadState stable_state;
542
if (try_stable_load_state(&stable_state, thread, InactiveSafepointCounter)) {
543
return safepoint_safe_with(thread, stable_state);
552
void SafepointSynchronize::block(JavaThread *thread) {
553
assert(thread != nullptr, "thread must be set");
556
ttyLocker::break_tty_lock_for_safepoint(os::current_thread_id());
560
if (thread->is_terminated()) {
562
thread->block_if_vm_exited();
568
JavaThreadState state = thread->thread_state();
569
thread->frame_anchor()->make_walkable();
571
uint64_t safepoint_id = SafepointSynchronize::safepoint_counter();
577
thread->safepoint_state()->set_safepoint_id(safepoint_id);
580
OrderAccess::storestore();
582
thread->set_thread_state_fence(_thread_blocked);
584
_wait_barrier->wait(static_cast<int>(safepoint_id));
585
assert(_state != _synchronized, "Can't be");
588
OrderAccess::loadstore();
589
thread->set_thread_state(state);
592
thread->safepoint_state()->reset_safepoint_id();
594
OrderAccess::fence();
596
guarantee(thread->safepoint_state()->get_safepoint_id() == InactiveSafepointCounter,
597
"The safepoint id should be set only in block path");
607
void SafepointSynchronize::handle_polling_page_exception(JavaThread *thread) {
608
assert(thread->thread_state() == _thread_in_Java, "should come from Java code");
609
thread->set_thread_state(_thread_in_vm);
612
MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, thread));
614
if (log_is_enabled(Info, safepoint, stats)) {
615
Atomic::inc(&_nof_threads_hit_polling_page);
618
ThreadSafepointState* state = thread->safepoint_state();
620
state->handle_polling_page_exception();
622
thread->set_thread_state(_thread_in_Java);
626
void SafepointSynchronize::print_safepoint_timeout() {
627
if (!timeout_error_printed) {
628
timeout_error_printed = true;
631
LogTarget(Warning, safepoint) lt;
632
if (lt.is_enabled()) {
637
ls.print_cr("# SafepointSynchronize::begin: Timeout detected:");
638
ls.print_cr("# SafepointSynchronize::begin: Timed out while spinning to reach a safepoint.");
639
ls.print_cr("# SafepointSynchronize::begin: Threads which did not reach the safepoint:");
640
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur_thread = jtiwh.next(); ) {
641
if (cur_thread->safepoint_state()->is_running()) {
643
cur_thread->print_on(&ls);
647
ls.print_cr("# SafepointSynchronize::begin: (End of list)");
653
if (AbortVMOnSafepointTimeout && (os::elapsedTime() * MILLIUNITS > AbortVMOnSafepointTimeoutDelay)) {
655
for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur_thread = jtiwh.next(); ) {
656
if (cur_thread->safepoint_state()->is_running()) {
657
if (!os::signal_thread(cur_thread, SIGILL, "blocking a safepoint")) {
661
os::naked_sleep(3000);
664
fatal("Safepoint sync time longer than %.6f ms detected when executing %s.",
665
SafepointTimeoutDelay, VMThread::vm_operation()->name());
672
ThreadSafepointState::ThreadSafepointState(JavaThread *thread)
673
: _at_poll_safepoint(false), _thread(thread), _safepoint_safe(false),
674
_safepoint_id(SafepointSynchronize::InactiveSafepointCounter), _next(nullptr) {
677
void ThreadSafepointState::create(JavaThread *thread) {
678
ThreadSafepointState *state = new ThreadSafepointState(thread);
679
thread->set_safepoint_state(state);
682
void ThreadSafepointState::destroy(JavaThread *thread) {
683
if (thread->safepoint_state()) {
684
delete(thread->safepoint_state());
685
thread->set_safepoint_state(nullptr);
689
uint64_t ThreadSafepointState::get_safepoint_id() const {
690
return Atomic::load_acquire(&_safepoint_id);
693
void ThreadSafepointState::reset_safepoint_id() {
694
Atomic::release_store(&_safepoint_id, SafepointSynchronize::InactiveSafepointCounter);
697
void ThreadSafepointState::set_safepoint_id(uint64_t safepoint_id) {
698
Atomic::release_store(&_safepoint_id, safepoint_id);
701
void ThreadSafepointState::examine_state_of_thread(uint64_t safepoint_count) {
702
assert(is_running(), "better be running or just have hit safepoint poll");
704
JavaThreadState stable_state;
705
if (!SafepointSynchronize::try_stable_load_state(&stable_state, _thread, safepoint_count)) {
711
if (safepoint_safe_with(_thread, stable_state)) {
712
account_safe_thread();
721
assert(is_running(), "examine_state_of_thread on non-running thread");
725
void ThreadSafepointState::account_safe_thread() {
726
SafepointSynchronize::decrement_waiting_to_block();
727
if (_thread->in_critical()) {
729
SafepointSynchronize::increment_jni_active_count();
731
DEBUG_ONLY(_thread->set_visited_for_critical_count(SafepointSynchronize::safepoint_counter());)
732
assert(!_safepoint_safe, "Must be unsafe before safe");
733
_safepoint_safe = true;
736
void ThreadSafepointState::restart() {
737
assert(_safepoint_safe, "Must be safe before unsafe");
738
_safepoint_safe = false;
741
void ThreadSafepointState::print_on(outputStream *st) const {
742
const char *s = _safepoint_safe ? "_at_safepoint" : "_running";
744
st->print_cr("Thread: " INTPTR_FORMAT
745
" [0x%2x] State: %s _at_poll_safepoint %d",
746
p2i(_thread), _thread->osthread()->thread_id(), s, _at_poll_safepoint);
748
_thread->print_thread_state_on(st);
754
void ThreadSafepointState::handle_polling_page_exception() {
755
JavaThread* self = thread();
756
assert(self == JavaThread::current(), "must be self");
759
address real_return_addr = self->saved_exception_pc();
761
CodeBlob *cb = CodeCache::find_blob(real_return_addr);
762
assert(cb != nullptr && cb->is_nmethod(), "return address should be in nmethod");
763
nmethod* nm = cb->as_nmethod();
766
frame stub_fr = self->last_frame();
767
CodeBlob* stub_cb = stub_fr.cb();
768
assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
769
RegisterMap map(self,
770
RegisterMap::UpdateMap::include,
771
RegisterMap::ProcessFrames::skip,
772
RegisterMap::WalkContinuation::skip);
773
frame caller_fr = stub_fr.sender(&map);
776
assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
783
if( nm->is_at_poll_return(real_return_addr) ) {
785
bool return_oop = nm->method()->is_returning_oop();
792
oop result = caller_fr.saved_oop_result(&map);
793
assert(oopDesc::is_oop_or_null(result), "must be oop");
794
return_value = Handle(self, result);
795
assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
801
StackWatermarkSet::after_unwind(self);
804
SafepointMechanism::process_if_requested_with_exit_check(self, true );
808
caller_fr.set_saved_oop_result(&map, return_value());
816
assert(real_return_addr == caller_fr.pc(), "must match");
818
set_at_poll_safepoint(true);
827
SafepointMechanism::process_if_requested_with_exit_check(self, false );
828
set_at_poll_safepoint(false);
830
if (self->has_async_exception_condition()) {
831
Deoptimization::deoptimize_frame(self, caller_fr.id());
832
log_info(exceptions)("deferred async exception at compiled safepoint");
836
if (self->has_pending_exception() ) {
837
RegisterMap map(self,
838
RegisterMap::UpdateMap::include,
839
RegisterMap::ProcessFrames::skip,
840
RegisterMap::WalkContinuation::skip);
841
frame caller_fr = stub_fr.sender(&map);
842
if (caller_fr.is_deoptimized_frame()) {
852
fatal("Exception installed and deoptimization is pending");
862
jlong SafepointTracing::_last_safepoint_begin_time_ns = 0;
863
jlong SafepointTracing::_last_safepoint_sync_time_ns = 0;
864
jlong SafepointTracing::_last_safepoint_end_time_ns = 0;
865
jlong SafepointTracing::_last_app_time_ns = 0;
866
int SafepointTracing::_nof_threads = 0;
867
int SafepointTracing::_nof_running = 0;
868
int SafepointTracing::_page_trap = 0;
869
VM_Operation::VMOp_Type SafepointTracing::_current_type;
870
jlong SafepointTracing::_max_sync_time = 0;
871
jlong SafepointTracing::_max_vmop_time = 0;
872
uint64_t SafepointTracing::_op_count[VM_Operation::VMOp_Terminating] = {0};
874
void SafepointTracing::init() {
876
_last_safepoint_end_time_ns = os::javaTimeNanos();
880
static void print_header(outputStream* st) {
884
st->print("VM Operation "
885
"[ threads: total initial_running ]"
886
"[ time: sync vmop total ]");
888
st->print_cr(" page_trap_count");
893
void SafepointTracing::statistics_log() {
894
LogTarget(Info, safepoint, stats) lt;
895
assert (lt.is_enabled(), "should only be called when printing statistics is enabled");
898
static int _cur_stat_index = 0;
901
if ((_cur_stat_index % 30) == 0) {
909
INT32_FORMAT_W(8) " " INT32_FORMAT_W(8) " "
911
VM_Operation::name(_current_type),
915
INT64_FORMAT_W(10) " " INT64_FORMAT_W(10) " " INT64_FORMAT_W(10) " ]",
916
(int64_t)(_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns),
917
(int64_t)(_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns),
918
(int64_t)(_last_safepoint_end_time_ns - _last_safepoint_begin_time_ns));
920
ls.print_cr(INT32_FORMAT_W(16), _page_trap);
925
void SafepointTracing::statistics_exit_log() {
926
if (!log_is_enabled(Info, safepoint, stats)) {
929
for (int index = 0; index < VM_Operation::VMOp_Terminating; index++) {
930
if (_op_count[index] != 0) {
931
log_info(safepoint, stats)("%-28s" UINT64_FORMAT_W(10), VM_Operation::name(index),
936
log_info(safepoint, stats)("Maximum sync time " INT64_FORMAT" ns",
937
(int64_t)(_max_sync_time));
938
log_info(safepoint, stats)("Maximum vm operation time (except for Exit VM operation) "
940
(int64_t)(_max_vmop_time));
943
void SafepointTracing::begin(VM_Operation::VMOp_Type type) {
945
_current_type = type;
948
_last_safepoint_begin_time_ns = os::javaTimeNanos();
949
_last_safepoint_sync_time_ns = 0;
951
_last_app_time_ns = _last_safepoint_begin_time_ns - _last_safepoint_end_time_ns;
952
_last_safepoint_end_time_ns = 0;
954
RuntimeService::record_safepoint_begin(_last_app_time_ns);
957
void SafepointTracing::synchronized(int nof_threads, int nof_running, int traps) {
958
_last_safepoint_sync_time_ns = os::javaTimeNanos();
959
_nof_threads = nof_threads;
960
_nof_running = nof_running;
962
RuntimeService::record_safepoint_synchronized(_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns);
965
void SafepointTracing::end() {
966
_last_safepoint_end_time_ns = os::javaTimeNanos();
968
if (_max_sync_time < (_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns)) {
969
_max_sync_time = _last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns;
971
if (_max_vmop_time < (_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns)) {
972
_max_vmop_time = _last_safepoint_end_time_ns - _last_safepoint_sync_time_ns;
974
if (log_is_enabled(Info, safepoint, stats)) {
980
"Time since last: " JLONG_FORMAT " ns, "
981
"Reaching safepoint: " JLONG_FORMAT " ns, "
982
"At safepoint: " JLONG_FORMAT " ns, "
983
"Total: " JLONG_FORMAT " ns",
984
VM_Operation::name(_current_type),
986
_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns,
987
_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns,
988
_last_safepoint_end_time_ns - _last_safepoint_begin_time_ns
991
RuntimeService::record_safepoint_end(_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns);