| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 25 matching lines...) Expand all Loading... |
| 36 #include "regexp-macro-assembler.h" | 36 #include "regexp-macro-assembler.h" |
| 37 #include "runtime.h" | 37 #include "runtime.h" |
| 38 #include "stub-cache.h" | 38 #include "stub-cache.h" |
| 39 #include "codegen.h" | 39 #include "codegen.h" |
| 40 #include "runtime.h" | 40 #include "runtime.h" |
| 41 | 41 |
| 42 namespace v8 { | 42 namespace v8 { |
| 43 namespace internal { | 43 namespace internal { |
| 44 | 44 |
| 45 | 45 |
| 46 void FastNewClosureStub::InitializeInterfaceDescriptor( |
| 47 Isolate* isolate, |
| 48 CodeStubInterfaceDescriptor* descriptor) { |
| 49 static Register registers[] = { ebx }; |
| 50 descriptor->register_param_count_ = 1; |
| 51 descriptor->register_params_ = registers; |
| 52 descriptor->deoptimization_handler_ = |
| 53 Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry; |
| 54 } |
| 55 |
| 56 |
| 46 void ToNumberStub::InitializeInterfaceDescriptor( | 57 void ToNumberStub::InitializeInterfaceDescriptor( |
| 47 Isolate* isolate, | 58 Isolate* isolate, |
| 48 CodeStubInterfaceDescriptor* descriptor) { | 59 CodeStubInterfaceDescriptor* descriptor) { |
| 49 static Register registers[] = { eax }; | 60 static Register registers[] = { eax }; |
| 50 descriptor->register_param_count_ = 1; | 61 descriptor->register_param_count_ = 1; |
| 51 descriptor->register_params_ = registers; | 62 descriptor->register_params_ = registers; |
| 52 descriptor->deoptimization_handler_ = NULL; | 63 descriptor->deoptimization_handler_ = NULL; |
| 53 } | 64 } |
| 54 | 65 |
| 55 | 66 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 __ push(descriptor->register_params_[i]); | 303 __ push(descriptor->register_params_[i]); |
| 293 } | 304 } |
| 294 ExternalReference miss = descriptor->miss_handler(); | 305 ExternalReference miss = descriptor->miss_handler(); |
| 295 __ CallExternalReference(miss, descriptor->register_param_count_); | 306 __ CallExternalReference(miss, descriptor->register_param_count_); |
| 296 } | 307 } |
| 297 | 308 |
| 298 __ ret(0); | 309 __ ret(0); |
| 299 } | 310 } |
| 300 | 311 |
| 301 | 312 |
| 302 void FastNewClosureStub::Generate(MacroAssembler* masm) { | |
| 303 // Create a new closure from the given function info in new | |
| 304 // space. Set the context to the current context in esi. | |
| 305 Counters* counters = masm->isolate()->counters(); | |
| 306 | |
| 307 Label gc; | |
| 308 __ Allocate(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); | |
| 309 | |
| 310 __ IncrementCounter(counters->fast_new_closure_total(), 1); | |
| 311 | |
| 312 // Get the function info from the stack. | |
| 313 __ mov(edx, Operand(esp, 1 * kPointerSize)); | |
| 314 | |
| 315 int map_index = Context::FunctionMapIndex(language_mode_, is_generator_); | |
| 316 | |
| 317 // Compute the function map in the current native context and set that | |
| 318 // as the map of the allocated object. | |
| 319 __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); | |
| 320 __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); | |
| 321 __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); | |
| 322 __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); | |
| 323 | |
| 324 // Initialize the rest of the function. We don't have to update the | |
| 325 // write barrier because the allocated object is in new space. | |
| 326 Factory* factory = masm->isolate()->factory(); | |
| 327 __ mov(ebx, Immediate(factory->empty_fixed_array())); | |
| 328 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); | |
| 329 __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); | |
| 330 __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), | |
| 331 Immediate(factory->the_hole_value())); | |
| 332 __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); | |
| 333 __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); | |
| 334 __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); | |
| 335 | |
| 336 // Initialize the code pointer in the function to be the one | |
| 337 // found in the shared function info object. | |
| 338 // But first check if there is an optimized version for our context. | |
| 339 Label check_optimized; | |
| 340 Label install_unoptimized; | |
| 341 if (FLAG_cache_optimized_code) { | |
| 342 __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); | |
| 343 __ test(ebx, ebx); | |
| 344 __ j(not_zero, &check_optimized, Label::kNear); | |
| 345 } | |
| 346 __ bind(&install_unoptimized); | |
| 347 __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), | |
| 348 Immediate(factory->undefined_value())); | |
| 349 __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); | |
| 350 __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); | |
| 351 __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); | |
| 352 | |
| 353 // Return and remove the on-stack parameter. | |
| 354 __ ret(1 * kPointerSize); | |
| 355 | |
| 356 __ bind(&check_optimized); | |
| 357 | |
| 358 __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); | |
| 359 | |
| 360 // ecx holds native context, ebx points to fixed array of 3-element entries | |
| 361 // (native context, optimized code, literals). | |
| 362 // Map must never be empty, so check the first elements. | |
| 363 Label install_optimized; | |
| 364 // Speculatively move code object into edx. | |
| 365 __ mov(edx, FieldOperand(ebx, SharedFunctionInfo::kFirstCodeSlot)); | |
| 366 __ cmp(ecx, FieldOperand(ebx, SharedFunctionInfo::kFirstContextSlot)); | |
| 367 __ j(equal, &install_optimized); | |
| 368 | |
| 369 // Iterate through the rest of map backwards. edx holds an index as a Smi. | |
| 370 Label loop; | |
| 371 Label restore; | |
| 372 __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); | |
| 373 __ bind(&loop); | |
| 374 // Do not double check first entry. | |
| 375 __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kSecondEntryIndex))); | |
| 376 __ j(equal, &restore); | |
| 377 __ sub(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); | |
| 378 __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); | |
| 379 __ j(not_equal, &loop, Label::kNear); | |
| 380 // Hit: fetch the optimized code. | |
| 381 __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); | |
| 382 | |
| 383 __ bind(&install_optimized); | |
| 384 __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); | |
| 385 | |
| 386 // TODO(fschneider): Idea: store proper code pointers in the optimized code | |
| 387 // map and either unmangle them on marking or do nothing as the whole map is | |
| 388 // discarded on major GC anyway. | |
| 389 __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); | |
| 390 __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); | |
| 391 | |
| 392 // Now link a function into a list of optimized functions. | |
| 393 __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); | |
| 394 | |
| 395 __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); | |
| 396 // No need for write barrier as JSFunction (eax) is in the new space. | |
| 397 | |
| 398 __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); | |
| 399 // Store JSFunction (eax) into edx before issuing write barrier as | |
| 400 // it clobbers all the registers passed. | |
| 401 __ mov(edx, eax); | |
| 402 __ RecordWriteContextSlot( | |
| 403 ecx, | |
| 404 Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), | |
| 405 edx, | |
| 406 ebx, | |
| 407 kDontSaveFPRegs); | |
| 408 | |
| 409 // Return and remove the on-stack parameter. | |
| 410 __ ret(1 * kPointerSize); | |
| 411 | |
| 412 __ bind(&restore); | |
| 413 // Restore SharedFunctionInfo into edx. | |
| 414 __ mov(edx, Operand(esp, 1 * kPointerSize)); | |
| 415 __ jmp(&install_unoptimized); | |
| 416 | |
| 417 // Create a new closure through the slower runtime call. | |
| 418 __ bind(&gc); | |
| 419 __ pop(ecx); // Temporarily remove return address. | |
| 420 __ pop(edx); | |
| 421 __ push(esi); | |
| 422 __ push(edx); | |
| 423 __ push(Immediate(factory->false_value())); | |
| 424 __ push(ecx); // Restore return address. | |
| 425 __ TailCallRuntime(Runtime::kNewClosure, 3, 1); | |
| 426 } | |
| 427 | |
| 428 | |
| 429 void FastNewContextStub::Generate(MacroAssembler* masm) { | 313 void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 430 // Try to allocate the context in new space. | 314 // Try to allocate the context in new space. |
| 431 Label gc; | 315 Label gc; |
| 432 int length = slots_ + Context::MIN_CONTEXT_SLOTS; | 316 int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 433 __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, | 317 __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 434 eax, ebx, ecx, &gc, TAG_OBJECT); | 318 eax, ebx, ecx, &gc, TAG_OBJECT); |
| 435 | 319 |
| 436 // Get the function from the stack. | 320 // Get the function from the stack. |
| 437 __ mov(ecx, Operand(esp, 1 * kPointerSize)); | 321 __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 438 | 322 |
| (...skipping 7243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7682 __ bind(&fast_elements_case); | 7566 __ bind(&fast_elements_case); |
| 7683 GenerateCase(masm, FAST_ELEMENTS); | 7567 GenerateCase(masm, FAST_ELEMENTS); |
| 7684 } | 7568 } |
| 7685 | 7569 |
| 7686 | 7570 |
| 7687 #undef __ | 7571 #undef __ |
| 7688 | 7572 |
| 7689 } } // namespace v8::internal | 7573 } } // namespace v8::internal |
| 7690 | 7574 |
| 7691 #endif // V8_TARGET_ARCH_IA32 | 7575 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |