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