8203469: Faster safepoints
Reviewed-by: dcubed, pchilanomate, dholmes, acorn, coleenp, eosterlund
This commit is contained in:
parent
66aa45649a
commit
bec8431683
@ -107,7 +107,7 @@ class DependencyContext : public StackObj {
|
||||
_safepoint_counter(SafepointSynchronize::safepoint_counter()) {}
|
||||
|
||||
~DependencyContext() {
|
||||
assert(_safepoint_counter == SafepointSynchronize::safepoint_counter(), "safepoint happened");
|
||||
assert(SafepointSynchronize::is_same_safepoint(_safepoint_counter), "must be the same safepoint");
|
||||
}
|
||||
#else
|
||||
DependencyContext(nmethodBucket* volatile* bucket_addr, volatile uint64_t* last_cleanup_addr)
|
||||
|
@ -82,10 +82,6 @@ static void prepare_for_emergency_dump(Thread* thread) {
|
||||
Heap_lock->unlock();
|
||||
}
|
||||
|
||||
if (Safepoint_lock->owned_by_self()) {
|
||||
Safepoint_lock->unlock();
|
||||
}
|
||||
|
||||
if (VMOperationQueue_lock->owned_by_self()) {
|
||||
VMOperationQueue_lock->unlock();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2019, 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
|
||||
@ -383,8 +383,7 @@ void JfrStackTrace::resolve_linenos() {
|
||||
}
|
||||
|
||||
bool JfrStackTrace::record_safe(JavaThread* thread, int skip, bool leakp /* false */) {
|
||||
assert(SafepointSynchronize::safepoint_safe(thread, thread->thread_state())
|
||||
|| thread == Thread::current(), "Thread stack needs to be walkable");
|
||||
assert(thread == Thread::current(), "Thread stack needs to be walkable");
|
||||
vframeStream vfs(thread);
|
||||
u4 count = 0;
|
||||
_reached_root = true;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2019, 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
|
||||
@ -303,13 +303,9 @@ void HandshakeState::process_self_inner(JavaThread* thread) {
|
||||
}
|
||||
|
||||
bool HandshakeState::vmthread_can_process_handshake(JavaThread* target) {
|
||||
// SafepointSynchronize::safepoint_safe() does not consider an externally
|
||||
// suspended thread to be safe. However, this function must be called with
|
||||
// the Threads_lock held so an externally suspended thread cannot be
|
||||
// resumed thus it is safe.
|
||||
assert(Threads_lock->owned_by_self(), "Not holding Threads_lock.");
|
||||
return SafepointSynchronize::safepoint_safe(target, target->thread_state()) ||
|
||||
target->is_ext_suspended() || target->is_terminated();
|
||||
// handshake_safe may only be called with polls armed.
|
||||
// VM thread controls this by first claiming the handshake via claim_handshake_for_vmthread.
|
||||
return SafepointSynchronize::handshake_safe(target);
|
||||
}
|
||||
|
||||
static bool possibly_vmthread_can_process_handshake(JavaThread* target) {
|
||||
|
@ -314,10 +314,10 @@ class ThreadBlockInVMWithDeadlockCheck : public ThreadStateTransition {
|
||||
// Once we are blocked vm expects stack to be walkable
|
||||
thread->frame_anchor()->make_walkable(thread);
|
||||
|
||||
thread->set_thread_state((JavaThreadState)(_thread_in_vm + 1));
|
||||
InterfaceSupport::serialize_thread_state_with_handler(thread);
|
||||
|
||||
SafepointMechanism::callback_if_safepoint(thread);
|
||||
// All unsafe states are treated the same by the VMThread
|
||||
// so we can skip the _thread_in_vm_trans state here. Since
|
||||
// we don't read poll, it's enough to order the stores.
|
||||
OrderAccess::storestore();
|
||||
|
||||
thread->set_thread_state(_thread_blocked);
|
||||
|
||||
@ -325,23 +325,13 @@ class ThreadBlockInVMWithDeadlockCheck : public ThreadStateTransition {
|
||||
}
|
||||
~ThreadBlockInVMWithDeadlockCheck() {
|
||||
// Change to transition state
|
||||
_thread->set_thread_state((JavaThreadState)(_thread_blocked + 1));
|
||||
_thread->set_thread_state((JavaThreadState)(_thread_blocked_trans));
|
||||
|
||||
InterfaceSupport::serialize_thread_state_with_handler(_thread);
|
||||
|
||||
if (SafepointMechanism::should_block(_thread)) {
|
||||
release_monitor();
|
||||
SafepointMechanism::callback_if_safepoint(_thread);
|
||||
// The VMThread might have read that we were in a _thread_blocked state
|
||||
// and proceeded to process a handshake for us. If that's the case then
|
||||
// we need to block.
|
||||
// By doing this we are also making the current thread process its own
|
||||
// handshake if there is one pending and the VMThread didn't try to process
|
||||
// it yet. This is more of a side-effect and not really necessary; the
|
||||
// handshake could be processed later on.
|
||||
if (_thread->has_handshake()) {
|
||||
_thread->handshake_process_by_self();
|
||||
}
|
||||
SafepointMechanism::block_if_requested(_thread);
|
||||
}
|
||||
|
||||
_thread->set_thread_state(_thread_in_vm);
|
||||
|
@ -401,15 +401,10 @@ void Monitor::set_owner_implementation(Thread *new_owner) {
|
||||
// of m2 be less than the rank of m1.
|
||||
// The rank Mutex::native is an exception in that it is not subject
|
||||
// to the verification rules.
|
||||
// Here are some further notes relating to mutex acquisition anomalies:
|
||||
// . it is also ok to acquire Safepoint_lock at the very end while we
|
||||
// already hold Terminator_lock - may happen because of periodic safepoints
|
||||
if (this->rank() != Mutex::native &&
|
||||
this->rank() != Mutex::suspend_resume &&
|
||||
locks != NULL && locks->rank() <= this->rank() &&
|
||||
!SafepointSynchronize::is_at_safepoint() &&
|
||||
!(this == Safepoint_lock && contains(locks, Terminator_lock) &&
|
||||
SafepointSynchronize::is_synchronizing())) {
|
||||
!SafepointSynchronize::is_at_safepoint()) {
|
||||
new_owner->print_owned_locks();
|
||||
fatal("acquiring lock %s/%d out of order with lock %s/%d -- "
|
||||
"possible deadlock", this->name(), this->rank(),
|
||||
|
@ -56,10 +56,7 @@ class Monitor : public CHeapObj<mtInternal> {
|
||||
// (except for "event" and "access") for the deadlock detection to work correctly.
|
||||
// The rank native is only for use in Mutex's created by JVM_RawMonitorCreate,
|
||||
// which being external to the VM are not subject to deadlock detection.
|
||||
// The rank safepoint is used only for synchronization in reaching a
|
||||
// safepoint and leaving a safepoint. It is only used for the Safepoint_lock
|
||||
// currently. While at a safepoint no mutexes of rank safepoint are held
|
||||
// by any thread.
|
||||
// While at a safepoint no mutexes of rank safepoint are held by any thread.
|
||||
// The rank named "leaf" is probably historical (and should
|
||||
// be changed) -- mutexes of this rank aren't really leaf mutexes
|
||||
// at all.
|
||||
|
@ -72,7 +72,6 @@ Mutex* TouchedMethodLog_lock = NULL;
|
||||
Mutex* RetData_lock = NULL;
|
||||
Monitor* VMOperationQueue_lock = NULL;
|
||||
Monitor* VMOperationRequest_lock = NULL;
|
||||
Monitor* Safepoint_lock = NULL;
|
||||
Monitor* SerializePage_lock = NULL;
|
||||
Monitor* Threads_lock = NULL;
|
||||
Mutex* NonJavaThreadsList_lock = NULL;
|
||||
@ -275,8 +274,6 @@ void mutex_init() {
|
||||
// CMS_bitMap_lock leaf 1
|
||||
// CMS_freeList_lock leaf 2
|
||||
|
||||
def(Safepoint_lock , PaddedMonitor, safepoint, true, Monitor::_safepoint_check_sometimes); // locks SnippetCache_lock/Threads_lock
|
||||
|
||||
def(Threads_lock , PaddedMonitor, barrier, true, Monitor::_safepoint_check_sometimes);
|
||||
def(NonJavaThreadsList_lock , PaddedMutex, leaf, true, Monitor::_safepoint_check_never);
|
||||
|
||||
|
@ -68,7 +68,6 @@ extern Mutex* DerivedPointerTableGC_lock; // a lock to protect the derive
|
||||
extern Monitor* CGCPhaseManager_lock; // a lock to protect a concurrent GC's phase management
|
||||
extern Monitor* VMOperationQueue_lock; // a lock on queue of vm_operations waiting to execute
|
||||
extern Monitor* VMOperationRequest_lock; // a lock on Threads waiting for a vm_operation to terminate
|
||||
extern Monitor* Safepoint_lock; // a lock used by the safepoint abstraction
|
||||
extern Monitor* Threads_lock; // a lock on the Threads table of active Java threads
|
||||
// (also used by Safepoints too to block threads creation/destruction)
|
||||
extern Mutex* NonJavaThreadsList_lock; // a lock on the NonJavaThreads list
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,15 +26,15 @@
|
||||
#define SHARE_RUNTIME_SAFEPOINT_HPP
|
||||
|
||||
#include "memory/allocation.hpp"
|
||||
#include "runtime/mutexLocker.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
#include "runtime/thread.hpp"
|
||||
#include "utilities/ostream.hpp"
|
||||
#include "utilities/waitBarrier.hpp"
|
||||
|
||||
//
|
||||
// Safepoint synchronization
|
||||
////
|
||||
// The VMThread or CMS_thread uses the SafepointSynchronize::begin/end
|
||||
// The VMThread uses the SafepointSynchronize::begin/end
|
||||
// methods to enter/exit a safepoint region. The begin method will roll
|
||||
// all JavaThreads forward to a safepoint.
|
||||
//
|
||||
@ -45,9 +45,7 @@
|
||||
// exit safepoint methods, when a thread is blocked/restarted. Hence, all mutex exter/
|
||||
// exit points *must* be at a safepoint.
|
||||
|
||||
|
||||
class ThreadSafepointState;
|
||||
class JavaThread;
|
||||
|
||||
//
|
||||
// Implements roll-forward to safepoint (safepoint synchronization)
|
||||
@ -55,21 +53,10 @@ class JavaThread;
|
||||
class SafepointSynchronize : AllStatic {
|
||||
public:
|
||||
enum SynchronizeState {
|
||||
_not_synchronized = 0, // Threads not synchronized at a safepoint
|
||||
// Keep this value 0. See the comment in do_call_back()
|
||||
_not_synchronized = 0, // Threads not synchronized at a safepoint. Keep this value 0.
|
||||
_synchronizing = 1, // Synchronizing in progress
|
||||
_synchronized = 2 // All Java threads are stopped at a safepoint. Only VM thread is running
|
||||
};
|
||||
|
||||
enum SafepointingThread {
|
||||
_null_thread = 0,
|
||||
_vm_thread = 1,
|
||||
_other_thread = 2
|
||||
};
|
||||
|
||||
enum SafepointTimeoutReason {
|
||||
_spinning_timeout = 0,
|
||||
_blocking_timeout = 1
|
||||
_synchronized = 2 // All Java threads are running in native, blocked in OS or stopped at safepoint.
|
||||
// VM thread and any NonJavaThread may be running.
|
||||
};
|
||||
|
||||
// The enums are listed in the order of the tasks when done serially.
|
||||
@ -86,22 +73,33 @@ class SafepointSynchronize : AllStatic {
|
||||
};
|
||||
|
||||
private:
|
||||
static volatile SynchronizeState _state; // Threads might read this flag directly, without acquiring the Threads_lock
|
||||
static volatile int _waiting_to_block; // number of threads we are waiting for to block
|
||||
static int _current_jni_active_count; // Counts the number of active critical natives during the safepoint
|
||||
static int _defer_thr_suspend_loop_count; // Iterations before blocking VM threads
|
||||
friend class SafepointMechanism;
|
||||
friend class ThreadSafepointState;
|
||||
friend class HandshakeState;
|
||||
|
||||
enum SafepointTimeoutReason {
|
||||
_spinning_timeout = 0,
|
||||
_blocking_timeout = 1
|
||||
};
|
||||
|
||||
// Threads might read this flag directly, without acquiring the Threads_lock:
|
||||
static volatile SynchronizeState _state;
|
||||
// Number of threads we are waiting for to block:
|
||||
static int _waiting_to_block;
|
||||
// Counts the number of active critical natives during the safepoint:
|
||||
static int _current_jni_active_count;
|
||||
|
||||
// This counter is used for fast versions of jni_Get<Primitive>Field.
|
||||
// An even value means there is no ongoing safepoint operations.
|
||||
// An even value means there are no ongoing safepoint operations.
|
||||
// The counter is incremented ONLY at the beginning and end of each
|
||||
// safepoint. The fact that Threads_lock is held throughout each pair of
|
||||
// increments (at the beginning and end of each safepoint) guarantees
|
||||
// race freedom.
|
||||
// safepoint.
|
||||
static volatile uint64_t _safepoint_counter;
|
||||
|
||||
private:
|
||||
static long _end_of_last_safepoint; // Time of last safepoint in milliseconds
|
||||
static julong _coalesced_vmop_count; // coalesced vmop count
|
||||
// JavaThreads that need to block for the safepoint will stop on the
|
||||
// _wait_barrier, where they can quickly be started again.
|
||||
static WaitBarrier* _wait_barrier;
|
||||
static long _end_of_last_safepoint; // Time of last safepoint in milliseconds
|
||||
static julong _coalesced_vmop_count; // coalesced vmop count
|
||||
|
||||
// Statistics
|
||||
static void begin_statistics(int nof_threads, int nof_running);
|
||||
@ -114,42 +112,41 @@ private:
|
||||
// For debug long safepoint
|
||||
static void print_safepoint_timeout(SafepointTimeoutReason timeout_reason);
|
||||
|
||||
// Helper methods for safepoint procedure:
|
||||
static void arm_safepoint();
|
||||
static int synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running);
|
||||
static void disarm_safepoint();
|
||||
static void increment_jni_active_count();
|
||||
static void decrement_waiting_to_block();
|
||||
|
||||
// Used in safepoint_safe to do a stable load of the thread state.
|
||||
static bool try_stable_load_state(JavaThreadState *state,
|
||||
JavaThread *thread,
|
||||
uint64_t safepoint_count);
|
||||
|
||||
// Called when a thread voluntarily blocks
|
||||
static void block(JavaThread *thread);
|
||||
|
||||
// Called from VMThread during handshakes.
|
||||
// If true the VMThread may safely process the handshake operation for the JavaThread.
|
||||
static bool handshake_safe(JavaThread *thread);
|
||||
|
||||
public:
|
||||
|
||||
// Main entry points
|
||||
static void init(Thread* vmthread);
|
||||
|
||||
// Roll all threads forward to safepoint. Must be called by the
|
||||
// VMThread or CMS_thread.
|
||||
// Roll all threads forward to safepoint. Must be called by the VMThread.
|
||||
static void begin();
|
||||
static void end(); // Start all suspended threads again...
|
||||
|
||||
static bool safepoint_safe(JavaThread *thread, JavaThreadState state);
|
||||
|
||||
static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state);
|
||||
// The value for a not set safepoint id.
|
||||
static const uint64_t InactiveSafepointCounter;
|
||||
|
||||
// Query
|
||||
inline static bool is_at_safepoint() { return _state == _synchronized; }
|
||||
inline static bool is_synchronizing() { return _state == _synchronizing; }
|
||||
inline static uint64_t safepoint_counter() { return _safepoint_counter; }
|
||||
|
||||
inline static void increment_jni_active_count() {
|
||||
assert_locked_or_safepoint(Safepoint_lock);
|
||||
_current_jni_active_count++;
|
||||
}
|
||||
|
||||
private:
|
||||
inline static bool do_call_back() {
|
||||
return (_state != _not_synchronized);
|
||||
}
|
||||
|
||||
// Called when a thread voluntarily blocks
|
||||
static void block(JavaThread *thread, bool block_in_safepoint_check = true);
|
||||
|
||||
friend class SafepointMechanism;
|
||||
|
||||
public:
|
||||
static void signal_thread_at_safepoint() { _waiting_to_block--; }
|
||||
|
||||
static bool is_at_safepoint() { return _state == _synchronized; }
|
||||
static bool is_synchronizing() { return _state == _synchronizing; }
|
||||
static uint64_t safepoint_counter() { return _safepoint_counter; }
|
||||
static bool is_same_safepoint(uint64_t counter) { return (SafepointSynchronize::safepoint_counter() - counter) < 2; }
|
||||
// Exception handling for page polling
|
||||
static void handle_polling_page_exception(JavaThread *thread);
|
||||
|
||||
@ -164,13 +161,13 @@ public:
|
||||
static void do_cleanup_tasks();
|
||||
|
||||
static void print_stat_on_exit();
|
||||
inline static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; }
|
||||
static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; }
|
||||
|
||||
static void set_is_at_safepoint() { _state = _synchronized; }
|
||||
static void set_is_not_at_safepoint() { _state = _not_synchronized; }
|
||||
static void set_is_at_safepoint() { _state = _synchronized; }
|
||||
static void set_is_not_at_safepoint() { _state = _not_synchronized; }
|
||||
|
||||
// Assembly support
|
||||
static address address_of_state() { return (address)&_state; }
|
||||
static address address_of_state() { return (address)&_state; }
|
||||
|
||||
// Only used for making sure that no safepoint has happened in
|
||||
// JNI_FastGetField. Therefore only the low 32-bits are needed
|
||||
@ -201,44 +198,43 @@ public:
|
||||
|
||||
// State class for a thread suspended at a safepoint
|
||||
class ThreadSafepointState: public CHeapObj<mtInternal> {
|
||||
public:
|
||||
// These states are maintained by VM thread while threads are being brought
|
||||
// to a safepoint. After SafepointSynchronize::end(), they are reset to
|
||||
// _running.
|
||||
enum suspend_type {
|
||||
_running = 0, // Thread state not yet determined (i.e., not at a safepoint yet)
|
||||
_at_safepoint = 1, // Thread at a safepoint (f.ex., when blocked on a lock)
|
||||
_call_back = 2 // Keep executing and wait for callback (if thread is in interpreted or vm)
|
||||
};
|
||||
private:
|
||||
volatile bool _at_poll_safepoint; // At polling page safepoint (NOT a poll return safepoint)
|
||||
// Thread has called back the safepoint code (for debugging)
|
||||
bool _has_called_back;
|
||||
// At polling page safepoint (NOT a poll return safepoint):
|
||||
volatile bool _at_poll_safepoint;
|
||||
JavaThread* _thread;
|
||||
bool _safepoint_safe;
|
||||
volatile uint64_t _safepoint_id;
|
||||
JavaThreadState _orig_thread_state;
|
||||
|
||||
JavaThread * _thread;
|
||||
volatile suspend_type _type;
|
||||
JavaThreadState _orig_thread_state;
|
||||
ThreadSafepointState* _next;
|
||||
|
||||
void account_safe_thread();
|
||||
|
||||
public:
|
||||
ThreadSafepointState(JavaThread *thread);
|
||||
|
||||
// examine/roll-forward/restart
|
||||
void examine_state_of_thread();
|
||||
void roll_forward(suspend_type type);
|
||||
// Linked list support:
|
||||
ThreadSafepointState* get_next() const { return _next; }
|
||||
void set_next(ThreadSafepointState* value) { _next = value; }
|
||||
ThreadSafepointState** next_ptr() { return &_next; }
|
||||
|
||||
// examine/restart
|
||||
void examine_state_of_thread(uint64_t safepoint_count);
|
||||
void restart();
|
||||
|
||||
// Query
|
||||
JavaThread* thread() const { return _thread; }
|
||||
suspend_type type() const { return _type; }
|
||||
bool is_running() const { return (_type==_running); }
|
||||
bool is_running() const { return !_safepoint_safe; }
|
||||
|
||||
uint64_t get_safepoint_id() const;
|
||||
void reset_safepoint_id();
|
||||
void set_safepoint_id(uint64_t sid);
|
||||
|
||||
JavaThreadState orig_thread_state() const { return _orig_thread_state; }
|
||||
|
||||
// Support for safepoint timeout (debugging)
|
||||
bool has_called_back() const { return _has_called_back; }
|
||||
void set_has_called_back(bool val) { _has_called_back = val; }
|
||||
bool is_at_poll_safepoint() { return _at_poll_safepoint; }
|
||||
void set_at_poll_safepoint(bool val) { _at_poll_safepoint = val; }
|
||||
bool is_at_poll_safepoint() { return _at_poll_safepoint; }
|
||||
void set_at_poll_safepoint(bool val) { _at_poll_safepoint = val; }
|
||||
|
||||
void handle_polling_page_exception();
|
||||
|
||||
|
@ -86,6 +86,9 @@ void SafepointMechanism::default_initialize() {
|
||||
void SafepointMechanism::block_if_requested_slow(JavaThread *thread) {
|
||||
// local poll already checked, if used.
|
||||
if (global_poll()) {
|
||||
// Any load in ::block must not pass the global poll load.
|
||||
// Otherwise we might load an old safepoint counter (for example).
|
||||
OrderAccess::loadload();
|
||||
SafepointSynchronize::block(thread);
|
||||
}
|
||||
if (uses_thread_local_poll() && thread->has_handshake()) {
|
||||
|
@ -78,9 +78,6 @@ public:
|
||||
// Blocks a thread until safepoint/handshake is completed.
|
||||
static inline void block_if_requested(JavaThread* thread);
|
||||
|
||||
// Calls back if there is a pending safepoint but does not block for it.
|
||||
static inline void callback_if_safepoint(JavaThread* thread);
|
||||
|
||||
// Caller is responsible for using a memory barrier if needed.
|
||||
static inline void arm_local_poll(JavaThread* thread);
|
||||
static inline void disarm_local_poll(JavaThread* thread);
|
||||
|
@ -35,7 +35,7 @@ bool SafepointMechanism::local_poll_armed(JavaThread* thread) {
|
||||
}
|
||||
|
||||
bool SafepointMechanism::global_poll() {
|
||||
return SafepointSynchronize::do_call_back();
|
||||
return (SafepointSynchronize::_state != SafepointSynchronize::_not_synchronized);
|
||||
}
|
||||
|
||||
bool SafepointMechanism::local_poll(Thread* thread) {
|
||||
@ -62,20 +62,6 @@ void SafepointMechanism::block_if_requested(JavaThread *thread) {
|
||||
block_if_requested_slow(thread);
|
||||
}
|
||||
|
||||
void SafepointMechanism::callback_if_safepoint(JavaThread* thread) {
|
||||
if (!uses_thread_local_poll() || local_poll_armed(thread)) {
|
||||
// If using thread local polls, we should not check the
|
||||
// global_poll() and callback via block() if the VMThread
|
||||
// has not yet armed the local poll. Otherwise, when used in
|
||||
// combination with should_block(), the latter could miss
|
||||
// detecting the same safepoint that this method would detect
|
||||
// if only checking global polls.
|
||||
if (global_poll()) {
|
||||
SafepointSynchronize::block(thread, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SafepointMechanism::arm_local_poll(JavaThread* thread) {
|
||||
thread->set_polling_page(poll_armed_value());
|
||||
}
|
||||
|
@ -421,11 +421,21 @@ class Thread: public ThreadShadow {
|
||||
|
||||
#ifdef ASSERT
|
||||
private:
|
||||
bool _visited_for_critical_count;
|
||||
volatile uint64_t _visited_for_critical_count;
|
||||
|
||||
public:
|
||||
void set_visited_for_critical_count(bool z) { _visited_for_critical_count = z; }
|
||||
bool was_visited_for_critical_count() const { return _visited_for_critical_count; }
|
||||
void set_visited_for_critical_count(uint64_t safepoint_id) {
|
||||
assert(_visited_for_critical_count == 0, "Must be reset before set");
|
||||
assert((safepoint_id & 0x1) == 1, "Must be odd");
|
||||
_visited_for_critical_count = safepoint_id;
|
||||
}
|
||||
void reset_visited_for_critical_count(uint64_t safepoint_id) {
|
||||
assert(_visited_for_critical_count == safepoint_id, "Was not visited");
|
||||
_visited_for_critical_count = 0;
|
||||
}
|
||||
bool was_visited_for_critical_count(uint64_t safepoint_id) const {
|
||||
return _visited_for_critical_count == safepoint_id;
|
||||
}
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
@ -458,6 +458,8 @@ bool VMThread::no_op_safepoint_needed(bool check_time) {
|
||||
void VMThread::loop() {
|
||||
assert(_cur_vm_operation == NULL, "no current one should be executing");
|
||||
|
||||
SafepointSynchronize::init(_vm_thread);
|
||||
|
||||
while(true) {
|
||||
VM_Operation* safepoint_ops = NULL;
|
||||
//
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2019, 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
|
||||
@ -25,6 +25,7 @@
|
||||
#include "precompiled.hpp"
|
||||
#include "classfile/classLoader.hpp"
|
||||
#include "logging/log.hpp"
|
||||
#include "runtime/timer.hpp"
|
||||
#include "runtime/vm_version.hpp"
|
||||
#include "services/attachListener.hpp"
|
||||
#include "services/management.hpp"
|
||||
@ -40,7 +41,9 @@ PerfCounter* RuntimeService::_sync_time_ticks = NULL;
|
||||
PerfCounter* RuntimeService::_total_safepoints = NULL;
|
||||
PerfCounter* RuntimeService::_safepoint_time_ticks = NULL;
|
||||
PerfCounter* RuntimeService::_application_time_ticks = NULL;
|
||||
double RuntimeService::_last_safepoint_sync_time_sec = 0.0;
|
||||
jlong RuntimeService::_last_safepoint_sync_time_ns = 0;
|
||||
jlong RuntimeService::_last_safepoint_end_time_ns = 0;
|
||||
jlong RuntimeService::_last_app_time_ns = 0;
|
||||
|
||||
void RuntimeService::init() {
|
||||
|
||||
@ -89,12 +92,14 @@ void RuntimeService::record_safepoint_begin() {
|
||||
|
||||
// Print the time interval in which the app was executing
|
||||
if (_app_timer.is_updated()) {
|
||||
log_info(safepoint)("Application time: %3.7f seconds", last_application_time_sec());
|
||||
_last_app_time_ns = _app_timer.ticks_since_update();
|
||||
log_info(safepoint)("Application time: %3.7f seconds", TimeHelper::counter_to_seconds(_last_app_time_ns));
|
||||
}
|
||||
|
||||
// update the time stamp to begin recording safepoint time
|
||||
_last_safepoint_sync_time_ns = 0;
|
||||
_last_safepoint_end_time_ns = 0;
|
||||
_safepoint_timer.update();
|
||||
_last_safepoint_sync_time_sec = 0.0;
|
||||
if (UsePerfData) {
|
||||
_total_safepoints->inc();
|
||||
if (_app_timer.is_updated()) {
|
||||
@ -107,18 +112,24 @@ void RuntimeService::record_safepoint_synchronized() {
|
||||
if (UsePerfData) {
|
||||
_sync_time_ticks->inc(_safepoint_timer.ticks_since_update());
|
||||
}
|
||||
if (log_is_enabled(Info, safepoint)) {
|
||||
_last_safepoint_sync_time_sec = last_safepoint_time_sec();
|
||||
if (log_is_enabled(Info, safepoint) || log_is_enabled(Info, safepoint, stats)) {
|
||||
_last_safepoint_sync_time_ns = _safepoint_timer.ticks_since_update();
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeService::record_safepoint_end() {
|
||||
HS_PRIVATE_SAFEPOINT_END();
|
||||
|
||||
// Print the time interval for which the app was stopped
|
||||
// during the current safepoint operation.
|
||||
log_info(safepoint)("Total time for which application threads were stopped: %3.7f seconds, Stopping threads took: %3.7f seconds",
|
||||
last_safepoint_time_sec(), _last_safepoint_sync_time_sec);
|
||||
// Logging of safepoint+stats=info needs _last_safepoint_end_time_ns to be set.
|
||||
// Logging of safepoint=info needs _last_safepoint_end_time_ns for following log.
|
||||
if (log_is_enabled(Info, safepoint) || log_is_enabled(Info, safepoint, stats)) {
|
||||
_last_safepoint_end_time_ns = _safepoint_timer.ticks_since_update();
|
||||
log_info(safepoint)(
|
||||
"Total time for which application threads were stopped: %3.7f seconds, "
|
||||
"Stopping threads took: %3.7f seconds",
|
||||
TimeHelper::counter_to_seconds(_last_safepoint_end_time_ns),
|
||||
TimeHelper::counter_to_seconds(_last_safepoint_sync_time_ns));
|
||||
}
|
||||
|
||||
// update the time stamp to begin recording app time
|
||||
_app_timer.update();
|
||||
@ -127,6 +138,25 @@ void RuntimeService::record_safepoint_end() {
|
||||
}
|
||||
}
|
||||
|
||||
void RuntimeService::record_safepoint_epilog(const char* operation_name) {
|
||||
if (!log_is_enabled(Info, safepoint, stats)) {
|
||||
return;
|
||||
}
|
||||
|
||||
log_info(safepoint, stats)(
|
||||
"Safepoint \"%s\", "
|
||||
"Time since last: " JLONG_FORMAT " ns; "
|
||||
"Reaching safepoint: " JLONG_FORMAT " ns; "
|
||||
"At safepoint: " JLONG_FORMAT " ns; "
|
||||
"Total: " JLONG_FORMAT " ns",
|
||||
operation_name,
|
||||
_last_app_time_ns,
|
||||
_last_safepoint_sync_time_ns,
|
||||
_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns,
|
||||
_last_safepoint_end_time_ns
|
||||
);
|
||||
}
|
||||
|
||||
void RuntimeService::record_application_start() {
|
||||
// update the time stamp to begin recording app time
|
||||
_app_timer.update();
|
||||
|
@ -37,7 +37,9 @@ private:
|
||||
|
||||
static TimeStamp _safepoint_timer;
|
||||
static TimeStamp _app_timer;
|
||||
static double _last_safepoint_sync_time_sec;
|
||||
static jlong _last_safepoint_sync_time_ns;
|
||||
static jlong _last_safepoint_end_time_ns;
|
||||
static jlong _last_app_time_ns;
|
||||
|
||||
public:
|
||||
static void init();
|
||||
@ -47,13 +49,11 @@ public:
|
||||
static jlong safepoint_time_ms();
|
||||
static jlong application_time_ms();
|
||||
|
||||
static double last_safepoint_time_sec() { return _safepoint_timer.seconds(); }
|
||||
static double last_application_time_sec() { return _app_timer.seconds(); }
|
||||
|
||||
// callbacks
|
||||
static void record_safepoint_begin() NOT_MANAGEMENT_RETURN;
|
||||
static void record_safepoint_synchronized() NOT_MANAGEMENT_RETURN;
|
||||
static void record_safepoint_end() NOT_MANAGEMENT_RETURN;
|
||||
static void record_safepoint_epilog(const char* operation_name) NOT_MANAGEMENT_RETURN;
|
||||
static void record_application_start() NOT_MANAGEMENT_RETURN;
|
||||
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, 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
|
||||
@ -40,10 +40,9 @@ public class SafepointTest {
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:safepoint=trace",
|
||||
InnerClass.class.getName());
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("Safepoint synchronization initiated. (");
|
||||
output.shouldContain("Safepoint synchronization initiated");
|
||||
output.shouldContain("Entering safepoint region: ");
|
||||
output.shouldContain("Leaving safepoint region");
|
||||
output.shouldContain("_at_poll_safepoint");
|
||||
output.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user