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 SHARE_GC_Z_ZHEAP_INLINE_HPP
  25 #define SHARE_GC_Z_ZHEAP_INLINE_HPP
  26 
  27 #include "gc/z/zAddress.inline.hpp"
  28 #include "gc/z/zForwarding.inline.hpp"
  29 #include "gc/z/zForwardingTable.inline.hpp"
  30 #include "gc/z/zHash.inline.hpp"
  31 #include "gc/z/zHeap.hpp"
  32 #include "gc/z/zMark.inline.hpp"
  33 #include "gc/z/zOop.inline.hpp"
  34 #include "gc/z/zPage.inline.hpp"
  35 #include "gc/z/zPageTable.inline.hpp"
  36 #include "gc/z/zUtils.inline.hpp"
  37 #include "utilities/debug.hpp"
  38 
  39 inline ZHeap* ZHeap::heap() {
  40   assert(_heap != NULL, "Not initialized");
  41   return _heap;
  42 }
  43 
  44 inline ReferenceDiscoverer* ZHeap::reference_discoverer() {
  45   return &_reference_processor;
  46 }
  47 
  48 inline uint32_t ZHeap::hash_oop(oop obj) const {
  49   const uintptr_t offset = ZAddress::offset(ZOop::to_address(obj));
  50   return ZHash::address_to_uint32(offset);
  51 }
  52 
  53 inline bool ZHeap::is_object_live(uintptr_t addr) const {
  54   ZPage* page = _page_table.get(addr);
  55   return page->is_object_live(addr);
  56 }
  57 
  58 inline bool ZHeap::is_object_strongly_live(uintptr_t addr) const {
  59   ZPage* page = _page_table.get(addr);
  60   return page->is_object_strongly_live(addr);
  61 }
  62 
  63 template <bool finalizable, bool publish>
  64 inline void ZHeap::mark_object(uintptr_t addr) {
  65   assert(ZGlobalPhase == ZPhaseMark, "Mark not allowed");
  66   _mark.mark_object<finalizable, publish>(addr);
  67 }
  68 
  69 inline uintptr_t ZHeap::alloc_tlab(size_t size) {
  70   guarantee(size <= max_tlab_size(), "TLAB too large");
  71   return _object_allocator.alloc_object(size);
  72 }
  73 
  74 inline uintptr_t ZHeap::alloc_object(size_t size) {
  75   uintptr_t addr = _object_allocator.alloc_object(size);
  76   assert(ZAddress::is_good_or_null(addr), "Bad address");
  77 
  78   if (addr == 0) {
  79     out_of_memory();
  80   }
  81 
  82   return addr;
  83 }
  84 
  85 inline uintptr_t ZHeap::alloc_object_for_relocation(size_t size) {
  86   uintptr_t addr = _object_allocator.alloc_object_for_relocation(size);
  87   assert(ZAddress::is_good_or_null(addr), "Bad address");
  88   return addr;
  89 }
  90 
  91 inline void ZHeap::undo_alloc_object_for_relocation(uintptr_t addr, size_t size) {
  92   ZPage* const page = _page_table.get(addr);
  93   _object_allocator.undo_alloc_object_for_relocation(page, addr, size);
  94 }
  95 
  96 inline uintptr_t ZHeap::relocate_object(uintptr_t addr) {
  97   assert(ZGlobalPhase == ZPhaseRelocate, "Relocate not allowed");
  98 
  99   ZForwarding* const forwarding = _forwarding_table.get(addr);
 100   if (forwarding == NULL) {
 101     // Not forwarding
 102     return ZAddress::good(addr);
 103   }
 104 
 105   // Relocate object
 106   const bool retained = forwarding->retain_page();
 107   const uintptr_t new_addr = _relocate.relocate_object(forwarding, addr);
 108   if (retained) {
 109     forwarding->release_page();
 110   }
 111 
 112   return new_addr;
 113 }
 114 
 115 inline uintptr_t ZHeap::remap_object(uintptr_t addr) {
 116   assert(ZGlobalPhase == ZPhaseMark ||
 117          ZGlobalPhase == ZPhaseMarkCompleted, "Forward not allowed");
 118 
 119   ZForwarding* const forwarding = _forwarding_table.get(addr);
 120   if (forwarding == NULL) {
 121     // Not forwarding
 122     return ZAddress::good(addr);
 123   }
 124 
 125   // Forward object
 126   return _relocate.forward_object(forwarding, addr);
 127 }
 128 
 129 inline bool ZHeap::is_alloc_stalled() const {
 130   return _page_allocator.is_alloc_stalled();
 131 }
 132 
 133 inline void ZHeap::check_out_of_memory() {
 134   _page_allocator.check_out_of_memory();
 135 }
 136 
 137 inline bool ZHeap::is_oop(oop object) const {
 138   // Verify that we have a good address. Note that ZAddress::is_good()
 139   // would not be a strong enough verification, since it only verifies
 140   // that the metadata bits are good.
 141   const uintptr_t addr = ZOop::to_address(object);
 142   return ZAddress::good(addr) == addr;
 143 }
 144 
 145 #endif // SHARE_GC_Z_ZHEAP_INLINE_HPP