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 return (FLAG_use_gvn && FLAG_use_allocation_folding) ||
284 reinterpret_cast<Map*>(elements()) !=
285 GetHeap()->one_pointer_filler_map();
289 void JSObject::JSObjectVerify() {
290 VerifyHeapPointer(properties());
291 VerifyHeapPointer(elements());
293 if (GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS) {
294 CHECK(this->elements()->IsFixedArray());
295 CHECK_GE(this->elements()->length(), 2);
298 if (HasFastProperties()) {
299 CHECK_EQ(map()->unused_property_fields(),
300 (map()->inobject_properties() + properties()->length() -
301 map()->NextFreePropertyIndex()));
302 DescriptorArray* descriptors = map()->instance_descriptors();
303 for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
304 if (descriptors->GetDetails(i).type() == FIELD) {
305 Representation r = descriptors->GetDetails(i).representation();
306 int field = descriptors->GetFieldIndex(i);
307 Object* value = RawFastPropertyAt(field);
308 if (r.IsDouble()) ASSERT(value->IsHeapNumber());
309 if (value->IsUninitialized()) continue;
310 if (r.IsSmi()) ASSERT(value->IsSmi());
311 if (r.IsHeapObject()) ASSERT(value->IsHeapObject());
316 // If a GC was caused while constructing this object, the elements
317 // pointer may point to a one pointer filler map.
318 if (ElementsAreSafeToExamine()) {
319 CHECK_EQ((map()->has_fast_smi_or_object_elements() ||
320 (elements() == GetHeap()->empty_fixed_array())),
321 (elements()->map() == GetHeap()->fixed_array_map() ||
322 elements()->map() == GetHeap()->fixed_cow_array_map()));
323 CHECK(map()->has_fast_object_elements() == HasFastObjectElements());
328 void Map::MapVerify() {
329 Heap* heap = GetHeap();
330 CHECK(!heap->InNewSpace(this));
331 CHECK(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
332 CHECK(instance_size() == kVariableSizeSentinel ||
333 (kPointerSize <= instance_size() &&
334 instance_size() < heap->Capacity()));
335 VerifyHeapPointer(prototype());
336 VerifyHeapPointer(instance_descriptors());
337 SLOW_ASSERT(instance_descriptors()->IsSortedNoDuplicates());
338 if (HasTransitionArray()) {
339 SLOW_ASSERT(transitions()->IsSortedNoDuplicates());
340 SLOW_ASSERT(transitions()->IsConsistentWithBackPointers(this));
345 void Map::SharedMapVerify() {
348 CHECK(instance_descriptors()->IsEmpty());
349 CHECK_EQ(0, pre_allocated_property_fields());
350 CHECK_EQ(0, unused_property_fields());
351 CHECK_EQ(StaticVisitorBase::GetVisitorId(instance_type(), instance_size()),
356 void Map::VerifyOmittedMapChecks() {
357 if (!FLAG_omit_map_checks_for_leaf_maps) return;
360 HasTransitionArray() ||
361 is_dictionary_map()) {
362 CHECK_EQ(0, dependent_code()->number_of_entries(
363 DependentCode::kPrototypeCheckGroup));
368 void CodeCache::CodeCacheVerify() {
369 VerifyHeapPointer(default_cache());
370 VerifyHeapPointer(normal_type_cache());
371 CHECK(default_cache()->IsFixedArray());
372 CHECK(normal_type_cache()->IsUndefined()
373 || normal_type_cache()->IsCodeCacheHashTable());
377 void PolymorphicCodeCache::PolymorphicCodeCacheVerify() {
378 VerifyHeapPointer(cache());
379 CHECK(cache()->IsUndefined() || cache()->IsPolymorphicCodeCacheHashTable());
383 void TypeFeedbackInfo::TypeFeedbackInfoVerify() {
384 VerifyObjectField(kStorage1Offset);
385 VerifyObjectField(kStorage2Offset);
386 VerifyHeapPointer(type_feedback_cells());
390 void AliasedArgumentsEntry::AliasedArgumentsEntryVerify() {
391 VerifySmiField(kAliasedContextSlot);
395 void FixedArray::FixedArrayVerify() {
396 for (int i = 0; i < length(); i++) {
398 if (e->IsHeapObject()) {
399 VerifyHeapPointer(e);
407 void FixedDoubleArray::FixedDoubleArrayVerify() {
408 for (int i = 0; i < length(); i++) {
409 if (!is_the_hole(i)) {
410 double value = get_scalar(i);
411 CHECK(!std::isnan(value) ||
412 (BitCast<uint64_t>(value) ==
413 BitCast<uint64_t>(canonical_not_the_hole_nan_as_double())) ||
414 ((BitCast<uint64_t>(value) & Double::kSignMask) != 0));
420 void ConstantPoolArray::ConstantPoolArrayVerify() {
421 CHECK(IsConstantPoolArray());
425 void JSGeneratorObject::JSGeneratorObjectVerify() {
426 // In an expression like "new g()", there can be a point where a generator
427 // object is allocated but its fields are all undefined, as it hasn't yet been
428 // initialized by the generator. Hence these weak checks.
429 VerifyObjectField(kFunctionOffset);
430 VerifyObjectField(kContextOffset);
431 VerifyObjectField(kReceiverOffset);
432 VerifyObjectField(kOperandStackOffset);
433 VerifyObjectField(kContinuationOffset);
434 VerifyObjectField(kStackHandlerIndexOffset);
438 void JSModule::JSModuleVerify() {
439 VerifyObjectField(kContextOffset);
440 VerifyObjectField(kScopeInfoOffset);
441 CHECK(context()->IsUndefined() ||
442 Context::cast(context())->IsModuleContext());
446 void JSValue::JSValueVerify() {
448 if (v->IsHeapObject()) {
449 VerifyHeapPointer(v);
454 void JSDate::JSDateVerify() {
455 if (value()->IsHeapObject()) {
456 VerifyHeapPointer(value());
458 CHECK(value()->IsUndefined() || value()->IsSmi() || value()->IsHeapNumber());
459 CHECK(year()->IsUndefined() || year()->IsSmi() || year()->IsNaN());
460 CHECK(month()->IsUndefined() || month()->IsSmi() || month()->IsNaN());
461 CHECK(day()->IsUndefined() || day()->IsSmi() || day()->IsNaN());
462 CHECK(weekday()->IsUndefined() || weekday()->IsSmi() || weekday()->IsNaN());
463 CHECK(hour()->IsUndefined() || hour()->IsSmi() || hour()->IsNaN());
464 CHECK(min()->IsUndefined() || min()->IsSmi() || min()->IsNaN());
465 CHECK(sec()->IsUndefined() || sec()->IsSmi() || sec()->IsNaN());
466 CHECK(cache_stamp()->IsUndefined() ||
467 cache_stamp()->IsSmi() ||
468 cache_stamp()->IsNaN());
470 if (month()->IsSmi()) {
471 int month = Smi::cast(this->month())->value();
472 CHECK(0 <= month && month <= 11);
474 if (day()->IsSmi()) {
475 int day = Smi::cast(this->day())->value();
476 CHECK(1 <= day && day <= 31);
478 if (hour()->IsSmi()) {
479 int hour = Smi::cast(this->hour())->value();
480 CHECK(0 <= hour && hour <= 23);
482 if (min()->IsSmi()) {
483 int min = Smi::cast(this->min())->value();
484 CHECK(0 <= min && min <= 59);
486 if (sec()->IsSmi()) {
487 int sec = Smi::cast(this->sec())->value();
488 CHECK(0 <= sec && sec <= 59);
490 if (weekday()->IsSmi()) {
491 int weekday = Smi::cast(this->weekday())->value();
492 CHECK(0 <= weekday && weekday <= 6);
494 if (cache_stamp()->IsSmi()) {
495 CHECK(Smi::cast(cache_stamp())->value() <=
496 Smi::cast(GetIsolate()->date_cache()->stamp())->value());
501 void JSMessageObject::JSMessageObjectVerify() {
502 CHECK(IsJSMessageObject());
503 CHECK(type()->IsString());
504 CHECK(arguments()->IsJSArray());
505 VerifyObjectField(kStartPositionOffset);
506 VerifyObjectField(kEndPositionOffset);
507 VerifyObjectField(kArgumentsOffset);
508 VerifyObjectField(kScriptOffset);
509 VerifyObjectField(kStackTraceOffset);
510 VerifyObjectField(kStackFramesOffset);
514 void String::StringVerify() {
516 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
517 if (IsInternalizedString()) {
518 CHECK(!GetHeap()->InNewSpace(this));
520 if (IsConsString()) {
521 ConsString::cast(this)->ConsStringVerify();
522 } else if (IsSlicedString()) {
523 SlicedString::cast(this)->SlicedStringVerify();
528 void ConsString::ConsStringVerify() {
529 CHECK(this->first()->IsString());
530 CHECK(this->second() == GetHeap()->empty_string() ||
531 this->second()->IsString());
532 CHECK(this->length() >= ConsString::kMinLength);
533 if (this->IsFlat()) {
534 // A flat cons can only be created by String::SlowTryFlatten.
535 // Afterwards, the first part may be externalized.
536 CHECK(this->first()->IsSeqString() || this->first()->IsExternalString());
541 void SlicedString::SlicedStringVerify() {
542 CHECK(!this->parent()->IsConsString());
543 CHECK(!this->parent()->IsSlicedString());
544 CHECK(this->length() >= SlicedString::kMinLength);
548 void JSFunction::JSFunctionVerify() {
549 CHECK(IsJSFunction());
550 VerifyObjectField(kPrototypeOrInitialMapOffset);
551 VerifyObjectField(kNextFunctionLinkOffset);
552 CHECK(code()->IsCode());
553 CHECK(next_function_link() == NULL ||
554 next_function_link()->IsUndefined() ||
555 next_function_link()->IsJSFunction());
559 void SharedFunctionInfo::SharedFunctionInfoVerify() {
560 CHECK(IsSharedFunctionInfo());
561 VerifyObjectField(kNameOffset);
562 VerifyObjectField(kCodeOffset);
563 VerifyObjectField(kOptimizedCodeMapOffset);
564 VerifyObjectField(kScopeInfoOffset);
565 VerifyObjectField(kInstanceClassNameOffset);
566 VerifyObjectField(kFunctionDataOffset);
567 VerifyObjectField(kScriptOffset);
568 VerifyObjectField(kDebugInfoOffset);
572 void JSGlobalProxy::JSGlobalProxyVerify() {
573 CHECK(IsJSGlobalProxy());
575 VerifyObjectField(JSGlobalProxy::kNativeContextOffset);
576 // Make sure that this object has no properties, elements.
577 CHECK_EQ(0, properties()->length());
578 CHECK(HasFastObjectElements());
579 CHECK_EQ(0, FixedArray::cast(elements())->length());
583 void JSGlobalObject::JSGlobalObjectVerify() {
584 CHECK(IsJSGlobalObject());
586 for (int i = GlobalObject::kBuiltinsOffset;
587 i < JSGlobalObject::kSize;
589 VerifyObjectField(i);
594 void JSBuiltinsObject::JSBuiltinsObjectVerify() {
595 CHECK(IsJSBuiltinsObject());
597 for (int i = GlobalObject::kBuiltinsOffset;
598 i < JSBuiltinsObject::kSize;
600 VerifyObjectField(i);
605 void Oddball::OddballVerify() {
607 VerifyHeapPointer(to_string());
608 Object* number = to_number();
609 if (number->IsHeapObject()) {
610 CHECK(number == HeapObject::cast(number)->GetHeap()->nan_value());
612 CHECK(number->IsSmi());
613 int value = Smi::cast(number)->value();
614 // Hidden oddballs have negative smis.
615 const int kLeastHiddenOddballNumber = -4;
617 CHECK(value >= kLeastHiddenOddballNumber);
622 void Cell::CellVerify() {
624 VerifyObjectField(kValueOffset);
628 void PropertyCell::PropertyCellVerify() {
629 CHECK(IsPropertyCell());
630 VerifyObjectField(kValueOffset);
631 VerifyObjectField(kTypeOffset);
635 void Code::CodeVerify() {
636 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
638 relocation_info()->Verify();
639 Address last_gc_pc = NULL;
640 for (RelocIterator it(this); !it.done(); it.next()) {
641 it.rinfo()->Verify();
642 // Ensure that GC will not iterate twice over the same pointer.
643 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
644 CHECK(it.rinfo()->pc() != last_gc_pc);
645 last_gc_pc = it.rinfo()->pc();
651 void Code::VerifyEmbeddedObjectsDependency() {
652 int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT);
653 for (RelocIterator it(this, mode_mask); !it.done(); it.next()) {
654 Object* obj = it.rinfo()->target_object();
655 if (IsWeakEmbeddedObject(kind(), obj)) {
657 Map* map = Map::cast(obj);
658 CHECK(map->dependent_code()->Contains(
659 DependentCode::kWeaklyEmbeddedGroup, this));
660 } else if (obj->IsJSObject()) {
661 Object* raw_table = GetIsolate()->heap()->weak_object_to_code_table();
662 WeakHashTable* table = WeakHashTable::cast(raw_table);
663 CHECK(DependentCode::cast(table->Lookup(obj))->Contains(
664 DependentCode::kWeaklyEmbeddedGroup, this));
671 void JSArray::JSArrayVerify() {
673 CHECK(length()->IsNumber() || length()->IsUndefined());
674 // If a GC was caused while constructing this array, the elements
675 // pointer may point to a one pointer filler map.
676 if (ElementsAreSafeToExamine()) {
677 CHECK(elements()->IsUndefined() ||
678 elements()->IsFixedArray() ||
679 elements()->IsFixedDoubleArray());
684 void JSSet::JSSetVerify() {
687 VerifyHeapPointer(table());
688 CHECK(table()->IsHashTable() || table()->IsUndefined());
692 void JSMap::JSMapVerify() {
695 VerifyHeapPointer(table());
696 CHECK(table()->IsHashTable() || table()->IsUndefined());
700 void JSWeakMap::JSWeakMapVerify() {
701 CHECK(IsJSWeakMap());
703 VerifyHeapPointer(table());
704 CHECK(table()->IsHashTable() || table()->IsUndefined());
708 void JSWeakSet::JSWeakSetVerify() {
709 CHECK(IsJSWeakSet());
711 VerifyHeapPointer(table());
712 CHECK(table()->IsHashTable() || table()->IsUndefined());
716 void JSRegExp::JSRegExpVerify() {
718 CHECK(data()->IsUndefined() || data()->IsFixedArray());
720 case JSRegExp::ATOM: {
721 FixedArray* arr = FixedArray::cast(data());
722 CHECK(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
725 case JSRegExp::IRREGEXP: {
726 bool is_native = RegExpImpl::UsesNativeRegExp();
728 FixedArray* arr = FixedArray::cast(data());
729 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
730 // Smi : Not compiled yet (-1) or code prepared for flushing.
731 // JSObject: Compilation error.
732 // Code/ByteArray: Compiled code.
733 CHECK(ascii_data->IsSmi() ||
734 (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray()));
735 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
736 CHECK(uc16_data->IsSmi() ||
737 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
739 Object* ascii_saved = arr->get(JSRegExp::kIrregexpASCIICodeSavedIndex);
740 CHECK(ascii_saved->IsSmi() || ascii_saved->IsString() ||
741 ascii_saved->IsCode());
742 Object* uc16_saved = arr->get(JSRegExp::kIrregexpUC16CodeSavedIndex);
743 CHECK(uc16_saved->IsSmi() || uc16_saved->IsString() ||
744 uc16_saved->IsCode());
746 CHECK(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
747 CHECK(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
751 CHECK_EQ(JSRegExp::NOT_COMPILED, TypeTag());
752 CHECK(data()->IsUndefined());
758 void JSProxy::JSProxyVerify() {
760 VerifyPointer(handler());
761 CHECK(hash()->IsSmi() || hash()->IsUndefined());
765 void JSFunctionProxy::JSFunctionProxyVerify() {
766 CHECK(IsJSFunctionProxy());
768 VerifyPointer(call_trap());
769 VerifyPointer(construct_trap());
773 void JSArrayBuffer::JSArrayBufferVerify() {
774 CHECK(IsJSArrayBuffer());
776 VerifyPointer(byte_length());
777 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
778 || byte_length()->IsUndefined());
782 void JSArrayBufferView::JSArrayBufferViewVerify() {
783 CHECK(IsJSArrayBufferView());
785 VerifyPointer(buffer());
786 CHECK(buffer()->IsJSArrayBuffer() || buffer()->IsUndefined());
788 VerifyPointer(byte_offset());
789 CHECK(byte_offset()->IsSmi() || byte_offset()->IsHeapNumber()
790 || byte_offset()->IsUndefined());
792 VerifyPointer(byte_length());
793 CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber()
794 || byte_length()->IsUndefined());
798 void JSTypedArray::JSTypedArrayVerify() {
799 CHECK(IsJSTypedArray());
800 JSArrayBufferViewVerify();
801 VerifyPointer(length());
802 CHECK(length()->IsSmi() || length()->IsHeapNumber()
803 || length()->IsUndefined());
805 VerifyPointer(elements());
809 void JSDataView::JSDataViewVerify() {
810 CHECK(IsJSDataView());
811 JSArrayBufferViewVerify();
815 void Foreign::ForeignVerify() {
820 void Box::BoxVerify() {
826 void AccessorInfo::AccessorInfoVerify() {
827 VerifyPointer(name());
828 VerifyPointer(flag());
829 VerifyPointer(expected_receiver_type());
833 void ExecutableAccessorInfo::ExecutableAccessorInfoVerify() {
834 CHECK(IsExecutableAccessorInfo());
835 AccessorInfoVerify();
836 VerifyPointer(getter());
837 VerifyPointer(setter());
838 VerifyPointer(data());
842 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorVerify() {
843 CHECK(IsDeclaredAccessorDescriptor());
844 VerifyPointer(serialized_data());
848 void DeclaredAccessorInfo::DeclaredAccessorInfoVerify() {
849 CHECK(IsDeclaredAccessorInfo());
850 AccessorInfoVerify();
851 VerifyPointer(descriptor());
855 void AccessorPair::AccessorPairVerify() {
856 CHECK(IsAccessorPair());
857 VerifyPointer(getter());
858 VerifyPointer(setter());
859 VerifySmiField(kAccessFlagsOffset);
863 void AccessCheckInfo::AccessCheckInfoVerify() {
864 CHECK(IsAccessCheckInfo());
865 VerifyPointer(named_callback());
866 VerifyPointer(indexed_callback());
867 VerifyPointer(data());
871 void InterceptorInfo::InterceptorInfoVerify() {
872 CHECK(IsInterceptorInfo());
873 VerifyPointer(getter());
874 VerifyPointer(setter());
875 VerifyPointer(query());
876 VerifyPointer(deleter());
877 VerifyPointer(enumerator());
878 VerifyPointer(data());
882 void CallHandlerInfo::CallHandlerInfoVerify() {
883 CHECK(IsCallHandlerInfo());
884 VerifyPointer(callback());
885 VerifyPointer(data());
889 void TemplateInfo::TemplateInfoVerify() {
890 VerifyPointer(tag());
891 VerifyPointer(property_list());
892 VerifyPointer(property_accessors());
896 void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
897 CHECK(IsFunctionTemplateInfo());
898 TemplateInfoVerify();
899 VerifyPointer(serial_number());
900 VerifyPointer(call_code());
901 VerifyPointer(prototype_template());
902 VerifyPointer(parent_template());
903 VerifyPointer(named_property_handler());
904 VerifyPointer(indexed_property_handler());
905 VerifyPointer(instance_template());
906 VerifyPointer(signature());
907 VerifyPointer(access_check_info());
911 void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
912 CHECK(IsObjectTemplateInfo());
913 TemplateInfoVerify();
914 VerifyPointer(constructor());
915 VerifyPointer(internal_field_count());
919 void SignatureInfo::SignatureInfoVerify() {
920 CHECK(IsSignatureInfo());
921 VerifyPointer(receiver());
922 VerifyPointer(args());
926 void TypeSwitchInfo::TypeSwitchInfoVerify() {
927 CHECK(IsTypeSwitchInfo());
928 VerifyPointer(types());
932 void AllocationSite::AllocationSiteVerify() {
933 CHECK(IsAllocationSite());
937 void AllocationMemento::AllocationMementoVerify() {
938 CHECK(IsAllocationMemento());
939 VerifyHeapPointer(allocation_site());
940 CHECK(!IsValid() || GetAllocationSite()->IsAllocationSite());
944 void Script::ScriptVerify() {
946 VerifyPointer(source());
947 VerifyPointer(name());
948 line_offset()->SmiVerify();
949 column_offset()->SmiVerify();
950 VerifyPointer(data());
951 VerifyPointer(wrapper());
953 VerifyPointer(line_ends());
958 void JSFunctionResultCache::JSFunctionResultCacheVerify() {
959 JSFunction::cast(get(kFactoryIndex))->Verify();
961 int size = Smi::cast(get(kCacheSizeIndex))->value();
962 CHECK(kEntriesIndex <= size);
963 CHECK(size <= length());
964 CHECK_EQ(0, size % kEntrySize);
966 int finger = Smi::cast(get(kFingerIndex))->value();
967 CHECK(kEntriesIndex <= finger);
968 CHECK((finger < size) || (finger == kEntriesIndex && finger == size));
969 CHECK_EQ(0, finger % kEntrySize);
971 if (FLAG_enable_slow_asserts) {
972 for (int i = kEntriesIndex; i < size; i++) {
973 CHECK(!get(i)->IsTheHole());
976 for (int i = size; i < length(); i++) {
977 CHECK(get(i)->IsTheHole());
984 void NormalizedMapCache::NormalizedMapCacheVerify() {
985 FixedArray::cast(this)->Verify();
986 if (FLAG_enable_slow_asserts) {
987 for (int i = 0; i < length(); i++) {
990 Map::cast(e)->SharedMapVerify();
992 CHECK(e->IsUndefined());
999 #ifdef ENABLE_DEBUGGER_SUPPORT
1000 void DebugInfo::DebugInfoVerify() {
1001 CHECK(IsDebugInfo());
1002 VerifyPointer(shared());
1003 VerifyPointer(original_code());
1004 VerifyPointer(code());
1005 VerifyPointer(break_points());
1009 void BreakPointInfo::BreakPointInfoVerify() {
1010 CHECK(IsBreakPointInfo());
1011 code_position()->SmiVerify();
1012 source_position()->SmiVerify();
1013 statement_position()->SmiVerify();
1014 VerifyPointer(break_point_objects());
1016 #endif // ENABLE_DEBUGGER_SUPPORT
1017 #endif // VERIFY_HEAP
1021 void JSObject::IncrementSpillStatistics(SpillInformation* info) {
1022 info->number_of_objects_++;
1024 if (HasFastProperties()) {
1025 info->number_of_objects_with_fast_properties_++;
1026 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
1027 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
1029 NameDictionary* dict = property_dictionary();
1030 info->number_of_slow_used_properties_ += dict->NumberOfElements();
1031 info->number_of_slow_unused_properties_ +=
1032 dict->Capacity() - dict->NumberOfElements();
1034 // Indexed properties
1035 switch (GetElementsKind()) {
1036 case FAST_HOLEY_SMI_ELEMENTS:
1037 case FAST_SMI_ELEMENTS:
1038 case FAST_HOLEY_DOUBLE_ELEMENTS:
1039 case FAST_DOUBLE_ELEMENTS:
1040 case FAST_HOLEY_ELEMENTS:
1041 case FAST_ELEMENTS: {
1042 info->number_of_objects_with_fast_elements_++;
1044 FixedArray* e = FixedArray::cast(elements());
1045 int len = e->length();
1046 Heap* heap = GetHeap();
1047 for (int i = 0; i < len; i++) {
1048 if (e->get(i) == heap->the_hole_value()) holes++;
1050 info->number_of_fast_used_elements_ += len - holes;
1051 info->number_of_fast_unused_elements_ += holes;
1055 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
1056 case EXTERNAL_##TYPE##_ELEMENTS: \
1057 case TYPE##_ELEMENTS:
1059 TYPED_ARRAYS(TYPED_ARRAY_CASE)
1060 #undef TYPED_ARRAY_CASE
1061 { info->number_of_objects_with_fast_elements_++;
1062 FixedArrayBase* e = FixedArrayBase::cast(elements());
1063 info->number_of_fast_used_elements_ += e->length();
1066 case DICTIONARY_ELEMENTS: {
1067 SeededNumberDictionary* dict = element_dictionary();
1068 info->number_of_slow_used_elements_ += dict->NumberOfElements();
1069 info->number_of_slow_unused_elements_ +=
1070 dict->Capacity() - dict->NumberOfElements();
1073 case NON_STRICT_ARGUMENTS_ELEMENTS:
1079 void JSObject::SpillInformation::Clear() {
1080 number_of_objects_ = 0;
1081 number_of_objects_with_fast_properties_ = 0;
1082 number_of_objects_with_fast_elements_ = 0;
1083 number_of_fast_used_fields_ = 0;
1084 number_of_fast_unused_fields_ = 0;
1085 number_of_slow_used_properties_ = 0;
1086 number_of_slow_unused_properties_ = 0;
1087 number_of_fast_used_elements_ = 0;
1088 number_of_fast_unused_elements_ = 0;
1089 number_of_slow_used_elements_ = 0;
1090 number_of_slow_unused_elements_ = 0;
1094 void JSObject::SpillInformation::Print() {
1095 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
1097 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
1098 number_of_objects_with_fast_properties_,
1099 number_of_fast_used_fields_, number_of_fast_unused_fields_);
1101 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
1102 number_of_objects_ - number_of_objects_with_fast_properties_,
1103 number_of_slow_used_properties_, number_of_slow_unused_properties_);
1105 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
1106 number_of_objects_with_fast_elements_,
1107 number_of_fast_used_elements_, number_of_fast_unused_elements_);
1109 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
1110 number_of_objects_ - number_of_objects_with_fast_elements_,
1111 number_of_slow_used_elements_, number_of_slow_unused_elements_);
1117 bool DescriptorArray::IsSortedNoDuplicates(int valid_entries) {
1118 if (valid_entries == -1) valid_entries = number_of_descriptors();
1119 Name* current_key = NULL;
1120 uint32_t current = 0;
1121 for (int i = 0; i < number_of_descriptors(); i++) {
1122 Name* key = GetSortedKey(i);
1123 if (key == current_key) {
1128 uint32_t hash = GetSortedKey(i)->Hash();
1129 if (hash < current) {
1139 bool TransitionArray::IsSortedNoDuplicates(int valid_entries) {
1140 ASSERT(valid_entries == -1);
1141 Name* current_key = NULL;
1142 uint32_t current = 0;
1143 for (int i = 0; i < number_of_transitions(); i++) {
1144 Name* key = GetSortedKey(i);
1145 if (key == current_key) {
1150 uint32_t hash = GetSortedKey(i)->Hash();
1151 if (hash < current) {
1161 static bool CheckOneBackPointer(Map* current_map, Object* target) {
1162 return !target->IsMap() || Map::cast(target)->GetBackPointer() == current_map;
1166 bool TransitionArray::IsConsistentWithBackPointers(Map* current_map) {
1167 for (int i = 0; i < number_of_transitions(); ++i) {
1168 if (!CheckOneBackPointer(current_map, GetTarget(i))) return false;
1176 } } // namespace v8::internal