< prev index next >

src/hotspot/share/oops/compressedKlass.cpp

Print this page

 59   if (UseCompactObjectHeaders) {
 60     _narrow_klass_pointer_bits = narrow_klass_pointer_bits_coh;
 61     _max_shift = max_shift_coh;
 62   } else {
 63     _narrow_klass_pointer_bits = narrow_klass_pointer_bits_noncoh;
 64     _max_shift = max_shift_noncoh;
 65   }
 66 }
 67 
 68 #ifdef ASSERT
 69 void CompressedKlassPointers::sanity_check_after_initialization() {
 70   // In expectation of an assert, prepare condensed info to be printed with the assert.
 71   char tmp[256];
 72   os::snprintf(tmp, sizeof(tmp), "klass range: " RANGE2FMT ","
 73       " base " PTR_FORMAT ", shift %d, lowest/highest valid narrowKlass %u/%u",
 74       RANGE2FMTARGS(_klass_range_start, _klass_range_end),
 75       p2i(_base), _shift, _lowest_valid_narrow_klass_id, _highest_valid_narrow_klass_id);
 76 #define ASSERT_HERE(cond) assert(cond, " (%s)", tmp);
 77 #define ASSERT_HERE_2(cond, msg) assert(cond, msg " (%s)", tmp);
 78 




 79   // All values must be inited
 80   ASSERT_HERE(_max_shift != -1);
 81   ASSERT_HERE(_klass_range_start != (address)-1);
 82   ASSERT_HERE(_klass_range_end != (address)-1);
 83   ASSERT_HERE(_lowest_valid_narrow_klass_id != (narrowKlass)-1);
 84   ASSERT_HERE(_base != (address)-1);
 85   ASSERT_HERE(_shift != -1);
 86 
 87   const size_t klass_align = klass_alignment_in_bytes();
 88 
 89   // must be aligned enough hold 64-bit data
 90   ASSERT_HERE(is_aligned(klass_align, sizeof(uint64_t)));
 91 
 92   // should be smaller than the minimum metaspace chunk size (soft requirement)
 93   ASSERT_HERE(klass_align <= K);
 94 
 95   ASSERT_HERE(_klass_range_end > _klass_range_start);
 96 
 97   // Check that Klass range is fully engulfed in the encoding range
 98   const address encoding_start = _base;

205   return reserve_address_space_X(nth_bit(32), nth_bit(48), size, nth_bit(32), aslr);
206 }
207 
208 void CompressedKlassPointers::initialize(address addr, size_t len) {
209 
210   if (len > max_klass_range_size()) {
211     stringStream ss;
212     ss.print("Class space size (%zu) exceeds the maximum possible size (%zu)",
213               len, max_klass_range_size());
214     vm_exit_during_initialization(ss.base());
215   }
216 
217   // Remember the Klass range:
218   _klass_range_start = addr;
219   _klass_range_end = addr + len;
220 
221   // Calculate Base and Shift:
222 
223   if (UseCompactObjectHeaders) {
224 
225     // In compact object header mode, with 22-bit narrowKlass, we don't attempt for





226     // zero-based mode. Instead, we set the base to the start of the klass range and
227     // then try for the smallest shift possible that still covers the whole range.
228     // The reason is that we want to avoid, if possible, shifts larger than
229     // a cacheline size.
230     _base = addr;
231 
232     const int log_cacheline = exact_log2(DEFAULT_CACHE_LINE_SIZE);
233     int s = max_shift();
234     while (s > log_cacheline && ((size_t)nth_bit(narrow_klass_pointer_bits() + s - 1) > len)) {
235       s--;
236     }
237     _shift = s;
238 
239   } else {
240 
241     // Traditional (non-compact) header mode
242     const uintptr_t unscaled_max = nth_bit(narrow_klass_pointer_bits());
243     const uintptr_t zerobased_max = nth_bit(narrow_klass_pointer_bits() + max_shift());
244 
245 #ifdef AARCH64

 59   if (UseCompactObjectHeaders) {
 60     _narrow_klass_pointer_bits = narrow_klass_pointer_bits_coh;
 61     _max_shift = max_shift_coh;
 62   } else {
 63     _narrow_klass_pointer_bits = narrow_klass_pointer_bits_noncoh;
 64     _max_shift = max_shift_noncoh;
 65   }
 66 }
 67 
 68 #ifdef ASSERT
 69 void CompressedKlassPointers::sanity_check_after_initialization() {
 70   // In expectation of an assert, prepare condensed info to be printed with the assert.
 71   char tmp[256];
 72   os::snprintf(tmp, sizeof(tmp), "klass range: " RANGE2FMT ","
 73       " base " PTR_FORMAT ", shift %d, lowest/highest valid narrowKlass %u/%u",
 74       RANGE2FMTARGS(_klass_range_start, _klass_range_end),
 75       p2i(_base), _shift, _lowest_valid_narrow_klass_id, _highest_valid_narrow_klass_id);
 76 #define ASSERT_HERE(cond) assert(cond, " (%s)", tmp);
 77 #define ASSERT_HERE_2(cond, msg) assert(cond, msg " (%s)", tmp);
 78 
 79   // There is no technical reason preventing us from using other klass pointer bit lengths,
 80   // but it should be a deliberate choice
 81   ASSERT_HERE(_narrow_klass_pointer_bits == 32 || _narrow_klass_pointer_bits == 19);
 82 
 83   // All values must be inited
 84   ASSERT_HERE(_max_shift != -1);
 85   ASSERT_HERE(_klass_range_start != (address)-1);
 86   ASSERT_HERE(_klass_range_end != (address)-1);
 87   ASSERT_HERE(_lowest_valid_narrow_klass_id != (narrowKlass)-1);
 88   ASSERT_HERE(_base != (address)-1);
 89   ASSERT_HERE(_shift != -1);
 90 
 91   const size_t klass_align = klass_alignment_in_bytes();
 92 
 93   // must be aligned enough hold 64-bit data
 94   ASSERT_HERE(is_aligned(klass_align, sizeof(uint64_t)));
 95 
 96   // should be smaller than the minimum metaspace chunk size (soft requirement)
 97   ASSERT_HERE(klass_align <= K);
 98 
 99   ASSERT_HERE(_klass_range_end > _klass_range_start);
100 
101   // Check that Klass range is fully engulfed in the encoding range
102   const address encoding_start = _base;

209   return reserve_address_space_X(nth_bit(32), nth_bit(48), size, nth_bit(32), aslr);
210 }
211 
212 void CompressedKlassPointers::initialize(address addr, size_t len) {
213 
214   if (len > max_klass_range_size()) {
215     stringStream ss;
216     ss.print("Class space size (%zu) exceeds the maximum possible size (%zu)",
217               len, max_klass_range_size());
218     vm_exit_during_initialization(ss.base());
219   }
220 
221   // Remember the Klass range:
222   _klass_range_start = addr;
223   _klass_range_end = addr + len;
224 
225   // Calculate Base and Shift:
226 
227   if (UseCompactObjectHeaders) {
228 
229     // This handles the case that we - experimentally - reduce the number of
230     // class pointer bits further, such that (shift + num bits) < 32.
231     assert(len <= (size_t)nth_bit(narrow_klass_pointer_bits() + max_shift()),
232            "klass range size exceeds encoding, len: %zu, narrow_klass_pointer_bits: %d, max_shift: %d", len, narrow_klass_pointer_bits(), max_shift());
233 
234     // In compact object header mode, with 19-bit narrowKlass, we don't attempt for
235     // zero-based mode. Instead, we set the base to the start of the klass range and
236     // then try for the smallest shift possible that still covers the whole range.
237     // The reason is that we want to avoid, if possible, shifts larger than
238     // a cacheline size.
239     _base = addr;
240 
241     const int log_cacheline = exact_log2(DEFAULT_CACHE_LINE_SIZE);
242     int s = max_shift();
243     while (s > log_cacheline && ((size_t)nth_bit(narrow_klass_pointer_bits() + s - 1) > len)) {
244       s--;
245     }
246     _shift = s;
247 
248   } else {
249 
250     // Traditional (non-compact) header mode
251     const uintptr_t unscaled_max = nth_bit(narrow_klass_pointer_bits());
252     const uintptr_t zerobased_max = nth_bit(narrow_klass_pointer_bits() + max_shift());
253 
254 #ifdef AARCH64
< prev index next >