OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
8 | 8 |
9 #include "src/code-factory.h" | 9 #include "src/code-factory.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // o rdi: the JS function object being called (i.e. ourselves) | 88 // o rdi: the JS function object being called (i.e. ourselves) |
89 // o rsi: our context | 89 // o rsi: our context |
90 // o rbp: our caller's frame pointer | 90 // o rbp: our caller's frame pointer |
91 // o rsp: stack pointer (pointing to return address) | 91 // o rsp: stack pointer (pointing to return address) |
92 // | 92 // |
93 // The function builds a JS frame. Please see JavaScriptFrameConstants in | 93 // The function builds a JS frame. Please see JavaScriptFrameConstants in |
94 // frames-x64.h for its layout. | 94 // frames-x64.h for its layout. |
95 void FullCodeGenerator::Generate() { | 95 void FullCodeGenerator::Generate() { |
96 CompilationInfo* info = info_; | 96 CompilationInfo* info = info_; |
97 handler_table_ = | 97 handler_table_ = |
98 isolate()->factory()->NewFixedArray(function()->handler_count(), TENURED); | 98 Handle<HandlerTable>::cast(isolate()->factory()->NewFixedArray( |
| 99 HandlerTable::LengthForRange(function()->handler_count()), TENURED)); |
99 | 100 |
100 profiling_counter_ = isolate()->factory()->NewCell( | 101 profiling_counter_ = isolate()->factory()->NewCell( |
101 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); | 102 Handle<Smi>(Smi::FromInt(FLAG_interrupt_budget), isolate())); |
102 SetFunctionPosition(function()); | 103 SetFunctionPosition(function()); |
103 Comment cmnt(masm_, "[ function compiled by full code generator"); | 104 Comment cmnt(masm_, "[ function compiled by full code generator"); |
104 | 105 |
105 ProfileEntryHookStub::MaybeCallEntryHook(masm_); | 106 ProfileEntryHookStub::MaybeCallEntryHook(masm_); |
106 | 107 |
107 #ifdef DEBUG | 108 #ifdef DEBUG |
108 if (strlen(FLAG_stop_at) > 0 && | 109 if (strlen(FLAG_stop_at) > 0 && |
(...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2148 Label l_next, l_call, l_loop; | 2149 Label l_next, l_call, l_loop; |
2149 Register load_receiver = LoadDescriptor::ReceiverRegister(); | 2150 Register load_receiver = LoadDescriptor::ReceiverRegister(); |
2150 Register load_name = LoadDescriptor::NameRegister(); | 2151 Register load_name = LoadDescriptor::NameRegister(); |
2151 | 2152 |
2152 // Initial send value is undefined. | 2153 // Initial send value is undefined. |
2153 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 2154 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
2154 __ jmp(&l_next); | 2155 __ jmp(&l_next); |
2155 | 2156 |
2156 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } | 2157 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
2157 __ bind(&l_catch); | 2158 __ bind(&l_catch); |
2158 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); | |
2159 __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw" | 2159 __ LoadRoot(load_name, Heap::kthrow_stringRootIndex); // "throw" |
2160 __ Push(load_name); | 2160 __ Push(load_name); |
2161 __ Push(Operand(rsp, 2 * kPointerSize)); // iter | 2161 __ Push(Operand(rsp, 2 * kPointerSize)); // iter |
2162 __ Push(rax); // exception | 2162 __ Push(rax); // exception |
2163 __ jmp(&l_call); | 2163 __ jmp(&l_call); |
2164 | 2164 |
2165 // try { received = %yield result } | 2165 // try { received = %yield result } |
2166 // Shuffle the received result above a try handler and yield it without | 2166 // Shuffle the received result above a try handler and yield it without |
2167 // re-boxing. | 2167 // re-boxing. |
2168 __ bind(&l_try); | 2168 __ bind(&l_try); |
2169 __ Pop(rax); // result | 2169 __ Pop(rax); // result |
2170 __ PushTryHandler(StackHandler::CATCH, expr->index()); | 2170 EnterTryBlock(expr->index(), &l_catch); |
2171 const int handler_size = StackHandlerConstants::kSize; | 2171 const int try_block_size = TryCatch::kElementCount * kPointerSize; |
2172 __ Push(rax); // result | 2172 __ Push(rax); // result |
2173 __ jmp(&l_suspend); | 2173 __ jmp(&l_suspend); |
2174 __ bind(&l_continuation); | 2174 __ bind(&l_continuation); |
2175 __ jmp(&l_resume); | 2175 __ jmp(&l_resume); |
2176 __ bind(&l_suspend); | 2176 __ bind(&l_suspend); |
2177 const int generator_object_depth = kPointerSize + handler_size; | 2177 const int generator_object_depth = kPointerSize + try_block_size; |
2178 __ movp(rax, Operand(rsp, generator_object_depth)); | 2178 __ movp(rax, Operand(rsp, generator_object_depth)); |
2179 __ Push(rax); // g | 2179 __ Push(rax); // g |
| 2180 __ Push(Smi::FromInt(expr->index())); // handler-index |
2180 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); | 2181 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
2181 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), | 2182 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), |
2182 Smi::FromInt(l_continuation.pos())); | 2183 Smi::FromInt(l_continuation.pos())); |
2183 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); | 2184 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); |
2184 __ movp(rcx, rsi); | 2185 __ movp(rcx, rsi); |
2185 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, | 2186 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, |
2186 kDontSaveFPRegs); | 2187 kDontSaveFPRegs); |
2187 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 2188 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2); |
2188 __ movp(context_register(), | 2189 __ movp(context_register(), |
2189 Operand(rbp, StandardFrameConstants::kContextOffset)); | 2190 Operand(rbp, StandardFrameConstants::kContextOffset)); |
2190 __ Pop(rax); // result | 2191 __ Pop(rax); // result |
2191 EmitReturnSequence(); | 2192 EmitReturnSequence(); |
2192 __ bind(&l_resume); // received in rax | 2193 __ bind(&l_resume); // received in rax |
2193 __ PopTryHandler(); | 2194 ExitTryBlock(expr->index()); |
2194 | 2195 |
2195 // receiver = iter; f = 'next'; arg = received; | 2196 // receiver = iter; f = 'next'; arg = received; |
2196 __ bind(&l_next); | 2197 __ bind(&l_next); |
2197 | 2198 |
2198 __ LoadRoot(load_name, Heap::knext_stringRootIndex); | 2199 __ LoadRoot(load_name, Heap::knext_stringRootIndex); |
2199 __ Push(load_name); // "next" | 2200 __ Push(load_name); // "next" |
2200 __ Push(Operand(rsp, 2 * kPointerSize)); // iter | 2201 __ Push(Operand(rsp, 2 * kPointerSize)); // iter |
2201 __ Push(rax); // received | 2202 __ Push(rax); // received |
2202 | 2203 |
2203 // result = receiver[f](arg); | 2204 // result = receiver[f](arg); |
(...skipping 3093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5297 __ Pop(rdx); | 5298 __ Pop(rdx); |
5298 __ SmiToInteger32(rdx, rdx); | 5299 __ SmiToInteger32(rdx, rdx); |
5299 __ Move(rcx, masm_->CodeObject()); | 5300 __ Move(rcx, masm_->CodeObject()); |
5300 __ addp(rdx, rcx); | 5301 __ addp(rdx, rcx); |
5301 __ jmp(rdx); | 5302 __ jmp(rdx); |
5302 } | 5303 } |
5303 | 5304 |
5304 | 5305 |
5305 #undef __ | 5306 #undef __ |
5306 | 5307 |
5307 #define __ ACCESS_MASM(masm()) | |
5308 | |
5309 FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( | |
5310 int* stack_depth, | |
5311 int* context_length) { | |
5312 // The macros used here must preserve the result register. | |
5313 | |
5314 // Because the handler block contains the context of the finally | |
5315 // code, we can restore it directly from there for the finally code | |
5316 // rather than iteratively unwinding contexts via their previous | |
5317 // links. | |
5318 __ Drop(*stack_depth); // Down to the handler block. | |
5319 if (*context_length > 0) { | |
5320 // Restore the context to its dedicated register and the stack. | |
5321 __ movp(rsi, Operand(rsp, StackHandlerConstants::kContextOffset)); | |
5322 __ movp(Operand(rbp, StandardFrameConstants::kContextOffset), rsi); | |
5323 } | |
5324 __ PopTryHandler(); | |
5325 __ call(finally_entry_); | |
5326 | |
5327 *stack_depth = 0; | |
5328 *context_length = 0; | |
5329 return previous_; | |
5330 } | |
5331 | |
5332 | |
5333 #undef __ | |
5334 | |
5335 | 5308 |
5336 static const byte kJnsInstruction = 0x79; | 5309 static const byte kJnsInstruction = 0x79; |
5337 static const byte kNopByteOne = 0x66; | 5310 static const byte kNopByteOne = 0x66; |
5338 static const byte kNopByteTwo = 0x90; | 5311 static const byte kNopByteTwo = 0x90; |
5339 #ifdef DEBUG | 5312 #ifdef DEBUG |
5340 static const byte kCallInstruction = 0xe8; | 5313 static const byte kCallInstruction = 0xe8; |
5341 #endif | 5314 #endif |
5342 | 5315 |
5343 | 5316 |
5344 void BackEdgeTable::PatchAt(Code* unoptimized_code, | 5317 void BackEdgeTable::PatchAt(Code* unoptimized_code, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5406 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5379 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
5407 Assembler::target_address_at(call_target_address, | 5380 Assembler::target_address_at(call_target_address, |
5408 unoptimized_code)); | 5381 unoptimized_code)); |
5409 return OSR_AFTER_STACK_CHECK; | 5382 return OSR_AFTER_STACK_CHECK; |
5410 } | 5383 } |
5411 | 5384 |
5412 | 5385 |
5413 } } // namespace v8::internal | 5386 } } // namespace v8::internal |
5414 | 5387 |
5415 #endif // V8_TARGET_ARCH_X64 | 5388 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |