Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: src/factory.cc

Issue 240263002: Handlify six more allocators in from the Heap class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/factory.h ('k') | src/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 "factory.h" 5 #include "factory.h"
6 6
7 #include "macro-assembler.h" 7 #include "macro-assembler.h"
8 #include "isolate-inl.h" 8 #include "isolate-inl.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 slice->set_hash_field(String::kEmptyHashField); 552 slice->set_hash_field(String::kEmptyHashField);
553 slice->set_length(length); 553 slice->set_length(length);
554 slice->set_parent(*str); 554 slice->set_parent(*str);
555 slice->set_offset(offset); 555 slice->set_offset(offset);
556 return slice; 556 return slice;
557 } 557 }
558 558
559 559
560 MaybeHandle<String> Factory::NewExternalStringFromAscii( 560 MaybeHandle<String> Factory::NewExternalStringFromAscii(
561 const ExternalAsciiString::Resource* resource) { 561 const ExternalAsciiString::Resource* resource) {
562 CALL_HEAP_FUNCTION( 562 size_t length = resource->length();
563 isolate(), 563 if (length > static_cast<size_t>(String::kMaxLength)) {
564 isolate()->heap()->AllocateExternalStringFromAscii(resource), 564 isolate()->ThrowInvalidStringLength();
565 String); 565 return MaybeHandle<String>();
566 }
567
568 Handle<Map> map = external_ascii_string_map();
569 Handle<ExternalAsciiString> external_string =
570 New<ExternalAsciiString>(map, NEW_SPACE);
571 external_string->set_length(static_cast<int>(length));
572 external_string->set_hash_field(String::kEmptyHashField);
573 external_string->set_resource(resource);
574
575 return external_string;
566 } 576 }
567 577
568 578
569 MaybeHandle<String> Factory::NewExternalStringFromTwoByte( 579 MaybeHandle<String> Factory::NewExternalStringFromTwoByte(
570 const ExternalTwoByteString::Resource* resource) { 580 const ExternalTwoByteString::Resource* resource) {
571 CALL_HEAP_FUNCTION( 581 size_t length = resource->length();
572 isolate(), 582 if (length > static_cast<size_t>(String::kMaxLength)) {
573 isolate()->heap()->AllocateExternalStringFromTwoByte(resource), 583 isolate()->ThrowInvalidStringLength();
574 String); 584 return MaybeHandle<String>();
585 }
586
587 // For small strings we check whether the resource contains only
588 // one byte characters. If yes, we use a different string map.
589 static const size_t kOneByteCheckLengthLimit = 32;
590 bool is_one_byte = length <= kOneByteCheckLengthLimit &&
591 String::IsOneByte(resource->data(), static_cast<int>(length));
592 Handle<Map> map = is_one_byte ?
593 external_string_with_one_byte_data_map() : external_string_map();
594 Handle<ExternalTwoByteString> external_string =
595 New<ExternalTwoByteString>(map, NEW_SPACE);
596 external_string->set_length(static_cast<int>(length));
597 external_string->set_hash_field(String::kEmptyHashField);
598 external_string->set_resource(resource);
599
600 return external_string;
575 } 601 }
576 602
577 603
578 Handle<Symbol> Factory::NewSymbol() { 604 Handle<Symbol> Factory::NewSymbol() {
579 CALL_HEAP_FUNCTION( 605 CALL_HEAP_FUNCTION(
580 isolate(), 606 isolate(),
581 isolate()->heap()->AllocateSymbol(), 607 isolate()->heap()->AllocateSymbol(),
582 Symbol); 608 Symbol);
583 } 609 }
584 610
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 1633
1608 CALL_HEAP_FUNCTION( 1634 CALL_HEAP_FUNCTION(
1609 isolate(), 1635 isolate(),
1610 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle), 1636 isolate()->heap()->AllocateJSObject(*typed_array_fun_handle),
1611 JSTypedArray); 1637 JSTypedArray);
1612 } 1638 }
1613 1639
1614 1640
1615 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler, 1641 Handle<JSProxy> Factory::NewJSProxy(Handle<Object> handler,
1616 Handle<Object> prototype) { 1642 Handle<Object> prototype) {
1617 CALL_HEAP_FUNCTION( 1643 // Allocate map.
1618 isolate(), 1644 // TODO(rossberg): Once we optimize proxies, think about a scheme to share
1619 isolate()->heap()->AllocateJSProxy(*handler, *prototype), 1645 // maps. Will probably depend on the identity of the handler object, too.
1620 JSProxy); 1646 Handle<Map> map = NewMap(JS_PROXY_TYPE, JSProxy::kSize);
1647 map->set_prototype(*prototype);
1648
1649 // Allocate the proxy object.
1650 Handle<JSProxy> result = New<JSProxy>(map, NEW_SPACE);
1651 result->InitializeBody(map->instance_size(), Smi::FromInt(0));
1652 result->set_handler(*handler);
1653 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER);
1654 return result;
1621 } 1655 }
1622 1656
1623 1657
1624 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler, 1658 Handle<JSProxy> Factory::NewJSFunctionProxy(Handle<Object> handler,
1625 Handle<Object> call_trap, 1659 Handle<Object> call_trap,
1626 Handle<Object> construct_trap, 1660 Handle<Object> construct_trap,
1627 Handle<Object> prototype) { 1661 Handle<Object> prototype) {
1628 CALL_HEAP_FUNCTION( 1662 // Allocate map.
1629 isolate(), 1663 // TODO(rossberg): Once we optimize proxies, think about a scheme to share
1630 isolate()->heap()->AllocateJSFunctionProxy( 1664 // maps. Will probably depend on the identity of the handler object, too.
1631 *handler, *call_trap, *construct_trap, *prototype), 1665 Handle<Map> map = NewMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize);
1632 JSProxy); 1666 map->set_prototype(*prototype);
1667
1668 // Allocate the proxy object.
1669 Handle<JSFunctionProxy> result = New<JSFunctionProxy>(map, NEW_SPACE);
1670 result->InitializeBody(map->instance_size(), Smi::FromInt(0));
1671 result->set_handler(*handler);
1672 result->set_hash(*undefined_value(), SKIP_WRITE_BARRIER);
1673 result->set_call_trap(*call_trap);
1674 result->set_construct_trap(*construct_trap);
1675 return result;
1633 } 1676 }
1634 1677
1635 1678
1636 void Factory::ReinitializeJSReceiver(Handle<JSReceiver> object, 1679 void Factory::ReinitializeJSReceiver(Handle<JSReceiver> object,
1637 InstanceType type, 1680 InstanceType type,
1638 int size) { 1681 int size) {
1639 ASSERT(type >= FIRST_JS_OBJECT_TYPE); 1682 ASSERT(type >= FIRST_JS_OBJECT_TYPE);
1640 1683
1641 // Allocate fresh map. 1684 // Allocate fresh map.
1642 // TODO(rossberg): Once we optimize proxies, cache these maps. 1685 // TODO(rossberg): Once we optimize proxies, cache these maps.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 } 1793 }
1751 1794
1752 1795
1753 Handle<JSMessageObject> Factory::NewJSMessageObject( 1796 Handle<JSMessageObject> Factory::NewJSMessageObject(
1754 Handle<String> type, 1797 Handle<String> type,
1755 Handle<JSArray> arguments, 1798 Handle<JSArray> arguments,
1756 int start_position, 1799 int start_position,
1757 int end_position, 1800 int end_position,
1758 Handle<Object> script, 1801 Handle<Object> script,
1759 Handle<Object> stack_frames) { 1802 Handle<Object> stack_frames) {
1760 CALL_HEAP_FUNCTION(isolate(), 1803 Handle<Map> map = message_object_map();
1761 isolate()->heap()->AllocateJSMessageObject(*type, 1804 Handle<JSMessageObject> message = New<JSMessageObject>(map, NEW_SPACE);
1762 *arguments, 1805 message->set_properties(*empty_fixed_array(), SKIP_WRITE_BARRIER);
1763 start_position, 1806 message->initialize_elements();
1764 end_position, 1807 message->set_elements(*empty_fixed_array(), SKIP_WRITE_BARRIER);
1765 *script, 1808 message->set_type(*type);
1766 *stack_frames), 1809 message->set_arguments(*arguments);
1767 JSMessageObject); 1810 message->set_start_position(start_position);
1811 message->set_end_position(end_position);
1812 message->set_script(*script);
1813 message->set_stack_frames(*stack_frames);
1814 return message;
1768 } 1815 }
1769 1816
1770 1817
1771 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) { 1818 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(Handle<String> name) {
1772 CALL_HEAP_FUNCTION(isolate(), 1819 Handle<Map> map = shared_function_info_map();
1773 isolate()->heap()->AllocateSharedFunctionInfo(*name), 1820 Handle<SharedFunctionInfo> share = New<SharedFunctionInfo>(map,
1774 SharedFunctionInfo); 1821 OLD_POINTER_SPACE);
1822
1823 // Set pointer fields.
1824 share->set_name(*name);
1825 Code* illegal = isolate()->builtins()->builtin(Builtins::kIllegal);
1826 share->set_code(illegal);
1827 share->set_optimized_code_map(Smi::FromInt(0));
1828 share->set_scope_info(ScopeInfo::Empty(isolate()));
1829 Code* construct_stub =
1830 isolate()->builtins()->builtin(Builtins::kJSConstructStubGeneric);
1831 share->set_construct_stub(construct_stub);
1832 share->set_instance_class_name(*Object_string());
1833 share->set_function_data(*undefined_value(), SKIP_WRITE_BARRIER);
1834 share->set_script(*undefined_value(), SKIP_WRITE_BARRIER);
1835 share->set_debug_info(*undefined_value(), SKIP_WRITE_BARRIER);
1836 share->set_inferred_name(*empty_string(), SKIP_WRITE_BARRIER);
1837 share->set_initial_map(*undefined_value(), SKIP_WRITE_BARRIER);
1838 share->set_ast_node_count(0);
1839 share->set_counters(0);
1840
1841 // Set integer fields (smi or int, depending on the architecture).
1842 share->set_length(0);
1843 share->set_formal_parameter_count(0);
1844 share->set_expected_nof_properties(0);
1845 share->set_num_literals(0);
1846 share->set_start_position_and_type(0);
1847 share->set_end_position(0);
1848 share->set_function_token_position(0);
1849 // All compiler hints default to false or 0.
1850 share->set_compiler_hints(0);
1851 share->set_opt_count_and_bailout_reason(0);
1852
1853 return share;
1775 } 1854 }
1776 1855
1777 1856
1778 Handle<String> Factory::NumberToString(Handle<Object> number, 1857 Handle<String> Factory::NumberToString(Handle<Object> number,
1779 bool check_number_string_cache) { 1858 bool check_number_string_cache) {
1780 CALL_HEAP_FUNCTION(isolate(), 1859 CALL_HEAP_FUNCTION(isolate(),
1781 isolate()->heap()->NumberToString( 1860 isolate()->heap()->NumberToString(
1782 *number, check_number_string_cache), 1861 *number, check_number_string_cache),
1783 String); 1862 String);
1784 } 1863 }
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2170 if (String::Equals(name, infinity_string())) return infinity_value(); 2249 if (String::Equals(name, infinity_string())) return infinity_value();
2171 return Handle<Object>::null(); 2250 return Handle<Object>::null();
2172 } 2251 }
2173 2252
2174 2253
2175 Handle<Object> Factory::ToBoolean(bool value) { 2254 Handle<Object> Factory::ToBoolean(bool value) {
2176 return value ? true_value() : false_value(); 2255 return value ? true_value() : false_value();
2177 } 2256 }
2178 2257
2179 } } // namespace v8::internal 2258 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/factory.h ('k') | src/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698