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