32 #include "oops/compressedOops.hpp"
33 #include "gc/shared/collectedHeap.hpp"
34 #include "runtime/arguments.hpp"
35 #include "runtime/globals.hpp"
36
37 // For UseCompressedOops.
38 address CompressedOops::_base = nullptr;
39 int CompressedOops::_shift = 0;
40 bool CompressedOops::_use_implicit_null_checks = true;
41 MemRegion CompressedOops::_heap_address_range;
42
43 // Choose the heap base address and oop encoding mode
44 // when compressed oops are used:
45 // Unscaled - Use 32-bits oops without encoding when
46 // NarrowOopHeapBaseMin + heap_size < 4Gb
47 // ZeroBased - Use zero based compressed oops with encoding when
48 // NarrowOopHeapBaseMin + heap_size < 32Gb
49 // HeapBased - Use compressed oops with heap base + encoding.
50 void CompressedOops::initialize(const ReservedHeapSpace& heap_space) {
51 #ifdef _LP64
52 // Subtract a page because something can get allocated at heap base.
53 // This also makes implicit null checking work, because the
54 // memory+1 page below heap_base needs to cause a signal.
55 // See needs_explicit_null_check.
56 // Only set the heap base for compressed oops because it indicates
57 // compressed oops for pstack code.
58 if ((uint64_t)heap_space.end() > UnscaledOopHeapMax) {
59 // Didn't reserve heap below 4Gb. Must shift.
60 set_shift(LogMinObjAlignmentInBytes);
61 }
62 if ((uint64_t)heap_space.end() <= OopEncodingHeapMax) {
63 // Did reserve heap below 32Gb. Can use base == 0;
64 set_base(nullptr);
65 } else {
66 set_base((address)heap_space.compressed_oop_base());
67 }
68
69 _heap_address_range = heap_space.region();
70
71 LogTarget(Debug, gc, heap, coops) lt;
72 if (lt.is_enabled()) {
73 ResourceMark rm;
74 LogStream ls(lt);
75 print_mode(&ls);
76 }
77
78 // Tell tests in which mode we run.
79 Arguments::PropertyList_add(new SystemProperty("java.vm.compressedOopsMode",
80 mode_to_string(mode()),
81 false));
82
83 // base() is one page below the heap.
84 assert((intptr_t)base() <= ((intptr_t)_heap_address_range.start() - (intptr_t)os::vm_page_size()) ||
85 base() == nullptr, "invalid value");
86 assert(shift() == LogMinObjAlignmentInBytes ||
87 shift() == 0, "invalid value");
|
32 #include "oops/compressedOops.hpp"
33 #include "gc/shared/collectedHeap.hpp"
34 #include "runtime/arguments.hpp"
35 #include "runtime/globals.hpp"
36
37 // For UseCompressedOops.
38 address CompressedOops::_base = nullptr;
39 int CompressedOops::_shift = 0;
40 bool CompressedOops::_use_implicit_null_checks = true;
41 MemRegion CompressedOops::_heap_address_range;
42
43 // Choose the heap base address and oop encoding mode
44 // when compressed oops are used:
45 // Unscaled - Use 32-bits oops without encoding when
46 // NarrowOopHeapBaseMin + heap_size < 4Gb
47 // ZeroBased - Use zero based compressed oops with encoding when
48 // NarrowOopHeapBaseMin + heap_size < 32Gb
49 // HeapBased - Use compressed oops with heap base + encoding.
50 void CompressedOops::initialize(const ReservedHeapSpace& heap_space) {
51 #ifdef _LP64
52 if (UseCompatibleCompressedOops) {
53 set_shift(LogMinObjAlignmentInBytes);
54 set_base((address)heap_space.compressed_oop_base());
55 } else {
56 // Subtract a page because something can get allocated at heap base.
57 // This also makes implicit null checking work, because the
58 // memory+1 page below heap_base needs to cause a signal.
59 // See needs_explicit_null_check.
60 // Only set the heap base for compressed oops because it indicates
61 // compressed oops for pstack code.
62 if ((uint64_t)heap_space.end() > UnscaledOopHeapMax) {
63 // Didn't reserve heap below 4Gb. Must shift.
64 set_shift(LogMinObjAlignmentInBytes);
65 }
66 if ((uint64_t)heap_space.end() <= OopEncodingHeapMax) {
67 // Did reserve heap below 32Gb. Can use base == 0;
68 set_base(nullptr);
69 } else {
70 set_base((address)heap_space.compressed_oop_base());
71 }
72 }
73
74 _heap_address_range = heap_space.region();
75
76 LogTarget(Debug, gc, heap, coops) lt;
77 if (lt.is_enabled()) {
78 ResourceMark rm;
79 LogStream ls(lt);
80 print_mode(&ls);
81 }
82
83 // Tell tests in which mode we run.
84 Arguments::PropertyList_add(new SystemProperty("java.vm.compressedOopsMode",
85 mode_to_string(mode()),
86 false));
87
88 // base() is one page below the heap.
89 assert((intptr_t)base() <= ((intptr_t)_heap_address_range.start() - (intptr_t)os::vm_page_size()) ||
90 base() == nullptr, "invalid value");
91 assert(shift() == LogMinObjAlignmentInBytes ||
92 shift() == 0, "invalid value");
|