From c933e28935a5bd7bb9f44c74450ce7220996b581 Mon Sep 17 00:00:00 2001 From: "vegorov@chromium.org" Date: Fri, 28 Oct 2011 12:49:09 +0000 Subject: [PATCH] Make C++ to JS transition faster by avoiding JavaScriptFrameIterator in SaveContext. R=kmillikin@chromium.org BUG=v8:1730 Review URL: http://codereview.chromium.org/8403037 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9835 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/isolate-inl.h | 4 +--- src/isolate.h | 6 +++--- src/runtime.cc | 25 +++++++++++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/isolate-inl.h b/src/isolate-inl.h index d6e613176d..0a2c17404e 100644 --- a/src/isolate-inl.h +++ b/src/isolate-inl.h @@ -45,9 +45,7 @@ SaveContext::SaveContext(Isolate* isolate) : prev_(isolate->save_context()) { } isolate->set_save_context(this); - // If there is no JS frame under the current C frame, use the value 0. - JavaScriptFrameIterator it(isolate); - js_sp_ = it.done() ? 0 : it.frame()->sp(); + c_entry_fp_ = isolate->c_entry_fp(isolate->thread_local_top()); } diff --git a/src/isolate.h b/src/isolate.h index 5453bf249a..116b802670 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -1246,8 +1246,8 @@ class SaveContext BASE_EMBEDDED { SaveContext* prev() { return prev_; } // Returns true if this save context is below a given JavaScript frame. - bool below(JavaScriptFrame* frame) { - return (js_sp_ == 0) || (frame->sp() < js_sp_); + bool IsBelowFrame(JavaScriptFrame* frame) { + return (c_entry_fp_ == 0) || (c_entry_fp_ > frame->sp()); } private: @@ -1256,7 +1256,7 @@ class SaveContext BASE_EMBEDDED { Handle dummy_; #endif SaveContext* prev_; - Address js_sp_; // The top JS frame's sp when saving context. + Address c_entry_fp_; }; diff --git a/src/runtime.cc b/src/runtime.cc index 51ed26d889..3161614e7c 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -10725,6 +10725,18 @@ static const int kFrameDetailsAtReturnIndex = 7; static const int kFrameDetailsFlagsIndex = 8; static const int kFrameDetailsFirstDynamicIndex = 9; + +static SaveContext* FindSavedContextForFrame(Isolate* isolate, + JavaScriptFrame* frame) { + SaveContext* save = isolate->save_context(); + while (save != NULL && !save->IsBelowFrame(frame)) { + save = save->prev(); + } + ASSERT(save != NULL); + return save; +} + + // Return an array with frame details // args[0]: number: break id // args[1]: number: frame index @@ -10780,11 +10792,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_GetFrameDetails) { // Traverse the saved contexts chain to find the active context for the // selected frame. - SaveContext* save = isolate->save_context(); - while (save != NULL && !save->below(it.frame())) { - save = save->prev(); - } - ASSERT(save != NULL); + SaveContext* save = FindSavedContextForFrame(isolate, it.frame()); // Get the frame id. Handle frame_id(WrapFrameId(it.frame()->id()), isolate); @@ -12062,11 +12070,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugEvaluate) { // Traverse the saved contexts chain to find the active context for the // selected frame. - SaveContext* save = isolate->save_context(); - while (save != NULL && !save->below(frame)) { - save = save->prev(); - } - ASSERT(save != NULL); + SaveContext* save = FindSavedContextForFrame(isolate, frame); + SaveContext savex(isolate); isolate->set_context(*(save->context()));