00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "v8.h"
00029
00030 #include "disassembler.h"
00031 #include "disasm.h"
00032 #include "macro-assembler.h"
00033
00034 namespace v8 { namespace internal {
00035
00036 #ifdef DEBUG
00037
00038 static const char* TypeToString(InstanceType type);
00039
00040
00041 void Object::Print() {
00042 if (IsSmi()) {
00043 Smi::cast(this)->SmiPrint();
00044 } else if (IsFailure()) {
00045 Failure::cast(this)->FailurePrint();
00046 } else {
00047 HeapObject::cast(this)->HeapObjectPrint();
00048 }
00049 Flush();
00050 }
00051
00052
00053 void Object::PrintLn() {
00054 Print();
00055 PrintF("\n");
00056 }
00057
00058
00059 void Object::Verify() {
00060 if (IsSmi()) {
00061 Smi::cast(this)->SmiVerify();
00062 } else if (IsFailure()) {
00063 Failure::cast(this)->FailureVerify();
00064 } else {
00065 HeapObject::cast(this)->HeapObjectVerify();
00066 }
00067 }
00068
00069
00070 void Object::VerifyPointer(Object* p) {
00071 if (p->IsHeapObject()) {
00072 HeapObject::VerifyHeapPointer(p);
00073 } else {
00074 ASSERT(p->IsSmi());
00075 }
00076 }
00077
00078
00079 void Smi::SmiVerify() {
00080 ASSERT(IsSmi());
00081 }
00082
00083
00084 void Failure::FailureVerify() {
00085 ASSERT(IsFailure());
00086 }
00087
00088
00089 void HeapObject::PrintHeader(const char* id) {
00090 PrintF("%p: [%s]\n", this, id);
00091 }
00092
00093
00094 void HeapObject::HeapObjectPrint() {
00095 InstanceType instance_type = map()->instance_type();
00096
00097 HandleScope scope;
00098 if (instance_type < FIRST_NONSTRING_TYPE) {
00099 String::cast(this)->StringPrint();
00100 return;
00101 }
00102
00103 switch (instance_type) {
00104 case MAP_TYPE:
00105 Map::cast(this)->MapPrint();
00106 break;
00107 case HEAP_NUMBER_TYPE:
00108 HeapNumber::cast(this)->HeapNumberPrint();
00109 break;
00110 case FIXED_ARRAY_TYPE:
00111 FixedArray::cast(this)->FixedArrayPrint();
00112 break;
00113 case BYTE_ARRAY_TYPE:
00114 ByteArray::cast(this)->ByteArrayPrint();
00115 break;
00116 case FILLER_TYPE:
00117 PrintF("filler");
00118 break;
00119 case JS_OBJECT_TYPE:
00120 case JS_ARRAY_TYPE:
00121 case JS_REGEXP_TYPE:
00122 JSObject::cast(this)->JSObjectPrint();
00123 break;
00124 case ODDBALL_TYPE:
00125 Oddball::cast(this)->to_string()->Print();
00126 break;
00127 case JS_FUNCTION_TYPE:
00128 JSFunction::cast(this)->JSFunctionPrint();
00129 break;
00130 case JS_GLOBAL_PROXY_TYPE:
00131 JSGlobalProxy::cast(this)->JSGlobalProxyPrint();
00132 break;
00133 case JS_GLOBAL_OBJECT_TYPE:
00134 JSGlobalObject::cast(this)->JSGlobalObjectPrint();
00135 break;
00136 case JS_BUILTINS_OBJECT_TYPE:
00137 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint();
00138 break;
00139 case JS_VALUE_TYPE:
00140 PrintF("Value wrapper around:");
00141 JSValue::cast(this)->value()->Print();
00142 break;
00143 case CODE_TYPE:
00144 Code::cast(this)->CodePrint();
00145 break;
00146 case PROXY_TYPE:
00147 Proxy::cast(this)->ProxyPrint();
00148 break;
00149 case SHARED_FUNCTION_INFO_TYPE:
00150 SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint();
00151 break;
00152
00153 #define MAKE_STRUCT_CASE(NAME, Name, name) \
00154 case NAME##_TYPE: \
00155 Name::cast(this)->Name##Print(); \
00156 break;
00157 STRUCT_LIST(MAKE_STRUCT_CASE)
00158 #undef MAKE_STRUCT_CASE
00159
00160 default:
00161 PrintF("UNKNOWN TYPE %d", map()->instance_type());
00162 UNREACHABLE();
00163 break;
00164 }
00165 }
00166
00167
00168 void HeapObject::HeapObjectVerify() {
00169 InstanceType instance_type = map()->instance_type();
00170
00171 if (instance_type < FIRST_NONSTRING_TYPE) {
00172 String::cast(this)->StringVerify();
00173 return;
00174 }
00175
00176 switch (instance_type) {
00177 case MAP_TYPE:
00178 Map::cast(this)->MapVerify();
00179 break;
00180 case HEAP_NUMBER_TYPE:
00181 HeapNumber::cast(this)->HeapNumberVerify();
00182 break;
00183 case FIXED_ARRAY_TYPE:
00184 FixedArray::cast(this)->FixedArrayVerify();
00185 break;
00186 case BYTE_ARRAY_TYPE:
00187 ByteArray::cast(this)->ByteArrayVerify();
00188 break;
00189 case CODE_TYPE:
00190 Code::cast(this)->CodeVerify();
00191 break;
00192 case ODDBALL_TYPE:
00193 Oddball::cast(this)->OddballVerify();
00194 break;
00195 case JS_OBJECT_TYPE:
00196 JSObject::cast(this)->JSObjectVerify();
00197 break;
00198 case JS_VALUE_TYPE:
00199 JSValue::cast(this)->JSValueVerify();
00200 break;
00201 case JS_FUNCTION_TYPE:
00202 JSFunction::cast(this)->JSFunctionVerify();
00203 break;
00204 case JS_GLOBAL_PROXY_TYPE:
00205 JSGlobalProxy::cast(this)->JSGlobalProxyVerify();
00206 break;
00207 case JS_GLOBAL_OBJECT_TYPE:
00208 JSGlobalObject::cast(this)->JSGlobalObjectVerify();
00209 break;
00210 case JS_BUILTINS_OBJECT_TYPE:
00211 JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify();
00212 break;
00213 case JS_ARRAY_TYPE:
00214 JSArray::cast(this)->JSArrayVerify();
00215 break;
00216 case JS_REGEXP_TYPE:
00217 JSRegExp::cast(this)->JSRegExpVerify();
00218 break;
00219 case FILLER_TYPE:
00220 break;
00221 case PROXY_TYPE:
00222 Proxy::cast(this)->ProxyVerify();
00223 break;
00224 case SHARED_FUNCTION_INFO_TYPE:
00225 SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify();
00226 break;
00227
00228 #define MAKE_STRUCT_CASE(NAME, Name, name) \
00229 case NAME##_TYPE: \
00230 Name::cast(this)->Name##Verify(); \
00231 break;
00232 STRUCT_LIST(MAKE_STRUCT_CASE)
00233 #undef MAKE_STRUCT_CASE
00234
00235 default:
00236 UNREACHABLE();
00237 break;
00238 }
00239 }
00240
00241
00242 void HeapObject::VerifyHeapPointer(Object* p) {
00243 ASSERT(p->IsHeapObject());
00244 ASSERT(Heap::Contains(HeapObject::cast(p)));
00245 }
00246
00247
00248 void HeapNumber::HeapNumberVerify() {
00249 ASSERT(IsHeapNumber());
00250 }
00251
00252
00253 void ByteArray::ByteArrayPrint() {
00254 PrintF("byte array, data starts at %p", GetDataStartAddress());
00255 }
00256
00257
00258 void ByteArray::ByteArrayVerify() {
00259 ASSERT(IsByteArray());
00260 }
00261
00262
00263 void JSObject::PrintProperties() {
00264 if (HasFastProperties()) {
00265 for (DescriptorReader r(map()->instance_descriptors());
00266 !r.eos();
00267 r.advance()) {
00268 PrintF(" ");
00269 r.GetKey()->StringPrint();
00270 PrintF(": ");
00271 if (r.type() == FIELD) {
00272 FastPropertyAt(r.GetFieldIndex())->ShortPrint();
00273 PrintF(" (field at offset %d)\n", r.GetFieldIndex());
00274 } else if (r.type() == CONSTANT_FUNCTION) {
00275 r.GetConstantFunction()->ShortPrint();
00276 PrintF(" (constant function)\n");
00277 } else if (r.type() == CALLBACKS) {
00278 r.GetCallbacksObject()->ShortPrint();
00279 PrintF(" (callback)\n");
00280 } else if (r.type() == MAP_TRANSITION) {
00281 PrintF(" (map transition)\n");
00282 } else {
00283 UNREACHABLE();
00284 }
00285 }
00286 } else {
00287 property_dictionary()->Print();
00288 }
00289 }
00290
00291
00292 void JSObject::PrintElements() {
00293 if (HasFastElements()) {
00294 FixedArray* p = FixedArray::cast(elements());
00295 for (int i = 0; i < p->length(); i++) {
00296 PrintF(" %d: ", i);
00297 p->get(i)->ShortPrint();
00298 PrintF("\n");
00299 }
00300 } else {
00301 elements()->Print();
00302 }
00303 }
00304
00305
00306 void JSObject::JSObjectPrint() {
00307 PrintF("%p: [JSObject]\n", this);
00308 PrintF(" - map = %p\n", map());
00309 PrintF(" - prototype = %p\n", GetPrototype());
00310 PrintF(" {\n");
00311 PrintProperties();
00312 PrintElements();
00313 PrintF(" }\n");
00314 }
00315
00316
00317 void JSObject::JSObjectVerify() {
00318 VerifyHeapPointer(properties());
00319 VerifyHeapPointer(elements());
00320 if (HasFastProperties()) {
00321 CHECK(map()->unused_property_fields() ==
00322 (map()->inobject_properties() + properties()->length() -
00323 map()->NextFreePropertyIndex()));
00324 }
00325 }
00326
00327
00328 static const char* TypeToString(InstanceType type) {
00329 switch (type) {
00330 case INVALID_TYPE: return "INVALID";
00331 case MAP_TYPE: return "MAP";
00332 case HEAP_NUMBER_TYPE: return "HEAP_NUMBER";
00333 case SHORT_SYMBOL_TYPE:
00334 case MEDIUM_SYMBOL_TYPE:
00335 case LONG_SYMBOL_TYPE: return "SYMBOL";
00336 case SHORT_ASCII_SYMBOL_TYPE:
00337 case MEDIUM_ASCII_SYMBOL_TYPE:
00338 case LONG_ASCII_SYMBOL_TYPE: return "ASCII_SYMBOL";
00339 case SHORT_SLICED_SYMBOL_TYPE:
00340 case MEDIUM_SLICED_SYMBOL_TYPE:
00341 case LONG_SLICED_SYMBOL_TYPE: return "SLICED_SYMBOL";
00342 case SHORT_SLICED_ASCII_SYMBOL_TYPE:
00343 case MEDIUM_SLICED_ASCII_SYMBOL_TYPE:
00344 case LONG_SLICED_ASCII_SYMBOL_TYPE: return "SLICED_ASCII_SYMBOL";
00345 case SHORT_CONS_SYMBOL_TYPE:
00346 case MEDIUM_CONS_SYMBOL_TYPE:
00347 case LONG_CONS_SYMBOL_TYPE: return "CONS_SYMBOL";
00348 case SHORT_CONS_ASCII_SYMBOL_TYPE:
00349 case MEDIUM_CONS_ASCII_SYMBOL_TYPE:
00350 case LONG_CONS_ASCII_SYMBOL_TYPE: return "CONS_ASCII_SYMBOL";
00351 case SHORT_EXTERNAL_ASCII_SYMBOL_TYPE:
00352 case MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE:
00353 case LONG_EXTERNAL_ASCII_SYMBOL_TYPE:
00354 case SHORT_EXTERNAL_SYMBOL_TYPE:
00355 case MEDIUM_EXTERNAL_SYMBOL_TYPE:
00356 case LONG_EXTERNAL_SYMBOL_TYPE: return "EXTERNAL_SYMBOL";
00357 case SHORT_ASCII_STRING_TYPE:
00358 case MEDIUM_ASCII_STRING_TYPE:
00359 case LONG_ASCII_STRING_TYPE: return "ASCII_STRING";
00360 case SHORT_STRING_TYPE:
00361 case MEDIUM_STRING_TYPE:
00362 case LONG_STRING_TYPE: return "TWO_BYTE_STRING";
00363 case SHORT_CONS_STRING_TYPE:
00364 case MEDIUM_CONS_STRING_TYPE:
00365 case LONG_CONS_STRING_TYPE:
00366 case SHORT_CONS_ASCII_STRING_TYPE:
00367 case MEDIUM_CONS_ASCII_STRING_TYPE:
00368 case LONG_CONS_ASCII_STRING_TYPE: return "CONS_STRING";
00369 case SHORT_SLICED_STRING_TYPE:
00370 case MEDIUM_SLICED_STRING_TYPE:
00371 case LONG_SLICED_STRING_TYPE:
00372 case SHORT_SLICED_ASCII_STRING_TYPE:
00373 case MEDIUM_SLICED_ASCII_STRING_TYPE:
00374 case LONG_SLICED_ASCII_STRING_TYPE: return "SLICED_STRING";
00375 case SHORT_EXTERNAL_ASCII_STRING_TYPE:
00376 case MEDIUM_EXTERNAL_ASCII_STRING_TYPE:
00377 case LONG_EXTERNAL_ASCII_STRING_TYPE:
00378 case SHORT_EXTERNAL_STRING_TYPE:
00379 case MEDIUM_EXTERNAL_STRING_TYPE:
00380 case LONG_EXTERNAL_STRING_TYPE: return "EXTERNAL_STRING";
00381 case FIXED_ARRAY_TYPE: return "FIXED_ARRAY";
00382 case BYTE_ARRAY_TYPE: return "BYTE_ARRAY";
00383 case FILLER_TYPE: return "FILLER";
00384 case JS_OBJECT_TYPE: return "JS_OBJECT";
00385 case ODDBALL_TYPE: return "ODDBALL";
00386 case SHARED_FUNCTION_INFO_TYPE: return "SHARED_FUNCTION_INFO";
00387 case JS_FUNCTION_TYPE: return "JS_FUNCTION";
00388 case CODE_TYPE: return "CODE";
00389 case JS_ARRAY_TYPE: return "JS_ARRAY";
00390 case JS_REGEXP_TYPE: return "JS_REGEXP";
00391 case JS_VALUE_TYPE: return "JS_VALUE";
00392 case JS_GLOBAL_OBJECT_TYPE: return "JS_GLOBAL_OBJECT";
00393 case JS_BUILTINS_OBJECT_TYPE: return "JS_BUILTINS_OBJECT";
00394 case JS_GLOBAL_PROXY_TYPE: return "JS_GLOBAL_PROXY";
00395 case PROXY_TYPE: return "PROXY";
00396 case SMI_TYPE: return "SMI";
00397 #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return #NAME;
00398 STRUCT_LIST(MAKE_STRUCT_CASE)
00399 #undef MAKE_STRUCT_CASE
00400 }
00401 return "UNKNOWN";
00402 }
00403
00404
00405 void Map::MapPrint() {
00406 HeapObject::PrintHeader("Map");
00407 PrintF(" - type: %s\n", TypeToString(instance_type()));
00408 PrintF(" - instance size: %d\n", instance_size());
00409 PrintF(" - unused property fields: %d\n", unused_property_fields());
00410 PrintF(" - instance descriptors: ");
00411 instance_descriptors()->ShortPrint();
00412 PrintF("\n - prototype: ");
00413 prototype()->ShortPrint();
00414 PrintF("\n - constructor: ");
00415 constructor()->ShortPrint();
00416 PrintF("\n");
00417 }
00418
00419
00420 void Map::MapVerify() {
00421 ASSERT(!Heap::InNewSpace(this));
00422 ASSERT(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
00423 ASSERT(kPointerSize <= instance_size()
00424 && instance_size() < Heap::Capacity());
00425 VerifyHeapPointer(prototype());
00426 VerifyHeapPointer(instance_descriptors());
00427 }
00428
00429
00430 void FixedArray::FixedArrayPrint() {
00431 HeapObject::PrintHeader("FixedArray");
00432 PrintF(" - length: %d", length());
00433 for (int i = 0; i < length(); i++) {
00434 PrintF("\n [%d]: ", i);
00435 get(i)->ShortPrint();
00436 }
00437 PrintF("\n");
00438 }
00439
00440
00441 void FixedArray::FixedArrayVerify() {
00442 for (int i = 0; i < length(); i++) {
00443 Object* e = get(i);
00444 if (e->IsHeapObject()) {
00445 VerifyHeapPointer(e);
00446 } else {
00447 e->Verify();
00448 }
00449 }
00450 }
00451
00452
00453 void JSValue::JSValuePrint() {
00454 HeapObject::PrintHeader("ValueObject");
00455 value()->Print();
00456 }
00457
00458
00459 void JSValue::JSValueVerify() {
00460 Object* v = value();
00461 if (v->IsHeapObject()) {
00462 VerifyHeapPointer(v);
00463 }
00464 }
00465
00466
00467 void String::StringPrint() {
00468 if (IsSymbol()) {
00469 PrintF("#");
00470 } else if (IsConsString()) {
00471 PrintF("c\"");
00472 } else {
00473 PrintF("\"");
00474 }
00475
00476 for (int i = 0; i < length(); i++) {
00477 PrintF("%c", Get(i));
00478 }
00479
00480 if (!IsSymbol()) PrintF("\"");
00481 }
00482
00483
00484 void String::StringVerify() {
00485 CHECK(IsString());
00486 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
00487 if (IsSymbol()) {
00488 CHECK(!Heap::InNewSpace(this));
00489 }
00490 }
00491
00492
00493 void JSFunction::JSFunctionPrint() {
00494 HeapObject::PrintHeader("Function");
00495 PrintF(" - map = 0x%p\n", map());
00496 PrintF(" - is boilerplate: %s\n", IsBoilerplate() ? "yes" : "no");
00497 PrintF(" - initial_map = ");
00498 if (has_initial_map()) {
00499 initial_map()->ShortPrint();
00500 }
00501 PrintF("\n - shared_info = ");
00502 shared()->ShortPrint();
00503 PrintF("\n - name = ");
00504 shared()->name()->Print();
00505 PrintF("\n - context = ");
00506 unchecked_context()->ShortPrint();
00507 PrintF("\n - code = ");
00508 code()->ShortPrint();
00509 PrintF("\n");
00510
00511 PrintProperties();
00512 PrintElements();
00513
00514 PrintF("\n");
00515 }
00516
00517
00518 void JSFunction::JSFunctionVerify() {
00519 CHECK(IsJSFunction());
00520 VerifyObjectField(kPrototypeOrInitialMapOffset);
00521 }
00522
00523
00524 void SharedFunctionInfo::SharedFunctionInfoPrint() {
00525 HeapObject::PrintHeader("SharedFunctionInfo");
00526 PrintF(" - name: ");
00527 name()->ShortPrint();
00528 PrintF("\n - expected_nof_properties: %d", expected_nof_properties());
00529 PrintF("\n - instance class name =");
00530 instance_class_name()->Print();
00531 PrintF("\n - code =");
00532 code()->ShortPrint();
00533 PrintF("\n - source code =");
00534 GetSourceCode()->ShortPrint();
00535 PrintF("\n - lazy load: %s",
00536 lazy_load_data() == Heap::undefined_value() ? "no" : "yes");
00537
00538
00539
00540 PrintF("\n - function token position = %d", function_token_position());
00541 PrintF("\n - start position = %d", start_position());
00542 PrintF("\n - end position = %d", end_position());
00543 PrintF("\n - is expression = %d", is_expression());
00544 PrintF("\n - debug info = ");
00545 debug_info()->Print();
00546 PrintF("\n - length = %d", length());
00547 PrintF("\n");
00548 }
00549
00550 void SharedFunctionInfo::SharedFunctionInfoVerify() {
00551 CHECK(IsSharedFunctionInfo());
00552 VerifyObjectField(kNameOffset);
00553 VerifyObjectField(kCodeOffset);
00554 VerifyObjectField(kInstanceClassNameOffset);
00555 VerifyObjectField(kExternalReferenceDataOffset);
00556 VerifyObjectField(kLazyLoadDataOffset);
00557 VerifyObjectField(kScriptOffset);
00558 VerifyObjectField(kDebugInfoOffset);
00559 }
00560
00561
00562 void JSGlobalProxy::JSGlobalProxyPrint() {
00563 PrintF("global_proxy");
00564 JSObjectPrint();
00565 PrintF("context : ");
00566 context()->ShortPrint();
00567 PrintF("\n");
00568 }
00569
00570
00571 void JSGlobalProxy::JSGlobalProxyVerify() {
00572 CHECK(IsJSGlobalProxy());
00573 JSObjectVerify();
00574 VerifyObjectField(JSGlobalProxy::kContextOffset);
00575
00576 CHECK_EQ(0, properties()->length());
00577 CHECK_EQ(0, elements()->length());
00578 }
00579
00580
00581 void JSGlobalObject::JSGlobalObjectPrint() {
00582 PrintF("global ");
00583 JSObjectPrint();
00584 PrintF("global context : ");
00585 global_context()->ShortPrint();
00586 PrintF("\n");
00587 }
00588
00589
00590 void JSGlobalObject::JSGlobalObjectVerify() {
00591 CHECK(IsJSGlobalObject());
00592 JSObjectVerify();
00593 for (int i = GlobalObject::kBuiltinsOffset;
00594 i < JSGlobalObject::kSize;
00595 i += kPointerSize) {
00596 VerifyObjectField(i);
00597 }
00598 }
00599
00600
00601 void JSBuiltinsObject::JSBuiltinsObjectPrint() {
00602 PrintF("builtins ");
00603 JSObjectPrint();
00604 }
00605
00606
00607 void JSBuiltinsObject::JSBuiltinsObjectVerify() {
00608 CHECK(IsJSBuiltinsObject());
00609 JSObjectVerify();
00610 for (int i = GlobalObject::kBuiltinsOffset;
00611 i < JSBuiltinsObject::kSize;
00612 i += kPointerSize) {
00613 VerifyObjectField(i);
00614 }
00615 }
00616
00617
00618 void Oddball::OddballVerify() {
00619 CHECK(IsOddball());
00620 VerifyHeapPointer(to_string());
00621 Object* number = to_number();
00622 if (number->IsHeapObject()) {
00623 ASSERT(number == Heap::nan_value());
00624 } else {
00625 ASSERT(number->IsSmi());
00626 int value = Smi::cast(number)->value();
00627 ASSERT(value == 0 || value == 1 || value == -1);
00628 }
00629 }
00630
00631
00632 void Code::CodePrint() {
00633 HeapObject::PrintHeader("Code");
00634 #ifdef ENABLE_DISASSEMBLER
00635 Disassemble();
00636 #endif
00637 }
00638
00639
00640 void Code::CodeVerify() {
00641 CHECK(ic_flag() == IC_TARGET_IS_ADDRESS);
00642 Address last_gc_pc = NULL;
00643 for (RelocIterator it(this); !it.done(); it.next()) {
00644 it.rinfo()->Verify();
00645
00646 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
00647 CHECK(it.rinfo()->pc() != last_gc_pc);
00648 last_gc_pc = it.rinfo()->pc();
00649 }
00650 }
00651 }
00652
00653
00654 void JSArray::JSArrayVerify() {
00655 JSObjectVerify();
00656 ASSERT(length()->IsNumber() || length()->IsUndefined());
00657 ASSERT(elements()->IsUndefined() || elements()->IsFixedArray());
00658 }
00659
00660
00661 void JSRegExp::JSRegExpVerify() {
00662 JSObjectVerify();
00663 ASSERT(data()->IsUndefined() || data()->IsFixedArray());
00664 switch (TypeTag()) {
00665 case JSRegExp::ATOM: {
00666 FixedArray* arr = FixedArray::cast(data());
00667 ASSERT(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
00668 break;
00669 }
00670 case JSRegExp::JSCRE: {
00671 FixedArray* arr = FixedArray::cast(data());
00672 ASSERT(arr->get(JSRegExp::kJscreDataIndex)->IsFixedArray());
00673 break;
00674 }
00675 default:
00676 ASSERT_EQ(JSRegExp::NOT_COMPILED, TypeTag());
00677 ASSERT(data()->IsUndefined());
00678 break;
00679 }
00680 }
00681
00682
00683 void Proxy::ProxyPrint() {
00684 PrintF("proxy to %p", proxy());
00685 }
00686
00687
00688 void Proxy::ProxyVerify() {
00689 ASSERT(IsProxy());
00690 }
00691
00692
00693 void Dictionary::Print() {
00694 int capacity = Capacity();
00695 for (int i = 0; i < capacity; i++) {
00696 Object* k = KeyAt(i);
00697 if (IsKey(k)) {
00698 PrintF(" ");
00699 if (k->IsString()) {
00700 String::cast(k)->StringPrint();
00701 } else {
00702 k->ShortPrint();
00703 }
00704 PrintF(": ");
00705 ValueAt(i)->ShortPrint();
00706 PrintF("\n");
00707 }
00708 }
00709 }
00710
00711
00712 void AccessorInfo::AccessorInfoVerify() {
00713 CHECK(IsAccessorInfo());
00714 VerifyPointer(getter());
00715 VerifyPointer(setter());
00716 VerifyPointer(name());
00717 VerifyPointer(data());
00718 VerifyPointer(flag());
00719 }
00720
00721 void AccessorInfo::AccessorInfoPrint() {
00722 PrintF("AccessorInfo");
00723 PrintF("\n - getter: ");
00724 getter()->ShortPrint();
00725 PrintF("\n - setter: ");
00726 setter()->ShortPrint();
00727 PrintF("\n - name: ");
00728 name()->ShortPrint();
00729 PrintF("\n - data: ");
00730 data()->ShortPrint();
00731 PrintF("\n - flag: ");
00732 flag()->ShortPrint();
00733 }
00734
00735 void AccessCheckInfo::AccessCheckInfoVerify() {
00736 CHECK(IsAccessCheckInfo());
00737 VerifyPointer(named_callback());
00738 VerifyPointer(indexed_callback());
00739 VerifyPointer(data());
00740 }
00741
00742 void AccessCheckInfo::AccessCheckInfoPrint() {
00743 PrintF("AccessCheckInfo");
00744 PrintF("\n - named_callback: ");
00745 named_callback()->ShortPrint();
00746 PrintF("\n - indexed_callback: ");
00747 indexed_callback()->ShortPrint();
00748 PrintF("\n - data: ");
00749 data()->ShortPrint();
00750 }
00751
00752 void InterceptorInfo::InterceptorInfoVerify() {
00753 CHECK(IsInterceptorInfo());
00754 VerifyPointer(getter());
00755 VerifyPointer(setter());
00756 VerifyPointer(query());
00757 VerifyPointer(deleter());
00758 VerifyPointer(enumerator());
00759 VerifyPointer(data());
00760 }
00761
00762 void InterceptorInfo::InterceptorInfoPrint() {
00763 PrintF("InterceptorInfo");
00764 PrintF("\n - getter: ");
00765 getter()->ShortPrint();
00766 PrintF("\n - setter: ");
00767 setter()->ShortPrint();
00768 PrintF("\n - query: ");
00769 query()->ShortPrint();
00770 PrintF("\n - deleter: ");
00771 deleter()->ShortPrint();
00772 PrintF("\n - enumerator: ");
00773 enumerator()->ShortPrint();
00774 PrintF("\n - data: ");
00775 data()->ShortPrint();
00776 }
00777
00778 void CallHandlerInfo::CallHandlerInfoVerify() {
00779 CHECK(IsCallHandlerInfo());
00780 VerifyPointer(callback());
00781 VerifyPointer(data());
00782 }
00783
00784 void CallHandlerInfo::CallHandlerInfoPrint() {
00785 PrintF("CallHandlerInfo");
00786 PrintF("\n - callback: ");
00787 callback()->ShortPrint();
00788 PrintF("\n - data: ");
00789 data()->ShortPrint();
00790 }
00791
00792 void TemplateInfo::TemplateInfoVerify() {
00793 VerifyPointer(tag());
00794 VerifyPointer(property_list());
00795 }
00796
00797 void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
00798 CHECK(IsFunctionTemplateInfo());
00799 TemplateInfoVerify();
00800 VerifyPointer(serial_number());
00801 VerifyPointer(call_code());
00802 VerifyPointer(property_accessors());
00803 VerifyPointer(prototype_template());
00804 VerifyPointer(parent_template());
00805 VerifyPointer(named_property_handler());
00806 VerifyPointer(indexed_property_handler());
00807 VerifyPointer(instance_template());
00808 VerifyPointer(signature());
00809 VerifyPointer(access_check_info());
00810 }
00811
00812 void FunctionTemplateInfo::FunctionTemplateInfoPrint() {
00813 PrintF("FunctionTemplateInfo");
00814 PrintF("\n - tag: ");
00815 tag()->ShortPrint();
00816 PrintF("\n - property_list: ");
00817 property_list()->ShortPrint();
00818 PrintF("\n - serial_number: ");
00819 serial_number()->ShortPrint();
00820 PrintF("\n - call_code: ");
00821 call_code()->ShortPrint();
00822 PrintF("\n - property_accessors: ");
00823 property_accessors()->ShortPrint();
00824 PrintF("\n - prototype_template: ");
00825 prototype_template()->ShortPrint();
00826 PrintF("\n - parent_template: ");
00827 parent_template()->ShortPrint();
00828 PrintF("\n - named_property_handler: ");
00829 named_property_handler()->ShortPrint();
00830 PrintF("\n - indexed_property_handler: ");
00831 indexed_property_handler()->ShortPrint();
00832 PrintF("\n - instance_template: ");
00833 instance_template()->ShortPrint();
00834 PrintF("\n - signature: ");
00835 signature()->ShortPrint();
00836 PrintF("\n - access_check_info: ");
00837 access_check_info()->ShortPrint();
00838 PrintF("\n - hidden_prototype: %s", hidden_prototype() ? "true" : "false");
00839 PrintF("\n - undetectable: %s", undetectable() ? "true" : "false");
00840 PrintF("\n - need_access_check: %s", needs_access_check() ? "true" : "false");
00841 }
00842
00843 void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
00844 CHECK(IsObjectTemplateInfo());
00845 TemplateInfoVerify();
00846 VerifyPointer(constructor());
00847 VerifyPointer(internal_field_count());
00848 }
00849
00850 void ObjectTemplateInfo::ObjectTemplateInfoPrint() {
00851 PrintF("ObjectTemplateInfo");
00852 PrintF("\n - constructor: ");
00853 constructor()->ShortPrint();
00854 PrintF("\n - internal_field_count: ");
00855 internal_field_count()->ShortPrint();
00856 }
00857
00858 void SignatureInfo::SignatureInfoVerify() {
00859 CHECK(IsSignatureInfo());
00860 VerifyPointer(receiver());
00861 VerifyPointer(args());
00862 }
00863
00864 void SignatureInfo::SignatureInfoPrint() {
00865 PrintF("SignatureInfo");
00866 PrintF("\n - receiver: ");
00867 receiver()->ShortPrint();
00868 PrintF("\n - args: ");
00869 args()->ShortPrint();
00870 }
00871
00872 void TypeSwitchInfo::TypeSwitchInfoVerify() {
00873 CHECK(IsTypeSwitchInfo());
00874 VerifyPointer(types());
00875 }
00876
00877 void TypeSwitchInfo::TypeSwitchInfoPrint() {
00878 PrintF("TypeSwitchInfo");
00879 PrintF("\n - types: ");
00880 types()->ShortPrint();
00881 }
00882
00883
00884 void Script::ScriptVerify() {
00885 CHECK(IsScript());
00886 VerifyPointer(source());
00887 VerifyPointer(name());
00888 line_offset()->SmiVerify();
00889 column_offset()->SmiVerify();
00890 type()->SmiVerify();
00891 }
00892
00893
00894 void Script::ScriptPrint() {
00895 HeapObject::PrintHeader("Script");
00896 PrintF("\n - source: ");
00897 source()->ShortPrint();
00898 PrintF("\n - name: ");
00899 name()->ShortPrint();
00900 PrintF("\n - line_offset: ");
00901 line_offset()->ShortPrint();
00902 PrintF("\n - column_offset: ");
00903 column_offset()->ShortPrint();
00904 PrintF("\n - type: ");
00905 type()->ShortPrint();
00906 PrintF("\n");
00907 }
00908
00909
00910 void DebugInfo::DebugInfoVerify() {
00911 CHECK(IsDebugInfo());
00912 VerifyPointer(shared());
00913 VerifyPointer(original_code());
00914 VerifyPointer(code());
00915 VerifyPointer(break_points());
00916 }
00917
00918
00919 void DebugInfo::DebugInfoPrint() {
00920 PrintF("DebugInfo");
00921 PrintF("\n - shared");
00922 shared()->ShortPrint();
00923 PrintF("\n - original_code");
00924 original_code()->ShortPrint();
00925 PrintF("\n - code");
00926 code()->ShortPrint();
00927 PrintF("\n - break_points");
00928 break_points()->ShortPrint();
00929 }
00930
00931
00932 void BreakPointInfo::BreakPointInfoVerify() {
00933 CHECK(IsBreakPointInfo());
00934 code_position()->SmiVerify();
00935 source_position()->SmiVerify();
00936 statement_position()->SmiVerify();
00937 VerifyPointer(break_point_objects());
00938 }
00939
00940
00941 void BreakPointInfo::BreakPointInfoPrint() {
00942 PrintF("BreakPointInfo");
00943 PrintF("\n - code_position %d", code_position());
00944 PrintF("\n - source_position %d", source_position());
00945 PrintF("\n - statement_position %d", statement_position());
00946 PrintF("\n - break_point_objects ");
00947 break_point_objects()->ShortPrint();
00948 }
00949
00950
00951 void JSObject::IncrementSpillStatistics(SpillInformation* info) {
00952 info->number_of_objects_++;
00953
00954 if (HasFastProperties()) {
00955 info->number_of_objects_with_fast_properties_++;
00956 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
00957 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
00958 } else {
00959 Dictionary* dict = property_dictionary();
00960 info->number_of_slow_used_properties_ += dict->NumberOfElements();
00961 info->number_of_slow_unused_properties_ +=
00962 dict->Capacity() - dict->NumberOfElements();
00963 }
00964
00965 if (HasFastElements()) {
00966 info->number_of_objects_with_fast_elements_++;
00967 int holes = 0;
00968 FixedArray* e = FixedArray::cast(elements());
00969 int len = e->length();
00970 for (int i = 0; i < len; i++) {
00971 if (e->get(i) == Heap::the_hole_value()) holes++;
00972 }
00973 info->number_of_fast_used_elements_ += len - holes;
00974 info->number_of_fast_unused_elements_ += holes;
00975 } else {
00976 Dictionary* dict = element_dictionary();
00977 info->number_of_slow_used_elements_ += dict->NumberOfElements();
00978 info->number_of_slow_unused_elements_ +=
00979 dict->Capacity() - dict->NumberOfElements();
00980 }
00981 }
00982
00983
00984 void JSObject::SpillInformation::Clear() {
00985 number_of_objects_ = 0;
00986 number_of_objects_with_fast_properties_ = 0;
00987 number_of_objects_with_fast_elements_ = 0;
00988 number_of_fast_used_fields_ = 0;
00989 number_of_fast_unused_fields_ = 0;
00990 number_of_slow_used_properties_ = 0;
00991 number_of_slow_unused_properties_ = 0;
00992 number_of_fast_used_elements_ = 0;
00993 number_of_fast_unused_elements_ = 0;
00994 number_of_slow_used_elements_ = 0;
00995 number_of_slow_unused_elements_ = 0;
00996 }
00997
00998 void JSObject::SpillInformation::Print() {
00999 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
01000
01001 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
01002 number_of_objects_with_fast_properties_,
01003 number_of_fast_used_fields_, number_of_fast_unused_fields_);
01004
01005 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
01006 number_of_objects_ - number_of_objects_with_fast_properties_,
01007 number_of_slow_used_properties_, number_of_slow_unused_properties_);
01008
01009 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
01010 number_of_objects_with_fast_elements_,
01011 number_of_fast_used_elements_, number_of_fast_unused_elements_);
01012
01013 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
01014 number_of_objects_ - number_of_objects_with_fast_elements_,
01015 number_of_slow_used_elements_, number_of_slow_unused_elements_);
01016
01017 PrintF("\n");
01018 }
01019
01020
01021 void DescriptorArray::PrintDescriptors() {
01022 PrintF("Descriptor array %d\n", number_of_descriptors());
01023 int number = 0;
01024 for (DescriptorReader r(this); !r.eos(); r.advance()) {
01025 Descriptor desc;
01026 r.Get(&desc);
01027 PrintF(" %d: ", number++);
01028 desc.Print();
01029 }
01030 PrintF("\n");
01031 }
01032
01033
01034 bool DescriptorArray::IsSortedNoDuplicates() {
01035 String* current_key = NULL;
01036 uint32_t current = 0;
01037 for (DescriptorReader r(this); !r.eos(); r.advance()) {
01038 String* key = r.GetKey();
01039 if (key == current_key) {
01040 PrintDescriptors();
01041 return false;
01042 }
01043 current_key = key;
01044 uint32_t hash = r.GetKey()->Hash();
01045 if (hash < current) {
01046 PrintDescriptors();
01047 return false;
01048 }
01049 current = hash;
01050 }
01051 return true;
01052 }
01053
01054
01055 #endif // DEBUG
01056
01057 } }