mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
6541756: Reduce executable C-heap
Add executable parameters to reserve_memory and commit_memory to reduce executable memory to only the Code Heap. Reviewed-by: xlu, kvn, acorn
This commit is contained in:
parent
472349069b
commit
cec3a034d1
7 changed files with 122 additions and 58 deletions
|
@ -28,7 +28,7 @@
|
|||
|
||||
// ReservedSpace
|
||||
ReservedSpace::ReservedSpace(size_t size) {
|
||||
initialize(size, 0, false, NULL, 0);
|
||||
initialize(size, 0, false, NULL, 0, false);
|
||||
}
|
||||
|
||||
ReservedSpace::ReservedSpace(size_t size, size_t alignment,
|
||||
|
@ -36,7 +36,13 @@ ReservedSpace::ReservedSpace(size_t size, size_t alignment,
|
|||
char* requested_address,
|
||||
const size_t noaccess_prefix) {
|
||||
initialize(size+noaccess_prefix, alignment, large, requested_address,
|
||||
noaccess_prefix);
|
||||
noaccess_prefix, false);
|
||||
}
|
||||
|
||||
ReservedSpace::ReservedSpace(size_t size, size_t alignment,
|
||||
bool large,
|
||||
bool executable) {
|
||||
initialize(size, alignment, large, NULL, 0, executable);
|
||||
}
|
||||
|
||||
char *
|
||||
|
@ -132,7 +138,8 @@ ReservedSpace::ReservedSpace(const size_t prefix_size,
|
|||
const bool try_reserve_special = UseLargePages &&
|
||||
prefix_align == os::large_page_size();
|
||||
if (!os::can_commit_large_page_memory() && try_reserve_special) {
|
||||
initialize(size, prefix_align, true, requested_address, noaccess_prefix);
|
||||
initialize(size, prefix_align, true, requested_address, noaccess_prefix,
|
||||
false);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -141,6 +148,7 @@ ReservedSpace::ReservedSpace(const size_t prefix_size,
|
|||
_alignment = 0;
|
||||
_special = false;
|
||||
_noaccess_prefix = 0;
|
||||
_executable = false;
|
||||
|
||||
// Assert that if noaccess_prefix is used, it is the same as prefix_align.
|
||||
assert(noaccess_prefix == 0 ||
|
||||
|
@ -189,7 +197,8 @@ ReservedSpace::ReservedSpace(const size_t prefix_size,
|
|||
|
||||
void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
|
||||
char* requested_address,
|
||||
const size_t noaccess_prefix) {
|
||||
const size_t noaccess_prefix,
|
||||
bool executable) {
|
||||
const size_t granularity = os::vm_allocation_granularity();
|
||||
assert((size & granularity - 1) == 0,
|
||||
"size not aligned to os::vm_allocation_granularity()");
|
||||
|
@ -201,6 +210,7 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
|
|||
_base = NULL;
|
||||
_size = 0;
|
||||
_special = false;
|
||||
_executable = executable;
|
||||
_alignment = 0;
|
||||
_noaccess_prefix = 0;
|
||||
if (size == 0) {
|
||||
|
@ -214,7 +224,7 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
|
|||
|
||||
if (special) {
|
||||
|
||||
base = os::reserve_memory_special(size, requested_address);
|
||||
base = os::reserve_memory_special(size, requested_address, executable);
|
||||
|
||||
if (base != NULL) {
|
||||
// Check alignment constraints
|
||||
|
@ -284,7 +294,7 @@ void ReservedSpace::initialize(size_t size, size_t alignment, bool large,
|
|||
|
||||
|
||||
ReservedSpace::ReservedSpace(char* base, size_t size, size_t alignment,
|
||||
bool special) {
|
||||
bool special, bool executable) {
|
||||
assert((size % os::vm_allocation_granularity()) == 0,
|
||||
"size not allocation aligned");
|
||||
_base = base;
|
||||
|
@ -292,6 +302,7 @@ ReservedSpace::ReservedSpace(char* base, size_t size, size_t alignment,
|
|||
_alignment = alignment;
|
||||
_noaccess_prefix = 0;
|
||||
_special = special;
|
||||
_executable = executable;
|
||||
}
|
||||
|
||||
|
||||
|
@ -299,9 +310,10 @@ ReservedSpace ReservedSpace::first_part(size_t partition_size, size_t alignment,
|
|||
bool split, bool realloc) {
|
||||
assert(partition_size <= size(), "partition failed");
|
||||
if (split) {
|
||||
os::split_reserved_memory(_base, _size, partition_size, realloc);
|
||||
os::split_reserved_memory(base(), size(), partition_size, realloc);
|
||||
}
|
||||
ReservedSpace result(base(), partition_size, alignment, special());
|
||||
ReservedSpace result(base(), partition_size, alignment, special(),
|
||||
executable());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -310,7 +322,7 @@ ReservedSpace
|
|||
ReservedSpace::last_part(size_t partition_size, size_t alignment) {
|
||||
assert(partition_size <= size(), "partition failed");
|
||||
ReservedSpace result(base() + partition_size, size() - partition_size,
|
||||
alignment, special());
|
||||
alignment, special(), executable());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -348,6 +360,7 @@ void ReservedSpace::release() {
|
|||
_size = 0;
|
||||
_noaccess_prefix = 0;
|
||||
_special = false;
|
||||
_executable = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -396,6 +409,14 @@ ReservedHeapSpace::ReservedHeapSpace(const size_t prefix_size,
|
|||
protect_noaccess_prefix(prefix_size+suffix_size);
|
||||
}
|
||||
|
||||
// Reserve space for code segment. Same as Java heap only we mark this as
|
||||
// executable.
|
||||
ReservedCodeSpace::ReservedCodeSpace(size_t r_size,
|
||||
size_t rs_align,
|
||||
bool large) :
|
||||
ReservedSpace(r_size, rs_align, large, /*executable*/ true) {
|
||||
}
|
||||
|
||||
// VirtualSpace
|
||||
|
||||
VirtualSpace::VirtualSpace() {
|
||||
|
@ -413,6 +434,7 @@ VirtualSpace::VirtualSpace() {
|
|||
_middle_alignment = 0;
|
||||
_upper_alignment = 0;
|
||||
_special = false;
|
||||
_executable = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -426,6 +448,7 @@ bool VirtualSpace::initialize(ReservedSpace rs, size_t committed_size) {
|
|||
_high = low();
|
||||
|
||||
_special = rs.special();
|
||||
_executable = rs.executable();
|
||||
|
||||
// When a VirtualSpace begins life at a large size, make all future expansion
|
||||
// and shrinking occur aligned to a granularity of large pages. This avoids
|
||||
|
@ -483,6 +506,7 @@ void VirtualSpace::release() {
|
|||
_middle_alignment = 0;
|
||||
_upper_alignment = 0;
|
||||
_special = false;
|
||||
_executable = false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -592,7 +616,7 @@ bool VirtualSpace::expand_by(size_t bytes, bool pre_touch) {
|
|||
assert(low_boundary() <= lower_high() &&
|
||||
lower_high() + lower_needs <= lower_high_boundary(),
|
||||
"must not expand beyond region");
|
||||
if (!os::commit_memory(lower_high(), lower_needs)) {
|
||||
if (!os::commit_memory(lower_high(), lower_needs, _executable)) {
|
||||
debug_only(warning("os::commit_memory failed"));
|
||||
return false;
|
||||
} else {
|
||||
|
@ -603,7 +627,8 @@ bool VirtualSpace::expand_by(size_t bytes, bool pre_touch) {
|
|||
assert(lower_high_boundary() <= middle_high() &&
|
||||
middle_high() + middle_needs <= middle_high_boundary(),
|
||||
"must not expand beyond region");
|
||||
if (!os::commit_memory(middle_high(), middle_needs, middle_alignment())) {
|
||||
if (!os::commit_memory(middle_high(), middle_needs, middle_alignment(),
|
||||
_executable)) {
|
||||
debug_only(warning("os::commit_memory failed"));
|
||||
return false;
|
||||
}
|
||||
|
@ -613,7 +638,7 @@ bool VirtualSpace::expand_by(size_t bytes, bool pre_touch) {
|
|||
assert(middle_high_boundary() <= upper_high() &&
|
||||
upper_high() + upper_needs <= upper_high_boundary(),
|
||||
"must not expand beyond region");
|
||||
if (!os::commit_memory(upper_high(), upper_needs)) {
|
||||
if (!os::commit_memory(upper_high(), upper_needs, _executable)) {
|
||||
debug_only(warning("os::commit_memory failed"));
|
||||
return false;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue