Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/isolate.cc

Issue 2788413004: [inspector] cache stack frame for call sites (Closed)
Patch Set: put map separately Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/heap.cc ('k') | src/objects.cc » ('j') | src/objects.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/isolate.h" 5 #include "src/isolate.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <fstream> // NOLINT(readability/streams) 9 #include <fstream> // NOLINT(readability/streams)
10 #include <sstream> 10 #include <sstream>
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 618
619 Handle<StackFrameInfo> NewStackFrameObject(FrameSummary& summ) { 619 Handle<StackFrameInfo> NewStackFrameObject(FrameSummary& summ) {
620 if (summ.IsJavaScript()) return NewStackFrameObject(summ.AsJavaScript()); 620 if (summ.IsJavaScript()) return NewStackFrameObject(summ.AsJavaScript());
621 if (summ.IsWasm()) return NewStackFrameObject(summ.AsWasm()); 621 if (summ.IsWasm()) return NewStackFrameObject(summ.AsWasm());
622 UNREACHABLE(); 622 UNREACHABLE();
623 return factory()->NewStackFrameInfo(); 623 return factory()->NewStackFrameInfo();
624 } 624 }
625 625
626 Handle<StackFrameInfo> NewStackFrameObject( 626 Handle<StackFrameInfo> NewStackFrameObject(
627 const FrameSummary::JavaScriptFrameSummary& summ) { 627 const FrameSummary::JavaScriptFrameSummary& summ) {
628 int code_offset = summ.code_offset();
629 Handle<ByteArray> source_position_table(
630 summ.abstract_code()->source_position_table(), isolate_);
631 Handle<UnseededNumberDictionary> cache = GetCache(source_position_table);
632 int entry = cache->FindEntry(code_offset);
633 if (entry != UnseededNumberDictionary::kNotFound) {
634 return handle(StackFrameInfo::cast(cache->ValueAt(entry)), isolate_);
Yang 2017/04/04 19:47:06 You would check here whether the cached StackFrame
kozy 2017/04/04 20:48:24 It eliminates almost all performance benefits: con
Yang 2017/04/04 21:15:18 Can we land this without performance improvements
kozy 2017/04/04 23:08:12 Yes, first + third sound good to me. I'll try to i
635 }
636
628 Handle<StackFrameInfo> frame = factory()->NewStackFrameInfo(); 637 Handle<StackFrameInfo> frame = factory()->NewStackFrameInfo();
629 Handle<Script> script = Handle<Script>::cast(summ.script()); 638 Handle<Script> script = Handle<Script>::cast(summ.script());
630 if (options_ & StackTrace::kLineNumber) { 639 if (options_ & StackTrace::kLineNumber) {
631 Script::PositionInfo info; 640 Script::PositionInfo info;
632 bool valid_pos = Script::GetPositionInfo(script, summ.SourcePosition(), 641 bool valid_pos = Script::GetPositionInfo(script, summ.SourcePosition(),
633 &info, Script::WITH_OFFSET); 642 &info, Script::WITH_OFFSET);
634 if (valid_pos) { 643 if (valid_pos) {
635 frame->set_line_number(info.line + 1); 644 frame->set_line_number(info.line + 1);
636 if (options_ & StackTrace::kColumnOffset) { 645 if (options_ & StackTrace::kColumnOffset) {
637 frame->set_column_number(info.column + 1); 646 frame->set_column_number(info.column + 1);
(...skipping 12 matching lines...) Expand all
650 frame->set_is_eval(script->compilation_type() == 659 frame->set_is_eval(script->compilation_type() ==
651 Script::COMPILATION_TYPE_EVAL); 660 Script::COMPILATION_TYPE_EVAL);
652 } 661 }
653 if (options_ & StackTrace::kFunctionName) { 662 if (options_ & StackTrace::kFunctionName) {
654 Handle<String> name = summ.FunctionName(); 663 Handle<String> name = summ.FunctionName();
655 frame->set_function_name(*name); 664 frame->set_function_name(*name);
656 } 665 }
657 if (options_ & StackTrace::kIsConstructor) { 666 if (options_ & StackTrace::kIsConstructor) {
658 frame->set_is_constructor(summ.is_constructor()); 667 frame->set_is_constructor(summ.is_constructor());
659 } 668 }
669 auto new_cache =
670 UnseededNumberDictionary::AtNumberPut(cache, code_offset, frame);
671 if (*new_cache != *cache) {
672 PutCache(source_position_table, cache);
673 }
660 return frame; 674 return frame;
661 } 675 }
662 676
663 Handle<StackFrameInfo> NewStackFrameObject( 677 Handle<StackFrameInfo> NewStackFrameObject(
664 const FrameSummary::WasmFrameSummary& summ) { 678 const FrameSummary::WasmFrameSummary& summ) {
665 Handle<StackFrameInfo> info = factory()->NewStackFrameInfo(); 679 Handle<StackFrameInfo> info = factory()->NewStackFrameInfo();
666 680
667 if (options_ & StackTrace::kFunctionName) { 681 if (options_ & StackTrace::kFunctionName) {
668 Handle<WasmCompiledModule> compiled_module( 682 Handle<WasmCompiledModule> compiled_module(
669 summ.wasm_instance()->compiled_module(), isolate_); 683 summ.wasm_instance()->compiled_module(), isolate_);
(...skipping 14 matching lines...) Expand all
684 } 698 }
685 if (options_ & StackTrace::kScriptId) { 699 if (options_ & StackTrace::kScriptId) {
686 info->set_script_id(summ.script()->id()); 700 info->set_script_id(summ.script()->id());
687 } 701 }
688 return info; 702 return info;
689 } 703 }
690 704
691 private: 705 private:
692 inline Factory* factory() { return isolate_->factory(); } 706 inline Factory* factory() { return isolate_->factory(); }
693 707
708 Handle<UnseededNumberDictionary> GetCache(
709 Handle<ByteArray> source_position_table) {
710 Handle<WeakHashTable> table_to_cache(isolate_->heap()->stack_frame_cache());
711 Object* maybe_cache = table_to_cache->Lookup(source_position_table);
712 if (maybe_cache->IsUnseededNumberDictionary()) {
713 return handle(UnseededNumberDictionary::cast(maybe_cache));
714 }
715 Handle<UnseededNumberDictionary> cache =
716 UnseededNumberDictionary::New(isolate_, 1);
717 auto new_table_to_cache =
718 WeakHashTable::Put(table_to_cache, source_position_table, cache);
719 if (*new_table_to_cache != *table_to_cache) {
720 isolate_->heap()->SetStackFrameCache(*new_table_to_cache);
721 }
722 return cache;
723 }
724
725 void PutCache(Handle<ByteArray> source_position_table,
726 Handle<UnseededNumberDictionary> cache) {
727 Handle<WeakHashTable> table_to_cache(isolate_->heap()->stack_frame_cache());
728 auto new_table_to_cache =
729 WeakHashTable::Put(table_to_cache, source_position_table, cache);
730 if (*new_table_to_cache != *table_to_cache) {
731 isolate_->heap()->SetStackFrameCache(*new_table_to_cache);
732 }
733 }
734
694 Isolate* isolate_; 735 Isolate* isolate_;
695 StackTrace::StackTraceOptions options_; 736 StackTrace::StackTraceOptions options_;
696 }; 737 };
697 738
698 Handle<JSArray> Isolate::CaptureCurrentStackTrace( 739 Handle<JSArray> Isolate::CaptureCurrentStackTrace(
699 int frame_limit, StackTrace::StackTraceOptions options) { 740 int frame_limit, StackTrace::StackTraceOptions options) {
700 DisallowJavascriptExecution no_js(this); 741 DisallowJavascriptExecution no_js(this);
701 CaptureStackTraceHelper helper(this, options); 742 CaptureStackTraceHelper helper(this, options);
702 743
703 // Ensure no negative values. 744 // Ensure no negative values.
(...skipping 2947 matching lines...) Expand 10 before | Expand all | Expand 10 after
3651 // Then check whether this scope intercepts. 3692 // Then check whether this scope intercepts.
3652 if ((flag & intercept_mask_)) { 3693 if ((flag & intercept_mask_)) {
3653 intercepted_flags_ |= flag; 3694 intercepted_flags_ |= flag;
3654 return true; 3695 return true;
3655 } 3696 }
3656 return false; 3697 return false;
3657 } 3698 }
3658 3699
3659 } // namespace internal 3700 } // namespace internal
3660 } // namespace v8 3701 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | src/objects.cc » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698