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/disassembler.h"
8 #include "src/disasm.h"
9 #include "src/jsregexp.h"
10 #include "src/macro-assembler.h"
11 #include "src/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 FieldIndex index = FieldIndex::ForDescriptor(map(), i);
289 Object* value = RawFastPropertyAt(index);
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 ConstantPoolArray::Iterator code_iter(this, ConstantPoolArray::CODE_PTR);
406 while (!code_iter.is_finished()) {
407 Address code_entry = get_code_ptr_entry(code_iter.next_index());
408 VerifyPointer(Code::GetCodeFromTargetAddress(code_entry));
410 ConstantPoolArray::Iterator heap_iter(this, ConstantPoolArray::HEAP_PTR);
411 while (!heap_iter.is_finished()) {
412 VerifyObjectField(OffsetOfElementAt(heap_iter.next_index()));
417 void JSGeneratorObject::JSGeneratorObjectVerify() {
418 // In an expression like "new g()", there can be a point where a generator
419 // object is allocated but its fields are all undefined, as it hasn't yet been
420 // initialized by the generator. Hence these weak checks.
421 VerifyObjectField(kFunctionOffset);
422 VerifyObjectField(kContextOffset);
423 VerifyObjectField(kReceiverOffset);
424 VerifyObjectField(kOperandStackOffset);
425 VerifyObjectField(kContinuationOffset);
426 VerifyObjectField(kStackHandlerIndexOffset);
430 void JSModule::JSModuleVerify() {
431 VerifyObjectField(kContextOffset);
432 VerifyObjectField(kScopeInfoOffset);
433 CHECK(context()->IsUndefined() ||
434 Context::cast(context())->IsModuleContext());
438 void JSValue::JSValueVerify() {
440 if (v->IsHeapObject()) {
441 VerifyHeapPointer(v);
446 void JSDate::JSDateVerify() {
447 if (value()->IsHeapObject()) {
448 VerifyHeapPointer(value());
450 CHECK(value()->IsUndefined() || value()->IsSmi() || value()->IsHeapNumber());
451 CHECK(year()->IsUndefined() || year()->IsSmi() || year()->IsNaN());
452 CHECK(month()->IsUndefined() || month()->IsSmi() || month()->IsNaN());
453 CHECK(day()->IsUndefined() || day()->IsSmi() || day()->IsNaN());
454 CHECK(weekday()->IsUndefined() || weekday()->IsSmi() || weekday()->IsNaN());
455 CHECK(hour()->IsUndefined() || hour()->IsSmi() || hour()->IsNaN());
456 CHECK(min()->IsUndefined() || min()->IsSmi() || min()->IsNaN());
457 CHECK(sec()->IsUndefined() || sec()->IsSmi() || sec()->IsNaN());
458 CHECK(cache_stamp()->IsUndefined() ||
459 cache_stamp()->IsSmi() ||
460 cache_stamp()->IsNaN());
462 if (month()->IsSmi()) {
463 int month = Smi::cast(this->month())->value();
464 CHECK(0 <= month && month <= 11);
466 if (day()->IsSmi()) {
467 int day = Smi::cast(this->day())->value();
468 CHECK(1 <= day && day <= 31);
470 if (hour()->IsSmi()) {
471 int hour = Smi::cast(this->hour())->value();
472 CHECK(0 <= hour && hour <= 23);
474 if (min()->IsSmi()) {
475 int min = Smi::cast(this->min())->value();
476 CHECK(0 <= min && min <= 59);
478 if (sec()->IsSmi()) {
479 int sec = Smi::cast(this->sec())->value();
480 CHECK(0 <= sec && sec <= 59);
482 if (weekday()->IsSmi()) {
483 int weekday = Smi::cast(this->weekday())->value();
484 CHECK(0 <= weekday && weekday <= 6);
486 if (cache_stamp()->IsSmi()) {
487 CHECK(Smi::cast(cache_stamp())->value() <=
488 Smi::cast(GetIsolate()->date_cache()->stamp())->value());
493 void JSMessageObject::JSMessageObjectVerify() {
494 CHECK(IsJSMessageObject());
495 CHECK(type()->IsString());
496 CHECK(arguments()->IsJSArray());
497 VerifyObjectField(kStartPositionOffset);
498 VerifyObjectField(kEndPositionOffset);
499 VerifyObjectField(kArgumentsOffset);
500 VerifyObjectField(kScriptOffset);
501 VerifyObjectField(kStackFramesOffset);
505 void String::StringVerify() {
507 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
508 if (IsInternalizedString()) {
509 CHECK(!GetHeap()->InNewSpace(this));
511 if (IsConsString()) {
512 ConsString::cast(this)->ConsStringVerify();
513 } else if (IsSlicedString()) {
514 SlicedString::cast(this)->SlicedStringVerify();
519 void ConsString::ConsStringVerify() {
520 CHECK(this->first()->IsString());
521 CHECK(this->second() == GetHeap()->empty_string() ||
522 this->second()->IsString());
523 CHECK(this->length() >= ConsString::kMinLength);
524 CHECK(this->length() == this->first()->length() + this->second()->length());
525 if (this->IsFlat()) {
526 // A flat cons can only be created by String::SlowTryFlatten.
527 // Afterwards, the first part may be externalized.
528 CHECK(this->first()->IsSeqString() || this->first()->IsExternalString());
533 void SlicedString::SlicedStringVerify() {
534 CHECK(!this->parent()->IsConsString());
535 CHECK(!this->parent()->IsSlicedString());
536 CHECK(this->length() >= SlicedString::kMinLength);
540 void JSFunction::JSFunctionVerify() {
541 CHECK(IsJSFunction());
542 VerifyObjectField(kPrototypeOrInitialMapOffset);
543 VerifyObjectField(kNextFunctionLinkOffset);
544 CHECK(code()->IsCode());
545 CHECK(next_function_link() == NULL ||
546 next_function_link()->IsUndefined() ||
547 next_function_link()->IsJSFunction());
551 void SharedFunctionInfo::SharedFunctionInfoVerify() {
552 CHECK(IsSharedFunctionInfo());
553 VerifyObjectField(kNameOffset);
554 VerifyObjectField(kCodeOffset);
555 VerifyObjectField(kOptimizedCodeMapOffset);
556 VerifyObjectField(kFeedbackVectorOffset);
557 VerifyObjectField(kScopeInfoOffset);
558 VerifyObjectField(kInstanceClassNameOffset);
559 VerifyObjectField(kFunctionDataOffset);
560 VerifyObjectField(kScriptOffset);
561 VerifyObjectField(kDebugInfoOffset);
565 void JSGlobalProxy::JSGlobalProxyVerify() {
566 CHECK(IsJSGlobalProxy());
568 VerifyObjectField(JSGlobalProxy::kNativeContextOffset);
569 // Make sure that this object has no properties, elements.
570 CHECK_EQ(0, properties()->length());
571 CHECK(HasFastSmiElements());
572 CHECK_EQ(0, FixedArray::cast(elements())->length());
576 void JSGlobalObject::JSGlobalObjectVerify() {
577 CHECK(IsJSGlobalObject());
579 for (int i = GlobalObject::kBuiltinsOffset;
580 i < JSGlobalObject::kSize;
582 VerifyObjectField(i);
587 void JSBuiltinsObject::JSBuiltinsObjectVerify() {
588 CHECK(IsJSBuiltinsObject());
590 for (int i = GlobalObject::kBuiltinsOffset;
591 i < JSBuiltinsObject::kSize;
593 VerifyObjectField(i);
598 void Oddball::OddballVerify() {
600 Heap* heap = GetHeap();
601 VerifyHeapPointer(to_string());
602 Object* number = to_number();
603 if (number->IsHeapObject()) {
604 CHECK(number == heap->nan_value());
606 CHECK(number->IsSmi());
607 int value = Smi::cast(number)->value();
608 // Hidden oddballs have negative smis.
609 const int kLeastHiddenOddballNumber = -5;
611 CHECK(value >= kLeastHiddenOddballNumber);
613 if (map() == heap->undefined_map()) {
614 CHECK(this == heap->undefined_value());
615 } else if (map() == heap->the_hole_map()) {
616 CHECK(this == heap->the_hole_value());
617 } else if (map() == heap->null_map()) {
618 CHECK(this == heap->null_value());
619 } else if (map() == heap->boolean_map()) {
620 CHECK(this == heap->true_value() ||
621 this == heap->false_value());
622 } else if (map() == heap->uninitialized_map()) {
623 CHECK(this == heap->uninitialized_value());
624 } else if (map() == heap->no_interceptor_result_sentinel_map()) {
625 CHECK(this == heap->no_interceptor_result_sentinel());
626 } else if (map() == heap->arguments_marker_map()) {
627 CHECK(this == heap->arguments_marker());
628 } else if (map() == heap->termination_exception_map()) {
629 CHECK(this == heap->termination_exception());
630 } else if (map() == heap->exception_map()) {
631 CHECK(this == heap->exception());
638 void Cell::CellVerify() {
640 VerifyObjectField(kValueOffset);
644 void PropertyCell::PropertyCellVerify() {
645 CHECK(IsPropertyCell());
646 VerifyObjectField(kValueOffset);
647 VerifyObjectField(kTypeOffset);
651 void Code::CodeVerify() {
652 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
654 relocation_info()->ObjectVerify();
655 Address last_gc_pc = NULL;
656 Isolate* isolate = GetIsolate();
657 for (RelocIterator it(this); !it.done(); it.next()) {
658 it.rinfo()->Verify(isolate);
659 // Ensure that GC will not iterate twice over the same pointer.
660 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
661 CHECK(it.rinfo()->pc() != last_gc_pc);
662 last_gc_pc = it.rinfo()->pc();
668 void Code::VerifyEmbeddedObjectsDependency() {
669 if (!CanContainWeakObjects()) return;
670 DisallowHeapAllocation no_gc;
671 Isolate* isolate = GetIsolate();
672 HandleScope scope(isolate);
673 int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
674 for (RelocIterator it(this, mode_mask); !it.done(); it.next()) {
675 Object* obj = it.rinfo()->target_object();
676 if (IsWeakObject(obj)) {
678 Map* map = Map::cast(obj);
679 DependentCode::DependencyGroup group = is_optimized_code() ?
680 DependentCode::kWeakCodeGroup : DependentCode::kWeakICGroup;
681 CHECK(map->dependent_code()->Contains(group, this));
682 } else if (obj->IsJSObject()) {
683 Object* raw_table = GetIsolate()->heap()->weak_object_to_code_table();
684 WeakHashTable* table = WeakHashTable::cast(raw_table);
685 Handle<Object> key_obj(obj, isolate);
686 CHECK(DependentCode::cast(table->Lookup(key_obj))->Contains(
687 DependentCode::kWeakCodeGroup, this));
694 void JSArray::JSArrayVerify() {
696 CHECK(length()->IsNumber() || length()->IsUndefined());
697 // If a GC was caused while constructing this array, the elements
698 // pointer may point to a one pointer filler map.
699 if (ElementsAreSafeToExamine()) {
700 CHECK(elements()->IsUndefined() ||
701 elements()->IsFixedArray() ||
702 elements()->IsFixedDoubleArray());
707 void JSSet::JSSetVerify() {
710 VerifyHeapPointer(table());
711 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
712 // TODO(arv): Verify OrderedHashTable too.
716 void JSMap::JSMapVerify() {
719 VerifyHeapPointer(table());
720 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
721 // TODO(arv): Verify OrderedHashTable too.
725 void JSSetIterator::JSSetIteratorVerify() {
726 CHECK(IsJSSetIterator());
728 VerifyHeapPointer(table());
729 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
730 CHECK(index()->IsSmi() || index()->IsUndefined());
731 CHECK(kind()->IsSmi() || kind()->IsUndefined());
735 void JSMapIterator::JSMapIteratorVerify() {
736 CHECK(IsJSMapIterator());
738 VerifyHeapPointer(table());
739 CHECK(table()->IsOrderedHashTable() || table()->IsUndefined());
740 CHECK(index()->IsSmi() || index()->IsUndefined());
741 CHECK(kind()->IsSmi() || kind()->IsUndefined());
745 void JSWeakMap::JSWeakMapVerify() {
746 CHECK(IsJSWeakMap());
748 VerifyHeapPointer(table());
749 CHECK(table()->IsHashTable() || table()->IsUndefined());
753 void JSWeakSet::JSWeakSetVerify() {
754 CHECK(IsJSWeakSet());
756 VerifyHeapPointer(table());
757 CHECK(table()->IsHashTable() || table()->IsUndefined());
761 void JSRegExp::JSRegExpVerify() {
763 CHECK(data()->IsUndefined() || data()->IsFixedArray());
765 case JSRegExp::ATOM: {
766 FixedArray* arr = FixedArray::cast(data());
767 CHECK(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
770 case JSRegExp::IRREGEXP: {
771 bool is_native = RegExpImpl::UsesNativeRegExp();
773 FixedArray* arr = FixedArray::cast(data());
774 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
775 // Smi : Not compiled yet (-1) or code prepared for flushing.
776 // JSObject: Compilation error.
777 // Code/ByteArray: Compiled code.
778 CHECK(ascii_data->IsSmi() ||
779 (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray()));
780 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
781 CHECK(uc16_data->IsSmi() ||
782 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
784 Object* ascii_saved = arr->get(JSRegExp::kIrregexpASCIICodeSavedIndex);
785 CHECK(ascii_saved->IsSmi() || ascii_saved->IsString() ||
786 ascii_saved->IsCode());
787 Object* uc16_saved = arr->get(JSRegExp::kIrregexpUC16CodeSavedIndex);
788 CHECK(uc16_saved->IsSmi() || uc16_saved->IsString() ||
789 uc16_saved->IsCode());
791 CHECK(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
792 CHECK(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
796 CHECK_EQ(JSRegExp::NOT_COMPILED, TypeTag());
797 CHECK(data()->IsUndefined());
803 void JSProxy::JSProxyVerify() {
805 VerifyPointer(handler());
806 CHECK(hash()->IsSmi() || hash()->IsUndefined());
810 void JSFunctionProxy::JSFunctionProxyVerify() {
811 CHECK(IsJSFunctionProxy());
813 VerifyPointer(call_trap());
814 VerifyPointer(construct_trap());
818 void JSArrayBuffer::JSArrayBufferVerify() {
819 CHECK(IsJSArrayBuffer());
821 VerifyPointer(byte_length());
822 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
823 || byte_length()->IsUndefined());
827 void JSArrayBufferView::JSArrayBufferViewVerify() {
828 CHECK(IsJSArrayBufferView());
830 VerifyPointer(buffer());
831 CHECK(buffer()->IsJSArrayBuffer() || buffer()->IsUndefined()
832 || buffer() == Smi::FromInt(0));
834 VerifyPointer(byte_offset());
835 CHECK(byte_offset()->IsSmi() || byte_offset()->IsHeapNumber()
836 || byte_offset()->IsUndefined());
838 VerifyPointer(byte_length());
839 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
840 || byte_length()->IsUndefined());
844 void JSTypedArray::JSTypedArrayVerify() {
845 CHECK(IsJSTypedArray());
846 JSArrayBufferViewVerify();
847 VerifyPointer(length());
848 CHECK(length()->IsSmi() || length()->IsHeapNumber()
849 || length()->IsUndefined());
851 VerifyPointer(elements());
855 void JSDataView::JSDataViewVerify() {
856 CHECK(IsJSDataView());
857 JSArrayBufferViewVerify();
861 void Foreign::ForeignVerify() {
866 void Box::BoxVerify() {
868 value()->ObjectVerify();
872 void AccessorInfo::AccessorInfoVerify() {
873 VerifyPointer(name());
874 VerifyPointer(flag());
875 VerifyPointer(expected_receiver_type());
879 void ExecutableAccessorInfo::ExecutableAccessorInfoVerify() {
880 CHECK(IsExecutableAccessorInfo());
881 AccessorInfoVerify();
882 VerifyPointer(getter());
883 VerifyPointer(setter());
884 VerifyPointer(data());
888 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorVerify() {
889 CHECK(IsDeclaredAccessorDescriptor());
890 VerifyPointer(serialized_data());
894 void DeclaredAccessorInfo::DeclaredAccessorInfoVerify() {
895 CHECK(IsDeclaredAccessorInfo());
896 AccessorInfoVerify();
897 VerifyPointer(descriptor());
901 void AccessorPair::AccessorPairVerify() {
902 CHECK(IsAccessorPair());
903 VerifyPointer(getter());
904 VerifyPointer(setter());
905 VerifySmiField(kAccessFlagsOffset);
909 void AccessCheckInfo::AccessCheckInfoVerify() {
910 CHECK(IsAccessCheckInfo());
911 VerifyPointer(named_callback());
912 VerifyPointer(indexed_callback());
913 VerifyPointer(data());
917 void InterceptorInfo::InterceptorInfoVerify() {
918 CHECK(IsInterceptorInfo());
919 VerifyPointer(getter());
920 VerifyPointer(setter());
921 VerifyPointer(query());
922 VerifyPointer(deleter());
923 VerifyPointer(enumerator());
924 VerifyPointer(data());
928 void CallHandlerInfo::CallHandlerInfoVerify() {
929 CHECK(IsCallHandlerInfo());
930 VerifyPointer(callback());
931 VerifyPointer(data());
935 void TemplateInfo::TemplateInfoVerify() {
936 VerifyPointer(tag());
937 VerifyPointer(property_list());
938 VerifyPointer(property_accessors());
942 void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
943 CHECK(IsFunctionTemplateInfo());
944 TemplateInfoVerify();
945 VerifyPointer(serial_number());
946 VerifyPointer(call_code());
947 VerifyPointer(prototype_template());
948 VerifyPointer(parent_template());
949 VerifyPointer(named_property_handler());
950 VerifyPointer(indexed_property_handler());
951 VerifyPointer(instance_template());
952 VerifyPointer(signature());
953 VerifyPointer(access_check_info());
957 void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
958 CHECK(IsObjectTemplateInfo());
959 TemplateInfoVerify();
960 VerifyPointer(constructor());
961 VerifyPointer(internal_field_count());
965 void SignatureInfo::SignatureInfoVerify() {
966 CHECK(IsSignatureInfo());
967 VerifyPointer(receiver());
968 VerifyPointer(args());
972 void TypeSwitchInfo::TypeSwitchInfoVerify() {
973 CHECK(IsTypeSwitchInfo());
974 VerifyPointer(types());
978 void AllocationSite::AllocationSiteVerify() {
979 CHECK(IsAllocationSite());
983 void AllocationMemento::AllocationMementoVerify() {
984 CHECK(IsAllocationMemento());
985 VerifyHeapPointer(allocation_site());
986 CHECK(!IsValid() || GetAllocationSite()->IsAllocationSite());
990 void Script::ScriptVerify() {
992 VerifyPointer(source());
993 VerifyPointer(name());
994 line_offset()->SmiVerify();
995 column_offset()->SmiVerify();
996 VerifyPointer(wrapper());
998 VerifyPointer(line_ends());
1003 void JSFunctionResultCache::JSFunctionResultCacheVerify() {
1004 JSFunction::cast(get(kFactoryIndex))->ObjectVerify();
1006 int size = Smi::cast(get(kCacheSizeIndex))->value();
1007 CHECK(kEntriesIndex <= size);
1008 CHECK(size <= length());
1009 CHECK_EQ(0, size % kEntrySize);
1011 int finger = Smi::cast(get(kFingerIndex))->value();
1012 CHECK(kEntriesIndex <= finger);
1013 CHECK((finger < size) || (finger == kEntriesIndex && finger == size));
1014 CHECK_EQ(0, finger % kEntrySize);
1016 if (FLAG_enable_slow_asserts) {
1017 for (int i = kEntriesIndex; i < size; i++) {
1018 CHECK(!get(i)->IsTheHole());
1019 get(i)->ObjectVerify();
1021 for (int i = size; i < length(); i++) {
1022 CHECK(get(i)->IsTheHole());
1023 get(i)->ObjectVerify();
1029 void NormalizedMapCache::NormalizedMapCacheVerify() {
1030 FixedArray::cast(this)->FixedArrayVerify();
1031 if (FLAG_enable_slow_asserts) {
1032 for (int i = 0; i < length(); i++) {
1033 Object* e = FixedArray::get(i);
1035 Map::cast(e)->SharedMapVerify();
1037 CHECK(e->IsUndefined());
1044 void DebugInfo::DebugInfoVerify() {
1045 CHECK(IsDebugInfo());
1046 VerifyPointer(shared());
1047 VerifyPointer(original_code());
1048 VerifyPointer(code());
1049 VerifyPointer(break_points());
1053 void BreakPointInfo::BreakPointInfoVerify() {
1054 CHECK(IsBreakPointInfo());
1055 code_position()->SmiVerify();
1056 source_position()->SmiVerify();
1057 statement_position()->SmiVerify();
1058 VerifyPointer(break_point_objects());
1060 #endif // VERIFY_HEAP
1064 void JSObject::IncrementSpillStatistics(SpillInformation* info) {
1065 info->number_of_objects_++;
1067 if (HasFastProperties()) {
1068 info->number_of_objects_with_fast_properties_++;
1069 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
1070 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
1072 NameDictionary* dict = property_dictionary();
1073 info->number_of_slow_used_properties_ += dict->NumberOfElements();
1074 info->number_of_slow_unused_properties_ +=
1075 dict->Capacity() - dict->NumberOfElements();
1077 // Indexed properties
1078 switch (GetElementsKind()) {
1079 case FAST_HOLEY_SMI_ELEMENTS:
1080 case FAST_SMI_ELEMENTS:
1081 case FAST_HOLEY_DOUBLE_ELEMENTS:
1082 case FAST_DOUBLE_ELEMENTS:
1083 case FAST_HOLEY_ELEMENTS:
1084 case FAST_ELEMENTS: {
1085 info->number_of_objects_with_fast_elements_++;
1087 FixedArray* e = FixedArray::cast(elements());
1088 int len = e->length();
1089 Heap* heap = GetHeap();
1090 for (int i = 0; i < len; i++) {
1091 if (e->get(i) == heap->the_hole_value()) holes++;
1093 info->number_of_fast_used_elements_ += len - holes;
1094 info->number_of_fast_unused_elements_ += holes;
1098 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1099 case EXTERNAL_##TYPE##_ELEMENTS: \
1100 case TYPE##_ELEMENTS:
1102 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1103 #undef TYPED_ARRAY_CASE
1104 { info->number_of_objects_with_fast_elements_++;
1105 FixedArrayBase* e = FixedArrayBase::cast(elements());
1106 info->number_of_fast_used_elements_ += e->length();
1109 case DICTIONARY_ELEMENTS: {
1110 SeededNumberDictionary* dict = element_dictionary();
1111 info->number_of_slow_used_elements_ += dict->NumberOfElements();
1112 info->number_of_slow_unused_elements_ +=
1113 dict->Capacity() - dict->NumberOfElements();
1116 case SLOPPY_ARGUMENTS_ELEMENTS:
1122 void JSObject::SpillInformation::Clear() {
1123 number_of_objects_ = 0;
1124 number_of_objects_with_fast_properties_ = 0;
1125 number_of_objects_with_fast_elements_ = 0;
1126 number_of_fast_used_fields_ = 0;
1127 number_of_fast_unused_fields_ = 0;
1128 number_of_slow_used_properties_ = 0;
1129 number_of_slow_unused_properties_ = 0;
1130 number_of_fast_used_elements_ = 0;
1131 number_of_fast_unused_elements_ = 0;
1132 number_of_slow_used_elements_ = 0;
1133 number_of_slow_unused_elements_ = 0;
1137 void JSObject::SpillInformation::Print() {
1138 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
1140 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
1141 number_of_objects_with_fast_properties_,
1142 number_of_fast_used_fields_, number_of_fast_unused_fields_);
1144 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
1145 number_of_objects_ - number_of_objects_with_fast_properties_,
1146 number_of_slow_used_properties_, number_of_slow_unused_properties_);
1148 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
1149 number_of_objects_with_fast_elements_,
1150 number_of_fast_used_elements_, number_of_fast_unused_elements_);
1152 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
1153 number_of_objects_ - number_of_objects_with_fast_elements_,
1154 number_of_slow_used_elements_, number_of_slow_unused_elements_);
1160 bool DescriptorArray::IsSortedNoDuplicates(int valid_entries) {
1161 if (valid_entries == -1) valid_entries = number_of_descriptors();
1162 Name* current_key = NULL;
1163 uint32_t current = 0;
1164 for (int i = 0; i < number_of_descriptors(); i++) {
1165 Name* key = GetSortedKey(i);
1166 if (key == current_key) {
1171 uint32_t hash = GetSortedKey(i)->Hash();
1172 if (hash < current) {
1182 bool TransitionArray::IsSortedNoDuplicates(int valid_entries) {
1183 ASSERT(valid_entries == -1);
1184 Name* current_key = NULL;
1185 uint32_t current = 0;
1186 for (int i = 0; i < number_of_transitions(); i++) {
1187 Name* key = GetSortedKey(i);
1188 if (key == current_key) {
1193 uint32_t hash = GetSortedKey(i)->Hash();
1194 if (hash < current) {
1204 static bool CheckOneBackPointer(Map* current_map, Object* target) {
1205 return !target->IsMap() || Map::cast(target)->GetBackPointer() == current_map;
1209 bool TransitionArray::IsConsistentWithBackPointers(Map* current_map) {
1210 for (int i = 0; i < number_of_transitions(); ++i) {
1211 if (!CheckOneBackPointer(current_map, GetTarget(i))) return false;
1219 } } // namespace v8::internal