91 // |//////////|///////////////////////////| |
92 // |///CDS////|////1gb class space////////| ... ... |
93 // |//////////|///////////////////////////| |
94 // | | |
95 // 0x8_0000_0000 0x8_4800_0000 0x9_0000_0000
96 //
97
98 // If compressed klass pointers then use narrowKlass.
99 typedef juint narrowKlass;
100
101 // For UseCompressedClassPointers.
102 class CompressedKlassPointers : public AllStatic {
103 friend class VMStructs;
104 friend class ArchiveBuilder;
105
106 // We use a different narrow Klass pointer geometry depending on
107 // whether we run in standard mode or in compact-object-header-mode.
108
109 // Narrow klass pointer bits for an unshifted narrow Klass pointer.
110 static constexpr int narrow_klass_pointer_bits_noncoh = 32;
111 static constexpr int narrow_klass_pointer_bits_coh = 22;
112
113 // Bit size of a narrowKlass
114 static int _narrow_klass_pointer_bits;
115
116 // The maximum shift values we can use depending on UseCompactObjectHeaders
117 static constexpr int max_shift_noncoh = 3;
118 static constexpr int max_shift_coh = 10;
119
120 // Maximum shift usable
121 static int _max_shift;
122
123 // Encoding Base, Encoding Shift
124 static address _base;
125 static int _shift;
126
127 // Start and end of the Klass Range. Start includes the protection zone if one exists.
128 // Note: guaranteed to be aligned to 1<<shift (klass_alignment_in_bytes)
129 static address _klass_range_start;
130 static address _klass_range_end;
131
171 // 4) call reserve_address_space_for_compressed_classes() either from CDS initialization or, if CDS is off,
172 // from metaspace initialization. Reserves space for class space + CDS, attempts to reserve such that
173 // we later can use a "good" encoding scheme. Reservation is highly CPU-specific.
174 // 5) Initialize the narrow Klass encoding scheme by determining encoding base and shift:
175 // 5a) if CDS=on: Calls initialize_for_given_encoding() with the reservation base from step (4) and the
176 // CDS-intrinsic setting for shift; here, we don't have any freedom to deviate from the base.
177 // 5b) if CDS=off: Calls initialize() - here, we have more freedom and, if we want, can choose an encoding
178 // base that differs from the reservation base from step (4). That allows us, e.g., to later use
179 // zero-based encoding.
180 // 6) ... from now on, we can use base() and shift().
181
182 // Called right after argument parsing; defines narrow klass pointer geometry limits
183 static void pre_initialize();
184
185 // The number of bits a narrow Klass pointer has;
186 static int narrow_klass_pointer_bits() { check_init(_narrow_klass_pointer_bits); return _narrow_klass_pointer_bits; }
187
188 // The maximum possible shift; the actual shift employed later can be smaller (see initialize())
189 static int max_shift() { check_init(_max_shift); return _max_shift; }
190
191 // Returns the maximum allowed klass range size. It is calculated from the length of the encoding range
192 // resulting from the current encoding settings (base, shift), capped to a certain max. value.
193 static size_t max_klass_range_size();
194
195 // On 64-bit, we need the class space to confine Klass structures to the encoding range, which is determined
196 // by bit size of narrowKlass IDs and the shift. On 32-bit, we support compressed class pointer only
197 // "pro-forma": narrowKlass have the same size as addresses (32 bits), and therefore the encoding range is
198 // equal to the address space size. Here, we don't need a class space.
199 static constexpr bool needs_class_space() { return LP64_ONLY(true) NOT_LP64(false); }
200
201 // Reserve a range of memory that is to contain Klass strucutures which are referenced by narrow Klass IDs.
202 // If optimize_for_zero_base is true, the implementation will attempt to reserve optimized for zero-based encoding.
203 static char* reserve_address_space_for_compressed_classes(size_t size, bool aslr, bool optimize_for_zero_base);
204
205 // Given a klass range [addr, addr+len) and a given encoding scheme, assert that this scheme covers the range, then
206 // set this encoding scheme. Used by CDS at runtime to re-instate the scheme used to pre-compute klass ids for
207 // archived heap objects. In this case, we don't have the freedom to choose base and shift; they are handed to
208 // us from CDS.
209 // Note: CDS with +UCCP for 32-bit currently unsupported.
210 static void initialize_for_given_encoding(address addr, size_t len, address requested_base, int requested_shift);
211
212 // Given an address range [addr, addr+len) which the encoding is supposed to
|
91 // |//////////|///////////////////////////| |
92 // |///CDS////|////1gb class space////////| ... ... |
93 // |//////////|///////////////////////////| |
94 // | | |
95 // 0x8_0000_0000 0x8_4800_0000 0x9_0000_0000
96 //
97
98 // If compressed klass pointers then use narrowKlass.
99 typedef juint narrowKlass;
100
101 // For UseCompressedClassPointers.
102 class CompressedKlassPointers : public AllStatic {
103 friend class VMStructs;
104 friend class ArchiveBuilder;
105
106 // We use a different narrow Klass pointer geometry depending on
107 // whether we run in standard mode or in compact-object-header-mode.
108
109 // Narrow klass pointer bits for an unshifted narrow Klass pointer.
110 static constexpr int narrow_klass_pointer_bits_noncoh = 32;
111 static constexpr int narrow_klass_pointer_bits_coh = 19;
112
113 // Bit size of a narrowKlass
114 static int _narrow_klass_pointer_bits;
115
116 // The maximum shift values we can use depending on UseCompactObjectHeaders
117 static constexpr int max_shift_noncoh = 3;
118 static constexpr int max_shift_coh = 10;
119
120 // Maximum shift usable
121 static int _max_shift;
122
123 // Encoding Base, Encoding Shift
124 static address _base;
125 static int _shift;
126
127 // Start and end of the Klass Range. Start includes the protection zone if one exists.
128 // Note: guaranteed to be aligned to 1<<shift (klass_alignment_in_bytes)
129 static address _klass_range_start;
130 static address _klass_range_end;
131
171 // 4) call reserve_address_space_for_compressed_classes() either from CDS initialization or, if CDS is off,
172 // from metaspace initialization. Reserves space for class space + CDS, attempts to reserve such that
173 // we later can use a "good" encoding scheme. Reservation is highly CPU-specific.
174 // 5) Initialize the narrow Klass encoding scheme by determining encoding base and shift:
175 // 5a) if CDS=on: Calls initialize_for_given_encoding() with the reservation base from step (4) and the
176 // CDS-intrinsic setting for shift; here, we don't have any freedom to deviate from the base.
177 // 5b) if CDS=off: Calls initialize() - here, we have more freedom and, if we want, can choose an encoding
178 // base that differs from the reservation base from step (4). That allows us, e.g., to later use
179 // zero-based encoding.
180 // 6) ... from now on, we can use base() and shift().
181
182 // Called right after argument parsing; defines narrow klass pointer geometry limits
183 static void pre_initialize();
184
185 // The number of bits a narrow Klass pointer has;
186 static int narrow_klass_pointer_bits() { check_init(_narrow_klass_pointer_bits); return _narrow_klass_pointer_bits; }
187
188 // The maximum possible shift; the actual shift employed later can be smaller (see initialize())
189 static int max_shift() { check_init(_max_shift); return _max_shift; }
190
191 // Returns the maximum encoding range, given the current geometry (narrow klass bit size and shift)
192 static size_t max_encoding_range_size() { return nth_bit(narrow_klass_pointer_bits() + max_shift()); }
193
194 // For use before pre-initialization
195 static constexpr size_t max_klass_range_size_coh = nth_bit(narrow_klass_pointer_bits_coh + max_shift_coh);
196
197 // Returns the maximum allowed klass range size.
198 static size_t max_klass_range_size();
199
200 // On 64-bit, we need the class space to confine Klass structures to the encoding range, which is determined
201 // by bit size of narrowKlass IDs and the shift. On 32-bit, we support compressed class pointer only
202 // "pro-forma": narrowKlass have the same size as addresses (32 bits), and therefore the encoding range is
203 // equal to the address space size. Here, we don't need a class space.
204 static constexpr bool needs_class_space() { return LP64_ONLY(true) NOT_LP64(false); }
205
206 // Reserve a range of memory that is to contain Klass strucutures which are referenced by narrow Klass IDs.
207 // If optimize_for_zero_base is true, the implementation will attempt to reserve optimized for zero-based encoding.
208 static char* reserve_address_space_for_compressed_classes(size_t size, bool aslr, bool optimize_for_zero_base);
209
210 // Given a klass range [addr, addr+len) and a given encoding scheme, assert that this scheme covers the range, then
211 // set this encoding scheme. Used by CDS at runtime to re-instate the scheme used to pre-compute klass ids for
212 // archived heap objects. In this case, we don't have the freedom to choose base and shift; they are handed to
213 // us from CDS.
214 // Note: CDS with +UCCP for 32-bit currently unsupported.
215 static void initialize_for_given_encoding(address addr, size_t len, address requested_base, int requested_shift);
216
217 // Given an address range [addr, addr+len) which the encoding is supposed to
|