1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "disassembler.h"
33 #include "objects-visiting.h"
40 void MaybeObject::Verify() {
41 Object* this_as_object;
42 if (ToObject(&this_as_object)) {
43 if (this_as_object->IsSmi()) {
44 Smi::cast(this_as_object)->SmiVerify();
46 HeapObject::cast(this_as_object)->HeapObjectVerify();
49 Failure::cast(this)->FailureVerify();
54 void Object::VerifyPointer(Object* p) {
55 if (p->IsHeapObject()) {
56 HeapObject::VerifyHeapPointer(p);
63 void Smi::SmiVerify() {
68 void Failure::FailureVerify() {
73 void HeapObject::HeapObjectVerify() {
74 InstanceType instance_type = map()->instance_type();
76 if (instance_type < FIRST_NONSTRING_TYPE) {
77 String::cast(this)->StringVerify();
81 switch (instance_type) {
83 Map::cast(this)->MapVerify();
85 case HEAP_NUMBER_TYPE:
86 HeapNumber::cast(this)->HeapNumberVerify();
88 case FIXED_ARRAY_TYPE:
89 FixedArray::cast(this)->FixedArrayVerify();
91 case FIXED_DOUBLE_ARRAY_TYPE:
92 FixedDoubleArray::cast(this)->FixedDoubleArrayVerify();
95 ByteArray::cast(this)->ByteArrayVerify();
98 FreeSpace::cast(this)->FreeSpaceVerify();
100 case EXTERNAL_PIXEL_ARRAY_TYPE:
101 ExternalPixelArray::cast(this)->ExternalPixelArrayVerify();
103 case EXTERNAL_BYTE_ARRAY_TYPE:
104 ExternalByteArray::cast(this)->ExternalByteArrayVerify();
106 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
107 ExternalUnsignedByteArray::cast(this)->ExternalUnsignedByteArrayVerify();
109 case EXTERNAL_SHORT_ARRAY_TYPE:
110 ExternalShortArray::cast(this)->ExternalShortArrayVerify();
112 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
113 ExternalUnsignedShortArray::cast(this)->
114 ExternalUnsignedShortArrayVerify();
116 case EXTERNAL_INT_ARRAY_TYPE:
117 ExternalIntArray::cast(this)->ExternalIntArrayVerify();
119 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
120 ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayVerify();
122 case EXTERNAL_FLOAT_ARRAY_TYPE:
123 ExternalFloatArray::cast(this)->ExternalFloatArrayVerify();
125 case EXTERNAL_DOUBLE_ARRAY_TYPE:
126 ExternalDoubleArray::cast(this)->ExternalDoubleArrayVerify();
129 Code::cast(this)->CodeVerify();
132 Oddball::cast(this)->OddballVerify();
135 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
136 JSObject::cast(this)->JSObjectVerify();
139 JSModule::cast(this)->JSModuleVerify();
142 JSValue::cast(this)->JSValueVerify();
145 JSDate::cast(this)->JSDateVerify();
147 case JS_FUNCTION_TYPE:
148 JSFunction::cast(this)->JSFunctionVerify();
150 case JS_GLOBAL_PROXY_TYPE:
151 JSGlobalProxy::cast(this)->JSGlobalProxyVerify();
153 case JS_GLOBAL_OBJECT_TYPE:
154 JSGlobalObject::cast(this)->JSGlobalObjectVerify();
156 case JS_BUILTINS_OBJECT_TYPE:
157 JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify();
159 case JS_GLOBAL_PROPERTY_CELL_TYPE:
160 JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellVerify();
163 JSArray::cast(this)->JSArrayVerify();
166 JSSet::cast(this)->JSSetVerify();
169 JSMap::cast(this)->JSMapVerify();
171 case JS_WEAK_MAP_TYPE:
172 JSWeakMap::cast(this)->JSWeakMapVerify();
175 JSRegExp::cast(this)->JSRegExpVerify();
180 JSProxy::cast(this)->JSProxyVerify();
182 case JS_FUNCTION_PROXY_TYPE:
183 JSFunctionProxy::cast(this)->JSFunctionProxyVerify();
186 Foreign::cast(this)->ForeignVerify();
188 case SHARED_FUNCTION_INFO_TYPE:
189 SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify();
191 case JS_MESSAGE_OBJECT_TYPE:
192 JSMessageObject::cast(this)->JSMessageObjectVerify();
195 #define MAKE_STRUCT_CASE(NAME, Name, name) \
197 Name::cast(this)->Name##Verify(); \
199 STRUCT_LIST(MAKE_STRUCT_CASE)
200 #undef MAKE_STRUCT_CASE
209 void HeapObject::VerifyHeapPointer(Object* p) {
210 ASSERT(p->IsHeapObject());
211 ASSERT(HEAP->Contains(HeapObject::cast(p)));
215 void HeapNumber::HeapNumberVerify() {
216 ASSERT(IsHeapNumber());
220 void ByteArray::ByteArrayVerify() {
221 ASSERT(IsByteArray());
225 void FreeSpace::FreeSpaceVerify() {
226 ASSERT(IsFreeSpace());
230 void ExternalPixelArray::ExternalPixelArrayVerify() {
231 ASSERT(IsExternalPixelArray());
235 void ExternalByteArray::ExternalByteArrayVerify() {
236 ASSERT(IsExternalByteArray());
240 void ExternalUnsignedByteArray::ExternalUnsignedByteArrayVerify() {
241 ASSERT(IsExternalUnsignedByteArray());
245 void ExternalShortArray::ExternalShortArrayVerify() {
246 ASSERT(IsExternalShortArray());
250 void ExternalUnsignedShortArray::ExternalUnsignedShortArrayVerify() {
251 ASSERT(IsExternalUnsignedShortArray());
255 void ExternalIntArray::ExternalIntArrayVerify() {
256 ASSERT(IsExternalIntArray());
260 void ExternalUnsignedIntArray::ExternalUnsignedIntArrayVerify() {
261 ASSERT(IsExternalUnsignedIntArray());
265 void ExternalFloatArray::ExternalFloatArrayVerify() {
266 ASSERT(IsExternalFloatArray());
270 void ExternalDoubleArray::ExternalDoubleArrayVerify() {
271 ASSERT(IsExternalDoubleArray());
275 void JSObject::JSObjectVerify() {
276 VerifyHeapPointer(properties());
277 VerifyHeapPointer(elements());
279 if (GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS) {
280 ASSERT(this->elements()->IsFixedArray());
281 ASSERT(this->elements()->length() >= 2);
284 if (HasFastProperties()) {
285 CHECK_EQ(map()->unused_property_fields(),
286 (map()->inobject_properties() + properties()->length() -
287 map()->NextFreePropertyIndex()));
289 ASSERT_EQ((map()->has_fast_elements() ||
290 map()->has_fast_smi_only_elements() ||
291 (elements() == GetHeap()->empty_fixed_array())),
292 (elements()->map() == GetHeap()->fixed_array_map() ||
293 elements()->map() == GetHeap()->fixed_cow_array_map()));
294 ASSERT(map()->has_fast_elements() == HasFastElements());
298 void Map::MapVerify() {
299 ASSERT(!HEAP->InNewSpace(this));
300 ASSERT(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
301 ASSERT(instance_size() == kVariableSizeSentinel ||
302 (kPointerSize <= instance_size() &&
303 instance_size() < HEAP->Capacity()));
304 VerifyHeapPointer(prototype());
305 VerifyHeapPointer(instance_descriptors());
306 SLOW_ASSERT(instance_descriptors()->IsSortedNoDuplicates());
307 SLOW_ASSERT(instance_descriptors()->IsConsistentWithBackPointers(this));
311 void Map::SharedMapVerify() {
314 ASSERT(instance_descriptors()->IsEmpty());
315 ASSERT_EQ(0, pre_allocated_property_fields());
316 ASSERT_EQ(0, unused_property_fields());
317 ASSERT_EQ(StaticVisitorBase::GetVisitorId(instance_type(), instance_size()),
322 void CodeCache::CodeCacheVerify() {
323 VerifyHeapPointer(default_cache());
324 VerifyHeapPointer(normal_type_cache());
325 ASSERT(default_cache()->IsFixedArray());
326 ASSERT(normal_type_cache()->IsUndefined()
327 || normal_type_cache()->IsCodeCacheHashTable());
331 void PolymorphicCodeCache::PolymorphicCodeCacheVerify() {
332 VerifyHeapPointer(cache());
333 ASSERT(cache()->IsUndefined() || cache()->IsPolymorphicCodeCacheHashTable());
337 void TypeFeedbackInfo::TypeFeedbackInfoVerify() {
338 VerifyObjectField(kIcTotalCountOffset);
339 VerifyObjectField(kIcWithTypeinfoCountOffset);
340 VerifyHeapPointer(type_feedback_cells());
344 void AliasedArgumentsEntry::AliasedArgumentsEntryVerify() {
345 VerifySmiField(kAliasedContextSlot);
349 void FixedArray::FixedArrayVerify() {
350 for (int i = 0; i < length(); i++) {
352 if (e->IsHeapObject()) {
353 VerifyHeapPointer(e);
361 void FixedDoubleArray::FixedDoubleArrayVerify() {
362 for (int i = 0; i < length(); i++) {
363 if (!is_the_hole(i)) {
364 double value = get_scalar(i);
365 ASSERT(!isnan(value) ||
366 (BitCast<uint64_t>(value) ==
367 BitCast<uint64_t>(canonical_not_the_hole_nan_as_double())) ||
368 ((BitCast<uint64_t>(value) & Double::kSignMask) != 0));
374 void JSModule::JSModuleVerify() {
375 Object* v = context();
376 if (v->IsHeapObject()) {
377 VerifyHeapPointer(v);
379 CHECK(v->IsUndefined() || v->IsModuleContext());
383 void JSValue::JSValueVerify() {
385 if (v->IsHeapObject()) {
386 VerifyHeapPointer(v);
391 void JSDate::JSDateVerify() {
392 if (value()->IsHeapObject()) {
393 VerifyHeapPointer(value());
395 CHECK(value()->IsUndefined() || value()->IsSmi() || value()->IsHeapNumber());
396 CHECK(year()->IsUndefined() || year()->IsSmi() || year()->IsNaN());
397 CHECK(month()->IsUndefined() || month()->IsSmi() || month()->IsNaN());
398 CHECK(day()->IsUndefined() || day()->IsSmi() || day()->IsNaN());
399 CHECK(weekday()->IsUndefined() || weekday()->IsSmi() || weekday()->IsNaN());
400 CHECK(hour()->IsUndefined() || hour()->IsSmi() || hour()->IsNaN());
401 CHECK(min()->IsUndefined() || min()->IsSmi() || min()->IsNaN());
402 CHECK(sec()->IsUndefined() || sec()->IsSmi() || sec()->IsNaN());
403 CHECK(cache_stamp()->IsUndefined() ||
404 cache_stamp()->IsSmi() ||
405 cache_stamp()->IsNaN());
407 if (month()->IsSmi()) {
408 int month = Smi::cast(this->month())->value();
409 CHECK(0 <= month && month <= 11);
411 if (day()->IsSmi()) {
412 int day = Smi::cast(this->day())->value();
413 CHECK(1 <= day && day <= 31);
415 if (hour()->IsSmi()) {
416 int hour = Smi::cast(this->hour())->value();
417 CHECK(0 <= hour && hour <= 23);
419 if (min()->IsSmi()) {
420 int min = Smi::cast(this->min())->value();
421 CHECK(0 <= min && min <= 59);
423 if (sec()->IsSmi()) {
424 int sec = Smi::cast(this->sec())->value();
425 CHECK(0 <= sec && sec <= 59);
427 if (weekday()->IsSmi()) {
428 int weekday = Smi::cast(this->weekday())->value();
429 CHECK(0 <= weekday && weekday <= 6);
431 if (cache_stamp()->IsSmi()) {
432 CHECK(Smi::cast(cache_stamp())->value() <=
433 Smi::cast(Isolate::Current()->date_cache()->stamp())->value());
438 void JSMessageObject::JSMessageObjectVerify() {
439 CHECK(IsJSMessageObject());
440 CHECK(type()->IsString());
441 CHECK(arguments()->IsJSArray());
442 VerifyObjectField(kStartPositionOffset);
443 VerifyObjectField(kEndPositionOffset);
444 VerifyObjectField(kArgumentsOffset);
445 VerifyObjectField(kScriptOffset);
446 VerifyObjectField(kStackTraceOffset);
447 VerifyObjectField(kStackFramesOffset);
451 void String::StringVerify() {
453 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
455 CHECK(!HEAP->InNewSpace(this));
457 if (IsConsString()) {
458 ConsString::cast(this)->ConsStringVerify();
459 } else if (IsSlicedString()) {
460 SlicedString::cast(this)->SlicedStringVerify();
465 void ConsString::ConsStringVerify() {
466 CHECK(this->first()->IsString());
467 CHECK(this->second() == GetHeap()->empty_string() ||
468 this->second()->IsString());
469 CHECK(this->length() >= ConsString::kMinLength);
470 if (this->IsFlat()) {
471 // A flat cons can only be created by String::SlowTryFlatten.
472 // Afterwards, the first part may be externalized.
473 CHECK(this->first()->IsSeqString() || this->first()->IsExternalString());
478 void SlicedString::SlicedStringVerify() {
479 CHECK(!this->parent()->IsConsString());
480 CHECK(!this->parent()->IsSlicedString());
481 CHECK(this->length() >= SlicedString::kMinLength);
485 void JSFunction::JSFunctionVerify() {
486 CHECK(IsJSFunction());
487 VerifyObjectField(kPrototypeOrInitialMapOffset);
488 VerifyObjectField(kNextFunctionLinkOffset);
489 CHECK(code()->IsCode());
490 CHECK(next_function_link()->IsUndefined() ||
491 next_function_link()->IsJSFunction());
495 void SharedFunctionInfo::SharedFunctionInfoVerify() {
496 CHECK(IsSharedFunctionInfo());
497 VerifyObjectField(kNameOffset);
498 VerifyObjectField(kCodeOffset);
499 VerifyObjectField(kScopeInfoOffset);
500 VerifyObjectField(kInstanceClassNameOffset);
501 VerifyObjectField(kFunctionDataOffset);
502 VerifyObjectField(kScriptOffset);
503 VerifyObjectField(kDebugInfoOffset);
507 void JSGlobalProxy::JSGlobalProxyVerify() {
508 CHECK(IsJSGlobalProxy());
510 VerifyObjectField(JSGlobalProxy::kContextOffset);
511 // Make sure that this object has no properties, elements.
512 CHECK_EQ(0, properties()->length());
513 CHECK(HasFastElements());
514 CHECK_EQ(0, FixedArray::cast(elements())->length());
518 void JSGlobalObject::JSGlobalObjectVerify() {
519 CHECK(IsJSGlobalObject());
521 for (int i = GlobalObject::kBuiltinsOffset;
522 i < JSGlobalObject::kSize;
524 VerifyObjectField(i);
529 void JSBuiltinsObject::JSBuiltinsObjectVerify() {
530 CHECK(IsJSBuiltinsObject());
532 for (int i = GlobalObject::kBuiltinsOffset;
533 i < JSBuiltinsObject::kSize;
535 VerifyObjectField(i);
540 void Oddball::OddballVerify() {
542 VerifyHeapPointer(to_string());
543 Object* number = to_number();
544 if (number->IsHeapObject()) {
545 ASSERT(number == HEAP->nan_value());
547 ASSERT(number->IsSmi());
548 int value = Smi::cast(number)->value();
549 // Hidden oddballs have negative smis.
550 const int kLeastHiddenOddballNumber = -4;
552 ASSERT(value >= kLeastHiddenOddballNumber);
557 void JSGlobalPropertyCell::JSGlobalPropertyCellVerify() {
558 CHECK(IsJSGlobalPropertyCell());
559 VerifyObjectField(kValueOffset);
563 void Code::CodeVerify() {
564 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
566 relocation_info()->Verify();
567 Address last_gc_pc = NULL;
568 for (RelocIterator it(this); !it.done(); it.next()) {
569 it.rinfo()->Verify();
570 // Ensure that GC will not iterate twice over the same pointer.
571 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
572 CHECK(it.rinfo()->pc() != last_gc_pc);
573 last_gc_pc = it.rinfo()->pc();
579 void JSArray::JSArrayVerify() {
581 ASSERT(length()->IsNumber() || length()->IsUndefined());
582 ASSERT(elements()->IsUndefined() ||
583 elements()->IsFixedArray() ||
584 elements()->IsFixedDoubleArray());
588 void JSSet::JSSetVerify() {
591 VerifyHeapPointer(table());
592 ASSERT(table()->IsHashTable() || table()->IsUndefined());
596 void JSMap::JSMapVerify() {
599 VerifyHeapPointer(table());
600 ASSERT(table()->IsHashTable() || table()->IsUndefined());
604 void JSWeakMap::JSWeakMapVerify() {
605 CHECK(IsJSWeakMap());
607 VerifyHeapPointer(table());
608 ASSERT(table()->IsHashTable() || table()->IsUndefined());
612 void JSRegExp::JSRegExpVerify() {
614 ASSERT(data()->IsUndefined() || data()->IsFixedArray());
616 case JSRegExp::ATOM: {
617 FixedArray* arr = FixedArray::cast(data());
618 ASSERT(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
621 case JSRegExp::IRREGEXP: {
622 bool is_native = RegExpImpl::UsesNativeRegExp();
624 FixedArray* arr = FixedArray::cast(data());
625 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
626 // Smi : Not compiled yet (-1) or code prepared for flushing.
627 // JSObject: Compilation error.
628 // Code/ByteArray: Compiled code.
629 ASSERT(ascii_data->IsSmi() ||
630 (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray()));
631 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
632 ASSERT(uc16_data->IsSmi() ||
633 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
635 Object* ascii_saved = arr->get(JSRegExp::kIrregexpASCIICodeSavedIndex);
636 ASSERT(ascii_saved->IsSmi() || ascii_saved->IsString() ||
637 ascii_saved->IsCode());
638 Object* uc16_saved = arr->get(JSRegExp::kIrregexpUC16CodeSavedIndex);
639 ASSERT(uc16_saved->IsSmi() || uc16_saved->IsString() ||
640 uc16_saved->IsCode());
642 ASSERT(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
643 ASSERT(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
647 ASSERT_EQ(JSRegExp::NOT_COMPILED, TypeTag());
648 ASSERT(data()->IsUndefined());
654 void JSProxy::JSProxyVerify() {
656 VerifyPointer(handler());
657 ASSERT(hash()->IsSmi() || hash()->IsUndefined());
661 void JSFunctionProxy::JSFunctionProxyVerify() {
662 CHECK(IsJSFunctionProxy());
664 VerifyPointer(call_trap());
665 VerifyPointer(construct_trap());
669 void Foreign::ForeignVerify() {
674 void AccessorInfo::AccessorInfoVerify() {
675 CHECK(IsAccessorInfo());
676 VerifyPointer(getter());
677 VerifyPointer(setter());
678 VerifyPointer(name());
679 VerifyPointer(data());
680 VerifyPointer(flag());
684 void AccessorPair::AccessorPairVerify() {
685 CHECK(IsAccessorPair());
686 VerifyPointer(getter());
687 VerifyPointer(setter());
691 void AccessCheckInfo::AccessCheckInfoVerify() {
692 CHECK(IsAccessCheckInfo());
693 VerifyPointer(named_callback());
694 VerifyPointer(indexed_callback());
695 VerifyPointer(data());
699 void InterceptorInfo::InterceptorInfoVerify() {
700 CHECK(IsInterceptorInfo());
701 VerifyPointer(getter());
702 VerifyPointer(setter());
703 VerifyPointer(query());
704 VerifyPointer(deleter());
705 VerifyPointer(enumerator());
706 VerifyPointer(data());
710 void CallHandlerInfo::CallHandlerInfoVerify() {
711 CHECK(IsCallHandlerInfo());
712 VerifyPointer(callback());
713 VerifyPointer(data());
717 void TemplateInfo::TemplateInfoVerify() {
718 VerifyPointer(tag());
719 VerifyPointer(property_list());
722 void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
723 CHECK(IsFunctionTemplateInfo());
724 TemplateInfoVerify();
725 VerifyPointer(serial_number());
726 VerifyPointer(call_code());
727 VerifyPointer(property_accessors());
728 VerifyPointer(prototype_template());
729 VerifyPointer(parent_template());
730 VerifyPointer(named_property_handler());
731 VerifyPointer(indexed_property_handler());
732 VerifyPointer(instance_template());
733 VerifyPointer(signature());
734 VerifyPointer(access_check_info());
738 void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
739 CHECK(IsObjectTemplateInfo());
740 TemplateInfoVerify();
741 VerifyPointer(constructor());
742 VerifyPointer(internal_field_count());
746 void SignatureInfo::SignatureInfoVerify() {
747 CHECK(IsSignatureInfo());
748 VerifyPointer(receiver());
749 VerifyPointer(args());
753 void TypeSwitchInfo::TypeSwitchInfoVerify() {
754 CHECK(IsTypeSwitchInfo());
755 VerifyPointer(types());
759 void Script::ScriptVerify() {
761 VerifyPointer(source());
762 VerifyPointer(name());
763 line_offset()->SmiVerify();
764 column_offset()->SmiVerify();
765 VerifyPointer(data());
766 VerifyPointer(wrapper());
768 VerifyPointer(line_ends());
773 #ifdef ENABLE_DEBUGGER_SUPPORT
774 void DebugInfo::DebugInfoVerify() {
775 CHECK(IsDebugInfo());
776 VerifyPointer(shared());
777 VerifyPointer(original_code());
778 VerifyPointer(code());
779 VerifyPointer(break_points());
783 void BreakPointInfo::BreakPointInfoVerify() {
784 CHECK(IsBreakPointInfo());
785 code_position()->SmiVerify();
786 source_position()->SmiVerify();
787 statement_position()->SmiVerify();
788 VerifyPointer(break_point_objects());
790 #endif // ENABLE_DEBUGGER_SUPPORT
793 void JSObject::IncrementSpillStatistics(SpillInformation* info) {
794 info->number_of_objects_++;
796 if (HasFastProperties()) {
797 info->number_of_objects_with_fast_properties_++;
798 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
799 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
801 StringDictionary* dict = property_dictionary();
802 info->number_of_slow_used_properties_ += dict->NumberOfElements();
803 info->number_of_slow_unused_properties_ +=
804 dict->Capacity() - dict->NumberOfElements();
806 // Indexed properties
807 switch (GetElementsKind()) {
808 case FAST_ELEMENTS: {
809 info->number_of_objects_with_fast_elements_++;
811 FixedArray* e = FixedArray::cast(elements());
812 int len = e->length();
814 for (int i = 0; i < len; i++) {
815 if (e->get(i) == heap->the_hole_value()) holes++;
817 info->number_of_fast_used_elements_ += len - holes;
818 info->number_of_fast_unused_elements_ += holes;
821 case EXTERNAL_PIXEL_ELEMENTS: {
822 info->number_of_objects_with_fast_elements_++;
823 ExternalPixelArray* e = ExternalPixelArray::cast(elements());
824 info->number_of_fast_used_elements_ += e->length();
827 case DICTIONARY_ELEMENTS: {
828 SeededNumberDictionary* dict = element_dictionary();
829 info->number_of_slow_used_elements_ += dict->NumberOfElements();
830 info->number_of_slow_unused_elements_ +=
831 dict->Capacity() - dict->NumberOfElements();
841 void JSObject::SpillInformation::Clear() {
842 number_of_objects_ = 0;
843 number_of_objects_with_fast_properties_ = 0;
844 number_of_objects_with_fast_elements_ = 0;
845 number_of_fast_used_fields_ = 0;
846 number_of_fast_unused_fields_ = 0;
847 number_of_slow_used_properties_ = 0;
848 number_of_slow_unused_properties_ = 0;
849 number_of_fast_used_elements_ = 0;
850 number_of_fast_unused_elements_ = 0;
851 number_of_slow_used_elements_ = 0;
852 number_of_slow_unused_elements_ = 0;
855 void JSObject::SpillInformation::Print() {
856 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
858 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
859 number_of_objects_with_fast_properties_,
860 number_of_fast_used_fields_, number_of_fast_unused_fields_);
862 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
863 number_of_objects_ - number_of_objects_with_fast_properties_,
864 number_of_slow_used_properties_, number_of_slow_unused_properties_);
866 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
867 number_of_objects_with_fast_elements_,
868 number_of_fast_used_elements_, number_of_fast_unused_elements_);
870 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
871 number_of_objects_ - number_of_objects_with_fast_elements_,
872 number_of_slow_used_elements_, number_of_slow_unused_elements_);
878 bool DescriptorArray::IsSortedNoDuplicates() {
879 String* current_key = NULL;
880 uint32_t current = 0;
881 for (int i = 0; i < number_of_descriptors(); i++) {
882 String* key = GetKey(i);
883 if (key == current_key) {
888 uint32_t hash = GetKey(i)->Hash();
889 if (hash < current) {
899 static bool CheckOneBackPointer(Map* current_map, Object* target) {
900 return !target->IsMap() || Map::cast(target)->GetBackPointer() == current_map;
904 bool DescriptorArray::IsConsistentWithBackPointers(Map* current_map) {
905 for (int i = 0; i < number_of_descriptors(); ++i) {
906 switch (GetType(i)) {
908 case CONSTANT_TRANSITION:
909 if (!CheckOneBackPointer(current_map, GetValue(i))) {
913 case ELEMENTS_TRANSITION: {
914 Object* object = GetValue(i);
915 if (!CheckOneBackPointer(current_map, object)) {
918 if (object->IsFixedArray()) {
919 FixedArray* array = FixedArray::cast(object);
920 for (int i = 0; i < array->length(); ++i) {
921 if (!CheckOneBackPointer(current_map, array->get(i))) {
929 Object* object = GetValue(i);
930 if (object->IsAccessorPair()) {
931 AccessorPair* accessors = AccessorPair::cast(object);
932 if (!CheckOneBackPointer(current_map, accessors->getter())) {
935 if (!CheckOneBackPointer(current_map, accessors->setter())) {
943 case CONSTANT_FUNCTION:
946 case NULL_DESCRIPTOR:
954 void JSFunctionResultCache::JSFunctionResultCacheVerify() {
955 JSFunction::cast(get(kFactoryIndex))->Verify();
957 int size = Smi::cast(get(kCacheSizeIndex))->value();
958 ASSERT(kEntriesIndex <= size);
959 ASSERT(size <= length());
960 ASSERT_EQ(0, size % kEntrySize);
962 int finger = Smi::cast(get(kFingerIndex))->value();
963 ASSERT(kEntriesIndex <= finger);
964 ASSERT((finger < size) || (finger == kEntriesIndex && finger == size));
965 ASSERT_EQ(0, finger % kEntrySize);
967 if (FLAG_enable_slow_asserts) {
968 for (int i = kEntriesIndex; i < size; i++) {
969 ASSERT(!get(i)->IsTheHole());
972 for (int i = size; i < length(); i++) {
973 ASSERT(get(i)->IsTheHole());
980 void NormalizedMapCache::NormalizedMapCacheVerify() {
981 FixedArray::cast(this)->Verify();
982 if (FLAG_enable_slow_asserts) {
983 for (int i = 0; i < length(); i++) {
986 Map::cast(e)->SharedMapVerify();
988 ASSERT(e->IsUndefined());
995 void Map::ZapInstanceDescriptors() {
996 DescriptorArray* descriptors = instance_descriptors();
997 if (descriptors == GetHeap()->empty_descriptor_array()) return;
998 FixedArray* contents = FixedArray::cast(
999 descriptors->get(DescriptorArray::kContentArrayIndex));
1000 MemsetPointer(descriptors->data_start(),
1001 GetHeap()->the_hole_value(),
1002 descriptors->length());
1003 MemsetPointer(contents->data_start(),
1004 GetHeap()->the_hole_value(),
1005 contents->length());
1009 void Map::ZapPrototypeTransitions() {
1010 FixedArray* proto_transitions = prototype_transitions();
1011 MemsetPointer(proto_transitions->data_start(),
1012 GetHeap()->the_hole_value(),
1013 proto_transitions->length());
1019 } } // namespace v8::internal