diff options
Diffstat (limited to 'deps/v8/src/heap.h')
-rw-r--r-- | deps/v8/src/heap.h | 299 |
1 files changed, 189 insertions, 110 deletions
diff --git a/deps/v8/src/heap.h b/deps/v8/src/heap.h index 31adcbdba..f3959882d 100644 --- a/deps/v8/src/heap.h +++ b/deps/v8/src/heap.h @@ -34,104 +34,107 @@ namespace v8 { namespace internal { // Defines all the roots in Heap. -#define STRONG_ROOT_LIST(V) \ - V(Map, meta_map) \ - V(Map, heap_number_map) \ - V(Map, short_string_map) \ - V(Map, medium_string_map) \ - V(Map, long_string_map) \ - V(Map, short_ascii_string_map) \ - V(Map, medium_ascii_string_map) \ - V(Map, long_ascii_string_map) \ - V(Map, short_symbol_map) \ - V(Map, medium_symbol_map) \ - V(Map, long_symbol_map) \ - V(Map, short_ascii_symbol_map) \ - V(Map, medium_ascii_symbol_map) \ - V(Map, long_ascii_symbol_map) \ - V(Map, short_cons_symbol_map) \ - V(Map, medium_cons_symbol_map) \ - V(Map, long_cons_symbol_map) \ - V(Map, short_cons_ascii_symbol_map) \ - V(Map, medium_cons_ascii_symbol_map) \ - V(Map, long_cons_ascii_symbol_map) \ - V(Map, short_sliced_symbol_map) \ - V(Map, medium_sliced_symbol_map) \ - V(Map, long_sliced_symbol_map) \ - V(Map, short_sliced_ascii_symbol_map) \ - V(Map, medium_sliced_ascii_symbol_map) \ - V(Map, long_sliced_ascii_symbol_map) \ - V(Map, short_external_symbol_map) \ - V(Map, medium_external_symbol_map) \ - V(Map, long_external_symbol_map) \ - V(Map, short_external_ascii_symbol_map) \ - V(Map, medium_external_ascii_symbol_map) \ - V(Map, long_external_ascii_symbol_map) \ - V(Map, short_cons_string_map) \ - V(Map, medium_cons_string_map) \ - V(Map, long_cons_string_map) \ - V(Map, short_cons_ascii_string_map) \ - V(Map, medium_cons_ascii_string_map) \ - V(Map, long_cons_ascii_string_map) \ - V(Map, short_sliced_string_map) \ - V(Map, medium_sliced_string_map) \ - V(Map, long_sliced_string_map) \ - V(Map, short_sliced_ascii_string_map) \ - V(Map, medium_sliced_ascii_string_map) \ - V(Map, long_sliced_ascii_string_map) \ - V(Map, short_external_string_map) \ - V(Map, medium_external_string_map) \ - V(Map, long_external_string_map) \ - V(Map, short_external_ascii_string_map) \ - V(Map, medium_external_ascii_string_map) \ - V(Map, long_external_ascii_string_map) \ - V(Map, undetectable_short_string_map) \ - V(Map, undetectable_medium_string_map) \ - V(Map, undetectable_long_string_map) \ - V(Map, undetectable_short_ascii_string_map) \ - V(Map, undetectable_medium_ascii_string_map) \ - V(Map, undetectable_long_ascii_string_map) \ - V(Map, byte_array_map) \ - V(Map, fixed_array_map) \ - V(Map, hash_table_map) \ - V(Map, context_map) \ - V(Map, catch_context_map) \ - V(Map, global_context_map) \ - V(Map, code_map) \ - V(Map, oddball_map) \ - V(Map, boilerplate_function_map) \ - V(Map, shared_function_info_map) \ - V(Map, proxy_map) \ - V(Map, one_word_filler_map) \ - V(Map, two_word_filler_map) \ - V(Object, nan_value) \ - V(Object, undefined_value) \ - V(Object, minus_zero_value) \ - V(Object, null_value) \ - V(Object, true_value) \ - V(Object, false_value) \ - V(String, empty_string) \ - V(FixedArray, empty_fixed_array) \ - V(DescriptorArray, empty_descriptor_array) \ - V(Object, the_hole_value) \ - V(Map, neander_map) \ - V(JSObject, message_listeners) \ - V(Proxy, prototype_accessors) \ - V(Dictionary, code_stubs) \ - V(Dictionary, non_monomorphic_cache) \ - V(Code, js_entry_code) \ - V(Code, js_construct_entry_code) \ - V(Code, c_entry_code) \ - V(Code, c_entry_debug_break_code) \ - V(FixedArray, number_string_cache) \ - V(FixedArray, single_character_string_cache) \ - V(FixedArray, natives_source_cache) \ - V(Object, last_script_id) +#define STRONG_ROOT_LIST(V) \ + V(Map, meta_map, MetaMap) \ + V(Map, heap_number_map, HeapNumberMap) \ + V(Map, short_string_map, ShortStringMap) \ + V(Map, medium_string_map, MediumStringMap) \ + V(Map, long_string_map, LongStringMap) \ + V(Map, short_ascii_string_map, ShortAsciiStringMap) \ + V(Map, medium_ascii_string_map, MediumAsciiStringMap) \ + V(Map, long_ascii_string_map, LongAsciiStringMap) \ + V(Map, short_symbol_map, ShortSymbolMap) \ + V(Map, medium_symbol_map, MediumSymbolMap) \ + V(Map, long_symbol_map, LongSymbolMap) \ + V(Map, short_ascii_symbol_map, ShortAsciiSymbolMap) \ + V(Map, medium_ascii_symbol_map, MediumAsciiSymbolMap) \ + V(Map, long_ascii_symbol_map, LongAsciiSymbolMap) \ + V(Map, short_cons_symbol_map, ShortConsSymbolMap) \ + V(Map, medium_cons_symbol_map, MediumConsSymbolMap) \ + V(Map, long_cons_symbol_map, LongConsSymbolMap) \ + V(Map, short_cons_ascii_symbol_map, ShortConsAsciiSymbolMap) \ + V(Map, medium_cons_ascii_symbol_map, MediumConsAsciiSymbolMap) \ + V(Map, long_cons_ascii_symbol_map, LongConsAsciiSymbolMap) \ + V(Map, short_sliced_symbol_map, ShortSlicedSymbolMap) \ + V(Map, medium_sliced_symbol_map, MediumSlicedSymbolMap) \ + V(Map, long_sliced_symbol_map, LongSlicedSymbolMap) \ + V(Map, short_sliced_ascii_symbol_map, ShortSlicedAsciiSymbolMap) \ + V(Map, medium_sliced_ascii_symbol_map, MediumSlicedAsciiSymbolMap) \ + V(Map, long_sliced_ascii_symbol_map, LongSlicedAsciiSymbolMap) \ + V(Map, short_external_symbol_map, ShortExternalSymbolMap) \ + V(Map, medium_external_symbol_map, MediumExternalSymbolMap) \ + V(Map, long_external_symbol_map, LongExternalSymbolMap) \ + V(Map, short_external_ascii_symbol_map, ShortExternalAsciiSymbolMap) \ + V(Map, medium_external_ascii_symbol_map, MediumExternalAsciiSymbolMap) \ + V(Map, long_external_ascii_symbol_map, LongExternalAsciiSymbolMap) \ + V(Map, short_cons_string_map, ShortConsStringMap) \ + V(Map, medium_cons_string_map, MediumConsStringMap) \ + V(Map, long_cons_string_map, LongConsStringMap) \ + V(Map, short_cons_ascii_string_map, ShortConsAsciiStringMap) \ + V(Map, medium_cons_ascii_string_map, MediumConsAsciiStringMap) \ + V(Map, long_cons_ascii_string_map, LongConsAsciiStringMap) \ + V(Map, short_sliced_string_map, ShortSlicedStringMap) \ + V(Map, medium_sliced_string_map, MediumSlicedStringMap) \ + V(Map, long_sliced_string_map, LongSlicedStringMap) \ + V(Map, short_sliced_ascii_string_map, ShortSlicedAsciiStringMap) \ + V(Map, medium_sliced_ascii_string_map, MediumSlicedAsciiStringMap) \ + V(Map, long_sliced_ascii_string_map, LongSlicedAsciiStringMap) \ + V(Map, short_external_string_map, ShortExternalStringMap) \ + V(Map, medium_external_string_map, MediumExternalStringMap) \ + V(Map, long_external_string_map, LongExternalStringMap) \ + V(Map, short_external_ascii_string_map, ShortExternalAsciiStringMap) \ + V(Map, medium_external_ascii_string_map, MediumExternalAsciiStringMap) \ + V(Map, long_external_ascii_string_map, LongExternalAsciiStringMap) \ + V(Map, undetectable_short_string_map, UndetectableShortStringMap) \ + V(Map, undetectable_medium_string_map, UndetectableMediumStringMap) \ + V(Map, undetectable_long_string_map, UndetectableLongStringMap) \ + V(Map, undetectable_short_ascii_string_map, UndetectableShortAsciiStringMap) \ + V(Map, \ + undetectable_medium_ascii_string_map, \ + UndetectableMediumAsciiStringMap) \ + V(Map, undetectable_long_ascii_string_map, UndetectableLongAsciiStringMap) \ + V(Map, byte_array_map, ByteArrayMap) \ + V(Map, fixed_array_map, FixedArrayMap) \ + V(Map, hash_table_map, HashTableMap) \ + V(Map, context_map, ContextMap) \ + V(Map, catch_context_map, CatchContextMap) \ + V(Map, global_context_map, GlobalContextMap) \ + V(Map, code_map, CodeMap) \ + V(Map, oddball_map, OddballMap) \ + V(Map, global_property_cell_map, GlobalPropertyCellMap) \ + V(Map, boilerplate_function_map, BoilerplateFunctionMap) \ + V(Map, shared_function_info_map, SharedFunctionInfoMap) \ + V(Map, proxy_map, ProxyMap) \ + V(Map, one_pointer_filler_map, OnePointerFillerMap) \ + V(Map, two_pointer_filler_map, TwoPointerFillerMap) \ + V(Object, nan_value, NanValue) \ + V(Object, undefined_value, UndefinedValue) \ + V(Object, minus_zero_value, MinusZeroValue) \ + V(Object, null_value, NullValue) \ + V(Object, true_value, TrueValue) \ + V(Object, false_value, FalseValue) \ + V(String, empty_string, EmptyString) \ + V(FixedArray, empty_fixed_array, EmptyFixedArray) \ + V(DescriptorArray, empty_descriptor_array, EmptyDescriptorArray) \ + V(Object, the_hole_value, TheHoleValue) \ + V(Map, neander_map, NeanderMap) \ + V(JSObject, message_listeners, MessageListeners) \ + V(Proxy, prototype_accessors, PrototypeAccessors) \ + V(NumberDictionary, code_stubs, CodeStubs) \ + V(NumberDictionary, non_monomorphic_cache, NonMonomorphicCache) \ + V(Code, js_entry_code, JsEntryCode) \ + V(Code, js_construct_entry_code, JsConstructEntryCode) \ + V(Code, c_entry_code, CEntryCode) \ + V(Code, c_entry_debug_break_code, CEntryDebugBreakCode) \ + V(FixedArray, number_string_cache, NumberStringCache) \ + V(FixedArray, single_character_string_cache, SingleCharacterStringCache) \ + V(FixedArray, natives_source_cache, NativesSourceCache) \ + V(Object, last_script_id, LastScriptId) #define ROOT_LIST(V) \ STRONG_ROOT_LIST(V) \ - V(Object, symbol_table) + V(SymbolTable, symbol_table, SymbolTable) #define SYMBOL_LIST(V) \ V(Array_symbol, "Array") \ @@ -260,6 +263,7 @@ class Heap : public AllStatic { static OldSpace* old_data_space() { return old_data_space_; } static OldSpace* code_space() { return code_space_; } static MapSpace* map_space() { return map_space_; } + static CellSpace* cell_space() { return cell_space_; } static LargeObjectSpace* lo_space() { return lo_space_; } static bool always_allocate() { return always_allocate_scope_depth_ != 0; } @@ -288,6 +292,12 @@ class Heap : public AllStatic { static Object* AllocateJSObject(JSFunction* constructor, PretenureFlag pretenure = NOT_TENURED); + // Allocates and initializes a new global object based on a constructor. + // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation + // failed. + // Please note this does not perform a garbage collection. + static Object* AllocateGlobalObject(JSFunction* constructor); + // Returns a deep copy of the JavaScript object. // Properties and elements are copied too. // Returns failure if allocation failed. @@ -408,6 +418,12 @@ class Heap : public AllStatic { // Please note this does not perform a garbage collection. static Object* AllocateByteArray(int length); + // Allocate a tenured JS global property cell. + // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation + // failed. + // Please note this does not perform a garbage collection. + static Object* AllocateJSGlobalPropertyCell(Object* value); + // Allocates a fixed array initialized with undefined values // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation // failed. @@ -623,18 +639,29 @@ class Heap : public AllStatic { global_gc_epilogue_callback_ = callback; } - // Heap roots -#define ROOT_ACCESSOR(type, name) static type* name() { return name##_; } + // Heap root getters. We have versions with and without type::cast() here. + // You can't use type::cast during GC because the assert fails. +#define ROOT_ACCESSOR(type, name, camel_name) \ + static inline type* name() { \ + return type::cast(roots_[k##camel_name##RootIndex]); \ + } \ + static inline type* raw_unchecked_##name() { \ + return reinterpret_cast<type*>(roots_[k##camel_name##RootIndex]); \ + } ROOT_LIST(ROOT_ACCESSOR) #undef ROOT_ACCESSOR // Utility type maps -#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \ - static Map* name##_map() { return name##_map_; } +#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \ + static inline Map* name##_map() { \ + return Map::cast(roots_[k##Name##MapRootIndex]); \ + } STRUCT_LIST(STRUCT_MAP_ACCESSOR) #undef STRUCT_MAP_ACCESSOR -#define SYMBOL_ACCESSOR(name, str) static String* name() { return name##_; } +#define SYMBOL_ACCESSOR(name, str) static inline String* name() { \ + return String::cast(roots_[k##name##RootIndex]); \ + } SYMBOL_LIST(SYMBOL_ACCESSOR) #undef SYMBOL_ACCESSOR @@ -679,11 +706,13 @@ class Heap : public AllStatic { static inline AllocationSpace TargetSpaceId(InstanceType type); // Sets the stub_cache_ (only used when expanding the dictionary). - static void set_code_stubs(Dictionary* value) { code_stubs_ = value; } + static void public_set_code_stubs(NumberDictionary* value) { + roots_[kCodeStubsRootIndex] = value; + } // Sets the non_monomorphic_cache_ (only used when expanding the dictionary). - static void set_non_monomorphic_cache(Dictionary* value) { - non_monomorphic_cache_ = value; + static void public_set_non_monomorphic_cache(NumberDictionary* value) { + roots_[kNonMonomorphicCacheRootIndex] = value; } // Update the next script id. @@ -824,6 +853,7 @@ class Heap : public AllStatic { static OldSpace* old_data_space_; static OldSpace* code_space_; static MapSpace* map_space_; + static CellSpace* cell_space_; static LargeObjectSpace* lo_space_; static HeapState gc_state_; @@ -836,6 +866,13 @@ class Heap : public AllStatic { static int mc_count_; // how many mark-compact collections happened static int gc_count_; // how many gc happened +#define ROOT_ACCESSOR(type, name, camel_name) \ + static inline void set_##name(type* value) { \ + roots_[k##camel_name##RootIndex] = value; \ + } + ROOT_LIST(ROOT_ACCESSOR) +#undef ROOT_ACCESSOR + #ifdef DEBUG static bool allocation_allowed_; @@ -870,20 +907,49 @@ class Heap : public AllStatic { // last GC. static int old_gen_exhausted_; - // Declare all the roots -#define ROOT_DECLARATION(type, name) static type* name##_; - ROOT_LIST(ROOT_DECLARATION) -#undef ROOT_DECLARATION + // Declare all the root indices. + enum RootListIndex { +#define ROOT_INDEX_DECLARATION(type, name, camel_name) k##camel_name##RootIndex, + STRONG_ROOT_LIST(ROOT_INDEX_DECLARATION) +#undef ROOT_INDEX_DECLARATION // Utility type maps -#define DECLARE_STRUCT_MAP(NAME, Name, name) static Map* name##_map_; +#define DECLARE_STRUCT_MAP(NAME, Name, name) k##Name##MapRootIndex, STRUCT_LIST(DECLARE_STRUCT_MAP) #undef DECLARE_STRUCT_MAP -#define SYMBOL_DECLARATION(name, str) static String* name##_; - SYMBOL_LIST(SYMBOL_DECLARATION) +#define SYMBOL_INDEX_DECLARATION(name, str) k##name##RootIndex, + SYMBOL_LIST(SYMBOL_INDEX_DECLARATION) #undef SYMBOL_DECLARATION + kSymbolTableRootIndex, + kStrongRootListLength = kSymbolTableRootIndex, + kRootListLength + }; + + static Object* roots_[kRootListLength]; + + struct StringTypeTable { + InstanceType type; + int size; + RootListIndex index; + }; + + struct ConstantSymbolTable { + const char* contents; + RootListIndex index; + }; + + struct StructTable { + InstanceType type; + int size; + RootListIndex index; + }; + + static const StringTypeTable string_type_table[]; + static const ConstantSymbolTable constant_symbol_table[]; + static const StructTable struct_table[]; + // The special hidden symbol which is an empty string, but does not match // any string when looked up in properties. static String* hidden_symbol_; @@ -911,7 +977,10 @@ class Heap : public AllStatic { // to Heap::AllocateRaw(size_in_bytes, MAP_SPACE), except that (a) it doesn't // have to test the allocation space argument and (b) can reduce code size // (since both AllocateRaw and AllocateRawMap are inlined). - static inline Object* AllocateRawMap(int size_in_bytes); + static inline Object* AllocateRawMap(); + + // Allocate an uninitialized object in the global property cell space. + static inline Object* AllocateRawCell(); // Initializes a JSObject based on its map. static void InitializeJSObjectFromMap(JSObject* obj, @@ -920,7 +989,15 @@ class Heap : public AllStatic { static bool CreateInitialMaps(); static bool CreateInitialObjects(); + + // These four Create*EntryStub functions are here because of a gcc-4.4 bug + // that assigns wrong vtable entries. + static void CreateCEntryStub(); + static void CreateCEntryDebugBreakStub(); + static void CreateJSEntryStub(); + static void CreateJSConstructEntryStub(); static void CreateFixedStubs(); + static Object* CreateOddball(Map* map, const char* to_string, Object* to_number); @@ -1042,9 +1119,11 @@ class VerifyPointersAndRSetVisitor: public ObjectVisitor { HeapObject* object = HeapObject::cast(*current); ASSERT(Heap::Contains(object)); ASSERT(object->map()->IsMap()); +#ifndef V8_TARGET_ARCH_X64 if (Heap::InNewSpace(object)) { ASSERT(Page::IsRSetSet(reinterpret_cast<Address>(current), 0)); } +#endif } } } |