1 /*
 2  * Copyright Amazon.com Inc. 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 
25 #ifndef SHARE_GC_SHARED_FULLGCFORWARDING_HPP
26 #define SHARE_GC_SHARED_FULLGCFORWARDING_HPP
27 
28 #include "memory/allStatic.hpp"
29 #include "memory/memRegion.hpp"
30 #include "oops/markWord.hpp"
31 #include "oops/oopsHierarchy.hpp"
32 
33 /*
34  * Implements forwarding for the Full GCs of Serial, Parallel, G1 and Shenandoah in
35  * a way that preserves upper N bits of object mark-words, which contain crucial
36  * Klass* information when running with compact headers. The encoding is similar to
37  * compressed-oops encoding: it basically subtracts the forwardee address from the
38  * heap-base, shifts that difference into the right place, and sets the lowest two
39  * bits (to indicate 'forwarded' state as usual).
40  * With compact-headers, we have 40 bits to encode forwarding pointers. This is
41  * enough to address 8TB of heap. If the heap size exceeds that limit, we turn off
42  * compact headers.
43  */
44 class FullGCForwarding : public AllStatic {
45   static const int NumLowBitsNarrow = LP64_ONLY(markWord::klass_shift) NOT_LP64(0 /*unused*/);
46   static const int NumLowBitsWide   = BitsPerWord;
47   static const int Shift            = markWord::lock_bits + markWord::lock_shift;
48 
49   static HeapWord* _heap_base;
50   static int _num_low_bits;
51 public:
52   static void initialize_flags(size_t max_heap_size);
53   static void initialize(MemRegion heap);
54   static inline void forward_to(oop from, oop to);
55   static inline oop forwardee(oop from);
56   static inline bool is_forwarded(oop obj);
57 };
58 
59 #endif // SHARE_GC_SHARED_FULLGCFORWARDING_HPP