src/share/vm/runtime/safepoint.hpp

Thu, 24 May 2018 20:03:11 +0800

author
aoqi
date
Thu, 24 May 2018 20:03:11 +0800
changeset 8868
91ddc23482a4
parent 6876
710a3c8b516e
child 9852
70aa912cebe5
permissions
-rw-r--r--

Increase MaxHeapSize for better performance on MIPS

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_RUNTIME_SAFEPOINT_HPP
aoqi@0 26 #define SHARE_VM_RUNTIME_SAFEPOINT_HPP
aoqi@0 27
aoqi@0 28 #include "asm/assembler.hpp"
aoqi@0 29 #include "code/nmethod.hpp"
aoqi@0 30 #include "memory/allocation.hpp"
aoqi@0 31 #include "runtime/extendedPC.hpp"
aoqi@0 32 #include "runtime/mutexLocker.hpp"
aoqi@0 33 #include "runtime/os.hpp"
aoqi@0 34 #include "utilities/ostream.hpp"
aoqi@0 35
aoqi@0 36 //
aoqi@0 37 // Safepoint synchronization
aoqi@0 38 ////
aoqi@0 39 // The VMThread or CMS_thread uses the SafepointSynchronize::begin/end
aoqi@0 40 // methods to enter/exit a safepoint region. The begin method will roll
aoqi@0 41 // all JavaThreads forward to a safepoint.
aoqi@0 42 //
aoqi@0 43 // JavaThreads must use the ThreadSafepointState abstraction (defined in
aoqi@0 44 // thread.hpp) to indicate that that they are at a safepoint.
aoqi@0 45 //
aoqi@0 46 // The Mutex/Condition variable and ObjectLocker classes calls the enter/
aoqi@0 47 // exit safepoint methods, when a thread is blocked/restarted. Hence, all mutex exter/
aoqi@0 48 // exit points *must* be at a safepoint.
aoqi@0 49
aoqi@0 50
aoqi@0 51 class ThreadSafepointState;
aoqi@0 52 class SnippetCache;
aoqi@0 53 class nmethod;
aoqi@0 54
aoqi@0 55 //
aoqi@0 56 // Implements roll-forward to safepoint (safepoint synchronization)
aoqi@0 57 //
aoqi@0 58 class SafepointSynchronize : AllStatic {
aoqi@0 59 public:
aoqi@0 60 enum SynchronizeState {
aoqi@0 61 _not_synchronized = 0, // Threads not synchronized at a safepoint
aoqi@0 62 // Keep this value 0. See the coment in do_call_back()
aoqi@0 63 _synchronizing = 1, // Synchronizing in progress
aoqi@0 64 _synchronized = 2 // All Java threads are stopped at a safepoint. Only VM thread is running
aoqi@0 65 };
aoqi@0 66
aoqi@0 67 enum SafepointingThread {
aoqi@0 68 _null_thread = 0,
aoqi@0 69 _vm_thread = 1,
aoqi@0 70 _other_thread = 2
aoqi@0 71 };
aoqi@0 72
aoqi@0 73 enum SafepointTimeoutReason {
aoqi@0 74 _spinning_timeout = 0,
aoqi@0 75 _blocking_timeout = 1
aoqi@0 76 };
aoqi@0 77
aoqi@0 78 typedef struct {
aoqi@0 79 float _time_stamp; // record when the current safepoint occurs in seconds
aoqi@0 80 int _vmop_type; // type of VM operation triggers the safepoint
aoqi@0 81 int _nof_total_threads; // total number of Java threads
aoqi@0 82 int _nof_initial_running_threads; // total number of initially seen running threads
aoqi@0 83 int _nof_threads_wait_to_block; // total number of threads waiting for to block
aoqi@0 84 bool _page_armed; // true if polling page is armed, false otherwise
aoqi@0 85 int _nof_threads_hit_page_trap; // total number of threads hitting the page trap
aoqi@0 86 jlong _time_to_spin; // total time in millis spent in spinning
aoqi@0 87 jlong _time_to_wait_to_block; // total time in millis spent in waiting for to block
aoqi@0 88 jlong _time_to_do_cleanups; // total time in millis spent in performing cleanups
aoqi@0 89 jlong _time_to_sync; // total time in millis spent in getting to _synchronized
aoqi@0 90 jlong _time_to_exec_vmop; // total time in millis spent in vm operation itself
aoqi@0 91 } SafepointStats;
aoqi@0 92
aoqi@0 93 private:
aoqi@0 94 static volatile SynchronizeState _state; // Threads might read this flag directly, without acquireing the Threads_lock
aoqi@0 95 static volatile int _waiting_to_block; // number of threads we are waiting for to block
aoqi@0 96 static int _current_jni_active_count; // Counts the number of active critical natives during the safepoint
aoqi@0 97
aoqi@0 98 // This counter is used for fast versions of jni_Get<Primitive>Field.
aoqi@0 99 // An even value means there is no ongoing safepoint operations.
aoqi@0 100 // The counter is incremented ONLY at the beginning and end of each
aoqi@0 101 // safepoint. The fact that Threads_lock is held throughout each pair of
aoqi@0 102 // increments (at the beginning and end of each safepoint) guarantees
aoqi@0 103 // race freedom.
aoqi@0 104 public:
aoqi@0 105 static volatile int _safepoint_counter;
aoqi@0 106 private:
aoqi@0 107 static long _end_of_last_safepoint; // Time of last safepoint in milliseconds
aoqi@0 108
aoqi@0 109 // statistics
aoqi@0 110 static jlong _safepoint_begin_time; // time when safepoint begins
aoqi@0 111 static SafepointStats* _safepoint_stats; // array of SafepointStats struct
aoqi@0 112 static int _cur_stat_index; // current index to the above array
aoqi@0 113 static julong _safepoint_reasons[]; // safepoint count for each VM op
aoqi@0 114 static julong _coalesced_vmop_count; // coalesced vmop count
aoqi@0 115 static jlong _max_sync_time; // maximum sync time in nanos
aoqi@0 116 static jlong _max_vmop_time; // maximum vm operation time in nanos
aoqi@0 117 static float _ts_of_current_safepoint; // time stamp of current safepoint in seconds
aoqi@0 118
aoqi@0 119 static void begin_statistics(int nof_threads, int nof_running);
aoqi@0 120 static void update_statistics_on_spin_end();
aoqi@0 121 static void update_statistics_on_sync_end(jlong end_time);
aoqi@0 122 static void update_statistics_on_cleanup_end(jlong end_time);
aoqi@0 123 static void end_statistics(jlong end_time);
aoqi@0 124 static void print_statistics();
aoqi@0 125 inline static void inc_page_trap_count() {
aoqi@0 126 Atomic::inc(&_safepoint_stats[_cur_stat_index]._nof_threads_hit_page_trap);
aoqi@0 127 }
aoqi@0 128
aoqi@0 129 // For debug long safepoint
aoqi@0 130 static void print_safepoint_timeout(SafepointTimeoutReason timeout_reason);
aoqi@0 131
aoqi@0 132 public:
aoqi@0 133
aoqi@0 134 // Main entry points
aoqi@0 135
aoqi@0 136 // Roll all threads forward to safepoint. Must be called by the
aoqi@0 137 // VMThread or CMS_thread.
aoqi@0 138 static void begin();
aoqi@0 139 static void end(); // Start all suspended threads again...
aoqi@0 140
aoqi@0 141 static bool safepoint_safe(JavaThread *thread, JavaThreadState state);
aoqi@0 142
aoqi@0 143 static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state);
aoqi@0 144
aoqi@0 145 // Query
aoqi@0 146 inline static bool is_at_safepoint() { return _state == _synchronized; }
aoqi@0 147 inline static bool is_synchronizing() { return _state == _synchronizing; }
aoqi@0 148
aoqi@0 149 inline static bool do_call_back() {
aoqi@0 150 return (_state != _not_synchronized);
aoqi@0 151 }
aoqi@0 152
aoqi@0 153 inline static void increment_jni_active_count() {
aoqi@0 154 assert_locked_or_safepoint(Safepoint_lock);
aoqi@0 155 _current_jni_active_count++;
aoqi@0 156 }
aoqi@0 157
aoqi@0 158 // Called when a thread volantary blocks
aoqi@0 159 static void block(JavaThread *thread);
aoqi@0 160 static void signal_thread_at_safepoint() { _waiting_to_block--; }
aoqi@0 161
aoqi@0 162 // Exception handling for page polling
aoqi@0 163 static void handle_polling_page_exception(JavaThread *thread);
aoqi@0 164
aoqi@0 165 // VM Thread interface for determining safepoint rate
aoqi@0 166 static long last_non_safepoint_interval() {
aoqi@0 167 return os::javaTimeMillis() - _end_of_last_safepoint;
aoqi@0 168 }
aoqi@0 169 static long end_of_last_safepoint() {
aoqi@0 170 return _end_of_last_safepoint;
aoqi@0 171 }
aoqi@0 172 static bool is_cleanup_needed();
aoqi@0 173 static void do_cleanup_tasks();
aoqi@0 174
aoqi@0 175 // debugging
aoqi@0 176 static void print_state() PRODUCT_RETURN;
aoqi@0 177 static void safepoint_msg(const char* format, ...) ATTRIBUTE_PRINTF(1, 2) PRODUCT_RETURN;
aoqi@0 178
aoqi@0 179 static void deferred_initialize_stat();
aoqi@0 180 static void print_stat_on_exit();
aoqi@0 181 inline static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; }
aoqi@0 182
aoqi@0 183 static void set_is_at_safepoint() { _state = _synchronized; }
aoqi@0 184 static void set_is_not_at_safepoint() { _state = _not_synchronized; }
aoqi@0 185
aoqi@0 186 // assembly support
aoqi@0 187 static address address_of_state() { return (address)&_state; }
aoqi@0 188
aoqi@0 189 static address safepoint_counter_addr() { return (address)&_safepoint_counter; }
aoqi@0 190 };
aoqi@0 191
aoqi@0 192 // State class for a thread suspended at a safepoint
aoqi@0 193 class ThreadSafepointState: public CHeapObj<mtInternal> {
aoqi@0 194 public:
aoqi@0 195 // These states are maintained by VM thread while threads are being brought
aoqi@0 196 // to a safepoint. After SafepointSynchronize::end(), they are reset to
aoqi@0 197 // _running.
aoqi@0 198 enum suspend_type {
aoqi@0 199 _running = 0, // Thread state not yet determined (i.e., not at a safepoint yet)
aoqi@0 200 _at_safepoint = 1, // Thread at a safepoint (f.ex., when blocked on a lock)
aoqi@0 201 _call_back = 2 // Keep executing and wait for callback (if thread is in interpreted or vm)
aoqi@0 202 };
aoqi@0 203 private:
aoqi@0 204 volatile bool _at_poll_safepoint; // At polling page safepoint (NOT a poll return safepoint)
aoqi@0 205 // Thread has called back the safepoint code (for debugging)
aoqi@0 206 bool _has_called_back;
aoqi@0 207
aoqi@0 208 JavaThread * _thread;
aoqi@0 209 volatile suspend_type _type;
aoqi@0 210 JavaThreadState _orig_thread_state;
aoqi@0 211
aoqi@0 212
aoqi@0 213 public:
aoqi@0 214 ThreadSafepointState(JavaThread *thread);
aoqi@0 215
aoqi@0 216 // examine/roll-forward/restart
aoqi@0 217 void examine_state_of_thread();
aoqi@0 218 void roll_forward(suspend_type type);
aoqi@0 219 void restart();
aoqi@0 220
aoqi@0 221 // Query
aoqi@0 222 JavaThread* thread() const { return _thread; }
aoqi@0 223 suspend_type type() const { return _type; }
aoqi@0 224 bool is_running() const { return (_type==_running); }
aoqi@0 225 JavaThreadState orig_thread_state() const { return _orig_thread_state; }
aoqi@0 226
aoqi@0 227 // Support for safepoint timeout (debugging)
aoqi@0 228 bool has_called_back() const { return _has_called_back; }
aoqi@0 229 void set_has_called_back(bool val) { _has_called_back = val; }
aoqi@0 230 bool is_at_poll_safepoint() { return _at_poll_safepoint; }
aoqi@0 231 void set_at_poll_safepoint(bool val) { _at_poll_safepoint = val; }
aoqi@0 232
aoqi@0 233 void handle_polling_page_exception();
aoqi@0 234
aoqi@0 235 // debugging
aoqi@0 236 void print_on(outputStream* st) const;
aoqi@0 237 void print() const { print_on(tty); }
aoqi@0 238
aoqi@0 239 // Initialize
aoqi@0 240 static void create(JavaThread *thread);
aoqi@0 241 static void destroy(JavaThread *thread);
aoqi@0 242
aoqi@0 243 void safepoint_msg(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
aoqi@0 244 if (ShowSafepointMsgs) {
aoqi@0 245 va_list ap;
aoqi@0 246 va_start(ap, format);
aoqi@0 247 tty->vprint_cr(format, ap);
aoqi@0 248 va_end(ap);
aoqi@0 249 }
aoqi@0 250 }
aoqi@0 251 };
aoqi@0 252
aoqi@0 253
aoqi@0 254
aoqi@0 255 #endif // SHARE_VM_RUNTIME_SAFEPOINT_HPP

mercurial