< prev index next >

src/hotspot/share/oops/compressedKlass.inline.hpp

Print this page

 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_OOPS_COMPRESSEDKLASS_INLINE_HPP
 26 #define SHARE_OOPS_COMPRESSEDKLASS_INLINE_HPP
 27 
 28 #include "oops/compressedKlass.hpp"
 29 
 30 #include "memory/universe.hpp"
 31 #include "oops/oop.hpp"
 32 #include "utilities/align.hpp"
 33 #include "utilities/globalDefinitions.hpp"
 34 
 35 static inline bool check_alignment(Klass* v) {
 36   return (intptr_t)v % KlassAlignmentInBytes == 0;
 37 }
 38 
 39 inline Klass* CompressedKlassPointers::decode_not_null_without_asserts(narrowKlass v, address narrow_base, int shift) {
 40   return (Klass*)((uintptr_t)narrow_base +((uintptr_t)v << shift));
 41 }
 42 
 43 inline Klass* CompressedKlassPointers::decode_not_null(narrowKlass v, address narrow_base, int shift) {
 44   assert(!is_null(v), "narrow klass value can never be zero");
 45   Klass* result = decode_not_null_without_asserts(v, narrow_base, shift);
 46   assert(check_alignment(result), "address not aligned: " PTR_FORMAT, p2i(result));
 47   return result;
 48 }
 49 




 50 inline narrowKlass CompressedKlassPointers::encode_not_null(Klass* v, address narrow_base, int shift) {
 51   assert(!is_null(v), "klass value can never be zero");
 52   assert(check_alignment(v), "Address not aligned");
 53   uint64_t pd = (uint64_t)(pointer_delta(v, narrow_base, 1));
 54   assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding");
 55   uint64_t result = pd >> shift;
 56   assert((result & CONST64(0xffffffff00000000)) == 0, "narrow klass pointer overflow");
 57   assert(decode_not_null((narrowKlass)result, narrow_base, shift) == v, "reversibility");
 58   return (narrowKlass)result;
 59 }
 60 
 61 inline Klass* CompressedKlassPointers::decode_not_null_without_asserts(narrowKlass v) {
 62   return decode_not_null_without_asserts(v, base(), shift());
 63 }
 64 
 65 inline Klass* CompressedKlassPointers::decode_without_asserts(narrowKlass v) {
 66   return is_null(v) ? nullptr : decode_not_null_without_asserts(v);
 67 }
 68 
 69 inline Klass* CompressedKlassPointers::decode_not_null(narrowKlass v) {

 70   return decode_not_null(v, base(), shift());
 71 }
 72 
 73 inline Klass* CompressedKlassPointers::decode(narrowKlass v) {
 74   return is_null(v) ? nullptr : decode_not_null(v);
 75 }
 76 
 77 inline narrowKlass CompressedKlassPointers::encode_not_null(Klass* v) {
 78   return encode_not_null(v, base(), shift());


 79 }
 80 
 81 inline narrowKlass CompressedKlassPointers::encode(Klass* v) {
 82   return is_null(v) ? (narrowKlass)0 : encode_not_null(v);
 83 }
 84 































 85 #endif // SHARE_OOPS_COMPRESSEDKLASS_INLINE_HPP

 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_OOPS_COMPRESSEDKLASS_INLINE_HPP
 26 #define SHARE_OOPS_COMPRESSEDKLASS_INLINE_HPP
 27 
 28 #include "oops/compressedKlass.hpp"
 29 
 30 #include "memory/universe.hpp"
 31 #include "oops/oop.hpp"
 32 #include "utilities/align.hpp"
 33 #include "utilities/globalDefinitions.hpp"
 34 
 35 inline Klass* CompressedKlassPointers::decode_not_null_without_asserts(narrowKlass v, address narrow_base_base, int shift) {
 36   return (Klass*)((uintptr_t)narrow_base_base +((uintptr_t)v << shift));




 37 }
 38 
 39 inline Klass* CompressedKlassPointers::decode_not_null(narrowKlass v, address narrow_base, int shift) {
 40   assert(!is_null(v), "narrow klass value can never be zero");
 41   Klass* result = decode_not_null_without_asserts(v, narrow_base, shift);
 42   DEBUG_ONLY(check_valid_klass(result, narrow_base, shift));
 43   return result;
 44 }
 45 
 46 inline narrowKlass CompressedKlassPointers::encode_not_null_without_asserts(Klass* k, address narrow_base, int shift) {
 47   return (narrowKlass)(pointer_delta(k, narrow_base, 1) >> shift);
 48 }
 49 
 50 inline narrowKlass CompressedKlassPointers::encode_not_null(Klass* v, address narrow_base, int shift) {
 51   assert(!is_null(v), "klass value can never be zero");
 52   DEBUG_ONLY(check_valid_klass(v);)
 53   narrowKlass result = encode_not_null_without_asserts(v, narrow_base, shift);



 54   assert(decode_not_null((narrowKlass)result, narrow_base, shift) == v, "reversibility");
 55   return result;
 56 }
 57 
 58 inline Klass* CompressedKlassPointers::decode_not_null_without_asserts(narrowKlass v) {
 59   return decode_not_null_without_asserts(v, base(), shift());
 60 }
 61 
 62 inline Klass* CompressedKlassPointers::decode_without_asserts(narrowKlass v) {
 63   return is_null(v) ? nullptr : decode_not_null_without_asserts(v);
 64 }
 65 
 66 inline Klass* CompressedKlassPointers::decode_not_null(narrowKlass v) {
 67   DEBUG_ONLY(check_valid_narrow_klass_id(v);)
 68   return decode_not_null(v, base(), shift());
 69 }
 70 
 71 inline Klass* CompressedKlassPointers::decode(narrowKlass v) {
 72   return is_null(v) ? nullptr : decode_not_null(v);
 73 }
 74 
 75 inline narrowKlass CompressedKlassPointers::encode_not_null(Klass* v) {
 76   narrowKlass nk = encode_not_null(v, base(), shift());
 77   DEBUG_ONLY(check_valid_narrow_klass_id(nk);)
 78   return nk;
 79 }
 80 
 81 inline narrowKlass CompressedKlassPointers::encode(Klass* v) {
 82   return is_null(v) ? (narrowKlass)0 : encode_not_null(v);
 83 }
 84 
 85 #ifdef ASSERT
 86 inline void CompressedKlassPointers::check_valid_klass(const Klass* k, address base, int shift) {
 87   const int log_alignment = MAX2(3, shift); // always at least 64-bit aligned
 88   assert(is_aligned(k, nth_bit(log_alignment)), "Klass (" PTR_FORMAT ") not properly aligned to %zu",
 89          p2i(k), nth_bit(shift));
 90   const address encoding_end = base + nth_bit(narrow_klass_pointer_bits() + shift);
 91   assert((address)k >= base && (address)k < encoding_end,
 92          "Klass (" PTR_FORMAT ") falls outside of the valid encoding range [" PTR_FORMAT "-" PTR_FORMAT ")",
 93          p2i(k), p2i(base), p2i(encoding_end));
 94 }
 95 
 96 inline void CompressedKlassPointers::check_valid_klass(const Klass* k) {
 97   assert(UseCompressedClassPointers, "Only call for +UseCCP");
 98   check_valid_klass(k, base(), shift());
 99   // Also assert that k falls into what we know is the valid Klass range. This is usually smaller
100   // than the encoding range (e.g. encoding range covers 4G, but we only have 1G class space and a
101   // tiny bit of CDS => 1.1G)
102   const address klassrange_end = base() + range();
103   assert((address)k < klassrange_end,
104       "Klass (" PTR_FORMAT ") falls outside of the valid klass range [" PTR_FORMAT "-" PTR_FORMAT ")",
105       p2i(k), p2i(base()), p2i(klassrange_end));
106 }
107 inline void CompressedKlassPointers::check_valid_narrow_klass_id(narrowKlass nk) {
108   assert(UseCompressedClassPointers, "Only call for +UseCCP");
109   const uint64_t nk_mask = ~right_n_bits(narrow_klass_pointer_bits());
110   assert(((uint64_t)nk & nk_mask) == 0, "narrow klass id bit spillover (%u)", nk);
111   assert(nk >= _lowest_valid_narrow_klass_id &&
112          nk <= _highest_valid_narrow_klass_id, "narrowKlass ID out of range (%u)", nk);
113 }
114 #endif // ASSERT
115 
116 #endif // SHARE_OOPS_COMPRESSEDKLASS_INLINE_HPP
< prev index next >