src/hotspot/share/runtime/safepoint.hpp
author kbarrett
Tue, 02 Jul 2019 18:24:47 -0400
changeset 55569 8e3a0ebf3497
parent 55514 03468b206457
child 57758 91a758925be7
permissions -rw-r--r--
8226366: Excessive ServiceThread wakeups for OopStorage cleanup Summary: Drive wakes via safepoint cleanups with interval minimums. Reviewed-by: coleenp, tschatzl
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"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    29
#include "runtime/os.hpp"
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    30
#include "runtime/thread.hpp"
53895
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
    31
#include "runtime/vmOperations.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    32
#include "utilities/ostream.hpp"
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    33
#include "utilities/waitBarrier.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    34
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Safepoint synchronization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
////
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    38
// The VMThread uses the SafepointSynchronize::begin/end
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// methods to enter/exit a safepoint region. The begin method will roll
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// all JavaThreads forward to a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// JavaThreads must use the ThreadSafepointState abstraction (defined in
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// thread.hpp) to indicate that that they are at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// The Mutex/Condition variable and ObjectLocker classes calls the enter/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// exit safepoint methods, when a thread is blocked/restarted. Hence, all mutex exter/
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// exit points *must* be at a safepoint.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
class ThreadSafepointState;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
55514
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
    51
class SafepointStateTracker {
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
    52
  uint64_t _safepoint_id;
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
    53
  bool     _at_safepoint;
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
    54
public:
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
    55
  SafepointStateTracker(uint64_t safepoint_id, bool at_safepoint);
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
    56
  bool safepoint_state_changed();
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
    57
};
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
    58
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// Implements roll-forward to safepoint (safepoint synchronization)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
class SafepointSynchronize : AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  enum SynchronizeState {
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    65
      _not_synchronized = 0,                   // Threads not synchronized at a safepoint. Keep this value 0.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      _synchronizing    = 1,                   // Synchronizing in progress
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    67
      _synchronized     = 2                    // All Java threads are running in native, blocked in OS or stopped at safepoint.
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    68
                                               // VM thread and any NonJavaThread may be running.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    71
  // The enums are listed in the order of the tasks when done serially.
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    72
  enum SafepointCleanupTasks {
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    73
    SAFEPOINT_CLEANUP_DEFLATE_MONITORS,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    74
    SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    75
    SAFEPOINT_CLEANUP_COMPILATION_POLICY,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    76
    SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    77
    SAFEPOINT_CLEANUP_STRING_TABLE_REHASH,
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    78
    SAFEPOINT_CLEANUP_CLD_PURGE,
47774
69c081ca110a 8184765: Dynamically resize SystemDictionary
gziemski
parents: 47216
diff changeset
    79
    SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE,
55569
8e3a0ebf3497 8226366: Excessive ServiceThread wakeups for OopStorage cleanup
kbarrett
parents: 55514
diff changeset
    80
    SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP,
46702
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    81
    // Leave this one last.
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    82
    SAFEPOINT_CLEANUP_NUM_TASKS
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    83
  };
13ae789b982e 8180932: Parallelize safepoint cleanup
rkennke
parents: 37176
diff changeset
    84
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
 private:
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    86
  friend class SafepointMechanism;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    87
  friend class ThreadSafepointState;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    88
  friend class HandshakeState;
55514
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
    89
  friend class SafepointStateTracker;
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    90
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    91
  // Threads might read this flag directly, without acquiring the Threads_lock:
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    92
  static volatile SynchronizeState _state;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    93
  // Number of threads we are waiting for to block:
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    94
  static int              _waiting_to_block;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    95
  // Counts the number of active critical natives during the safepoint:
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    96
  static int              _current_jni_active_count;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // This counter is used for fast versions of jni_Get<Primitive>Field.
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
    99
  // An even value means there are no ongoing safepoint operations.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  // The counter is incremented ONLY at the beginning and end of each
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   101
  // safepoint.
52672
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   102
  static volatile uint64_t _safepoint_counter;
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   103
55514
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   104
  // A change in this counter or a change in the result of
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   105
  // is_at_safepoint() are used by SafepointStateTracker::
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   106
  // safepoint_state_changed() to determine its answer.
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   107
  static uint64_t _safepoint_id;
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   108
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   109
  // JavaThreads that need to block for the safepoint will stop on the
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   110
  // _wait_barrier, where they can quickly be started again.
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   111
  static WaitBarrier* _wait_barrier;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   112
  static long         _end_of_last_safepoint;     // Time of last safepoint in milliseconds
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   113
  static julong       _coalesced_vmop_count;     // coalesced vmop count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13195
diff changeset
   115
  // Statistics
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  static void begin_statistics(int nof_threads, int nof_running);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  static void update_statistics_on_spin_end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  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
   119
  static void update_statistics_on_cleanup_end(jlong end_time);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  static void end_statistics(jlong end_time);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  static void print_statistics();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // For debug long safepoint
53895
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   124
  static void print_safepoint_timeout();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   126
  // Helper methods for safepoint procedure:
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   127
  static void arm_safepoint();
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   128
  static int synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running);
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   129
  static void disarm_safepoint();
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   130
  static void increment_jni_active_count();
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   131
  static void decrement_waiting_to_block();
