hotspot/src/share/vm/memory/gcLocker.cpp
author stefank
Fri, 14 Feb 2014 09:29:56 +0100
changeset 22883 5378704451dc
parent 22234 da823d78ad65
child 23540 06f7d6e1f654
permissions -rw-r--r--
8034764: Use process_strong_roots to adjust the StringTable Reviewed-by: tschatzl, brutisso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 20079
diff changeset
     2
 * Copyright (c) 1997, 2013, 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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "memory/gcLocker.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/sharedHeap.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
volatile jint GC_locker::_jni_lock_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
volatile jint GC_locker::_lock_count     = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
volatile bool GC_locker::_needs_gc       = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
volatile bool GC_locker::_doing_gc       = false;
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    34
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    35
#ifdef ASSERT
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    36
volatile jint GC_locker::_debug_jni_lock_count = 0;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    37
#endif
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    38
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    39
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    40
#ifdef ASSERT
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    41
void GC_locker::verify_critical_count() {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    42
  if (SafepointSynchronize::is_at_safepoint()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    43
    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
    44
    int count = 0;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    45
    // Count the number of threads with critical operations in progress
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    46
    for (JavaThread* thr = Threads::first(); thr; thr = thr->next()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    47
      if (thr->in_critical()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    48
        count++;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    49
      }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    50
    }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    51
    if (_jni_lock_count != count) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    52
      tty->print_cr("critical counts don't match: %d != %d", _jni_lock_count, count);
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    53
      for (JavaThread* thr = Threads::first(); thr; thr = thr->next()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    54
        if (thr->in_critical()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    55
          tty->print_cr(INTPTR_FORMAT " in_critical %d", thr, thr->in_critical());
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    56
        }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    57
      }
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
    assert(_jni_lock_count == count, "must be equal");
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
}
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    62
#endif
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    63
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    64
bool GC_locker::check_active_before_gc() {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    65
  assert(SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    66
  if (is_active() && !_needs_gc) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    67
    verify_critical_count();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    68
    _needs_gc = true;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    69
    if (PrintJNIGCStalls && PrintGCDetails) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    70
      ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11637
diff changeset
    71
      gclog_or_tty->print_cr("%.3f: Setting _needs_gc. Thread \"%s\" %d locked.",
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11637
diff changeset
    72
                             gclog_or_tty->time_stamp().seconds(), Thread::current()->name(), _jni_lock_count);
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    73
    }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    74
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    75
  }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    76
  return is_active();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    77
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
void GC_locker::stall_until_clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  assert(!JavaThread::current()->in_critical(), "Would deadlock");
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    81
  MutexLocker   ml(JNICritical_lock);
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    82
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    83
  if (needs_gc()) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    84
    if (PrintJNIGCStalls && PrintGCDetails) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    85
      ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11637
diff changeset
    86
      gclog_or_tty->print_cr("%.3f: Allocation failed. Thread \"%s\" is stalled by JNI critical section, %d locked.",
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11637
diff changeset
    87
                             gclog_or_tty->time_stamp().seconds(), Thread::current()->name(), _jni_lock_count);
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    88
    }
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
    89
  }
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    90
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // Wait for _needs_gc  to be cleared
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    92
  while (needs_gc()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    JNICritical_lock->wait();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    97
void GC_locker::jni_lock(JavaThread* thread) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    98
  assert(!thread->in_critical(), "shouldn't currently be in a critical region");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  MutexLocker mu(JNICritical_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // Block entering threads if we know at least one thread is in a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  // JNI critical region and we need a GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // We check that at least one thread is in a critical region before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // blocking because blocked threads are woken up by a thread exiting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  // a JNI critical region.
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   105
  while ((needs_gc() && is_jni_active()) || _doing_gc) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    JNICritical_lock->wait();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   108
  thread->enter_critical();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   109
  _jni_lock_count++;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   110
  increment_debug_jni_lock_count();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   113
void GC_locker::jni_unlock(JavaThread* thread) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   114
  assert(thread->in_last_critical(), "should be exiting critical region");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  MutexLocker mu(JNICritical_lock);
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   116
  _jni_lock_count--;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   117
  decrement_debug_jni_lock_count();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   118
  thread->exit_critical();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  if (needs_gc() && !is_jni_active()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    // We're the last thread out. Cause a GC to occur.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // GC will also check is_active, so this check is not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    // strictly needed. It's added here to make it clear that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // the GC will NOT be performed if any other caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    // of GC_locker::lock() still needs GC locked.
20079
edbc2f7b38ef 8024974: Incorrect use of GC_locker::is_active()
stefank
parents: 11788
diff changeset
   125
    if (!is_active_internal()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      _doing_gc = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
        // Must give up the lock while at a safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
        MutexUnlocker munlock(JNICritical_lock);
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   130
        if (PrintJNIGCStalls && PrintGCDetails) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   131
          ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
11788
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11637
diff changeset
   132
          gclog_or_tty->print_cr("%.3f: Thread \"%s\" is performing GC after exiting critical section, %d locked",
bef6166c683c 7145537: minor tweaks to LogEvents
never
parents: 11637
diff changeset
   133
                                 gclog_or_tty->time_stamp().seconds(), Thread::current()->name(), _jni_lock_count);
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   134
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
        Universe::heap()->collect(GCCause::_gc_locker);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      _doing_gc = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    }
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   139
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   140
    _needs_gc = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    JNICritical_lock->notify_all();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// Implementation of No_GC_Verifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
No_GC_Verifier::No_GC_Verifier(bool verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  _verifygc = verifygc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  if (_verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    CollectedHeap* h = Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    assert(!h->is_gc_active(), "GC active during No_GC_Verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    _old_invocations = h->total_collections();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
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
No_GC_Verifier::~No_GC_Verifier() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  if (_verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    CollectedHeap* h = Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    assert(!h->is_gc_active(), "GC active during No_GC_Verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    if (_old_invocations != h->total_collections()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      fatal("collection in a No_GC_Verifier secured function");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    }
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
Pause_No_GC_Verifier::Pause_No_GC_Verifier(No_GC_Verifier * ngcv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  _ngcv = ngcv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  if (_ngcv->_verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    // if we were verifying, then make sure that nothing is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    // wrong before we "pause" verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    CollectedHeap* h = Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    assert(!h->is_gc_active(), "GC active during No_GC_Verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    if (_ngcv->_old_invocations != h->total_collections()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      fatal("collection in a No_GC_Verifier secured function");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    }
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
Pause_No_GC_Verifier::~Pause_No_GC_Verifier() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  if (_ngcv->_verifygc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    // if we were verifying before, then reenable verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    CollectedHeap* h = Universe::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    assert(!h->is_gc_active(), "GC active during No_GC_Verifier");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
    _ngcv->_old_invocations = h->total_collections();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  }
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
// JRT_LEAF rules:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
// A JRT_LEAF method may not interfere with safepointing by
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
//   1) acquiring or blocking on a Mutex or JavaLock - checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
//   2) allocating heap memory - checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
//   3) executing a VM operation - checked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
//   4) executing a system call (including malloc) that could block or grab a lock
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
//   5) invoking GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
//   6) reaching a safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
//   7) running too long
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
// Nor may any method it calls.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
JRT_Leaf_Verifier::JRT_Leaf_Verifier()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  : No_Safepoint_Verifier(true, JRT_Leaf_Verifier::should_verify_GC())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
JRT_Leaf_Verifier::~JRT_Leaf_Verifier()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
bool JRT_Leaf_Verifier::should_verify_GC() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  switch (JavaThread::current()->thread_state()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  case _thread_in_Java:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    // is in a leaf routine, there must be no safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  case _thread_in_native:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    // A native thread is not subject to safepoints.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    // Even while it is in a leaf routine, GC is ok
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    // Leaf routines cannot be called from other contexts.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
#endif