6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "logging/log.hpp"
27 #include "gc/g1/concurrentMarkThread.hpp"
28 #include "gc/g1/g1Allocator.inline.hpp"
29 #include "gc/g1/g1CollectedHeap.hpp"
30 #include "gc/g1/g1CollectedHeap.inline.hpp"
31 #include "gc/g1/g1HeapVerifier.hpp"
32 #include "gc/g1/g1Policy.hpp"
33 #include "gc/g1/g1RemSet.hpp"
34 #include "gc/g1/g1RootProcessor.hpp"
35 #include "gc/g1/heapRegion.hpp"
36 #include "gc/g1/heapRegion.inline.hpp"
37 #include "gc/g1/heapRegionRemSet.hpp"
38 #include "gc/g1/g1StringDedup.hpp"
39 #include "memory/resourceArea.hpp"
40 #include "oops/oop.inline.hpp"
41
42 class VerifyRootsClosure: public OopClosure {
43 private:
44 G1CollectedHeap* _g1h;
45 VerifyOption _vo;
46 bool _failures;
47 public:
48 // _vo == UsePrevMarking -> use "prev" marking information,
49 // _vo == UseNextMarking -> use "next" marking information,
50 // _vo == UseMarkWord -> use mark word from object header.
51 VerifyRootsClosure(VerifyOption vo) :
52 _g1h(G1CollectedHeap::heap()),
53 _vo(vo),
54 _failures(false) { }
55
56 bool failures() { return _failures; }
57
58 template <class T> void do_oop_nv(T* p) {
59 T heap_oop = oopDesc::load_heap_oop(p);
60 if (!oopDesc::is_null(heap_oop)) {
61 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
62 if (_g1h->is_obj_dead_cond(obj, _vo)) {
63 Log(gc, verify) log;
64 log.info("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
65 if (_vo == VerifyOption_G1UseMarkWord) {
66 log.error(" Mark word: " PTR_FORMAT, p2i(obj->mark()));
67 }
68 ResourceMark rm;
69 obj->print_on(log.error_stream());
70 _failures = true;
71 }
72 }
73 }
74
75 void do_oop(oop* p) { do_oop_nv(p); }
76 void do_oop(narrowOop* p) { do_oop_nv(p); }
77 };
78
79 class G1VerifyCodeRootOopClosure: public OopClosure {
80 G1CollectedHeap* _g1h;
81 OopClosure* _root_cl;
82 nmethod* _nm;
83 VerifyOption _vo;
84 bool _failures;
85
86 template <class T> void do_oop_work(T* p) {
87 // First verify that this root is live
88 _root_cl->do_oop(p);
89
391 } else {
392 VerifyRegionClosure blk(false, vo);
393 _g1h->heap_region_iterate(&blk);
394 if (blk.failures()) {
395 failures = true;
396 }
397 }
398
399 if (G1StringDedup::is_enabled()) {
400 log_debug(gc, verify)("StrDedup");
401 G1StringDedup::verify();
402 }
403
404 if (failures) {
405 log_error(gc, verify)("Heap after failed verification:");
406 // It helps to have the per-region information in the output to
407 // help us track down what went wrong. This is why we call
408 // print_extended_on() instead of print_on().
409 Log(gc, verify) log;
410 ResourceMark rm;
411 _g1h->print_extended_on(log.error_stream());
412 }
413 guarantee(!failures, "there should not have been any failures");
414 }
415
416 // Heap region set verification
417
418 class VerifyRegionListsClosure : public HeapRegionClosure {
419 private:
420 HeapRegionSet* _old_set;
421 HeapRegionSet* _humongous_set;
422 HeapRegionManager* _hrm;
423
424 public:
425 uint _old_count;
426 uint _humongous_count;
427 uint _free_count;
428
429 VerifyRegionListsClosure(HeapRegionSet* old_set,
430 HeapRegionSet* humongous_set,
431 HeapRegionManager* hrm) :
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/g1/concurrentMarkThread.hpp"
27 #include "gc/g1/g1Allocator.inline.hpp"
28 #include "gc/g1/g1CollectedHeap.hpp"
29 #include "gc/g1/g1CollectedHeap.inline.hpp"
30 #include "gc/g1/g1HeapVerifier.hpp"
31 #include "gc/g1/g1Policy.hpp"
32 #include "gc/g1/g1RemSet.hpp"
33 #include "gc/g1/g1RootProcessor.hpp"
34 #include "gc/g1/heapRegion.hpp"
35 #include "gc/g1/heapRegion.inline.hpp"
36 #include "gc/g1/heapRegionRemSet.hpp"
37 #include "gc/g1/g1StringDedup.hpp"
38 #include "logging/log.hpp"
39 #include "logging/logStream.hpp"
40 #include "memory/resourceArea.hpp"
41 #include "oops/oop.inline.hpp"
42
43 class VerifyRootsClosure: public OopClosure {
44 private:
45 G1CollectedHeap* _g1h;
46 VerifyOption _vo;
47 bool _failures;
48 public:
49 // _vo == UsePrevMarking -> use "prev" marking information,
50 // _vo == UseNextMarking -> use "next" marking information,
51 // _vo == UseMarkWord -> use mark word from object header.
52 VerifyRootsClosure(VerifyOption vo) :
53 _g1h(G1CollectedHeap::heap()),
54 _vo(vo),
55 _failures(false) { }
56
57 bool failures() { return _failures; }
58
59 template <class T> void do_oop_nv(T* p) {
60 T heap_oop = oopDesc::load_heap_oop(p);
61 if (!oopDesc::is_null(heap_oop)) {
62 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
63 if (_g1h->is_obj_dead_cond(obj, _vo)) {
64 Log(gc, verify) log;
65 log.info("Root location " PTR_FORMAT " points to dead obj " PTR_FORMAT, p2i(p), p2i(obj));
66 if (_vo == VerifyOption_G1UseMarkWord) {
67 log.error(" Mark word: " PTR_FORMAT, p2i(obj->mark()));
68 }
69 ResourceMark rm;
70 // Unconditional write?
71 LogStream ls(log.error());
72 obj->print_on(&ls);
73 _failures = true;
74 }
75 }
76 }
77
78 void do_oop(oop* p) { do_oop_nv(p); }
79 void do_oop(narrowOop* p) { do_oop_nv(p); }
80 };
81
82 class G1VerifyCodeRootOopClosure: public OopClosure {
83 G1CollectedHeap* _g1h;
84 OopClosure* _root_cl;
85 nmethod* _nm;
86 VerifyOption _vo;
87 bool _failures;
88
89 template <class T> void do_oop_work(T* p) {
90 // First verify that this root is live
91 _root_cl->do_oop(p);
92
394 } else {
395 VerifyRegionClosure blk(false, vo);
396 _g1h->heap_region_iterate(&blk);
397 if (blk.failures()) {
398 failures = true;
399 }
400 }
401
402 if (G1StringDedup::is_enabled()) {
403 log_debug(gc, verify)("StrDedup");
404 G1StringDedup::verify();
405 }
406
407 if (failures) {
408 log_error(gc, verify)("Heap after failed verification:");
409 // It helps to have the per-region information in the output to
410 // help us track down what went wrong. This is why we call
411 // print_extended_on() instead of print_on().
412 Log(gc, verify) log;
413 ResourceMark rm;
414 // Unconditional write?
415 LogStream ls(log.error());
416 _g1h->print_extended_on(&ls);
417 }
418 guarantee(!failures, "there should not have been any failures");
419 }
420
421 // Heap region set verification
422
423 class VerifyRegionListsClosure : public HeapRegionClosure {
424 private:
425 HeapRegionSet* _old_set;
426 HeapRegionSet* _humongous_set;
427 HeapRegionManager* _hrm;
428
429 public:
430 uint _old_count;
431 uint _humongous_count;
432 uint _free_count;
433
434 VerifyRegionListsClosure(HeapRegionSet* old_set,
435 HeapRegionSet* humongous_set,
436 HeapRegionManager* hrm) :
|