[heap] Add instrumentation to GcSafeFindCodeForInnerPointer

... in order to ease issues debugging.

Bug: chromium:1241665
Change-Id: I3b51d3eaaa9c03cfadbdadc4e91dee35617f4b33
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3293090
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Reviewed-by: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77999}
This commit is contained in:
Igor Sheludko 2021-11-19 18:10:36 +01:00 committed by V8 LUCI CQ
parent c201bb0909
commit 4dab3a31f7
3 changed files with 44 additions and 19 deletions

View File

@ -608,7 +608,17 @@ Handle<String> Isolate::StackTraceString() {
void Isolate::PushStackTraceAndDie(void* ptr1, void* ptr2, void* ptr3,
void* ptr4) {
StackTraceFailureMessage message(this, ptr1, ptr2, ptr3, ptr4);
StackTraceFailureMessage message(this,
StackTraceFailureMessage::kIncludeStackTrace,
ptr1, ptr2, ptr3, ptr4);
message.Print();
base::OS::Abort();
}
void Isolate::PushParamsAndDie(void* ptr1, void* ptr2, void* ptr3, void* ptr4) {
StackTraceFailureMessage message(
this, StackTraceFailureMessage::kDontIncludeStackTrace, ptr1, ptr2, ptr3,
ptr4);
message.Print();
base::OS::Abort();
}
@ -617,14 +627,14 @@ void StackTraceFailureMessage::Print() volatile {
// Print the details of this failure message object, including its own address
// to force stack allocation.
base::OS::PrintError(
"Stacktrace:\n ptr1=%p\n ptr2=%p\n ptr3=%p\n ptr4=%p\n "
"Stacktrace:\n ptr1=%p\n ptr2=%p\n ptr3=%p\n ptr4=%p\n "
"failure_message_object=%p\n%s",
ptr1_, ptr2_, ptr3_, ptr4_, this, &js_stack_trace_[0]);
}
StackTraceFailureMessage::StackTraceFailureMessage(Isolate* isolate, void* ptr1,
void* ptr2, void* ptr3,
void* ptr4) {
StackTraceFailureMessage::StackTraceFailureMessage(
Isolate* isolate, StackTraceFailureMessage::StackTraceMode mode, void* ptr1,
void* ptr2, void* ptr3, void* ptr4) {
isolate_ = isolate;
ptr1_ = ptr1;
ptr2_ = ptr2;
@ -633,17 +643,20 @@ StackTraceFailureMessage::StackTraceFailureMessage(Isolate* isolate, void* ptr1,
// Write a stracktrace into the {js_stack_trace_} buffer.
const size_t buffer_length = arraysize(js_stack_trace_);
memset(&js_stack_trace_, 0, buffer_length);
FixedStringAllocator fixed(&js_stack_trace_[0], buffer_length - 1);
StringStream accumulator(&fixed, StringStream::kPrintObjectConcise);
isolate->PrintStack(&accumulator, Isolate::kPrintStackVerbose);
// Keeping a reference to the last code objects to increase likelyhood that
// they get included in the minidump.
const size_t code_objects_length = arraysize(code_objects_);
size_t i = 0;
StackFrameIterator it(isolate);
for (; !it.done() && i < code_objects_length; it.Advance()) {
code_objects_[i++] =
reinterpret_cast<void*>(it.frame()->unchecked_code().ptr());
memset(&code_objects_, 0, sizeof(code_objects_));
if (mode == kIncludeStackTrace) {
FixedStringAllocator fixed(&js_stack_trace_[0], buffer_length - 1);
StringStream accumulator(&fixed, StringStream::kPrintObjectConcise);
isolate->PrintStack(&accumulator, Isolate::kPrintStackVerbose);
// Keeping a reference to the last code objects to increase likelyhood that
// they get included in the minidump.
const size_t code_objects_length = arraysize(code_objects_);
size_t i = 0;
StackFrameIterator it(isolate);
for (; !it.done() && i < code_objects_length; it.Advance()) {
code_objects_[i++] =
reinterpret_cast<void*>(it.frame()->unchecked_code().ptr());
}
}
}

View File

@ -872,6 +872,9 @@ class V8_EXPORT_PRIVATE Isolate final : private HiddenFactory {
void* ptr2 = nullptr,
void* ptr3 = nullptr,
void* ptr4 = nullptr);
// Similar to the above but without collecting the stack trace.
V8_NOINLINE void PushParamsAndDie(void* ptr1 = nullptr, void* ptr2 = nullptr,
void* ptr3 = nullptr, void* ptr4 = nullptr);
Handle<FixedArray> CaptureCurrentStackTrace(
int frame_limit, StackTrace::StackTraceOptions options);
Handle<Object> CaptureSimpleStackTrace(Handle<JSReceiver> error_object,
@ -2455,9 +2458,11 @@ class StackLimitCheck {
class StackTraceFailureMessage {
public:
explicit StackTraceFailureMessage(Isolate* isolate, void* ptr1 = nullptr,
void* ptr2 = nullptr, void* ptr3 = nullptr,
void* ptr4 = nullptr);
enum StackTraceMode { kIncludeStackTrace, kDontIncludeStackTrace };
explicit StackTraceFailureMessage(Isolate* isolate, StackTraceMode mode,
void* ptr1 = nullptr, void* ptr2 = nullptr,
void* ptr3 = nullptr, void* ptr4 = nullptr);
V8_NOINLINE void Print() volatile;

View File

@ -7091,6 +7091,13 @@ Code Heap::GcSafeFindCodeForInnerPointer(Address inner_pointer) {
return code;
}
}
// TODO(1241665): Remove once the issue is solved.
isolate()->PushParamsAndDie(
reinterpret_cast<void*>(inner_pointer),
const_cast<uint8_t*>(isolate()->embedded_blob_code()),
const_cast<uint8_t*>(Isolate::CurrentEmbeddedBlobCode()),
reinterpret_cast<void*>(Isolate::CurrentEmbeddedBlobCodeSize()));
UNREACHABLE();
}