hotspot/src/share/vm/memory/gcLocker.hpp
author brutisso
Mon, 16 Apr 2012 08:57:18 +0200
changeset 12379 2cf45b79ce3a
parent 11793 49aa0b2124b6
child 14583 d70ee55535f4
permissions -rw-r--r--
4988100: oop_verify_old_oop appears to be dead Summary: removed oop_verify_old_oop and allow_dirty. Also reviewed by: alexlamsl@gmail.com Reviewed-by: jmasa, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
     2
 * Copyright (c) 1997, 2012, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_MEMORY_GCLOCKER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_MEMORY_GCLOCKER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "gc_interface/collectedHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/genCollectedHeap.hpp"
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
#ifdef TARGET_OS_FAMILY_linux
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
# include "os_linux.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    34
# include "thread_linux.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    35
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    36
#ifdef TARGET_OS_FAMILY_solaris
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    37
# include "os_solaris.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    38
# include "thread_solaris.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    40
#ifdef TARGET_OS_FAMILY_windows
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    41
# include "os_windows.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    42
# include "thread_windows.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    43
#endif
10565
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    44
#ifdef TARGET_OS_FAMILY_bsd
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    45
# include "os_bsd.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    46
# include "thread_bsd.inline.hpp"
dc90c239f4ec 7089790: integrate bsd-port changes
never
parents: 7397
diff changeset
    47
#endif
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    48
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// The direct lock/unlock calls do not force a collection if an unlock
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// decrements the count to zero. Avoid calling these if at all possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
class GC_locker: public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
 private:
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    54
  // 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
    55
  // 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
    56
  // _needs_gc is true.  The current value is computed during
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    57
  // safepointing and decremented during the slow path of GC_locker
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    58
  // unlocking.
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    59
  static volatile jint _jni_lock_count;  // number of jni active instances.
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    60
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  static volatile jint _lock_count;      // number of other active instances
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  static volatile bool _needs_gc;        // heap is filling, we need a GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
                                         // note: bool is typedef'd as jint
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  static volatile bool _doing_gc;        // unlock_critical() is doing a GC
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    66
#ifdef ASSERT
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    67
  // 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
    68
  // validate the jni_lock_count that is computed during safepoints.
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    69
  static volatile jint _debug_jni_lock_count;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    70
