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