| File: | jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp |
| Warning: | line 235, column 42 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | ||||
| 2 | * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. | ||||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||||
| 4 | * | ||||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||||
| 7 | * published by the Free Software Foundation. | ||||
| 8 | * | ||||
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||||
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||
| 12 | * version 2 for more details (a copy is included in the LICENSE file that | ||||
| 13 | * accompanied this code). | ||||
| 14 | * | ||||
| 15 | * You should have received a copy of the GNU General Public License version | ||||
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, | ||||
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
| 18 | * | ||||
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||||
| 20 | * or visit www.oracle.com if you need additional information or have any | ||||
| 21 | * questions. | ||||
| 22 | * | ||||
| 23 | */ | ||||
| 24 | |||||
| 25 | #include "precompiled.hpp" | ||||
| 26 | #include "classfile/classLoaderDataGraph.hpp" | ||||
| 27 | #include "classfile/dictionary.hpp" | ||||
| 28 | #include "classfile/stringTable.hpp" | ||||
| 29 | #include "classfile/symbolTable.hpp" | ||||
| 30 | #include "code/codeCache.hpp" | ||||
| 31 | #include "code/icBuffer.hpp" | ||||
| 32 | #include "code/nmethod.hpp" | ||||
| 33 | #include "code/pcDesc.hpp" | ||||
| 34 | #include "code/scopeDesc.hpp" | ||||
| 35 | #include "compiler/compilationPolicy.hpp" | ||||
| 36 | #include "gc/shared/collectedHeap.hpp" | ||||
| 37 | #include "gc/shared/gcLocker.hpp" | ||||
| 38 | #include "gc/shared/oopStorage.hpp" | ||||
| 39 | #include "gc/shared/strongRootsScope.hpp" | ||||
| 40 | #include "gc/shared/workerThread.hpp" | ||||
| 41 | #include "gc/shared/workerUtils.hpp" | ||||
| 42 | #include "interpreter/interpreter.hpp" | ||||
| 43 | #include "jfr/jfrEvents.hpp" | ||||
| 44 | #include "logging/log.hpp" | ||||
| 45 | #include "logging/logStream.hpp" | ||||
| 46 | #include "memory/resourceArea.hpp" | ||||
| 47 | #include "memory/universe.hpp" | ||||
| 48 | #include "oops/oop.inline.hpp" | ||||
| 49 | #include "oops/symbol.hpp" | ||||
| 50 | #include "runtime/atomic.hpp" | ||||
| 51 | #include "runtime/deoptimization.hpp" | ||||
| 52 | #include "runtime/frame.inline.hpp" | ||||
| 53 | #include "runtime/handles.inline.hpp" | ||||
| 54 | #include "runtime/interfaceSupport.inline.hpp" | ||||
| 55 | #include "runtime/mutexLocker.hpp" | ||||
| 56 | #include "runtime/orderAccess.hpp" | ||||
| 57 | #include "runtime/osThread.hpp" | ||||
| 58 | #include "runtime/safepoint.hpp" | ||||
| 59 | #include "runtime/safepointMechanism.inline.hpp" | ||||
| 60 | #include "runtime/signature.hpp" | ||||
| 61 | #include "runtime/stackWatermarkSet.inline.hpp" | ||||
| 62 | #include "runtime/stubCodeGenerator.hpp" | ||||
| 63 | #include "runtime/stubRoutines.hpp" | ||||
| 64 | #include "runtime/sweeper.hpp" | ||||
| 65 | #include "runtime/synchronizer.hpp" | ||||
| 66 | #include "runtime/thread.inline.hpp" | ||||
| 67 | #include "runtime/threadSMR.hpp" | ||||
| 68 | #include "runtime/threadWXSetters.inline.hpp" | ||||
| 69 | #include "runtime/timerTrace.hpp" | ||||
| 70 | #include "services/runtimeService.hpp" | ||||
| 71 | #include "utilities/events.hpp" | ||||
| 72 | #include "utilities/macros.hpp" | ||||
| 73 | |||||
| 74 | static void post_safepoint_begin_event(EventSafepointBegin& event, | ||||
| 75 | uint64_t safepoint_id, | ||||
| 76 | int thread_count, | ||||
| 77 | int critical_thread_count) { | ||||
| 78 | if (event.should_commit()) { | ||||
| 79 | event.set_safepointId(safepoint_id); | ||||
| 80 | event.set_totalThreadCount(thread_count); | ||||
| 81 | event.set_jniCriticalThreadCount(critical_thread_count); | ||||
| 82 | event.commit(); | ||||
| 83 | } | ||||
| 84 | } | ||||
| 85 | |||||
| 86 | static void post_safepoint_cleanup_event(EventSafepointCleanup& event, uint64_t safepoint_id) { | ||||
| 87 | if (event.should_commit()) { | ||||
| 88 | event.set_safepointId(safepoint_id); | ||||
| 89 | event.commit(); | ||||
| 90 | } | ||||
| 91 | } | ||||
| 92 | |||||
| 93 | static void post_safepoint_synchronize_event(EventSafepointStateSynchronization& event, | ||||
| 94 | uint64_t safepoint_id, | ||||
| 95 | int initial_number_of_threads, | ||||
| 96 | int threads_waiting_to_block, | ||||
| 97 | uint64_t iterations) { | ||||
| 98 | if (event.should_commit()) { | ||||
| 99 | event.set_safepointId(safepoint_id); | ||||
| 100 | event.set_initialThreadCount(initial_number_of_threads); | ||||
| 101 | event.set_runningThreadCount(threads_waiting_to_block); | ||||
| 102 | event.set_iterations(iterations); | ||||
| 103 | event.commit(); | ||||
| 104 | } | ||||
| 105 | } | ||||
| 106 | |||||
| 107 | static void post_safepoint_cleanup_task_event(EventSafepointCleanupTask& event, | ||||
| 108 | uint64_t safepoint_id, | ||||
| 109 | const char* name) { | ||||
| 110 | if (event.should_commit()) { | ||||
| 111 | event.set_safepointId(safepoint_id); | ||||
| 112 | event.set_name(name); | ||||
| 113 | event.commit(); | ||||
| 114 | } | ||||
| 115 | } | ||||
| 116 | |||||
| 117 | static void post_safepoint_end_event(EventSafepointEnd& event, uint64_t safepoint_id) { | ||||
| 118 | if (event.should_commit()) { | ||||
| 119 | event.set_safepointId(safepoint_id); | ||||
| 120 | event.commit(); | ||||
| 121 | } | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | // SafepointCheck | ||||
| 125 | SafepointStateTracker::SafepointStateTracker(uint64_t safepoint_id, bool at_safepoint) | ||||
| 126 | : _safepoint_id(safepoint_id), _at_safepoint(at_safepoint) {} | ||||
| 127 | |||||
| 128 | bool SafepointStateTracker::safepoint_state_changed() { | ||||
| 129 | return _safepoint_id != SafepointSynchronize::safepoint_id() || | ||||
| 130 | _at_safepoint != SafepointSynchronize::is_at_safepoint(); | ||||
| 131 | } | ||||
| 132 | |||||
| 133 | // -------------------------------------------------------------------------------------------------- | ||||
| 134 | // Implementation of Safepoint begin/end | ||||
| 135 | |||||
| 136 | SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized; | ||||
| 137 | int SafepointSynchronize::_waiting_to_block = 0; | ||||
| 138 | volatile uint64_t SafepointSynchronize::_safepoint_counter = 0; | ||||
| 139 | uint64_t SafepointSynchronize::_safepoint_id = 0; | ||||
| 140 | const uint64_t SafepointSynchronize::InactiveSafepointCounter = 0; | ||||
| 141 | int SafepointSynchronize::_current_jni_active_count = 0; | ||||
| 142 | |||||
| 143 | WaitBarrier* SafepointSynchronize::_wait_barrier; | ||||
| 144 | |||||
| 145 | static bool timeout_error_printed = false; | ||||
| 146 | |||||
| 147 | // Statistic related | ||||
| 148 | static jlong _safepoint_begin_time = 0; | ||||
| 149 | static volatile int _nof_threads_hit_polling_page = 0; | ||||
| 150 | |||||
| 151 | void SafepointSynchronize::init(Thread* vmthread) { | ||||
| 152 | // WaitBarrier should never be destroyed since we will have | ||||
| 153 | // threads waiting on it while exiting. | ||||
| 154 | _wait_barrier = new WaitBarrier(vmthread); | ||||
| 155 | SafepointTracing::init(); | ||||
| 156 | } | ||||
| 157 | |||||
| 158 | void SafepointSynchronize::increment_jni_active_count() { | ||||
| 159 | assert(Thread::current()->is_VM_thread(), "Only VM thread may increment")do { if (!(Thread::current()->is_VM_thread())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 159, "assert(" "Thread::current()->is_VM_thread()" ") failed" , "Only VM thread may increment"); ::breakpoint(); } } while ( 0); | ||||
| 160 | ++_current_jni_active_count; | ||||
| 161 | } | ||||
| 162 | |||||
| 163 | void SafepointSynchronize::decrement_waiting_to_block() { | ||||
| 164 | assert(_waiting_to_block > 0, "sanity check")do { if (!(_waiting_to_block > 0)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 164, "assert(" "_waiting_to_block > 0" ") failed", "sanity check" ); ::breakpoint(); } } while (0); | ||||
| 165 | assert(Thread::current()->is_VM_thread(), "Only VM thread may decrement")do { if (!(Thread::current()->is_VM_thread())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 165, "assert(" "Thread::current()->is_VM_thread()" ") failed" , "Only VM thread may decrement"); ::breakpoint(); } } while ( 0); | ||||
| 166 | --_waiting_to_block; | ||||
| 167 | } | ||||
| 168 | |||||
| 169 | bool SafepointSynchronize::thread_not_running(ThreadSafepointState *cur_state) { | ||||
| 170 | if (!cur_state->is_running()) { | ||||
| 171 | // Robustness: asserted in the caller, but handle/tolerate it for release bits. | ||||
| 172 | LogTarget(Error, safepoint)LogTargetImpl<LogLevel::Error, (LogTag::_safepoint), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG)> lt; | ||||
| 173 | if (lt.is_enabled()) { | ||||
| 174 | ResourceMark rm; | ||||
| 175 | LogStream ls(lt); | ||||
| 176 | ls.print("Illegal initial state detected: "); | ||||
| 177 | cur_state->print_on(&ls); | ||||
| 178 | } | ||||
| 179 | return true; | ||||
| 180 | } | ||||
| 181 | cur_state->examine_state_of_thread(SafepointSynchronize::safepoint_counter()); | ||||
| 182 | if (!cur_state->is_running()) { | ||||
| 183 | return true; | ||||
| 184 | } | ||||
| 185 | LogTarget(Trace, safepoint)LogTargetImpl<LogLevel::Trace, (LogTag::_safepoint), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG)> lt; | ||||
| 186 | if (lt.is_enabled()) { | ||||
| 187 | ResourceMark rm; | ||||
| 188 | LogStream ls(lt); | ||||
| 189 | cur_state->print_on(&ls); | ||||
| 190 | } | ||||
| 191 | return false; | ||||
| 192 | } | ||||
| 193 | |||||
| 194 | #ifdef ASSERT1 | ||||
| 195 | static void assert_list_is_valid(const ThreadSafepointState* tss_head, int still_running) { | ||||
| 196 | int a = 0; | ||||
| 197 | const ThreadSafepointState *tmp_tss = tss_head; | ||||
| 198 | while (tmp_tss != NULL__null) { | ||||
| 199 | ++a; | ||||
| 200 | assert(tmp_tss->is_running(), "Illegal initial state")do { if (!(tmp_tss->is_running())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 200, "assert(" "tmp_tss->is_running()" ") failed", "Illegal initial state" ); ::breakpoint(); } } while (0); | ||||
| 201 | tmp_tss = tmp_tss->get_next(); | ||||
| 202 | } | ||||
| 203 | assert(a == still_running, "Must be the same")do { if (!(a == still_running)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 203, "assert(" "a == still_running" ") failed", "Must be the same" ); ::breakpoint(); } } while (0); | ||||
| 204 | } | ||||
| 205 | #endif // ASSERT | ||||
| 206 | |||||
| 207 | static void back_off(int64_t start_time) { | ||||
| 208 | // We start with fine-grained nanosleeping until a millisecond has | ||||
| 209 | // passed, at which point we resort to plain naked_short_sleep. | ||||
| 210 | if (os::javaTimeNanos() - start_time < NANOSECS_PER_MILLISEC) { | ||||
| 211 | os::naked_short_nanosleep(10 * (NANOUNITS / MICROUNITS)); | ||||
| 212 | } else { | ||||
| 213 | os::naked_short_sleep(1); | ||||
| 214 | } | ||||
| 215 | } | ||||
| 216 | |||||
| 217 | int SafepointSynchronize::synchronize_threads(jlong safepoint_limit_time, int nof_threads, int* initial_running) | ||||
| 218 | { | ||||
| 219 | JavaThreadIteratorWithHandle jtiwh; | ||||
| 220 | |||||
| 221 | #ifdef ASSERT1 | ||||
| 222 | for (; JavaThread *cur = jtiwh.next(); ) { | ||||
| 223 | assert(cur->safepoint_state()->is_running(), "Illegal initial state")do { if (!(cur->safepoint_state()->is_running())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 223, "assert(" "cur->safepoint_state()->is_running()" ") failed", "Illegal initial state"); ::breakpoint(); } } while (0); | ||||
| 224 | } | ||||
| 225 | jtiwh.rewind(); | ||||
| 226 | #endif // ASSERT | ||||
| 227 | |||||
| 228 | // Iterate through all threads until it has been determined how to stop them all at a safepoint. | ||||
| 229 | int still_running = nof_threads; | ||||
| 230 | ThreadSafepointState *tss_head = NULL__null; | ||||
| 231 | ThreadSafepointState **p_prev = &tss_head; | ||||
| 232 | for (; JavaThread *cur = jtiwh.next(); ) { | ||||
| 233 | ThreadSafepointState *cur_tss = cur->safepoint_state(); | ||||
| 234 | assert(cur_tss->get_next() == NULL, "Must be NULL")do { if (!(cur_tss->get_next() == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 234, "assert(" "cur_tss->get_next() == __null" ") failed" , "Must be NULL"); ::breakpoint(); } } while (0); | ||||
| 235 | if (thread_not_running(cur_tss)) { | ||||
| 236 | --still_running; | ||||
| 237 | } else { | ||||
| 238 | *p_prev = cur_tss; | ||||
| 239 | p_prev = cur_tss->next_ptr(); | ||||
| 240 | } | ||||
| 241 | } | ||||
| 242 | *p_prev = NULL__null; | ||||
| 243 | |||||
| 244 | DEBUG_ONLY(assert_list_is_valid(tss_head, still_running);)assert_list_is_valid(tss_head, still_running); | ||||
| 245 | |||||
| 246 | *initial_running = still_running; | ||||
| 247 | |||||
| 248 | // If there is no thread still running, we are already done. | ||||
| 249 | if (still_running <= 0) { | ||||
| 250 | assert(tss_head == NULL, "Must be empty")do { if (!(tss_head == __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 250, "assert(" "tss_head == __null" ") failed", "Must be empty" ); ::breakpoint(); } } while (0); | ||||
| 251 | return 1; | ||||
| 252 | } | ||||
| 253 | |||||
| 254 | int iterations = 1; // The first iteration is above. | ||||
| 255 | int64_t start_time = os::javaTimeNanos(); | ||||
| 256 | |||||
| 257 | do { | ||||
| 258 | // Check if this has taken too long: | ||||
| 259 | if (SafepointTimeout && safepoint_limit_time < os::javaTimeNanos()) { | ||||
| 260 | print_safepoint_timeout(); | ||||
| 261 | } | ||||
| 262 | |||||
| 263 | p_prev = &tss_head; | ||||
| 264 | ThreadSafepointState *cur_tss = tss_head; | ||||
| 265 | while (cur_tss != NULL__null) { | ||||
| 266 | assert(cur_tss->is_running(), "Illegal initial state")do { if (!(cur_tss->is_running())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 266, "assert(" "cur_tss->is_running()" ") failed", "Illegal initial state" ); ::breakpoint(); } } while (0); | ||||
| 267 | if (thread_not_running(cur_tss)) { | ||||
| 268 | --still_running; | ||||
| 269 | *p_prev = NULL__null; | ||||
| 270 | ThreadSafepointState *tmp = cur_tss; | ||||
| 271 | cur_tss = cur_tss->get_next(); | ||||
| 272 | tmp->set_next(NULL__null); | ||||
| 273 | } else { | ||||
| 274 | *p_prev = cur_tss; | ||||
| 275 | p_prev = cur_tss->next_ptr(); | ||||
| 276 | cur_tss = cur_tss->get_next(); | ||||
| 277 | } | ||||
| 278 | } | ||||
| 279 | |||||
| 280 | DEBUG_ONLY(assert_list_is_valid(tss_head, still_running);)assert_list_is_valid(tss_head, still_running); | ||||
| 281 | |||||
| 282 | if (still_running > 0) { | ||||
| 283 | back_off(start_time); | ||||
| 284 | } | ||||
| 285 | |||||
| 286 | iterations++; | ||||
| 287 | } while (still_running > 0); | ||||
| 288 | |||||
| 289 | assert(tss_head == NULL, "Must be empty")do { if (!(tss_head == __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 289, "assert(" "tss_head == __null" ") failed", "Must be empty" ); ::breakpoint(); } } while (0); | ||||
| 290 | |||||
| 291 | return iterations; | ||||
| 292 | } | ||||
| 293 | |||||
| 294 | void SafepointSynchronize::arm_safepoint() { | ||||
| 295 | // Begin the process of bringing the system to a safepoint. | ||||
| 296 | // Java threads can be in several different states and are | ||||
| 297 | // stopped by different mechanisms: | ||||
| 298 | // | ||||
| 299 | // 1. Running interpreted | ||||
| 300 | // When executing branching/returning byte codes interpreter | ||||
| 301 | // checks if the poll is armed, if so blocks in SS::block(). | ||||
| 302 | // 2. Running in native code | ||||
| 303 | // When returning from the native code, a Java thread must check | ||||
| 304 | // the safepoint _state to see if we must block. If the | ||||
| 305 | // VM thread sees a Java thread in native, it does | ||||
| 306 | // not wait for this thread to block. The order of the memory | ||||
| 307 | // writes and reads of both the safepoint state and the Java | ||||
| 308 | // threads state is critical. In order to guarantee that the | ||||
| 309 | // memory writes are serialized with respect to each other, | ||||
| 310 | // the VM thread issues a memory barrier instruction. | ||||
| 311 | // 3. Running compiled Code | ||||
| 312 | // Compiled code reads the local polling page that | ||||
| 313 | // is set to fault if we are trying to get to a safepoint. | ||||
| 314 | // 4. Blocked | ||||
| 315 | // A thread which is blocked will not be allowed to return from the | ||||
| 316 | // block condition until the safepoint operation is complete. | ||||
| 317 | // 5. In VM or Transitioning between states | ||||
| 318 | // If a Java thread is currently running in the VM or transitioning | ||||
| 319 | // between states, the safepointing code will poll the thread state | ||||
| 320 | // until the thread blocks itself when it attempts transitions to a | ||||
| 321 | // new state or locking a safepoint checked monitor. | ||||
| 322 | |||||
| 323 | // We must never miss a thread with correct safepoint id, so we must make sure we arm | ||||
| 324 | // the wait barrier for the next safepoint id/counter. | ||||
| 325 | // Arming must be done after resetting _current_jni_active_count, _waiting_to_block. | ||||
| 326 | _wait_barrier->arm(static_cast<int>(_safepoint_counter + 1)); | ||||
| 327 | |||||
| 328 | assert((_safepoint_counter & 0x1) == 0, "must be even")do { if (!((_safepoint_counter & 0x1) == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 328, "assert(" "(_safepoint_counter & 0x1) == 0" ") failed" , "must be even"); ::breakpoint(); } } while (0); | ||||
| 329 | // The store to _safepoint_counter must happen after any stores in arming. | ||||
| 330 | Atomic::release_store(&_safepoint_counter, _safepoint_counter + 1); | ||||
| 331 | |||||
| 332 | // We are synchronizing | ||||
| 333 | OrderAccess::storestore(); // Ordered with _safepoint_counter | ||||
| 334 | _state = _synchronizing; | ||||
| 335 | |||||
| 336 | // Arming the per thread poll while having _state != _not_synchronized means safepointing | ||||
| 337 | log_trace(safepoint)(!(LogImpl<(LogTag::_safepoint), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_safepoint), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("Setting thread local yield flag for threads"); | ||||
| 338 | OrderAccess::storestore(); // storestore, global state -> local state | ||||
| 339 | for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur = jtiwh.next(); ) { | ||||
| 340 | // Make sure the threads start polling, it is time to yield. | ||||
| 341 | SafepointMechanism::arm_local_poll(cur); | ||||
| 342 | } | ||||
| 343 | |||||
| 344 | OrderAccess::fence(); // storestore|storeload, global state -> local state | ||||
| 345 | } | ||||
| 346 | |||||
| 347 | // Roll all threads forward to a safepoint and suspend them all | ||||
| 348 | void SafepointSynchronize::begin() { | ||||
| 349 | assert(Thread::current()->is_VM_thread(), "Only VM thread may execute a safepoint")do { if (!(Thread::current()->is_VM_thread())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 349, "assert(" "Thread::current()->is_VM_thread()" ") failed" , "Only VM thread may execute a safepoint"); ::breakpoint(); } } while (0); | ||||
| 350 | |||||
| 351 | EventSafepointBegin begin_event; | ||||
| 352 | SafepointTracing::begin(VMThread::vm_op_type()); | ||||
| 353 | |||||
| 354 | Universe::heap()->safepoint_synchronize_begin(); | ||||
| 355 | |||||
| 356 | // By getting the Threads_lock, we assure that no threads are about to start or | ||||
| 357 | // exit. It is released again in SafepointSynchronize::end(). | ||||
| 358 | Threads_lock->lock(); | ||||
| 359 | |||||
| 360 | assert( _state == _not_synchronized, "trying to safepoint synchronize with wrong state")do { if (!(_state == _not_synchronized)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 360, "assert(" "_state == _not_synchronized" ") failed", "trying to safepoint synchronize with wrong state" ); ::breakpoint(); } } while (0); | ||||
| 361 | |||||
| 362 | int nof_threads = Threads::number_of_threads(); | ||||
| 363 | |||||
| 364 | _nof_threads_hit_polling_page = 0; | ||||
| 365 | |||||
| 366 | log_debug(safepoint)(!(LogImpl<(LogTag::_safepoint), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl <(LogTag::_safepoint), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Debug>("Safepoint synchronization initiated using %s wait barrier. (%d threads)", _wait_barrier->description(), nof_threads); | ||||
| 367 | |||||
| 368 | // Reset the count of active JNI critical threads | ||||
| 369 | _current_jni_active_count = 0; | ||||
| 370 | |||||
| 371 | // Set number of threads to wait for | ||||
| 372 | _waiting_to_block = nof_threads; | ||||
| 373 | |||||
| 374 | jlong safepoint_limit_time = 0; | ||||
| 375 | if (SafepointTimeout) { | ||||
| 376 | // Set the limit time, so that it can be compared to see if this has taken | ||||
| 377 | // too long to complete. | ||||
| 378 | safepoint_limit_time = SafepointTracing::start_of_safepoint() + (jlong)SafepointTimeoutDelay * (NANOUNITS / MILLIUNITS); | ||||
| 379 | timeout_error_printed = false; | ||||
| 380 | } | ||||
| 381 | |||||
| 382 | EventSafepointStateSynchronization sync_event; | ||||
| 383 | int initial_running = 0; | ||||
| 384 | |||||
| 385 | // Arms the safepoint, _current_jni_active_count and _waiting_to_block must be set before. | ||||
| 386 | arm_safepoint(); | ||||
| 387 | |||||
| 388 | // Will spin until all threads are safe. | ||||
| 389 | int iterations = synchronize_threads(safepoint_limit_time, nof_threads, &initial_running); | ||||
| 390 | assert(_waiting_to_block == 0, "No thread should be running")do { if (!(_waiting_to_block == 0)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 390, "assert(" "_waiting_to_block == 0" ") failed", "No thread should be running" ); ::breakpoint(); } } while (0); | ||||
| 391 | |||||
| 392 | #ifndef PRODUCT | ||||
| 393 | // Mark all threads | ||||
| 394 | if (VerifyCrossModifyFence) { | ||||
| 395 | JavaThreadIteratorWithHandle jtiwh; | ||||
| 396 | for (; JavaThread *cur = jtiwh.next(); ) { | ||||
| 397 | cur->set_requires_cross_modify_fence(true); | ||||
| 398 | } | ||||
| 399 | } | ||||
| 400 | |||||
| 401 | if (safepoint_limit_time != 0) { | ||||
| 402 | jlong current_time = os::javaTimeNanos(); | ||||
| 403 | if (safepoint_limit_time < current_time) { | ||||
| 404 | log_warning(safepoint)(!(LogImpl<(LogTag::_safepoint), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Warning))) ? (void)0 : LogImpl <(LogTag::_safepoint), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Warning>("# SafepointSynchronize: Finished after " | ||||
| 405 | INT64_FORMAT_W(6)"%" "6" "l" "d" " ms", | ||||
| 406 | (int64_t)(current_time - SafepointTracing::start_of_safepoint()) / (NANOUNITS / MILLIUNITS)); | ||||
| 407 | } | ||||
| 408 | } | ||||
| 409 | #endif | ||||
| 410 | |||||
| 411 | assert(Threads_lock->owned_by_self(), "must hold Threads_lock")do { if (!(Threads_lock->owned_by_self())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 411, "assert(" "Threads_lock->owned_by_self()" ") failed" , "must hold Threads_lock"); ::breakpoint(); } } while (0); | ||||
| 412 | |||||
| 413 | // Record state | ||||
| 414 | _state = _synchronized; | ||||
| 415 | |||||
| 416 | OrderAccess::fence(); | ||||
| 417 | |||||
| 418 | // Set the new id | ||||
| 419 | ++_safepoint_id; | ||||
| 420 | |||||
| 421 | #ifdef ASSERT1 | ||||
| 422 | // Make sure all the threads were visited. | ||||
| 423 | for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur = jtiwh.next(); ) { | ||||
| 424 | assert(cur->was_visited_for_critical_count(_safepoint_counter), "missed a thread")do { if (!(cur->was_visited_for_critical_count(_safepoint_counter ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 424, "assert(" "cur->was_visited_for_critical_count(_safepoint_counter)" ") failed", "missed a thread"); ::breakpoint(); } } while (0 ); | ||||
| 425 | } | ||||
| 426 | #endif // ASSERT | ||||
| 427 | |||||
| 428 | // Update the count of active JNI critical regions | ||||
| 429 | GCLocker::set_jni_lock_count(_current_jni_active_count); | ||||
| 430 | |||||
| 431 | post_safepoint_synchronize_event(sync_event, | ||||
| 432 | _safepoint_id, | ||||
| 433 | initial_running, | ||||
| 434 | _waiting_to_block, iterations); | ||||
| 435 | |||||
| 436 | SafepointTracing::synchronized(nof_threads, initial_running, _nof_threads_hit_polling_page); | ||||
| 437 | |||||
| 438 | // We do the safepoint cleanup first since a GC related safepoint | ||||
| 439 | // needs cleanup to be completed before running the GC op. | ||||
| 440 | EventSafepointCleanup cleanup_event; | ||||
| 441 | do_cleanup_tasks(); | ||||
| 442 | post_safepoint_cleanup_event(cleanup_event, _safepoint_id); | ||||
| 443 | |||||
| 444 | post_safepoint_begin_event(begin_event, _safepoint_id, nof_threads, _current_jni_active_count); | ||||
| 445 | SafepointTracing::cleanup(); | ||||
| 446 | } | ||||
| 447 | |||||
| 448 | void SafepointSynchronize::disarm_safepoint() { | ||||
| 449 | uint64_t active_safepoint_counter = _safepoint_counter; | ||||
| 450 | { | ||||
| 451 | JavaThreadIteratorWithHandle jtiwh; | ||||
| 452 | #ifdef ASSERT1 | ||||
| 453 | // A pending_exception cannot be installed during a safepoint. The threads | ||||
| 454 | // may install an async exception after they come back from a safepoint into | ||||
| 455 | // pending_exception after they unblock. But that should happen later. | ||||
| 456 | for (; JavaThread *cur = jtiwh.next(); ) { | ||||
| 457 | assert (!(cur->has_pending_exception() &&do { if (!(!(cur->has_pending_exception() && cur-> safepoint_state()->is_at_poll_safepoint()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 459, "assert(" "!(cur->has_pending_exception() && cur->safepoint_state()->is_at_poll_safepoint())" ") failed", "safepoint installed a pending exception"); ::breakpoint (); } } while (0) | ||||
| 458 | cur->safepoint_state()->is_at_poll_safepoint()),do { if (!(!(cur->has_pending_exception() && cur-> safepoint_state()->is_at_poll_safepoint()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 459, "assert(" "!(cur->has_pending_exception() && cur->safepoint_state()->is_at_poll_safepoint())" ") failed", "safepoint installed a pending exception"); ::breakpoint (); } } while (0) | ||||
| 459 | "safepoint installed a pending exception")do { if (!(!(cur->has_pending_exception() && cur-> safepoint_state()->is_at_poll_safepoint()))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 459, "assert(" "!(cur->has_pending_exception() && cur->safepoint_state()->is_at_poll_safepoint())" ") failed", "safepoint installed a pending exception"); ::breakpoint (); } } while (0); | ||||
| 460 | } | ||||
| 461 | #endif // ASSERT | ||||
| 462 | |||||
| 463 | OrderAccess::fence(); // keep read and write of _state from floating up | ||||
| 464 | assert(_state == _synchronized, "must be synchronized before ending safepoint synchronization")do { if (!(_state == _synchronized)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 464, "assert(" "_state == _synchronized" ") failed", "must be synchronized before ending safepoint synchronization" ); ::breakpoint(); } } while (0); | ||||
| 465 | |||||
| 466 | // Change state first to _not_synchronized. | ||||
| 467 | // No threads should see _synchronized when running. | ||||
| 468 | _state = _not_synchronized; | ||||
| 469 | |||||
| 470 | // Set the next dormant (even) safepoint id. | ||||
| 471 | assert((_safepoint_counter & 0x1) == 1, "must be odd")do { if (!((_safepoint_counter & 0x1) == 1)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 471, "assert(" "(_safepoint_counter & 0x1) == 1" ") failed" , "must be odd"); ::breakpoint(); } } while (0); | ||||
| 472 | Atomic::release_store(&_safepoint_counter, _safepoint_counter + 1); | ||||
| 473 | |||||
| 474 | OrderAccess::fence(); // Keep the local state from floating up. | ||||
| 475 | |||||
| 476 | jtiwh.rewind(); | ||||
| 477 | for (; JavaThread *current = jtiwh.next(); ) { | ||||
| 478 | // Clear the visited flag to ensure that the critical counts are collected properly. | ||||
| 479 | DEBUG_ONLY(current->reset_visited_for_critical_count(active_safepoint_counter);)current->reset_visited_for_critical_count(active_safepoint_counter ); | ||||
| 480 | ThreadSafepointState* cur_state = current->safepoint_state(); | ||||
| 481 | assert(!cur_state->is_running(), "Thread not suspended at safepoint")do { if (!(!cur_state->is_running())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 481, "assert(" "!cur_state->is_running()" ") failed", "Thread not suspended at safepoint" ); ::breakpoint(); } } while (0); | ||||
| 482 | cur_state->restart(); // TSS _running | ||||
| 483 | assert(cur_state->is_running(), "safepoint state has not been reset")do { if (!(cur_state->is_running())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 483, "assert(" "cur_state->is_running()" ") failed", "safepoint state has not been reset" ); ::breakpoint(); } } while (0); | ||||
| 484 | } | ||||
| 485 | } // ~JavaThreadIteratorWithHandle | ||||
| 486 | |||||
| 487 | // Release threads lock, so threads can be created/destroyed again. | ||||
| 488 | Threads_lock->unlock(); | ||||
| 489 | |||||
| 490 | // Wake threads after local state is correctly set. | ||||
| 491 | _wait_barrier->disarm(); | ||||
| 492 | } | ||||
| 493 | |||||
| 494 | // Wake up all threads, so they are ready to resume execution after the safepoint | ||||
| 495 | // operation has been carried out | ||||
| 496 | void SafepointSynchronize::end() { | ||||
| 497 | assert(Threads_lock->owned_by_self(), "must hold Threads_lock")do { if (!(Threads_lock->owned_by_self())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 497, "assert(" "Threads_lock->owned_by_self()" ") failed" , "must hold Threads_lock"); ::breakpoint(); } } while (0); | ||||
| 498 | EventSafepointEnd event; | ||||
| 499 | assert(Thread::current()->is_VM_thread(), "Only VM thread can execute a safepoint")do { if (!(Thread::current()->is_VM_thread())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 499, "assert(" "Thread::current()->is_VM_thread()" ") failed" , "Only VM thread can execute a safepoint"); ::breakpoint(); } } while (0); | ||||
| 500 | |||||
| 501 | disarm_safepoint(); | ||||
| 502 | |||||
| 503 | Universe::heap()->safepoint_synchronize_end(); | ||||
| 504 | |||||
| 505 | SafepointTracing::end(); | ||||
| 506 | |||||
| 507 | post_safepoint_end_event(event, safepoint_id()); | ||||
| 508 | } | ||||
| 509 | |||||
| 510 | bool SafepointSynchronize::is_cleanup_needed() { | ||||
| 511 | // Need a safepoint if some inline cache buffers is non-empty | ||||
| 512 | if (!InlineCacheBuffer::is_empty()) return true; | ||||
| 513 | if (StringTable::needs_rehashing()) return true; | ||||
| 514 | if (SymbolTable::needs_rehashing()) return true; | ||||
| 515 | return false; | ||||
| 516 | } | ||||
| 517 | |||||
| 518 | class ParallelSPCleanupThreadClosure : public ThreadClosure { | ||||
| 519 | public: | ||||
| 520 | void do_thread(Thread* thread) { | ||||
| 521 | if (thread->is_Java_thread()) { | ||||
| 522 | StackWatermarkSet::start_processing(JavaThread::cast(thread), StackWatermarkKind::gc); | ||||
| 523 | } | ||||
| 524 | } | ||||
| 525 | }; | ||||
| 526 | |||||
| 527 | class ParallelSPCleanupTask : public WorkerTask { | ||||
| 528 | private: | ||||
| 529 | SubTasksDone _subtasks; | ||||
| 530 | uint _num_workers; | ||||
| 531 | bool _do_lazy_roots; | ||||
| 532 | |||||
| 533 | class Tracer { | ||||
| 534 | private: | ||||
| 535 | const char* _name; | ||||
| 536 | EventSafepointCleanupTask _event; | ||||
| 537 | TraceTime _timer; | ||||
| 538 | |||||
| 539 | public: | ||||
| 540 | Tracer(const char* name) : | ||||
| 541 | _name(name), | ||||
| 542 | _event(), | ||||
| 543 | _timer(name, TRACETIME_LOG(Info, safepoint, cleanup)(LogImpl<(LogTag::_safepoint), (LogTag::_cleanup), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info)) ? static_cast<TraceTimerLogPrintFunc >(&LogImpl<(LogTag::_safepoint), (LogTag::_cleanup) , (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel::Info>) : (TraceTimerLogPrintFunc )__null) {} | ||||
| 544 | ~Tracer() { | ||||
| 545 | post_safepoint_cleanup_task_event(_event, SafepointSynchronize::safepoint_id(), _name); | ||||
| 546 | } | ||||
| 547 | }; | ||||
| 548 | |||||
| 549 | public: | ||||
| 550 | ParallelSPCleanupTask(uint num_workers) : | ||||
| 551 | WorkerTask("Parallel Safepoint Cleanup"), | ||||
| 552 | _subtasks(SafepointSynchronize::SAFEPOINT_CLEANUP_NUM_TASKS), | ||||
| 553 | _num_workers(num_workers), | ||||
| 554 | _do_lazy_roots(!VMThread::vm_operation()->skip_thread_oop_barriers() && | ||||
| 555 | Universe::heap()->uses_stack_watermark_barrier()) {} | ||||
| 556 | |||||
| 557 | void work(uint worker_id) { | ||||
| 558 | if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_LAZY_ROOT_PROCESSING)) { | ||||
| 559 | if (_do_lazy_roots) { | ||||
| 560 | Tracer t("lazy partial thread root processing"); | ||||
| 561 | ParallelSPCleanupThreadClosure cl; | ||||
| 562 | Threads::threads_do(&cl); | ||||
| 563 | } | ||||
| 564 | } | ||||
| 565 | |||||
| 566 | if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_UPDATE_INLINE_CACHES)) { | ||||
| 567 | Tracer t("updating inline caches"); | ||||
| 568 | InlineCacheBuffer::update_inline_caches(); | ||||
| 569 | } | ||||
| 570 | |||||
| 571 | if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_COMPILATION_POLICY)) { | ||||
| 572 | Tracer t("compilation policy safepoint handler"); | ||||
| 573 | CompilationPolicy::do_safepoint_work(); | ||||
| 574 | } | ||||
| 575 | |||||
| 576 | if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_SYMBOL_TABLE_REHASH)) { | ||||
| 577 | if (SymbolTable::needs_rehashing()) { | ||||
| 578 | Tracer t("rehashing symbol table"); | ||||
| 579 | SymbolTable::rehash_table(); | ||||
| 580 | } | ||||
| 581 | } | ||||
| 582 | |||||
| 583 | if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_STRING_TABLE_REHASH)) { | ||||
| 584 | if (StringTable::needs_rehashing()) { | ||||
| 585 | Tracer t("rehashing string table"); | ||||
| 586 | StringTable::rehash_table(); | ||||
| 587 | } | ||||
| 588 | } | ||||
| 589 | |||||
| 590 | if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_SYSTEM_DICTIONARY_RESIZE)) { | ||||
| 591 | if (Dictionary::does_any_dictionary_needs_resizing()) { | ||||
| 592 | Tracer t("resizing system dictionaries"); | ||||
| 593 | ClassLoaderDataGraph::resize_dictionaries(); | ||||
| 594 | } | ||||
| 595 | } | ||||
| 596 | |||||
| 597 | if (_subtasks.try_claim_task(SafepointSynchronize::SAFEPOINT_CLEANUP_REQUEST_OOPSTORAGE_CLEANUP)) { | ||||
| 598 | // Don't bother reporting event or time for this very short operation. | ||||
| 599 | // To have any utility we'd also want to report whether needed. | ||||
| 600 | OopStorage::trigger_cleanup_if_needed(); | ||||
| 601 | } | ||||
| 602 | |||||
| 603 | _subtasks.all_tasks_claimed(); | ||||
| 604 | } | ||||
| 605 | }; | ||||
| 606 | |||||
| 607 | // Various cleaning tasks that should be done periodically at safepoints. | ||||
| 608 | void SafepointSynchronize::do_cleanup_tasks() { | ||||
| 609 | |||||
| 610 | TraceTime timer("safepoint cleanup tasks", TRACETIME_LOG(Info, safepoint, cleanup)(LogImpl<(LogTag::_safepoint), (LogTag::_cleanup), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info)) ? static_cast<TraceTimerLogPrintFunc >(&LogImpl<(LogTag::_safepoint), (LogTag::_cleanup) , (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel::Info>) : (TraceTimerLogPrintFunc )__null); | ||||
| 611 | |||||
| 612 | CollectedHeap* heap = Universe::heap(); | ||||
| 613 | assert(heap != NULL, "heap not initialized yet?")do { if (!(heap != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 613, "assert(" "heap != __null" ") failed", "heap not initialized yet?" ); ::breakpoint(); } } while (0); | ||||
| 614 | WorkerThreads* cleanup_workers = heap->safepoint_workers(); | ||||
| 615 | if (cleanup_workers != NULL__null) { | ||||
| 616 | // Parallel cleanup using GC provided thread pool. | ||||
| 617 | uint num_cleanup_workers = cleanup_workers->active_workers(); | ||||
| 618 | ParallelSPCleanupTask cleanup(num_cleanup_workers); | ||||
| 619 | cleanup_workers->run_task(&cleanup); | ||||
| 620 | } else { | ||||
| 621 | // Serial cleanup using VMThread. | ||||
| 622 | ParallelSPCleanupTask cleanup(1); | ||||
| 623 | cleanup.work(0); | ||||
| 624 | } | ||||
| 625 | |||||
| 626 | assert(InlineCacheBuffer::is_empty(), "should have cleaned up ICBuffer")do { if (!(InlineCacheBuffer::is_empty())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 626, "assert(" "InlineCacheBuffer::is_empty()" ") failed", "should have cleaned up ICBuffer" ); ::breakpoint(); } } while (0); | ||||
| 627 | |||||
| 628 | if (log_is_enabled(Debug, monitorinflation)(LogImpl<(LogTag::_monitorinflation), (LogTag::__NO_TAG), ( LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag ::__NO_TAG)>::is_level(LogLevel::Debug))) { | ||||
| 629 | // The VMThread calls do_final_audit_and_print_stats() which calls | ||||
| 630 | // audit_and_print_stats() at the Info level at VM exit time. | ||||
| 631 | ObjectSynchronizer::audit_and_print_stats(false /* on_exit */); | ||||
| 632 | } | ||||
| 633 | } | ||||
| 634 | |||||
| 635 | // Methods for determining if a JavaThread is safepoint safe. | ||||
| 636 | |||||
| 637 | // False means unsafe with undetermined state. | ||||
| 638 | // True means a determined state, but it may be an unsafe state. | ||||
| 639 | // If called from a non-safepoint context safepoint_count MUST be InactiveSafepointCounter. | ||||
| 640 | bool SafepointSynchronize::try_stable_load_state(JavaThreadState *state, JavaThread *thread, uint64_t safepoint_count) { | ||||
| 641 | assert((safepoint_count != InactiveSafepointCounter &&do { if (!((safepoint_count != InactiveSafepointCounter && Thread::current() == (Thread*)VMThread::vm_thread() && SafepointSynchronize::_state != _not_synchronized) || safepoint_count == InactiveSafepointCounter)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 644, "assert(" "(safepoint_count != InactiveSafepointCounter && Thread::current() == (Thread*)VMThread::vm_thread() && SafepointSynchronize::_state != _not_synchronized) || safepoint_count == InactiveSafepointCounter" ") failed", "Invalid check"); ::breakpoint(); } } while (0) | ||||
| 642 | Thread::current() == (Thread*)VMThread::vm_thread() &&do { if (!((safepoint_count != InactiveSafepointCounter && Thread::current() == (Thread*)VMThread::vm_thread() && SafepointSynchronize::_state != _not_synchronized) || safepoint_count == InactiveSafepointCounter)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 644, "assert(" "(safepoint_count != InactiveSafepointCounter && Thread::current() == (Thread*)VMThread::vm_thread() && SafepointSynchronize::_state != _not_synchronized) || safepoint_count == InactiveSafepointCounter" ") failed", "Invalid check"); ::breakpoint(); } } while (0) | ||||
| 643 | SafepointSynchronize::_state != _not_synchronized)do { if (!((safepoint_count != InactiveSafepointCounter && Thread::current() == (Thread*)VMThread::vm_thread() && SafepointSynchronize::_state != _not_synchronized) || safepoint_count == InactiveSafepointCounter)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 644, "assert(" "(safepoint_count != InactiveSafepointCounter && Thread::current() == (Thread*)VMThread::vm_thread() && SafepointSynchronize::_state != _not_synchronized) || safepoint_count == InactiveSafepointCounter" ") failed", "Invalid check"); ::breakpoint(); } } while (0) | ||||
| 644 | || safepoint_count == InactiveSafepointCounter, "Invalid check")do { if (!((safepoint_count != InactiveSafepointCounter && Thread::current() == (Thread*)VMThread::vm_thread() && SafepointSynchronize::_state != _not_synchronized) || safepoint_count == InactiveSafepointCounter)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 644, "assert(" "(safepoint_count != InactiveSafepointCounter && Thread::current() == (Thread*)VMThread::vm_thread() && SafepointSynchronize::_state != _not_synchronized) || safepoint_count == InactiveSafepointCounter" ") failed", "Invalid check"); ::breakpoint(); } } while (0); | ||||
| 645 | |||||
| 646 | // To handle the thread_blocked state on the backedge of the WaitBarrier from | ||||
| 647 | // previous safepoint and reading the reset value (0/InactiveSafepointCounter) we | ||||
| 648 | // re-read state after we read thread safepoint id. The JavaThread changes its | ||||
| 649 | // thread state from thread_blocked before resetting safepoint id to 0. | ||||
| 650 | // This guarantees the second read will be from an updated thread state. It can | ||||
| 651 | // either be different state making this an unsafe state or it can see blocked | ||||
| 652 | // again. When we see blocked twice with a 0 safepoint id, either: | ||||
| 653 | // - It is normally blocked, e.g. on Mutex, TBIVM. | ||||
| 654 | // - It was in SS:block(), looped around to SS:block() and is blocked on the WaitBarrier. | ||||
| 655 | // - It was in SS:block() but now on a Mutex. | ||||
| 656 | // All of these cases are safe. | ||||
| 657 | |||||
| 658 | *state = thread->thread_state(); | ||||
| 659 | OrderAccess::loadload(); | ||||
| 660 | uint64_t sid = thread->safepoint_state()->get_safepoint_id(); // Load acquire | ||||
| 661 | if (sid != InactiveSafepointCounter && sid != safepoint_count) { | ||||
| 662 | // In an old safepoint, state not relevant. | ||||
| 663 | return false; | ||||
| 664 | } | ||||
| 665 | return *state == thread->thread_state(); | ||||
| 666 | } | ||||
| 667 | |||||
| 668 | static bool safepoint_safe_with(JavaThread *thread, JavaThreadState state) { | ||||
| 669 | switch(state) { | ||||
| 670 | case _thread_in_native: | ||||
| 671 | // native threads are safe if they have no java stack or have walkable stack | ||||
| 672 | return !thread->has_last_Java_frame() || thread->frame_anchor()->walkable(); | ||||
| 673 | |||||
| 674 | case _thread_blocked: | ||||
| 675 | // On wait_barrier or blocked. | ||||
| 676 | // Blocked threads should already have walkable stack. | ||||
| 677 | assert(!thread->has_last_Java_frame() || thread->frame_anchor()->walkable(), "blocked and not walkable")do { if (!(!thread->has_last_Java_frame() || thread->frame_anchor ()->walkable())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 677, "assert(" "!thread->has_last_Java_frame() || thread->frame_anchor()->walkable()" ") failed", "blocked and not walkable"); ::breakpoint(); } } while (0); | ||||
| 678 | return true; | ||||
| 679 | |||||
| 680 | default: | ||||
| 681 | return false; | ||||
| 682 | } | ||||
| 683 | } | ||||
| 684 | |||||
| 685 | bool SafepointSynchronize::handshake_safe(JavaThread *thread) { | ||||
| 686 | if (thread->is_terminated()) { | ||||
| 687 | return true; | ||||
| 688 | } | ||||
| 689 | JavaThreadState stable_state; | ||||
| 690 | if (try_stable_load_state(&stable_state, thread, InactiveSafepointCounter)) { | ||||
| 691 | return safepoint_safe_with(thread, stable_state); | ||||
| 692 | } | ||||
| 693 | return false; | ||||
| 694 | } | ||||
| 695 | |||||
| 696 | |||||
| 697 | // ------------------------------------------------------------------------------------------------------- | ||||
| 698 | // Implementation of Safepoint blocking point | ||||
| 699 | |||||
| 700 | void SafepointSynchronize::block(JavaThread *thread) { | ||||
| 701 | assert(thread != NULL, "thread must be set")do { if (!(thread != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 701, "assert(" "thread != __null" ") failed", "thread must be set" ); ::breakpoint(); } } while (0); | ||||
| 702 | |||||
| 703 | // Threads shouldn't block if they are in the middle of printing, but... | ||||
| 704 | ttyLocker::break_tty_lock_for_safepoint(os::current_thread_id()); | ||||
| 705 | |||||
| 706 | // Only bail from the block() call if the thread is gone from the | ||||
| 707 | // thread list; starting to exit should still block. | ||||
| 708 | if (thread->is_terminated()) { | ||||
| 709 | // block current thread if we come here from native code when VM is gone | ||||
| 710 | thread->block_if_vm_exited(); | ||||
| 711 | |||||
| 712 | // otherwise do nothing | ||||
| 713 | return; | ||||
| 714 | } | ||||
| 715 | |||||
| 716 | JavaThreadState state = thread->thread_state(); | ||||
| 717 | thread->frame_anchor()->make_walkable(thread); | ||||
| 718 | |||||
| 719 | uint64_t safepoint_id = SafepointSynchronize::safepoint_counter(); | ||||
| 720 | |||||
| 721 | // We have no idea where the VMThread is, it might even be at next safepoint. | ||||
| 722 | // So we can miss this poll, but stop at next. | ||||
| 723 | |||||
| 724 | // Load dependent store, it must not pass loading of safepoint_id. | ||||
| 725 | thread->safepoint_state()->set_safepoint_id(safepoint_id); // Release store | ||||
| 726 | |||||
| 727 | // This part we can skip if we notice we miss or are in a future safepoint. | ||||
| 728 | OrderAccess::storestore(); | ||||
| 729 | // Load in wait barrier should not float up | ||||
| 730 | thread->set_thread_state_fence(_thread_blocked); | ||||
| 731 | |||||
| 732 | _wait_barrier->wait(static_cast<int>(safepoint_id)); | ||||
| 733 | assert(_state != _synchronized, "Can't be")do { if (!(_state != _synchronized)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 733, "assert(" "_state != _synchronized" ") failed", "Can't be" ); ::breakpoint(); } } while (0); | ||||
| 734 | |||||
| 735 | // If barrier is disarmed stop store from floating above loads in barrier. | ||||
| 736 | OrderAccess::loadstore(); | ||||
| 737 | thread->set_thread_state(state); | ||||
| 738 | |||||
| 739 | // Then we reset the safepoint id to inactive. | ||||
| 740 | thread->safepoint_state()->reset_safepoint_id(); // Release store | ||||
| 741 | |||||
| 742 | OrderAccess::fence(); | ||||
| 743 | |||||
| 744 | guarantee(thread->safepoint_state()->get_safepoint_id() == InactiveSafepointCounter,do { if (!(thread->safepoint_state()->get_safepoint_id( ) == InactiveSafepointCounter)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 745, "guarantee(" "thread->safepoint_state()->get_safepoint_id() == InactiveSafepointCounter" ") failed", "The safepoint id should be set only in block path" ); ::breakpoint(); } } while (0) | ||||
| 745 | "The safepoint id should be set only in block path")do { if (!(thread->safepoint_state()->get_safepoint_id( ) == InactiveSafepointCounter)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 745, "guarantee(" "thread->safepoint_state()->get_safepoint_id() == InactiveSafepointCounter" ") failed", "The safepoint id should be set only in block path" ); ::breakpoint(); } } while (0); | ||||
| 746 | |||||
| 747 | // cross_modify_fence is done by SafepointMechanism::process_if_requested | ||||
| 748 | // which is the only caller here. | ||||
| 749 | } | ||||
| 750 | |||||
| 751 | // ------------------------------------------------------------------------------------------------------ | ||||
| 752 | // Exception handlers | ||||
| 753 | |||||
| 754 | |||||
| 755 | void SafepointSynchronize::handle_polling_page_exception(JavaThread *thread) { | ||||
| 756 | assert(thread->thread_state() == _thread_in_Java, "should come from Java code")do { if (!(thread->thread_state() == _thread_in_Java)) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 756, "assert(" "thread->thread_state() == _thread_in_Java" ") failed", "should come from Java code"); ::breakpoint(); } } while (0); | ||||
| |||||
| 757 | |||||
| 758 | // Enable WXWrite: the function is called implicitly from java code. | ||||
| 759 | MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, thread)); | ||||
| 760 | |||||
| 761 | if (log_is_enabled(Info, safepoint, stats)(LogImpl<(LogTag::_safepoint), (LogTag::_stats), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Info))) { | ||||
| 762 | Atomic::inc(&_nof_threads_hit_polling_page); | ||||
| 763 | } | ||||
| 764 | |||||
| 765 | ThreadSafepointState* state = thread->safepoint_state(); | ||||
| 766 | |||||
| 767 | state->handle_polling_page_exception(); | ||||
| 768 | } | ||||
| 769 | |||||
| 770 | |||||
| 771 | void SafepointSynchronize::print_safepoint_timeout() { | ||||
| 772 | if (!timeout_error_printed) { | ||||
| 773 | timeout_error_printed = true; | ||||
| 774 | // Print out the thread info which didn't reach the safepoint for debugging | ||||
| 775 | // purposes (useful when there are lots of threads in the debugger). | ||||
| 776 | LogTarget(Warning, safepoint)LogTargetImpl<LogLevel::Warning, (LogTag::_safepoint), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG)> lt; | ||||
| 777 | if (lt.is_enabled()) { | ||||
| 778 | ResourceMark rm; | ||||
| 779 | LogStream ls(lt); | ||||
| 780 | |||||
| 781 | ls.cr(); | ||||
| 782 | ls.print_cr("# SafepointSynchronize::begin: Timeout detected:"); | ||||
| 783 | ls.print_cr("# SafepointSynchronize::begin: Timed out while spinning to reach a safepoint."); | ||||
| 784 | ls.print_cr("# SafepointSynchronize::begin: Threads which did not reach the safepoint:"); | ||||
| 785 | for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur_thread = jtiwh.next(); ) { | ||||
| 786 | if (cur_thread->safepoint_state()->is_running()) { | ||||
| 787 | ls.print("# "); | ||||
| 788 | cur_thread->print_on(&ls); | ||||
| 789 | ls.cr(); | ||||
| 790 | } | ||||
| 791 | } | ||||
| 792 | ls.print_cr("# SafepointSynchronize::begin: (End of list)"); | ||||
| 793 | } | ||||
| 794 | } | ||||
| 795 | |||||
| 796 | // To debug the long safepoint, specify both AbortVMOnSafepointTimeout & | ||||
| 797 | // ShowMessageBoxOnError. | ||||
| 798 | if (AbortVMOnSafepointTimeout) { | ||||
| 799 | // Send the blocking thread a signal to terminate and write an error file. | ||||
| 800 | for (JavaThreadIteratorWithHandle jtiwh; JavaThread *cur_thread = jtiwh.next(); ) { | ||||
| 801 | if (cur_thread->safepoint_state()->is_running()) { | ||||
| 802 | if (!os::signal_thread(cur_thread, SIGILL4, "blocking a safepoint")) { | ||||
| 803 | break; // Could not send signal. Report fatal error. | ||||
| 804 | } | ||||
| 805 | // Give cur_thread a chance to report the error and terminate the VM. | ||||
| 806 | os::naked_sleep(3000); | ||||
| 807 | } | ||||
| 808 | } | ||||
| 809 | fatal("Safepoint sync time longer than " INTX_FORMAT "ms detected when executing %s.",do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 810, "Safepoint sync time longer than " "%" "l" "d" "ms detected when executing %s." , SafepointTimeoutDelay, VMThread::vm_operation()->name()) ; ::breakpoint(); } while (0) | ||||
| 810 | SafepointTimeoutDelay, VMThread::vm_operation()->name())do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 810, "Safepoint sync time longer than " "%" "l" "d" "ms detected when executing %s." , SafepointTimeoutDelay, VMThread::vm_operation()->name()) ; ::breakpoint(); } while (0); | ||||
| 811 | } | ||||
| 812 | } | ||||
| 813 | |||||
| 814 | // ------------------------------------------------------------------------------------------------------- | ||||
| 815 | // Implementation of ThreadSafepointState | ||||
| 816 | |||||
| 817 | ThreadSafepointState::ThreadSafepointState(JavaThread *thread) | ||||
| 818 | : _at_poll_safepoint(false), _thread(thread), _safepoint_safe(false), | ||||
| 819 | _safepoint_id(SafepointSynchronize::InactiveSafepointCounter), _next(NULL__null) { | ||||
| 820 | } | ||||
| 821 | |||||
| 822 | void ThreadSafepointState::create(JavaThread *thread) { | ||||
| 823 | ThreadSafepointState *state = new ThreadSafepointState(thread); | ||||
| 824 | thread->set_safepoint_state(state); | ||||
| 825 | } | ||||
| 826 | |||||
| 827 | void ThreadSafepointState::destroy(JavaThread *thread) { | ||||
| 828 | if (thread->safepoint_state()) { | ||||
| 829 | delete(thread->safepoint_state()); | ||||
| 830 | thread->set_safepoint_state(NULL__null); | ||||
| 831 | } | ||||
| 832 | } | ||||
| 833 | |||||
| 834 | uint64_t ThreadSafepointState::get_safepoint_id() const { | ||||
| 835 | return Atomic::load_acquire(&_safepoint_id); | ||||
| 836 | } | ||||
| 837 | |||||
| 838 | void ThreadSafepointState::reset_safepoint_id() { | ||||
| 839 | Atomic::release_store(&_safepoint_id, SafepointSynchronize::InactiveSafepointCounter); | ||||
| 840 | } | ||||
| 841 | |||||
| 842 | void ThreadSafepointState::set_safepoint_id(uint64_t safepoint_id) { | ||||
| 843 | Atomic::release_store(&_safepoint_id, safepoint_id); | ||||
| 844 | } | ||||
| 845 | |||||
| 846 | void ThreadSafepointState::examine_state_of_thread(uint64_t safepoint_count) { | ||||
| 847 | assert(is_running(), "better be running or just have hit safepoint poll")do { if (!(is_running())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 847, "assert(" "is_running()" ") failed", "better be running or just have hit safepoint poll" ); ::breakpoint(); } } while (0); | ||||
| 848 | |||||
| 849 | JavaThreadState stable_state; | ||||
| 850 | if (!SafepointSynchronize::try_stable_load_state(&stable_state, _thread, safepoint_count)) { | ||||
| 851 | // We could not get stable state of the JavaThread. | ||||
| 852 | // Consider it running and just return. | ||||
| 853 | return; | ||||
| 854 | } | ||||
| 855 | |||||
| 856 | if (safepoint_safe_with(_thread, stable_state)) { | ||||
| 857 | account_safe_thread(); | ||||
| 858 | return; | ||||
| 859 | } | ||||
| 860 | |||||
| 861 | // All other thread states will continue to run until they | ||||
| 862 | // transition and self-block in state _blocked | ||||
| 863 | // Safepoint polling in compiled code causes the Java threads to do the same. | ||||
| 864 | // Note: new threads may require a malloc so they must be allowed to finish | ||||
| 865 | |||||
| 866 | assert(is_running(), "examine_state_of_thread on non-running thread")do { if (!(is_running())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 866, "assert(" "is_running()" ") failed", "examine_state_of_thread on non-running thread" ); ::breakpoint(); } } while (0); | ||||
| 867 | return; | ||||
| 868 | } | ||||
| 869 | |||||
| 870 | void ThreadSafepointState::account_safe_thread() { | ||||
| 871 | SafepointSynchronize::decrement_waiting_to_block(); | ||||
| 872 | if (_thread->in_critical()) { | ||||
| 873 | // Notice that this thread is in a critical section | ||||
| 874 | SafepointSynchronize::increment_jni_active_count(); | ||||
| 875 | } | ||||
| 876 | DEBUG_ONLY(_thread->set_visited_for_critical_count(SafepointSynchronize::safepoint_counter());)_thread->set_visited_for_critical_count(SafepointSynchronize ::safepoint_counter()); | ||||
| 877 | assert(!_safepoint_safe, "Must be unsafe before safe")do { if (!(!_safepoint_safe)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 877, "assert(" "!_safepoint_safe" ") failed", "Must be unsafe before safe" ); ::breakpoint(); } } while (0); | ||||
| 878 | _safepoint_safe = true; | ||||
| 879 | } | ||||
| 880 | |||||
| 881 | void ThreadSafepointState::restart() { | ||||
| 882 | assert(_safepoint_safe, "Must be safe before unsafe")do { if (!(_safepoint_safe)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 882, "assert(" "_safepoint_safe" ") failed", "Must be safe before unsafe" ); ::breakpoint(); } } while (0); | ||||
| 883 | _safepoint_safe = false; | ||||
| 884 | } | ||||
| 885 | |||||
| 886 | void ThreadSafepointState::print_on(outputStream *st) const { | ||||
| 887 | const char *s = _safepoint_safe ? "_at_safepoint" : "_running"; | ||||
| 888 | |||||
| 889 | st->print_cr("Thread: " INTPTR_FORMAT"0x%016" "l" "x" | ||||
| 890 | " [0x%2x] State: %s _at_poll_safepoint %d", | ||||
| 891 | p2i(_thread), _thread->osthread()->thread_id(), s, _at_poll_safepoint); | ||||
| 892 | |||||
| 893 | _thread->print_thread_state_on(st); | ||||
| 894 | } | ||||
| 895 | |||||
| 896 | // --------------------------------------------------------------------------------------------------------------------- | ||||
| 897 | |||||
| 898 | // Process pending operation. | ||||
| 899 | void ThreadSafepointState::handle_polling_page_exception() { | ||||
| 900 | JavaThread* self = thread(); | ||||
| 901 | assert(self == JavaThread::current(), "must be self")do { if (!(self == JavaThread::current())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 901, "assert(" "self == JavaThread::current()" ") failed", "must be self" ); ::breakpoint(); } } while (0); | ||||
| 902 | |||||
| 903 | // Step 1: Find the nmethod from the return address | ||||
| 904 | address real_return_addr = self->saved_exception_pc(); | ||||
| 905 | |||||
| 906 | CodeBlob *cb = CodeCache::find_blob(real_return_addr); | ||||
| 907 | assert(cb != NULL && cb->is_compiled(), "return address should be in nmethod")do { if (!(cb != __null && cb->is_compiled())) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 907, "assert(" "cb != __null && cb->is_compiled()" ") failed", "return address should be in nmethod"); ::breakpoint (); } } while (0); | ||||
| 908 | CompiledMethod* nm = (CompiledMethod*)cb; | ||||
| 909 | |||||
| 910 | // Find frame of caller | ||||
| 911 | frame stub_fr = self->last_frame(); | ||||
| 912 | CodeBlob* stub_cb = stub_fr.cb(); | ||||
| 913 | assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub")do { if (!(stub_cb->is_safepoint_stub())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 913, "assert(" "stub_cb->is_safepoint_stub()" ") failed" , "must be a safepoint stub"); ::breakpoint(); } } while (0); | ||||
| 914 | RegisterMap map(self, true, false); | ||||
| 915 | frame caller_fr = stub_fr.sender(&map); | ||||
| 916 | |||||
| 917 | // Should only be poll_return or poll | ||||
| 918 | assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" )do { if (!(nm->is_at_poll_or_poll_return(real_return_addr) )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 918, "assert(" "nm->is_at_poll_or_poll_return(real_return_addr)" ") failed", "should not be at call"); ::breakpoint(); } } while (0); | ||||
| 919 | |||||
| 920 | // This is a poll immediately before a return. The exception handling code | ||||
| 921 | // has already had the effect of causing the return to occur, so the execution | ||||
| 922 | // will continue immediately after the call. In addition, the oopmap at the | ||||
| 923 | // return point does not mark the return value as an oop (if it is), so | ||||
| 924 | // it needs a handle here to be updated. | ||||
| 925 | if( nm->is_at_poll_return(real_return_addr) ) { | ||||
| 926 | // See if return type is an oop. | ||||
| 927 | bool return_oop = nm->method()->is_returning_oop(); | ||||
| 928 | HandleMark hm(self); | ||||
| 929 | Handle return_value; | ||||
| 930 | if (return_oop
| ||||
| 931 | // The oop result has been saved on the stack together with all | ||||
| 932 | // the other registers. In order to preserve it over GCs we need | ||||
| 933 | // to keep it in a handle. | ||||
| 934 | oop result = caller_fr.saved_oop_result(&map); | ||||
| 935 | assert(oopDesc::is_oop_or_null(result), "must be oop")do { if (!(oopDesc::is_oop_or_null(result))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 935, "assert(" "oopDesc::is_oop_or_null(result)" ") failed" , "must be oop"); ::breakpoint(); } } while (0); | ||||
| 936 | return_value = Handle(self, result); | ||||
| 937 | assert(Universe::heap()->is_in_or_null(result), "must be heap pointer")do { if (!(Universe::heap()->is_in_or_null(result))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 937, "assert(" "Universe::heap()->is_in_or_null(result)" ") failed", "must be heap pointer"); ::breakpoint(); } } while (0); | ||||
| 938 | } | ||||
| 939 | |||||
| 940 | // We get here if compiled return polls found a reason to call into the VM. | ||||
| 941 | // One condition for that is that the top frame is not yet safe to use. | ||||
| 942 | // The following stack watermark barrier poll will catch such situations. | ||||
| 943 | StackWatermarkSet::after_unwind(self); | ||||
| 944 | |||||
| 945 | // Process pending operation | ||||
| 946 | SafepointMechanism::process_if_requested_with_exit_check(self, true /* check asyncs */); | ||||
| 947 | |||||
| 948 | // restore oop result, if any | ||||
| 949 | if (return_oop) { | ||||
| 950 | caller_fr.set_saved_oop_result(&map, return_value()); | ||||
| 951 | } | ||||
| 952 | } | ||||
| 953 | |||||
| 954 | // This is a safepoint poll. Verify the return address and block. | ||||
| 955 | else { | ||||
| 956 | |||||
| 957 | // verify the blob built the "return address" correctly | ||||
| 958 | assert(real_return_addr == caller_fr.pc(), "must match")do { if (!(real_return_addr == caller_fr.pc())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 958, "assert(" "real_return_addr == caller_fr.pc()" ") failed" , "must match"); ::breakpoint(); } } while (0); | ||||
| 959 | |||||
| 960 | set_at_poll_safepoint(true); | ||||
| 961 | // Process pending operation | ||||
| 962 | // We never deliver an async exception at a polling point as the | ||||
| 963 | // compiler may not have an exception handler for it. The polling | ||||
| 964 | // code will notice the pending async exception, deoptimize and | ||||
| 965 | // the exception will be delivered. (Polling at a return point | ||||
| 966 | // is ok though). Sure is a lot of bother for a deprecated feature... | ||||
| 967 | SafepointMechanism::process_if_requested_with_exit_check(self, false /* check asyncs */); | ||||
| 968 | set_at_poll_safepoint(false); | ||||
| 969 | |||||
| 970 | // If we have a pending async exception deoptimize the frame | ||||
| 971 | // as otherwise we may never deliver it. | ||||
| 972 | if (self->has_async_exception_condition()) { | ||||
| 973 | ThreadInVMfromJava __tiv(self, false /* check asyncs */); | ||||
| 974 | Deoptimization::deoptimize_frame(self, caller_fr.id()); | ||||
| 975 | } | ||||
| 976 | |||||
| 977 | // If an exception has been installed we must check for a pending deoptimization | ||||
| 978 | // Deoptimize frame if exception has been thrown. | ||||
| 979 | |||||
| 980 | if (self->has_pending_exception() ) { | ||||
| 981 | RegisterMap map(self, true, false); | ||||
| 982 | frame caller_fr = stub_fr.sender(&map); | ||||
| 983 | if (caller_fr.is_deoptimized_frame()) { | ||||
| 984 | // The exception patch will destroy registers that are still | ||||
| 985 | // live and will be needed during deoptimization. Defer the | ||||
| 986 | // Async exception should have deferred the exception until the | ||||
| 987 | // next safepoint which will be detected when we get into | ||||
| 988 | // the interpreter so if we have an exception now things | ||||
| 989 | // are messed up. | ||||
| 990 | |||||
| 991 | fatal("Exception installed and deoptimization is pending")do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 991, "Exception installed and deoptimization is pending"); :: breakpoint(); } while (0); | ||||
| 992 | } | ||||
| 993 | } | ||||
| 994 | } | ||||
| 995 | } | ||||
| 996 | |||||
| 997 | |||||
| 998 | // ------------------------------------------------------------------------------------------------------- | ||||
| 999 | // Implementation of SafepointTracing | ||||
| 1000 | |||||
| 1001 | jlong SafepointTracing::_last_safepoint_begin_time_ns = 0; | ||||
| 1002 | jlong SafepointTracing::_last_safepoint_sync_time_ns = 0; | ||||
| 1003 | jlong SafepointTracing::_last_safepoint_cleanup_time_ns = 0; | ||||
| 1004 | jlong SafepointTracing::_last_safepoint_end_time_ns = 0; | ||||
| 1005 | jlong SafepointTracing::_last_app_time_ns = 0; | ||||
| 1006 | int SafepointTracing::_nof_threads = 0; | ||||
| 1007 | int SafepointTracing::_nof_running = 0; | ||||
| 1008 | int SafepointTracing::_page_trap = 0; | ||||
| 1009 | VM_Operation::VMOp_Type SafepointTracing::_current_type; | ||||
| 1010 | jlong SafepointTracing::_max_sync_time = 0; | ||||
| 1011 | jlong SafepointTracing::_max_vmop_time = 0; | ||||
| 1012 | uint64_t SafepointTracing::_op_count[VM_Operation::VMOp_Terminating] = {0}; | ||||
| 1013 | |||||
| 1014 | void SafepointTracing::init() { | ||||
| 1015 | // Application start | ||||
| 1016 | _last_safepoint_end_time_ns = os::javaTimeNanos(); | ||||
| 1017 | } | ||||
| 1018 | |||||
| 1019 | // Helper method to print the header. | ||||
| 1020 | static void print_header(outputStream* st) { | ||||
| 1021 | // The number of spaces is significant here, and should match the format | ||||
| 1022 | // specifiers in print_statistics(). | ||||
| 1023 | |||||
| 1024 | st->print("VM Operation " | ||||
| 1025 | "[ threads: total initial_running ]" | ||||
| 1026 | "[ time: sync cleanup vmop total ]"); | ||||
| 1027 | |||||
| 1028 | st->print_cr(" page_trap_count"); | ||||
| 1029 | } | ||||
| 1030 | |||||
| 1031 | // This prints a nice table. To get the statistics to not shift due to the logging uptime | ||||
| 1032 | // decorator, use the option as: -Xlog:safepoint+stats:[outputfile]:none | ||||
| 1033 | void SafepointTracing::statistics_log() { | ||||
| 1034 | LogTarget(Info, safepoint, stats)LogTargetImpl<LogLevel::Info, (LogTag::_safepoint), (LogTag ::_stats), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG)> lt; | ||||
| 1035 | assert (lt.is_enabled(), "should only be called when printing statistics is enabled")do { if (!(lt.is_enabled())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/runtime/safepoint.cpp" , 1035, "assert(" "lt.is_enabled()" ") failed", "should only be called when printing statistics is enabled" ); ::breakpoint(); } } while (0); | ||||
| 1036 | LogStream ls(lt); | ||||
| 1037 | |||||
| 1038 | static int _cur_stat_index = 0; | ||||
| 1039 | |||||
| 1040 | // Print header every 30 entries | ||||
| 1041 | if ((_cur_stat_index % 30) == 0) { | ||||
| 1042 | print_header(&ls); | ||||
| 1043 | _cur_stat_index = 1; // wrap | ||||
| 1044 | } else { | ||||
| 1045 | _cur_stat_index++; | ||||
| 1046 | } | ||||
| 1047 | |||||
| 1048 | ls.print("%-28s [ " | ||||
| 1049 | INT32_FORMAT_W(8)"%" "8" "d" " " INT32_FORMAT_W(8)"%" "8" "d" " " | ||||
| 1050 | "]", | ||||
| 1051 | VM_Operation::name(_current_type), | ||||
| 1052 | _nof_threads, | ||||
| 1053 | _nof_running); | ||||
| 1054 | ls.print("[ " | ||||
| 1055 | INT64_FORMAT_W(10)"%" "10" "l" "d" " " INT64_FORMAT_W(10)"%" "10" "l" "d" " " | ||||
| 1056 | INT64_FORMAT_W(10)"%" "10" "l" "d" " " INT64_FORMAT_W(10)"%" "10" "l" "d" " ]", | ||||
| 1057 | (int64_t)(_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns), | ||||
| 1058 | (int64_t)(_last_safepoint_cleanup_time_ns - _last_safepoint_sync_time_ns), | ||||
| 1059 | (int64_t)(_last_safepoint_end_time_ns - _last_safepoint_cleanup_time_ns), | ||||
| 1060 | (int64_t)(_last_safepoint_end_time_ns - _last_safepoint_begin_time_ns)); | ||||
| 1061 | |||||
| 1062 | ls.print_cr(INT32_FORMAT_W(16)"%" "16" "d", _page_trap); | ||||
| 1063 | } | ||||
| 1064 | |||||
| 1065 | // This method will be called when VM exits. This tries to summarize the sampling. | ||||
| 1066 | // Current thread may already be deleted, so don't use ResourceMark. | ||||
| 1067 | void SafepointTracing::statistics_exit_log() { | ||||
| 1068 | if (!log_is_enabled(Info, safepoint, stats)(LogImpl<(LogTag::_safepoint), (LogTag::_stats), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Info))) { | ||||
| 1069 | return; | ||||
| 1070 | } | ||||
| 1071 | for (int index = 0; index < VM_Operation::VMOp_Terminating; index++) { | ||||
| 1072 | if (_op_count[index] != 0) { | ||||
| 1073 | log_info(safepoint, stats)(!(LogImpl<(LogTag::_safepoint), (LogTag::_stats), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) ? (void)0 : LogImpl <(LogTag::_safepoint), (LogTag::_stats), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Info>("%-28s" UINT64_FORMAT_W(10)"%" "10" "l" "u", VM_Operation::name(index), | ||||
| 1074 | _op_count[index]); | ||||
| 1075 | } | ||||
| 1076 | } | ||||
| 1077 | |||||
| 1078 | log_info(safepoint, stats)(!(LogImpl<(LogTag::_safepoint), (LogTag::_stats), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) ? (void)0 : LogImpl <(LogTag::_safepoint), (LogTag::_stats), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Info>("Maximum sync time " INT64_FORMAT"%" "l" "d"" ns", | ||||
| 1079 | (int64_t)(_max_sync_time)); | ||||
| 1080 | log_info(safepoint, stats)(!(LogImpl<(LogTag::_safepoint), (LogTag::_stats), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) ? (void)0 : LogImpl <(LogTag::_safepoint), (LogTag::_stats), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Info>("Maximum vm operation time (except for Exit VM operation) " | ||||
| 1081 | INT64_FORMAT"%" "l" "d" " ns", | ||||
| 1082 | (int64_t)(_max_vmop_time)); | ||||
| 1083 | } | ||||
| 1084 | |||||
| 1085 | void SafepointTracing::begin(VM_Operation::VMOp_Type type) { | ||||
| 1086 | _op_count[type]++; | ||||
| 1087 | _current_type = type; | ||||
| 1088 | |||||
| 1089 | // update the time stamp to begin recording safepoint time | ||||
| 1090 | _last_safepoint_begin_time_ns = os::javaTimeNanos(); | ||||
| 1091 | _last_safepoint_sync_time_ns = 0; | ||||
| 1092 | _last_safepoint_cleanup_time_ns = 0; | ||||
| 1093 | |||||
| 1094 | _last_app_time_ns = _last_safepoint_begin_time_ns - _last_safepoint_end_time_ns; | ||||
| 1095 | _last_safepoint_end_time_ns = 0; | ||||
| 1096 | |||||
| 1097 | RuntimeService::record_safepoint_begin(_last_app_time_ns); | ||||
| 1098 | } | ||||
| 1099 | |||||
| 1100 | void SafepointTracing::synchronized(int nof_threads, int nof_running, int traps) { | ||||
| 1101 | _last_safepoint_sync_time_ns = os::javaTimeNanos(); | ||||
| 1102 | _nof_threads = nof_threads; | ||||
| 1103 | _nof_running = nof_running; | ||||
| 1104 | _page_trap = traps; | ||||
| 1105 | RuntimeService::record_safepoint_synchronized(_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns); | ||||
| 1106 | } | ||||
| 1107 | |||||
| 1108 | void SafepointTracing::cleanup() { | ||||
| 1109 | _last_safepoint_cleanup_time_ns = os::javaTimeNanos(); | ||||
| 1110 | } | ||||
| 1111 | |||||
| 1112 | void SafepointTracing::end() { | ||||
| 1113 | _last_safepoint_end_time_ns = os::javaTimeNanos(); | ||||
| 1114 | |||||
| 1115 | if (_max_sync_time < (_last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns)) { | ||||
| 1116 | _max_sync_time = _last_safepoint_sync_time_ns - _last_safepoint_begin_time_ns; | ||||
| 1117 | } | ||||
| 1118 | if (_max_vmop_time < (_last_safepoint_end_time_ns - _last_safepoint_sync_time_ns)) { | ||||
| 1119 | _max_vmop_time = _last_safepoint_end_time_ns - _last_safepoint_sync_time_ns; | ||||
| 1120 | } | ||||
| 1121 | if (log_is_enabled(Info, safepoint, stats)(LogImpl<(LogTag::_safepoint), (LogTag::_stats), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Info))) { | ||||
| 1122 | statistics_log(); | ||||
| 1123 | } | ||||
| 1124 | |||||
| 1125 | log_info(safepoint)(!(LogImpl<(LogTag::_safepoint), (LogTag::__NO_TAG), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Info))) ? (void)0 : LogImpl <(LogTag::_safepoint), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Info>( | ||||
| 1126 | "Safepoint \"%s\", " | ||||
| 1127 | "Time since last: " JLONG_FORMAT"%" "l" "d" " ns, " | ||||
| 1128 | "Reaching safepoint: " JLONG_FORMAT"%" "l" "d" " ns, " | ||||
| 1129 | "At safepoint: " JLONG_FORMAT"%" "l" "d" " ns, " | ||||
| 1130 | "Total: " JLONG_FORMAT"%" "l" "d" " ns", | ||||
| 1131 | VM_Operation::name(_current_type), | ||||
| 1132 | _last_app_time_ns, | ||||
| 1133 | _last_safepoint_cleanup_time_ns - _last_safepoint_begin_time_ns, | ||||
| 1134 | _last_safepoint_end_time_ns - _last_safepoint_cleanup_time_ns, | ||||
| 1135 | _last_safepoint_end_time_ns - _last_safepoint_begin_time_ns | ||||
| 1136 | ); | ||||
| 1137 | |||||
| 1138 | RuntimeService::record_safepoint_end(_last_safepoint_end_time_ns - _last_safepoint_cleanup_time_ns); | ||||
| 1139 | } |
| 1 | /* | |||
| 2 | * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. | |||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |||
| 4 | * | |||
| 5 | * This code is free software; you can redistribute it and/or modify it | |||
| 6 | * under the terms of the GNU General Public License version 2 only, as | |||
| 7 | * published by the Free Software Foundation. | |||
| 8 | * | |||
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT | |||
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |||
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |||
| 12 | * version 2 for more details (a copy is included in the LICENSE file that | |||
| 13 | * accompanied this code). | |||
| 14 | * | |||
| 15 | * You should have received a copy of the GNU General Public License version | |||
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, | |||
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |||
| 18 | * | |||
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |||
| 20 | * or visit www.oracle.com if you need additional information or have any | |||
| 21 | * questions. | |||
| 22 | * | |||
| 23 | */ | |||
| 24 | ||||
| 25 | #ifndef CPU_X86_FRAME_X86_INLINE_HPP | |||
| 26 | #define CPU_X86_FRAME_X86_INLINE_HPP | |||
| 27 | ||||
| 28 | #include "code/codeCache.hpp" | |||
| 29 | #include "code/vmreg.inline.hpp" | |||
| 30 | #include "runtime/registerMap.hpp" | |||
| 31 | ||||
| 32 | // Inline functions for Intel frames: | |||
| 33 | ||||
| 34 | // Constructors: | |||
| 35 | ||||
| 36 | inline frame::frame() { | |||
| 37 | _pc = NULL__null; | |||
| 38 | _sp = NULL__null; | |||
| 39 | _unextended_sp = NULL__null; | |||
| 40 | _fp = NULL__null; | |||
| 41 | _cb = NULL__null; | |||
| 42 | _deopt_state = unknown; | |||
| 43 | } | |||
| 44 | ||||
| 45 | inline void frame::init(intptr_t* sp, intptr_t* fp, address pc) { | |||
| 46 | _sp = sp; | |||
| 47 | _unextended_sp = sp; | |||
| 48 | _fp = fp; | |||
| 49 | _pc = pc; | |||
| 50 | assert(pc != NULL, "no pc?")do { if (!(pc != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp" , 50, "assert(" "pc != __null" ") failed", "no pc?"); ::breakpoint (); } } while (0); | |||
| 51 | _cb = CodeCache::find_blob(pc); | |||
| 52 | adjust_unextended_sp(); | |||
| 53 | ||||
| 54 | address original_pc = CompiledMethod::get_deopt_original_pc(this); | |||
| 55 | if (original_pc != NULL__null) { | |||
| 56 | _pc = original_pc; | |||
| 57 | _deopt_state = is_deoptimized; | |||
| 58 | } else { | |||
| 59 | _deopt_state = not_deoptimized; | |||
| 60 | } | |||
| 61 | } | |||
| 62 | ||||
| 63 | inline frame::frame(intptr_t* sp, intptr_t* fp, address pc) { | |||
| 64 | init(sp, fp, pc); | |||
| 65 | } | |||
| 66 | ||||
| 67 | inline frame::frame(intptr_t* sp, intptr_t* unextended_sp, intptr_t* fp, address pc) { | |||
| 68 | _sp = sp; | |||
| 69 | _unextended_sp = unextended_sp; | |||
| 70 | _fp = fp; | |||
| 71 | _pc = pc; | |||
| 72 | assert(pc != NULL, "no pc?")do { if (!(pc != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp" , 72, "assert(" "pc != __null" ") failed", "no pc?"); ::breakpoint (); } } while (0); | |||
| 73 | _cb = CodeCache::find_blob(pc); | |||
| 74 | adjust_unextended_sp(); | |||
| 75 | ||||
| 76 | address original_pc = CompiledMethod::get_deopt_original_pc(this); | |||
| 77 | if (original_pc != NULL__null) { | |||
| 78 | _pc = original_pc; | |||
| 79 | assert(_cb->as_compiled_method()->insts_contains_inclusive(_pc),do { if (!(_cb->as_compiled_method()->insts_contains_inclusive (_pc))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp" , 80, "assert(" "_cb->as_compiled_method()->insts_contains_inclusive(_pc)" ") failed", "original PC must be in the main code section of the the compiled method (or must be immediately following it)" ); ::breakpoint(); } } while (0) | |||
| 80 | "original PC must be in the main code section of the the compiled method (or must be immediately following it)")do { if (!(_cb->as_compiled_method()->insts_contains_inclusive (_pc))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp" , 80, "assert(" "_cb->as_compiled_method()->insts_contains_inclusive(_pc)" ") failed", "original PC must be in the main code section of the the compiled method (or must be immediately following it)" ); ::breakpoint(); } } while (0); | |||
| 81 | _deopt_state = is_deoptimized; | |||
| 82 | } else { | |||
| 83 | if (_cb->is_deoptimization_stub()) { | |||
| 84 | _deopt_state = is_deoptimized; | |||
| 85 | } else { | |||
| 86 | _deopt_state = not_deoptimized; | |||
| 87 | } | |||
| 88 | } | |||
| 89 | } | |||
| 90 | ||||
| 91 | inline frame::frame(intptr_t* sp, intptr_t* fp) { | |||
| 92 | _sp = sp; | |||
| 93 | _unextended_sp = sp; | |||
| 94 | _fp = fp; | |||
| 95 | _pc = (address)(sp[-1]); | |||
| 96 | ||||
| 97 | // Here's a sticky one. This constructor can be called via AsyncGetCallTrace | |||
| 98 | // when last_Java_sp is non-null but the pc fetched is junk. If we are truly | |||
| 99 | // unlucky the junk value could be to a zombied method and we'll die on the | |||
| 100 | // find_blob call. This is also why we can have no asserts on the validity | |||
| 101 | // of the pc we find here. AsyncGetCallTrace -> pd_get_top_frame_for_signal_handler | |||
| 102 | // -> pd_last_frame should use a specialized version of pd_last_frame which could | |||
| 103 | // call a specialized frame constructor instead of this one. | |||
| 104 | // Then we could use the assert below. However this assert is of somewhat dubious | |||
| 105 | // value. | |||
| 106 | // UPDATE: this constructor is only used by trace_method_handle_stub() now. | |||
| 107 | // assert(_pc != NULL, "no pc?"); | |||
| 108 | ||||
| 109 | _cb = CodeCache::find_blob(_pc); | |||
| 110 | adjust_unextended_sp(); | |||
| 111 | ||||
| 112 | address original_pc = CompiledMethod::get_deopt_original_pc(this); | |||
| 113 | if (original_pc != NULL__null) { | |||
| 114 | _pc = original_pc; | |||
| 115 | _deopt_state = is_deoptimized; | |||
| 116 | } else { | |||
| 117 | _deopt_state = not_deoptimized; | |||
| 118 | } | |||
| 119 | } | |||
| 120 | ||||
| 121 | // Accessors | |||
| 122 | ||||
| 123 | inline bool frame::equal(frame other) const { | |||
| 124 | bool ret = sp() == other.sp() | |||
| 125 | && unextended_sp() == other.unextended_sp() | |||
| 126 | && fp() == other.fp() | |||
| 127 | && pc() == other.pc(); | |||
| 128 | assert(!ret || ret && cb() == other.cb() && _deopt_state == other._deopt_state, "inconsistent construction")do { if (!(!ret || ret && cb() == other.cb() && _deopt_state == other._deopt_state)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp" , 128, "assert(" "!ret || ret && cb() == other.cb() && _deopt_state == other._deopt_state" ") failed", "inconsistent construction"); ::breakpoint(); } } while (0); | |||
| 129 | return ret; | |||
| 130 | } | |||
| 131 | ||||
| 132 | // Return unique id for this frame. The id must have a value where we can distinguish | |||
| 133 | // identity and younger/older relationship. NULL represents an invalid (incomparable) | |||
| 134 | // frame. | |||
| 135 | inline intptr_t* frame::id(void) const { return unextended_sp(); } | |||
| 136 | ||||
| 137 | // Return true if the frame is older (less recent activation) than the frame represented by id | |||
| 138 | inline bool frame::is_older(intptr_t* id) const { assert(this->id() != NULL && id != NULL, "NULL frame id")do { if (!(this->id() != __null && id != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp" , 138, "assert(" "this->id() != __null && id != __null" ") failed", "NULL frame id"); ::breakpoint(); } } while (0); | |||
| 139 | return this->id() > id ; } | |||
| 140 | ||||
| 141 | ||||
| 142 | ||||
| 143 | inline intptr_t* frame::link() const { return (intptr_t*) *(intptr_t **)addr_at(link_offset); } | |||
| 144 | ||||
| 145 | inline intptr_t* frame::unextended_sp() const { return _unextended_sp; } | |||
| 146 | ||||
| 147 | // Return address: | |||
| 148 | ||||
| 149 | inline address* frame::sender_pc_addr() const { return (address*) addr_at( return_addr_offset); } | |||
| 150 | inline address frame::sender_pc() const { return *sender_pc_addr(); } | |||
| 151 | ||||
| 152 | inline intptr_t* frame::sender_sp() const { return addr_at( sender_sp_offset); } | |||
| 153 | ||||
| 154 | inline intptr_t** frame::interpreter_frame_locals_addr() const { | |||
| 155 | return (intptr_t**)addr_at(interpreter_frame_locals_offset); | |||
| 156 | } | |||
| 157 | ||||
| 158 | inline intptr_t* frame::interpreter_frame_last_sp() const { | |||
| 159 | return *(intptr_t**)addr_at(interpreter_frame_last_sp_offset); | |||
| 160 | } | |||
| 161 | ||||
| 162 | inline intptr_t* frame::interpreter_frame_bcp_addr() const { | |||
| 163 | return (intptr_t*)addr_at(interpreter_frame_bcp_offset); | |||
| 164 | } | |||
| 165 | ||||
| 166 | ||||
| 167 | inline intptr_t* frame::interpreter_frame_mdp_addr() const { | |||
| 168 | return (intptr_t*)addr_at(interpreter_frame_mdp_offset); | |||
| 169 | } | |||
| 170 | ||||
| 171 | ||||
| 172 | ||||
| 173 | // Constant pool cache | |||
| 174 | ||||
| 175 | inline ConstantPoolCache** frame::interpreter_frame_cache_addr() const { | |||
| 176 | return (ConstantPoolCache**)addr_at(interpreter_frame_cache_offset); | |||
| 177 | } | |||
| 178 | ||||
| 179 | // Method | |||
| 180 | ||||
| 181 | inline Method** frame::interpreter_frame_method_addr() const { | |||
| 182 | return (Method**)addr_at(interpreter_frame_method_offset); | |||
| 183 | } | |||
| 184 | ||||
| 185 | // Mirror | |||
| 186 | ||||
| 187 | inline oop* frame::interpreter_frame_mirror_addr() const { | |||
| 188 | return (oop*)addr_at(interpreter_frame_mirror_offset); | |||
| 189 | } | |||
| 190 | ||||
| 191 | // top of expression stack | |||
| 192 | inline intptr_t* frame::interpreter_frame_tos_address() const { | |||
| 193 | intptr_t* last_sp = interpreter_frame_last_sp(); | |||
| 194 | if (last_sp == NULL__null) { | |||
| 195 | return sp(); | |||
| 196 | } else { | |||
| 197 | // sp() may have been extended or shrunk by an adapter. At least | |||
| 198 | // check that we don't fall behind the legal region. | |||
| 199 | // For top deoptimized frame last_sp == interpreter_frame_monitor_end. | |||
| 200 | assert(last_sp <= (intptr_t*) interpreter_frame_monitor_end(), "bad tos")do { if (!(last_sp <= (intptr_t*) interpreter_frame_monitor_end ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp" , 200, "assert(" "last_sp <= (intptr_t*) interpreter_frame_monitor_end()" ") failed", "bad tos"); ::breakpoint(); } } while (0); | |||
| 201 | return last_sp; | |||
| 202 | } | |||
| 203 | } | |||
| 204 | ||||
| 205 | inline oop* frame::interpreter_frame_temp_oop_addr() const { | |||
| 206 | return (oop *)(fp() + interpreter_frame_oop_temp_offset); | |||
| 207 | } | |||
| 208 | ||||
| 209 | inline int frame::interpreter_frame_monitor_size() { | |||
| 210 | return BasicObjectLock::size(); | |||
| 211 | } | |||
| 212 | ||||
| 213 | ||||
| 214 | // expression stack | |||
| 215 | // (the max_stack arguments are used by the GC; see class FrameClosure) | |||
| 216 | ||||
| 217 | inline intptr_t* frame::interpreter_frame_expression_stack() const { | |||
| 218 | intptr_t* monitor_end = (intptr_t*) interpreter_frame_monitor_end(); | |||
| 219 | return monitor_end-1; | |||
| 220 | } | |||
| 221 | ||||
| 222 | // Entry frames | |||
| 223 | ||||
| 224 | inline JavaCallWrapper** frame::entry_frame_call_wrapper_addr() const { | |||
| 225 | return (JavaCallWrapper**)addr_at(entry_frame_call_wrapper_offset); | |||
| 226 | } | |||
| 227 | ||||
| 228 | // Compiled frames | |||
| 229 | ||||
| 230 | // Register is a class, but it would be assigned numerical value. | |||
| 231 | // "0" is assigned for rax. Thus we need to ignore -Wnonnull. | |||
| 232 | PRAGMA_DIAG_PUSHGCC diagnostic push | |||
| 233 | PRAGMA_NONNULL_IGNOREDGCC diagnostic ignored "-Wnonnull" | |||
| 234 | inline oop frame::saved_oop_result(RegisterMap* map) const { | |||
| 235 | oop* result_adr = (oop *)map->location(rax->as_VMReg()); | |||
| ||||
| 236 | guarantee(result_adr != NULL, "bad register save location")do { if (!(result_adr != __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp" , 236, "guarantee(" "result_adr != NULL" ") failed", "bad register save location" ); ::breakpoint(); } } while (0); | |||
| 237 | ||||
| 238 | return (*result_adr); | |||
| 239 | } | |||
| 240 | ||||
| 241 | inline void frame::set_saved_oop_result(RegisterMap* map, oop obj) { | |||
| 242 | oop* result_adr = (oop *)map->location(rax->as_VMReg()); | |||
| 243 | guarantee(result_adr != NULL, "bad register save location")do { if (!(result_adr != __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/cpu/x86/frame_x86.inline.hpp" , 243, "guarantee(" "result_adr != NULL" ") failed", "bad register save location" ); ::breakpoint(); } } while (0); | |||
| 244 | ||||
| 245 | *result_adr = obj; | |||
| 246 | } | |||
| 247 | PRAGMA_DIAG_POPGCC diagnostic pop | |||
| 248 | ||||
| 249 | #endif // CPU_X86_FRAME_X86_INLINE_HPP |