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