| 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_ZFORWARDING_HPP | 
|---|
| 25 | #define SHARE_GC_Z_ZFORWARDING_HPP | 
|---|
| 26 |  | 
|---|
| 27 | #include "gc/z/zAttachedArray.hpp" | 
|---|
| 28 | #include "gc/z/zForwardingEntry.hpp" | 
|---|
| 29 | #include "gc/z/zVirtualMemory.hpp" | 
|---|
| 30 |  | 
|---|
| 31 | class ZPage; | 
|---|
| 32 |  | 
|---|
| 33 | typedef uint32_t ZForwardingCursor; | 
|---|
| 34 |  | 
|---|
| 35 | class ZForwarding { | 
|---|
| 36 | friend class VMStructs; | 
|---|
| 37 | friend class ZForwardingTest; | 
|---|
| 38 |  | 
|---|
| 39 | private: | 
|---|
| 40 | typedef ZAttachedArray<ZForwarding, ZForwardingEntry> AttachedArray; | 
|---|
| 41 |  | 
|---|
| 42 | const ZVirtualMemory _virtual; | 
|---|
| 43 | const size_t         _object_alignment_shift; | 
|---|
| 44 | const AttachedArray  _entries; | 
|---|
| 45 | ZPage*               _page; | 
|---|
| 46 | volatile uint32_t    _refcount; | 
|---|
| 47 | volatile bool        _pinned; | 
|---|
| 48 |  | 
|---|
| 49 | bool inc_refcount(); | 
|---|
| 50 | bool dec_refcount(); | 
|---|
| 51 |  | 
|---|
| 52 | ZForwardingEntry* entries() const; | 
|---|
| 53 | ZForwardingEntry at(ZForwardingCursor* cursor) const; | 
|---|
| 54 | ZForwardingEntry first(uintptr_t from_index, ZForwardingCursor* cursor) const; | 
|---|
| 55 | ZForwardingEntry next(ZForwardingCursor* cursor) const; | 
|---|
| 56 |  | 
|---|
| 57 | ZForwarding(ZPage* page, uint32_t nentries); | 
|---|
| 58 |  | 
|---|
| 59 | public: | 
|---|
| 60 | static ZForwarding* create(ZPage* page); | 
|---|
| 61 | static void destroy(ZForwarding* forwarding); | 
|---|
| 62 |  | 
|---|
| 63 | uintptr_t start() const; | 
|---|
| 64 | size_t size() const; | 
|---|
| 65 | size_t object_alignment_shift() const; | 
|---|
| 66 | ZPage* page() const; | 
|---|
| 67 |  | 
|---|
| 68 | bool is_pinned() const; | 
|---|
| 69 | void set_pinned(); | 
|---|
| 70 |  | 
|---|
| 71 | bool retain_page(); | 
|---|
| 72 | void release_page(); | 
|---|
| 73 |  | 
|---|
| 74 | ZForwardingEntry find(uintptr_t from_index) const; | 
|---|
| 75 | ZForwardingEntry find(uintptr_t from_index, ZForwardingCursor* cursor) const; | 
|---|
| 76 | uintptr_t insert(uintptr_t from_index, uintptr_t to_offset, ZForwardingCursor* cursor); | 
|---|
| 77 |  | 
|---|
| 78 | void verify() const; | 
|---|
| 79 | }; | 
|---|
| 80 |  | 
|---|
| 81 | #endif // SHARE_GC_Z_ZFORWARDING_HPP | 
|---|
| 82 |  | 
|---|