Skip to content

Commit dc662e5

Browse files
alexkozyCommit bot
authored andcommitted
[inspector] store stack frame in struct instead of JSObject
JSObject is slow: creating strings for keys and storing values by these keys after takes significant amount of time. With this CL console methods (most of them collect top stack frame to calculate source location) are ~33% faster. V8Debugger::captureStackTrace is ~50% faster. BUG=v8:6189 [email protected] [email protected] Review-Url: https://codereview.chromium.org/2789073002 Cr-Commit-Position: refs/heads/master@{#44344}
1 parent 32d4d8e commit dc662e5

14 files changed

Lines changed: 164 additions & 186 deletions

File tree

include/v8.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8646,8 +8646,8 @@ class Internals {
86468646
static const int kNodeIsIndependentShift = 3;
86478647
static const int kNodeIsActiveShift = 4;
86488648

8649-
static const int kJSApiObjectType = 0xba;
8650-
static const int kJSObjectType = 0xbb;
8649+
static const int kJSApiObjectType = 0xbb;
8650+
static const int kJSObjectType = 0xbc;
86518651
static const int kFirstNonstringType = 0x80;
86528652
static const int kOddballType = 0x82;
86538653
static const int kForeignType = 0x86;

src/api.cc

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,8 +2846,8 @@ Local<StackFrame> StackTrace::GetFrame(uint32_t index) const {
28462846
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
28472847
auto self = Utils::OpenHandle(this);
28482848
auto obj = i::JSReceiver::GetElement(isolate, self, index).ToHandleChecked();
2849-
auto jsobj = i::Handle<i::JSObject>::cast(obj);
2850-
return scope.Escape(Utils::StackFrameToLocal(jsobj));
2849+
auto info = i::Handle<i::StackFrameInfo>::cast(obj);
2850+
return scope.Escape(Utils::StackFrameToLocal(info));
28512851
}
28522852

28532853

@@ -2875,77 +2875,59 @@ Local<StackTrace> StackTrace::CurrentStackTrace(
28752875

28762876
// --- S t a c k F r a m e ---
28772877

2878-
static int getIntProperty(const StackFrame* f, const char* propertyName,
2879-
int defaultValue) {
2880-
i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2881-
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2882-
i::HandleScope scope(isolate);
2883-
i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2884-
i::Handle<i::Object> obj =
2885-
i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked();
2886-
return obj->IsSmi() ? i::Smi::cast(*obj)->value() : defaultValue;
2887-
}
2888-
2889-
28902878
int StackFrame::GetLineNumber() const {
2891-
return getIntProperty(this, "lineNumber", Message::kNoLineNumberInfo);
2879+
int v = Utils::OpenHandle(this)->line_number();
2880+
return v ? v : Message::kNoLineNumberInfo;
28922881
}
28932882

28942883

28952884
int StackFrame::GetColumn() const {
2896-
return getIntProperty(this, "column", Message::kNoColumnInfo);
2885+
int v = Utils::OpenHandle(this)->column_number();
2886+
return v ? v : Message::kNoLineNumberInfo;
28972887
}
28982888

28992889

29002890
int StackFrame::GetScriptId() const {
2901-
return getIntProperty(this, "scriptId", Message::kNoScriptIdInfo);
2891+
int v = Utils::OpenHandle(this)->script_id();
2892+
return v ? v : Message::kNoScriptIdInfo;
29022893
}
29032894

2904-
2905-
static Local<String> getStringProperty(const StackFrame* f,
2906-
const char* propertyName) {
2907-
i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2908-
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2895+
Local<String> StackFrame::GetScriptName() const {
2896+
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
29092897
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2910-
i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2911-
i::Handle<i::Object> obj =
2912-
i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked();
2898+
i::Handle<i::StackFrameInfo> self = Utils::OpenHandle(this);
2899+
i::Handle<i::Object> obj(self->script_name(), isolate);
29132900
return obj->IsString()
29142901
? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj)))
29152902
: Local<String>();
29162903
}
29172904

29182905

2919-
Local<String> StackFrame::GetScriptName() const {
2920-
return getStringProperty(this, "scriptName");
2921-
}
2922-
2923-
29242906
Local<String> StackFrame::GetScriptNameOrSourceURL() const {
2925-
return getStringProperty(this, "scriptNameOrSourceURL");
2907+
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2908+
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2909+
i::Handle<i::StackFrameInfo> self = Utils::OpenHandle(this);
2910+
i::Handle<i::Object> obj(self->script_name_or_source_url(), isolate);
2911+
return obj->IsString()
2912+
? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj)))
2913+
: Local<String>();
29262914
}
29272915

29282916

29292917
Local<String> StackFrame::GetFunctionName() const {
2930-
return getStringProperty(this, "functionName");
2931-
}
2932-
2933-
2934-
static bool getBoolProperty(const StackFrame* f, const char* propertyName) {
2935-
i::Isolate* isolate = Utils::OpenHandle(f)->GetIsolate();
2936-
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(isolate);
2937-
i::HandleScope scope(isolate);
2938-
i::Handle<i::JSObject> self = Utils::OpenHandle(f);
2939-
i::Handle<i::Object> obj =
2940-
i::JSReceiver::GetProperty(isolate, self, propertyName).ToHandleChecked();
2941-
return obj->IsTrue(isolate);
2918+
i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate();
2919+
EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
2920+
i::Handle<i::StackFrameInfo> self = Utils::OpenHandle(this);
2921+
i::Handle<i::Object> obj(self->function_name(), isolate);
2922+
return obj->IsString()
2923+
? scope.Escape(Local<String>::Cast(Utils::ToLocal(obj)))
2924+
: Local<String>();
29422925
}
29432926

