742 // Based on the allocation size and a minimum chunk size,
743 // returned chunk size (for expanding space for chunk allocation).
744 size_t calc_chunk_size(size_t allocation_word_size);
745
746 // Called when an allocation from the current chunk fails.
747 // Gets a new chunk (may require getting a new virtual space),
748 // and allocates from that chunk.
749 MetaWord* grow_and_allocate(size_t word_size);
750
751 // Notify memory usage to MemoryService.
752 void track_metaspace_memory_usage();
753
754 // debugging support.
755
756 void dump(outputStream* const out) const;
757 void print_on(outputStream* st) const;
758 void locked_print_chunks_in_use_on(outputStream* st) const;
759
760 void verify();
761 void verify_chunk_size(Metachunk* chunk);
762 NOT_PRODUCT(void mangle_freed_chunks();)
763 #ifdef ASSERT
764 void verify_allocated_blocks_words();
765 #endif
766
767 size_t get_raw_word_size(size_t word_size) {
768 size_t byte_size = word_size * BytesPerWord;
769
770 size_t raw_bytes_size = MAX2(byte_size, sizeof(Metablock));
771 raw_bytes_size = align_size_up(raw_bytes_size, Metachunk::object_alignment());
772
773 size_t raw_word_size = raw_bytes_size / BytesPerWord;
774 assert(raw_word_size * BytesPerWord == raw_bytes_size, "Size problem");
775
776 return raw_word_size;
777 }
778 };
779
780 uint const SpaceManager::_small_chunk_limit = 4;
781
782 const char* SpaceManager::_expand_lock_name =
2494 curr->print_on(out);
2495 curr_total += curr->word_size();
2496 used += curr->used_word_size();
2497 capacity += curr->word_size();
2498 waste += curr->free_word_size() + curr->overhead();;
2499 }
2500 }
2501
2502 if (log_is_enabled(Trace, gc, metaspace, freelist)) {
2503 block_freelists()->print_on(out);
2504 }
2505
2506 size_t free = current_chunk() == NULL ? 0 : current_chunk()->free_word_size();
2507 // Free space isn't wasted.
2508 waste -= free;
2509
2510 out->print_cr("total of all chunks " SIZE_FORMAT " used " SIZE_FORMAT
2511 " free " SIZE_FORMAT " capacity " SIZE_FORMAT
2512 " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
2513 }
2514
2515 #ifndef PRODUCT
2516 void SpaceManager::mangle_freed_chunks() {
2517 for (ChunkIndex index = ZeroIndex;
2518 index < NumberOfInUseLists;
2519 index = next_chunk_index(index)) {
2520 for (Metachunk* curr = chunks_in_use(index);
2521 curr != NULL;
2522 curr = curr->next()) {
2523 curr->mangle();
2524 }
2525 }
2526 }
2527 #endif // PRODUCT
2528
2529 // MetaspaceAux
2530
2531
2532 size_t MetaspaceAux::_capacity_words[] = {0, 0};
2533 size_t MetaspaceAux::_used_words[] = {0, 0};
2534
2535 size_t MetaspaceAux::free_bytes(Metaspace::MetadataType mdtype) {
2536 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
2537 return list == NULL ? 0 : list->free_bytes();
2538 }
2539
2540 size_t MetaspaceAux::free_bytes() {
2541 return free_bytes(Metaspace::ClassType) + free_bytes(Metaspace::NonClassType);
2542 }
2543
2544 void MetaspaceAux::dec_capacity(Metaspace::MetadataType mdtype, size_t words) {
2545 assert_lock_strong(SpaceManager::expand_lock());
2546 assert(words <= capacity_words(mdtype),
2547 "About to decrement below 0: words " SIZE_FORMAT
|
742 // Based on the allocation size and a minimum chunk size,
743 // returned chunk size (for expanding space for chunk allocation).
744 size_t calc_chunk_size(size_t allocation_word_size);
745
746 // Called when an allocation from the current chunk fails.
747 // Gets a new chunk (may require getting a new virtual space),
748 // and allocates from that chunk.
749 MetaWord* grow_and_allocate(size_t word_size);
750
751 // Notify memory usage to MemoryService.
752 void track_metaspace_memory_usage();
753
754 // debugging support.
755
756 void dump(outputStream* const out) const;
757 void print_on(outputStream* st) const;
758 void locked_print_chunks_in_use_on(outputStream* st) const;
759
760 void verify();
761 void verify_chunk_size(Metachunk* chunk);
762 #ifdef ASSERT
763 void verify_allocated_blocks_words();
764 #endif
765
766 size_t get_raw_word_size(size_t word_size) {
767 size_t byte_size = word_size * BytesPerWord;
768
769 size_t raw_bytes_size = MAX2(byte_size, sizeof(Metablock));
770 raw_bytes_size = align_size_up(raw_bytes_size, Metachunk::object_alignment());
771
772 size_t raw_word_size = raw_bytes_size / BytesPerWord;
773 assert(raw_word_size * BytesPerWord == raw_bytes_size, "Size problem");
774
775 return raw_word_size;
776 }
777 };
778
779 uint const SpaceManager::_small_chunk_limit = 4;
780
781 const char* SpaceManager::_expand_lock_name =
2493 curr->print_on(out);
2494 curr_total += curr->word_size();
2495 used += curr->used_word_size();
2496 capacity += curr->word_size();
2497 waste += curr->free_word_size() + curr->overhead();;
2498 }
2499 }
2500
2501 if (log_is_enabled(Trace, gc, metaspace, freelist)) {
2502 block_freelists()->print_on(out);
2503 }
2504
2505 size_t free = current_chunk() == NULL ? 0 : current_chunk()->free_word_size();
2506 // Free space isn't wasted.
2507 waste -= free;
2508
2509 out->print_cr("total of all chunks " SIZE_FORMAT " used " SIZE_FORMAT
2510 " free " SIZE_FORMAT " capacity " SIZE_FORMAT
2511 " waste " SIZE_FORMAT, curr_total, used, free, capacity, waste);
2512 }
2513
2514 // MetaspaceAux
2515
2516
2517 size_t MetaspaceAux::_capacity_words[] = {0, 0};
2518 size_t MetaspaceAux::_used_words[] = {0, 0};
2519
2520 size_t MetaspaceAux::free_bytes(Metaspace::MetadataType mdtype) {
2521 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
2522 return list == NULL ? 0 : list->free_bytes();
2523 }
2524
2525 size_t MetaspaceAux::free_bytes() {
2526 return free_bytes(Metaspace::ClassType) + free_bytes(Metaspace::NonClassType);
2527 }
2528
2529 void MetaspaceAux::dec_capacity(Metaspace::MetadataType mdtype, size_t words) {
2530 assert_lock_strong(SpaceManager::expand_lock());
2531 assert(words <= capacity_words(mdtype),
2532 "About to decrement below 0: words " SIZE_FORMAT
|