OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 3819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3830 | 3830 |
3831 FixedTypedArrayBase* elements = | 3831 FixedTypedArrayBase* elements = |
3832 reinterpret_cast<FixedTypedArrayBase*>(object); | 3832 reinterpret_cast<FixedTypedArrayBase*>(object); |
3833 elements->set_map(MapForFixedTypedArray(array_type)); | 3833 elements->set_map(MapForFixedTypedArray(array_type)); |
3834 elements->set_length(length); | 3834 elements->set_length(length); |
3835 memset(elements->DataPtr(), 0, elements->DataSize()); | 3835 memset(elements->DataPtr(), 0, elements->DataSize()); |
3836 return elements; | 3836 return elements; |
3837 } | 3837 } |
3838 | 3838 |
3839 | 3839 |
3840 MaybeObject* Heap::CreateCode(const CodeDesc& desc, | 3840 MaybeObject* Heap::AllocateCode(int object_size, |
3841 Code::Flags flags, | 3841 bool immovable) { |
3842 Handle<Object> self_reference, | 3842 ASSERT(IsAligned(static_cast<intptr_t>(object_size), kCodeAlignment)); |
3843 bool immovable, | |
3844 bool crankshafted, | |
3845 int prologue_offset) { | |
3846 // Allocate ByteArray and ConstantPoolArray before the Code object, so that we | |
3847 // do not risk leaving uninitialized Code object (and breaking the heap). | |
3848 ByteArray* reloc_info; | |
3849 MaybeObject* maybe_reloc_info = AllocateByteArray(desc.reloc_size, TENURED); | |
3850 if (!maybe_reloc_info->To(&reloc_info)) return maybe_reloc_info; | |
3851 | |
3852 ConstantPoolArray* constant_pool; | |
3853 if (FLAG_enable_ool_constant_pool) { | |
3854 MaybeObject* maybe_constant_pool = desc.origin->AllocateConstantPool(this); | |
3855 if (!maybe_constant_pool->To(&constant_pool)) return maybe_constant_pool; | |
3856 } else { | |
3857 constant_pool = empty_constant_pool_array(); | |
3858 } | |
3859 | |
3860 // Compute size. | |
3861 int body_size = RoundUp(desc.instr_size, kObjectAlignment); | |
3862 int obj_size = Code::SizeFor(body_size); | |
3863 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); | |
3864 MaybeObject* maybe_result; | 3843 MaybeObject* maybe_result; |
3865 // Large code objects and code objects which should stay at a fixed address | 3844 // Large code objects and code objects which should stay at a fixed address |
3866 // are allocated in large object space. | 3845 // are allocated in large object space. |
3867 HeapObject* result; | 3846 HeapObject* result; |
3868 bool force_lo_space = obj_size > code_space()->AreaSize(); | 3847 bool force_lo_space = object_size > code_space()->AreaSize(); |
3869 if (force_lo_space) { | 3848 if (force_lo_space) { |
3870 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); | 3849 maybe_result = lo_space_->AllocateRaw(object_size, EXECUTABLE); |
3871 } else { | 3850 } else { |
3872 maybe_result = AllocateRaw(obj_size, CODE_SPACE, CODE_SPACE); | 3851 maybe_result = AllocateRaw(object_size, CODE_SPACE, CODE_SPACE); |
3873 } | 3852 } |
3874 if (!maybe_result->To<HeapObject>(&result)) return maybe_result; | 3853 if (!maybe_result->To<HeapObject>(&result)) return maybe_result; |
3875 | 3854 |
3876 if (immovable && !force_lo_space && | 3855 if (immovable && !force_lo_space && |
3877 // Objects on the first page of each space are never moved. | 3856 // Objects on the first page of each space are never moved. |
3878 !code_space_->FirstPage()->Contains(result->address())) { | 3857 !code_space_->FirstPage()->Contains(result->address())) { |
3879 // Discard the first code allocation, which was on a page where it could be | 3858 // Discard the first code allocation, which was on a page where it could be |
3880 // moved. | 3859 // moved. |
3881 CreateFillerObjectAt(result->address(), obj_size); | 3860 CreateFillerObjectAt(result->address(), object_size); |
3882 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); | 3861 maybe_result = lo_space_->AllocateRaw(object_size, EXECUTABLE); |
3883 if (!maybe_result->To<HeapObject>(&result)) return maybe_result; | 3862 if (!maybe_result->To<HeapObject>(&result)) return maybe_result; |
3884 } | 3863 } |
3885 | 3864 |
3886 // Initialize the object | |
3887 result->set_map_no_write_barrier(code_map()); | 3865 result->set_map_no_write_barrier(code_map()); |
3888 Code* code = Code::cast(result); | 3866 Code* code = Code::cast(result); |
3889 ASSERT(!isolate_->code_range()->exists() || | 3867 ASSERT(!isolate_->code_range()->exists() || |
3890 isolate_->code_range()->contains(code->address())); | 3868 isolate_->code_range()->contains(code->address())); |
3891 code->set_instruction_size(desc.instr_size); | |
3892 code->set_relocation_info(reloc_info); | |
3893 code->set_flags(flags); | |
3894 code->set_raw_kind_specific_flags1(0); | |
3895 code->set_raw_kind_specific_flags2(0); | |
3896 code->set_is_crankshafted(crankshafted); | |
3897 code->set_deoptimization_data(empty_fixed_array(), SKIP_WRITE_BARRIER); | |
3898 code->set_raw_type_feedback_info(undefined_value()); | |
3899 code->set_next_code_link(undefined_value()); | |
3900 code->set_handler_table(empty_fixed_array(), SKIP_WRITE_BARRIER); | |
3901 code->set_gc_metadata(Smi::FromInt(0)); | 3869 code->set_gc_metadata(Smi::FromInt(0)); |
3902 code->set_ic_age(global_ic_age_); | 3870 code->set_ic_age(global_ic_age_); |
3903 code->set_prologue_offset(prologue_offset); | |
3904 if (code->kind() == Code::OPTIMIZED_FUNCTION) { | |
3905 ASSERT(!code->marked_for_deoptimization()); | |
3906 } | |
3907 if (code->is_inline_cache_stub()) { | |
3908 ASSERT(!code->is_weak_stub()); | |
3909 ASSERT(!code->is_invalidated_weak_stub()); | |
3910 } | |
3911 | |
3912 if (FLAG_enable_ool_constant_pool) { | |
3913 desc.origin->PopulateConstantPool(constant_pool); | |
3914 } | |
3915 code->set_constant_pool(constant_pool); | |
3916 | |
3917 #ifdef ENABLE_DEBUGGER_SUPPORT | |
3918 if (code->kind() == Code::FUNCTION) { | |
3919 code->set_has_debug_break_slots( | |
3920 isolate_->debugger()->IsDebuggerActive()); | |
3921 } | |
3922 #endif | |
3923 | |
3924 // Allow self references to created code object by patching the handle to | |
3925 // point to the newly allocated Code object. | |
3926 if (!self_reference.is_null()) { | |
3927 *(self_reference.location()) = code; | |
3928 } | |
3929 // Migrate generated code. | |
3930 // The generated code can contain Object** values (typically from handles) | |
3931 // that are dereferenced during the copy to point directly to the actual heap | |
3932 // objects. These pointers can include references to the code object itself, | |
3933 // through the self_reference parameter. | |
3934 code->CopyFrom(desc); | |
3935 | |
3936 #ifdef VERIFY_HEAP | |
3937 if (FLAG_verify_heap) { | |
3938 code->Verify(); | |
3939 } | |
3940 #endif | |
3941 return code; | 3871 return code; |
3942 } | 3872 } |
3943 | 3873 |
3944 | 3874 |
3945 MaybeObject* Heap::CopyCode(Code* code) { | 3875 MaybeObject* Heap::CopyCode(Code* code) { |
3946 MaybeObject* maybe_result; | 3876 MaybeObject* maybe_result; |
3947 Object* new_constant_pool; | 3877 Object* new_constant_pool; |
3948 if (FLAG_enable_ool_constant_pool && | 3878 if (FLAG_enable_ool_constant_pool && |
3949 code->constant_pool() != empty_constant_pool_array()) { | 3879 code->constant_pool() != empty_constant_pool_array()) { |
3950 // Copy the constant pool, since edits to the copied code may modify | 3880 // Copy the constant pool, since edits to the copied code may modify |
(...skipping 3207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7158 static_cast<int>(object_sizes_last_time_[index])); | 7088 static_cast<int>(object_sizes_last_time_[index])); |
7159 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7089 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
7160 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7090 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
7161 | 7091 |
7162 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7092 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
7163 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7093 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
7164 ClearObjectStats(); | 7094 ClearObjectStats(); |
7165 } | 7095 } |
7166 | 7096 |
7167 } } // namespace v8::internal | 7097 } } // namespace v8::internal |
OLD | NEW |