fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame^] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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" |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 32 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 33 | #include "objects-visiting.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 35 | namespace v8 { |
| 36 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 37 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 38 | #ifdef DEBUG |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame^] | 39 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [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 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | } else { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 49 | Failure::cast(this)->FailureVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 94 | case PIXEL_ARRAY_TYPE: |
| 95 | PixelArray::cast(this)->PixelArrayVerify(); |
| 96 | break; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +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; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 119 | case CODE_TYPE: |
| 120 | Code::cast(this)->CodeVerify(); |
| 121 | break; |
| 122 | case ODDBALL_TYPE: |
| 123 | Oddball::cast(this)->OddballVerify(); |
| 124 | break; |
| 125 | case JS_OBJECT_TYPE: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 126 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 127 | JSObject::cast(this)->JSObjectVerify(); |
| 128 | break; |
| 129 | case JS_VALUE_TYPE: |
| 130 | JSValue::cast(this)->JSValueVerify(); |
| 131 | break; |
| 132 | case JS_FUNCTION_TYPE: |
| 133 | JSFunction::cast(this)->JSFunctionVerify(); |
| 134 | break; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 135 | case JS_GLOBAL_PROXY_TYPE: |
| 136 | JSGlobalProxy::cast(this)->JSGlobalProxyVerify(); |
| 137 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | case JS_GLOBAL_OBJECT_TYPE: |
| 139 | JSGlobalObject::cast(this)->JSGlobalObjectVerify(); |
| 140 | break; |
| 141 | case JS_BUILTINS_OBJECT_TYPE: |
| 142 | JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify(); |
| 143 | break; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 144 | case JS_GLOBAL_PROPERTY_CELL_TYPE: |
| 145 | JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellVerify(); |
| 146 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 147 | case JS_ARRAY_TYPE: |
| 148 | JSArray::cast(this)->JSArrayVerify(); |
| 149 | break; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 150 | case JS_REGEXP_TYPE: |
| 151 | JSRegExp::cast(this)->JSRegExpVerify(); |
| 152 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | case FILLER_TYPE: |
| 154 | break; |
| 155 | case PROXY_TYPE: |
| 156 | Proxy::cast(this)->ProxyVerify(); |
| 157 | break; |
| 158 | case SHARED_FUNCTION_INFO_TYPE: |
| 159 | SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify(); |
| 160 | break; |
| 161 | |
| 162 | #define MAKE_STRUCT_CASE(NAME, Name, name) \ |
| 163 | case NAME##_TYPE: \ |
| 164 | Name::cast(this)->Name##Verify(); \ |
| 165 | break; |
| 166 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 167 | #undef MAKE_STRUCT_CASE |
| 168 | |
| 169 | default: |
| 170 | UNREACHABLE(); |
| 171 | break; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | |
| 176 | void HeapObject::VerifyHeapPointer(Object* p) { |
| 177 | ASSERT(p->IsHeapObject()); |
| 178 | ASSERT(Heap::Contains(HeapObject::cast(p))); |
| 179 | } |
| 180 | |
| 181 | |
| 182 | void HeapNumber::HeapNumberVerify() { |
| 183 | ASSERT(IsHeapNumber()); |
| 184 | } |
| 185 | |
| 186 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | void ByteArray::ByteArrayVerify() { |
| 188 | ASSERT(IsByteArray()); |
| 189 | } |
| 190 | |
| 191 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 192 | void PixelArray::PixelArrayVerify() { |
| 193 | ASSERT(IsPixelArray()); |
| 194 | } |
| 195 | |
| 196 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 197 | void ExternalByteArray::ExternalByteArrayVerify() { |
| 198 | ASSERT(IsExternalByteArray()); |
| 199 | } |
| 200 | |
| 201 | |
| 202 | void ExternalUnsignedByteArray::ExternalUnsignedByteArrayVerify() { |
| 203 | ASSERT(IsExternalUnsignedByteArray()); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | void ExternalShortArray::ExternalShortArrayVerify() { |
| 208 | ASSERT(IsExternalShortArray()); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | void ExternalUnsignedShortArray::ExternalUnsignedShortArrayVerify() { |
| 213 | ASSERT(IsExternalUnsignedShortArray()); |
| 214 | } |
| 215 | |
| 216 | |
| 217 | void ExternalIntArray::ExternalIntArrayVerify() { |
| 218 | ASSERT(IsExternalIntArray()); |
| 219 | } |
| 220 | |
| 221 | |
| 222 | void ExternalUnsignedIntArray::ExternalUnsignedIntArrayVerify() { |
| 223 | ASSERT(IsExternalUnsignedIntArray()); |
| 224 | } |
| 225 | |
| 226 | |
| 227 | void ExternalFloatArray::ExternalFloatArrayVerify() { |
| 228 | ASSERT(IsExternalFloatArray()); |
| 229 | } |
| 230 | |
| 231 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 232 | void JSObject::JSObjectVerify() { |
| 233 | VerifyHeapPointer(properties()); |
| 234 | VerifyHeapPointer(elements()); |
| 235 | if (HasFastProperties()) { |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 236 | CHECK_EQ(map()->unused_property_fields(), |
| 237 | (map()->inobject_properties() + properties()->length() - |
| 238 | map()->NextFreePropertyIndex())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 239 | } |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 240 | ASSERT(map()->has_fast_elements() == |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 241 | (elements()->map() == Heap::fixed_array_map() || |
| 242 | elements()->map() == Heap::fixed_cow_array_map())); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 243 | ASSERT(map()->has_fast_elements() == HasFastElements()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 247 | void Map::MapVerify() { |
| 248 | ASSERT(!Heap::InNewSpace(this)); |
| 249 | ASSERT(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 250 | ASSERT(instance_size() == kVariableSizeSentinel || |
| 251 | (kPointerSize <= instance_size() && |
| 252 | instance_size() < Heap::Capacity())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 253 | VerifyHeapPointer(prototype()); |
| 254 | VerifyHeapPointer(instance_descriptors()); |
| 255 | } |
| 256 | |
| 257 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 258 | void Map::SharedMapVerify() { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 259 | MapVerify(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 260 | ASSERT(is_shared()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 261 | ASSERT_EQ(Heap::empty_descriptor_array(), instance_descriptors()); |
| 262 | ASSERT_EQ(Heap::empty_fixed_array(), code_cache()); |
| 263 | ASSERT_EQ(0, pre_allocated_property_fields()); |
| 264 | ASSERT_EQ(0, unused_property_fields()); |
| 265 | ASSERT_EQ(StaticVisitorBase::GetVisitorId(instance_type(), instance_size()), |
| 266 | visitor_id()); |
| 267 | } |
| 268 | |
| 269 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 270 | void CodeCache::CodeCacheVerify() { |
| 271 | VerifyHeapPointer(default_cache()); |
| 272 | VerifyHeapPointer(normal_type_cache()); |
| 273 | ASSERT(default_cache()->IsFixedArray()); |
| 274 | ASSERT(normal_type_cache()->IsUndefined() |
| 275 | || normal_type_cache()->IsCodeCacheHashTable()); |
| 276 | } |
| 277 | |
| 278 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 279 | void FixedArray::FixedArrayVerify() { |
| 280 | for (int i = 0; i < length(); i++) { |
| 281 | Object* e = get(i); |
| 282 | if (e->IsHeapObject()) { |
| 283 | VerifyHeapPointer(e); |
| 284 | } else { |
| 285 | e->Verify(); |
| 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 291 | void JSValue::JSValueVerify() { |
| 292 | Object* v = value(); |
| 293 | if (v->IsHeapObject()) { |
| 294 | VerifyHeapPointer(v); |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 299 | void String::StringVerify() { |
| 300 | CHECK(IsString()); |
| 301 | CHECK(length() >= 0 && length() <= Smi::kMaxValue); |
| 302 | if (IsSymbol()) { |
| 303 | CHECK(!Heap::InNewSpace(this)); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 308 | void JSFunction::JSFunctionVerify() { |
| 309 | CHECK(IsJSFunction()); |
| 310 | VerifyObjectField(kPrototypeOrInitialMapOffset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 311 | VerifyObjectField(kNextFunctionLinkOffset); |
| 312 | CHECK(next_function_link()->IsUndefined() || |
| 313 | next_function_link()->IsJSFunction()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 317 | void SharedFunctionInfo::SharedFunctionInfoVerify() { |
| 318 | CHECK(IsSharedFunctionInfo()); |
| 319 | VerifyObjectField(kNameOffset); |
| 320 | VerifyObjectField(kCodeOffset); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 321 | VerifyObjectField(kScopeInfoOffset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 322 | VerifyObjectField(kInstanceClassNameOffset); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 323 | VerifyObjectField(kFunctionDataOffset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 324 | VerifyObjectField(kScriptOffset); |
| 325 | VerifyObjectField(kDebugInfoOffset); |
| 326 | } |
| 327 | |
| 328 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 329 | void JSGlobalProxy::JSGlobalProxyVerify() { |
| 330 | CHECK(IsJSGlobalProxy()); |
| 331 | JSObjectVerify(); |
| 332 | VerifyObjectField(JSGlobalProxy::kContextOffset); |
| 333 | // Make sure that this object has no properties, elements. |
| 334 | CHECK_EQ(0, properties()->length()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 335 | CHECK(HasFastElements()); |
| 336 | CHECK_EQ(0, FixedArray::cast(elements())->length()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 340 | void JSGlobalObject::JSGlobalObjectVerify() { |
| 341 | CHECK(IsJSGlobalObject()); |
| 342 | JSObjectVerify(); |
| 343 | for (int i = GlobalObject::kBuiltinsOffset; |
| 344 | i < JSGlobalObject::kSize; |
| 345 | i += kPointerSize) { |
| 346 | VerifyObjectField(i); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 351 | void JSBuiltinsObject::JSBuiltinsObjectVerify() { |
| 352 | CHECK(IsJSBuiltinsObject()); |
| 353 | JSObjectVerify(); |
| 354 | for (int i = GlobalObject::kBuiltinsOffset; |
| 355 | i < JSBuiltinsObject::kSize; |
| 356 | i += kPointerSize) { |
| 357 | VerifyObjectField(i); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | |
| 362 | void Oddball::OddballVerify() { |
| 363 | CHECK(IsOddball()); |
| 364 | VerifyHeapPointer(to_string()); |
| 365 | Object* number = to_number(); |
| 366 | if (number->IsHeapObject()) { |
| 367 | ASSERT(number == Heap::nan_value()); |
| 368 | } else { |
| 369 | ASSERT(number->IsSmi()); |
| 370 | int value = Smi::cast(number)->value(); |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 371 | ASSERT(value == 0 || value == 1 || value == -1 || |
| 372 | value == -2 || value == -3); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
| 376 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 377 | void JSGlobalPropertyCell::JSGlobalPropertyCellVerify() { |
| 378 | CHECK(IsJSGlobalPropertyCell()); |
| 379 | VerifyObjectField(kValueOffset); |
| 380 | } |
| 381 | |
| 382 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | void Code::CodeVerify() { |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 384 | CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()), |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 385 | kCodeAlignment)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 386 | Address last_gc_pc = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 387 | for (RelocIterator it(this); !it.done(); it.next()) { |
| 388 | it.rinfo()->Verify(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 389 | // Ensure that GC will not iterate twice over the same pointer. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 390 | if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 391 | CHECK(it.rinfo()->pc() != last_gc_pc); |
| 392 | last_gc_pc = it.rinfo()->pc(); |
| 393 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
| 397 | |
| 398 | void JSArray::JSArrayVerify() { |
| 399 | JSObjectVerify(); |
| 400 | ASSERT(length()->IsNumber() || length()->IsUndefined()); |
| 401 | ASSERT(elements()->IsUndefined() || elements()->IsFixedArray()); |
| 402 | } |
| 403 | |
| 404 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 405 | void JSRegExp::JSRegExpVerify() { |
| 406 | JSObjectVerify(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 407 | ASSERT(data()->IsUndefined() || data()->IsFixedArray()); |
| 408 | switch (TypeTag()) { |
| 409 | case JSRegExp::ATOM: { |
| 410 | FixedArray* arr = FixedArray::cast(data()); |
| 411 | ASSERT(arr->get(JSRegExp::kAtomPatternIndex)->IsString()); |
| 412 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 413 | } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 414 | case JSRegExp::IRREGEXP: { |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 415 | bool is_native = RegExpImpl::UsesNativeRegExp(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 416 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 417 | FixedArray* arr = FixedArray::cast(data()); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 418 | Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 419 | // TheHole : Not compiled yet. |
| 420 | // JSObject: Compilation error. |
| 421 | // Code/ByteArray: Compiled code. |
| 422 | ASSERT(ascii_data->IsTheHole() || ascii_data->IsJSObject() || |
| 423 | (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 424 | Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex); |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 425 | ASSERT(uc16_data->IsTheHole() || ascii_data->IsJSObject() || |
| 426 | (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray())); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 427 | ASSERT(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi()); |
| 428 | ASSERT(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 429 | break; |
| 430 | } |
| 431 | default: |
| 432 | ASSERT_EQ(JSRegExp::NOT_COMPILED, TypeTag()); |
| 433 | ASSERT(data()->IsUndefined()); |
| 434 | break; |
kasperl@chromium.org | 41044eb | 2008-10-06 08:24:46 +0000 | [diff] [blame] | 435 | } |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 439 | void Proxy::ProxyVerify() { |
| 440 | ASSERT(IsProxy()); |
| 441 | } |
| 442 | |
| 443 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 444 | void AccessorInfo::AccessorInfoVerify() { |
| 445 | CHECK(IsAccessorInfo()); |
| 446 | VerifyPointer(getter()); |
| 447 | VerifyPointer(setter()); |
| 448 | VerifyPointer(name()); |
| 449 | VerifyPointer(data()); |
| 450 | VerifyPointer(flag()); |
| 451 | } |
| 452 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 453 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 454 | void AccessCheckInfo::AccessCheckInfoVerify() { |
| 455 | CHECK(IsAccessCheckInfo()); |
| 456 | VerifyPointer(named_callback()); |
| 457 | VerifyPointer(indexed_callback()); |
| 458 | VerifyPointer(data()); |
| 459 | } |
| 460 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 461 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 462 | void InterceptorInfo::InterceptorInfoVerify() { |
| 463 | CHECK(IsInterceptorInfo()); |
| 464 | VerifyPointer(getter()); |
| 465 | VerifyPointer(setter()); |
| 466 | VerifyPointer(query()); |
| 467 | VerifyPointer(deleter()); |
| 468 | VerifyPointer(enumerator()); |
| 469 | VerifyPointer(data()); |
| 470 | } |
| 471 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 472 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 473 | void CallHandlerInfo::CallHandlerInfoVerify() { |
| 474 | CHECK(IsCallHandlerInfo()); |
| 475 | VerifyPointer(callback()); |
| 476 | VerifyPointer(data()); |
| 477 | } |
| 478 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 479 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 480 | void TemplateInfo::TemplateInfoVerify() { |
| 481 | VerifyPointer(tag()); |
| 482 | VerifyPointer(property_list()); |
| 483 | } |
| 484 | |
| 485 | void FunctionTemplateInfo::FunctionTemplateInfoVerify() { |
| 486 | CHECK(IsFunctionTemplateInfo()); |
| 487 | TemplateInfoVerify(); |
| 488 | VerifyPointer(serial_number()); |
| 489 | VerifyPointer(call_code()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 490 | VerifyPointer(property_accessors()); |
| 491 | VerifyPointer(prototype_template()); |
| 492 | VerifyPointer(parent_template()); |
| 493 | VerifyPointer(named_property_handler()); |
| 494 | VerifyPointer(indexed_property_handler()); |
| 495 | VerifyPointer(instance_template()); |
| 496 | VerifyPointer(signature()); |
| 497 | VerifyPointer(access_check_info()); |
| 498 | } |
| 499 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 500 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 501 | void ObjectTemplateInfo::ObjectTemplateInfoVerify() { |
| 502 | CHECK(IsObjectTemplateInfo()); |
| 503 | TemplateInfoVerify(); |
| 504 | VerifyPointer(constructor()); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 505 | VerifyPointer(internal_field_count()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 506 | } |
| 507 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 508 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 509 | void SignatureInfo::SignatureInfoVerify() { |
| 510 | CHECK(IsSignatureInfo()); |
| 511 | VerifyPointer(receiver()); |
| 512 | VerifyPointer(args()); |
| 513 | } |
| 514 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 515 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 516 | void TypeSwitchInfo::TypeSwitchInfoVerify() { |
| 517 | CHECK(IsTypeSwitchInfo()); |
| 518 | VerifyPointer(types()); |
| 519 | } |
| 520 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 521 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 522 | void Script::ScriptVerify() { |
| 523 | CHECK(IsScript()); |
| 524 | VerifyPointer(source()); |
| 525 | VerifyPointer(name()); |
| 526 | line_offset()->SmiVerify(); |
| 527 | column_offset()->SmiVerify(); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 528 | VerifyPointer(data()); |
| 529 | VerifyPointer(wrapper()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 530 | type()->SmiVerify(); |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 531 | VerifyPointer(line_ends()); |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 532 | VerifyPointer(id()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 533 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 534 | |
| 535 | |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 536 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 537 | void DebugInfo::DebugInfoVerify() { |
| 538 | CHECK(IsDebugInfo()); |
| 539 | VerifyPointer(shared()); |
| 540 | VerifyPointer(original_code()); |
| 541 | VerifyPointer(code()); |
| 542 | VerifyPointer(break_points()); |
| 543 | } |
| 544 | |
| 545 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 546 | void BreakPointInfo::BreakPointInfoVerify() { |
| 547 | CHECK(IsBreakPointInfo()); |
| 548 | code_position()->SmiVerify(); |
| 549 | source_position()->SmiVerify(); |
| 550 | statement_position()->SmiVerify(); |
| 551 | VerifyPointer(break_point_objects()); |
| 552 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 553 | #endif // ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 554 | |
| 555 | |
| 556 | void JSObject::IncrementSpillStatistics(SpillInformation* info) { |
| 557 | info->number_of_objects_++; |
| 558 | // Named properties |
| 559 | if (HasFastProperties()) { |
| 560 | info->number_of_objects_with_fast_properties_++; |
| 561 | info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex(); |
| 562 | info->number_of_fast_unused_fields_ += map()->unused_property_fields(); |
| 563 | } else { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 564 | StringDictionary* dict = property_dictionary(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 565 | info->number_of_slow_used_properties_ += dict->NumberOfElements(); |
| 566 | info->number_of_slow_unused_properties_ += |
| 567 | dict->Capacity() - dict->NumberOfElements(); |
| 568 | } |
| 569 | // Indexed properties |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 570 | switch (GetElementsKind()) { |
| 571 | case FAST_ELEMENTS: { |
| 572 | info->number_of_objects_with_fast_elements_++; |
| 573 | int holes = 0; |
| 574 | FixedArray* e = FixedArray::cast(elements()); |
| 575 | int len = e->length(); |
| 576 | for (int i = 0; i < len; i++) { |
| 577 | if (e->get(i) == Heap::the_hole_value()) holes++; |
| 578 | } |
| 579 | info->number_of_fast_used_elements_ += len - holes; |
| 580 | info->number_of_fast_unused_elements_ += holes; |
| 581 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 582 | } |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 583 | case PIXEL_ELEMENTS: { |
| 584 | info->number_of_objects_with_fast_elements_++; |
| 585 | PixelArray* e = PixelArray::cast(elements()); |
| 586 | info->number_of_fast_used_elements_ += e->length(); |
| 587 | break; |
| 588 | } |
| 589 | case DICTIONARY_ELEMENTS: { |
| 590 | NumberDictionary* dict = element_dictionary(); |
| 591 | info->number_of_slow_used_elements_ += dict->NumberOfElements(); |
| 592 | info->number_of_slow_unused_elements_ += |
| 593 | dict->Capacity() - dict->NumberOfElements(); |
| 594 | break; |
| 595 | } |
| 596 | default: |
| 597 | UNREACHABLE(); |
| 598 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
| 602 | |
| 603 | void JSObject::SpillInformation::Clear() { |
| 604 | number_of_objects_ = 0; |
| 605 | number_of_objects_with_fast_properties_ = 0; |
| 606 | number_of_objects_with_fast_elements_ = 0; |
| 607 | number_of_fast_used_fields_ = 0; |
| 608 | number_of_fast_unused_fields_ = 0; |
| 609 | number_of_slow_used_properties_ = 0; |
| 610 | number_of_slow_unused_properties_ = 0; |
| 611 | number_of_fast_used_elements_ = 0; |
| 612 | number_of_fast_unused_elements_ = 0; |
| 613 | number_of_slow_used_elements_ = 0; |
| 614 | number_of_slow_unused_elements_ = 0; |
| 615 | } |
| 616 | |
| 617 | void JSObject::SpillInformation::Print() { |
| 618 | PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_); |
| 619 | |
| 620 | PrintF(" - fast properties (#%d): %d (used) %d (unused)\n", |
| 621 | number_of_objects_with_fast_properties_, |
| 622 | number_of_fast_used_fields_, number_of_fast_unused_fields_); |
| 623 | |
| 624 | PrintF(" - slow properties (#%d): %d (used) %d (unused)\n", |
| 625 | number_of_objects_ - number_of_objects_with_fast_properties_, |
| 626 | number_of_slow_used_properties_, number_of_slow_unused_properties_); |
| 627 | |
| 628 | PrintF(" - fast elements (#%d): %d (used) %d (unused)\n", |
| 629 | number_of_objects_with_fast_elements_, |
| 630 | number_of_fast_used_elements_, number_of_fast_unused_elements_); |
| 631 | |
| 632 | PrintF(" - slow elements (#%d): %d (used) %d (unused)\n", |
| 633 | number_of_objects_ - number_of_objects_with_fast_elements_, |
| 634 | number_of_slow_used_elements_, number_of_slow_unused_elements_); |
| 635 | |
| 636 | PrintF("\n"); |
| 637 | } |
| 638 | |
| 639 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 640 | bool DescriptorArray::IsSortedNoDuplicates() { |
| 641 | String* current_key = NULL; |
| 642 | uint32_t current = 0; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 643 | for (int i = 0; i < number_of_descriptors(); i++) { |
| 644 | String* key = GetKey(i); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 645 | if (key == current_key) { |
| 646 | PrintDescriptors(); |
| 647 | return false; |
| 648 | } |
| 649 | current_key = key; |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 650 | uint32_t hash = GetKey(i)->Hash(); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 651 | if (hash < current) { |
| 652 | PrintDescriptors(); |
| 653 | return false; |
| 654 | } |
| 655 | current = hash; |
| 656 | } |
| 657 | return true; |
| 658 | } |
| 659 | |
| 660 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 661 | void JSFunctionResultCache::JSFunctionResultCacheVerify() { |
| 662 | JSFunction::cast(get(kFactoryIndex))->Verify(); |
| 663 | |
| 664 | int size = Smi::cast(get(kCacheSizeIndex))->value(); |
| 665 | ASSERT(kEntriesIndex <= size); |
| 666 | ASSERT(size <= length()); |
| 667 | ASSERT_EQ(0, size % kEntrySize); |
| 668 | |
| 669 | int finger = Smi::cast(get(kFingerIndex))->value(); |
| 670 | ASSERT(kEntriesIndex <= finger); |
| 671 | ASSERT(finger < size || finger == kEntriesIndex); |
| 672 | ASSERT_EQ(0, finger % kEntrySize); |
| 673 | |
| 674 | if (FLAG_enable_slow_asserts) { |
| 675 | for (int i = kEntriesIndex; i < size; i++) { |
| 676 | ASSERT(!get(i)->IsTheHole()); |
| 677 | get(i)->Verify(); |
| 678 | } |
| 679 | for (int i = size; i < length(); i++) { |
| 680 | ASSERT(get(i)->IsTheHole()); |
| 681 | get(i)->Verify(); |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 687 | void NormalizedMapCache::NormalizedMapCacheVerify() { |
| 688 | FixedArray::cast(this)->Verify(); |
| 689 | if (FLAG_enable_slow_asserts) { |
| 690 | for (int i = 0; i < length(); i++) { |
| 691 | Object* e = get(i); |
| 692 | if (e->IsMap()) { |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 693 | Map::cast(e)->SharedMapVerify(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 694 | } else { |
| 695 | ASSERT(e->IsUndefined()); |
| 696 | } |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 702 | #endif // DEBUG |
| 703 | |
| 704 | } } // namespace v8::internal |