| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 4403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4414 #ifdef ENABLE_DEBUGGER_SUPPORT | 4414 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 4415 // Spill everything, even constants, to the frame. | 4415 // Spill everything, even constants, to the frame. |
| 4416 frame_->SpillAll(); | 4416 frame_->SpillAll(); |
| 4417 | 4417 |
| 4418 frame_->DebugBreak(); | 4418 frame_->DebugBreak(); |
| 4419 // Ignore the return value. | 4419 // Ignore the return value. |
| 4420 #endif | 4420 #endif |
| 4421 } | 4421 } |
| 4422 | 4422 |
| 4423 | 4423 |
| 4424 Result CodeGenerator::InstantiateBoilerplate(Handle<JSFunction> boilerplate) { | 4424 Result CodeGenerator::InstantiateFunction( |
| 4425 ASSERT(boilerplate->IsBoilerplate()); | 4425 Handle<SharedFunctionInfo> function_info) { |
| 4426 | |
| 4427 // The inevitable call will sync frame elements to memory anyway, so | 4426 // The inevitable call will sync frame elements to memory anyway, so |
| 4428 // we do it eagerly to allow us to push the arguments directly into | 4427 // we do it eagerly to allow us to push the arguments directly into |
| 4429 // place. | 4428 // place. |
| 4430 frame()->SyncRange(0, frame()->element_count() - 1); | 4429 frame()->SyncRange(0, frame()->element_count() - 1); |
| 4431 | 4430 |
| 4432 // Use the fast case closure allocation code that allocates in new | 4431 // Use the fast case closure allocation code that allocates in new |
| 4433 // space for nested functions that don't need literals cloning. | 4432 // space for nested functions that don't need literals cloning. |
| 4434 if (scope()->is_function_scope() && boilerplate->NumberOfLiterals() == 0) { | 4433 if (scope()->is_function_scope() && function_info->num_literals() == 0) { |
| 4435 FastNewClosureStub stub; | 4434 FastNewClosureStub stub; |
| 4436 frame()->EmitPush(Immediate(boilerplate)); | 4435 frame()->EmitPush(Immediate(function_info)); |
| 4437 return frame()->CallStub(&stub, 1); | 4436 return frame()->CallStub(&stub, 1); |
| 4438 } else { | 4437 } else { |
| 4439 // Call the runtime to instantiate the function boilerplate | 4438 // Call the runtime to instantiate the function boilerplate |
| 4440 // object. | 4439 // object. |
| 4441 frame()->EmitPush(esi); | 4440 frame()->EmitPush(esi); |
| 4442 frame()->EmitPush(Immediate(boilerplate)); | 4441 frame()->EmitPush(Immediate(function_info)); |
| 4443 return frame()->CallRuntime(Runtime::kNewClosure, 2); | 4442 return frame()->CallRuntime(Runtime::kNewClosure, 2); |
| 4444 } | 4443 } |
| 4445 } | 4444 } |
| 4446 | 4445 |
| 4447 | 4446 |
| 4448 void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) { | 4447 void CodeGenerator::VisitFunctionLiteral(FunctionLiteral* node) { |
| 4449 Comment cmnt(masm_, "[ FunctionLiteral"); | 4448 Comment cmnt(masm_, "[ FunctionLiteral"); |
| 4450 ASSERT(!in_safe_int32_mode()); | 4449 ASSERT(!in_safe_int32_mode()); |
| 4451 // Build the function boilerplate and instantiate it. | 4450 // Build the function info and instantiate it. |
| 4452 Handle<JSFunction> boilerplate = | 4451 Handle<SharedFunctionInfo> function_info = |
| 4453 Compiler::BuildBoilerplate(node, script(), this); | 4452 Compiler::BuildFunctionInfo(node, script(), this); |
| 4454 // Check for stack-overflow exception. | 4453 // Check for stack-overflow exception. |
| 4455 if (HasStackOverflow()) return; | 4454 if (HasStackOverflow()) return; |
| 4456 Result result = InstantiateBoilerplate(boilerplate); | 4455 Result result = InstantiateFunction(function_info); |
| 4457 frame()->Push(&result); | 4456 frame()->Push(&result); |
| 4458 } | 4457 } |
| 4459 | 4458 |
| 4460 | 4459 |
| 4461 void CodeGenerator::VisitFunctionBoilerplateLiteral( | 4460 void CodeGenerator::VisitSharedFunctionInfoLiteral( |
| 4462 FunctionBoilerplateLiteral* node) { | 4461 SharedFunctionInfoLiteral* node) { |
| 4463 ASSERT(!in_safe_int32_mode()); | 4462 ASSERT(!in_safe_int32_mode()); |
| 4464 Comment cmnt(masm_, "[ FunctionBoilerplateLiteral"); | 4463 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); |
| 4465 Result result = InstantiateBoilerplate(node->boilerplate()); | 4464 Result result = InstantiateFunction(node->shared_function_info()); |
| 4466 frame()->Push(&result); | 4465 frame()->Push(&result); |
| 4467 } | 4466 } |
| 4468 | 4467 |
| 4469 | 4468 |
| 4470 void CodeGenerator::VisitConditional(Conditional* node) { | 4469 void CodeGenerator::VisitConditional(Conditional* node) { |
| 4471 Comment cmnt(masm_, "[ Conditional"); | 4470 Comment cmnt(masm_, "[ Conditional"); |
| 4472 ASSERT(!in_safe_int32_mode()); | 4471 ASSERT(!in_safe_int32_mode()); |
| 4473 JumpTarget then; | 4472 JumpTarget then; |
| 4474 JumpTarget else_; | 4473 JumpTarget else_; |
| 4475 JumpTarget exit; | 4474 JumpTarget exit; |
| (...skipping 3722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8198 } | 8197 } |
| 8199 | 8198 |
| 8200 case UNLOADED: | 8199 case UNLOADED: |
| 8201 case ILLEGAL: | 8200 case ILLEGAL: |
| 8202 UNREACHABLE(); | 8201 UNREACHABLE(); |
| 8203 } | 8202 } |
| 8204 } | 8203 } |
| 8205 | 8204 |
| 8206 | 8205 |
| 8207 void FastNewClosureStub::Generate(MacroAssembler* masm) { | 8206 void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 8208 // Clone the boilerplate in new space. Set the context to the | 8207 // Create a new closure from the given function info in new |
| 8209 // current context in esi. | 8208 // space. Set the context to the current context in esi. |
| 8210 Label gc; | 8209 Label gc; |
| 8211 __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); | 8210 __ AllocateInNewSpace(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
| 8212 | 8211 |
| 8213 // Get the boilerplate function from the stack. | 8212 // Get the function info from the stack. |
| 8214 __ mov(edx, Operand(esp, 1 * kPointerSize)); | 8213 __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 8215 | 8214 |
| 8216 // Compute the function map in the current global context and set that | 8215 // Compute the function map in the current global context and set that |
| 8217 // as the map of the allocated object. | 8216 // as the map of the allocated object. |
| 8218 __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); | 8217 __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 8219 __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset)); | 8218 __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalContextOffset)); |
| 8220 __ mov(ecx, Operand(ecx, Context::SlotOffset(Context::FUNCTION_MAP_INDEX))); | 8219 __ mov(ecx, Operand(ecx, Context::SlotOffset(Context::FUNCTION_MAP_INDEX))); |
| 8221 __ mov(FieldOperand(eax, JSObject::kMapOffset), ecx); | 8220 __ mov(FieldOperand(eax, JSObject::kMapOffset), ecx); |
| 8222 | 8221 |
| 8223 // Clone the rest of the boilerplate fields. We don't have to update | 8222 // Initialize the rest of the function. We don't have to update the |
| 8224 // the write barrier because the allocated object is in new space. | 8223 // write barrier because the allocated object is in new space. |
| 8225 for (int offset = kPointerSize; | 8224 __ mov(ebx, Immediate(Factory::empty_fixed_array())); |
| 8226 offset < JSFunction::kSize; | 8225 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 8227 offset += kPointerSize) { | 8226 __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 8228 if (offset == JSFunction::kContextOffset) { | 8227 __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
| 8229 __ mov(FieldOperand(eax, offset), esi); | 8228 Immediate(Factory::the_hole_value())); |
| 8230 } else { | 8229 __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 8231 __ mov(ebx, FieldOperand(edx, offset)); | 8230 __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 8232 __ mov(FieldOperand(eax, offset), ebx); | 8231 __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 8233 } | |
| 8234 } | |
| 8235 | 8232 |
| 8236 // Return and remove the on-stack parameter. | 8233 // Return and remove the on-stack parameter. |
| 8237 __ ret(1 * kPointerSize); | 8234 __ ret(1 * kPointerSize); |
| 8238 | 8235 |
| 8239 // Create a new closure through the slower runtime call. | 8236 // Create a new closure through the slower runtime call. |
| 8240 __ bind(&gc); | 8237 __ bind(&gc); |
| 8241 __ pop(ecx); // Temporarily remove return address. | 8238 __ pop(ecx); // Temporarily remove return address. |
| 8242 __ pop(edx); | 8239 __ pop(edx); |
| 8243 __ push(esi); | 8240 __ push(esi); |
| 8244 __ push(edx); | 8241 __ push(edx); |
| (...skipping 3282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11527 return "CompareStub_EQ"; | 11524 return "CompareStub_EQ"; |
| 11528 } | 11525 } |
| 11529 } | 11526 } |
| 11530 } | 11527 } |
| 11531 default: return "CompareStub"; | 11528 default: return "CompareStub"; |
| 11532 } | 11529 } |
| 11533 } | 11530 } |
| 11534 | 11531 |
| 11535 | 11532 |
| 11536 int CompareStub::MinorKey() { | 11533 int CompareStub::MinorKey() { |
| 11537 // Encode the three parameters in a unique 16 bit value. | 11534 // Encode the three parameters in a unique 16 bit value. To avoid duplicate |
| 11535 // stubs the never NaN NaN condition is only taken into account if the |
| 11536 // condition is equals. |
| 11538 ASSERT(static_cast<unsigned>(cc_) < (1 << 14)); | 11537 ASSERT(static_cast<unsigned>(cc_) < (1 << 14)); |
| 11539 int nnn_value = (never_nan_nan_ ? 2 : 0); | 11538 return ConditionField::encode(static_cast<unsigned>(cc_)) |
| 11540 if (cc_ != equal) nnn_value = 0; // Avoid duplicate stubs. | 11539 | StrictField::encode(strict_) |
| 11541 return (static_cast<unsigned>(cc_) << 2) | nnn_value | (strict_ ? 1 : 0); | 11540 | NeverNanNanField::encode(cc_ == equal ? never_nan_nan_ : false); |
| 11542 } | 11541 } |
| 11543 | 11542 |
| 11544 | 11543 |
| 11545 void StringAddStub::Generate(MacroAssembler* masm) { | 11544 void StringAddStub::Generate(MacroAssembler* masm) { |
| 11546 Label string_add_runtime; | 11545 Label string_add_runtime; |
| 11547 | 11546 |
| 11548 // Load the two arguments. | 11547 // Load the two arguments. |
| 11549 __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. | 11548 __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 11550 __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. | 11549 __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 11551 | 11550 |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12274 | 12273 |
| 12275 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) | 12274 // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 12276 // tagged as a small integer. | 12275 // tagged as a small integer. |
| 12277 __ bind(&runtime); | 12276 __ bind(&runtime); |
| 12278 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); | 12277 __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 12279 } | 12278 } |
| 12280 | 12279 |
| 12281 #undef __ | 12280 #undef __ |
| 12282 | 12281 |
| 12283 } } // namespace v8::internal | 12282 } } // namespace v8::internal |
| OLD | NEW |