hotspot/src/share/vm/gc/shared/gcLocker.hpp
author david
Thu, 14 Jan 2016 13:26:19 +0100
changeset 35492 c8c0273e6b91
parent 35061 be6025ebffea
permissions -rw-r--r--
8146690: Make all classes in GC follow the naming convention. Reviewed-by: dholmes, stefank
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25468
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
1
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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25468
diff changeset
    25
#ifndef SHARE_VM_GC_SHARED_GCLOCKER_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25468
diff changeset
    26
#define SHARE_VM_GC_SHARED_GCLOCKER_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25468
diff changeset
    28
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25468
diff changeset
    29
#include "gc/shared/genCollectedHeap.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
#include "memory/universe.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
#include "oops/oop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// The direct lock/unlock calls do not force a collection if an unlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// decrements the count to zero. Avoid calling these if at all possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    36
class GCLocker: public AllStatic {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
 private:
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    38
  // The _jni_lock_count keeps track of the number of threads that are
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    39
  // currently in a critical region.  It's only kept up to date when
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    40
  // _needs_gc is true.  The current value is computed during
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    41
  // safepointing and decremented during the slow path of GCLocker
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    42
  // unlocking.
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    43
  static volatile jint _jni_lock_count;  // number of jni active instances.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static volatile bool _needs_gc;        // heap is filling, we need a GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
                                         // note: bool is typedef'd as jint
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  static volatile bool _doing_gc;        // unlock_critical() is doing a GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    48
#ifdef ASSERT
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    49
  // This lock count is updated for all operations and is used to
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    50
  // validate the jni_lock_count that is computed during safepoints.
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    51
  static volatile jint _debug_jni_lock_count;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    52
#endif
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    53
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    54
  // At a safepoint, visit all threads and count the number of active
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    55
  // critical sections.  This is used to ensure that all active
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    56
  // critical sections are exited before a new one is started.
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    57
  static void verify_critical_count() NOT_DEBUG_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    59
  static void jni_lock(JavaThread* thread);
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    60
  static void jni_unlock(JavaThread* thread);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
11793
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    62
  static bool is_active_internal() {
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    63
    verify_critical_count();
23540
06f7d6e1f654 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 22234
diff changeset
    64
    return _jni_lock_count > 0;
11793
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    65
  }
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    66
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    67
  static void log_debug_jni(const char* msg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // Accessors
11793
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    70
  static bool is_active() {
20079
edbc2f7b38ef 8024974: Incorrect use of GC_locker::is_active()
stefank
parents: 14583
diff changeset
    71
    assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
11793
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    72
    return is_active_internal();
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    73
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  static bool needs_gc()       { return _needs_gc;                        }
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    75
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Shorthand
11793
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    77
  static bool is_active_and_needs_gc() {
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    78
    // Use is_active_internal since _needs_gc can change from true to
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    79
    // false outside of a safepoint, triggering the assert in
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    80
    // is_active.
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    81
    return needs_gc() && is_active_internal();
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    82
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    84
  // In debug mode track the locking state at all times
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 23540
diff changeset
    85
  static void increment_debug_jni_lock_count() NOT_DEBUG_RETURN;
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 23540
diff changeset
    86
  static void decrement_debug_jni_lock_count() NOT_DEBUG_RETURN;
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    87
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    88
  // Set the current lock count
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    89
  static void set_jni_lock_count(int count) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    90
    _jni_lock_count = count;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    91
    verify_critical_count();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    92
  }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    93
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    94
  // Sets _needs_gc if is_active() is true. Returns is_active().
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  static bool check_active_before_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // Stalls the caller (who should not be in a jni critical section)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // until needs_gc() clears. Note however that needs_gc() may be
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // set at a subsequent safepoint and/or cleared under the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // JNICritical_lock, so the caller may not safely assert upon
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // return from this method that "!needs_gc()" since that is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // not a stable predicate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  static void stall_until_clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // The following two methods are used for JNI critical regions.
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   106
  // If we find that we failed to perform a GC because the GCLocker
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // was active, arrange for one as soon as possible by allowing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // all threads in critical regions to complete, but not allowing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  // other critical regions to be entered. The reasons for that are:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // 1) a GC request won't be starved by overlapping JNI critical
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  //    region activities, which can cause unnecessary OutOfMemory errors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // 2) even if allocation requests can still be satisfied before GC locker
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  //    becomes inactive, for example, in tenured generation possibly with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  //    heap expansion, those allocations can trigger lots of safepointing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  //    attempts (ineffective GC attempts) and require Heap_lock which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  //    slow down allocations tremendously.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Note that critical regions can be nested in a single thread, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // we must allow threads already in critical regions to continue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // JNI critical regions are the only participants in this scheme
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // because they are, by spec, well bounded while in a critical region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  //
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   124
  // Each of the following two method is split into a fast path and a
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   125
  // slow path. JNICritical_lock is only grabbed in the slow path.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // _needs_gc is initially false and every java thread will go
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   127
  // through the fast path, which simply increments or decrements the
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   128
  // current thread's critical count.  When GC happens at a safepoint,
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   129
  // GCLocker::is_active() is checked. Since there is no safepoint in
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   130
  // the fast path of lock_critical() and unlock_critical(), there is
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   131
  // no race condition between the fast path and GC. After _needs_gc
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   132
  // is set at a safepoint, every thread will go through the slow path
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   133
  // after the safepoint.  Since after a safepoint, each of the
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   134
  // following two methods is either entered from the method entry and
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   135
  // falls into the slow path, or is resumed from the safepoints in
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   136
  // the method, which only exist in the slow path. So when _needs_gc
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   137
  // is set, the slow path is always taken, till _needs_gc is cleared.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  static void lock_critical(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static void unlock_critical(JavaThread* thread);
11637
030466036615 7013347: allow crypto functions to be called inline to enhance performance
never
parents: 11631
diff changeset
   140
030466036615 7013347: allow crypto functions to be called inline to enhance performance
never
parents: 11631
diff changeset
   141
  static address needs_gc_address() { return (address) &_needs_gc; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   145
// A NoGCVerifier object can be placed in methods where one assumes that
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
// no garbage collection will occur. The destructor will verify this property
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// unless the constructor is called with argument false (not verifygc).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
// The check will only be done in debug mode and if verifygc true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   151
class NoGCVerifier: public StackObj {
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   152
 friend class PauseNoGCVerifier;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  bool _verifygc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  unsigned int _old_invocations;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
#ifdef ASSERT
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   160
  NoGCVerifier(bool verifygc = true);
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   161
  ~NoGCVerifier();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
#else
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   163
  NoGCVerifier(bool verifygc = true) {}
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   164
  ~NoGCVerifier() {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   168
// A PauseNoGCVerifier is used to temporarily pause the behavior
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   169
// of a NoGCVerifier object. If we are not in debug mode or if the
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   170
// NoGCVerifier object has a _verifygc value of false, then there
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
// is nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   173
class PauseNoGCVerifier: public StackObj {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
 private:
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   175
  NoGCVerifier * _ngcv;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
#ifdef ASSERT
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   179
  PauseNoGCVerifier(NoGCVerifier * ngcv);
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   180
  ~PauseNoGCVerifier();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
#else
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   182
  PauseNoGCVerifier(NoGCVerifier * ngcv) {}
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   183
  ~PauseNoGCVerifier() {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   188
// A NoSafepointVerifier object will throw an assertion failure if
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
// the current thread passes a possible safepoint while this object is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// instantiated. A safepoint, will either be: an oop allocation, blocking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
// on a Mutex or JavaLock, or executing a VM operation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
//
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   193
// If StrictSafepointChecks is turned off, it degrades into a NoGCVerifier
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
//
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   195
class NoSafepointVerifier : public NoGCVerifier {
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   196
 friend class PauseNoSafepointVerifier;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  bool _activated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  Thread *_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
#ifdef ASSERT
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   203
  NoSafepointVerifier(bool activated = true, bool verifygc = true ) :
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   204
    NoGCVerifier(verifygc),
345
8a4c345e460c 6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents: 1
diff changeset
   205
    _activated(activated) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
    _thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    if (_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
      _thread->_allow_allocation_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
      _thread->_allow_safepoint_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   213
  ~NoSafepointVerifier() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    if (_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
      _thread->_allow_allocation_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      _thread->_allow_safepoint_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
#else
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   220
  NoSafepointVerifier(bool activated = true, bool verifygc = true) : NoGCVerifier(verifygc){}
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   221
  ~NoSafepointVerifier() {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   225
// A PauseNoSafepointVerifier is used to temporarily pause the
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   226
// behavior of a NoSafepointVerifier object. If we are not in debug
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   227
// mode then there is nothing to do. If the NoSafepointVerifier
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
// object has an _activated value of false, then there is nothing to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
// do for safepoint and allocation checking, but there may still be
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   230
// something to do for the underlying NoGCVerifier object.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   232
class PauseNoSafepointVerifier : public PauseNoGCVerifier {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
 private:
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   234
  NoSafepointVerifier * _nsv;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
#ifdef ASSERT
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   238
  PauseNoSafepointVerifier(NoSafepointVerifier * nsv)
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   239
    : PauseNoGCVerifier(nsv) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    _nsv = nsv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    if (_nsv->_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      _nsv->_thread->_allow_allocation_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      _nsv->_thread->_allow_safepoint_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   248
  ~PauseNoSafepointVerifier() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    if (_nsv->_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      _nsv->_thread->_allow_allocation_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      _nsv->_thread->_allow_safepoint_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
#else
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   255
  PauseNoSafepointVerifier(NoSafepointVerifier * nsv)
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   256
    : PauseNoGCVerifier(nsv) {}
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   257
  ~PauseNoSafepointVerifier() {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
2995
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   261
// A SkipGCALot object is used to elide the usual effect of gc-a-lot
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   262
// over a section of execution by a thread. Currently, it's used only to
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   263
// prevent re-entrant calls to GC.
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   264
class SkipGCALot : public StackObj {
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   265
  private:
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   266
   bool _saved;
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   267
   Thread* _t;
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   268
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   269
  public:
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   270
#ifdef ASSERT
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   271
    SkipGCALot(Thread* t) : _t(t) {
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   272
      _saved = _t->skip_gcalot();
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   273
      _t->set_skip_gcalot(true);
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   274
    }
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   275
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   276
    ~SkipGCALot() {
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   277
      assert(_t->skip_gcalot(), "Save-restore protocol invariant");
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   278
      _t->set_skip_gcalot(_saved);
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   279
    }
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   280
#else
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   281
    SkipGCALot(Thread* t) { }
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   282
    ~SkipGCALot() { }
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   283
#endif
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   284
};
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   285
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
// JRT_LEAF currently can be called from either _thread_in_Java or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
// _thread_in_native mode. In _thread_in_native, it is ok
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
// for another thread to trigger GC. The rest of the JRT_LEAF
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
// rules apply.
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   290
class JRTLeafVerifier : public NoSafepointVerifier {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  static bool should_verify_GC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
#ifdef ASSERT
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   294
  JRTLeafVerifier();
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   295
  ~JRTLeafVerifier();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
#else
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   297
  JRTLeafVerifier() {}
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   298
  ~JRTLeafVerifier() {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   302
// A NoAllocVerifier object can be placed in methods where one assumes that
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
// no allocation will occur. The destructor will verify this property
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
// unless the constructor is called with argument false (not activated).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
// The check will only be done in debug mode and if activated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
// Note: this only makes sense at safepoints (otherwise, other threads may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
// allocate concurrently.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   310
class NoAllocVerifier : public StackObj {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  bool  _activated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
#ifdef ASSERT
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   316
  NoAllocVerifier(bool activated = true) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    _activated = activated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    if (_activated) Thread::current()->_allow_allocation_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   321
  ~NoAllocVerifier() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
    if (_activated) Thread::current()->_allow_allocation_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
#else
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   325
  NoAllocVerifier(bool activated = true) {}
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   326
  ~NoAllocVerifier() {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   329
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 25468
diff changeset
   330
#endif // SHARE_VM_GC_SHARED_GCLOCKER_HPP