2944-
bool StackFrame::IsEval() const { return getBoolProperty(this, "isEval"); }
2945-
2927+
bool StackFrame::IsEval() const { return Utils::OpenHandle(this)->is_eval(); }
29462928

29472929
bool StackFrame::IsConstructor() const {
2948-
return getBoolProperty(this, "isConstructor");
2930+
return Utils::OpenHandle(this)->is_constructor();
29492931
}
29502932

29512933

src/api.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class RegisteredExtension {
106106
V(Context, Context) \
107107
V(External, Object) \
108108
V(StackTrace, JSArray) \
109-
V(StackFrame, JSObject) \
109+
V(StackFrame, StackFrameInfo) \
110110
V(Proxy, JSProxy) \
111111
V(NativeWeakMap, JSWeakMap) \
112112
V(debug::GeneratorObject, JSGeneratorObject) \
@@ -188,7 +188,7 @@ class Utils {
188188
static inline Local<StackTrace> StackTraceToLocal(
189189
v8::internal::Handle<v8::internal::JSArray> obj);
190190
static inline Local<StackFrame> StackFrameToLocal(
191-
v8::internal::Handle<v8::internal::JSObject> obj);
191+
v8::internal::Handle<v8::internal::StackFrameInfo> obj);
192192
static inline Local<Number> NumberToLocal(
193193
v8::internal::Handle<v8::internal::Object> obj);
194194
static inline Local<Integer> IntegerToLocal(
@@ -318,7 +318,7 @@ MAKE_TO_LOCAL(AccessorSignatureToLocal, FunctionTemplateInfo, AccessorSignature)
318318
MAKE_TO_LOCAL(MessageToLocal, Object, Message)
319319
MAKE_TO_LOCAL(PromiseToLocal, JSObject, Promise)
320320
MAKE_TO_LOCAL(StackTraceToLocal, JSArray, StackTrace)
321-
MAKE_TO_LOCAL(StackFrameToLocal, JSObject, StackFrame)
321+
MAKE_TO_LOCAL(StackFrameToLocal, StackFrameInfo, StackFrame)
322322
MAKE_TO_LOCAL(NumberToLocal, Object, Number)
323323
MAKE_TO_LOCAL(IntegerToLocal, Object, Integer)
324324
MAKE_TO_LOCAL(Uint32ToLocal, Object, Uint32)

src/ast/ast-types.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ AstType::bitset AstBitsetType::Lub(i::Map* map) {
312312
case ALIASED_ARGUMENTS_ENTRY_TYPE:
313313
case DEBUG_INFO_TYPE:
314314
case BREAK_POINT_INFO_TYPE:
315+
case STACK_FRAME_INFO_TYPE:
315316
case CELL_TYPE:
316317
case WEAK_CELL_TYPE:
317318
case PROTOTYPE_INFO_TYPE:

src/compiler/types.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ Type::bitset BitsetType::Lub(i::Map* map) {
320320
case PROMISE_REACTION_JOB_INFO_TYPE:
321321
case DEBUG_INFO_TYPE:
322322
case BREAK_POINT_INFO_TYPE:
323+
case STACK_FRAME_INFO_TYPE:
323324
case CELL_TYPE:
324325
case WEAK_CELL_TYPE:
325326
case PROTOTYPE_INFO_TYPE:

src/deoptimizer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,6 +4203,7 @@ Handle<Object> TranslatedState::MaterializeCapturedObjectAt(
42034203
case PROMISE_REACTION_JOB_INFO_TYPE:
42044204
case DEBUG_INFO_TYPE:
42054205
case BREAK_POINT_INFO_TYPE:
4206+
case STACK_FRAME_INFO_TYPE:
42064207
case CELL_TYPE:
42074208
case WEAK_CELL_TYPE:
42084209
case PROTOTYPE_INFO_TYPE:

src/factory.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,6 +2592,19 @@ Handle<BreakPointInfo> Factory::NewBreakPointInfo(int source_position) {
25922592
return new_break_point_info;
25932593
}
25942594

2595+
Handle<StackFrameInfo> Factory::NewStackFrameInfo() {
2596+
Handle<StackFrameInfo> stack_frame_info =
2597+
Handle<StackFrameInfo>::cast(NewStruct(STACK_FRAME_INFO_TYPE));
2598+
stack_frame_info->set_line_number(0);
2599+
stack_frame_info->set_column_number(0);
2600+
stack_frame_info->set_script_id(0);
2601+
stack_frame_info->set_script_name(Smi::kZero);
2602+
stack_frame_info->set_script_name_or_source_url(Smi::kZero);
2603+
stack_frame_info->set_function_name(Smi::kZero);
2604+
stack_frame_info->set_flag(0);
2605+
return stack_frame_info;
2606+
}
2607+
25952608
Handle<JSObject> Factory::NewArgumentsObject(Handle<JSFunction> callee,
25962609
int length) {
25972610
bool strict_mode_callee = is_strict(callee->shared()->language_mode()) ||

src/factory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class V8_EXPORT_PRIVATE Factory final {
321321
Handle<Script> NewScript(Handle<String> source);
322322

323323
Handle<BreakPointInfo> NewBreakPointInfo(int source_position);
324+
Handle<StackFrameInfo> NewStackFrameInfo();
324325

325326
// Foreign objects are pretenured when allocated by the bootstrapper.
326327
Handle<Foreign> NewForeign(Address addr,

0 commit comments

Comments
 (0)