| 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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 | 994 |
| 1017 | 995 |
| 1018 Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( | 996 Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( |
| 1019 Handle<FixedDoubleArray> array) { | 997 Handle<FixedDoubleArray> array) { |
| 1020 CALL_HEAP_FUNCTION(isolate(), | 998 CALL_HEAP_FUNCTION(isolate(), |
| 1021 isolate()->heap()->CopyFixedDoubleArray(*array), | 999 isolate()->heap()->CopyFixedDoubleArray(*array), |
| 1022 FixedDoubleArray); | 1000 FixedDoubleArray); |
| 1023 } | 1001 } |
| 1024 | 1002 |
| 1025 | 1003 |
| 1026 Handle<ConstantPoolArray> Factory::CopyConstantPoolArray( | |
| 1027 Handle<ConstantPoolArray> array) { | |
| 1028 CALL_HEAP_FUNCTION(isolate(), | |
| 1029 isolate()->heap()->CopyConstantPoolArray(*array), | |
| 1030 ConstantPoolArray); | |
| 1031 } | |
| 1032 | |
| 1033 | |
| 1034 Handle<Object> Factory::NewNumber(double value, | 1004 Handle<Object> Factory::NewNumber(double value, |
| 1035 PretenureFlag pretenure) { | 1005 PretenureFlag pretenure) { |
| 1036 // We need to distinguish the minus zero value and this cannot be | 1006 // We need to distinguish the minus zero value and this cannot be |
| 1037 // done after conversion to int. Doing this by comparing bit | 1007 // done after conversion to int. Doing this by comparing bit |
| 1038 // patterns is faster than using fpclassify() et al. | 1008 // patterns is faster than using fpclassify() et al. |
| 1039 if (IsMinusZero(value)) return NewHeapNumber(-0.0, IMMUTABLE, pretenure); | 1009 if (IsMinusZero(value)) return NewHeapNumber(-0.0, IMMUTABLE, pretenure); |
| 1040 | 1010 |
| 1041 int int_value = FastD2IChecked(value); | 1011 int int_value = FastD2IChecked(value); |
| 1042 if (value == int_value && Smi::IsValid(int_value)) { | 1012 if (value == int_value && Smi::IsValid(int_value)) { |
| 1043 return handle(Smi::FromInt(int_value), isolate()); | 1013 return handle(Smi::FromInt(int_value), isolate()); |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 | 1470 |
| 1501 | 1471 |
| 1502 Handle<Code> Factory::NewCode(const CodeDesc& desc, | 1472 Handle<Code> Factory::NewCode(const CodeDesc& desc, |
| 1503 Code::Flags flags, | 1473 Code::Flags flags, |
| 1504 Handle<Object> self_ref, | 1474 Handle<Object> self_ref, |
| 1505 bool immovable, | 1475 bool immovable, |
| 1506 bool crankshafted, | 1476 bool crankshafted, |
| 1507 int prologue_offset, | 1477 int prologue_offset, |
| 1508 bool is_debug) { | 1478 bool is_debug) { |
| 1509 Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED); | 1479 Handle<ByteArray> reloc_info = NewByteArray(desc.reloc_size, TENURED); |
| 1510 Handle<ConstantPoolArray> constant_pool = | |
| 1511 desc.origin->NewConstantPool(isolate()); | |
| 1512 | 1480 |
| 1513 // Compute size. | 1481 // Compute size. |
| 1514 int body_size = RoundUp(desc.instr_size, kObjectAlignment); | 1482 int body_size = RoundUp(desc.instr_size, kObjectAlignment); |
| 1515 int obj_size = Code::SizeFor(body_size); | 1483 int obj_size = Code::SizeFor(body_size); |
| 1516 | 1484 |
| 1517 Handle<Code> code = NewCodeRaw(obj_size, immovable); | 1485 Handle<Code> code = NewCodeRaw(obj_size, immovable); |
| 1518 DCHECK(isolate()->code_range() == NULL || | 1486 DCHECK(isolate()->code_range() == NULL || |
| 1519 !isolate()->code_range()->valid() || | 1487 !isolate()->code_range()->valid() || |
| 1520 isolate()->code_range()->contains(code->address())); | 1488 isolate()->code_range()->contains(code->address())); |
| 1521 | 1489 |
| 1522 // The code object has not been fully initialized yet. We rely on the | 1490 // The code object has not been fully initialized yet. We rely on the |
| 1523 // fact that no allocation will happen from this point on. | 1491 // fact that no allocation will happen from this point on. |
| 1524 DisallowHeapAllocation no_gc; | 1492 DisallowHeapAllocation no_gc; |
| 1525 code->set_gc_metadata(Smi::FromInt(0)); | 1493 code->set_gc_metadata(Smi::FromInt(0)); |
| 1526 code->set_ic_age(isolate()->heap()->global_ic_age()); | 1494 code->set_ic_age(isolate()->heap()->global_ic_age()); |
| 1527 code->set_instruction_size(desc.instr_size); | 1495 code->set_instruction_size(desc.instr_size); |
| 1528 code->set_relocation_info(*reloc_info); | 1496 code->set_relocation_info(*reloc_info); |
| 1529 code->set_flags(flags); | 1497 code->set_flags(flags); |
| 1530 code->set_raw_kind_specific_flags1(0); | 1498 code->set_raw_kind_specific_flags1(0); |
| 1531 code->set_raw_kind_specific_flags2(0); | 1499 code->set_raw_kind_specific_flags2(0); |
| 1532 code->set_is_crankshafted(crankshafted); | 1500 code->set_is_crankshafted(crankshafted); |
| 1533 code->set_deoptimization_data(*empty_fixed_array(), SKIP_WRITE_BARRIER); | 1501 code->set_deoptimization_data(*empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 1534 code->set_raw_type_feedback_info(Smi::FromInt(0)); | 1502 code->set_raw_type_feedback_info(Smi::FromInt(0)); |
| 1535 code->set_next_code_link(*undefined_value()); | 1503 code->set_next_code_link(*undefined_value()); |
| 1536 code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER); | 1504 code->set_handler_table(*empty_fixed_array(), SKIP_WRITE_BARRIER); |
| 1537 code->set_prologue_offset(prologue_offset); | 1505 code->set_prologue_offset(prologue_offset); |
| 1506 if (FLAG_enable_embedded_constant_pool) { |
| 1507 code->set_constant_pool_offset(desc.instr_size - desc.constant_pool_size); |
| 1508 } |
| 1538 if (code->kind() == Code::OPTIMIZED_FUNCTION) { | 1509 if (code->kind() == Code::OPTIMIZED_FUNCTION) { |
| 1539 code->set_marked_for_deoptimization(false); | 1510 code->set_marked_for_deoptimization(false); |
| 1540 } | 1511 } |
| 1541 | 1512 |
| 1542 if (is_debug) { | 1513 if (is_debug) { |
| 1543 DCHECK(code->kind() == Code::FUNCTION); | 1514 DCHECK(code->kind() == Code::FUNCTION); |
| 1544 code->set_has_debug_break_slots(true); | 1515 code->set_has_debug_break_slots(true); |
| 1545 } | 1516 } |
| 1546 | 1517 |
| 1547 desc.origin->PopulateConstantPool(*constant_pool); | |
| 1548 code->set_constant_pool(*constant_pool); | |
| 1549 | |
| 1550 // Allow self references to created code object by patching the handle to | 1518 // Allow self references to created code object by patching the handle to |
| 1551 // point to the newly allocated Code object. | 1519 // point to the newly allocated Code object. |
| 1552 if (!self_ref.is_null()) *(self_ref.location()) = *code; | 1520 if (!self_ref.is_null()) *(self_ref.location()) = *code; |
| 1553 | 1521 |
| 1554 // Migrate generated code. | 1522 // Migrate generated code. |
| 1555 // The generated code can contain Object** values (typically from handles) | 1523 // The generated code can contain Object** values (typically from handles) |
| 1556 // that are dereferenced during the copy to point directly to the actual heap | 1524 // that are dereferenced during the copy to point directly to the actual heap |
| 1557 // objects. These pointers can include references to the code object itself, | 1525 // objects. These pointers can include references to the code object itself, |
| 1558 // through the self_reference parameter. | 1526 // through the self_reference parameter. |
| 1559 code->CopyFrom(desc); | 1527 code->CopyFrom(desc); |
| (...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2481 return Handle<Object>::null(); | 2449 return Handle<Object>::null(); |
| 2482 } | 2450 } |
| 2483 | 2451 |
| 2484 | 2452 |
| 2485 Handle<Object> Factory::ToBoolean(bool value) { | 2453 Handle<Object> Factory::ToBoolean(bool value) { |
| 2486 return value ? true_value() : false_value(); | 2454 return value ? true_value() : false_value(); |
| 2487 } | 2455 } |
| 2488 | 2456 |
| 2489 | 2457 |
| 2490 } } // namespace v8::internal | 2458 } } // namespace v8::internal |
| OLD | NEW |