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