1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "disassembler.h"
10 #include "macro-assembler.h"
11 #include "objects-visiting.h"
18 void Object::ObjectVerify() {
20 Smi::cast(this)->SmiVerify();
22 HeapObject::cast(this)->HeapObjectVerify();
27 void Object::VerifyPointer(Object* p) {
28 if (p->IsHeapObject()) {
29 HeapObject::VerifyHeapPointer(p);
36 void Smi::SmiVerify() {
41 void HeapObject::HeapObjectVerify() {
42 InstanceType instance_type = map()->instance_type();
44 if (instance_type < FIRST_NONSTRING_TYPE) {
45 String::cast(this)->StringVerify();
49 switch (instance_type) {
51 Symbol::cast(this)->SymbolVerify();
54 Map::cast(this)->MapVerify();
56 case HEAP_NUMBER_TYPE:
57 HeapNumber::cast(this)->HeapNumberVerify();
60 Float32x4::cast(this)->Float32x4Verify();
63 Float64x2::cast(this)->Float64x2Verify();
66 Int32x4::cast(this)->Int32x4Verify();
68 case FIXED_ARRAY_TYPE:
69 FixedArray::cast(this)->FixedArrayVerify();
71 case FIXED_DOUBLE_ARRAY_TYPE:
72 FixedDoubleArray::cast(this)->FixedDoubleArrayVerify();
74 case CONSTANT_POOL_ARRAY_TYPE:
75 ConstantPoolArray::cast(this)->ConstantPoolArrayVerify();
78 ByteArray::cast(this)->ByteArrayVerify();
81 FreeSpace::cast(this)->FreeSpaceVerify();
84 #define VERIFY_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
85 case EXTERNAL_##TYPE##_ARRAY_TYPE: \
86 External##Type##Array::cast(this)->External##Type##ArrayVerify(); \
88 case FIXED_##TYPE##_ARRAY_TYPE: \
89 Fixed##Type##Array::cast(this)->FixedTypedArrayVerify(); \
92 TYPED_ARRAYS(VERIFY_TYPED_ARRAY)
93 #undef VERIFY_TYPED_ARRAY
96 Code::cast(this)->CodeVerify();
99 Oddball::cast(this)->OddballVerify();
102 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
103 JSObject::cast(this)->JSObjectVerify();
105 case JS_GENERATOR_OBJECT_TYPE:
106 JSGeneratorObject::cast(this)->JSGeneratorObjectVerify();
109 JSModule::cast(this)->JSModuleVerify();
112 JSValue::cast(this)->JSValueVerify();
115 JSDate::cast(this)->JSDateVerify();
117 case JS_FUNCTION_TYPE:
118 JSFunction::cast(this)->JSFunctionVerify();
120 case JS_GLOBAL_PROXY_TYPE:
121 JSGlobalProxy::cast(this)->JSGlobalProxyVerify();
123 case JS_GLOBAL_OBJECT_TYPE:
124 JSGlobalObject::cast(this)->JSGlobalObjectVerify();
126 case JS_BUILTINS_OBJECT_TYPE:
127 JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify();
130 Cell::cast(this)->CellVerify();
132 case PROPERTY_CELL_TYPE:
133 PropertyCell::cast(this)->PropertyCellVerify();
136 JSArray::cast(this)->JSArrayVerify();
139 JSSet::cast(this)->JSSetVerify();
142 JSMap::cast(this)->JSMapVerify();
144 case JS_SET_ITERATOR_TYPE:
145 JSSetIterator::cast(this)->JSSetIteratorVerify();
147 case JS_MAP_ITERATOR_TYPE:
148 JSMapIterator::cast(this)->JSMapIteratorVerify();
150 case JS_WEAK_MAP_TYPE:
151 JSWeakMap::cast(this)->JSWeakMapVerify();
153 case JS_WEAK_SET_TYPE:
154 JSWeakSet::cast(this)->JSWeakSetVerify();
157 JSRegExp::cast(this)->JSRegExpVerify();
162 JSProxy::cast(this)->JSProxyVerify();
164 case JS_FUNCTION_PROXY_TYPE:
165 JSFunctionProxy::cast(this)->JSFunctionProxyVerify();
168 Foreign::cast(this)->ForeignVerify();
170 case SHARED_FUNCTION_INFO_TYPE:
171 SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify();
173 case JS_MESSAGE_OBJECT_TYPE:
174 JSMessageObject::cast(this)->JSMessageObjectVerify();
176 case JS_ARRAY_BUFFER_TYPE:
177 JSArrayBuffer::cast(this)->JSArrayBufferVerify();
179 case JS_TYPED_ARRAY_TYPE:
180 JSTypedArray::cast(this)->JSTypedArrayVerify();
182 case JS_DATA_VIEW_TYPE:
183 JSDataView::cast(this)->JSDataViewVerify();
186 #define MAKE_STRUCT_CASE(NAME, Name, name) \
188 Name::cast(this)->Name##Verify(); \
190 STRUCT_LIST(MAKE_STRUCT_CASE)
191 #undef MAKE_STRUCT_CASE
200 void HeapObject::VerifyHeapPointer(Object* p) {
201 CHECK(p->IsHeapObject());
202 HeapObject* ho = HeapObject::cast(p);
203 CHECK(ho->GetHeap()->Contains(ho));
207 void Symbol::SymbolVerify() {
209 CHECK(HasHashCode());
211 CHECK(name()->IsUndefined() || name()->IsString());
212 CHECK(flags()->IsSmi());
216 void HeapNumber::HeapNumberVerify() {
217 CHECK(IsHeapNumber());
221 void Float32x4::Float32x4Verify() {
222 CHECK(IsFloat32x4());
226 void Float64x2::Float64x2Verify() {
227 CHECK(IsFloat64x2());
231 void Int32x4::Int32x4Verify() {
236 void ByteArray::ByteArrayVerify() {
237 CHECK(IsByteArray());
241 void FreeSpace::FreeSpaceVerify() {
242 CHECK(IsFreeSpace());
246 #define EXTERNAL_ARRAY_VERIFY(Type, type, TYPE, ctype, size) \
247 void External##Type##Array::External##Type##ArrayVerify() { \
248 CHECK(IsExternal##Type##Array()); \
251 TYPED_ARRAYS(EXTERNAL_ARRAY_VERIFY)
252 #undef EXTERNAL_ARRAY_VERIFY
255 template <class Traits>
256 void FixedTypedArray<Traits>::FixedTypedArrayVerify() {
257 CHECK(IsHeapObject() &&
258 HeapObject::cast(this)->map()->instance_type() ==
259 Traits::kInstanceType);
263 bool JSObject::ElementsAreSafeToExamine() {
264 // If a GC was caused while constructing this object, the elements
265 // pointer may point to a one pointer filler map.
266 return reinterpret_cast<Map*>(elements()) !=
267 GetHeap()->one_pointer_filler_map();
271 void JSObject::JSObjectVerify() {
272 VerifyHeapPointer(properties());
273 VerifyHeapPointer(elements());
275 if (GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS) {
276 CHECK(this->elements()->IsFixedArray());
277 CHECK_GE(this->elements()->length(), 2);
280 if (HasFastProperties()) {
281 CHECK_EQ(map()->unused_property_fields(),
282 (map()->inobject_properties() + properties()->length() -
283 map()->NextFreePropertyIndex()));
284 DescriptorArray* descriptors = map()->instance_descriptors();
285 for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
286 if (descriptors->GetDetails(i).type() == FIELD) {
287 Representation r = descriptors->GetDetails(i).representation();
288 int field = descriptors->GetFieldIndex(i);
289 Object* value = RawFastPropertyAt(field);
290 if (r.IsDouble()) ASSERT(value->IsHeapNumber());
291 if (value->IsUninitialized()) continue;
292 if (r.IsSmi()) ASSERT(value->IsSmi());
293 if (r.IsHeapObject()) ASSERT(value->IsHeapObject());
294 HeapType* field_type = descriptors->GetFieldType(i);
296 CHECK(field_type->Is(HeapType::None()));
297 } else if (!HeapType::Any()->Is(field_type)) {
298 CHECK(!field_type->NowStable() || field_type->NowContains(value));
304 // If a GC was caused while constructing this object, the elements
305 // pointer may point to a one pointer filler map.
306 if (ElementsAreSafeToExamine()) {
307 CHECK_EQ((map()->has_fast_smi_or_object_elements() ||
308 (elements() == GetHeap()->empty_fixed_array())),
309 (elements()->map() == GetHeap()->fixed_array_map() ||
310 elements()->map() == GetHeap()->fixed_cow_array_map()));
311 CHECK(map()->has_fast_object_elements() == HasFastObjectElements());
316 void Map::MapVerify() {
317 Heap* heap = GetHeap();
318 CHECK(!heap->InNewSpace(this));
319 CHECK(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
320 CHECK(instance_size() == kVariableSizeSentinel ||
321 (kPointerSize <= instance_size() &&
322 instance_size() < heap->Capacity()));
323 VerifyHeapPointer(prototype());
324 VerifyHeapPointer(instance_descriptors());
325 SLOW_ASSERT(instance_descriptors()->IsSortedNoDuplicates());
326 if (HasTransitionArray()) {
327 SLOW_ASSERT(transitions()->IsSortedNoDuplicates());
328 SLOW_ASSERT(transitions()->IsConsistentWithBackPointers(this));
333 void Map::SharedMapVerify() {
336 CHECK(instance_descriptors()->IsEmpty());
337 CHECK_EQ(0, pre_allocated_property_fields());
338 CHECK_EQ(0, unused_property_fields());
339 CHECK_EQ(StaticVisitorBase::GetVisitorId(instance_type(), instance_size()),
344 void Map::VerifyOmittedMapChecks() {
345 if (!FLAG_omit_map_checks_for_leaf_maps) return;
348 HasTransitionArray() ||
349 is_dictionary_map()) {
350 CHECK_EQ(0, dependent_code()->number_of_entries(
351 DependentCode::kPrototypeCheckGroup));
356 void CodeCache::CodeCacheVerify() {
357 VerifyHeapPointer(default_cache());
358 VerifyHeapPointer(normal_type_cache());
359 CHECK(default_cache()->IsFixedArray());
360 CHECK(normal_type_cache()->IsUndefined()
361 || normal_type_cache()->IsCodeCacheHashTable());
365 void PolymorphicCodeCache::PolymorphicCodeCacheVerify() {
366 VerifyHeapPointer(cache());
367 CHECK(cache()->IsUndefined() || cache()->IsPolymorphicCodeCacheHashTable());
371 void TypeFeedbackInfo::TypeFeedbackInfoVerify() {
372 VerifyObjectField(kStorage1Offset);
373 VerifyObjectField(kStorage2Offset);
377 void AliasedArgumentsEntry::AliasedArgumentsEntryVerify() {
378 VerifySmiField(kAliasedContextSlot);
382 void FixedArray::FixedArrayVerify() {
383 for (int i = 0; i < length(); i++) {
390 void FixedDoubleArray::FixedDoubleArrayVerify() {
391 for (int i = 0; i < length(); i++) {
392 if (!is_the_hole(i)) {
393 double value = get_scalar(i);
394 CHECK(!std::isnan(value) ||
395 (BitCast<uint64_t>(value) ==
396 BitCast<uint64_t>(canonical_not_the_hole_nan_as_double())) ||
397 ((BitCast<uint64_t>(value) & Double::kSignMask) != 0));
403 void ConstantPoolArray::ConstantPoolArrayVerify() {
404 CHECK(IsConstantPoolArray());
405 for (int i = 0; i < count_of_code_ptr_entries(); i++) {
406 Address code_entry = get_code_ptr_entry(first_code_ptr_index() + i);
407 VerifyPointer(Code::GetCodeFromTargetAddress(code_entry));
409 for (int i = 0; i < count_of_heap_ptr_entries(); i++) {
410 VerifyObjectField(OffsetOfElementAt(first_heap_ptr_index() + i));
415 void JSGeneratorObject::JSGeneratorObjectVerify() {
416 // In an expression like "new g()", there can be a point where a generator
417 // object is allocated but its fields are all undefined, as it hasn't yet been
418 // initialized by the generator. Hence these weak checks.
419 VerifyObjectField(kFunctionOffset);
420 VerifyObjectField(kContextOffset);
421 VerifyObjectField(kReceiverOffset);
422 VerifyObjectField(kOperandStackOffset);
423 VerifyObjectField(kContinuationOffset);
424 VerifyObjectField(kStackHandlerIndexOffset);
428 void JSModule::JSModuleVerify() {
429 VerifyObjectField(kContextOffset);
430 VerifyObjectField(kScopeInfoOffset);
431 CHECK(context()->IsUndefined() ||
432 Context::cast(context())->IsModuleContext());
436 void JSValue::JSValueVerify() {
438 if (v->IsHeapObject()) {
439 VerifyHeapPointer(v);
444 void JSDate::JSDateVerify() {
445 if (value()->IsHeapObject()) {
446 VerifyHeapPointer(value());
448 CHECK(value()->IsUndefined() || value()->IsSmi() || value()->IsHeapNumber());
449 CHECK(year()->IsUndefined() || year()->IsSmi() || year()->IsNaN());
450 CHECK(month()->IsUndefined() || month()->IsSmi() || month()->IsNaN());
451 CHECK(day()->IsUndefined() || day()->IsSmi() || day()->IsNaN());
452 CHECK(weekday()->IsUndefined() || weekday()->IsSmi() || weekday()->IsNaN());
453 CHECK(hour()->IsUndefined() || hour()->IsSmi() || hour()->IsNaN());
454 CHECK(min()->IsUndefined() || min()->IsSmi() || min()->IsNaN());
455 CHECK(sec()->IsUndefined() || sec()->IsSmi() || sec()->IsNaN());
456 CHECK(cache_stamp()->IsUndefined() ||
457 cache_stamp()->IsSmi() ||
458 cache_stamp()->IsNaN());
460 if (month()->IsSmi()) {
461 int month = Smi::cast(this->month())->value();
462 CHECK(0 <= month && month <= 11);
464 if (day()->IsSmi()) {
465 int day = Smi::cast(this->day())->value();
466 CHECK(1 <= day && day <= 31);
468 if (hour()->IsSmi()) {
469 int hour = Smi::cast(this->hour())->value();
470 CHECK(0 <= hour && hour <= 23);
472 if (min()->IsSmi()) {
473 int min = Smi::cast(this->min())->value();
474 CHECK(0 <= min && min <= 59);
476 if (sec()->IsSmi()) {
477 int sec = Smi::cast(this->sec())->value();
478 CHECK(0 <= sec && sec <= 59);
480 if (weekday()->IsSmi()) {
481 int weekday = Smi::cast(this->weekday())->value();
482 CHECK(0 <= weekday && weekday <= 6);
484 if (cache_stamp()->IsSmi()) {
485 CHECK(Smi::cast(cache_stamp())->value() <=
486 Smi::cast(GetIsolate()->date_cache()->stamp())->value());
491 void JSMessageObject::JSMessageObjectVerify() {
492 CHECK(IsJSMessageObject());
493 CHECK(type()->IsString());
494 CHECK(arguments()->IsJSArray());
495 VerifyObjectField(kStartPositionOffset);
496 VerifyObjectField(kEndPositionOffset);
497 VerifyObjectField(kArgumentsOffset);
498 VerifyObjectField(kScriptOffset);
499 VerifyObjectField(kStackFramesOffset);
503 void String::StringVerify() {
505 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
506 if (IsInternalizedString()) {
507 CHECK(!GetHeap()->InNewSpace(this));
509 if (IsConsString()) {
510 ConsString::cast(this)->ConsStringVerify();
511 } else if (IsSlicedString()) {
512 SlicedString::cast(this)->SlicedStringVerify();
517 void ConsString::ConsStringVerify() {
518 CHECK(this->first()->IsString());
519 CHECK(this->second() == GetHeap()->empty_string() ||
520 this->second()->IsString());
521 CHECK(this->length() >= ConsString::kMinLength);
522 CHECK(this->length() == this->first()->length() + this->second()->length());
523 if (this->IsFlat()) {
524 // A flat cons can only be created by String::SlowTryFlatten.
525 // Afterwards, the first part may be externalized.
526 CHECK(this->first()->IsSeqString() || this->first()->IsExternalString());
531 void SlicedString::SlicedStringVerify() {
532 CHECK(!this->parent()->IsConsString());
533 CHECK(!this->parent()->IsSlicedString());
534 CHECK(this->length() >= SlicedString::kMinLength);
538 void JSFunction::JSFunctionVerify() {
539 CHECK(IsJSFunction());
540 VerifyObjectField(kPrototypeOrInitialMapOffset);
541 VerifyObjectField(kNextFunctionLinkOffset);
542 CHECK(code()->IsCode());
543 CHECK(next_function_link() == NULL ||
544 next_function_link()->IsUndefined() ||
545 next_function_link()->IsJSFunction());
549 void SharedFunctionInfo::SharedFunctionInfoVerify() {
550 CHECK(IsSharedFunctionInfo());
551 VerifyObjectField(kNameOffset);
552 VerifyObjectField(kCodeOffset);
553 VerifyObjectField(kOptimizedCodeMapOffset);
554 VerifyObjectField(kFeedbackVectorOffset);
555 VerifyObjectField(kScopeInfoOffset);
556 VerifyObjectField(kInstanceClassNameOffset);
557 VerifyObjectField(kFunctionDataOffset);
558 VerifyObjectField(kScriptOffset);
559 VerifyObjectField(kDebugInfoOffset);
563 void JSGlobalProxy::JSGlobalProxyVerify() {
564 CHECK(IsJSGlobalProxy());
566 VerifyObjectField(JSGlobalProxy::kNativeContextOffset);
567 // Make sure that this object has no properties, elements.
568 CHECK_EQ(0, properties()->length());
569 CHECK(HasFastObjectElements());
570 CHECK_EQ(0, FixedArray::cast(elements())->length());
574 void JSGlobalObject::JSGlobalObjectVerify() {
575 CHECK(IsJSGlobalObject());
577 for (int i = GlobalObject::kBuiltinsOffset;
578 i < JSGlobalObject::kSize;
580 VerifyObjectField(i);
585 void JSBuiltinsObject::JSBuiltinsObjectVerify() {
586 CHECK(IsJSBuiltinsObject());
588 for (int i = GlobalObject::kBuiltinsOffset;
589 i < JSBuiltinsObject::kSize;
591 VerifyObjectField(i);
596 void Oddball::OddballVerify() {
598 Heap* heap = GetHeap();
599 VerifyHeapPointer(to_string());
600 Object* number = to_number();
601 if (number->IsHeapObject()) {
602 CHECK(number == heap->nan_value());
604 CHECK(number->IsSmi());
605 int value = Smi::cast(number)->value();
606 // Hidden oddballs have negative smis.
607 const int kLeastHiddenOddballNumber = -5;
609 CHECK(value >= kLeastHiddenOddballNumber);
611 if (map() == heap->undefined_map()) {
612 CHECK(this == heap->undefined_value());
613 } else if (map() == heap->the_hole_map()) {
614 CHECK(this == heap->the_hole_value());
615 } else if (map() == heap->null_map()) {
616 CHECK(this == heap->null_value());
617 } else if (map() == heap->boolean_map()) {
618 CHECK(this == heap->true_value() ||
619 this == heap->false_value());
620 } else if (map() == heap->uninitialized_map()) {
621 CHECK(this == heap->uninitialized_value());
622 } else if (map() == heap->no_interceptor_result_sentinel_map()) {
623 CHECK(this == heap->no_interceptor_result_sentinel());
624 } else if (map() == heap->arguments_marker_map()) {
625 CHECK(this == heap->arguments_marker());
626 } else if (map() == heap->termination_exception_map()) {
627 CHECK(this == heap->termination_exception());
628 } else if (map() == heap->exception_map()) {
629 CHECK(this == heap->exception());
636 void Cell::CellVerify() {
638 VerifyObjectField(kValueOffset);
642 void PropertyCell::PropertyCellVerify() {
643 CHECK(IsPropertyCell());
644 VerifyObjectField(kValueOffset);
645 VerifyObjectField(kTypeOffset);
649 void Code::CodeVerify() {
650 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
652 relocation_info()->ObjectVerify();
653 Address last_gc_pc = NULL;
654 for (RelocIterator it(this); !it.done(); it.next()) {
655 it.rinfo()->Verify();
656 // Ensure that GC will not iterate twice over the same pointer.
657 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
658 CHECK(it.rinfo()->pc() != last_gc_pc);
659 last_gc_pc = it.rinfo()->pc();
665 void Code::VerifyEmbeddedObjectsDependency() {
666 if (!CanContainWeakObjects()) return;
667 DisallowHeapAllocation no_gc;
668 Isolate* isolate = GetIsolate();
669 HandleScope scope(isolate);
670 int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
671 for (RelocIterator it(this, mode_mask); !it.done(); it.next()) {
672 Object* obj = it.rinfo()->target_object();
673 if (IsWeakObject(obj)) {
675 Map* map = Map::cast(obj);
676 DependentCode::DependencyGroup group = is_optimized_code() ?
677 DependentCode::kWeakCodeGroup : DependentCode::kWeakICGroup;
678 CHECK(map->dependent_code()->Contains(group, this));
679 } else if (obj->IsJSObject()) {
680 Object* raw_table = GetIsolate()->heap()->weak_object_to_code_table();
681 WeakHashTable* table = WeakHashTable::cast(raw_table);
682 Handle<Object> key_obj(obj, isolate);
683 CHECK(DependentCode::cast(table->Lookup(key_obj))->Contains(
684 DependentCode::kWeakCodeGroup, this));
691 void JSArray::JSArrayVerify() {
693 CHECK(length()->IsNumber() || length()->IsUndefined());
694 // If a GC was caused while constructing this array, the elements
695 // pointer may point to a one pointer filler map.
696 if (ElementsAreSafeToExamine()) {
697 CHECK(elements()->IsUndefined() ||
698 elements()->IsFixedArray() ||
699 elements()->IsFixedDoubleArray());
704 void JSSet::JSSetVerify() {
707 VerifyHeapPointer(table());
708 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
709 // TODO(arv): Verify OrderedHashTable too.
713 void JSMap::JSMapVerify() {
716 VerifyHeapPointer(table());
717 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
718 // TODO(arv): Verify OrderedHashTable too.
722 void JSSetIterator::JSSetIteratorVerify() {
723 CHECK(IsJSSetIterator());
725 VerifyHeapPointer(table());
726 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
727 CHECK(index()->IsSmi());
728 CHECK(count()->IsSmi());
729 CHECK(kind()->IsSmi());
730 VerifyHeapPointer(next_iterator());
731 CHECK(next_iterator()->IsJSSetIterator() || next_iterator()->IsUndefined());
732 VerifyHeapPointer(table());
733 CHECK(previous_iterator()->IsJSSetIterator()
734 || previous_iterator()->IsUndefined());
738 void JSMapIterator::JSMapIteratorVerify() {
739 CHECK(IsJSMapIterator());
741 VerifyHeapPointer(table());
742 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
743 CHECK(index()->IsSmi());
744 CHECK(count()->IsSmi());
745 CHECK(kind()->IsSmi());
746 VerifyHeapPointer(next_iterator());
747 CHECK(next_iterator()->IsJSMapIterator() || next_iterator()->IsUndefined());
748 VerifyHeapPointer(table());
749 CHECK(previous_iterator()->IsJSMapIterator()
750 || previous_iterator()->IsUndefined());
754 void JSWeakMap::JSWeakMapVerify() {
755 CHECK(IsJSWeakMap());
757 VerifyHeapPointer(table());
758 CHECK(table()->IsHashTable() || table()->IsUndefined());
762 void JSWeakSet::JSWeakSetVerify() {
763 CHECK(IsJSWeakSet());
765 VerifyHeapPointer(table());
766 CHECK(table()->IsHashTable() || table()->IsUndefined());
770 void JSRegExp::JSRegExpVerify() {
772 CHECK(data()->IsUndefined() || data()->IsFixedArray());
774 case JSRegExp::ATOM: {
775 FixedArray* arr = FixedArray::cast(data());
776 CHECK(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
779 case JSRegExp::IRREGEXP: {
780 bool is_native = RegExpImpl::UsesNativeRegExp();
782 FixedArray* arr = FixedArray::cast(data());
783 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
784 // Smi : Not compiled yet (-1) or code prepared for flushing.
785 // JSObject: Compilation error.
786 // Code/ByteArray: Compiled code.
787 CHECK(ascii_data->IsSmi() ||
788 (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray()));
789 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
790 CHECK(uc16_data->IsSmi() ||
791 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
793 Object* ascii_saved = arr->get(JSRegExp::kIrregexpASCIICodeSavedIndex);
794 CHECK(ascii_saved->IsSmi() || ascii_saved->IsString() ||
795 ascii_saved->IsCode());
796 Object* uc16_saved = arr->get(JSRegExp::kIrregexpUC16CodeSavedIndex);
797 CHECK(uc16_saved->IsSmi() || uc16_saved->IsString() ||
798 uc16_saved->IsCode());
800 CHECK(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
801 CHECK(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
805 CHECK_EQ(JSRegExp::NOT_COMPILED, TypeTag());
806 CHECK(data()->IsUndefined());
812 void JSProxy::JSProxyVerify() {
814 VerifyPointer(handler());
815 CHECK(hash()->IsSmi() || hash()->IsUndefined());
819 void JSFunctionProxy::JSFunctionProxyVerify() {
820 CHECK(IsJSFunctionProxy());
822 VerifyPointer(call_trap());
823 VerifyPointer(construct_trap());
827 void JSArrayBuffer::JSArrayBufferVerify() {
828 CHECK(IsJSArrayBuffer());
830 VerifyPointer(byte_length());
831 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
832 || byte_length()->IsUndefined());
836 void JSArrayBufferView::JSArrayBufferViewVerify() {
837 CHECK(IsJSArrayBufferView());
839 VerifyPointer(buffer());
840 CHECK(buffer()->IsJSArrayBuffer() || buffer()->IsUndefined()
841 || buffer() == Smi::FromInt(0));
843 VerifyPointer(byte_offset());
844 CHECK(byte_offset()->IsSmi() || byte_offset()->IsHeapNumber()
845 || byte_offset()->IsUndefined());
847 VerifyPointer(byte_length());
848 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
849 || byte_length()->IsUndefined());
853 void JSTypedArray::JSTypedArrayVerify() {
854 CHECK(IsJSTypedArray());
855 JSArrayBufferViewVerify();
856 VerifyPointer(length());
857 CHECK(length()->IsSmi() || length()->IsHeapNumber()
858 || length()->IsUndefined());
860 VerifyPointer(elements());
864 void JSDataView::JSDataViewVerify() {
865 CHECK(IsJSDataView());
866 JSArrayBufferViewVerify();
870 void Foreign::ForeignVerify() {
875 void Box::BoxVerify() {
877 value()->ObjectVerify();
881 void AccessorInfo::AccessorInfoVerify() {
882 VerifyPointer(name());
883 VerifyPointer(flag());
884 VerifyPointer(expected_receiver_type());
888 void ExecutableAccessorInfo::ExecutableAccessorInfoVerify() {
889 CHECK(IsExecutableAccessorInfo());
890 AccessorInfoVerify();
891 VerifyPointer(getter());
892 VerifyPointer(setter());
893 VerifyPointer(data());
897 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorVerify() {
898 CHECK(IsDeclaredAccessorDescriptor());
899 VerifyPointer(serialized_data());
903 void DeclaredAccessorInfo::DeclaredAccessorInfoVerify() {
904 CHECK(IsDeclaredAccessorInfo());
905 AccessorInfoVerify();
906 VerifyPointer(descriptor());
910 void AccessorPair::AccessorPairVerify() {
911 CHECK(IsAccessorPair());
912 VerifyPointer(getter());
913 VerifyPointer(setter());
914 VerifySmiField(kAccessFlagsOffset);
918 void AccessCheckInfo::AccessCheckInfoVerify() {
919 CHECK(IsAccessCheckInfo());
920 VerifyPointer(named_callback());
921 VerifyPointer(indexed_callback());
922 VerifyPointer(data());
926 void InterceptorInfo::InterceptorInfoVerify() {
927 CHECK(IsInterceptorInfo());
928 VerifyPointer(getter());
929 VerifyPointer(setter());
930 VerifyPointer(query());
931 VerifyPointer(deleter());
932 VerifyPointer(enumerator());
933 VerifyPointer(data());
937 void CallHandlerInfo::CallHandlerInfoVerify() {
938 CHECK(IsCallHandlerInfo());
939 VerifyPointer(callback());
940 VerifyPointer(data());
944 void TemplateInfo::TemplateInfoVerify() {
945 VerifyPointer(tag());
946 VerifyPointer(property_list());
947 VerifyPointer(property_accessors());
951 void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
952 CHECK(IsFunctionTemplateInfo());
953 TemplateInfoVerify();
954 VerifyPointer(serial_number());
955 VerifyPointer(call_code());
956 VerifyPointer(prototype_template());
957 VerifyPointer(parent_template());
958 VerifyPointer(named_property_handler());
959 VerifyPointer(indexed_property_handler());
960 VerifyPointer(instance_template());
961 VerifyPointer(signature());
962 VerifyPointer(access_check_info());
966 void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
967 CHECK(IsObjectTemplateInfo());
968 TemplateInfoVerify();
969 VerifyPointer(constructor());
970 VerifyPointer(internal_field_count());
974 void SignatureInfo::SignatureInfoVerify() {
975 CHECK(IsSignatureInfo());
976 VerifyPointer(receiver());
977 VerifyPointer(args());
981 void TypeSwitchInfo::TypeSwitchInfoVerify() {
982 CHECK(IsTypeSwitchInfo());
983 VerifyPointer(types());
987 void AllocationSite::AllocationSiteVerify() {
988 CHECK(IsAllocationSite());
992 void AllocationMemento::AllocationMementoVerify() {
993 CHECK(IsAllocationMemento());
994 VerifyHeapPointer(allocation_site());
995 CHECK(!IsValid() || GetAllocationSite()->IsAllocationSite());
999 void Script::ScriptVerify() {
1001 VerifyPointer(source());
1002 VerifyPointer(name());
1003 line_offset()->SmiVerify();
1004 column_offset()->SmiVerify();
1005 VerifyPointer(wrapper());
1006 type()->SmiVerify();
1007 VerifyPointer(line_ends());
1008 VerifyPointer(id());
1012 void JSFunctionResultCache::JSFunctionResultCacheVerify() {
1013 JSFunction::cast(get(kFactoryIndex))->ObjectVerify();
1015 int size = Smi::cast(get(kCacheSizeIndex))->value();
1016 CHECK(kEntriesIndex <= size);
1017 CHECK(size <= length());
1018 CHECK_EQ(0, size % kEntrySize);
1020 int finger = Smi::cast(get(kFingerIndex))->value();
1021 CHECK(kEntriesIndex <= finger);
1022 CHECK((finger < size) || (finger == kEntriesIndex && finger == size));
1023 CHECK_EQ(0, finger % kEntrySize);
1025 if (FLAG_enable_slow_asserts) {
1026 for (int i = kEntriesIndex; i < size; i++) {
1027 CHECK(!get(i)->IsTheHole());
1028 get(i)->ObjectVerify();
1030 for (int i = size; i < length(); i++) {
1031 CHECK(get(i)->IsTheHole());
1032 get(i)->ObjectVerify();
1038 void NormalizedMapCache::NormalizedMapCacheVerify() {
1039 FixedArray::cast(this)->FixedArrayVerify();
1040 if (FLAG_enable_slow_asserts) {
1041 for (int i = 0; i < length(); i++) {
1042 Object* e = FixedArray::get(i);
1044 Map::cast(e)->SharedMapVerify();
1046 CHECK(e->IsUndefined());
1053 void DebugInfo::DebugInfoVerify() {
1054 CHECK(IsDebugInfo());
1055 VerifyPointer(shared());
1056 VerifyPointer(original_code());
1057 VerifyPointer(code());
1058 VerifyPointer(break_points());
1062 void BreakPointInfo::BreakPointInfoVerify() {
1063 CHECK(IsBreakPointInfo());
1064 code_position()->SmiVerify();
1065 source_position()->SmiVerify();
1066 statement_position()->SmiVerify();
1067 VerifyPointer(break_point_objects());
1069 #endif // VERIFY_HEAP
1073 void JSObject::IncrementSpillStatistics(SpillInformation* info) {
1074 info->number_of_objects_++;
1076 if (HasFastProperties()) {
1077 info->number_of_objects_with_fast_properties_++;
1078 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
1079 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
1081 NameDictionary* dict = property_dictionary();
1082 info->number_of_slow_used_properties_ += dict->NumberOfElements();
1083 info->number_of_slow_unused_properties_ +=
1084 dict->Capacity() - dict->NumberOfElements();
1086 // Indexed properties
1087 switch (GetElementsKind()) {
1088 case FAST_HOLEY_SMI_ELEMENTS:
1089 case FAST_SMI_ELEMENTS:
1090 case FAST_HOLEY_DOUBLE_ELEMENTS:
1091 case FAST_DOUBLE_ELEMENTS:
1092 case FAST_HOLEY_ELEMENTS:
1093 case FAST_ELEMENTS: {
1094 info->number_of_objects_with_fast_elements_++;
1096 FixedArray* e = FixedArray::cast(elements());
1097 int len = e->length();
1098 Heap* heap = GetHeap();
1099 for (int i = 0; i < len; i++) {
1100 if (e->get(i) == heap->the_hole_value()) holes++;
1102 info->number_of_fast_used_elements_ += len - holes;
1103 info->number_of_fast_unused_elements_ += holes;
1107 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1108 case EXTERNAL_##TYPE##_ELEMENTS: \
1109 case TYPE##_ELEMENTS:
1111 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1112 #undef TYPED_ARRAY_CASE
1113 { info->number_of_objects_with_fast_elements_++;
1114 FixedArrayBase* e = FixedArrayBase::cast(elements());
1115 info->number_of_fast_used_elements_ += e->length();
1118 case DICTIONARY_ELEMENTS: {
1119 SeededNumberDictionary* dict = element_dictionary();
1120 info->number_of_slow_used_elements_ += dict->NumberOfElements();
1121 info->number_of_slow_unused_elements_ +=
1122 dict->Capacity() - dict->NumberOfElements();
1125 case SLOPPY_ARGUMENTS_ELEMENTS:
1131 void JSObject::SpillInformation::Clear() {
1132 number_of_objects_ = 0;
1133 number_of_objects_with_fast_properties_ = 0;
1134 number_of_objects_with_fast_elements_ = 0;
1135 number_of_fast_used_fields_ = 0;
1136 number_of_fast_unused_fields_ = 0;
1137 number_of_slow_used_properties_ = 0;
1138 number_of_slow_unused_properties_ = 0;
1139 number_of_fast_used_elements_ = 0;
1140 number_of_fast_unused_elements_ = 0;
1141 number_of_slow_used_elements_ = 0;
1142 number_of_slow_unused_elements_ = 0;
1146 void JSObject::SpillInformation::Print() {
1147 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
1149 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
1150 number_of_objects_with_fast_properties_,
1151 number_of_fast_used_fields_, number_of_fast_unused_fields_);
1153 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
1154 number_of_objects_ - number_of_objects_with_fast_properties_,
1155 number_of_slow_used_properties_, number_of_slow_unused_properties_);
1157 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
1158 number_of_objects_with_fast_elements_,
1159 number_of_fast_used_elements_, number_of_fast_unused_elements_);
1161 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
1162 number_of_objects_ - number_of_objects_with_fast_elements_,
1163 number_of_slow_used_elements_, number_of_slow_unused_elements_);
1169 bool DescriptorArray::IsSortedNoDuplicates(int valid_entries) {
1170 if (valid_entries == -1) valid_entries = number_of_descriptors();
1171 Name* current_key = NULL;
1172 uint32_t current = 0;
1173 for (int i = 0; i < number_of_descriptors(); i++) {
1174 Name* key = GetSortedKey(i);
1175 if (key == current_key) {
1180 uint32_t hash = GetSortedKey(i)->Hash();
1181 if (hash < current) {
1191 bool TransitionArray::IsSortedNoDuplicates(int valid_entries) {
1192 ASSERT(valid_entries == -1);
1193 Name* current_key = NULL;
1194 uint32_t current = 0;
1195 for (int i = 0; i < number_of_transitions(); i++) {
1196 Name* key = GetSortedKey(i);
1197 if (key == current_key) {
1202 uint32_t hash = GetSortedKey(i)->Hash();
1203 if (hash < current) {
1213 static bool CheckOneBackPointer(Map* current_map, Object* target) {
1214 return !target->IsMap() || Map::cast(target)->GetBackPointer() == current_map;
1218 bool TransitionArray::IsConsistentWithBackPointers(Map* current_map) {
1219 for (int i = 0; i < number_of_transitions(); ++i) {
1220 if (!CheckOneBackPointer(current_map, GetTarget(i))) return false;
1228 } } // namespace v8::internal