Commit 4a0cf0b9 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[stack-trace] Cache source position for JavaScript stack frames

Retrieving the source position for a JavaScript stack frame is a
costly operation (it requires decoding the source position table).

The source position is usually retrieved twice, once for the line
number, and once for the column number.

This CL caches the resolved source position the first time around,
improving relevant stack trace serialization micro benchmarks by ~6%.

R=jgruber@chromium.org

Bug: v8:8742
Change-Id: Ife9903208d2be100e272ccad805a77c33e0df93a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1715447Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62891}
parent bd70a600
......@@ -332,6 +332,7 @@ void JSStackFrame::FromFrameArray(Isolate* isolate, Handle<FrameArray> array,
function_ = handle(array->Function(frame_ix), isolate);
code_ = handle(array->Code(frame_ix), isolate);
offset_ = array->Offset(frame_ix).value();
cached_position_ = base::nullopt;
const int flags = array->Flags(frame_ix).value();
is_constructor_ = (flags & FrameArray::kIsConstructor) != 0;
......@@ -348,6 +349,7 @@ JSStackFrame::JSStackFrame(Isolate* isolate, Handle<Object> receiver,
function_(function),
code_(code),
offset_(offset),
cached_position_(base::nullopt),
is_async_(false),
is_constructor_(false),
is_strict_(false) {}
......@@ -512,9 +514,12 @@ bool JSStackFrame::IsToplevel() {
}
int JSStackFrame::GetPosition() const {
if (cached_position_) return *cached_position_;
Handle<SharedFunctionInfo> shared = handle(function_->shared(), isolate_);
SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate_, shared);
return code_->SourcePosition(offset_);
cached_position_ = code_->SourcePosition(offset_);
return *cached_position_;
}
bool JSStackFrame::HasScript() const {
......
......@@ -12,6 +12,7 @@
#include <memory>
#include "src/base/optional.h"
#include "src/common/message-template.h"
#include "src/handles/handles.h"
......@@ -146,6 +147,7 @@ class JSStackFrame : public StackFrameBase {
Handle<JSFunction> function_;
Handle<AbstractCode> code_;
int offset_;
mutable base::Optional<int> cached_position_;
bool is_async_ : 1;
bool is_constructor_ : 1;
......
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