OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "factory.h" | 5 #include "factory.h" |
6 | 6 |
| 7 #include "macro-assembler.h" |
7 #include "isolate-inl.h" | 8 #include "isolate-inl.h" |
8 | 9 |
9 namespace v8 { | 10 namespace v8 { |
10 namespace internal { | 11 namespace internal { |
11 | 12 |
12 Handle<Box> Factory::NewBox(Handle<Object> value) { | 13 Handle<Box> Factory::NewBox(Handle<Object> value) { |
13 Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE)); | 14 Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE)); |
14 result->set_value(*value); | 15 result->set_value(*value); |
15 return result; | 16 return result; |
16 } | 17 } |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 | 1251 |
1251 | 1252 |
1252 Handle<JSObject> Factory::NewExternal(void* value) { | 1253 Handle<JSObject> Factory::NewExternal(void* value) { |
1253 Handle<Foreign> foreign = NewForeign(static_cast<Address>(value)); | 1254 Handle<Foreign> foreign = NewForeign(static_cast<Address>(value)); |
1254 Handle<JSObject> external = NewJSObjectFromMap(external_map()); | 1255 Handle<JSObject> external = NewJSObjectFromMap(external_map()); |
1255 external->SetInternalField(0, *foreign); | 1256 external->SetInternalField(0, *foreign); |
1256 return external; | 1257 return external; |
1257 } | 1258 } |
1258 | 1259 |
1259 | 1260 |
| 1261 |
| 1262 Handle<Code> NewCodeHelper(Isolate* isolate, int object_size, bool immovable) { |
| 1263 CALL_HEAP_FUNCTION(isolate, |
| 1264 isolate->heap()->AllocateCode(object_size, immovable), |
| 1265 Code); |
| 1266 } |
| 1267 |
| 1268 |
1260 Handle<Code> Factory::NewCode(const CodeDesc& desc, | 1269 Handle<Code> Factory::NewCode(const CodeDesc& desc, |
1261 Code::Flags flags, | 1270 Code::Flags flags, |
1262 Handle<Object> self_ref, | 1271 Handle<Object> self_ref, |
1263 bool immovable, | 1272 bool immovable, |
1264 bool crankshafted, | 1273 bool crankshafted, |
1265 int prologue_offset) { | 1274 int prologue_offset) { |
1266 CALL_HEAP_FUNCTION(isolate(), | 1275 Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED); |
1267 isolate()->heap()->CreateCode( | 1276 Handle<ConstantPoolArray> constant_pool = |
1268 desc, flags, self_ref, immovable, crankshafted, | 1277 desc.origin->NewConstantPool(isolate()); |
1269 prologue_offset), | 1278 |
1270 Code); | 1279 // Compute size. |
| 1280 int body_size = RoundUp(desc.instr_size, kObjectAlignment); |
| 1281 int obj_size = Code::SizeFor(body_size); |
| 1282 |
| 1283 Handle<Code> code = NewCodeHelper(isolate(), obj_size, immovable); |
| 1284 ASSERT(!isolate()->code_range()->exists() || |
| 1285 isolate()->code_range()->contains(code->address())); |
| 1286 |
| 1287 code->set_instruction_size(desc.instr_size); |
| 1288 code->set_relocation_info(*reloc_info); |
| 1289 code->set_flags(flags); |
| 1290 code->set_raw_kind_specific_flags1(0); |
| 1291 code->set_raw_kind_specific_flags2(0); |
| 1292 code->set_is_crankshafted(crankshafted); |
| 1293 code->set_deoptimization_data(*empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 1294 code->set_raw_type_feedback_info(*undefined_value()); |
| 1295 code->set_next_code_link(*undefined_value()); |
| 1296 code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 1297 code->set_prologue_offset(prologue_offset); |
| 1298 if (code->kind() == Code::OPTIMIZED_FUNCTION) { |
| 1299 code->set_marked_for_deoptimization(false); |
| 1300 } |
| 1301 |
| 1302 desc.origin->PopulateConstantPool(*constant_pool); |
| 1303 code->set_constant_pool(*constant_pool); |
| 1304 |
| 1305 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1306 if (code->kind() == Code::FUNCTION) { |
| 1307 code->set_has_debug_break_slots(isolate()->debugger()->IsDebuggerActive()); |
| 1308 } |
| 1309 #endif |
| 1310 |
| 1311 // Allow self references to created code object by patching the handle to |
| 1312 // point to the newly allocated Code object. |
| 1313 if (!self_ref.is_null()) *(self_ref.location()) = *code; |
| 1314 |
| 1315 // Migrate generated code. |
| 1316 // The generated code can contain Object** values (typically from handles) |
| 1317 // that are dereferenced during the copy to point directly to the actual heap |
| 1318 // objects. These pointers can include references to the code object itself, |
| 1319 // through the self_reference parameter. |
| 1320 code->CopyFrom(desc); |
| 1321 |
| 1322 #ifdef VERIFY_HEAP |
| 1323 if (FLAG_verify_heap) { |
| 1324 code->Verify(); |
| 1325 } |
| 1326 #endif |
| 1327 return code; |
1271 } | 1328 } |
1272 | 1329 |
1273 | 1330 |
1274 Handle<Code> Factory::CopyCode(Handle<Code> code) { | 1331 Handle<Code> Factory::CopyCode(Handle<Code> code) { |
1275 CALL_HEAP_FUNCTION(isolate(), | 1332 CALL_HEAP_FUNCTION(isolate(), |
1276 isolate()->heap()->CopyCode(*code), | 1333 isolate()->heap()->CopyCode(*code), |
1277 Code); | 1334 Code); |
1278 } | 1335 } |
1279 | 1336 |
1280 | 1337 |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 if (String::Equals(name, infinity_string())) return infinity_value(); | 2047 if (String::Equals(name, infinity_string())) return infinity_value(); |
1991 return Handle<Object>::null(); | 2048 return Handle<Object>::null(); |
1992 } | 2049 } |
1993 | 2050 |
1994 | 2051 |
1995 Handle<Object> Factory::ToBoolean(bool value) { | 2052 Handle<Object> Factory::ToBoolean(bool value) { |
1996 return value ? true_value() : false_value(); | 2053 return value ? true_value() : false_value(); |
1997 } | 2054 } |
1998 | 2055 |
1999 } } // namespace v8::internal | 2056 } } // namespace v8::internal |
OLD | NEW |