comparison src/share/vm/runtime/thread.hpp @ 1930:2d26b0046e0d

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 30 Nov 2010 14:53:30 +0100
parents abc670a709dc fa83ab460c54
children 06f017f7daa7
comparison
equal deleted inserted replaced
1484:6b7001391c97 1930:2d26b0046e0d
1 /* 1 /*
2 * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
14 * 14 *
15 * You should have received a copy of the GNU General Public License version 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, 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. 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * CA 95054 USA or visit www.sun.com if you need additional information or 20 * or visit www.oracle.com if you need additional information or have any
21 * have any questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 class ThreadSafepointState; 25 class ThreadSafepointState;
26 class ThreadProfiler; 26 class ThreadProfiler;
28 class JvmtiThreadState; 28 class JvmtiThreadState;
29 class JvmtiGetLoadedClassesClosure; 29 class JvmtiGetLoadedClassesClosure;
30 class ThreadStatistics; 30 class ThreadStatistics;
31 class ConcurrentLocksDump; 31 class ConcurrentLocksDump;
32 class ParkEvent ; 32 class ParkEvent ;
33 class Parker;
33 34
34 class ciEnv; 35 class ciEnv;
35 class CompileThread; 36 class CompileThread;
36 class CompileLog; 37 class CompileLog;
37 class CompileTask; 38 class CompileTask;
223 // Private thread-local objectmonitor list - a simple cache organized as a SLL. 224 // Private thread-local objectmonitor list - a simple cache organized as a SLL.
224 public: 225 public:
225 ObjectMonitor * omFreeList ; 226 ObjectMonitor * omFreeList ;
226 int omFreeCount ; // length of omFreeList 227 int omFreeCount ; // length of omFreeList
227 int omFreeProvision ; // reload chunk size 228 int omFreeProvision ; // reload chunk size
229 ObjectMonitor * omInUseList; // SLL to track monitors in circulation
230 int omInUseCount; // length of omInUseList
228 231
229 public: 232 public:
230 enum { 233 enum {
231 is_definitely_current_thread = true 234 is_definitely_current_thread = true
232 }; 235 };
266 static ThreadPriority get_priority(const Thread* const thread); 269 static ThreadPriority get_priority(const Thread* const thread);
267 static void start(Thread* thread); 270 static void start(Thread* thread);
268 static void interrupt(Thread* thr); 271 static void interrupt(Thread* thr);
269 static bool is_interrupted(Thread* thr, bool clear_interrupted); 272 static bool is_interrupted(Thread* thr, bool clear_interrupted);
270 273
274 ObjectMonitor** omInUseList_addr() { return (ObjectMonitor **)&omInUseList; }
271 Monitor* SR_lock() const { return _SR_lock; } 275 Monitor* SR_lock() const { return _SR_lock; }
272 276
273 bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; } 277 bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; }
274 278
275 void set_suspend_flag(SuspendFlags f) { 279 void set_suspend_flag(SuspendFlags f) {
405 } 409 }
406 410
407 // Sweeper support 411 // Sweeper support
408 void nmethods_do(CodeBlobClosure* cf); 412 void nmethods_do(CodeBlobClosure* cf);
409 413
410 // Tells if adr belong to this thread. This is used
411 // for checking if a lock is owned by the running thread.
412
413 // Used by fast lock support 414 // Used by fast lock support
414 virtual bool is_lock_owned(address adr) const; 415 virtual bool is_lock_owned(address adr) const;
415 416
416 // Check if address is in the stack of the thread (not just for locks). 417 // Check if address is in the stack of the thread (not just for locks).
417 // Warning: the method can only be used on the running thread 418 // Warning: the method can only be used on the running thread
443 444
444 void set_stack_base(address base) { _stack_base = base; } 445 void set_stack_base(address base) { _stack_base = base; }
445 size_t stack_size() const { return _stack_size; } 446 size_t stack_size() const { return _stack_size; }
446 void set_stack_size(size_t size) { _stack_size = size; } 447 void set_stack_size(size_t size) { _stack_size = size; }
447 void record_stack_base_and_size(); 448 void record_stack_base_and_size();
449
450 bool on_local_stack(address adr) const {
451 /* QQQ this has knowledge of direction, ought to be a stack method */
452 return (_stack_base >= adr && adr >= (_stack_base - _stack_size));
453 }
448 454
449 int lgrp_id() const { return _lgrp_id; } 455 int lgrp_id() const { return _lgrp_id; }
450 void set_lgrp_id(int value) { _lgrp_id = value; } 456 void set_lgrp_id(int value) { _lgrp_id = value; }
451 457
452 // Printing 458 // Printing
491 static ByteSize exception_line_offset() { return byte_offset_of(Thread, _exception_line ); } 497 static ByteSize exception_line_offset() { return byte_offset_of(Thread, _exception_line ); }
492 static ByteSize active_handles_offset() { return byte_offset_of(Thread, _active_handles ); } 498 static ByteSize active_handles_offset() { return byte_offset_of(Thread, _active_handles ); }
493 499
494 static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base ); } 500 static ByteSize stack_base_offset() { return byte_offset_of(Thread, _stack_base ); }
495 static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size ); } 501 static ByteSize stack_size_offset() { return byte_offset_of(Thread, _stack_size ); }
496 static ByteSize omFreeList_offset() { return byte_offset_of(Thread, omFreeList); }
497 502
498 #define TLAB_FIELD_OFFSET(name) \ 503 #define TLAB_FIELD_OFFSET(name) \
499 static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); } 504 static ByteSize tlab_##name##_offset() { return byte_offset_of(Thread, _tlab) + ThreadLocalAllocBuffer::name##_offset(); }
500 505
501 TLAB_FIELD_OFFSET(start) 506 TLAB_FIELD_OFFSET(start)
538 static void SpinAcquire (volatile int * Lock, const char * Name) ; 543 static void SpinAcquire (volatile int * Lock, const char * Name) ;
539 static void SpinRelease (volatile int * Lock) ; 544 static void SpinRelease (volatile int * Lock) ;
540 static void muxAcquire (volatile intptr_t * Lock, const char * Name) ; 545 static void muxAcquire (volatile intptr_t * Lock, const char * Name) ;
541 static void muxAcquireW (volatile intptr_t * Lock, ParkEvent * ev) ; 546 static void muxAcquireW (volatile intptr_t * Lock, ParkEvent * ev) ;
542 static void muxRelease (volatile intptr_t * Lock) ; 547 static void muxRelease (volatile intptr_t * Lock) ;
543
544 }; 548 };
545 549
546 // Inline implementation of Thread::current() 550 // Inline implementation of Thread::current()
547 // Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of 551 // Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of
548 // startup. 552 // startup.
605 virtual void run(); 609 virtual void run();
606 610
607 private: 611 private:
608 static WatcherThread* _watcher_thread; 612 static WatcherThread* _watcher_thread;
609 613
610 static bool _should_terminate; 614 volatile static bool _should_terminate; // updated without holding lock
611 public: 615 public:
612 enum SomeConstants { 616 enum SomeConstants {
613 delay_interval = 10 // interrupt delay in milliseconds 617 delay_interval = 10 // interrupt delay in milliseconds
614 }; 618 };
615 619
674 // Deopt support 678 // Deopt support
675 DeoptResourceMark* _deopt_mark; // Holds special ResourceMark for deoptimization 679 DeoptResourceMark* _deopt_mark; // Holds special ResourceMark for deoptimization
676 680
677 intptr_t* _must_deopt_id; // id of frame that needs to be deopted once we 681 intptr_t* _must_deopt_id; // id of frame that needs to be deopted once we
678 // transition out of native 682 // transition out of native
679 683 nmethod* _deopt_nmethod; // nmethod that is currently being deoptimized
680 vframeArray* _vframe_array_head; // Holds the heap of the active vframeArrays 684 vframeArray* _vframe_array_head; // Holds the heap of the active vframeArrays
681 vframeArray* _vframe_array_last; // Holds last vFrameArray we popped 685 vframeArray* _vframe_array_last; // Holds last vFrameArray we popped
682 // Because deoptimization is lazy we must save jvmti requests to set locals 686 // Because deoptimization is lazy we must save jvmti requests to set locals
683 // in compiled frames until we deoptimize and we have an interpreter frame. 687 // in compiled frames until we deoptimize and we have an interpreter frame.
684 // This holds the pointer to array (yeah like there might be more than one) of 688 // This holds the pointer to array (yeah like there might be more than one) of
837 _jni_environment.functions = functionTable; 841 _jni_environment.functions = functionTable;
838 } 842 }
839 struct JNINativeInterface_* get_jni_functions() { 843 struct JNINativeInterface_* get_jni_functions() {
840 return (struct JNINativeInterface_ *)_jni_environment.functions; 844 return (struct JNINativeInterface_ *)_jni_environment.functions;
841 } 845 }
846
847 // This function is called at thread creation to allow
848 // platform specific thread variables to be initialized.
849 void cache_global_variables();
842 850
843 // Executes Shutdown.shutdown() 851 // Executes Shutdown.shutdown()
844 void invoke_shutdown_hooks(); 852 void invoke_shutdown_hooks();
845 853
846 // Cleanup on thread exit 854 // Cleanup on thread exit
1090 DeoptResourceMark* deopt_mark(void) { return _deopt_mark; } 1098 DeoptResourceMark* deopt_mark(void) { return _deopt_mark; }
1091 1099
1092 intptr_t* must_deopt_id() { return _must_deopt_id; } 1100 intptr_t* must_deopt_id() { return _must_deopt_id; }
1093 void set_must_deopt_id(intptr_t* id) { _must_deopt_id = id; } 1101 void set_must_deopt_id(intptr_t* id) { _must_deopt_id = id; }
1094 void clear_must_deopt_id() { _must_deopt_id = NULL; } 1102 void clear_must_deopt_id() { _must_deopt_id = NULL; }
1103
1104 void set_deopt_nmethod(nmethod* nm) { _deopt_nmethod = nm; }
1105 nmethod* deopt_nmethod() { return _deopt_nmethod; }
1095 1106
1096 methodOop callee_target() const { return _callee_target; } 1107 methodOop callee_target() const { return _callee_target; }
1097 void set_callee_target (methodOop x) { _callee_target = x; } 1108 void set_callee_target (methodOop x) { _callee_target = x; }
1098 1109
1099 // Oop results of vm runtime calls 1110 // Oop results of vm runtime calls
1481 static DirtyCardQueueSet& dirty_card_queue_set() { 1492 static DirtyCardQueueSet& dirty_card_queue_set() {
1482 return _dirty_card_queue_set; 1493 return _dirty_card_queue_set;
1483 } 1494 }
1484 #endif // !SERIALGC 1495 #endif // !SERIALGC
1485 1496
1497 // This method initializes the SATB and dirty card queues before a
1498 // JavaThread is added to the Java thread list. Right now, we don't
1499 // have to do anything to the dirty card queue (it should have been
1500 // activated when the thread was created), but we have to activate
1501 // the SATB queue if the thread is created while a marking cycle is
1502 // in progress. The activation / de-activation of the SATB queues at
1503 // the beginning / end of a marking cycle is done during safepoints
1504 // so we have to make sure this method is called outside one to be
1505 // able to safely read the active field of the SATB queue set. Right
1506 // now, it is called just before the thread is added to the Java
1507 // thread list in the Threads::add() method. That method is holding
1508 // the Threads_lock which ensures we are outside a safepoint. We
1509 // cannot do the obvious and set the active field of the SATB queue
1510 // when the thread is created given that, in some cases, safepoints
1511 // might happen between the JavaThread constructor being called and the
1512 // thread being added to the Java thread list (an example of this is
1513 // when the structure for the DestroyJavaVM thread is created).
1514 #ifndef SERIALGC
1515 void initialize_queues();
1516 #else // !SERIALGC
1517 void initialize_queues() { }
1518 #endif // !SERIALGC
1519
1486 // Machine dependent stuff 1520 // Machine dependent stuff
1487 #include "incls/_thread_pd.hpp.incl" 1521 #include "incls/_thread_pd.hpp.incl"
1488 1522
1489 public: 1523 public:
1490 void set_blocked_on_compilation(bool value) { 1524 void set_blocked_on_compilation(bool value) {
1579 ciEnv* _env; 1613 ciEnv* _env;
1580 CompileLog* _log; 1614 CompileLog* _log;
1581 CompileTask* _task; 1615 CompileTask* _task;
1582 CompileQueue* _queue; 1616 CompileQueue* _queue;
1583 bool _is_compiling; 1617 bool _is_compiling;
1618 BufferBlob* _buffer_blob;
1584 1619
1585 public: 1620 public:
1586 1621
1587 static CompilerThread* current(); 1622 static CompilerThread* current();
1588 1623
1598 CompilerCounters* counters() { return _counters; } 1633 CompilerCounters* counters() { return _counters; }
1599 1634
1600 // Get/set the thread's compilation environment. 1635 // Get/set the thread's compilation environment.
1601 ciEnv* env() { return _env; } 1636 ciEnv* env() { return _env; }
1602 void set_env(ciEnv* env) { _env = env; } 1637 void set_env(ciEnv* env) { _env = env; }
1638
1639 BufferBlob* get_buffer_blob() { return _buffer_blob; }
1640 void set_buffer_blob(BufferBlob* b) { _buffer_blob = b; };
1603 1641
1604 // Get/set the thread's logging information 1642 // Get/set the thread's logging information
1605 CompileLog* log() { return _log; } 1643 CompileLog* log() { return _log; }
1606 void init_log(CompileLog* log) { 1644 void init_log(CompileLog* log) {
1607 // Set once, for good. 1645 // Set once, for good.
1736 if (_thread) _thread->leave_signal_handler(); 1774 if (_thread) _thread->leave_signal_handler();
1737 _thread = NULL; 1775 _thread = NULL;
1738 } 1776 }
1739 }; 1777 };
1740 1778
1741 // ParkEvents are type-stable and immortal.
1742 //
1743 // Lifecycle: Once a ParkEvent is associated with a thread that ParkEvent remains
1744 // associated with the thread for the thread's entire lifetime - the relationship is
1745 // stable. A thread will be associated at most one ParkEvent. When the thread
1746 // expires, the ParkEvent moves to the EventFreeList. New threads attempt to allocate from
1747 // the EventFreeList before creating a new Event. Type-stability frees us from
1748 // worrying about stale Event or Thread references in the objectMonitor subsystem.
1749 // (A reference to ParkEvent is always valid, even though the event may no longer be associated
1750 // with the desired or expected thread. A key aspect of this design is that the callers of
1751 // park, unpark, etc must tolerate stale references and spurious wakeups).
1752 //
1753 // Only the "associated" thread can block (park) on the ParkEvent, although
1754 // any other thread can unpark a reachable parkevent. Park() is allowed to
1755 // return spuriously. In fact park-unpark a really just an optimization to
1756 // avoid unbounded spinning and surrender the CPU to be a polite system citizen.
1757 // A degenerate albeit "impolite" park-unpark implementation could simply return.
1758 // See http://blogs.sun.com/dave for more details.
1759 //
1760 // Eventually I'd like to eliminate Events and ObjectWaiters, both of which serve as
1761 // thread proxies, and simply make the THREAD structure type-stable and persistent.
1762 // Currently, we unpark events associated with threads, but ideally we'd just
1763 // unpark threads.
1764 //
1765 // The base-class, PlatformEvent, is platform-specific while the ParkEvent is
1766 // platform-independent. PlatformEvent provides park(), unpark(), etc., and
1767 // is abstract -- that is, a PlatformEvent should never be instantiated except
1768 // as part of a ParkEvent.
1769 // Equivalently we could have defined a platform-independent base-class that
1770 // exported Allocate(), Release(), etc. The platform-specific class would extend
1771 // that base-class, adding park(), unpark(), etc.
1772 //
1773 // A word of caution: The JVM uses 2 very similar constructs:
1774 // 1. ParkEvent are used for Java-level "monitor" synchronization.
1775 // 2. Parkers are used by JSR166-JUC park-unpark.
1776 //
1777 // We'll want to eventually merge these redundant facilities and use ParkEvent.
1778
1779
1780 class ParkEvent : public os::PlatformEvent {
1781 private:
1782 ParkEvent * FreeNext ;
1783
1784 // Current association
1785 Thread * AssociatedWith ;
1786 intptr_t RawThreadIdentity ; // LWPID etc
1787 volatile int Incarnation ;
1788
1789 // diagnostic : keep track of last thread to wake this thread.
1790 // this is useful for construction of dependency graphs.
1791 void * LastWaker ;
1792
1793 public:
1794 // MCS-CLH list linkage and Native Mutex/Monitor
1795 ParkEvent * volatile ListNext ;
1796 ParkEvent * volatile ListPrev ;
1797 volatile intptr_t OnList ;
1798 volatile int TState ;
1799 volatile int Notified ; // for native monitor construct
1800 volatile int IsWaiting ; // Enqueued on WaitSet
1801
1802
1803 private:
1804 static ParkEvent * volatile FreeList ;
1805 static volatile int ListLock ;
1806
1807 // It's prudent to mark the dtor as "private"
1808 // ensuring that it's not visible outside the package.
1809 // Unfortunately gcc warns about such usage, so
1810 // we revert to the less desirable "protected" visibility.
1811 // The other compilers accept private dtors.
1812
1813 protected: // Ensure dtor is never invoked
1814 ~ParkEvent() { guarantee (0, "invariant") ; }
1815
1816 ParkEvent() : PlatformEvent() {
1817 AssociatedWith = NULL ;
1818 FreeNext = NULL ;
1819 ListNext = NULL ;
1820 ListPrev = NULL ;
1821 OnList = 0 ;
1822 TState = 0 ;
1823 Notified = 0 ;
1824 IsWaiting = 0 ;
1825 }
1826
1827 // We use placement-new to force ParkEvent instances to be
1828 // aligned on 256-byte address boundaries. This ensures that the least
1829 // significant byte of a ParkEvent address is always 0.
1830
1831 void * operator new (size_t sz) ;
1832 void operator delete (void * a) ;
1833
1834 public:
1835 static ParkEvent * Allocate (Thread * t) ;
1836 static void Release (ParkEvent * e) ;
1837 } ;