| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 Handle<FixedDoubleArray> Factory::NewFixedDoubleArray(int size, | 72 Handle<FixedDoubleArray> Factory::NewFixedDoubleArray(int size, |
| 73 PretenureFlag pretenure) { | 73 PretenureFlag pretenure) { |
| 74 ASSERT(0 <= size); | 74 ASSERT(0 <= size); |
| 75 CALL_HEAP_FUNCTION( | 75 CALL_HEAP_FUNCTION( |
| 76 isolate(), | 76 isolate(), |
| 77 isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure), | 77 isolate()->heap()->AllocateUninitializedFixedDoubleArray(size, pretenure), |
| 78 FixedDoubleArray); | 78 FixedDoubleArray); |
| 79 } | 79 } |
| 80 | 80 |
| 81 | 81 |
| 82 Handle<ConstantPoolArray> Factory::NewConstantPoolArray( |
| 83 int number_of_int64_entries, |
| 84 int number_of_ptr_entries, |
| 85 int number_of_int32_entries) { |
| 86 ASSERT(number_of_int64_entries > 0 || number_of_ptr_entries > 0 || |
| 87 number_of_int32_entries > 0); |
| 88 CALL_HEAP_FUNCTION( |
| 89 isolate(), |
| 90 isolate()->heap()->AllocateConstantPoolArray(number_of_int64_entries, |
| 91 number_of_ptr_entries, |
| 92 number_of_int32_entries), |
| 93 ConstantPoolArray); |
| 94 } |
| 95 |
| 96 |
| 82 Handle<NameDictionary> Factory::NewNameDictionary(int at_least_space_for) { | 97 Handle<NameDictionary> Factory::NewNameDictionary(int at_least_space_for) { |
| 83 ASSERT(0 <= at_least_space_for); | 98 ASSERT(0 <= at_least_space_for); |
| 84 CALL_HEAP_FUNCTION(isolate(), | 99 CALL_HEAP_FUNCTION(isolate(), |
| 85 NameDictionary::Allocate(isolate()->heap(), | 100 NameDictionary::Allocate(isolate()->heap(), |
| 86 at_least_space_for), | 101 at_least_space_for), |
| 87 NameDictionary); | 102 NameDictionary); |
| 88 } | 103 } |
| 89 | 104 |
| 90 | 105 |
| 91 Handle<SeededNumberDictionary> Factory::NewSeededNumberDictionary( | 106 Handle<SeededNumberDictionary> Factory::NewSeededNumberDictionary( |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 531 |
| 517 Handle<Cell> Factory::NewCell(Handle<Object> value) { | 532 Handle<Cell> Factory::NewCell(Handle<Object> value) { |
| 518 AllowDeferredHandleDereference convert_to_cell; | 533 AllowDeferredHandleDereference convert_to_cell; |
| 519 CALL_HEAP_FUNCTION( | 534 CALL_HEAP_FUNCTION( |
| 520 isolate(), | 535 isolate(), |
| 521 isolate()->heap()->AllocateCell(*value), | 536 isolate()->heap()->AllocateCell(*value), |
| 522 Cell); | 537 Cell); |
| 523 } | 538 } |
| 524 | 539 |
| 525 | 540 |
| 541 Handle<PropertyCell> Factory::NewPropertyCellWithHole() { |
| 542 CALL_HEAP_FUNCTION( |
| 543 isolate(), |
| 544 isolate()->heap()->AllocatePropertyCell(), |
| 545 PropertyCell); |
| 546 } |
| 547 |
| 548 |
| 526 Handle<PropertyCell> Factory::NewPropertyCell(Handle<Object> value) { | 549 Handle<PropertyCell> Factory::NewPropertyCell(Handle<Object> value) { |
| 527 AllowDeferredHandleDereference convert_to_cell; | 550 AllowDeferredHandleDereference convert_to_cell; |
| 528 CALL_HEAP_FUNCTION( | 551 Handle<PropertyCell> cell = NewPropertyCellWithHole(); |
| 529 isolate(), | 552 PropertyCell::SetValueInferType(cell, value); |
| 530 isolate()->heap()->AllocatePropertyCell(*value), | 553 return cell; |
| 531 PropertyCell); | |
| 532 } | 554 } |
| 533 | 555 |
| 534 | 556 |
| 535 Handle<AllocationSite> Factory::NewAllocationSite() { | 557 Handle<AllocationSite> Factory::NewAllocationSite() { |
| 536 CALL_HEAP_FUNCTION( | 558 CALL_HEAP_FUNCTION( |
| 537 isolate(), | 559 isolate(), |
| 538 isolate()->heap()->AllocateAllocationSite(), | 560 isolate()->heap()->AllocateAllocationSite(), |
| 539 AllocationSite); | 561 AllocationSite); |
| 540 } | 562 } |
| 541 | 563 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 FixedArray); | 639 FixedArray); |
| 618 } | 640 } |
| 619 | 641 |
| 620 | 642 |
| 621 Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( | 643 Handle<FixedDoubleArray> Factory::CopyFixedDoubleArray( |
| 622 Handle<FixedDoubleArray> array) { | 644 Handle<FixedDoubleArray> array) { |
| 623 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); | 645 CALL_HEAP_FUNCTION(isolate(), array->Copy(), FixedDoubleArray); |
| 624 } | 646 } |
| 625 | 647 |
| 626 | 648 |
| 649 Handle<ConstantPoolArray> Factory::CopyConstantPoolArray( |
| 650 Handle<ConstantPoolArray> array) { |
| 651 CALL_HEAP_FUNCTION(isolate(), array->Copy(), ConstantPoolArray); |
| 652 } |
| 653 |
| 654 |
| 627 Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo( | 655 Handle<JSFunction> Factory::BaseNewFunctionFromSharedFunctionInfo( |
| 628 Handle<SharedFunctionInfo> function_info, | 656 Handle<SharedFunctionInfo> function_info, |
| 629 Handle<Map> function_map, | 657 Handle<Map> function_map, |
| 630 PretenureFlag pretenure) { | 658 PretenureFlag pretenure) { |
| 631 CALL_HEAP_FUNCTION( | 659 CALL_HEAP_FUNCTION( |
| 632 isolate(), | 660 isolate(), |
| 633 isolate()->heap()->AllocateFunction(*function_map, | 661 isolate()->heap()->AllocateFunction(*function_map, |
| 634 *function_info, | 662 *function_info, |
| 635 isolate()->heap()->the_hole_value(), | 663 isolate()->heap()->the_hole_value(), |
| 636 pretenure), | 664 pretenure), |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 CALL_HEAP_FUNCTION(isolate(), | 1008 CALL_HEAP_FUNCTION(isolate(), |
| 981 isolate()->heap()->AllocateExternal(value), | 1009 isolate()->heap()->AllocateExternal(value), |
| 982 JSObject); | 1010 JSObject); |
| 983 } | 1011 } |
| 984 | 1012 |
| 985 | 1013 |
| 986 Handle<Code> Factory::NewCode(const CodeDesc& desc, | 1014 Handle<Code> Factory::NewCode(const CodeDesc& desc, |
| 987 Code::Flags flags, | 1015 Code::Flags flags, |
| 988 Handle<Object> self_ref, | 1016 Handle<Object> self_ref, |
| 989 bool immovable, | 1017 bool immovable, |
| 990 bool crankshafted) { | 1018 bool crankshafted, |
| 1019 int prologue_offset) { |
| 991 CALL_HEAP_FUNCTION(isolate(), | 1020 CALL_HEAP_FUNCTION(isolate(), |
| 992 isolate()->heap()->CreateCode( | 1021 isolate()->heap()->CreateCode( |
| 993 desc, flags, self_ref, immovable, crankshafted), | 1022 desc, flags, self_ref, immovable, crankshafted, |
| 1023 prologue_offset), |
| 994 Code); | 1024 Code); |
| 995 } | 1025 } |
| 996 | 1026 |
| 997 | 1027 |
| 998 Handle<Code> Factory::CopyCode(Handle<Code> code) { | 1028 Handle<Code> Factory::CopyCode(Handle<Code> code) { |
| 999 CALL_HEAP_FUNCTION(isolate(), | 1029 CALL_HEAP_FUNCTION(isolate(), |
| 1000 isolate()->heap()->CopyCode(*code), | 1030 isolate()->heap()->CopyCode(*code), |
| 1001 Code); | 1031 Code); |
| 1002 } | 1032 } |
| 1003 | 1033 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1024 | 1054 |
| 1025 | 1055 |
| 1026 Handle<JSModule> Factory::NewJSModule(Handle<Context> context, | 1056 Handle<JSModule> Factory::NewJSModule(Handle<Context> context, |
| 1027 Handle<ScopeInfo> scope_info) { | 1057 Handle<ScopeInfo> scope_info) { |
| 1028 CALL_HEAP_FUNCTION( | 1058 CALL_HEAP_FUNCTION( |
| 1029 isolate(), | 1059 isolate(), |
| 1030 isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule); | 1060 isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule); |
| 1031 } | 1061 } |
| 1032 | 1062 |
| 1033 | 1063 |
| 1034 Handle<GlobalObject> Factory::NewGlobalObject( | 1064 // TODO(mstarzinger): Temporary wrapper until handlified. |
| 1035 Handle<JSFunction> constructor) { | 1065 static Handle<NameDictionary> NameDictionaryAdd(Handle<NameDictionary> dict, |
| 1036 CALL_HEAP_FUNCTION(isolate(), | 1066 Handle<Name> name, |
| 1037 isolate()->heap()->AllocateGlobalObject(*constructor), | 1067 Handle<Object> value, |
| 1068 PropertyDetails details) { |
| 1069 CALL_HEAP_FUNCTION(dict->GetIsolate(), |
| 1070 dict->Add(*name, *value, details), |
| 1071 NameDictionary); |
| 1072 } |
| 1073 |
| 1074 |
| 1075 static Handle<GlobalObject> NewGlobalObjectFromMap(Isolate* isolate, |
| 1076 Handle<Map> map) { |
| 1077 CALL_HEAP_FUNCTION(isolate, |
| 1078 isolate->heap()->Allocate(*map, OLD_POINTER_SPACE), |
| 1038 GlobalObject); | 1079 GlobalObject); |
| 1039 } | 1080 } |
| 1040 | 1081 |
| 1041 | 1082 |
| 1083 Handle<GlobalObject> Factory::NewGlobalObject(Handle<JSFunction> constructor) { |
| 1084 ASSERT(constructor->has_initial_map()); |
| 1085 Handle<Map> map(constructor->initial_map()); |
| 1086 ASSERT(map->is_dictionary_map()); |
| 1087 |
| 1088 // Make sure no field properties are described in the initial map. |
| 1089 // This guarantees us that normalizing the properties does not |
| 1090 // require us to change property values to PropertyCells. |
| 1091 ASSERT(map->NextFreePropertyIndex() == 0); |
| 1092 |
| 1093 // Make sure we don't have a ton of pre-allocated slots in the |
| 1094 // global objects. They will be unused once we normalize the object. |
| 1095 ASSERT(map->unused_property_fields() == 0); |
| 1096 ASSERT(map->inobject_properties() == 0); |
| 1097 |
| 1098 // Initial size of the backing store to avoid resize of the storage during |
| 1099 // bootstrapping. The size differs between the JS global object ad the |
| 1100 // builtins object. |
| 1101 int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512; |
| 1102 |
| 1103 // Allocate a dictionary object for backing storage. |
| 1104 int at_least_space_for = map->NumberOfOwnDescriptors() * 2 + initial_size; |
| 1105 Handle<NameDictionary> dictionary = NewNameDictionary(at_least_space_for); |
| 1106 |
| 1107 // The global object might be created from an object template with accessors. |
| 1108 // Fill these accessors into the dictionary. |
| 1109 Handle<DescriptorArray> descs(map->instance_descriptors()); |
| 1110 for (int i = 0; i < map->NumberOfOwnDescriptors(); i++) { |
| 1111 PropertyDetails details = descs->GetDetails(i); |
| 1112 ASSERT(details.type() == CALLBACKS); // Only accessors are expected. |
| 1113 PropertyDetails d = PropertyDetails(details.attributes(), CALLBACKS, i + 1); |
| 1114 Handle<Name> name(descs->GetKey(i)); |
| 1115 Handle<Object> value(descs->GetCallbacksObject(i), isolate()); |
| 1116 Handle<PropertyCell> cell = NewPropertyCell(value); |
| 1117 NameDictionaryAdd(dictionary, name, cell, d); |
| 1118 } |
| 1119 |
| 1120 // Allocate the global object and initialize it with the backing store. |
| 1121 Handle<GlobalObject> global = NewGlobalObjectFromMap(isolate(), map); |
| 1122 isolate()->heap()->InitializeJSObjectFromMap(*global, *dictionary, *map); |
| 1123 |
| 1124 // Create a new map for the global object. |
| 1125 Handle<Map> new_map = Map::CopyDropDescriptors(map); |
| 1126 new_map->set_dictionary_map(true); |
| 1127 |
| 1128 // Set up the global object as a normalized object. |
| 1129 global->set_map(*new_map); |
| 1130 global->set_properties(*dictionary); |
| 1131 |
| 1132 // Make sure result is a global object with properties in dictionary. |
| 1133 ASSERT(global->IsGlobalObject() && !global->HasFastProperties()); |
| 1134 return global; |
| 1135 } |
| 1136 |
| 1042 | 1137 |
| 1043 Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map, | 1138 Handle<JSObject> Factory::NewJSObjectFromMap(Handle<Map> map, |
| 1044 PretenureFlag pretenure, | 1139 PretenureFlag pretenure, |
| 1045 bool alloc_props) { | 1140 bool alloc_props) { |
| 1046 CALL_HEAP_FUNCTION( | 1141 CALL_HEAP_FUNCTION( |
| 1047 isolate(), | 1142 isolate(), |
| 1048 isolate()->heap()->AllocateJSObjectFromMap(*map, pretenure, alloc_props), | 1143 isolate()->heap()->AllocateJSObjectFromMap(*map, pretenure, alloc_props), |
| 1049 JSObject); | 1144 JSObject); |
| 1050 } | 1145 } |
| 1051 | 1146 |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1646 return Handle<Object>::null(); | 1741 return Handle<Object>::null(); |
| 1647 } | 1742 } |
| 1648 | 1743 |
| 1649 | 1744 |
| 1650 Handle<Object> Factory::ToBoolean(bool value) { | 1745 Handle<Object> Factory::ToBoolean(bool value) { |
| 1651 return value ? true_value() : false_value(); | 1746 return value ? true_value() : false_value(); |
| 1652 } | 1747 } |
| 1653 | 1748 |
| 1654 | 1749 |
| 1655 } } // namespace v8::internal | 1750 } } // namespace v8::internal |
| OLD | NEW |