comparison src/share/vm/gc_implementation/g1/g1CollectedHeap.cpp @ 390:cc68c8e9b309

6752248: G1: introduce parallel heap verification Summary: Introduce parallel heap verification in G1. Reviewed-by: jcoomes, apetrusenko
author tonyp
date Mon, 06 Oct 2008 13:16:35 -0400
parents 0edda524b58c
children 078b8a0d8d7c
comparison
equal deleted inserted replaced
389:ee21eaa8ffe1 390:cc68c8e9b309
1787 assert(!res, "Should not abort"); 1787 assert(!res, "Should not abort");
1788 } 1788 }
1789 } 1789 }
1790 } 1790 }
1791 1791
1792 class ResetClaimValuesClosure: public HeapRegionClosure {
1793 public:
1794 bool doHeapRegion(HeapRegion* r) {
1795 r->set_claim_value(HeapRegion::InitialClaimValue);
1796 return false;
1797 }
1798 };
1799
1800 void
1801 G1CollectedHeap::reset_heap_region_claim_values() {
1802 ResetClaimValuesClosure blk;
1803 heap_region_iterate(&blk);
1804 }
1805
1792 #ifdef ASSERT 1806 #ifdef ASSERT
1793 // This checks whether all regions in the heap have the correct claim 1807 // This checks whether all regions in the heap have the correct claim
1794 // value. I also piggy-backed on this a check to ensure that the 1808 // value. I also piggy-backed on this a check to ensure that the
1795 // humongous_start_region() information on "continues humongous" 1809 // humongous_start_region() information on "continues humongous"
1796 // regions is correct. 1810 // regions is correct.
2029 }; 2043 };
2030 2044
2031 class VerifyRegionClosure: public HeapRegionClosure { 2045 class VerifyRegionClosure: public HeapRegionClosure {
2032 public: 2046 public:
2033 bool _allow_dirty; 2047 bool _allow_dirty;
2034 VerifyRegionClosure(bool allow_dirty) 2048 bool _par;
2035 : _allow_dirty(allow_dirty) {} 2049 VerifyRegionClosure(bool allow_dirty, bool par = false)
2050 : _allow_dirty(allow_dirty), _par(par) {}
2036 bool doHeapRegion(HeapRegion* r) { 2051 bool doHeapRegion(HeapRegion* r) {
2037 guarantee(r->claim_value() == 0, "Should be unclaimed at verify points."); 2052 guarantee(_par || r->claim_value() == HeapRegion::InitialClaimValue,
2053 "Should be unclaimed at verify points.");
2038 if (r->isHumongous()) { 2054 if (r->isHumongous()) {
2039 if (r->startsHumongous()) { 2055 if (r->startsHumongous()) {
2040 // Verify the single H object. 2056 // Verify the single H object.
2041 oop(r->bottom())->verify(); 2057 oop(r->bottom())->verify();
2042 size_t word_sz = oop(r->bottom())->size(); 2058 size_t word_sz = oop(r->bottom())->size();
2080 } 2096 }
2081 } 2097 }
2082 } 2098 }
2083 }; 2099 };
2084 2100
2101 // This is the task used for parallel heap verification.
2102
2103 class G1ParVerifyTask: public AbstractGangTask {
2104 private:
2105 G1CollectedHeap* _g1h;
2106 bool _allow_dirty;
2107
2108 public:
2109 G1ParVerifyTask(G1CollectedHeap* g1h, bool allow_dirty) :
2110 AbstractGangTask("Parallel verify task"),
2111 _g1h(g1h), _allow_dirty(allow_dirty) { }
2112
2113 void work(int worker_i) {
2114 VerifyRegionClosure blk(_allow_dirty, true);
2115 _g1h->heap_region_par_iterate_chunked(&blk, worker_i,
2116 HeapRegion::ParVerifyClaimValue);
2117 }
2118 };
2119
2085 void G1CollectedHeap::verify(bool allow_dirty, bool silent) { 2120 void G1CollectedHeap::verify(bool allow_dirty, bool silent) {
2086 if (SafepointSynchronize::is_at_safepoint() || ! UseTLAB) { 2121 if (SafepointSynchronize::is_at_safepoint() || ! UseTLAB) {
2087 if (!silent) { gclog_or_tty->print("roots "); } 2122 if (!silent) { gclog_or_tty->print("roots "); }
2088 VerifyRootsClosure rootsCl; 2123 VerifyRootsClosure rootsCl;
2089 process_strong_roots(false, 2124 process_strong_roots(false,
2090 SharedHeap::SO_AllClasses, 2125 SharedHeap::SO_AllClasses,
2091 &rootsCl, 2126 &rootsCl,
2092 &rootsCl); 2127 &rootsCl);
2093 rem_set()->invalidate(perm_gen()->used_region(), false); 2128 rem_set()->invalidate(perm_gen()->used_region(), false);
2094 if (!silent) { gclog_or_tty->print("heapRegions "); } 2129 if (!silent) { gclog_or_tty->print("heapRegions "); }
2095 VerifyRegionClosure blk(allow_dirty); 2130 if (GCParallelVerificationEnabled && ParallelGCThreads > 1) {
2096 _hrs->iterate(&blk); 2131 assert(check_heap_region_claim_values(HeapRegion::InitialClaimValue),
2132 "sanity check");
2133
2134 G1ParVerifyTask task(this, allow_dirty);
2135 int n_workers = workers()->total_workers();
2136 set_par_threads(n_workers);
2137 workers()->run_task(&task);
2138 set_par_threads(0);
2139
2140 assert(check_heap_region_claim_values(HeapRegion::ParVerifyClaimValue),
2141 "sanity check");
2142
2143 reset_heap_region_claim_values();
2144
2145 assert(check_heap_region_claim_values(HeapRegion::InitialClaimValue),
2146 "sanity check");
2147 } else {
2148 VerifyRegionClosure blk(allow_dirty);
2149 _hrs->iterate(&blk);
2150 }
2097 if (!silent) gclog_or_tty->print("remset "); 2151 if (!silent) gclog_or_tty->print("remset ");
2098 rem_set()->verify(); 2152 rem_set()->verify();
2099 guarantee(!rootsCl.failures(), "should not have had failures"); 2153 guarantee(!rootsCl.failures(), "should not have had failures");
2100 } else { 2154 } else {
2101 if (!silent) gclog_or_tty->print("(SKIPPING roots, heapRegions, remset) "); 2155 if (!silent) gclog_or_tty->print("(SKIPPING roots, heapRegions, remset) ");