1 /*
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
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 *
403 // the card is not young. And we only clean the card if we have been
404 // asked to (i.e., card_ptr != NULL).
405 if (card_ptr != NULL) {
406 *card_ptr = CardTableModRefBS::clean_card_val();
407 // We must complete this write before we do any of the reads below.
408 OrderAccess::storeload();
409 }
410
411 // Cache the boundaries of the memory region in some const locals
412 HeapWord* const start = mr.start();
413 HeapWord* const end = mr.end();
414
415 // We used to use "block_start_careful" here. But we're actually happy
416 // to update the BOT while we do this...
417 HeapWord* cur = block_start(start);
418 assert(cur <= start, "Postcondition");
419
420 oop obj;
421
422 HeapWord* next = cur;
423 while (next <= start) {
424 cur = next;
425 obj = oop(cur);
426 if (obj->klass_or_null() == NULL) {
427 // Ran into an unparseable point.
428 return cur;
429 }
430 // Otherwise...
431 next = cur + block_size(cur);
432 }
433
434 // If we finish the above loop...We have a parseable object that
435 // begins on or before the start of the memory region, and ends
436 // inside or spans the entire region.
437
438 assert(obj == oop(cur), "sanity");
439 assert(cur <= start, "Loop postcondition");
440 assert(obj->klass_or_null() != NULL, "Loop postcondition");
441 assert((cur + block_size(cur)) > start, "Loop postcondition");
442
443 if (!g1h->is_obj_dead(obj)) {
444 obj->oop_iterate(cl, mr);
445 }
446
447 while (cur < end) {
448 obj = oop(cur);
449 if (obj->klass_or_null() == NULL) {
450 // Ran into an unparseable point.
451 return cur;
452 };
453
454 // Otherwise:
455 next = cur + block_size(cur);
456
457 if (!g1h->is_obj_dead(obj)) {
458 if (next < end || !obj->is_objArray()) {
459 // This object either does not span the MemRegion
460 // boundary, or if it does it's not an array.
461 // Apply closure to whole object.
462 obj->oop_iterate(cl);
463 } else {
464 // This obj is an array that spans the boundary.
465 // Stop at the boundary.
466 obj->oop_iterate(cl, mr);
467 }
468 }
469 cur = next;
470 }
471 return NULL;
472 }
473
474 // Code roots support
475
476 void HeapRegion::add_strong_code_root(nmethod* nm) {
477 HeapRegionRemSet* hrrs = rem_set();
478 hrrs->add_strong_code_root(nm);
479 }
480
481 void HeapRegion::add_strong_code_root_locked(nmethod* nm) {
482 assert_locked_or_safepoint(CodeCache_lock);
483 HeapRegionRemSet* hrrs = rem_set();
484 hrrs->add_strong_code_root_locked(nm);
485 }
486
487 void HeapRegion::remove_strong_code_root(nmethod* nm) {
488 HeapRegionRemSet* hrrs = rem_set();
489 hrrs->remove_strong_code_root(nm);
490 }
|
1 /*
2 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
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 *
403 // the card is not young. And we only clean the card if we have been
404 // asked to (i.e., card_ptr != NULL).
405 if (card_ptr != NULL) {
406 *card_ptr = CardTableModRefBS::clean_card_val();
407 // We must complete this write before we do any of the reads below.
408 OrderAccess::storeload();
409 }
410
411 // Cache the boundaries of the memory region in some const locals
412 HeapWord* const start = mr.start();
413 HeapWord* const end = mr.end();
414
415 // We used to use "block_start_careful" here. But we're actually happy
416 // to update the BOT while we do this...
417 HeapWord* cur = block_start(start);
418 assert(cur <= start, "Postcondition");
419
420 oop obj;
421
422 HeapWord* next = cur;
423 do {
424 cur = next;
425 obj = oop(cur);
426 if (obj->klass_or_null() == NULL) {
427 // Ran into an unparseable point.
428 return cur;
429 }
430 // Otherwise...
431 next = cur + block_size(cur);
432 } while (next <= start);
433
434 // If we finish the above loop...We have a parseable object that
435 // begins on or before the start of the memory region, and ends
436 // inside or spans the entire region.
437 assert(cur <= start, "Loop postcondition");
438 assert(obj->klass_or_null() != NULL, "Loop postcondition");
439
440 do {
441 obj = oop(cur);
442 assert((cur + block_size(cur)) > (HeapWord*)obj, "Loop invariant");
443 if (obj->klass_or_null() == NULL) {
444 // Ran into an unparseable point.
445 return cur;
446 }
447
448 // Advance the current pointer. "obj" still points to the object to iterate.
449 cur = cur + block_size(cur);
450
451 if (!g1h->is_obj_dead(obj)) {
452 // Non-objArrays are sometimes marked imprecise at the object start. We
453 // always need to iterate over them in full.
454 // We only iterate over object arrays in full if they are completely contained
455 // in the memory region.
456 if (!obj->is_objArray() || (((HeapWord*)obj) >= start && cur <= end)) {
457 obj->oop_iterate(cl);
458 } else {
459 obj->oop_iterate(cl, mr);
460 }
461 }
462 } while (cur < end);
463
464 return NULL;
465 }
466
467 // Code roots support
468
469 void HeapRegion::add_strong_code_root(nmethod* nm) {
470 HeapRegionRemSet* hrrs = rem_set();
471 hrrs->add_strong_code_root(nm);
472 }
473
474 void HeapRegion::add_strong_code_root_locked(nmethod* nm) {
475 assert_locked_or_safepoint(CodeCache_lock);
476 HeapRegionRemSet* hrrs = rem_set();
477 hrrs->add_strong_code_root_locked(nm);
478 }
479
480 void HeapRegion::remove_strong_code_root(nmethod* nm) {
481 HeapRegionRemSet* hrrs = rem_set();
482 hrrs->remove_strong_code_root(nm);
483 }
|