Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "disassembler.h" |
| 31 | #include "disasm.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 32 | #include "jsregexp.h" |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 33 | #include "objects-visiting.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 38 | #ifdef DEBUG |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 39 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 40 | void MaybeObject::Verify() { |
| 41 | Object* this_as_object; |
| 42 | if (ToObject(&this_as_object)) { |
| 43 | if (this_as_object->IsSmi()) { |
| 44 | Smi::cast(this_as_object)->SmiVerify(); |
| 45 | } else { |
| 46 | HeapObject::cast(this_as_object)->HeapObjectVerify(); |
| 47 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 48 | } else { |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 49 | Failure::cast(this)->FailureVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | |
| 54 | void Object::VerifyPointer(Object* p) { |
| 55 | if (p->IsHeapObject()) { |
| 56 | HeapObject::VerifyHeapPointer(p); |
| 57 | } else { |
| 58 | ASSERT(p->IsSmi()); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | |
| 63 | void Smi::SmiVerify() { |
| 64 | ASSERT(IsSmi()); |
| 65 | } |
| 66 | |
| 67 | |
| 68 | void Failure::FailureVerify() { |
| 69 | ASSERT(IsFailure()); |
| 70 | } |
| 71 | |
| 72 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 73 | void HeapObject::HeapObjectVerify() { |
| 74 | InstanceType instance_type = map()->instance_type(); |
| 75 | |
| 76 | if (instance_type < FIRST_NONSTRING_TYPE) { |
| 77 | String::cast(this)->StringVerify(); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | switch (instance_type) { |
| 82 | case MAP_TYPE: |
| 83 | Map::cast(this)->MapVerify(); |
| 84 | break; |
| 85 | case HEAP_NUMBER_TYPE: |
| 86 | HeapNumber::cast(this)->HeapNumberVerify(); |
| 87 | break; |
| 88 | case FIXED_ARRAY_TYPE: |
| 89 | FixedArray::cast(this)->FixedArrayVerify(); |
| 90 | break; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 91 | case FIXED_DOUBLE_ARRAY_TYPE: |
| 92 | FixedDoubleArray::cast(this)->FixedDoubleArrayVerify(); |
| 93 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 94 | case BYTE_ARRAY_TYPE: |
| 95 | ByteArray::cast(this)->ByteArrayVerify(); |
| 96 | break; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 97 | case EXTERNAL_PIXEL_ARRAY_TYPE: |
| 98 | ExternalPixelArray::cast(this)->ExternalPixelArrayVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 99 | break; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 100 | case EXTERNAL_BYTE_ARRAY_TYPE: |
| 101 | ExternalByteArray::cast(this)->ExternalByteArrayVerify(); |
| 102 | break; |
| 103 | case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 104 | ExternalUnsignedByteArray::cast(this)->ExternalUnsignedByteArrayVerify(); |
| 105 | break; |
| 106 | case EXTERNAL_SHORT_ARRAY_TYPE: |
| 107 | ExternalShortArray::cast(this)->ExternalShortArrayVerify(); |
| 108 | break; |
| 109 | case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 110 | ExternalUnsignedShortArray::cast(this)-> |
| 111 | ExternalUnsignedShortArrayVerify(); |
| 112 | break; |
| 113 | case EXTERNAL_INT_ARRAY_TYPE: |
| 114 | ExternalIntArray::cast(this)->ExternalIntArrayVerify(); |
| 115 | break; |
| 116 | case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 117 | ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayVerify(); |
| 118 | break; |
| 119 | case EXTERNAL_FLOAT_ARRAY_TYPE: |
| 120 | ExternalFloatArray::cast(this)->ExternalFloatArrayVerify(); |
| 121 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 122 | case EXTERNAL_DOUBLE_ARRAY_TYPE: |
| 123 | ExternalDoubleArray::cast(this)->ExternalDoubleArrayVerify(); |
| 124 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 125 | case CODE_TYPE: |
| 126 | Code::cast(this)->CodeVerify(); |
| 127 | break; |
| 128 | case ODDBALL_TYPE: |
| 129 | Oddball::cast(this)->OddballVerify(); |
| 130 | break; |
| 131 | case JS_OBJECT_TYPE: |
| 132 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
| 133 | JSObject::cast(this)->JSObjectVerify(); |
| 134 | break; |
| 135 | case JS_VALUE_TYPE: |
| 136 | JSValue::cast(this)->JSValueVerify(); |
| 137 | break; |
| 138 | case JS_FUNCTION_TYPE: |
| 139 | JSFunction::cast(this)->JSFunctionVerify(); |
| 140 | break; |
| 141 | case JS_GLOBAL_PROXY_TYPE: |
| 142 | JSGlobalProxy::cast(this)->JSGlobalProxyVerify(); |
| 143 | break; |
| 144 | case JS_GLOBAL_OBJECT_TYPE: |
| 145 | JSGlobalObject::cast(this)->JSGlobalObjectVerify(); |
| 146 | break; |
| 147 | case JS_BUILTINS_OBJECT_TYPE: |
| 148 | JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify(); |
| 149 | break; |
| 150 | case JS_GLOBAL_PROPERTY_CELL_TYPE: |
| 151 | JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellVerify(); |
| 152 | break; |
| 153 | case JS_ARRAY_TYPE: |
| 154 | JSArray::cast(this)->JSArrayVerify(); |
| 155 | break; |
| 156 | case JS_REGEXP_TYPE: |
| 157 | JSRegExp::cast(this)->JSRegExpVerify(); |
| 158 | break; |
| 159 | case FILLER_TYPE: |
| 160 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 161 | case JS_PROXY_TYPE: |
| 162 | JSProxy::cast(this)->JSProxyVerify(); |
| 163 | break; |
| 164 | case FOREIGN_TYPE: |
| 165 | Foreign::cast(this)->ForeignVerify(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 166 | break; |
| 167 | case SHARED_FUNCTION_INFO_TYPE: |
| 168 | SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify(); |
| 169 | break; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 170 | case JS_MESSAGE_OBJECT_TYPE: |
| 171 | JSMessageObject::cast(this)->JSMessageObjectVerify(); |
| 172 | break; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 173 | |
| 174 | #define MAKE_STRUCT_CASE(NAME, Name, name) \ |
| 175 | case NAME##_TYPE: \ |
| 176 | Name::cast(this)->Name##Verify(); \ |
| 177 | break; |
| 178 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 179 | #undef MAKE_STRUCT_CASE |
| 180 | |
| 181 | default: |
| 182 | UNREACHABLE(); |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | |
| 188 | void HeapObject::VerifyHeapPointer(Object* p) { |
| 189 | ASSERT(p->IsHeapObject()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 190 | ASSERT(HEAP->Contains(HeapObject::cast(p))); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | |
| 194 | void HeapNumber::HeapNumberVerify() { |
| 195 | ASSERT(IsHeapNumber()); |
| 196 | } |
| 197 | |
| 198 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 199 | void ByteArray::ByteArrayVerify() { |
| 200 | ASSERT(IsByteArray()); |
| 201 | } |
| 202 | |
| 203 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 204 | void ExternalPixelArray::ExternalPixelArrayVerify() { |
| 205 | ASSERT(IsExternalPixelArray()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 209 | void ExternalByteArray::ExternalByteArrayVerify() { |
| 210 | ASSERT(IsExternalByteArray()); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | void ExternalUnsignedByteArray::ExternalUnsignedByteArrayVerify() { |
| 215 | ASSERT(IsExternalUnsignedByteArray()); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | void ExternalShortArray::ExternalShortArrayVerify() { |
| 220 | ASSERT(IsExternalShortArray()); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | void ExternalUnsignedShortArray::ExternalUnsignedShortArrayVerify() { |
| 225 | ASSERT(IsExternalUnsignedShortArray()); |
| 226 | } |
| 227 | |
| 228 | |
| 229 | void ExternalIntArray::ExternalIntArrayVerify() { |
| 230 | ASSERT(IsExternalIntArray()); |
| 231 | } |
| 232 | |
| 233 | |
| 234 | void ExternalUnsignedIntArray::ExternalUnsignedIntArrayVerify() { |
| 235 | ASSERT(IsExternalUnsignedIntArray()); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | void ExternalFloatArray::ExternalFloatArrayVerify() { |
| 240 | ASSERT(IsExternalFloatArray()); |
| 241 | } |
| 242 | |
| 243 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 244 | void ExternalDoubleArray::ExternalDoubleArrayVerify() { |
| 245 | ASSERT(IsExternalDoubleArray()); |
| 246 | } |
| 247 | |
| 248 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 249 | void JSObject::JSObjectVerify() { |
| 250 | VerifyHeapPointer(properties()); |
| 251 | VerifyHeapPointer(elements()); |
| 252 | if (HasFastProperties()) { |
| 253 | CHECK_EQ(map()->unused_property_fields(), |
| 254 | (map()->inobject_properties() + properties()->length() - |
| 255 | map()->NextFreePropertyIndex())); |
| 256 | } |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 257 | ASSERT(map()->has_fast_elements() == |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 258 | (elements()->map() == GetHeap()->fixed_array_map() || |
| 259 | elements()->map() == GetHeap()->fixed_cow_array_map())); |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 260 | ASSERT(map()->has_fast_elements() == HasFastElements()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 264 | void Map::MapVerify() { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 265 | ASSERT(!HEAP->InNewSpace(this)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 266 | ASSERT(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE); |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 267 | ASSERT(instance_size() == kVariableSizeSentinel || |
| 268 | (kPointerSize <= instance_size() && |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 269 | instance_size() < HEAP->Capacity())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 270 | VerifyHeapPointer(prototype()); |
| 271 | VerifyHeapPointer(instance_descriptors()); |
| 272 | } |
| 273 | |
| 274 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 275 | void Map::SharedMapVerify() { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 276 | MapVerify(); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 277 | ASSERT(is_shared()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 278 | ASSERT(instance_descriptors()->IsEmpty()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 279 | ASSERT_EQ(0, pre_allocated_property_fields()); |
| 280 | ASSERT_EQ(0, unused_property_fields()); |
| 281 | ASSERT_EQ(StaticVisitorBase::GetVisitorId(instance_type(), instance_size()), |
| 282 | visitor_id()); |
| 283 | } |
| 284 | |
| 285 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 286 | void CodeCache::CodeCacheVerify() { |
| 287 | VerifyHeapPointer(default_cache()); |
| 288 | VerifyHeapPointer(normal_type_cache()); |
| 289 | ASSERT(default_cache()->IsFixedArray()); |
| 290 | ASSERT(normal_type_cache()->IsUndefined() |
| 291 | || normal_type_cache()->IsCodeCacheHashTable()); |
| 292 | } |
| 293 | |
| 294 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 295 | void PolymorphicCodeCache::PolymorphicCodeCacheVerify() { |
| 296 | VerifyHeapPointer(cache()); |
| 297 | ASSERT(cache()->IsUndefined() || cache()->IsPolymorphicCodeCacheHashTable()); |
| 298 | } |
| 299 | |
| 300 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 301 | void FixedArray::FixedArrayVerify() { |
| 302 | for (int i = 0; i < length(); i++) { |
| 303 | Object* e = get(i); |
| 304 | if (e->IsHeapObject()) { |
| 305 | VerifyHeapPointer(e); |
| 306 | } else { |
| 307 | e->Verify(); |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 313 | void FixedDoubleArray::FixedDoubleArrayVerify() { |
| 314 | for (int i = 0; i < length(); i++) { |
| 315 | if (!is_the_hole(i)) { |
| 316 | double value = get(i); |
| 317 | ASSERT(!isnan(value) || |
| 318 | (BitCast<uint64_t>(value) == |
| 319 | BitCast<uint64_t>(canonical_not_the_hole_nan_as_double()))); |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 325 | void JSValue::JSValueVerify() { |
| 326 | Object* v = value(); |
| 327 | if (v->IsHeapObject()) { |
| 328 | VerifyHeapPointer(v); |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 333 | void JSMessageObject::JSMessageObjectVerify() { |
| 334 | CHECK(IsJSMessageObject()); |
| 335 | CHECK(type()->IsString()); |
| 336 | CHECK(arguments()->IsJSArray()); |
| 337 | VerifyObjectField(kStartPositionOffset); |
| 338 | VerifyObjectField(kEndPositionOffset); |
| 339 | VerifyObjectField(kArgumentsOffset); |
| 340 | VerifyObjectField(kScriptOffset); |
| 341 | VerifyObjectField(kStackTraceOffset); |
| 342 | VerifyObjectField(kStackFramesOffset); |
| 343 | } |
| 344 | |
| 345 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 346 | void String::StringVerify() { |
| 347 | CHECK(IsString()); |
| 348 | CHECK(length() >= 0 && length() <= Smi::kMaxValue); |
| 349 | if (IsSymbol()) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 350 | CHECK(!HEAP->InNewSpace(this)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 355 | void JSFunction::JSFunctionVerify() { |
| 356 | CHECK(IsJSFunction()); |
| 357 | VerifyObjectField(kPrototypeOrInitialMapOffset); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 358 | VerifyObjectField(kNextFunctionLinkOffset); |
| 359 | CHECK(next_function_link()->IsUndefined() || |
| 360 | next_function_link()->IsJSFunction()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 364 | void SharedFunctionInfo::SharedFunctionInfoVerify() { |
| 365 | CHECK(IsSharedFunctionInfo()); |
| 366 | VerifyObjectField(kNameOffset); |
| 367 | VerifyObjectField(kCodeOffset); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 368 | VerifyObjectField(kScopeInfoOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 369 | VerifyObjectField(kInstanceClassNameOffset); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 370 | VerifyObjectField(kFunctionDataOffset); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 371 | VerifyObjectField(kScriptOffset); |
| 372 | VerifyObjectField(kDebugInfoOffset); |
| 373 | } |
| 374 | |
| 375 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 376 | void JSGlobalProxy::JSGlobalProxyVerify() { |
| 377 | CHECK(IsJSGlobalProxy()); |
| 378 | JSObjectVerify(); |
| 379 | VerifyObjectField(JSGlobalProxy::kContextOffset); |
| 380 | // Make sure that this object has no properties, elements. |
| 381 | CHECK_EQ(0, properties()->length()); |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 382 | CHECK(HasFastElements()); |
| 383 | CHECK_EQ(0, FixedArray::cast(elements())->length()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 387 | void JSGlobalObject::JSGlobalObjectVerify() { |
| 388 | CHECK(IsJSGlobalObject()); |
| 389 | JSObjectVerify(); |
| 390 | for (int i = GlobalObject::kBuiltinsOffset; |
| 391 | i < JSGlobalObject::kSize; |
| 392 | i += kPointerSize) { |
| 393 | VerifyObjectField(i); |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 398 | void JSBuiltinsObject::JSBuiltinsObjectVerify() { |
| 399 | CHECK(IsJSBuiltinsObject()); |
| 400 | JSObjectVerify(); |
| 401 | for (int i = GlobalObject::kBuiltinsOffset; |
| 402 | i < JSBuiltinsObject::kSize; |
| 403 | i += kPointerSize) { |
| 404 | VerifyObjectField(i); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | |
| 409 | void Oddball::OddballVerify() { |
| 410 | CHECK(IsOddball()); |
| 411 | VerifyHeapPointer(to_string()); |
| 412 | Object* number = to_number(); |
| 413 | if (number->IsHeapObject()) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 414 | ASSERT(number == HEAP->nan_value()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 415 | } else { |
| 416 | ASSERT(number->IsSmi()); |
| 417 | int value = Smi::cast(number)->value(); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 418 | // Hidden oddballs have negative smis. |
| 419 | const int kLeastHiddenOddballNumber = -4; |
| 420 | ASSERT(value <= 1); |
| 421 | ASSERT(value >= kLeastHiddenOddballNumber); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
| 425 | |
| 426 | void JSGlobalPropertyCell::JSGlobalPropertyCellVerify() { |
| 427 | CHECK(IsJSGlobalPropertyCell()); |
| 428 | VerifyObjectField(kValueOffset); |
| 429 | } |
| 430 | |
| 431 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 432 | void Code::CodeVerify() { |
| 433 | CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()), |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 434 | kCodeAlignment)); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 435 | Address last_gc_pc = NULL; |
| 436 | for (RelocIterator it(this); !it.done(); it.next()) { |
| 437 | it.rinfo()->Verify(); |
| 438 | // Ensure that GC will not iterate twice over the same pointer. |
| 439 | if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) { |
| 440 | CHECK(it.rinfo()->pc() != last_gc_pc); |
| 441 | last_gc_pc = it.rinfo()->pc(); |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | |
| 447 | void JSArray::JSArrayVerify() { |
| 448 | JSObjectVerify(); |
| 449 | ASSERT(length()->IsNumber() || length()->IsUndefined()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame^] | 450 | ASSERT(elements()->IsUndefined() || |
| 451 | elements()->IsFixedArray() || |
| 452 | elements()->IsFixedDoubleArray()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | |
| 456 | void JSRegExp::JSRegExpVerify() { |
| 457 | JSObjectVerify(); |
| 458 | ASSERT(data()->IsUndefined() || data()->IsFixedArray()); |
| 459 | switch (TypeTag()) { |
| 460 | case JSRegExp::ATOM: { |
| 461 | FixedArray* arr = FixedArray::cast(data()); |
| 462 | ASSERT(arr->get(JSRegExp::kAtomPatternIndex)->IsString()); |
| 463 | break; |
| 464 | } |
| 465 | case JSRegExp::IRREGEXP: { |
| 466 | bool is_native = RegExpImpl::UsesNativeRegExp(); |
| 467 | |
| 468 | FixedArray* arr = FixedArray::cast(data()); |
| 469 | Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 470 | // Smi : Not compiled yet (-1) or code prepared for flushing. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 471 | // JSObject: Compilation error. |
| 472 | // Code/ByteArray: Compiled code. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 473 | ASSERT(ascii_data->IsSmi() || |
| 474 | (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray())); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 475 | Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 476 | ASSERT(uc16_data->IsSmi() || |
| 477 | (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray())); |
| 478 | |
| 479 | Object* ascii_saved = arr->get(JSRegExp::kIrregexpASCIICodeSavedIndex); |
| 480 | ASSERT(ascii_saved->IsSmi() || ascii_saved->IsString() || |
| 481 | ascii_saved->IsCode()); |
| 482 | Object* uc16_saved = arr->get(JSRegExp::kIrregexpUC16CodeSavedIndex); |
| 483 | ASSERT(uc16_saved->IsSmi() || uc16_saved->IsString() || |
| 484 | uc16_saved->IsCode()); |
| 485 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 486 | ASSERT(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi()); |
| 487 | ASSERT(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi()); |
| 488 | break; |
| 489 | } |
| 490 | default: |
| 491 | ASSERT_EQ(JSRegExp::NOT_COMPILED, TypeTag()); |
| 492 | ASSERT(data()->IsUndefined()); |
| 493 | break; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 498 | void JSProxy::JSProxyVerify() { |
| 499 | ASSERT(IsJSProxy()); |
| 500 | VerifyPointer(handler()); |
| 501 | } |
| 502 | |
| 503 | void Foreign::ForeignVerify() { |
| 504 | ASSERT(IsForeign()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | |
| 508 | void AccessorInfo::AccessorInfoVerify() { |
| 509 | CHECK(IsAccessorInfo()); |
| 510 | VerifyPointer(getter()); |
| 511 | VerifyPointer(setter()); |
| 512 | VerifyPointer(name()); |
| 513 | VerifyPointer(data()); |
| 514 | VerifyPointer(flag()); |
| 515 | } |
| 516 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 517 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 518 | void AccessCheckInfo::AccessCheckInfoVerify() { |
| 519 | CHECK(IsAccessCheckInfo()); |
| 520 | VerifyPointer(named_callback()); |
| 521 | VerifyPointer(indexed_callback()); |
| 522 | VerifyPointer(data()); |
| 523 | } |
| 524 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 525 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 526 | void InterceptorInfo::InterceptorInfoVerify() { |
| 527 | CHECK(IsInterceptorInfo()); |
| 528 | VerifyPointer(getter()); |
| 529 | VerifyPointer(setter()); |
| 530 | VerifyPointer(query()); |
| 531 | VerifyPointer(deleter()); |
| 532 | VerifyPointer(enumerator()); |
| 533 | VerifyPointer(data()); |
| 534 | } |
| 535 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 536 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 537 | void CallHandlerInfo::CallHandlerInfoVerify() { |
| 538 | CHECK(IsCallHandlerInfo()); |
| 539 | VerifyPointer(callback()); |
| 540 | VerifyPointer(data()); |
| 541 | } |
| 542 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 543 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 544 | void TemplateInfo::TemplateInfoVerify() { |
| 545 | VerifyPointer(tag()); |
| 546 | VerifyPointer(property_list()); |
| 547 | } |
| 548 | |
| 549 | void FunctionTemplateInfo::FunctionTemplateInfoVerify() { |
| 550 | CHECK(IsFunctionTemplateInfo()); |
| 551 | TemplateInfoVerify(); |
| 552 | VerifyPointer(serial_number()); |
| 553 | VerifyPointer(call_code()); |
| 554 | VerifyPointer(property_accessors()); |
| 555 | VerifyPointer(prototype_template()); |
| 556 | VerifyPointer(parent_template()); |
| 557 | VerifyPointer(named_property_handler()); |
| 558 | VerifyPointer(indexed_property_handler()); |
| 559 | VerifyPointer(instance_template()); |
| 560 | VerifyPointer(signature()); |
| 561 | VerifyPointer(access_check_info()); |
| 562 | } |
| 563 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 564 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 565 | void ObjectTemplateInfo::ObjectTemplateInfoVerify() { |
| 566 | CHECK(IsObjectTemplateInfo()); |
| 567 | TemplateInfoVerify(); |
| 568 | VerifyPointer(constructor()); |
| 569 | VerifyPointer(internal_field_count()); |
| 570 | } |
| 571 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 572 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 573 | void SignatureInfo::SignatureInfoVerify() { |
| 574 | CHECK(IsSignatureInfo()); |
| 575 | VerifyPointer(receiver()); |
| 576 | VerifyPointer(args()); |
| 577 | } |
| 578 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 579 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 580 | void TypeSwitchInfo::TypeSwitchInfoVerify() { |
| 581 | CHECK(IsTypeSwitchInfo()); |
| 582 | VerifyPointer(types()); |
| 583 | } |
| 584 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 585 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 586 | void Script::ScriptVerify() { |
| 587 | CHECK(IsScript()); |
| 588 | VerifyPointer(source()); |
| 589 | VerifyPointer(name()); |
| 590 | line_offset()->SmiVerify(); |
| 591 | column_offset()->SmiVerify(); |
| 592 | VerifyPointer(data()); |
| 593 | VerifyPointer(wrapper()); |
| 594 | type()->SmiVerify(); |
| 595 | VerifyPointer(line_ends()); |
| 596 | VerifyPointer(id()); |
| 597 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 598 | |
| 599 | |
| 600 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 601 | void DebugInfo::DebugInfoVerify() { |
| 602 | CHECK(IsDebugInfo()); |
| 603 | VerifyPointer(shared()); |
| 604 | VerifyPointer(original_code()); |
| 605 | VerifyPointer(code()); |
| 606 | VerifyPointer(break_points()); |
| 607 | } |
| 608 | |
| 609 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 610 | void BreakPointInfo::BreakPointInfoVerify() { |
| 611 | CHECK(IsBreakPointInfo()); |
| 612 | code_position()->SmiVerify(); |
| 613 | source_position()->SmiVerify(); |
| 614 | statement_position()->SmiVerify(); |
| 615 | VerifyPointer(break_point_objects()); |
| 616 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 617 | #endif // ENABLE_DEBUGGER_SUPPORT |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 618 | |
| 619 | |
| 620 | void JSObject::IncrementSpillStatistics(SpillInformation* info) { |
| 621 | info->number_of_objects_++; |
| 622 | // Named properties |
| 623 | if (HasFastProperties()) { |
| 624 | info->number_of_objects_with_fast_properties_++; |
| 625 | info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex(); |
| 626 | info->number_of_fast_unused_fields_ += map()->unused_property_fields(); |
| 627 | } else { |
| 628 | StringDictionary* dict = property_dictionary(); |
| 629 | info->number_of_slow_used_properties_ += dict->NumberOfElements(); |
| 630 | info->number_of_slow_unused_properties_ += |
| 631 | dict->Capacity() - dict->NumberOfElements(); |
| 632 | } |
| 633 | // Indexed properties |
| 634 | switch (GetElementsKind()) { |
| 635 | case FAST_ELEMENTS: { |
| 636 | info->number_of_objects_with_fast_elements_++; |
| 637 | int holes = 0; |
| 638 | FixedArray* e = FixedArray::cast(elements()); |
| 639 | int len = e->length(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 640 | Heap* heap = HEAP; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 641 | for (int i = 0; i < len; i++) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 642 | if (e->get(i) == heap->the_hole_value()) holes++; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 643 | } |
| 644 | info->number_of_fast_used_elements_ += len - holes; |
| 645 | info->number_of_fast_unused_elements_ += holes; |
| 646 | break; |
| 647 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 648 | case EXTERNAL_PIXEL_ELEMENTS: { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 649 | info->number_of_objects_with_fast_elements_++; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 650 | ExternalPixelArray* e = ExternalPixelArray::cast(elements()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 651 | info->number_of_fast_used_elements_ += e->length(); |
| 652 | break; |
| 653 | } |
| 654 | case DICTIONARY_ELEMENTS: { |
| 655 | NumberDictionary* dict = element_dictionary(); |
| 656 | info->number_of_slow_used_elements_ += dict->NumberOfElements(); |
| 657 | info->number_of_slow_unused_elements_ += |
| 658 | dict->Capacity() - dict->NumberOfElements(); |
| 659 | break; |
| 660 | } |
| 661 | default: |
| 662 | UNREACHABLE(); |
| 663 | break; |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | |
| 668 | void JSObject::SpillInformation::Clear() { |
| 669 | number_of_objects_ = 0; |
| 670 | number_of_objects_with_fast_properties_ = 0; |
| 671 | number_of_objects_with_fast_elements_ = 0; |
| 672 | number_of_fast_used_fields_ = 0; |
| 673 | number_of_fast_unused_fields_ = 0; |
| 674 | number_of_slow_used_properties_ = 0; |
| 675 | number_of_slow_unused_properties_ = 0; |
| 676 | number_of_fast_used_elements_ = 0; |
| 677 | number_of_fast_unused_elements_ = 0; |
| 678 | number_of_slow_used_elements_ = 0; |
| 679 | number_of_slow_unused_elements_ = 0; |
| 680 | } |
| 681 | |
| 682 | void JSObject::SpillInformation::Print() { |
| 683 | PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_); |
| 684 | |
| 685 | PrintF(" - fast properties (#%d): %d (used) %d (unused)\n", |
| 686 | number_of_objects_with_fast_properties_, |
| 687 | number_of_fast_used_fields_, number_of_fast_unused_fields_); |
| 688 | |
| 689 | PrintF(" - slow properties (#%d): %d (used) %d (unused)\n", |
| 690 | number_of_objects_ - number_of_objects_with_fast_properties_, |
| 691 | number_of_slow_used_properties_, number_of_slow_unused_properties_); |
| 692 | |
| 693 | PrintF(" - fast elements (#%d): %d (used) %d (unused)\n", |
| 694 | number_of_objects_with_fast_elements_, |
| 695 | number_of_fast_used_elements_, number_of_fast_unused_elements_); |
| 696 | |
| 697 | PrintF(" - slow elements (#%d): %d (used) %d (unused)\n", |
| 698 | number_of_objects_ - number_of_objects_with_fast_elements_, |
| 699 | number_of_slow_used_elements_, number_of_slow_unused_elements_); |
| 700 | |
| 701 | PrintF("\n"); |
| 702 | } |
| 703 | |
| 704 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 705 | bool DescriptorArray::IsSortedNoDuplicates() { |
| 706 | String* current_key = NULL; |
| 707 | uint32_t current = 0; |
| 708 | for (int i = 0; i < number_of_descriptors(); i++) { |
| 709 | String* key = GetKey(i); |
| 710 | if (key == current_key) { |
| 711 | PrintDescriptors(); |
| 712 | return false; |
| 713 | } |
| 714 | current_key = key; |
| 715 | uint32_t hash = GetKey(i)->Hash(); |
| 716 | if (hash < current) { |
| 717 | PrintDescriptors(); |
| 718 | return false; |
| 719 | } |
| 720 | current = hash; |
| 721 | } |
| 722 | return true; |
| 723 | } |
| 724 | |
| 725 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 726 | void JSFunctionResultCache::JSFunctionResultCacheVerify() { |
| 727 | JSFunction::cast(get(kFactoryIndex))->Verify(); |
| 728 | |
| 729 | int size = Smi::cast(get(kCacheSizeIndex))->value(); |
| 730 | ASSERT(kEntriesIndex <= size); |
| 731 | ASSERT(size <= length()); |
| 732 | ASSERT_EQ(0, size % kEntrySize); |
| 733 | |
| 734 | int finger = Smi::cast(get(kFingerIndex))->value(); |
| 735 | ASSERT(kEntriesIndex <= finger); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 736 | ASSERT((finger < size) || (finger == kEntriesIndex && finger == size)); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 737 | ASSERT_EQ(0, finger % kEntrySize); |
| 738 | |
| 739 | if (FLAG_enable_slow_asserts) { |
| 740 | for (int i = kEntriesIndex; i < size; i++) { |
| 741 | ASSERT(!get(i)->IsTheHole()); |
| 742 | get(i)->Verify(); |
| 743 | } |
| 744 | for (int i = size; i < length(); i++) { |
| 745 | ASSERT(get(i)->IsTheHole()); |
| 746 | get(i)->Verify(); |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 752 | void NormalizedMapCache::NormalizedMapCacheVerify() { |
| 753 | FixedArray::cast(this)->Verify(); |
| 754 | if (FLAG_enable_slow_asserts) { |
| 755 | for (int i = 0; i < length(); i++) { |
| 756 | Object* e = get(i); |
| 757 | if (e->IsMap()) { |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 758 | Map::cast(e)->SharedMapVerify(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 759 | } else { |
| 760 | ASSERT(e->IsUndefined()); |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 767 | #endif // DEBUG |
| 768 | |
| 769 | } } // namespace v8::internal |