OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1758 | 1758 |
1759 MaybeObject* Heap::AllocateMap(InstanceType instance_type, | 1759 MaybeObject* Heap::AllocateMap(InstanceType instance_type, |
1760 int instance_size, | 1760 int instance_size, |
1761 ElementsKind elements_kind) { | 1761 ElementsKind elements_kind) { |
1762 Object* result; | 1762 Object* result; |
1763 { MaybeObject* maybe_result = AllocateRawMap(); | 1763 { MaybeObject* maybe_result = AllocateRawMap(); |
1764 if (!maybe_result->ToObject(&result)) return maybe_result; | 1764 if (!maybe_result->ToObject(&result)) return maybe_result; |
1765 } | 1765 } |
1766 | 1766 |
1767 Map* map = reinterpret_cast<Map*>(result); | 1767 Map* map = reinterpret_cast<Map*>(result); |
1768 map->set_map(meta_map()); | 1768 map->set_map_unsafe(meta_map()); |
1769 map->set_instance_type(instance_type); | 1769 map->set_instance_type(instance_type); |
1770 map->set_visitor_id( | 1770 map->set_visitor_id( |
1771 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); | 1771 StaticVisitorBase::GetVisitorId(instance_type, instance_size)); |
1772 map->set_prototype(null_value()); | 1772 map->set_prototype(null_value(), SKIP_WRITE_BARRIER); |
1773 map->set_constructor(null_value()); | 1773 map->set_constructor(null_value(), SKIP_WRITE_BARRIER); |
1774 map->set_instance_size(instance_size); | 1774 map->set_instance_size(instance_size); |
1775 map->set_inobject_properties(0); | 1775 map->set_inobject_properties(0); |
1776 map->set_pre_allocated_property_fields(0); | 1776 map->set_pre_allocated_property_fields(0); |
1777 map->init_instance_descriptors(); | 1777 map->init_instance_descriptors(); |
1778 map->set_code_cache(empty_fixed_array()); | 1778 map->set_code_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); |
1779 map->set_prototype_transitions(empty_fixed_array()); | 1779 map->set_prototype_transitions(empty_fixed_array(), SKIP_WRITE_BARRIER); |
1780 map->set_unused_property_fields(0); | 1780 map->set_unused_property_fields(0); |
1781 map->set_bit_field(0); | 1781 map->set_bit_field(0); |
1782 map->set_bit_field2(1 << Map::kIsExtensible); | 1782 map->set_bit_field2(1 << Map::kIsExtensible); |
1783 map->set_elements_kind(elements_kind); | 1783 map->set_elements_kind(elements_kind); |
1784 | 1784 |
1785 // If the map object is aligned fill the padding area with Smi 0 objects. | 1785 // If the map object is aligned fill the padding area with Smi 0 objects. |
1786 if (Map::kPadStart < Map::kSize) { | 1786 if (Map::kPadStart < Map::kSize) { |
1787 memset(reinterpret_cast<byte*>(map) + Map::kPadStart - kHeapObjectTag, | 1787 memset(reinterpret_cast<byte*>(map) + Map::kPadStart - kHeapObjectTag, |
1788 0, | 1788 0, |
1789 Map::kSize - Map::kPadStart); | 1789 Map::kSize - Map::kPadStart); |
1790 } | 1790 } |
1791 return map; | 1791 return map; |
1792 } | 1792 } |
1793 | 1793 |
1794 | 1794 |
1795 MaybeObject* Heap::AllocateCodeCache() { | 1795 MaybeObject* Heap::AllocateCodeCache() { |
1796 Object* result; | 1796 Object* result; |
1797 { MaybeObject* maybe_result = AllocateStruct(CODE_CACHE_TYPE); | 1797 { MaybeObject* maybe_result = AllocateStruct(CODE_CACHE_TYPE); |
1798 if (!maybe_result->ToObject(&result)) return maybe_result; | 1798 if (!maybe_result->ToObject(&result)) return maybe_result; |
1799 } | 1799 } |
1800 CodeCache* code_cache = CodeCache::cast(result); | 1800 CodeCache* code_cache = CodeCache::cast(result); |
1801 code_cache->set_default_cache(empty_fixed_array()); | 1801 code_cache->set_default_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); |
1802 code_cache->set_normal_type_cache(undefined_value()); | 1802 code_cache->set_normal_type_cache(undefined_value(), SKIP_WRITE_BARRIER); |
1803 return code_cache; | 1803 return code_cache; |
1804 } | 1804 } |
1805 | 1805 |
1806 | 1806 |
1807 MaybeObject* Heap::AllocatePolymorphicCodeCache() { | 1807 MaybeObject* Heap::AllocatePolymorphicCodeCache() { |
1808 return AllocateStruct(POLYMORPHIC_CODE_CACHE_TYPE); | 1808 return AllocateStruct(POLYMORPHIC_CODE_CACHE_TYPE); |
1809 } | 1809 } |
1810 | 1810 |
1811 | 1811 |
1812 const Heap::StringTypeTable Heap::string_type_table[] = { | 1812 const Heap::StringTypeTable Heap::string_type_table[] = { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2118 // spaces. | 2118 // spaces. |
2119 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); | 2119 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); |
2120 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 2120 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
2121 | 2121 |
2122 Object* result; | 2122 Object* result; |
2123 { MaybeObject* maybe_result = | 2123 { MaybeObject* maybe_result = |
2124 AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE); | 2124 AllocateRaw(HeapNumber::kSize, space, OLD_DATA_SPACE); |
2125 if (!maybe_result->ToObject(&result)) return maybe_result; | 2125 if (!maybe_result->ToObject(&result)) return maybe_result; |
2126 } | 2126 } |
2127 | 2127 |
2128 HeapObject::cast(result)->set_map(heap_number_map()); | 2128 HeapObject::cast(result)->set_map_unsafe(heap_number_map()); |
2129 HeapNumber::cast(result)->set_value(value); | 2129 HeapNumber::cast(result)->set_value(value); |
2130 return result; | 2130 return result; |
2131 } | 2131 } |
2132 | 2132 |
2133 | 2133 |
2134 MaybeObject* Heap::AllocateHeapNumber(double value) { | 2134 MaybeObject* Heap::AllocateHeapNumber(double value) { |
2135 // Use general version, if we're forced to always allocate. | 2135 // Use general version, if we're forced to always allocate. |
2136 if (always_allocate()) return AllocateHeapNumber(value, TENURED); | 2136 if (always_allocate()) return AllocateHeapNumber(value, TENURED); |
2137 | 2137 |
2138 // This version of AllocateHeapNumber is optimized for | 2138 // This version of AllocateHeapNumber is optimized for |
2139 // allocation in new space. | 2139 // allocation in new space. |
2140 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); | 2140 STATIC_ASSERT(HeapNumber::kSize <= Page::kMaxHeapObjectSize); |
2141 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); | 2141 ASSERT(allocation_allowed_ && gc_state_ == NOT_IN_GC); |
2142 Object* result; | 2142 Object* result; |
2143 { MaybeObject* maybe_result = new_space_.AllocateRaw(HeapNumber::kSize); | 2143 { MaybeObject* maybe_result = new_space_.AllocateRaw(HeapNumber::kSize); |
2144 if (!maybe_result->ToObject(&result)) return maybe_result; | 2144 if (!maybe_result->ToObject(&result)) return maybe_result; |
2145 } | 2145 } |
2146 HeapObject::cast(result)->set_map(heap_number_map()); | 2146 HeapObject::cast(result)->set_map_unsafe(heap_number_map()); |
2147 HeapNumber::cast(result)->set_value(value); | 2147 HeapNumber::cast(result)->set_value(value); |
2148 return result; | 2148 return result; |
2149 } | 2149 } |
2150 | 2150 |
2151 | 2151 |
2152 MaybeObject* Heap::AllocateJSGlobalPropertyCell(Object* value) { | 2152 MaybeObject* Heap::AllocateJSGlobalPropertyCell(Object* value) { |
2153 Object* result; | 2153 Object* result; |
2154 { MaybeObject* maybe_result = AllocateRawCell(); | 2154 { MaybeObject* maybe_result = AllocateRawCell(); |
2155 if (!maybe_result->ToObject(&result)) return maybe_result; | 2155 if (!maybe_result->ToObject(&result)) return maybe_result; |
2156 } | 2156 } |
2157 HeapObject::cast(result)->set_map(global_property_cell_map()); | 2157 HeapObject::cast(result)->set_map_unsafe(global_property_cell_map()); |
2158 JSGlobalPropertyCell::cast(result)->set_value(value); | 2158 JSGlobalPropertyCell::cast(result)->set_value(value); |
2159 return result; | 2159 return result; |
2160 } | 2160 } |
2161 | 2161 |
2162 | 2162 |
2163 MaybeObject* Heap::CreateOddball(const char* to_string, | 2163 MaybeObject* Heap::CreateOddball(const char* to_string, |
2164 Object* to_number, | 2164 Object* to_number, |
2165 byte kind) { | 2165 byte kind) { |
2166 Object* result; | 2166 Object* result; |
2167 { MaybeObject* maybe_result = Allocate(oddball_map(), OLD_POINTER_SPACE); | 2167 { MaybeObject* maybe_result = Allocate(oddball_map(), OLD_POINTER_SPACE); |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2686 | 2686 |
2687 // Set pointer fields. | 2687 // Set pointer fields. |
2688 share->set_name(name); | 2688 share->set_name(name); |
2689 Code* illegal = isolate_->builtins()->builtin(Builtins::kIllegal); | 2689 Code* illegal = isolate_->builtins()->builtin(Builtins::kIllegal); |
2690 share->set_code(illegal); | 2690 share->set_code(illegal); |
2691 share->set_scope_info(ScopeInfo::Empty()); | 2691 share->set_scope_info(ScopeInfo::Empty()); |
2692 Code* construct_stub = | 2692 Code* construct_stub = |
2693 isolate_->builtins()->builtin(Builtins::kJSConstructStubGeneric); | 2693 isolate_->builtins()->builtin(Builtins::kJSConstructStubGeneric); |
2694 share->set_construct_stub(construct_stub); | 2694 share->set_construct_stub(construct_stub); |
2695 share->set_instance_class_name(Object_symbol()); | 2695 share->set_instance_class_name(Object_symbol()); |
2696 share->set_function_data(undefined_value()); | 2696 share->set_function_data(undefined_value(), SKIP_WRITE_BARRIER); |
2697 share->set_script(undefined_value()); | 2697 share->set_script(undefined_value(), SKIP_WRITE_BARRIER); |
2698 share->set_debug_info(undefined_value()); | 2698 share->set_debug_info(undefined_value(), SKIP_WRITE_BARRIER); |
2699 share->set_inferred_name(empty_string()); | 2699 share->set_inferred_name(empty_string(), SKIP_WRITE_BARRIER); |
2700 share->set_initial_map(undefined_value()); | 2700 share->set_initial_map(undefined_value(), SKIP_WRITE_BARRIER); |
2701 share->set_this_property_assignments(undefined_value()); | 2701 share->set_this_property_assignments(undefined_value(), SKIP_WRITE_BARRIER); |
2702 share->set_deopt_counter(Smi::FromInt(FLAG_deopt_every_n_times)); | 2702 share->set_deopt_counter(Smi::FromInt(FLAG_deopt_every_n_times)); |
2703 | 2703 |
2704 // Set integer fields (smi or int, depending on the architecture). | 2704 // Set integer fields (smi or int, depending on the architecture). |
2705 share->set_length(0); | 2705 share->set_length(0); |
2706 share->set_formal_parameter_count(0); | 2706 share->set_formal_parameter_count(0); |
2707 share->set_expected_nof_properties(0); | 2707 share->set_expected_nof_properties(0); |
2708 share->set_num_literals(0); | 2708 share->set_num_literals(0); |
2709 share->set_start_position_and_type(0); | 2709 share->set_start_position_and_type(0); |
2710 share->set_end_position(0); | 2710 share->set_end_position(0); |
2711 share->set_function_token_position(0); | 2711 share->set_function_token_position(0); |
(...skipping 11 matching lines...) Expand all Loading... |
2723 int start_position, | 2723 int start_position, |
2724 int end_position, | 2724 int end_position, |
2725 Object* script, | 2725 Object* script, |
2726 Object* stack_trace, | 2726 Object* stack_trace, |
2727 Object* stack_frames) { | 2727 Object* stack_frames) { |
2728 Object* result; | 2728 Object* result; |
2729 { MaybeObject* maybe_result = Allocate(message_object_map(), NEW_SPACE); | 2729 { MaybeObject* maybe_result = Allocate(message_object_map(), NEW_SPACE); |
2730 if (!maybe_result->ToObject(&result)) return maybe_result; | 2730 if (!maybe_result->ToObject(&result)) return maybe_result; |
2731 } | 2731 } |
2732 JSMessageObject* message = JSMessageObject::cast(result); | 2732 JSMessageObject* message = JSMessageObject::cast(result); |
2733 message->set_properties(Heap::empty_fixed_array()); | 2733 message->set_properties(Heap::empty_fixed_array(), SKIP_WRITE_BARRIER); |
2734 message->set_elements(Heap::empty_fixed_array()); | 2734 message->set_elements(Heap::empty_fixed_array(), SKIP_WRITE_BARRIER); |
2735 message->set_type(type); | 2735 message->set_type(type); |
2736 message->set_arguments(arguments); | 2736 message->set_arguments(arguments); |
2737 message->set_start_position(start_position); | 2737 message->set_start_position(start_position); |
2738 message->set_end_position(end_position); | 2738 message->set_end_position(end_position); |
2739 message->set_script(script); | 2739 message->set_script(script); |
2740 message->set_stack_trace(stack_trace); | 2740 message->set_stack_trace(stack_trace); |
2741 message->set_stack_frames(stack_frames); | 2741 message->set_stack_frames(stack_frames); |
2742 return result; | 2742 return result; |
2743 } | 2743 } |
2744 | 2744 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3084 return AllocateByteArray(length); | 3084 return AllocateByteArray(length); |
3085 } | 3085 } |
3086 int size = ByteArray::SizeFor(length); | 3086 int size = ByteArray::SizeFor(length); |
3087 Object* result; | 3087 Object* result; |
3088 { MaybeObject* maybe_result = (size <= MaxObjectSizeInPagedSpace()) | 3088 { MaybeObject* maybe_result = (size <= MaxObjectSizeInPagedSpace()) |
3089 ? old_data_space_->AllocateRaw(size) | 3089 ? old_data_space_->AllocateRaw(size) |
3090 : lo_space_->AllocateRaw(size, NOT_EXECUTABLE); | 3090 : lo_space_->AllocateRaw(size, NOT_EXECUTABLE); |
3091 if (!maybe_result->ToObject(&result)) return maybe_result; | 3091 if (!maybe_result->ToObject(&result)) return maybe_result; |
3092 } | 3092 } |
3093 | 3093 |
3094 reinterpret_cast<ByteArray*>(result)->set_map(byte_array_map()); | 3094 reinterpret_cast<ByteArray*>(result)->set_map_unsafe(byte_array_map()); |
3095 reinterpret_cast<ByteArray*>(result)->set_length(length); | 3095 reinterpret_cast<ByteArray*>(result)->set_length(length); |
3096 return result; | 3096 return result; |
3097 } | 3097 } |
3098 | 3098 |
3099 | 3099 |
3100 MaybeObject* Heap::AllocateByteArray(int length) { | 3100 MaybeObject* Heap::AllocateByteArray(int length) { |
3101 if (length < 0 || length > ByteArray::kMaxLength) { | 3101 if (length < 0 || length > ByteArray::kMaxLength) { |
3102 return Failure::OutOfMemoryException(); | 3102 return Failure::OutOfMemoryException(); |
3103 } | 3103 } |
3104 int size = ByteArray::SizeFor(length); | 3104 int size = ByteArray::SizeFor(length); |
3105 AllocationSpace space = | 3105 AllocationSpace space = |
3106 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : NEW_SPACE; | 3106 (size > MaxObjectSizeInPagedSpace()) ? LO_SPACE : NEW_SPACE; |
3107 Object* result; | 3107 Object* result; |
3108 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); | 3108 { MaybeObject* maybe_result = AllocateRaw(size, space, OLD_DATA_SPACE); |
3109 if (!maybe_result->ToObject(&result)) return maybe_result; | 3109 if (!maybe_result->ToObject(&result)) return maybe_result; |
3110 } | 3110 } |
3111 | 3111 |
3112 reinterpret_cast<ByteArray*>(result)->set_map(byte_array_map()); | 3112 reinterpret_cast<ByteArray*>(result)->set_map_unsafe(byte_array_map()); |
3113 reinterpret_cast<ByteArray*>(result)->set_length(length); | 3113 reinterpret_cast<ByteArray*>(result)->set_length(length); |
3114 return result; | 3114 return result; |
3115 } | 3115 } |
3116 | 3116 |
3117 | 3117 |
3118 void Heap::CreateFillerObjectAt(Address addr, int size) { | 3118 void Heap::CreateFillerObjectAt(Address addr, int size) { |
3119 if (size == 0) return; | 3119 if (size == 0) return; |
3120 HeapObject* filler = HeapObject::FromAddress(addr); | 3120 HeapObject* filler = HeapObject::FromAddress(addr); |
3121 if (size == kPointerSize) { | 3121 if (size == kPointerSize) { |
3122 filler->set_map(one_pointer_filler_map()); | 3122 filler->set_map_unsafe(one_pointer_filler_map()); |
3123 } else if (size == 2 * kPointerSize) { | 3123 } else if (size == 2 * kPointerSize) { |
3124 filler->set_map(two_pointer_filler_map()); | 3124 filler->set_map_unsafe(two_pointer_filler_map()); |
3125 } else { | 3125 } else { |
3126 filler->set_map(free_space_map()); | 3126 filler->set_map_unsafe(free_space_map()); |
3127 FreeSpace::cast(filler)->set_size(size); | 3127 FreeSpace::cast(filler)->set_size(size); |
3128 } | 3128 } |
3129 } | 3129 } |
3130 | 3130 |
3131 | 3131 |
3132 MaybeObject* Heap::AllocateExternalArray(int length, | 3132 MaybeObject* Heap::AllocateExternalArray(int length, |
3133 ExternalArrayType array_type, | 3133 ExternalArrayType array_type, |
3134 void* external_pointer, | 3134 void* external_pointer, |
3135 PretenureFlag pretenure) { | 3135 PretenureFlag pretenure) { |
3136 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; | 3136 AllocationSpace space = (pretenure == TENURED) ? OLD_DATA_SPACE : NEW_SPACE; |
3137 Object* result; | 3137 Object* result; |
3138 { MaybeObject* maybe_result = AllocateRaw(ExternalArray::kAlignedSize, | 3138 { MaybeObject* maybe_result = AllocateRaw(ExternalArray::kAlignedSize, |
3139 space, | 3139 space, |
3140 OLD_DATA_SPACE); | 3140 OLD_DATA_SPACE); |
3141 if (!maybe_result->ToObject(&result)) return maybe_result; | 3141 if (!maybe_result->ToObject(&result)) return maybe_result; |
3142 } | 3142 } |
3143 | 3143 |
3144 reinterpret_cast<ExternalArray*>(result)->set_map( | 3144 reinterpret_cast<ExternalArray*>(result)->set_map_unsafe( |
3145 MapForExternalArrayType(array_type)); | 3145 MapForExternalArrayType(array_type)); |
3146 reinterpret_cast<ExternalArray*>(result)->set_length(length); | 3146 reinterpret_cast<ExternalArray*>(result)->set_length(length); |
3147 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( | 3147 reinterpret_cast<ExternalArray*>(result)->set_external_pointer( |
3148 external_pointer); | 3148 external_pointer); |
3149 | 3149 |
3150 return result; | 3150 return result; |
3151 } | 3151 } |
3152 | 3152 |
3153 | 3153 |
3154 MaybeObject* Heap::CreateCode(const CodeDesc& desc, | 3154 MaybeObject* Heap::CreateCode(const CodeDesc& desc, |
(...skipping 16 matching lines...) Expand all Loading... |
3171 if (obj_size > MaxObjectSizeInPagedSpace() || immovable) { | 3171 if (obj_size > MaxObjectSizeInPagedSpace() || immovable) { |
3172 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); | 3172 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); |
3173 } else { | 3173 } else { |
3174 maybe_result = code_space_->AllocateRaw(obj_size); | 3174 maybe_result = code_space_->AllocateRaw(obj_size); |
3175 } | 3175 } |
3176 | 3176 |
3177 Object* result; | 3177 Object* result; |
3178 if (!maybe_result->ToObject(&result)) return maybe_result; | 3178 if (!maybe_result->ToObject(&result)) return maybe_result; |
3179 | 3179 |
3180 // Initialize the object | 3180 // Initialize the object |
3181 HeapObject::cast(result)->set_map(code_map()); | 3181 HeapObject::cast(result)->set_map_unsafe(code_map()); |
3182 Code* code = Code::cast(result); | 3182 Code* code = Code::cast(result); |
3183 ASSERT(!isolate_->code_range()->exists() || | 3183 ASSERT(!isolate_->code_range()->exists() || |
3184 isolate_->code_range()->contains(code->address())); | 3184 isolate_->code_range()->contains(code->address())); |
3185 code->set_instruction_size(desc.instr_size); | 3185 code->set_instruction_size(desc.instr_size); |
3186 code->set_relocation_info(reloc_info); | 3186 code->set_relocation_info(reloc_info); |
3187 code->set_flags(flags); | 3187 code->set_flags(flags); |
3188 if (code->is_call_stub() || code->is_keyed_call_stub()) { | 3188 if (code->is_call_stub() || code->is_keyed_call_stub()) { |
3189 code->set_check_type(RECEIVER_MAP_CHECK); | 3189 code->set_check_type(RECEIVER_MAP_CHECK); |
3190 } | 3190 } |
3191 code->set_deoptimization_data(empty_fixed_array()); | 3191 code->set_deoptimization_data(empty_fixed_array(), SKIP_WRITE_BARRIER); |
3192 code->set_handler_table(empty_fixed_array()); | 3192 code->set_handler_table(empty_fixed_array(), SKIP_WRITE_BARRIER); |
3193 code->set_next_code_flushing_candidate(undefined_value()); | 3193 code->set_next_code_flushing_candidate(undefined_value()); |
3194 // Allow self references to created code object by patching the handle to | 3194 // Allow self references to created code object by patching the handle to |
3195 // point to the newly allocated Code object. | 3195 // point to the newly allocated Code object. |
3196 if (!self_reference.is_null()) { | 3196 if (!self_reference.is_null()) { |
3197 *(self_reference.location()) = code; | 3197 *(self_reference.location()) = code; |
3198 } | 3198 } |
3199 // Migrate generated code. | 3199 // Migrate generated code. |
3200 // The generated code can contain Object** values (typically from handles) | 3200 // The generated code can contain Object** values (typically from handles) |
3201 // that are dereferenced during the copy to point directly to the actual heap | 3201 // that are dereferenced during the copy to point directly to the actual heap |
3202 // objects. These pointers can include references to the code object itself, | 3202 // objects. These pointers can include references to the code object itself, |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3299 ASSERT(map->instance_type() != MAP_TYPE); | 3299 ASSERT(map->instance_type() != MAP_TYPE); |
3300 // If allocation failures are disallowed, we may allocate in a different | 3300 // If allocation failures are disallowed, we may allocate in a different |
3301 // space when new space is full and the object is not a large object. | 3301 // space when new space is full and the object is not a large object. |
3302 AllocationSpace retry_space = | 3302 AllocationSpace retry_space = |
3303 (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type()); | 3303 (space != NEW_SPACE) ? space : TargetSpaceId(map->instance_type()); |
3304 Object* result; | 3304 Object* result; |
3305 { MaybeObject* maybe_result = | 3305 { MaybeObject* maybe_result = |
3306 AllocateRaw(map->instance_size(), space, retry_space); | 3306 AllocateRaw(map->instance_size(), space, retry_space); |
3307 if (!maybe_result->ToObject(&result)) return maybe_result; | 3307 if (!maybe_result->ToObject(&result)) return maybe_result; |
3308 } | 3308 } |
3309 HeapObject::cast(result)->set_map(map); | 3309 // No need for write barrier since object is white and map is in old space. |
| 3310 HeapObject::cast(result)->set_map_unsafe(map); |
3310 return result; | 3311 return result; |
3311 } | 3312 } |
3312 | 3313 |
3313 | 3314 |
3314 void Heap::InitializeFunction(JSFunction* function, | 3315 void Heap::InitializeFunction(JSFunction* function, |
3315 SharedFunctionInfo* shared, | 3316 SharedFunctionInfo* shared, |
3316 Object* prototype) { | 3317 Object* prototype) { |
3317 ASSERT(!prototype->IsMap()); | 3318 ASSERT(!prototype->IsMap()); |
3318 function->initialize_properties(); | 3319 function->initialize_properties(); |
3319 function->initialize_elements(); | 3320 function->initialize_elements(); |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3626 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); | 3627 MaybeObject* maybe_map_obj = AllocateMap(JS_PROXY_TYPE, JSProxy::kSize); |
3627 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; | 3628 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
3628 map->set_prototype(prototype); | 3629 map->set_prototype(prototype); |
3629 | 3630 |
3630 // Allocate the proxy object. | 3631 // Allocate the proxy object. |
3631 JSProxy* result; | 3632 JSProxy* result; |
3632 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); | 3633 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
3633 if (!maybe_result->To<JSProxy>(&result)) return maybe_result; | 3634 if (!maybe_result->To<JSProxy>(&result)) return maybe_result; |
3634 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); | 3635 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
3635 result->set_handler(handler); | 3636 result->set_handler(handler); |
3636 result->set_hash(undefined_value()); | 3637 result->set_hash(undefined_value(), SKIP_WRITE_BARRIER); |
3637 return result; | 3638 return result; |
3638 } | 3639 } |
3639 | 3640 |
3640 | 3641 |
3641 MaybeObject* Heap::AllocateJSFunctionProxy(Object* handler, | 3642 MaybeObject* Heap::AllocateJSFunctionProxy(Object* handler, |
3642 Object* call_trap, | 3643 Object* call_trap, |
3643 Object* construct_trap, | 3644 Object* construct_trap, |
3644 Object* prototype) { | 3645 Object* prototype) { |
3645 // Allocate map. | 3646 // Allocate map. |
3646 // TODO(rossberg): Once we optimize proxies, think about a scheme to share | 3647 // TODO(rossberg): Once we optimize proxies, think about a scheme to share |
3647 // maps. Will probably depend on the identity of the handler object, too. | 3648 // maps. Will probably depend on the identity of the handler object, too. |
3648 Map* map; | 3649 Map* map; |
3649 MaybeObject* maybe_map_obj = | 3650 MaybeObject* maybe_map_obj = |
3650 AllocateMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); | 3651 AllocateMap(JS_FUNCTION_PROXY_TYPE, JSFunctionProxy::kSize); |
3651 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; | 3652 if (!maybe_map_obj->To<Map>(&map)) return maybe_map_obj; |
3652 map->set_prototype(prototype); | 3653 map->set_prototype(prototype); |
3653 | 3654 |
3654 // Allocate the proxy object. | 3655 // Allocate the proxy object. |
3655 JSFunctionProxy* result; | 3656 JSFunctionProxy* result; |
3656 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); | 3657 MaybeObject* maybe_result = Allocate(map, NEW_SPACE); |
3657 if (!maybe_result->To<JSFunctionProxy>(&result)) return maybe_result; | 3658 if (!maybe_result->To<JSFunctionProxy>(&result)) return maybe_result; |
3658 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); | 3659 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
3659 result->set_handler(handler); | 3660 result->set_handler(handler); |
3660 result->set_hash(undefined_value()); | 3661 result->set_hash(undefined_value(), SKIP_WRITE_BARRIER); |
3661 result->set_call_trap(call_trap); | 3662 result->set_call_trap(call_trap); |
3662 result->set_construct_trap(construct_trap); | 3663 result->set_construct_trap(construct_trap); |
3663 return result; | 3664 return result; |
3664 } | 3665 } |
3665 | 3666 |
3666 | 3667 |
3667 MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) { | 3668 MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) { |
3668 ASSERT(constructor->has_initial_map()); | 3669 ASSERT(constructor->has_initial_map()); |
3669 Map* map = constructor->initial_map(); | 3670 Map* map = constructor->initial_map(); |
3670 | 3671 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3838 maybe = LookupAsciiSymbol("<freezing call trap>"); | 3839 maybe = LookupAsciiSymbol("<freezing call trap>"); |
3839 if (!maybe->To<String>(&name)) return maybe; | 3840 if (!maybe->To<String>(&name)) return maybe; |
3840 maybe = AllocateSharedFunctionInfo(name); | 3841 maybe = AllocateSharedFunctionInfo(name); |
3841 if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe; | 3842 if (!maybe->To<SharedFunctionInfo>(&shared)) return maybe; |
3842 } | 3843 } |
3843 | 3844 |
3844 // Because of possible retries of this function after failure, | 3845 // Because of possible retries of this function after failure, |
3845 // we must NOT fail after this point, where we have changed the type! | 3846 // we must NOT fail after this point, where we have changed the type! |
3846 | 3847 |
3847 // Reset the map for the object. | 3848 // Reset the map for the object. |
3848 object->set_map(map); | 3849 object->set_map_unsafe(map); |
3849 JSObject* jsobj = JSObject::cast(object); | 3850 JSObject* jsobj = JSObject::cast(object); |
3850 | 3851 |
3851 // Reinitialize the object from the constructor map. | 3852 // Reinitialize the object from the constructor map. |
3852 InitializeJSObjectFromMap(jsobj, FixedArray::cast(properties), map); | 3853 InitializeJSObjectFromMap(jsobj, FixedArray::cast(properties), map); |
3853 | 3854 |
3854 // Functions require some minimal initialization. | 3855 // Functions require some minimal initialization. |
3855 if (type == JS_FUNCTION_TYPE) { | 3856 if (type == JS_FUNCTION_TYPE) { |
3856 map->set_function_with_prototype(true); | 3857 map->set_function_with_prototype(true); |
3857 InitializeFunction(JSFunction::cast(object), shared, the_hole_value()); | 3858 InitializeFunction(JSFunction::cast(object), shared, the_hole_value()); |
3858 JSFunction::cast(object)->set_context( | 3859 JSFunction::cast(object)->set_context( |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4037 } | 4038 } |
4038 | 4039 |
4039 // Allocate string. | 4040 // Allocate string. |
4040 Object* result; | 4041 Object* result; |
4041 { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) | 4042 { MaybeObject* maybe_result = (size > MaxObjectSizeInPagedSpace()) |
4042 ? lo_space_->AllocateRaw(size, NOT_EXECUTABLE) | 4043 ? lo_space_->AllocateRaw(size, NOT_EXECUTABLE) |
4043 : old_data_space_->AllocateRaw(size); | 4044 : old_data_space_->AllocateRaw(size); |
4044 if (!maybe_result->ToObject(&result)) return maybe_result; | 4045 if (!maybe_result->ToObject(&result)) return maybe_result; |
4045 } | 4046 } |
4046 | 4047 |
4047 reinterpret_cast<HeapObject*>(result)->set_map(map); | 4048 reinterpret_cast<HeapObject*>(result)->set_map_unsafe(map); |
4048 // Set length and hash fields of the allocated string. | 4049 // Set length and hash fields of the allocated string. |
4049 String* answer = String::cast(result); | 4050 String* answer = String::cast(result); |
4050 answer->set_length(chars); | 4051 answer->set_length(chars); |
4051 answer->set_hash_field(hash_field); | 4052 answer->set_hash_field(hash_field); |
4052 | 4053 |
4053 ASSERT_EQ(size, answer->Size()); | 4054 ASSERT_EQ(size, answer->Size()); |
4054 | 4055 |
4055 // Fill in the characters. | 4056 // Fill in the characters. |
4056 for (int i = 0; i < chars; i++) { | 4057 for (int i = 0; i < chars; i++) { |
4057 answer->Set(i, buffer->GetNext()); | 4058 answer->Set(i, buffer->GetNext()); |
(...skipping 23 matching lines...) Expand all Loading... |
4081 } | 4082 } |
4082 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) { | 4083 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) { |
4083 space = LO_SPACE; | 4084 space = LO_SPACE; |
4084 } | 4085 } |
4085 Object* result; | 4086 Object* result; |
4086 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); | 4087 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); |
4087 if (!maybe_result->ToObject(&result)) return maybe_result; | 4088 if (!maybe_result->ToObject(&result)) return maybe_result; |
4088 } | 4089 } |
4089 | 4090 |
4090 // Partially initialize the object. | 4091 // Partially initialize the object. |
4091 HeapObject::cast(result)->set_map(ascii_string_map()); | 4092 HeapObject::cast(result)->set_map_unsafe(ascii_string_map()); |
4092 String::cast(result)->set_length(length); | 4093 String::cast(result)->set_length(length); |
4093 String::cast(result)->set_hash_field(String::kEmptyHashField); | 4094 String::cast(result)->set_hash_field(String::kEmptyHashField); |
4094 ASSERT_EQ(size, HeapObject::cast(result)->Size()); | 4095 ASSERT_EQ(size, HeapObject::cast(result)->Size()); |
4095 return result; | 4096 return result; |
4096 } | 4097 } |
4097 | 4098 |
4098 | 4099 |
4099 MaybeObject* Heap::AllocateRawTwoByteString(int length, | 4100 MaybeObject* Heap::AllocateRawTwoByteString(int length, |
4100 PretenureFlag pretenure) { | 4101 PretenureFlag pretenure) { |
4101 if (length < 0 || length > SeqTwoByteString::kMaxLength) { | 4102 if (length < 0 || length > SeqTwoByteString::kMaxLength) { |
(...skipping 14 matching lines...) Expand all Loading... |
4116 } | 4117 } |
4117 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) { | 4118 } else if (space == OLD_DATA_SPACE && size > MaxObjectSizeInPagedSpace()) { |
4118 space = LO_SPACE; | 4119 space = LO_SPACE; |
4119 } | 4120 } |
4120 Object* result; | 4121 Object* result; |
4121 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); | 4122 { MaybeObject* maybe_result = AllocateRaw(size, space, retry_space); |
4122 if (!maybe_result->ToObject(&result)) return maybe_result; | 4123 if (!maybe_result->ToObject(&result)) return maybe_result; |
4123 } | 4124 } |
4124 | 4125 |
4125 // Partially initialize the object. | 4126 // Partially initialize the object. |
4126 HeapObject::cast(result)->set_map(string_map()); | 4127 HeapObject::cast(result)->set_map_unsafe(string_map()); |
4127 String::cast(result)->set_length(length); | 4128 String::cast(result)->set_length(length); |
4128 String::cast(result)->set_hash_field(String::kEmptyHashField); | 4129 String::cast(result)->set_hash_field(String::kEmptyHashField); |
4129 ASSERT_EQ(size, HeapObject::cast(result)->Size()); | 4130 ASSERT_EQ(size, HeapObject::cast(result)->Size()); |
4130 return result; | 4131 return result; |
4131 } | 4132 } |
4132 | 4133 |
4133 | 4134 |
4134 MaybeObject* Heap::AllocateEmptyFixedArray() { | 4135 MaybeObject* Heap::AllocateEmptyFixedArray() { |
4135 int size = FixedArray::SizeFor(0); | 4136 int size = FixedArray::SizeFor(0); |
4136 Object* result; | 4137 Object* result; |
4137 { MaybeObject* maybe_result = | 4138 { MaybeObject* maybe_result = |
4138 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); | 4139 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); |
4139 if (!maybe_result->ToObject(&result)) return maybe_result; | 4140 if (!maybe_result->ToObject(&result)) return maybe_result; |
4140 } | 4141 } |
4141 // Initialize the object. | 4142 // Initialize the object. |
4142 reinterpret_cast<FixedArray*>(result)->set_map(fixed_array_map()); | 4143 reinterpret_cast<FixedArray*>(result)->set_map_unsafe(fixed_array_map()); |
4143 reinterpret_cast<FixedArray*>(result)->set_length(0); | 4144 reinterpret_cast<FixedArray*>(result)->set_length(0); |
4144 return result; | 4145 return result; |
4145 } | 4146 } |
4146 | 4147 |
4147 | 4148 |
4148 MaybeObject* Heap::AllocateRawFixedArray(int length) { | 4149 MaybeObject* Heap::AllocateRawFixedArray(int length) { |
4149 if (length < 0 || length > FixedArray::kMaxLength) { | 4150 if (length < 0 || length > FixedArray::kMaxLength) { |
4150 return Failure::OutOfMemoryException(); | 4151 return Failure::OutOfMemoryException(); |
4151 } | 4152 } |
4152 ASSERT(length > 0); | 4153 ASSERT(length > 0); |
4153 // Use the general function if we're forced to always allocate. | 4154 // Use the general function if we're forced to always allocate. |
4154 if (always_allocate()) return AllocateFixedArray(length, TENURED); | 4155 if (always_allocate()) return AllocateFixedArray(length, TENURED); |
4155 // Allocate the raw data for a fixed array. | 4156 // Allocate the raw data for a fixed array. |
4156 int size = FixedArray::SizeFor(length); | 4157 int size = FixedArray::SizeFor(length); |
4157 return size <= kMaxObjectSizeInNewSpace | 4158 return size <= kMaxObjectSizeInNewSpace |
4158 ? new_space_.AllocateRaw(size) | 4159 ? new_space_.AllocateRaw(size) |
4159 : lo_space_->AllocateRaw(size, NOT_EXECUTABLE); | 4160 : lo_space_->AllocateRaw(size, NOT_EXECUTABLE); |
4160 } | 4161 } |
4161 | 4162 |
4162 | 4163 |
4163 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { | 4164 MaybeObject* Heap::CopyFixedArrayWithMap(FixedArray* src, Map* map) { |
4164 int len = src->length(); | 4165 int len = src->length(); |
4165 Object* obj; | 4166 Object* obj; |
4166 { MaybeObject* maybe_obj = AllocateRawFixedArray(len); | 4167 { MaybeObject* maybe_obj = AllocateRawFixedArray(len); |
4167 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 4168 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
4168 } | 4169 } |
4169 if (InNewSpace(obj)) { | 4170 if (InNewSpace(obj)) { |
4170 HeapObject* dst = HeapObject::cast(obj); | 4171 HeapObject* dst = HeapObject::cast(obj); |
4171 dst->set_map(map); | 4172 dst->set_map_unsafe(map); |
4172 CopyBlock(dst->address() + kPointerSize, | 4173 CopyBlock(dst->address() + kPointerSize, |
4173 src->address() + kPointerSize, | 4174 src->address() + kPointerSize, |
4174 FixedArray::SizeFor(len) - kPointerSize); | 4175 FixedArray::SizeFor(len) - kPointerSize); |
4175 return obj; | 4176 return obj; |
4176 } | 4177 } |
4177 HeapObject::cast(obj)->set_map(map); | 4178 HeapObject::cast(obj)->set_map_unsafe(map); |
4178 FixedArray* result = FixedArray::cast(obj); | 4179 FixedArray* result = FixedArray::cast(obj); |
4179 result->set_length(len); | 4180 result->set_length(len); |
4180 | 4181 |
4181 // Copy the content | 4182 // Copy the content |
4182 AssertNoAllocation no_gc; | 4183 AssertNoAllocation no_gc; |
4183 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); | 4184 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); |
4184 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); | 4185 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); |
4185 return result; | 4186 return result; |
4186 } | 4187 } |
4187 | 4188 |
4188 | 4189 |
4189 MaybeObject* Heap::CopyFixedDoubleArrayWithMap(FixedDoubleArray* src, | 4190 MaybeObject* Heap::CopyFixedDoubleArrayWithMap(FixedDoubleArray* src, |
4190 Map* map) { | 4191 Map* map) { |
4191 int len = src->length(); | 4192 int len = src->length(); |
4192 Object* obj; | 4193 Object* obj; |
4193 { MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(len, NOT_TENURED); | 4194 { MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(len, NOT_TENURED); |
4194 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 4195 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
4195 } | 4196 } |
4196 HeapObject* dst = HeapObject::cast(obj); | 4197 HeapObject* dst = HeapObject::cast(obj); |
4197 dst->set_map(map); | 4198 dst->set_map_unsafe(map); |
4198 CopyBlock( | 4199 CopyBlock( |
4199 dst->address() + FixedDoubleArray::kLengthOffset, | 4200 dst->address() + FixedDoubleArray::kLengthOffset, |
4200 src->address() + FixedDoubleArray::kLengthOffset, | 4201 src->address() + FixedDoubleArray::kLengthOffset, |
4201 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset); | 4202 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset); |
4202 return obj; | 4203 return obj; |
4203 } | 4204 } |
4204 | 4205 |
4205 | 4206 |
4206 MaybeObject* Heap::AllocateFixedArray(int length) { | 4207 MaybeObject* Heap::AllocateFixedArray(int length) { |
4207 ASSERT(length >= 0); | 4208 ASSERT(length >= 0); |
4208 if (length == 0) return empty_fixed_array(); | 4209 if (length == 0) return empty_fixed_array(); |
4209 Object* result; | 4210 Object* result; |
4210 { MaybeObject* maybe_result = AllocateRawFixedArray(length); | 4211 { MaybeObject* maybe_result = AllocateRawFixedArray(length); |
4211 if (!maybe_result->ToObject(&result)) return maybe_result; | 4212 if (!maybe_result->ToObject(&result)) return maybe_result; |
4212 } | 4213 } |
4213 // Initialize header. | 4214 // Initialize header. |
4214 FixedArray* array = reinterpret_cast<FixedArray*>(result); | 4215 FixedArray* array = reinterpret_cast<FixedArray*>(result); |
4215 array->set_map(fixed_array_map()); | 4216 array->set_map_unsafe(fixed_array_map()); |
4216 array->set_length(length); | 4217 array->set_length(length); |
4217 // Initialize body. | 4218 // Initialize body. |
4218 ASSERT(!InNewSpace(undefined_value())); | 4219 ASSERT(!InNewSpace(undefined_value())); |
4219 MemsetPointer(array->data_start(), undefined_value(), length); | 4220 MemsetPointer(array->data_start(), undefined_value(), length); |
4220 return result; | 4221 return result; |
4221 } | 4222 } |
4222 | 4223 |
4223 | 4224 |
4224 MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) { | 4225 MaybeObject* Heap::AllocateRawFixedArray(int length, PretenureFlag pretenure) { |
4225 if (length < 0 || length > FixedArray::kMaxLength) { | 4226 if (length < 0 || length > FixedArray::kMaxLength) { |
(...skipping 27 matching lines...) Expand all Loading... |
4253 ASSERT(length >= 0); | 4254 ASSERT(length >= 0); |
4254 ASSERT(heap->empty_fixed_array()->IsFixedArray()); | 4255 ASSERT(heap->empty_fixed_array()->IsFixedArray()); |
4255 if (length == 0) return heap->empty_fixed_array(); | 4256 if (length == 0) return heap->empty_fixed_array(); |
4256 | 4257 |
4257 ASSERT(!heap->InNewSpace(filler)); | 4258 ASSERT(!heap->InNewSpace(filler)); |
4258 Object* result; | 4259 Object* result; |
4259 { MaybeObject* maybe_result = heap->AllocateRawFixedArray(length, pretenure); | 4260 { MaybeObject* maybe_result = heap->AllocateRawFixedArray(length, pretenure); |
4260 if (!maybe_result->ToObject(&result)) return maybe_result; | 4261 if (!maybe_result->ToObject(&result)) return maybe_result; |
4261 } | 4262 } |
4262 | 4263 |
4263 HeapObject::cast(result)->set_map(heap->fixed_array_map()); | 4264 HeapObject::cast(result)->set_map_unsafe(heap->fixed_array_map()); |
4264 FixedArray* array = FixedArray::cast(result); | 4265 FixedArray* array = FixedArray::cast(result); |
4265 array->set_length(length); | 4266 array->set_length(length); |
4266 MemsetPointer(array->data_start(), filler, length); | 4267 MemsetPointer(array->data_start(), filler, length); |
4267 return array; | 4268 return array; |
4268 } | 4269 } |
4269 | 4270 |
4270 | 4271 |
4271 MaybeObject* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { | 4272 MaybeObject* Heap::AllocateFixedArray(int length, PretenureFlag pretenure) { |
4272 return AllocateFixedArrayWithFiller(this, | 4273 return AllocateFixedArrayWithFiller(this, |
4273 length, | 4274 length, |
(...skipping 12 matching lines...) Expand all Loading... |
4286 | 4287 |
4287 | 4288 |
4288 MaybeObject* Heap::AllocateUninitializedFixedArray(int length) { | 4289 MaybeObject* Heap::AllocateUninitializedFixedArray(int length) { |
4289 if (length == 0) return empty_fixed_array(); | 4290 if (length == 0) return empty_fixed_array(); |
4290 | 4291 |
4291 Object* obj; | 4292 Object* obj; |
4292 { MaybeObject* maybe_obj = AllocateRawFixedArray(length); | 4293 { MaybeObject* maybe_obj = AllocateRawFixedArray(length); |
4293 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 4294 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
4294 } | 4295 } |
4295 | 4296 |
4296 reinterpret_cast<FixedArray*>(obj)->set_map(fixed_array_map()); | 4297 reinterpret_cast<FixedArray*>(obj)->set_map_unsafe(fixed_array_map()); |
4297 FixedArray::cast(obj)->set_length(length); | 4298 FixedArray::cast(obj)->set_length(length); |
4298 return obj; | 4299 return obj; |
4299 } | 4300 } |
4300 | 4301 |
4301 | 4302 |
4302 MaybeObject* Heap::AllocateEmptyFixedDoubleArray() { | 4303 MaybeObject* Heap::AllocateEmptyFixedDoubleArray() { |
4303 int size = FixedDoubleArray::SizeFor(0); | 4304 int size = FixedDoubleArray::SizeFor(0); |
4304 Object* result; | 4305 Object* result; |
4305 { MaybeObject* maybe_result = | 4306 { MaybeObject* maybe_result = |
4306 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); | 4307 AllocateRaw(size, OLD_DATA_SPACE, OLD_DATA_SPACE); |
4307 if (!maybe_result->ToObject(&result)) return maybe_result; | 4308 if (!maybe_result->ToObject(&result)) return maybe_result; |
4308 } | 4309 } |
4309 // Initialize the object. | 4310 // Initialize the object. |
4310 reinterpret_cast<FixedDoubleArray*>(result)->set_map( | 4311 reinterpret_cast<FixedDoubleArray*>(result)->set_map_unsafe( |
4311 fixed_double_array_map()); | 4312 fixed_double_array_map()); |
4312 reinterpret_cast<FixedDoubleArray*>(result)->set_length(0); | 4313 reinterpret_cast<FixedDoubleArray*>(result)->set_length(0); |
4313 return result; | 4314 return result; |
4314 } | 4315 } |
4315 | 4316 |
4316 | 4317 |
4317 MaybeObject* Heap::AllocateUninitializedFixedDoubleArray( | 4318 MaybeObject* Heap::AllocateUninitializedFixedDoubleArray( |
4318 int length, | 4319 int length, |
4319 PretenureFlag pretenure) { | 4320 PretenureFlag pretenure) { |
4320 if (length == 0) return empty_fixed_double_array(); | 4321 if (length == 0) return empty_fixed_double_array(); |
4321 | 4322 |
4322 Object* obj; | 4323 Object* obj; |
4323 { MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); | 4324 { MaybeObject* maybe_obj = AllocateRawFixedDoubleArray(length, pretenure); |
4324 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 4325 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
4325 } | 4326 } |
4326 | 4327 |
4327 reinterpret_cast<FixedDoubleArray*>(obj)->set_map(fixed_double_array_map()); | 4328 reinterpret_cast<FixedDoubleArray*>(obj)->set_map_unsafe( |
| 4329 fixed_double_array_map()); |
4328 FixedDoubleArray::cast(obj)->set_length(length); | 4330 FixedDoubleArray::cast(obj)->set_length(length); |
4329 return obj; | 4331 return obj; |
4330 } | 4332 } |
4331 | 4333 |
4332 | 4334 |
4333 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, | 4335 MaybeObject* Heap::AllocateRawFixedDoubleArray(int length, |
4334 PretenureFlag pretenure) { | 4336 PretenureFlag pretenure) { |
4335 if (length < 0 || length > FixedDoubleArray::kMaxLength) { | 4337 if (length < 0 || length > FixedDoubleArray::kMaxLength) { |
4336 return Failure::OutOfMemoryException(); | 4338 return Failure::OutOfMemoryException(); |
4337 } | 4339 } |
(...skipping 15 matching lines...) Expand all Loading... |
4353 | 4355 |
4354 return AllocateRaw(size, space, retry_space); | 4356 return AllocateRaw(size, space, retry_space); |
4355 } | 4357 } |
4356 | 4358 |
4357 | 4359 |
4358 MaybeObject* Heap::AllocateHashTable(int length, PretenureFlag pretenure) { | 4360 MaybeObject* Heap::AllocateHashTable(int length, PretenureFlag pretenure) { |
4359 Object* result; | 4361 Object* result; |
4360 { MaybeObject* maybe_result = AllocateFixedArray(length, pretenure); | 4362 { MaybeObject* maybe_result = AllocateFixedArray(length, pretenure); |
4361 if (!maybe_result->ToObject(&result)) return maybe_result; | 4363 if (!maybe_result->ToObject(&result)) return maybe_result; |
4362 } | 4364 } |
4363 reinterpret_cast<HeapObject*>(result)->set_map(hash_table_map()); | 4365 reinterpret_cast<HeapObject*>(result)->set_map_unsafe(hash_table_map()); |
4364 ASSERT(result->IsHashTable()); | 4366 ASSERT(result->IsHashTable()); |
4365 return result; | 4367 return result; |
4366 } | 4368 } |
4367 | 4369 |
4368 | 4370 |
4369 MaybeObject* Heap::AllocateGlobalContext() { | 4371 MaybeObject* Heap::AllocateGlobalContext() { |
4370 Object* result; | 4372 Object* result; |
4371 { MaybeObject* maybe_result = | 4373 { MaybeObject* maybe_result = |
4372 AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS); | 4374 AllocateFixedArray(Context::GLOBAL_CONTEXT_SLOTS); |
4373 if (!maybe_result->ToObject(&result)) return maybe_result; | 4375 if (!maybe_result->ToObject(&result)) return maybe_result; |
4374 } | 4376 } |
4375 Context* context = reinterpret_cast<Context*>(result); | 4377 Context* context = reinterpret_cast<Context*>(result); |
4376 context->set_map(global_context_map()); | 4378 context->set_map_unsafe(global_context_map()); |
4377 ASSERT(context->IsGlobalContext()); | 4379 ASSERT(context->IsGlobalContext()); |
4378 ASSERT(result->IsContext()); | 4380 ASSERT(result->IsContext()); |
4379 return result; | 4381 return result; |
4380 } | 4382 } |
4381 | 4383 |
4382 | 4384 |
4383 MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) { | 4385 MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) { |
4384 ASSERT(length >= Context::MIN_CONTEXT_SLOTS); | 4386 ASSERT(length >= Context::MIN_CONTEXT_SLOTS); |
4385 Object* result; | 4387 Object* result; |
4386 { MaybeObject* maybe_result = AllocateFixedArray(length); | 4388 { MaybeObject* maybe_result = AllocateFixedArray(length); |
4387 if (!maybe_result->ToObject(&result)) return maybe_result; | 4389 if (!maybe_result->ToObject(&result)) return maybe_result; |
4388 } | 4390 } |
4389 Context* context = reinterpret_cast<Context*>(result); | 4391 Context* context = reinterpret_cast<Context*>(result); |
4390 context->set_map(function_context_map()); | 4392 context->set_map_unsafe(function_context_map()); |
4391 context->set_closure(function); | 4393 context->set_closure(function); |
4392 context->set_previous(function->context()); | 4394 context->set_previous(function->context()); |
4393 context->set_extension(NULL); | 4395 context->set_extension(NULL); |
4394 context->set_global(function->context()->global()); | 4396 context->set_global(function->context()->global()); |
4395 return context; | 4397 return context; |
4396 } | 4398 } |
4397 | 4399 |
4398 | 4400 |
4399 MaybeObject* Heap::AllocateCatchContext(JSFunction* function, | 4401 MaybeObject* Heap::AllocateCatchContext(JSFunction* function, |
4400 Context* previous, | 4402 Context* previous, |
4401 String* name, | 4403 String* name, |
4402 Object* thrown_object) { | 4404 Object* thrown_object) { |
4403 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == Context::THROWN_OBJECT_INDEX); | 4405 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == Context::THROWN_OBJECT_INDEX); |
4404 Object* result; | 4406 Object* result; |
4405 { MaybeObject* maybe_result = | 4407 { MaybeObject* maybe_result = |
4406 AllocateFixedArray(Context::MIN_CONTEXT_SLOTS + 1); | 4408 AllocateFixedArray(Context::MIN_CONTEXT_SLOTS + 1); |
4407 if (!maybe_result->ToObject(&result)) return maybe_result; | 4409 if (!maybe_result->ToObject(&result)) return maybe_result; |
4408 } | 4410 } |
4409 Context* context = reinterpret_cast<Context*>(result); | 4411 Context* context = reinterpret_cast<Context*>(result); |
4410 context->set_map(catch_context_map()); | 4412 context->set_map_unsafe(catch_context_map()); |
4411 context->set_closure(function); | 4413 context->set_closure(function); |
4412 context->set_previous(previous); | 4414 context->set_previous(previous); |
4413 context->set_extension(name); | 4415 context->set_extension(name); |
4414 context->set_global(previous->global()); | 4416 context->set_global(previous->global()); |
4415 context->set(Context::THROWN_OBJECT_INDEX, thrown_object); | 4417 context->set(Context::THROWN_OBJECT_INDEX, thrown_object); |
4416 return context; | 4418 return context; |
4417 } | 4419 } |
4418 | 4420 |
4419 | 4421 |
4420 MaybeObject* Heap::AllocateWithContext(JSFunction* function, | 4422 MaybeObject* Heap::AllocateWithContext(JSFunction* function, |
4421 Context* previous, | 4423 Context* previous, |
4422 JSObject* extension) { | 4424 JSObject* extension) { |
4423 Object* result; | 4425 Object* result; |
4424 { MaybeObject* maybe_result = AllocateFixedArray(Context::MIN_CONTEXT_SLOTS); | 4426 { MaybeObject* maybe_result = AllocateFixedArray(Context::MIN_CONTEXT_SLOTS); |
4425 if (!maybe_result->ToObject(&result)) return maybe_result; | 4427 if (!maybe_result->ToObject(&result)) return maybe_result; |
4426 } | 4428 } |
4427 Context* context = reinterpret_cast<Context*>(result); | 4429 Context* context = reinterpret_cast<Context*>(result); |
4428 context->set_map(with_context_map()); | 4430 context->set_map_unsafe(with_context_map()); |
4429 context->set_closure(function); | 4431 context->set_closure(function); |
4430 context->set_previous(previous); | 4432 context->set_previous(previous); |
4431 context->set_extension(extension); | 4433 context->set_extension(extension); |
4432 context->set_global(previous->global()); | 4434 context->set_global(previous->global()); |
4433 return context; | 4435 return context; |
4434 } | 4436 } |
4435 | 4437 |
4436 | 4438 |
4437 MaybeObject* Heap::AllocateBlockContext(JSFunction* function, | 4439 MaybeObject* Heap::AllocateBlockContext(JSFunction* function, |
4438 Context* previous, | 4440 Context* previous, |
4439 ScopeInfo* scope_info) { | 4441 ScopeInfo* scope_info) { |
4440 Object* result; | 4442 Object* result; |
4441 { MaybeObject* maybe_result = | 4443 { MaybeObject* maybe_result = |
4442 AllocateFixedArrayWithHoles(scope_info->ContextLength()); | 4444 AllocateFixedArrayWithHoles(scope_info->ContextLength()); |
4443 if (!maybe_result->ToObject(&result)) return maybe_result; | 4445 if (!maybe_result->ToObject(&result)) return maybe_result; |
4444 } | 4446 } |
4445 Context* context = reinterpret_cast<Context*>(result); | 4447 Context* context = reinterpret_cast<Context*>(result); |
4446 context->set_map(block_context_map()); | 4448 context->set_map_unsafe(block_context_map()); |
4447 context->set_closure(function); | 4449 context->set_closure(function); |
4448 context->set_previous(previous); | 4450 context->set_previous(previous); |
4449 context->set_extension(scope_info); | 4451 context->set_extension(scope_info); |
4450 context->set_global(previous->global()); | 4452 context->set_global(previous->global()); |
4451 return context; | 4453 return context; |
4452 } | 4454 } |
4453 | 4455 |
4454 | 4456 |
4455 MaybeObject* Heap::AllocateScopeInfo(int length) { | 4457 MaybeObject* Heap::AllocateScopeInfo(int length) { |
4456 FixedArray* scope_info; | 4458 FixedArray* scope_info; |
4457 MaybeObject* maybe_scope_info = AllocateFixedArray(length, TENURED); | 4459 MaybeObject* maybe_scope_info = AllocateFixedArray(length, TENURED); |
4458 if (!maybe_scope_info->To(&scope_info)) return maybe_scope_info; | 4460 if (!maybe_scope_info->To(&scope_info)) return maybe_scope_info; |
4459 scope_info->set_map(scope_info_map()); | 4461 scope_info->set_map_unsafe(scope_info_map()); |
4460 return scope_info; | 4462 return scope_info; |
4461 } | 4463 } |
4462 | 4464 |
4463 | 4465 |
4464 MaybeObject* Heap::AllocateStruct(InstanceType type) { | 4466 MaybeObject* Heap::AllocateStruct(InstanceType type) { |
4465 Map* map; | 4467 Map* map; |
4466 switch (type) { | 4468 switch (type) { |
4467 #define MAKE_CASE(NAME, Name, name) \ | 4469 #define MAKE_CASE(NAME, Name, name) \ |
4468 case NAME##_TYPE: map = name##_map(); break; | 4470 case NAME##_TYPE: map = name##_map(); break; |
4469 STRUCT_LIST(MAKE_CASE) | 4471 STRUCT_LIST(MAKE_CASE) |
(...skipping 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6456 isolate_->heap()->store_buffer()->Compact(); | 6458 isolate_->heap()->store_buffer()->Compact(); |
6457 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); | 6459 isolate_->heap()->store_buffer()->Filter(MemoryChunk::ABOUT_TO_BE_FREED); |
6458 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { | 6460 for (chunk = chunks_queued_for_free_; chunk != NULL; chunk = next) { |
6459 next = chunk->next_chunk(); | 6461 next = chunk->next_chunk(); |
6460 isolate_->memory_allocator()->Free(chunk); | 6462 isolate_->memory_allocator()->Free(chunk); |
6461 } | 6463 } |
6462 chunks_queued_for_free_ = NULL; | 6464 chunks_queued_for_free_ = NULL; |
6463 } | 6465 } |
6464 | 6466 |
6465 } } // namespace v8::internal | 6467 } } // namespace v8::internal |
OLD | NEW |