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_X87 | 7 #if V8_TARGET_ARCH_X87 |
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 edi: the JS function object being called (i.e. ourselves) | 88 // o edi: the JS function object being called (i.e. ourselves) |
89 // o esi: our context | 89 // o esi: our context |
90 // o ebp: our caller's frame pointer | 90 // o ebp: our caller's frame pointer |
91 // o esp: stack pointer (pointing to return address) | 91 // o esp: 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-x87.h for its layout. | 94 // frames-x87.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 1992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2101 Label l_next, l_call, l_loop; | 2102 Label l_next, l_call, l_loop; |
2102 Register load_receiver = LoadDescriptor::ReceiverRegister(); | 2103 Register load_receiver = LoadDescriptor::ReceiverRegister(); |
2103 Register load_name = LoadDescriptor::NameRegister(); | 2104 Register load_name = LoadDescriptor::NameRegister(); |
2104 | 2105 |
2105 // Initial send value is undefined. | 2106 // Initial send value is undefined. |
2106 __ mov(eax, isolate()->factory()->undefined_value()); | 2107 __ mov(eax, isolate()->factory()->undefined_value()); |
2107 __ jmp(&l_next); | 2108 __ jmp(&l_next); |
2108 | 2109 |
2109 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } | 2110 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
2110 __ bind(&l_catch); | 2111 __ bind(&l_catch); |
2111 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); | |
2112 __ mov(load_name, isolate()->factory()->throw_string()); // "throw" | 2112 __ mov(load_name, isolate()->factory()->throw_string()); // "throw" |
2113 __ push(load_name); // "throw" | 2113 __ push(load_name); // "throw" |
2114 __ push(Operand(esp, 2 * kPointerSize)); // iter | 2114 __ push(Operand(esp, 2 * kPointerSize)); // iter |
2115 __ push(eax); // exception | 2115 __ push(eax); // exception |
2116 __ jmp(&l_call); | 2116 __ jmp(&l_call); |
2117 | 2117 |
2118 // try { received = %yield result } | 2118 // try { received = %yield result } |
2119 // Shuffle the received result above a try handler and yield it without | 2119 // Shuffle the received result above a try handler and yield it without |
2120 // re-boxing. | 2120 // re-boxing. |
2121 __ bind(&l_try); | 2121 __ bind(&l_try); |
2122 __ pop(eax); // result | 2122 __ pop(eax); // result |
2123 __ PushTryHandler(StackHandler::CATCH, expr->index()); | 2123 EnterTryBlock(expr->index(), &l_catch); |
2124 const int handler_size = StackHandlerConstants::kSize; | 2124 const int try_block_size = TryCatch::kElementCount * kPointerSize; |
2125 __ push(eax); // result | 2125 __ push(eax); // result |
2126 __ jmp(&l_suspend); | 2126 __ jmp(&l_suspend); |
2127 __ bind(&l_continuation); | 2127 __ bind(&l_continuation); |
2128 __ jmp(&l_resume); | 2128 __ jmp(&l_resume); |
2129 __ bind(&l_suspend); | 2129 __ bind(&l_suspend); |
2130 const int generator_object_depth = kPointerSize + handler_size; | 2130 const int generator_object_depth = kPointerSize + try_block_size; |
2131 __ mov(eax, Operand(esp, generator_object_depth)); | 2131 __ mov(eax, Operand(esp, generator_object_depth)); |
2132 __ push(eax); // g | 2132 __ push(eax); // g |
| 2133 __ push(Immediate(Smi::FromInt(expr->index()))); // handler-index |
2133 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); | 2134 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
2134 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), | 2135 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
2135 Immediate(Smi::FromInt(l_continuation.pos()))); | 2136 Immediate(Smi::FromInt(l_continuation.pos()))); |
2136 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); | 2137 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
2137 __ mov(ecx, esi); | 2138 __ mov(ecx, esi); |
2138 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, | 2139 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
2139 kDontSaveFPRegs); | 2140 kDontSaveFPRegs); |
2140 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 2141 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2); |
2141 __ mov(context_register(), | 2142 __ mov(context_register(), |
2142 Operand(ebp, StandardFrameConstants::kContextOffset)); | 2143 Operand(ebp, StandardFrameConstants::kContextOffset)); |
2143 __ pop(eax); // result | 2144 __ pop(eax); // result |
2144 EmitReturnSequence(); | 2145 EmitReturnSequence(); |
2145 __ bind(&l_resume); // received in eax | 2146 __ bind(&l_resume); // received in eax |
2146 __ PopTryHandler(); | 2147 ExitTryBlock(expr->index()); |
2147 | 2148 |
2148 // receiver = iter; f = iter.next; arg = received; | 2149 // receiver = iter; f = iter.next; arg = received; |
2149 __ bind(&l_next); | 2150 __ bind(&l_next); |
2150 | 2151 |
2151 __ mov(load_name, isolate()->factory()->next_string()); | 2152 __ mov(load_name, isolate()->factory()->next_string()); |
2152 __ push(load_name); // "next" | 2153 __ push(load_name); // "next" |
2153 __ push(Operand(esp, 2 * kPointerSize)); // iter | 2154 __ push(Operand(esp, 2 * kPointerSize)); // iter |
2154 __ push(eax); // received | 2155 __ push(eax); // received |
2155 | 2156 |
2156 // result = receiver[f](arg); | 2157 // result = receiver[f](arg); |
(...skipping 3104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5261 // Uncook return address. | 5262 // Uncook return address. |
5262 __ pop(edx); | 5263 __ pop(edx); |
5263 __ SmiUntag(edx); | 5264 __ SmiUntag(edx); |
5264 __ add(edx, Immediate(masm_->CodeObject())); | 5265 __ add(edx, Immediate(masm_->CodeObject())); |
5265 __ jmp(edx); | 5266 __ jmp(edx); |
5266 } | 5267 } |
5267 | 5268 |
5268 | 5269 |
5269 #undef __ | 5270 #undef __ |
5270 | 5271 |
5271 #define __ ACCESS_MASM(masm()) | |
5272 | |
5273 FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( | |
5274 int* stack_depth, | |
5275 int* context_length) { | |
5276 // The macros used here must preserve the result register. | |
5277 | |
5278 // Because the handler block contains the context of the finally | |
5279 // code, we can restore it directly from there for the finally code | |
5280 // rather than iteratively unwinding contexts via their previous | |
5281 // links. | |
5282 __ Drop(*stack_depth); // Down to the handler block. | |
5283 if (*context_length > 0) { | |
5284 // Restore the context to its dedicated register and the stack. | |
5285 __ mov(esi, Operand(esp, StackHandlerConstants::kContextOffset)); | |
5286 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); | |
5287 } | |
5288 __ PopTryHandler(); | |
5289 __ call(finally_entry_); | |
5290 | |
5291 *stack_depth = 0; | |
5292 *context_length = 0; | |
5293 return previous_; | |
5294 } | |
5295 | |
5296 #undef __ | |
5297 | |
5298 | 5272 |
5299 static const byte kJnsInstruction = 0x79; | 5273 static const byte kJnsInstruction = 0x79; |
5300 static const byte kJnsOffset = 0x11; | 5274 static const byte kJnsOffset = 0x11; |
5301 static const byte kNopByteOne = 0x66; | 5275 static const byte kNopByteOne = 0x66; |
5302 static const byte kNopByteTwo = 0x90; | 5276 static const byte kNopByteTwo = 0x90; |
5303 #ifdef DEBUG | 5277 #ifdef DEBUG |
5304 static const byte kCallInstruction = 0xe8; | 5278 static const byte kCallInstruction = 0xe8; |
5305 #endif | 5279 #endif |
5306 | 5280 |
5307 | 5281 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5369 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5343 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
5370 Assembler::target_address_at(call_target_address, | 5344 Assembler::target_address_at(call_target_address, |
5371 unoptimized_code)); | 5345 unoptimized_code)); |
5372 return OSR_AFTER_STACK_CHECK; | 5346 return OSR_AFTER_STACK_CHECK; |
5373 } | 5347 } |
5374 | 5348 |
5375 | 5349 |
5376 } } // namespace v8::internal | 5350 } } // namespace v8::internal |
5377 | 5351 |
5378 #endif // V8_TARGET_ARCH_X87 | 5352 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |