/* * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ #ifndef SHARE_GC_Z_ZHEAP_INLINE_HPP #define SHARE_GC_Z_ZHEAP_INLINE_HPP #include "gc/z/zAddress.inline.hpp" #include "gc/z/zForwarding.inline.hpp" #include "gc/z/zForwardingTable.inline.hpp" #include "gc/z/zHash.inline.hpp" #include "gc/z/zHeap.hpp" #include "gc/z/zMark.inline.hpp" #include "gc/z/zOop.inline.hpp" #include "gc/z/zPage.inline.hpp" #include "gc/z/zPageTable.inline.hpp" #include "gc/z/zUtils.inline.hpp" #include "utilities/debug.hpp" inline ZHeap* ZHeap::heap() { assert(_heap != NULL, "Not initialized"); return _heap; } inline ReferenceDiscoverer* ZHeap::reference_discoverer() { return &_reference_processor; } inline uint32_t ZHeap::hash_oop(oop obj) const { const uintptr_t offset = ZAddress::offset(ZOop::to_address(obj)); return ZHash::address_to_uint32(offset); } inline bool ZHeap::is_object_live(uintptr_t addr) const { ZPage* page = _page_table.get(addr); return page->is_object_live(addr); } inline bool ZHeap::is_object_strongly_live(uintptr_t addr) const { ZPage* page = _page_table.get(addr); return page->is_object_strongly_live(addr); } template inline void ZHeap::mark_object(uintptr_t addr) { assert(ZGlobalPhase == ZPhaseMark, "Mark not allowed"); _mark.mark_object(addr); } inline uintptr_t ZHeap::alloc_tlab(size_t size) { guarantee(size <= max_tlab_size(), "TLAB too large"); return _object_allocator.alloc_object(size); } inline uintptr_t ZHeap::alloc_object(size_t size) { uintptr_t addr = _object_allocator.alloc_object(size); assert(ZAddress::is_good_or_null(addr), "Bad address"); if (addr == 0) { out_of_memory(); } return addr; } inline uintptr_t ZHeap::alloc_object_for_relocation(size_t size) { uintptr_t addr = _object_allocator.alloc_object_for_relocation(size); assert(ZAddress::is_good_or_null(addr), "Bad address"); return addr; } inline void ZHeap::undo_alloc_object_for_relocation(uintptr_t addr, size_t size) { ZPage* const page = _page_table.get(addr); _object_allocator.undo_alloc_object_for_relocation(page, addr, size); } inline uintptr_t ZHeap::relocate_object(uintptr_t addr) { assert(ZGlobalPhase == ZPhaseRelocate, "Relocate not allowed"); ZForwarding* const forwarding = _forwarding_table.get(addr); if (forwarding == NULL) { // Not forwarding return ZAddress::good(addr); } // Relocate object const bool retained = forwarding->retain_page(); const uintptr_t new_addr = _relocate.relocate_object(forwarding, addr); if (retained) { forwarding->release_page(); } return new_addr; } inline uintptr_t ZHeap::remap_object(uintptr_t addr) { assert(ZGlobalPhase == ZPhaseMark || ZGlobalPhase == ZPhaseMarkCompleted, "Forward not allowed"); ZForwarding* const forwarding = _forwarding_table.get(addr); if (forwarding == NULL) { // Not forwarding return ZAddress::good(addr); } // Forward object return _relocate.forward_object(forwarding, addr); } inline bool ZHeap::is_alloc_stalled() const { return _page_allocator.is_alloc_stalled(); } inline void ZHeap::check_out_of_memory() { _page_allocator.check_out_of_memory(); } inline void ZHeap::pin_allocating(uintptr_t page_start) { ZPage* page = _page_table.get(page_start); page->pin_allocating(); } inline void ZHeap::unpin_allocating(uintptr_t page_start) { ZPage* page = _page_table.get(page_start); page->unpin_allocating(); } inline bool ZHeap::is_oop(oop object) const { // Verify that we have a good address. Note that ZAddress::is_good() // would not be a strong enough verification, since it only verifies // that the metadata bits are good. const uintptr_t addr = ZOop::to_address(object); return ZAddress::good(addr) == addr; } #endif // SHARE_GC_Z_ZHEAP_INLINE_HPP