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