| 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_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
| 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-ia32.h for its layout. | 94 // frames-ia32.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 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2107 Label l_next, l_call, l_loop; | 2108 Label l_next, l_call, l_loop; |
| 2108 Register load_receiver = LoadDescriptor::ReceiverRegister(); | 2109 Register load_receiver = LoadDescriptor::ReceiverRegister(); |
| 2109 Register load_name = LoadDescriptor::NameRegister(); | 2110 Register load_name = LoadDescriptor::NameRegister(); |
| 2110 | 2111 |
| 2111 // Initial send value is undefined. | 2112 // Initial send value is undefined. |
| 2112 __ mov(eax, isolate()->factory()->undefined_value()); | 2113 __ mov(eax, isolate()->factory()->undefined_value()); |
| 2113 __ jmp(&l_next); | 2114 __ jmp(&l_next); |
| 2114 | 2115 |
| 2115 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } | 2116 // catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; } |
| 2116 __ bind(&l_catch); | 2117 __ bind(&l_catch); |
| 2117 handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos())); | |
| 2118 __ mov(load_name, isolate()->factory()->throw_string()); // "throw" | 2118 __ mov(load_name, isolate()->factory()->throw_string()); // "throw" |
| 2119 __ push(load_name); // "throw" | 2119 __ push(load_name); // "throw" |
| 2120 __ push(Operand(esp, 2 * kPointerSize)); // iter | 2120 __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2121 __ push(eax); // exception | 2121 __ push(eax); // exception |
| 2122 __ jmp(&l_call); | 2122 __ jmp(&l_call); |
| 2123 | 2123 |
| 2124 // try { received = %yield result } | 2124 // try { received = %yield result } |
| 2125 // Shuffle the received result above a try handler and yield it without | 2125 // Shuffle the received result above a try handler and yield it without |
| 2126 // re-boxing. | 2126 // re-boxing. |
| 2127 __ bind(&l_try); | 2127 __ bind(&l_try); |
| 2128 __ pop(eax); // result | 2128 __ pop(eax); // result |
| 2129 __ PushTryHandler(StackHandler::CATCH, expr->index()); | 2129 EnterTryBlock(expr->index(), &l_catch); |
| 2130 const int handler_size = StackHandlerConstants::kSize; | 2130 const int try_block_size = TryCatch::kElementCount * kPointerSize; |
| 2131 __ push(eax); // result | 2131 __ push(eax); // result |
| 2132 __ jmp(&l_suspend); | 2132 __ jmp(&l_suspend); |
| 2133 __ bind(&l_continuation); | 2133 __ bind(&l_continuation); |
| 2134 __ jmp(&l_resume); | 2134 __ jmp(&l_resume); |
| 2135 __ bind(&l_suspend); | 2135 __ bind(&l_suspend); |
| 2136 const int generator_object_depth = kPointerSize + handler_size; | 2136 const int generator_object_depth = kPointerSize + try_block_size; |
| 2137 __ mov(eax, Operand(esp, generator_object_depth)); | 2137 __ mov(eax, Operand(esp, generator_object_depth)); |
| 2138 __ push(eax); // g | 2138 __ push(eax); // g |
| 2139 __ push(Immediate(Smi::FromInt(expr->index()))); // handler-index |
| 2139 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); | 2140 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); |
| 2140 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), | 2141 __ mov(FieldOperand(eax, JSGeneratorObject::kContinuationOffset), |
| 2141 Immediate(Smi::FromInt(l_continuation.pos()))); | 2142 Immediate(Smi::FromInt(l_continuation.pos()))); |
| 2142 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); | 2143 __ mov(FieldOperand(eax, JSGeneratorObject::kContextOffset), esi); |
| 2143 __ mov(ecx, esi); | 2144 __ mov(ecx, esi); |
| 2144 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, | 2145 __ RecordWriteField(eax, JSGeneratorObject::kContextOffset, ecx, edx, |
| 2145 kDontSaveFPRegs); | 2146 kDontSaveFPRegs); |
| 2146 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 2147 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 2); |
| 2147 __ mov(context_register(), | 2148 __ mov(context_register(), |
| 2148 Operand(ebp, StandardFrameConstants::kContextOffset)); | 2149 Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2149 __ pop(eax); // result | 2150 __ pop(eax); // result |
| 2150 EmitReturnSequence(); | 2151 EmitReturnSequence(); |
| 2151 __ bind(&l_resume); // received in eax | 2152 __ bind(&l_resume); // received in eax |
| 2152 __ PopTryHandler(); | 2153 ExitTryBlock(expr->index()); |
| 2153 | 2154 |
| 2154 // receiver = iter; f = iter.next; arg = received; | 2155 // receiver = iter; f = iter.next; arg = received; |
| 2155 __ bind(&l_next); | 2156 __ bind(&l_next); |
| 2156 | 2157 |
| 2157 __ mov(load_name, isolate()->factory()->next_string()); | 2158 __ mov(load_name, isolate()->factory()->next_string()); |
| 2158 __ push(load_name); // "next" | 2159 __ push(load_name); // "next" |
| 2159 __ push(Operand(esp, 2 * kPointerSize)); // iter | 2160 __ push(Operand(esp, 2 * kPointerSize)); // iter |
| 2160 __ push(eax); // received | 2161 __ push(eax); // received |
| 2161 | 2162 |
| 2162 // result = receiver[f](arg); | 2163 // result = receiver[f](arg); |
| (...skipping 3106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5269 // Uncook return address. | 5270 // Uncook return address. |
| 5270 __ pop(edx); | 5271 __ pop(edx); |
| 5271 __ SmiUntag(edx); | 5272 __ SmiUntag(edx); |
| 5272 __ add(edx, Immediate(masm_->CodeObject())); | 5273 __ add(edx, Immediate(masm_->CodeObject())); |
| 5273 __ jmp(edx); | 5274 __ jmp(edx); |
| 5274 } | 5275 } |
| 5275 | 5276 |
| 5276 | 5277 |
| 5277 #undef __ | 5278 #undef __ |
| 5278 | 5279 |
| 5279 #define __ ACCESS_MASM(masm()) | |
| 5280 | |
| 5281 FullCodeGenerator::NestedStatement* FullCodeGenerator::TryFinally::Exit( | |
| 5282 int* stack_depth, | |
| 5283 int* context_length) { | |
| 5284 // The macros used here must preserve the result register. | |
| 5285 | |
| 5286 // Because the handler block contains the context of the finally | |
| 5287 // code, we can restore it directly from there for the finally code | |
| 5288 // rather than iteratively unwinding contexts via their previous | |
| 5289 // links. | |
| 5290 __ Drop(*stack_depth); // Down to the handler block. | |
| 5291 if (*context_length > 0) { | |
| 5292 // Restore the context to its dedicated register and the stack. | |
| 5293 __ mov(esi, Operand(esp, StackHandlerConstants::kContextOffset)); | |
| 5294 __ mov(Operand(ebp, StandardFrameConstants::kContextOffset), esi); | |
| 5295 } | |
| 5296 __ PopTryHandler(); | |
| 5297 __ call(finally_entry_); | |
| 5298 | |
| 5299 *stack_depth = 0; | |
| 5300 *context_length = 0; | |
| 5301 return previous_; | |
| 5302 } | |
| 5303 | |
| 5304 #undef __ | |
| 5305 | |
| 5306 | 5280 |
| 5307 static const byte kJnsInstruction = 0x79; | 5281 static const byte kJnsInstruction = 0x79; |
| 5308 static const byte kJnsOffset = 0x11; | 5282 static const byte kJnsOffset = 0x11; |
| 5309 static const byte kNopByteOne = 0x66; | 5283 static const byte kNopByteOne = 0x66; |
| 5310 static const byte kNopByteTwo = 0x90; | 5284 static const byte kNopByteTwo = 0x90; |
| 5311 #ifdef DEBUG | 5285 #ifdef DEBUG |
| 5312 static const byte kCallInstruction = 0xe8; | 5286 static const byte kCallInstruction = 0xe8; |
| 5313 #endif | 5287 #endif |
| 5314 | 5288 |
| 5315 | 5289 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5377 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), | 5351 DCHECK_EQ(isolate->builtins()->OsrAfterStackCheck()->entry(), |
| 5378 Assembler::target_address_at(call_target_address, | 5352 Assembler::target_address_at(call_target_address, |
| 5379 unoptimized_code)); | 5353 unoptimized_code)); |
| 5380 return OSR_AFTER_STACK_CHECK; | 5354 return OSR_AFTER_STACK_CHECK; |
| 5381 } | 5355 } |
| 5382 | 5356 |
| 5383 | 5357 |
| 5384 } } // namespace v8::internal | 5358 } } // namespace v8::internal |
| 5385 | 5359 |
| 5386 #endif // V8_TARGET_ARCH_IA32 | 5360 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |