Chromium Code Reviews| Index: src/debug/liveedit.cc |
| diff --git a/src/debug/liveedit.cc b/src/debug/liveedit.cc |
| index ace829739faeb6dd93286dd27eeb27bc75980889..742e475866df103cacd8e3d7da91989bab050259 100644 |
| --- a/src/debug/liveedit.cc |
| +++ b/src/debug/liveedit.cc |
| @@ -604,12 +604,9 @@ static int GetArrayLength(Handle<JSArray> array) { |
| return Smi::cast(length)->value(); |
| } |
| - |
| -void FunctionInfoWrapper::SetInitialProperties(Handle<String> name, |
| - int start_position, |
| - int end_position, int param_num, |
| - int literal_count, |
| - int parent_index) { |
| +void FunctionInfoWrapper::SetInitialProperties( |
| + Handle<String> name, int start_position, int end_position, int param_num, |
| + int literal_count, int parent_index, int function_literal_id) { |
| HandleScope scope(isolate()); |
| this->SetField(kFunctionNameOffset_, name); |
| this->SetSmiValueField(kStartPositionOffset_, start_position); |
| @@ -617,6 +614,7 @@ void FunctionInfoWrapper::SetInitialProperties(Handle<String> name, |
| this->SetSmiValueField(kParamNumOffset_, param_num); |
| this->SetSmiValueField(kLiteralNumOffset_, literal_count); |
| this->SetSmiValueField(kParentIndexOffset_, parent_index); |
| + this->SetSmiValueField(kFunctionLiteralIdOffset_, function_literal_id); |
| } |
| void FunctionInfoWrapper::SetSharedFunctionInfo( |
| @@ -1038,15 +1036,38 @@ void LiveEdit::ReplaceFunctionCode( |
| isolate->compilation_cache()->Remove(shared_info); |
| } |
| - |
| -void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array) { |
| +void LiveEdit::FunctionSourceUpdated(Handle<JSArray> shared_info_array, |
| + int new_function_literal_id) { |
| SharedInfoWrapper shared_info_wrapper(shared_info_array); |
| Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
| + shared_info->set_function_literal_id(new_function_literal_id); |
| DeoptimizeDependentFunctions(*shared_info); |
| shared_info_array->GetIsolate()->compilation_cache()->Remove(shared_info); |
| } |
| +void LiveEdit::FixupScript(Handle<Script> script, int max_function_literal_id) { |
| + Isolate* isolate = script->GetIsolate(); |
| + Handle<FixedArray> old_infos(script->shared_function_infos(), isolate); |
| + Handle<FixedArray> new_infos(isolate->factory()->NewFixedArrayWithSmis( |
| + max_function_literal_id + 1, 0)); |
| + script->set_shared_function_infos(*new_infos); |
| + for (int index = 0; index < old_infos->length(); ++index) { |
| + Object* raw = old_infos->get(index); |
| + if (raw->IsSmi() || WeakCell::cast(raw)->cleared()) continue; |
| + // We can't use SharedFunctionInfo::SetScript(info, undefined_value()) here, |
| + // as we severed the link from the Script to the SharedFunctionInfo above. |
| + Handle<SharedFunctionInfo> info( |
| + SharedFunctionInfo::cast(WeakCell::cast(raw)->value()), isolate); |
| + info->set_script(isolate->heap()->undefined_value()); |
| + Handle<Object> new_noscript_list = WeakFixedArray::Add( |
| + isolate->factory()->noscript_shared_function_infos(), info); |
| + isolate->heap()->SetRootNoScriptSharedFunctionInfos(*new_noscript_list); |
| + |
| + // Put the SharedFunctionInfo at its new, correct location. |
| + SharedFunctionInfo::SetScript(info, script); |
| + } |
| +} |
| void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper, |
| Handle<Object> script_handle) { |
| @@ -1054,6 +1075,21 @@ void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper, |
| UnwrapSharedFunctionInfoFromJSValue(function_wrapper); |
| Isolate* isolate = function_wrapper->GetIsolate(); |
| CHECK(script_handle->IsScript() || script_handle->IsUndefined(isolate)); |
| +#if 0 |
|
Toon Verwaest
2016/12/06 21:10:14
left-over code?
jochen (gone - plz use gerrit)
2016/12/07 15:57:00
yes, removed
|
| + if (shared_info->script()->IsScript()) { |
| + Handle<Script> old_script(Script::cast(shared_info->script()), isolate); |
| + Handle<Object> raw(old_script->shared_function_infos()->get( |
| + shared_info->function_literal_id()), |
| + isolate); |
| + if (raw->IsWeakCell() && !Handle<WeakCell>::cast(raw)->cleared()) { |
| + Handle<SharedFunctionInfo> old_info( |
| + SharedFunctionInfo::cast(Handle<WeakCell>::cast(raw)->value()), |
| + isolate); |
| + SharedFunctionInfo::SetScript(old_info, |
| + isolate->factory()->undefined_value()); |
| + } |
| + } |
| +#endif |
| SharedFunctionInfo::SetScript(shared_info, script_handle); |
| shared_info->DisableOptimization(kLiveEdit); |
| @@ -1173,6 +1209,10 @@ static Handle<Script> CreateScriptCopy(Handle<Script> original) { |
| copy->set_eval_from_shared(original->eval_from_shared()); |
| copy->set_eval_from_position(original->eval_from_position()); |
| + Handle<FixedArray> infos(isolate->factory()->NewFixedArrayWithSmis( |
| + original->shared_function_infos()->length(), 0)); |
| + copy->set_shared_function_infos(*infos); |
| + |
| // Copy all the flags, but clear compilation state. |
| copy->set_flags(original->flags()); |
| copy->set_compilation_state(Script::COMPILATION_STATE_INITIAL); |
| @@ -1180,7 +1220,6 @@ static Handle<Script> CreateScriptCopy(Handle<Script> original) { |
| return copy; |
| } |
| - |
| Handle<Object> LiveEdit::ChangeScriptSource(Handle<Script> original_script, |
| Handle<String> new_source, |
| Handle<Object> old_script_name) { |
| @@ -1856,8 +1895,6 @@ void LiveEditFunctionTracker::VisitFunctionLiteral(FunctionLiteral* node) { |
| // Recurse using the regular traversal. |
| AstTraversalVisitor::VisitFunctionLiteral(node); |
| // FunctionDone are called in post-order. |
| - // TODO(jgruber): If required, replace the (linear cost) |
| - // FindSharedFunctionInfo call with a more efficient implementation. |
| Handle<SharedFunctionInfo> info = |
| script_->FindSharedFunctionInfo(node).ToHandleChecked(); |
| FunctionDone(info, node->scope()); |
| @@ -1869,7 +1906,7 @@ void LiveEditFunctionTracker::FunctionStarted(FunctionLiteral* fun) { |
| info.SetInitialProperties(fun->name(), fun->start_position(), |
| fun->end_position(), fun->parameter_count(), |
| fun->materialized_literal_count(), |
| - current_parent_index_); |
| + current_parent_index_, fun->function_literal_id()); |
| current_parent_index_ = len_; |
| SetElementSloppy(result_, len_, info.GetJSArray()); |
| len_++; |