blob: b60e54d3135d638a52312c2b10b94bcb9b6e1039 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2008 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"
Steve Blocka7e24c12009-10-30 11:49:00 +000032#include "jsregexp.h"
33
34namespace v8 {
35namespace internal {
36
37#ifdef DEBUG
38
39static const char* TypeToString(InstanceType type);
40
41
42void Object::Print() {
43 if (IsSmi()) {
44 Smi::cast(this)->SmiPrint();
45 } else if (IsFailure()) {
46 Failure::cast(this)->FailurePrint();
47 } else {
48 HeapObject::cast(this)->HeapObjectPrint();
49 }
50 Flush();
51}
52
53
54void Object::PrintLn() {
55 Print();
56 PrintF("\n");
57}
58
59
60void Object::Verify() {
61 if (IsSmi()) {
62 Smi::cast(this)->SmiVerify();
63 } else if (IsFailure()) {
64 Failure::cast(this)->FailureVerify();
65 } else {
66 HeapObject::cast(this)->HeapObjectVerify();
67 }
68}
69
70
71void Object::VerifyPointer(Object* p) {
72 if (p->IsHeapObject()) {
73 HeapObject::VerifyHeapPointer(p);
74 } else {
75 ASSERT(p->IsSmi());
76 }
77}
78
79
80void Smi::SmiVerify() {
81 ASSERT(IsSmi());
82}
83
84
85void Failure::FailureVerify() {
86 ASSERT(IsFailure());
87}
88
89
90void HeapObject::PrintHeader(const char* id) {
91 PrintF("%p: [%s]\n", this, id);
92}
93
94
95void HeapObject::HeapObjectPrint() {
96 InstanceType instance_type = map()->instance_type();
97
98 HandleScope scope;
99 if (instance_type < FIRST_NONSTRING_TYPE) {
100 String::cast(this)->StringPrint();
101 return;
102 }
103
104 switch (instance_type) {
105 case MAP_TYPE:
106 Map::cast(this)->MapPrint();
107 break;
108 case HEAP_NUMBER_TYPE:
109 HeapNumber::cast(this)->HeapNumberPrint();
110 break;
111 case FIXED_ARRAY_TYPE:
112 FixedArray::cast(this)->FixedArrayPrint();
113 break;
114 case BYTE_ARRAY_TYPE:
115 ByteArray::cast(this)->ByteArrayPrint();
116 break;
117 case PIXEL_ARRAY_TYPE:
118 PixelArray::cast(this)->PixelArrayPrint();
119 break;
Steve Block3ce2e202009-11-05 08:53:23 +0000120 case EXTERNAL_BYTE_ARRAY_TYPE:
121 ExternalByteArray::cast(this)->ExternalByteArrayPrint();
122 break;
123 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
124 ExternalUnsignedByteArray::cast(this)->ExternalUnsignedByteArrayPrint();
125 break;
126 case EXTERNAL_SHORT_ARRAY_TYPE:
127 ExternalShortArray::cast(this)->ExternalShortArrayPrint();
128 break;
129 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
130 ExternalUnsignedShortArray::cast(this)->ExternalUnsignedShortArrayPrint();
131 break;
132 case EXTERNAL_INT_ARRAY_TYPE:
133 ExternalIntArray::cast(this)->ExternalIntArrayPrint();
134 break;
135 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
136 ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayPrint();
137 break;
138 case EXTERNAL_FLOAT_ARRAY_TYPE:
139 ExternalFloatArray::cast(this)->ExternalFloatArrayPrint();
140 break;
Steve Blocka7e24c12009-10-30 11:49:00 +0000141 case FILLER_TYPE:
142 PrintF("filler");
143 break;
144 case JS_OBJECT_TYPE: // fall through
145 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
146 case JS_ARRAY_TYPE:
147 case JS_REGEXP_TYPE:
148 JSObject::cast(this)->JSObjectPrint();
149 break;
150 case ODDBALL_TYPE:
151 Oddball::cast(this)->to_string()->Print();
152 break;
153 case JS_FUNCTION_TYPE:
154 JSFunction::cast(this)->JSFunctionPrint();
155 break;
156 case JS_GLOBAL_PROXY_TYPE:
157 JSGlobalProxy::cast(this)->JSGlobalProxyPrint();
158 break;
159 case JS_GLOBAL_OBJECT_TYPE:
160 JSGlobalObject::cast(this)->JSGlobalObjectPrint();
161 break;
162 case JS_BUILTINS_OBJECT_TYPE:
163 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint();
164 break;
165 case JS_VALUE_TYPE:
166 PrintF("Value wrapper around:");
167 JSValue::cast(this)->value()->Print();
168 break;
169 case CODE_TYPE:
170 Code::cast(this)->CodePrint();
171 break;
172 case PROXY_TYPE:
173 Proxy::cast(this)->ProxyPrint();
174 break;
175 case SHARED_FUNCTION_INFO_TYPE:
176 SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint();
177 break;
178 case JS_GLOBAL_PROPERTY_CELL_TYPE:
179 JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellPrint();
180 break;
181#define MAKE_STRUCT_CASE(NAME, Name, name) \
182 case NAME##_TYPE: \
183 Name::cast(this)->Name##Print(); \
184 break;
185 STRUCT_LIST(MAKE_STRUCT_CASE)
186#undef MAKE_STRUCT_CASE
187
188 default:
189 PrintF("UNKNOWN TYPE %d", map()->instance_type());
190 UNREACHABLE();
191 break;
192 }
193}
194
195
196void HeapObject::HeapObjectVerify() {
197 InstanceType instance_type = map()->instance_type();
198
199 if (instance_type < FIRST_NONSTRING_TYPE) {
200 String::cast(this)->StringVerify();
201 return;
202 }
203
204 switch (instance_type) {
205 case MAP_TYPE:
206 Map::cast(this)->MapVerify();
207 break;
208 case HEAP_NUMBER_TYPE:
209 HeapNumber::cast(this)->HeapNumberVerify();
210 break;
211 case FIXED_ARRAY_TYPE:
212 FixedArray::cast(this)->FixedArrayVerify();
213 break;
214 case BYTE_ARRAY_TYPE:
215 ByteArray::cast(this)->ByteArrayVerify();
216 break;
217 case PIXEL_ARRAY_TYPE:
218 PixelArray::cast(this)->PixelArrayVerify();
219 break;
Steve Block3ce2e202009-11-05 08:53:23 +0000220 case EXTERNAL_BYTE_ARRAY_TYPE:
221 ExternalByteArray::cast(this)->ExternalByteArrayVerify();
222 break;
223 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
224 ExternalUnsignedByteArray::cast(this)->ExternalUnsignedByteArrayVerify();
225 break;
226 case EXTERNAL_SHORT_ARRAY_TYPE:
227 ExternalShortArray::cast(this)->ExternalShortArrayVerify();
228 break;
229 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
230 ExternalUnsignedShortArray::cast(this)->
231 ExternalUnsignedShortArrayVerify();
232 break;
233 case EXTERNAL_INT_ARRAY_TYPE:
234 ExternalIntArray::cast(this)->ExternalIntArrayVerify();
235 break;
236 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
237 ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayVerify();
238 break;
239 case EXTERNAL_FLOAT_ARRAY_TYPE:
240 ExternalFloatArray::cast(this)->ExternalFloatArrayVerify();
241 break;
Steve Blocka7e24c12009-10-30 11:49:00 +0000242 case CODE_TYPE:
243 Code::cast(this)->CodeVerify();
244 break;
245 case ODDBALL_TYPE:
246 Oddball::cast(this)->OddballVerify();
247 break;
248 case JS_OBJECT_TYPE:
249 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
250 JSObject::cast(this)->JSObjectVerify();
251 break;
252 case JS_VALUE_TYPE:
253 JSValue::cast(this)->JSValueVerify();
254 break;
255 case JS_FUNCTION_TYPE:
256 JSFunction::cast(this)->JSFunctionVerify();
257 break;
258 case JS_GLOBAL_PROXY_TYPE:
259 JSGlobalProxy::cast(this)->JSGlobalProxyVerify();
260 break;
261 case JS_GLOBAL_OBJECT_TYPE:
262 JSGlobalObject::cast(this)->JSGlobalObjectVerify();
263 break;
264 case JS_BUILTINS_OBJECT_TYPE:
265 JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify();
266 break;
267 case JS_GLOBAL_PROPERTY_CELL_TYPE:
268 JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellVerify();
269 break;
270 case JS_ARRAY_TYPE:
271 JSArray::cast(this)->JSArrayVerify();
272 break;
273 case JS_REGEXP_TYPE:
274 JSRegExp::cast(this)->JSRegExpVerify();
275 break;
276 case FILLER_TYPE:
277 break;
278 case PROXY_TYPE:
279 Proxy::cast(this)->ProxyVerify();
280 break;
281 case SHARED_FUNCTION_INFO_TYPE:
282 SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify();
283 break;
284
285#define MAKE_STRUCT_CASE(NAME, Name, name) \
286 case NAME##_TYPE: \
287 Name::cast(this)->Name##Verify(); \
288 break;
289 STRUCT_LIST(MAKE_STRUCT_CASE)
290#undef MAKE_STRUCT_CASE
291
292 default:
293 UNREACHABLE();
294 break;
295 }
296}
297
298
299void HeapObject::VerifyHeapPointer(Object* p) {
300 ASSERT(p->IsHeapObject());
301 ASSERT(Heap::Contains(HeapObject::cast(p)));
302}
303
304
305void HeapNumber::HeapNumberVerify() {
306 ASSERT(IsHeapNumber());
307}
308
309
310void ByteArray::ByteArrayPrint() {
311 PrintF("byte array, data starts at %p", GetDataStartAddress());
312}
313
314
315void PixelArray::PixelArrayPrint() {
316 PrintF("pixel array");
317}
318
319
Steve Block3ce2e202009-11-05 08:53:23 +0000320void ExternalByteArray::ExternalByteArrayPrint() {
321 PrintF("external byte array");
322}
323
324
325void ExternalUnsignedByteArray::ExternalUnsignedByteArrayPrint() {
326 PrintF("external unsigned byte array");
327}
328
329
330void ExternalShortArray::ExternalShortArrayPrint() {
331 PrintF("external short array");
332}
333
334
335void ExternalUnsignedShortArray::ExternalUnsignedShortArrayPrint() {
336 PrintF("external unsigned short array");
337}
338
339
340void ExternalIntArray::ExternalIntArrayPrint() {
341 PrintF("external int array");
342}
343
344
345void ExternalUnsignedIntArray::ExternalUnsignedIntArrayPrint() {
346 PrintF("external unsigned int array");
347}
348
349
350void ExternalFloatArray::ExternalFloatArrayPrint() {
351 PrintF("external float array");
352}
353
354
Steve Blocka7e24c12009-10-30 11:49:00 +0000355void ByteArray::ByteArrayVerify() {
356 ASSERT(IsByteArray());
357}
358
359
360void PixelArray::PixelArrayVerify() {
361 ASSERT(IsPixelArray());
362}
363
364
Steve Block3ce2e202009-11-05 08:53:23 +0000365void ExternalByteArray::ExternalByteArrayVerify() {
366 ASSERT(IsExternalByteArray());
367}
368
369
370void ExternalUnsignedByteArray::ExternalUnsignedByteArrayVerify() {
371 ASSERT(IsExternalUnsignedByteArray());
372}
373
374
375void ExternalShortArray::ExternalShortArrayVerify() {
376 ASSERT(IsExternalShortArray());
377}
378
379
380void ExternalUnsignedShortArray::ExternalUnsignedShortArrayVerify() {
381 ASSERT(IsExternalUnsignedShortArray());
382}
383
384
385void ExternalIntArray::ExternalIntArrayVerify() {
386 ASSERT(IsExternalIntArray());
387}
388
389
390void ExternalUnsignedIntArray::ExternalUnsignedIntArrayVerify() {
391 ASSERT(IsExternalUnsignedIntArray());
392}
393
394
395void ExternalFloatArray::ExternalFloatArrayVerify() {
396 ASSERT(IsExternalFloatArray());
397}
398
399
Steve Blocka7e24c12009-10-30 11:49:00 +0000400void JSObject::PrintProperties() {
401 if (HasFastProperties()) {
402 DescriptorArray* descs = map()->instance_descriptors();
403 for (int i = 0; i < descs->number_of_descriptors(); i++) {
404 PrintF(" ");
405 descs->GetKey(i)->StringPrint();
406 PrintF(": ");
407 switch (descs->GetType(i)) {
408 case FIELD: {
409 int index = descs->GetFieldIndex(i);
410 FastPropertyAt(index)->ShortPrint();
411 PrintF(" (field at offset %d)\n", index);
412 break;
413 }
414 case CONSTANT_FUNCTION:
415 descs->GetConstantFunction(i)->ShortPrint();
416 PrintF(" (constant function)\n");
417 break;
418 case CALLBACKS:
419 descs->GetCallbacksObject(i)->ShortPrint();
420 PrintF(" (callback)\n");
421 break;
422 case MAP_TRANSITION:
423 PrintF(" (map transition)\n");
424 break;
425 case CONSTANT_TRANSITION:
426 PrintF(" (constant transition)\n");
427 break;
428 case NULL_DESCRIPTOR:
429 PrintF(" (null descriptor)\n");
430 break;
431 default:
432 UNREACHABLE();
433 break;
434 }
435 }
436 } else {
437 property_dictionary()->Print();
438 }
439}
440
441
442void JSObject::PrintElements() {
443 switch (GetElementsKind()) {
444 case FAST_ELEMENTS: {
445 // Print in array notation for non-sparse arrays.
446 FixedArray* p = FixedArray::cast(elements());
447 for (int i = 0; i < p->length(); i++) {
448 PrintF(" %d: ", i);
449 p->get(i)->ShortPrint();
450 PrintF("\n");
451 }
452 break;
453 }
454 case PIXEL_ELEMENTS: {
455 PixelArray* p = PixelArray::cast(elements());
456 for (int i = 0; i < p->length(); i++) {
457 PrintF(" %d: %d\n", i, p->get(i));
458 }
459 break;
460 }
Steve Block3ce2e202009-11-05 08:53:23 +0000461 case EXTERNAL_BYTE_ELEMENTS: {
462 ExternalByteArray* p = ExternalByteArray::cast(elements());
463 for (int i = 0; i < p->length(); i++) {
464 PrintF(" %d: %d\n", i, static_cast<int>(p->get(i)));
465 }
466 break;
467 }
468 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: {
469 ExternalUnsignedByteArray* p =
470 ExternalUnsignedByteArray::cast(elements());
471 for (int i = 0; i < p->length(); i++) {
472 PrintF(" %d: %d\n", i, static_cast<int>(p->get(i)));
473 }
474 break;
475 }
476 case EXTERNAL_SHORT_ELEMENTS: {
477 ExternalShortArray* p = ExternalShortArray::cast(elements());
478 for (int i = 0; i < p->length(); i++) {
479 PrintF(" %d: %d\n", i, static_cast<int>(p->get(i)));
480 }
481 break;
482 }
483 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: {
484 ExternalUnsignedShortArray* p =
485 ExternalUnsignedShortArray::cast(elements());
486 for (int i = 0; i < p->length(); i++) {
487 PrintF(" %d: %d\n", i, static_cast<int>(p->get(i)));
488 }
489 break;
490 }
491 case EXTERNAL_INT_ELEMENTS: {
492 ExternalIntArray* p = ExternalIntArray::cast(elements());
493 for (int i = 0; i < p->length(); i++) {
494 PrintF(" %d: %d\n", i, static_cast<int>(p->get(i)));
495 }
496 break;
497 }
498 case EXTERNAL_UNSIGNED_INT_ELEMENTS: {
499 ExternalUnsignedIntArray* p =
500 ExternalUnsignedIntArray::cast(elements());
501 for (int i = 0; i < p->length(); i++) {
502 PrintF(" %d: %d\n", i, static_cast<int>(p->get(i)));
503 }
504 break;
505 }
506 case EXTERNAL_FLOAT_ELEMENTS: {
507 ExternalFloatArray* p = ExternalFloatArray::cast(elements());
508 for (int i = 0; i < p->length(); i++) {
509 PrintF(" %d: %f\n", i, p->get(i));
510 }
511 break;
512 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000513 case DICTIONARY_ELEMENTS:
514 elements()->Print();
515 break;
516 default:
517 UNREACHABLE();
518 break;
519 }
520}
521
522
523void JSObject::JSObjectPrint() {
524 PrintF("%p: [JSObject]\n", this);
525 PrintF(" - map = %p\n", map());
526 PrintF(" - prototype = %p\n", GetPrototype());
527 PrintF(" {\n");
528 PrintProperties();
529 PrintElements();
530 PrintF(" }\n");
531}
532
533
534void JSObject::JSObjectVerify() {
535 VerifyHeapPointer(properties());
536 VerifyHeapPointer(elements());
537 if (HasFastProperties()) {
538 CHECK_EQ(map()->unused_property_fields(),
539 (map()->inobject_properties() + properties()->length() -
540 map()->NextFreePropertyIndex()));
541 }
542}
543
544
545static const char* TypeToString(InstanceType type) {
546 switch (type) {
547 case INVALID_TYPE: return "INVALID";
548 case MAP_TYPE: return "MAP";
549 case HEAP_NUMBER_TYPE: return "HEAP_NUMBER";
Steve Blockd0582a62009-12-15 09:54:21 +0000550 case SYMBOL_TYPE: return "SYMBOL";
551 case ASCII_SYMBOL_TYPE: return "ASCII_SYMBOL";
552 case CONS_SYMBOL_TYPE: return "CONS_SYMBOL";
553 case CONS_ASCII_SYMBOL_TYPE: return "CONS_ASCII_SYMBOL";
554 case EXTERNAL_ASCII_SYMBOL_TYPE:
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100555 case EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE:
Steve Blockd0582a62009-12-15 09:54:21 +0000556 case EXTERNAL_SYMBOL_TYPE: return "EXTERNAL_SYMBOL";
557 case ASCII_STRING_TYPE: return "ASCII_STRING";
558 case STRING_TYPE: return "TWO_BYTE_STRING";
559 case CONS_STRING_TYPE:
560 case CONS_ASCII_STRING_TYPE: return "CONS_STRING";
561 case EXTERNAL_ASCII_STRING_TYPE:
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100562 case EXTERNAL_STRING_WITH_ASCII_DATA_TYPE:
Steve Blockd0582a62009-12-15 09:54:21 +0000563 case EXTERNAL_STRING_TYPE: return "EXTERNAL_STRING";
Steve Blocka7e24c12009-10-30 11:49:00 +0000564 case FIXED_ARRAY_TYPE: return "FIXED_ARRAY";
565 case BYTE_ARRAY_TYPE: return "BYTE_ARRAY";
566 case PIXEL_ARRAY_TYPE: return "PIXEL_ARRAY";
Steve Block3ce2e202009-11-05 08:53:23 +0000567 case EXTERNAL_BYTE_ARRAY_TYPE: return "EXTERNAL_BYTE_ARRAY";
568 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
569 return "EXTERNAL_UNSIGNED_BYTE_ARRAY";
570 case EXTERNAL_SHORT_ARRAY_TYPE: return "EXTERNAL_SHORT_ARRAY";
571 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
572 return "EXTERNAL_UNSIGNED_SHORT_ARRAY";
573 case EXTERNAL_INT_ARRAY_TYPE: return "EXTERNAL_INT_ARRAY";
574 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
575 return "EXTERNAL_UNSIGNED_INT_ARRAY";
576 case EXTERNAL_FLOAT_ARRAY_TYPE: return "EXTERNAL_FLOAT_ARRAY";
Steve Blocka7e24c12009-10-30 11:49:00 +0000577 case FILLER_TYPE: return "FILLER";
578 case JS_OBJECT_TYPE: return "JS_OBJECT";
579 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: return "JS_CONTEXT_EXTENSION_OBJECT";
580 case ODDBALL_TYPE: return "ODDBALL";
581 case JS_GLOBAL_PROPERTY_CELL_TYPE: return "JS_GLOBAL_PROPERTY_CELL";
582 case SHARED_FUNCTION_INFO_TYPE: return "SHARED_FUNCTION_INFO";
583 case JS_FUNCTION_TYPE: return "JS_FUNCTION";
584 case CODE_TYPE: return "CODE";
585 case JS_ARRAY_TYPE: return "JS_ARRAY";
586 case JS_REGEXP_TYPE: return "JS_REGEXP";
587 case JS_VALUE_TYPE: return "JS_VALUE";
588 case JS_GLOBAL_OBJECT_TYPE: return "JS_GLOBAL_OBJECT";
589 case JS_BUILTINS_OBJECT_TYPE: return "JS_BUILTINS_OBJECT";
590 case JS_GLOBAL_PROXY_TYPE: return "JS_GLOBAL_PROXY";
591 case PROXY_TYPE: return "PROXY";
Steve Blocka7e24c12009-10-30 11:49:00 +0000592#define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return #NAME;
593 STRUCT_LIST(MAKE_STRUCT_CASE)
594#undef MAKE_STRUCT_CASE
595 }
596 return "UNKNOWN";
597}
598
599
600void Map::MapPrint() {
601 HeapObject::PrintHeader("Map");
602 PrintF(" - type: %s\n", TypeToString(instance_type()));
603 PrintF(" - instance size: %d\n", instance_size());
604 PrintF(" - inobject properties: %d\n", inobject_properties());
605 PrintF(" - pre-allocated property fields: %d\n",
606 pre_allocated_property_fields());
607 PrintF(" - unused property fields: %d\n", unused_property_fields());
608 if (is_hidden_prototype()) {
609 PrintF(" - hidden_prototype\n");
610 }
611 if (has_named_interceptor()) {
612 PrintF(" - named_interceptor\n");
613 }
614 if (has_indexed_interceptor()) {
615 PrintF(" - indexed_interceptor\n");
616 }
617 if (is_undetectable()) {
618 PrintF(" - undetectable\n");
619 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000620 if (has_instance_call_handler()) {
621 PrintF(" - instance_call_handler\n");
622 }
623 if (is_access_check_needed()) {
624 PrintF(" - access_check_needed\n");
625 }
626 PrintF(" - instance descriptors: ");
627 instance_descriptors()->ShortPrint();
628 PrintF("\n - prototype: ");
629 prototype()->ShortPrint();
630 PrintF("\n - constructor: ");
631 constructor()->ShortPrint();
632 PrintF("\n");
633}
634
635
636void Map::MapVerify() {
637 ASSERT(!Heap::InNewSpace(this));
638 ASSERT(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
639 ASSERT(kPointerSize <= instance_size()
640 && instance_size() < Heap::Capacity());
641 VerifyHeapPointer(prototype());
642 VerifyHeapPointer(instance_descriptors());
643}
644
645
Steve Block6ded16b2010-05-10 14:33:55 +0100646void CodeCache::CodeCachePrint() {
647 HeapObject::PrintHeader("CodeCache");
648 PrintF("\n - default_cache: ");
649 default_cache()->ShortPrint();
650 PrintF("\n - normal_type_cache: ");
651 normal_type_cache()->ShortPrint();
652}
653
654
655void CodeCache::CodeCacheVerify() {
656 VerifyHeapPointer(default_cache());
657 VerifyHeapPointer(normal_type_cache());
658 ASSERT(default_cache()->IsFixedArray());
659 ASSERT(normal_type_cache()->IsUndefined()
660 || normal_type_cache()->IsCodeCacheHashTable());
661}
662
663
Steve Blocka7e24c12009-10-30 11:49:00 +0000664void FixedArray::FixedArrayPrint() {
665 HeapObject::PrintHeader("FixedArray");
666 PrintF(" - length: %d", length());
667 for (int i = 0; i < length(); i++) {
668 PrintF("\n [%d]: ", i);
669 get(i)->ShortPrint();
670 }
671 PrintF("\n");
672}
673
674
675void FixedArray::FixedArrayVerify() {
676 for (int i = 0; i < length(); i++) {
677 Object* e = get(i);
678 if (e->IsHeapObject()) {
679 VerifyHeapPointer(e);
680 } else {
681 e->Verify();
682 }
683 }
684}
685
686
687void JSValue::JSValuePrint() {
688 HeapObject::PrintHeader("ValueObject");
689 value()->Print();
690}
691
692
693void JSValue::JSValueVerify() {
694 Object* v = value();
695 if (v->IsHeapObject()) {
696 VerifyHeapPointer(v);
697 }
698}
699
700
701void String::StringPrint() {
702 if (StringShape(this).IsSymbol()) {
703 PrintF("#");
704 } else if (StringShape(this).IsCons()) {
705 PrintF("c\"");
706 } else {
707 PrintF("\"");
708 }
709
710 for (int i = 0; i < length(); i++) {
711 PrintF("%c", Get(i));
712 }
713
714 if (!StringShape(this).IsSymbol()) PrintF("\"");
715}
716
717
718void String::StringVerify() {
719 CHECK(IsString());
720 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
721 if (IsSymbol()) {
722 CHECK(!Heap::InNewSpace(this));
723 }
724}
725
726
727void JSFunction::JSFunctionPrint() {
728 HeapObject::PrintHeader("Function");
729 PrintF(" - map = 0x%p\n", map());
Steve Blocka7e24c12009-10-30 11:49:00 +0000730 PrintF(" - initial_map = ");
731 if (has_initial_map()) {
732 initial_map()->ShortPrint();
733 }
734 PrintF("\n - shared_info = ");
735 shared()->ShortPrint();
736 PrintF("\n - name = ");
737 shared()->name()->Print();
738 PrintF("\n - context = ");
739 unchecked_context()->ShortPrint();
740 PrintF("\n - code = ");
741 code()->ShortPrint();
742 PrintF("\n");
743
744 PrintProperties();
745 PrintElements();
746
747 PrintF("\n");
748}
749
750
751void JSFunction::JSFunctionVerify() {
752 CHECK(IsJSFunction());
753 VerifyObjectField(kPrototypeOrInitialMapOffset);
754}
755
756
757void SharedFunctionInfo::SharedFunctionInfoPrint() {
758 HeapObject::PrintHeader("SharedFunctionInfo");
759 PrintF(" - name: ");
760 name()->ShortPrint();
761 PrintF("\n - expected_nof_properties: %d", expected_nof_properties());
762 PrintF("\n - instance class name = ");
763 instance_class_name()->Print();
764 PrintF("\n - code = ");
765 code()->ShortPrint();
766 PrintF("\n - source code = ");
767 GetSourceCode()->ShortPrint();
768 // Script files are often large, hard to read.
769 // PrintF("\n - script =");
770 // script()->Print();
771 PrintF("\n - function token position = %d", function_token_position());
772 PrintF("\n - start position = %d", start_position());
773 PrintF("\n - end position = %d", end_position());
774 PrintF("\n - is expression = %d", is_expression());
775 PrintF("\n - debug info = ");
776 debug_info()->ShortPrint();
777 PrintF("\n - length = %d", length());
Steve Blocka7e24c12009-10-30 11:49:00 +0000778 PrintF("\n - has_only_simple_this_property_assignments = %d",
779 has_only_simple_this_property_assignments());
780 PrintF("\n - this_property_assignments = ");
781 this_property_assignments()->ShortPrint();
782 PrintF("\n");
783}
784
785void SharedFunctionInfo::SharedFunctionInfoVerify() {
786 CHECK(IsSharedFunctionInfo());
787 VerifyObjectField(kNameOffset);
788 VerifyObjectField(kCodeOffset);
789 VerifyObjectField(kInstanceClassNameOffset);
Steve Block6ded16b2010-05-10 14:33:55 +0100790 VerifyObjectField(kFunctionDataOffset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000791 VerifyObjectField(kScriptOffset);
792 VerifyObjectField(kDebugInfoOffset);
793}
794
795
796void JSGlobalProxy::JSGlobalProxyPrint() {
797 PrintF("global_proxy");
798 JSObjectPrint();
799 PrintF("context : ");
800 context()->ShortPrint();
801 PrintF("\n");
802}
803
804
805void JSGlobalProxy::JSGlobalProxyVerify() {
806 CHECK(IsJSGlobalProxy());
807 JSObjectVerify();
808 VerifyObjectField(JSGlobalProxy::kContextOffset);
809 // Make sure that this object has no properties, elements.
810 CHECK_EQ(0, properties()->length());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100811 CHECK(HasFastElements());
812 CHECK_EQ(0, FixedArray::cast(elements())->length());
Steve Blocka7e24c12009-10-30 11:49:00 +0000813}
814
815
816void JSGlobalObject::JSGlobalObjectPrint() {
817 PrintF("global ");
818 JSObjectPrint();
819 PrintF("global context : ");
820 global_context()->ShortPrint();
821 PrintF("\n");
822}
823
824
825void JSGlobalObject::JSGlobalObjectVerify() {
826 CHECK(IsJSGlobalObject());
827 JSObjectVerify();
828 for (int i = GlobalObject::kBuiltinsOffset;
829 i < JSGlobalObject::kSize;
830 i += kPointerSize) {
831 VerifyObjectField(i);
832 }
833}
834
835
836void JSBuiltinsObject::JSBuiltinsObjectPrint() {
837 PrintF("builtins ");
838 JSObjectPrint();
839}
840
841
842void JSBuiltinsObject::JSBuiltinsObjectVerify() {
843 CHECK(IsJSBuiltinsObject());
844 JSObjectVerify();
845 for (int i = GlobalObject::kBuiltinsOffset;
846 i < JSBuiltinsObject::kSize;
847 i += kPointerSize) {
848 VerifyObjectField(i);
849 }
850}
851
852
853void Oddball::OddballVerify() {
854 CHECK(IsOddball());
855 VerifyHeapPointer(to_string());
856 Object* number = to_number();
857 if (number->IsHeapObject()) {
858 ASSERT(number == Heap::nan_value());
859 } else {
860 ASSERT(number->IsSmi());
861 int value = Smi::cast(number)->value();
862 ASSERT(value == 0 || value == 1 || value == -1 ||
863 value == -2 || value == -3);
864 }
865}
866
867
868void JSGlobalPropertyCell::JSGlobalPropertyCellVerify() {
869 CHECK(IsJSGlobalPropertyCell());
870 VerifyObjectField(kValueOffset);
871}
872
873
874void JSGlobalPropertyCell::JSGlobalPropertyCellPrint() {
875 HeapObject::PrintHeader("JSGlobalPropertyCell");
876}
877
878
879void Code::CodePrint() {
880 HeapObject::PrintHeader("Code");
881#ifdef ENABLE_DISASSEMBLER
882 Disassemble(NULL);
883#endif
884}
885
886
887void Code::CodeVerify() {
888 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
889 static_cast<intptr_t>(kCodeAlignment)));
890 Address last_gc_pc = NULL;
891 for (RelocIterator it(this); !it.done(); it.next()) {
892 it.rinfo()->Verify();
893 // Ensure that GC will not iterate twice over the same pointer.
894 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
895 CHECK(it.rinfo()->pc() != last_gc_pc);
896 last_gc_pc = it.rinfo()->pc();
897 }
898 }
899}
900
901
902void JSArray::JSArrayVerify() {
903 JSObjectVerify();
904 ASSERT(length()->IsNumber() || length()->IsUndefined());
905 ASSERT(elements()->IsUndefined() || elements()->IsFixedArray());
906}
907
908
909void JSRegExp::JSRegExpVerify() {
910 JSObjectVerify();
911 ASSERT(data()->IsUndefined() || data()->IsFixedArray());
912 switch (TypeTag()) {
913 case JSRegExp::ATOM: {
914 FixedArray* arr = FixedArray::cast(data());
915 ASSERT(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
916 break;
917 }
918 case JSRegExp::IRREGEXP: {
919 bool is_native = RegExpImpl::UsesNativeRegExp();
920
921 FixedArray* arr = FixedArray::cast(data());
922 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
923 // TheHole : Not compiled yet.
924 // JSObject: Compilation error.
925 // Code/ByteArray: Compiled code.
926 ASSERT(ascii_data->IsTheHole() || ascii_data->IsJSObject() ||
927 (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray()));
928 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
929 ASSERT(uc16_data->IsTheHole() || ascii_data->IsJSObject() ||
930 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
931 ASSERT(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
932 ASSERT(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
933 break;
934 }
935 default:
936 ASSERT_EQ(JSRegExp::NOT_COMPILED, TypeTag());
937 ASSERT(data()->IsUndefined());
938 break;
939 }
940}
941
942
943void Proxy::ProxyPrint() {
944 PrintF("proxy to %p", proxy());
945}
946
947
948void Proxy::ProxyVerify() {
949 ASSERT(IsProxy());
950}
951
952
953void AccessorInfo::AccessorInfoVerify() {
954 CHECK(IsAccessorInfo());
955 VerifyPointer(getter());
956 VerifyPointer(setter());
957 VerifyPointer(name());
958 VerifyPointer(data());
959 VerifyPointer(flag());
Steve Blockd0582a62009-12-15 09:54:21 +0000960 VerifyPointer(load_stub_cache());
Steve Blocka7e24c12009-10-30 11:49:00 +0000961}
962
963void AccessorInfo::AccessorInfoPrint() {
964 HeapObject::PrintHeader("AccessorInfo");
965 PrintF("\n - getter: ");
966 getter()->ShortPrint();
967 PrintF("\n - setter: ");
968 setter()->ShortPrint();
969 PrintF("\n - name: ");
970 name()->ShortPrint();
971 PrintF("\n - data: ");
972 data()->ShortPrint();
973 PrintF("\n - flag: ");
974 flag()->ShortPrint();
975}
976
977void AccessCheckInfo::AccessCheckInfoVerify() {
978 CHECK(IsAccessCheckInfo());
979 VerifyPointer(named_callback());
980 VerifyPointer(indexed_callback());
981 VerifyPointer(data());
982}
983
984void AccessCheckInfo::AccessCheckInfoPrint() {
985 HeapObject::PrintHeader("AccessCheckInfo");
986 PrintF("\n - named_callback: ");
987 named_callback()->ShortPrint();
988 PrintF("\n - indexed_callback: ");
989 indexed_callback()->ShortPrint();
990 PrintF("\n - data: ");
991 data()->ShortPrint();
992}
993
994void InterceptorInfo::InterceptorInfoVerify() {
995 CHECK(IsInterceptorInfo());
996 VerifyPointer(getter());
997 VerifyPointer(setter());
998 VerifyPointer(query());
999 VerifyPointer(deleter());
1000 VerifyPointer(enumerator());
1001 VerifyPointer(data());
1002}
1003
1004void InterceptorInfo::InterceptorInfoPrint() {
1005 HeapObject::PrintHeader("InterceptorInfo");
1006 PrintF("\n - getter: ");
1007 getter()->ShortPrint();
1008 PrintF("\n - setter: ");
1009 setter()->ShortPrint();
1010 PrintF("\n - query: ");
1011 query()->ShortPrint();
1012 PrintF("\n - deleter: ");
1013 deleter()->ShortPrint();
1014 PrintF("\n - enumerator: ");
1015 enumerator()->ShortPrint();
1016 PrintF("\n - data: ");
1017 data()->ShortPrint();
1018}
1019
1020void CallHandlerInfo::CallHandlerInfoVerify() {
1021 CHECK(IsCallHandlerInfo());
1022 VerifyPointer(callback());
1023 VerifyPointer(data());
1024}
1025
1026void CallHandlerInfo::CallHandlerInfoPrint() {
1027 HeapObject::PrintHeader("CallHandlerInfo");
1028 PrintF("\n - callback: ");
1029 callback()->ShortPrint();
1030 PrintF("\n - data: ");
1031 data()->ShortPrint();
1032}
1033
1034void TemplateInfo::TemplateInfoVerify() {
1035 VerifyPointer(tag());
1036 VerifyPointer(property_list());
1037}
1038
1039void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
1040 CHECK(IsFunctionTemplateInfo());
1041 TemplateInfoVerify();
1042 VerifyPointer(serial_number());
1043 VerifyPointer(call_code());
1044 VerifyPointer(property_accessors());
1045 VerifyPointer(prototype_template());
1046 VerifyPointer(parent_template());
1047 VerifyPointer(named_property_handler());
1048 VerifyPointer(indexed_property_handler());
1049 VerifyPointer(instance_template());
1050 VerifyPointer(signature());
1051 VerifyPointer(access_check_info());
1052}
1053
1054void FunctionTemplateInfo::FunctionTemplateInfoPrint() {
1055 HeapObject::PrintHeader("FunctionTemplateInfo");
Andrei Popescu402d9372010-02-26 13:31:12 +00001056 PrintF("\n - class name: ");
1057 class_name()->ShortPrint();
Steve Blocka7e24c12009-10-30 11:49:00 +00001058 PrintF("\n - tag: ");
1059 tag()->ShortPrint();
1060 PrintF("\n - property_list: ");
1061 property_list()->ShortPrint();
1062 PrintF("\n - serial_number: ");
1063 serial_number()->ShortPrint();
1064 PrintF("\n - call_code: ");
1065 call_code()->ShortPrint();
1066 PrintF("\n - property_accessors: ");
1067 property_accessors()->ShortPrint();
1068 PrintF("\n - prototype_template: ");
1069 prototype_template()->ShortPrint();
1070 PrintF("\n - parent_template: ");
1071 parent_template()->ShortPrint();
1072 PrintF("\n - named_property_handler: ");
1073 named_property_handler()->ShortPrint();
1074 PrintF("\n - indexed_property_handler: ");
1075 indexed_property_handler()->ShortPrint();
1076 PrintF("\n - instance_template: ");
1077 instance_template()->ShortPrint();
1078 PrintF("\n - signature: ");
1079 signature()->ShortPrint();
1080 PrintF("\n - access_check_info: ");
1081 access_check_info()->ShortPrint();
1082 PrintF("\n - hidden_prototype: %s", hidden_prototype() ? "true" : "false");
1083 PrintF("\n - undetectable: %s", undetectable() ? "true" : "false");
1084 PrintF("\n - need_access_check: %s", needs_access_check() ? "true" : "false");
1085}
1086
1087void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
1088 CHECK(IsObjectTemplateInfo());
1089 TemplateInfoVerify();
1090 VerifyPointer(constructor());
1091 VerifyPointer(internal_field_count());
1092}
1093
1094void ObjectTemplateInfo::ObjectTemplateInfoPrint() {
1095 HeapObject::PrintHeader("ObjectTemplateInfo");
1096 PrintF("\n - constructor: ");
1097 constructor()->ShortPrint();
1098 PrintF("\n - internal_field_count: ");
1099 internal_field_count()->ShortPrint();
1100}
1101
1102void SignatureInfo::SignatureInfoVerify() {
1103 CHECK(IsSignatureInfo());
1104 VerifyPointer(receiver());
1105 VerifyPointer(args());
1106}
1107
1108void SignatureInfo::SignatureInfoPrint() {
1109 HeapObject::PrintHeader("SignatureInfo");
1110 PrintF("\n - receiver: ");
1111 receiver()->ShortPrint();
1112 PrintF("\n - args: ");
1113 args()->ShortPrint();
1114}
1115
1116void TypeSwitchInfo::TypeSwitchInfoVerify() {
1117 CHECK(IsTypeSwitchInfo());
1118 VerifyPointer(types());
1119}
1120
1121void TypeSwitchInfo::TypeSwitchInfoPrint() {
1122 HeapObject::PrintHeader("TypeSwitchInfo");
1123 PrintF("\n - types: ");
1124 types()->ShortPrint();
1125}
1126
1127
1128void Script::ScriptVerify() {
1129 CHECK(IsScript());
1130 VerifyPointer(source());
1131 VerifyPointer(name());
1132 line_offset()->SmiVerify();
1133 column_offset()->SmiVerify();
1134 VerifyPointer(data());
1135 VerifyPointer(wrapper());
1136 type()->SmiVerify();
1137 VerifyPointer(line_ends());
1138 VerifyPointer(id());
1139}
1140
1141
1142void Script::ScriptPrint() {
1143 HeapObject::PrintHeader("Script");
1144 PrintF("\n - source: ");
1145 source()->ShortPrint();
1146 PrintF("\n - name: ");
1147 name()->ShortPrint();
1148 PrintF("\n - line_offset: ");
1149 line_offset()->ShortPrint();
1150 PrintF("\n - column_offset: ");
1151 column_offset()->ShortPrint();
1152 PrintF("\n - type: ");
1153 type()->ShortPrint();
1154 PrintF("\n - id: ");
1155 id()->ShortPrint();
Steve Blockd0582a62009-12-15 09:54:21 +00001156 PrintF("\n - data: ");
1157 data()->ShortPrint();
1158 PrintF("\n - context data: ");
1159 context_data()->ShortPrint();
1160 PrintF("\n - wrapper: ");
1161 wrapper()->ShortPrint();
1162 PrintF("\n - compilation type: ");
1163 compilation_type()->ShortPrint();
1164 PrintF("\n - line ends: ");
1165 line_ends()->ShortPrint();
1166 PrintF("\n - eval from shared: ");
1167 eval_from_shared()->ShortPrint();
1168 PrintF("\n - eval from instructions offset: ");
1169 eval_from_instructions_offset()->ShortPrint();
Steve Blocka7e24c12009-10-30 11:49:00 +00001170 PrintF("\n");
1171}
1172
1173
1174#ifdef ENABLE_DEBUGGER_SUPPORT
1175void DebugInfo::DebugInfoVerify() {
1176 CHECK(IsDebugInfo());
1177 VerifyPointer(shared());
1178 VerifyPointer(original_code());
1179 VerifyPointer(code());
1180 VerifyPointer(break_points());
1181}
1182
1183
1184void DebugInfo::DebugInfoPrint() {
1185 HeapObject::PrintHeader("DebugInfo");
1186 PrintF("\n - shared: ");
1187 shared()->ShortPrint();
1188 PrintF("\n - original_code: ");
1189 original_code()->ShortPrint();
1190 PrintF("\n - code: ");
1191 code()->ShortPrint();
1192 PrintF("\n - break_points: ");
1193 break_points()->Print();
1194}
1195
1196
1197void BreakPointInfo::BreakPointInfoVerify() {
1198 CHECK(IsBreakPointInfo());
1199 code_position()->SmiVerify();
1200 source_position()->SmiVerify();
1201 statement_position()->SmiVerify();
1202 VerifyPointer(break_point_objects());
1203}
1204
1205
1206void BreakPointInfo::BreakPointInfoPrint() {
1207 HeapObject::PrintHeader("BreakPointInfo");
1208 PrintF("\n - code_position: %d", code_position());
1209 PrintF("\n - source_position: %d", source_position());
1210 PrintF("\n - statement_position: %d", statement_position());
1211 PrintF("\n - break_point_objects: ");
1212 break_point_objects()->ShortPrint();
1213}
1214#endif
1215
1216
1217void JSObject::IncrementSpillStatistics(SpillInformation* info) {
1218 info->number_of_objects_++;
1219 // Named properties
1220 if (HasFastProperties()) {
1221 info->number_of_objects_with_fast_properties_++;
1222 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
1223 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
1224 } else {
1225 StringDictionary* dict = property_dictionary();
1226 info->number_of_slow_used_properties_ += dict->NumberOfElements();
1227 info->number_of_slow_unused_properties_ +=
1228 dict->Capacity() - dict->NumberOfElements();
1229 }
1230 // Indexed properties
1231 switch (GetElementsKind()) {
1232 case FAST_ELEMENTS: {
1233 info->number_of_objects_with_fast_elements_++;
1234 int holes = 0;
1235 FixedArray* e = FixedArray::cast(elements());
1236 int len = e->length();
1237 for (int i = 0; i < len; i++) {
1238 if (e->get(i) == Heap::the_hole_value()) holes++;
1239 }
1240 info->number_of_fast_used_elements_ += len - holes;
1241 info->number_of_fast_unused_elements_ += holes;
1242 break;
1243 }
1244 case PIXEL_ELEMENTS: {
1245 info->number_of_objects_with_fast_elements_++;
1246 PixelArray* e = PixelArray::cast(elements());
1247 info->number_of_fast_used_elements_ += e->length();
1248 break;
1249 }
1250 case DICTIONARY_ELEMENTS: {
1251 NumberDictionary* dict = element_dictionary();
1252 info->number_of_slow_used_elements_ += dict->NumberOfElements();
1253 info->number_of_slow_unused_elements_ +=
1254 dict->Capacity() - dict->NumberOfElements();
1255 break;
1256 }
1257 default:
1258 UNREACHABLE();
1259 break;
1260 }
1261}
1262
1263
1264void JSObject::SpillInformation::Clear() {
1265 number_of_objects_ = 0;
1266 number_of_objects_with_fast_properties_ = 0;
1267 number_of_objects_with_fast_elements_ = 0;
1268 number_of_fast_used_fields_ = 0;
1269 number_of_fast_unused_fields_ = 0;
1270 number_of_slow_used_properties_ = 0;
1271 number_of_slow_unused_properties_ = 0;
1272 number_of_fast_used_elements_ = 0;
1273 number_of_fast_unused_elements_ = 0;
1274 number_of_slow_used_elements_ = 0;
1275 number_of_slow_unused_elements_ = 0;
1276}
1277
1278void JSObject::SpillInformation::Print() {
1279 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
1280
1281 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
1282 number_of_objects_with_fast_properties_,
1283 number_of_fast_used_fields_, number_of_fast_unused_fields_);
1284
1285 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
1286 number_of_objects_ - number_of_objects_with_fast_properties_,
1287 number_of_slow_used_properties_, number_of_slow_unused_properties_);
1288
1289 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
1290 number_of_objects_with_fast_elements_,
1291 number_of_fast_used_elements_, number_of_fast_unused_elements_);
1292
1293 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
1294 number_of_objects_ - number_of_objects_with_fast_elements_,
1295 number_of_slow_used_elements_, number_of_slow_unused_elements_);
1296
1297 PrintF("\n");
1298}
1299
1300
1301void DescriptorArray::PrintDescriptors() {
1302 PrintF("Descriptor array %d\n", number_of_descriptors());
1303 for (int i = 0; i < number_of_descriptors(); i++) {
1304 PrintF(" %d: ", i);
1305 Descriptor desc;
1306 Get(i, &desc);
1307 desc.Print();
1308 }
1309 PrintF("\n");
1310}
1311
1312
1313bool DescriptorArray::IsSortedNoDuplicates() {
1314 String* current_key = NULL;
1315 uint32_t current = 0;
1316 for (int i = 0; i < number_of_descriptors(); i++) {
1317 String* key = GetKey(i);
1318 if (key == current_key) {
1319 PrintDescriptors();
1320 return false;
1321 }
1322 current_key = key;
1323 uint32_t hash = GetKey(i)->Hash();
1324 if (hash < current) {
1325 PrintDescriptors();
1326 return false;
1327 }
1328 current = hash;
1329 }
1330 return true;
1331}
1332
1333
Steve Block6ded16b2010-05-10 14:33:55 +01001334void JSFunctionResultCache::JSFunctionResultCacheVerify() {
1335 JSFunction::cast(get(kFactoryIndex))->Verify();
1336
1337 int size = Smi::cast(get(kCacheSizeIndex))->value();
1338 ASSERT(kEntriesIndex <= size);
1339 ASSERT(size <= length());
1340 ASSERT_EQ(0, size % kEntrySize);
1341
1342 int finger = Smi::cast(get(kFingerIndex))->value();
1343 ASSERT(kEntriesIndex <= finger);
1344 ASSERT(finger < size || finger == kEntriesIndex);
1345 ASSERT_EQ(0, finger % kEntrySize);
1346
1347 if (FLAG_enable_slow_asserts) {
1348 for (int i = kEntriesIndex; i < size; i++) {
1349 ASSERT(!get(i)->IsTheHole());
1350 get(i)->Verify();
1351 }
1352 for (int i = size; i < length(); i++) {
1353 ASSERT(get(i)->IsTheHole());
1354 get(i)->Verify();
1355 }
1356 }
1357}
1358
1359
Steve Blocka7e24c12009-10-30 11:49:00 +00001360#endif // DEBUG
1361
1362} } // namespace v8::internal