5893 G1STWIsAliveClosure is_alive(this);
5894 G1KeepAliveClosure keep_alive(this);
5895 JNIHandles::weak_oops_do(&is_alive, &keep_alive);
5896 }
5897
5898 release_gc_alloc_regions(n_workers, evacuation_info);
5899 g1_rem_set()->cleanup_after_oops_into_collection_set_do();
5900
5901 // Reset and re-enable the hot card cache.
5902 // Note the counts for the cards in the regions in the
5903 // collection set are reset when the collection set is freed.
5904 hot_card_cache->reset_hot_cache();
5905 hot_card_cache->set_use_cache(true);
5906
5907 // Migrate the strong code roots attached to each region in
5908 // the collection set. Ideally we would like to do this
5909 // after we have finished the scanning/evacuation of the
5910 // strong code roots for a particular heap region.
5911 migrate_strong_code_roots();
5912
5913 if (g1_policy()->during_initial_mark_pause()) {
5914 // Reset the claim values set during marking the strong code roots
5915 reset_heap_region_claim_values();
5916 }
5917
5918 finalize_for_evac_failure();
5919
5920 if (evacuation_failed()) {
5921 remove_self_forwarding_pointers();
5922
5923 // Reset the G1EvacuationFailureALot counters and flags
5924 // Note: the values are reset only when an actual
5925 // evacuation failure occurs.
5926 NOT_PRODUCT(reset_evacuation_should_fail();)
5927 }
5928
5929 // Enqueue any remaining references remaining on the STW
5930 // reference processor's discovered lists. We need to do
5931 // this after the card table is cleaned (and verified) as
5932 // the act of enqueueing entries on to the pending list
5953 OldRegionSet* old_proxy_set,
5954 HumongousRegionSet* humongous_proxy_set,
5955 HRRSCleanupTask* hrrs_cleanup_task,
5956 bool par) {
5957 if (hr->used() > 0 && hr->max_live_bytes() == 0 && !hr->is_young()) {
5958 if (hr->isHumongous()) {
5959 assert(hr->startsHumongous(), "we should only see starts humongous");
5960 free_humongous_region(hr, pre_used, free_list, humongous_proxy_set, par);
5961 } else {
5962 _old_set.remove_with_proxy(hr, old_proxy_set);
5963 free_region(hr, pre_used, free_list, par);
5964 }
5965 } else {
5966 hr->rem_set()->do_cleanup_work(hrrs_cleanup_task);
5967 }
5968 }
5969
5970 void G1CollectedHeap::free_region(HeapRegion* hr,
5971 size_t* pre_used,
5972 FreeRegionList* free_list,
5973 bool par) {
5974 assert(!hr->isHumongous(), "this is only for non-humongous regions");
5975 assert(!hr->is_empty(), "the region should not be empty");
5976 assert(free_list != NULL, "pre-condition");
5977
5978 // Clear the card counts for this region.
5979 // Note: we only need to do this if the region is not young
5980 // (since we don't refine cards in young regions).
5981 if (!hr->is_young()) {
5982 _cg1r->hot_card_cache()->reset_card_counts(hr);
5983 }
5984 *pre_used += hr->used();
5985 hr->hr_clear(par, true /* clear_space */);
5986 free_list->add_as_head(hr);
5987 }
5988
5989 void G1CollectedHeap::free_humongous_region(HeapRegion* hr,
5990 size_t* pre_used,
5991 FreeRegionList* free_list,
5992 HumongousRegionSet* humongous_proxy_set,
5993 bool par) {
5994 assert(hr->startsHumongous(), "this is only for starts humongous regions");
5995 assert(free_list != NULL, "pre-condition");
5996 assert(humongous_proxy_set != NULL, "pre-condition");
5997
5998 size_t hr_used = hr->used();
5999 size_t hr_capacity = hr->capacity();
6000 size_t hr_pre_used = 0;
6001 _humongous_set.remove_with_proxy(hr, humongous_proxy_set);
6002 // We need to read this before we make the region non-humongous,
6003 // otherwise the information will be gone.
6004 uint last_index = hr->last_hc_index();
6005 hr->set_notHumongous();
6187 if (non_young) {
6188 if (cur->is_young()) {
6189 double end_sec = os::elapsedTime();
6190 double elapsed_ms = (end_sec - start_sec) * 1000.0;
6191 non_young_time_ms += elapsed_ms;
6192
6193 start_sec = os::elapsedTime();
6194 non_young = false;
6195 }
6196 } else {
6197 if (!cur->is_young()) {
6198 double end_sec = os::elapsedTime();
6199 double elapsed_ms = (end_sec - start_sec) * 1000.0;
6200 young_time_ms += elapsed_ms;
6201
6202 start_sec = os::elapsedTime();
6203 non_young = true;
6204 }
6205 }
6206
6207 rs_lengths += cur->rem_set()->occupied();
6208
6209 HeapRegion* next = cur->next_in_collection_set();
6210 assert(cur->in_collection_set(), "bad CS");
6211 cur->set_next_in_collection_set(NULL);
6212 cur->set_in_collection_set(false);
6213
6214 if (cur->is_young()) {
6215 int index = cur->young_index_in_cset();
6216 assert(index != -1, "invariant");
6217 assert((uint) index < policy->young_cset_region_length(), "invariant");
6218 size_t words_survived = _surviving_young_words[index];
6219 cur->record_surv_words_in_group(words_survived);
6220
6221 // At this point the we have 'popped' cur from the collection set
6222 // (linked via next_in_collection_set()) but it is still in the
6223 // young list (linked via next_young_region()). Clear the
6224 // _next_young_region field.
6225 cur->set_next_young_region(NULL);
6226 } else {
6227 int index = cur->young_index_in_cset();
6228 assert(index == -1, "invariant");
6229 }
6230
6231 assert( (cur->is_young() && cur->young_index_in_cset() > -1) ||
6232 (!cur->is_young() && cur->young_index_in_cset() == -1),
6233 "invariant" );
6234
6235 if (!cur->evacuation_failed()) {
6236 MemRegion used_mr = cur->used_region();
6237
6238 // And the region is empty.
6239 assert(!used_mr.is_empty(), "Should not have empty regions in a CS.");
6240 free_region(cur, &pre_used, &local_free_list, false /* par */);
6241 } else {
6242 cur->uninstall_surv_rate_group();
6243 if (cur->is_young()) {
6244 cur->set_young_index_in_cset(-1);
6245 }
6246 cur->set_not_young();
6247 cur->set_evacuation_failed(false);
6248 // The region is now considered to be old.
6249 _old_set.add(cur);
6250 evacuation_info.increment_collectionset_used_after(cur->used());
6251 }
6252 cur = next;
6253 }
6254
6255 evacuation_info.set_regions_freed(local_free_list.length());
6256 policy->record_max_rs_lengths(rs_lengths);
6257 policy->cset_regions_freed();
6258
6259 double end_sec = os::elapsedTime();
6260 double elapsed_ms = (end_sec - start_sec) * 1000.0;
6867 if (nm != NULL) {
6868 nm->oops_do(&_oop_cl);
6869 }
6870 }
6871 };
6872
6873 class MarkStrongCodeRootsHRClosure: public HeapRegionClosure {
6874 G1CollectedHeap* _g1h;
6875 uint _worker_id;
6876
6877 public:
6878 MarkStrongCodeRootsHRClosure(G1CollectedHeap* g1h, uint worker_id) :
6879 _g1h(g1h), _worker_id(worker_id) {}
6880
6881 bool doHeapRegion(HeapRegion *hr) {
6882 HeapRegionRemSet* hrrs = hr->rem_set();
6883 if (hr->continuesHumongous()) {
6884 // Code roots should never be attached to a continuation of a humongous region
6885 assert(hrrs->strong_code_roots_list_length() == 0,
6886 err_msg("code roots should never be attached to continuations of humongous region "HR_FORMAT
6887 " starting at "HR_FORMAT", but has "INT32_FORMAT,
6888 HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region()),
6889 hrrs->strong_code_roots_list_length()));
6890 return false;
6891 }
6892
6893 if (hr->in_collection_set()) {
6894 // Don't mark code roots into regions in the collection set here.
6895 // They will be marked when we scan them.
6896 return false;
6897 }
6898
6899 MarkStrongCodeRootCodeBlobClosure cb_cl(_g1h->concurrent_mark(), hr, _worker_id);
6900 hr->strong_code_roots_do(&cb_cl);
6901 return false;
6902 }
6903 };
6904
6905 void G1CollectedHeap::mark_strong_code_roots(uint worker_id) {
6906 MarkStrongCodeRootsHRClosure cl(this, worker_id);
6907 if (G1CollectedHeap::use_parallel_gc_threads()) {
|
5893 G1STWIsAliveClosure is_alive(this);
5894 G1KeepAliveClosure keep_alive(this);
5895 JNIHandles::weak_oops_do(&is_alive, &keep_alive);
5896 }
5897
5898 release_gc_alloc_regions(n_workers, evacuation_info);
5899 g1_rem_set()->cleanup_after_oops_into_collection_set_do();
5900
5901 // Reset and re-enable the hot card cache.
5902 // Note the counts for the cards in the regions in the
5903 // collection set are reset when the collection set is freed.
5904 hot_card_cache->reset_hot_cache();
5905 hot_card_cache->set_use_cache(true);
5906
5907 // Migrate the strong code roots attached to each region in
5908 // the collection set. Ideally we would like to do this
5909 // after we have finished the scanning/evacuation of the
5910 // strong code roots for a particular heap region.
5911 migrate_strong_code_roots();
5912
5913 // Purge superfluous chunks.
5914 G1CodeRootSet::purge_chunks(G1CodeRootsChunkCacheKeepRatio);
5915
5916 if (g1_policy()->during_initial_mark_pause()) {
5917 // Reset the claim values set during marking the strong code roots
5918 reset_heap_region_claim_values();
5919 }
5920
5921 finalize_for_evac_failure();
5922
5923 if (evacuation_failed()) {
5924 remove_self_forwarding_pointers();
5925
5926 // Reset the G1EvacuationFailureALot counters and flags
5927 // Note: the values are reset only when an actual
5928 // evacuation failure occurs.
5929 NOT_PRODUCT(reset_evacuation_should_fail();)
5930 }
5931
5932 // Enqueue any remaining references remaining on the STW
5933 // reference processor's discovered lists. We need to do
5934 // this after the card table is cleaned (and verified) as
5935 // the act of enqueueing entries on to the pending list
5956 OldRegionSet* old_proxy_set,
5957 HumongousRegionSet* humongous_proxy_set,
5958 HRRSCleanupTask* hrrs_cleanup_task,
5959 bool par) {
5960 if (hr->used() > 0 && hr->max_live_bytes() == 0 && !hr->is_young()) {
5961 if (hr->isHumongous()) {
5962 assert(hr->startsHumongous(), "we should only see starts humongous");
5963 free_humongous_region(hr, pre_used, free_list, humongous_proxy_set, par);
5964 } else {
5965 _old_set.remove_with_proxy(hr, old_proxy_set);
5966 free_region(hr, pre_used, free_list, par);
5967 }
5968 } else {
5969 hr->rem_set()->do_cleanup_work(hrrs_cleanup_task);
5970 }
5971 }
5972
5973 void G1CollectedHeap::free_region(HeapRegion* hr,
5974 size_t* pre_used,
5975 FreeRegionList* free_list,
5976 bool par, bool locked) {
5977 assert(!hr->isHumongous(), "this is only for non-humongous regions");
5978 assert(!hr->is_empty(), "the region should not be empty");
5979 assert(free_list != NULL, "pre-condition");
5980
5981 // Clear the card counts for this region.
5982 // Note: we only need to do this if the region is not young
5983 // (since we don't refine cards in young regions).
5984 if (!hr->is_young()) {
5985 _cg1r->hot_card_cache()->reset_card_counts(hr);
5986 }
5987 *pre_used += hr->used();
5988 hr->hr_clear(par, true /* clear_space */, locked);
5989 free_list->add_as_head(hr);
5990 }
5991
5992 void G1CollectedHeap::free_humongous_region(HeapRegion* hr,
5993 size_t* pre_used,
5994 FreeRegionList* free_list,
5995 HumongousRegionSet* humongous_proxy_set,
5996 bool par) {
5997 assert(hr->startsHumongous(), "this is only for starts humongous regions");
5998 assert(free_list != NULL, "pre-condition");
5999 assert(humongous_proxy_set != NULL, "pre-condition");
6000
6001 size_t hr_used = hr->used();
6002 size_t hr_capacity = hr->capacity();
6003 size_t hr_pre_used = 0;
6004 _humongous_set.remove_with_proxy(hr, humongous_proxy_set);
6005 // We need to read this before we make the region non-humongous,
6006 // otherwise the information will be gone.
6007 uint last_index = hr->last_hc_index();
6008 hr->set_notHumongous();
6190 if (non_young) {
6191 if (cur->is_young()) {
6192 double end_sec = os::elapsedTime();
6193 double elapsed_ms = (end_sec - start_sec) * 1000.0;
6194 non_young_time_ms += elapsed_ms;
6195
6196 start_sec = os::elapsedTime();
6197 non_young = false;
6198 }
6199 } else {
6200 if (!cur->is_young()) {
6201 double end_sec = os::elapsedTime();
6202 double elapsed_ms = (end_sec - start_sec) * 1000.0;
6203 young_time_ms += elapsed_ms;
6204
6205 start_sec = os::elapsedTime();
6206 non_young = true;
6207 }
6208 }
6209
6210 rs_lengths += cur->rem_set()->occupied_locked();
6211
6212 HeapRegion* next = cur->next_in_collection_set();
6213 assert(cur->in_collection_set(), "bad CS");
6214 cur->set_next_in_collection_set(NULL);
6215 cur->set_in_collection_set(false);
6216
6217 if (cur->is_young()) {
6218 int index = cur->young_index_in_cset();
6219 assert(index != -1, "invariant");
6220 assert((uint) index < policy->young_cset_region_length(), "invariant");
6221 size_t words_survived = _surviving_young_words[index];
6222 cur->record_surv_words_in_group(words_survived);
6223
6224 // At this point the we have 'popped' cur from the collection set
6225 // (linked via next_in_collection_set()) but it is still in the
6226 // young list (linked via next_young_region()). Clear the
6227 // _next_young_region field.
6228 cur->set_next_young_region(NULL);
6229 } else {
6230 int index = cur->young_index_in_cset();
6231 assert(index == -1, "invariant");
6232 }
6233
6234 assert( (cur->is_young() && cur->young_index_in_cset() > -1) ||
6235 (!cur->is_young() && cur->young_index_in_cset() == -1),
6236 "invariant" );
6237
6238 if (!cur->evacuation_failed()) {
6239 MemRegion used_mr = cur->used_region();
6240
6241 // And the region is empty.
6242 assert(!used_mr.is_empty(), "Should not have empty regions in a CS.");
6243 free_region(cur, &pre_used, &local_free_list, false /* par */, true /* locked */);
6244 } else {
6245 cur->uninstall_surv_rate_group();
6246 if (cur->is_young()) {
6247 cur->set_young_index_in_cset(-1);
6248 }
6249 cur->set_not_young();
6250 cur->set_evacuation_failed(false);
6251 // The region is now considered to be old.
6252 _old_set.add(cur);
6253 evacuation_info.increment_collectionset_used_after(cur->used());
6254 }
6255 cur = next;
6256 }
6257
6258 evacuation_info.set_regions_freed(local_free_list.length());
6259 policy->record_max_rs_lengths(rs_lengths);
6260 policy->cset_regions_freed();
6261
6262 double end_sec = os::elapsedTime();
6263 double elapsed_ms = (end_sec - start_sec) * 1000.0;
6870 if (nm != NULL) {
6871 nm->oops_do(&_oop_cl);
6872 }
6873 }
6874 };
6875
6876 class MarkStrongCodeRootsHRClosure: public HeapRegionClosure {
6877 G1CollectedHeap* _g1h;
6878 uint _worker_id;
6879
6880 public:
6881 MarkStrongCodeRootsHRClosure(G1CollectedHeap* g1h, uint worker_id) :
6882 _g1h(g1h), _worker_id(worker_id) {}
6883
6884 bool doHeapRegion(HeapRegion *hr) {
6885 HeapRegionRemSet* hrrs = hr->rem_set();
6886 if (hr->continuesHumongous()) {
6887 // Code roots should never be attached to a continuation of a humongous region
6888 assert(hrrs->strong_code_roots_list_length() == 0,
6889 err_msg("code roots should never be attached to continuations of humongous region "HR_FORMAT
6890 " starting at "HR_FORMAT", but has "SIZE_FORMAT,
6891 HR_FORMAT_PARAMS(hr), HR_FORMAT_PARAMS(hr->humongous_start_region()),
6892 hrrs->strong_code_roots_list_length()));
6893 return false;
6894 }
6895
6896 if (hr->in_collection_set()) {
6897 // Don't mark code roots into regions in the collection set here.
6898 // They will be marked when we scan them.
6899 return false;
6900 }
6901
6902 MarkStrongCodeRootCodeBlobClosure cb_cl(_g1h->concurrent_mark(), hr, _worker_id);
6903 hr->strong_code_roots_do(&cb_cl);
6904 return false;
6905 }
6906 };
6907
6908 void G1CollectedHeap::mark_strong_code_roots(uint worker_id) {
6909 MarkStrongCodeRootsHRClosure cl(this, worker_id);
6910 if (G1CollectedHeap::use_parallel_gc_threads()) {
|