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 "src/disasm.h"
8 #include "src/disassembler.h"
9 #include "src/heap/objects-visiting.h"
10 #include "src/jsregexp.h"
11 #include "src/macro-assembler.h"
12 #include "src/ostreams.h"
19 void Object::ObjectVerify() {
21 Smi::cast(this)->SmiVerify();
23 HeapObject::cast(this)->HeapObjectVerify();
28 void Object::VerifyPointer(Object* p) {
29 if (p->IsHeapObject()) {
30 HeapObject::VerifyHeapPointer(p);
37 void Smi::SmiVerify() {
42 void HeapObject::HeapObjectVerify() {
43 InstanceType instance_type = map()->instance_type();
45 if (instance_type < FIRST_NONSTRING_TYPE) {
46 String::cast(this)->StringVerify();
50 switch (instance_type) {
52 Symbol::cast(this)->SymbolVerify();
55 Map::cast(this)->MapVerify();
57 case HEAP_NUMBER_TYPE:
58 case MUTABLE_HEAP_NUMBER_TYPE:
59 HeapNumber::cast(this)->HeapNumberVerify();
61 case FIXED_ARRAY_TYPE:
62 FixedArray::cast(this)->FixedArrayVerify();
64 case FIXED_DOUBLE_ARRAY_TYPE:
65 FixedDoubleArray::cast(this)->FixedDoubleArrayVerify();
67 case CONSTANT_POOL_ARRAY_TYPE:
68 ConstantPoolArray::cast(this)->ConstantPoolArrayVerify();
71 ByteArray::cast(this)->ByteArrayVerify();
74 FreeSpace::cast(this)->FreeSpaceVerify();
77 #define VERIFY_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
78 case EXTERNAL_##TYPE##_ARRAY_TYPE: \
79 External##Type##Array::cast(this)->External##Type##ArrayVerify(); \
81 case FIXED_##TYPE##_ARRAY_TYPE: \
82 Fixed##Type##Array::cast(this)->FixedTypedArrayVerify(); \
85 TYPED_ARRAYS(VERIFY_TYPED_ARRAY)
86 #undef VERIFY_TYPED_ARRAY
89 Code::cast(this)->CodeVerify();
92 Oddball::cast(this)->OddballVerify();
95 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
96 JSObject::cast(this)->JSObjectVerify();
98 case JS_GENERATOR_OBJECT_TYPE:
99 JSGeneratorObject::cast(this)->JSGeneratorObjectVerify();
102 JSModule::cast(this)->JSModuleVerify();
105 JSValue::cast(this)->JSValueVerify();
108 JSDate::cast(this)->JSDateVerify();
110 case JS_FUNCTION_TYPE:
111 JSFunction::cast(this)->JSFunctionVerify();
113 case JS_GLOBAL_PROXY_TYPE:
114 JSGlobalProxy::cast(this)->JSGlobalProxyVerify();
116 case JS_GLOBAL_OBJECT_TYPE:
117 JSGlobalObject::cast(this)->JSGlobalObjectVerify();
119 case JS_BUILTINS_OBJECT_TYPE:
120 JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify();
123 Cell::cast(this)->CellVerify();
125 case PROPERTY_CELL_TYPE:
126 PropertyCell::cast(this)->PropertyCellVerify();
129 JSArray::cast(this)->JSArrayVerify();
132 JSSet::cast(this)->JSSetVerify();
135 JSMap::cast(this)->JSMapVerify();
137 case JS_SET_ITERATOR_TYPE:
138 JSSetIterator::cast(this)->JSSetIteratorVerify();
140 case JS_MAP_ITERATOR_TYPE:
141 JSMapIterator::cast(this)->JSMapIteratorVerify();
143 case JS_WEAK_MAP_TYPE:
144 JSWeakMap::cast(this)->JSWeakMapVerify();
146 case JS_WEAK_SET_TYPE:
147 JSWeakSet::cast(this)->JSWeakSetVerify();
150 JSRegExp::cast(this)->JSRegExpVerify();
155 JSProxy::cast(this)->JSProxyVerify();
157 case JS_FUNCTION_PROXY_TYPE:
158 JSFunctionProxy::cast(this)->JSFunctionProxyVerify();
161 Foreign::cast(this)->ForeignVerify();
163 case SHARED_FUNCTION_INFO_TYPE:
164 SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify();
166 case JS_MESSAGE_OBJECT_TYPE:
167 JSMessageObject::cast(this)->JSMessageObjectVerify();
169 case JS_ARRAY_BUFFER_TYPE:
170 JSArrayBuffer::cast(this)->JSArrayBufferVerify();
172 case JS_TYPED_ARRAY_TYPE:
173 JSTypedArray::cast(this)->JSTypedArrayVerify();
175 case JS_DATA_VIEW_TYPE:
176 JSDataView::cast(this)->JSDataViewVerify();
179 #define MAKE_STRUCT_CASE(NAME, Name, name) \
181 Name::cast(this)->Name##Verify(); \
183 STRUCT_LIST(MAKE_STRUCT_CASE)
184 #undef MAKE_STRUCT_CASE
193 void HeapObject::VerifyHeapPointer(Object* p) {
194 CHECK(p->IsHeapObject());
195 HeapObject* ho = HeapObject::cast(p);
196 CHECK(ho->GetHeap()->Contains(ho));
200 void Symbol::SymbolVerify() {
202 CHECK(HasHashCode());
204 CHECK(name()->IsUndefined() || name()->IsString());
205 CHECK(flags()->IsSmi());
209 void HeapNumber::HeapNumberVerify() {
210 CHECK(IsHeapNumber() || IsMutableHeapNumber());
214 void ByteArray::ByteArrayVerify() {
215 CHECK(IsByteArray());
219 void FreeSpace::FreeSpaceVerify() {
220 CHECK(IsFreeSpace());
224 #define EXTERNAL_ARRAY_VERIFY(Type, type, TYPE, ctype, size) \
225 void External##Type##Array::External##Type##ArrayVerify() { \
226 CHECK(IsExternal##Type##Array()); \
229 TYPED_ARRAYS(EXTERNAL_ARRAY_VERIFY)
230 #undef EXTERNAL_ARRAY_VERIFY
233 template <class Traits>
234 void FixedTypedArray<Traits>::FixedTypedArrayVerify() {
235 CHECK(IsHeapObject() &&
236 HeapObject::cast(this)->map()->instance_type() ==
237 Traits::kInstanceType);
241 bool JSObject::ElementsAreSafeToExamine() {
242 // If a GC was caused while constructing this object, the elements
243 // pointer may point to a one pointer filler map.
244 return reinterpret_cast<Map*>(elements()) !=
245 GetHeap()->one_pointer_filler_map();
249 void JSObject::JSObjectVerify() {
250 VerifyHeapPointer(properties());
251 VerifyHeapPointer(elements());
253 if (GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS) {
254 CHECK(this->elements()->IsFixedArray());
255 CHECK_GE(this->elements()->length(), 2);
258 if (HasFastProperties()) {
259 CHECK_EQ(map()->unused_property_fields(),
260 (map()->inobject_properties() + properties()->length() -
261 map()->NextFreePropertyIndex()));
262 DescriptorArray* descriptors = map()->instance_descriptors();
263 for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
264 if (descriptors->GetDetails(i).type() == FIELD) {
265 Representation r = descriptors->GetDetails(i).representation();
266 FieldIndex index = FieldIndex::ForDescriptor(map(), i);
267 Object* value = RawFastPropertyAt(index);
268 if (r.IsDouble()) DCHECK(value->IsMutableHeapNumber());
269 if (value->IsUninitialized()) continue;
270 if (r.IsSmi()) DCHECK(value->IsSmi());
271 if (r.IsHeapObject()) DCHECK(value->IsHeapObject());
272 HeapType* field_type = descriptors->GetFieldType(i);
274 CHECK(field_type->Is(HeapType::None()));
275 } else if (!HeapType::Any()->Is(field_type)) {
276 CHECK(!field_type->NowStable() || field_type->NowContains(value));
282 // If a GC was caused while constructing this object, the elements
283 // pointer may point to a one pointer filler map.
284 if (ElementsAreSafeToExamine()) {
285 CHECK_EQ((map()->has_fast_smi_or_object_elements() ||
286 (elements() == GetHeap()->empty_fixed_array())),
287 (elements()->map() == GetHeap()->fixed_array_map() ||
288 elements()->map() == GetHeap()->fixed_cow_array_map()));
289 CHECK(map()->has_fast_object_elements() == HasFastObjectElements());
294 void Map::MapVerify() {
295 Heap* heap = GetHeap();
296 CHECK(!heap->InNewSpace(this));
297 CHECK(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
298 CHECK(instance_size() == kVariableSizeSentinel ||
299 (kPointerSize <= instance_size() &&
300 instance_size() < heap->Capacity()));
301 VerifyHeapPointer(prototype());
302 VerifyHeapPointer(instance_descriptors());
303 SLOW_DCHECK(instance_descriptors()->IsSortedNoDuplicates());
304 if (HasTransitionArray()) {
305 SLOW_DCHECK(transitions()->IsSortedNoDuplicates());
306 SLOW_DCHECK(transitions()->IsConsistentWithBackPointers(this));
311 void Map::DictionaryMapVerify() {
313 CHECK(is_dictionary_map());
314 CHECK(instance_descriptors()->IsEmpty());
315 CHECK_EQ(0, pre_allocated_property_fields());
316 CHECK_EQ(0, unused_property_fields());
317 CHECK_EQ(StaticVisitorBase::GetVisitorId(instance_type(), instance_size()),
322 void Map::VerifyOmittedMapChecks() {
323 if (!FLAG_omit_map_checks_for_leaf_maps) return;
326 HasTransitionArray() ||
327 is_dictionary_map()) {
328 CHECK_EQ(0, dependent_code()->number_of_entries(
329 DependentCode::kPrototypeCheckGroup));
334 void CodeCache::CodeCacheVerify() {
335 VerifyHeapPointer(default_cache());
336 VerifyHeapPointer(normal_type_cache());
337 CHECK(default_cache()->IsFixedArray());
338 CHECK(normal_type_cache()->IsUndefined()
339 || normal_type_cache()->IsCodeCacheHashTable());
343 void PolymorphicCodeCache::PolymorphicCodeCacheVerify() {
344 VerifyHeapPointer(cache());
345 CHECK(cache()->IsUndefined() || cache()->IsPolymorphicCodeCacheHashTable());
349 void TypeFeedbackInfo::TypeFeedbackInfoVerify() {
350 VerifyObjectField(kStorage1Offset);
351 VerifyObjectField(kStorage2Offset);
352 VerifyObjectField(kStorage3Offset);
356 void AliasedArgumentsEntry::AliasedArgumentsEntryVerify() {
357 VerifySmiField(kAliasedContextSlot);
361 void FixedArray::FixedArrayVerify() {
362 for (int i = 0; i < length(); i++) {
369 void FixedDoubleArray::FixedDoubleArrayVerify() {
370 for (int i = 0; i < length(); i++) {
371 if (!is_the_hole(i)) {
372 double value = get_scalar(i);
373 CHECK(!std::isnan(value) ||
374 (BitCast<uint64_t>(value) ==
375 BitCast<uint64_t>(canonical_not_the_hole_nan_as_double())) ||
376 ((BitCast<uint64_t>(value) & Double::kSignMask) != 0));
382 void ConstantPoolArray::ConstantPoolArrayVerify() {
383 CHECK(IsConstantPoolArray());
384 ConstantPoolArray::Iterator code_iter(this, ConstantPoolArray::CODE_PTR);
385 while (!code_iter.is_finished()) {
386 Address code_entry = get_code_ptr_entry(code_iter.next_index());
387 VerifyPointer(Code::GetCodeFromTargetAddress(code_entry));
389 ConstantPoolArray::Iterator heap_iter(this, ConstantPoolArray::HEAP_PTR);
390 while (!heap_iter.is_finished()) {
391 VerifyObjectField(OffsetOfElementAt(heap_iter.next_index()));
396 void JSGeneratorObject::JSGeneratorObjectVerify() {
397 // In an expression like "new g()", there can be a point where a generator
398 // object is allocated but its fields are all undefined, as it hasn't yet been
399 // initialized by the generator. Hence these weak checks.
400 VerifyObjectField(kFunctionOffset);
401 VerifyObjectField(kContextOffset);
402 VerifyObjectField(kReceiverOffset);
403 VerifyObjectField(kOperandStackOffset);
404 VerifyObjectField(kContinuationOffset);
405 VerifyObjectField(kStackHandlerIndexOffset);
409 void JSModule::JSModuleVerify() {
410 VerifyObjectField(kContextOffset);
411 VerifyObjectField(kScopeInfoOffset);
412 CHECK(context()->IsUndefined() ||
413 Context::cast(context())->IsModuleContext());
417 void JSValue::JSValueVerify() {
419 if (v->IsHeapObject()) {
420 VerifyHeapPointer(v);
425 void JSDate::JSDateVerify() {
426 if (value()->IsHeapObject()) {
427 VerifyHeapPointer(value());
429 CHECK(value()->IsUndefined() || value()->IsSmi() || value()->IsHeapNumber());
430 CHECK(year()->IsUndefined() || year()->IsSmi() || year()->IsNaN());
431 CHECK(month()->IsUndefined() || month()->IsSmi() || month()->IsNaN());
432 CHECK(day()->IsUndefined() || day()->IsSmi() || day()->IsNaN());
433 CHECK(weekday()->IsUndefined() || weekday()->IsSmi() || weekday()->IsNaN());
434 CHECK(hour()->IsUndefined() || hour()->IsSmi() || hour()->IsNaN());
435 CHECK(min()->IsUndefined() || min()->IsSmi() || min()->IsNaN());
436 CHECK(sec()->IsUndefined() || sec()->IsSmi() || sec()->IsNaN());
437 CHECK(cache_stamp()->IsUndefined() ||
438 cache_stamp()->IsSmi() ||
439 cache_stamp()->IsNaN());
441 if (month()->IsSmi()) {
442 int month = Smi::cast(this->month())->value();
443 CHECK(0 <= month && month <= 11);
445 if (day()->IsSmi()) {
446 int day = Smi::cast(this->day())->value();
447 CHECK(1 <= day && day <= 31);
449 if (hour()->IsSmi()) {
450 int hour = Smi::cast(this->hour())->value();
451 CHECK(0 <= hour && hour <= 23);
453 if (min()->IsSmi()) {
454 int min = Smi::cast(this->min())->value();
455 CHECK(0 <= min && min <= 59);
457 if (sec()->IsSmi()) {
458 int sec = Smi::cast(this->sec())->value();
459 CHECK(0 <= sec && sec <= 59);
461 if (weekday()->IsSmi()) {
462 int weekday = Smi::cast(this->weekday())->value();
463 CHECK(0 <= weekday && weekday <= 6);
465 if (cache_stamp()->IsSmi()) {
466 CHECK(Smi::cast(cache_stamp())->value() <=
467 Smi::cast(GetIsolate()->date_cache()->stamp())->value());
472 void JSMessageObject::JSMessageObjectVerify() {
473 CHECK(IsJSMessageObject());
474 CHECK(type()->IsString());
475 CHECK(arguments()->IsJSArray());
476 VerifyObjectField(kStartPositionOffset);
477 VerifyObjectField(kEndPositionOffset);
478 VerifyObjectField(kArgumentsOffset);
479 VerifyObjectField(kScriptOffset);
480 VerifyObjectField(kStackFramesOffset);
484 void String::StringVerify() {
486 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
487 if (IsInternalizedString()) {
488 CHECK(!GetHeap()->InNewSpace(this));
490 if (IsConsString()) {
491 ConsString::cast(this)->ConsStringVerify();
492 } else if (IsSlicedString()) {
493 SlicedString::cast(this)->SlicedStringVerify();
498 void ConsString::ConsStringVerify() {
499 CHECK(this->first()->IsString());
500 CHECK(this->second() == GetHeap()->empty_string() ||
501 this->second()->IsString());
502 CHECK(this->length() >= ConsString::kMinLength);
503 CHECK(this->length() == this->first()->length() + this->second()->length());
504 if (this->IsFlat()) {
505 // A flat cons can only be created by String::SlowTryFlatten.
506 // Afterwards, the first part may be externalized.
507 CHECK(this->first()->IsSeqString() || this->first()->IsExternalString());
512 void SlicedString::SlicedStringVerify() {
513 CHECK(!this->parent()->IsConsString());
514 CHECK(!this->parent()->IsSlicedString());
515 CHECK(this->length() >= SlicedString::kMinLength);
519 void JSFunction::JSFunctionVerify() {
520 CHECK(IsJSFunction());
521 VerifyObjectField(kPrototypeOrInitialMapOffset);
522 VerifyObjectField(kNextFunctionLinkOffset);
523 CHECK(code()->IsCode());
524 CHECK(next_function_link() == NULL ||
525 next_function_link()->IsUndefined() ||
526 next_function_link()->IsJSFunction());
530 void SharedFunctionInfo::SharedFunctionInfoVerify() {
531 CHECK(IsSharedFunctionInfo());
532 VerifyObjectField(kNameOffset);
533 VerifyObjectField(kCodeOffset);
534 VerifyObjectField(kOptimizedCodeMapOffset);
535 VerifyObjectField(kFeedbackVectorOffset);
536 VerifyObjectField(kScopeInfoOffset);
537 VerifyObjectField(kInstanceClassNameOffset);
538 VerifyObjectField(kFunctionDataOffset);
539 VerifyObjectField(kScriptOffset);
540 VerifyObjectField(kDebugInfoOffset);
544 void JSGlobalProxy::JSGlobalProxyVerify() {
545 CHECK(IsJSGlobalProxy());
547 VerifyObjectField(JSGlobalProxy::kNativeContextOffset);
548 // Make sure that this object has no properties, elements.
549 CHECK_EQ(0, properties()->length());
550 CHECK(HasFastSmiElements());
551 CHECK_EQ(0, FixedArray::cast(elements())->length());
555 void JSGlobalObject::JSGlobalObjectVerify() {
556 CHECK(IsJSGlobalObject());
558 for (int i = GlobalObject::kBuiltinsOffset;
559 i < JSGlobalObject::kSize;
561 VerifyObjectField(i);
566 void JSBuiltinsObject::JSBuiltinsObjectVerify() {
567 CHECK(IsJSBuiltinsObject());
569 for (int i = GlobalObject::kBuiltinsOffset;
570 i < JSBuiltinsObject::kSize;
572 VerifyObjectField(i);
577 void Oddball::OddballVerify() {
579 Heap* heap = GetHeap();
580 VerifyHeapPointer(to_string());
581 Object* number = to_number();
582 if (number->IsHeapObject()) {
583 CHECK(number == heap->nan_value());
585 CHECK(number->IsSmi());
586 int value = Smi::cast(number)->value();
587 // Hidden oddballs have negative smis.
588 const int kLeastHiddenOddballNumber = -5;
590 CHECK(value >= kLeastHiddenOddballNumber);
592 if (map() == heap->undefined_map()) {
593 CHECK(this == heap->undefined_value());
594 } else if (map() == heap->the_hole_map()) {
595 CHECK(this == heap->the_hole_value());
596 } else if (map() == heap->null_map()) {
597 CHECK(this == heap->null_value());
598 } else if (map() == heap->boolean_map()) {
599 CHECK(this == heap->true_value() ||
600 this == heap->false_value());
601 } else if (map() == heap->uninitialized_map()) {
602 CHECK(this == heap->uninitialized_value());
603 } else if (map() == heap->no_interceptor_result_sentinel_map()) {
604 CHECK(this == heap->no_interceptor_result_sentinel());
605 } else if (map() == heap->arguments_marker_map()) {
606 CHECK(this == heap->arguments_marker());
607 } else if (map() == heap->termination_exception_map()) {
608 CHECK(this == heap->termination_exception());
609 } else if (map() == heap->exception_map()) {
610 CHECK(this == heap->exception());
617 void Cell::CellVerify() {
619 VerifyObjectField(kValueOffset);
623 void PropertyCell::PropertyCellVerify() {
624 CHECK(IsPropertyCell());
625 VerifyObjectField(kValueOffset);
626 VerifyObjectField(kTypeOffset);
630 void Code::CodeVerify() {
631 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
633 relocation_info()->ObjectVerify();
634 Address last_gc_pc = NULL;
635 Isolate* isolate = GetIsolate();
636 for (RelocIterator it(this); !it.done(); it.next()) {
637 it.rinfo()->Verify(isolate);
638 // Ensure that GC will not iterate twice over the same pointer.
639 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
640 CHECK(it.rinfo()->pc() != last_gc_pc);
641 last_gc_pc = it.rinfo()->pc();
644 CHECK(raw_type_feedback_info() == Smi::FromInt(0) ||
645 raw_type_feedback_info()->IsSmi() == IsCodeStubOrIC());
649 void Code::VerifyEmbeddedObjectsDependency() {
650 if (!CanContainWeakObjects()) return;
651 DisallowHeapAllocation no_gc;
652 Isolate* isolate = GetIsolate();
653 HandleScope scope(isolate);
654 int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
655 for (RelocIterator it(this, mode_mask); !it.done(); it.next()) {
656 Object* obj = it.rinfo()->target_object();
657 if (IsWeakObject(obj)) {
659 Map* map = Map::cast(obj);
660 DependentCode::DependencyGroup group = is_optimized_code() ?
661 DependentCode::kWeakCodeGroup : DependentCode::kWeakICGroup;
662 CHECK(map->dependent_code()->Contains(group, this));
663 } else if (obj->IsJSObject()) {
664 Object* raw_table = GetIsolate()->heap()->weak_object_to_code_table();
665 WeakHashTable* table = WeakHashTable::cast(raw_table);
666 Handle<Object> key_obj(obj, isolate);
667 CHECK(DependentCode::cast(table->Lookup(key_obj))->Contains(
668 DependentCode::kWeakCodeGroup, this));
675 void JSArray::JSArrayVerify() {
677 CHECK(length()->IsNumber() || length()->IsUndefined());
678 // If a GC was caused while constructing this array, the elements
679 // pointer may point to a one pointer filler map.
680 if (ElementsAreSafeToExamine()) {
681 CHECK(elements()->IsUndefined() ||
682 elements()->IsFixedArray() ||
683 elements()->IsFixedDoubleArray());
688 void JSSet::JSSetVerify() {
691 VerifyHeapPointer(table());
692 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
693 // TODO(arv): Verify OrderedHashTable too.
697 void JSMap::JSMapVerify() {
700 VerifyHeapPointer(table());
701 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
702 // TODO(arv): Verify OrderedHashTable too.
706 void JSSetIterator::JSSetIteratorVerify() {
707 CHECK(IsJSSetIterator());
709 VerifyHeapPointer(table());
710 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
711 CHECK(index()->IsSmi() || index()->IsUndefined());
712 CHECK(kind()->IsSmi() || kind()->IsUndefined());
716 void JSMapIterator::JSMapIteratorVerify() {
717 CHECK(IsJSMapIterator());
719 VerifyHeapPointer(table());
720 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
721 CHECK(index()->IsSmi() || index()->IsUndefined());
722 CHECK(kind()->IsSmi() || kind()->IsUndefined());
726 void JSWeakMap::JSWeakMapVerify() {
727 CHECK(IsJSWeakMap());
729 VerifyHeapPointer(table());
730 CHECK(table()->IsHashTable() || table()->IsUndefined());
734 void JSWeakSet::JSWeakSetVerify() {
735 CHECK(IsJSWeakSet());
737 VerifyHeapPointer(table());
738 CHECK(table()->IsHashTable() || table()->IsUndefined());
742 void JSRegExp::JSRegExpVerify() {
744 CHECK(data()->IsUndefined() || data()->IsFixedArray());
746 case JSRegExp::ATOM: {
747 FixedArray* arr = FixedArray::cast(data());
748 CHECK(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
751 case JSRegExp::IRREGEXP: {
752 bool is_native = RegExpImpl::UsesNativeRegExp();
754 FixedArray* arr = FixedArray::cast(data());
755 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
756 // Smi : Not compiled yet (-1) or code prepared for flushing.
757 // JSObject: Compilation error.
758 // Code/ByteArray: Compiled code.
759 CHECK(ascii_data->IsSmi() ||
760 (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray()));
761 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
762 CHECK(uc16_data->IsSmi() ||
763 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
765 Object* ascii_saved = arr->get(JSRegExp::kIrregexpASCIICodeSavedIndex);
766 CHECK(ascii_saved->IsSmi() || ascii_saved->IsString() ||
767 ascii_saved->IsCode());
768 Object* uc16_saved = arr->get(JSRegExp::kIrregexpUC16CodeSavedIndex);
769 CHECK(uc16_saved->IsSmi() || uc16_saved->IsString() ||
770 uc16_saved->IsCode());
772 CHECK(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
773 CHECK(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
777 CHECK_EQ(JSRegExp::NOT_COMPILED, TypeTag());
778 CHECK(data()->IsUndefined());
784 void JSProxy::JSProxyVerify() {
786 VerifyPointer(handler());
787 CHECK(hash()->IsSmi() || hash()->IsUndefined());
791 void JSFunctionProxy::JSFunctionProxyVerify() {
792 CHECK(IsJSFunctionProxy());
794 VerifyPointer(call_trap());
795 VerifyPointer(construct_trap());
799 void JSArrayBuffer::JSArrayBufferVerify() {
800 CHECK(IsJSArrayBuffer());
802 VerifyPointer(byte_length());
803 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
804 || byte_length()->IsUndefined());
808 void JSArrayBufferView::JSArrayBufferViewVerify() {
809 CHECK(IsJSArrayBufferView());
811 VerifyPointer(buffer());
812 CHECK(buffer()->IsJSArrayBuffer() || buffer()->IsUndefined()
813 || buffer() == Smi::FromInt(0));
815 VerifyPointer(byte_offset());
816 CHECK(byte_offset()->IsSmi() || byte_offset()->IsHeapNumber()
817 || byte_offset()->IsUndefined());
819 VerifyPointer(byte_length());
820 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
821 || byte_length()->IsUndefined());
825 void JSTypedArray::JSTypedArrayVerify() {
826 CHECK(IsJSTypedArray());
827 JSArrayBufferViewVerify();
828 VerifyPointer(length());
829 CHECK(length()->IsSmi() || length()->IsHeapNumber()
830 || length()->IsUndefined());
832 VerifyPointer(elements());
836 void JSDataView::JSDataViewVerify() {
837 CHECK(IsJSDataView());
838 JSArrayBufferViewVerify();
842 void Foreign::ForeignVerify() {
847 void Box::BoxVerify() {
849 value()->ObjectVerify();
853 void AccessorInfo::AccessorInfoVerify() {
854 VerifyPointer(name());
855 VerifyPointer(flag());
856 VerifyPointer(expected_receiver_type());
860 void ExecutableAccessorInfo::ExecutableAccessorInfoVerify() {
861 CHECK(IsExecutableAccessorInfo());
862 AccessorInfoVerify();
863 VerifyPointer(getter());
864 VerifyPointer(setter());
865 VerifyPointer(data());
869 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorVerify() {
870 CHECK(IsDeclaredAccessorDescriptor());
871 VerifyPointer(serialized_data());
875 void DeclaredAccessorInfo::DeclaredAccessorInfoVerify() {
876 CHECK(IsDeclaredAccessorInfo());
877 AccessorInfoVerify();
878 VerifyPointer(descriptor());
882 void AccessorPair::AccessorPairVerify() {
883 CHECK(IsAccessorPair());
884 VerifyPointer(getter());
885 VerifyPointer(setter());
889 void AccessCheckInfo::AccessCheckInfoVerify() {
890 CHECK(IsAccessCheckInfo());
891 VerifyPointer(named_callback());
892 VerifyPointer(indexed_callback());
893 VerifyPointer(data());
897 void InterceptorInfo::InterceptorInfoVerify() {
898 CHECK(IsInterceptorInfo());
899 VerifyPointer(getter());
900 VerifyPointer(setter());
901 VerifyPointer(query());
902 VerifyPointer(deleter());
903 VerifyPointer(enumerator());
904 VerifyPointer(data());
908 void CallHandlerInfo::CallHandlerInfoVerify() {
909 CHECK(IsCallHandlerInfo());
910 VerifyPointer(callback());
911 VerifyPointer(data());
915 void TemplateInfo::TemplateInfoVerify() {
916 VerifyPointer(tag());
917 VerifyPointer(property_list());
918 VerifyPointer(property_accessors());
922 void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
923 CHECK(IsFunctionTemplateInfo());
924 TemplateInfoVerify();
925 VerifyPointer(serial_number());
926 VerifyPointer(call_code());
927 VerifyPointer(prototype_template());
928 VerifyPointer(parent_template());
929 VerifyPointer(named_property_handler());
930 VerifyPointer(indexed_property_handler());
931 VerifyPointer(instance_template());
932 VerifyPointer(signature());
933 VerifyPointer(access_check_info());
937 void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
938 CHECK(IsObjectTemplateInfo());
939 TemplateInfoVerify();
940 VerifyPointer(constructor());
941 VerifyPointer(internal_field_count());
945 void SignatureInfo::SignatureInfoVerify() {
946 CHECK(IsSignatureInfo());
947 VerifyPointer(receiver());
948 VerifyPointer(args());
952 void TypeSwitchInfo::TypeSwitchInfoVerify() {
953 CHECK(IsTypeSwitchInfo());
954 VerifyPointer(types());
958 void AllocationSite::AllocationSiteVerify() {
959 CHECK(IsAllocationSite());
963 void AllocationMemento::AllocationMementoVerify() {
964 CHECK(IsAllocationMemento());
965 VerifyHeapPointer(allocation_site());
966 CHECK(!IsValid() || GetAllocationSite()->IsAllocationSite());
970 void Script::ScriptVerify() {
972 VerifyPointer(source());
973 VerifyPointer(name());
974 line_offset()->SmiVerify();
975 column_offset()->SmiVerify();
976 VerifyPointer(wrapper());
978 VerifyPointer(line_ends());
983 void JSFunctionResultCache::JSFunctionResultCacheVerify() {
984 JSFunction::cast(get(kFactoryIndex))->ObjectVerify();
986 int size = Smi::cast(get(kCacheSizeIndex))->value();
987 CHECK(kEntriesIndex <= size);
988 CHECK(size <= length());
989 CHECK_EQ(0, size % kEntrySize);
991 int finger = Smi::cast(get(kFingerIndex))->value();
992 CHECK(kEntriesIndex <= finger);
993 CHECK((finger < size) || (finger == kEntriesIndex && finger == size));
994 CHECK_EQ(0, finger % kEntrySize);
996 if (FLAG_enable_slow_asserts) {
997 for (int i = kEntriesIndex; i < size; i++) {
998 CHECK(!get(i)->IsTheHole());
999 get(i)->ObjectVerify();
1001 for (int i = size; i < length(); i++) {
1002 CHECK(get(i)->IsTheHole());
1003 get(i)->ObjectVerify();
1009 void NormalizedMapCache::NormalizedMapCacheVerify() {
1010 FixedArray::cast(this)->FixedArrayVerify();
1011 if (FLAG_enable_slow_asserts) {
1012 for (int i = 0; i < length(); i++) {
1013 Object* e = FixedArray::get(i);
1015 Map::cast(e)->DictionaryMapVerify();
1017 CHECK(e->IsUndefined());
1024 void DebugInfo::DebugInfoVerify() {
1025 CHECK(IsDebugInfo());
1026 VerifyPointer(shared());
1027 VerifyPointer(original_code());
1028 VerifyPointer(code());
1029 VerifyPointer(break_points());
1033 void BreakPointInfo::BreakPointInfoVerify() {
1034 CHECK(IsBreakPointInfo());
1035 code_position()->SmiVerify();
1036 source_position()->SmiVerify();
1037 statement_position()->SmiVerify();
1038 VerifyPointer(break_point_objects());
1040 #endif // VERIFY_HEAP
1044 void JSObject::IncrementSpillStatistics(SpillInformation* info) {
1045 info->number_of_objects_++;
1047 if (HasFastProperties()) {
1048 info->number_of_objects_with_fast_properties_++;
1049 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
1050 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
1052 NameDictionary* dict = property_dictionary();
1053 info->number_of_slow_used_properties_ += dict->NumberOfElements();
1054 info->number_of_slow_unused_properties_ +=
1055 dict->Capacity() - dict->NumberOfElements();
1057 // Indexed properties
1058 switch (GetElementsKind()) {
1059 case FAST_HOLEY_SMI_ELEMENTS:
1060 case FAST_SMI_ELEMENTS:
1061 case FAST_HOLEY_DOUBLE_ELEMENTS:
1062 case FAST_DOUBLE_ELEMENTS:
1063 case FAST_HOLEY_ELEMENTS:
1064 case FAST_ELEMENTS: {
1065 info->number_of_objects_with_fast_elements_++;
1067 FixedArray* e = FixedArray::cast(elements());
1068 int len = e->length();
1069 Heap* heap = GetHeap();
1070 for (int i = 0; i < len; i++) {
1071 if (e->get(i) == heap->the_hole_value()) holes++;
1073 info->number_of_fast_used_elements_ += len - holes;
1074 info->number_of_fast_unused_elements_ += holes;
1078 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1079 case EXTERNAL_##TYPE##_ELEMENTS: \
1080 case TYPE##_ELEMENTS:
1082 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1083 #undef TYPED_ARRAY_CASE
1084 { info->number_of_objects_with_fast_elements_++;
1085 FixedArrayBase* e = FixedArrayBase::cast(elements());
1086 info->number_of_fast_used_elements_ += e->length();
1089 case DICTIONARY_ELEMENTS: {
1090 SeededNumberDictionary* dict = element_dictionary();
1091 info->number_of_slow_used_elements_ += dict->NumberOfElements();
1092 info->number_of_slow_unused_elements_ +=
1093 dict->Capacity() - dict->NumberOfElements();
1096 case SLOPPY_ARGUMENTS_ELEMENTS:
1102 void JSObject::SpillInformation::Clear() {
1103 number_of_objects_ = 0;
1104 number_of_objects_with_fast_properties_ = 0;
1105 number_of_objects_with_fast_elements_ = 0;
1106 number_of_fast_used_fields_ = 0;
1107 number_of_fast_unused_fields_ = 0;
1108 number_of_slow_used_properties_ = 0;
1109 number_of_slow_unused_properties_ = 0;
1110 number_of_fast_used_elements_ = 0;
1111 number_of_fast_unused_elements_ = 0;
1112 number_of_slow_used_elements_ = 0;
1113 number_of_slow_unused_elements_ = 0;
1117 void JSObject::SpillInformation::Print() {
1118 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
1120 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
1121 number_of_objects_with_fast_properties_,
1122 number_of_fast_used_fields_, number_of_fast_unused_fields_);
1124 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
1125 number_of_objects_ - number_of_objects_with_fast_properties_,
1126 number_of_slow_used_properties_, number_of_slow_unused_properties_);
1128 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
1129 number_of_objects_with_fast_elements_,
1130 number_of_fast_used_elements_, number_of_fast_unused_elements_);
1132 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
1133 number_of_objects_ - number_of_objects_with_fast_elements_,
1134 number_of_slow_used_elements_, number_of_slow_unused_elements_);
1140 bool DescriptorArray::IsSortedNoDuplicates(int valid_entries) {
1141 if (valid_entries == -1) valid_entries = number_of_descriptors();
1142 Name* current_key = NULL;
1143 uint32_t current = 0;
1144 for (int i = 0; i < number_of_descriptors(); i++) {
1145 Name* key = GetSortedKey(i);
1146 if (key == current_key) {
1147 OFStream os(stdout);
1148 PrintDescriptors(os);
1152 uint32_t hash = GetSortedKey(i)->Hash();
1153 if (hash < current) {
1154 OFStream os(stdout);
1155 PrintDescriptors(os);
1164 bool TransitionArray::IsSortedNoDuplicates(int valid_entries) {
1165 DCHECK(valid_entries == -1);
1166 Name* current_key = NULL;
1167 uint32_t current = 0;
1168 for (int i = 0; i < number_of_transitions(); i++) {
1169 Name* key = GetSortedKey(i);
1170 if (key == current_key) {
1171 OFStream os(stdout);
1172 PrintTransitions(os);
1176 uint32_t hash = GetSortedKey(i)->Hash();
1177 if (hash < current) {
1178 OFStream os(stdout);
1179 PrintTransitions(os);
1188 static bool CheckOneBackPointer(Map* current_map, Object* target) {
1189 return !target->IsMap() || Map::cast(target)->GetBackPointer() == current_map;
1193 bool TransitionArray::IsConsistentWithBackPointers(Map* current_map) {
1194 for (int i = 0; i < number_of_transitions(); ++i) {
1195 if (!CheckOneBackPointer(current_map, GetTarget(i))) return false;
1203 } } // namespace v8::internal