1093 if (vs_word_size == 0) { |
1093 if (vs_word_size == 0) { |
1094 return false; |
1094 return false; |
1095 } |
1095 } |
1096 // Reserve the space |
1096 // Reserve the space |
1097 size_t vs_byte_size = vs_word_size * BytesPerWord; |
1097 size_t vs_byte_size = vs_word_size * BytesPerWord; |
1098 assert(vs_byte_size % os::vm_page_size() == 0, "Not aligned"); |
1098 assert(vs_byte_size % os::vm_allocation_granularity() == 0, "Not aligned"); |
1099 |
1099 |
1100 // Allocate the meta virtual space and initialize it. |
1100 // Allocate the meta virtual space and initialize it. |
1101 VirtualSpaceNode* new_entry = new VirtualSpaceNode(vs_byte_size); |
1101 VirtualSpaceNode* new_entry = new VirtualSpaceNode(vs_byte_size); |
1102 if (!new_entry->initialize()) { |
1102 if (!new_entry->initialize()) { |
1103 delete new_entry; |
1103 delete new_entry; |
1165 // Should the capacity of the metaspaces be expanded for |
1165 // Should the capacity of the metaspaces be expanded for |
1166 // this allocation? If it's the virtual space for classes and is |
1166 // this allocation? If it's the virtual space for classes and is |
1167 // being used for CompressedHeaders, don't allocate a new virtualspace. |
1167 // being used for CompressedHeaders, don't allocate a new virtualspace. |
1168 if (can_grow() && MetaspaceGC::should_expand(this, word_size)) { |
1168 if (can_grow() && MetaspaceGC::should_expand(this, word_size)) { |
1169 // Get another virtual space. |
1169 // Get another virtual space. |
1170 size_t grow_vs_words = |
1170 size_t allocation_aligned_expand_words = |
1171 MAX2((size_t)VirtualSpaceSize, aligned_expand_vs_by_words); |
1171 align_size_up(aligned_expand_vs_by_words, os::vm_allocation_granularity() / BytesPerWord); |
|
1172 size_t grow_vs_words = |
|
1173 MAX2((size_t)VirtualSpaceSize, allocation_aligned_expand_words); |
1172 if (grow_vs(grow_vs_words)) { |
1174 if (grow_vs(grow_vs_words)) { |
1173 // Got it. It's on the list now. Get a chunk from it. |
1175 // Got it. It's on the list now. Get a chunk from it. |
1174 assert(current_virtual_space()->expanded_words() == 0, |
1176 assert(current_virtual_space()->expanded_words() == 0, |
1175 "New virtuals space nodes should not have expanded"); |
1177 "New virtual space nodes should not have expanded"); |
1176 |
1178 |
1177 size_t grow_chunks_by_words_aligned = align_size_up(grow_chunks_by_words, |
1179 size_t grow_chunks_by_words_aligned = align_size_up(grow_chunks_by_words, |
1178 page_size_words); |
1180 page_size_words); |
1179 // We probably want to expand by aligned_expand_vs_by_words here. |
1181 // We probably want to expand by aligned_expand_vs_by_words here. |
1180 expand_by(current_virtual_space(), grow_chunks_by_words_aligned); |
1182 expand_by(current_virtual_space(), grow_chunks_by_words_aligned); |
3355 |
3357 |
3356 /////////////// Unit tests /////////////// |
3358 /////////////// Unit tests /////////////// |
3357 |
3359 |
3358 #ifndef PRODUCT |
3360 #ifndef PRODUCT |
3359 |
3361 |
3360 class MetaspaceAuxTest : AllStatic { |
3362 class TestMetaspaceAuxTest : AllStatic { |
3361 public: |
3363 public: |
3362 static void test_reserved() { |
3364 static void test_reserved() { |
3363 size_t reserved = MetaspaceAux::reserved_bytes(); |
3365 size_t reserved = MetaspaceAux::reserved_bytes(); |
3364 |
3366 |
3365 assert(reserved > 0, "assert"); |
3367 assert(reserved > 0, "assert"); |
3395 assert(committed_class > 0, "assert"); |
3397 assert(committed_class > 0, "assert"); |
3396 assert(committed_class < committed, "assert"); |
3398 assert(committed_class < committed, "assert"); |
3397 } |
3399 } |
3398 } |
3400 } |
3399 |
3401 |
|
3402 static void test_virtual_space_list_large_chunk() { |
|
3403 VirtualSpaceList* vs_list = new VirtualSpaceList(os::vm_allocation_granularity()); |
|
3404 MutexLockerEx cl(SpaceManager::expand_lock(), Mutex::_no_safepoint_check_flag); |
|
3405 // A size larger than VirtualSpaceSize (256k) and add one page to make it _not_ be |
|
3406 // vm_allocation_granularity aligned on Windows. |
|
3407 size_t large_size = (size_t)(2*256*K + (os::vm_page_size()/BytesPerWord)); |
|
3408 large_size += (os::vm_page_size()/BytesPerWord); |
|
3409 vs_list->get_new_chunk(large_size, large_size, 0); |
|
3410 } |
|
3411 |
3400 static void test() { |
3412 static void test() { |
3401 test_reserved(); |
3413 test_reserved(); |
3402 test_committed(); |
3414 test_committed(); |
|
3415 test_virtual_space_list_large_chunk(); |
3403 } |
3416 } |
3404 }; |
3417 }; |
3405 |
3418 |
3406 void MetaspaceAux_test() { |
3419 void TestMetaspaceAux_test() { |
3407 MetaspaceAuxTest::test(); |
3420 TestMetaspaceAuxTest::test(); |
3408 } |
3421 } |
3409 |
3422 |
3410 #endif |
3423 #endif |