src/hotspot/share/runtime/safepoint.hpp
author coleenp
Thu, 10 Jan 2019 15:13:51 -0500
changeset 53244 9807daeb47c4
parent 52673 61b3b58a1d1d
child 53646 043ae846819f
permissions -rw-r--r--
8216167: Update include guards to reflect correct directories Summary: Use script and some manual fixup to fix directores names in include guards. Reviewed-by: lfoltan, eosterlund, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52673
diff changeset
     2
 * Copyright (c) 1997, 2019, 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: 5042
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5042
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: 5042
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52673
diff changeset
    25
#ifndef SHARE_RUNTIME_SAFEPOINT_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52673
diff changeset
    26
#define SHARE_RUNTIME_SAFEPOINT_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    28
#include "memory/allocation.hpp"
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    29
#include "runtime/mutexLocker.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    30
#include "runtime/os.hpp"
52673
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 52672
diff changeset
    31
#include "utilities/globalDefinitions.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    32
#include "utilities/ostream.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Safepoint synchronization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// The VMThread or CMS_thread uses the SafepointSynchronize::begin/end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// methods to enter/exit a safepoint region. The begin method will roll
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// all JavaThreads forward to a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// JavaThreads must use the ThreadSafepointState abstraction (defined in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// thread.hpp) to indicate that that they are at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// The Mutex/Condition variable and ObjectLocker classes calls the enter/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// exit safepoint methods, when a thread is blocked/restarted. Hence, all mutex exter/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// exit points *must* be at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
class ThreadSafepointState;
52673
61b3b58a1d1d 8214181: safepoint header cleanup
rehn
parents: 52672
diff changeset
    50
