comparison src/share/vm/runtime/thread.cpp @ 7179:d0aa87f04bd5

8003720: NPG: Method in interpreter stack frame can be deallocated Summary: Pass down a closure during root scanning to keep the class of the method alive. Reviewed-by: coleenp, jcoomes
author stefank
date Tue, 27 Nov 2012 10:13:20 +0100
parents 53715fb1597d
children f34d701e952e
comparison
equal deleted inserted replaced
7178:19c1bd641922 7179:d0aa87f04bd5
824 assert(SharedHeap::heap()->workers()->active_workers() > 0, 824 assert(SharedHeap::heap()->workers()->active_workers() > 0,
825 "Should only fail when parallel."); 825 "Should only fail when parallel.");
826 return false; 826 return false;
827 } 827 }
828 828
829 void Thread::oops_do(OopClosure* f, CodeBlobClosure* cf) { 829 void Thread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) {
830 active_handles()->oops_do(f); 830 active_handles()->oops_do(f);
831 // Do oop for ThreadShadow 831 // Do oop for ThreadShadow
832 f->do_oop((oop*)&_pending_exception); 832 f->do_oop((oop*)&_pending_exception);
833 handle_area()->oops_do(f); 833 handle_area()->oops_do(f);
834 } 834 }
2703 _cur_thr->set_processed_thread(NULL); 2703 _cur_thr->set_processed_thread(NULL);
2704 } 2704 }
2705 } 2705 }
2706 }; 2706 };
2707 2707
2708 void JavaThread::oops_do(OopClosure* f, CodeBlobClosure* cf) { 2708 void JavaThread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) {
2709 // Verify that the deferred card marks have been flushed. 2709 // Verify that the deferred card marks have been flushed.
2710 assert(deferred_card_mark().is_empty(), "Should be empty during GC"); 2710 assert(deferred_card_mark().is_empty(), "Should be empty during GC");
2711 2711
2712 // The ThreadProfiler oops_do is done from FlatProfiler::oops_do 2712 // The ThreadProfiler oops_do is done from FlatProfiler::oops_do
2713 // since there may be more than one thread using each ThreadProfiler. 2713 // since there may be more than one thread using each ThreadProfiler.
2714 2714
2715 // Traverse the GCHandles 2715 // Traverse the GCHandles
2716 Thread::oops_do(f, cf); 2716 Thread::oops_do(f, cld_f, cf);
2717 2717
2718 assert( (!has_last_Java_frame() && java_call_counter() == 0) || 2718 assert( (!has_last_Java_frame() && java_call_counter() == 0) ||
2719 (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!"); 2719 (has_last_Java_frame() && java_call_counter() > 0), "wrong java_sp info!");
2720 2720
2721 if (has_last_Java_frame()) { 2721 if (has_last_Java_frame()) {
2739 chunk->oops_do(f); 2739 chunk->oops_do(f);
2740 } 2740 }
2741 2741
2742 // Traverse the execution stack 2742 // Traverse the execution stack
2743 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) { 2743 for(StackFrameStream fst(this); !fst.is_done(); fst.next()) {
2744 fst.current()->oops_do(f, cf, fst.register_map()); 2744 fst.current()->oops_do(f, cld_f, cf, fst.register_map());
2745 } 2745 }
2746 } 2746 }
2747 2747
2748 // callee_target is never live across a gc point so NULL it here should 2748 // callee_target is never live across a gc point so NULL it here should
2749 // it still contain a methdOop. 2749 // it still contain a methdOop.
2873 2873
2874 static void frame_verify(frame* f, const RegisterMap *map) { f->verify(map); } 2874 static void frame_verify(frame* f, const RegisterMap *map) { f->verify(map); }
2875 2875
2876 void JavaThread::verify() { 2876 void JavaThread::verify() {
2877 // Verify oops in the thread. 2877 // Verify oops in the thread.
2878 oops_do(&VerifyOopClosure::verify_oop, NULL); 2878 oops_do(&VerifyOopClosure::verify_oop, NULL, NULL);
2879 2879
2880 // Verify the stack frames. 2880 // Verify the stack frames.
2881 frames_do(frame_verify); 2881 frames_do(frame_verify);
2882 } 2882 }
2883 2883
3123 3123
3124 3124
3125 static void oops_print(frame* f, const RegisterMap *map) { 3125 static void oops_print(frame* f, const RegisterMap *map) {
3126 PrintAndVerifyOopClosure print; 3126 PrintAndVerifyOopClosure print;
3127 f->print_value(); 3127 f->print_value();
3128 f->oops_do(&print, NULL, (RegisterMap*)map); 3128 f->oops_do(&print, NULL, NULL, (RegisterMap*)map);
3129 } 3129 }
3130 3130
3131 // Print our all the locations that contain oops and whether they are 3131 // Print our all the locations that contain oops and whether they are
3132 // valid or not. This useful when trying to find the oldest frame 3132 // valid or not. This useful when trying to find the oldest frame
3133 // where an oop has gone bad since the frame walk is from youngest to 3133 // where an oop has gone bad since the frame walk is from youngest to
3225 #ifndef PRODUCT 3225 #ifndef PRODUCT
3226 _ideal_graph_printer = NULL; 3226 _ideal_graph_printer = NULL;
3227 #endif 3227 #endif
3228 } 3228 }
3229 3229
3230 void CompilerThread::oops_do(OopClosure* f, CodeBlobClosure* cf) { 3230 void CompilerThread::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) {
3231 JavaThread::oops_do(f, cf); 3231 JavaThread::oops_do(f, cld_f, cf);
3232 if (_scanned_nmethod != NULL && cf != NULL) { 3232 if (_scanned_nmethod != NULL && cf != NULL) {
3233 // Safepoints can occur when the sweeper is scanning an nmethod so 3233 // Safepoints can occur when the sweeper is scanning an nmethod so
3234 // process it here to make sure it isn't unloaded in the middle of 3234 // process it here to make sure it isn't unloaded in the middle of
3235 // a scan. 3235 // a scan.
3236 cf->do_code_blob(_scanned_nmethod); 3236 cf->do_code_blob(_scanned_nmethod);
4199 // In particular, these things should never be called when the Threads_lock 4199 // In particular, these things should never be called when the Threads_lock
4200 // is held by some other thread. (Note: the Safepoint abstraction also 4200 // is held by some other thread. (Note: the Safepoint abstraction also
4201 // uses the Threads_lock to gurantee this property. It also makes sure that 4201 // uses the Threads_lock to gurantee this property. It also makes sure that
4202 // all threads gets blocked when exiting or starting). 4202 // all threads gets blocked when exiting or starting).
4203 4203
4204 void Threads::oops_do(OopClosure* f, CodeBlobClosure* cf) { 4204 void Threads::oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) {
4205 ALL_JAVA_THREADS(p) { 4205 ALL_JAVA_THREADS(p) {
4206 p->oops_do(f, cf); 4206 p->oops_do(f, cld_f, cf);
4207 } 4207 }
4208 VMThread::vm_thread()->oops_do(f, cf); 4208 VMThread::vm_thread()->oops_do(f, cld_f, cf);
4209 } 4209 }
4210 4210
4211 void Threads::possibly_parallel_oops_do(OopClosure* f, CodeBlobClosure* cf) { 4211 void Threads::possibly_parallel_oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf) {
4212 // Introduce a mechanism allowing parallel threads to claim threads as 4212 // Introduce a mechanism allowing parallel threads to claim threads as
4213 // root groups. Overhead should be small enough to use all the time, 4213 // root groups. Overhead should be small enough to use all the time,
4214 // even in sequential code. 4214 // even in sequential code.
4215 SharedHeap* sh = SharedHeap::heap(); 4215 SharedHeap* sh = SharedHeap::heap();
4216 // Cannot yet substitute active_workers for n_par_threads 4216 // Cannot yet substitute active_workers for n_par_threads
4223 (SharedHeap::heap()->n_par_threads() == 4223 (SharedHeap::heap()->n_par_threads() ==
4224 SharedHeap::heap()->workers()->active_workers()), "Mismatch"); 4224 SharedHeap::heap()->workers()->active_workers()), "Mismatch");
4225 int cp = SharedHeap::heap()->strong_roots_parity(); 4225 int cp = SharedHeap::heap()->strong_roots_parity();
4226 ALL_JAVA_THREADS(p) { 4226 ALL_JAVA_THREADS(p) {
4227 if (p->claim_oops_do(is_par, cp)) { 4227 if (p->claim_oops_do(is_par, cp)) {
4228 p->oops_do(f, cf); 4228 p->oops_do(f, cld_f, cf);
4229 } 4229 }
4230 } 4230 }
4231 VMThread* vmt = VMThread::vm_thread(); 4231 VMThread* vmt = VMThread::vm_thread();
4232 if (vmt->claim_oops_do(is_par, cp)) { 4232 if (vmt->claim_oops_do(is_par, cp)) {
4233 vmt->oops_do(f, cf); 4233 vmt->oops_do(f, cld_f, cf);
4234 } 4234 }
4235 } 4235 }
4236 4236
4237 #ifndef SERIALGC 4237 #ifndef SERIALGC
4238 // Used by ParallelScavenge 4238 // Used by ParallelScavenge