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