| 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 // Put api_function_address in place. | 455 // Put api_function_address in place. |
| 456 Address function_address = v8::ToCData<Address>(api_call_info->callback()); | 456 Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
| 457 __ mov(api_function_address, Immediate(function_address)); | 457 __ mov(api_function_address, Immediate(function_address)); |
| 458 | 458 |
| 459 // Jump to stub. | 459 // Jump to stub. |
| 460 CallApiFunctionStub stub(restore_context, call_data_undefined, argc); | 460 CallApiFunctionStub stub(restore_context, call_data_undefined, argc); |
| 461 __ TailCallStub(&stub); | 461 __ TailCallStub(&stub); |
| 462 } | 462 } |
| 463 | 463 |
| 464 | 464 |
| 465 // Generates call to API function. | |
| 466 static void GenerateFastApiCall(MacroAssembler* masm, | |
| 467 const CallOptimization& optimization, | |
| 468 int argc, | |
| 469 Handle<Map> map_to_holder, | |
| 470 CallOptimization::HolderLookup holder_lookup) { | |
| 471 Counters* counters = masm->isolate()->counters(); | |
| 472 __ IncrementCounter(counters->call_const_fast_api(), 1); | |
| 473 | |
| 474 // Move holder to a register | |
| 475 Register holder_reg = ecx; | |
| 476 switch (holder_lookup) { | |
| 477 case CallOptimization::kHolderIsReceiver: | |
| 478 { | |
| 479 ASSERT(map_to_holder.is_null()); | |
| 480 __ mov(holder_reg, Operand(esp, (argc + 1)* kPointerSize)); | |
| 481 } | |
| 482 break; | |
| 483 case CallOptimization::kHolderIsPrototypeOfMap: | |
| 484 { | |
| 485 Handle<JSObject> holder(JSObject::cast(map_to_holder->prototype())); | |
| 486 if (!masm->isolate()->heap()->InNewSpace(*holder)) { | |
| 487 __ mov(holder_reg, holder); | |
| 488 } else { | |
| 489 __ mov(holder_reg, map_to_holder); | |
| 490 __ mov(holder_reg, FieldOperand(holder_reg, Map::kPrototypeOffset)); | |
| 491 } | |
| 492 } | |
| 493 break; | |
| 494 case CallOptimization::kHolderNotFound: | |
| 495 UNREACHABLE(); | |
| 496 } | |
| 497 GenerateFastApiCallBody(masm, | |
| 498 optimization, | |
| 499 argc, | |
| 500 holder_reg, | |
| 501 false); | |
| 502 } | |
| 503 | |
| 504 | |
| 505 // Generate call to api function. | 465 // Generate call to api function. |
| 506 // This function uses push() to generate smaller, faster code than | 466 // This function uses push() to generate smaller, faster code than |
| 507 // the version above. It is an optimization that should will be removed | 467 // the version above. It is an optimization that should will be removed |
| 508 // when api call ICs are generated in hydrogen. | 468 // when api call ICs are generated in hydrogen. |
| 509 static void GenerateFastApiCall(MacroAssembler* masm, | 469 static void GenerateFastApiCall(MacroAssembler* masm, |
| 510 const CallOptimization& optimization, | 470 const CallOptimization& optimization, |
| 511 Register receiver, | 471 Register receiver, |
| 512 Register scratch1, | 472 Register scratch1, |
| 513 int argc, | 473 int argc, |
| 514 Register* values) { | 474 Register* values) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 | 565 |
| 606 // Check that the maps from interceptor's holder to constant function's | 566 // Check that the maps from interceptor's holder to constant function's |
| 607 // holder haven't changed and thus we can use cached constant function. | 567 // holder haven't changed and thus we can use cached constant function. |
| 608 if (*interceptor_holder != lookup->holder()) { | 568 if (*interceptor_holder != lookup->holder()) { |
| 609 stub_compiler_->CheckPrototypes( | 569 stub_compiler_->CheckPrototypes( |
| 610 IC::CurrentTypeOf(interceptor_holder, masm->isolate()), holder, | 570 IC::CurrentTypeOf(interceptor_holder, masm->isolate()), holder, |
| 611 handle(lookup->holder()), scratch1, scratch2, scratch3, | 571 handle(lookup->holder()), scratch1, scratch2, scratch3, |
| 612 name, miss_label); | 572 name, miss_label); |
| 613 } | 573 } |
| 614 | 574 |
| 615 Handle<Map> lookup_map; | 575 Handle<JSFunction> fun = optimization.constant_function(); |
| 616 CallOptimization::HolderLookup holder_lookup = | 576 stub_compiler_->GenerateJumpFunction(object, fun); |
| 617 CallOptimization::kHolderNotFound; | |
| 618 if (optimization.is_simple_api_call() && | |
| 619 !lookup->holder()->IsGlobalObject()) { | |
| 620 lookup_map = optimization.LookupHolderOfExpectedType( | |
| 621 object, object, interceptor_holder, &holder_lookup); | |
| 622 if (holder_lookup == CallOptimization::kHolderNotFound) { | |
| 623 lookup_map = | |
| 624 optimization.LookupHolderOfExpectedType( | |
| 625 object, | |
| 626 interceptor_holder, | |
| 627 Handle<JSObject>(lookup->holder()), | |
| 628 &holder_lookup); | |
| 629 } | |
| 630 } | |
| 631 | |
| 632 // Invoke function. | |
| 633 if (holder_lookup != CallOptimization::kHolderNotFound) { | |
| 634 int argc = arguments_.immediate(); | |
| 635 GenerateFastApiCall(masm, | |
| 636 optimization, | |
| 637 argc, | |
| 638 lookup_map, | |
| 639 holder_lookup); | |
| 640 } else { | |
| 641 Handle<JSFunction> fun = optimization.constant_function(); | |
| 642 stub_compiler_->GenerateJumpFunction(object, fun); | |
| 643 } | |
| 644 | 577 |
| 645 // Invoke a regular function. | 578 // Invoke a regular function. |
| 646 __ bind(®ular_invoke); | 579 __ bind(®ular_invoke); |
| 647 } | 580 } |
| 648 | 581 |
| 649 void CompileRegular(MacroAssembler* masm, | 582 void CompileRegular(MacroAssembler* masm, |
| 650 Handle<JSObject> object, | 583 Handle<JSObject> object, |
| 651 Register receiver, | 584 Register receiver, |
| 652 Register scratch1, | 585 Register scratch1, |
| 653 Register scratch2, | 586 Register scratch2, |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 index.translate(holder), Representation::Tagged()); | 1436 index.translate(holder), Representation::Tagged()); |
| 1504 GenerateJumpFunction(object, edi, &miss); | 1437 GenerateJumpFunction(object, edi, &miss); |
| 1505 | 1438 |
| 1506 HandlerFrontendFooter(&miss); | 1439 HandlerFrontendFooter(&miss); |
| 1507 | 1440 |
| 1508 // Return the generated code. | 1441 // Return the generated code. |
| 1509 return GetCode(Code::FAST, name); | 1442 return GetCode(Code::FAST, name); |
| 1510 } | 1443 } |
| 1511 | 1444 |
| 1512 | 1445 |
| 1513 Handle<Code> CallStubCompiler::CompileFastApiCall( | |
| 1514 const CallOptimization& optimization, | |
| 1515 Handle<Object> object, | |
| 1516 Handle<JSObject> holder, | |
| 1517 Handle<Cell> cell, | |
| 1518 Handle<JSFunction> function, | |
| 1519 Handle<String> name) { | |
| 1520 ASSERT(optimization.is_simple_api_call()); | |
| 1521 // Bail out if object is a global object as we don't want to | |
| 1522 // repatch it to global receiver. | |
| 1523 if (object->IsGlobalObject()) return Handle<Code>::null(); | |
| 1524 if (!cell.is_null()) return Handle<Code>::null(); | |
| 1525 if (!object->IsJSObject()) return Handle<Code>::null(); | |
| 1526 Handle<JSObject> receiver = Handle<JSObject>::cast(object); | |
| 1527 CallOptimization::HolderLookup holder_lookup = | |
| 1528 CallOptimization::kHolderNotFound; | |
| 1529 Handle<Map> lookup_map = optimization.LookupHolderOfExpectedType( | |
| 1530 receiver, receiver, holder, &holder_lookup); | |
| 1531 if (holder_lookup == CallOptimization::kHolderNotFound) { | |
| 1532 return Handle<Code>::null(); | |
| 1533 } | |
| 1534 | |
| 1535 Label miss; | |
| 1536 GenerateNameCheck(name, &miss); | |
| 1537 | |
| 1538 // Get the receiver from the stack. | |
| 1539 const int argc = arguments().immediate(); | |
| 1540 __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); | |
| 1541 | |
| 1542 // Check that the receiver isn't a smi. | |
| 1543 __ JumpIfSmi(edx, &miss); | |
| 1544 | |
| 1545 Counters* counters = isolate()->counters(); | |
| 1546 __ IncrementCounter(counters->call_const(), 1); | |
| 1547 | |
| 1548 // Check that the maps haven't changed and find a Holder as a side effect. | |
| 1549 CheckPrototypes(IC::CurrentTypeOf(object, isolate()), edx, holder, | |
| 1550 ebx, eax, edi, name, &miss); | |
| 1551 | |
| 1552 GenerateFastApiCall(masm(), optimization, argc, lookup_map, holder_lookup); | |
| 1553 | |
| 1554 HandlerFrontendFooter(&miss); | |
| 1555 | |
| 1556 // Return the generated code. | |
| 1557 return GetCode(function); | |
| 1558 } | |
| 1559 | |
| 1560 | |
| 1561 void StubCompiler::GenerateBooleanCheck(Register object, Label* miss) { | 1446 void StubCompiler::GenerateBooleanCheck(Register object, Label* miss) { |
| 1562 Label success; | 1447 Label success; |
| 1563 // Check that the object is a boolean. | 1448 // Check that the object is a boolean. |
| 1564 __ cmp(object, factory()->true_value()); | 1449 __ cmp(object, factory()->true_value()); |
| 1565 __ j(equal, &success); | 1450 __ j(equal, &success); |
| 1566 __ cmp(object, factory()->false_value()); | 1451 __ cmp(object, factory()->false_value()); |
| 1567 __ j(not_equal, miss); | 1452 __ j(not_equal, miss); |
| 1568 __ bind(&success); | 1453 __ bind(&success); |
| 1569 } | 1454 } |
| 1570 | 1455 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1705 return GetCode(Code::FAST, name); | 1590 return GetCode(Code::FAST, name); |
| 1706 } | 1591 } |
| 1707 | 1592 |
| 1708 | 1593 |
| 1709 Handle<Code> CallStubCompiler::CompileCallGlobal( | 1594 Handle<Code> CallStubCompiler::CompileCallGlobal( |
| 1710 Handle<JSObject> object, | 1595 Handle<JSObject> object, |
| 1711 Handle<GlobalObject> holder, | 1596 Handle<GlobalObject> holder, |
| 1712 Handle<PropertyCell> cell, | 1597 Handle<PropertyCell> cell, |
| 1713 Handle<JSFunction> function, | 1598 Handle<JSFunction> function, |
| 1714 Handle<Name> name) { | 1599 Handle<Name> name) { |
| 1715 if (HasCustomCallGenerator(function)) { | |
| 1716 Handle<Code> code = CompileCustomCall( | |
| 1717 object, holder, cell, function, Handle<String>::cast(name), | |
| 1718 Code::NORMAL); | |
| 1719 // A null handle means bail out to the regular compiler code below. | |
| 1720 if (!code.is_null()) return code; | |
| 1721 } | |
| 1722 | |
| 1723 Label miss; | 1600 Label miss; |
| 1724 HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); | 1601 HandlerFrontendHeader(object, holder, name, RECEIVER_MAP_CHECK, &miss); |
| 1725 // Potentially loads a closure that matches the shared function info of the | 1602 // Potentially loads a closure that matches the shared function info of the |
| 1726 // function, rather than function. | 1603 // function, rather than function. |
| 1727 GenerateLoadFunctionFromCell(cell, function, &miss); | 1604 GenerateLoadFunctionFromCell(cell, function, &miss); |
| 1728 GenerateJumpFunction(object, edi, function); | 1605 GenerateJumpFunction(object, edi, function); |
| 1729 | 1606 |
| 1730 HandlerFrontendFooter(&miss); | 1607 HandlerFrontendFooter(&miss); |
| 1731 | 1608 |
| 1732 // Return the generated code. | 1609 // Return the generated code. |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 // ----------------------------------- | 1957 // ----------------------------------- |
| 2081 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); | 1958 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); |
| 2082 } | 1959 } |
| 2083 | 1960 |
| 2084 | 1961 |
| 2085 #undef __ | 1962 #undef __ |
| 2086 | 1963 |
| 2087 } } // namespace v8::internal | 1964 } } // namespace v8::internal |
| 2088 | 1965 |
| 2089 #endif // V8_TARGET_ARCH_IA32 | 1966 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |