< prev index next >

src/hotspot/share/gc/z/zPhysicalMemory.cpp

Print this page


   1 /*
   2  * Copyright (c) 2015, 2018, 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  */


  74   // Add new segment
  75   _segments[_nsegments] = segment;
  76   _nsegments++;
  77 }
  78 
  79 ZPhysicalMemory ZPhysicalMemory::split(size_t split_size) {
  80   // Only splitting of single-segment instances have been implemented.
  81   assert(nsegments() == 1, "Can only have one segment");
  82   assert(split_size <= size(), "Invalid size");
  83   return ZPhysicalMemory(_segments[0].split(split_size));
  84 }
  85 
  86 void ZPhysicalMemory::clear() {
  87   if (_segments != NULL) {
  88     FreeHeap(_segments);
  89     _segments = NULL;
  90     _nsegments = 0;
  91   }
  92 }
  93 
  94 ZPhysicalMemoryManager::ZPhysicalMemoryManager(size_t max_capacity, size_t granule_size) :
  95     _backing(max_capacity, granule_size),
  96     _max_capacity(max_capacity),
  97     _current_max_capacity(max_capacity),
  98     _capacity(0),
  99     _used(0) {}
 100 
 101 bool ZPhysicalMemoryManager::is_initialized() const {
 102   return _backing.is_initialized();
 103 }
 104 
 105 void ZPhysicalMemoryManager::try_ensure_unused_capacity(size_t size) {
 106   const size_t unused = unused_capacity();
 107   if (unused >= size) {
 108     // Don't try to expand, enough unused capacity available
 109     return;
 110   }
 111 
 112   const size_t current_max = current_max_capacity();
 113   if (_capacity == current_max) {
 114     // Don't try to expand, current max capacity reached
 115     return;


   1 /*
   2  * Copyright (c) 2015, 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  */


  74   // Add new segment
  75   _segments[_nsegments] = segment;
  76   _nsegments++;
  77 }
  78 
  79 ZPhysicalMemory ZPhysicalMemory::split(size_t split_size) {
  80   // Only splitting of single-segment instances have been implemented.
  81   assert(nsegments() == 1, "Can only have one segment");
  82   assert(split_size <= size(), "Invalid size");
  83   return ZPhysicalMemory(_segments[0].split(split_size));
  84 }
  85 
  86 void ZPhysicalMemory::clear() {
  87   if (_segments != NULL) {
  88     FreeHeap(_segments);
  89     _segments = NULL;
  90     _nsegments = 0;
  91   }
  92 }
  93 
  94 ZPhysicalMemoryManager::ZPhysicalMemoryManager(size_t max_capacity) :
  95     _backing(max_capacity),
  96     _max_capacity(max_capacity),
  97     _current_max_capacity(max_capacity),
  98     _capacity(0),
  99     _used(0) {}
 100 
 101 bool ZPhysicalMemoryManager::is_initialized() const {
 102   return _backing.is_initialized();
 103 }
 104 
 105 void ZPhysicalMemoryManager::try_ensure_unused_capacity(size_t size) {
 106   const size_t unused = unused_capacity();
 107   if (unused >= size) {
 108     // Don't try to expand, enough unused capacity available
 109     return;
 110   }
 111 
 112   const size_t current_max = current_max_capacity();
 113   if (_capacity == current_max) {
 114     // Don't try to expand, current max capacity reached
 115     return;


< prev index next >