mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 10:04:42 +02:00
7006810: G1: Introduce peace-of-mind checking in the Suspendible Thread Set
Add asserts to ensure thread is in the right state. Reviewed-by: tschatzl, pliden
This commit is contained in:
parent
a890eee817
commit
f979b6f8f6
3 changed files with 21 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -33,16 +33,20 @@ bool SuspendibleThreadSet::_suspend_all = false;
|
||||||
double SuspendibleThreadSet::_suspend_all_start = 0.0;
|
double SuspendibleThreadSet::_suspend_all_start = 0.0;
|
||||||
|
|
||||||
void SuspendibleThreadSet::join() {
|
void SuspendibleThreadSet::join() {
|
||||||
|
assert(!Thread::current()->is_suspendible_thread(), "Thread already joined");
|
||||||
MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
||||||
while (_suspend_all) {
|
while (_suspend_all) {
|
||||||
ml.wait(Mutex::_no_safepoint_check_flag);
|
ml.wait(Mutex::_no_safepoint_check_flag);
|
||||||
}
|
}
|
||||||
_nthreads++;
|
_nthreads++;
|
||||||
|
DEBUG_ONLY(Thread::current()->set_suspendible_thread();)
|
||||||
}
|
}
|
||||||
|
|
||||||
void SuspendibleThreadSet::leave() {
|
void SuspendibleThreadSet::leave() {
|
||||||
|
assert(Thread::current()->is_suspendible_thread(), "Thread not joined");
|
||||||
MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
||||||
assert(_nthreads > 0, "Invalid");
|
assert(_nthreads > 0, "Invalid");
|
||||||
|
DEBUG_ONLY(Thread::current()->clear_suspendible_thread();)
|
||||||
_nthreads--;
|
_nthreads--;
|
||||||
if (_suspend_all) {
|
if (_suspend_all) {
|
||||||
ml.notify_all();
|
ml.notify_all();
|
||||||
|
@ -50,6 +54,7 @@ void SuspendibleThreadSet::leave() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SuspendibleThreadSet::yield() {
|
void SuspendibleThreadSet::yield() {
|
||||||
|
assert(Thread::current()->is_suspendible_thread(), "Must have joined");
|
||||||
if (_suspend_all) {
|
if (_suspend_all) {
|
||||||
MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
MonitorLockerEx ml(STS_lock, Mutex::_no_safepoint_check_flag);
|
||||||
if (_suspend_all) {
|
if (_suspend_all) {
|
||||||
|
|
|
@ -190,6 +190,7 @@ Thread::Thread() {
|
||||||
set_stack_size(0);
|
set_stack_size(0);
|
||||||
set_self_raw_id(0);
|
set_self_raw_id(0);
|
||||||
set_lgrp_id(-1);
|
set_lgrp_id(-1);
|
||||||
|
DEBUG_ONLY(clear_suspendible_thread();)
|
||||||
|
|
||||||
// allocated data structures
|
// allocated data structures
|
||||||
set_osthread(NULL);
|
set_osthread(NULL);
|
||||||
|
|
|
@ -206,11 +206,25 @@ class Thread: public ThreadShadow {
|
||||||
private:
|
private:
|
||||||
int _num_nested_signal;
|
int _num_nested_signal;
|
||||||
|
|
||||||
|
DEBUG_ONLY(bool _suspendible_thread;)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void enter_signal_handler() { _num_nested_signal++; }
|
void enter_signal_handler() { _num_nested_signal++; }
|
||||||
void leave_signal_handler() { _num_nested_signal--; }
|
void leave_signal_handler() { _num_nested_signal--; }
|
||||||
bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
|
bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
|
||||||
|
|
||||||
|
#ifdef ASSERT
|
||||||
|
void set_suspendible_thread() {
|
||||||
|
_suspendible_thread = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_suspendible_thread() {
|
||||||
|
_suspendible_thread = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_suspendible_thread() { return _suspendible_thread; }
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Active_handles points to a block of handles
|
// Active_handles points to a block of handles
|
||||||
JNIHandleBlock* _active_handles;
|
JNIHandleBlock* _active_handles;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue