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  */
  23 
  24 #ifndef OS_LINUX_GC_Z_ZPHYSICALMEMORYBACKING_LINUX_HPP
  25 #define OS_LINUX_GC_Z_ZPHYSICALMEMORYBACKING_LINUX_HPP
  26 
  27 #include "gc/z/zBackingFile_linux.hpp"
  28 #include "gc/z/zMemory.hpp"
  29 
  30 class ZErrno;
  31 class ZPhysicalMemory;
  32 
  33 class ZPhysicalMemoryBacking {
  34 private:
  35   ZBackingFile   _file;
  36   ZMemoryManager _committed;
  37   ZMemoryManager _uncommitted;
  38 
  39   void warn_available_space(size_t max) const;
  40   void warn_max_map_count(size_t max) const;
  41 
  42   void map_failed(ZErrno err) const;
  43 
  44   void advise_view(uintptr_t addr, size_t size, int advice) const;
  45   void pretouch_view(uintptr_t addr, size_t size) const;
  46   void map_view(const ZPhysicalMemory& pmem, uintptr_t addr) const;
  47   void unmap_view(const ZPhysicalMemory& pmem, uintptr_t addr) const;
  48 
  49 public:
  50   bool is_initialized() const;
  51 
  52   void warn_commit_limits(size_t max) const;
  53   bool supports_uncommit();
  54 
  55   size_t commit(size_t size);
  56   size_t uncommit(size_t size);
  57 
  58   ZPhysicalMemory alloc(size_t size);
  59   void free(const ZPhysicalMemory& pmem);
  60 
  61   uintptr_t nmt_address(uintptr_t offset) const;
  62 
  63   void pretouch(uintptr_t offset, size_t size) const;
  64 
  65   void map(const ZPhysicalMemory& pmem, uintptr_t offset) const;
  66   void unmap(const ZPhysicalMemory& pmem, uintptr_t offset) const;
  67 
  68   void debug_map(const ZPhysicalMemory& pmem, uintptr_t offset) const;
  69   void debug_unmap(const ZPhysicalMemory& pmem, uintptr_t offset) const;
  70 };
  71 
  72 #endif // OS_LINUX_GC_Z_ZPHYSICALMEMORYBACKING_LINUX_HPP