Mercurial > hg > truffle
comparison src/share/vm/memory/metaspace.cpp @ 14237:db1ff6781ab4
Merge
author | morris |
---|---|
date | Fri, 10 Jan 2014 12:54:08 -0800 |
parents | ce86c36b8921 a2a3f08b96fa |
children | e4e941b83466 |
comparison
equal
deleted
inserted
replaced
14196:c8907928a976 | 14237:db1ff6781ab4 |
---|---|
285 // Accessors | 285 // Accessors |
286 MemRegion* reserved() { return &_reserved; } | 286 MemRegion* reserved() { return &_reserved; } |
287 VirtualSpace* virtual_space() const { return (VirtualSpace*) &_virtual_space; } | 287 VirtualSpace* virtual_space() const { return (VirtualSpace*) &_virtual_space; } |
288 | 288 |
289 // Returns true if "word_size" is available in the VirtualSpace | 289 // Returns true if "word_size" is available in the VirtualSpace |
290 bool is_available(size_t word_size) { return _top + word_size <= end(); } | 290 bool is_available(size_t word_size) { return word_size <= pointer_delta(end(), _top, sizeof(MetaWord)); } |
291 | 291 |
292 MetaWord* top() const { return _top; } | 292 MetaWord* top() const { return _top; } |
293 void inc_top(size_t word_size) { _top += word_size; } | 293 void inc_top(size_t word_size) { _top += word_size; } |
294 | 294 |
295 uintx container_count() { return _container_count; } | 295 uintx container_count() { return _container_count; } |
3638 assert(cm.sum_free_chunks_count() == (num_small_chunks + num_spec_chunks), "should be space for 3 chunks"); | 3638 assert(cm.sum_free_chunks_count() == (num_small_chunks + num_spec_chunks), "should be space for 3 chunks"); |
3639 assert(cm.sum_free_chunks() == words_left, "sizes should add up"); | 3639 assert(cm.sum_free_chunks() == words_left, "sizes should add up"); |
3640 } | 3640 } |
3641 | 3641 |
3642 } | 3642 } |
3643 | |
3644 #define assert_is_available_positive(word_size) \ | |
3645 assert(vsn.is_available(word_size), \ | |
3646 err_msg(#word_size ": " PTR_FORMAT " bytes were not available in " \ | |
3647 "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \ | |
3648 (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end())); | |
3649 | |
3650 #define assert_is_available_negative(word_size) \ | |
3651 assert(!vsn.is_available(word_size), \ | |
3652 err_msg(#word_size ": " PTR_FORMAT " bytes should not be available in " \ | |
3653 "VirtualSpaceNode [" PTR_FORMAT ", " PTR_FORMAT ")", \ | |
3654 (uintptr_t)(word_size * BytesPerWord), vsn.bottom(), vsn.end())); | |
3655 | |
3656 static void test_is_available_positive() { | |
3657 // Reserve some memory. | |
3658 VirtualSpaceNode vsn(os::vm_allocation_granularity()); | |
3659 assert(vsn.initialize(), "Failed to setup VirtualSpaceNode"); | |
3660 | |
3661 // Commit some memory. | |
3662 size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord; | |
3663 bool expanded = vsn.expand_by(commit_word_size, commit_word_size); | |
3664 assert(expanded, "Failed to commit"); | |
3665 | |
3666 // Check that is_available accepts the committed size. | |
3667 assert_is_available_positive(commit_word_size); | |
3668 | |
3669 // Check that is_available accepts half the committed size. | |
3670 size_t expand_word_size = commit_word_size / 2; | |
3671 assert_is_available_positive(expand_word_size); | |
3672 } | |
3673 | |
3674 static void test_is_available_negative() { | |
3675 // Reserve some memory. | |
3676 VirtualSpaceNode vsn(os::vm_allocation_granularity()); | |
3677 assert(vsn.initialize(), "Failed to setup VirtualSpaceNode"); | |
3678 | |
3679 // Commit some memory. | |
3680 size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord; | |
3681 bool expanded = vsn.expand_by(commit_word_size, commit_word_size); | |
3682 assert(expanded, "Failed to commit"); | |
3683 | |
3684 // Check that is_available doesn't accept a too large size. | |
3685 size_t two_times_commit_word_size = commit_word_size * 2; | |
3686 assert_is_available_negative(two_times_commit_word_size); | |
3687 } | |
3688 | |
3689 static void test_is_available_overflow() { | |
3690 // Reserve some memory. | |
3691 VirtualSpaceNode vsn(os::vm_allocation_granularity()); | |
3692 assert(vsn.initialize(), "Failed to setup VirtualSpaceNode"); | |
3693 | |
3694 // Commit some memory. | |
3695 size_t commit_word_size = os::vm_allocation_granularity() / BytesPerWord; | |
3696 bool expanded = vsn.expand_by(commit_word_size, commit_word_size); | |
3697 assert(expanded, "Failed to commit"); | |
3698 | |
3699 // Calculate a size that will overflow the virtual space size. | |
3700 void* virtual_space_max = (void*)(uintptr_t)-1; | |
3701 size_t bottom_to_max = pointer_delta(virtual_space_max, vsn.bottom(), 1); | |
3702 size_t overflow_size = bottom_to_max + BytesPerWord; | |
3703 size_t overflow_word_size = overflow_size / BytesPerWord; | |
3704 | |
3705 // Check that is_available can handle the overflow. | |
3706 assert_is_available_negative(overflow_word_size); | |
3707 } | |
3708 | |
3709 static void test_is_available() { | |
3710 TestVirtualSpaceNodeTest::test_is_available_positive(); | |
3711 TestVirtualSpaceNodeTest::test_is_available_negative(); | |
3712 TestVirtualSpaceNodeTest::test_is_available_overflow(); | |
3713 } | |
3643 }; | 3714 }; |
3644 | 3715 |
3645 void TestVirtualSpaceNode_test() { | 3716 void TestVirtualSpaceNode_test() { |
3646 TestVirtualSpaceNodeTest::test(); | 3717 TestVirtualSpaceNodeTest::test(); |
3718 TestVirtualSpaceNodeTest::test_is_available(); | |
3647 } | 3719 } |
3648 | 3720 |
3649 #endif | 3721 #endif |