Commit 63dc5a02 authored by yangguo's avatar yangguo Committed by Commit bot

[liveedit] deal with FCG and bytecode... at the same time.

BUG=v8:5265

Review-Url: https://codereview.chromium.org/2218873002
Cr-Commit-Position: refs/heads/master@{#38482}
parent 6380c31a
...@@ -620,52 +620,20 @@ void FunctionInfoWrapper::SetInitialProperties(Handle<String> name, ...@@ -620,52 +620,20 @@ void FunctionInfoWrapper::SetInitialProperties(Handle<String> name,
this->SetSmiValueField(kParentIndexOffset_, parent_index); this->SetSmiValueField(kParentIndexOffset_, parent_index);
} }
void FunctionInfoWrapper::SetFunctionCode(Handle<AbstractCode> function_code,
Handle<HeapObject> code_scope_info) {
// CompileForLiveEdit must deliver full-codegen code.
Handle<JSValue> code_wrapper = WrapInJSValue(function_code);
this->SetField(kCodeOffset_, code_wrapper);
Handle<JSValue> scope_wrapper = WrapInJSValue(code_scope_info);
this->SetField(kCodeScopeInfoOffset_, scope_wrapper);
}
void FunctionInfoWrapper::SetSharedFunctionInfo( void FunctionInfoWrapper::SetSharedFunctionInfo(
Handle<SharedFunctionInfo> info) { Handle<SharedFunctionInfo> info) {
Handle<JSValue> info_holder = WrapInJSValue(info); Handle<JSValue> info_holder = WrapInJSValue(info);
this->SetField(kSharedFunctionInfoOffset_, info_holder); this->SetField(kSharedFunctionInfoOffset_, info_holder);
} }
Handle<AbstractCode> FunctionInfoWrapper::GetFunctionCode() { Handle<SharedFunctionInfo> FunctionInfoWrapper::GetSharedFunctionInfo() {
Handle<Object> element = this->GetField(kCodeOffset_); Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_);
Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element); Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element);
Handle<Object> raw_result = UnwrapJSValue(value_wrapper); Handle<Object> raw_result = UnwrapJSValue(value_wrapper);
CHECK(raw_result->IsAbstractCode()); CHECK(raw_result->IsSharedFunctionInfo());
return Handle<AbstractCode>::cast(raw_result); return Handle<SharedFunctionInfo>::cast(raw_result);
} }
MaybeHandle<TypeFeedbackMetadata> FunctionInfoWrapper::GetFeedbackMetadata() {
Handle<Object> element = this->GetField(kSharedFunctionInfoOffset_);
if (element->IsJSValue()) {
Handle<JSValue> value_wrapper = Handle<JSValue>::cast(element);
Handle<Object> raw_result = UnwrapJSValue(value_wrapper);
Handle<SharedFunctionInfo> shared =
Handle<SharedFunctionInfo>::cast(raw_result);
return Handle<TypeFeedbackMetadata>(shared->feedback_metadata(), isolate());
} else {
// Scripts may never have a SharedFunctionInfo created.
return MaybeHandle<TypeFeedbackMetadata>();
}
}
Handle<Object> FunctionInfoWrapper::GetCodeScopeInfo() {
Handle<Object> element = this->GetField(kCodeScopeInfoOffset_);
return UnwrapJSValue(Handle<JSValue>::cast(element));
}
void SharedInfoWrapper::SetProperties(Handle<String> name, void SharedInfoWrapper::SetProperties(Handle<String> name,
int start_position, int start_position,
int end_position, int end_position,
...@@ -1005,41 +973,57 @@ void LiveEdit::ReplaceFunctionCode( ...@@ -1005,41 +973,57 @@ void LiveEdit::ReplaceFunctionCode(
SharedInfoWrapper shared_info_wrapper(shared_info_array); SharedInfoWrapper shared_info_wrapper(shared_info_array);
Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo();
Handle<SharedFunctionInfo> new_shared_info =
compile_info_wrapper.GetSharedFunctionInfo();
bool feedback_metadata_changed = false; bool feedback_metadata_changed = false;
if (shared_info->is_compiled()) { if (shared_info->is_compiled()) {
Handle<AbstractCode> new_code = compile_info_wrapper.GetFunctionCode(); // Take whatever code we can get from the new shared function info. We
if (shared_info->HasBytecodeArray()) { // expect activations of neither the old bytecode nor old FCG code, since
DCHECK(new_code->IsBytecodeArray()); // the lowest activation is going to be restarted.
// The old code is interpreted, the new code must be interpreted as well. Handle<Code> old_code(shared_info->code());
shared_info->ClearBytecodeArray(); Handle<Code> new_code(new_shared_info->code());
shared_info->set_bytecode_array(BytecodeArray::cast(*new_code)); // Clear old bytecode. This will trigger self-healing if we do not install
// new bytecode.
shared_info->ClearBytecodeArray();
if (old_code->is_interpreter_trampoline_builtin()) {
// Every function from this SFI is interpreted.
if (new_code->is_interpreter_trampoline_builtin()) {
// We have newly compiled bytecode. Simply replace the old one.
shared_info->set_bytecode_array(new_shared_info->bytecode_array());
} else {
// Rely on self-healing for places that used to run bytecode.
shared_info->ReplaceCode(*new_code);
}
} else { } else {
Handle<Code> old_code(shared_info->code()); // Functions from this SFI can be either interpreted or running FCG.
DCHECK(old_code->kind() == Code::FUNCTION); DCHECK(old_code->kind() == Code::FUNCTION);
DCHECK(new_code->kind() == AbstractCode::FUNCTION); if (new_shared_info->HasBytecodeArray()) {
ReplaceCodeObject(old_code, Handle<Code>::cast(new_code)); // Start using new bytecode everywhere.
shared_info->set_bytecode_array(new_shared_info->bytecode_array());
ReplaceCodeObject(old_code,
isolate->builtins()->InterpreterEntryTrampoline());
} else {
// Start using new FCG code everywhere.
// Rely on self-healing for places that used to run bytecode.
DCHECK(new_code->kind() == Code::FUNCTION);
ReplaceCodeObject(old_code, new_code);
}
} }
if (shared_info->HasDebugInfo()) { if (shared_info->HasDebugInfo()) {
// Existing break points will be re-applied. Reset the debug info here. // Existing break points will be re-applied. Reset the debug info here.
isolate->debug()->RemoveDebugInfoAndClearFromShared( isolate->debug()->RemoveDebugInfoAndClearFromShared(
handle(shared_info->GetDebugInfo())); handle(shared_info->GetDebugInfo()));
} }
Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); shared_info->set_scope_info(new_shared_info->scope_info());
if (code_scope_info->IsFixedArray()) {
shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info));
}
shared_info->DisableOptimization(kLiveEdit); shared_info->DisableOptimization(kLiveEdit);
// Update the type feedback vector, if needed. // Update the type feedback vector, if needed.
MaybeHandle<TypeFeedbackMetadata> feedback_metadata = Handle<TypeFeedbackMetadata> new_feedback_metadata(
compile_info_wrapper.GetFeedbackMetadata(); new_shared_info->feedback_metadata());
if (!feedback_metadata.is_null()) { feedback_metadata_changed =
Handle<TypeFeedbackMetadata> checked_feedback_metadata = new_feedback_metadata->DiffersFrom(shared_info->feedback_metadata());
feedback_metadata.ToHandleChecked(); shared_info->set_feedback_metadata(*new_feedback_metadata);
feedback_metadata_changed = checked_feedback_metadata->DiffersFrom(
shared_info->feedback_metadata());
shared_info->set_feedback_metadata(*checked_feedback_metadata);
}
} }
int start_position = compile_info_wrapper.GetStartPosition(); int start_position = compile_info_wrapper.GetStartPosition();
...@@ -1154,19 +1138,19 @@ void LiveEdit::PatchFunctionPositions(Handle<JSArray> shared_info_array, ...@@ -1154,19 +1138,19 @@ void LiveEdit::PatchFunctionPositions(Handle<JSArray> shared_info_array,
info->set_end_position(new_function_end); info->set_end_position(new_function_end);
info->set_function_token_position(new_function_token_pos); info->set_function_token_position(new_function_token_pos);
if (info->code()->kind() == Code::FUNCTION) { if (info->HasBytecodeArray()) {
Handle<ByteArray> new_source_position_table = TranslateSourcePositionTable(
Handle<ByteArray>(info->code()->source_position_table()),
position_change_array);
info->code()->set_source_position_table(*new_source_position_table);
} else if (info->HasBytecodeArray()) {
Handle<ByteArray> new_source_position_table = TranslateSourcePositionTable( Handle<ByteArray> new_source_position_table = TranslateSourcePositionTable(
Handle<ByteArray>(info->bytecode_array()->source_position_table()), Handle<ByteArray>(info->bytecode_array()->source_position_table()),
position_change_array); position_change_array);
info->bytecode_array()->set_source_position_table( info->bytecode_array()->set_source_position_table(
*new_source_position_table); *new_source_position_table);
} }
if (info->code()->kind() == Code::FUNCTION) {
Handle<ByteArray> new_source_position_table = TranslateSourcePositionTable(
Handle<ByteArray>(info->code()->source_position_table()),
position_change_array);
info->code()->set_source_position_table(*new_source_position_table);
}
if (info->HasDebugInfo()) { if (info->HasDebugInfo()) {
// Existing break points will be re-applied. Reset the debug info here. // Existing break points will be re-applied. Reset the debug info here.
info->GetIsolate()->debug()->RemoveDebugInfoAndClearFromShared( info->GetIsolate()->debug()->RemoveDebugInfoAndClearFromShared(
...@@ -1898,8 +1882,6 @@ void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared, ...@@ -1898,8 +1882,6 @@ void LiveEditFunctionTracker::FunctionDone(Handle<SharedFunctionInfo> shared,
FunctionInfoWrapper info = FunctionInfoWrapper::cast( FunctionInfoWrapper info = FunctionInfoWrapper::cast(
*JSReceiver::GetElement(isolate_, result_, current_parent_index_) *JSReceiver::GetElement(isolate_, result_, current_parent_index_)
.ToHandleChecked()); .ToHandleChecked());
info.SetFunctionCode(Handle<AbstractCode>(shared->abstract_code()),
Handle<HeapObject>(shared->scope_info()));
info.SetSharedFunctionInfo(shared); info.SetSharedFunctionInfo(shared);
Handle<Object> scope_info_list = SerializeFunctionScope(scope); Handle<Object> scope_info_list = SerializeFunctionScope(scope);
......
...@@ -295,15 +295,14 @@ class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> { ...@@ -295,15 +295,14 @@ class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> {
int end_position, int param_num, int literal_count, int end_position, int param_num, int literal_count,
int parent_index); int parent_index);
void SetFunctionCode(Handle<AbstractCode> function_code,
Handle<HeapObject> code_scope_info);
void SetFunctionScopeInfo(Handle<Object> scope_info_array) { void SetFunctionScopeInfo(Handle<Object> scope_info_array) {
this->SetField(kFunctionScopeInfoOffset_, scope_info_array); this->SetField(kFunctionScopeInfoOffset_, scope_info_array);
} }
void SetSharedFunctionInfo(Handle<SharedFunctionInfo> info); void SetSharedFunctionInfo(Handle<SharedFunctionInfo> info);
Handle<SharedFunctionInfo> GetSharedFunctionInfo();
int GetLiteralCount() { int GetLiteralCount() {
return this->GetSmiValueField(kLiteralNumOffset_); return this->GetSmiValueField(kLiteralNumOffset_);
} }
...@@ -312,12 +311,6 @@ class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> { ...@@ -312,12 +311,6 @@ class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> {
return this->GetSmiValueField(kParentIndexOffset_); return this->GetSmiValueField(kParentIndexOffset_);
} }
Handle<AbstractCode> GetFunctionCode();
MaybeHandle<TypeFeedbackMetadata> GetFeedbackMetadata();
Handle<Object> GetCodeScopeInfo();
int GetStartPosition() { int GetStartPosition() {
return this->GetSmiValueField(kStartPositionOffset_); return this->GetSmiValueField(kStartPositionOffset_);
} }
...@@ -329,13 +322,11 @@ class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> { ...@@ -329,13 +322,11 @@ class FunctionInfoWrapper : public JSArrayBasedStruct<FunctionInfoWrapper> {
static const int kStartPositionOffset_ = 1; static const int kStartPositionOffset_ = 1;
static const int kEndPositionOffset_ = 2; static const int kEndPositionOffset_ = 2;
static const int kParamNumOffset_ = 3; static const int kParamNumOffset_ = 3;
static const int kCodeOffset_ = 4; static const int kFunctionScopeInfoOffset_ = 4;
static const int kCodeScopeInfoOffset_ = 5; static const int kParentIndexOffset_ = 5;
static const int kFunctionScopeInfoOffset_ = 6; static const int kSharedFunctionInfoOffset_ = 6;
static const int kParentIndexOffset_ = 7; static const int kLiteralNumOffset_ = 7;
static const int kSharedFunctionInfoOffset_ = 8; static const int kSize_ = 8;
static const int kLiteralNumOffset_ = 9;
static const int kSize_ = 10;
friend class JSArrayBasedStruct<FunctionInfoWrapper>; friend class JSArrayBasedStruct<FunctionInfoWrapper>;
}; };
......
...@@ -842,11 +842,9 @@ ...@@ -842,11 +842,9 @@
this.start_position = raw_array[1]; this.start_position = raw_array[1];
this.end_position = raw_array[2]; this.end_position = raw_array[2];
this.param_num = raw_array[3]; this.param_num = raw_array[3];
this.code = raw_array[4]; this.scope_info = raw_array[4];
this.code_scope_info = raw_array[5]; this.outer_index = raw_array[5];
this.scope_info = raw_array[6]; this.shared_function_info = raw_array[6];
this.outer_index = raw_array[7];
this.shared_function_info = raw_array[8];
this.next_sibling_index = null; this.next_sibling_index = null;
this.raw_array = raw_array; this.raw_array = raw_array;
} }
......
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