Commit 6d21451b authored by Irina Yatsenko's avatar Irina Yatsenko Committed by Commit Bot

Add crash keys via a callback to the embedder that created the isolate.

This allows us to keep v8 free of the dependency on the crash/base components.
Second half of the change: https://chromium-review.googlesource.com/c/chromium/src/+/1690003.


Bug: v8:9323
Change-Id: If35288e3916df951ae6e2ae39e1cb06fab5fbf8c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1699102
Commit-Queue: Irina Yatsenko <irinayat@microsoft.com>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63177}
parent e6d8bdfa
......@@ -439,14 +439,6 @@ class Platform {
*/
virtual void DumpWithoutCrashing() {}
/**
* Lets the embedder to add crash keys.
*/
virtual void AddCrashKey(int id, const char* name, uintptr_t value) {
// "noop" is a valid implementation if the embedder doesn't care to log
// additional data for crashes.
}
protected:
/**
* Default implementation of current wall-clock time in milliseconds
......
......@@ -6644,6 +6644,16 @@ typedef void* (*CreateHistogramCallback)(const char* name,
typedef void (*AddHistogramSampleCallback)(void* histogram, int sample);
// --- Crashkeys Callback ---
enum class CrashKeyId {
kIsolateAddress,
kReadonlySpaceFirstPageAddress,
kMapSpaceFirstPageAddress,
kCodeSpaceFirstPageAddress,
};
typedef void (*AddCrashKeyCallback)(CrashKeyId id, const std::string& value);
// --- Enter/Leave Script Callback ---
typedef void (*BeforeCallEnteredCallback)(Isolate*);
typedef void (*CallCompletedCallback)(Isolate*);
......@@ -8358,6 +8368,13 @@ class V8_EXPORT Isolate {
void SetCreateHistogramFunction(CreateHistogramCallback);
void SetAddHistogramSampleFunction(AddHistogramSampleCallback);
/**
* Enables the host application to provide a mechanism for recording a
* predefined set of data as crash keys to be used in postmortem debugging in
* case of a crash.
*/
void SetAddCrashKeyCallback(AddCrashKeyCallback);
/**
* Optional notification that the embedder is idle.
* V8 uses the notification to perform garbage collection.
......
......@@ -8359,6 +8359,11 @@ void Isolate::SetAddHistogramSampleFunction(
->SetAddHistogramSampleFunction(callback);
}
void Isolate::SetAddCrashKeyCallback(AddCrashKeyCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->SetAddCrashKeyCallback(callback);
}
bool Isolate::IdleNotificationDeadline(double deadline_in_seconds) {
// Returning true tells the caller that it need not
// continue to call IdleNotification.
......
......@@ -3309,19 +3309,31 @@ bool Isolate::InitWithSnapshot(ReadOnlyDeserializer* read_only_deserializer,
return Init(read_only_deserializer, startup_deserializer);
}
static void AddCrashKeysForIsolateAndHeapPointers(Isolate* isolate) {
v8::Platform* platform = V8::GetCurrentPlatform();
static std::string AddressToString(uintptr_t address) {
std::stringstream stream_address;
stream_address << "0x" << std::hex << address;
return stream_address.str();
}
void Isolate::AddCrashKeysForIsolateAndHeapPointers() {
DCHECK_NOT_NULL(add_crash_key_callback_);
const int id = isolate->id();
platform->AddCrashKey(id, "isolate", reinterpret_cast<uintptr_t>(isolate));
const uintptr_t isolate_address = reinterpret_cast<uintptr_t>(this);
add_crash_key_callback_(v8::CrashKeyId::kIsolateAddress,
AddressToString(isolate_address));
auto heap = isolate->heap();
platform->AddCrashKey(id, "ro_space",
reinterpret_cast<uintptr_t>(heap->read_only_space()->first_page()));
platform->AddCrashKey(id, "map_space",
reinterpret_cast<uintptr_t>(heap->map_space()->first_page()));
platform->AddCrashKey(id, "code_space",
reinterpret_cast<uintptr_t>(heap->code_space()->first_page()));
const uintptr_t ro_space_firstpage_address =
reinterpret_cast<uintptr_t>(heap()->read_only_space()->first_page());
add_crash_key_callback_(v8::CrashKeyId::kReadonlySpaceFirstPageAddress,
AddressToString(ro_space_firstpage_address));
const uintptr_t map_space_firstpage_address =
reinterpret_cast<uintptr_t>(heap()->map_space()->first_page());
add_crash_key_callback_(v8::CrashKeyId::kMapSpaceFirstPageAddress,
AddressToString(map_space_firstpage_address));
const uintptr_t code_space_firstpage_address =
reinterpret_cast<uintptr_t>(heap()->code_space()->first_page());
add_crash_key_callback_(v8::CrashKeyId::kCodeSpaceFirstPageAddress,
AddressToString(code_space_firstpage_address));
}
bool Isolate::Init(ReadOnlyDeserializer* read_only_deserializer,
......@@ -3569,7 +3581,6 @@ bool Isolate::Init(ReadOnlyDeserializer* read_only_deserializer,
PrintF("[Initializing isolate from scratch took %0.3f ms]\n", ms);
}
AddCrashKeysForIsolateAndHeapPointers(this);
return true;
}
......@@ -4429,6 +4440,13 @@ bool Isolate::HasPrepareStackTraceCallback() const {
return prepare_stack_trace_callback_ != nullptr;
}
void Isolate::SetAddCrashKeyCallback(AddCrashKeyCallback callback) {
add_crash_key_callback_ = callback;
// Log the initial set of data.
AddCrashKeysForIsolateAndHeapPointers();
}
void Isolate::SetAtomicsWaitCallback(v8::Isolate::AtomicsWaitCallback callback,
void* data) {
atomics_wait_callback_ = callback;
......
......@@ -1514,6 +1514,8 @@ class Isolate final : private HiddenFactory {
Handle<JSArray> sites);
bool HasPrepareStackTraceCallback() const;
void SetAddCrashKeyCallback(AddCrashKeyCallback callback);
void SetRAILMode(RAILMode rail_mode);
RAILMode rail_mode() { return rail_mode_.load(); }
......@@ -1658,6 +1660,8 @@ class Isolate final : private HiddenFactory {
return "";
}
void AddCrashKeysForIsolateAndHeapPointers();
// This class contains a collection of data accessible from both C++ runtime
// and compiled code (including assembly stubs, builtins, interpreter bytecode
// handlers and optimized code).
......@@ -1883,6 +1887,11 @@ class Isolate final : private HiddenFactory {
base::Mutex thread_data_table_mutex_;
ThreadDataTable thread_data_table_;
// Enables the host application to provide a mechanism for recording a
// predefined set of data as crash keys to be used in postmortem debugging
// in case of a crash.
AddCrashKeyCallback add_crash_key_callback_ = nullptr;
// Delete new/delete operators to ensure that Isolate::New() and
// Isolate::Delete() are used for Isolate creation and deletion.
void* operator new(size_t, void* ptr) { return ptr; }
......
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