| 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 "src/factory.h" | 5 #include "src/factory.h" |
| 6 | 6 |
| 7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
| 8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 Handle<FixedDoubleArray> double_array = | 119 Handle<FixedDoubleArray> double_array = |
| 120 Handle<FixedDoubleArray>::cast(array); | 120 Handle<FixedDoubleArray>::cast(array); |
| 121 for (int i = 0; i < size; ++i) { | 121 for (int i = 0; i < size; ++i) { |
| 122 double_array->set_the_hole(i); | 122 double_array->set_the_hole(i); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 return array; | 125 return array; |
| 126 } | 126 } |
| 127 | 127 |
| 128 | 128 |
| 129 Handle<ConstantPoolArray> Factory::NewConstantPoolArray( | |
| 130 const ConstantPoolArray::NumberOfEntries& small) { | |
| 131 DCHECK(small.total_count() > 0); | |
| 132 CALL_HEAP_FUNCTION( | |
| 133 isolate(), | |
| 134 isolate()->heap()->AllocateConstantPoolArray(small), | |
| 135 ConstantPoolArray); | |
| 136 } | |
| 137 | |
| 138 | |
| 139 Handle<ConstantPoolArray> Factory::NewExtendedConstantPoolArray( | |
| 140 const ConstantPoolArray::NumberOfEntries& small, | |
| 141 const ConstantPoolArray::NumberOfEntries& extended) { | |
| 142 DCHECK(small.total_count() > 0); | |
| 143 DCHECK(extended.total_count() > 0); | |
| 144 CALL_HEAP_FUNCTION( | |
| 145 isolate(), | |
| 146 isolate()->heap()->AllocateExtendedConstantPoolArray(small, extended), | |
| 147 ConstantPoolArray); | |
| 148 } | |
| 149 | |
| 150 | |
| 151 Handle<OrderedHashSet> Factory::NewOrderedHashSet() { | 129 Handle<OrderedHashSet> Factory::NewOrderedHashSet() { |
| 152 return OrderedHashSet::Allocate(isolate(), OrderedHashSet::kMinCapacity); | 130 return OrderedHashSet::Allocate(isolate(), OrderedHashSet::kMinCapacity); |
| 153 } | 131 } |
| 154 | 132 |
| 155 | 133 |
| 156 Handle<OrderedHashMap> Factory::NewOrderedHashMap() { | 134 Handle<OrderedHashMap> Factory::NewOrderedHashMap() { |
| 157 return OrderedHashMap::Allocate(isolate(), OrderedHashMap::kMinCapacity); | 135 return OrderedHashMap::Allocate(isolate(), OrderedHashMap::kMinCapacity); |
| 158 } | 136 } |
| 159 | 137 |
| 160 | 138 |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 | 995 |
| 1018 | 996 |
| 1019 Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( | 997 Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( |
| 1020 Handle<FixedDoubleArray> array) { | 998 Handle<FixedDoubleArray> array) { |
| 1021 CALL_HEAP_FUNCTION(isolate(), | 999 CALL_HEAP_FUNCTION(isolate(), |
| 1022 isolate()->heap()->CopyFixedDoubleArray(*array), | 1000 isolate()->heap()->CopyFixedDoubleArray(*array), |
| 1023 FixedDoubleArray); | 1001 FixedDoubleArray); |
| 1024 } | 1002 } |
| 1025 | 1003 |
| 1026 | 1004 |
| 1027 Handle<ConstantPoolArray> Factory::CopyConstantPoolArray( | |
| 1028 Handle<ConstantPoolArray> array) { | |
| 1029 CALL_HEAP_FUNCTION(isolate(), | |
| 1030 isolate()->heap()->CopyConstantPoolArray(*array), | |
| 1031 ConstantPoolArray); | |
| 1032 } | |
| 1033 | |
| 1034 | |
| 1035 Handle<Object> Factory::NewNumber(double value, | 1005 Handle<Object> Factory::NewNumber(double value, |
| 1036 PretenureFlag pretenure) { | 1006 PretenureFlag pretenure) { |
| 1037 // We need to distinguish the minus zero value and this cannot be | 1007 // We need to distinguish the minus zero value and this cannot be |
| 1038 // done after conversion to int. Doing this by comparing bit | 1008 // done after conversion to int. Doing this by comparing bit |
| 1039 // patterns is faster than using fpclassify() et al. | 1009 // patterns is faster than using fpclassify() et al. |
| 1040 if (IsMinusZero(value)) return NewHeapNumber(-0.0, IMMUTABLE, pretenure); | 1010 if (IsMinusZero(value)) return NewHeapNumber(-0.0, IMMUTABLE, pretenure); |
| 1041 | 1011 |
| 1042 int int_value = FastD2IChecked(value); | 1012 int int_value = FastD2IChecked(value); |
| 1043 if (value == int_value && Smi::IsValid(int_value)) { | 1013 if (value == int_value && Smi::IsValid(int_value)) { |
| 1044 return handle(Smi::FromInt(int_value), isolate()); | 1014 return handle(Smi::FromInt(int_value), isolate()); |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 | 1423 |
| 1454 | 1424 |
| 1455 Handle<Code> Factory::NewCode(const CodeDesc& desc, | 1425 Handle<Code> Factory::NewCode(const CodeDesc& desc, |
| 1456 Code::Flags flags, | 1426 Code::Flags flags, |
| 1457 Handle<Object> self_ref, | 1427 Handle<Object> self_ref, |
| 1458 bool immovable, | 1428 bool immovable, |
| 1459 bool crankshafted, | 1429 bool crankshafted, |
| 1460 int prologue_offset, | 1430 int prologue_offset, |
| 1461 bool is_debug) { | 1431 bool is_debug) { |
| 1462 Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED); | 1432 Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED); |
| 1463 Handle<ConstantPoolArray> constant_pool = | |
| 1464 desc.origin->NewConstantPool(isolate()); | |
| 1465 | 1433 |
| 1466 // Compute size. | 1434 // Compute size. |
| 1467 int body_size = RoundUp(desc.instr_size, kObjectAlignment); | 1435 int body_size = RoundUp(desc.instr_size, kObjectAlignment); |
| 1468 int obj_size = Code::SizeFor(body_size); | 1436 int obj_size = Code::SizeFor(body_size); |
| 1469 | 1437 |
| 1470 Handle<Code> code = NewCodeRaw(obj_size, immovable); | 1438 Handle<Code> code = NewCodeRaw(obj_size, immovable); |
| 1471 DCHECK(isolate()->code_range() == NULL || | 1439 DCHECK(isolate()->code_range() == NULL || |
| 1472 !isolate()->code_range()->valid() || | 1440 !isolate()->code_range()->valid() || |
| 1473 isolate()->code_range()->contains(code->address())); | 1441 isolate()->code_range()->contains(code->address())); |
| 1474 | 1442 |
| 1475 // The code object has not been fully initialized yet. We rely on the | 1443 // The code object has not been fully initialized yet. We rely on the |
| 1476 // fact that no allocation will happen from this point on. | 1444 // fact that no allocation will happen from this point on. |
| 1477 DisallowHeapAllocation no_gc; | 1445 DisallowHeapAllocation no_gc; |
| 1478 code->set_gc_metadata(Smi::FromInt(0)); | 1446 code->set_gc_metadata(Smi::FromInt(0)); |
| 1479 code->set_ic_age(isolate()->heap()->global_ic_age()); | 1447 code->set_ic_age(isolate()->heap()->global_ic_age()); |
| 1480 code->set_instruction_size(desc.instr_size); | 1448 code->set_instruction_size(desc.instr_size); |
| 1481 code->set_relocation_info(*reloc_info); | 1449 code->set_relocation_info(*reloc_info); |
| 1482 code->set_flags(flags); | 1450 code->set_flags(flags); |
| 1483 code->set_raw_kind_specific_flags1(0); | 1451 code->set_raw_kind_specific_flags1(0); |
| 1484 code->set_raw_kind_specific_flags2(0); | 1452 code->set_raw_kind_specific_flags2(0); |
| 1485 code->set_is_crankshafted(crankshafted); | 1453 code->set_is_crankshafted(crankshafted); |
| 1486 code->set_deoptimization_data(*empty_fixed_array(), SKIP_WRITE_BARRIER); | 1454 code->set_deoptimization_data(*empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 1487 code->set_raw_type_feedback_info(Smi::FromInt(0)); | 1455 code->set_raw_type_feedback_info(Smi::FromInt(0)); |
| 1488 code->set_next_code_link(*undefined_value()); | 1456 code->set_next_code_link(*undefined_value()); |
| 1489 code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER); | 1457 code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 1490 code->set_prologue_offset(prologue_offset); | 1458 code->set_prologue_offset(prologue_offset); |
| 1459 if (FLAG_enable_embedded_constant_pool) { |
| 1460 code->set_constant_pool_offset(desc.instr_size - desc.constant_pool_size); |
| 1461 } |
| 1491 if (code->kind() == Code::OPTIMIZED_FUNCTION) { | 1462 if (code->kind() == Code::OPTIMIZED_FUNCTION) { |
| 1492 code->set_marked_for_deoptimization(false); | 1463 code->set_marked_for_deoptimization(false); |
| 1493 } | 1464 } |
| 1494 | 1465 |
| 1495 if (is_debug) { | 1466 if (is_debug) { |
| 1496 DCHECK(code->kind() == Code::FUNCTION); | 1467 DCHECK(code->kind() == Code::FUNCTION); |
| 1497 code->set_has_debug_break_slots(true); | 1468 code->set_has_debug_break_slots(true); |
| 1498 } | 1469 } |
| 1499 | 1470 |
| 1500 desc.origin->PopulateConstantPool(*constant_pool); | |
| 1501 code->set_constant_pool(*constant_pool); | |
| 1502 | |
| 1503 // Allow self references to created code object by patching the handle to | 1471 // Allow self references to created code object by patching the handle to |
| 1504 // point to the newly allocated Code object. | 1472 // point to the newly allocated Code object. |
| 1505 if (!self_ref.is_null()) *(self_ref.location()) = *code; | 1473 if (!self_ref.is_null()) *(self_ref.location()) = *code; |
| 1506 | 1474 |
| 1507 // Migrate generated code. | 1475 // Migrate generated code. |
| 1508 // The generated code can contain Object** values (typically from handles) | 1476 // The generated code can contain Object** values (typically from handles) |
| 1509 // that are dereferenced during the copy to point directly to the actual heap | 1477 // that are dereferenced during the copy to point directly to the actual heap |
| 1510 // objects. These pointers can include references to the code object itself, | 1478 // objects. These pointers can include references to the code object itself, |
| 1511 // through the self_reference parameter. | 1479 // through the self_reference parameter. |
| 1512 code->CopyFrom(desc); | 1480 code->CopyFrom(desc); |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2463 } | 2431 } |
| 2464 | 2432 |
| 2465 | 2433 |
| 2466 Handle<Object> Factory::ToBoolean(bool value) { | 2434 Handle<Object> Factory::ToBoolean(bool value) { |
| 2467 return value ? true_value() : false_value(); | 2435 return value ? true_value() : false_value(); |
| 2468 } | 2436 } |
| 2469 | 2437 |
| 2470 | 2438 |
| 2471 } // namespace internal | 2439 } // namespace internal |
| 2472 } // namespace v8 | 2440 } // namespace v8 |
| OLD | NEW |