From: yangguo@chromium.org Date: Mon, 14 Apr 2014 19:37:51 +0000 (+0000) Subject: Reland "Handlify Runtime::InitializeIntrinsicFunctionNames." X-Git-Tag: upstream/4.7.83~9627 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=123a271e72b3cc5fcca1c7ab8cd5a1efbaf5e9da;p=platform%2Fupstream%2Fv8.git Reland "Handlify Runtime::InitializeIntrinsicFunctionNames." R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/236823003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20738 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/factory.cc b/src/factory.cc index 4fb9147..b2c7f84 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1332,17 +1332,6 @@ Handle Factory::NewJSModule(Handle context, } -// TODO(mstarzinger): Temporary wrapper until handlified. -static Handle NameDictionaryAdd(Handle dict, - Handle name, - Handle value, - PropertyDetails details) { - CALL_HEAP_FUNCTION(dict->GetIsolate(), - dict->Add(*name, *value, details), - NameDictionary); -} - - static Handle NewGlobalObjectFromMap(Isolate* isolate, Handle map) { CALL_HEAP_FUNCTION(isolate, @@ -1385,7 +1374,7 @@ Handle Factory::NewGlobalObject(Handle constructor) { Handle name(descs->GetKey(i)); Handle value(descs->GetCallbacksObject(i), isolate()); Handle cell = NewPropertyCell(value); - NameDictionaryAdd(dictionary, name, cell, d); + NameDictionary::AddNameEntry(dictionary, name, cell, d); } // Allocate the global object and initialize it with the backing store. diff --git a/src/heap.cc b/src/heap.cc index 0eaadf0..8559cb4 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -2996,10 +2996,6 @@ bool Heap::CreateInitialObjects() { NameDictionary::Allocate(this, Runtime::kNumFunctions); if (!maybe_obj->ToObject(&obj)) return false; } - { MaybeObject* maybe_obj = Runtime::InitializeIntrinsicFunctionNames(this, - obj); - if (!maybe_obj->ToObject(&obj)) return false; - } set_intrinsic_function_names(NameDictionary::cast(obj)); { MaybeObject* maybe_obj = AllocateInitialNumberStringCache(); @@ -6113,6 +6109,11 @@ bool Heap::CreateHeapObjects() { array_buffers_list_ = undefined_value(); allocation_sites_list_ = undefined_value(); weak_object_to_code_table_ = undefined_value(); + + HandleScope scope(isolate()); + Runtime::InitializeIntrinsicFunctionNames( + isolate(), handle(intrinsic_function_names(), isolate())); + return true; } diff --git a/src/objects.cc b/src/objects.cc index 46e2d66..76d2709 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -634,17 +634,6 @@ void JSObject::SetNormalizedProperty(Handle object, } -// TODO(mstarzinger): Temporary wrapper until handlified. -static Handle NameDictionaryAdd(Handle dict, - Handle name, - Handle value, - PropertyDetails details) { - CALL_HEAP_FUNCTION(dict->GetIsolate(), - dict->Add(*name, *value, details), - NameDictionary); -} - - void JSObject::SetNormalizedProperty(Handle object, Handle name, Handle value, @@ -664,8 +653,8 @@ void JSObject::SetNormalizedProperty(Handle object, store_value = object->GetIsolate()->factory()->NewPropertyCell(value); } - property_dictionary = - NameDictionaryAdd(property_dictionary, name, store_value, details); + property_dictionary = NameDictionary::AddNameEntry( + property_dictionary, name, store_value, details); object->set_properties(*property_dictionary); return; } @@ -1914,7 +1903,8 @@ void JSObject::AddSlowProperty(Handle object, value = cell; } PropertyDetails details = PropertyDetails(attributes, NORMAL, 0); - Handle result = NameDictionaryAdd(dict, name, value, details); + Handle result = + NameDictionary::AddNameEntry(dict, name, value, details); if (*dict != *result) object->set_properties(*result); } @@ -4473,7 +4463,7 @@ void JSObject::NormalizeProperties(Handle object, Handle value(descs->GetConstant(i), isolate); PropertyDetails d = PropertyDetails( details.attributes(), NORMAL, i + 1); - dictionary = NameDictionaryAdd(dictionary, key, value, d); + dictionary = NameDictionary::AddNameEntry(dictionary, key, value, d); break; } case FIELD: { @@ -4482,7 +4472,7 @@ void JSObject::NormalizeProperties(Handle object, object->RawFastPropertyAt(descs->GetFieldIndex(i)), isolate); PropertyDetails d = PropertyDetails(details.attributes(), NORMAL, i + 1); - dictionary = NameDictionaryAdd(dictionary, key, value, d); + dictionary = NameDictionary::AddNameEntry(dictionary, key, value, d); break; } case CALLBACKS: { @@ -4490,7 +4480,7 @@ void JSObject::NormalizeProperties(Handle object, Handle value(descs->GetCallbacksObject(i), isolate); PropertyDetails d = PropertyDetails( details.attributes(), CALLBACKS, i + 1); - dictionary = NameDictionaryAdd(dictionary, key, value, d); + dictionary = NameDictionary::AddNameEntry(dictionary, key, value, d); break; } case INTERCEPTOR: @@ -14320,6 +14310,16 @@ int HashTable:: FindEntry(uint32_t); +Handle NameDictionary::AddNameEntry(Handle dict, + Handle name, + Handle value, + PropertyDetails details) { + CALL_HEAP_FUNCTION(dict->GetIsolate(), + dict->Add(*name, *value, details), + NameDictionary); +} + + Handle JSObject::PrepareSlowElementsForSort( Handle object, uint32_t limit) { CALL_HEAP_FUNCTION(object->GetIsolate(), @@ -14851,7 +14851,7 @@ Handle JSGlobalObject::EnsurePropertyCell( isolate->factory()->the_hole_value()); PropertyDetails details(NONE, NORMAL, 0); details = details.AsDeleted(); - Handle dictionary = NameDictionaryAdd( + Handle dictionary = NameDictionary::AddNameEntry( handle(global->property_dictionary()), name, cell, details); global->set_properties(*dictionary); return cell; diff --git a/src/objects.h b/src/objects.h index e58b37e..23893e7 100644 --- a/src/objects.h +++ b/src/objects.h @@ -4107,6 +4107,12 @@ class NameDictionary: public Dictionary AddNameEntry(Handle dict, + Handle name, + Handle value, + PropertyDetails details); }; diff --git a/src/runtime.cc b/src/runtime.cc index 2975ebe..6c1ff6b 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -15084,31 +15084,21 @@ static const Runtime::Function kIntrinsicFunctions[] = { #undef F -MaybeObject* Runtime::InitializeIntrinsicFunctionNames(Heap* heap, - Object* dictionary) { - ASSERT(dictionary != NULL); - ASSERT(NameDictionary::cast(dictionary)->NumberOfElements() == 0); +void Runtime::InitializeIntrinsicFunctionNames(Isolate* isolate, + Handle dict) { + ASSERT(dict->NumberOfElements() == 0); + HandleScope scope(isolate); for (int i = 0; i < kNumFunctions; ++i) { const char* name = kIntrinsicFunctions[i].name; if (name == NULL) continue; - Object* name_string; - { MaybeObject* maybe_name_string = - heap->InternalizeUtf8String(name); - if (!maybe_name_string->ToObject(&name_string)) return maybe_name_string; - } - NameDictionary* name_dictionary = NameDictionary::cast(dictionary); - { MaybeObject* maybe_dictionary = name_dictionary->Add( - String::cast(name_string), - Smi::FromInt(i), - PropertyDetails(NONE, NORMAL, Representation::None())); - if (!maybe_dictionary->ToObject(&dictionary)) { - // Non-recoverable failure. Calling code must restart heap - // initialization. - return maybe_dictionary; - } - } + Handle new_dict = NameDictionary::AddNameEntry( + dict, + isolate->factory()->InternalizeUtf8String(name), + Handle(Smi::FromInt(i), isolate), + PropertyDetails(NONE, NORMAL, Representation::None())); + // The dictionary does not need to grow. + CHECK(new_dict.is_identical_to(dict)); } - return dictionary; } diff --git a/src/runtime.h b/src/runtime.h index 3a5c454..c1c563a 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -798,11 +798,8 @@ class Runtime : public AllStatic { // Add internalized strings for all the intrinsic function names to a // StringDictionary. - // Returns failure if an allocation fails. In this case, it must be - // retried with a new, empty StringDictionary, not with the same one. - // Alternatively, heap initialization can be completely restarted. - MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames( - Heap* heap, Object* dictionary); + static void InitializeIntrinsicFunctionNames(Isolate* isolate, + Handle dict); // Get the intrinsic function with the given name, which must be internalized. static const Function* FunctionForName(Handle name);