Mercurial > hg > graal-compiler
diff src/share/vm/runtime/thread.cpp @ 4137:04b9a2566eec
Merge with hsx23/hotspot.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 21:40:27 +0100 |
parents | dc7902820c9b bca17e38de00 |
children | 723df37192d6 |
line wrap: on
line diff
--- a/src/share/vm/runtime/thread.cpp Sat Dec 17 20:50:09 2011 +0100 +++ b/src/share/vm/runtime/thread.cpp Sat Dec 17 21:40:27 2011 +0100 @@ -90,6 +90,10 @@ # include "os_windows.inline.hpp" # include "thread_windows.inline.hpp" #endif +#ifdef TARGET_OS_FAMILY_bsd +# include "os_bsd.inline.hpp" +# include "thread_bsd.inline.hpp" +#endif #ifndef SERIALGC #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp" #include "gc_implementation/g1/concurrentMarkThread.inline.hpp" @@ -107,6 +111,7 @@ // Only bother with this argument setup if dtrace is available +#ifndef USDT2 HS_DTRACE_PROBE_DECL(hotspot, vm__init__begin); HS_DTRACE_PROBE_DECL(hotspot, vm__init__end); HS_DTRACE_PROBE_DECL5(hotspot, thread__start, char*, intptr_t, @@ -127,6 +132,26 @@ java_lang_Thread::is_daemon((javathread)->threadObj())); \ } +#else /* USDT2 */ + +#define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_PROBE_START +#define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_PROBE_STOP + +#define DTRACE_THREAD_PROBE(probe, javathread) \ + { \ + ResourceMark rm(this); \ + int len = 0; \ + const char* name = (javathread)->get_thread_name(); \ + len = strlen(name); \ + HOTSPOT_THREAD_PROBE_##probe( /* probe = start, stop */ \ + (char *) name, len, \ + java_lang_Thread::thread_id((javathread)->threadObj()), \ + (uintptr_t) (javathread)->osthread()->thread_id(), \ + java_lang_Thread::is_daemon((javathread)->threadObj())); \ + } + +#endif /* USDT2 */ + #else // ndef DTRACE_ENABLED #define DTRACE_THREAD_PROBE(probe, javathread) @@ -750,15 +775,16 @@ jint thread_parity = _oops_do_parity; if (thread_parity != strong_roots_parity) { jint res = Atomic::cmpxchg(strong_roots_parity, &_oops_do_parity, thread_parity); - if (res == thread_parity) return true; - else { + if (res == thread_parity) { + return true; + } else { guarantee(res == strong_roots_parity, "Or else what?"); - assert(SharedHeap::heap()->n_par_threads() > 0, - "Should only fail when parallel."); + assert(SharedHeap::heap()->workers()->active_workers() > 0, + "Should only fail when parallel."); return false; } } - assert(SharedHeap::heap()->n_par_threads() > 0, + assert(SharedHeap::heap()->workers()->active_workers() > 0, "Should only fail when parallel."); return false; } @@ -967,7 +993,7 @@ // General purpose hook into Java code, run once when the VM is initialized. // The Java library method itself may be changed independently from the VM. static void call_postVMInitHook(TRAPS) { - klassOop k = SystemDictionary::sun_misc_PostVMInitHook_klass(); + klassOop k = SystemDictionary::PostVMInitHook_klass(); instanceKlassHandle klass (THREAD, k); if (klass.not_null()) { JavaValue result(T_VOID); @@ -1276,7 +1302,6 @@ _exception_oop = NULL; _exception_pc = 0; _exception_handler_pc = 0; - _exception_stack_size = 0; _is_method_handle_return = 0; _jvmti_thread_state= NULL; _should_post_on_exceptions_flag = JNI_FALSE; @@ -1329,7 +1354,7 @@ DirtyCardQueueSet JavaThread::_dirty_card_queue_set; #endif // !SERIALGC -JavaThread::JavaThread(bool is_attaching) : +JavaThread::JavaThread(bool is_attaching_via_jni) : Thread() #ifndef SERIALGC , _satb_mark_queue(&_satb_mark_queue_set), @@ -1337,7 +1362,11 @@ #endif // !SERIALGC { initialize(); - _is_attaching = is_attaching; + if (is_attaching_via_jni) { + _jni_attach_state = _attaching_via_jni; + } else { + _jni_attach_state = _not_attaching_via_jni; + } assert(_deferred_card_mark.is_empty(), "Default MemRegion ctor"); } @@ -1393,7 +1422,7 @@ tty->print_cr("creating thread %p", this); } initialize(); - _is_attaching = false; + _jni_attach_state = _not_attaching_via_jni; set_entry_point(entry_point); // Create the native thread itself. // %note runtime_23 @@ -1505,6 +1534,10 @@ // Note: Due to JVM_StopThread we can have pending exceptions already! if (!this->has_pending_exception() && !java_lang_Thread::is_stillborn(this->threadObj())) { + { + ResourceMark rm(this); + this->set_native_thread_name(this->get_thread_name()); + } HandleMark hm(this); this->entry_point()(this, this); } @@ -2694,7 +2727,7 @@ name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length(), buf, buflen); } } - else if (is_attaching()) { // workaround for 6412693 - see 6404306 + else if (is_attaching_via_jni()) { // workaround for 6412693 - see 6404306 name_str = "<no-name - thread is attaching>"; } else { @@ -2875,6 +2908,44 @@ } } +class PrintAndVerifyOopClosure: public OopClosure { + protected: + template <class T> inline void do_oop_work(T* p) { + oop obj = oopDesc::load_decode_heap_oop(p); + if (obj == NULL) return; + tty->print(INTPTR_FORMAT ": ", p); + if (obj->is_oop_or_null()) { + if (obj->is_objArray()) { + tty->print_cr("valid objArray: " INTPTR_FORMAT, (oopDesc*) obj); + } else { + obj->print(); + } + } else { + tty->print_cr("invalid oop: " INTPTR_FORMAT, (oopDesc*) obj); + } + tty->cr(); + } + public: + virtual void do_oop(oop* p) { do_oop_work(p); } + virtual void do_oop(narrowOop* p) { do_oop_work(p); } +}; + + +static void oops_print(frame* f, const RegisterMap *map) { + PrintAndVerifyOopClosure print; + f->print_value(); + f->oops_do(&print, NULL, (RegisterMap*)map); +} + +// Print our all the locations that contain oops and whether they are +// valid or not. This useful when trying to find the oldest frame +// where an oop has gone bad since the frame walk is from youngest to +// oldest. +void JavaThread::trace_oops() { + tty->print_cr("[Trace oops]"); + frames_do(oops_print); +} + #ifdef ASSERT // Print or validate the layout of stack frames @@ -2891,7 +2962,7 @@ values.validate(); } else { tty->print_cr("[Describe stack layout]"); - values.print(); + values.print(this); } } #endif @@ -3039,7 +3110,11 @@ os::pause(); } +#ifndef USDT2 HS_DTRACE_PROBE(hotspot, vm__init__begin); +#else /* USDT2 */ + HOTSPOT_VM_INIT_BEGIN(); +#endif /* USDT2 */ // Record VM creation timing statistics TraceVmCreationTime create_vm_timer; @@ -3294,7 +3369,11 @@ // debug stuff, that does not work until all basic classes have been initialized. set_init_completed(); +#ifndef USDT2 HS_DTRACE_PROBE(hotspot, vm__init__end); +#else /* USDT2 */ + HOTSPOT_VM_INIT_END(); +#endif /* USDT2 */ // record VM initialization completion time Management::record_vm_init_completed(); @@ -3349,7 +3428,9 @@ // Notify JVMTI agents that VM initialization is complete - nop if no agents. JvmtiExport::post_vm_initialized(); - Chunk::start_chunk_pool_cleaner_task(); + if (CleanChunkPoolAsync) { + Chunk::start_chunk_pool_cleaner_task(); + } // initialize compiler(s) CompileBroker::compilation_init(); @@ -3700,6 +3781,14 @@ // heap is unparseable if they are caught. Grab the Heap_lock // to prevent this. The GC vm_operations will not be able to // queue until after the vm thread is dead. + // After this point, we'll never emerge out of the safepoint before + // the VM exits, so concurrent GC threads do not need to be explicitly + // stopped; they remain inactive until the process exits. + // Note: some concurrent G1 threads may be running during a safepoint, + // but these will not be accessing the heap, just some G1-specific side + // data structures that are not accessed by any other threads but them + // after this point in a terminal safepoint. + MutexLocker ml(Heap_lock); VMThread::wait_for_vm_thread_exit(); @@ -3852,7 +3941,15 @@ // root groups. Overhead should be small enough to use all the time, // even in sequential code. SharedHeap* sh = SharedHeap::heap(); - bool is_par = (sh->n_par_threads() > 0); + // Cannot yet substitute active_workers for n_par_threads + // because of G1CollectedHeap::verify() use of + // SharedHeap::process_strong_roots(). n_par_threads == 0 will + // turn off parallelism in process_strong_roots while active_workers + // is being used for parallelism elsewhere. + bool is_par = sh->n_par_threads() > 0; + assert(!is_par || + (SharedHeap::heap()->n_par_threads() == + SharedHeap::heap()->workers()->active_workers()), "Mismatch"); int cp = SharedHeap::heap()->strong_roots_parity(); ALL_JAVA_THREADS(p) { if (p->claim_oops_do(is_par, cp)) { @@ -3860,8 +3957,9 @@ } } VMThread* vmt = VMThread::vm_thread(); - if (vmt->claim_oops_do(is_par, cp)) + if (vmt->claim_oops_do(is_par, cp)) { vmt->oops_do(f, cf); + } } #ifndef SERIALGC