ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 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" |
| 32 | #include "macro-assembler.h" |
| 33 | |
| 34 | namespace v8 { namespace internal { |
| 35 | |
| 36 | #ifdef DEBUG |
| 37 | |
| 38 | static const char* TypeToString(InstanceType type); |
| 39 | |
| 40 | |
| 41 | void Object::Print() { |
| 42 | if (IsSmi()) { |
| 43 | Smi::cast(this)->SmiPrint(); |
| 44 | } else if (IsFailure()) { |
| 45 | Failure::cast(this)->FailurePrint(); |
| 46 | } else { |
| 47 | HeapObject::cast(this)->HeapObjectPrint(); |
| 48 | } |
| 49 | Flush(); |
| 50 | } |
| 51 | |
| 52 | |
| 53 | void Object::PrintLn() { |
| 54 | Print(); |
| 55 | PrintF("\n"); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | void Object::Verify() { |
| 60 | if (IsSmi()) { |
| 61 | Smi::cast(this)->SmiVerify(); |
| 62 | } else if (IsFailure()) { |
| 63 | Failure::cast(this)->FailureVerify(); |
| 64 | } else { |
| 65 | HeapObject::cast(this)->HeapObjectVerify(); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
| 70 | void Object::VerifyPointer(Object* p) { |
| 71 | if (p->IsHeapObject()) { |
| 72 | HeapObject::VerifyHeapPointer(p); |
| 73 | } else { |
| 74 | ASSERT(p->IsSmi()); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | |
| 79 | void Smi::SmiVerify() { |
| 80 | ASSERT(IsSmi()); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | void Failure::FailureVerify() { |
| 85 | ASSERT(IsFailure()); |
| 86 | } |
| 87 | |
| 88 | |
| 89 | void HeapObject::PrintHeader(const char* id) { |
| 90 | PrintF("%p: [%s]\n", this, id); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | void HeapObject::HeapObjectPrint() { |
| 95 | InstanceType instance_type = map()->instance_type(); |
| 96 | |
| 97 | HandleScope scope; |
| 98 | if (instance_type < FIRST_NONSTRING_TYPE) { |
| 99 | String::cast(this)->StringPrint(); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | switch (instance_type) { |
| 104 | case MAP_TYPE: |
| 105 | Map::cast(this)->MapPrint(); |
| 106 | break; |
| 107 | case HEAP_NUMBER_TYPE: |
| 108 | HeapNumber::cast(this)->HeapNumberPrint(); |
| 109 | break; |
| 110 | case FIXED_ARRAY_TYPE: |
| 111 | FixedArray::cast(this)->FixedArrayPrint(); |
| 112 | break; |
| 113 | case BYTE_ARRAY_TYPE: |
| 114 | ByteArray::cast(this)->ByteArrayPrint(); |
| 115 | break; |
| 116 | case FILLER_TYPE: |
| 117 | PrintF("filler"); |
| 118 | break; |
| 119 | case JS_OBJECT_TYPE: // fall through |
| 120 | case JS_ARRAY_TYPE: |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 121 | case JS_REGEXP_TYPE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | JSObject::cast(this)->JSObjectPrint(); |
| 123 | break; |
| 124 | case ODDBALL_TYPE: |
| 125 | Oddball::cast(this)->to_string()->Print(); |
| 126 | break; |
| 127 | case JS_FUNCTION_TYPE: |
| 128 | JSFunction::cast(this)->JSFunctionPrint(); |
| 129 | break; |
| 130 | case JS_GLOBAL_OBJECT_TYPE: |
| 131 | JSGlobalObject::cast(this)->JSGlobalObjectPrint(); |
| 132 | break; |
| 133 | case JS_BUILTINS_OBJECT_TYPE: |
| 134 | JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(); |
| 135 | break; |
| 136 | case JS_VALUE_TYPE: |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 137 | PrintF("Value wrapper around:"); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 138 | JSValue::cast(this)->value()->Print(); |
| 139 | break; |
| 140 | case CODE_TYPE: |
| 141 | Code::cast(this)->CodePrint(); |
| 142 | break; |
| 143 | case PROXY_TYPE: |
| 144 | Proxy::cast(this)->ProxyPrint(); |
| 145 | break; |
| 146 | case SHARED_FUNCTION_INFO_TYPE: |
| 147 | SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(); |
| 148 | break; |
| 149 | |
| 150 | #define MAKE_STRUCT_CASE(NAME, Name, name) \ |
| 151 | case NAME##_TYPE: \ |
| 152 | Name::cast(this)->Name##Print(); \ |
| 153 | break; |
| 154 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 155 | #undef MAKE_STRUCT_CASE |
| 156 | |
| 157 | default: |
| 158 | PrintF("UNKNOWN TYPE %d", map()->instance_type()); |
| 159 | UNREACHABLE(); |
| 160 | break; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | |
| 165 | void HeapObject::HeapObjectVerify() { |
| 166 | InstanceType instance_type = map()->instance_type(); |
| 167 | |
| 168 | if (instance_type < FIRST_NONSTRING_TYPE) { |
| 169 | String::cast(this)->StringVerify(); |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | switch (instance_type) { |
| 174 | case MAP_TYPE: |
| 175 | Map::cast(this)->MapVerify(); |
| 176 | break; |
| 177 | case HEAP_NUMBER_TYPE: |
| 178 | HeapNumber::cast(this)->HeapNumberVerify(); |
| 179 | break; |
| 180 | case FIXED_ARRAY_TYPE: |
| 181 | FixedArray::cast(this)->FixedArrayVerify(); |
| 182 | break; |
| 183 | case BYTE_ARRAY_TYPE: |
| 184 | ByteArray::cast(this)->ByteArrayVerify(); |
| 185 | break; |
| 186 | case CODE_TYPE: |
| 187 | Code::cast(this)->CodeVerify(); |
| 188 | break; |
| 189 | case ODDBALL_TYPE: |
| 190 | Oddball::cast(this)->OddballVerify(); |
| 191 | break; |
| 192 | case JS_OBJECT_TYPE: |
| 193 | JSObject::cast(this)->JSObjectVerify(); |
| 194 | break; |
| 195 | case JS_VALUE_TYPE: |
| 196 | JSValue::cast(this)->JSValueVerify(); |
| 197 | break; |
| 198 | case JS_FUNCTION_TYPE: |
| 199 | JSFunction::cast(this)->JSFunctionVerify(); |
| 200 | break; |
| 201 | case JS_GLOBAL_OBJECT_TYPE: |
| 202 | JSGlobalObject::cast(this)->JSGlobalObjectVerify(); |
| 203 | break; |
| 204 | case JS_BUILTINS_OBJECT_TYPE: |
| 205 | JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify(); |
| 206 | break; |
| 207 | case JS_ARRAY_TYPE: |
| 208 | JSArray::cast(this)->JSArrayVerify(); |
| 209 | break; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 210 | case JS_REGEXP_TYPE: |
| 211 | JSRegExp::cast(this)->JSRegExpVerify(); |
| 212 | break; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 213 | case FILLER_TYPE: |
| 214 | break; |
| 215 | case PROXY_TYPE: |
| 216 | Proxy::cast(this)->ProxyVerify(); |
| 217 | break; |
| 218 | case SHARED_FUNCTION_INFO_TYPE: |
| 219 | SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify(); |
| 220 | break; |
| 221 | |
| 222 | #define MAKE_STRUCT_CASE(NAME, Name, name) \ |
| 223 | case NAME##_TYPE: \ |
| 224 | Name::cast(this)->Name##Verify(); \ |
| 225 | break; |
| 226 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 227 | #undef MAKE_STRUCT_CASE |
| 228 | |
| 229 | default: |
| 230 | UNREACHABLE(); |
| 231 | break; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | |
| 236 | void HeapObject::VerifyHeapPointer(Object* p) { |
| 237 | ASSERT(p->IsHeapObject()); |
| 238 | ASSERT(Heap::Contains(HeapObject::cast(p))); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | void HeapNumber::HeapNumberVerify() { |
| 243 | ASSERT(IsHeapNumber()); |
| 244 | } |
| 245 | |
| 246 | |
| 247 | void ByteArray::ByteArrayPrint() { |
| 248 | PrintF("byte array, data starts at %p", GetDataStartAddress()); |
| 249 | } |
| 250 | |
| 251 | |
| 252 | void ByteArray::ByteArrayVerify() { |
| 253 | ASSERT(IsByteArray()); |
| 254 | } |
| 255 | |
| 256 | |
| 257 | void JSObject::PrintProperties() { |
| 258 | if (HasFastProperties()) { |
| 259 | for (DescriptorReader r(map()->instance_descriptors()); |
| 260 | !r.eos(); |
| 261 | r.advance()) { |
| 262 | PrintF(" "); |
| 263 | r.GetKey()->StringPrint(); |
| 264 | PrintF(": "); |
| 265 | if (r.type() == FIELD) { |
| 266 | properties()->get(r.GetFieldIndex())->ShortPrint(); |
| 267 | PrintF(" (field at offset %d)\n", r.GetFieldIndex()); |
| 268 | } else if (r.type() == CONSTANT_FUNCTION) { |
| 269 | r.GetConstantFunction()->ShortPrint(); |
| 270 | PrintF(" (constant function)\n"); |
| 271 | } else if (r.type() == CALLBACKS) { |
| 272 | r.GetCallbacksObject()->ShortPrint(); |
| 273 | PrintF(" (callback)\n"); |
| 274 | } else if (r.type() == MAP_TRANSITION) { |
| 275 | PrintF(" (map transition)\n"); |
| 276 | } else { |
| 277 | UNREACHABLE(); |
| 278 | } |
| 279 | } |
| 280 | } else { |
| 281 | property_dictionary()->Print(); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | |
| 286 | void JSObject::PrintElements() { |
| 287 | if (HasFastElements()) { |
| 288 | FixedArray* p = FixedArray::cast(elements()); |
| 289 | for (int i = 0; i < p->length(); i++) { |
| 290 | PrintF(" %d: ", i); |
| 291 | p->get(i)->ShortPrint(); |
| 292 | PrintF("\n"); |
| 293 | } |
| 294 | } else { |
| 295 | elements()->Print(); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | |
| 300 | void JSObject::JSObjectPrint() { |
| 301 | PrintF("%p: [JSObject]\n", this); |
| 302 | PrintF(" - map = %p\n", map()); |
| 303 | PrintF(" - prototype = %p\n", GetPrototype()); |
| 304 | PrintF(" {\n"); |
| 305 | PrintProperties(); |
| 306 | PrintElements(); |
| 307 | PrintF(" }\n"); |
| 308 | } |
| 309 | |
| 310 | |
| 311 | void JSObject::JSObjectVerify() { |
| 312 | VerifyHeapPointer(properties()); |
| 313 | VerifyHeapPointer(elements()); |
| 314 | if (HasFastProperties()) { |
| 315 | CHECK(map()->unused_property_fields() == |
| 316 | (properties()->length() - map()->NextFreePropertyIndex())); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | |
| 321 | static const char* TypeToString(InstanceType type) { |
| 322 | switch (type) { |
| 323 | case MAP_TYPE: return "MAP"; |
| 324 | case HEAP_NUMBER_TYPE: return "HEAP_NUMBER"; |
| 325 | case SHORT_SYMBOL_TYPE: |
| 326 | case MEDIUM_SYMBOL_TYPE: |
| 327 | case LONG_SYMBOL_TYPE: return "SYMBOL"; |
| 328 | case SHORT_ASCII_SYMBOL_TYPE: |
| 329 | case MEDIUM_ASCII_SYMBOL_TYPE: |
| 330 | case LONG_ASCII_SYMBOL_TYPE: return "ASCII_SYMBOL"; |
| 331 | case SHORT_SLICED_SYMBOL_TYPE: |
| 332 | case MEDIUM_SLICED_SYMBOL_TYPE: |
| 333 | case LONG_SLICED_SYMBOL_TYPE: return "SLICED_SYMBOL"; |
| 334 | case SHORT_SLICED_ASCII_SYMBOL_TYPE: |
| 335 | case MEDIUM_SLICED_ASCII_SYMBOL_TYPE: |
| 336 | case LONG_SLICED_ASCII_SYMBOL_TYPE: return "SLICED_ASCII_SYMBOL"; |
| 337 | case SHORT_CONS_SYMBOL_TYPE: |
| 338 | case MEDIUM_CONS_SYMBOL_TYPE: |
| 339 | case LONG_CONS_SYMBOL_TYPE: return "CONS_SYMBOL"; |
| 340 | case SHORT_CONS_ASCII_SYMBOL_TYPE: |
| 341 | case MEDIUM_CONS_ASCII_SYMBOL_TYPE: |
| 342 | case LONG_CONS_ASCII_SYMBOL_TYPE: return "CONS_ASCII_SYMBOL"; |
| 343 | case SHORT_EXTERNAL_ASCII_SYMBOL_TYPE: |
| 344 | case MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE: |
| 345 | case LONG_EXTERNAL_ASCII_SYMBOL_TYPE: |
| 346 | case SHORT_EXTERNAL_SYMBOL_TYPE: |
| 347 | case MEDIUM_EXTERNAL_SYMBOL_TYPE: |
| 348 | case LONG_EXTERNAL_SYMBOL_TYPE: return "EXTERNAL_SYMBOL"; |
| 349 | case SHORT_ASCII_STRING_TYPE: |
| 350 | case MEDIUM_ASCII_STRING_TYPE: |
| 351 | case LONG_ASCII_STRING_TYPE: return "ASCII_STRING"; |
| 352 | case SHORT_STRING_TYPE: |
| 353 | case MEDIUM_STRING_TYPE: |
| 354 | case LONG_STRING_TYPE: return "TWO_BYTE_STRING"; |
| 355 | case SHORT_CONS_STRING_TYPE: |
| 356 | case MEDIUM_CONS_STRING_TYPE: |
| 357 | case LONG_CONS_STRING_TYPE: |
| 358 | case SHORT_CONS_ASCII_STRING_TYPE: |
| 359 | case MEDIUM_CONS_ASCII_STRING_TYPE: |
| 360 | case LONG_CONS_ASCII_STRING_TYPE: return "CONS_STRING"; |
| 361 | case SHORT_SLICED_STRING_TYPE: |
| 362 | case MEDIUM_SLICED_STRING_TYPE: |
| 363 | case LONG_SLICED_STRING_TYPE: |
| 364 | case SHORT_SLICED_ASCII_STRING_TYPE: |
| 365 | case MEDIUM_SLICED_ASCII_STRING_TYPE: |
| 366 | case LONG_SLICED_ASCII_STRING_TYPE: return "SLICED_STRING"; |
| 367 | case SHORT_EXTERNAL_ASCII_STRING_TYPE: |
| 368 | case MEDIUM_EXTERNAL_ASCII_STRING_TYPE: |
| 369 | case LONG_EXTERNAL_ASCII_STRING_TYPE: |
| 370 | case SHORT_EXTERNAL_STRING_TYPE: |
| 371 | case MEDIUM_EXTERNAL_STRING_TYPE: |
| 372 | case LONG_EXTERNAL_STRING_TYPE: return "EXTERNAL_STRING"; |
| 373 | case FIXED_ARRAY_TYPE: return "FIXED_ARRAY"; |
| 374 | case BYTE_ARRAY_TYPE: return "BYTE_ARRAY"; |
| 375 | case FILLER_TYPE: return "FILLER"; |
| 376 | case JS_OBJECT_TYPE: return "JS_OBJECT"; |
| 377 | case ODDBALL_TYPE: return "ODDBALL"; |
| 378 | case SHARED_FUNCTION_INFO_TYPE: return "SHARED_FUNCTION_INFO"; |
| 379 | case JS_FUNCTION_TYPE: return "JS_FUNCTION"; |
| 380 | case CODE_TYPE: return "CODE"; |
| 381 | case JS_ARRAY_TYPE: return "JS_ARRAY"; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 382 | case JS_REGEXP_TYPE: return "JS_REGEXP"; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 383 | case JS_VALUE_TYPE: return "JS_VALUE"; |
| 384 | case JS_GLOBAL_OBJECT_TYPE: return "JS_GLOBAL_OBJECT"; |
| 385 | case JS_BUILTINS_OBJECT_TYPE: return "JS_BUILTINS_OBJECT"; |
| 386 | case PROXY_TYPE: return "PROXY"; |
| 387 | case SMI_TYPE: return "SMI"; |
| 388 | #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return #NAME; |
| 389 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 390 | #undef MAKE_STRUCT_CASE |
| 391 | } |
| 392 | return "UNKNOWN"; |
| 393 | } |
| 394 | |
| 395 | |
| 396 | void Map::MapPrint() { |
| 397 | HeapObject::PrintHeader("Map"); |
| 398 | PrintF(" - type: %s\n", TypeToString(instance_type())); |
| 399 | PrintF(" - instance size: %d\n", instance_size()); |
| 400 | PrintF(" - unused property fields: %d\n", unused_property_fields()); |
| 401 | PrintF(" - instance descriptors: "); |
| 402 | instance_descriptors()->ShortPrint(); |
| 403 | PrintF("\n - prototype: "); |
| 404 | prototype()->ShortPrint(); |
| 405 | PrintF("\n - constructor: "); |
| 406 | constructor()->ShortPrint(); |
| 407 | PrintF("\n"); |
| 408 | } |
| 409 | |
| 410 | |
| 411 | void Map::MapVerify() { |
| 412 | ASSERT(!Heap::InNewSpace(this)); |
| 413 | ASSERT(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE); |
| 414 | ASSERT(kPointerSize <= instance_size() |
| 415 | && instance_size() < Heap::Capacity()); |
| 416 | VerifyHeapPointer(prototype()); |
| 417 | VerifyHeapPointer(instance_descriptors()); |
| 418 | } |
| 419 | |
| 420 | |
| 421 | void FixedArray::FixedArrayPrint() { |
| 422 | HeapObject::PrintHeader("FixedArray"); |
| 423 | PrintF(" - length: %d", length()); |
| 424 | for (int i = 0; i < length(); i++) { |
| 425 | PrintF("\n [%d]: ", i); |
| 426 | get(i)->ShortPrint(); |
| 427 | } |
| 428 | PrintF("\n"); |
| 429 | } |
| 430 | |
| 431 | |
| 432 | void FixedArray::FixedArrayVerify() { |
| 433 | for (int i = 0; i < length(); i++) { |
| 434 | Object* e = get(i); |
| 435 | if (e->IsHeapObject()) { |
| 436 | VerifyHeapPointer(e); |
| 437 | } else { |
| 438 | e->Verify(); |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | |
| 444 | void JSValue::JSValuePrint() { |
| 445 | HeapObject::PrintHeader("ValueObject"); |
| 446 | value()->Print(); |
| 447 | } |
| 448 | |
| 449 | |
| 450 | void JSValue::JSValueVerify() { |
| 451 | Object* v = value(); |
| 452 | if (v->IsHeapObject()) { |
| 453 | VerifyHeapPointer(v); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | |
| 458 | void String::StringPrint() { |
| 459 | if (IsSymbol()) { |
| 460 | PrintF("#"); |
| 461 | } else if (IsConsString()) { |
| 462 | PrintF("c\""); |
| 463 | } else { |
| 464 | PrintF("\""); |
| 465 | } |
| 466 | |
| 467 | for (int i = 0; i < length(); i++) { |
| 468 | PrintF("%c", Get(i)); |
| 469 | } |
| 470 | |
| 471 | if (!IsSymbol()) PrintF("\""); |
| 472 | } |
| 473 | |
| 474 | |
| 475 | void String::StringVerify() { |
| 476 | CHECK(IsString()); |
| 477 | CHECK(length() >= 0 && length() <= Smi::kMaxValue); |
| 478 | if (IsSymbol()) { |
| 479 | CHECK(!Heap::InNewSpace(this)); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | |
| 484 | void JSFunction::JSFunctionPrint() { |
| 485 | HeapObject::PrintHeader("Function"); |
| 486 | PrintF(" - map = 0x%p\n", map()); |
| 487 | PrintF(" - is boilerplate: %s\n", IsBoilerplate() ? "yes" : "no"); |
| 488 | PrintF(" - initial_map = "); |
| 489 | if (has_initial_map()) { |
| 490 | initial_map()->ShortPrint(); |
| 491 | } |
| 492 | PrintF("\n - shared_info = "); |
| 493 | shared()->ShortPrint(); |
| 494 | PrintF("\n - name = "); |
| 495 | shared()->name()->Print(); |
| 496 | PrintF("\n - context = "); |
| 497 | unchecked_context()->ShortPrint(); |
| 498 | PrintF("\n - code = "); |
| 499 | code()->ShortPrint(); |
| 500 | PrintF("\n"); |
| 501 | |
| 502 | PrintProperties(); |
| 503 | PrintElements(); |
| 504 | |
| 505 | PrintF("\n"); |
| 506 | } |
| 507 | |
| 508 | |
| 509 | void JSFunction::JSFunctionVerify() { |
| 510 | CHECK(IsJSFunction()); |
| 511 | VerifyObjectField(kPrototypeOrInitialMapOffset); |
| 512 | } |
| 513 | |
| 514 | |
| 515 | void SharedFunctionInfo::SharedFunctionInfoPrint() { |
| 516 | HeapObject::PrintHeader("SharedFunctionInfo"); |
| 517 | PrintF(" - name: "); |
| 518 | name()->ShortPrint(); |
| 519 | PrintF("\n - expected_nof_properties: %d", expected_nof_properties()); |
| 520 | PrintF("\n - instance class name ="); |
| 521 | instance_class_name()->Print(); |
| 522 | PrintF("\n - code ="); |
| 523 | code()->ShortPrint(); |
| 524 | PrintF("\n - source code ="); |
| 525 | GetSourceCode()->ShortPrint(); |
| 526 | PrintF("\n - lazy load: %s", |
| 527 | lazy_load_data() == Heap::undefined_value() ? "no" : "yes"); |
| 528 | // Script files are often large, hard to read. |
| 529 | // PrintF("\n - script ="); |
| 530 | // script()->Print(); |
| 531 | PrintF("\n - function token position = %d", function_token_position()); |
| 532 | PrintF("\n - start position = %d", start_position()); |
| 533 | PrintF("\n - end position = %d", end_position()); |
| 534 | PrintF("\n - is expression = %d", is_expression()); |
| 535 | PrintF("\n - debug info = "); |
| 536 | debug_info()->Print(); |
| 537 | PrintF("\n - length = %d", length()); |
| 538 | PrintF("\n"); |
| 539 | } |
| 540 | |
| 541 | void SharedFunctionInfo::SharedFunctionInfoVerify() { |
| 542 | CHECK(IsSharedFunctionInfo()); |
| 543 | VerifyObjectField(kNameOffset); |
| 544 | VerifyObjectField(kCodeOffset); |
| 545 | VerifyObjectField(kInstanceClassNameOffset); |
| 546 | VerifyObjectField(kExternalReferenceDataOffset); |
| 547 | VerifyObjectField(kLazyLoadDataOffset); |
| 548 | VerifyObjectField(kScriptOffset); |
| 549 | VerifyObjectField(kDebugInfoOffset); |
| 550 | } |
| 551 | |
| 552 | |
| 553 | void JSGlobalObject::JSGlobalObjectPrint() { |
| 554 | PrintF("global "); |
| 555 | JSObjectPrint(); |
| 556 | } |
| 557 | |
| 558 | |
| 559 | void JSGlobalObject::JSGlobalObjectVerify() { |
| 560 | CHECK(IsJSGlobalObject()); |
| 561 | JSObjectVerify(); |
| 562 | for (int i = GlobalObject::kBuiltinsOffset; |
| 563 | i < JSGlobalObject::kSize; |
| 564 | i += kPointerSize) { |
| 565 | VerifyObjectField(i); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | |
| 570 | void JSBuiltinsObject::JSBuiltinsObjectPrint() { |
| 571 | PrintF("builtins "); |
| 572 | JSObjectPrint(); |
| 573 | } |
| 574 | |
| 575 | |
| 576 | void JSBuiltinsObject::JSBuiltinsObjectVerify() { |
| 577 | CHECK(IsJSBuiltinsObject()); |
| 578 | JSObjectVerify(); |
| 579 | for (int i = GlobalObject::kBuiltinsOffset; |
| 580 | i < JSBuiltinsObject::kSize; |
| 581 | i += kPointerSize) { |
| 582 | VerifyObjectField(i); |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | |
| 587 | void Oddball::OddballVerify() { |
| 588 | CHECK(IsOddball()); |
| 589 | VerifyHeapPointer(to_string()); |
| 590 | Object* number = to_number(); |
| 591 | if (number->IsHeapObject()) { |
| 592 | ASSERT(number == Heap::nan_value()); |
| 593 | } else { |
| 594 | ASSERT(number->IsSmi()); |
| 595 | int value = Smi::cast(number)->value(); |
| 596 | ASSERT(value == 0 || value == 1 || value == -1); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 601 | void Code::CodePrint() { |
| 602 | HeapObject::PrintHeader("Code"); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 603 | #ifdef ENABLE_DISASSEMBLER |
| 604 | Disassemble(); |
| 605 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | |
| 609 | void Code::CodeVerify() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 610 | CHECK(ic_flag() == IC_TARGET_IS_ADDRESS); |
| 611 | Address last_gc_pc = NULL; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 612 | for (RelocIterator it(this); !it.done(); it.next()) { |
| 613 | it.rinfo()->Verify(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 614 | // Ensure that GC will not iterate twice over the same pointer. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 615 | if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 616 | CHECK(it.rinfo()->pc() != last_gc_pc); |
| 617 | last_gc_pc = it.rinfo()->pc(); |
| 618 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 619 | } |
| 620 | } |
| 621 | |
| 622 | |
| 623 | void JSArray::JSArrayVerify() { |
| 624 | JSObjectVerify(); |
| 625 | ASSERT(length()->IsNumber() || length()->IsUndefined()); |
| 626 | ASSERT(elements()->IsUndefined() || elements()->IsFixedArray()); |
| 627 | } |
| 628 | |
| 629 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame^] | 630 | void JSRegExp::JSRegExpVerify() { |
| 631 | JSObjectVerify(); |
| 632 | ASSERT(type()->IsSmi() || type()->IsUndefined()); |
| 633 | ASSERT(data()->IsUndefined() || data()->IsFixedArray()); |
| 634 | } |
| 635 | |
| 636 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 637 | void Proxy::ProxyPrint() { |
| 638 | PrintF("proxy to %p", proxy()); |
| 639 | } |
| 640 | |
| 641 | |
| 642 | void Proxy::ProxyVerify() { |
| 643 | ASSERT(IsProxy()); |
| 644 | } |
| 645 | |
| 646 | |
| 647 | void Dictionary::Print() { |
| 648 | int capacity = Capacity(); |
| 649 | for (int i = 0; i < capacity; i++) { |
| 650 | Object* k = KeyAt(i); |
| 651 | if (IsKey(k)) { |
| 652 | PrintF(" "); |
| 653 | if (k->IsString()) { |
| 654 | String::cast(k)->StringPrint(); |
| 655 | } else { |
| 656 | k->ShortPrint(); |
| 657 | } |
| 658 | PrintF(": "); |
| 659 | ValueAt(i)->ShortPrint(); |
| 660 | PrintF("\n"); |
| 661 | } |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | |
| 666 | void AccessorInfo::AccessorInfoVerify() { |
| 667 | CHECK(IsAccessorInfo()); |
| 668 | VerifyPointer(getter()); |
| 669 | VerifyPointer(setter()); |
| 670 | VerifyPointer(name()); |
| 671 | VerifyPointer(data()); |
| 672 | VerifyPointer(flag()); |
| 673 | } |
| 674 | |
| 675 | void AccessorInfo::AccessorInfoPrint() { |
| 676 | PrintF("AccessorInfo"); |
| 677 | PrintF("\n - getter: "); |
| 678 | getter()->ShortPrint(); |
| 679 | PrintF("\n - setter: "); |
| 680 | setter()->ShortPrint(); |
| 681 | PrintF("\n - name: "); |
| 682 | name()->ShortPrint(); |
| 683 | PrintF("\n - data: "); |
| 684 | data()->ShortPrint(); |
| 685 | PrintF("\n - flag: "); |
| 686 | flag()->ShortPrint(); |
| 687 | } |
| 688 | |
| 689 | void AccessCheckInfo::AccessCheckInfoVerify() { |
| 690 | CHECK(IsAccessCheckInfo()); |
| 691 | VerifyPointer(named_callback()); |
| 692 | VerifyPointer(indexed_callback()); |
| 693 | VerifyPointer(data()); |
| 694 | } |
| 695 | |
| 696 | void AccessCheckInfo::AccessCheckInfoPrint() { |
| 697 | PrintF("AccessCheckInfo"); |
| 698 | PrintF("\n - named_callback: "); |
| 699 | named_callback()->ShortPrint(); |
| 700 | PrintF("\n - indexed_callback: "); |
| 701 | indexed_callback()->ShortPrint(); |
| 702 | PrintF("\n - data: "); |
| 703 | data()->ShortPrint(); |
| 704 | } |
| 705 | |
| 706 | void InterceptorInfo::InterceptorInfoVerify() { |
| 707 | CHECK(IsInterceptorInfo()); |
| 708 | VerifyPointer(getter()); |
| 709 | VerifyPointer(setter()); |
| 710 | VerifyPointer(query()); |
| 711 | VerifyPointer(deleter()); |
| 712 | VerifyPointer(enumerator()); |
| 713 | VerifyPointer(data()); |
| 714 | } |
| 715 | |
| 716 | void InterceptorInfo::InterceptorInfoPrint() { |
| 717 | PrintF("InterceptorInfo"); |
| 718 | PrintF("\n - getter: "); |
| 719 | getter()->ShortPrint(); |
| 720 | PrintF("\n - setter: "); |
| 721 | setter()->ShortPrint(); |
| 722 | PrintF("\n - query: "); |
| 723 | query()->ShortPrint(); |
| 724 | PrintF("\n - deleter: "); |
| 725 | deleter()->ShortPrint(); |
| 726 | PrintF("\n - enumerator: "); |
| 727 | enumerator()->ShortPrint(); |
| 728 | PrintF("\n - data: "); |
| 729 | data()->ShortPrint(); |
| 730 | } |
| 731 | |
| 732 | void CallHandlerInfo::CallHandlerInfoVerify() { |
| 733 | CHECK(IsCallHandlerInfo()); |
| 734 | VerifyPointer(callback()); |
| 735 | VerifyPointer(data()); |
| 736 | } |
| 737 | |
| 738 | void CallHandlerInfo::CallHandlerInfoPrint() { |
| 739 | PrintF("CallHandlerInfo"); |
| 740 | PrintF("\n - callback: "); |
| 741 | callback()->ShortPrint(); |
| 742 | PrintF("\n - data: "); |
| 743 | data()->ShortPrint(); |
| 744 | } |
| 745 | |
| 746 | void TemplateInfo::TemplateInfoVerify() { |
| 747 | VerifyPointer(tag()); |
| 748 | VerifyPointer(property_list()); |
| 749 | } |
| 750 | |
| 751 | void FunctionTemplateInfo::FunctionTemplateInfoVerify() { |
| 752 | CHECK(IsFunctionTemplateInfo()); |
| 753 | TemplateInfoVerify(); |
| 754 | VerifyPointer(serial_number()); |
| 755 | VerifyPointer(call_code()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 756 | VerifyPointer(property_accessors()); |
| 757 | VerifyPointer(prototype_template()); |
| 758 | VerifyPointer(parent_template()); |
| 759 | VerifyPointer(named_property_handler()); |
| 760 | VerifyPointer(indexed_property_handler()); |
| 761 | VerifyPointer(instance_template()); |
| 762 | VerifyPointer(signature()); |
| 763 | VerifyPointer(access_check_info()); |
| 764 | } |
| 765 | |
| 766 | void FunctionTemplateInfo::FunctionTemplateInfoPrint() { |
| 767 | PrintF("FunctionTemplateInfo"); |
| 768 | PrintF("\n - tag: "); |
| 769 | tag()->ShortPrint(); |
| 770 | PrintF("\n - property_list: "); |
| 771 | property_list()->ShortPrint(); |
| 772 | PrintF("\n - serial_number: "); |
| 773 | serial_number()->ShortPrint(); |
| 774 | PrintF("\n - call_code: "); |
| 775 | call_code()->ShortPrint(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 776 | PrintF("\n - property_accessors: "); |
| 777 | property_accessors()->ShortPrint(); |
| 778 | PrintF("\n - prototype_template: "); |
| 779 | prototype_template()->ShortPrint(); |
| 780 | PrintF("\n - parent_template: "); |
| 781 | parent_template()->ShortPrint(); |
| 782 | PrintF("\n - named_property_handler: "); |
| 783 | named_property_handler()->ShortPrint(); |
| 784 | PrintF("\n - indexed_property_handler: "); |
| 785 | indexed_property_handler()->ShortPrint(); |
| 786 | PrintF("\n - instance_template: "); |
| 787 | instance_template()->ShortPrint(); |
| 788 | PrintF("\n - signature: "); |
| 789 | signature()->ShortPrint(); |
| 790 | PrintF("\n - access_check_info: "); |
| 791 | access_check_info()->ShortPrint(); |
| 792 | PrintF("\n - hidden_prototype: %s", hidden_prototype() ? "true" : "false"); |
| 793 | PrintF("\n - undetectable: %s", undetectable() ? "true" : "false"); |
| 794 | PrintF("\n - need_access_check: %s", needs_access_check() ? "true" : "false"); |
| 795 | } |
| 796 | |
| 797 | void ObjectTemplateInfo::ObjectTemplateInfoVerify() { |
| 798 | CHECK(IsObjectTemplateInfo()); |
| 799 | TemplateInfoVerify(); |
| 800 | VerifyPointer(constructor()); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 801 | VerifyPointer(internal_field_count()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void ObjectTemplateInfo::ObjectTemplateInfoPrint() { |
| 805 | PrintF("ObjectTemplateInfo"); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 806 | PrintF("\n - constructor: "); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 807 | constructor()->ShortPrint(); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 808 | PrintF("\n - internal_field_count: "); |
| 809 | internal_field_count()->ShortPrint(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | void SignatureInfo::SignatureInfoVerify() { |
| 813 | CHECK(IsSignatureInfo()); |
| 814 | VerifyPointer(receiver()); |
| 815 | VerifyPointer(args()); |
| 816 | } |
| 817 | |
| 818 | void SignatureInfo::SignatureInfoPrint() { |
| 819 | PrintF("SignatureInfo"); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 820 | PrintF("\n - receiver: "); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 821 | receiver()->ShortPrint(); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 822 | PrintF("\n - args: "); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 823 | args()->ShortPrint(); |
| 824 | } |
| 825 | |
| 826 | void TypeSwitchInfo::TypeSwitchInfoVerify() { |
| 827 | CHECK(IsTypeSwitchInfo()); |
| 828 | VerifyPointer(types()); |
| 829 | } |
| 830 | |
| 831 | void TypeSwitchInfo::TypeSwitchInfoPrint() { |
| 832 | PrintF("TypeSwitchInfo"); |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 833 | PrintF("\n - types: "); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 834 | types()->ShortPrint(); |
| 835 | } |
| 836 | |
| 837 | |
| 838 | void Script::ScriptVerify() { |
| 839 | CHECK(IsScript()); |
| 840 | VerifyPointer(source()); |
| 841 | VerifyPointer(name()); |
| 842 | line_offset()->SmiVerify(); |
| 843 | column_offset()->SmiVerify(); |
| 844 | type()->SmiVerify(); |
| 845 | } |
| 846 | |
| 847 | |
| 848 | void Script::ScriptPrint() { |
| 849 | HeapObject::PrintHeader("Script"); |
| 850 | PrintF("\n - source: "); |
| 851 | source()->ShortPrint(); |
| 852 | PrintF("\n - name: "); |
| 853 | name()->ShortPrint(); |
| 854 | PrintF("\n - line_offset: "); |
| 855 | line_offset()->ShortPrint(); |
| 856 | PrintF("\n - column_offset: "); |
| 857 | column_offset()->ShortPrint(); |
| 858 | PrintF("\n - type: "); |
| 859 | type()->ShortPrint(); |
| 860 | PrintF("\n"); |
| 861 | } |
| 862 | |
| 863 | |
| 864 | void DebugInfo::DebugInfoVerify() { |
| 865 | CHECK(IsDebugInfo()); |
| 866 | VerifyPointer(shared()); |
| 867 | VerifyPointer(original_code()); |
| 868 | VerifyPointer(code()); |
| 869 | VerifyPointer(break_points()); |
| 870 | } |
| 871 | |
| 872 | |
| 873 | void DebugInfo::DebugInfoPrint() { |
| 874 | PrintF("DebugInfo"); |
| 875 | PrintF("\n - shared"); |
| 876 | shared()->ShortPrint(); |
| 877 | PrintF("\n - original_code"); |
| 878 | original_code()->ShortPrint(); |
| 879 | PrintF("\n - code"); |
| 880 | code()->ShortPrint(); |
| 881 | PrintF("\n - break_points"); |
| 882 | break_points()->ShortPrint(); |
| 883 | } |
| 884 | |
| 885 | |
| 886 | void BreakPointInfo::BreakPointInfoVerify() { |
| 887 | CHECK(IsBreakPointInfo()); |
| 888 | code_position()->SmiVerify(); |
| 889 | source_position()->SmiVerify(); |
| 890 | statement_position()->SmiVerify(); |
| 891 | VerifyPointer(break_point_objects()); |
| 892 | } |
| 893 | |
| 894 | |
| 895 | void BreakPointInfo::BreakPointInfoPrint() { |
| 896 | PrintF("BreakPointInfo"); |
| 897 | PrintF("\n - code_position %d", code_position()); |
| 898 | PrintF("\n - source_position %d", source_position()); |
| 899 | PrintF("\n - statement_position %d", statement_position()); |
| 900 | PrintF("\n - break_point_objects "); |
| 901 | break_point_objects()->ShortPrint(); |
| 902 | } |
| 903 | |
| 904 | |
| 905 | void JSObject::IncrementSpillStatistics(SpillInformation* info) { |
| 906 | info->number_of_objects_++; |
| 907 | // Named properties |
| 908 | if (HasFastProperties()) { |
| 909 | info->number_of_objects_with_fast_properties_++; |
| 910 | info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex(); |
| 911 | info->number_of_fast_unused_fields_ += map()->unused_property_fields(); |
| 912 | } else { |
| 913 | Dictionary* dict = property_dictionary(); |
| 914 | info->number_of_slow_used_properties_ += dict->NumberOfElements(); |
| 915 | info->number_of_slow_unused_properties_ += |
| 916 | dict->Capacity() - dict->NumberOfElements(); |
| 917 | } |
| 918 | // Indexed properties |
| 919 | if (HasFastElements()) { |
| 920 | info->number_of_objects_with_fast_elements_++; |
| 921 | int holes = 0; |
| 922 | FixedArray* e = FixedArray::cast(elements()); |
| 923 | int len = e->length(); |
| 924 | for (int i = 0; i < len; i++) { |
| 925 | if (e->get(i) == Heap::the_hole_value()) holes++; |
| 926 | } |
| 927 | info->number_of_fast_used_elements_ += len - holes; |
| 928 | info->number_of_fast_unused_elements_ += holes; |
| 929 | } else { |
| 930 | Dictionary* dict = element_dictionary(); |
| 931 | info->number_of_slow_used_elements_ += dict->NumberOfElements(); |
| 932 | info->number_of_slow_unused_elements_ += |
| 933 | dict->Capacity() - dict->NumberOfElements(); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | |
| 938 | void JSObject::SpillInformation::Clear() { |
| 939 | number_of_objects_ = 0; |
| 940 | number_of_objects_with_fast_properties_ = 0; |
| 941 | number_of_objects_with_fast_elements_ = 0; |
| 942 | number_of_fast_used_fields_ = 0; |
| 943 | number_of_fast_unused_fields_ = 0; |
| 944 | number_of_slow_used_properties_ = 0; |
| 945 | number_of_slow_unused_properties_ = 0; |
| 946 | number_of_fast_used_elements_ = 0; |
| 947 | number_of_fast_unused_elements_ = 0; |
| 948 | number_of_slow_used_elements_ = 0; |
| 949 | number_of_slow_unused_elements_ = 0; |
| 950 | } |
| 951 | |
| 952 | void JSObject::SpillInformation::Print() { |
| 953 | PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_); |
| 954 | |
| 955 | PrintF(" - fast properties (#%d): %d (used) %d (unused)\n", |
| 956 | number_of_objects_with_fast_properties_, |
| 957 | number_of_fast_used_fields_, number_of_fast_unused_fields_); |
| 958 | |
| 959 | PrintF(" - slow properties (#%d): %d (used) %d (unused)\n", |
| 960 | number_of_objects_ - number_of_objects_with_fast_properties_, |
| 961 | number_of_slow_used_properties_, number_of_slow_unused_properties_); |
| 962 | |
| 963 | PrintF(" - fast elements (#%d): %d (used) %d (unused)\n", |
| 964 | number_of_objects_with_fast_elements_, |
| 965 | number_of_fast_used_elements_, number_of_fast_unused_elements_); |
| 966 | |
| 967 | PrintF(" - slow elements (#%d): %d (used) %d (unused)\n", |
| 968 | number_of_objects_ - number_of_objects_with_fast_elements_, |
| 969 | number_of_slow_used_elements_, number_of_slow_unused_elements_); |
| 970 | |
| 971 | PrintF("\n"); |
| 972 | } |
| 973 | |
| 974 | |
| 975 | void DescriptorArray::PrintDescriptors() { |
| 976 | PrintF("Descriptor array %d\n", number_of_descriptors()); |
| 977 | int number = 0; |
| 978 | for (DescriptorReader r(this); !r.eos(); r.advance()) { |
| 979 | Descriptor desc; |
| 980 | r.Get(&desc); |
| 981 | PrintF(" %d: ", number++); |
| 982 | desc.Print(); |
| 983 | } |
| 984 | PrintF("\n"); |
| 985 | } |
| 986 | |
| 987 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 988 | bool DescriptorArray::IsSortedNoDuplicates() { |
| 989 | String* current_key = NULL; |
| 990 | uint32_t current = 0; |
| 991 | for (DescriptorReader r(this); !r.eos(); r.advance()) { |
| 992 | String* key = r.GetKey(); |
| 993 | if (key == current_key) { |
| 994 | PrintDescriptors(); |
| 995 | return false; |
| 996 | } |
| 997 | current_key = key; |
| 998 | uint32_t hash = r.GetKey()->Hash(); |
| 999 | if (hash < current) { |
| 1000 | PrintDescriptors(); |
| 1001 | return false; |
| 1002 | } |
| 1003 | current = hash; |
| 1004 | } |
| 1005 | return true; |
| 1006 | } |
| 1007 | |
| 1008 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1009 | #endif // DEBUG |
| 1010 | |
| 1011 | } } // namespace v8::internal |