#endif
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    71
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Accessors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  static bool is_jni_active() {
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    74
    assert(_needs_gc, "only valid when _needs_gc is set");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    return _jni_lock_count > 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    78
  // 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
    79
  // critical sections.  This is used to ensure that all active
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    80
  // critical sections are exited before a new one is started.
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    81
  static void verify_critical_count() NOT_DEBUG_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    83
  static void jni_lock(JavaThread* thread);
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    84
  static void jni_unlock(JavaThread* thread);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
11793
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    86
  static bool is_active_internal() {
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    87
    verify_critical_count();
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    88
    return _lock_count > 0 || _jni_lock_count > 0;
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    89
  }
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    90
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  // Accessors
11793
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    93
  static bool is_active() {
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    94
    assert(_needs_gc || SafepointSynchronize::is_at_safepoint(), "only read at safepoint");
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    95
    return is_active_internal();
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
    96
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  static bool needs_gc()       { return _needs_gc;                        }
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
    98
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Shorthand
11793
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
   100
  static bool is_active_and_needs_gc() {
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
   101
    // 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
   102
    // 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
   103
    // is_active.
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
   104
    return needs_gc() && is_active_internal();
49aa0b2124b6 7144318: GCLocker assert failure: assert(_needs_gc || SafepointSynchronize::is_at_safepoint(
never
parents: 11788
diff changeset
   105
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   107
  // In debug mode track the locking state at all times
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   108
  static void increment_debug_jni_lock_count() {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   109
#ifdef ASSERT
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   110
    assert(_debug_jni_lock_count >= 0, "bad value");
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   111
    Atomic::inc(&_debug_jni_lock_count);
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   112
#endif
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   113
  }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   114
  static void decrement_debug_jni_lock_count() {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   115
#ifdef ASSERT
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   116
    assert(_debug_jni_lock_count > 0, "bad value");
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   117
    Atomic::dec(&_debug_jni_lock_count);
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   118
#endif
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   119
  }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   120
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   121
  // Set the current lock count
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   122
  static void set_jni_lock_count(int count) {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   123
    _jni_lock_count = count;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   124
    verify_critical_count();
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   125
  }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   126
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   127
  // Sets _needs_gc if is_active() is true. Returns is_active().
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  static bool check_active_before_gc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Stalls the caller (who should not be in a jni critical section)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // until needs_gc() clears. Note however that needs_gc() may be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // set at a subsequent safepoint and/or cleared under the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  // JNICritical_lock, so the caller may not safely assert upon
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  // return from this method that "!needs_gc()" since that is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // not a stable predicate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  static void stall_until_clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  // Non-structured GC locking: currently needed for JNI. Use with care!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static void lock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  static void unlock();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // The following two methods are used for JNI critical regions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  // If we find that we failed to perform a GC because the GC_locker
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  // was active, arrange for one as soon as possible by allowing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // all threads in critical regions to complete, but not allowing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // other critical regions to be entered. The reasons for that are:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  // 1) a GC request won't be starved by overlapping JNI critical
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  //    region activities, which can cause unnecessary OutOfMemory errors.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // 2) even if allocation requests can still be satisfied before GC locker
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  //    becomes inactive, for example, in tenured generation possibly with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  //    heap expansion, those allocations can trigger lots of safepointing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  //    attempts (ineffective GC attempts) and require Heap_lock which
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  //    slow down allocations tremendously.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  // Note that critical regions can be nested in a single thread, so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // we must allow threads already in critical regions to continue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // JNI critical regions are the only participants in this scheme
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // because they are, by spec, well bounded while in a critical region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  //
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   161
  // 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
   162
  // slow path. JNICritical_lock is only grabbed in the slow path.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  // _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
   164
  // through the fast path, which simply increments or decrements the
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   165
  // current thread's critical count.  When GC happens at a safepoint,
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   166
  // GC_locker::is_active() is checked. Since there is no safepoint in
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   167
  // the fast path of lock_critical() and unlock_critical(), there is
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   168
  // 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
   169
  // 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
   170
  // after the safepoint.  Since after a safepoint, each of the
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   171
  // following two methods is either entered from the method entry and
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 10565
diff changeset
   172
  // 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
   173
  // 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
   174
  // is set, the slow path is always taken, till _needs_gc is cleared.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  static void lock_critical(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  static void unlock_critical(JavaThread* thread);
11637
030466036615 7013347: allow crypto functions to be called inline to enhance performance
never
parents: 11631
diff changeset
   177
030466036615 7013347: allow crypto functions to be called inline to enhance performance
never
parents: 11631
diff changeset
   178
  static address needs_gc_address() { return (address) &_needs_gc; }
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
// A No_GC_Verifier object can be placed in methods where one assumes that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
// no garbage collection will occur. The destructor will verify this property
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
// unless the constructor is called with argument false (not verifygc).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
// The check will only be done in debug mode and if verifygc true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
class No_GC_Verifier: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
 friend class Pause_No_GC_Verifier;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  bool _verifygc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  unsigned int _old_invocations;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  No_GC_Verifier(bool verifygc = true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  ~No_GC_Verifier();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  No_GC_Verifier(bool verifygc = true) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  ~No_GC_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
// A Pause_No_GC_Verifier is used to temporarily pause the behavior
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
// of a No_GC_Verifier object. If we are not in debug mode or if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// No_GC_Verifier object has a _verifygc value of false, then there
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
// is nothing to do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
class Pause_No_GC_Verifier: public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  No_GC_Verifier * _ngcv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  Pause_No_GC_Verifier(No_GC_Verifier * ngcv);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  ~Pause_No_GC_Verifier();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  Pause_No_GC_Verifier(No_GC_Verifier * ngcv) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  ~Pause_No_GC_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
// A No_Safepoint_Verifier object will throw an assertion failure if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
// the current thread passes a possible safepoint while this object is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
// instantiated. A safepoint, will either be: an oop allocation, blocking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
// on a Mutex or JavaLock, or executing a VM operation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
// If StrictSafepointChecks is turned off, it degrades into a No_GC_Verifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
class No_Safepoint_Verifier : public No_GC_Verifier {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
 friend class Pause_No_Safepoint_Verifier;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  bool _activated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  Thread *_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
#ifdef ASSERT
345
8a4c345e460c 6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents: 1
diff changeset
   240
  No_Safepoint_Verifier(bool activated = true, bool verifygc = true ) :
8a4c345e460c 6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents: 1
diff changeset
   241
    No_GC_Verifier(verifygc),
8a4c345e460c 6679708: No_Safepoint_Verifier and BacktraceBuilder have uninitialized fields
never
parents: 1
diff changeset
   242
    _activated(activated) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    _thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    if (_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
      _thread->_allow_allocation_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
      _thread->_allow_safepoint_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  ~No_Safepoint_Verifier() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
    if (_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      _thread->_allow_allocation_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      _thread->_allow_safepoint_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  No_Safepoint_Verifier(bool activated = true, bool verifygc = true) : No_GC_Verifier(verifygc){}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  ~No_Safepoint_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
// A Pause_No_Safepoint_Verifier is used to temporarily pause the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
// behavior of a No_Safepoint_Verifier object. If we are not in debug
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
// mode then there is nothing to do. If the No_Safepoint_Verifier
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
// object has an _activated value of false, then there is nothing to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
// do for safepoint and allocation checking, but there may still be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
// something to do for the underlying No_GC_Verifier object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
class Pause_No_Safepoint_Verifier : public Pause_No_GC_Verifier {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  No_Safepoint_Verifier * _nsv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  Pause_No_Safepoint_Verifier(No_Safepoint_Verifier * nsv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    : Pause_No_GC_Verifier(nsv) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    _nsv = nsv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    if (_nsv->_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
      _nsv->_thread->_allow_allocation_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      _nsv->_thread->_allow_safepoint_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  ~Pause_No_Safepoint_Verifier() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    if (_nsv->_activated) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      _nsv->_thread->_allow_allocation_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
      _nsv->_thread->_allow_safepoint_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  Pause_No_Safepoint_Verifier(No_Safepoint_Verifier * nsv)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    : Pause_No_GC_Verifier(nsv) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  ~Pause_No_Safepoint_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
2995
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   298
// 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
   299
// 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
   300
// prevent re-entrant calls to GC.
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   301
class SkipGCALot : public StackObj {
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   302
  private:
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   303
   bool _saved;
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   304
   Thread* _t;
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   305
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   306
  public:
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   307
#ifdef ASSERT
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   308
    SkipGCALot(Thread* t) : _t(t) {
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   309
      _saved = _t->skip_gcalot();
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   310
      _t->set_skip_gcalot(true);
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   311
    }
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   312
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   313
    ~SkipGCALot() {
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   314
      assert(_t->skip_gcalot(), "Save-restore protocol invariant");
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   315
      _t->set_skip_gcalot(_saved);
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   316
    }
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   317
#else
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   318
    SkipGCALot(Thread* t) { }
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   319
    ~SkipGCALot() { }
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   320
#endif
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   321
};
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 670
diff changeset
   322
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
// JRT_LEAF currently can be called from either _thread_in_Java or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
// _thread_in_native mode. In _thread_in_native, it is ok
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
// for another thread to trigger GC. The rest of the JRT_LEAF
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
// rules apply.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
class JRT_Leaf_Verifier : public No_Safepoint_Verifier {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  static bool should_verify_GC();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  JRT_Leaf_Verifier();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  ~JRT_Leaf_Verifier();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  JRT_Leaf_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  ~JRT_Leaf_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
// A No_Alloc_Verifier object can be placed in methods where one assumes that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
// no allocation will occur. The destructor will verify this property
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
// unless the constructor is called with argument false (not activated).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
// The check will only be done in debug mode and if activated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
// Note: this only makes sense at safepoints (otherwise, other threads may
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
// allocate concurrently.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
class No_Alloc_Verifier : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  bool  _activated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  No_Alloc_Verifier(bool activated = true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
    _activated = activated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    if (_activated) Thread::current()->_allow_allocation_count++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  ~No_Alloc_Verifier() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    if (_activated) Thread::current()->_allow_allocation_count--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  No_Alloc_Verifier(bool activated = true) {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  ~No_Alloc_Verifier() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   366
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   367
#endif // SHARE_VM_MEMORY_GCLOCKER_HPP