hotspot/src/share/vm/gc/shared/gcLocker.cpp
author dholmes
Sun, 21 Aug 2016 20:56:37 -0400
changeset 40655 9f644073d3a0
parent 37242 91e5f98fff6f
permissions -rw-r--r--
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp Summary: Remove atomic.inline.hpp and move the contents back into atomic.hpp Reviewed-by: stefank, pliden, simonis
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 37242
diff changeset
     2
 * Copyright (c) 1997, 2016, 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: 670
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 670
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: 670
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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    26
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30154
diff changeset
    27
#include "gc/shared/gcLocker.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/resourceArea.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    29
#include "logging/log.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 37242
diff changeset
    30
#include "runtime/atomic.hpp"
24351
61b33cc6d3cf 8042195: Introduce umbrella header orderAccess.inline.hpp.
goetz
parents: 23540
diff changeset
    31
#include "runtime/thread.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    33
volatile jint GCLocker::_jni_lock_count = 0;
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    34
volatile bool GCLocker::_needs_gc       = false;
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    35
volatile bool GCLocker::_doing_gc       = false;
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    36
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    37
#ifdef ASSERT
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    38
volatile jint GCLocker::_debug_jni_lock_count = 0;
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    39
#endif
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    40
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    41
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    42
#ifdef ASSERT
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    43
void GCLocker::verify_critical_count() {
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    44
  if (SafepointSynchronize::is_at_safepoint()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    45
    assert(!needs_gc() || _debug_jni_lock_count == _jni_lock_count, "must agree");
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    46
    int count = 0;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    47
    // Count the number of threads with critical operations in progress
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    48
    for (JavaThread* thr = Threads::first(); thr; thr = thr->next()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    49
      if (thr->in_critical()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    50
        count++;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    51
      }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    52
    }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    53
    if (_jni_lock_count != count) {
37226
9b0d4b523ce4 8153188: Use log_error(gc, verify) for logging in verification code
brutisso
parents: 35492
diff changeset
    54
      log_error(gc, verify)("critical counts don't match: %d != %d", _jni_lock_count, count);
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    55
      for (JavaThread* thr = Threads::first(); thr; thr = thr->next()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    56
        if (thr->in_critical()) {
37226
9b0d4b523ce4 8153188: Use log_error(gc, verify) for logging in verification code
brutisso
parents: 35492
diff changeset
    57
          log_error(gc, verify)(INTPTR_FORMAT " in_critical %d", p2i(thr), thr->in_critical());
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    58
        }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    59
      }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    60
    }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    61
    assert(_jni_lock_count == count, "must be equal");
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    62
  }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    63
}
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    64
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    65
// In debug mode track the locking state at all times
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    66
void GCLocker::increment_debug_jni_lock_count() {
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    67
  assert(_debug_jni_lock_count >= 0, "bad value");
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    68
  Atomic::inc(&_debug_jni_lock_count);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    69
}
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    70
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    71
void GCLocker::decrement_debug_jni_lock_count() {
25351
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    72
  assert(_debug_jni_lock_count > 0, "bad value");
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    73
  Atomic::dec(&_debug_jni_lock_count);
7c198a690050 8044775: Improve usage of umbrella header atomic.inline.hpp.
goetz
parents: 24424
diff changeset
    74
}
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    75
#endif
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    76
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    77
void GCLocker::log_debug_jni(const char* msg) {
37242
91e5f98fff6f 8152632: Rename LogHandle(...) to Log(...)
stefank
parents: 37226
diff changeset
    78
  Log(gc, jni) log;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    79
  if (log.is_debug()) {
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    80
    ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    81
    log.debug("%s Thread \"%s\" %d locked.", msg, Thread::current()->name(), _jni_lock_count);
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    82
  }
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    83
}
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    84
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    85
bool GCLocker::check_active_before_gc() {
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    86
  assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    87
  if (is_active() && !_needs_gc) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    88
    verify_critical_count();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    89
    _needs_gc = true;
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
    90
    log_debug_jni("Setting _needs_gc.");
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    91
  }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    92
  return is_active();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    93
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
    95
void GCLocker::stall_until_clear() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  assert(!JavaThread::current()->in_critical(), "Would deadlock");
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    97
  MutexLocker   ml(JNICritical_lock);
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    98
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    99
  if (needs_gc()) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   100
    log_debug_jni("Allocation failed. Thread stalled by JNI critical section.");
