comparison src/share/vm/memory/metaspace.cpp @ 12235:d6c266999345

8023476: Metaspace capacity > reserved Reviewed-by: stefank, hseigel, mgerdin
author ehelin
date Thu, 12 Sep 2013 10:15:30 +0200
parents 24e87613ee58
children c4c768305a8f
comparison
equal deleted inserted replaced
12234:b82260e84582 12235:d6c266999345
175 // Add the simple linked list of chunks to the freelist of chunks 175 // Add the simple linked list of chunks to the freelist of chunks
176 // of type index. 176 // of type index.
177 void return_chunks(ChunkIndex index, Metachunk* chunks); 177 void return_chunks(ChunkIndex index, Metachunk* chunks);
178 178
179 // Total of the space in the free chunks list 179 // Total of the space in the free chunks list
180 size_t free_chunks_total(); 180 size_t free_chunks_total_words();
181 size_t free_chunks_total_in_bytes(); 181 size_t free_chunks_total_bytes();
182 182
183 // Number of chunks in the free chunks list 183 // Number of chunks in the free chunks list
184 size_t free_chunks_count(); 184 size_t free_chunks_count();
185 185
186 void inc_free_chunks_total(size_t v, size_t count = 1) { 186 void inc_free_chunks_total(size_t v, size_t count = 1) {
1078 while (iter.repeat()) { 1078 while (iter.repeat()) {
1079 VirtualSpaceNode* vsl = iter.get_next(); 1079 VirtualSpaceNode* vsl = iter.get_next();
1080 // Sum used region [bottom, top) in each virtualspace 1080 // Sum used region [bottom, top) in each virtualspace
1081 allocated_by_vs += vsl->used_words_in_vs(); 1081 allocated_by_vs += vsl->used_words_in_vs();
1082 } 1082 }
1083 assert(allocated_by_vs >= chunk_manager()->free_chunks_total(), 1083 assert(allocated_by_vs >= chunk_manager()->free_chunks_total_words(),
1084 err_msg("Total in free chunks " SIZE_FORMAT 1084 err_msg("Total in free chunks " SIZE_FORMAT
1085 " greater than total from virtual_spaces " SIZE_FORMAT, 1085 " greater than total from virtual_spaces " SIZE_FORMAT,
1086 allocated_by_vs, chunk_manager()->free_chunks_total())); 1086 allocated_by_vs, chunk_manager()->free_chunks_total_words()));
1087 size_t used = 1087 size_t used =
1088 allocated_by_vs - chunk_manager()->free_chunks_total(); 1088 allocated_by_vs - chunk_manager()->free_chunks_total_words();
1089 return used; 1089 return used;
1090 } 1090 }
1091 1091
1092 // Space available in all MetadataVirtualspaces allocated 1092 // Space available in all MetadataVirtualspaces allocated
1093 // for metadata. This is the upper limit on the capacity 1093 // for metadata. This is the upper limit on the capacity
1524 if (TraceMetadataChunkAllocation && Verbose) { 1524 if (TraceMetadataChunkAllocation && Verbose) {
1525 gclog_or_tty->print("Metadebug::deallocate_chunk_a_lot: %d) ", 1525 gclog_or_tty->print("Metadebug::deallocate_chunk_a_lot: %d) ",
1526 sm->sum_count_in_chunks_in_use()); 1526 sm->sum_count_in_chunks_in_use());
1527 dummy_chunk->print_on(gclog_or_tty); 1527 dummy_chunk->print_on(gclog_or_tty);
1528 gclog_or_tty->print_cr(" Free chunks total %d count %d", 1528 gclog_or_tty->print_cr(" Free chunks total %d count %d",
1529 vsl->chunk_manager()->free_chunks_total(), 1529 vsl->chunk_manager()->free_chunks_total_words(),
1530 vsl->chunk_manager()->free_chunks_count()); 1530 vsl->chunk_manager()->free_chunks_count());
1531 } 1531 }
1532 } 1532 }
1533 } else { 1533 } else {
1534 Metadebug::inc_deallocate_chunk_a_lot_count(); 1534 Metadebug::inc_deallocate_chunk_a_lot_count();
1581 } 1581 }
1582 #endif 1582 #endif
1583 1583
1584 // ChunkManager methods 1584 // ChunkManager methods
1585 1585
1586 size_t ChunkManager::free_chunks_total() { 1586 size_t ChunkManager::free_chunks_total_words() {
1587 return _free_chunks_total; 1587 return _free_chunks_total;
1588 } 1588 }
1589 1589
1590 size_t ChunkManager::free_chunks_total_in_bytes() { 1590 size_t ChunkManager::free_chunks_total_bytes() {
1591 return free_chunks_total() * BytesPerWord; 1591 return free_chunks_total_words() * BytesPerWord;
1592 } 1592 }
1593 1593
1594 size_t ChunkManager::free_chunks_count() { 1594 size_t ChunkManager::free_chunks_count() {
1595 #ifdef ASSERT 1595 #ifdef ASSERT
1596 if (!UseConcMarkSweepGC && !SpaceManager::expand_lock()->is_locked()) { 1596 if (!UseConcMarkSweepGC && !SpaceManager::expand_lock()->is_locked()) {
2565 } 2565 }
2566 } 2566 }
2567 return used * BytesPerWord; 2567 return used * BytesPerWord;
2568 } 2568 }
2569 2569
2570 size_t MetaspaceAux::free_in_bytes(Metaspace::MetadataType mdtype) { 2570 size_t MetaspaceAux::free_bytes_slow(Metaspace::MetadataType mdtype) {
2571 size_t free = 0; 2571 size_t free = 0;
2572 ClassLoaderDataGraphMetaspaceIterator iter; 2572 ClassLoaderDataGraphMetaspaceIterator iter;
2573 while (iter.repeat()) { 2573 while (iter.repeat()) {
2574 Metaspace* msp = iter.get_next(); 2574 Metaspace* msp = iter.get_next();
2575 if (msp != NULL) { 2575 if (msp != NULL) {
2576 free += msp->free_words(mdtype); 2576 free += msp->free_words_slow(mdtype);
2577 } 2577 }
2578 } 2578 }
2579 return free * BytesPerWord; 2579 return free * BytesPerWord;
2580 } 2580 }
2581 2581
2594 } 2594 }
2595 } 2595 }
2596 return capacity * BytesPerWord; 2596 return capacity * BytesPerWord;
2597 } 2597 }
2598 2598
2599 size_t MetaspaceAux::reserved_in_bytes(Metaspace::MetadataType mdtype) { 2599 size_t MetaspaceAux::capacity_bytes_slow() {
2600 #ifdef PRODUCT
2601 // Use allocated_capacity_bytes() in PRODUCT instead of this function.
2602 guarantee(false, "Should not call capacity_bytes_slow() in the PRODUCT");
2603 #endif
2604 size_t class_capacity = capacity_bytes_slow(Metaspace::ClassType);
2605 size_t non_class_capacity = capacity_bytes_slow(Metaspace::NonClassType);
2606 assert(allocated_capacity_bytes() == class_capacity + non_class_capacity,
2607 err_msg("bad accounting: allocated_capacity_bytes() " SIZE_FORMAT
2608 " class_capacity + non_class_capacity " SIZE_FORMAT
2609 " class_capacity " SIZE_FORMAT " non_class_capacity " SIZE_FORMAT,
2610 allocated_capacity_bytes(), class_capacity + non_class_capacity,
2611 class_capacity, non_class_capacity));
2612
2613 return class_capacity + non_class_capacity;
2614 }
2615
2616 size_t MetaspaceAux::reserved_bytes(Metaspace::MetadataType mdtype) {
2600 VirtualSpaceList* list = Metaspace::get_space_list(mdtype); 2617 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
2601 return list == NULL ? 0 : list->virtual_space_total(); 2618 return list == NULL ? 0 : list->virtual_space_total() * BytesPerWord;
2602 } 2619 }
2603 2620
2604 size_t MetaspaceAux::min_chunk_size() { return Metaspace::first_chunk_word_size(); } 2621 size_t MetaspaceAux::min_chunk_size_words() { return Metaspace::first_chunk_word_size(); }
2605 2622
2606 size_t MetaspaceAux::free_chunks_total(Metaspace::MetadataType mdtype) { 2623 size_t MetaspaceAux::free_chunks_total_words(Metaspace::MetadataType mdtype) {
2607 VirtualSpaceList* list = Metaspace::get_space_list(mdtype); 2624 VirtualSpaceList* list = Metaspace::get_space_list(mdtype);
2608 if (list == NULL) { 2625 if (list == NULL) {
2609 return 0; 2626 return 0;
2610 } 2627 }
2611 ChunkManager* chunk = list->chunk_manager(); 2628 ChunkManager* chunk = list->chunk_manager();
2612 chunk->slow_verify(); 2629 chunk->slow_verify();
2613 return chunk->free_chunks_total(); 2630 return chunk->free_chunks_total_words();
2614 } 2631 }
2615 2632
2616 size_t MetaspaceAux::free_chunks_total_in_bytes(Metaspace::MetadataType mdtype) { 2633 size_t MetaspaceAux::free_chunks_total_bytes(Metaspace::MetadataType mdtype) {
2617 return free_chunks_total(mdtype) * BytesPerWord; 2634 return free_chunks_total_words(mdtype) * BytesPerWord;
2618 } 2635 }
2619 2636
2620 size_t MetaspaceAux::free_chunks_total() { 2637 size_t MetaspaceAux::free_chunks_total_words() {
2621 return free_chunks_total(Metaspace::ClassType) + 2638 return free_chunks_total_words(Metaspace::ClassType) +
2622 free_chunks_total(Metaspace::NonClassType); 2639 free_chunks_total_words(Metaspace::NonClassType);
2623 } 2640 }
2624 2641
2625 size_t MetaspaceAux::free_chunks_total_in_bytes() { 2642 size_t MetaspaceAux::free_chunks_total_bytes() {
2626 return free_chunks_total() * BytesPerWord; 2643 return free_chunks_total_words() * BytesPerWord;
2627 } 2644 }
2628 2645
2629 void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) { 2646 void MetaspaceAux::print_metaspace_change(size_t prev_metadata_used) {
2630 gclog_or_tty->print(", [Metaspace:"); 2647 gclog_or_tty->print(", [Metaspace:");
2631 if (PrintGCDetails && Verbose) { 2648 if (PrintGCDetails && Verbose) {
2632 gclog_or_tty->print(" " SIZE_FORMAT 2649 gclog_or_tty->print(" " SIZE_FORMAT
2633 "->" SIZE_FORMAT 2650 "->" SIZE_FORMAT
2634 "(" SIZE_FORMAT ")", 2651 "(" SIZE_FORMAT ")",
2635 prev_metadata_used, 2652 prev_metadata_used,
2636 allocated_used_bytes(), 2653 allocated_used_bytes(),
2637 reserved_in_bytes()); 2654 reserved_bytes());
2638 } else { 2655 } else {
2639 gclog_or_tty->print(" " SIZE_FORMAT "K" 2656 gclog_or_tty->print(" " SIZE_FORMAT "K"
2640 "->" SIZE_FORMAT "K" 2657 "->" SIZE_FORMAT "K"
2641 "(" SIZE_FORMAT "K)", 2658 "(" SIZE_FORMAT "K)",
2642 prev_metadata_used / K, 2659 prev_metadata_used/K,
2643 allocated_used_bytes() / K, 2660 allocated_used_bytes()/K,
2644 reserved_in_bytes()/ K); 2661 reserved_bytes()/K);
2645 } 2662 }
2646 2663
2647 gclog_or_tty->print("]"); 2664 gclog_or_tty->print("]");
2648 } 2665 }
2649 2666
2652 Metaspace::MetadataType nct = Metaspace::NonClassType; 2669 Metaspace::MetadataType nct = Metaspace::NonClassType;
2653 2670
2654 out->print_cr(" Metaspace total " 2671 out->print_cr(" Metaspace total "
2655 SIZE_FORMAT "K, used " SIZE_FORMAT "K," 2672 SIZE_FORMAT "K, used " SIZE_FORMAT "K,"
2656 " reserved " SIZE_FORMAT "K", 2673 " reserved " SIZE_FORMAT "K",
2657 allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_in_bytes()/K); 2674 allocated_capacity_bytes()/K, allocated_used_bytes()/K, reserved_bytes()/K);
2658 2675
2659 out->print_cr(" data space " 2676 out->print_cr(" data space "
2660 SIZE_FORMAT "K, used " SIZE_FORMAT "K," 2677 SIZE_FORMAT "K, used " SIZE_FORMAT "K,"
2661 " reserved " SIZE_FORMAT "K", 2678 " reserved " SIZE_FORMAT "K",
2662 allocated_capacity_bytes(nct)/K, 2679 allocated_capacity_bytes(nct)/K,
2663 allocated_used_bytes(nct)/K, 2680 allocated_used_bytes(nct)/K,
2664 reserved_in_bytes(nct)/K); 2681 reserved_bytes(nct)/K);
2665 if (Metaspace::using_class_space()) { 2682 if (Metaspace::using_class_space()) {
2666 Metaspace::MetadataType ct = Metaspace::ClassType; 2683 Metaspace::MetadataType ct = Metaspace::ClassType;
2667 out->print_cr(" class space " 2684 out->print_cr(" class space "
2668 SIZE_FORMAT "K, used " SIZE_FORMAT "K," 2685 SIZE_FORMAT "K, used " SIZE_FORMAT "K,"
2669 " reserved " SIZE_FORMAT "K", 2686 " reserved " SIZE_FORMAT "K",
2670 allocated_capacity_bytes(ct)/K, 2687 allocated_capacity_bytes(ct)/K,
2671 allocated_used_bytes(ct)/K, 2688 allocated_used_bytes(ct)/K,
2672 reserved_in_bytes(ct)/K); 2689 reserved_bytes(ct)/K);
2673 } 2690 }
2674 } 2691 }
2675 2692
2676 // Print information for class space and data space separately. 2693 // Print information for class space and data space separately.
2677 // This is almost the same as above. 2694 // This is almost the same as above.
2678 void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) { 2695 void MetaspaceAux::print_on(outputStream* out, Metaspace::MetadataType mdtype) {
2679 size_t free_chunks_capacity_bytes = free_chunks_total_in_bytes(mdtype); 2696 size_t free_chunks_capacity_bytes = free_chunks_total_bytes(mdtype);
2680 size_t capacity_bytes = capacity_bytes_slow(mdtype); 2697 size_t capacity_bytes = capacity_bytes_slow(mdtype);
2681 size_t used_bytes = used_bytes_slow(mdtype); 2698 size_t used_bytes = used_bytes_slow(mdtype);
2682 size_t free_bytes = free_in_bytes(mdtype); 2699 size_t free_bytes = free_bytes_slow(mdtype);
2683 size_t used_and_free = used_bytes + free_bytes + 2700 size_t used_and_free = used_bytes + free_bytes +
2684 free_chunks_capacity_bytes; 2701 free_chunks_capacity_bytes;
2685 out->print_cr(" Chunk accounting: used in chunks " SIZE_FORMAT 2702 out->print_cr(" Chunk accounting: used in chunks " SIZE_FORMAT
2686 "K + unused in chunks " SIZE_FORMAT "K + " 2703 "K + unused in chunks " SIZE_FORMAT "K + "
2687 " capacity in free chunks " SIZE_FORMAT "K = " SIZE_FORMAT 2704 " capacity in free chunks " SIZE_FORMAT "K = " SIZE_FORMAT
3130 } else { 3147 } else {
3131 return vsm()->sum_used_in_chunks_in_use(); // includes overhead! 3148 return vsm()->sum_used_in_chunks_in_use(); // includes overhead!
3132 } 3149 }
3133 } 3150 }
3134 3151
3135 size_t Metaspace::free_words(MetadataType mdtype) const { 3152 size_t Metaspace::free_words_slow(MetadataType mdtype) const {
3136 if (mdtype == ClassType) { 3153 if (mdtype == ClassType) {
3137 return using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0; 3154 return using_class_space() ? class_vsm()->sum_free_in_chunks_in_use() : 0;
3138 } else { 3155 } else {
3139 return vsm()->sum_free_in_chunks_in_use(); 3156 return vsm()->sum_free_in_chunks_in_use();
3140 } 3157 }