3131class outputStream ;
3232class Klass ;
3333
34+ // Narrow Klass Encoding
35+ //
36+ // Klass Range:
37+ // a contiguous memory range into which we place Klass that should be encodable. Not every Klass
38+ // needs to be encodable. There is only one such memory range.
39+ // If CDS is disabled, this Klass Range is the same as the metaspace class space. If CDS is enabled, the
40+ // Klass Range contains both CDS and class space adjacent to each other (with a potential small
41+ // unused alignment gap between them).
42+ //
43+ // Encoding Range:
44+ // This is the range covered by the current encoding scheme. The encoding scheme is defined by
45+ // the encoding base, encoding shift and (implicitly) the bit size of the narrowKlass. The
46+ // Encoding Range is:
47+ // [ <encoding base> ... <encoding base> + (1 << (<narrowKlass-bitsize> + <shift>) )
48+ //
49+ // Note that while the Klass Range must be contained within the Encoding Range, the Encoding Range
50+ // is typically a lot larger than the Klass Range:
51+ // - the encoding base can start before the Klass Range start (specifically, it can start at 0 for
52+ // zero-based encoding)
53+ // - the end of the Encoding Range usually extends far beyond the end of the Klass Range.
54+ //
55+ //
56+ // Examples:
57+ //
58+ // "unscaled" (zero-based zero-shift) encoding, CDS off, class space of 1G starts at 0x4B00_0000:
59+ // - Encoding Range: [0 .. 0x1_0000_0000 ) (4 GB)
60+ // - Klass Range: [0x4B00_0000 .. 0x 8B00_0000 ) (1 GB)
61+ //
62+ //
63+ // _base _klass_range_start _klass_range_end encoding end
64+ // | |//////////////////////////////| |
65+ // | ... |///////1gb class space////////| ... |
66+ // | |//////////////////////////////| |
67+ // 0x0 0x4B00_0000 0x8B00_0000 0x1_0000_0000
68+ //
69+ //
70+ //
71+ // "zero-based" (but scaled) encoding, shift=3, CDS off, 1G Class space at 0x7_C000_0000 (31GB):
72+ // - Encoding Range: [0 .. 0x8_0000_0000 ) (32 GB)
73+ // - Klass Range: [0x7_C000_0000 .. 0x8_0000_0000 ) (1 GB)
74+ //
75+ // encoding end
76+ // _base _klass_range_start _klass_range_end
77+ // | |//////////////////////////////|
78+ // | ... |///////1gb class space////////|
79+ // | |//////////////////////////////|
80+ // 0x0 0x7_C000_0000 0x8_0000_0000
81+ //
82+ //
83+ // CDS enabled, 128MB CDS region starts 0x8_0000_0000, followed by a 1GB class space. Encoding
84+ // base will point to CDS region start, shift=0:
85+ // - Encoding Range: [0x8_0000_0000 .. 0x9_0000_0000 ) (4 GB)
86+ // - Klass Range: [0x8_0000_0000 .. 0x8_4800_0000 ) (128 MB + 1 GB)
87+ //
88+ // _base
89+ // _klass_range_start _klass_range_end encoding end
90+ // |//////////|///////////////////////////| |
91+ // |///CDS////|////1gb class space////////| ... ... |
92+ // |//////////|///////////////////////////| |
93+ // | | |
94+ // 0x8_0000_0000 0x8_4800_0000 0x9_0000_0000
95+ //
96+
3497// If compressed klass pointers then use narrowKlass.
3598typedef juint narrowKlass;
3699
@@ -50,12 +113,10 @@ class CompressedKlassPointers : public AllStatic {
50113 static address _base;
51114 static int _shift;
52115
53- // Together with base, this defines the address range within which Klass
54- // structures will be located: [base, base+range). While the maximal
55- // possible encoding range is 4|32G for shift 0|3, if we know beforehand
56- // the expected range of Klass* pointers will be smaller, a platform
57- // could use this info to optimize encoding.
58- static size_t _range;
116+ // Start and end of the Klass Range.
117+ // Note: guaranteed to be aligned to KlassAlignmentInBytes
118+ static address _klass_range_start;
119+ static address _klass_range_end;
59120
60121 // Helper function for common cases.
61122 static char * reserve_address_space_X (uintptr_t from, uintptr_t to, size_t size, size_t alignment, bool aslr);
@@ -92,9 +153,13 @@ class CompressedKlassPointers : public AllStatic {
92153 static void print_mode (outputStream* st);
93154
94155 static address base () { return _base; }
95- static size_t range () { return _range; }
96156 static int shift () { return _shift; }
97157
158+ static address klass_range_start () { return _klass_range_start; }
159+ static address klass_range_end () { return _klass_range_end; }
160+
161+ static inline address encoding_range_end ();
162+
98163 static bool is_null (Klass* v) { return v == nullptr ; }
99164 static bool is_null (narrowKlass v) { return v == 0 ; }
100165
@@ -110,14 +175,9 @@ class CompressedKlassPointers : public AllStatic {
110175
111176 // Returns whether the pointer is in the memory region used for encoding compressed
112177 // class pointers. This includes CDS.
113-
114- // encoding encoding
115- // base end (base+range)
116- // |-----------------------------------------------------------------------|
117- // |----CDS---| |--------------------class space---------------------------|
118-
119- static inline bool is_in_encoding_range (const void * p) {
120- return p >= _base && p < (_base + _range);
178+ static inline bool is_encodable (const void * p) {
179+ return (address) p >= _klass_range_start &&
180+ (address) p < _klass_range_end;
121181 }
122182};
123183
0 commit comments