386
7f121b1192f2 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 1
diff changeset
   101
  }
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   102
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // Wait for _needs_gc  to be cleared
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   104
  while (needs_gc()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    JNICritical_lock->wait();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   109
void GCLocker::jni_lock(JavaThread* thread) {
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   110
  assert(!thread->in_critical(), "shouldn't currently be in a critical region");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  MutexLocker mu(JNICritical_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // Block entering threads if we know at least one thread is in a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  // JNI critical region and we need a GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // We check that at least one thread is in a critical region before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // blocking because blocked threads are woken up by a thread exiting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // a JNI critical region.
23540
06f7d6e1f654 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 22234
diff changeset
   117
  while (is_active_and_needs_gc() || _doing_gc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    JNICritical_lock->wait();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  }
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   120
  thread->enter_critical();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   121
  _jni_lock_count++;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   122
  increment_debug_jni_lock_count();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   125
void GCLocker::jni_unlock(JavaThread* thread) {
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   126
  assert(thread->in_last_critical(), "should be exiting critical region");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  MutexLocker mu(JNICritical_lock);
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   128
  _jni_lock_count--;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   129
  decrement_debug_jni_lock_count();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   130
  thread->exit_critical();
23540
06f7d6e1f654 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 22234
diff changeset
   131
  if (needs_gc() && !is_active_internal()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    // We're the last thread out. Cause a GC to occur.
23540
06f7d6e1f654 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 22234
diff changeset
   133
    _doing_gc = true;
06f7d6e1f654 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 22234
diff changeset
   134
    {
06f7d6e1f654 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 22234
diff changeset
   135
      // Must give up the lock while at a safepoint
06f7d6e1f654 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 22234
diff changeset
   136
      MutexUnlocker munlock(JNICritical_lock);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 30764
diff changeset
   137
      log_debug_jni("Performing GC after exiting critical section.");
23540
06f7d6e1f654 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 22234
diff changeset
   138
      Universe::heap()->collect(GCCause::_gc_locker);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    }
23540
06f7d6e1f654 8028498: runtime/SharedArchiveFile/CdsDifferentObjectAlignment.java asserts in RT_Baseline
sjohanss
parents: 22234
diff changeset
   140
    _doing_gc = false;
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   141
    _needs_gc = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    JNICritical_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   146
// Implementation of NoGCVerifier
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   150
NoGCVerifier::NoGCVerifier(bool verifygc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  _verifygc = verifygc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  if (_verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    CollectedHeap* h = Universe::heap();
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   154
    assert(!h->is_gc_active(), "GC active during NoGCVerifier");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    _old_invocations = h->total_collections();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   160
NoGCVerifier::~NoGCVerifier() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  if (_verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    CollectedHeap* h = Universe::heap();
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   163
    assert(!h->is_gc_active(), "GC active during NoGCVerifier");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    if (_old_invocations != h->total_collections()) {
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   165
      fatal("collection in a NoGCVerifier secured function");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   170
PauseNoGCVerifier::PauseNoGCVerifier(NoGCVerifier * ngcv) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  _ngcv = ngcv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  if (_ngcv->_verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    // if we were verifying, then make sure that nothing is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    // wrong before we "pause" verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    CollectedHeap* h = Universe::heap();
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   176
    assert(!h->is_gc_active(), "GC active during NoGCVerifier");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    if (_ngcv->_old_invocations != h->total_collections()) {
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   178
      fatal("collection in a NoGCVerifier secured function");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   184
PauseNoGCVerifier::~PauseNoGCVerifier() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  if (_ngcv->_verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    // if we were verifying before, then reenable verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    CollectedHeap* h = Universe::heap();
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   188
    assert(!h->is_gc_active(), "GC active during NoGCVerifier");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    _ngcv->_old_invocations = h->total_collections();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
// JRT_LEAF rules:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
// A JRT_LEAF method may not interfere with safepointing by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
//   1) acquiring or blocking on a Mutex or JavaLock - checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
//   2) allocating heap memory - checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
//   3) executing a VM operation - checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
//   4) executing a system call (including malloc) that could block or grab a lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
//   5) invoking GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
//   6) reaching a safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
//   7) running too long
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
// Nor may any method it calls.
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   204
JRTLeafVerifier::JRTLeafVerifier()
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   205
  : NoSafepointVerifier(true, JRTLeafVerifier::should_verify_GC())
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 35061
diff changeset
   209
JRTLeafVerifier::~JRTLeafVerifier()
1
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
bool JRTLeafVerifier::should_verify_GC() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  switch (JavaThread::current()->thread_state()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  case _thread_in_Java:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    // is in a leaf routine, there must be no safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  case _thread_in_native:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    // A native thread is not subject to safepoints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    // Even while it is in a leaf routine, GC is ok
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    // Leaf routines cannot be called from other contexts.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
#endif