< prev index next >

src/hotspot/share/gc/z/zGranuleMap.inline.hpp

Print this page


   1 /*
   2  * Copyright (c) 2017, 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 SHARE_GC_Z_ZADDRESSRANGEMAP_INLINE_HPP
  25 #define SHARE_GC_Z_ZADDRESSRANGEMAP_INLINE_HPP
  26 
  27 #include "gc/z/zAddress.inline.hpp"
  28 #include "gc/z/zAddressRangeMap.hpp"
  29 #include "gc/z/zGlobals.hpp"

  30 #include "memory/allocation.inline.hpp"
  31 
  32 template <typename T, size_t AddressRangeShift>
  33 ZAddressRangeMap<T, AddressRangeShift>::ZAddressRangeMap() :
  34     _map(MmapArrayAllocator<T>::allocate(size(), mtGC)) {}
  35 
  36 template <typename T, size_t AddressRangeShift>
  37 ZAddressRangeMap<T, AddressRangeShift>::~ZAddressRangeMap() {
  38   MmapArrayAllocator<T>::free(_map, size());
  39 }
  40 
  41 template <typename T, size_t AddressRangeShift>
  42 size_t ZAddressRangeMap<T, AddressRangeShift>::index_for_addr(uintptr_t addr) const {
  43   assert(!ZAddress::is_null(addr), "Invalid address");
  44 
  45   const size_t index = ZAddress::offset(addr) >> AddressRangeShift;
  46   assert(index < size(), "Invalid index");
  47 
  48   return index;
  49 }
  50 
  51 template <typename T, size_t AddressRangeShift>
  52 size_t ZAddressRangeMap<T, AddressRangeShift>::size() const {
  53   return ZAddressOffsetMax >> AddressRangeShift;
  54 }
  55 
  56 template <typename T, size_t AddressRangeShift>
  57 T ZAddressRangeMap<T, AddressRangeShift>::get(uintptr_t addr) const {
  58   const uintptr_t index = index_for_addr(addr);
  59   return _map[index];
  60 }
  61 
  62 template <typename T, size_t AddressRangeShift>
  63 void ZAddressRangeMap<T, AddressRangeShift>::put(uintptr_t addr, T value) {
  64   const uintptr_t index = index_for_addr(addr);
  65   _map[index] = value;
  66 }
  67 
  68 template <typename T, size_t AddressRangeShift>
  69 inline ZAddressRangeMapIterator<T, AddressRangeShift>::ZAddressRangeMapIterator(const ZAddressRangeMap<T, AddressRangeShift>* map) :
  70     _map(map),
  71     _next(0) {}
  72 
  73 template <typename T, size_t AddressRangeShift>
  74 inline bool ZAddressRangeMapIterator<T, AddressRangeShift>::next(T* value) {
  75   if (_next < _map->size()) {
  76     *value = _map->_map[_next++];
  77     return true;
  78   }
  79 
  80   // End of map
  81   return false;
  82 }
  83 
  84 #endif // SHARE_GC_Z_ZADDRESSRANGEMAP_INLINE_HPP
   1 /*
   2  * Copyright (c) 2017, 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 SHARE_GC_Z_ZGRANULEMAP_INLINE_HPP
  25 #define SHARE_GC_Z_ZGRANULEMAP_INLINE_HPP
  26 
  27 #include "gc/z/zAddress.inline.hpp"

  28 #include "gc/z/zGlobals.hpp"
  29 #include "gc/z/zGranuleMap.hpp"
  30 #include "memory/allocation.inline.hpp"
  31 
  32 template <typename T>
  33 inline ZGranuleMap<T>::ZGranuleMap() :
  34     _map(MmapArrayAllocator<T>::allocate(size(), mtGC)) {}
  35 
  36 template <typename T>
  37 inline ZGranuleMap<T>::~ZGranuleMap() {
  38   MmapArrayAllocator<T>::free(_map, size());
  39 }
  40 
  41 template <typename T>
  42 inline size_t ZGranuleMap<T>::index_for_addr(uintptr_t addr) const {
  43   assert(!ZAddress::is_null(addr), "Invalid address");
  44 
  45   const size_t index = ZAddress::offset(addr) >> ZGranuleSizeShift;
  46   assert(index < size(), "Invalid index");
  47 
  48   return index;
  49 }
  50 
  51 template <typename T>
  52 inline size_t ZGranuleMap<T>::size() const {
  53   return ZAddressOffsetMax >> ZGranuleSizeShift;
  54 }
  55 
  56 template <typename T>
  57 inline T ZGranuleMap<T>::get(uintptr_t addr) const {
  58   const size_t index = index_for_addr(addr);
  59   return _map[index];
  60 }
  61 
  62 template <typename T>
  63 inline void ZGranuleMap<T>::put(uintptr_t addr, T value) {
  64   const size_t index = index_for_addr(addr);
  65   _map[index] = value;
  66 }
  67 
  68 template <typename T>
  69 inline ZGranuleMapIterator<T>::ZGranuleMapIterator(const ZGranuleMap<T>* map) :
  70     _map(map),
  71     _next(0) {}
  72 
  73 template <typename T>
  74 inline bool ZGranuleMapIterator<T>::next(T* value) {
  75   if (_next < _map->size()) {
  76     *value = _map->_map[_next++];
  77     return true;
  78   }
  79 
  80   // End of map
  81   return false;
  82 }
  83 
  84 #endif // SHARE_GC_Z_ZGRANULEMAP_INLINE_HPP
< prev index next >