From: yangguo@chromium.org Date: Tue, 29 Apr 2014 08:25:24 +0000 (+0000) Subject: Make CreateInitialObjects more concise. X-Git-Tag: upstream/4.7.83~9367 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=553421709925e98e4b75b128bab6c322592e01ba;p=platform%2Fupstream%2Fv8.git Make CreateInitialObjects more concise. R=ishell@chromium.org Review URL: https://codereview.chromium.org/255003002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21038 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/factory.cc b/src/factory.cc index 22b6489..355e24f 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1086,15 +1086,6 @@ Handle Factory::NewHeapNumber(double value, } -Handle Factory::NewNeanderObject() { - CALL_HEAP_FUNCTION( - isolate(), - isolate()->heap()->AllocateJSObjectFromMap( - isolate()->heap()->neander_map()), - JSObject); -} - - Handle Factory::NewTypeError(const char* message, Vector< Handle > args) { return NewError("MakeTypeError", message, args); diff --git a/src/factory.h b/src/factory.h index 0cc7c59..7b9a9b3 100644 --- a/src/factory.h +++ b/src/factory.h @@ -339,7 +339,9 @@ class Factory V8_FINAL { // These objects are used by the api to create env-independent data // structures in the heap. - Handle NewNeanderObject(); + inline Handle NewNeanderObject() { + return NewJSObjectFromMap(neander_map()); + } Handle NewArgumentsObject(Handle callee, int length); diff --git a/src/heap.cc b/src/heap.cc index d7e1abd..0c1cc57 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -2397,11 +2397,6 @@ MaybeObject* Heap::AllocateFillerObject(int size, } -MaybeObject* Heap::AllocatePolymorphicCodeCache() { - return AllocateStruct(POLYMORPHIC_CODE_CACHE_TYPE); -} - - const Heap::StringTypeTable Heap::string_type_table[] = { #define STRING_TYPE_ELEMENT(type, size, name, camel_name) \ {type, size, k##camel_name##MapRootIndex}, @@ -2721,32 +2716,24 @@ MaybeObject* Heap::AllocatePropertyCell() { } -bool Heap::CreateApiObjects() { - Object* obj; +void Heap::CreateApiObjects() { + HandleScope scope(isolate()); + Factory* factory = isolate()->factory(); + Handle new_neander_map = + factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); - { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); - if (!maybe_obj->ToObject(&obj)) return false; - } // Don't use Smi-only elements optimizations for objects with the neander // map. There are too many cases where element values are set directly with a // bottleneck to trap the Smi-only -> fast elements transition, and there // appears to be no benefit for optimize this case. - Map* new_neander_map = Map::cast(obj); new_neander_map->set_elements_kind(TERMINAL_FAST_ELEMENTS_KIND); - set_neander_map(new_neander_map); + set_neander_map(*new_neander_map); - { MaybeObject* maybe_obj = AllocateJSObjectFromMap(neander_map()); - if (!maybe_obj->ToObject(&obj)) return false; - } - Object* elements; - { MaybeObject* maybe_elements = AllocateFixedArray(2); - if (!maybe_elements->ToObject(&elements)) return false; - } - FixedArray::cast(elements)->set(0, Smi::FromInt(0)); - JSObject::cast(obj)->set_elements(FixedArray::cast(elements)); - set_message_listeners(JSObject::cast(obj)); - - return true; + Handle listeners = factory->NewNeanderObject(); + Handle elements = factory->NewFixedArray(2); + elements->set(0, Smi::FromInt(0)); + listeners->set_elements(*elements); + set_message_listeners(*listeners); } @@ -2792,7 +2779,7 @@ void Heap::CreateFixedStubs() { } -bool Heap::CreateInitialObjects() { +void Heap::CreateInitialObjects() { HandleScope scope(isolate()); Factory* factory = isolate()->factory(); @@ -2874,19 +2861,14 @@ bool Heap::CreateInitialObjects() { roots_[constant_string_table[i].index] = *str; } - Object* obj; - // Allocate the hidden string which is used to identify the hidden properties // in JSObjects. The hash code has a special value so that it will not match // the empty string when searching for the property. It cannot be part of the // loop above because it needs to be allocated manually with the special // hash code in place. The hash code for the hidden_string is zero to ensure // that it will always be at the first entry in property descriptors. - { MaybeObject* maybe_obj = AllocateOneByteInternalizedString( + hidden_string_ = *factory->NewOneByteInternalizedString( OneByteVector("", 0), String::kEmptyStringHash); - if (!maybe_obj->ToObject(&obj)) return false; - } - hidden_string_ = String::cast(obj); // Create the code_stubs dictionary. The initial size is set to avoid // expanding the dictionary during bootstrapping. @@ -2896,10 +2878,8 @@ bool Heap::CreateInitialObjects() { // is set to avoid expanding the dictionary during bootstrapping. set_non_monomorphic_cache(*UnseededNumberDictionary::New(isolate(), 64)); - { MaybeObject* maybe_obj = AllocatePolymorphicCodeCache(); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_polymorphic_code_cache(PolymorphicCodeCache::cast(obj)); + set_polymorphic_code_cache(PolymorphicCodeCache::cast( + *factory->NewStruct(POLYMORPHIC_CODE_CACHE_TYPE))); set_instanceof_cache_function(Smi::FromInt(0)); set_instanceof_cache_map(Smi::FromInt(0)); @@ -2908,125 +2888,60 @@ bool Heap::CreateInitialObjects() { CreateFixedStubs(); // Allocate the dictionary of intrinsic function names. - { - Handle function_names = - NameDictionary::New(isolate(), Runtime::kNumFunctions); - Runtime::InitializeIntrinsicFunctionNames(isolate(), function_names); - set_intrinsic_function_names(*function_names); - } + Handle intrinsic_names = + NameDictionary::New(isolate(), Runtime::kNumFunctions); + Runtime::InitializeIntrinsicFunctionNames(isolate(), intrinsic_names); + set_intrinsic_function_names(*intrinsic_names); - { MaybeObject* maybe_obj = AllocateInitialNumberStringCache(); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_number_string_cache(FixedArray::cast(obj)); + set_number_string_cache(*factory->NewFixedArray( + kInitialNumberStringCacheSize * 2, TENURED)); // Allocate cache for single character one byte strings. - { MaybeObject* maybe_obj = - AllocateFixedArray(String::kMaxOneByteCharCode + 1, TENURED); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_single_character_string_cache(FixedArray::cast(obj)); - - // Allocate cache for string split. - { MaybeObject* maybe_obj = AllocateFixedArray( - RegExpResultsCache::kRegExpResultsCacheSize, TENURED); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_string_split_cache(FixedArray::cast(obj)); + set_single_character_string_cache(*factory->NewFixedArray( + String::kMaxOneByteCharCode + 1, TENURED)); - { MaybeObject* maybe_obj = AllocateFixedArray( - RegExpResultsCache::kRegExpResultsCacheSize, TENURED); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_regexp_multiple_cache(FixedArray::cast(obj)); + // Allocate cache for string split and regexp-multiple. + set_string_split_cache(*factory->NewFixedArray( + RegExpResultsCache::kRegExpResultsCacheSize, TENURED)); + set_regexp_multiple_cache(*factory->NewFixedArray( + RegExpResultsCache::kRegExpResultsCacheSize, TENURED)); // Allocate cache for external strings pointing to native source code. - { MaybeObject* maybe_obj = AllocateFixedArray(Natives::GetBuiltinsCount()); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_natives_source_cache(FixedArray::cast(obj)); + set_natives_source_cache(*factory->NewFixedArray( + Natives::GetBuiltinsCount())); - { MaybeObject* maybe_obj = AllocateCell(undefined_value()); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_undefined_cell(Cell::cast(obj)); + set_undefined_cell(*factory->NewCell(factory->undefined_value())); // The symbol registry is initialized lazily. set_symbol_registry(undefined_value()); // Allocate object to hold object observation state. - { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); - if (!maybe_obj->ToObject(&obj)) return false; - } - { MaybeObject* maybe_obj = AllocateJSObjectFromMap(Map::cast(obj)); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_observation_state(JSObject::cast(obj)); + set_observation_state(*factory->NewJSObjectFromMap( + factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize))); // Allocate object to hold object microtask state. - { MaybeObject* maybe_obj = AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); - if (!maybe_obj->ToObject(&obj)) return false; - } - { MaybeObject* maybe_obj = AllocateJSObjectFromMap(Map::cast(obj)); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_microtask_state(JSObject::cast(obj)); + set_microtask_state(*factory->NewJSObjectFromMap( + factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize))); - { MaybeObject* maybe_obj = AllocateSymbol(); - if (!maybe_obj->ToObject(&obj)) return false; - } - Symbol::cast(obj)->set_is_private(true); - set_frozen_symbol(Symbol::cast(obj)); + set_frozen_symbol(*factory->NewPrivateSymbol()); + set_nonexistent_symbol(*factory->NewPrivateSymbol()); + set_elements_transition_symbol(*factory->NewPrivateSymbol()); + set_uninitialized_symbol(*factory->NewPrivateSymbol()); + set_megamorphic_symbol(*factory->NewPrivateSymbol()); + set_observed_symbol(*factory->NewPrivateSymbol()); - { MaybeObject* maybe_obj = AllocateSymbol(); - if (!maybe_obj->ToObject(&obj)) return false; - } - Symbol::cast(obj)->set_is_private(true); - set_nonexistent_symbol(Symbol::cast(obj)); + Handle slow_element_dictionary = + SeededNumberDictionary::New(isolate(), 0, TENURED); + slow_element_dictionary->set_requires_slow_elements(); + set_empty_slow_element_dictionary(*slow_element_dictionary); - { MaybeObject* maybe_obj = AllocateSymbol(); - if (!maybe_obj->ToObject(&obj)) return false; - } - Symbol::cast(obj)->set_is_private(true); - set_elements_transition_symbol(Symbol::cast(obj)); - - { MaybeObject* maybe_obj = AllocateSymbol(); - if (!maybe_obj->ToObject(&obj)) return false; - } - Symbol::cast(obj)->set_is_private(true); - set_uninitialized_symbol(Symbol::cast(obj)); - - { MaybeObject* maybe_obj = AllocateSymbol(); - if (!maybe_obj->ToObject(&obj)) return false; - } - Symbol::cast(obj)->set_is_private(true); - set_megamorphic_symbol(Symbol::cast(obj)); - - { - Handle dict = - SeededNumberDictionary::New(isolate(), 0, TENURED); - dict->set_requires_slow_elements(); - set_empty_slow_element_dictionary(*dict); - } - - { MaybeObject* maybe_obj = AllocateSymbol(); - if (!maybe_obj->ToObject(&obj)) return false; - } - Symbol::cast(obj)->set_is_private(true); - set_observed_symbol(Symbol::cast(obj)); - - { MaybeObject* maybe_obj = AllocateFixedArray(0, TENURED); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_materialized_objects(FixedArray::cast(obj)); + set_materialized_objects(*factory->NewFixedArray(0, TENURED)); // Handling of script id generation is in Factory::NewScript. set_last_script_id(Smi::FromInt(v8::UnboundScript::kNoScriptId)); - { MaybeObject* maybe_obj = AllocateAllocationSitesScratchpad(); - if (!maybe_obj->ToObject(&obj)) return false; - } - set_allocation_sites_scratchpad(FixedArray::cast(obj)); + set_allocation_sites_scratchpad(*factory->NewFixedArray( + kAllocationSiteScratchpadSize, TENURED)); InitializeAllocationSitesScratchpad(); // Initialize keyed lookup cache. @@ -3040,8 +2955,6 @@ bool Heap::CreateInitialObjects() { // Initialize compilation cache. isolate_->compilation_cache()->Clear(); - - return true; } @@ -3175,13 +3088,6 @@ void RegExpResultsCache::Clear(FixedArray* cache) { } -MaybeObject* Heap::AllocateInitialNumberStringCache() { - MaybeObject* maybe_obj = - AllocateFixedArray(kInitialNumberStringCacheSize * 2, TENURED); - return maybe_obj; -} - - int Heap::FullSizeNumberStringCacheLength() { // Compute the size of the number string cache based on the max newspace size. // The number string cache has a minimum size based on twice the initial cache @@ -3204,13 +3110,6 @@ void Heap::FlushNumberStringCache() { } -MaybeObject* Heap::AllocateAllocationSitesScratchpad() { - MaybeObject* maybe_obj = - AllocateFixedArray(kAllocationSiteScratchpadSize, TENURED); - return maybe_obj; -} - - void Heap::FlushAllocationSitesScratchpad() { for (int i = 0; i < allocation_sites_scratchpad_length_; i++) { allocation_sites_scratchpad()->set_undefined(i); @@ -5419,10 +5318,10 @@ bool Heap::SetUp() { bool Heap::CreateHeapObjects() { // Create initial maps. if (!CreateInitialMaps()) return false; - if (!CreateApiObjects()) return false; + CreateApiObjects(); // Create initial objects - if (!CreateInitialObjects()) return false; + CreateInitialObjects(); CHECK_EQ(0, gc_count_); native_contexts_list_ = undefined_value(); diff --git a/src/heap.h b/src/heap.h index b6d5adb..cb50109 100644 --- a/src/heap.h +++ b/src/heap.h @@ -739,9 +739,6 @@ class Heap { bool double_align, AllocationSpace space); - // Allocates an empty PolymorphicCodeCache. - MUST_USE_RESULT MaybeObject* AllocatePolymorphicCodeCache(); - // Clear the Instanceof cache (used when a prototype changes). inline void ClearInstanceofCache(); @@ -1281,7 +1278,7 @@ class Heap { // Support for the API. // - bool CreateApiObjects(); + void CreateApiObjects(); // Adjusts the amount of registered external memory. // Returns the adjusted value. @@ -1961,7 +1958,7 @@ class Heap { AllocationSite* allocation_site); bool CreateInitialMaps(); - bool CreateInitialObjects(); + void CreateInitialObjects(); // These five Create*EntryStub functions are here and forced to not be inlined // because of a gcc-4.4 bug that assigns wrong vtable entries. @@ -2045,16 +2042,11 @@ class Heap { GCTracer* tracer_; - // Allocates a small number to string cache. - MUST_USE_RESULT MaybeObject* AllocateInitialNumberStringCache(); // Creates and installs the full-sized number string cache. int FullSizeNumberStringCacheLength(); // Flush the number to string cache. void FlushNumberStringCache(); - // Allocates a fixed-size allocation sites scratchpad. - MUST_USE_RESULT MaybeObject* AllocateAllocationSitesScratchpad(); - // Sets used allocation sites entries to undefined. void FlushAllocationSitesScratchpad();