1 /*
2  * Copyright (c) 2015, 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_ZADDRESS_INLINE_HPP
25 #define SHARE_GC_Z_ZADDRESS_INLINE_HPP
26 
27 #include "gc/z/zAddress.hpp"
28 #include "gc/z/zGlobals.hpp"
29 #include "utilities/macros.hpp"
30 #include OS_CPU_HEADER_INLINE(gc/z/zAddress)
31 
is_null(uintptr_t value)32 inline bool ZAddress::is_null(uintptr_t value) {
33   return value == 0;
34 }
35 
is_bad(uintptr_t value)36 inline bool ZAddress::is_bad(uintptr_t value) {
37   return value & ZAddressBadMask;
38 }
39 
is_good(uintptr_t value)40 inline bool ZAddress::is_good(uintptr_t value) {
41   return !is_bad(value) && !is_null(value);
42 }
43 
is_good_or_null(uintptr_t value)44 inline bool ZAddress::is_good_or_null(uintptr_t value) {
45   // Checking if an address is "not bad" is an optimized version of
46   // checking if it's "good or null", which eliminates an explicit
47   // null check. However, the implicit null check only checks that
48   // the mask bits are zero, not that the entire address is zero.
49   // This means that an address without mask bits would pass through
50   // the barrier as if it was null. This should be harmless as such
51   // addresses should ever be passed through the barrier.
52   const bool result = !is_bad(value);
53   assert((is_good(value) || is_null(value)) == result, "Bad address");
54   return result;
55 }
56 
is_weak_bad(uintptr_t value)57 inline bool ZAddress::is_weak_bad(uintptr_t value) {
58   return value & ZAddressWeakBadMask;
59 }
60 
is_weak_good(uintptr_t value)61 inline bool ZAddress::is_weak_good(uintptr_t value) {
62   return !is_weak_bad(value) && !is_null(value);
63 }
64 
is_weak_good_or_null(uintptr_t value)65 inline bool ZAddress::is_weak_good_or_null(uintptr_t value) {
66   return !is_weak_bad(value);
67 }
68 
is_marked(uintptr_t value)69 inline bool ZAddress::is_marked(uintptr_t value) {
70   return value & ZAddressMetadataMarked;
71 }
72 
is_finalizable(uintptr_t value)73 inline bool ZAddress::is_finalizable(uintptr_t value) {
74   return value & ZAddressMetadataFinalizable;
75 }
76 
is_finalizable_good(uintptr_t value)77 inline bool ZAddress::is_finalizable_good(uintptr_t value) {
78   return is_finalizable(value) && is_good(value ^ ZAddressMetadataFinalizable);
79 }
80 
is_remapped(uintptr_t value)81 inline bool ZAddress::is_remapped(uintptr_t value) {
82   return value & ZAddressMetadataRemapped;
83 }
84 
offset(uintptr_t value)85 inline uintptr_t ZAddress::offset(uintptr_t value) {
86   return value & ZAddressOffsetMask;
87 }
88 
good(uintptr_t value)89 inline uintptr_t ZAddress::good(uintptr_t value) {
90   return address(offset(value) | ZAddressGoodMask);
91 }
92 
good_or_null(uintptr_t value)93 inline uintptr_t ZAddress::good_or_null(uintptr_t value) {
94   return is_null(value) ? 0 : good(value);
95 }
96 
finalizable_good(uintptr_t value)97 inline uintptr_t ZAddress::finalizable_good(uintptr_t value) {
98   return address(offset(value) | ZAddressMetadataFinalizable | ZAddressGoodMask);
99 }
100 
marked(uintptr_t value)101 inline uintptr_t ZAddress::marked(uintptr_t value) {
102   return address(offset(value) | ZAddressMetadataMarked);
103 }
104 
marked0(uintptr_t value)105 inline uintptr_t ZAddress::marked0(uintptr_t value) {
106   return address(offset(value) | ZAddressMetadataMarked0);
107 }
108 
marked1(uintptr_t value)109 inline uintptr_t ZAddress::marked1(uintptr_t value) {
110   return address(offset(value) | ZAddressMetadataMarked1);
111 }
112 
remapped(uintptr_t value)113 inline uintptr_t ZAddress::remapped(uintptr_t value) {
114   return address(offset(value) | ZAddressMetadataRemapped);
115 }
116 
remapped_or_null(uintptr_t value)117 inline uintptr_t ZAddress::remapped_or_null(uintptr_t value) {
118   return is_null(value) ? 0 : remapped(value);
119 }
120 
121 #endif // SHARE_GC_Z_ZADDRESS_INLINE_HPP
122