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