923 MetaWord* BlockFreelist::get_block(size_t word_size) {
924 assert(word_size >= SmallBlocks::small_block_min_size(), "never get dark matter");
925
926 // Try small_blocks first.
927 if (word_size < SmallBlocks::small_block_max_size()) {
928 // Don't create small_blocks() until needed. small_blocks() allocates the small block list for
929 // this space manager.
930 MetaWord* new_block = (MetaWord*) small_blocks()->get_block(word_size);
931 if (new_block != NULL) {
932 log_trace(gc, metaspace, freelist, blocks)("getting block at " INTPTR_FORMAT " size = " SIZE_FORMAT,
933 p2i(new_block), word_size);
934 return new_block;
935 }
936 }
937
938 if (word_size < BlockFreelist::min_dictionary_size()) {
939 // If allocation in small blocks fails, this is Dark Matter. Too small for dictionary.
940 return NULL;
941 }
942
943 Metablock* free_block =
944 dictionary()->get_chunk(word_size, FreeBlockDictionary<Metablock>::atLeast);
945 if (free_block == NULL) {
946 return NULL;
947 }
948
949 const size_t block_size = free_block->size();
950 if (block_size > WasteMultiplier * word_size) {
951 return_block((MetaWord*)free_block, block_size);
952 return NULL;
953 }
954
955 MetaWord* new_block = (MetaWord*)free_block;
956 assert(block_size >= word_size, "Incorrect size of block from freelist");
957 const size_t unused = block_size - word_size;
958 if (unused >= SmallBlocks::small_block_min_size()) {
959 return_block(new_block + word_size, unused);
960 }
961
962 log_trace(gc, metaspace, freelist, blocks)("getting block at " INTPTR_FORMAT " size = " SIZE_FORMAT,
963 p2i(new_block), word_size);
964 return new_block;
1895
1896 slow_locked_verify();
1897
1898 Metachunk* chunk = NULL;
1899 if (list_index(word_size) != HumongousIndex) {
1900 ChunkList* free_list = find_free_chunks_list(word_size);
1901 assert(free_list != NULL, "Sanity check");
1902
1903 chunk = free_list->head();
1904
1905 if (chunk == NULL) {
1906 return NULL;
1907 }
1908
1909 // Remove the chunk as the head of the list.
1910 free_list->remove_chunk(chunk);
1911
1912 log_trace(gc, metaspace, freelist)("ChunkManager::free_chunks_get: free_list " PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT,
1913 p2i(free_list), p2i(chunk), chunk->word_size());
1914 } else {
1915 chunk = humongous_dictionary()->get_chunk(
1916 word_size,
1917 FreeBlockDictionary<Metachunk>::atLeast);
1918
1919 if (chunk == NULL) {
1920 return NULL;
1921 }
1922
1923 log_debug(gc, metaspace, alloc)("Free list allocate humongous chunk size " SIZE_FORMAT " for requested size " SIZE_FORMAT " waste " SIZE_FORMAT,
1924 chunk->word_size(), word_size, chunk->word_size() - word_size);
1925 }
1926
1927 // Chunk has been removed from the chunk manager; update counters.
1928 account_for_removed_chunk(chunk);
1929
1930 // Remove it from the links to this freelist
1931 chunk->set_next(NULL);
1932 chunk->set_prev(NULL);
1933 #ifdef ASSERT
1934 // Chunk is no longer on any freelist. Setting to false make container_count_slow()
1935 // work.
1936 chunk->set_is_tagged_free(false);
1937 #endif
|
923 MetaWord* BlockFreelist::get_block(size_t word_size) {
924 assert(word_size >= SmallBlocks::small_block_min_size(), "never get dark matter");
925
926 // Try small_blocks first.
927 if (word_size < SmallBlocks::small_block_max_size()) {
928 // Don't create small_blocks() until needed. small_blocks() allocates the small block list for
929 // this space manager.
930 MetaWord* new_block = (MetaWord*) small_blocks()->get_block(word_size);
931 if (new_block != NULL) {
932 log_trace(gc, metaspace, freelist, blocks)("getting block at " INTPTR_FORMAT " size = " SIZE_FORMAT,
933 p2i(new_block), word_size);
934 return new_block;
935 }
936 }
937
938 if (word_size < BlockFreelist::min_dictionary_size()) {
939 // If allocation in small blocks fails, this is Dark Matter. Too small for dictionary.
940 return NULL;
941 }
942
943 Metablock* free_block = dictionary()->get_chunk(word_size);
944 if (free_block == NULL) {
945 return NULL;
946 }
947
948 const size_t block_size = free_block->size();
949 if (block_size > WasteMultiplier * word_size) {
950 return_block((MetaWord*)free_block, block_size);
951 return NULL;
952 }
953
954 MetaWord* new_block = (MetaWord*)free_block;
955 assert(block_size >= word_size, "Incorrect size of block from freelist");
956 const size_t unused = block_size - word_size;
957 if (unused >= SmallBlocks::small_block_min_size()) {
958 return_block(new_block + word_size, unused);
959 }
960
961 log_trace(gc, metaspace, freelist, blocks)("getting block at " INTPTR_FORMAT " size = " SIZE_FORMAT,
962 p2i(new_block), word_size);
963 return new_block;
1894
1895 slow_locked_verify();
1896
1897 Metachunk* chunk = NULL;
1898 if (list_index(word_size) != HumongousIndex) {
1899 ChunkList* free_list = find_free_chunks_list(word_size);
1900 assert(free_list != NULL, "Sanity check");
1901
1902 chunk = free_list->head();
1903
1904 if (chunk == NULL) {
1905 return NULL;
1906 }
1907
1908 // Remove the chunk as the head of the list.
1909 free_list->remove_chunk(chunk);
1910
1911 log_trace(gc, metaspace, freelist)("ChunkManager::free_chunks_get: free_list " PTR_FORMAT " head " PTR_FORMAT " size " SIZE_FORMAT,
1912 p2i(free_list), p2i(chunk), chunk->word_size());
1913 } else {
1914 chunk = humongous_dictionary()->get_chunk(word_size);
1915
1916 if (chunk == NULL) {
1917 return NULL;
1918 }
1919
1920 log_debug(gc, metaspace, alloc)("Free list allocate humongous chunk size " SIZE_FORMAT " for requested size " SIZE_FORMAT " waste " SIZE_FORMAT,
1921 chunk->word_size(), word_size, chunk->word_size() - word_size);
1922 }
1923
1924 // Chunk has been removed from the chunk manager; update counters.
1925 account_for_removed_chunk(chunk);
1926
1927 // Remove it from the links to this freelist
1928 chunk->set_next(NULL);
1929 chunk->set_prev(NULL);
1930 #ifdef ASSERT
1931 // Chunk is no longer on any freelist. Setting to false make container_count_slow()
1932 // work.
1933 chunk->set_is_tagged_free(false);
1934 #endif
|