| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 1664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1675 if (!maybe_obj->ToObject(&obj)) return false; | 1675 if (!maybe_obj->ToObject(&obj)) return false; |
| 1676 } | 1676 } |
| 1677 set_byte_array_map(Map::cast(obj)); | 1677 set_byte_array_map(Map::cast(obj)); |
| 1678 | 1678 |
| 1679 { MaybeObject* maybe_obj = AllocateByteArray(0, TENURED); | 1679 { MaybeObject* maybe_obj = AllocateByteArray(0, TENURED); |
| 1680 if (!maybe_obj->ToObject(&obj)) return false; | 1680 if (!maybe_obj->ToObject(&obj)) return false; |
| 1681 } | 1681 } |
| 1682 set_empty_byte_array(ByteArray::cast(obj)); | 1682 set_empty_byte_array(ByteArray::cast(obj)); |
| 1683 | 1683 |
| 1684 { MaybeObject* maybe_obj = | 1684 { MaybeObject* maybe_obj = |
| 1685 AllocateMap(PIXEL_ARRAY_TYPE, PixelArray::kAlignedSize); | 1685 AllocateMap(EXTERNAL_PIXEL_ARRAY_TYPE, ExternalArray::kAlignedSize); |
| 1686 if (!maybe_obj->ToObject(&obj)) return false; | 1686 if (!maybe_obj->ToObject(&obj)) return false; |
| 1687 } | 1687 } |
| 1688 set_pixel_array_map(Map::cast(obj)); | 1688 set_external_pixel_array_map(Map::cast(obj)); |
| 1689 | 1689 |
| 1690 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE, | 1690 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_BYTE_ARRAY_TYPE, |
| 1691 ExternalArray::kAlignedSize); | 1691 ExternalArray::kAlignedSize); |
| 1692 if (!maybe_obj->ToObject(&obj)) return false; | 1692 if (!maybe_obj->ToObject(&obj)) return false; |
| 1693 } | 1693 } |
| 1694 set_external_byte_array_map(Map::cast(obj)); | 1694 set_external_byte_array_map(Map::cast(obj)); |
| 1695 | 1695 |
| 1696 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, | 1696 { MaybeObject* maybe_obj = AllocateMap(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 1697 ExternalArray::kAlignedSize); | 1697 ExternalArray::kAlignedSize); |
| 1698 if (!maybe_obj->ToObject(&obj)) return false; | 1698 if (!maybe_obj->ToObject(&obj)) return false; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 if (!maybe_elements->ToObject(&elements)) return false; | 1875 if (!maybe_elements->ToObject(&elements)) return false; |
| 1876 } | 1876 } |
| 1877 FixedArray::cast(elements)->set(0, Smi::FromInt(0)); | 1877 FixedArray::cast(elements)->set(0, Smi::FromInt(0)); |
| 1878 JSObject::cast(obj)->set_elements(FixedArray::cast(elements)); | 1878 JSObject::cast(obj)->set_elements(FixedArray::cast(elements)); |
| 1879 set_message_listeners(JSObject::cast(obj)); | 1879 set_message_listeners(JSObject::cast(obj)); |
| 1880 | 1880 |
| 1881 return true; | 1881 return true; |
| 1882 } | 1882 } |
| 1883 | 1883 |
| 1884 | 1884 |
| 1885 void Heap::CreateCEntryStub() { | |
| 1886 CEntryStub stub(1); | |
| 1887 set_c_entry_code(*stub.GetCode()); | |
| 1888 } | |
| 1889 | |
| 1890 | |
| 1891 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP | |
| 1892 void Heap::CreateRegExpCEntryStub() { | |
| 1893 RegExpCEntryStub stub; | |
| 1894 set_re_c_entry_code(*stub.GetCode()); | |
| 1895 } | |
| 1896 #endif | |
| 1897 | |
| 1898 | |
| 1899 void Heap::CreateJSEntryStub() { | 1885 void Heap::CreateJSEntryStub() { |
| 1900 JSEntryStub stub; | 1886 JSEntryStub stub; |
| 1901 set_js_entry_code(*stub.GetCode()); | 1887 set_js_entry_code(*stub.GetCode()); |
| 1902 } | 1888 } |
| 1903 | 1889 |
| 1904 | 1890 |
| 1905 void Heap::CreateJSConstructEntryStub() { | 1891 void Heap::CreateJSConstructEntryStub() { |
| 1906 JSConstructEntryStub stub; | 1892 JSConstructEntryStub stub; |
| 1907 set_js_construct_entry_code(*stub.GetCode()); | 1893 set_js_construct_entry_code(*stub.GetCode()); |
| 1908 } | 1894 } |
| 1909 | 1895 |
| 1910 | 1896 |
| 1911 #if V8_TARGET_ARCH_ARM | |
| 1912 void Heap::CreateDirectCEntryStub() { | |
| 1913 DirectCEntryStub stub; | |
| 1914 set_direct_c_entry_code(*stub.GetCode()); | |
| 1915 } | |
| 1916 #endif | |
| 1917 | |
| 1918 | |
| 1919 void Heap::CreateFixedStubs() { | 1897 void Heap::CreateFixedStubs() { |
| 1920 // Here we create roots for fixed stubs. They are needed at GC | 1898 // Here we create roots for fixed stubs. They are needed at GC |
| 1921 // for cooking and uncooking (check out frames.cc). | 1899 // for cooking and uncooking (check out frames.cc). |
| 1922 // The eliminates the need for doing dictionary lookup in the | 1900 // The eliminates the need for doing dictionary lookup in the |
| 1923 // stub cache for these stubs. | 1901 // stub cache for these stubs. |
| 1924 HandleScope scope; | 1902 HandleScope scope; |
| 1925 // gcc-4.4 has problem generating correct code of following snippet: | 1903 // gcc-4.4 has problem generating correct code of following snippet: |
| 1926 // { CEntryStub stub; | 1904 // { JSEntryStub stub; |
| 1927 // c_entry_code_ = *stub.GetCode(); | 1905 // js_entry_code_ = *stub.GetCode(); |
| 1928 // } | 1906 // } |
| 1929 // { DebuggerStatementStub stub; | 1907 // { JSConstructEntryStub stub; |
| 1930 // debugger_statement_code_ = *stub.GetCode(); | 1908 // js_construct_entry_code_ = *stub.GetCode(); |
| 1931 // } | 1909 // } |
| 1932 // To workaround the problem, make separate functions without inlining. | 1910 // To workaround the problem, make separate functions without inlining. |
| 1933 CreateCEntryStub(); | 1911 Heap::CreateJSEntryStub(); |
| 1934 CreateJSEntryStub(); | 1912 Heap::CreateJSConstructEntryStub(); |
| 1935 CreateJSConstructEntryStub(); | |
| 1936 #if V8_TARGET_ARCH_ARM && !V8_INTERPRETED_REGEXP | |
| 1937 CreateRegExpCEntryStub(); | |
| 1938 #endif | |
| 1939 #if V8_TARGET_ARCH_ARM | |
| 1940 Heap::CreateDirectCEntryStub(); | |
| 1941 #endif | |
| 1942 } | 1913 } |
| 1943 | 1914 |
| 1944 | 1915 |
| 1945 bool Heap::CreateInitialObjects() { | 1916 bool Heap::CreateInitialObjects() { |
| 1946 Object* obj; | 1917 Object* obj; |
| 1947 | 1918 |
| 1948 // The -0 value must be set before NumberFromDouble works. | 1919 // The -0 value must be set before NumberFromDouble works. |
| 1949 { MaybeObject* maybe_obj = AllocateHeapNumber(-0.0, TENURED); | 1920 { MaybeObject* maybe_obj = AllocateHeapNumber(-0.0, TENURED); |
| 1950 if (!maybe_obj->ToObject(&obj)) return false; | 1921 if (!maybe_obj->ToObject(&obj)) return false; |
| 1951 } | 1922 } |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2239 case kExternalShortArray: | 2210 case kExternalShortArray: |
| 2240 return kExternalShortArrayMapRootIndex; | 2211 return kExternalShortArrayMapRootIndex; |
| 2241 case kExternalUnsignedShortArray: | 2212 case kExternalUnsignedShortArray: |
| 2242 return kExternalUnsignedShortArrayMapRootIndex; | 2213 return kExternalUnsignedShortArrayMapRootIndex; |
| 2243 case kExternalIntArray: | 2214 case kExternalIntArray: |
| 2244 return kExternalIntArrayMapRootIndex; | 2215 return kExternalIntArrayMapRootIndex; |
| 2245 case kExternalUnsignedIntArray: | 2216 case kExternalUnsignedIntArray: |
| 2246 return kExternalUnsignedIntArrayMapRootIndex; | 2217 return kExternalUnsignedIntArrayMapRootIndex; |
| 2247 case kExternalFloatArray: | 2218 case kExternalFloatArray: |
| 2248 return kExternalFloatArrayMapRootIndex; | 2219 return kExternalFloatArrayMapRootIndex; |
| 2220 case kExternalPixelArray: |
| 2221 return kExternalPixelArrayMapRootIndex; |
| 2249 default: | 2222 default: |
| 2250 UNREACHABLE(); | 2223 UNREACHABLE(); |
| 2251 return kUndefinedValueRootIndex; | 2224 return kUndefinedValueRootIndex; |
| 2252 } | 2225 } |
| 2253 } | 2226 } |
| 2254 | 2227 |
| 2255 | 2228 |
| 2256 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { | 2229 MaybeObject* Heap::NumberFromDouble(double value, PretenureFlag pretenure) { |
| 2257 // We need to distinguish the minus zero value and this cannot be | 2230 // We need to distinguish the minus zero value and this cannot be |
| 2258 // done after conversion to int. Doing this by comparing bit | 2231 // done after conversion to int. Doing this by comparing bit |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2675 filler->set_map(one_pointer_filler_map()); | 2648 filler->set_map(one_pointer_filler_map()); |
| 2676 } else if (size == 2 * kPointerSize) { | 2649 } else if (size == 2 * kPointerSize) { |
| 2677 filler->set_map(two_pointer_filler_map()); | 2650 filler->set_map(two_pointer_filler_map()); |
| 2678 } else { | 2651 } else { |
| 2679 filler->set_map(byte_array_map()); | 2652 filler->set_map(byte_array_map()); |
| 2680 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size)); | 2653 ByteArray::cast(filler)->set_length(ByteArray::LengthFor(size)); |
| 2681 } | 2654 } |
| 2682 } | 2655 } |
| 2683 | 2656 |
| 2684 | 2657 |
| 2685 MaybeObject* Heap::AllocatePixelArray(int length, | |
| 2686 uint8_t* external_pointer, | |
| 2687 PretenureFlag pretenure) { | |
| 2688 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | |
| 2689 Object* result; | |
| 2690 { MaybeObject* maybe_result = | |
| 2691 AllocateRaw(PixelArray::kAlignedSize, space, OLD_DATA_SPACE); | |
| 2692 if (!maybe_result->ToObject(&result)) return maybe_result; | |
| 2693 } | |
| 2694 | |
| 2695 reinterpret_cast<PixelArray*>(result)->set_map(pixel_array_map()); | |
| 2696 reinterpret_cast<PixelArray*>(result)->set_length(length); | |
| 2697 reinterpret_cast<PixelArray*>(result)->set_external_pointer(external_pointer); | |
| 2698 | |
| 2699 return result; | |
| 2700 } | |
| 2701 | |
| 2702 | |
| 2703 MaybeObject* Heap::AllocateExternalArray(int length, | 2658 MaybeObject* Heap::AllocateExternalArray(int length, |
| 2704 ExternalArrayType array_type, | 2659 ExternalArrayType array_type, |
| 2705 void* external_pointer, | 2660 void* external_pointer, |
| 2706 PretenureFlag pretenure) { | 2661 PretenureFlag pretenure) { |
| 2707 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 2662 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
| 2708 Object* result; | 2663 Object* result; |
| 2709 { MaybeObject* maybe_result = AllocateRaw(ExternalArray::kAlignedSize, | 2664 { MaybeObject* maybe_result = AllocateRaw(ExternalArray::kAlignedSize, |
| 2710 space, | 2665 space, |
| 2711 OLD_DATA_SPACE); | 2666 OLD_DATA_SPACE); |
| 2712 if (!maybe_result->ToObject(&result)) return maybe_result; | 2667 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2713 } | 2668 } |
| 2714 | 2669 |
| 2715 reinterpret_cast<ExternalArray*>(result)->set_map( | 2670 reinterpret_cast<ExternalArray*>(result)->set_map( |
| 2716 MapForExternalArrayType(array_type)); | 2671 MapForExternalArrayType(array_type)); |
| 2717 reinterpret_cast<ExternalArray*>(result)->set_length(length); | 2672 reinterpret_cast<ExternalArray*>(result)->set_length(length); |
| 2718 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( | 2673 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( |
| 2719 external_pointer); | 2674 external_pointer); |
| 2720 | 2675 |
| 2721 return result; | 2676 return result; |
| 2722 } | 2677 } |
| 2723 | 2678 |
| 2724 | 2679 |
| 2725 MaybeObject* Heap::CreateCode(const CodeDesc& desc, | 2680 MaybeObject* Heap::CreateCode(const CodeDesc& desc, |
| 2726 Code::Flags flags, | 2681 Code::Flags flags, |
| 2727 Handle<Object> self_reference) { | 2682 Handle<Object> self_reference, |
| 2683 bool immovable) { |
| 2728 // Allocate ByteArray before the Code object, so that we do not risk | 2684 // Allocate ByteArray before the Code object, so that we do not risk |
| 2729 // leaving uninitialized Code object (and breaking the heap). | 2685 // leaving uninitialized Code object (and breaking the heap). |
| 2730 Object* reloc_info; | 2686 Object* reloc_info; |
| 2731 { MaybeObject* maybe_reloc_info = AllocateByteArray(desc.reloc_size, TENURED); | 2687 { MaybeObject* maybe_reloc_info = AllocateByteArray(desc.reloc_size, TENURED); |
| 2732 if (!maybe_reloc_info->ToObject(&reloc_info)) return maybe_reloc_info; | 2688 if (!maybe_reloc_info->ToObject(&reloc_info)) return maybe_reloc_info; |
| 2733 } | 2689 } |
| 2734 | 2690 |
| 2735 // Compute size | 2691 // Compute size. |
| 2736 int body_size = RoundUp(desc.instr_size, kObjectAlignment); | 2692 int body_size = RoundUp(desc.instr_size, kObjectAlignment); |
| 2737 int obj_size = Code::SizeFor(body_size); | 2693 int obj_size = Code::SizeFor(body_size); |
| 2738 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); | 2694 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); |
| 2739 MaybeObject* maybe_result; | 2695 MaybeObject* maybe_result; |
| 2740 if (obj_size > MaxObjectSizeInPagedSpace()) { | 2696 // Large code objects and code objects which should stay at a fixed address |
| 2697 // are allocated in large object space. |
| 2698 if (obj_size > MaxObjectSizeInPagedSpace() || immovable) { |
| 2741 maybe_result = lo_space_->AllocateRawCode(obj_size); | 2699 maybe_result = lo_space_->AllocateRawCode(obj_size); |
| 2742 } else { | 2700 } else { |
| 2743 maybe_result = code_space_->AllocateRaw(obj_size); | 2701 maybe_result = code_space_->AllocateRaw(obj_size); |
| 2744 } | 2702 } |
| 2745 | 2703 |
| 2746 Object* result; | 2704 Object* result; |
| 2747 if (!maybe_result->ToObject(&result)) return maybe_result; | 2705 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 2748 | 2706 |
| 2749 // Initialize the object | 2707 // Initialize the object |
| 2750 HeapObject::cast(result)->set_map(code_map()); | 2708 HeapObject::cast(result)->set_map(code_map()); |
| (...skipping 3052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5803 } | 5761 } |
| 5804 | 5762 |
| 5805 | 5763 |
| 5806 void ExternalStringTable::TearDown() { | 5764 void ExternalStringTable::TearDown() { |
| 5807 new_space_strings_.Free(); | 5765 new_space_strings_.Free(); |
| 5808 old_space_strings_.Free(); | 5766 old_space_strings_.Free(); |
| 5809 } | 5767 } |
| 5810 | 5768 |
| 5811 | 5769 |
| 5812 } } // namespace v8::internal | 5770 } } // namespace v8::internal |
| OLD | NEW |