Mercurial > hg > truffle
diff src/share/vm/gc_interface/collectedHeap.cpp @ 4708:3c648b9ad052
7121373: Clean up CollectedHeap::is_in
Summary: Fixed G1CollectedHeap::is_in, added tests, cleaned up comments and made Space::is_in pure virtual.
Reviewed-by: brutisso, tonyp, jcoomes
author | stefank |
---|---|
date | Wed, 14 Dec 2011 12:15:26 +0100 |
parents | e5928e7dab26 |
children | b6a04c79ccbc |
line wrap: on
line diff
--- a/src/share/vm/gc_interface/collectedHeap.cpp Fri Dec 09 19:28:34 2011 -0800 +++ b/src/share/vm/gc_interface/collectedHeap.cpp Wed Dec 14 12:15:26 2011 +0100 @@ -471,3 +471,26 @@ return mirror; } + +/////////////// Unit tests /////////////// + +#ifndef PRODUCT +void CollectedHeap::test_is_in() { + CollectedHeap* heap = Universe::heap(); + + // Test that NULL is not in the heap. + assert(!heap->is_in(NULL), "NULL is unexpectedly in the heap"); + + // Test that a pointer to before the heap start is reported as outside the heap. + assert(heap->_reserved.start() >= (void*)MinObjAlignment, "sanity"); + void* before_heap = (void*)((intptr_t)heap->_reserved.start() - MinObjAlignment); + assert(!heap->is_in(before_heap), + err_msg("before_heap: " PTR_FORMAT " is unexpectedly in the heap", before_heap)); + + // Test that a pointer to after the heap end is reported as outside the heap. + assert(heap->_reserved.end() <= (void*)(uintptr_t(-1) - (uint)MinObjAlignment), "sanity"); + void* after_heap = (void*)((intptr_t)heap->_reserved.end() + MinObjAlignment); + assert(!heap->is_in(after_heap), + err_msg("after_heap: " PTR_FORMAT " is unexpectedly in the heap", after_heap)); +} +#endif