73 |
73 |
74 void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() { |
74 void G1YoungRemSetSamplingThread::sample_young_list_rs_lengths() { |
75 SuspendibleThreadSetJoiner sts; |
75 SuspendibleThreadSetJoiner sts; |
76 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
76 G1CollectedHeap* g1h = G1CollectedHeap::heap(); |
77 G1Policy* g1p = g1h->g1_policy(); |
77 G1Policy* g1p = g1h->g1_policy(); |
|
78 G1CollectionSet* g1cs = g1h->collection_set(); |
78 if (g1p->adaptive_young_list_length()) { |
79 if (g1p->adaptive_young_list_length()) { |
79 int regions_visited = 0; |
80 int regions_visited = 0; |
80 HeapRegion* hr = g1h->young_list()->first_region(); |
81 HeapRegion* hr = g1cs->inc_head(); |
81 size_t sampled_rs_lengths = 0; |
82 size_t sampled_rs_lengths = 0; |
82 |
83 |
83 while (hr != NULL) { |
84 while (hr != NULL) { |
84 size_t rs_length = hr->rem_set()->occupied(); |
85 size_t rs_length = hr->rem_set()->occupied(); |
85 sampled_rs_lengths += rs_length; |
86 sampled_rs_lengths += rs_length; |
86 |
87 |
87 // The current region may not yet have been added to the |
88 // Update the collection set policy information for this region |
88 // incremental collection set (it gets added when it is |
89 g1cs->update_young_region_prediction(hr, rs_length); |
89 // retired as the current allocation region). |
|
90 if (hr->in_collection_set()) { |
|
91 // Update the collection set policy information for this region |
|
92 g1h->collection_set()->update_young_region_prediction(hr, rs_length); |
|
93 } |
|
94 |
90 |
95 ++regions_visited; |
91 ++regions_visited; |
96 |
92 |
97 // we try to yield every time we visit 10 regions |
93 // we try to yield every time we visit 10 regions |
98 if (regions_visited == 10) { |
94 if (regions_visited == 10) { |
99 if (sts.should_yield()) { |
95 if (sts.should_yield()) { |
100 sts.yield(); |
96 sts.yield(); |
101 // A gc may have occurred and our sampling data is stale and further |
97 // A gc may have occurred and our sampling data is stale and further |
102 // traversal of the young list is unsafe |
98 // traversal of the collection set is unsafe |
103 return; |
99 return; |
104 } |
100 } |
105 regions_visited = 0; |
101 regions_visited = 0; |
106 } |
102 } |
107 hr = hr->get_next_young_region(); |
103 assert(hr == g1cs->inc_tail() || hr->next_in_collection_set() != NULL, "next should only be null at tail of icset"); |
|
104 hr = hr->next_in_collection_set(); |
108 } |
105 } |
109 g1p->revise_young_list_target_length_if_necessary(sampled_rs_lengths); |
106 g1p->revise_young_list_target_length_if_necessary(sampled_rs_lengths); |
110 } |
107 } |
111 } |
108 } |