OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 2945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2956 Object* result; | 2956 Object* result; |
2957 { MaybeObject* maybe_result = AllocateRawCell(); | 2957 { MaybeObject* maybe_result = AllocateRawCell(); |
2958 if (!maybe_result->ToObject(&result)) return maybe_result; | 2958 if (!maybe_result->ToObject(&result)) return maybe_result; |
2959 } | 2959 } |
2960 HeapObject::cast(result)->set_map_no_write_barrier(cell_map()); | 2960 HeapObject::cast(result)->set_map_no_write_barrier(cell_map()); |
2961 Cell::cast(result)->set_value(value); | 2961 Cell::cast(result)->set_value(value); |
2962 return result; | 2962 return result; |
2963 } | 2963 } |
2964 | 2964 |
2965 | 2965 |
2966 MaybeObject* Heap::AllocatePropertyCell(Object* value) { | 2966 MaybeObject* Heap::AllocatePropertyCell() { |
2967 Object* result; | 2967 Object* result; |
2968 MaybeObject* maybe_result = AllocateRawPropertyCell(); | 2968 MaybeObject* maybe_result = AllocateRawPropertyCell(); |
2969 if (!maybe_result->ToObject(&result)) return maybe_result; | 2969 if (!maybe_result->ToObject(&result)) return maybe_result; |
2970 | 2970 |
2971 HeapObject::cast(result)->set_map_no_write_barrier( | 2971 HeapObject::cast(result)->set_map_no_write_barrier( |
2972 global_property_cell_map()); | 2972 global_property_cell_map()); |
2973 PropertyCell* cell = PropertyCell::cast(result); | 2973 PropertyCell* cell = PropertyCell::cast(result); |
2974 cell->set_dependent_code(DependentCode::cast(empty_fixed_array()), | 2974 cell->set_dependent_code(DependentCode::cast(empty_fixed_array()), |
2975 SKIP_WRITE_BARRIER); | 2975 SKIP_WRITE_BARRIER); |
2976 cell->set_value(value); | 2976 cell->set_value(the_hole_value()); |
2977 cell->set_type(Type::None()); | 2977 cell->set_type(Type::None()); |
2978 maybe_result = cell->SetValueInferType(value); | |
2979 if (maybe_result->IsFailure()) return maybe_result; | |
2980 return result; | 2978 return result; |
2981 } | 2979 } |
2982 | 2980 |
2983 | 2981 |
2984 MaybeObject* Heap::AllocateBox(Object* value, PretenureFlag pretenure) { | 2982 MaybeObject* Heap::AllocateBox(Object* value, PretenureFlag pretenure) { |
2985 Box* result; | 2983 Box* result; |
2986 MaybeObject* maybe_result = AllocateStruct(BOX_TYPE); | 2984 MaybeObject* maybe_result = AllocateStruct(BOX_TYPE); |
2987 if (!maybe_result->To(&result)) return maybe_result; | 2985 if (!maybe_result->To(&result)) return maybe_result; |
2988 result->set_value(value); | 2986 result->set_value(value); |
2989 return result; | 2987 return result; |
(...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4844 if (!maybe_result->To<JSFunctionProxy>(&result)) return maybe_result; | 4842 if (!maybe_result->To<JSFunctionProxy>(&result)) return maybe_result; |
4845 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); | 4843 result->InitializeBody(map->instance_size(), Smi::FromInt(0)); |
4846 result->set_handler(handler); | 4844 result->set_handler(handler); |
4847 result->set_hash(undefined_value(), SKIP_WRITE_BARRIER); | 4845 result->set_hash(undefined_value(), SKIP_WRITE_BARRIER); |
4848 result->set_call_trap(call_trap); | 4846 result->set_call_trap(call_trap); |
4849 result->set_construct_trap(construct_trap); | 4847 result->set_construct_trap(construct_trap); |
4850 return result; | 4848 return result; |
4851 } | 4849 } |
4852 | 4850 |
4853 | 4851 |
4854 MaybeObject* Heap::AllocateGlobalObject(JSFunction* constructor) { | |
4855 ASSERT(constructor->has_initial_map()); | |
4856 Map* map = constructor->initial_map(); | |
4857 ASSERT(map->is_dictionary_map()); | |
4858 | |
4859 // Make sure no field properties are described in the initial map. | |
4860 // This guarantees us that normalizing the properties does not | |
4861 // require us to change property values to PropertyCells. | |
4862 ASSERT(map->NextFreePropertyIndex() == 0); | |
4863 | |
4864 // Make sure we don't have a ton of pre-allocated slots in the | |
4865 // global objects. They will be unused once we normalize the object. | |
4866 ASSERT(map->unused_property_fields() == 0); | |
4867 ASSERT(map->inobject_properties() == 0); | |
4868 | |
4869 // Initial size of the backing store to avoid resize of the storage during | |
4870 // bootstrapping. The size differs between the JS global object ad the | |
4871 // builtins object. | |
4872 int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512; | |
4873 | |
4874 // Allocate a dictionary object for backing storage. | |
4875 NameDictionary* dictionary; | |
4876 MaybeObject* maybe_dictionary = | |
4877 NameDictionary::Allocate( | |
4878 this, | |
4879 map->NumberOfOwnDescriptors() * 2 + initial_size); | |
4880 if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary; | |
4881 | |
4882 // The global object might be created from an object template with accessors. | |
4883 // Fill these accessors into the dictionary. | |
4884 DescriptorArray* descs = map->instance_descriptors(); | |
4885 for (int i = 0; i < map->NumberOfOwnDescriptors(); i++) { | |
4886 PropertyDetails details = descs->GetDetails(i); | |
4887 ASSERT(details.type() == CALLBACKS); // Only accessors are expected. | |
4888 PropertyDetails d = PropertyDetails(details.attributes(), CALLBACKS, i + 1); | |
4889 Object* value = descs->GetCallbacksObject(i); | |
4890 MaybeObject* maybe_value = AllocatePropertyCell(value); | |
4891 if (!maybe_value->ToObject(&value)) return maybe_value; | |
4892 | |
4893 MaybeObject* maybe_added = dictionary->Add(descs->GetKey(i), value, d); | |
4894 if (!maybe_added->To(&dictionary)) return maybe_added; | |
4895 } | |
4896 | |
4897 // Allocate the global object and initialize it with the backing store. | |
4898 JSObject* global; | |
4899 MaybeObject* maybe_global = Allocate(map, OLD_POINTER_SPACE); | |
4900 if (!maybe_global->To(&global)) return maybe_global; | |
4901 | |
4902 InitializeJSObjectFromMap(global, dictionary, map); | |
4903 | |
4904 // Create a new map for the global object. | |
4905 Map* new_map; | |
4906 MaybeObject* maybe_map = map->CopyDropDescriptors(); | |
4907 if (!maybe_map->To(&new_map)) return maybe_map; | |
4908 new_map->set_dictionary_map(true); | |
4909 | |
4910 // Set up the global object as a normalized object. | |
4911 global->set_map(new_map); | |
4912 global->set_properties(dictionary); | |
4913 | |
4914 // Make sure result is a global object with properties in dictionary. | |
4915 ASSERT(global->IsGlobalObject()); | |
4916 ASSERT(!global->HasFastProperties()); | |
4917 return global; | |
4918 } | |
4919 | |
4920 | |
4921 MaybeObject* Heap::CopyJSObject(JSObject* source, AllocationSite* site) { | 4852 MaybeObject* Heap::CopyJSObject(JSObject* source, AllocationSite* site) { |
4922 // Never used to copy functions. If functions need to be copied we | 4853 // Never used to copy functions. If functions need to be copied we |
4923 // have to be careful to clear the literals array. | 4854 // have to be careful to clear the literals array. |
4924 SLOW_ASSERT(!source->IsJSFunction()); | 4855 SLOW_ASSERT(!source->IsJSFunction()); |
4925 | 4856 |
4926 // Make the clone. | 4857 // Make the clone. |
4927 Map* map = source->map(); | 4858 Map* map = source->map(); |
4928 int object_size = map->instance_size(); | 4859 int object_size = map->instance_size(); |
4929 Object* clone; | 4860 Object* clone; |
4930 | 4861 |
(...skipping 3076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8007 if (FLAG_concurrent_recompilation) { | 7938 if (FLAG_concurrent_recompilation) { |
8008 heap_->relocation_mutex_->Lock(); | 7939 heap_->relocation_mutex_->Lock(); |
8009 #ifdef DEBUG | 7940 #ifdef DEBUG |
8010 heap_->relocation_mutex_locked_by_optimizer_thread_ = | 7941 heap_->relocation_mutex_locked_by_optimizer_thread_ = |
8011 heap_->isolate()->optimizing_compiler_thread()->IsOptimizerThread(); | 7942 heap_->isolate()->optimizing_compiler_thread()->IsOptimizerThread(); |
8012 #endif // DEBUG | 7943 #endif // DEBUG |
8013 } | 7944 } |
8014 } | 7945 } |
8015 | 7946 |
8016 } } // namespace v8::internal | 7947 } } // namespace v8::internal |
OLD | NEW |