< prev index next >

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

Print this page

 96   return v;
 97 }
 98 
 99 inline uint32_t CompressedOops::narrow_oop_value(oop o) {
100   return narrow_oop_value(encode(o));
101 }
102 
103 inline uint32_t CompressedOops::narrow_oop_value(narrowOop o) {
104   return static_cast<uint32_t>(o);
105 }
106 
107 template<typename T>
108 inline narrowOop CompressedOops::narrow_oop_cast(T i) {
109   static_assert(std::is_integral<T>::value, "precondition");
110   uint32_t narrow_value = static_cast<uint32_t>(i);
111   // Ensure no bits lost in conversion to uint32_t.
112   assert(i == static_cast<T>(narrow_value), "narrowOop overflow");
113   return static_cast<narrowOop>(narrow_value);
114 }
115 
116 static inline bool check_alignment(Klass* v) {
117   return (intptr_t)v % KlassAlignmentInBytes == 0;
118 }
119 
120 inline Klass* CompressedKlassPointers::decode_raw(narrowKlass v) {
121   return decode_raw(v, base());
122 }
123 
124 inline Klass* CompressedKlassPointers::decode_raw(narrowKlass v, address narrow_base) {
125   return (Klass*)((uintptr_t)narrow_base +((uintptr_t)v << shift()));
126 }
127 
128 inline Klass* CompressedKlassPointers::decode_not_null(narrowKlass v) {
129   return decode_not_null(v, base());
130 }
131 
132 inline Klass* CompressedKlassPointers::decode_not_null(narrowKlass v, address narrow_base) {
133   assert(!is_null(v), "narrow klass value can never be zero");
134   Klass* result = decode_raw(v, narrow_base);
135   assert(check_alignment(result), "address not aligned: " PTR_FORMAT, p2i(result));
136   return result;
137 }
138 
139 inline Klass* CompressedKlassPointers::decode(narrowKlass v) {
140   return is_null(v) ? (Klass*)NULL : decode_not_null(v);
141 }
142 
143 inline narrowKlass CompressedKlassPointers::encode_not_null(Klass* v) {
144   return encode_not_null(v, base());
145 }
146 
147 inline narrowKlass CompressedKlassPointers::encode_not_null(Klass* v, address narrow_base) {
148   assert(!is_null(v), "klass value can never be zero");
149   assert(check_alignment(v), "Address not aligned");
150   uint64_t pd = (uint64_t)(pointer_delta(v, narrow_base, 1));
151   assert(KlassEncodingMetaspaceMax > pd, "change encoding max if new encoding");
152   uint64_t result = pd >> shift();
153   assert((result & CONST64(0xffffffff00000000)) == 0, "narrow klass pointer overflow");
154   assert(decode_not_null(result, narrow_base) == v, "reversibility");
155   return (narrowKlass)result;
156 }
157 
158 inline narrowKlass CompressedKlassPointers::encode(Klass* v) {
159   return is_null(v) ? (narrowKlass)0 : encode_not_null(v);
160 }
161 
162 #endif // SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP

 96   return v;
 97 }
 98 
 99 inline uint32_t CompressedOops::narrow_oop_value(oop o) {
100   return narrow_oop_value(encode(o));
101 }
102 
103 inline uint32_t CompressedOops::narrow_oop_value(narrowOop o) {
104   return static_cast<uint32_t>(o);
105 }
106 
107 template<typename T>
108 inline narrowOop CompressedOops::narrow_oop_cast(T i) {
109   static_assert(std::is_integral<T>::value, "precondition");
110   uint32_t narrow_value = static_cast<uint32_t>(i);
111   // Ensure no bits lost in conversion to uint32_t.
112   assert(i == static_cast<T>(narrow_value), "narrowOop overflow");
113   return static_cast<narrowOop>(narrow_value);
114 }
115 














































116 #endif // SHARE_OOPS_COMPRESSEDOOPS_INLINE_HPP
< prev index next >