hotspot/src/share/vm/memory/gcLocker.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 345 8a4c345e460c
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// The direct lock/unlock calls do not force a collection if an unlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// decrements the count to zero. Avoid calling these if at all possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
class GC_locker: public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  static volatile jint _jni_lock_count;  // number of jni active instances
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  static volatile jint _lock_count;      // number of other active instances
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  static volatile bool _needs_gc;        // heap is filling, we need a GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
                                         // note: bool is typedef'd as jint
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  static volatile bool _doing_gc;        // unlock_critical() is doing a GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  static bool is_jni_active() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    return _jni_lock_count > 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  static void set_needs_gc() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    assert(SafepointSynchronize::is_at_safepoint(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
      "needs_gc is only set at a safepoint");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    _needs_gc = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  static void clear_needs_gc() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    assert_lock_strong(JNICritical_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    _needs_gc = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  static void jni_lock() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    Atomic::inc(&_jni_lock_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    CHECK_UNHANDLED_OOPS_ONLY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      if (CheckUnhandledOops) { Thread::current()->_gc_locked_out_count++; })
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    assert(Universe::heap() == NULL || !Universe::heap()->is_gc_active(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
           "locking failed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  static void jni_unlock() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    Atomic::dec(&_jni_lock_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    CHECK_UNHANDLED_OOPS_ONLY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      if (CheckUnhandledOops) { Thread::current()->_gc_locked_out_count--; })
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  static void jni_lock_slow();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  static void jni_unlock_slow();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  static bool is_active();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  static bool needs_gc()       { return _needs_gc;                        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Shorthand
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  static bool is_active_and_needs_gc() { return is_active() && needs_gc();}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Calls set_needs_gc() if is_active() is true. Returns is_active().
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  static bool check_active_before_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Stalls the caller (who should not be in a jni critical section)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // until needs_gc() clears. Note however that needs_gc() may be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // set at a subsequent safepoint and/or cleared under the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // JNICritical_lock, so the caller may not safely assert upon
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // return from this method that "!needs_gc()" since that is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // not a stable predicate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  static void stall_until_clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // Non-structured GC locking: currently needed for JNI. Use with care!
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  static void lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  static void unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // The following two methods are used for JNI critical regions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // If we find that we failed to perform a GC because the GC_locker
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // was active, arrange for one as soon as possible by allowing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // all threads in critical regions to complete, but not allowing
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // other critical regions to be entered. The reasons for that are:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // 1) a GC request won't be starved by overlapping JNI critical
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  //    region activities, which can cause unnecessary OutOfMemory errors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // 2) even if allocation requests can still be satisfied before GC locker
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  //    becomes inactive, for example, in tenured generation possibly with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  //    heap expansion, those allocations can trigger lots of safepointing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  //    attempts (ineffective GC attempts) and require Heap_lock which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  //    slow down allocations tremendously.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // Note that critical regions can be nested in a single thread, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // we must allow threads already in critical regions to continue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // JNI critical regions are the only participants in this scheme
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // because they are, by spec, well bounded while in a critical region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // Each of the following two method is split into a fast path and a slow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // path. JNICritical_lock is only grabbed in the slow path.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // _needs_gc is initially false and every java thread will go
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // through the fast path (which does the same thing as the slow path
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // when _needs_gc is false). When GC happens at a safepoint,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // GC_locker::is_active() is checked. Since there is no safepoint in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // fast path of lock_critical() and unlock_critical(), there is no race
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  // condition between the fast path and GC. After _needs_gc is set at a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // safepoint, every thread will go through the slow path after the safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // Since after a safepoint, each of the following two methods is either
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  // entered from the method entry and falls into the slow path, or is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // resumed from the safepoints in the method, which only exist in the slow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // path. So when _needs_gc is set, the slow path is always taken, till
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // _needs_gc is cleared.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  static void lock_critical(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  static void unlock_critical(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// A No_GC_Verifier object can be placed in methods where one assumes that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// no garbage collection will occur. The destructor will verify this property
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// unless the constructor is called with argument false (not verifygc).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
// The check will only be done in debug mode and if verifygc true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
class No_GC_Verifier: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
 friend class Pause_No_GC_Verifier;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  bool _verifygc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  unsigned int _old_invocations;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  No_GC_Verifier(bool verifygc = true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  ~No_GC_Verifier();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  No_GC_Verifier(bool verifygc = true) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  ~No_GC_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// A Pause_No_GC_Verifier is used to temporarily pause the behavior
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
// of a No_GC_Verifier object. If we are not in debug mode or if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// No_GC_Verifier object has a _verifygc value of false, then there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// is nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
class Pause_No_GC_Verifier: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  No_GC_Verifier * _ngcv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  Pause_No_GC_Verifier(No_GC_Verifier * ngcv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  ~Pause_No_GC_Verifier();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  Pause_No_GC_Verifier(No_GC_Verifier * ngcv) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  ~Pause_No_GC_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
// A No_Safepoint_Verifier object will throw an assertion failure if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// the current thread passes a possible safepoint while this object is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// instantiated. A safepoint, will either be: an oop allocation, blocking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
// on a Mutex or JavaLock, or executing a VM operation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// If StrictSafepointChecks is turned off, it degrades into a No_GC_Verifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
class No_Safepoint_Verifier : public No_GC_Verifier {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
 friend class Pause_No_Safepoint_Verifier;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  bool _activated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  Thread *_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  No_Safepoint_Verifier(bool activated = true, bool verifygc = true ) : No_GC_Verifier(verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    _thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    if (_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      _thread->_allow_allocation_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      _thread->_allow_safepoint_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  ~No_Safepoint_Verifier() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    if (_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      _thread->_allow_allocation_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
      _thread->_allow_safepoint_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  No_Safepoint_Verifier(bool activated = true, bool verifygc = true) : No_GC_Verifier(verifygc){}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  ~No_Safepoint_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// A Pause_No_Safepoint_Verifier is used to temporarily pause the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
// behavior of a No_Safepoint_Verifier object. If we are not in debug
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// mode then there is nothing to do. If the No_Safepoint_Verifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
// object has an _activated value of false, then there is nothing to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
// do for safepoint and allocation checking, but there may still be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
// something to do for the underlying No_GC_Verifier object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
class Pause_No_Safepoint_Verifier : public Pause_No_GC_Verifier {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  No_Safepoint_Verifier * _nsv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  Pause_No_Safepoint_Verifier(No_Safepoint_Verifier * nsv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    : Pause_No_GC_Verifier(nsv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    _nsv = nsv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    if (_nsv->_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
      _nsv->_thread->_allow_allocation_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      _nsv->_thread->_allow_safepoint_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  ~Pause_No_Safepoint_Verifier() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    if (_nsv->_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
      _nsv->_thread->_allow_allocation_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      _nsv->_thread->_allow_safepoint_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  Pause_No_Safepoint_Verifier(No_Safepoint_Verifier * nsv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    : Pause_No_GC_Verifier(nsv) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  ~Pause_No_Safepoint_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
// JRT_LEAF currently can be called from either _thread_in_Java or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// _thread_in_native mode. In _thread_in_native, it is ok
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// for another thread to trigger GC. The rest of the JRT_LEAF
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// rules apply.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
class JRT_Leaf_Verifier : public No_Safepoint_Verifier {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  static bool should_verify_GC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  JRT_Leaf_Verifier();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  ~JRT_Leaf_Verifier();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  JRT_Leaf_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  ~JRT_Leaf_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
// A No_Alloc_Verifier object can be placed in methods where one assumes that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
// no allocation will occur. The destructor will verify this property
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
// unless the constructor is called with argument false (not activated).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
// The check will only be done in debug mode and if activated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
// Note: this only makes sense at safepoints (otherwise, other threads may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
// allocate concurrently.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
class No_Alloc_Verifier : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  bool  _activated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  No_Alloc_Verifier(bool activated = true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    _activated = activated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    if (_activated) Thread::current()->_allow_allocation_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  ~No_Alloc_Verifier() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    if (_activated) Thread::current()->_allow_allocation_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  No_Alloc_Verifier(bool activated = true) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  ~No_Alloc_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
};