< prev index next >

src/hotspot/share/memory/metaspace/chunkManager.cpp

Print this page
rev 54012 : imported patch autouncommit-metachunks


 286   return free_chunks(index);
 287 }
 288 
 289 // Helper for chunk splitting: given a target chunk size and a larger free chunk,
 290 // split up the larger chunk into n smaller chunks, at least one of which should be
 291 // the target chunk of target chunk size. The smaller chunks, including the target
 292 // chunk, are returned to the freelist. The pointer to the target chunk is returned.
 293 // Note that this chunk is supposed to be removed from the freelist right away.
 294 Metachunk* ChunkManager::split_chunk(size_t target_chunk_word_size, Metachunk* larger_chunk) {
 295   assert(larger_chunk->word_size() > target_chunk_word_size, "Sanity");
 296 
 297   const ChunkIndex larger_chunk_index = larger_chunk->get_chunk_type();
 298   const ChunkIndex target_chunk_index = get_chunk_type_by_size(target_chunk_word_size, is_class());
 299 
 300   MetaWord* const region_start = (MetaWord*)larger_chunk;
 301   const size_t region_word_len = larger_chunk->word_size();
 302   MetaWord* const region_end = region_start + region_word_len;
 303   VirtualSpaceNode* const vsn = larger_chunk->container();
 304   OccupancyMap* const ocmap = vsn->occupancy_map();
 305 




 306   // Any larger non-humongous chunk size is a multiple of any smaller chunk size.
 307   // Since non-humongous chunks are aligned to their chunk size, the larger chunk should start
 308   // at an address suitable to place the smaller target chunk.
 309   assert_is_aligned(region_start, target_chunk_word_size);
 310 
 311   // Remove old chunk.
 312   free_chunks(larger_chunk_index)->remove_chunk(larger_chunk);
 313   larger_chunk->remove_sentinel();
 314 
 315   // Prevent access to the old chunk from here on.
 316   larger_chunk = NULL;
 317   // ... and wipe it.
 318   DEBUG_ONLY(memset(region_start, 0xfe, region_word_len * BytesPerWord));
 319 
 320   // In its place create first the target chunk...
 321   MetaWord* p = region_start;
 322   Metachunk* target_chunk = ::new (p) Metachunk(target_chunk_index, is_class(), target_chunk_word_size, vsn);
 323   assert(target_chunk == (Metachunk*)p, "Sanity");
 324   target_chunk->set_origin(origin_split);
 325 


 451       return NULL;
 452     }
 453 
 454     // Remove the chunk as the head of the list.
 455     free_list->remove_chunk(chunk);
 456 
 457     log_trace(gc, metaspace, freelist)("ChunkManager::free_chunks_get: free_list: " PTR_FORMAT " chunks left: " SSIZE_FORMAT ".",
 458                                        p2i(free_list), free_list->count());
 459 
 460   } else {
 461     chunk = humongous_dictionary()->get_chunk(word_size);
 462 
 463     if (chunk == NULL) {
 464       return NULL;
 465     }
 466 
 467     log_trace(gc, metaspace, alloc)("Free list allocate humongous chunk size " SIZE_FORMAT " for requested size " SIZE_FORMAT " waste " SIZE_FORMAT,
 468                                     chunk->word_size(), word_size, chunk->word_size() - word_size);
 469   }
 470 




 471   // Chunk has been removed from the chunk manager; update counters.
 472   account_for_removed_chunk(chunk);
 473   do_update_in_use_info_for_chunk(chunk, true);
 474   chunk->container()->inc_container_count();
 475   chunk->inc_use_count();
 476 
 477   // Remove it from the links to this freelist
 478   chunk->set_next(NULL);
 479   chunk->set_prev(NULL);
 480 
 481   // Run some verifications (some more if we did a chunk split)
 482 #ifdef ASSERT
 483 
 484   EVERY_NTH(VerifyMetaspaceInterval)
 485     // Be extra verify-y when chunk split happened.
 486     locked_verify(true);
 487     VirtualSpaceNode* const vsn = chunk->container();
 488     vsn->verify(true);
 489     if (we_did_split_a_chunk) {
 490       vsn->verify_free_chunks_are_ideally_merged();


 581   if (index == SmallIndex || index == SpecializedIndex) {
 582     if (!attempt_to_coalesce_around_chunk(chunk, MediumIndex)) {
 583       // This did not work. But if this chunk is special, we still may form a small chunk?
 584       if (index == SpecializedIndex) {
 585         if (!attempt_to_coalesce_around_chunk(chunk, SmallIndex)) {
 586           // give up.
 587         }
 588       }
 589     }
 590   }
 591 
 592   // From here on do not access chunk anymore, it may have been merged with another chunk.
 593 
 594 #ifdef ASSERT
 595   EVERY_NTH(VerifyMetaspaceInterval)
 596     this->locked_verify(true);
 597     vsn->verify(true);
 598     vsn->verify_free_chunks_are_ideally_merged();
 599   END_EVERY_NTH
 600 #endif




 601 
 602 }
 603 
 604 void ChunkManager::return_chunk_list(Metachunk* chunks) {
 605   if (chunks == NULL) {
 606     return;
 607   }
 608   LogTarget(Trace, gc, metaspace, freelist) log;
 609   if (log.is_enabled()) { // tracing
 610     log.print("returning list of chunks...");
 611   }
 612   unsigned num_chunks_returned = 0;
 613   size_t size_chunks_returned = 0;
 614   Metachunk* cur = chunks;
 615   while (cur != NULL) {
 616     // Capture the next link before it is changed
 617     // by the call to return_chunk_at_head();
 618     Metachunk* next = cur->next();
 619     if (log.is_enabled()) { // tracing
 620       num_chunks_returned ++;




 286   return free_chunks(index);
 287 }
 288 
 289 // Helper for chunk splitting: given a target chunk size and a larger free chunk,
 290 // split up the larger chunk into n smaller chunks, at least one of which should be
 291 // the target chunk of target chunk size. The smaller chunks, including the target
 292 // chunk, are returned to the freelist. The pointer to the target chunk is returned.
 293 // Note that this chunk is supposed to be removed from the freelist right away.
 294 Metachunk* ChunkManager::split_chunk(size_t target_chunk_word_size, Metachunk* larger_chunk) {
 295   assert(larger_chunk->word_size() > target_chunk_word_size, "Sanity");
 296 
 297   const ChunkIndex larger_chunk_index = larger_chunk->get_chunk_type();
 298   const ChunkIndex target_chunk_index = get_chunk_type_by_size(target_chunk_word_size, is_class());
 299 
 300   MetaWord* const region_start = (MetaWord*)larger_chunk;
 301   const size_t region_word_len = larger_chunk->word_size();
 302   MetaWord* const region_end = region_start + region_word_len;
 303   VirtualSpaceNode* const vsn = larger_chunk->container();
 304   OccupancyMap* const ocmap = vsn->occupancy_map();
 305 
 306   if (AutoUncommitMetaChunks) {
 307     larger_chunk->commit();
 308   }
 309 
 310   // Any larger non-humongous chunk size is a multiple of any smaller chunk size.
 311   // Since non-humongous chunks are aligned to their chunk size, the larger chunk should start
 312   // at an address suitable to place the smaller target chunk.
 313   assert_is_aligned(region_start, target_chunk_word_size);
 314 
 315   // Remove old chunk.
 316   free_chunks(larger_chunk_index)->remove_chunk(larger_chunk);
 317   larger_chunk->remove_sentinel();
 318 
 319   // Prevent access to the old chunk from here on.
 320   larger_chunk = NULL;
 321   // ... and wipe it.
 322   DEBUG_ONLY(memset(region_start, 0xfe, region_word_len * BytesPerWord));
 323 
 324   // In its place create first the target chunk...
 325   MetaWord* p = region_start;
 326   Metachunk* target_chunk = ::new (p) Metachunk(target_chunk_index, is_class(), target_chunk_word_size, vsn);
 327   assert(target_chunk == (Metachunk*)p, "Sanity");
 328   target_chunk->set_origin(origin_split);
 329 


 455       return NULL;
 456     }
 457 
 458     // Remove the chunk as the head of the list.
 459     free_list->remove_chunk(chunk);
 460 
 461     log_trace(gc, metaspace, freelist)("ChunkManager::free_chunks_get: free_list: " PTR_FORMAT " chunks left: " SSIZE_FORMAT ".",
 462                                        p2i(free_list), free_list->count());
 463 
 464   } else {
 465     chunk = humongous_dictionary()->get_chunk(word_size);
 466 
 467     if (chunk == NULL) {
 468       return NULL;
 469     }
 470 
 471     log_trace(gc, metaspace, alloc)("Free list allocate humongous chunk size " SIZE_FORMAT " for requested size " SIZE_FORMAT " waste " SIZE_FORMAT,
 472                                     chunk->word_size(), word_size, chunk->word_size() - word_size);
 473   }
 474 
 475   if (AutoUncommitMetaChunks) {
 476     chunk->commit();
 477   }
 478 
 479   // Chunk has been removed from the chunk manager; update counters.
 480   account_for_removed_chunk(chunk);
 481   do_update_in_use_info_for_chunk(chunk, true);
 482   chunk->container()->inc_container_count();
 483   chunk->inc_use_count();
 484 
 485   // Remove it from the links to this freelist
 486   chunk->set_next(NULL);
 487   chunk->set_prev(NULL);
 488 
 489   // Run some verifications (some more if we did a chunk split)
 490 #ifdef ASSERT
 491 
 492   EVERY_NTH(VerifyMetaspaceInterval)
 493     // Be extra verify-y when chunk split happened.
 494     locked_verify(true);
 495     VirtualSpaceNode* const vsn = chunk->container();
 496     vsn->verify(true);
 497     if (we_did_split_a_chunk) {
 498       vsn->verify_free_chunks_are_ideally_merged();


 589   if (index == SmallIndex || index == SpecializedIndex) {
 590     if (!attempt_to_coalesce_around_chunk(chunk, MediumIndex)) {
 591       // This did not work. But if this chunk is special, we still may form a small chunk?
 592       if (index == SpecializedIndex) {
 593         if (!attempt_to_coalesce_around_chunk(chunk, SmallIndex)) {
 594           // give up.
 595         }
 596       }
 597     }
 598   }
 599 
 600   // From here on do not access chunk anymore, it may have been merged with another chunk.
 601 
 602 #ifdef ASSERT
 603   EVERY_NTH(VerifyMetaspaceInterval)
 604     this->locked_verify(true);
 605     vsn->verify(true);
 606     vsn->verify_free_chunks_are_ideally_merged();
 607   END_EVERY_NTH
 608 #endif
 609 
 610   if (AutoUncommitMetaChunks) {
 611     chunk->uncommit();
 612   }
 613 
 614 }
 615 
 616 void ChunkManager::return_chunk_list(Metachunk* chunks) {
 617   if (chunks == NULL) {
 618     return;
 619   }
 620   LogTarget(Trace, gc, metaspace, freelist) log;
 621   if (log.is_enabled()) { // tracing
 622     log.print("returning list of chunks...");
 623   }
 624   unsigned num_chunks_returned = 0;
 625   size_t size_chunks_returned = 0;
 626   Metachunk* cur = chunks;
 627   while (cur != NULL) {
 628     // Capture the next link before it is changed
 629     // by the call to return_chunk_at_head();
 630     Metachunk* next = cur->next();
 631     if (log.is_enabled()) { // tracing
 632       num_chunks_returned ++;


< prev index next >