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