From ae06768ef09fd774c67d71d3667ddb99673ef17f Mon Sep 17 00:00:00 2001 From: "mvstanton@chromium.org" Date: Mon, 14 Apr 2014 11:44:13 +0000 Subject: [PATCH] Handlification in ic.cc R=yangguo@chromium.org Review URL: https://codereview.chromium.org/235453010 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20720 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/ic.cc | 288 ++++++++++++++++++++++++++++++++++++++------------------------ src/ic.h | 38 ++++----- 2 files changed, 195 insertions(+), 131 deletions(-) diff --git a/src/ic.cc b/src/ic.cc index a5936c6..fef90e4 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -375,22 +375,22 @@ void IC::UpdateState(Handle receiver, Handle name) { } -Failure* IC::TypeError(const char* type, - Handle object, - Handle key) { +MaybeHandle IC::TypeError(const char* type, + Handle object, + Handle key) { HandleScope scope(isolate()); Handle args[2] = { key, object }; Handle error = isolate()->factory()->NewTypeError( type, HandleVector(args, 2)); - return isolate()->Throw(*error); + return isolate()->Throw(error); } -Failure* IC::ReferenceError(const char* type, Handle name) { +MaybeHandle IC::ReferenceError(const char* type, Handle name) { HandleScope scope(isolate()); Handle error = isolate()->factory()->NewReferenceError( type, HandleVector(&name, 1)); - return isolate()->Throw(*error); + return isolate()->Throw(error); } @@ -572,8 +572,7 @@ static bool MigrateDeprecated(Handle object) { } -MaybeObject* LoadIC::Load(Handle object, - Handle name) { +MaybeHandle LoadIC::Load(Handle object, Handle name) { // If the object is undefined or null it's illegal to try to get any // of its properties; throw a TypeError in that case. if (object->IsUndefined() || object->IsNull()) { @@ -599,7 +598,7 @@ MaybeObject* LoadIC::Load(Handle object, set_target(*stub); if (FLAG_trace_ic) PrintF("[LoadIC : +#prototype /function]\n"); } - return *Accessors::FunctionGetPrototype(Handle::cast(object)); + return Accessors::FunctionGetPrototype(Handle::cast(object)); } } @@ -610,10 +609,12 @@ MaybeObject* LoadIC::Load(Handle object, // Rewrite to the generic keyed load stub. if (FLAG_use_ic) set_target(*generic_stub()); Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, - Runtime::GetElementOrCharAt(isolate(), object, index)); - return *result; + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, + Runtime::GetElementOrCharAt(isolate(), object, index), + Object); + return result; } bool use_ic = MigrateDeprecated(object) ? false : FLAG_use_ic; @@ -636,16 +637,18 @@ MaybeObject* LoadIC::Load(Handle object, PropertyAttributes attr; // Get the property. Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, - Object::GetProperty(object, object, &lookup, name, &attr)); + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, + Object::GetProperty(object, object, &lookup, name, &attr), + Object); // If the property is not present, check if we need to throw an exception. if ((lookup.IsInterceptor() || lookup.IsHandler()) && attr == ABSENT && IsUndeclaredGlobal(object)) { return ReferenceError("not_defined", name); } - return *result; + return result; } @@ -1121,15 +1124,19 @@ Handle KeyedLoadIC::LoadElementStub(Handle receiver) { } -MaybeObject* KeyedLoadIC::Load(Handle object, Handle key) { +MaybeHandle KeyedLoadIC::Load(Handle object, + Handle key) { if (MigrateDeprecated(object)) { Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, Runtime::GetObjectProperty(isolate(), object, key)); - return *result; + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, + Runtime::GetObjectProperty(isolate(), object, key), + Object); + return result; } - MaybeObject* maybe_object = NULL; + Handle load_handle; Handle stub = generic_stub(); // Check for non-string values that can be converted into an @@ -1137,8 +1144,11 @@ MaybeObject* KeyedLoadIC::Load(Handle object, Handle key) { key = TryConvertKey(key, isolate()); if (key->IsInternalizedString()) { - maybe_object = LoadIC::Load(object, Handle::cast(key)); - if (maybe_object->IsFailure()) return maybe_object; + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + load_handle, + LoadIC::Load(object, Handle::cast(key)), + Object); } else if (FLAG_use_ic && !object->IsAccessCheckNeeded()) { if (object->IsString() && key->IsNumber()) { if (state() == UNINITIALIZED) stub = string_stub(); @@ -1164,11 +1174,14 @@ MaybeObject* KeyedLoadIC::Load(Handle object, Handle key) { TRACE_IC("LoadIC", key); } - if (maybe_object != NULL) return maybe_object; + if (!load_handle.is_null()) return load_handle; Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, Runtime::GetObjectProperty(isolate(), object, key)); - return *result; + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, + Runtime::GetObjectProperty(isolate(), object, key), + Object); + return result; } @@ -1232,17 +1245,19 @@ static bool LookupForWrite(Handle receiver, } -MaybeObject* StoreIC::Store(Handle object, - Handle name, - Handle value, - JSReceiver::StoreFromKeyed store_mode) { +MaybeHandle StoreIC::Store(Handle object, + Handle name, + Handle value, + JSReceiver::StoreFromKeyed store_mode) { if (MigrateDeprecated(object) || object->IsJSProxy()) { Handle receiver = Handle::cast(object); Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, - JSReceiver::SetProperty(receiver, name, value, NONE, strict_mode())); - return *result; + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, + JSReceiver::SetProperty(receiver, name, value, NONE, strict_mode()), + Object); + return result; } // If the object is undefined or null it's illegal to try to set any @@ -1259,7 +1274,7 @@ MaybeObject* StoreIC::Store(Handle object, // Ignore other stores where the receiver is not a JSObject. // TODO(1475): Must check prototype chains of object wrappers. - if (!object->IsJSObject()) return *value; + if (!object->IsJSObject()) return value; Handle receiver = Handle::cast(object); @@ -1267,20 +1282,24 @@ MaybeObject* StoreIC::Store(Handle object, uint32_t index; if (name->AsArrayIndex(&index)) { Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, - JSObject::SetElement(receiver, index, value, NONE, strict_mode())); - return *value; + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, + JSObject::SetElement(receiver, index, value, NONE, strict_mode()), + Object); + return value; } // Observed objects are always modified through the runtime. if (receiver->map()->is_observed()) { Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, JSReceiver::SetProperty( - receiver, name, value, NONE, strict_mode(), store_mode)); - return *result; + receiver, name, value, NONE, strict_mode(), store_mode), + Object); + return result; } LookupResult lookup(isolate()); @@ -1309,11 +1328,13 @@ MaybeObject* StoreIC::Store(Handle object, // Set the property. Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, JSReceiver::SetProperty( - receiver, name, value, NONE, strict_mode(), store_mode)); - return *result; + receiver, name, value, NONE, strict_mode(), store_mode), + Object); + return result; } @@ -1704,31 +1725,36 @@ KeyedAccessStoreMode KeyedStoreIC::GetStoreMode(Handle receiver, } -MaybeObject* KeyedStoreIC::Store(Handle object, - Handle key, - Handle value) { +MaybeHandle KeyedStoreIC::Store(Handle object, + Handle key, + Handle value) { if (MigrateDeprecated(object)) { Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, Runtime::SetObjectProperty( - isolate(), object, key, value, NONE, strict_mode())); - return *result; + isolate(), object, key, value, NONE, strict_mode()), + Object); + return result; } // Check for non-string values that can be converted into an // internalized string directly or is representable as a smi. key = TryConvertKey(key, isolate()); - MaybeObject* maybe_object = NULL; + Handle store_handle; Handle stub = generic_stub(); if (key->IsInternalizedString()) { - maybe_object = StoreIC::Store(object, - Handle::cast(key), - value, - JSReceiver::MAY_BE_STORE_FROM_KEYED); - if (maybe_object->IsFailure()) return maybe_object; + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + store_handle, + StoreIC::Store(object, + Handle::cast(key), + value, + JSReceiver::MAY_BE_STORE_FROM_KEYED), + Object); } else { bool use_ic = FLAG_use_ic && !object->IsStringWrapper() && @@ -1780,13 +1806,15 @@ MaybeObject* KeyedStoreIC::Store(Handle object, TRACE_IC("StoreIC", key); } - if (maybe_object) return maybe_object; + if (!store_handle.is_null()) return store_handle; Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, Runtime::SetObjectProperty( - isolate(), object, key, value, NONE, strict_mode())); - return *result; + isolate(), object, key, value, NONE, strict_mode()), + Object); + return result; } @@ -1806,7 +1834,9 @@ RUNTIME_FUNCTION(MaybeObject*, LoadIC_Miss) { Handle receiver = args.at(0); Handle key = args.at(1); ic.UpdateState(receiver, key); - return ic.Load(receiver, key); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, ic.Load(receiver, key)); + return *result; } @@ -1818,7 +1848,9 @@ RUNTIME_FUNCTION(MaybeObject*, KeyedLoadIC_Miss) { Handle receiver = args.at(0); Handle key = args.at(1); ic.UpdateState(receiver, key); - return ic.Load(receiver, key); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, ic.Load(receiver, key)); + return *result; } @@ -1829,7 +1861,9 @@ RUNTIME_FUNCTION(MaybeObject*, KeyedLoadIC_MissFromStubFailure) { Handle receiver = args.at(0); Handle key = args.at(1); ic.UpdateState(receiver, key); - return ic.Load(receiver, key); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, ic.Load(receiver, key)); + return *result; } @@ -1841,7 +1875,12 @@ RUNTIME_FUNCTION(MaybeObject*, StoreIC_Miss) { Handle receiver = args.at(0); Handle key = args.at(1); ic.UpdateState(receiver, key); - return ic.Store(receiver, key, args.at(2)); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, + result, + ic.Store(receiver, key, args.at(2))); + return *result; } @@ -1852,7 +1891,12 @@ RUNTIME_FUNCTION(MaybeObject*, StoreIC_MissFromStubFailure) { Handle receiver = args.at(0); Handle key = args.at(1); ic.UpdateState(receiver, key); - return ic.Store(receiver, key, args.at(2)); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, + result, + ic.Store(receiver, key, args.at(2))); + return *result; } @@ -1883,46 +1927,42 @@ RUNTIME_FUNCTION(MaybeObject*, StoreIC_ArrayLength) { // it is necessary to extend the properties array of a // JSObject. RUNTIME_FUNCTION(MaybeObject*, SharedStoreIC_ExtendStorage) { - SealHandleScope shs(isolate); + HandleScope shs(isolate); ASSERT(args.length() == 3); // Convert the parameters - JSObject* object = JSObject::cast(args[0]); - Map* transition = Map::cast(args[1]); - Object* value = args[2]; + Handle object = args.at(0); + Handle transition = args.at(1); + Handle value = args.at(2); // Check the object has run out out property space. ASSERT(object->HasFastProperties()); ASSERT(object->map()->unused_property_fields() == 0); // Expand the properties array. - FixedArray* old_storage = object->properties(); + Handle old_storage = handle(object->properties(), isolate); int new_unused = transition->unused_property_fields(); int new_size = old_storage->length() + new_unused + 1; - Object* result; - MaybeObject* maybe_result = old_storage->CopySize(new_size); - if (!maybe_result->ToObject(&result)) return maybe_result; - FixedArray* new_storage = FixedArray::cast(result); + Handle new_storage = isolate->factory()->CopySizeFixedArray( + old_storage, new_size); - Object* to_store = value; + Handle to_store = value; - DescriptorArray* descriptors = transition->instance_descriptors(); - PropertyDetails details = descriptors->GetDetails(transition->LastAdded()); + PropertyDetails details = transition->instance_descriptors()->GetDetails( + transition->LastAdded()); if (details.representation().IsDouble()) { - MaybeObject* maybe_storage = - isolate->heap()->AllocateHeapNumber(value->Number()); - if (!maybe_storage->To(&to_store)) return maybe_storage; + to_store = isolate->factory()->NewHeapNumber(value->Number()); } - new_storage->set(old_storage->length(), to_store); + new_storage->set(old_storage->length(), *to_store); // Set the new property value and do the map transition. - object->set_properties(new_storage); - object->set_map(transition); + object->set_properties(*new_storage); + object->set_map(*transition); // Return the stored value. - return value; + return *value; } @@ -1934,7 +1974,12 @@ RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_Miss) { Handle receiver = args.at(0); Handle key = args.at(1); ic.UpdateState(receiver, key); - return ic.Store(receiver, key, args.at(2)); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, + result, + ic.Store(receiver, key, args.at(2))); + return *result; } @@ -1945,7 +1990,12 @@ RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_MissFromStubFailure) { Handle receiver = args.at(0); Handle key = args.at(1); ic.UpdateState(receiver, key); - return ic.Store(receiver, key, args.at(2)); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, + result, + ic.Store(receiver, key, args.at(2))); + return *result; } @@ -2425,9 +2475,10 @@ Type* BinaryOpIC::State::KindToType(Kind kind, Zone* zone) { } -MaybeObject* BinaryOpIC::Transition(Handle allocation_site, - Handle left, - Handle right) { +MaybeHandle BinaryOpIC::Transition( + Handle allocation_site, + Handle left, + Handle right) { State state(target()->extra_ic_state()); // Compute the actual result using the builtin for the binary operation. @@ -2435,9 +2486,11 @@ MaybeObject* BinaryOpIC::Transition(Handle allocation_site, TokenToJSBuiltin(state.op())); Handle function = handle(JSFunction::cast(builtin), isolate()); Handle result; - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate(), result, - Execution::Call(isolate(), function, left, 1, &right)); + ASSIGN_RETURN_ON_EXCEPTION( + isolate(), + result, + Execution::Call(isolate(), function, left, 1, &right), + Object); // Execution::Call can execute arbitrary JavaScript, hence potentially // update the state of this very IC, so we must update the stored state. @@ -2495,7 +2548,7 @@ MaybeObject* BinaryOpIC::Transition(Handle allocation_site, PatchInlinedSmiCode(address(), DISABLE_INLINED_SMI_CHECK); } - return *result; + return result; } @@ -2505,7 +2558,12 @@ RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_Miss) { Handle left = args.at(BinaryOpICStub::kLeft); Handle right = args.at(BinaryOpICStub::kRight); BinaryOpIC ic(isolate); - return ic.Transition(Handle::null(), left, right); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, + result, + ic.Transition(Handle::null(), left, right)); + return *result; } @@ -2519,7 +2577,12 @@ RUNTIME_FUNCTION(MaybeObject*, BinaryOpIC_MissWithAllocationSite) { Handle right = args.at( BinaryOpWithAllocationSiteStub::kRight); BinaryOpIC ic(isolate); - return ic.Transition(allocation_site, left, right); + Handle result; + ASSIGN_RETURN_FAILURE_ON_EXCEPTION( + isolate, + result, + ic.Transition(allocation_site, left, right)); + return *result; } @@ -2761,16 +2824,17 @@ void CompareNilIC::Clear(Address address, } -MaybeObject* CompareNilIC::DoCompareNilSlow(NilValue nil, - Handle object) { +Handle CompareNilIC::DoCompareNilSlow(Isolate* isolate, + NilValue nil, + Handle object) { if (object->IsNull() || object->IsUndefined()) { - return Smi::FromInt(true); + return handle(Smi::FromInt(true), isolate); } - return Smi::FromInt(object->IsUndetectableObject()); + return handle(Smi::FromInt(object->IsUndetectableObject()), isolate); } -MaybeObject* CompareNilIC::CompareNil(Handle object) { +Handle CompareNilIC::CompareNil(Handle object) { ExtraICState extra_ic_state = target()->extra_ic_state(); CompareNilICStub stub(extra_ic_state); @@ -2794,7 +2858,7 @@ MaybeObject* CompareNilIC::CompareNil(Handle object) { code = stub.GetCode(isolate()); } set_target(*code); - return DoCompareNilSlow(nil, object); + return DoCompareNilSlow(isolate(), nil, object); } @@ -2802,7 +2866,7 @@ RUNTIME_FUNCTION(MaybeObject*, CompareNilIC_Miss) { HandleScope scope(isolate); Handle object = args.at(0); CompareNilIC ic(isolate); - return ic.CompareNil(object); + return *ic.CompareNil(object); } @@ -2854,12 +2918,12 @@ Builtins::JavaScript BinaryOpIC::TokenToJSBuiltin(Token::Value op) { } -MaybeObject* ToBooleanIC::ToBoolean(Handle object) { +Handle ToBooleanIC::ToBoolean(Handle object) { ToBooleanStub stub(target()->extra_ic_state()); bool to_boolean_value = stub.UpdateStatus(object); Handle code = stub.GetCode(isolate()); set_target(*code); - return Smi::FromInt(to_boolean_value ? 1 : 0); + return handle(Smi::FromInt(to_boolean_value ? 1 : 0), isolate()); } @@ -2868,7 +2932,7 @@ RUNTIME_FUNCTION(MaybeObject*, ToBooleanIC_Miss) { HandleScope scope(isolate); Handle object = args.at(0); ToBooleanIC ic(isolate); - return ic.ToBoolean(object); + return *ic.ToBoolean(object); } diff --git a/src/ic.h b/src/ic.h index ca03988..ea074ca 100644 --- a/src/ic.h +++ b/src/ic.h @@ -196,10 +196,10 @@ class IC { void TraceIC(const char* type, Handle name); #endif - Failure* TypeError(const char* type, - Handle object, - Handle key); - Failure* ReferenceError(const char* type, Handle name); + MaybeHandle TypeError(const char* type, + Handle object, + Handle key); + MaybeHandle ReferenceError(const char* type, Handle name); // Access the target code for the given IC address. static inline Code* GetTargetAtAddress(Address address, @@ -397,8 +397,8 @@ class LoadIC: public IC { static Handle initialize_stub(Isolate* isolate, ExtraICState extra_state); - MUST_USE_RESULT MaybeObject* Load(Handle object, - Handle name); + MUST_USE_RESULT MaybeHandle Load(Handle object, + Handle name); protected: virtual Code::Kind kind() const { return Code::LOAD_IC; } @@ -459,8 +459,8 @@ class KeyedLoadIC: public LoadIC { ASSERT(target()->is_keyed_load_stub()); } - MUST_USE_RESULT MaybeObject* Load(Handle object, - Handle key); + MUST_USE_RESULT MaybeHandle Load(Handle object, + Handle key); // Code generator routines. static void GenerateMiss(MacroAssembler* masm); @@ -564,7 +564,7 @@ class StoreIC: public IC { static Handle initialize_stub(Isolate* isolate, StrictMode strict_mode); - MUST_USE_RESULT MaybeObject* Store( + MUST_USE_RESULT MaybeHandle Store( Handle object, Handle name, Handle value, @@ -653,9 +653,9 @@ class KeyedStoreIC: public StoreIC { ASSERT(target()->is_keyed_store_stub()); } - MUST_USE_RESULT MaybeObject* Store(Handle object, - Handle name, - Handle value); + MUST_USE_RESULT MaybeHandle Store(Handle object, + Handle name, + Handle value); // Code generators for stub routines. Only called once at startup. static void GenerateInitialize(MacroAssembler* masm) { GenerateMiss(masm); } @@ -860,9 +860,9 @@ class BinaryOpIC: public IC { static Builtins::JavaScript TokenToJSBuiltin(Token::Value op); - MaybeObject* Transition(Handle allocation_site, - Handle left, - Handle right) V8_WARN_UNUSED_RESULT; + MaybeHandle Transition(Handle allocation_site, + Handle left, + Handle right) V8_WARN_UNUSED_RESULT; }; @@ -944,7 +944,7 @@ class CompareNilIC: public IC { public: explicit CompareNilIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) {} - MUST_USE_RESULT MaybeObject* CompareNil(Handle object); + Handle CompareNil(Handle object); static Handle GetUninitialized(); @@ -952,8 +952,8 @@ class CompareNilIC: public IC { Code* target, ConstantPoolArray* constant_pool); - static MUST_USE_RESULT MaybeObject* DoCompareNilSlow(NilValue nil, - Handle object); + static Handle DoCompareNilSlow(Isolate* isolate, NilValue nil, + Handle object); }; @@ -961,7 +961,7 @@ class ToBooleanIC: public IC { public: explicit ToBooleanIC(Isolate* isolate) : IC(EXTRA_CALL_FRAME, isolate) { } - MaybeObject* ToBoolean(Handle object); + Handle ToBoolean(Handle object); }; -- 2.7.4