rev 57380 : [mq]: metaspace-improvement

   1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 #include "precompiled.hpp"
  25 
  26 
  27 #include "memory/metaspace/chunkAllocSequence.hpp"
  28 #include "memory/metaspace/chunkLevel.hpp"

  29 #include "memory/metaspace/chunkManager.hpp"
  30 #include "memory/metaspace/metachunk.hpp"





  31 #include "runtime/mutexLocker.hpp"
  32 #include "utilities/debug.hpp"
  33 #include "utilities/globalDefinitions.hpp"

  34 
  35 namespace metaspace {
  36 
  37 // Creates a chunk manager with a given name (which is for debug purposes only)
  38 // and an associated space list which will be used to request new chunks from
  39 // (see get_chunk())
  40 ChunkManager::ChunkManager(const char* name, VirtualSpaceList* space_list)
  41   : _vs_list(space_list)
  42   , _name(name)
  43   , _chunks {}
  44   , _num_chunks {}
  45   , _total_word_size(0)
  46   , _total_num_chunks(0)
  47 {







  48 }
  49 
  50 void ChunkManager::account_for_added_chunk(const Metachunk* c) {
  51   assert_lock_strong(MetaspaceExpand_lock);

























































































  52 
  53   const chklvl_t lvl = c->level();
  54   chklvl::check_valid_level(lvl);
  55 
  56   _total_num_chunks ++;
  57   _total_word_size += chklvl::word_size_for_level(lvl);
  58   _num_chunks[lvl] ++;
  59 }
  60 












































  61 void ChunkManager::account_for_removed_chunk(const Metachunk* c) {
  62   assert_lock_strong(MetaspaceExpand_lock);








  63 
  64   const chklvl_t lvl = c->level();
  65   chklvl::check_valid_level(lvl);

  66 
  67   assert(_total_num_chunks > 0, "Sanity.");
  68   _total_num_chunks --;
  69   const size_t word_size = chklvl::word_size_for_level(lvl);
  70   assert(_total_word_size >= word_size, "Sanity.");
  71   _total_word_size -= chklvl::word_size_for_level(lvl);
  72   assert(_num_chunks[lvl] > 0, "Sanity.");
  73   _num_chunks[lvl] --;
  74 }
  75 






  76 
  77 // Remove a chunk of the given level from its freelist, and adjust accounting.
  78 // If no chunk of this given level is free, return NULL.
  79 Metachunk* ChunkManager::get_chunk_simple(chklvl_t level) {
  80 
  81   assert_lock_strong(MetaspaceExpand_lock);
  82   chklvl::check_valid_level(level);
  83 
  84   Metachunk* c = _chunks[level];
  85   if (c != NULL) {
  86     account_for_removed_chunk(c);






  87   }
  88   return c;









  89 






  90 }

  91 





  92 





  93 






























































































  94 
  95 // Return a chunk to the ChunkManager and adjust accounting. May merge chunk
  96 //  with neighbors.
  97 // Happens after a Classloader was unloaded and releases its metaspace chunks.
  98 // !! Note: this may invalidate the chunk. Do not access the chunk after
  99 //    this function returns !!
 100 void ChunkManager::return_chunk(Metachunk* chunk) {
 101 

 102 







 103 }
 104 






































































































 105 
 106 // Remove the given chunk from its free list and adjust accounting.
 107 // (Called during VirtualSpaceNode purging which happens during a Metaspace GC.)
 108 void ChunkManager::remove_chunk(Metachunk* chunk) {





 109   assert_lock_strong(MetaspaceExpand_lock);
 110   chunk->remove_from_list();
 111   account_for_removed_chunk(chunk);

























 112 }
 113 



























































 114 

 115 












































 116 
 117 } // namespace metaspace
 118 
 119 
 120 
--- EOF ---