fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. 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 "jsregexp.h" |
| 33 | #include "objects-visiting.h" |
| 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
| 38 | #ifdef OBJECT_PRINT |
| 39 | |
| 40 | static const char* TypeToString(InstanceType type); |
| 41 | |
| 42 | |
| 43 | void MaybeObject::Print(FILE* out) { |
| 44 | Object* this_as_object; |
| 45 | if (ToObject(&this_as_object)) { |
| 46 | if (this_as_object->IsSmi()) { |
| 47 | Smi::cast(this_as_object)->SmiPrint(out); |
| 48 | } else { |
| 49 | HeapObject::cast(this_as_object)->HeapObjectPrint(out); |
| 50 | } |
| 51 | } else { |
| 52 | Failure::cast(this)->FailurePrint(out); |
| 53 | } |
| 54 | Flush(out); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | void MaybeObject::PrintLn(FILE* out) { |
| 59 | Print(out); |
| 60 | PrintF(out, "\n"); |
| 61 | } |
| 62 | |
| 63 | |
| 64 | void HeapObject::PrintHeader(FILE* out, const char* id) { |
| 65 | PrintF(out, "%p: [%s]\n", reinterpret_cast<void*>(this), id); |
| 66 | } |
| 67 | |
| 68 | |
| 69 | void HeapObject::HeapObjectPrint(FILE* out) { |
| 70 | InstanceType instance_type = map()->instance_type(); |
| 71 | |
| 72 | HandleScope scope; |
| 73 | if (instance_type < FIRST_NONSTRING_TYPE) { |
| 74 | String::cast(this)->StringPrint(out); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | switch (instance_type) { |
| 79 | case MAP_TYPE: |
| 80 | Map::cast(this)->MapPrint(out); |
| 81 | break; |
| 82 | case HEAP_NUMBER_TYPE: |
| 83 | HeapNumber::cast(this)->HeapNumberPrint(out); |
| 84 | break; |
| 85 | case FIXED_ARRAY_TYPE: |
| 86 | FixedArray::cast(this)->FixedArrayPrint(out); |
| 87 | break; |
| 88 | case BYTE_ARRAY_TYPE: |
| 89 | ByteArray::cast(this)->ByteArrayPrint(out); |
| 90 | break; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 91 | case EXTERNAL_PIXEL_ARRAY_TYPE: |
| 92 | ExternalPixelArray::cast(this)->ExternalPixelArrayPrint(out); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 93 | break; |
| 94 | case EXTERNAL_BYTE_ARRAY_TYPE: |
| 95 | ExternalByteArray::cast(this)->ExternalByteArrayPrint(out); |
| 96 | break; |
| 97 | case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 98 | ExternalUnsignedByteArray::cast(this) |
| 99 | ->ExternalUnsignedByteArrayPrint(out); |
| 100 | break; |
| 101 | case EXTERNAL_SHORT_ARRAY_TYPE: |
| 102 | ExternalShortArray::cast(this)->ExternalShortArrayPrint(out); |
| 103 | break; |
| 104 | case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 105 | ExternalUnsignedShortArray::cast(this) |
| 106 | ->ExternalUnsignedShortArrayPrint(out); |
| 107 | break; |
| 108 | case EXTERNAL_INT_ARRAY_TYPE: |
| 109 | ExternalIntArray::cast(this)->ExternalIntArrayPrint(out); |
| 110 | break; |
| 111 | case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 112 | ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayPrint(out); |
| 113 | break; |
| 114 | case EXTERNAL_FLOAT_ARRAY_TYPE: |
| 115 | ExternalFloatArray::cast(this)->ExternalFloatArrayPrint(out); |
| 116 | break; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 117 | case EXTERNAL_DOUBLE_ARRAY_TYPE: |
| 118 | ExternalDoubleArray::cast(this)->ExternalDoubleArrayPrint(out); |
| 119 | break; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 120 | case FILLER_TYPE: |
| 121 | PrintF(out, "filler"); |
| 122 | break; |
| 123 | case JS_OBJECT_TYPE: // fall through |
| 124 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
| 125 | case JS_ARRAY_TYPE: |
| 126 | case JS_REGEXP_TYPE: |
| 127 | JSObject::cast(this)->JSObjectPrint(out); |
| 128 | break; |
| 129 | case ODDBALL_TYPE: |
| 130 | Oddball::cast(this)->to_string()->Print(out); |
| 131 | break; |
| 132 | case JS_FUNCTION_TYPE: |
| 133 | JSFunction::cast(this)->JSFunctionPrint(out); |
| 134 | break; |
| 135 | case JS_GLOBAL_PROXY_TYPE: |
| 136 | JSGlobalProxy::cast(this)->JSGlobalProxyPrint(out); |
| 137 | break; |
| 138 | case JS_GLOBAL_OBJECT_TYPE: |
| 139 | JSGlobalObject::cast(this)->JSGlobalObjectPrint(out); |
| 140 | break; |
| 141 | case JS_BUILTINS_OBJECT_TYPE: |
| 142 | JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(out); |
| 143 | break; |
| 144 | case JS_VALUE_TYPE: |
| 145 | PrintF(out, "Value wrapper around:"); |
| 146 | JSValue::cast(this)->value()->Print(out); |
| 147 | break; |
| 148 | case CODE_TYPE: |
| 149 | Code::cast(this)->CodePrint(out); |
| 150 | break; |
| 151 | case PROXY_TYPE: |
| 152 | Proxy::cast(this)->ProxyPrint(out); |
| 153 | break; |
| 154 | case SHARED_FUNCTION_INFO_TYPE: |
| 155 | SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(out); |
| 156 | break; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 157 | case JS_MESSAGE_OBJECT_TYPE: |
| 158 | JSMessageObject::cast(this)->JSMessageObjectPrint(out); |
| 159 | break; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 160 | case JS_GLOBAL_PROPERTY_CELL_TYPE: |
| 161 | JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellPrint(out); |
| 162 | break; |
| 163 | #define MAKE_STRUCT_CASE(NAME, Name, name) \ |
| 164 | case NAME##_TYPE: \ |
| 165 | Name::cast(this)->Name##Print(out); \ |
| 166 | break; |
| 167 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 168 | #undef MAKE_STRUCT_CASE |
| 169 | |
| 170 | default: |
| 171 | PrintF(out, "UNKNOWN TYPE %d", map()->instance_type()); |
| 172 | UNREACHABLE(); |
| 173 | break; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | |
| 178 | void ByteArray::ByteArrayPrint(FILE* out) { |
| 179 | PrintF(out, "byte array, data starts at %p", GetDataStartAddress()); |
| 180 | } |
| 181 | |
| 182 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 183 | void ExternalPixelArray::ExternalPixelArrayPrint(FILE* out) { |
| 184 | PrintF(out, "external pixel array"); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
| 188 | void ExternalByteArray::ExternalByteArrayPrint(FILE* out) { |
| 189 | PrintF(out, "external byte array"); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | void ExternalUnsignedByteArray::ExternalUnsignedByteArrayPrint(FILE* out) { |
| 194 | PrintF(out, "external unsigned byte array"); |
| 195 | } |
| 196 | |
| 197 | |
| 198 | void ExternalShortArray::ExternalShortArrayPrint(FILE* out) { |
| 199 | PrintF(out, "external short array"); |
| 200 | } |
| 201 | |
| 202 | |
| 203 | void ExternalUnsignedShortArray::ExternalUnsignedShortArrayPrint(FILE* out) { |
| 204 | PrintF(out, "external unsigned short array"); |
| 205 | } |
| 206 | |
| 207 | |
| 208 | void ExternalIntArray::ExternalIntArrayPrint(FILE* out) { |
| 209 | PrintF(out, "external int array"); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | void ExternalUnsignedIntArray::ExternalUnsignedIntArrayPrint(FILE* out) { |
| 214 | PrintF(out, "external unsigned int array"); |
| 215 | } |
| 216 | |
| 217 | |
| 218 | void ExternalFloatArray::ExternalFloatArrayPrint(FILE* out) { |
| 219 | PrintF(out, "external float array"); |
| 220 | } |
| 221 | |
| 222 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 223 | void ExternalDoubleArray::ExternalDoubleArrayPrint(FILE* out) { |
| 224 | PrintF(out, "external double array"); |
| 225 | } |
| 226 | |
| 227 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 228 | void JSObject::PrintProperties(FILE* out) { |
| 229 | if (HasFastProperties()) { |
| 230 | DescriptorArray* descs = map()->instance_descriptors(); |
| 231 | for (int i = 0; i < descs->number_of_descriptors(); i++) { |
| 232 | PrintF(out, " "); |
| 233 | descs->GetKey(i)->StringPrint(out); |
| 234 | PrintF(out, ": "); |
| 235 | switch (descs->GetType(i)) { |
| 236 | case FIELD: { |
| 237 | int index = descs->GetFieldIndex(i); |
| 238 | FastPropertyAt(index)->ShortPrint(out); |
| 239 | PrintF(out, " (field at offset %d)\n", index); |
| 240 | break; |
| 241 | } |
| 242 | case CONSTANT_FUNCTION: |
| 243 | descs->GetConstantFunction(i)->ShortPrint(out); |
| 244 | PrintF(out, " (constant function)\n"); |
| 245 | break; |
| 246 | case CALLBACKS: |
| 247 | descs->GetCallbacksObject(i)->ShortPrint(out); |
| 248 | PrintF(out, " (callback)\n"); |
| 249 | break; |
| 250 | case MAP_TRANSITION: |
| 251 | PrintF(out, " (map transition)\n"); |
| 252 | break; |
| 253 | case CONSTANT_TRANSITION: |
| 254 | PrintF(out, " (constant transition)\n"); |
| 255 | break; |
| 256 | case NULL_DESCRIPTOR: |
| 257 | PrintF(out, " (null descriptor)\n"); |
| 258 | break; |
| 259 | default: |
| 260 | UNREACHABLE(); |
| 261 | break; |
| 262 | } |
| 263 | } |
| 264 | } else { |
| 265 | property_dictionary()->Print(out); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | |
| 270 | void JSObject::PrintElements(FILE* out) { |
| 271 | switch (GetElementsKind()) { |
| 272 | case FAST_ELEMENTS: { |
| 273 | // Print in array notation for non-sparse arrays. |
| 274 | FixedArray* p = FixedArray::cast(elements()); |
| 275 | for (int i = 0; i < p->length(); i++) { |
| 276 | PrintF(out, " %d: ", i); |
| 277 | p->get(i)->ShortPrint(out); |
| 278 | PrintF(out, "\n"); |
| 279 | } |
| 280 | break; |
| 281 | } |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 282 | case EXTERNAL_PIXEL_ELEMENTS: { |
| 283 | ExternalPixelArray* p = ExternalPixelArray::cast(elements()); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 284 | for (int i = 0; i < p->length(); i++) { |
| 285 | PrintF(out, " %d: %d\n", i, p->get(i)); |
| 286 | } |
| 287 | break; |
| 288 | } |
| 289 | case EXTERNAL_BYTE_ELEMENTS: { |
| 290 | ExternalByteArray* p = ExternalByteArray::cast(elements()); |
| 291 | for (int i = 0; i < p->length(); i++) { |
| 292 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i))); |
| 293 | } |
| 294 | break; |
| 295 | } |
| 296 | case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: { |
| 297 | ExternalUnsignedByteArray* p = |
| 298 | ExternalUnsignedByteArray::cast(elements()); |
| 299 | for (int i = 0; i < p->length(); i++) { |
| 300 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i))); |
| 301 | } |
| 302 | break; |
| 303 | } |
| 304 | case EXTERNAL_SHORT_ELEMENTS: { |
| 305 | ExternalShortArray* p = ExternalShortArray::cast(elements()); |
| 306 | for (int i = 0; i < p->length(); i++) { |
| 307 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i))); |
| 308 | } |
| 309 | break; |
| 310 | } |
| 311 | case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: { |
| 312 | ExternalUnsignedShortArray* p = |
| 313 | ExternalUnsignedShortArray::cast(elements()); |
| 314 | for (int i = 0; i < p->length(); i++) { |
| 315 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i))); |
| 316 | } |
| 317 | break; |
| 318 | } |
| 319 | case EXTERNAL_INT_ELEMENTS: { |
| 320 | ExternalIntArray* p = ExternalIntArray::cast(elements()); |
| 321 | for (int i = 0; i < p->length(); i++) { |
| 322 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i))); |
| 323 | } |
| 324 | break; |
| 325 | } |
| 326 | case EXTERNAL_UNSIGNED_INT_ELEMENTS: { |
| 327 | ExternalUnsignedIntArray* p = |
| 328 | ExternalUnsignedIntArray::cast(elements()); |
| 329 | for (int i = 0; i < p->length(); i++) { |
| 330 | PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i))); |
| 331 | } |
| 332 | break; |
| 333 | } |
| 334 | case EXTERNAL_FLOAT_ELEMENTS: { |
| 335 | ExternalFloatArray* p = ExternalFloatArray::cast(elements()); |
| 336 | for (int i = 0; i < p->length(); i++) { |
| 337 | PrintF(out, " %d: %f\n", i, p->get(i)); |
| 338 | } |
| 339 | break; |
| 340 | } |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 341 | case EXTERNAL_DOUBLE_ELEMENTS: { |
| 342 | ExternalDoubleArray* p = ExternalDoubleArray::cast(elements()); |
| 343 | for (int i = 0; i < p->length(); i++) { |
| 344 | PrintF(out, " %d: %f\n", i, p->get(i)); |
| 345 | } |
| 346 | break; |
| 347 | } |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 348 | case DICTIONARY_ELEMENTS: |
| 349 | elements()->Print(out); |
| 350 | break; |
| 351 | default: |
| 352 | UNREACHABLE(); |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | |
| 358 | void JSObject::JSObjectPrint(FILE* out) { |
| 359 | PrintF(out, "%p: [JSObject]\n", reinterpret_cast<void*>(this)); |
| 360 | PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map())); |
| 361 | PrintF(out, " - prototype = %p\n", reinterpret_cast<void*>(GetPrototype())); |
| 362 | PrintF(out, " {\n"); |
| 363 | PrintProperties(out); |
| 364 | PrintElements(out); |
| 365 | PrintF(out, " }\n"); |
| 366 | } |
| 367 | |
| 368 | |
| 369 | static const char* TypeToString(InstanceType type) { |
| 370 | switch (type) { |
| 371 | case INVALID_TYPE: return "INVALID"; |
| 372 | case MAP_TYPE: return "MAP"; |
| 373 | case HEAP_NUMBER_TYPE: return "HEAP_NUMBER"; |
| 374 | case SYMBOL_TYPE: return "SYMBOL"; |
| 375 | case ASCII_SYMBOL_TYPE: return "ASCII_SYMBOL"; |
| 376 | case CONS_SYMBOL_TYPE: return "CONS_SYMBOL"; |
| 377 | case CONS_ASCII_SYMBOL_TYPE: return "CONS_ASCII_SYMBOL"; |
| 378 | case EXTERNAL_ASCII_SYMBOL_TYPE: |
| 379 | case EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE: |
| 380 | case EXTERNAL_SYMBOL_TYPE: return "EXTERNAL_SYMBOL"; |
| 381 | case ASCII_STRING_TYPE: return "ASCII_STRING"; |
| 382 | case STRING_TYPE: return "TWO_BYTE_STRING"; |
| 383 | case CONS_STRING_TYPE: |
| 384 | case CONS_ASCII_STRING_TYPE: return "CONS_STRING"; |
| 385 | case EXTERNAL_ASCII_STRING_TYPE: |
| 386 | case EXTERNAL_STRING_WITH_ASCII_DATA_TYPE: |
| 387 | case EXTERNAL_STRING_TYPE: return "EXTERNAL_STRING"; |
| 388 | case FIXED_ARRAY_TYPE: return "FIXED_ARRAY"; |
| 389 | case BYTE_ARRAY_TYPE: return "BYTE_ARRAY"; |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 390 | case EXTERNAL_PIXEL_ARRAY_TYPE: return "EXTERNAL_PIXEL_ARRAY"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 391 | case EXTERNAL_BYTE_ARRAY_TYPE: return "EXTERNAL_BYTE_ARRAY"; |
| 392 | case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 393 | return "EXTERNAL_UNSIGNED_BYTE_ARRAY"; |
| 394 | case EXTERNAL_SHORT_ARRAY_TYPE: return "EXTERNAL_SHORT_ARRAY"; |
| 395 | case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 396 | return "EXTERNAL_UNSIGNED_SHORT_ARRAY"; |
| 397 | case EXTERNAL_INT_ARRAY_TYPE: return "EXTERNAL_INT_ARRAY"; |
| 398 | case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 399 | return "EXTERNAL_UNSIGNED_INT_ARRAY"; |
| 400 | case EXTERNAL_FLOAT_ARRAY_TYPE: return "EXTERNAL_FLOAT_ARRAY"; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 401 | case EXTERNAL_DOUBLE_ARRAY_TYPE: return "EXTERNAL_DOUBLE_ARRAY"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 402 | case FILLER_TYPE: return "FILLER"; |
| 403 | case JS_OBJECT_TYPE: return "JS_OBJECT"; |
| 404 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: return "JS_CONTEXT_EXTENSION_OBJECT"; |
| 405 | case ODDBALL_TYPE: return "ODDBALL"; |
| 406 | case JS_GLOBAL_PROPERTY_CELL_TYPE: return "JS_GLOBAL_PROPERTY_CELL"; |
| 407 | case SHARED_FUNCTION_INFO_TYPE: return "SHARED_FUNCTION_INFO"; |
| 408 | case JS_FUNCTION_TYPE: return "JS_FUNCTION"; |
| 409 | case CODE_TYPE: return "CODE"; |
| 410 | case JS_ARRAY_TYPE: return "JS_ARRAY"; |
| 411 | case JS_REGEXP_TYPE: return "JS_REGEXP"; |
| 412 | case JS_VALUE_TYPE: return "JS_VALUE"; |
| 413 | case JS_GLOBAL_OBJECT_TYPE: return "JS_GLOBAL_OBJECT"; |
| 414 | case JS_BUILTINS_OBJECT_TYPE: return "JS_BUILTINS_OBJECT"; |
| 415 | case JS_GLOBAL_PROXY_TYPE: return "JS_GLOBAL_PROXY"; |
| 416 | case PROXY_TYPE: return "PROXY"; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 417 | case JS_MESSAGE_OBJECT_TYPE: return "JS_MESSAGE_OBJECT_TYPE"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 418 | #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return #NAME; |
| 419 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 420 | #undef MAKE_STRUCT_CASE |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 421 | default: return "UNKNOWN"; |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 422 | } |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | |
| 426 | void Map::MapPrint(FILE* out) { |
| 427 | HeapObject::PrintHeader(out, "Map"); |
| 428 | PrintF(out, " - type: %s\n", TypeToString(instance_type())); |
| 429 | PrintF(out, " - instance size: %d\n", instance_size()); |
| 430 | PrintF(out, " - inobject properties: %d\n", inobject_properties()); |
| 431 | PrintF(out, " - pre-allocated property fields: %d\n", |
| 432 | pre_allocated_property_fields()); |
| 433 | PrintF(out, " - unused property fields: %d\n", unused_property_fields()); |
| 434 | if (is_hidden_prototype()) { |
| 435 | PrintF(out, " - hidden_prototype\n"); |
| 436 | } |
| 437 | if (has_named_interceptor()) { |
| 438 | PrintF(out, " - named_interceptor\n"); |
| 439 | } |
| 440 | if (has_indexed_interceptor()) { |
| 441 | PrintF(out, " - indexed_interceptor\n"); |
| 442 | } |
| 443 | if (is_undetectable()) { |
| 444 | PrintF(out, " - undetectable\n"); |
| 445 | } |
| 446 | if (has_instance_call_handler()) { |
| 447 | PrintF(out, " - instance_call_handler\n"); |
| 448 | } |
| 449 | if (is_access_check_needed()) { |
| 450 | PrintF(out, " - access_check_needed\n"); |
| 451 | } |
| 452 | PrintF(out, " - instance descriptors: "); |
| 453 | instance_descriptors()->ShortPrint(out); |
| 454 | PrintF(out, "\n - prototype: "); |
| 455 | prototype()->ShortPrint(out); |
| 456 | PrintF(out, "\n - constructor: "); |
| 457 | constructor()->ShortPrint(out); |
| 458 | PrintF(out, "\n"); |
| 459 | } |
| 460 | |
| 461 | |
| 462 | void CodeCache::CodeCachePrint(FILE* out) { |
| 463 | HeapObject::PrintHeader(out, "CodeCache"); |
| 464 | PrintF(out, "\n - default_cache: "); |
| 465 | default_cache()->ShortPrint(out); |
| 466 | PrintF(out, "\n - normal_type_cache: "); |
| 467 | normal_type_cache()->ShortPrint(out); |
| 468 | } |
| 469 | |
| 470 | |
| 471 | void FixedArray::FixedArrayPrint(FILE* out) { |
| 472 | HeapObject::PrintHeader(out, "FixedArray"); |
| 473 | PrintF(out, " - length: %d", length()); |
| 474 | for (int i = 0; i < length(); i++) { |
| 475 | PrintF(out, "\n [%d]: ", i); |
| 476 | get(i)->ShortPrint(out); |
| 477 | } |
| 478 | PrintF(out, "\n"); |
| 479 | } |
| 480 | |
| 481 | |
| 482 | void JSValue::JSValuePrint(FILE* out) { |
| 483 | HeapObject::PrintHeader(out, "ValueObject"); |
| 484 | value()->Print(out); |
| 485 | } |
| 486 | |
| 487 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 488 | void JSMessageObject::JSMessageObjectPrint(FILE* out) { |
| 489 | HeapObject::PrintHeader(out, "JSMessageObject"); |
| 490 | PrintF(out, " - type: "); |
| 491 | type()->ShortPrint(out); |
| 492 | PrintF(out, "\n - arguments: "); |
| 493 | arguments()->ShortPrint(out); |
| 494 | PrintF(out, "\n - start_position: %d", start_position()); |
| 495 | PrintF(out, "\n - end_position: %d", end_position()); |
| 496 | PrintF(out, "\n - script: "); |
| 497 | script()->ShortPrint(out); |
| 498 | PrintF(out, "\n - stack_trace: "); |
| 499 | stack_trace()->ShortPrint(out); |
| 500 | PrintF(out, "\n - stack_frames: "); |
| 501 | stack_frames()->ShortPrint(out); |
| 502 | PrintF(out, "\n"); |
| 503 | } |
| 504 | |
| 505 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 506 | void String::StringPrint(FILE* out) { |
| 507 | if (StringShape(this).IsSymbol()) { |
| 508 | PrintF(out, "#"); |
| 509 | } else if (StringShape(this).IsCons()) { |
| 510 | PrintF(out, "c\""); |
| 511 | } else { |
| 512 | PrintF(out, "\""); |
| 513 | } |
| 514 | |
| 515 | const char truncated_epilogue[] = "...<truncated>"; |
| 516 | int len = length(); |
| 517 | if (!FLAG_use_verbose_printer) { |
| 518 | if (len > 100) { |
| 519 | len = 100 - sizeof(truncated_epilogue); |
| 520 | } |
| 521 | } |
| 522 | for (int i = 0; i < len; i++) { |
| 523 | PrintF(out, "%c", Get(i)); |
| 524 | } |
| 525 | if (len != length()) { |
| 526 | PrintF(out, "%s", truncated_epilogue); |
| 527 | } |
| 528 | |
| 529 | if (!StringShape(this).IsSymbol()) PrintF(out, "\""); |
| 530 | } |
| 531 | |
| 532 | |
| 533 | void JSFunction::JSFunctionPrint(FILE* out) { |
| 534 | HeapObject::PrintHeader(out, "Function"); |
| 535 | PrintF(out, " - map = 0x%p\n", reinterpret_cast<void*>(map())); |
| 536 | PrintF(out, " - initial_map = "); |
| 537 | if (has_initial_map()) { |
| 538 | initial_map()->ShortPrint(out); |
| 539 | } |
| 540 | PrintF(out, "\n - shared_info = "); |
| 541 | shared()->ShortPrint(out); |
| 542 | PrintF(out, "\n - name = "); |
| 543 | shared()->name()->Print(out); |
| 544 | PrintF(out, "\n - context = "); |
| 545 | unchecked_context()->ShortPrint(out); |
| 546 | PrintF(out, "\n - code = "); |
| 547 | code()->ShortPrint(out); |
| 548 | PrintF(out, "\n"); |
| 549 | |
| 550 | PrintProperties(out); |
| 551 | PrintElements(out); |
| 552 | |
| 553 | PrintF(out, "\n"); |
| 554 | } |
| 555 | |
| 556 | |
| 557 | void SharedFunctionInfo::SharedFunctionInfoPrint(FILE* out) { |
| 558 | HeapObject::PrintHeader(out, "SharedFunctionInfo"); |
| 559 | PrintF(out, " - name: "); |
| 560 | name()->ShortPrint(out); |
| 561 | PrintF(out, "\n - expected_nof_properties: %d", expected_nof_properties()); |
| 562 | PrintF(out, "\n - instance class name = "); |
| 563 | instance_class_name()->Print(out); |
| 564 | PrintF(out, "\n - code = "); |
| 565 | code()->ShortPrint(out); |
| 566 | PrintF(out, "\n - source code = "); |
| 567 | GetSourceCode()->ShortPrint(out); |
| 568 | // Script files are often large, hard to read. |
| 569 | // PrintF(out, "\n - script ="); |
| 570 | // script()->Print(out); |
| 571 | PrintF(out, "\n - function token position = %d", function_token_position()); |
| 572 | PrintF(out, "\n - start position = %d", start_position()); |
| 573 | PrintF(out, "\n - end position = %d", end_position()); |
| 574 | PrintF(out, "\n - is expression = %d", is_expression()); |
| 575 | PrintF(out, "\n - debug info = "); |
| 576 | debug_info()->ShortPrint(out); |
| 577 | PrintF(out, "\n - length = %d", length()); |
| 578 | PrintF(out, "\n - has_only_simple_this_property_assignments = %d", |
| 579 | has_only_simple_this_property_assignments()); |
| 580 | PrintF(out, "\n - this_property_assignments = "); |
| 581 | this_property_assignments()->ShortPrint(out); |
| 582 | PrintF(out, "\n"); |
| 583 | } |
| 584 | |
| 585 | |
| 586 | void JSGlobalProxy::JSGlobalProxyPrint(FILE* out) { |
| 587 | PrintF(out, "global_proxy"); |
| 588 | JSObjectPrint(out); |
| 589 | PrintF(out, "context : "); |
| 590 | context()->ShortPrint(out); |
| 591 | PrintF(out, "\n"); |
| 592 | } |
| 593 | |
| 594 | |
| 595 | void JSGlobalObject::JSGlobalObjectPrint(FILE* out) { |
| 596 | PrintF(out, "global "); |
| 597 | JSObjectPrint(out); |
| 598 | PrintF(out, "global context : "); |
| 599 | global_context()->ShortPrint(out); |
| 600 | PrintF(out, "\n"); |
| 601 | } |
| 602 | |
| 603 | |
| 604 | void JSBuiltinsObject::JSBuiltinsObjectPrint(FILE* out) { |
| 605 | PrintF(out, "builtins "); |
| 606 | JSObjectPrint(out); |
| 607 | } |
| 608 | |
| 609 | |
| 610 | void JSGlobalPropertyCell::JSGlobalPropertyCellPrint(FILE* out) { |
| 611 | HeapObject::PrintHeader(out, "JSGlobalPropertyCell"); |
| 612 | } |
| 613 | |
| 614 | |
| 615 | void Code::CodePrint(FILE* out) { |
| 616 | HeapObject::PrintHeader(out, "Code"); |
| 617 | #ifdef ENABLE_DISASSEMBLER |
| 618 | if (FLAG_use_verbose_printer) { |
| 619 | Disassemble(NULL, out); |
| 620 | } |
| 621 | #endif |
| 622 | } |
| 623 | |
| 624 | |
| 625 | void Proxy::ProxyPrint(FILE* out) { |
| 626 | PrintF(out, "proxy to %p", proxy()); |
| 627 | } |
| 628 | |
| 629 | |
| 630 | void AccessorInfo::AccessorInfoPrint(FILE* out) { |
| 631 | HeapObject::PrintHeader(out, "AccessorInfo"); |
| 632 | PrintF(out, "\n - getter: "); |
| 633 | getter()->ShortPrint(out); |
| 634 | PrintF(out, "\n - setter: "); |
| 635 | setter()->ShortPrint(out); |
| 636 | PrintF(out, "\n - name: "); |
| 637 | name()->ShortPrint(out); |
| 638 | PrintF(out, "\n - data: "); |
| 639 | data()->ShortPrint(out); |
| 640 | PrintF(out, "\n - flag: "); |
| 641 | flag()->ShortPrint(out); |
| 642 | } |
| 643 | |
| 644 | |
| 645 | void AccessCheckInfo::AccessCheckInfoPrint(FILE* out) { |
| 646 | HeapObject::PrintHeader(out, "AccessCheckInfo"); |
| 647 | PrintF(out, "\n - named_callback: "); |
| 648 | named_callback()->ShortPrint(out); |
| 649 | PrintF(out, "\n - indexed_callback: "); |
| 650 | indexed_callback()->ShortPrint(out); |
| 651 | PrintF(out, "\n - data: "); |
| 652 | data()->ShortPrint(out); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | void InterceptorInfo::InterceptorInfoPrint(FILE* out) { |
| 657 | HeapObject::PrintHeader(out, "InterceptorInfo"); |
| 658 | PrintF(out, "\n - getter: "); |
| 659 | getter()->ShortPrint(out); |
| 660 | PrintF(out, "\n - setter: "); |
| 661 | setter()->ShortPrint(out); |
| 662 | PrintF(out, "\n - query: "); |
| 663 | query()->ShortPrint(out); |
| 664 | PrintF(out, "\n - deleter: "); |
| 665 | deleter()->ShortPrint(out); |
| 666 | PrintF(out, "\n - enumerator: "); |
| 667 | enumerator()->ShortPrint(out); |
| 668 | PrintF(out, "\n - data: "); |
| 669 | data()->ShortPrint(out); |
| 670 | } |
| 671 | |
| 672 | |
| 673 | void CallHandlerInfo::CallHandlerInfoPrint(FILE* out) { |
| 674 | HeapObject::PrintHeader(out, "CallHandlerInfo"); |
| 675 | PrintF(out, "\n - callback: "); |
| 676 | callback()->ShortPrint(out); |
| 677 | PrintF(out, "\n - data: "); |
| 678 | data()->ShortPrint(out); |
| 679 | PrintF(out, "\n - call_stub_cache: "); |
| 680 | } |
| 681 | |
| 682 | |
| 683 | void FunctionTemplateInfo::FunctionTemplateInfoPrint(FILE* out) { |
| 684 | HeapObject::PrintHeader(out, "FunctionTemplateInfo"); |
| 685 | PrintF(out, "\n - class name: "); |
| 686 | class_name()->ShortPrint(out); |
| 687 | PrintF(out, "\n - tag: "); |
| 688 | tag()->ShortPrint(out); |
| 689 | PrintF(out, "\n - property_list: "); |
| 690 | property_list()->ShortPrint(out); |
| 691 | PrintF(out, "\n - serial_number: "); |
| 692 | serial_number()->ShortPrint(out); |
| 693 | PrintF(out, "\n - call_code: "); |
| 694 | call_code()->ShortPrint(out); |
| 695 | PrintF(out, "\n - property_accessors: "); |
| 696 | property_accessors()->ShortPrint(out); |
| 697 | PrintF(out, "\n - prototype_template: "); |
| 698 | prototype_template()->ShortPrint(out); |
| 699 | PrintF(out, "\n - parent_template: "); |
| 700 | parent_template()->ShortPrint(out); |
| 701 | PrintF(out, "\n - named_property_handler: "); |
| 702 | named_property_handler()->ShortPrint(out); |
| 703 | PrintF(out, "\n - indexed_property_handler: "); |
| 704 | indexed_property_handler()->ShortPrint(out); |
| 705 | PrintF(out, "\n - instance_template: "); |
| 706 | instance_template()->ShortPrint(out); |
| 707 | PrintF(out, "\n - signature: "); |
| 708 | signature()->ShortPrint(out); |
| 709 | PrintF(out, "\n - access_check_info: "); |
| 710 | access_check_info()->ShortPrint(out); |
| 711 | PrintF(out, "\n - hidden_prototype: %s", |
| 712 | hidden_prototype() ? "true" : "false"); |
| 713 | PrintF(out, "\n - undetectable: %s", undetectable() ? "true" : "false"); |
| 714 | PrintF(out, "\n - need_access_check: %s", |
| 715 | needs_access_check() ? "true" : "false"); |
| 716 | } |
| 717 | |
| 718 | |
| 719 | void ObjectTemplateInfo::ObjectTemplateInfoPrint(FILE* out) { |
| 720 | HeapObject::PrintHeader(out, "ObjectTemplateInfo"); |
| 721 | PrintF(out, "\n - constructor: "); |
| 722 | constructor()->ShortPrint(out); |
| 723 | PrintF(out, "\n - internal_field_count: "); |
| 724 | internal_field_count()->ShortPrint(out); |
| 725 | } |
| 726 | |
| 727 | |
| 728 | void SignatureInfo::SignatureInfoPrint(FILE* out) { |
| 729 | HeapObject::PrintHeader(out, "SignatureInfo"); |
| 730 | PrintF(out, "\n - receiver: "); |
| 731 | receiver()->ShortPrint(out); |
| 732 | PrintF(out, "\n - args: "); |
| 733 | args()->ShortPrint(out); |
| 734 | } |
| 735 | |
| 736 | |
| 737 | void TypeSwitchInfo::TypeSwitchInfoPrint(FILE* out) { |
| 738 | HeapObject::PrintHeader(out, "TypeSwitchInfo"); |
| 739 | PrintF(out, "\n - types: "); |
| 740 | types()->ShortPrint(out); |
| 741 | } |
| 742 | |
| 743 | |
| 744 | void Script::ScriptPrint(FILE* out) { |
| 745 | HeapObject::PrintHeader(out, "Script"); |
| 746 | PrintF(out, "\n - source: "); |
| 747 | source()->ShortPrint(out); |
| 748 | PrintF(out, "\n - name: "); |
| 749 | name()->ShortPrint(out); |
| 750 | PrintF(out, "\n - line_offset: "); |
| 751 | line_offset()->ShortPrint(out); |
| 752 | PrintF(out, "\n - column_offset: "); |
| 753 | column_offset()->ShortPrint(out); |
| 754 | PrintF(out, "\n - type: "); |
| 755 | type()->ShortPrint(out); |
| 756 | PrintF(out, "\n - id: "); |
| 757 | id()->ShortPrint(out); |
| 758 | PrintF(out, "\n - data: "); |
| 759 | data()->ShortPrint(out); |
| 760 | PrintF(out, "\n - context data: "); |
| 761 | context_data()->ShortPrint(out); |
| 762 | PrintF(out, "\n - wrapper: "); |
| 763 | wrapper()->ShortPrint(out); |
| 764 | PrintF(out, "\n - compilation type: "); |
| 765 | compilation_type()->ShortPrint(out); |
| 766 | PrintF(out, "\n - line ends: "); |
| 767 | line_ends()->ShortPrint(out); |
| 768 | PrintF(out, "\n - eval from shared: "); |
| 769 | eval_from_shared()->ShortPrint(out); |
| 770 | PrintF(out, "\n - eval from instructions offset: "); |
| 771 | eval_from_instructions_offset()->ShortPrint(out); |
| 772 | PrintF(out, "\n"); |
| 773 | } |
| 774 | |
| 775 | |
| 776 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 777 | void DebugInfo::DebugInfoPrint(FILE* out) { |
| 778 | HeapObject::PrintHeader(out, "DebugInfo"); |
| 779 | PrintF(out, "\n - shared: "); |
| 780 | shared()->ShortPrint(out); |
| 781 | PrintF(out, "\n - original_code: "); |
| 782 | original_code()->ShortPrint(out); |
| 783 | PrintF(out, "\n - code: "); |
| 784 | code()->ShortPrint(out); |
| 785 | PrintF(out, "\n - break_points: "); |
| 786 | break_points()->Print(out); |
| 787 | } |
| 788 | |
| 789 | |
| 790 | void BreakPointInfo::BreakPointInfoPrint(FILE* out) { |
| 791 | HeapObject::PrintHeader(out, "BreakPointInfo"); |
| 792 | PrintF(out, "\n - code_position: %d", code_position()->value()); |
| 793 | PrintF(out, "\n - source_position: %d", source_position()->value()); |
| 794 | PrintF(out, "\n - statement_position: %d", statement_position()->value()); |
| 795 | PrintF(out, "\n - break_point_objects: "); |
| 796 | break_point_objects()->ShortPrint(out); |
| 797 | } |
| 798 | #endif // ENABLE_DEBUGGER_SUPPORT |
| 799 | |
| 800 | |
| 801 | void DescriptorArray::PrintDescriptors(FILE* out) { |
| 802 | PrintF(out, "Descriptor array %d\n", number_of_descriptors()); |
| 803 | for (int i = 0; i < number_of_descriptors(); i++) { |
| 804 | PrintF(out, " %d: ", i); |
| 805 | Descriptor desc; |
| 806 | Get(i, &desc); |
| 807 | desc.Print(out); |
| 808 | } |
| 809 | PrintF(out, "\n"); |
| 810 | } |
| 811 | |
| 812 | |
| 813 | #endif // OBJECT_PRINT |
| 814 | |
| 815 | |
| 816 | } } // namespace v8::internal |