[interpreter] Fix self-healing with preserved bytecode.
This fixes the self-healing mechanism for closures in the interpreter entry trampoline not that bytecode can be preserved even when baseline code is already available. R=rmcilroy@chromium.org TEST=cctest/test-compiler/IgnitionEntryTrampolineSelfHealing BUG=chromium:638225 Review-Url: https://codereview.chromium.org/2257143002 Cr-Commit-Position: refs/heads/master@{#38747}
This commit is contained in:
parent
99edc1b8e7
commit
4598d9139e
@ -1054,11 +1054,13 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
__ ldr(kInterpreterBytecodeArrayRegister,
|
||||
FieldMemOperand(debug_info, DebugInfo::kDebugBytecodeArrayIndex), ne);
|
||||
|
||||
// Check whether we should continue to use the interpreter.
|
||||
Label switch_to_different_code_kind;
|
||||
__ ldr(r0, FieldMemOperand(r0, SharedFunctionInfo::kCodeOffset));
|
||||
__ cmp(r0, Operand(masm->CodeObject())); // Self-reference to this code.
|
||||
__ b(ne, &switch_to_different_code_kind);
|
||||
|
||||
// Check function data field is actually a BytecodeArray object.
|
||||
Label bytecode_array_not_present;
|
||||
__ CompareRoot(kInterpreterBytecodeArrayRegister,
|
||||
Heap::kUndefinedValueRootIndex);
|
||||
__ b(eq, &bytecode_array_not_present);
|
||||
if (FLAG_debug_code) {
|
||||
__ SmiTst(kInterpreterBytecodeArrayRegister);
|
||||
__ Assert(ne, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry);
|
||||
@ -1122,10 +1124,10 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
LeaveInterpreterFrame(masm, r2);
|
||||
__ Jump(lr);
|
||||
|
||||
// If the bytecode array is no longer present, then the underlying function
|
||||
// has been switched to a different kind of code and we heal the closure by
|
||||
// switching the code entry field over to the new code object as well.
|
||||
__ bind(&bytecode_array_not_present);
|
||||
// If the shared code is no longer this entry trampoline, then the underlying
|
||||
// function has been switched to a different kind of code and we heal the
|
||||
// closure by switching the code entry field over to the new code as well.
|
||||
__ bind(&switch_to_different_code_kind);
|
||||
__ LeaveFrame(StackFrame::JAVA_SCRIPT);
|
||||
__ ldr(r4, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset));
|
||||
__ ldr(r4, FieldMemOperand(r4, SharedFunctionInfo::kCodeOffset));
|
||||
|
@ -1059,11 +1059,13 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldMemOperand(x0, SharedFunctionInfo::kFunctionDataOffset));
|
||||
__ Bind(&bytecode_array_loaded);
|
||||
|
||||
// Check whether we should continue to use the interpreter.
|
||||
Label switch_to_different_code_kind;
|
||||
__ Ldr(x0, FieldMemOperand(x0, SharedFunctionInfo::kCodeOffset));
|
||||
__ Cmp(x0, Operand(masm->CodeObject())); // Self-reference to this code.
|
||||
__ B(ne, &switch_to_different_code_kind);
|
||||
|
||||
// Check function data field is actually a BytecodeArray object.
|
||||
Label bytecode_array_not_present;
|
||||
__ CompareRoot(kInterpreterBytecodeArrayRegister,
|
||||
Heap::kUndefinedValueRootIndex);
|
||||
__ B(eq, &bytecode_array_not_present);
|
||||
if (FLAG_debug_code) {
|
||||
__ AssertNotSmi(kInterpreterBytecodeArrayRegister,
|
||||
kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry);
|
||||
@ -1131,10 +1133,10 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldMemOperand(debug_info, DebugInfo::kDebugBytecodeArrayIndex));
|
||||
__ B(&bytecode_array_loaded);
|
||||
|
||||
// If the bytecode array is no longer present, then the underlying function
|
||||
// has been switched to a different kind of code and we heal the closure by
|
||||
// switching the code entry field over to the new code object as well.
|
||||
__ Bind(&bytecode_array_not_present);
|
||||
// If the shared code is no longer this entry trampoline, then the underlying
|
||||
// function has been switched to a different kind of code and we heal the
|
||||
// closure by switching the code entry field over to the new code as well.
|
||||
__ bind(&switch_to_different_code_kind);
|
||||
__ LeaveFrame(StackFrame::JAVA_SCRIPT);
|
||||
__ Ldr(x7, FieldMemOperand(x1, JSFunction::kSharedFunctionInfoOffset));
|
||||
__ Ldr(x7, FieldMemOperand(x7, SharedFunctionInfo::kCodeOffset));
|
||||
|
@ -584,11 +584,13 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldOperand(eax, SharedFunctionInfo::kFunctionDataOffset));
|
||||
__ bind(&bytecode_array_loaded);
|
||||
|
||||
// Check whether we should continue to use the interpreter.
|
||||
Label switch_to_different_code_kind;
|
||||
__ Move(ecx, masm->CodeObject()); // Self-reference to this code.
|
||||
__ cmp(ecx, FieldOperand(eax, SharedFunctionInfo::kCodeOffset));
|
||||
__ j(not_equal, &switch_to_different_code_kind);
|
||||
|
||||
// Check function data field is actually a BytecodeArray object.
|
||||
Label bytecode_array_not_present;
|
||||
__ CompareRoot(kInterpreterBytecodeArrayRegister,
|
||||
Heap::kUndefinedValueRootIndex);
|
||||
__ j(equal, &bytecode_array_not_present);
|
||||
if (FLAG_debug_code) {
|
||||
__ AssertNotSmi(kInterpreterBytecodeArrayRegister);
|
||||
__ CmpObjectType(kInterpreterBytecodeArrayRegister, BYTECODE_ARRAY_TYPE,
|
||||
@ -660,10 +662,10 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldOperand(debug_info, DebugInfo::kDebugBytecodeArrayIndex));
|
||||
__ jmp(&bytecode_array_loaded);
|
||||
|
||||
// If the bytecode array is no longer present, then the underlying function
|
||||
// has been switched to a different kind of code and we heal the closure by
|
||||
// switching the code entry field over to the new code object as well.
|
||||
__ bind(&bytecode_array_not_present);
|
||||
// If the shared code is no longer this entry trampoline, then the underlying
|
||||
// function has been switched to a different kind of code and we heal the
|
||||
// closure by switching the code entry field over to the new code as well.
|
||||
__ bind(&switch_to_different_code_kind);
|
||||
__ pop(edx); // Callee's new target.
|
||||
__ pop(edi); // Callee's JS function.
|
||||
__ pop(esi); // Callee's context.
|
||||
|
@ -1045,10 +1045,13 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldMemOperand(a0, SharedFunctionInfo::kFunctionDataOffset));
|
||||
__ bind(&bytecode_array_loaded);
|
||||
|
||||
// Check whether we should continue to use the interpreter.
|
||||
Label switch_to_different_code_kind;
|
||||
__ lw(a0, FieldMemOperand(a0, SharedFunctionInfo::kCodeOffset));
|
||||
__ Branch(&switch_to_different_code_kind, ne, a0,
|
||||
Operand(masm->CodeObject())); // Self-reference to this code.
|
||||
|
||||
// Check function data field is actually a BytecodeArray object.
|
||||
Label bytecode_array_not_present;
|
||||
__ JumpIfRoot(kInterpreterBytecodeArrayRegister,
|
||||
Heap::kUndefinedValueRootIndex, &bytecode_array_not_present);
|
||||
if (FLAG_debug_code) {
|
||||
__ SmiTst(kInterpreterBytecodeArrayRegister, t0);
|
||||
__ Assert(ne, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, t0,
|
||||
@ -1119,10 +1122,10 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldMemOperand(debug_info, DebugInfo::kDebugBytecodeArrayIndex));
|
||||
__ Branch(&bytecode_array_loaded);
|
||||
|
||||
// If the bytecode array is no longer present, then the underlying function
|
||||
// has been switched to a different kind of code and we heal the closure by
|
||||
// switching the code entry field over to the new code object as well.
|
||||
__ bind(&bytecode_array_not_present);
|
||||
// If the shared code is no longer this entry trampoline, then the underlying
|
||||
// function has been switched to a different kind of code and we heal the
|
||||
// closure by switching the code entry field over to the new code as well.
|
||||
__ bind(&switch_to_different_code_kind);
|
||||
__ LeaveFrame(StackFrame::JAVA_SCRIPT);
|
||||
__ lw(t0, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
|
||||
__ lw(t0, FieldMemOperand(t0, SharedFunctionInfo::kCodeOffset));
|
||||
|
@ -1037,10 +1037,13 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldMemOperand(a0, SharedFunctionInfo::kFunctionDataOffset));
|
||||
__ bind(&bytecode_array_loaded);
|
||||
|
||||
// Check whether we should continue to use the interpreter.
|
||||
Label switch_to_different_code_kind;
|
||||
__ ld(a0, FieldMemOperand(a0, SharedFunctionInfo::kCodeOffset));
|
||||
__ Branch(&switch_to_different_code_kind, ne, a0,
|
||||
Operand(masm->CodeObject())); // Self-reference to this code.
|
||||
|
||||
// Check function data field is actually a BytecodeArray object.
|
||||
Label bytecode_array_not_present;
|
||||
__ JumpIfRoot(kInterpreterBytecodeArrayRegister,
|
||||
Heap::kUndefinedValueRootIndex, &bytecode_array_not_present);
|
||||
if (FLAG_debug_code) {
|
||||
__ SmiTst(kInterpreterBytecodeArrayRegister, a4);
|
||||
__ Assert(ne, kFunctionDataShouldBeBytecodeArrayOnInterpreterEntry, a4,
|
||||
@ -1111,10 +1114,10 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldMemOperand(debug_info, DebugInfo::kDebugBytecodeArrayIndex));
|
||||
__ Branch(&bytecode_array_loaded);
|
||||
|
||||
// If the bytecode array is no longer present, then the underlying function
|
||||
// has been switched to a different kind of code and we heal the closure by
|
||||
// switching the code entry field over to the new code object as well.
|
||||
__ bind(&bytecode_array_not_present);
|
||||
// If the shared code is no longer this entry trampoline, then the underlying
|
||||
// function has been switched to a different kind of code and we heal the
|
||||
// closure by switching the code entry field over to the new code as well.
|
||||
__ bind(&switch_to_different_code_kind);
|
||||
__ LeaveFrame(StackFrame::JAVA_SCRIPT);
|
||||
__ ld(a4, FieldMemOperand(a1, JSFunction::kSharedFunctionInfoOffset));
|
||||
__ ld(a4, FieldMemOperand(a4, SharedFunctionInfo::kCodeOffset));
|
||||
|
@ -663,11 +663,13 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldOperand(rax, SharedFunctionInfo::kFunctionDataOffset));
|
||||
__ bind(&bytecode_array_loaded);
|
||||
|
||||
// Check whether we should continue to use the interpreter.
|
||||
Label switch_to_different_code_kind;
|
||||
__ Move(rcx, masm->CodeObject()); // Self-reference to this code.
|
||||
__ cmpp(rcx, FieldOperand(rax, SharedFunctionInfo::kCodeOffset));
|
||||
__ j(not_equal, &switch_to_different_code_kind);
|
||||
|
||||
// Check function data field is actually a BytecodeArray object.
|
||||
Label bytecode_array_not_present;
|
||||
__ CompareRoot(kInterpreterBytecodeArrayRegister,
|
||||
Heap::kUndefinedValueRootIndex);
|
||||
__ j(equal, &bytecode_array_not_present);
|
||||
if (FLAG_debug_code) {
|
||||
__ AssertNotSmi(kInterpreterBytecodeArrayRegister);
|
||||
__ CmpObjectType(kInterpreterBytecodeArrayRegister, BYTECODE_ARRAY_TYPE,
|
||||
@ -739,10 +741,10 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
|
||||
FieldOperand(debug_info, DebugInfo::kDebugBytecodeArrayIndex));
|
||||
__ jmp(&bytecode_array_loaded);
|
||||
|
||||
// If the bytecode array is no longer present, then the underlying function
|
||||
// has been switched to a different kind of code and we heal the closure by
|
||||
// switching the code entry field over to the new code object as well.
|
||||
__ bind(&bytecode_array_not_present);
|
||||
// If the shared code is no longer this entry trampoline, then the underlying
|
||||
// function has been switched to a different kind of code and we heal the
|
||||
// closure by switching the code entry field over to the new code as well.
|
||||
__ bind(&switch_to_different_code_kind);
|
||||
__ leave(); // Leave the frame so we can tail call.
|
||||
__ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
|
||||
__ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kCodeOffset));
|
||||
|
@ -785,7 +785,8 @@ TEST(IgnitionBaselineOnReturn) {
|
||||
FLAG_always_opt = false;
|
||||
CcTest::InitializeVM();
|
||||
FLAG_ignition = true;
|
||||
reinterpret_cast<i::Isolate*>(CcTest::isolate())->interpreter()->Initialize();
|
||||
Isolate* isolate = CcTest::i_isolate();
|
||||
isolate->interpreter()->Initialize();
|
||||
v8::HandleScope scope(CcTest::isolate());
|
||||
InstallIsBaselineCompiledHelper(CcTest::isolate());
|
||||
|
||||
@ -803,3 +804,36 @@ TEST(IgnitionBaselineOnReturn) {
|
||||
CHECK_EQ(true, GetGlobalProperty("is_baseline_after_return")->BooleanValue());
|
||||
CHECK_EQ(1234.0, GetGlobalProperty("return_val")->Number());
|
||||
}
|
||||
|
||||
TEST(IgnitionEntryTrampolineSelfHealing) {
|
||||
FLAG_allow_natives_syntax = true;
|
||||
FLAG_always_opt = false;
|
||||
CcTest::InitializeVM();
|
||||
FLAG_ignition = true;
|
||||
Isolate* isolate = CcTest::i_isolate();
|
||||
isolate->interpreter()->Initialize();
|
||||
v8::HandleScope scope(CcTest::isolate());
|
||||
|
||||
CompileRun(
|
||||
"function MkFun() {"
|
||||
" function f() { return 23 }"
|
||||
" return f"
|
||||
"}"
|
||||
"var f1 = MkFun(); f1();"
|
||||
"var f2 = MkFun(); f2();"
|
||||
"%BaselineFunctionOnNextCall(f1);");
|
||||
Handle<JSFunction> f1 = Handle<JSFunction>::cast(GetGlobalProperty("f1"));
|
||||
Handle<JSFunction> f2 = Handle<JSFunction>::cast(GetGlobalProperty("f2"));
|
||||
|
||||
// Function {f1} is marked for baseline.
|
||||
CompileRun("var result1 = f1()");
|
||||
CHECK_NE(*isolate->builtins()->InterpreterEntryTrampoline(), f1->code());
|
||||
CHECK_EQ(*isolate->builtins()->InterpreterEntryTrampoline(), f2->code());
|
||||
CHECK_EQ(23.0, GetGlobalProperty("result1")->Number());
|
||||
|
||||
// Function {f2} will self-heal now.
|
||||
CompileRun("var result2 = f2()");
|
||||
CHECK_NE(*isolate->builtins()->InterpreterEntryTrampoline(), f1->code());
|
||||
CHECK_NE(*isolate->builtins()->InterpreterEntryTrampoline(), f2->code());
|
||||
CHECK_EQ(23.0, GetGlobalProperty("result2")->Number());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user