442 assert(Universe::heap()->is_in_reserved(start + words - 1), "not in heap");
443 }
444
445 void CollectedHeap::zap_filler_array(HeapWord* start, size_t words, bool zap)
446 {
447 if (ZapFillerObjects && zap) {
448 Copy::fill_to_words(start + filler_array_hdr_size(),
449 words - filler_array_hdr_size(), 0XDEAFBABE);
450 }
451 }
452 #endif // ASSERT
453
454 void
455 CollectedHeap::fill_with_array(HeapWord* start, size_t words, bool zap)
456 {
457 assert(words >= filler_array_min_size(), "too small for an array");
458 assert(words <= filler_array_max_size(), "too big for a single object");
459
460 const size_t payload_size = words - filler_array_hdr_size();
461 const size_t len = payload_size * HeapWordSize / sizeof(jint);
462 assert((int)len >= 0, err_msg("size too large " SIZE_FORMAT " becomes %d", words, (int)len));
463
464 // Set the length first for concurrent GC.
465 ((arrayOop)start)->set_length((int)len);
466 post_allocation_setup_common(Universe::intArrayKlassObj(), start);
467 DEBUG_ONLY(zap_filler_array(start, words, zap);)
468 }
469
470 void
471 CollectedHeap::fill_with_object_impl(HeapWord* start, size_t words, bool zap)
472 {
473 assert(words <= filler_array_max_size(), "too big for a single object");
474
475 if (words >= filler_array_min_size()) {
476 fill_with_array(start, words, zap);
477 } else if (words > 0) {
478 assert(words == min_fill_size(), "unaligned size");
479 post_allocation_setup_common(SystemDictionary::Object_klass(), start);
480 }
481 }
482
605 _reserved.set_end(end);
606 }
607
608 /////////////// Unit tests ///////////////
609
610 #ifndef PRODUCT
611 void CollectedHeap::test_is_in() {
612 CollectedHeap* heap = Universe::heap();
613
614 uintptr_t epsilon = (uintptr_t) MinObjAlignment;
615 uintptr_t heap_start = (uintptr_t) heap->_reserved.start();
616 uintptr_t heap_end = (uintptr_t) heap->_reserved.end();
617
618 // Test that NULL is not in the heap.
619 assert(!heap->is_in(NULL), "NULL is unexpectedly in the heap");
620
621 // Test that a pointer to before the heap start is reported as outside the heap.
622 assert(heap_start >= ((uintptr_t)NULL + epsilon), "sanity");
623 void* before_heap = (void*)(heap_start - epsilon);
624 assert(!heap->is_in(before_heap),
625 err_msg("before_heap: " PTR_FORMAT " is unexpectedly in the heap", p2i(before_heap)));
626
627 // Test that a pointer to after the heap end is reported as outside the heap.
628 assert(heap_end <= ((uintptr_t)-1 - epsilon), "sanity");
629 void* after_heap = (void*)(heap_end + epsilon);
630 assert(!heap->is_in(after_heap),
631 err_msg("after_heap: " PTR_FORMAT " is unexpectedly in the heap", p2i(after_heap)));
632 }
633 #endif
|
442 assert(Universe::heap()->is_in_reserved(start + words - 1), "not in heap");
443 }
444
445 void CollectedHeap::zap_filler_array(HeapWord* start, size_t words, bool zap)
446 {
447 if (ZapFillerObjects && zap) {
448 Copy::fill_to_words(start + filler_array_hdr_size(),
449 words - filler_array_hdr_size(), 0XDEAFBABE);
450 }
451 }
452 #endif // ASSERT
453
454 void
455 CollectedHeap::fill_with_array(HeapWord* start, size_t words, bool zap)
456 {
457 assert(words >= filler_array_min_size(), "too small for an array");
458 assert(words <= filler_array_max_size(), "too big for a single object");
459
460 const size_t payload_size = words - filler_array_hdr_size();
461 const size_t len = payload_size * HeapWordSize / sizeof(jint);
462 assert((int)len >= 0, "size too large " SIZE_FORMAT " becomes %d", words, (int)len);
463
464 // Set the length first for concurrent GC.
465 ((arrayOop)start)->set_length((int)len);
466 post_allocation_setup_common(Universe::intArrayKlassObj(), start);
467 DEBUG_ONLY(zap_filler_array(start, words, zap);)
468 }
469
470 void
471 CollectedHeap::fill_with_object_impl(HeapWord* start, size_t words, bool zap)
472 {
473 assert(words <= filler_array_max_size(), "too big for a single object");
474
475 if (words >= filler_array_min_size()) {
476 fill_with_array(start, words, zap);
477 } else if (words > 0) {
478 assert(words == min_fill_size(), "unaligned size");
479 post_allocation_setup_common(SystemDictionary::Object_klass(), start);
480 }
481 }
482
605 _reserved.set_end(end);
606 }
607
608 /////////////// Unit tests ///////////////
609
610 #ifndef PRODUCT
611 void CollectedHeap::test_is_in() {
612 CollectedHeap* heap = Universe::heap();
613
614 uintptr_t epsilon = (uintptr_t) MinObjAlignment;
615 uintptr_t heap_start = (uintptr_t) heap->_reserved.start();
616 uintptr_t heap_end = (uintptr_t) heap->_reserved.end();
617
618 // Test that NULL is not in the heap.
619 assert(!heap->is_in(NULL), "NULL is unexpectedly in the heap");
620
621 // Test that a pointer to before the heap start is reported as outside the heap.
622 assert(heap_start >= ((uintptr_t)NULL + epsilon), "sanity");
623 void* before_heap = (void*)(heap_start - epsilon);
624 assert(!heap->is_in(before_heap),
625 "before_heap: " PTR_FORMAT " is unexpectedly in the heap", p2i(before_heap));
626
627 // Test that a pointer to after the heap end is reported as outside the heap.
628 assert(heap_end <= ((uintptr_t)-1 - epsilon), "sanity");
629 void* after_heap = (void*)(heap_end + epsilon);
630 assert(!heap->is_in(after_heap),
631 "after_heap: " PTR_FORMAT " is unexpectedly in the heap", p2i(after_heap));
632 }
633 #endif
|