Commit 0996db8b authored by Igor Sheludko's avatar Igor Sheludko Committed by V8 LUCI CQ

[ext-code-space] Allocate external code space near embedded builtins

Bug: v8:11880
Change-Id: I9a936c293e261142111e235c041e3526680d9629
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3240828Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77519}
parent 4b437bee
......@@ -104,7 +104,8 @@ STATIC_ASSERT(V8_DEFAULT_STACK_SIZE_KB* KB +
kStackLimitSlackForDeoptimizationInBytes <=
MB);
#if defined(V8_SHORT_BUILTIN_CALLS) && !defined(V8_COMPRESS_POINTERS)
#if defined(V8_SHORT_BUILTIN_CALLS) && \
(!defined(V8_COMPRESS_POINTERS) || defined(V8_EXTERNAL_CODE_SPACE))
#define V8_ENABLE_NEAR_CODE_RANGE_BOOL true
#else
#define V8_ENABLE_NEAR_CODE_RANGE_BOOL false
......
......@@ -364,10 +364,13 @@ uint32_t Isolate::CurrentEmbeddedBlobDataSize() {
}
base::AddressRegion Isolate::GetShortBuiltinsCallRegion() {
DCHECK(V8_ENABLE_NEAR_CODE_RANGE_BOOL);
DCHECK_LT(CurrentEmbeddedBlobCodeSize(), kShortBuiltinCallsBoundary);
Address embedded_blob_code_start =
reinterpret_cast<Address>(CurrentEmbeddedBlobCode());
if (embedded_blob_code_start == kNullAddress) {
// Return empty region if there's no embedded blob.
return base::AddressRegion(kNullAddress, 0);
}
Address embedded_blob_code_end =
embedded_blob_code_start + CurrentEmbeddedBlobCodeSize();
Address region_start =
......
......@@ -1627,6 +1627,8 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
return V8_SHORT_BUILTIN_CALLS_BOOL && is_short_builtin_calls_enabled_;
}
// Returns a region from which it's possible to make short calls/jumps to
// embedded builtins or empty region if there's no embedded blob.
static base::AddressRegion GetShortBuiltinsCallRegion();
void set_array_buffer_allocator(v8::ArrayBuffer::Allocator* allocator) {
......
......@@ -35,16 +35,19 @@ Address CodeRangeAddressHint::GetAddressHint(size_t code_range_size,
size_t alignment) {
base::MutexGuard guard(&mutex_);
// Try to allocate code range in the preferred region where we can use
// short instructions for calling/jumping to embedded builtins.
base::AddressRegion preferred_region = Isolate::GetShortBuiltinsCallRegion();
Address result = 0;
auto it = recently_freed_.find(code_range_size);
// No recently freed region has been found, try to provide a hint for placing
// a code region
// a code region.
if (it == recently_freed_.end() || it->second.empty()) {
if (V8_ENABLE_NEAR_CODE_RANGE_BOOL) {
base::AddressRegion region = Isolate::GetShortBuiltinsCallRegion();
DCHECK_LT(region.begin(), region.end());
if (V8_ENABLE_NEAR_CODE_RANGE_BOOL && !preferred_region.is_empty()) {
auto memory_ranges = base::OS::GetFreeMemoryRangesWithin(
region.begin(), region.end(), code_range_size, alignment);
preferred_region.begin(), preferred_region.end(), code_range_size,
alignment);
if (!memory_ranges.empty()) {
result = memory_ranges.front().start;
CHECK(IsAligned(result, alignment));
......@@ -56,13 +59,12 @@ Address CodeRangeAddressHint::GetAddressHint(size_t code_range_size,
}
// Try to reuse near code range first.
if (V8_ENABLE_NEAR_CODE_RANGE_BOOL) {
base::AddressRegion region = Isolate::GetShortBuiltinsCallRegion();
if (V8_ENABLE_NEAR_CODE_RANGE_BOOL && !preferred_region.is_empty()) {
auto freed_regions_for_size = it->second;
for (auto it_freed = freed_regions_for_size.rbegin();
it_freed != freed_regions_for_size.rend(); ++it_freed) {
Address code_range_start = *it_freed;
if (region.contains(code_range_start, code_range_size)) {
if (preferred_region.contains(code_range_start, code_range_size)) {
CHECK(IsAligned(code_range_start, alignment));
freed_regions_for_size.erase((it_freed + 1).base());
return code_range_start;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment