| 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 4029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4040 return elements; | 4040 return elements; |
| 4041 } | 4041 } |
| 4042 | 4042 |
| 4043 | 4043 |
| 4044 MaybeObject* Heap::CreateCode(const CodeDesc& desc, | 4044 MaybeObject* Heap::CreateCode(const CodeDesc& desc, |
| 4045 Code::Flags flags, | 4045 Code::Flags flags, |
| 4046 Handle<Object> self_reference, | 4046 Handle<Object> self_reference, |
| 4047 bool immovable, | 4047 bool immovable, |
| 4048 bool crankshafted, | 4048 bool crankshafted, |
| 4049 int prologue_offset) { | 4049 int prologue_offset) { |
| 4050 // Allocate ByteArray before the Code object, so that we do not risk | 4050 // Allocate ByteArray and ConstantPoolArray before the Code object, so that we |
| 4051 // leaving uninitialized Code object (and breaking the heap). | 4051 // do not risk leaving uninitialized Code object (and breaking the heap). |
| 4052 ByteArray* reloc_info; | 4052 ByteArray* reloc_info; |
| 4053 MaybeObject* maybe_reloc_info = AllocateByteArray(desc.reloc_size, TENURED); | 4053 MaybeObject* maybe_reloc_info = AllocateByteArray(desc.reloc_size, TENURED); |
| 4054 if (!maybe_reloc_info->To(&reloc_info)) return maybe_reloc_info; | 4054 if (!maybe_reloc_info->To(&reloc_info)) return maybe_reloc_info; |
| 4055 | 4055 |
| 4056 ConstantPoolArray* constant_pool; |
| 4057 if (FLAG_enable_ool_constant_pool) { |
| 4058 MaybeObject* maybe_constant_pool = desc.origin->AllocateConstantPool(this); |
| 4059 if (!maybe_constant_pool->To(&constant_pool)) return maybe_constant_pool; |
| 4060 } else { |
| 4061 constant_pool = empty_constant_pool_array(); |
| 4062 } |
| 4063 |
| 4056 // Compute size. | 4064 // Compute size. |
| 4057 int body_size = RoundUp(desc.instr_size, kObjectAlignment); | 4065 int body_size = RoundUp(desc.instr_size, kObjectAlignment); |
| 4058 int obj_size = Code::SizeFor(body_size); | 4066 int obj_size = Code::SizeFor(body_size); |
| 4059 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); | 4067 ASSERT(IsAligned(static_cast<intptr_t>(obj_size), kCodeAlignment)); |
| 4060 MaybeObject* maybe_result; | 4068 MaybeObject* maybe_result; |
| 4061 // Large code objects and code objects which should stay at a fixed address | 4069 // Large code objects and code objects which should stay at a fixed address |
| 4062 // are allocated in large object space. | 4070 // are allocated in large object space. |
| 4063 HeapObject* result; | 4071 HeapObject* result; |
| 4064 bool force_lo_space = obj_size > code_space()->AreaSize(); | 4072 bool force_lo_space = obj_size > code_space()->AreaSize(); |
| 4065 if (force_lo_space) { | 4073 if (force_lo_space) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 4092 code->set_is_crankshafted(crankshafted); | 4100 code->set_is_crankshafted(crankshafted); |
| 4093 code->set_deoptimization_data(empty_fixed_array(), SKIP_WRITE_BARRIER); | 4101 code->set_deoptimization_data(empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 4094 code->set_raw_type_feedback_info(undefined_value()); | 4102 code->set_raw_type_feedback_info(undefined_value()); |
| 4095 code->set_handler_table(empty_fixed_array(), SKIP_WRITE_BARRIER); | 4103 code->set_handler_table(empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 4096 code->set_gc_metadata(Smi::FromInt(0)); | 4104 code->set_gc_metadata(Smi::FromInt(0)); |
| 4097 code->set_ic_age(global_ic_age_); | 4105 code->set_ic_age(global_ic_age_); |
| 4098 code->set_prologue_offset(prologue_offset); | 4106 code->set_prologue_offset(prologue_offset); |
| 4099 if (code->kind() == Code::OPTIMIZED_FUNCTION) { | 4107 if (code->kind() == Code::OPTIMIZED_FUNCTION) { |
| 4100 code->set_marked_for_deoptimization(false); | 4108 code->set_marked_for_deoptimization(false); |
| 4101 } | 4109 } |
| 4102 code->set_constant_pool(empty_constant_pool_array()); | 4110 |
| 4111 if (FLAG_enable_ool_constant_pool) { |
| 4112 desc.origin->PopulateConstantPool(constant_pool); |
| 4113 } |
| 4114 code->set_constant_pool(constant_pool); |
| 4103 | 4115 |
| 4104 #ifdef ENABLE_DEBUGGER_SUPPORT | 4116 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 4105 if (code->kind() == Code::FUNCTION) { | 4117 if (code->kind() == Code::FUNCTION) { |
| 4106 code->set_has_debug_break_slots( | 4118 code->set_has_debug_break_slots( |
| 4107 isolate_->debugger()->IsDebuggerActive()); | 4119 isolate_->debugger()->IsDebuggerActive()); |
| 4108 } | 4120 } |
| 4109 #endif | 4121 #endif |
| 4110 | 4122 |
| 4111 // Allow self references to created code object by patching the handle to | 4123 // Allow self references to created code object by patching the handle to |
| 4112 // point to the newly allocated Code object. | 4124 // point to the newly allocated Code object. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4123 #ifdef VERIFY_HEAP | 4135 #ifdef VERIFY_HEAP |
| 4124 if (FLAG_verify_heap) { | 4136 if (FLAG_verify_heap) { |
| 4125 code->Verify(); | 4137 code->Verify(); |
| 4126 } | 4138 } |
| 4127 #endif | 4139 #endif |
| 4128 return code; | 4140 return code; |
| 4129 } | 4141 } |
| 4130 | 4142 |
| 4131 | 4143 |
| 4132 MaybeObject* Heap::CopyCode(Code* code) { | 4144 MaybeObject* Heap::CopyCode(Code* code) { |
| 4145 MaybeObject* maybe_result; |
| 4146 Object* new_constant_pool; |
| 4147 if (FLAG_enable_ool_constant_pool && |
| 4148 code->constant_pool() != empty_constant_pool_array()) { |
| 4149 // Copy the constant pool, since edits to the copied code may modify |
| 4150 // the constant pool. |
| 4151 maybe_result = CopyConstantPoolArray(code->constant_pool()); |
| 4152 if (!maybe_result->ToObject(&new_constant_pool)) return maybe_result; |
| 4153 } else { |
| 4154 new_constant_pool = empty_constant_pool_array(); |
| 4155 } |
| 4156 |
| 4133 // Allocate an object the same size as the code object. | 4157 // Allocate an object the same size as the code object. |
| 4134 int obj_size = code->Size(); | 4158 int obj_size = code->Size(); |
| 4135 MaybeObject* maybe_result; | |
| 4136 if (obj_size > code_space()->AreaSize()) { | 4159 if (obj_size > code_space()->AreaSize()) { |
| 4137 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); | 4160 maybe_result = lo_space_->AllocateRaw(obj_size, EXECUTABLE); |
| 4138 } else { | 4161 } else { |
| 4139 maybe_result = AllocateRaw(obj_size, CODE_SPACE, CODE_SPACE); | 4162 maybe_result = AllocateRaw(obj_size, CODE_SPACE, CODE_SPACE); |
| 4140 } | 4163 } |
| 4141 | 4164 |
| 4142 Object* result; | 4165 Object* result; |
| 4143 if (!maybe_result->ToObject(&result)) return maybe_result; | 4166 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4144 | 4167 |
| 4145 // Copy code object. | 4168 // Copy code object. |
| 4146 Address old_addr = code->address(); | 4169 Address old_addr = code->address(); |
| 4147 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); | 4170 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); |
| 4148 CopyBlock(new_addr, old_addr, obj_size); | 4171 CopyBlock(new_addr, old_addr, obj_size); |
| 4172 Code* new_code = Code::cast(result); |
| 4173 |
| 4174 // Update the constant pool. |
| 4175 new_code->set_constant_pool(new_constant_pool); |
| 4176 |
| 4149 // Relocate the copy. | 4177 // Relocate the copy. |
| 4150 Code* new_code = Code::cast(result); | |
| 4151 ASSERT(!isolate_->code_range()->exists() || | 4178 ASSERT(!isolate_->code_range()->exists() || |
| 4152 isolate_->code_range()->contains(code->address())); | 4179 isolate_->code_range()->contains(code->address())); |
| 4153 new_code->Relocate(new_addr - old_addr); | 4180 new_code->Relocate(new_addr - old_addr); |
| 4154 return new_code; | 4181 return new_code; |
| 4155 } | 4182 } |
| 4156 | 4183 |
| 4157 | 4184 |
| 4158 MaybeObject* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { | 4185 MaybeObject* Heap::CopyCode(Code* code, Vector<byte> reloc_info) { |
| 4159 // Allocate ByteArray before the Code object, so that we do not risk | 4186 // Allocate ByteArray and ConstantPoolArray before the Code object, so that we |
| 4160 // leaving uninitialized Code object (and breaking the heap). | 4187 // do not risk leaving uninitialized Code object (and breaking the heap). |
| 4161 Object* reloc_info_array; | 4188 Object* reloc_info_array; |
| 4162 { MaybeObject* maybe_reloc_info_array = | 4189 { MaybeObject* maybe_reloc_info_array = |
| 4163 AllocateByteArray(reloc_info.length(), TENURED); | 4190 AllocateByteArray(reloc_info.length(), TENURED); |
| 4164 if (!maybe_reloc_info_array->ToObject(&reloc_info_array)) { | 4191 if (!maybe_reloc_info_array->ToObject(&reloc_info_array)) { |
| 4165 return maybe_reloc_info_array; | 4192 return maybe_reloc_info_array; |
| 4166 } | 4193 } |
| 4167 } | 4194 } |
| 4195 Object* new_constant_pool; |
| 4196 if (FLAG_enable_ool_constant_pool && |
| 4197 code->constant_pool() != empty_constant_pool_array()) { |
| 4198 // Copy the constant pool, since edits to the copied code may modify |
| 4199 // the constant pool. |
| 4200 MaybeObject* maybe_constant_pool = |
| 4201 CopyConstantPoolArray(code->constant_pool()); |
| 4202 if (!maybe_constant_pool->ToObject(&new_constant_pool)) |
| 4203 return maybe_constant_pool; |
| 4204 } else { |
| 4205 new_constant_pool = empty_constant_pool_array(); |
| 4206 } |
| 4168 | 4207 |
| 4169 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); | 4208 int new_body_size = RoundUp(code->instruction_size(), kObjectAlignment); |
| 4170 | 4209 |
| 4171 int new_obj_size = Code::SizeFor(new_body_size); | 4210 int new_obj_size = Code::SizeFor(new_body_size); |
| 4172 | 4211 |
| 4173 Address old_addr = code->address(); | 4212 Address old_addr = code->address(); |
| 4174 | 4213 |
| 4175 size_t relocation_offset = | 4214 size_t relocation_offset = |
| 4176 static_cast<size_t>(code->instruction_end() - old_addr); | 4215 static_cast<size_t>(code->instruction_end() - old_addr); |
| 4177 | 4216 |
| 4178 MaybeObject* maybe_result; | 4217 MaybeObject* maybe_result; |
| 4179 if (new_obj_size > code_space()->AreaSize()) { | 4218 if (new_obj_size > code_space()->AreaSize()) { |
| 4180 maybe_result = lo_space_->AllocateRaw(new_obj_size, EXECUTABLE); | 4219 maybe_result = lo_space_->AllocateRaw(new_obj_size, EXECUTABLE); |
| 4181 } else { | 4220 } else { |
| 4182 maybe_result = AllocateRaw(new_obj_size, CODE_SPACE, CODE_SPACE); | 4221 maybe_result = AllocateRaw(new_obj_size, CODE_SPACE, CODE_SPACE); |
| 4183 } | 4222 } |
| 4184 | 4223 |
| 4185 Object* result; | 4224 Object* result; |
| 4186 if (!maybe_result->ToObject(&result)) return maybe_result; | 4225 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 4187 | 4226 |
| 4188 // Copy code object. | 4227 // Copy code object. |
| 4189 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); | 4228 Address new_addr = reinterpret_cast<HeapObject*>(result)->address(); |
| 4190 | 4229 |
| 4191 // Copy header and instructions. | 4230 // Copy header and instructions. |
| 4192 CopyBytes(new_addr, old_addr, relocation_offset); | 4231 CopyBytes(new_addr, old_addr, relocation_offset); |
| 4193 | 4232 |
| 4194 Code* new_code = Code::cast(result); | 4233 Code* new_code = Code::cast(result); |
| 4195 new_code->set_relocation_info(ByteArray::cast(reloc_info_array)); | 4234 new_code->set_relocation_info(ByteArray::cast(reloc_info_array)); |
| 4196 | 4235 |
| 4236 // Update constant pool. |
| 4237 new_code->set_constant_pool(new_constant_pool); |
| 4238 |
| 4197 // Copy patched rinfo. | 4239 // Copy patched rinfo. |
| 4198 CopyBytes(new_code->relocation_start(), | 4240 CopyBytes(new_code->relocation_start(), |
| 4199 reloc_info.start(), | 4241 reloc_info.start(), |
| 4200 static_cast<size_t>(reloc_info.length())); | 4242 static_cast<size_t>(reloc_info.length())); |
| 4201 | 4243 |
| 4202 // Relocate the copy. | 4244 // Relocate the copy. |
| 4203 ASSERT(!isolate_->code_range()->exists() || | 4245 ASSERT(!isolate_->code_range()->exists() || |
| 4204 isolate_->code_range()->contains(code->address())); | 4246 isolate_->code_range()->contains(code->address())); |
| 4205 new_code->Relocate(new_addr - old_addr); | 4247 new_code->Relocate(new_addr - old_addr); |
| 4206 | 4248 |
| (...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5303 if (number_of_code_ptr_entries > 0) { | 5345 if (number_of_code_ptr_entries > 0) { |
| 5304 int offset = | 5346 int offset = |
| 5305 constant_pool->OffsetOfElementAt(constant_pool->first_code_ptr_index()); | 5347 constant_pool->OffsetOfElementAt(constant_pool->first_code_ptr_index()); |
| 5306 MemsetPointer( | 5348 MemsetPointer( |
| 5307 reinterpret_cast<Address*>(HeapObject::RawField(constant_pool, offset)), | 5349 reinterpret_cast<Address*>(HeapObject::RawField(constant_pool, offset)), |
| 5308 isolate()->builtins()->builtin(Builtins::kIllegal)->entry(), | 5350 isolate()->builtins()->builtin(Builtins::kIllegal)->entry(), |
| 5309 number_of_code_ptr_entries); | 5351 number_of_code_ptr_entries); |
| 5310 } | 5352 } |
| 5311 if (number_of_heap_ptr_entries > 0) { | 5353 if (number_of_heap_ptr_entries > 0) { |
| 5312 int offset = | 5354 int offset = |
| 5313 constant_pool->OffsetOfElementAt(constant_pool->first_code_ptr_index()); | 5355 constant_pool->OffsetOfElementAt(constant_pool->first_heap_ptr_index()); |
| 5314 MemsetPointer( | 5356 MemsetPointer( |
| 5315 HeapObject::RawField(constant_pool, offset), | 5357 HeapObject::RawField(constant_pool, offset), |
| 5316 undefined_value(), | 5358 undefined_value(), |
| 5317 number_of_heap_ptr_entries); | 5359 number_of_heap_ptr_entries); |
| 5318 } | 5360 } |
| 5319 return constant_pool; | 5361 return constant_pool; |
| 5320 } | 5362 } |
| 5321 | 5363 |
| 5322 | 5364 |
| 5323 MaybeObject* Heap::AllocateEmptyConstantPoolArray() { | 5365 MaybeObject* Heap::AllocateEmptyConstantPoolArray() { |
| (...skipping 2424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7748 static_cast<int>(object_sizes_last_time_[index])); | 7790 static_cast<int>(object_sizes_last_time_[index])); |
| 7749 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) | 7791 CODE_AGE_LIST_COMPLETE(ADJUST_LAST_TIME_OBJECT_COUNT) |
| 7750 #undef ADJUST_LAST_TIME_OBJECT_COUNT | 7792 #undef ADJUST_LAST_TIME_OBJECT_COUNT |
| 7751 | 7793 |
| 7752 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); | 7794 OS::MemCopy(object_counts_last_time_, object_counts_, sizeof(object_counts_)); |
| 7753 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); | 7795 OS::MemCopy(object_sizes_last_time_, object_sizes_, sizeof(object_sizes_)); |
| 7754 ClearObjectStats(); | 7796 ClearObjectStats(); |
| 7755 } | 7797 } |
| 7756 | 7798 |
| 7757 } } // namespace v8::internal | 7799 } } // namespace v8::internal |
| OLD | NEW |