Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 4 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 5 | #include "src/v8.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 6 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 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" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 13 | |
| 14 | namespace v8 { |
| 15 | namespace internal { |
| 16 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 17 | #ifdef VERIFY_HEAP |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 18 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 19 | void Object::ObjectVerify() { |
| 20 | if (IsSmi()) { |
| 21 | Smi::cast(this)->SmiVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 22 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 23 | HeapObject::cast(this)->HeapObjectVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 24 | } |
| 25 | } |
| 26 | |
| 27 | |
| 28 | void Object::VerifyPointer(Object* p) { |
| 29 | if (p->IsHeapObject()) { |
| 30 | HeapObject::VerifyHeapPointer(p); |
| 31 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 32 | CHECK(p->IsSmi()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
| 36 | |
| 37 | void Smi::SmiVerify() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 38 | CHECK(IsSmi()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 42 | void HeapObject::HeapObjectVerify() { |
| 43 | InstanceType instance_type = map()->instance_type(); |
| 44 | |
| 45 | if (instance_type < FIRST_NONSTRING_TYPE) { |
| 46 | String::cast(this)->StringVerify(); |
| 47 | return; |
| 48 | } |
| 49 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 50 | // TODO(yangguo): Use this check once crbug/436911 has been fixed. |
| 51 | // DCHECK(!NeedsToEnsureDoubleAlignment() || |
| 52 | // IsAligned(OffsetFrom(address()), kDoubleAlignment)); |
| 53 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 54 | switch (instance_type) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 55 | case SYMBOL_TYPE: |
| 56 | Symbol::cast(this)->SymbolVerify(); |
| 57 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 58 | case MAP_TYPE: |
| 59 | Map::cast(this)->MapVerify(); |
| 60 | break; |
| 61 | case HEAP_NUMBER_TYPE: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 62 | case MUTABLE_HEAP_NUMBER_TYPE: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 63 | HeapNumber::cast(this)->HeapNumberVerify(); |
| 64 | break; |
| 65 | case FIXED_ARRAY_TYPE: |
| 66 | FixedArray::cast(this)->FixedArrayVerify(); |
| 67 | break; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 68 | case FIXED_DOUBLE_ARRAY_TYPE: |
| 69 | FixedDoubleArray::cast(this)->FixedDoubleArrayVerify(); |
| 70 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 71 | case CONSTANT_POOL_ARRAY_TYPE: |
| 72 | ConstantPoolArray::cast(this)->ConstantPoolArrayVerify(); |
| 73 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 74 | case BYTE_ARRAY_TYPE: |
| 75 | ByteArray::cast(this)->ByteArrayVerify(); |
| 76 | break; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 77 | case FREE_SPACE_TYPE: |
| 78 | FreeSpace::cast(this)->FreeSpaceVerify(); |
| 79 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 80 | |
| 81 | #define VERIFY_TYPED_ARRAY(Type, type, TYPE, ctype, size) \ |
| 82 | case EXTERNAL_##TYPE##_ARRAY_TYPE: \ |
| 83 | External##Type##Array::cast(this)->External##Type##ArrayVerify(); \ |
| 84 | break; \ |
| 85 | case FIXED_##TYPE##_ARRAY_TYPE: \ |
| 86 | Fixed##Type##Array::cast(this)->FixedTypedArrayVerify(); \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 87 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 88 | |
| 89 | TYPED_ARRAYS(VERIFY_TYPED_ARRAY) |
| 90 | #undef VERIFY_TYPED_ARRAY |
| 91 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 92 | case CODE_TYPE: |
| 93 | Code::cast(this)->CodeVerify(); |
| 94 | break; |
| 95 | case ODDBALL_TYPE: |
| 96 | Oddball::cast(this)->OddballVerify(); |
| 97 | break; |
| 98 | case JS_OBJECT_TYPE: |
| 99 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
| 100 | JSObject::cast(this)->JSObjectVerify(); |
| 101 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 102 | case JS_GENERATOR_OBJECT_TYPE: |
| 103 | JSGeneratorObject::cast(this)->JSGeneratorObjectVerify(); |
| 104 | break; |
| 105 | case JS_MODULE_TYPE: |
| 106 | JSModule::cast(this)->JSModuleVerify(); |
| 107 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 108 | case JS_VALUE_TYPE: |
| 109 | JSValue::cast(this)->JSValueVerify(); |
| 110 | break; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 111 | case JS_DATE_TYPE: |
| 112 | JSDate::cast(this)->JSDateVerify(); |
| 113 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 114 | case JS_FUNCTION_TYPE: |
| 115 | JSFunction::cast(this)->JSFunctionVerify(); |
| 116 | break; |
| 117 | case JS_GLOBAL_PROXY_TYPE: |
| 118 | JSGlobalProxy::cast(this)->JSGlobalProxyVerify(); |
| 119 | break; |
| 120 | case JS_GLOBAL_OBJECT_TYPE: |
| 121 | JSGlobalObject::cast(this)->JSGlobalObjectVerify(); |
| 122 | break; |
| 123 | case JS_BUILTINS_OBJECT_TYPE: |
| 124 | JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify(); |
| 125 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 126 | case CELL_TYPE: |
| 127 | Cell::cast(this)->CellVerify(); |
| 128 | break; |
| 129 | case PROPERTY_CELL_TYPE: |
| 130 | PropertyCell::cast(this)->PropertyCellVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 131 | break; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 132 | case WEAK_CELL_TYPE: |
| 133 | WeakCell::cast(this)->WeakCellVerify(); |
| 134 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 135 | case JS_ARRAY_TYPE: |
| 136 | JSArray::cast(this)->JSArrayVerify(); |
| 137 | break; |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 138 | case JS_SET_TYPE: |
| 139 | JSSet::cast(this)->JSSetVerify(); |
| 140 | break; |
| 141 | case JS_MAP_TYPE: |
| 142 | JSMap::cast(this)->JSMapVerify(); |
| 143 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 144 | case JS_SET_ITERATOR_TYPE: |
| 145 | JSSetIterator::cast(this)->JSSetIteratorVerify(); |
| 146 | break; |
| 147 | case JS_MAP_ITERATOR_TYPE: |
| 148 | JSMapIterator::cast(this)->JSMapIteratorVerify(); |
| 149 | break; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 150 | case JS_WEAK_MAP_TYPE: |
| 151 | JSWeakMap::cast(this)->JSWeakMapVerify(); |
| 152 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 153 | case JS_WEAK_SET_TYPE: |
| 154 | JSWeakSet::cast(this)->JSWeakSetVerify(); |
| 155 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 156 | case JS_REGEXP_TYPE: |
| 157 | JSRegExp::cast(this)->JSRegExpVerify(); |
| 158 | break; |
| 159 | case FILLER_TYPE: |
| 160 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 161 | case JS_PROXY_TYPE: |
| 162 | JSProxy::cast(this)->JSProxyVerify(); |
| 163 | break; |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 164 | case JS_FUNCTION_PROXY_TYPE: |
| 165 | JSFunctionProxy::cast(this)->JSFunctionProxyVerify(); |
| 166 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 167 | case FOREIGN_TYPE: |
| 168 | Foreign::cast(this)->ForeignVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 169 | break; |
| 170 | case SHARED_FUNCTION_INFO_TYPE: |
| 171 | SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify(); |
| 172 | break; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 173 | case JS_MESSAGE_OBJECT_TYPE: |
| 174 | JSMessageObject::cast(this)->JSMessageObjectVerify(); |
| 175 | break; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 176 | case JS_ARRAY_BUFFER_TYPE: |
| 177 | JSArrayBuffer::cast(this)->JSArrayBufferVerify(); |
| 178 | break; |
| 179 | case JS_TYPED_ARRAY_TYPE: |
| 180 | JSTypedArray::cast(this)->JSTypedArrayVerify(); |
| 181 | break; |
| 182 | case JS_DATA_VIEW_TYPE: |
| 183 | JSDataView::cast(this)->JSDataViewVerify(); |
| 184 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 185 | |
| 186 | #define MAKE_STRUCT_CASE(NAME, Name, name) \ |
| 187 | case NAME##_TYPE: \ |
| 188 | Name::cast(this)->Name##Verify(); \ |
| 189 | break; |
| 190 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 191 | #undef MAKE_STRUCT_CASE |
| 192 | |
| 193 | default: |
| 194 | UNREACHABLE(); |
| 195 | break; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | |
| 200 | void HeapObject::VerifyHeapPointer(Object* p) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 201 | CHECK(p->IsHeapObject()); |
| 202 | HeapObject* ho = HeapObject::cast(p); |
| 203 | CHECK(ho->GetHeap()->Contains(ho)); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | void Symbol::SymbolVerify() { |
| 208 | CHECK(IsSymbol()); |
| 209 | CHECK(HasHashCode()); |
| 210 | CHECK_GT(Hash(), 0); |
| 211 | CHECK(name()->IsUndefined() || name()->IsString()); |
| 212 | CHECK(flags()->IsSmi()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | |
| 216 | void HeapNumber::HeapNumberVerify() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 217 | CHECK(IsHeapNumber() || IsMutableHeapNumber()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 221 | void ByteArray::ByteArrayVerify() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 222 | CHECK(IsByteArray()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 226 | void FreeSpace::FreeSpaceVerify() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 227 | CHECK(IsFreeSpace()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 231 | #define EXTERNAL_ARRAY_VERIFY(Type, type, TYPE, ctype, size) \ |
| 232 | void External##Type##Array::External##Type##ArrayVerify() { \ |
| 233 | CHECK(IsExternal##Type##Array()); \ |
| 234 | } |
| 235 | |
| 236 | TYPED_ARRAYS(EXTERNAL_ARRAY_VERIFY) |
| 237 | #undef EXTERNAL_ARRAY_VERIFY |
| 238 | |
| 239 | |
| 240 | template <class Traits> |
| 241 | void FixedTypedArray<Traits>::FixedTypedArrayVerify() { |
| 242 | CHECK(IsHeapObject() && |
| 243 | HeapObject::cast(this)->map()->instance_type() == |
| 244 | Traits::kInstanceType); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 248 | bool JSObject::ElementsAreSafeToExamine() { |
| 249 | // If a GC was caused while constructing this object, the elements |
| 250 | // pointer may point to a one pointer filler map. |
| 251 | return reinterpret_cast<Map*>(elements()) != |
| 252 | GetHeap()->one_pointer_filler_map(); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 256 | void JSObject::JSObjectVerify() { |
| 257 | VerifyHeapPointer(properties()); |
| 258 | VerifyHeapPointer(elements()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 259 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 260 | if (GetElementsKind() == SLOPPY_ARGUMENTS_ELEMENTS) { |
| 261 | CHECK(this->elements()->IsFixedArray()); |
| 262 | CHECK_GE(this->elements()->length(), 2); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 265 | if (HasFastProperties()) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 266 | int actual_unused_property_fields = map()->inobject_properties() + |
| 267 | properties()->length() - |
| 268 | map()->NextFreePropertyIndex(); |
| 269 | if (map()->unused_property_fields() != actual_unused_property_fields) { |
| 270 | // This could actually happen in the middle of StoreTransitionStub |
| 271 | // when the new extended backing store is already set into the object and |
| 272 | // the allocation of the MutableHeapNumber triggers GC (in this case map |
| 273 | // is not updated yet). |
| 274 | CHECK_EQ(map()->unused_property_fields(), |
| 275 | actual_unused_property_fields - JSObject::kFieldsAdded); |
| 276 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 277 | DescriptorArray* descriptors = map()->instance_descriptors(); |
| 278 | for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) { |
| 279 | if (descriptors->GetDetails(i).type() == FIELD) { |
| 280 | Representation r = descriptors->GetDetails(i).representation(); |
| 281 | FieldIndex index = FieldIndex::ForDescriptor(map(), i); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 282 | if (IsUnboxedDoubleField(index)) { |
| 283 | DCHECK(r.IsDouble()); |
| 284 | continue; |
| 285 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 286 | Object* value = RawFastPropertyAt(index); |
| 287 | if (r.IsDouble()) DCHECK(value->IsMutableHeapNumber()); |
| 288 | if (value->IsUninitialized()) continue; |
| 289 | if (r.IsSmi()) DCHECK(value->IsSmi()); |
| 290 | if (r.IsHeapObject()) DCHECK(value->IsHeapObject()); |
| 291 | HeapType* field_type = descriptors->GetFieldType(i); |
| 292 | if (r.IsNone()) { |
| 293 | CHECK(field_type->Is(HeapType::None())); |
| 294 | } else if (!HeapType::Any()->Is(field_type)) { |
| 295 | CHECK(!field_type->NowStable() || field_type->NowContains(value)); |
| 296 | } |
| 297 | } |
| 298 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 300 | |
| 301 | // If a GC was caused while constructing this object, the elements |
| 302 | // pointer may point to a one pointer filler map. |
| 303 | if (ElementsAreSafeToExamine()) { |
| 304 | CHECK_EQ((map()->has_fast_smi_or_object_elements() || |
| 305 | (elements() == GetHeap()->empty_fixed_array())), |
| 306 | (elements()->map() == GetHeap()->fixed_array_map() || |
| 307 | elements()->map() == GetHeap()->fixed_cow_array_map())); |
| 308 | CHECK(map()->has_fast_object_elements() == HasFastObjectElements()); |
| 309 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 313 | void Map::MapVerify() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 314 | Heap* heap = GetHeap(); |
| 315 | CHECK(!heap->InNewSpace(this)); |
| 316 | CHECK(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE); |
| 317 | CHECK(instance_size() == kVariableSizeSentinel || |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 318 | (kPointerSize <= instance_size() && |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 319 | instance_size() < heap->Capacity())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 320 | VerifyHeapPointer(prototype()); |
| 321 | VerifyHeapPointer(instance_descriptors()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 322 | SLOW_DCHECK(instance_descriptors()->IsSortedNoDuplicates()); |
| 323 | if (HasTransitionArray()) { |
| 324 | SLOW_DCHECK(transitions()->IsSortedNoDuplicates()); |
| 325 | SLOW_DCHECK(transitions()->IsConsistentWithBackPointers(this)); |
| 326 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 327 | SLOW_DCHECK(!FLAG_unbox_double_fields || |
| 328 | layout_descriptor()->IsConsistentWithMap(this)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 332 | void Map::DictionaryMapVerify() { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 333 | MapVerify(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 334 | CHECK(is_dictionary_map()); |
| 335 | CHECK(instance_descriptors()->IsEmpty()); |
| 336 | CHECK_EQ(0, pre_allocated_property_fields()); |
| 337 | CHECK_EQ(0, unused_property_fields()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 338 | CHECK_EQ(StaticVisitorBase::GetVisitorId(this), visitor_id()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 342 | void Map::VerifyOmittedMapChecks() { |
| 343 | if (!FLAG_omit_map_checks_for_leaf_maps) return; |
| 344 | if (!is_stable() || |
| 345 | is_deprecated() || |
| 346 | HasTransitionArray() || |
| 347 | is_dictionary_map()) { |
| 348 | CHECK_EQ(0, dependent_code()->number_of_entries( |
| 349 | DependentCode::kPrototypeCheckGroup)); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 354 | void CodeCache::CodeCacheVerify() { |
| 355 | VerifyHeapPointer(default_cache()); |
| 356 | VerifyHeapPointer(normal_type_cache()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 357 | CHECK(default_cache()->IsFixedArray()); |
| 358 | CHECK(normal_type_cache()->IsUndefined() |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 359 | || normal_type_cache()->IsCodeCacheHashTable()); |
| 360 | } |
| 361 | |
| 362 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 363 | void PolymorphicCodeCache::PolymorphicCodeCacheVerify() { |
| 364 | VerifyHeapPointer(cache()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 365 | CHECK(cache()->IsUndefined() || cache()->IsPolymorphicCodeCacheHashTable()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 369 | void TypeFeedbackInfo::TypeFeedbackInfoVerify() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 370 | VerifyObjectField(kStorage1Offset); |
| 371 | VerifyObjectField(kStorage2Offset); |
| 372 | VerifyObjectField(kStorage3Offset); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | |
| 376 | void AliasedArgumentsEntry::AliasedArgumentsEntryVerify() { |
| 377 | VerifySmiField(kAliasedContextSlot); |
| 378 | } |
| 379 | |
| 380 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 381 | void FixedArray::FixedArrayVerify() { |
| 382 | for (int i = 0; i < length(); i++) { |
| 383 | Object* e = get(i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 384 | VerifyPointer(e); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | |
| 388 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 389 | void FixedDoubleArray::FixedDoubleArrayVerify() { |
| 390 | for (int i = 0; i < length(); i++) { |
| 391 | if (!is_the_hole(i)) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 392 | double value = get_scalar(i); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 393 | CHECK(!std::isnan(value) || |
| 394 | (bit_cast<uint64_t>(value) == |
| 395 | bit_cast<uint64_t>(canonical_not_the_hole_nan_as_double())) || |
| 396 | ((bit_cast<uint64_t>(value) & Double::kSignMask) != 0)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 402 | void ConstantPoolArray::ConstantPoolArrayVerify() { |
| 403 | CHECK(IsConstantPoolArray()); |
| 404 | ConstantPoolArray::Iterator code_iter(this, ConstantPoolArray::CODE_PTR); |
| 405 | while (!code_iter.is_finished()) { |
| 406 | Address code_entry = get_code_ptr_entry(code_iter.next_index()); |
| 407 | VerifyPointer(Code::GetCodeFromTargetAddress(code_entry)); |
| 408 | } |
| 409 | ConstantPoolArray::Iterator heap_iter(this, ConstantPoolArray::HEAP_PTR); |
| 410 | while (!heap_iter.is_finished()) { |
| 411 | VerifyObjectField(OffsetOfElementAt(heap_iter.next_index())); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | |
| 416 | void JSGeneratorObject::JSGeneratorObjectVerify() { |
| 417 | // In an expression like "new g()", there can be a point where a generator |
| 418 | // object is allocated but its fields are all undefined, as it hasn't yet been |
| 419 | // initialized by the generator. Hence these weak checks. |
| 420 | VerifyObjectField(kFunctionOffset); |
| 421 | VerifyObjectField(kContextOffset); |
| 422 | VerifyObjectField(kReceiverOffset); |
| 423 | VerifyObjectField(kOperandStackOffset); |
| 424 | VerifyObjectField(kContinuationOffset); |
| 425 | VerifyObjectField(kStackHandlerIndexOffset); |
| 426 | } |
| 427 | |
| 428 | |
| 429 | void JSModule::JSModuleVerify() { |
| 430 | VerifyObjectField(kContextOffset); |
| 431 | VerifyObjectField(kScopeInfoOffset); |
| 432 | CHECK(context()->IsUndefined() || |
| 433 | Context::cast(context())->IsModuleContext()); |
| 434 | } |
| 435 | |
| 436 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 437 | void JSValue::JSValueVerify() { |
| 438 | Object* v = value(); |
| 439 | if (v->IsHeapObject()) { |
| 440 | VerifyHeapPointer(v); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 445 | void JSDate::JSDateVerify() { |
| 446 | if (value()->IsHeapObject()) { |
| 447 | VerifyHeapPointer(value()); |
| 448 | } |
| 449 | CHECK(value()->IsUndefined() || value()->IsSmi() || value()->IsHeapNumber()); |
| 450 | CHECK(year()->IsUndefined() || year()->IsSmi() || year()->IsNaN()); |
| 451 | CHECK(month()->IsUndefined() || month()->IsSmi() || month()->IsNaN()); |
| 452 | CHECK(day()->IsUndefined() || day()->IsSmi() || day()->IsNaN()); |
| 453 | CHECK(weekday()->IsUndefined() || weekday()->IsSmi() || weekday()->IsNaN()); |
| 454 | CHECK(hour()->IsUndefined() || hour()->IsSmi() || hour()->IsNaN()); |
| 455 | CHECK(min()->IsUndefined() || min()->IsSmi() || min()->IsNaN()); |
| 456 | CHECK(sec()->IsUndefined() || sec()->IsSmi() || sec()->IsNaN()); |
| 457 | CHECK(cache_stamp()->IsUndefined() || |
| 458 | cache_stamp()->IsSmi() || |
| 459 | cache_stamp()->IsNaN()); |
| 460 | |
| 461 | if (month()->IsSmi()) { |
| 462 | int month = Smi::cast(this->month())->value(); |
| 463 | CHECK(0 <= month && month <= 11); |
| 464 | } |
| 465 | if (day()->IsSmi()) { |
| 466 | int day = Smi::cast(this->day())->value(); |
| 467 | CHECK(1 <= day && day <= 31); |
| 468 | } |
| 469 | if (hour()->IsSmi()) { |
| 470 | int hour = Smi::cast(this->hour())->value(); |
| 471 | CHECK(0 <= hour && hour <= 23); |
| 472 | } |
| 473 | if (min()->IsSmi()) { |
| 474 | int min = Smi::cast(this->min())->value(); |
| 475 | CHECK(0 <= min && min <= 59); |
| 476 | } |
| 477 | if (sec()->IsSmi()) { |
| 478 | int sec = Smi::cast(this->sec())->value(); |
| 479 | CHECK(0 <= sec && sec <= 59); |
| 480 | } |
| 481 | if (weekday()->IsSmi()) { |
| 482 | int weekday = Smi::cast(this->weekday())->value(); |
| 483 | CHECK(0 <= weekday && weekday <= 6); |
| 484 | } |
| 485 | if (cache_stamp()->IsSmi()) { |
| 486 | CHECK(Smi::cast(cache_stamp())->value() <= |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 487 | Smi::cast(GetIsolate()->date_cache()->stamp())->value()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
| 491 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 492 | void JSMessageObject::JSMessageObjectVerify() { |
| 493 | CHECK(IsJSMessageObject()); |
| 494 | CHECK(type()->IsString()); |
| 495 | CHECK(arguments()->IsJSArray()); |
| 496 | VerifyObjectField(kStartPositionOffset); |
| 497 | VerifyObjectField(kEndPositionOffset); |
| 498 | VerifyObjectField(kArgumentsOffset); |
| 499 | VerifyObjectField(kScriptOffset); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 500 | VerifyObjectField(kStackFramesOffset); |
| 501 | } |
| 502 | |
| 503 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 504 | void String::StringVerify() { |
| 505 | CHECK(IsString()); |
| 506 | CHECK(length() >= 0 && length() <= Smi::kMaxValue); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 507 | if (IsInternalizedString()) { |
| 508 | CHECK(!GetHeap()->InNewSpace(this)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 509 | } |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 510 | if (IsConsString()) { |
| 511 | ConsString::cast(this)->ConsStringVerify(); |
| 512 | } else if (IsSlicedString()) { |
| 513 | SlicedString::cast(this)->SlicedStringVerify(); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | |
| 518 | void ConsString::ConsStringVerify() { |
| 519 | CHECK(this->first()->IsString()); |
| 520 | CHECK(this->second() == GetHeap()->empty_string() || |
| 521 | this->second()->IsString()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 522 | CHECK(this->length() >= ConsString::kMinLength); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 523 | CHECK(this->length() == this->first()->length() + this->second()->length()); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 524 | if (this->IsFlat()) { |
| 525 | // A flat cons can only be created by String::SlowTryFlatten. |
| 526 | // Afterwards, the first part may be externalized. |
| 527 | CHECK(this->first()->IsSeqString() || this->first()->IsExternalString()); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | |
| 532 | void SlicedString::SlicedStringVerify() { |
| 533 | CHECK(!this->parent()->IsConsString()); |
| 534 | CHECK(!this->parent()->IsSlicedString()); |
| 535 | CHECK(this->length() >= SlicedString::kMinLength); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 539 | void JSFunction::JSFunctionVerify() { |
| 540 | CHECK(IsJSFunction()); |
| 541 | VerifyObjectField(kPrototypeOrInitialMapOffset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 542 | VerifyObjectField(kNextFunctionLinkOffset); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 543 | CHECK(code()->IsCode()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 544 | CHECK(next_function_link() == NULL || |
| 545 | next_function_link()->IsUndefined() || |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 546 | next_function_link()->IsJSFunction()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 550 | void SharedFunctionInfo::SharedFunctionInfoVerify() { |
| 551 | CHECK(IsSharedFunctionInfo()); |
| 552 | VerifyObjectField(kNameOffset); |
| 553 | VerifyObjectField(kCodeOffset); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 554 | VerifyObjectField(kOptimizedCodeMapOffset); |
| 555 | VerifyObjectField(kFeedbackVectorOffset); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 556 | VerifyObjectField(kScopeInfoOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 557 | VerifyObjectField(kInstanceClassNameOffset); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 558 | VerifyObjectField(kFunctionDataOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 559 | VerifyObjectField(kScriptOffset); |
| 560 | VerifyObjectField(kDebugInfoOffset); |
| 561 | } |
| 562 | |
| 563 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 564 | void JSGlobalProxy::JSGlobalProxyVerify() { |
| 565 | CHECK(IsJSGlobalProxy()); |
| 566 | JSObjectVerify(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 567 | VerifyObjectField(JSGlobalProxy::kNativeContextOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 568 | // Make sure that this object has no properties, elements. |
| 569 | CHECK_EQ(0, properties()->length()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 570 | CHECK_EQ(FAST_HOLEY_SMI_ELEMENTS, GetElementsKind()); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 571 | CHECK_EQ(0, FixedArray::cast(elements())->length()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 575 | void JSGlobalObject::JSGlobalObjectVerify() { |
| 576 | CHECK(IsJSGlobalObject()); |
| 577 | JSObjectVerify(); |
| 578 | for (int i = GlobalObject::kBuiltinsOffset; |
| 579 | i < JSGlobalObject::kSize; |
| 580 | i += kPointerSize) { |
| 581 | VerifyObjectField(i); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 586 | void JSBuiltinsObject::JSBuiltinsObjectVerify() { |
| 587 | CHECK(IsJSBuiltinsObject()); |
| 588 | JSObjectVerify(); |
| 589 | for (int i = GlobalObject::kBuiltinsOffset; |
| 590 | i < JSBuiltinsObject::kSize; |
| 591 | i += kPointerSize) { |
| 592 | VerifyObjectField(i); |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | |
| 597 | void Oddball::OddballVerify() { |
| 598 | CHECK(IsOddball()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 599 | Heap* heap = GetHeap(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 600 | VerifyHeapPointer(to_string()); |
| 601 | Object* number = to_number(); |
| 602 | if (number->IsHeapObject()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 603 | CHECK(number == heap->nan_value()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 604 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 605 | CHECK(number->IsSmi()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 606 | int value = Smi::cast(number)->value(); |
Ben Murdoch | 592a9fc | 2012-03-05 11:04:45 +0000 | [diff] [blame] | 607 | // Hidden oddballs have negative smis. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 608 | const int kLeastHiddenOddballNumber = -5; |
| 609 | CHECK_LE(value, 1); |
| 610 | CHECK(value >= kLeastHiddenOddballNumber); |
| 611 | } |
| 612 | if (map() == heap->undefined_map()) { |
| 613 | CHECK(this == heap->undefined_value()); |
| 614 | } else if (map() == heap->the_hole_map()) { |
| 615 | CHECK(this == heap->the_hole_value()); |
| 616 | } else if (map() == heap->null_map()) { |
| 617 | CHECK(this == heap->null_value()); |
| 618 | } else if (map() == heap->boolean_map()) { |
| 619 | CHECK(this == heap->true_value() || |
| 620 | this == heap->false_value()); |
| 621 | } else if (map() == heap->uninitialized_map()) { |
| 622 | CHECK(this == heap->uninitialized_value()); |
| 623 | } else if (map() == heap->no_interceptor_result_sentinel_map()) { |
| 624 | CHECK(this == heap->no_interceptor_result_sentinel()); |
| 625 | } else if (map() == heap->arguments_marker_map()) { |
| 626 | CHECK(this == heap->arguments_marker()); |
| 627 | } else if (map() == heap->termination_exception_map()) { |
| 628 | CHECK(this == heap->termination_exception()); |
| 629 | } else if (map() == heap->exception_map()) { |
| 630 | CHECK(this == heap->exception()); |
| 631 | } else { |
| 632 | UNREACHABLE(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | |
| 636 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 637 | void Cell::CellVerify() { |
| 638 | CHECK(IsCell()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 639 | VerifyObjectField(kValueOffset); |
| 640 | } |
| 641 | |
| 642 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 643 | void PropertyCell::PropertyCellVerify() { |
| 644 | CHECK(IsPropertyCell()); |
| 645 | VerifyObjectField(kValueOffset); |
| 646 | VerifyObjectField(kTypeOffset); |
| 647 | } |
| 648 | |
| 649 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 650 | void WeakCell::WeakCellVerify() { |
| 651 | CHECK(IsWeakCell()); |
| 652 | VerifyObjectField(kValueOffset); |
| 653 | VerifyObjectField(kNextOffset); |
| 654 | } |
| 655 | |
| 656 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 657 | void Code::CodeVerify() { |
| 658 | CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()), |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 659 | kCodeAlignment)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 660 | relocation_info()->ObjectVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 661 | Address last_gc_pc = NULL; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 662 | Isolate* isolate = GetIsolate(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 663 | for (RelocIterator it(this); !it.done(); it.next()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 664 | it.rinfo()->Verify(isolate); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 665 | // Ensure that GC will not iterate twice over the same pointer. |
| 666 | if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) { |
| 667 | CHECK(it.rinfo()->pc() != last_gc_pc); |
| 668 | last_gc_pc = it.rinfo()->pc(); |
| 669 | } |
| 670 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 671 | CHECK(raw_type_feedback_info() == Smi::FromInt(0) || |
| 672 | raw_type_feedback_info()->IsSmi() == IsCodeStubOrIC()); |
| 673 | } |
| 674 | |
| 675 | |
| 676 | void Code::VerifyEmbeddedObjectsDependency() { |
| 677 | if (!CanContainWeakObjects()) return; |
| 678 | DisallowHeapAllocation no_gc; |
| 679 | Isolate* isolate = GetIsolate(); |
| 680 | HandleScope scope(isolate); |
| 681 | int mode_mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| 682 | for (RelocIterator it(this, mode_mask); !it.done(); it.next()) { |
| 683 | Object* obj = it.rinfo()->target_object(); |
| 684 | if (IsWeakObject(obj)) { |
| 685 | if (obj->IsMap()) { |
| 686 | Map* map = Map::cast(obj); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 687 | CHECK(map->dependent_code()->Contains(DependentCode::kWeakCodeGroup, |
| 688 | this)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 689 | } else if (obj->IsJSObject()) { |
| 690 | Object* raw_table = GetIsolate()->heap()->weak_object_to_code_table(); |
| 691 | WeakHashTable* table = WeakHashTable::cast(raw_table); |
| 692 | Handle<Object> key_obj(obj, isolate); |
| 693 | CHECK(DependentCode::cast(table->Lookup(key_obj))->Contains( |
| 694 | DependentCode::kWeakCodeGroup, this)); |
| 695 | } |
| 696 | } |
| 697 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | |
| 701 | void JSArray::JSArrayVerify() { |
| 702 | JSObjectVerify(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 703 | CHECK(length()->IsNumber() || length()->IsUndefined()); |
| 704 | // If a GC was caused while constructing this array, the elements |
| 705 | // pointer may point to a one pointer filler map. |
| 706 | if (ElementsAreSafeToExamine()) { |
| 707 | CHECK(elements()->IsUndefined() || |
| 708 | elements()->IsFixedArray() || |
| 709 | elements()->IsFixedDoubleArray()); |
| 710 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 714 | void JSSet::JSSetVerify() { |
| 715 | CHECK(IsJSSet()); |
| 716 | JSObjectVerify(); |
| 717 | VerifyHeapPointer(table()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 718 | CHECK(table()->IsOrderedHashTable() || table()->IsUndefined()); |
| 719 | // TODO(arv): Verify OrderedHashTable too. |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | |
| 723 | void JSMap::JSMapVerify() { |
| 724 | CHECK(IsJSMap()); |
| 725 | JSObjectVerify(); |
| 726 | VerifyHeapPointer(table()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 727 | CHECK(table()->IsOrderedHashTable() || table()->IsUndefined()); |
| 728 | // TODO(arv): Verify OrderedHashTable too. |
| 729 | } |
| 730 | |
| 731 | |
| 732 | void JSSetIterator::JSSetIteratorVerify() { |
| 733 | CHECK(IsJSSetIterator()); |
| 734 | JSObjectVerify(); |
| 735 | VerifyHeapPointer(table()); |
| 736 | CHECK(table()->IsOrderedHashTable() || table()->IsUndefined()); |
| 737 | CHECK(index()->IsSmi() || index()->IsUndefined()); |
| 738 | CHECK(kind()->IsSmi() || kind()->IsUndefined()); |
| 739 | } |
| 740 | |
| 741 | |
| 742 | void JSMapIterator::JSMapIteratorVerify() { |
| 743 | CHECK(IsJSMapIterator()); |
| 744 | JSObjectVerify(); |
| 745 | VerifyHeapPointer(table()); |
| 746 | CHECK(table()->IsOrderedHashTable() || table()->IsUndefined()); |
| 747 | CHECK(index()->IsSmi() || index()->IsUndefined()); |
| 748 | CHECK(kind()->IsSmi() || kind()->IsUndefined()); |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 752 | void JSWeakMap::JSWeakMapVerify() { |
| 753 | CHECK(IsJSWeakMap()); |
| 754 | JSObjectVerify(); |
| 755 | VerifyHeapPointer(table()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 756 | CHECK(table()->IsHashTable() || table()->IsUndefined()); |
| 757 | } |
| 758 | |
| 759 | |
| 760 | void JSWeakSet::JSWeakSetVerify() { |
| 761 | CHECK(IsJSWeakSet()); |
| 762 | JSObjectVerify(); |
| 763 | VerifyHeapPointer(table()); |
| 764 | CHECK(table()->IsHashTable() || table()->IsUndefined()); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 768 | void JSRegExp::JSRegExpVerify() { |
| 769 | JSObjectVerify(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 770 | CHECK(data()->IsUndefined() || data()->IsFixedArray()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 771 | switch (TypeTag()) { |
| 772 | case JSRegExp::ATOM: { |
| 773 | FixedArray* arr = FixedArray::cast(data()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 774 | CHECK(arr->get(JSRegExp::kAtomPatternIndex)->IsString()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 775 | break; |
| 776 | } |
| 777 | case JSRegExp::IRREGEXP: { |
| 778 | bool is_native = RegExpImpl::UsesNativeRegExp(); |
| 779 | |
| 780 | FixedArray* arr = FixedArray::cast(data()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 781 | Object* one_byte_data = arr->get(JSRegExp::kIrregexpLatin1CodeIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 782 | // Smi : Not compiled yet (-1) or code prepared for flushing. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 783 | // JSObject: Compilation error. |
| 784 | // Code/ByteArray: Compiled code. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 785 | CHECK( |
| 786 | one_byte_data->IsSmi() || |
| 787 | (is_native ? one_byte_data->IsCode() : one_byte_data->IsByteArray())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 788 | Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 789 | CHECK(uc16_data->IsSmi() || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 790 | (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray())); |
| 791 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 792 | Object* one_byte_saved = |
| 793 | arr->get(JSRegExp::kIrregexpLatin1CodeSavedIndex); |
| 794 | CHECK(one_byte_saved->IsSmi() || one_byte_saved->IsString() || |
| 795 | one_byte_saved->IsCode()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 796 | Object* uc16_saved = arr->get(JSRegExp::kIrregexpUC16CodeSavedIndex); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 797 | CHECK(uc16_saved->IsSmi() || uc16_saved->IsString() || |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 798 | uc16_saved->IsCode()); |
| 799 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 800 | CHECK(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi()); |
| 801 | CHECK(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 802 | break; |
| 803 | } |
| 804 | default: |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 805 | CHECK_EQ(JSRegExp::NOT_COMPILED, TypeTag()); |
| 806 | CHECK(data()->IsUndefined()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 807 | break; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 812 | void JSProxy::JSProxyVerify() { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 813 | CHECK(IsJSProxy()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 814 | VerifyPointer(handler()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 815 | CHECK(hash()->IsSmi() || hash()->IsUndefined()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 818 | |
| 819 | void JSFunctionProxy::JSFunctionProxyVerify() { |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 820 | CHECK(IsJSFunctionProxy()); |
Ben Murdoch | 589d697 | 2011-11-30 16:04:58 +0000 | [diff] [blame] | 821 | JSProxyVerify(); |
| 822 | VerifyPointer(call_trap()); |
| 823 | VerifyPointer(construct_trap()); |
| 824 | } |
| 825 | |
| 826 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 827 | void JSArrayBuffer::JSArrayBufferVerify() { |
| 828 | CHECK(IsJSArrayBuffer()); |
| 829 | JSObjectVerify(); |
| 830 | VerifyPointer(byte_length()); |
| 831 | CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber() |
| 832 | || byte_length()->IsUndefined()); |
| 833 | } |
| 834 | |
| 835 | |
| 836 | void JSArrayBufferView::JSArrayBufferViewVerify() { |
| 837 | CHECK(IsJSArrayBufferView()); |
| 838 | JSObjectVerify(); |
| 839 | VerifyPointer(buffer()); |
| 840 | CHECK(buffer()->IsJSArrayBuffer() || buffer()->IsUndefined() |
| 841 | || buffer() == Smi::FromInt(0)); |
| 842 | |
| 843 | VerifyPointer(byte_offset()); |
| 844 | CHECK(byte_offset()->IsSmi() || byte_offset()->IsHeapNumber() |
| 845 | || byte_offset()->IsUndefined()); |
| 846 | |
| 847 | VerifyPointer(byte_length()); |
| 848 | CHECK(byte_length()->IsSmi() || byte_length()->IsHeapNumber() |
| 849 | || byte_length()->IsUndefined()); |
| 850 | } |
| 851 | |
| 852 | |
| 853 | void JSTypedArray::JSTypedArrayVerify() { |
| 854 | CHECK(IsJSTypedArray()); |
| 855 | JSArrayBufferViewVerify(); |
| 856 | VerifyPointer(length()); |
| 857 | CHECK(length()->IsSmi() || length()->IsHeapNumber() |
| 858 | || length()->IsUndefined()); |
| 859 | |
| 860 | VerifyPointer(elements()); |
| 861 | } |
| 862 | |
| 863 | |
| 864 | void JSDataView::JSDataViewVerify() { |
| 865 | CHECK(IsJSDataView()); |
| 866 | JSArrayBufferViewVerify(); |
| 867 | } |
| 868 | |
| 869 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 870 | void Foreign::ForeignVerify() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 871 | CHECK(IsForeign()); |
| 872 | } |
| 873 | |
| 874 | |
| 875 | void Box::BoxVerify() { |
| 876 | CHECK(IsBox()); |
| 877 | value()->ObjectVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | |
| 881 | void AccessorInfo::AccessorInfoVerify() { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 882 | VerifyPointer(name()); |
| 883 | VerifyPointer(flag()); |
| 884 | VerifyPointer(expected_receiver_type()); |
| 885 | } |
| 886 | |
| 887 | |
| 888 | void ExecutableAccessorInfo::ExecutableAccessorInfoVerify() { |
| 889 | CHECK(IsExecutableAccessorInfo()); |
| 890 | AccessorInfoVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 891 | VerifyPointer(getter()); |
| 892 | VerifyPointer(setter()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 893 | VerifyPointer(data()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | |
| 897 | void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorVerify() { |
| 898 | CHECK(IsDeclaredAccessorDescriptor()); |
| 899 | VerifyPointer(serialized_data()); |
| 900 | } |
| 901 | |
| 902 | |
| 903 | void DeclaredAccessorInfo::DeclaredAccessorInfoVerify() { |
| 904 | CHECK(IsDeclaredAccessorInfo()); |
| 905 | AccessorInfoVerify(); |
| 906 | VerifyPointer(descriptor()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 909 | |
Ben Murdoch | 3ef787d | 2012-04-12 10:51:47 +0100 | [diff] [blame] | 910 | void AccessorPair::AccessorPairVerify() { |
| 911 | CHECK(IsAccessorPair()); |
| 912 | VerifyPointer(getter()); |
| 913 | VerifyPointer(setter()); |
| 914 | } |
| 915 | |
| 916 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 917 | void AccessCheckInfo::AccessCheckInfoVerify() { |
| 918 | CHECK(IsAccessCheckInfo()); |
| 919 | VerifyPointer(named_callback()); |
| 920 | VerifyPointer(indexed_callback()); |
| 921 | VerifyPointer(data()); |
| 922 | } |
| 923 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 924 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 925 | void InterceptorInfo::InterceptorInfoVerify() { |
| 926 | CHECK(IsInterceptorInfo()); |
| 927 | VerifyPointer(getter()); |
| 928 | VerifyPointer(setter()); |
| 929 | VerifyPointer(query()); |
| 930 | VerifyPointer(deleter()); |
| 931 | VerifyPointer(enumerator()); |
| 932 | VerifyPointer(data()); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 933 | VerifySmiField(kFlagsOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 936 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 937 | void CallHandlerInfo::CallHandlerInfoVerify() { |
| 938 | CHECK(IsCallHandlerInfo()); |
| 939 | VerifyPointer(callback()); |
| 940 | VerifyPointer(data()); |
| 941 | } |
| 942 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 943 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 944 | void TemplateInfo::TemplateInfoVerify() { |
| 945 | VerifyPointer(tag()); |
| 946 | VerifyPointer(property_list()); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 947 | VerifyPointer(property_accessors()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 950 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 951 | void FunctionTemplateInfo::FunctionTemplateInfoVerify() { |
| 952 | CHECK(IsFunctionTemplateInfo()); |
| 953 | TemplateInfoVerify(); |
| 954 | VerifyPointer(serial_number()); |
| 955 | VerifyPointer(call_code()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 956 | VerifyPointer(prototype_template()); |
| 957 | VerifyPointer(parent_template()); |
| 958 | VerifyPointer(named_property_handler()); |
| 959 | VerifyPointer(indexed_property_handler()); |
| 960 | VerifyPointer(instance_template()); |
| 961 | VerifyPointer(signature()); |
| 962 | VerifyPointer(access_check_info()); |
| 963 | } |
| 964 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 965 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 966 | void ObjectTemplateInfo::ObjectTemplateInfoVerify() { |
| 967 | CHECK(IsObjectTemplateInfo()); |
| 968 | TemplateInfoVerify(); |
| 969 | VerifyPointer(constructor()); |
| 970 | VerifyPointer(internal_field_count()); |
| 971 | } |
| 972 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 973 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 974 | void SignatureInfo::SignatureInfoVerify() { |
| 975 | CHECK(IsSignatureInfo()); |
| 976 | VerifyPointer(receiver()); |
| 977 | VerifyPointer(args()); |
| 978 | } |
| 979 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 980 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 981 | void TypeSwitchInfo::TypeSwitchInfoVerify() { |
| 982 | CHECK(IsTypeSwitchInfo()); |
| 983 | VerifyPointer(types()); |
| 984 | } |
| 985 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 986 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 987 | void AllocationSite::AllocationSiteVerify() { |
| 988 | CHECK(IsAllocationSite()); |
| 989 | } |
| 990 | |
| 991 | |
| 992 | void AllocationMemento::AllocationMementoVerify() { |
| 993 | CHECK(IsAllocationMemento()); |
| 994 | VerifyHeapPointer(allocation_site()); |
| 995 | CHECK(!IsValid() || GetAllocationSite()->IsAllocationSite()); |
| 996 | } |
| 997 | |
| 998 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 999 | void Script::ScriptVerify() { |
| 1000 | CHECK(IsScript()); |
| 1001 | VerifyPointer(source()); |
| 1002 | VerifyPointer(name()); |
| 1003 | line_offset()->SmiVerify(); |
| 1004 | column_offset()->SmiVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1005 | VerifyPointer(wrapper()); |
| 1006 | type()->SmiVerify(); |
| 1007 | VerifyPointer(line_ends()); |
| 1008 | VerifyPointer(id()); |
| 1009 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1010 | |
| 1011 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1012 | void JSFunctionResultCache::JSFunctionResultCacheVerify() { |
| 1013 | JSFunction::cast(get(kFactoryIndex))->ObjectVerify(); |
| 1014 | |
| 1015 | int size = Smi::cast(get(kCacheSizeIndex))->value(); |
| 1016 | CHECK(kEntriesIndex <= size); |
| 1017 | CHECK(size <= length()); |
| 1018 | CHECK_EQ(0, size % kEntrySize); |
| 1019 | |
| 1020 | int finger = Smi::cast(get(kFingerIndex))->value(); |
| 1021 | CHECK(kEntriesIndex <= finger); |
| 1022 | CHECK((finger < size) || (finger == kEntriesIndex && finger == size)); |
| 1023 | CHECK_EQ(0, finger % kEntrySize); |
| 1024 | |
| 1025 | if (FLAG_enable_slow_asserts) { |
| 1026 | for (int i = kEntriesIndex; i < size; i++) { |
| 1027 | CHECK(!get(i)->IsTheHole()); |
| 1028 | get(i)->ObjectVerify(); |
| 1029 | } |
| 1030 | for (int i = size; i < length(); i++) { |
| 1031 | CHECK(get(i)->IsTheHole()); |
| 1032 | get(i)->ObjectVerify(); |
| 1033 | } |
| 1034 | } |
| 1035 | } |
| 1036 | |
| 1037 | |
| 1038 | void NormalizedMapCache::NormalizedMapCacheVerify() { |
| 1039 | FixedArray::cast(this)->FixedArrayVerify(); |
| 1040 | if (FLAG_enable_slow_asserts) { |
| 1041 | for (int i = 0; i < length(); i++) { |
| 1042 | Object* e = FixedArray::get(i); |
| 1043 | if (e->IsMap()) { |
| 1044 | Map::cast(e)->DictionaryMapVerify(); |
| 1045 | } else { |
| 1046 | CHECK(e->IsUndefined()); |
| 1047 | } |
| 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1053 | void DebugInfo::DebugInfoVerify() { |
| 1054 | CHECK(IsDebugInfo()); |
| 1055 | VerifyPointer(shared()); |
| 1056 | VerifyPointer(original_code()); |
| 1057 | VerifyPointer(code()); |
| 1058 | VerifyPointer(break_points()); |
| 1059 | } |
| 1060 | |
| 1061 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1062 | void BreakPointInfo::BreakPointInfoVerify() { |
| 1063 | CHECK(IsBreakPointInfo()); |
| 1064 | code_position()->SmiVerify(); |
| 1065 | source_position()->SmiVerify(); |
| 1066 | statement_position()->SmiVerify(); |
| 1067 | VerifyPointer(break_point_objects()); |
| 1068 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1069 | #endif // VERIFY_HEAP |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1070 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1071 | #ifdef DEBUG |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1072 | |
| 1073 | void JSObject::IncrementSpillStatistics(SpillInformation* info) { |
| 1074 | info->number_of_objects_++; |
| 1075 | // Named properties |
| 1076 | if (HasFastProperties()) { |
| 1077 | info->number_of_objects_with_fast_properties_++; |
| 1078 | info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex(); |
| 1079 | info->number_of_fast_unused_fields_ += map()->unused_property_fields(); |
| 1080 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1081 | NameDictionary* dict = property_dictionary(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1082 | info->number_of_slow_used_properties_ += dict->NumberOfElements(); |
| 1083 | info->number_of_slow_unused_properties_ += |
| 1084 | dict->Capacity() - dict->NumberOfElements(); |
| 1085 | } |
| 1086 | // Indexed properties |
| 1087 | switch (GetElementsKind()) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1088 | case FAST_HOLEY_SMI_ELEMENTS: |
| 1089 | case FAST_SMI_ELEMENTS: |
| 1090 | case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 1091 | case FAST_DOUBLE_ELEMENTS: |
| 1092 | case FAST_HOLEY_ELEMENTS: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1093 | case FAST_ELEMENTS: { |
| 1094 | info->number_of_objects_with_fast_elements_++; |
| 1095 | int holes = 0; |
| 1096 | FixedArray* e = FixedArray::cast(elements()); |
| 1097 | int len = e->length(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1098 | Heap* heap = GetHeap(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1099 | for (int i = 0; i < len; i++) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1100 | if (e->get(i) == heap->the_hole_value()) holes++; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1101 | } |
| 1102 | info->number_of_fast_used_elements_ += len - holes; |
| 1103 | info->number_of_fast_unused_elements_ += holes; |
| 1104 | break; |
| 1105 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1106 | |
| 1107 | #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
| 1108 | case EXTERNAL_##TYPE##_ELEMENTS: \ |
| 1109 | case TYPE##_ELEMENTS: |
| 1110 | |
| 1111 | TYPED_ARRAYS(TYPED_ARRAY_CASE) |
| 1112 | #undef TYPED_ARRAY_CASE |
| 1113 | { info->number_of_objects_with_fast_elements_++; |
| 1114 | FixedArrayBase* e = FixedArrayBase::cast(elements()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1115 | info->number_of_fast_used_elements_ += e->length(); |
| 1116 | break; |
| 1117 | } |
| 1118 | case DICTIONARY_ELEMENTS: { |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame] | 1119 | SeededNumberDictionary* dict = element_dictionary(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1120 | info->number_of_slow_used_elements_ += dict->NumberOfElements(); |
| 1121 | info->number_of_slow_unused_elements_ += |
| 1122 | dict->Capacity() - dict->NumberOfElements(); |
| 1123 | break; |
| 1124 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1125 | case SLOPPY_ARGUMENTS_ELEMENTS: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1126 | break; |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | void JSObject::SpillInformation::Clear() { |
| 1132 | number_of_objects_ = 0; |
| 1133 | number_of_objects_with_fast_properties_ = 0; |
| 1134 | number_of_objects_with_fast_elements_ = 0; |
| 1135 | number_of_fast_used_fields_ = 0; |
| 1136 | number_of_fast_unused_fields_ = 0; |
| 1137 | number_of_slow_used_properties_ = 0; |
| 1138 | number_of_slow_unused_properties_ = 0; |
| 1139 | number_of_fast_used_elements_ = 0; |
| 1140 | number_of_fast_unused_elements_ = 0; |
| 1141 | number_of_slow_used_elements_ = 0; |
| 1142 | number_of_slow_unused_elements_ = 0; |
| 1143 | } |
| 1144 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1145 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1146 | void JSObject::SpillInformation::Print() { |
| 1147 | PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_); |
| 1148 | |
| 1149 | PrintF(" - fast properties (#%d): %d (used) %d (unused)\n", |
| 1150 | number_of_objects_with_fast_properties_, |
| 1151 | number_of_fast_used_fields_, number_of_fast_unused_fields_); |
| 1152 | |
| 1153 | PrintF(" - slow properties (#%d): %d (used) %d (unused)\n", |
| 1154 | number_of_objects_ - number_of_objects_with_fast_properties_, |
| 1155 | number_of_slow_used_properties_, number_of_slow_unused_properties_); |
| 1156 | |
| 1157 | PrintF(" - fast elements (#%d): %d (used) %d (unused)\n", |
| 1158 | number_of_objects_with_fast_elements_, |
| 1159 | number_of_fast_used_elements_, number_of_fast_unused_elements_); |
| 1160 | |
| 1161 | PrintF(" - slow elements (#%d): %d (used) %d (unused)\n", |
| 1162 | number_of_objects_ - number_of_objects_with_fast_elements_, |
| 1163 | number_of_slow_used_elements_, number_of_slow_unused_elements_); |
| 1164 | |
| 1165 | PrintF("\n"); |
| 1166 | } |
| 1167 | |
| 1168 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1169 | bool DescriptorArray::IsSortedNoDuplicates(int valid_entries) { |
| 1170 | if (valid_entries == -1) valid_entries = number_of_descriptors(); |
| 1171 | Name* current_key = NULL; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1172 | uint32_t current = 0; |
| 1173 | for (int i = 0; i < number_of_descriptors(); i++) { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1174 | Name* key = GetSortedKey(i); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1175 | if (key == current_key) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1176 | Print(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1177 | return false; |
| 1178 | } |
| 1179 | current_key = key; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1180 | uint32_t hash = GetSortedKey(i)->Hash(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1181 | if (hash < current) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1182 | Print(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1183 | return false; |
| 1184 | } |
| 1185 | current = hash; |
| 1186 | } |
| 1187 | return true; |
| 1188 | } |
| 1189 | |
| 1190 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1191 | bool LayoutDescriptor::IsConsistentWithMap(Map* map) { |
| 1192 | if (FLAG_unbox_double_fields) { |
| 1193 | DescriptorArray* descriptors = map->instance_descriptors(); |
| 1194 | int nof_descriptors = map->NumberOfOwnDescriptors(); |
| 1195 | for (int i = 0; i < nof_descriptors; i++) { |
| 1196 | PropertyDetails details = descriptors->GetDetails(i); |
| 1197 | if (details.type() != FIELD) continue; |
| 1198 | FieldIndex field_index = FieldIndex::ForDescriptor(map, i); |
| 1199 | bool tagged_expected = |
| 1200 | !field_index.is_inobject() || !details.representation().IsDouble(); |
| 1201 | for (int bit = 0; bit < details.field_width_in_words(); bit++) { |
| 1202 | bool tagged_actual = IsTagged(details.field_index() + bit); |
| 1203 | DCHECK_EQ(tagged_expected, tagged_actual); |
| 1204 | if (tagged_actual != tagged_expected) return false; |
| 1205 | } |
| 1206 | } |
| 1207 | } |
| 1208 | return true; |
| 1209 | } |
| 1210 | |
| 1211 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1212 | bool TransitionArray::IsSortedNoDuplicates(int valid_entries) { |
| 1213 | DCHECK(valid_entries == -1); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1214 | Name* prev_key = NULL; |
| 1215 | PropertyKind prev_kind = DATA; |
| 1216 | PropertyAttributes prev_attributes = NONE; |
| 1217 | uint32_t prev_hash = 0; |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1218 | for (int i = 0; i < number_of_transitions(); i++) { |
| 1219 | Name* key = GetSortedKey(i); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1220 | uint32_t hash = key->Hash(); |
| 1221 | PropertyKind kind = DATA; |
| 1222 | PropertyAttributes attributes = NONE; |
| 1223 | if (!IsSpecialTransition(key)) { |
| 1224 | Map* target = GetTarget(i); |
| 1225 | PropertyDetails details = GetTargetDetails(key, target); |
| 1226 | kind = details.kind(); |
| 1227 | attributes = details.attributes(); |
| 1228 | } else { |
| 1229 | // Duplicate entries are not allowed for non-property transitions. |
| 1230 | CHECK_NE(prev_key, key); |
| 1231 | } |
| 1232 | |
| 1233 | int cmp = CompareKeys(prev_key, prev_hash, prev_kind, prev_attributes, key, |
| 1234 | hash, kind, attributes); |
| 1235 | if (cmp >= 0) { |
| 1236 | Print(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1237 | return false; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1238 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1239 | prev_key = key; |
| 1240 | prev_hash = hash; |
| 1241 | prev_attributes = attributes; |
| 1242 | prev_kind = kind; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1243 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1244 | return true; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1248 | static bool CheckOneBackPointer(Map* current_map, Object* target) { |
| 1249 | return !target->IsMap() || Map::cast(target)->GetBackPointer() == current_map; |
| 1250 | } |
| 1251 | |
| 1252 | |
| 1253 | bool TransitionArray::IsConsistentWithBackPointers(Map* current_map) { |
| 1254 | for (int i = 0; i < number_of_transitions(); ++i) { |
| 1255 | if (!CheckOneBackPointer(current_map, GetTarget(i))) return false; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1256 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1257 | return true; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 1261 | void Code::VerifyEmbeddedObjectsInFullCode() { |
| 1262 | // Check that no context-specific object has been embedded. |
| 1263 | Heap* heap = GetIsolate()->heap(); |
| 1264 | int mask = RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT); |
| 1265 | for (RelocIterator it(this, mask); !it.done(); it.next()) { |
| 1266 | Object* obj = it.rinfo()->target_object(); |
| 1267 | if (obj->IsCell()) obj = Cell::cast(obj)->value(); |
| 1268 | if (obj->IsPropertyCell()) obj = PropertyCell::cast(obj)->value(); |
| 1269 | if (!obj->IsHeapObject()) continue; |
| 1270 | Map* map = obj->IsMap() ? Map::cast(obj) : HeapObject::cast(obj)->map(); |
| 1271 | int i = 0; |
| 1272 | while (map != heap->roots_array_start()[i++]) { |
| 1273 | CHECK_LT(i, Heap::kStrongRootListLength); |
| 1274 | } |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1279 | #endif // DEBUG |
| 1280 | |
| 1281 | } } // namespace v8::internal |