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 #include "src/bailout-reason.h" | 7 #include "src/bailout-reason.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/field-index.h" | 9 #include "src/field-index.h" |
10 #include "src/hydrogen.h" | 10 #include "src/hydrogen.h" |
(...skipping 1515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1526 template<> | 1526 template<> |
1527 HValue* CodeStubGraphBuilder<FastNewClosureStub>::BuildCodeStub() { | 1527 HValue* CodeStubGraphBuilder<FastNewClosureStub>::BuildCodeStub() { |
1528 Counters* counters = isolate()->counters(); | 1528 Counters* counters = isolate()->counters(); |
1529 Factory* factory = isolate()->factory(); | 1529 Factory* factory = isolate()->factory(); |
1530 HInstruction* empty_fixed_array = | 1530 HInstruction* empty_fixed_array = |
1531 Add<HConstant>(factory->empty_fixed_array()); | 1531 Add<HConstant>(factory->empty_fixed_array()); |
1532 HValue* shared_info = GetParameter(0); | 1532 HValue* shared_info = GetParameter(0); |
1533 | 1533 |
1534 AddIncrementCounter(counters->fast_new_closure_total()); | 1534 AddIncrementCounter(counters->fast_new_closure_total()); |
1535 | 1535 |
1536 IfBuilder optimize_now(this); | 1536 // Create a new closure from the given function info in new space |
1537 HInstruction* compile_hint = Add<HLoadNamedField>( | 1537 HValue* size = Add<HConstant>(JSFunction::kSize); |
1538 shared_info, static_cast<HValue*>(NULL), HObjectAccess::ForCompileHint()); | 1538 HInstruction* js_function = Add<HAllocate>(size, HType::JSObject(), |
1539 HValue* hint_mask = Add<HConstant>( | 1539 NOT_TENURED, JS_FUNCTION_TYPE); |
1540 static_cast<int32_t>(1 << SharedFunctionInfo::kOptimizeNextClosure)); | 1540 |
1541 HInstruction* optimize = | 1541 int map_index = Context::FunctionMapIndex(casted_stub()->strict_mode(), |
1542 AddUncasted<HBitwise>(Token::BIT_AND, compile_hint, hint_mask); | 1542 casted_stub()->kind()); |
1543 optimize_now.If<HCompareNumericAndBranch>(optimize, hint_mask, Token::EQ); | 1543 |
1544 optimize_now.Then(); | 1544 // Compute the function map in the current native context and set that |
1545 { | 1545 // as the map of the allocated object. |
1546 Add<HPushArguments>(context(), shared_info, graph()->GetConstantFalse()); | 1546 HInstruction* native_context = BuildGetNativeContext(); |
1547 Push(Add<HCallRuntime>(isolate()->factory()->empty_string(), | 1547 HInstruction* map_slot_value = Add<HLoadNamedField>( |
1548 Runtime::FunctionForId(Runtime::kNewClosure), 3)); | 1548 native_context, static_cast<HValue*>(NULL), |
| 1549 HObjectAccess::ForContextSlot(map_index)); |
| 1550 Add<HStoreNamedField>(js_function, HObjectAccess::ForMap(), map_slot_value); |
| 1551 |
| 1552 // Initialize the rest of the function. |
| 1553 Add<HStoreNamedField>(js_function, HObjectAccess::ForPropertiesPointer(), |
| 1554 empty_fixed_array); |
| 1555 Add<HStoreNamedField>(js_function, HObjectAccess::ForElementsPointer(), |
| 1556 empty_fixed_array); |
| 1557 Add<HStoreNamedField>(js_function, HObjectAccess::ForLiteralsPointer(), |
| 1558 empty_fixed_array); |
| 1559 Add<HStoreNamedField>(js_function, HObjectAccess::ForPrototypeOrInitialMap(), |
| 1560 graph()->GetConstantHole()); |
| 1561 Add<HStoreNamedField>(js_function, |
| 1562 HObjectAccess::ForSharedFunctionInfoPointer(), |
| 1563 shared_info); |
| 1564 Add<HStoreNamedField>(js_function, HObjectAccess::ForFunctionContextPointer(), |
| 1565 context()); |
| 1566 |
| 1567 // Initialize the code pointer in the function to be the one |
| 1568 // found in the shared function info object. |
| 1569 // But first check if there is an optimized version for our context. |
| 1570 if (FLAG_cache_optimized_code) { |
| 1571 BuildInstallFromOptimizedCodeMap(js_function, shared_info, native_context); |
| 1572 } else { |
| 1573 BuildInstallCode(js_function, shared_info); |
1549 } | 1574 } |
1550 optimize_now.Else(); | |
1551 { | |
1552 // Create a new closure from the given function info in new space | |
1553 HValue* size = Add<HConstant>(JSFunction::kSize); | |
1554 HInstruction* js_function = | |
1555 Add<HAllocate>(size, HType::JSObject(), NOT_TENURED, JS_FUNCTION_TYPE); | |
1556 | 1575 |
1557 int map_index = Context::FunctionMapIndex(casted_stub()->strict_mode(), | 1576 return js_function; |
1558 casted_stub()->kind()); | |
1559 | |
1560 // Compute the function map in the current native context and set that | |
1561 // as the map of the allocated object. | |
1562 HInstruction* native_context = BuildGetNativeContext(); | |
1563 HInstruction* map_slot_value = | |
1564 Add<HLoadNamedField>(native_context, static_cast<HValue*>(NULL), | |
1565 HObjectAccess::ForContextSlot(map_index)); | |
1566 Add<HStoreNamedField>(js_function, HObjectAccess::ForMap(), map_slot_value); | |
1567 | |
1568 // Initialize the rest of the function. | |
1569 Add<HStoreNamedField>(js_function, HObjectAccess::ForPropertiesPointer(), | |
1570 empty_fixed_array); | |
1571 Add<HStoreNamedField>(js_function, HObjectAccess::ForElementsPointer(), | |
1572 empty_fixed_array); | |
1573 Add<HStoreNamedField>(js_function, HObjectAccess::ForLiteralsPointer(), | |
1574 empty_fixed_array); | |
1575 Add<HStoreNamedField>(js_function, | |
1576 HObjectAccess::ForPrototypeOrInitialMap(), | |
1577 graph()->GetConstantHole()); | |
1578 Add<HStoreNamedField>(js_function, | |
1579 HObjectAccess::ForSharedFunctionInfoPointer(), | |
1580 shared_info); | |
1581 Add<HStoreNamedField>( | |
1582 js_function, HObjectAccess::ForFunctionContextPointer(), context()); | |
1583 | |
1584 // Initialize the code pointer in the function to be the one | |
1585 // found in the shared function info object. | |
1586 // But first check if there is an optimized version for our context. | |
1587 if (FLAG_cache_optimized_code) { | |
1588 BuildInstallFromOptimizedCodeMap(js_function, shared_info, | |
1589 native_context); | |
1590 } else { | |
1591 BuildInstallCode(js_function, shared_info); | |
1592 } | |
1593 Push(js_function); | |
1594 } | |
1595 optimize_now.End(); | |
1596 return Pop(); | |
1597 } | 1577 } |
1598 | 1578 |
1599 | 1579 |
1600 Handle<Code> FastNewClosureStub::GenerateCode() { | 1580 Handle<Code> FastNewClosureStub::GenerateCode() { |
1601 return DoGenerateCode(this); | 1581 return DoGenerateCode(this); |
1602 } | 1582 } |
1603 | 1583 |
1604 | 1584 |
1605 template<> | 1585 template<> |
1606 HValue* CodeStubGraphBuilder<FastNewContextStub>::BuildCodeStub() { | 1586 HValue* CodeStubGraphBuilder<FastNewContextStub>::BuildCodeStub() { |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 | 2019 |
2040 // Probe the stub cache. | 2020 // Probe the stub cache. |
2041 Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( | 2021 Code::Flags flags = Code::RemoveTypeAndHolderFromFlags( |
2042 Code::ComputeHandlerFlags(Code::LOAD_IC)); | 2022 Code::ComputeHandlerFlags(Code::LOAD_IC)); |
2043 Add<HTailCallThroughMegamorphicCache>(receiver, name, flags); | 2023 Add<HTailCallThroughMegamorphicCache>(receiver, name, flags); |
2044 | 2024 |
2045 // We never continue. | 2025 // We never continue. |
2046 return graph()->GetConstant0(); | 2026 return graph()->GetConstant0(); |
2047 } | 2027 } |
2048 } } // namespace v8::internal | 2028 } } // namespace v8::internal |
OLD | NEW |