837 jint res = Atomic::cmpxchg(strong_roots_parity, &_oops_do_parity, thread_parity);
838 if (res == thread_parity) {
839 return true;
840 } else {
841 guarantee(res == strong_roots_parity, "Or else what?");
842 return false;
843 }
844 }
845 return false;
846 }
847
848 void Thread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
849 active_handles()->oops_do(f);
850 // Do oop for ThreadShadow
851 f->do_oop((oop*)&_pending_exception);
852 handle_area()->oops_do(f);
853
854 if (MonitorInUseLists) {
855 // When using thread local monitor lists, we scan them here,
856 // and the remaining global monitors in ObjectSynchronizer::oops_do().
857 VM_Operation* op = VMThread::vm_operation();
858 if (op != NULL && op->deflates_idle_monitors()) {
859 DeflateMonitorCounters counters; // Dummy for now.
860 ObjectSynchronizer::deflate_thread_local_monitors(this, &counters, f);
861 } else {
862 ObjectSynchronizer::thread_local_used_oops_do(this, f);
863 }
864 }
865 }
866
867 void Thread::metadata_handles_do(void f(Metadata*)) {
868 // Only walk the Handles in Thread.
869 if (metadata_handles() != NULL) {
870 for (int i = 0; i< metadata_handles()->length(); i++) {
871 f(metadata_handles()->at(i));
872 }
873 }
874 }
875
876 void Thread::print_on(outputStream* st, bool print_extended_info) const {
877 // get_priority assumes osthread initialized
878 if (osthread() != NULL) {
879 int os_prio;
880 if (os::get_native_priority(this, &os_prio) == OS_OK) {
881 st->print("os_prio=%d ", os_prio);
882 }
883
884 st->print("cpu=%.2fms ",
4452 }
4453
4454 #ifdef ASSERT
4455 void Threads::assert_all_threads_claimed() {
4456 ALL_JAVA_THREADS(p) {
4457 const int thread_parity = p->oops_do_parity();
4458 assert((thread_parity == _thread_claim_parity),
4459 "Thread " PTR_FORMAT " has incorrect parity %d != %d", p2i(p), thread_parity, _thread_claim_parity);
4460 }
4461 VMThread* vmt = VMThread::vm_thread();
4462 const int thread_parity = vmt->oops_do_parity();
4463 assert((thread_parity == _thread_claim_parity),
4464 "VMThread " PTR_FORMAT " has incorrect parity %d != %d", p2i(vmt), thread_parity, _thread_claim_parity);
4465 }
4466 #endif // ASSERT
4467
4468 class ParallelOopsDoThreadClosure : public ThreadClosure {
4469 private:
4470 OopClosure* _f;
4471 CodeBlobClosure* _cf;
4472 CodeBlobClosure* _nmethods_cl;
4473 ThreadClosure* _thread_cl;
4474 public:
4475 ParallelOopsDoThreadClosure(OopClosure* f, CodeBlobClosure* cf, CodeBlobClosure* nmethods_cl, ThreadClosure* thread_cl) :
4476 _f(f), _cf(cf), _nmethods_cl(nmethods_cl), _thread_cl(thread_cl) {}
4477 void do_thread(Thread* t) {
4478 t->oops_do(_f, _cf);
4479 if (_thread_cl != NULL) {
4480 _thread_cl->do_thread(t);
4481 }
4482 if (_nmethods_cl != NULL && t->is_Java_thread() && !t->is_Code_cache_sweeper_thread()) {
4483 ((JavaThread*)t)->nmethods_do(_nmethods_cl);
4484 }
4485 }
4486 };
4487
4488 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf, CodeBlobClosure* nmethods_cl,
4489 ThreadClosure* thread_cl) {
4490 ParallelOopsDoThreadClosure tc(f, cf, nmethods_cl, thread_cl);
4491 possibly_parallel_threads_do(is_par, &tc);
4492 }
4493
4494 void Threads::nmethods_do(CodeBlobClosure* cf) {
4495 ALL_JAVA_THREADS(p) {
4496 // This is used by the code cache sweeper to mark nmethods that are active
4497 // on the stack of a Java thread. Ignore the sweeper thread itself to avoid
4498 // marking CodeCacheSweeperThread::_scanned_compiled_method as active.
4499 if(!p->is_Code_cache_sweeper_thread()) {
4500 p->nmethods_do(cf);
4501 }
4502 }
4503 }
4504
4505 void Threads::metadata_do(void f(Metadata*)) {
4506 ALL_JAVA_THREADS(p) {
4507 p->metadata_do(f);
4508 }
4509 }
4510
|
837 jint res = Atomic::cmpxchg(strong_roots_parity, &_oops_do_parity, thread_parity);
838 if (res == thread_parity) {
839 return true;
840 } else {
841 guarantee(res == strong_roots_parity, "Or else what?");
842 return false;
843 }
844 }
845 return false;
846 }
847
848 void Thread::oops_do(OopClosure* f, CodeBlobClosure* cf) {
849 active_handles()->oops_do(f);
850 // Do oop for ThreadShadow
851 f->do_oop((oop*)&_pending_exception);
852 handle_area()->oops_do(f);
853
854 if (MonitorInUseLists) {
855 // When using thread local monitor lists, we scan them here,
856 // and the remaining global monitors in ObjectSynchronizer::oops_do().
857 ObjectSynchronizer::thread_local_used_oops_do(this, f);
858 }
859 }
860
861 void Thread::metadata_handles_do(void f(Metadata*)) {
862 // Only walk the Handles in Thread.
863 if (metadata_handles() != NULL) {
864 for (int i = 0; i< metadata_handles()->length(); i++) {
865 f(metadata_handles()->at(i));
866 }
867 }
868 }
869
870 void Thread::print_on(outputStream* st, bool print_extended_info) const {
871 // get_priority assumes osthread initialized
872 if (osthread() != NULL) {
873 int os_prio;
874 if (os::get_native_priority(this, &os_prio) == OS_OK) {
875 st->print("os_prio=%d ", os_prio);
876 }
877
878 st->print("cpu=%.2fms ",
4446 }
4447
4448 #ifdef ASSERT
4449 void Threads::assert_all_threads_claimed() {
4450 ALL_JAVA_THREADS(p) {
4451 const int thread_parity = p->oops_do_parity();
4452 assert((thread_parity == _thread_claim_parity),
4453 "Thread " PTR_FORMAT " has incorrect parity %d != %d", p2i(p), thread_parity, _thread_claim_parity);
4454 }
4455 VMThread* vmt = VMThread::vm_thread();
4456 const int thread_parity = vmt->oops_do_parity();
4457 assert((thread_parity == _thread_claim_parity),
4458 "VMThread " PTR_FORMAT " has incorrect parity %d != %d", p2i(vmt), thread_parity, _thread_claim_parity);
4459 }
4460 #endif // ASSERT
4461
4462 class ParallelOopsDoThreadClosure : public ThreadClosure {
4463 private:
4464 OopClosure* _f;
4465 CodeBlobClosure* _cf;
4466 public:
4467 ParallelOopsDoThreadClosure(OopClosure* f, CodeBlobClosure* cf) : _f(f), _cf(cf) {}
4468 void do_thread(Thread* t) {
4469 t->oops_do(_f, _cf);
4470 }
4471 };
4472
4473 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CodeBlobClosure* cf) {
4474 ParallelOopsDoThreadClosure tc(f, cf);
4475 possibly_parallel_threads_do(is_par, &tc);
4476 }
4477
4478 void Threads::nmethods_do(CodeBlobClosure* cf) {
4479 ALL_JAVA_THREADS(p) {
4480 // This is used by the code cache sweeper to mark nmethods that are active
4481 // on the stack of a Java thread. Ignore the sweeper thread itself to avoid
4482 // marking CodeCacheSweeperThread::_scanned_compiled_method as active.
4483 if(!p->is_Code_cache_sweeper_thread()) {
4484 p->nmethods_do(cf);
4485 }
4486 }
4487 }
4488
4489 void Threads::metadata_do(void f(Metadata*)) {
4490 ALL_JAVA_THREADS(p) {
4491 p->metadata_do(f);
4492 }
4493 }
4494
|