/* * Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// Make sure region size is a power of 2. Rounding up since this // is beneficial in most cases.
region_size = round_up_power_of_2(region_size);
// Now make sure that we don't go over or under our limits.
region_size = clamp(region_size, HeapRegionBounds::min_size(), HeapRegionBounds::max_size());
// Calculate the log for the region size. int region_size_log = log2i_exact(region_size);
// Now, set up the globals.
guarantee(LogOfHRGrainBytes == 0, "we should only set it once");
LogOfHRGrainBytes = region_size_log;
guarantee(GrainBytes == 0, "we should only set it once");
GrainBytes = region_size;
guarantee(GrainWords == 0, "we should only set it once");
GrainWords = GrainBytes >> LogHeapWordSize;
guarantee(CardsPerRegion == 0, "we should only set it once");
CardsPerRegion = GrainBytes >> G1CardTable::card_shift();
LogCardsPerRegion = log2i(CardsPerRegion);
if (G1HeapRegionSize != GrainBytes) {
FLAG_SET_ERGO(G1HeapRegionSize, GrainBytes);
}
}
void HeapRegion::calc_gc_efficiency() { // GC efficiency is the ratio of how much space would be // reclaimed over how long we predict it would take to reclaim it.
G1Policy* policy = G1CollectedHeap::heap()->policy();
// Retrieve a prediction of the elapsed time for this region for // a mixed gc because the region will only be evacuated during a // mixed gc. double region_elapsed_time_ms = policy->predict_region_total_time_ms(this, false/* for_young_only_phase */);
_gc_efficiency = (double) reclaimable_bytes() / region_elapsed_time_ms;
}
_rem_set = new HeapRegionRemSet(this, config);
initialize();
}
void HeapRegion::initialize(bool clear_space, bool mangle_space) {
assert(_rem_set->is_empty(), "Remembered set must be empty");
if (clear_space) {
clear(mangle_space);
}
set_top(bottom());
hr_clear(false/*clear_space*/);
}
void HeapRegion::report_region_type_change(G1HeapRegionTraceType::Type to) {
HeapRegionTracer::send_region_type_change(_hrm_index,
get_trace_type(),
to,
(uintptr_t)bottom(),
used());
}
void HeapRegion::note_evacuation_failure(bool during_concurrent_start) { // PB must be bottom - we only evacuate old gen regions after scrubbing, and // young gen regions never have their PB set to anything other than bottom.
assert(parsable_bottom_acquire() == bottom(), "must be");
_garbage_bytes = 0;
if (during_concurrent_start) { // Self-forwarding marks all objects. Adjust TAMS so that these marks are // below it.
set_top_at_mark_start(top());
} else { // Outside of the mixed phase all regions that had an evacuation failure must // be young regions, and their TAMS is always bottom. Similarly, before the // start of the mixed phase, we scrubbed and reset TAMS to bottom.
assert(top_at_mark_start() == bottom(), "must be");
}
}
class VerifyCodeRootOopClosure: public OopClosure { const HeapRegion* _hr; bool _failures; bool _has_oops_in_region;
template <class T> void do_oop_work(T* p) {
T heap_oop = RawAccess<>::oop_load(p); if (!CompressedOops::is_null(heap_oop)) {
oop obj = CompressedOops::decode_not_null(heap_oop);
// Note: not all the oops embedded in the nmethod are in the // current region. We only look at those which are. if (_hr->is_in(obj)) { // Object is in the region. Check that its less than top if (_hr->top() <= cast_from_oop<HeapWord*>(obj)) { // Object is above top
log_error(gc, verify)("Object " PTR_FORMAT " in region " HR_FORMAT " is above top ",
p2i(obj), HR_FORMAT_PARAMS(_hr));
_failures = true; return;
} // Nmethod has at least one oop in the current region
_has_oops_in_region = true;
}
}
}
class VerifyCodeRootCodeBlobClosure: public CodeBlobClosure { const HeapRegion* _hr; bool _failures; public:
VerifyCodeRootCodeBlobClosure(const HeapRegion* hr) :
_hr(hr), _failures(false) {}
void do_code_blob(CodeBlob* cb) {
nmethod* nm = (cb == NULL) ? NULL : cb->as_compiled_method()->as_nmethod_or_null(); if (nm != NULL) { // Verify that the nemthod is live
VerifyCodeRootOopClosure oop_cl(_hr);
nm->oops_do(&oop_cl); if (!oop_cl.has_oops_in_region()) {
log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has nmethod " PTR_FORMAT " in its code roots with no pointers into region",
p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
_failures = true;
} elseif (oop_cl.failures()) {
log_error(gc, verify)("region [" PTR_FORMAT "," PTR_FORMAT "] has other failures for nmethod " PTR_FORMAT,
p2i(_hr->bottom()), p2i(_hr->end()), p2i(nm));
_failures = true;
}
}
}
bool failures() { return _failures; }
};
void HeapRegion::verify_code_roots(VerifyOption vo, bool* failures) const { if (!G1VerifyHeapRegionCodeRoots) { // We're not verifying code roots. return;
} if (vo == VerifyOption::G1UseFullMarking) { // Marking verification during a full GC is performed after class // unloading, code cache unloading, etc so the code roots // attached to each heap region are in an inconsistent state. They won't // be consistent until the code roots are rebuilt after the // actual GC. Skip verifying the code roots in this particular // time.
assert(VerifyDuringGC, "only way to get here"); return;
}
// if this region is empty then there should be no entries // on its code root list if (is_empty()) { if (code_roots_length > 0) {
log_error(gc, verify)("region " HR_FORMAT " is empty but has " SIZE_FORMAT " code root entries",
HR_FORMAT_PARAMS(this), code_roots_length);
*failures = true;
} return;
}
if (is_continues_humongous()) { if (code_roots_length > 0) {
log_error(gc, verify)("region " HR_FORMAT " is a continuation of a humongous region but has " SIZE_FORMAT " code root entries",
HR_FORMAT_PARAMS(this), code_roots_length);
*failures = true;
} return;
}
if (!_failures) {
log.error("----------");
}
log.error("Missing rem set entry:");
log.error("Field " PTR_FORMAT " of obj " PTR_FORMAT " in region " HR_FORMAT,
p2i(p), p2i(_containing_obj), HR_FORMAT_PARAMS(from));
ResourceMark rm;
LogStream ls(log.error());
_containing_obj->print_on(&ls);
log.error("points to obj " PTR_FORMAT " in region " HR_FORMAT " remset %s",
p2i(obj), HR_FORMAT_PARAMS(to), to->rem_set()->get_state_str()); if (oopDesc::is_oop(obj)) {
obj->print_on(&ls);
}
log.error("Obj head CTE = %d, field CTE = %d.", cv_obj, cv_field);
log.error("----------");
_failures = true;
_n_failures++;
}
}
}
}
};
// Closure that applies the given two closures in sequence. class G1Mux2Closure : public BasicOopIterateClosure {
OopClosure* _c1;
OopClosure* _c2; public:
G1Mux2Closure(OopClosure *c1, OopClosure *c2) { _c1 = c1; _c2 = c2; } template <class T> inlinevoid do_oop_work(T* p) { // Apply first closure; then apply the second.
_c1->do_oop(p);
_c2->do_oop(p);
} virtualinlinevoid do_oop(oop* p) { do_oop_work(p); } virtualinlinevoid do_oop(narrowOop* p) { do_oop_work(p); }
};
void HeapRegion::verify(VerifyOption vo, bool* failures) const {
G1CollectedHeap* g1h = G1CollectedHeap::heap();
*failures = false;
HeapWord* p = bottom();
HeapWord* prev_p = NULL;
VerifyLiveClosure vl_cl(g1h, vo);
VerifyRemSetClosure vr_cl(g1h, vo); bool is_region_humongous = is_humongous(); // We cast p to an oop, so region-bottom must be an obj-start.
assert(!is_region_humongous || is_starts_humongous(), "invariant");
size_t object_num = 0; while (p < top()) {
oop obj = cast_to_oop(p);
size_t obj_size = block_size(p);
object_num += 1;
if (!g1h->is_obj_dead_cond(obj, this, vo)) { if (oopDesc::is_oop(obj)) {
Klass* klass = obj->klass(); bool is_metaspace_object = Metaspace::contains(klass); if (!is_metaspace_object) {
log_error(gc, verify)("klass " PTR_FORMAT " of object " PTR_FORMAT " " "not metadata", p2i(klass), p2i(obj));
*failures = true; return;
} elseif (!klass->is_klass()) {
log_error(gc, verify)("klass " PTR_FORMAT " of object " PTR_FORMAT " " "not a klass", p2i(klass), p2i(obj));
*failures = true; return;
} else {
vl_cl.set_containing_obj(obj); if (!g1h->collector_state()->in_full_gc() || G1VerifyRSetsDuringFullGC) { // verify liveness and rem_set
vr_cl.set_containing_obj(obj);
G1Mux2Closure mux(&vl_cl, &vr_cl);
obj->oop_iterate(&mux);
if (vr_cl.failures()) {
*failures = true;
} if (G1MaxVerifyFailures >= 0 &&
vr_cl.n_failures() >= G1MaxVerifyFailures) { return;
}
} else { // verify only liveness
obj->oop_iterate(&vl_cl);
} if (vl_cl.failures()) {
*failures = true;
} if (G1MaxVerifyFailures >= 0 &&
vl_cl.n_failures() >= G1MaxVerifyFailures) { return;
}
}
} else {
log_error(gc, verify)(PTR_FORMAT " not an oop", p2i(obj));
*failures = true; return;
}
}
prev_p = p;
p += obj_size;
}
// Only regions in old generation contain valid BOT. if (!is_empty() && !is_young()) {
_bot_part.verify();
}
if (is_region_humongous) {
oop obj = cast_to_oop(this->humongous_start_region()->bottom()); if (cast_from_oop<HeapWord*>(obj) > bottom() || cast_from_oop<HeapWord*>(obj) + obj->size() < bottom()) {
log_error(gc, verify)("this humongous region is not part of its' humongous object " PTR_FORMAT, p2i(obj));
*failures = true; return;
}
}
if (!is_region_humongous && p != top()) {
log_error(gc, verify)("end of last object " PTR_FORMAT " " "does not match top " PTR_FORMAT, p2i(p), p2i(top()));
*failures = true; return;
}
void HeapRegion::object_iterate(ObjectClosure* blk) {
HeapWord* p = bottom(); while (p < top()) { if (block_is_obj(p, parsable_bottom())) {
blk->do_object(cast_to_oop(p));
}
p += block_size(p);
}
}
void HeapRegion::fill_with_dummy_object(HeapWord* address, size_t word_size, bool zap) { // Keep the BOT in sync for old generation regions. if (is_old()) {
update_bot_for_obj(address, word_size);
} // Fill in the object.
CollectedHeap::fill_with_object(address, word_size, zap);
}
// Fill the dead range with objects. G1 might need to create two objects if // the range is larger than half a region, which is the max_fill_size().
CollectedHeap::fill_with_objects(start, range_size);
HeapWord* current = start; do { // Update the BOT if the a threshold is crossed.
size_t obj_size = cast_to_oop(current)->size();
update_bot_for_block(current, current + obj_size);
// Advance to the next object.
current += obj_size;
guarantee(current <= end, "Should never go past end");
} while (current != end);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.