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