Commit 49ea60ef authored by rmcilroy's avatar rmcilroy Committed by Commit bot

[GC] Fix code flushing to use bytecode if it exists.

If code is flushed on a SFI, we can still use the bytecode if it was compiled,
since this never gets flushed.

This fixes a DCHECK where we were trying to compile the bytecode multiple
times after the baseline code was flushed.

BUG=chromium:668133

Review-Url: https://codereview.chromium.org/2526243002
Cr-Commit-Position: refs/heads/master@{#41274}
parent 76723502
......@@ -912,6 +912,8 @@ void MarkCompactCollector::Finish() {
void CodeFlusher::ProcessJSFunctionCandidates() {
Code* lazy_compile = isolate_->builtins()->builtin(Builtins::kCompileLazy);
Code* interpreter_entry_trampoline =
isolate_->builtins()->builtin(Builtins::kInterpreterEntryTrampoline);
Object* undefined = isolate_->heap()->undefined_value();
JSFunction* candidate = jsfunction_candidates_head_;
......@@ -934,8 +936,13 @@ void CodeFlusher::ProcessJSFunctionCandidates() {
if (!shared->OptimizedCodeMapIsCleared()) {
shared->ClearOptimizedCodeMap();
}
shared->set_code(lazy_compile);
candidate->set_code(lazy_compile);
if (shared->HasBytecodeArray()) {
shared->set_code(interpreter_entry_trampoline);
candidate->set_code(interpreter_entry_trampoline);
} else {
shared->set_code(lazy_compile);
candidate->set_code(lazy_compile);
}
} else {
DCHECK(Marking::IsBlack(code_mark));
candidate->set_code(code);
......@@ -962,7 +969,8 @@ void CodeFlusher::ProcessJSFunctionCandidates() {
void CodeFlusher::ProcessSharedFunctionInfoCandidates() {
Code* lazy_compile = isolate_->builtins()->builtin(Builtins::kCompileLazy);
Code* interpreter_entry_trampoline =
isolate_->builtins()->builtin(Builtins::kInterpreterEntryTrampoline);
SharedFunctionInfo* candidate = shared_function_info_candidates_head_;
SharedFunctionInfo* next_candidate;
while (candidate != NULL) {
......@@ -981,7 +989,11 @@ void CodeFlusher::ProcessSharedFunctionInfoCandidates() {
if (!candidate->OptimizedCodeMapIsCleared()) {
candidate->ClearOptimizedCodeMap();
}
candidate->set_code(lazy_compile);
if (candidate->HasBytecodeArray()) {
candidate->set_code(interpreter_entry_trampoline);
} else {
candidate->set_code(lazy_compile);
}
}
Object** code_slot =
......
......@@ -6244,6 +6244,10 @@ Code* SharedFunctionInfo::code() const {
void SharedFunctionInfo::set_code(Code* value, WriteBarrierMode mode) {
DCHECK(value->kind() != Code::OPTIMIZED_FUNCTION);
// If the SharedFunctionInfo has bytecode we should never mark it for lazy
// compile, since the bytecode is never flushed.
DCHECK(value != GetIsolate()->builtins()->builtin(Builtins::kCompileLazy) ||
!HasBytecodeArray());
WRITE_FIELD(this, kCodeOffset, value);
CONDITIONAL_WRITE_BARRIER(value->GetHeap(), this, kCodeOffset, value, mode);
}
......
......@@ -6275,9 +6275,9 @@ static void RemoveCodeAndGC(const v8::FunctionCallbackInfo<v8::Value>& args) {
Isolate* isolate = CcTest::i_isolate();
Handle<Object> obj = v8::Utils::OpenHandle(*args[0]);
Handle<JSFunction> fun = Handle<JSFunction>::cast(obj);
fun->shared()->ClearBytecodeArray(); // Bytecode is code too.
fun->ReplaceCode(*isolate->builtins()->CompileLazy());
fun->shared()->ReplaceCode(*isolate->builtins()->CompileLazy());
fun->shared()->ClearBytecodeArray(); // Bytecode is code too.
CcTest::CollectAllAvailableGarbage();
}
......
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