[tools] Add an API that exposes the location of builtins.

We have an API (GetCodeRange) which gives the location of V8 code on the
heap, but builtin code no longer lives on the heap.

The upcoming work on the V8 stack unwinder requires the embedder to
provide the code ranges for both the heap and builtins, so this API will
be used there.

Bug: v8:8116
Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng
Change-Id: I15e900716e68256b9732be0ea1a5cda24878eccf
Reviewed-on: https://chromium-review.googlesource.com/1196551
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55532}
This commit is contained in:
Peter Marshall 2018-08-30 16:23:30 +02:00 committed by Commit Bot
parent 038ce6aa9c
commit 2d62067879
3 changed files with 48 additions and 1 deletions

View File

@ -1945,6 +1945,11 @@ struct SampleInfo {
// executing an external callback.
};
struct MemoryRange {
const void* start;
size_t length_in_bytes;
};
/**
* A JSON Parser and Stringifier.
*/
@ -8156,7 +8161,9 @@ class V8_EXPORT Isolate {
void SetStackLimit(uintptr_t stack_limit);
/**
* Returns a memory range that can potentially contain jitted code.
* Returns a memory range that can potentially contain jitted code. Code for
* V8's 'builtins' will not be in this range if embedded builtins is enabled.
* Instead, see GetBuiltinsCodeRange.
*
* On Win64, embedders are advised to install function table callbacks for
* these ranges, as default SEH won't be able to unwind through jitted code.
@ -8170,6 +8177,15 @@ class V8_EXPORT Isolate {
*/
void GetCodeRange(void** start, size_t* length_in_bytes);
/**
* Returns a memory range containing the code for V8's builtin functions
* which are shared across isolates.
*
* If embedded builtins are disabled, then the memory range will be a null
* pointer with 0 length.
*/
MemoryRange GetBuiltinsCodeRange();
/** Set the callback to invoke in case of fatal errors. */
void SetFatalErrorHandler(FatalErrorCallback that);

View File

@ -8709,6 +8709,11 @@ void Isolate::GetCodeRange(void** start, size_t* length_in_bytes) {
}
}
MemoryRange Isolate::GetBuiltinsCodeRange() {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
return {reinterpret_cast<const void*>(isolate->embedded_blob()),
isolate->embedded_blob_size()};
}
#define CALLBACK_SETTER(ExternalName, Type, InternalName) \
void Isolate::Set##ExternalName(Type callback) { \

View File

@ -28761,3 +28761,29 @@ TEST(TestSetWasmThreadsEnabledCallback) {
i::FLAG_experimental_wasm_threads = false;
CHECK(i_isolate->AreWasmThreadsEnabled(i_context));
}
TEST(TestGetBuiltinsCodeRange) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
v8::MemoryRange builtins_range = isolate->GetBuiltinsCodeRange();
// Check that each off-heap builtin is within the builtins code range.
if (i::FLAG_embedded_builtins) {
for (int id = 0; id < i::Builtins::builtin_count; id++) {
if (!i::Builtins::IsIsolateIndependent(id)) continue;
i::Code* builtin = i_isolate->builtins()->builtin(id);
i::Address start = builtin->InstructionStart();
i::Address end = start + builtin->InstructionSize();
i::Address builtins_start =
reinterpret_cast<i::Address>(builtins_range.start);
CHECK(start >= builtins_start &&
end < builtins_start + builtins_range.length_in_bytes);
}
} else {
CHECK_EQ(nullptr, builtins_range.start);
CHECK_EQ(0, builtins_range.length_in_bytes);
}
}