From 4a5bccfc61ed828283703bb47f388cd6d8e2f410 Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Tue, 1 Apr 2014 08:57:48 +0000 Subject: [PATCH] Tighten object verification. Often, when we call MaybeObject::Verify, what we want is Object::ObjectVerify. R=hpayer@chromium.org Review URL: https://codereview.chromium.org/218993005 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20382 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/api.cc | 4 ++-- src/bootstrapper.cc | 2 +- src/objects-debug.cc | 33 +++++++++++++++++---------------- src/objects.h | 1 + src/spaces.cc | 6 +++--- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/api.cc b/src/api.cc index 9e24fee..2e46136 100644 --- a/src/api.cc +++ b/src/api.cc @@ -533,7 +533,7 @@ i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) { LOG_API(isolate, "Persistent::New"); i::Handle result = isolate->global_handles()->Create(*obj); #ifdef DEBUG - (*obj)->Verify(); + (*obj)->ObjectVerify(); #endif // DEBUG return result.location(); } @@ -542,7 +542,7 @@ i::Object** V8::GlobalizeReference(i::Isolate* isolate, i::Object** obj) { i::Object** V8::CopyPersistent(i::Object** obj) { i::Handle result = i::GlobalHandles::CopyGlobal(obj); #ifdef DEBUG - (*obj)->Verify(); + (*obj)->ObjectVerify(); #endif // DEBUG return result.location(); } diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc index dc0d902..be59441 100644 --- a/src/bootstrapper.cc +++ b/src/bootstrapper.cc @@ -2000,7 +2000,7 @@ bool Genesis::InstallNatives() { } #ifdef VERIFY_HEAP - builtins->Verify(); + builtins->ObjectVerify(); #endif return true; diff --git a/src/objects-debug.cc b/src/objects-debug.cc index ca025e6..ba9ff65 100644 --- a/src/objects-debug.cc +++ b/src/objects-debug.cc @@ -41,17 +41,22 @@ namespace internal { void MaybeObject::Verify() { Object* this_as_object; if (ToObject(&this_as_object)) { - if (this_as_object->IsSmi()) { - Smi::cast(this_as_object)->SmiVerify(); - } else { - HeapObject::cast(this_as_object)->HeapObjectVerify(); - } + this_as_object->ObjectVerify(); } else { Failure::cast(this)->FailureVerify(); } } +void Object::ObjectVerify() { + if (IsSmi()) { + Smi::cast(this)->SmiVerify(); + } else { + HeapObject::cast(this)->HeapObjectVerify(); + } +} + + void Object::VerifyPointer(Object* p) { if (p->IsHeapObject()) { HeapObject::VerifyHeapPointer(p); @@ -380,11 +385,7 @@ void AliasedArgumentsEntry::AliasedArgumentsEntryVerify() { void FixedArray::FixedArrayVerify() { for (int i = 0; i < length(); i++) { Object* e = get(i); - if (e->IsHeapObject()) { - VerifyHeapPointer(e); - } else { - e->Verify(); - } + VerifyPointer(e); } } @@ -626,7 +627,7 @@ void PropertyCell::PropertyCellVerify() { void Code::CodeVerify() { CHECK(IsAligned(reinterpret_cast(instruction_start()), kCodeAlignment)); - relocation_info()->Verify(); + relocation_info()->ObjectVerify(); Address last_gc_pc = NULL; for (RelocIterator it(this); !it.done(); it.next()) { it.rinfo()->Verify(); @@ -811,7 +812,7 @@ void Foreign::ForeignVerify() { void Box::BoxVerify() { CHECK(IsBox()); - value()->Verify(); + value()->ObjectVerify(); } @@ -947,7 +948,7 @@ void Script::ScriptVerify() { void JSFunctionResultCache::JSFunctionResultCacheVerify() { - JSFunction::cast(get(kFactoryIndex))->Verify(); + JSFunction::cast(get(kFactoryIndex))->ObjectVerify(); int size = Smi::cast(get(kCacheSizeIndex))->value(); CHECK(kEntriesIndex <= size); @@ -962,18 +963,18 @@ void JSFunctionResultCache::JSFunctionResultCacheVerify() { if (FLAG_enable_slow_asserts) { for (int i = kEntriesIndex; i < size; i++) { CHECK(!get(i)->IsTheHole()); - get(i)->Verify(); + get(i)->ObjectVerify(); } for (int i = size; i < length(); i++) { CHECK(get(i)->IsTheHole()); - get(i)->Verify(); + get(i)->ObjectVerify(); } } } void NormalizedMapCache::NormalizedMapCacheVerify() { - FixedArray::cast(this)->Verify(); + FixedArray::cast(this)->FixedArrayVerify(); if (FLAG_enable_slow_asserts) { for (int i = 0; i < length(); i++) { Object* e = get(i); diff --git a/src/objects.h b/src/objects.h index 98bf122..48e0a50 100644 --- a/src/objects.h +++ b/src/objects.h @@ -1629,6 +1629,7 @@ class Object : public MaybeObject { // < the length of the string. Used to implement [] on strings. inline bool IsStringObjectWithCharacterAt(uint32_t index); + DECLARE_VERIFIER(Object) #ifdef VERIFY_HEAP // Verify a pointer is a valid object pointer. static void VerifyPointer(Object* p); diff --git a/src/spaces.cc b/src/spaces.cc index 2ca8c98..6df15fa 100644 --- a/src/spaces.cc +++ b/src/spaces.cc @@ -1195,7 +1195,7 @@ void PagedSpace::Verify(ObjectVisitor* visitor) { VerifyObject(object); // The object itself should look OK. - object->Verify(); + object->ObjectVerify(); // All the interior pointers should be contained in the heap. int size = object->Size(); @@ -1478,7 +1478,7 @@ void NewSpace::Verify() { CHECK(!object->IsCode()); // The object itself should look OK. - object->Verify(); + object->ObjectVerify(); // All the interior pointers should be contained in the heap. VerifyPointersVisitor visitor; @@ -3119,7 +3119,7 @@ void LargeObjectSpace::Verify() { object->IsFixedDoubleArray() || object->IsByteArray()); // The object itself should look OK. - object->Verify(); + object->ObjectVerify(); // Byte arrays and strings don't have interior pointers. if (object->IsCode()) { -- 2.7.4