55514
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   132
  static bool thread_not_running(ThreadSafepointState *cur_state);
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   133
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   134
  // Used in safepoint_safe to do a stable load of the thread state.
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   135
  static bool try_stable_load_state(JavaThreadState *state,
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   136
                                    JavaThread *thread,
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   137
                                    uint64_t safepoint_count);
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   138
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   139
  // Called when a thread voluntarily blocks
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   140
  static void block(JavaThread *thread);
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   141
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   142
  // Called from VMThread during handshakes.
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   143
  // If true the VMThread may safely process the handshake operation for the JavaThread.
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   144
  static bool handshake_safe(JavaThread *thread);
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   145
55514
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   146
  static uint64_t safepoint_counter()             { return _safepoint_counter; }
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   147
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   150
  static void init(Thread* vmthread);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   152
  // Roll all threads forward to safepoint. Must be called by the VMThread.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static void begin();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  static void end();                    // Start all suspended threads again...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   156
  // The value for a not set safepoint id.
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   157
  static const uint64_t InactiveSafepointCounter;
11637
030466036615 7013347: allow crypto functions to be called inline to enhance performance
never
parents: 11631
diff changeset
   158
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Query
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   160
  static bool is_at_safepoint()                   { return _state == _synchronized; }
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   161
  static bool is_synchronizing()                  { return _state == _synchronizing; }
55514
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   162
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   163
  static uint64_t safepoint_id() {
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   164
    return _safepoint_id;
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   165
  }
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   166
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   167
  static SafepointStateTracker safepoint_state_tracker() {
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   168
    return SafepointStateTracker(safepoint_id(), is_at_safepoint());
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   169
  }
