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