OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 Object* result = AllocateRawMap(); | 1047 Object* result = AllocateRawMap(); |
1048 if (result->IsFailure()) return result; | 1048 if (result->IsFailure()) return result; |
1049 | 1049 |
1050 Map* map = reinterpret_cast<Map*>(result); | 1050 Map* map = reinterpret_cast<Map*>(result); |
1051 map->set_map(meta_map()); | 1051 map->set_map(meta_map()); |
1052 map->set_instance_type(instance_type); | 1052 map->set_instance_type(instance_type); |
1053 map->set_prototype(null_value()); | 1053 map->set_prototype(null_value()); |
1054 map->set_constructor(null_value()); | 1054 map->set_constructor(null_value()); |
1055 map->set_instance_size(instance_size); | 1055 map->set_instance_size(instance_size); |
1056 map->set_inobject_properties(0); | 1056 map->set_inobject_properties(0); |
| 1057 map->set_pre_allocated_property_fields(0); |
1057 map->set_instance_descriptors(empty_descriptor_array()); | 1058 map->set_instance_descriptors(empty_descriptor_array()); |
1058 map->set_code_cache(empty_fixed_array()); | 1059 map->set_code_cache(empty_fixed_array()); |
1059 map->set_unused_property_fields(0); | 1060 map->set_unused_property_fields(0); |
1060 map->set_bit_field(0); | 1061 map->set_bit_field(0); |
1061 map->set_bit_field2(0); | 1062 map->set_bit_field2(0); |
1062 return map; | 1063 return map; |
1063 } | 1064 } |
1064 | 1065 |
1065 | 1066 |
1066 const Heap::StringTypeTable Heap::string_type_table[] = { | 1067 const Heap::StringTypeTable Heap::string_type_table[] = { |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1604 share->set_construct_stub(construct_stub); | 1605 share->set_construct_stub(construct_stub); |
1605 share->set_expected_nof_properties(0); | 1606 share->set_expected_nof_properties(0); |
1606 share->set_length(0); | 1607 share->set_length(0); |
1607 share->set_formal_parameter_count(0); | 1608 share->set_formal_parameter_count(0); |
1608 share->set_instance_class_name(Object_symbol()); | 1609 share->set_instance_class_name(Object_symbol()); |
1609 share->set_function_data(undefined_value()); | 1610 share->set_function_data(undefined_value()); |
1610 share->set_script(undefined_value()); | 1611 share->set_script(undefined_value()); |
1611 share->set_start_position_and_type(0); | 1612 share->set_start_position_and_type(0); |
1612 share->set_debug_info(undefined_value()); | 1613 share->set_debug_info(undefined_value()); |
1613 share->set_inferred_name(empty_string()); | 1614 share->set_inferred_name(empty_string()); |
| 1615 share->set_compiler_hints(0); |
| 1616 share->set_this_property_assignments_count(0); |
| 1617 share->set_this_property_assignments(undefined_value()); |
1614 return result; | 1618 return result; |
1615 } | 1619 } |
1616 | 1620 |
1617 | 1621 |
1618 Object* Heap::AllocateConsString(String* first, String* second) { | 1622 Object* Heap::AllocateConsString(String* first, String* second) { |
1619 int first_length = first->length(); | 1623 int first_length = first->length(); |
1620 if (first_length == 0) return second; | 1624 if (first_length == 0) return second; |
1621 | 1625 |
1622 int second_length = second->length(); | 1626 int second_length = second->length(); |
1623 if (second_length == 0) return first; | 1627 if (second_length == 0) return first; |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2043 ASSERT(JSObject::cast(result)->HasFastProperties()); | 2047 ASSERT(JSObject::cast(result)->HasFastProperties()); |
2044 ASSERT(JSObject::cast(result)->HasFastElements()); | 2048 ASSERT(JSObject::cast(result)->HasFastElements()); |
2045 | 2049 |
2046 return result; | 2050 return result; |
2047 } | 2051 } |
2048 | 2052 |
2049 | 2053 |
2050 Object* Heap::AllocateInitialMap(JSFunction* fun) { | 2054 Object* Heap::AllocateInitialMap(JSFunction* fun) { |
2051 ASSERT(!fun->has_initial_map()); | 2055 ASSERT(!fun->has_initial_map()); |
2052 | 2056 |
2053 // First create a new map with the expected number of properties being | 2057 // First create a new map with the size and number of in-object properties |
2054 // allocated in-object. | 2058 // suggested by the function. |
2055 int expected_nof_properties = fun->shared()->expected_nof_properties(); | 2059 int instance_size = fun->shared()->CalculateInstanceSize(); |
2056 int instance_size = JSObject::kHeaderSize + | 2060 int in_object_properties = fun->shared()->CalculateInObjectProperties(); |
2057 expected_nof_properties * kPointerSize; | |
2058 if (instance_size > JSObject::kMaxInstanceSize) { | |
2059 instance_size = JSObject::kMaxInstanceSize; | |
2060 expected_nof_properties = (instance_size - JSObject::kHeaderSize) / | |
2061 kPointerSize; | |
2062 } | |
2063 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size); | 2061 Object* map_obj = Heap::AllocateMap(JS_OBJECT_TYPE, instance_size); |
2064 if (map_obj->IsFailure()) return map_obj; | 2062 if (map_obj->IsFailure()) return map_obj; |
2065 | 2063 |
2066 // Fetch or allocate prototype. | 2064 // Fetch or allocate prototype. |
2067 Object* prototype; | 2065 Object* prototype; |
2068 if (fun->has_instance_prototype()) { | 2066 if (fun->has_instance_prototype()) { |
2069 prototype = fun->instance_prototype(); | 2067 prototype = fun->instance_prototype(); |
2070 } else { | 2068 } else { |
2071 prototype = AllocateFunctionPrototype(fun); | 2069 prototype = AllocateFunctionPrototype(fun); |
2072 if (prototype->IsFailure()) return prototype; | 2070 if (prototype->IsFailure()) return prototype; |
2073 } | 2071 } |
2074 Map* map = Map::cast(map_obj); | 2072 Map* map = Map::cast(map_obj); |
2075 map->set_inobject_properties(expected_nof_properties); | 2073 map->set_inobject_properties(in_object_properties); |
2076 map->set_unused_property_fields(expected_nof_properties); | 2074 map->set_unused_property_fields(in_object_properties); |
2077 map->set_prototype(prototype); | 2075 map->set_prototype(prototype); |
| 2076 |
| 2077 // If the function has only simple this property assignments add field |
| 2078 // descriptors for these to the initial map as the object cannot be |
| 2079 // constructed without having these properties. |
| 2080 ASSERT(in_object_properties <= Map::kMaxPreAllocatedPropertyFields); |
| 2081 if (fun->shared()->has_only_this_property_assignments() && |
| 2082 fun->shared()->this_property_assignments_count() > 0) { |
| 2083 int count = fun->shared()->this_property_assignments_count(); |
| 2084 if (count > in_object_properties) { |
| 2085 count = in_object_properties; |
| 2086 } |
| 2087 DescriptorArray* descriptors = *Factory::NewDescriptorArray(count); |
| 2088 if (descriptors->IsFailure()) return descriptors; |
| 2089 for (int i = 0; i < count; i++) { |
| 2090 String* name = fun->shared()->GetThisPropertyAssignmentName(i); |
| 2091 ASSERT(name->IsSymbol()); |
| 2092 FieldDescriptor field(name, i, NONE); |
| 2093 descriptors->Set(i, &field); |
| 2094 } |
| 2095 descriptors->Sort(); |
| 2096 map->set_instance_descriptors(descriptors); |
| 2097 map->set_pre_allocated_property_fields(count); |
| 2098 map->set_unused_property_fields(in_object_properties - count); |
| 2099 } |
2078 return map; | 2100 return map; |
2079 } | 2101 } |
2080 | 2102 |
2081 | 2103 |
2082 void Heap::InitializeJSObjectFromMap(JSObject* obj, | 2104 void Heap::InitializeJSObjectFromMap(JSObject* obj, |
2083 FixedArray* properties, | 2105 FixedArray* properties, |
2084 Map* map) { | 2106 Map* map) { |
2085 obj->set_properties(properties); | 2107 obj->set_properties(properties); |
2086 obj->initialize_elements(); | 2108 obj->initialize_elements(); |
2087 // TODO(1240798): Initialize the object's body using valid initial values | 2109 // TODO(1240798): Initialize the object's body using valid initial values |
(...skipping 11 matching lines...) Expand all Loading... |
2099 // JSFunctions should be allocated using AllocateFunction to be | 2121 // JSFunctions should be allocated using AllocateFunction to be |
2100 // properly initialized. | 2122 // properly initialized. |
2101 ASSERT(map->instance_type() != JS_FUNCTION_TYPE); | 2123 ASSERT(map->instance_type() != JS_FUNCTION_TYPE); |
2102 | 2124 |
2103 // Both types of globla objects should be allocated using | 2125 // Both types of globla objects should be allocated using |
2104 // AllocateGloblaObject to be properly initialized. | 2126 // AllocateGloblaObject to be properly initialized. |
2105 ASSERT(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); | 2127 ASSERT(map->instance_type() != JS_GLOBAL_OBJECT_TYPE); |
2106 ASSERT(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); | 2128 ASSERT(map->instance_type() != JS_BUILTINS_OBJECT_TYPE); |
2107 | 2129 |
2108 // Allocate the backing storage for the properties. | 2130 // Allocate the backing storage for the properties. |
2109 int prop_size = map->unused_property_fields() - map->inobject_properties(); | 2131 int prop_size = |
| 2132 map->pre_allocated_property_fields() + |
| 2133 map->unused_property_fields() - |
| 2134 map->inobject_properties(); |
| 2135 ASSERT(prop_size >= 0); |
2110 Object* properties = AllocateFixedArray(prop_size, pretenure); | 2136 Object* properties = AllocateFixedArray(prop_size, pretenure); |
2111 if (properties->IsFailure()) return properties; | 2137 if (properties->IsFailure()) return properties; |
2112 | 2138 |
2113 // Allocate the JSObject. | 2139 // Allocate the JSObject. |
2114 AllocationSpace space = | 2140 AllocationSpace space = |
2115 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; | 2141 (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE; |
2116 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE; | 2142 if (map->instance_size() > MaxObjectSizeInPagedSpace()) space = LO_SPACE; |
2117 Object* obj = Allocate(map, space); | 2143 Object* obj = Allocate(map, space); |
2118 if (obj->IsFailure()) return obj; | 2144 if (obj->IsFailure()) return obj; |
2119 | 2145 |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2592 FixedArray* result = FixedArray::cast(obj); | 2618 FixedArray* result = FixedArray::cast(obj); |
2593 result->set_length(len); | 2619 result->set_length(len); |
2594 // Copy the content | 2620 // Copy the content |
2595 WriteBarrierMode mode = result->GetWriteBarrierMode(); | 2621 WriteBarrierMode mode = result->GetWriteBarrierMode(); |
2596 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); | 2622 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); |
2597 return result; | 2623 return result; |
2598 } | 2624 } |
2599 | 2625 |
2600 | 2626 |
2601 Object* Heap::AllocateFixedArray(int length) { | 2627 Object* Heap::AllocateFixedArray(int length) { |
| 2628 ASSERT(length >= 0); |
2602 if (length == 0) return empty_fixed_array(); | 2629 if (length == 0) return empty_fixed_array(); |
2603 Object* result = AllocateRawFixedArray(length); | 2630 Object* result = AllocateRawFixedArray(length); |
2604 if (!result->IsFailure()) { | 2631 if (!result->IsFailure()) { |
2605 // Initialize header. | 2632 // Initialize header. |
2606 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); | 2633 reinterpret_cast<Array*>(result)->set_map(fixed_array_map()); |
2607 FixedArray* array = FixedArray::cast(result); | 2634 FixedArray* array = FixedArray::cast(result); |
2608 array->set_length(length); | 2635 array->set_length(length); |
2609 Object* value = undefined_value(); | 2636 Object* value = undefined_value(); |
2610 // Initialize body. | 2637 // Initialize body. |
2611 for (int index = 0; index < length; index++) { | 2638 for (int index = 0; index < length; index++) { |
(...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3885 #ifdef DEBUG | 3912 #ifdef DEBUG |
3886 bool Heap::GarbageCollectionGreedyCheck() { | 3913 bool Heap::GarbageCollectionGreedyCheck() { |
3887 ASSERT(FLAG_gc_greedy); | 3914 ASSERT(FLAG_gc_greedy); |
3888 if (Bootstrapper::IsActive()) return true; | 3915 if (Bootstrapper::IsActive()) return true; |
3889 if (disallow_allocation_failure()) return true; | 3916 if (disallow_allocation_failure()) return true; |
3890 return CollectGarbage(0, NEW_SPACE); | 3917 return CollectGarbage(0, NEW_SPACE); |
3891 } | 3918 } |
3892 #endif | 3919 #endif |
3893 | 3920 |
3894 } } // namespace v8::internal | 3921 } } // namespace v8::internal |
OLD | NEW |