@@ -186,83 +186,63 @@ NarrowPtrStruct CompressedKlassPointers::_narrow_klass = { nullptr, 0, true };
186
186
// are compiled for 32bit to LP64_ONLY).
187
187
size_t CompressedKlassPointers::_range = 0 ;
188
188
189
+ #ifdef _LP64
190
+
191
+ // Given a klass range [addr, addr+len) and a given encoding scheme, assert that this scheme covers the range, then
192
+ // set this encoding scheme. Used by CDS at runtime to re-instate the scheme used to pre-compute klass ids for
193
+ // archived heap objects.
194
+ void CompressedKlassPointers::initialize_for_given_encoding (address addr, size_t len, address requested_base, int requested_shift) {
195
+ assert (is_valid_base (requested_base), " Address must be a valid encoding base" );
196
+ address const end = addr + len;
197
+
198
+ const int narrow_klasspointer_bits = sizeof (narrowKlass) * 8 ;
199
+ const size_t encoding_range_size = nth_bit (narrow_klasspointer_bits + requested_shift);
200
+ address encoding_range_end = requested_base + encoding_range_size;
201
+
202
+ // Note: it would be technically valid for the encoding base to precede the start of the Klass range. But we only call
203
+ // this function from CDS, and therefore know this to be true.
204
+ assert (requested_base == addr, " Invalid requested base" );
205
+ assert (encoding_range_end >= end, " Encoding does not cover the full Klass range" );
206
+
207
+ set_base (requested_base);
208
+ set_shift (requested_shift);
209
+ set_range (encoding_range_size);
210
+ }
189
211
190
212
// Given an address range [addr, addr+len) which the encoding is supposed to
191
213
// cover, choose base, shift and range.
192
214
// The address range is the expected range of uncompressed Klass pointers we
193
215
// will encounter (and the implicit promise that there will be no Klass
194
216
// structures outside this range).
195
217
void CompressedKlassPointers::initialize (address addr, size_t len) {
196
- #ifdef _LP64
197
218
assert (is_valid_base (addr), " Address must be a valid encoding base" );
198
219
address const end = addr + len;
199
220
200
221
address base;
201
222
int shift;
202
223
size_t range;
203
224
204
- if (UseSharedSpaces || DumpSharedSpaces) {
205
-
206
- // Special requirements if CDS is active:
207
- // Encoding base and shift must be the same between dump and run time.
208
- // CDS takes care that the SharedBaseAddress and CompressedClassSpaceSize
209
- // are the same. Archive size will be probably different at runtime, but
210
- // it can only be smaller than at, never larger, since archives get
211
- // shrunk at the end of the dump process.
212
- // From that it follows that the range [addr, len) we are handed in at
213
- // runtime will start at the same address then at dumptime, and its len
214
- // may be smaller at runtime then it was at dump time.
215
- //
216
- // To be very careful here, we avoid any optimizations and just keep using
217
- // the same address and shift value. Specifically we avoid using zero-based
218
- // encoding. We also set the expected value range to 4G (encoding range
219
- // cannot be larger than that).
220
-
225
+ // Attempt to run with encoding base == zero
226
+ if (end <= (address)KlassEncodingMetaspaceMax) {
227
+ base = 0 ;
228
+ } else {
221
229
base = addr;
230
+ }
222
231
223
- // JDK-8265705
224
- // This is a temporary fix for aarch64: there, if the range-to-be-encoded is located
225
- // below 32g, either encoding base should be zero or base should be aligned to 4G
226
- // and shift should be zero. The simplest way to fix this for now is to force
227
- // shift to zero for both runtime and dumptime.
228
- // Note however that this is not a perfect solution. Ideally this whole function
229
- // should be CDS agnostic, that would simplify it - and testing - a lot. See JDK-8267141
230
- // for details.
231
- shift = 0 ;
232
-
233
- // This must be true since at dumptime cds+ccs is 4G, at runtime it can
234
- // only be smaller, see comment above.
235
- assert (len <= 4 * G, " Encoding range cannot be larger than 4G" );
236
- range = 4 * G;
232
+ // Highest offset a Klass* can ever have in relation to base.
233
+ range = end - base;
237
234
235
+ // We may not even need a shift if the range fits into 32bit:
236
+ const uint64_t UnscaledClassSpaceMax = (uint64_t (max_juint) + 1 );
237
+ if (range < UnscaledClassSpaceMax) {
238
+ shift = 0 ;
238
239
} else {
239
-
240
- // Otherwise we attempt to use a zero base if the range fits in lower 32G.
241
- if (end <= (address)KlassEncodingMetaspaceMax) {
242
- base = 0 ;
243
- } else {
244
- base = addr;
245
- }
246
-
247
- // Highest offset a Klass* can ever have in relation to base.
248
- range = end - base;
249
-
250
- // We may not even need a shift if the range fits into 32bit:
251
- const uint64_t UnscaledClassSpaceMax = (uint64_t (max_juint) + 1 );
252
- if (range < UnscaledClassSpaceMax) {
253
- shift = 0 ;
254
- } else {
255
- shift = LogKlassAlignmentInBytes;
256
- }
257
-
240
+ shift = LogKlassAlignmentInBytes;
258
241
}
259
242
260
243
set_base (base);
261
244
set_shift (shift);
262
245
set_range (range);
263
- #else
264
- fatal (" 64bit only." );
265
- #endif
266
246
}
267
247
268
248
// Given an address p, return true if p can be used as an encoding base.
@@ -300,3 +280,5 @@ void CompressedKlassPointers::set_range(size_t range) {
300
280
assert (UseCompressedClassPointers, " no compressed klass ptrs?" );
301
281
_range = range;
302
282
}
283
+
284
+ #endif // _LP64
0 commit comments