142 #define FOR_ALL_BLOBS(cb, heap) for (CodeBlob* cb = first_blob(heap); cb != NULL; cb = next_blob(heap, cb)) |
142 #define FOR_ALL_BLOBS(cb, heap) for (CodeBlob* cb = first_blob(heap); cb != NULL; cb = next_blob(heap, cb)) |
143 |
143 |
144 address CodeCache::_low_bound = 0; |
144 address CodeCache::_low_bound = 0; |
145 address CodeCache::_high_bound = 0; |
145 address CodeCache::_high_bound = 0; |
146 int CodeCache::_number_of_nmethods_with_dependencies = 0; |
146 int CodeCache::_number_of_nmethods_with_dependencies = 0; |
147 bool CodeCache::_needs_cache_clean = false; |
|
148 nmethod* CodeCache::_scavenge_root_nmethods = NULL; |
147 nmethod* CodeCache::_scavenge_root_nmethods = NULL; |
149 |
148 |
150 // Initialize arrays of CodeHeap subsets |
149 // Initialize arrays of CodeHeap subsets |
151 GrowableArray<CodeHeap*>* CodeCache::_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (CodeBlobType::All, true); |
150 GrowableArray<CodeHeap*>* CodeCache::_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (CodeBlobType::All, true); |
152 GrowableArray<CodeHeap*>* CodeCache::_compiled_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (CodeBlobType::All, true); |
151 GrowableArray<CodeHeap*>* CodeCache::_compiled_heaps = new(ResourceObj::C_HEAP, mtCode) GrowableArray<CodeHeap*> (CodeBlobType::All, true); |
681 } |
680 } |
682 |
681 |
683 // Mark nmethods for unloading if they contain otherwise unreachable oops. |
682 // Mark nmethods for unloading if they contain otherwise unreachable oops. |
684 void CodeCache::do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred) { |
683 void CodeCache::do_unloading(BoolObjectClosure* is_alive, bool unloading_occurred) { |
685 assert_locked_or_safepoint(CodeCache_lock); |
684 assert_locked_or_safepoint(CodeCache_lock); |
|
685 UnloadingScope scope(is_alive); |
686 CompiledMethodIterator iter; |
686 CompiledMethodIterator iter; |
687 while(iter.next_alive()) { |
687 while(iter.next_alive()) { |
688 iter.method()->do_unloading(is_alive); |
688 iter.method()->do_unloading(unloading_occurred); |
689 } |
689 } |
690 |
|
691 // Now that all the unloaded nmethods are known, cleanup caches |
|
692 // before CLDG is purged. |
|
693 // This is another code cache walk but it is moved from gc_epilogue. |
|
694 // G1 does a parallel walk of the nmethods so cleans them up |
|
695 // as it goes and doesn't call this. |
|
696 do_unloading_nmethod_caches(unloading_occurred); |
|
697 } |
690 } |
698 |
691 |
699 void CodeCache::blobs_do(CodeBlobClosure* f) { |
692 void CodeCache::blobs_do(CodeBlobClosure* f) { |
700 assert_locked_or_safepoint(CodeCache_lock); |
693 assert_locked_or_safepoint(CodeCache_lock); |
701 FOR_ALL_ALLOCABLE_HEAPS(heap) { |
694 FOR_ALL_ALLOCABLE_HEAPS(heap) { |
906 |
899 |
907 void CodeCache::gc_epilogue() { |
900 void CodeCache::gc_epilogue() { |
908 prune_scavenge_root_nmethods(); |
901 prune_scavenge_root_nmethods(); |
909 } |
902 } |
910 |
903 |
911 |
904 uint8_t CodeCache::_unloading_cycle = 1; |
912 void CodeCache::do_unloading_nmethod_caches(bool class_unloading_occurred) { |
905 |
913 assert_locked_or_safepoint(CodeCache_lock); |
906 void CodeCache::increment_unloading_cycle() { |
914 // Even if classes are not unloaded, there may have been some nmethods that are |
907 if (_unloading_cycle == 1) { |
915 // unloaded because oops in them are no longer reachable. |
908 _unloading_cycle = 2; |
916 NOT_DEBUG(if (needs_cache_clean() || class_unloading_occurred)) { |
909 } else { |
917 CompiledMethodIterator iter; |
910 _unloading_cycle = 1; |
918 while(iter.next_alive()) { |
911 } |
919 CompiledMethod* cm = iter.method(); |
|
920 assert(!cm->is_unloaded(), "Tautology"); |
|
921 DEBUG_ONLY(if (needs_cache_clean() || class_unloading_occurred)) { |
|
922 // Clean up both unloaded klasses from nmethods and unloaded nmethods |
|
923 // from inline caches. |
|
924 cm->unload_nmethod_caches(/*parallel*/false, class_unloading_occurred); |
|
925 } |
|
926 DEBUG_ONLY(cm->verify()); |
|
927 DEBUG_ONLY(cm->verify_oop_relocations()); |
|
928 } |
|
929 } |
|
930 |
|
931 set_needs_cache_clean(false); |
|
932 verify_icholder_relocations(); |
|
933 } |
912 } |
934 |
913 |
935 void CodeCache::verify_oops() { |
914 void CodeCache::verify_oops() { |
936 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
915 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
937 VerifyOopClosure voc; |
916 VerifyOopClosure voc; |