class JavaThread;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// Implements roll-forward to safepoint (safepoint synchronization)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
class SafepointSynchronize : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  enum SynchronizeState {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      _not_synchronized = 0,                   // Threads not synchronized at a safepoint
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13195
diff changeset
    59
                                               // Keep this value 0. See the comment in do_call_back()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      _synchronizing    = 1,                   // Synchronizing in progress
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      _synchronized     = 2                    // All Java threads are stopped at a safepoint. Only VM thread is running
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  enum SafepointingThread {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      _null_thread  = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      _vm_thread    = 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      _other_thread = 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  enum SafepointTimeoutReason {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    _spinning_timeout = 0,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _blocking_timeout = 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    75
  // The enums are listed in the order of the tasks when done serially.
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    76
  enum SafepointCleanupTasks {
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    77
    SAFEPOINT_CLEANUP_DEFLATE_MONITORS,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    78
    SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    79
    SAFEPOINT_CLEANUP_COMPILATION_POLICY,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    80
    SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    81
    SAFEPOINT_CLEANUP_STRING_TABLE_REHASH,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    82
    SAFEPOINT_CLEANUP_CLD_PURGE,
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47216
diff changeset
    83
    SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE,
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    84
    // Leave this one last.
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    85
    SAFEPOINT_CLEANUP_NUM_TASKS
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    86
  };
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    87
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
 private:
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13195
diff changeset
    89
  static volatile SynchronizeState _state;     // Threads might read this flag directly, without acquiring the Threads_lock
5042
f86707fd195a 6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents: 1
diff changeset
    90
  static volatile int _waiting_to_block;       // number of threads we are waiting for to block
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
    91
  static int _current_jni_active_count;        // Counts the number of active critical natives during the safepoint
49169
af8578e25d17 8194085: Obsolete the deprecated SafepointSynchronize flags and remove related code
hseigel
parents: 49061
diff changeset
    92
  static int _defer_thr_suspend_loop_count;    // Iterations before blocking VM threads
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // This counter is used for fast versions of jni_Get<Primitive>Field.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // An even value means there is no ongoing safepoint operations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // The counter is incremented ONLY at the beginning and end of each
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // safepoint. The fact that Threads_lock is held throughout each pair of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // increments (at the beginning and end of each safepoint) guarantees
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // race freedom.
52672
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   100
  static volatile uint64_t _safepoint_counter;
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   101
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
private:
52672
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   103
  static long              _end_of_last_safepoint;     // Time of last safepoint in milliseconds
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   104
  static julong            _coalesced_vmop_count;     // coalesced vmop count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13195
diff changeset
   106
  // Statistics
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  static void begin_statistics(int nof_threads, int nof_running);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  static void update_statistics_on_spin_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  static void update_statistics_on_sync_end(jlong end_time);
5042
f86707fd195a 6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents: 1
diff changeset
   110
  static void update_statistics_on_cleanup_end(jlong end_time);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  static void end_statistics(jlong end_time);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  static void print_statistics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // For debug long safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  static void print_safepoint_timeout(SafepointTimeoutReason timeout_reason);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  // Main entry points
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // Roll all threads forward to safepoint. Must be called by the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // VMThread or CMS_thread.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  static void begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  static void end();                    // Start all suspended threads again...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  static bool safepoint_safe(JavaThread *thread, JavaThreadState state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
11637
030466036615 7013347: allow crypto functions to be called inline to enhance performance
never
parents: 11631
diff changeset
   128
  static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state);
030466036615 7013347: allow crypto functions to be called inline to enhance performance
never
parents: 11631
diff changeset
   129
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Query
52672
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   131
  inline static bool is_at_safepoint()       { return _state == _synchronized; }
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   132
  inline static bool is_synchronizing()      { return _state == _synchronizing; }
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   133
  inline static uint64_t safepoint_counter() { return _safepoint_counter; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
11631
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   135
  inline static void increment_jni_active_count() {
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   136
    assert_locked_or_safepoint(Safepoint_lock);
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   137
    _current_jni_active_count++;
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   138
  }
33813f69207b 7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
never
parents: 7397
diff changeset
   139
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47774
diff changeset
   140
private:
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47774
diff changeset
   141
  inline static bool do_call_back() {
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47774
diff changeset
   142
    return (_state != _not_synchronized);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47774
diff changeset
   143
  }
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47774
diff changeset
   144
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13195
diff changeset
   145
  // Called when a thread voluntarily blocks
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static void   block(JavaThread *thread);
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47774
diff changeset
   147
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47774
diff changeset
   148
  friend class SafepointMechanism;
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47774
diff changeset
   149
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47774
diff changeset
   150
public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  static void   signal_thread_at_safepoint()              { _waiting_to_block--; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // Exception handling for page polling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  static void handle_polling_page_exception(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // VM Thread interface for determining safepoint rate
5042
f86707fd195a 6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents: 1
diff changeset
   157
  static long last_non_safepoint_interval() {
f86707fd195a 6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents: 1
diff changeset
   158
    return os::javaTimeMillis() - _end_of_last_safepoint;
f86707fd195a 6933402: RFE: Improve PrintSafepointStatistics output to track cleanup time
xlu
parents: 1
diff changeset
   159
  }
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6269
diff changeset
   160
  static long end_of_last_safepoint() {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6269
diff changeset
   161
    return _end_of_last_safepoint;
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6269
diff changeset
   162
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  static bool is_cleanup_needed();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  static void do_cleanup_tasks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  static void print_stat_on_exit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  inline static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  static void set_is_at_safepoint()                        { _state = _synchronized; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  static void set_is_not_at_safepoint()                    { _state = _not_synchronized; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13195
diff changeset
   172
  // Assembly support
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  static address address_of_state()                        { return (address)&_state; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
52672
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   175
  // Only used for making sure that no safepoint has happened in
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   176
  // JNI_FastGetField. Therefore only the low 32-bits are needed
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   177
  // even if this is a 64-bit counter.
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   178
  static address safepoint_counter_addr() {
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   179
#ifdef VM_LITTLE_ENDIAN
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   180
    return (address)&_safepoint_counter;
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   181
#else /* BIG */
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   182
    // Return pointer to the 32 LSB:
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   183
    return (address) (((uint32_t*)(&_safepoint_counter)) + 1);
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   184
#endif
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   185
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
49333
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   188
// Some helper assert macros for safepoint checks.
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   189
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   190
#define assert_at_safepoint()                                           \
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   191
  assert(SafepointSynchronize::is_at_safepoint(), "should be at a safepoint")
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   192
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   193
#define assert_at_safepoint_msg(...)                                    \
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   194
  assert(SafepointSynchronize::is_at_safepoint(), __VA_ARGS__)
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   195
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   196
#define assert_not_at_safepoint()                                       \
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   197
  assert(!SafepointSynchronize::is_at_safepoint(), "should not be at a safepoint")
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   198
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   199
#define assert_not_at_safepoint_msg(...)                                \
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   200
  assert(!SafepointSynchronize::is_at_safepoint(), __VA_ARGS__)
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   201
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
// State class for a thread suspended at a safepoint
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11637
diff changeset
   203
class ThreadSafepointState: public CHeapObj<mtInternal> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  // These states are maintained by VM thread while threads are being brought
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  // to a safepoint.  After SafepointSynchronize::end(), they are reset to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // _running.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  enum suspend_type {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    _running                =  0, // Thread state not yet determined (i.e., not at a safepoint yet)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    _at_safepoint           =  1, // Thread at a safepoint (f.ex., when blocked on a lock)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    _call_back              =  2  // Keep executing and wait for callback (if thread is in interpreted or vm)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  volatile bool _at_poll_safepoint;  // At polling page safepoint (NOT a poll return safepoint)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  // Thread has called back the safepoint code (for debugging)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  bool                           _has_called_back;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  JavaThread *                   _thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  volatile suspend_type          _type;
6269
10e06287c0b0 6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents: 5547
diff changeset
   220
  JavaThreadState                _orig_thread_state;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  ThreadSafepointState(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // examine/roll-forward/restart
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  void examine_state_of_thread();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  void roll_forward(suspend_type type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  void restart();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // Query
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  JavaThread*  thread() const         { return _thread; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  suspend_type type() const           { return _type; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  bool         is_running() const     { return (_type==_running); }
6269
10e06287c0b0 6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents: 5547
diff changeset
   235
  JavaThreadState orig_thread_state() const { return _orig_thread_state; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // Support for safepoint timeout (debugging)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  bool has_called_back() const                   { return _has_called_back; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  void set_has_called_back(bool val)             { _has_called_back = val; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  bool              is_at_poll_safepoint() { return _at_poll_safepoint; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  void              set_at_poll_safepoint(bool val) { _at_poll_safepoint = val; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  void handle_polling_page_exception();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  void print_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  void print() const                        { print_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  // Initialize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  static void create(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  static void destroy(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6269
diff changeset
   254
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   255
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52673
diff changeset
   256
#endif // SHARE_RUNTIME_SAFEPOINT_HPP