03468b206457 8225702: Safepoint counter can't be used for safepoint detection
rehn
parents: 54807
diff changeset
   170
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // Exception handling for page polling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  static void handle_polling_page_exception(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  static bool is_cleanup_needed();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  static void do_cleanup_tasks();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   177
  static void set_is_at_safepoint()             { _state = _synchronized; }
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   178
  static void set_is_not_at_safepoint()         { _state = _not_synchronized; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13195
diff changeset
   180
  // Assembly support
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   181
  static address address_of_state()             { return (address)&_state; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
52672
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   183
  // Only used for making sure that no safepoint has happened in
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   184
  // JNI_FastGetField. Therefore only the low 32-bits are needed
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   185
  // even if this is a 64-bit counter.
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   186
  static address safepoint_counter_addr() {
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   187
#ifdef VM_LITTLE_ENDIAN
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   188
    return (address)&_safepoint_counter;
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   189
#else /* BIG */
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   190
    // Return pointer to the 32 LSB:
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   191
    return (address) (((uint32_t*)(&_safepoint_counter)) + 1);
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   192
#endif
bbfa1b3aaf7e 8212108: SafepointSynchronizer never ending counter (big enough)
rehn
parents: 52518
diff changeset
   193
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
49333
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   196
// 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
   197
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   198
#define assert_at_safepoint()                                           \
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   199
  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
   200
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   201
#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
   202
  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
   203
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   204
#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
   205
  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
   206
489f1dd40582 8196876: OopStorage::assert_at_safepoint clashes with assert_at_safepoint macros in g1CollectedHeap.hpp
kbarrett
parents: 49169
diff changeset
   207
#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
   208
  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
   209
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
// State class for a thread suspended at a safepoint
53847
74b616640b00 8219244: NMT: Change ThreadSafepointState's allocation type from mtInternal to mtThread
zgu
parents: 53775
diff changeset
   211
class ThreadSafepointState: public CHeapObj<mtThread> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
 private:
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   213
  // At polling page safepoint (NOT a poll return safepoint):
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   214
  volatile bool                   _at_poll_safepoint;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   215
  JavaThread*                     _thread;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   216
  bool                            _safepoint_safe;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   217
  volatile uint64_t               _safepoint_id;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   218
  JavaThreadState                 _orig_thread_state;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   220
  ThreadSafepointState*           _next;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   222
  void account_safe_thread();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  ThreadSafepointState(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   227
  // Linked list support:
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   228
  ThreadSafepointState* get_next() const { return _next; }
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   229
  void set_next(ThreadSafepointState* value) { _next = value; }
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   230
  ThreadSafepointState** next_ptr() { return &_next; }
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   231
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   232
  // examine/restart
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   233
  void examine_state_of_thread(uint64_t safepoint_count);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  void restart();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  // Query
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  JavaThread*  thread() const         { return _thread; }
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   238
  bool         is_running() const     { return !_safepoint_safe; }
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   239
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   240
  uint64_t get_safepoint_id() const;
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   241
  void     reset_safepoint_id();
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   242
  void     set_safepoint_id(uint64_t sid);
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   243
6269
10e06287c0b0 6975006: assert(check.is_deoptimized_frame()) failed: missed deopt
never
parents: 5547
diff changeset
   244
  JavaThreadState orig_thread_state() const { return _orig_thread_state; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  // Support for safepoint timeout (debugging)
53775
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   247
  bool is_at_poll_safepoint()           { return _at_poll_safepoint; }
5d20b085d893 8203469: Faster safepoints
rehn
parents: 53646
diff changeset
   248
  void set_at_poll_safepoint(bool val)  { _at_poll_safepoint = val; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  void handle_polling_page_exception();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  void print_on(outputStream* st) const;
54807
33fe50b6d707 8223626: move print() functions to cpp files
coleenp
parents: 54009
diff changeset
   254
  void print() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // Initialize
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  static void create(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  static void destroy(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
53895
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   261
class SafepointTracing : public AllStatic {
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   262
private:
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   263
  // Absolute
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   264
  static jlong _last_safepoint_begin_time_ns;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   265
  static jlong _last_safepoint_sync_time_ns;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   266
  static jlong _last_safepoint_cleanup_time_ns;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   267
  static jlong _last_safepoint_end_time_ns;
54009
13acb4339895 8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents: 53895
diff changeset
   268
  // amount of ms since epoch
13acb4339895 8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents: 53895
diff changeset
   269
  static jlong _last_safepoint_end_time_epoch_ms;
53895
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   270
  // Relative
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   271
  static jlong _last_app_time_ns;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 6269
diff changeset
   272
53895
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   273
  static int _nof_threads;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   274
  static int _nof_running;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   275
  static int _page_trap;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   276
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   277
  static VM_Operation::VMOp_Type _current_type;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   278
  static jlong     _max_sync_time;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   279
  static jlong     _max_vmop_time;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   280
  static uint64_t  _op_count[VM_Operation::VMOp_Terminating];
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   281
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   282
  static void statistics_log();
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   283
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   284
public:
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   285
  static void init();
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   286
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   287
  static void begin(VM_Operation::VMOp_Type type);
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   288
  static void synchronized(int nof_threads, int nof_running, int traps);
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   289
  static void cleanup();
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   290
  static void end();
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   291
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   292
  static void statistics_exit_log();
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   293
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   294
  static jlong time_since_last_safepoint_ms() {
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   295
    return (os::javaTimeNanos() - _last_safepoint_end_time_ns) / (NANOUNITS / MILLIUNITS);
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   296
  }
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   297
54009
13acb4339895 8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents: 53895
diff changeset
   298
  static jlong end_of_last_safepoint_epoch_ms() {
13acb4339895 8220151: SafepointTracing::end_of_last_safepoint_ms should return ms since epoch.
rehn
parents: 53895
diff changeset
   299
    return _last_safepoint_end_time_epoch_ms;
53895
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   300
  }
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   301
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   302
  static jlong start_of_safepoint() {
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   303
    return _last_safepoint_begin_time_ns;
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   304
  }
b22d8ae270a2 8219436: Safepoint logs correction and misc
rehn
parents: 53847
diff changeset
   305
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
   306
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52673
diff changeset
   307
#endif // SHARE_RUNTIME_SAFEPOINT_HPP