1 /*
2 * Copyright (c) 1997, 2018, 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 SHARE_VM_RUNTIME_THREAD_HPP
26 #define SHARE_VM_RUNTIME_THREAD_HPP
27
28 #include "jni.h"
29 #include "gc/shared/threadLocalAllocBuffer.hpp"
30 #include "memory/allocation.hpp"
31 #include "oops/oop.hpp"
32 #include "prims/jvmtiExport.hpp"
33 #include "runtime/frame.hpp"
34 #include "runtime/handshake.hpp"
35 #include "runtime/javaFrameAnchor.hpp"
36 #include "runtime/jniHandles.hpp"
37 #include "runtime/mutexLocker.hpp"
38 #include "runtime/os.hpp"
39 #include "runtime/osThread.hpp"
40 #include "runtime/park.hpp"
41 #include "runtime/safepoint.hpp"
42 #include "runtime/stubRoutines.hpp"
43 #include "runtime/threadLocalStorage.hpp"
44 #include "runtime/unhandledOops.hpp"
45 #include "trace/traceBackend.hpp"
46 #include "trace/traceMacros.hpp"
47 #include "utilities/align.hpp"
48 #include "utilities/exceptions.hpp"
49 #include "utilities/macros.hpp"
50 #if INCLUDE_ALL_GCS
51 #include "gc/g1/dirtyCardQueue.hpp"
52 #include "gc/g1/satbMarkQueue.hpp"
53 #endif // INCLUDE_ALL_GCS
54 #ifdef ZERO
55 # include "stack_zero.hpp"
56 #endif
57
58 class ThreadSafepointState;
59 class ThreadsList;
60 class ThreadsSMRSupport;
61 class NestedThreadsList;
62
305 // (Hence, !allow_safepoint() => !allow_allocation()).
306 //
307 // The two classes NoSafepointVerifier and No_Allocation_Verifier are used to set these counters.
308 //
309 NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen
310 debug_only(int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops.
311
312 // Used by SkipGCALot class.
313 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot?
314
315 friend class NoAllocVerifier;
316 friend class NoSafepointVerifier;
317 friend class PauseNoSafepointVerifier;
318 friend class GCLocker;
319
320 volatile void* _polling_page; // Thread local polling page
321
322 ThreadLocalAllocBuffer _tlab; // Thread-local eden
323 jlong _allocated_bytes; // Cumulative number of bytes allocated on
324 // the Java heap
325
326 mutable TRACE_DATA _trace_data; // Thread-local data for tracing
327
328 int _vm_operation_started_count; // VM_Operation support
329 int _vm_operation_completed_count; // VM_Operation support
330
331 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
332 // is waiting to lock
333 bool _current_pending_monitor_is_from_java; // locking is from Java code
334
335 // ObjectMonitor on which this thread called Object.wait()
336 ObjectMonitor* _current_waiting_monitor;
337
338 // Private thread-local objectmonitor list - a simple cache organized as a SLL.
339 public:
340 ObjectMonitor* omFreeList;
341 int omFreeCount; // length of omFreeList
342 int omFreeProvision; // reload chunk size
343 ObjectMonitor* omInUseList; // SLL to track monitors in circulation
344 int omInUseCount; // length of omInUseList
484 // Internal handle support
485 HandleArea* handle_area() const { return _handle_area; }
486 void set_handle_area(HandleArea* area) { _handle_area = area; }
487
488 GrowableArray<Metadata*>* metadata_handles() const { return _metadata_handles; }
489 void set_metadata_handles(GrowableArray<Metadata*>* handles){ _metadata_handles = handles; }
490
491 // Thread-Local Allocation Buffer (TLAB) support
492 ThreadLocalAllocBuffer& tlab() { return _tlab; }
493 void initialize_tlab() {
494 if (UseTLAB) {
495 tlab().initialize();
496 }
497 }
498
499 jlong allocated_bytes() { return _allocated_bytes; }
500 void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
501 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
502 inline jlong cooked_allocated_bytes();
503
504 TRACE_DEFINE_THREAD_TRACE_DATA_OFFSET;
505 TRACE_DATA* trace_data() const { return &_trace_data; }
506 bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; }
507
508 // VM operation support
509 int vm_operation_ticket() { return ++_vm_operation_started_count; }
510 int vm_operation_completed_count() { return _vm_operation_completed_count; }
511 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
512
513 // For tracking the heavyweight monitor the thread is pending on.
514 ObjectMonitor* current_pending_monitor() {
515 return _current_pending_monitor;
516 }
517 void set_current_pending_monitor(ObjectMonitor* monitor) {
518 _current_pending_monitor = monitor;
519 }
520 void set_current_pending_monitor_is_from_java(bool from_java) {
521 _current_pending_monitor_is_from_java = from_java;
522 }
523 bool current_pending_monitor_is_from_java() {
655
656 public:
657 void entering_jvmti_env_iteration() { ++_jvmti_env_iteration_count; }
658 void leaving_jvmti_env_iteration() { --_jvmti_env_iteration_count; }
659 bool is_inside_jvmti_env_iteration() { return _jvmti_env_iteration_count > 0; }
660
661 // Code generation
662 static ByteSize exception_file_offset() { return byte_offset_of(Thread, _exception_file); }
663 static ByteSize exception_line_offset() { return byte_offset_of(Thread, _exception_line); }
664 static ByteSize active_handles_offset() { return byte_offset_of(Thread, _active_handles); }
665
666 static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base); }
667 static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size); }
668
669 static ByteSize polling_page_offset() { return byte_offset_of(Thread, _polling_page); }
670
671 #define TLAB_FIELD_OFFSET(name) \
672 static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
673
674 TLAB_FIELD_OFFSET(start)
675 TLAB_FIELD_OFFSET(end)
676 TLAB_FIELD_OFFSET(top)
677 TLAB_FIELD_OFFSET(pf_top)
678 TLAB_FIELD_OFFSET(size) // desired_size
679 TLAB_FIELD_OFFSET(refill_waste_limit)
680 TLAB_FIELD_OFFSET(number_of_refills)
681 TLAB_FIELD_OFFSET(fast_refill_waste)
682 TLAB_FIELD_OFFSET(slow_allocations)
683
684 #undef TLAB_FIELD_OFFSET
685
686 static ByteSize allocated_bytes_offset() { return byte_offset_of(Thread, _allocated_bytes); }
687
688 public:
689 volatile intptr_t _Stalled;
690 volatile int _TypeTag;
691 ParkEvent * _ParkEvent; // for synchronized()
692 ParkEvent * _SleepEvent; // for Thread.sleep
693 ParkEvent * _MutexEvent; // for native internal Mutex/Monitor
694 ParkEvent * _MuxEvent; // for low-level muxAcquire-muxRelease
695 int NativeSyncRecursion; // diagnostic
|
1 /*
2 * Copyright (c) 1997, 2017, 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 SHARE_VM_RUNTIME_THREAD_HPP
26 #define SHARE_VM_RUNTIME_THREAD_HPP
27
28 #include "jni.h"
29 #include "gc/shared/threadLocalAllocBuffer.hpp"
30 #include "memory/allocation.hpp"
31 #include "oops/oop.hpp"
32 #include "prims/jvmtiExport.hpp"
33 #include "runtime/frame.hpp"
34 #include "runtime/handshake.hpp"
35 #include "runtime/javaFrameAnchor.hpp"
36 #include "runtime/jniHandles.hpp"
37 #include "runtime/mutexLocker.hpp"
38 #include "runtime/os.hpp"
39 #include "runtime/osThread.hpp"
40 #include "runtime/park.hpp"
41 #include "runtime/safepoint.hpp"
42 #include "runtime/stubRoutines.hpp"
43 #include "runtime/threadHeapSampler.hpp"
44 #include "runtime/threadLocalStorage.hpp"
45 #include "runtime/unhandledOops.hpp"
46 #include "trace/traceBackend.hpp"
47 #include "trace/traceMacros.hpp"
48 #include "utilities/align.hpp"
49 #include "utilities/exceptions.hpp"
50 #include "utilities/macros.hpp"
51 #if INCLUDE_ALL_GCS
52 #include "gc/g1/dirtyCardQueue.hpp"
53 #include "gc/g1/satbMarkQueue.hpp"
54 #endif // INCLUDE_ALL_GCS
55 #ifdef ZERO
56 # include "stack_zero.hpp"
57 #endif
58
59 class ThreadSafepointState;
60 class ThreadsList;
61 class ThreadsSMRSupport;
62 class NestedThreadsList;
63
306 // (Hence, !allow_safepoint() => !allow_allocation()).
307 //
308 // The two classes NoSafepointVerifier and No_Allocation_Verifier are used to set these counters.
309 //
310 NOT_PRODUCT(int _allow_safepoint_count;) // If 0, thread allow a safepoint to happen
311 debug_only(int _allow_allocation_count;) // If 0, the thread is allowed to allocate oops.
312
313 // Used by SkipGCALot class.
314 NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot?
315
316 friend class NoAllocVerifier;
317 friend class NoSafepointVerifier;
318 friend class PauseNoSafepointVerifier;
319 friend class GCLocker;
320
321 volatile void* _polling_page; // Thread local polling page
322
323 ThreadLocalAllocBuffer _tlab; // Thread-local eden
324 jlong _allocated_bytes; // Cumulative number of bytes allocated on
325 // the Java heap
326 ThreadHeapSampler _heap_sampler; // For use when sampling the memory.
327
328 mutable TRACE_DATA _trace_data; // Thread-local data for tracing
329
330 int _vm_operation_started_count; // VM_Operation support
331 int _vm_operation_completed_count; // VM_Operation support
332
333 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
334 // is waiting to lock
335 bool _current_pending_monitor_is_from_java; // locking is from Java code
336
337 // ObjectMonitor on which this thread called Object.wait()
338 ObjectMonitor* _current_waiting_monitor;
339
340 // Private thread-local objectmonitor list - a simple cache organized as a SLL.
341 public:
342 ObjectMonitor* omFreeList;
343 int omFreeCount; // length of omFreeList
344 int omFreeProvision; // reload chunk size
345 ObjectMonitor* omInUseList; // SLL to track monitors in circulation
346 int omInUseCount; // length of omInUseList
486 // Internal handle support
487 HandleArea* handle_area() const { return _handle_area; }
488 void set_handle_area(HandleArea* area) { _handle_area = area; }
489
490 GrowableArray<Metadata*>* metadata_handles() const { return _metadata_handles; }
491 void set_metadata_handles(GrowableArray<Metadata*>* handles){ _metadata_handles = handles; }
492
493 // Thread-Local Allocation Buffer (TLAB) support
494 ThreadLocalAllocBuffer& tlab() { return _tlab; }
495 void initialize_tlab() {
496 if (UseTLAB) {
497 tlab().initialize();
498 }
499 }
500
501 jlong allocated_bytes() { return _allocated_bytes; }
502 void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
503 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
504 inline jlong cooked_allocated_bytes();
505
506 ThreadHeapSampler& heap_sampler() { return _heap_sampler; }
507
508 TRACE_DEFINE_THREAD_TRACE_DATA_OFFSET;
509 TRACE_DATA* trace_data() const { return &_trace_data; }
510 bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; }
511
512 // VM operation support
513 int vm_operation_ticket() { return ++_vm_operation_started_count; }
514 int vm_operation_completed_count() { return _vm_operation_completed_count; }
515 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
516
517 // For tracking the heavyweight monitor the thread is pending on.
518 ObjectMonitor* current_pending_monitor() {
519 return _current_pending_monitor;
520 }
521 void set_current_pending_monitor(ObjectMonitor* monitor) {
522 _current_pending_monitor = monitor;
523 }
524 void set_current_pending_monitor_is_from_java(bool from_java) {
525 _current_pending_monitor_is_from_java = from_java;
526 }
527 bool current_pending_monitor_is_from_java() {
659
660 public:
661 void entering_jvmti_env_iteration() { ++_jvmti_env_iteration_count; }
662 void leaving_jvmti_env_iteration() { --_jvmti_env_iteration_count; }
663 bool is_inside_jvmti_env_iteration() { return _jvmti_env_iteration_count > 0; }
664
665 // Code generation
666 static ByteSize exception_file_offset() { return byte_offset_of(Thread, _exception_file); }
667 static ByteSize exception_line_offset() { return byte_offset_of(Thread, _exception_line); }
668 static ByteSize active_handles_offset() { return byte_offset_of(Thread, _active_handles); }
669
670 static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base); }
671 static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size); }
672
673 static ByteSize polling_page_offset() { return byte_offset_of(Thread, _polling_page); }
674
675 #define TLAB_FIELD_OFFSET(name) \
676 static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
677
678 TLAB_FIELD_OFFSET(start)
679 TLAB_FIELD_OFFSET(current_end)
680 TLAB_FIELD_OFFSET(top)
681 TLAB_FIELD_OFFSET(pf_top)
682 TLAB_FIELD_OFFSET(size) // desired_size
683 TLAB_FIELD_OFFSET(refill_waste_limit)
684 TLAB_FIELD_OFFSET(number_of_refills)
685 TLAB_FIELD_OFFSET(fast_refill_waste)
686 TLAB_FIELD_OFFSET(slow_allocations)
687
688 #undef TLAB_FIELD_OFFSET
689
690 static ByteSize allocated_bytes_offset() { return byte_offset_of(Thread, _allocated_bytes); }
691
692 public:
693 volatile intptr_t _Stalled;
694 volatile int _TypeTag;
695 ParkEvent * _ParkEvent; // for synchronized()
696 ParkEvent * _SleepEvent; // for Thread.sleep
697 ParkEvent * _MutexEvent; // for native internal Mutex/Monitor
698 ParkEvent * _MuxEvent; // for low-level muxAcquire-muxRelease
699 int NativeSyncRecursion; // diagnostic
|