< prev index next >

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

Print this page
rev 50187 : imported patch metaspace-split
rev 50188 : [mq]: 8176808-split-metaspace-cpp-2


   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 
  25 
  26 
  27 #include "precompiled.hpp"
  28 
  29 #include "logging/log.hpp"
  30 #include "logging/logStream.hpp"
  31 #include "memory/metaspace/metachunk.hpp"
  32 #include "memory/metaspace.hpp"
  33 #include "memory/metaspace/chunkManager.hpp"
  34 #include "memory/metaspace/metaspaceCommon.hpp"
  35 #include "memory/metaspace/occupancyMap.hpp"
  36 #include "memory/metaspace/virtualSpaceNode.hpp"
  37 #include "memory/virtualspace.hpp"
  38 #include "runtime/os.hpp"
  39 #include "services/memTracker.hpp"
  40 #include "utilities/copy.hpp"
  41 #include "utilities/debug.hpp"
  42 #include "utilities/globalDefinitions.hpp"
  43 
  44 namespace metaspace {
  45 namespace internals {
  46 
  47 // Decide if large pages should be committed when the memory is reserved.
  48 static bool should_commit_large_pages_when_reserving(size_t bytes) {
  49   if (UseLargePages && UseLargePagesInMetaspace && !os::can_commit_large_page_memory()) {
  50     size_t words = bytes / BytesPerWord;
  51     bool is_class = false; // We never reserve large pages for the class space.
  52     if (MetaspaceGC::can_expand(words, is_class) &&
  53         MetaspaceGC::allowed_expansion() >= words) {
  54       return true;
  55     }
  56   }
  57 
  58   return false;
  59 }
  60 
  61 // byte_size is the size of the associated virtualspace.
  62 VirtualSpaceNode::VirtualSpaceNode(bool is_class, size_t bytes) :
  63     _is_class(is_class), _top(NULL), _next(NULL), _rs(), _container_count(0), _occupancy_map(NULL) {
  64   assert_is_aligned(bytes, Metaspace::reserve_alignment());
  65   bool large_pages = should_commit_large_pages_when_reserving(bytes);


 579 
 580     while (free_words_in_vs() >= chunk_size) {
 581       Metachunk* chunk = get_chunk_vs(chunk_size);
 582       // Chunk will be allocated aligned, so allocation may require
 583       // additional padding chunks. That may cause above allocation to
 584       // fail. Just ignore the failed allocation and continue with the
 585       // next smaller chunk size. As the VirtualSpaceNode comitted
 586       // size should be a multiple of the smallest chunk size, we
 587       // should always be able to fill the VirtualSpace completely.
 588       if (chunk == NULL) {
 589         break;
 590       }
 591       chunk_manager->return_single_chunk(chunk);
 592     }
 593     DEBUG_ONLY(verify_container_count();)
 594   }
 595   assert(free_words_in_vs() == 0, "should be empty now");
 596 }
 597 
 598 } // namespace metaspace
 599 } // namespace internals


   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 


  25 #include "precompiled.hpp"
  26 
  27 #include "logging/log.hpp"
  28 #include "logging/logStream.hpp"
  29 #include "memory/metaspace/metachunk.hpp"
  30 #include "memory/metaspace.hpp"
  31 #include "memory/metaspace/chunkManager.hpp"
  32 #include "memory/metaspace/metaspaceCommon.hpp"
  33 #include "memory/metaspace/occupancyMap.hpp"
  34 #include "memory/metaspace/virtualSpaceNode.hpp"
  35 #include "memory/virtualspace.hpp"
  36 #include "runtime/os.hpp"
  37 #include "services/memTracker.hpp"
  38 #include "utilities/copy.hpp"
  39 #include "utilities/debug.hpp"
  40 #include "utilities/globalDefinitions.hpp"
  41 
  42 namespace metaspace {

  43 
  44 // Decide if large pages should be committed when the memory is reserved.
  45 static bool should_commit_large_pages_when_reserving(size_t bytes) {
  46   if (UseLargePages && UseLargePagesInMetaspace && !os::can_commit_large_page_memory()) {
  47     size_t words = bytes / BytesPerWord;
  48     bool is_class = false; // We never reserve large pages for the class space.
  49     if (MetaspaceGC::can_expand(words, is_class) &&
  50         MetaspaceGC::allowed_expansion() >= words) {
  51       return true;
  52     }
  53   }
  54 
  55   return false;
  56 }
  57 
  58 // byte_size is the size of the associated virtualspace.
  59 VirtualSpaceNode::VirtualSpaceNode(bool is_class, size_t bytes) :
  60     _is_class(is_class), _top(NULL), _next(NULL), _rs(), _container_count(0), _occupancy_map(NULL) {
  61   assert_is_aligned(bytes, Metaspace::reserve_alignment());
  62   bool large_pages = should_commit_large_pages_when_reserving(bytes);


 576 
 577     while (free_words_in_vs() >= chunk_size) {
 578       Metachunk* chunk = get_chunk_vs(chunk_size);
 579       // Chunk will be allocated aligned, so allocation may require
 580       // additional padding chunks. That may cause above allocation to
 581       // fail. Just ignore the failed allocation and continue with the
 582       // next smaller chunk size. As the VirtualSpaceNode comitted
 583       // size should be a multiple of the smallest chunk size, we
 584       // should always be able to fill the VirtualSpace completely.
 585       if (chunk == NULL) {
 586         break;
 587       }
 588       chunk_manager->return_single_chunk(chunk);
 589     }
 590     DEBUG_ONLY(verify_container_count();)
 591   }
 592   assert(free_words_in_vs() == 0, "should be empty now");
 593 }
 594 
 595 } // namespace metaspace
 596 
< prev index next >