From 2c394ad00ddfac23ee8f0fd92ad05cfe00dd8cf6 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 22 Apr 2014 07:33:20 +0000 Subject: [PATCH] Introduce exception object and remove some uses of MaybeObject::IsFailure(). R=bmeurer@chromium.org Review URL: https://codereview.chromium.org/240883003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20871 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 2 +- src/allocation-site-scopes.cc | 2 +- src/elements.cc | 2 -- src/heap.cc | 7 +++++++ src/heap.h | 2 ++ src/ic.cc | 11 +++++------ src/isolate.h | 18 +++++++++--------- src/objects-debug.cc | 4 +++- src/objects-inl.h | 19 +++++-------------- src/objects.h | 5 +++-- 10 files changed, 36 insertions(+), 36 deletions(-) diff --git a/include/v8.h b/include/v8.h index ab9f570..7e41ee8 100644 --- a/include/v8.h +++ b/include/v8.h @@ -5545,7 +5545,7 @@ class Internals { static const int kNullValueRootIndex = 7; static const int kTrueValueRootIndex = 8; static const int kFalseValueRootIndex = 9; - static const int kEmptyStringRootIndex = 160; + static const int kEmptyStringRootIndex = 162; static const int kNodeClassIdOffset = 1 * kApiPointerSize; static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; diff --git a/src/allocation-site-scopes.cc b/src/allocation-site-scopes.cc index bbfb39b..80dab8b 100644 --- a/src/allocation-site-scopes.cc +++ b/src/allocation-site-scopes.cc @@ -62,7 +62,7 @@ Handle AllocationSiteCreationContext::EnterNewScope() { void AllocationSiteCreationContext::ExitScope( Handle scope_site, Handle object) { - if (!object.is_null() && !object->IsFailure()) { + if (!object.is_null()) { bool top_level = !scope_site.is_null() && top().is_identical_to(scope_site); diff --git a/src/elements.cc b/src/elements.cc index 18f2619..9f83122 100644 --- a/src/elements.cc +++ b/src/elements.cc @@ -596,8 +596,6 @@ class ElementsAccessorBase : public ElementsAccessor { static void ValidateImpl(Handle holder) { Handle fixed_array_base(holder->elements()); - // When objects are first allocated, its elements are Failures. - if (fixed_array_base->IsFailure()) return; if (!fixed_array_base->IsHeapObject()) return; // Arrays that have been shifted in place can't be verified. if (fixed_array_base->IsFiller()) return; diff --git a/src/heap.cc b/src/heap.cc index 557294c..aadb83e 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -2578,6 +2578,7 @@ bool Heap::CreateInitialMaps() { ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, uninitialized); ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, arguments_marker); ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, no_interceptor_result_sentinel); + ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, exception); ALLOCATE_MAP(ODDBALL_TYPE, Oddball::kSize, termination_exception); for (unsigned i = 0; i < ARRAY_SIZE(string_type_table); i++) { @@ -2882,6 +2883,12 @@ bool Heap::CreateInitialObjects() { handle(Smi::FromInt(-3), isolate()), Oddball::kOther)); + set_exception( + *factory->NewOddball(factory->exception_map(), + "exception", + handle(Smi::FromInt(-5), isolate()), + Oddball::kException)); + for (unsigned i = 0; i < ARRAY_SIZE(constant_string_table); i++) { Handle str = factory->InternalizeUtf8String(constant_string_table[i].contents); diff --git a/src/heap.h b/src/heap.h index 409a01d..c44d99e 100644 --- a/src/heap.h +++ b/src/heap.h @@ -60,6 +60,7 @@ namespace internal { V(Oddball, true_value, TrueValue) \ V(Oddball, false_value, FalseValue) \ V(Oddball, uninitialized_value, UninitializedValue) \ + V(Oddball, exception, Exception) \ V(Map, cell_map, CellMap) \ V(Map, global_property_cell_map, GlobalPropertyCellMap) \ V(Map, shared_function_info_map, SharedFunctionInfoMap) \ @@ -187,6 +188,7 @@ namespace internal { V(Map, uninitialized_map, UninitializedMap) \ V(Map, arguments_marker_map, ArgumentsMarkerMap) \ V(Map, no_interceptor_result_sentinel_map, NoInterceptorResultSentinelMap) \ + V(Map, exception_map, ExceptionMap) \ V(Map, termination_exception_map, TerminationExceptionMap) \ V(Map, message_object_map, JSMessageObjectMap) \ V(Map, foreign_map, ForeignMap) \ diff --git a/src/ic.cc b/src/ic.cc index 86bef05..b075c14 100644 --- a/src/ic.cc +++ b/src/ic.cc @@ -1161,7 +1161,7 @@ MaybeHandle KeyedLoadIC::Load(Handle object, stub = sloppy_arguments_stub(); } else if (receiver->HasIndexedInterceptor()) { stub = indexed_interceptor_stub(); - } else if (!key->ToSmi()->IsFailure() && + } else if (!Object::ToSmi(isolate(), key).is_null() && (!target().is_identical_to(sloppy_arguments_stub()))) { stub = LoadElementStub(receiver); } @@ -1655,10 +1655,9 @@ bool IsOutOfBoundsAccess(Handle receiver, KeyedAccessStoreMode KeyedStoreIC::GetStoreMode(Handle receiver, Handle key, Handle value) { - ASSERT(!key->ToSmi()->IsFailure()); - Smi* smi_key = NULL; - key->ToSmi()->To(&smi_key); - int index = smi_key->value(); + Handle smi_key = Object::ToSmi(isolate(), key); + ASSERT(!smi_key.is_null() && smi_key->IsSmi()); + int index = Handle::cast(smi_key)->value(); bool oob_access = IsOutOfBoundsAccess(receiver, index); // Don't consider this a growing store if the store would send the receiver to // dictionary mode. @@ -1780,7 +1779,7 @@ MaybeHandle KeyedStoreIC::Store(Handle object, if (object->IsJSObject()) { Handle receiver = Handle::cast(object); - bool key_is_smi_like = key->IsSmi() || !key->ToSmi()->IsFailure(); + bool key_is_smi_like = !Object::ToSmi(isolate(), key).is_null(); if (receiver->elements()->map() == isolate()->heap()->sloppy_arguments_elements_map()) { if (strict_mode() == SLOPPY) { diff --git a/src/isolate.h b/src/isolate.h index 5dd4b4e..b3e403c 100644 --- a/src/isolate.h +++ b/src/isolate.h @@ -588,17 +588,17 @@ class Isolate { // Interface to pending exception. Object* pending_exception() { ASSERT(has_pending_exception()); - ASSERT(!thread_local_top_.pending_exception_->IsFailure()); + ASSERT(!thread_local_top_.pending_exception_->IsException()); return thread_local_top_.pending_exception_; } - void set_pending_exception(Object* exception) { - ASSERT(!exception->IsFailure()); - thread_local_top_.pending_exception_ = exception; + void set_pending_exception(Object* exception_obj) { + ASSERT(!exception_obj->IsException()); + thread_local_top_.pending_exception_ = exception_obj; } void clear_pending_exception() { - ASSERT(!thread_local_top_.pending_exception_->IsFailure()); + ASSERT(!thread_local_top_.pending_exception_->IsException()); thread_local_top_.pending_exception_ = heap_.the_hole_value(); } @@ -607,7 +607,7 @@ class Isolate { } bool has_pending_exception() { - ASSERT(!thread_local_top_.pending_exception_->IsFailure()); + ASSERT(!thread_local_top_.pending_exception_->IsException()); return !thread_local_top_.pending_exception_->IsTheHole(); } @@ -649,15 +649,15 @@ class Isolate { Object* scheduled_exception() { ASSERT(has_scheduled_exception()); - ASSERT(!thread_local_top_.scheduled_exception_->IsFailure()); + ASSERT(!thread_local_top_.scheduled_exception_->IsException()); return thread_local_top_.scheduled_exception_; } bool has_scheduled_exception() { - ASSERT(!thread_local_top_.scheduled_exception_->IsFailure()); + ASSERT(!thread_local_top_.scheduled_exception_->IsException()); return thread_local_top_.scheduled_exception_ != heap_.the_hole_value(); } void clear_scheduled_exception() { - ASSERT(!thread_local_top_.scheduled_exception_->IsFailure()); + ASSERT(!thread_local_top_.scheduled_exception_->IsException()); thread_local_top_.scheduled_exception_ = heap_.the_hole_value(); } diff --git a/src/objects-debug.cc b/src/objects-debug.cc index f6f1435..13026ed 100644 --- a/src/objects-debug.cc +++ b/src/objects-debug.cc @@ -618,7 +618,7 @@ void Oddball::OddballVerify() { CHECK(number->IsSmi()); int value = Smi::cast(number)->value(); // Hidden oddballs have negative smis. - const int kLeastHiddenOddballNumber = -4; + const int kLeastHiddenOddballNumber = -5; CHECK_LE(value, 1); CHECK(value >= kLeastHiddenOddballNumber); } @@ -639,6 +639,8 @@ void Oddball::OddballVerify() { CHECK(this == heap->arguments_marker()); } else if (map() == heap->termination_exception_map()) { CHECK(this == heap->termination_exception()); + } else if (map() == heap->exception_map()) { + CHECK(this == heap->exception()); } else { UNREACHABLE(); } diff --git a/src/objects-inl.h b/src/objects-inl.h index a89109f..83afd32 100644 --- a/src/objects-inl.h +++ b/src/objects-inl.h @@ -1002,6 +1002,11 @@ bool Object::IsTheHole() { } +bool Object::IsException() { + return IsOddball() && Oddball::cast(this)->kind() == Oddball::kException; +} + + bool Object::IsUninitialized() { return IsOddball() && Oddball::cast(this)->kind() == Oddball::kUninitialized; } @@ -1048,20 +1053,6 @@ Handle Object::ToSmi(Isolate* isolate, Handle object) { } -// TODO(ishell): Use handlified version instead. -MaybeObject* Object::ToSmi() { - if (IsSmi()) return this; - if (IsHeapNumber()) { - double value = HeapNumber::cast(this)->value(); - int int_value = FastD2I(value); - if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { - return Smi::FromInt(int_value); - } - } - return Failure::Exception(); -} - - MaybeHandle Object::ToObject(Isolate* isolate, Handle object) { return ToObject( diff --git a/src/objects.h b/src/objects.h index 6451601..60c2883 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1450,7 +1450,8 @@ class Object : public MaybeObject { // Oddball testing. INLINE(bool IsUndefined()); INLINE(bool IsNull()); - INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation. + INLINE(bool IsTheHole()); + INLINE(bool IsException()); INLINE(bool IsUninitialized()); INLINE(bool IsTrue()); INLINE(bool IsFalse()); @@ -1531,7 +1532,6 @@ class Object : public MaybeObject { // Failure is returned otherwise. static MUST_USE_RESULT inline Handle ToSmi(Isolate* isolate, Handle object); - MUST_USE_RESULT inline MaybeObject* ToSmi(); void Lookup(Name* name, LookupResult* result); @@ -9814,6 +9814,7 @@ class Oddball: public HeapObject { static const byte kUndefined = 5; static const byte kUninitialized = 6; static const byte kOther = 7; + static const byte kException = 8; typedef FixedBodyDescriptor