annotate src/hotspot/share/runtime/safepointVerifiers.hpp @ 52291:35a6956f4243

8209976: Improve iteration over non-JavaThreads Summary: Add NonJavaThread and move NamedThread iteration to new class. Reviewed-by: eosterlund, coleenp, rkennke
author kbarrett
date Tue, 28 Aug 2018 16:04:54 -0400
parents
children 9807daeb47c4
rev   line source
stefank@50089 1 /*
stefank@50089 2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
stefank@50089 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
stefank@50089 4 *
stefank@50089 5 * This code is free software; you can redistribute it and/or modify it
stefank@50089 6 * under the terms of the GNU General Public License version 2 only, as
stefank@50089 7 * published by the Free Software Foundation.
stefank@50089 8 *
stefank@50089 9 * This code is distributed in the hope that it will be useful, but WITHOUT
stefank@50089 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
stefank@50089 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
stefank@50089 12 * version 2 for more details (a copy is included in the LICENSE file that
stefank@50089 13 * accompanied this code).
stefank@50089 14 *
stefank@50089 15 * You should have received a copy of the GNU General Public License version
stefank@50089 16 * 2 along with this work; if not, write to the Free Software Foundation,
stefank@50089 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
stefank@50089 18 *
stefank@50089 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
stefank@50089 20 * or visit www.oracle.com if you need additional information or have any
stefank@50089 21 * questions.
stefank@50089 22 *
stefank@50089 23 */
stefank@50089 24
stefank@50089 25 #ifndef SHARE_VM_RUNTIME_SAFEPOINTVERIFIERS_HPP
stefank@50089 26 #define SHARE_VM_RUNTIME_SAFEPOINTVERIFIERS_HPP
stefank@50089 27
stefank@50089 28 #include "memory/allocation.hpp"
stefank@50089 29 #include "runtime/thread.hpp"
stefank@50089 30
stefank@50089 31 // A NoGCVerifier object can be placed in methods where one assumes that
stefank@50089 32 // no garbage collection will occur. The destructor will verify this property
stefank@50089 33 // unless the constructor is called with argument false (not verifygc).
stefank@50089 34 //
stefank@50089 35 // The check will only be done in debug mode and if verifygc true.
stefank@50089 36
stefank@50089 37 class NoGCVerifier: public StackObj {
stefank@50089 38 friend class PauseNoGCVerifier;
stefank@50089 39
stefank@50089 40 protected:
stefank@50089 41 bool _verifygc;
stefank@50089 42 unsigned int _old_invocations;
stefank@50089 43
stefank@50089 44 public:
stefank@50089 45 #ifdef ASSERT
stefank@50089 46 NoGCVerifier(bool verifygc = true);
stefank@50089 47 ~NoGCVerifier();
stefank@50089 48 #else
stefank@50089 49 NoGCVerifier(bool verifygc = true) {}
stefank@50089 50 ~NoGCVerifier() {}
stefank@50089 51 #endif
stefank@50089 52 };
stefank@50089 53
stefank@50089 54 // A PauseNoGCVerifier is used to temporarily pause the behavior
stefank@50089 55 // of a NoGCVerifier object. If we are not in debug mode or if the
stefank@50089 56 // NoGCVerifier object has a _verifygc value of false, then there
stefank@50089 57 // is nothing to do.
stefank@50089 58
stefank@50089 59 class PauseNoGCVerifier: public StackObj {
stefank@50089 60 private:
stefank@50089 61 NoGCVerifier * _ngcv;
stefank@50089 62
stefank@50089 63 public:
stefank@50089 64 #ifdef ASSERT
stefank@50089 65 PauseNoGCVerifier(NoGCVerifier * ngcv);
stefank@50089 66 ~PauseNoGCVerifier();
stefank@50089 67 #else
stefank@50089 68 PauseNoGCVerifier(NoGCVerifier * ngcv) {}
stefank@50089 69 ~PauseNoGCVerifier() {}
stefank@50089 70 #endif
stefank@50089 71 };
stefank@50089 72
stefank@50089 73
stefank@50089 74 // A NoSafepointVerifier object will throw an assertion failure if
stefank@50089 75 // the current thread passes a possible safepoint while this object is
stefank@50089 76 // instantiated. A safepoint, will either be: an oop allocation, blocking
stefank@50089 77 // on a Mutex or JavaLock, or executing a VM operation.
stefank@50089 78 //
stefank@50089 79 // If StrictSafepointChecks is turned off, it degrades into a NoGCVerifier
stefank@50089 80 //
stefank@50089 81 class NoSafepointVerifier : public NoGCVerifier {
stefank@50089 82 friend class PauseNoSafepointVerifier;
stefank@50089 83
stefank@50089 84 private:
stefank@50089 85 bool _activated;
stefank@50089 86 Thread *_thread;
stefank@50089 87 public:
stefank@50089 88 #ifdef ASSERT
stefank@50089 89 NoSafepointVerifier(bool activated = true, bool verifygc = true ) :
stefank@50089 90 NoGCVerifier(verifygc),
stefank@50089 91 _activated(activated) {
stefank@50089 92 _thread = Thread::current();
stefank@50089 93 if (_activated) {
stefank@50089 94 _thread->_allow_allocation_count++;
stefank@50089 95 _thread->_allow_safepoint_count++;
stefank@50089 96 }
stefank@50089 97 }
stefank@50089 98
stefank@50089 99 ~NoSafepointVerifier() {
stefank@50089 100 if (_activated) {
stefank@50089 101 _thread->_allow_allocation_count--;
stefank@50089 102 _thread->_allow_safepoint_count--;
stefank@50089 103 }
stefank@50089 104 }
stefank@50089 105 #else
stefank@50089 106 NoSafepointVerifier(bool activated = true, bool verifygc = true) : NoGCVerifier(verifygc){}
stefank@50089 107 ~NoSafepointVerifier() {}
stefank@50089 108 #endif
stefank@50089 109 };
stefank@50089 110
stefank@50089 111 // A PauseNoSafepointVerifier is used to temporarily pause the
stefank@50089 112 // behavior of a NoSafepointVerifier object. If we are not in debug
stefank@50089 113 // mode then there is nothing to do. If the NoSafepointVerifier
stefank@50089 114 // object has an _activated value of false, then there is nothing to
stefank@50089 115 // do for safepoint and allocation checking, but there may still be
stefank@50089 116 // something to do for the underlying NoGCVerifier object.
stefank@50089 117
stefank@50089 118 class PauseNoSafepointVerifier : public PauseNoGCVerifier {
stefank@50089 119 private:
stefank@50089 120 NoSafepointVerifier * _nsv;
stefank@50089 121
stefank@50089 122 public:
stefank@50089 123 #ifdef ASSERT
stefank@50089 124 PauseNoSafepointVerifier(NoSafepointVerifier * nsv)
stefank@50089 125 : PauseNoGCVerifier(nsv) {
stefank@50089 126
stefank@50089 127 _nsv = nsv;
stefank@50089 128 if (_nsv->_activated) {
stefank@50089 129 _nsv->_thread->_allow_allocation_count--;
stefank@50089 130 _nsv->_thread->_allow_safepoint_count--;
stefank@50089 131 }
stefank@50089 132 }
stefank@50089 133
stefank@50089 134 ~PauseNoSafepointVerifier() {
stefank@50089 135 if (_nsv->_activated) {
stefank@50089 136 _nsv->_thread->_allow_allocation_count++;
stefank@50089 137 _nsv->_thread->_allow_safepoint_count++;
stefank@50089 138 }
stefank@50089 139 }
stefank@50089 140 #else
stefank@50089 141 PauseNoSafepointVerifier(NoSafepointVerifier * nsv)
stefank@50089 142 : PauseNoGCVerifier(nsv) {}
stefank@50089 143 ~PauseNoSafepointVerifier() {}
stefank@50089 144 #endif
stefank@50089 145 };
stefank@50089 146
stefank@50089 147 // A NoAllocVerifier object can be placed in methods where one assumes that
stefank@50089 148 // no allocation will occur. The destructor will verify this property
stefank@50089 149 // unless the constructor is called with argument false (not activated).
stefank@50089 150 //
stefank@50089 151 // The check will only be done in debug mode and if activated.
stefank@50089 152 // Note: this only makes sense at safepoints (otherwise, other threads may
stefank@50089 153 // allocate concurrently.)
stefank@50089 154
stefank@50089 155 class NoAllocVerifier : public StackObj {
stefank@50089 156 private:
stefank@50089 157 bool _activated;
stefank@50089 158
stefank@50089 159 public:
stefank@50089 160 #ifdef ASSERT
stefank@50089 161 NoAllocVerifier(bool activated = true) {
stefank@50089 162 _activated = activated;
stefank@50089 163 if (_activated) Thread::current()->_allow_allocation_count++;
stefank@50089 164 }
stefank@50089 165
stefank@50089 166 ~NoAllocVerifier() {
stefank@50089 167 if (_activated) Thread::current()->_allow_allocation_count--;
stefank@50089 168 }
stefank@50089 169 #else
stefank@50089 170 NoAllocVerifier(bool activated = true) {}
stefank@50089 171 ~NoAllocVerifier() {}
stefank@50089 172 #endif
stefank@50089 173 };
stefank@50089 174
stefank@50089 175 #endif // SHARE_VM_RUNTIME_SAFEPOINTVERIFIERS_HPP