1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "disassembler.h"
33 #include "macro-assembler.h"
34 #include "objects-visiting.h"
41 void MaybeObject::Verify() {
42 Object* this_as_object;
43 if (ToObject(&this_as_object)) {
44 if (this_as_object->IsSmi()) {
45 Smi::cast(this_as_object)->SmiVerify();
47 HeapObject::cast(this_as_object)->HeapObjectVerify();
50 Failure::cast(this)->FailureVerify();
55 void Object::VerifyPointer(Object* p) {
56 if (p->IsHeapObject()) {
57 HeapObject::VerifyHeapPointer(p);
64 void Smi::SmiVerify() {
69 void Failure::FailureVerify() {
74 void HeapObject::HeapObjectVerify() {
75 InstanceType instance_type = map()->instance_type();
77 if (instance_type < FIRST_NONSTRING_TYPE) {
78 String::cast(this)->StringVerify();
82 switch (instance_type) {
84 Symbol::cast(this)->SymbolVerify();
87 Map::cast(this)->MapVerify();
89 case HEAP_NUMBER_TYPE:
90 HeapNumber::cast(this)->HeapNumberVerify();
93 Float32x4::cast(this)->Float32x4Verify();
96 Int32x4::cast(this)->Int32x4Verify();
98 case FIXED_ARRAY_TYPE:
99 FixedArray::cast(this)->FixedArrayVerify();
101 case FIXED_DOUBLE_ARRAY_TYPE:
102 FixedDoubleArray::cast(this)->FixedDoubleArrayVerify();
104 case CONSTANT_POOL_ARRAY_TYPE:
105 ConstantPoolArray::cast(this)->ConstantPoolArrayVerify();
107 case BYTE_ARRAY_TYPE:
108 ByteArray::cast(this)->ByteArrayVerify();
110 case FREE_SPACE_TYPE:
111 FreeSpace::cast(this)->FreeSpaceVerify();
114 #define VERIFY_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
115 case EXTERNAL_##TYPE##_ARRAY_TYPE: \
116 External##Type##Array::cast(this)->External##Type##ArrayVerify(); \
118 case FIXED_##TYPE##_ARRAY_TYPE: \
119 Fixed##Type##Array::cast(this)->FixedTypedArrayVerify(); \
122 TYPED_ARRAYS(VERIFY_TYPED_ARRAY)
123 #undef VERIFY_TYPED_ARRAY
126 Code::cast(this)->CodeVerify();
129 Oddball::cast(this)->OddballVerify();
132 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
133 JSObject::cast(this)->JSObjectVerify();
135 case JS_GENERATOR_OBJECT_TYPE:
136 JSGeneratorObject::cast(this)->JSGeneratorObjectVerify();
139 JSModule::cast(this)->JSModuleVerify();
142 JSValue::cast(this)->JSValueVerify();
145 JSDate::cast(this)->JSDateVerify();
147 case JS_FUNCTION_TYPE:
148 JSFunction::cast(this)->JSFunctionVerify();
150 case JS_GLOBAL_PROXY_TYPE:
151 JSGlobalProxy::cast(this)->JSGlobalProxyVerify();
153 case JS_GLOBAL_OBJECT_TYPE:
154 JSGlobalObject::cast(this)->JSGlobalObjectVerify();
156 case JS_BUILTINS_OBJECT_TYPE:
157 JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify();
160 Cell::cast(this)->CellVerify();
162 case PROPERTY_CELL_TYPE:
163 PropertyCell::cast(this)->PropertyCellVerify();
166 JSArray::cast(this)->JSArrayVerify();
169 JSSet::cast(this)->JSSetVerify();
172 JSMap::cast(this)->JSMapVerify();
174 case JS_WEAK_MAP_TYPE:
175 JSWeakMap::cast(this)->JSWeakMapVerify();
177 case JS_WEAK_SET_TYPE:
178 JSWeakSet::cast(this)->JSWeakSetVerify();
181 JSRegExp::cast(this)->JSRegExpVerify();
186 JSProxy::cast(this)->JSProxyVerify();
188 case JS_FUNCTION_PROXY_TYPE:
189 JSFunctionProxy::cast(this)->JSFunctionProxyVerify();
192 Foreign::cast(this)->ForeignVerify();
194 case SHARED_FUNCTION_INFO_TYPE:
195 SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify();
197 case JS_MESSAGE_OBJECT_TYPE:
198 JSMessageObject::cast(this)->JSMessageObjectVerify();
200 case JS_ARRAY_BUFFER_TYPE:
201 JSArrayBuffer::cast(this)->JSArrayBufferVerify();
203 case JS_TYPED_ARRAY_TYPE:
204 JSTypedArray::cast(this)->JSTypedArrayVerify();
206 case JS_DATA_VIEW_TYPE:
207 JSDataView::cast(this)->JSDataViewVerify();
210 #define MAKE_STRUCT_CASE(NAME, Name, name) \
212 Name::cast(this)->Name##Verify(); \
214 STRUCT_LIST(MAKE_STRUCT_CASE)
215 #undef MAKE_STRUCT_CASE
224 void HeapObject::VerifyHeapPointer(Object* p) {
225 CHECK(p->IsHeapObject());
226 HeapObject* ho = HeapObject::cast(p);
227 CHECK(ho->GetHeap()->Contains(ho));
231 void Symbol::SymbolVerify() {
233 CHECK(HasHashCode());
235 CHECK(name()->IsUndefined() || name()->IsString());
236 CHECK(flags()->IsSmi());
240 void HeapNumber::HeapNumberVerify() {
241 CHECK(IsHeapNumber());
245 void Float32x4::Float32x4Verify() {
246 CHECK(IsFloat32x4());
250 void Int32x4::Int32x4Verify() {
255 void ByteArray::ByteArrayVerify() {
256 CHECK(IsByteArray());
260 void FreeSpace::FreeSpaceVerify() {
261 CHECK(IsFreeSpace());
265 #define EXTERNAL_ARRAY_VERIFY(Type, type, TYPE, ctype, size) \
266 void External##Type##Array::External##Type##ArrayVerify() { \
267 CHECK(IsExternal##Type##Array()); \
270 TYPED_ARRAYS(EXTERNAL_ARRAY_VERIFY)
271 #undef EXTERNAL_ARRAY_VERIFY
274 template <class Traits>
275 void FixedTypedArray<Traits>::FixedTypedArrayVerify() {
276 CHECK(IsHeapObject() &&
277 HeapObject::cast(this)->map()->instance_type() ==
278 Traits::kInstanceType);
282 bool JSObject::ElementsAreSafeToExamine() {
283 // If a GC was caused while constructing this object, the elements
284 // pointer may point to a one pointer filler map.
285 return reinterpret_cast<Map*>(elements()) !=
286 GetHeap()->one_pointer_filler_map();
290 void JSObject::JSObjectVerify() {
291 VerifyHeapPointer(properties());
292 VerifyHeapPointer(elements());
294 if (GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS) {
295 CHECK(this->elements()->IsFixedArray());
296 CHECK_GE(this->elements()->length(), 2);
299 if (HasFastProperties()) {
300 CHECK_EQ(map()->unused_property_fields(),
301 (map()->inobject_properties() + properties()->length() -
302 map()->NextFreePropertyIndex()));
303 DescriptorArray* descriptors = map()->instance_descriptors();
304 for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
305 if (descriptors->GetDetails(i).type() == FIELD) {
306 Representation r = descriptors->GetDetails(i).representation();
307 int field = descriptors->GetFieldIndex(i);
308 Object* value = RawFastPropertyAt(field);
309 if (r.IsDouble()) ASSERT(value->IsHeapNumber());
310 if (value->IsUninitialized()) continue;
311 if (r.IsSmi()) ASSERT(value->IsSmi());
312 if (r.IsHeapObject()) ASSERT(value->IsHeapObject());
317 // If a GC was caused while constructing this object, the elements
318 // pointer may point to a one pointer filler map.
319 if (ElementsAreSafeToExamine()) {
320 CHECK_EQ((map()->has_fast_smi_or_object_elements() ||
321 (elements() == GetHeap()->empty_fixed_array())),
322 (elements()->map() == GetHeap()->fixed_array_map() ||
323 elements()->map() == GetHeap()->fixed_cow_array_map()));
324 CHECK(map()->has_fast_object_elements() == HasFastObjectElements());
329 void Map::MapVerify() {
330 Heap* heap = GetHeap();
331 CHECK(!heap->InNewSpace(this));
332 CHECK(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
333 CHECK(instance_size() == kVariableSizeSentinel ||
334 (kPointerSize <= instance_size() &&
335 instance_size() < heap->Capacity()));
336 VerifyHeapPointer(prototype());
337 VerifyHeapPointer(instance_descriptors());
338 SLOW_ASSERT(instance_descriptors()->IsSortedNoDuplicates());
339 if (HasTransitionArray()) {
340 SLOW_ASSERT(transitions()->IsSortedNoDuplicates());
341 SLOW_ASSERT(transitions()->IsConsistentWithBackPointers(this));
346 void Map::SharedMapVerify() {
349 CHECK(instance_descriptors()->IsEmpty());
350 CHECK_EQ(0, pre_allocated_property_fields());
351 CHECK_EQ(0, unused_property_fields());
352 CHECK_EQ(StaticVisitorBase::GetVisitorId(instance_type(), instance_size()),
357 void Map::VerifyOmittedMapChecks() {
358 if (!FLAG_omit_map_checks_for_leaf_maps) return;
361 HasTransitionArray() ||
362 is_dictionary_map()) {
363 CHECK_EQ(0, dependent_code()->number_of_entries(
364 DependentCode::kPrototypeCheckGroup));
369 void CodeCache::CodeCacheVerify() {
370 VerifyHeapPointer(default_cache());
371 VerifyHeapPointer(normal_type_cache());
372 CHECK(default_cache()->IsFixedArray());
373 CHECK(normal_type_cache()->IsUndefined()
374 || normal_type_cache()->IsCodeCacheHashTable());
378 void PolymorphicCodeCache::PolymorphicCodeCacheVerify() {
379 VerifyHeapPointer(cache());
380 CHECK(cache()->IsUndefined() || cache()->IsPolymorphicCodeCacheHashTable());
384 void TypeFeedbackInfo::TypeFeedbackInfoVerify() {
385 VerifyObjectField(kStorage1Offset);
386 VerifyObjectField(kStorage2Offset);
387 VerifyHeapPointer(feedback_vector());
391 void AliasedArgumentsEntry::AliasedArgumentsEntryVerify() {
392 VerifySmiField(kAliasedContextSlot);
396 void FixedArray::FixedArrayVerify() {
397 for (int i = 0; i < length(); i++) {
399 if (e->IsHeapObject()) {
400 VerifyHeapPointer(e);
408 void FixedDoubleArray::FixedDoubleArrayVerify() {
409 for (int i = 0; i < length(); i++) {
410 if (!is_the_hole(i)) {
411 double value = get_scalar(i);
412 CHECK(!std::isnan(value) ||
413 (BitCast<uint64_t>(value) ==
414 BitCast<uint64_t>(canonical_not_the_hole_nan_as_double())) ||
415 ((BitCast<uint64_t>(value) & Double::kSignMask) != 0));
421 void ConstantPoolArray::ConstantPoolArrayVerify() {
422 CHECK(IsConstantPoolArray());
423 for (int i = 0; i < count_of_code_ptr_entries(); i++) {
424 Address code_entry = get_code_ptr_entry(first_code_ptr_index() + i);
425 VerifyPointer(Code::GetCodeFromTargetAddress(code_entry));
427 for (int i = 0; i < count_of_heap_ptr_entries(); i++) {
428 VerifyObjectField(OffsetOfElementAt(first_heap_ptr_index() + i));
433 void JSGeneratorObject::JSGeneratorObjectVerify() {
434 // In an expression like "new g()", there can be a point where a generator
435 // object is allocated but its fields are all undefined, as it hasn't yet been
436 // initialized by the generator. Hence these weak checks.
437 VerifyObjectField(kFunctionOffset);
438 VerifyObjectField(kContextOffset);
439 VerifyObjectField(kReceiverOffset);
440 VerifyObjectField(kOperandStackOffset);
441 VerifyObjectField(kContinuationOffset);
442 VerifyObjectField(kStackHandlerIndexOffset);
446 void JSModule::JSModuleVerify() {
447 VerifyObjectField(kContextOffset);
448 VerifyObjectField(kScopeInfoOffset);
449 CHECK(context()->IsUndefined() ||
450 Context::cast(context())->IsModuleContext());
454 void JSValue::JSValueVerify() {
456 if (v->IsHeapObject()) {
457 VerifyHeapPointer(v);
462 void JSDate::JSDateVerify() {
463 if (value()->IsHeapObject()) {
464 VerifyHeapPointer(value());
466 CHECK(value()->IsUndefined() || value()->IsSmi() || value()->IsHeapNumber());
467 CHECK(year()->IsUndefined() || year()->IsSmi() || year()->IsNaN());
468 CHECK(month()->IsUndefined() || month()->IsSmi() || month()->IsNaN());
469 CHECK(day()->IsUndefined() || day()->IsSmi() || day()->IsNaN());
470 CHECK(weekday()->IsUndefined() || weekday()->IsSmi() || weekday()->IsNaN());
471 CHECK(hour()->IsUndefined() || hour()->IsSmi() || hour()->IsNaN());
472 CHECK(min()->IsUndefined() || min()->IsSmi() || min()->IsNaN());
473 CHECK(sec()->IsUndefined() || sec()->IsSmi() || sec()->IsNaN());
474 CHECK(cache_stamp()->IsUndefined() ||
475 cache_stamp()->IsSmi() ||
476 cache_stamp()->IsNaN());
478 if (month()->IsSmi()) {
479 int month = Smi::cast(this->month())->value();
480 CHECK(0 <= month && month <= 11);
482 if (day()->IsSmi()) {
483 int day = Smi::cast(this->day())->value();
484 CHECK(1 <= day && day <= 31);
486 if (hour()->IsSmi()) {
487 int hour = Smi::cast(this->hour())->value();
488 CHECK(0 <= hour && hour <= 23);
490 if (min()->IsSmi()) {
491 int min = Smi::cast(this->min())->value();
492 CHECK(0 <= min && min <= 59);
494 if (sec()->IsSmi()) {
495 int sec = Smi::cast(this->sec())->value();
496 CHECK(0 <= sec && sec <= 59);
498 if (weekday()->IsSmi()) {
499 int weekday = Smi::cast(this->weekday())->value();
500 CHECK(0 <= weekday && weekday <= 6);
502 if (cache_stamp()->IsSmi()) {
503 CHECK(Smi::cast(cache_stamp())->value() <=
504 Smi::cast(GetIsolate()->date_cache()->stamp())->value());
509 void JSMessageObject::JSMessageObjectVerify() {
510 CHECK(IsJSMessageObject());
511 CHECK(type()->IsString());
512 CHECK(arguments()->IsJSArray());
513 VerifyObjectField(kStartPositionOffset);
514 VerifyObjectField(kEndPositionOffset);
515 VerifyObjectField(kArgumentsOffset);
516 VerifyObjectField(kScriptOffset);
517 VerifyObjectField(kStackFramesOffset);
521 void String::StringVerify() {
523 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
524 if (IsInternalizedString()) {
525 CHECK(!GetHeap()->InNewSpace(this));
527 if (IsConsString()) {
528 ConsString::cast(this)->ConsStringVerify();
529 } else if (IsSlicedString()) {
530 SlicedString::cast(this)->SlicedStringVerify();
535 void ConsString::ConsStringVerify() {
536 CHECK(this->first()->IsString());
537 CHECK(this->second() == GetHeap()->empty_string() ||
538 this->second()->IsString());
539 CHECK(this->length() >= ConsString::kMinLength);
540 if (this->IsFlat()) {
541 // A flat cons can only be created by String::SlowTryFlatten.
542 // Afterwards, the first part may be externalized.
543 CHECK(this->first()->IsSeqString() || this->first()->IsExternalString());
548 void SlicedString::SlicedStringVerify() {
549 CHECK(!this->parent()->IsConsString());
550 CHECK(!this->parent()->IsSlicedString());
551 CHECK(this->length() >= SlicedString::kMinLength);
555 void JSFunction::JSFunctionVerify() {
556 CHECK(IsJSFunction());
557 VerifyObjectField(kPrototypeOrInitialMapOffset);
558 VerifyObjectField(kNextFunctionLinkOffset);
559 CHECK(code()->IsCode());
560 CHECK(next_function_link() == NULL ||
561 next_function_link()->IsUndefined() ||
562 next_function_link()->IsJSFunction());
566 void SharedFunctionInfo::SharedFunctionInfoVerify() {
567 CHECK(IsSharedFunctionInfo());
568 VerifyObjectField(kNameOffset);
569 VerifyObjectField(kCodeOffset);
570 VerifyObjectField(kOptimizedCodeMapOffset);
571 VerifyObjectField(kScopeInfoOffset);
572 VerifyObjectField(kInstanceClassNameOffset);
573 VerifyObjectField(kFunctionDataOffset);
574 VerifyObjectField(kScriptOffset);
575 VerifyObjectField(kDebugInfoOffset);
579 void JSGlobalProxy::JSGlobalProxyVerify() {
580 CHECK(IsJSGlobalProxy());
582 VerifyObjectField(JSGlobalProxy::kNativeContextOffset);
583 // Make sure that this object has no properties, elements.
584 CHECK_EQ(0, properties()->length());
585 CHECK(HasFastObjectElements());
586 CHECK_EQ(0, FixedArray::cast(elements())->length());
590 void JSGlobalObject::JSGlobalObjectVerify() {
591 CHECK(IsJSGlobalObject());
593 for (int i = GlobalObject::kBuiltinsOffset;
594 i < JSGlobalObject::kSize;
596 VerifyObjectField(i);
601 void JSBuiltinsObject::JSBuiltinsObjectVerify() {
602 CHECK(IsJSBuiltinsObject());
604 for (int i = GlobalObject::kBuiltinsOffset;
605 i < JSBuiltinsObject::kSize;
607 VerifyObjectField(i);
612 void Oddball::OddballVerify() {
614 VerifyHeapPointer(to_string());
615 Object* number = to_number();
616 if (number->IsHeapObject()) {
617 CHECK(number == HeapObject::cast(number)->GetHeap()->nan_value());
619 CHECK(number->IsSmi());
620 int value = Smi::cast(number)->value();
621 // Hidden oddballs have negative smis.
622 const int kLeastHiddenOddballNumber = -4;
624 CHECK(value >= kLeastHiddenOddballNumber);
629 void Cell::CellVerify() {
631 VerifyObjectField(kValueOffset);
635 void PropertyCell::PropertyCellVerify() {
636 CHECK(IsPropertyCell());
637 VerifyObjectField(kValueOffset);
638 VerifyObjectField(kTypeOffset);
642 void Code::CodeVerify() {
643 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
645 relocation_info()->Verify();
646 Address last_gc_pc = NULL;
647 for (RelocIterator it(this); !it.done(); it.next()) {
648 it.rinfo()->Verify();
649 // Ensure that GC will not iterate twice over the same pointer.
650 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
651 CHECK(it.rinfo()->pc() != last_gc_pc);
652 last_gc_pc = it.rinfo()->pc();
658 void Code::VerifyEmbeddedObjectsDependency() {
659 int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
660 for (RelocIterator it(this, mode_mask); !it.done(); it.next()) {
661 Object* obj = it.rinfo()->target_object();
662 if (IsWeakObject(obj)) {
664 Map* map = Map::cast(obj);
665 CHECK(map->dependent_code()->Contains(
666 DependentCode::kWeaklyEmbeddedGroup, this));
667 } else if (obj->IsJSObject()) {
668 Object* raw_table = GetIsolate()->heap()->weak_object_to_code_table();
669 WeakHashTable* table = WeakHashTable::cast(raw_table);
670 CHECK(DependentCode::cast(table->Lookup(obj))->Contains(
671 DependentCode::kWeaklyEmbeddedGroup, this));
678 void JSArray::JSArrayVerify() {
680 CHECK(length()->IsNumber() || length()->IsUndefined());
681 // If a GC was caused while constructing this array, the elements
682 // pointer may point to a one pointer filler map.
683 if (ElementsAreSafeToExamine()) {
684 CHECK(elements()->IsUndefined() ||
685 elements()->IsFixedArray() ||
686 elements()->IsFixedDoubleArray());
691 void JSSet::JSSetVerify() {
694 VerifyHeapPointer(table());
695 CHECK(table()->IsHashTable() || table()->IsUndefined());
699 void JSMap::JSMapVerify() {
702 VerifyHeapPointer(table());
703 CHECK(table()->IsHashTable() || table()->IsUndefined());
707 void JSWeakMap::JSWeakMapVerify() {
708 CHECK(IsJSWeakMap());
710 VerifyHeapPointer(table());
711 CHECK(table()->IsHashTable() || table()->IsUndefined());
715 void JSWeakSet::JSWeakSetVerify() {
716 CHECK(IsJSWeakSet());
718 VerifyHeapPointer(table());
719 CHECK(table()->IsHashTable() || table()->IsUndefined());
723 void JSRegExp::JSRegExpVerify() {
725 CHECK(data()->IsUndefined() || data()->IsFixedArray());
727 case JSRegExp::ATOM: {
728 FixedArray* arr = FixedArray::cast(data());
729 CHECK(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
732 case JSRegExp::IRREGEXP: {
733 bool is_native = RegExpImpl::UsesNativeRegExp();
735 FixedArray* arr = FixedArray::cast(data());
736 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
737 // Smi : Not compiled yet (-1) or code prepared for flushing.
738 // JSObject: Compilation error.
739 // Code/ByteArray: Compiled code.
740 CHECK(ascii_data->IsSmi() ||
741 (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray()));
742 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
743 CHECK(uc16_data->IsSmi() ||
744 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
746 Object* ascii_saved = arr->get(JSRegExp::kIrregexpASCIICodeSavedIndex);
747 CHECK(ascii_saved->IsSmi() || ascii_saved->IsString() ||
748 ascii_saved->IsCode());
749 Object* uc16_saved = arr->get(JSRegExp::kIrregexpUC16CodeSavedIndex);
750 CHECK(uc16_saved->IsSmi() || uc16_saved->IsString() ||
751 uc16_saved->IsCode());
753 CHECK(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
754 CHECK(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
758 CHECK_EQ(JSRegExp::NOT_COMPILED, TypeTag());
759 CHECK(data()->IsUndefined());
765 void JSProxy::JSProxyVerify() {
767 VerifyPointer(handler());
768 CHECK(hash()->IsSmi() || hash()->IsUndefined());
772 void JSFunctionProxy::JSFunctionProxyVerify() {
773 CHECK(IsJSFunctionProxy());
775 VerifyPointer(call_trap());
776 VerifyPointer(construct_trap());
780 void JSArrayBuffer::JSArrayBufferVerify() {
781 CHECK(IsJSArrayBuffer());
783 VerifyPointer(byte_length());
784 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
785 || byte_length()->IsUndefined());
789 void JSArrayBufferView::JSArrayBufferViewVerify() {
790 CHECK(IsJSArrayBufferView());
792 VerifyPointer(buffer());
793 CHECK(buffer()->IsJSArrayBuffer() || buffer()->IsUndefined()
794 || buffer() == Smi::FromInt(0));
796 VerifyPointer(byte_offset());
797 CHECK(byte_offset()->IsSmi() || byte_offset()->IsHeapNumber()
798 || byte_offset()->IsUndefined());
800 VerifyPointer(byte_length());
801 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
802 || byte_length()->IsUndefined());
806 void JSTypedArray::JSTypedArrayVerify() {
807 CHECK(IsJSTypedArray());
808 JSArrayBufferViewVerify();
809 VerifyPointer(length());
810 CHECK(length()->IsSmi() || length()->IsHeapNumber()
811 || length()->IsUndefined());
813 VerifyPointer(elements());
817 void JSDataView::JSDataViewVerify() {
818 CHECK(IsJSDataView());
819 JSArrayBufferViewVerify();
823 void Foreign::ForeignVerify() {
828 void Box::BoxVerify() {
834 void AccessorInfo::AccessorInfoVerify() {
835 VerifyPointer(name());
836 VerifyPointer(flag());
837 VerifyPointer(expected_receiver_type());
841 void ExecutableAccessorInfo::ExecutableAccessorInfoVerify() {
842 CHECK(IsExecutableAccessorInfo());
843 AccessorInfoVerify();
844 VerifyPointer(getter());
845 VerifyPointer(setter());
846 VerifyPointer(data());
850 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorVerify() {
851 CHECK(IsDeclaredAccessorDescriptor());
852 VerifyPointer(serialized_data());
856 void DeclaredAccessorInfo::DeclaredAccessorInfoVerify() {
857 CHECK(IsDeclaredAccessorInfo());
858 AccessorInfoVerify();
859 VerifyPointer(descriptor());
863 void AccessorPair::AccessorPairVerify() {
864 CHECK(IsAccessorPair());
865 VerifyPointer(getter());
866 VerifyPointer(setter());
867 VerifySmiField(kAccessFlagsOffset);
871 void AccessCheckInfo::AccessCheckInfoVerify() {
872 CHECK(IsAccessCheckInfo());
873 VerifyPointer(named_callback());
874 VerifyPointer(indexed_callback());
875 VerifyPointer(data());
879 void InterceptorInfo::InterceptorInfoVerify() {
880 CHECK(IsInterceptorInfo());
881 VerifyPointer(getter());
882 VerifyPointer(setter());
883 VerifyPointer(query());
884 VerifyPointer(deleter());
885 VerifyPointer(enumerator());
886 VerifyPointer(data());
890 void CallHandlerInfo::CallHandlerInfoVerify() {
891 CHECK(IsCallHandlerInfo());
892 VerifyPointer(callback());
893 VerifyPointer(data());
897 void TemplateInfo::TemplateInfoVerify() {
898 VerifyPointer(tag());
899 VerifyPointer(property_list());
900 VerifyPointer(property_accessors());
904 void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
905 CHECK(IsFunctionTemplateInfo());
906 TemplateInfoVerify();
907 VerifyPointer(serial_number());
908 VerifyPointer(call_code());
909 VerifyPointer(prototype_template());
910 VerifyPointer(parent_template());
911 VerifyPointer(named_property_handler());
912 VerifyPointer(indexed_property_handler());
913 VerifyPointer(instance_template());
914 VerifyPointer(signature());
915 VerifyPointer(access_check_info());
919 void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
920 CHECK(IsObjectTemplateInfo());
921 TemplateInfoVerify();
922 VerifyPointer(constructor());
923 VerifyPointer(internal_field_count());
927 void SignatureInfo::SignatureInfoVerify() {
928 CHECK(IsSignatureInfo());
929 VerifyPointer(receiver());
930 VerifyPointer(args());
934 void TypeSwitchInfo::TypeSwitchInfoVerify() {
935 CHECK(IsTypeSwitchInfo());
936 VerifyPointer(types());
940 void AllocationSite::AllocationSiteVerify() {
941 CHECK(IsAllocationSite());
945 void AllocationMemento::AllocationMementoVerify() {
946 CHECK(IsAllocationMemento());
947 VerifyHeapPointer(allocation_site());
948 CHECK(!IsValid() || GetAllocationSite()->IsAllocationSite());
952 void Script::ScriptVerify() {
954 VerifyPointer(source());
955 VerifyPointer(name());
956 line_offset()->SmiVerify();
957 column_offset()->SmiVerify();
958 VerifyPointer(wrapper());
960 VerifyPointer(line_ends());
965 void JSFunctionResultCache::JSFunctionResultCacheVerify() {
966 JSFunction::cast(get(kFactoryIndex))->Verify();
968 int size = Smi::cast(get(kCacheSizeIndex))->value();
969 CHECK(kEntriesIndex <= size);
970 CHECK(size <= length());
971 CHECK_EQ(0, size % kEntrySize);
973 int finger = Smi::cast(get(kFingerIndex))->value();
974 CHECK(kEntriesIndex <= finger);
975 CHECK((finger < size) || (finger == kEntriesIndex && finger == size));
976 CHECK_EQ(0, finger % kEntrySize);
978 if (FLAG_enable_slow_asserts) {
979 for (int i = kEntriesIndex; i < size; i++) {
980 CHECK(!get(i)->IsTheHole());
983 for (int i = size; i < length(); i++) {
984 CHECK(get(i)->IsTheHole());
991 void NormalizedMapCache::NormalizedMapCacheVerify() {
992 FixedArray::cast(this)->Verify();
993 if (FLAG_enable_slow_asserts) {
994 for (int i = 0; i < length(); i++) {
997 Map::cast(e)->SharedMapVerify();
999 CHECK(e->IsUndefined());
1006 #ifdef ENABLE_DEBUGGER_SUPPORT
1007 void DebugInfo::DebugInfoVerify() {
1008 CHECK(IsDebugInfo());
1009 VerifyPointer(shared());
1010 VerifyPointer(original_code());
1011 VerifyPointer(code());
1012 VerifyPointer(break_points());
1016 void BreakPointInfo::BreakPointInfoVerify() {
1017 CHECK(IsBreakPointInfo());
1018 code_position()->SmiVerify();
1019 source_position()->SmiVerify();
1020 statement_position()->SmiVerify();
1021 VerifyPointer(break_point_objects());
1023 #endif // ENABLE_DEBUGGER_SUPPORT
1024 #endif // VERIFY_HEAP
1028 void JSObject::IncrementSpillStatistics(SpillInformation* info) {
1029 info->number_of_objects_++;
1031 if (HasFastProperties()) {
1032 info->number_of_objects_with_fast_properties_++;
1033 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
1034 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
1036 NameDictionary* dict = property_dictionary();
1037 info->number_of_slow_used_properties_ += dict->NumberOfElements();
1038 info->number_of_slow_unused_properties_ +=
1039 dict->Capacity() - dict->NumberOfElements();
1041 // Indexed properties
1042 switch (GetElementsKind()) {
1043 case FAST_HOLEY_SMI_ELEMENTS:
1044 case FAST_SMI_ELEMENTS:
1045 case FAST_HOLEY_DOUBLE_ELEMENTS:
1046 case FAST_DOUBLE_ELEMENTS:
1047 case FAST_HOLEY_ELEMENTS:
1048 case FAST_ELEMENTS: {
1049 info->number_of_objects_with_fast_elements_++;
1051 FixedArray* e = FixedArray::cast(elements());
1052 int len = e->length();
1053 Heap* heap = GetHeap();
1054 for (int i = 0; i < len; i++) {
1055 if (e->get(i) == heap->the_hole_value()) holes++;
1057 info->number_of_fast_used_elements_ += len - holes;
1058 info->number_of_fast_unused_elements_ += holes;
1062 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1063 case EXTERNAL_##TYPE##_ELEMENTS: \
1064 case TYPE##_ELEMENTS:
1066 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1067 #undef TYPED_ARRAY_CASE
1068 { info->number_of_objects_with_fast_elements_++;
1069 FixedArrayBase* e = FixedArrayBase::cast(elements());
1070 info->number_of_fast_used_elements_ += e->length();
1073 case DICTIONARY_ELEMENTS: {
1074 SeededNumberDictionary* dict = element_dictionary();
1075 info->number_of_slow_used_elements_ += dict->NumberOfElements();
1076 info->number_of_slow_unused_elements_ +=
1077 dict->Capacity() - dict->NumberOfElements();
1080 case SLOPPY_ARGUMENTS_ELEMENTS:
1086 void JSObject::SpillInformation::Clear() {
1087 number_of_objects_ = 0;
1088 number_of_objects_with_fast_properties_ = 0;
1089 number_of_objects_with_fast_elements_ = 0;
1090 number_of_fast_used_fields_ = 0;
1091 number_of_fast_unused_fields_ = 0;
1092 number_of_slow_used_properties_ = 0;
1093 number_of_slow_unused_properties_ = 0;
1094 number_of_fast_used_elements_ = 0;
1095 number_of_fast_unused_elements_ = 0;
1096 number_of_slow_used_elements_ = 0;
1097 number_of_slow_unused_elements_ = 0;
1101 void JSObject::SpillInformation::Print() {
1102 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
1104 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
1105 number_of_objects_with_fast_properties_,
1106 number_of_fast_used_fields_, number_of_fast_unused_fields_);
1108 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
1109 number_of_objects_ - number_of_objects_with_fast_properties_,
1110 number_of_slow_used_properties_, number_of_slow_unused_properties_);
1112 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
1113 number_of_objects_with_fast_elements_,
1114 number_of_fast_used_elements_, number_of_fast_unused_elements_);
1116 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
1117 number_of_objects_ - number_of_objects_with_fast_elements_,
1118 number_of_slow_used_elements_, number_of_slow_unused_elements_);
1124 bool DescriptorArray::IsSortedNoDuplicates(int valid_entries) {
1125 if (valid_entries == -1) valid_entries = number_of_descriptors();
1126 Name* current_key = NULL;
1127 uint32_t current = 0;
1128 for (int i = 0; i < number_of_descriptors(); i++) {
1129 Name* key = GetSortedKey(i);
1130 if (key == current_key) {
1135 uint32_t hash = GetSortedKey(i)->Hash();
1136 if (hash < current) {
1146 bool TransitionArray::IsSortedNoDuplicates(int valid_entries) {
1147 ASSERT(valid_entries == -1);
1148 Name* current_key = NULL;
1149 uint32_t current = 0;
1150 for (int i = 0; i < number_of_transitions(); i++) {
1151 Name* key = GetSortedKey(i);
1152 if (key == current_key) {
1157 uint32_t hash = GetSortedKey(i)->Hash();
1158 if (hash < current) {
1168 static bool CheckOneBackPointer(Map* current_map, Object* target) {
1169 return !target->IsMap() || Map::cast(target)->GetBackPointer() == current_map;
1173 bool TransitionArray::IsConsistentWithBackPointers(Map* current_map) {
1174 for (int i = 0; i < number_of_transitions(); ++i) {
1175 if (!CheckOneBackPointer(current_map, GetTarget(i))) return false;
1183 } } // namespace v8::internal