blob: 53296d9272fae5a1ad093b002da99c0410cdf680 [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"
Kristian Monsen80d68ea2010-09-08 11:05:35 +010033#include "objects-visiting.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000034
35namespace v8 {
36namespace internal {
37
Ben Murdochb0fe1622011-05-05 13:52:32 +010038#ifdef OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +000039
40static const char* TypeToString(InstanceType type);
41
42
Ben Murdochb0fe1622011-05-05 13:52:32 +010043void MaybeObject::Print(FILE* out) {
John Reck59135872010-11-02 12:39:01 -070044 Object* this_as_object;
45 if (ToObject(&this_as_object)) {
46 if (this_as_object->IsSmi()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +010047 Smi::cast(this_as_object)->SmiPrint(out);
John Reck59135872010-11-02 12:39:01 -070048 } else {
Ben Murdochb0fe1622011-05-05 13:52:32 +010049 HeapObject::cast(this_as_object)->HeapObjectPrint(out);
John Reck59135872010-11-02 12:39:01 -070050 }
Steve Blocka7e24c12009-10-30 11:49:00 +000051 } else {
Ben Murdochb0fe1622011-05-05 13:52:32 +010052 Failure::cast(this)->FailurePrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +000053 }
Ben Murdochb0fe1622011-05-05 13:52:32 +010054 Flush(out);
Steve Blocka7e24c12009-10-30 11:49:00 +000055}
56
57
Ben Murdochb0fe1622011-05-05 13:52:32 +010058void MaybeObject::PrintLn(FILE* out) {
59 Print(out);
60 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +000061}
Ben Murdochb0fe1622011-05-05 13:52:32 +010062#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +000063
64
Ben Murdochb0fe1622011-05-05 13:52:32 +010065#ifdef DEBUG
John Reck59135872010-11-02 12:39:01 -070066void MaybeObject::Verify() {
67 Object* this_as_object;
68 if (ToObject(&this_as_object)) {
69 if (this_as_object->IsSmi()) {
70 Smi::cast(this_as_object)->SmiVerify();
71 } else {
72 HeapObject::cast(this_as_object)->HeapObjectVerify();
73 }
Steve Blocka7e24c12009-10-30 11:49:00 +000074 } else {
John Reck59135872010-11-02 12:39:01 -070075 Failure::cast(this)->FailureVerify();
Steve Blocka7e24c12009-10-30 11:49:00 +000076 }
77}
78
79
80void Object::VerifyPointer(Object* p) {
81 if (p->IsHeapObject()) {
82 HeapObject::VerifyHeapPointer(p);
83 } else {
84 ASSERT(p->IsSmi());
85 }
86}
87
88
89void Smi::SmiVerify() {
90 ASSERT(IsSmi());
91}
92
93
94void Failure::FailureVerify() {
95 ASSERT(IsFailure());
96}
Ben Murdochb0fe1622011-05-05 13:52:32 +010097#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +000098
99
Ben Murdochb0fe1622011-05-05 13:52:32 +0100100#ifdef OBJECT_PRINT
101void HeapObject::PrintHeader(FILE* out, const char* id) {
102 PrintF(out, "%p: [%s]\n", reinterpret_cast<void*>(this), id);
Steve Blocka7e24c12009-10-30 11:49:00 +0000103}
104
105
Ben Murdochb0fe1622011-05-05 13:52:32 +0100106void HeapObject::HeapObjectPrint(FILE* out) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000107 InstanceType instance_type = map()->instance_type();
108
109 HandleScope scope;
110 if (instance_type < FIRST_NONSTRING_TYPE) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100111 String::cast(this)->StringPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000112 return;
113 }
114
115 switch (instance_type) {
116 case MAP_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100117 Map::cast(this)->MapPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000118 break;
119 case HEAP_NUMBER_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100120 HeapNumber::cast(this)->HeapNumberPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000121 break;
122 case FIXED_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100123 FixedArray::cast(this)->FixedArrayPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000124 break;
125 case BYTE_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100126 ByteArray::cast(this)->ByteArrayPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000127 break;
128 case PIXEL_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100129 PixelArray::cast(this)->PixelArrayPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000130 break;
Steve Block3ce2e202009-11-05 08:53:23 +0000131 case EXTERNAL_BYTE_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100132 ExternalByteArray::cast(this)->ExternalByteArrayPrint(out);
Steve Block3ce2e202009-11-05 08:53:23 +0000133 break;
134 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100135 ExternalUnsignedByteArray::cast(this)
136 ->ExternalUnsignedByteArrayPrint(out);
Steve Block3ce2e202009-11-05 08:53:23 +0000137 break;
138 case EXTERNAL_SHORT_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100139 ExternalShortArray::cast(this)->ExternalShortArrayPrint(out);
Steve Block3ce2e202009-11-05 08:53:23 +0000140 break;
141 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100142 ExternalUnsignedShortArray::cast(this)
143 ->ExternalUnsignedShortArrayPrint(out);
Steve Block3ce2e202009-11-05 08:53:23 +0000144 break;
145 case EXTERNAL_INT_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100146 ExternalIntArray::cast(this)->ExternalIntArrayPrint(out);
Steve Block3ce2e202009-11-05 08:53:23 +0000147 break;
148 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100149 ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayPrint(out);
Steve Block3ce2e202009-11-05 08:53:23 +0000150 break;
151 case EXTERNAL_FLOAT_ARRAY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100152 ExternalFloatArray::cast(this)->ExternalFloatArrayPrint(out);
Steve Block3ce2e202009-11-05 08:53:23 +0000153 break;
Steve Blocka7e24c12009-10-30 11:49:00 +0000154 case FILLER_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100155 PrintF(out, "filler");
Steve Blocka7e24c12009-10-30 11:49:00 +0000156 break;
157 case JS_OBJECT_TYPE: // fall through
158 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
159 case JS_ARRAY_TYPE:
160 case JS_REGEXP_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100161 JSObject::cast(this)->JSObjectPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000162 break;
163 case ODDBALL_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100164 Oddball::cast(this)->to_string()->Print(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000165 break;
166 case JS_FUNCTION_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100167 JSFunction::cast(this)->JSFunctionPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000168 break;
169 case JS_GLOBAL_PROXY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100170 JSGlobalProxy::cast(this)->JSGlobalProxyPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000171 break;
172 case JS_GLOBAL_OBJECT_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100173 JSGlobalObject::cast(this)->JSGlobalObjectPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000174 break;
175 case JS_BUILTINS_OBJECT_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100176 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000177 break;
178 case JS_VALUE_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100179 PrintF(out, "Value wrapper around:");
180 JSValue::cast(this)->value()->Print(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000181 break;
182 case CODE_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100183 Code::cast(this)->CodePrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000184 break;
185 case PROXY_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100186 Proxy::cast(this)->ProxyPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000187 break;
188 case SHARED_FUNCTION_INFO_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100189 SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000190 break;
191 case JS_GLOBAL_PROPERTY_CELL_TYPE:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100192 JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000193 break;
194#define MAKE_STRUCT_CASE(NAME, Name, name) \
195 case NAME##_TYPE: \
Ben Murdochb0fe1622011-05-05 13:52:32 +0100196 Name::cast(this)->Name##Print(out); \
Steve Blocka7e24c12009-10-30 11:49:00 +0000197 break;
198 STRUCT_LIST(MAKE_STRUCT_CASE)
199#undef MAKE_STRUCT_CASE
200
201 default:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100202 PrintF(out, "UNKNOWN TYPE %d", map()->instance_type());
Steve Blocka7e24c12009-10-30 11:49:00 +0000203 UNREACHABLE();
204 break;
205 }
206}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100207#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000208
209
Ben Murdochb0fe1622011-05-05 13:52:32 +0100210#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000211void HeapObject::HeapObjectVerify() {
212 InstanceType instance_type = map()->instance_type();
213
214 if (instance_type < FIRST_NONSTRING_TYPE) {
215 String::cast(this)->StringVerify();
216 return;
217 }
218
219 switch (instance_type) {
220 case MAP_TYPE:
221 Map::cast(this)->MapVerify();
222 break;
223 case HEAP_NUMBER_TYPE:
224 HeapNumber::cast(this)->HeapNumberVerify();
225 break;
226 case FIXED_ARRAY_TYPE:
227 FixedArray::cast(this)->FixedArrayVerify();
228 break;
229 case BYTE_ARRAY_TYPE:
230 ByteArray::cast(this)->ByteArrayVerify();
231 break;
232 case PIXEL_ARRAY_TYPE:
233 PixelArray::cast(this)->PixelArrayVerify();
234 break;
Steve Block3ce2e202009-11-05 08:53:23 +0000235 case EXTERNAL_BYTE_ARRAY_TYPE:
236 ExternalByteArray::cast(this)->ExternalByteArrayVerify();
237 break;
238 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
239 ExternalUnsignedByteArray::cast(this)->ExternalUnsignedByteArrayVerify();
240 break;
241 case EXTERNAL_SHORT_ARRAY_TYPE:
242 ExternalShortArray::cast(this)->ExternalShortArrayVerify();
243 break;
244 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
245 ExternalUnsignedShortArray::cast(this)->
246 ExternalUnsignedShortArrayVerify();
247 break;
248 case EXTERNAL_INT_ARRAY_TYPE:
249 ExternalIntArray::cast(this)->ExternalIntArrayVerify();
250 break;
251 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
252 ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayVerify();
253 break;
254 case EXTERNAL_FLOAT_ARRAY_TYPE:
255 ExternalFloatArray::cast(this)->ExternalFloatArrayVerify();
256 break;
Steve Blocka7e24c12009-10-30 11:49:00 +0000257 case CODE_TYPE:
258 Code::cast(this)->CodeVerify();
259 break;
260 case ODDBALL_TYPE:
261 Oddball::cast(this)->OddballVerify();
262 break;
263 case JS_OBJECT_TYPE:
264 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
265 JSObject::cast(this)->JSObjectVerify();
266 break;
267 case JS_VALUE_TYPE:
268 JSValue::cast(this)->JSValueVerify();
269 break;
270 case JS_FUNCTION_TYPE:
271 JSFunction::cast(this)->JSFunctionVerify();
272 break;
273 case JS_GLOBAL_PROXY_TYPE:
274 JSGlobalProxy::cast(this)->JSGlobalProxyVerify();
275 break;
276 case JS_GLOBAL_OBJECT_TYPE:
277 JSGlobalObject::cast(this)->JSGlobalObjectVerify();
278 break;
279 case JS_BUILTINS_OBJECT_TYPE:
280 JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify();
281 break;
282 case JS_GLOBAL_PROPERTY_CELL_TYPE:
283 JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellVerify();
284 break;
285 case JS_ARRAY_TYPE:
286 JSArray::cast(this)->JSArrayVerify();
287 break;
288 case JS_REGEXP_TYPE:
289 JSRegExp::cast(this)->JSRegExpVerify();
290 break;
291 case FILLER_TYPE:
292 break;
293 case PROXY_TYPE:
294 Proxy::cast(this)->ProxyVerify();
295 break;
296 case SHARED_FUNCTION_INFO_TYPE:
297 SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify();
298 break;
299
300#define MAKE_STRUCT_CASE(NAME, Name, name) \
301 case NAME##_TYPE: \
302 Name::cast(this)->Name##Verify(); \
303 break;
304 STRUCT_LIST(MAKE_STRUCT_CASE)
305#undef MAKE_STRUCT_CASE
306
307 default:
308 UNREACHABLE();
309 break;
310 }
311}
312
313
314void HeapObject::VerifyHeapPointer(Object* p) {
315 ASSERT(p->IsHeapObject());
316 ASSERT(Heap::Contains(HeapObject::cast(p)));
317}
318
319
320void HeapNumber::HeapNumberVerify() {
321 ASSERT(IsHeapNumber());
322}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100323#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000324
325
Ben Murdochb0fe1622011-05-05 13:52:32 +0100326#ifdef OBJECT_PRINT
327void ByteArray::ByteArrayPrint(FILE* out) {
328 PrintF(out, "byte array, data starts at %p", GetDataStartAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +0000329}
330
331
Ben Murdochb0fe1622011-05-05 13:52:32 +0100332void PixelArray::PixelArrayPrint(FILE* out) {
333 PrintF(out, "pixel array");
Steve Blocka7e24c12009-10-30 11:49:00 +0000334}
335
336
Ben Murdochb0fe1622011-05-05 13:52:32 +0100337void ExternalByteArray::ExternalByteArrayPrint(FILE* out) {
338 PrintF(out, "external byte array");
Steve Block3ce2e202009-11-05 08:53:23 +0000339}
340
341
Ben Murdochb0fe1622011-05-05 13:52:32 +0100342void ExternalUnsignedByteArray::ExternalUnsignedByteArrayPrint(FILE* out) {
343 PrintF(out, "external unsigned byte array");
Steve Block3ce2e202009-11-05 08:53:23 +0000344}
345
346
Ben Murdochb0fe1622011-05-05 13:52:32 +0100347void ExternalShortArray::ExternalShortArrayPrint(FILE* out) {
348 PrintF(out, "external short array");
Steve Block3ce2e202009-11-05 08:53:23 +0000349}
350
351
Ben Murdochb0fe1622011-05-05 13:52:32 +0100352void ExternalUnsignedShortArray::ExternalUnsignedShortArrayPrint(FILE* out) {
353 PrintF(out, "external unsigned short array");
Steve Block3ce2e202009-11-05 08:53:23 +0000354}
355
356
Ben Murdochb0fe1622011-05-05 13:52:32 +0100357void ExternalIntArray::ExternalIntArrayPrint(FILE* out) {
358 PrintF(out, "external int array");
Steve Block3ce2e202009-11-05 08:53:23 +0000359}
360
361
Ben Murdochb0fe1622011-05-05 13:52:32 +0100362void ExternalUnsignedIntArray::ExternalUnsignedIntArrayPrint(FILE* out) {
363 PrintF(out, "external unsigned int array");
Steve Block3ce2e202009-11-05 08:53:23 +0000364}
365
366
Ben Murdochb0fe1622011-05-05 13:52:32 +0100367void ExternalFloatArray::ExternalFloatArrayPrint(FILE* out) {
368 PrintF(out, "external float array");
Steve Block3ce2e202009-11-05 08:53:23 +0000369}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100370#endif // OBJECT_PRINT
Steve Block3ce2e202009-11-05 08:53:23 +0000371
372
Ben Murdochb0fe1622011-05-05 13:52:32 +0100373#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000374void ByteArray::ByteArrayVerify() {
375 ASSERT(IsByteArray());
376}
377
378
379void PixelArray::PixelArrayVerify() {
380 ASSERT(IsPixelArray());
381}
382
383
Steve Block3ce2e202009-11-05 08:53:23 +0000384void ExternalByteArray::ExternalByteArrayVerify() {
385 ASSERT(IsExternalByteArray());
386}
387
388
389void ExternalUnsignedByteArray::ExternalUnsignedByteArrayVerify() {
390 ASSERT(IsExternalUnsignedByteArray());
391}
392
393
394void ExternalShortArray::ExternalShortArrayVerify() {
395 ASSERT(IsExternalShortArray());
396}
397
398
399void ExternalUnsignedShortArray::ExternalUnsignedShortArrayVerify() {
400 ASSERT(IsExternalUnsignedShortArray());
401}
402
403
404void ExternalIntArray::ExternalIntArrayVerify() {
405 ASSERT(IsExternalIntArray());
406}
407
408
409void ExternalUnsignedIntArray::ExternalUnsignedIntArrayVerify() {
410 ASSERT(IsExternalUnsignedIntArray());
411}
412
413
414void ExternalFloatArray::ExternalFloatArrayVerify() {
415 ASSERT(IsExternalFloatArray());
416}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100417#endif // DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +0000418
419
Ben Murdochb0fe1622011-05-05 13:52:32 +0100420#ifdef OBJECT_PRINT
421void JSObject::PrintProperties(FILE* out) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000422 if (HasFastProperties()) {
423 DescriptorArray* descs = map()->instance_descriptors();
424 for (int i = 0; i < descs->number_of_descriptors(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100425 PrintF(out, " ");
426 descs->GetKey(i)->StringPrint(out);
427 PrintF(out, ": ");
Steve Blocka7e24c12009-10-30 11:49:00 +0000428 switch (descs->GetType(i)) {
429 case FIELD: {
430 int index = descs->GetFieldIndex(i);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100431 FastPropertyAt(index)->ShortPrint(out);
432 PrintF(out, " (field at offset %d)\n", index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000433 break;
434 }
435 case CONSTANT_FUNCTION:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100436 descs->GetConstantFunction(i)->ShortPrint(out);
437 PrintF(out, " (constant function)\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000438 break;
439 case CALLBACKS:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100440 descs->GetCallbacksObject(i)->ShortPrint(out);
441 PrintF(out, " (callback)\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000442 break;
443 case MAP_TRANSITION:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100444 PrintF(out, " (map transition)\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000445 break;
446 case CONSTANT_TRANSITION:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100447 PrintF(out, " (constant transition)\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000448 break;
449 case NULL_DESCRIPTOR:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100450 PrintF(out, " (null descriptor)\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000451 break;
452 default:
453 UNREACHABLE();
454 break;
455 }
456 }
457 } else {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100458 property_dictionary()->Print(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000459 }
460}
461
462
Ben Murdochb0fe1622011-05-05 13:52:32 +0100463void JSObject::PrintElements(FILE* out) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000464 switch (GetElementsKind()) {
465 case FAST_ELEMENTS: {
466 // Print in array notation for non-sparse arrays.
467 FixedArray* p = FixedArray::cast(elements());
468 for (int i = 0; i < p->length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100469 PrintF(out, " %d: ", i);
470 p->get(i)->ShortPrint(out);
471 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000472 }
473 break;
474 }
475 case PIXEL_ELEMENTS: {
476 PixelArray* p = PixelArray::cast(elements());
477 for (int i = 0; i < p->length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100478 PrintF(out, " %d: %d\n", i, p->get(i));
Steve Blocka7e24c12009-10-30 11:49:00 +0000479 }
480 break;
481 }
Steve Block3ce2e202009-11-05 08:53:23 +0000482 case EXTERNAL_BYTE_ELEMENTS: {
483 ExternalByteArray* p = ExternalByteArray::cast(elements());
484 for (int i = 0; i < p->length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100485 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
Steve Block3ce2e202009-11-05 08:53:23 +0000486 }
487 break;
488 }
489 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: {
490 ExternalUnsignedByteArray* p =
491 ExternalUnsignedByteArray::cast(elements());
492 for (int i = 0; i < p->length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100493 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
Steve Block3ce2e202009-11-05 08:53:23 +0000494 }
495 break;
496 }
497 case EXTERNAL_SHORT_ELEMENTS: {
498 ExternalShortArray* p = ExternalShortArray::cast(elements());
499 for (int i = 0; i < p->length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100500 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
Steve Block3ce2e202009-11-05 08:53:23 +0000501 }
502 break;
503 }
504 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: {
505 ExternalUnsignedShortArray* p =
506 ExternalUnsignedShortArray::cast(elements());
507 for (int i = 0; i < p->length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100508 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
Steve Block3ce2e202009-11-05 08:53:23 +0000509 }
510 break;
511 }
512 case EXTERNAL_INT_ELEMENTS: {
513 ExternalIntArray* p = ExternalIntArray::cast(elements());
514 for (int i = 0; i < p->length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100515 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
Steve Block3ce2e202009-11-05 08:53:23 +0000516 }
517 break;
518 }
519 case EXTERNAL_UNSIGNED_INT_ELEMENTS: {
520 ExternalUnsignedIntArray* p =
521 ExternalUnsignedIntArray::cast(elements());
522 for (int i = 0; i < p->length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100523 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
Steve Block3ce2e202009-11-05 08:53:23 +0000524 }
525 break;
526 }
527 case EXTERNAL_FLOAT_ELEMENTS: {
528 ExternalFloatArray* p = ExternalFloatArray::cast(elements());
529 for (int i = 0; i < p->length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100530 PrintF(out, " %d: %f\n", i, p->get(i));
Steve Block3ce2e202009-11-05 08:53:23 +0000531 }
532 break;
533 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000534 case DICTIONARY_ELEMENTS:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100535 elements()->Print(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000536 break;
537 default:
538 UNREACHABLE();
539 break;
540 }
541}
542
543
Ben Murdochb0fe1622011-05-05 13:52:32 +0100544void JSObject::JSObjectPrint(FILE* out) {
545 PrintF(out, "%p: [JSObject]\n", reinterpret_cast<void*>(this));
546 PrintF(out, " - map = %p\n", reinterpret_cast<void*>(map()));
547 PrintF(out, " - prototype = %p\n", reinterpret_cast<void*>(GetPrototype()));
548 PrintF(out, " {\n");
549 PrintProperties(out);
550 PrintElements(out);
551 PrintF(out, " }\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000552}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100553#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000554
555
Ben Murdochb0fe1622011-05-05 13:52:32 +0100556#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000557void JSObject::JSObjectVerify() {
558 VerifyHeapPointer(properties());
559 VerifyHeapPointer(elements());
560 if (HasFastProperties()) {
561 CHECK_EQ(map()->unused_property_fields(),
562 (map()->inobject_properties() + properties()->length() -
563 map()->NextFreePropertyIndex()));
564 }
Steve Block8defd9f2010-07-08 12:39:36 +0100565 ASSERT(map()->has_fast_elements() ==
Iain Merrick75681382010-08-19 15:07:18 +0100566 (elements()->map() == Heap::fixed_array_map() ||
567 elements()->map() == Heap::fixed_cow_array_map()));
Steve Block8defd9f2010-07-08 12:39:36 +0100568 ASSERT(map()->has_fast_elements() == HasFastElements());
Steve Blocka7e24c12009-10-30 11:49:00 +0000569}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100570#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000571
572
Ben Murdochb0fe1622011-05-05 13:52:32 +0100573#ifdef OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000574static const char* TypeToString(InstanceType type) {
575 switch (type) {
576 case INVALID_TYPE: return "INVALID";
577 case MAP_TYPE: return "MAP";
578 case HEAP_NUMBER_TYPE: return "HEAP_NUMBER";
Steve Blockd0582a62009-12-15 09:54:21 +0000579 case SYMBOL_TYPE: return "SYMBOL";
580 case ASCII_SYMBOL_TYPE: return "ASCII_SYMBOL";
581 case CONS_SYMBOL_TYPE: return "CONS_SYMBOL";
582 case CONS_ASCII_SYMBOL_TYPE: return "CONS_ASCII_SYMBOL";
583 case EXTERNAL_ASCII_SYMBOL_TYPE:
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100584 case EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE:
Steve Blockd0582a62009-12-15 09:54:21 +0000585 case EXTERNAL_SYMBOL_TYPE: return "EXTERNAL_SYMBOL";
586 case ASCII_STRING_TYPE: return "ASCII_STRING";
587 case STRING_TYPE: return "TWO_BYTE_STRING";
588 case CONS_STRING_TYPE:
589 case CONS_ASCII_STRING_TYPE: return "CONS_STRING";
590 case EXTERNAL_ASCII_STRING_TYPE:
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100591 case EXTERNAL_STRING_WITH_ASCII_DATA_TYPE:
Steve Blockd0582a62009-12-15 09:54:21 +0000592 case EXTERNAL_STRING_TYPE: return "EXTERNAL_STRING";
Steve Blocka7e24c12009-10-30 11:49:00 +0000593 case FIXED_ARRAY_TYPE: return "FIXED_ARRAY";
594 case BYTE_ARRAY_TYPE: return "BYTE_ARRAY";
595 case PIXEL_ARRAY_TYPE: return "PIXEL_ARRAY";
Steve Block3ce2e202009-11-05 08:53:23 +0000596 case EXTERNAL_BYTE_ARRAY_TYPE: return "EXTERNAL_BYTE_ARRAY";
597 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
598 return "EXTERNAL_UNSIGNED_BYTE_ARRAY";
599 case EXTERNAL_SHORT_ARRAY_TYPE: return "EXTERNAL_SHORT_ARRAY";
600 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
601 return "EXTERNAL_UNSIGNED_SHORT_ARRAY";
602 case EXTERNAL_INT_ARRAY_TYPE: return "EXTERNAL_INT_ARRAY";
603 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
604 return "EXTERNAL_UNSIGNED_INT_ARRAY";
605 case EXTERNAL_FLOAT_ARRAY_TYPE: return "EXTERNAL_FLOAT_ARRAY";
Steve Blocka7e24c12009-10-30 11:49:00 +0000606 case FILLER_TYPE: return "FILLER";
607 case JS_OBJECT_TYPE: return "JS_OBJECT";
608 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: return "JS_CONTEXT_EXTENSION_OBJECT";
609 case ODDBALL_TYPE: return "ODDBALL";
610 case JS_GLOBAL_PROPERTY_CELL_TYPE: return "JS_GLOBAL_PROPERTY_CELL";
611 case SHARED_FUNCTION_INFO_TYPE: return "SHARED_FUNCTION_INFO";
612 case JS_FUNCTION_TYPE: return "JS_FUNCTION";
613 case CODE_TYPE: return "CODE";
614 case JS_ARRAY_TYPE: return "JS_ARRAY";
615 case JS_REGEXP_TYPE: return "JS_REGEXP";
616 case JS_VALUE_TYPE: return "JS_VALUE";
617 case JS_GLOBAL_OBJECT_TYPE: return "JS_GLOBAL_OBJECT";
618 case JS_BUILTINS_OBJECT_TYPE: return "JS_BUILTINS_OBJECT";
619 case JS_GLOBAL_PROXY_TYPE: return "JS_GLOBAL_PROXY";
620 case PROXY_TYPE: return "PROXY";
Steve Blocka7e24c12009-10-30 11:49:00 +0000621#define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return #NAME;
622 STRUCT_LIST(MAKE_STRUCT_CASE)
623#undef MAKE_STRUCT_CASE
624 }
625 return "UNKNOWN";
626}
627
628
Ben Murdochb0fe1622011-05-05 13:52:32 +0100629void Map::MapPrint(FILE* out) {
630 HeapObject::PrintHeader(out, "Map");
631 PrintF(out, " - type: %s\n", TypeToString(instance_type()));
632 PrintF(out, " - instance size: %d\n", instance_size());
633 PrintF(out, " - inobject properties: %d\n", inobject_properties());
634 PrintF(out, " - pre-allocated property fields: %d\n",
Steve Blocka7e24c12009-10-30 11:49:00 +0000635 pre_allocated_property_fields());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100636 PrintF(out, " - unused property fields: %d\n", unused_property_fields());
Steve Blocka7e24c12009-10-30 11:49:00 +0000637 if (is_hidden_prototype()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100638 PrintF(out, " - hidden_prototype\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000639 }
640 if (has_named_interceptor()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100641 PrintF(out, " - named_interceptor\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000642 }
643 if (has_indexed_interceptor()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100644 PrintF(out, " - indexed_interceptor\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000645 }
646 if (is_undetectable()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100647 PrintF(out, " - undetectable\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000648 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000649 if (has_instance_call_handler()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100650 PrintF(out, " - instance_call_handler\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000651 }
652 if (is_access_check_needed()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100653 PrintF(out, " - access_check_needed\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000654 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100655 PrintF(out, " - instance descriptors: ");
656 instance_descriptors()->ShortPrint(out);
657 PrintF(out, "\n - prototype: ");
658 prototype()->ShortPrint(out);
659 PrintF(out, "\n - constructor: ");
660 constructor()->ShortPrint(out);
661 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000662}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100663#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000664
665
Ben Murdochb0fe1622011-05-05 13:52:32 +0100666#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000667void Map::MapVerify() {
668 ASSERT(!Heap::InNewSpace(this));
669 ASSERT(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
Steve Block791712a2010-08-27 10:21:07 +0100670 ASSERT(instance_size() == kVariableSizeSentinel ||
671 (kPointerSize <= instance_size() &&
672 instance_size() < Heap::Capacity()));
Steve Blocka7e24c12009-10-30 11:49:00 +0000673 VerifyHeapPointer(prototype());
674 VerifyHeapPointer(instance_descriptors());
675}
676
677
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100678void Map::SharedMapVerify() {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100679 MapVerify();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100680 ASSERT(is_shared());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100681 ASSERT_EQ(Heap::empty_descriptor_array(), instance_descriptors());
682 ASSERT_EQ(Heap::empty_fixed_array(), code_cache());
683 ASSERT_EQ(0, pre_allocated_property_fields());
684 ASSERT_EQ(0, unused_property_fields());
685 ASSERT_EQ(StaticVisitorBase::GetVisitorId(instance_type(), instance_size()),
686 visitor_id());
687}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100688#endif // DEBUG
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100689
690
Ben Murdochb0fe1622011-05-05 13:52:32 +0100691#ifdef OBJECT_PRINT
692void CodeCache::CodeCachePrint(FILE* out) {
693 HeapObject::PrintHeader(out, "CodeCache");
694 PrintF(out, "\n - default_cache: ");
695 default_cache()->ShortPrint(out);
696 PrintF(out, "\n - normal_type_cache: ");
697 normal_type_cache()->ShortPrint(out);
Steve Block6ded16b2010-05-10 14:33:55 +0100698}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100699#endif // OBJECT_PRINT
Steve Block6ded16b2010-05-10 14:33:55 +0100700
701
Ben Murdochb0fe1622011-05-05 13:52:32 +0100702#ifdef DEBUG
Steve Block6ded16b2010-05-10 14:33:55 +0100703void CodeCache::CodeCacheVerify() {
704 VerifyHeapPointer(default_cache());
705 VerifyHeapPointer(normal_type_cache());
706 ASSERT(default_cache()->IsFixedArray());
707 ASSERT(normal_type_cache()->IsUndefined()
708 || normal_type_cache()->IsCodeCacheHashTable());
709}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100710#endif // DEBUG
Steve Block6ded16b2010-05-10 14:33:55 +0100711
712
Ben Murdochb0fe1622011-05-05 13:52:32 +0100713#ifdef OBJECT_PRINT
714void FixedArray::FixedArrayPrint(FILE* out) {
715 HeapObject::PrintHeader(out, "FixedArray");
716 PrintF(out, " - length: %d", length());
Steve Blocka7e24c12009-10-30 11:49:00 +0000717 for (int i = 0; i < length(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100718 PrintF(out, "\n [%d]: ", i);
719 get(i)->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000720 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100721 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000722}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100723#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000724
725
Ben Murdochb0fe1622011-05-05 13:52:32 +0100726#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000727void FixedArray::FixedArrayVerify() {
728 for (int i = 0; i < length(); i++) {
729 Object* e = get(i);
730 if (e->IsHeapObject()) {
731 VerifyHeapPointer(e);
732 } else {
733 e->Verify();
734 }
735 }
736}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100737#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000738
739
Ben Murdochb0fe1622011-05-05 13:52:32 +0100740#ifdef OBJECT_PRINT
741void JSValue::JSValuePrint(FILE* out) {
742 HeapObject::PrintHeader(out, "ValueObject");
743 value()->Print(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000744}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100745#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000746
747
Ben Murdochb0fe1622011-05-05 13:52:32 +0100748#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000749void JSValue::JSValueVerify() {
750 Object* v = value();
751 if (v->IsHeapObject()) {
752 VerifyHeapPointer(v);
753 }
754}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100755#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000756
757
Ben Murdochb0fe1622011-05-05 13:52:32 +0100758#ifdef OBJECT_PRINT
759void String::StringPrint(FILE* out) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000760 if (StringShape(this).IsSymbol()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100761 PrintF(out, "#");
Steve Blocka7e24c12009-10-30 11:49:00 +0000762 } else if (StringShape(this).IsCons()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100763 PrintF(out, "c\"");
Steve Blocka7e24c12009-10-30 11:49:00 +0000764 } else {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100765 PrintF(out, "\"");
Steve Blocka7e24c12009-10-30 11:49:00 +0000766 }
767
Ben Murdochb0fe1622011-05-05 13:52:32 +0100768 const char truncated_epilogue[] = "...<truncated>";
769 int len = length();
770 if (!FLAG_use_verbose_printer) {
771 if (len > 100) {
772 len = 100 - sizeof(truncated_epilogue);
773 }
774 }
775 for (int i = 0; i < len; i++) {
776 PrintF(out, "%c", Get(i));
777 }
778 if (len != length()) {
779 PrintF(out, "%s", truncated_epilogue);
Steve Blocka7e24c12009-10-30 11:49:00 +0000780 }
781
Ben Murdochb0fe1622011-05-05 13:52:32 +0100782 if (!StringShape(this).IsSymbol()) PrintF(out, "\"");
Steve Blocka7e24c12009-10-30 11:49:00 +0000783}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100784#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000785
786
Ben Murdochb0fe1622011-05-05 13:52:32 +0100787#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000788void String::StringVerify() {
789 CHECK(IsString());
790 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
791 if (IsSymbol()) {
792 CHECK(!Heap::InNewSpace(this));
793 }
794}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100795#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000796
797
Ben Murdochb0fe1622011-05-05 13:52:32 +0100798#ifdef OBJECT_PRINT
799void JSFunction::JSFunctionPrint(FILE* out) {
800 HeapObject::PrintHeader(out, "Function");
801 PrintF(out, " - map = 0x%p\n", reinterpret_cast<void*>(map()));
802 PrintF(out, " - initial_map = ");
Steve Blocka7e24c12009-10-30 11:49:00 +0000803 if (has_initial_map()) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100804 initial_map()->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000805 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100806 PrintF(out, "\n - shared_info = ");
807 shared()->ShortPrint(out);
808 PrintF(out, "\n - name = ");
809 shared()->name()->Print(out);
810 PrintF(out, "\n - context = ");
811 unchecked_context()->ShortPrint(out);
812 PrintF(out, "\n - code = ");
813 code()->ShortPrint(out);
814 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000815
Ben Murdochb0fe1622011-05-05 13:52:32 +0100816 PrintProperties(out);
817 PrintElements(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000818
Ben Murdochb0fe1622011-05-05 13:52:32 +0100819 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000820}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100821#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000822
823
Ben Murdochb0fe1622011-05-05 13:52:32 +0100824#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000825void JSFunction::JSFunctionVerify() {
826 CHECK(IsJSFunction());
827 VerifyObjectField(kPrototypeOrInitialMapOffset);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100828 VerifyObjectField(kNextFunctionLinkOffset);
829 CHECK(next_function_link()->IsUndefined() ||
830 next_function_link()->IsJSFunction());
Steve Blocka7e24c12009-10-30 11:49:00 +0000831}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100832#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000833
834
Ben Murdochb0fe1622011-05-05 13:52:32 +0100835#ifdef OBJECT_PRINT
836void SharedFunctionInfo::SharedFunctionInfoPrint(FILE* out) {
837 HeapObject::PrintHeader(out, "SharedFunctionInfo");
838 PrintF(out, " - name: ");
839 name()->ShortPrint(out);
840 PrintF(out, "\n - expected_nof_properties: %d", expected_nof_properties());
841 PrintF(out, "\n - instance class name = ");
842 instance_class_name()->Print(out);
843 PrintF(out, "\n - code = ");
844 code()->ShortPrint(out);
845 PrintF(out, "\n - source code = ");
846 GetSourceCode()->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000847 // Script files are often large, hard to read.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100848 // PrintF(out, "\n - script =");
849 // script()->Print(out);
850 PrintF(out, "\n - function token position = %d", function_token_position());
851 PrintF(out, "\n - start position = %d", start_position());
852 PrintF(out, "\n - end position = %d", end_position());
853 PrintF(out, "\n - is expression = %d", is_expression());
854 PrintF(out, "\n - debug info = ");
855 debug_info()->ShortPrint(out);
856 PrintF(out, "\n - length = %d", length());
857 PrintF(out, "\n - has_only_simple_this_property_assignments = %d",
Steve Blocka7e24c12009-10-30 11:49:00 +0000858 has_only_simple_this_property_assignments());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100859 PrintF(out, "\n - this_property_assignments = ");
860 this_property_assignments()->ShortPrint(out);
861 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000862}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100863#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000864
Ben Murdochb0fe1622011-05-05 13:52:32 +0100865
866#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000867void SharedFunctionInfo::SharedFunctionInfoVerify() {
868 CHECK(IsSharedFunctionInfo());
869 VerifyObjectField(kNameOffset);
870 VerifyObjectField(kCodeOffset);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100871 VerifyObjectField(kScopeInfoOffset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000872 VerifyObjectField(kInstanceClassNameOffset);
Steve Block6ded16b2010-05-10 14:33:55 +0100873 VerifyObjectField(kFunctionDataOffset);
Steve Blocka7e24c12009-10-30 11:49:00 +0000874 VerifyObjectField(kScriptOffset);
875 VerifyObjectField(kDebugInfoOffset);
876}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100877#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000878
879
Ben Murdochb0fe1622011-05-05 13:52:32 +0100880#ifdef OBJECT_PRINT
881void JSGlobalProxy::JSGlobalProxyPrint(FILE* out) {
882 PrintF(out, "global_proxy");
883 JSObjectPrint(out);
884 PrintF(out, "context : ");
885 context()->ShortPrint(out);
886 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000887}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100888#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000889
890
Ben Murdochb0fe1622011-05-05 13:52:32 +0100891#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000892void JSGlobalProxy::JSGlobalProxyVerify() {
893 CHECK(IsJSGlobalProxy());
894 JSObjectVerify();
895 VerifyObjectField(JSGlobalProxy::kContextOffset);
896 // Make sure that this object has no properties, elements.
897 CHECK_EQ(0, properties()->length());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100898 CHECK(HasFastElements());
899 CHECK_EQ(0, FixedArray::cast(elements())->length());
Steve Blocka7e24c12009-10-30 11:49:00 +0000900}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100901#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000902
903
Ben Murdochb0fe1622011-05-05 13:52:32 +0100904#ifdef OBJECT_PRINT
905void JSGlobalObject::JSGlobalObjectPrint(FILE* out) {
906 PrintF(out, "global ");
907 JSObjectPrint(out);
908 PrintF(out, "global context : ");
909 global_context()->ShortPrint(out);
910 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000911}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100912#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000913
914
Ben Murdochb0fe1622011-05-05 13:52:32 +0100915#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000916void JSGlobalObject::JSGlobalObjectVerify() {
917 CHECK(IsJSGlobalObject());
918 JSObjectVerify();
919 for (int i = GlobalObject::kBuiltinsOffset;
920 i < JSGlobalObject::kSize;
921 i += kPointerSize) {
922 VerifyObjectField(i);
923 }
924}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100925#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000926
927
Ben Murdochb0fe1622011-05-05 13:52:32 +0100928#ifdef OBJECT_PRINT
929void JSBuiltinsObject::JSBuiltinsObjectPrint(FILE* out) {
930 PrintF(out, "builtins ");
931 JSObjectPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000932}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100933#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000934
935
Ben Murdochb0fe1622011-05-05 13:52:32 +0100936#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000937void JSBuiltinsObject::JSBuiltinsObjectVerify() {
938 CHECK(IsJSBuiltinsObject());
939 JSObjectVerify();
940 for (int i = GlobalObject::kBuiltinsOffset;
941 i < JSBuiltinsObject::kSize;
942 i += kPointerSize) {
943 VerifyObjectField(i);
944 }
945}
946
947
948void Oddball::OddballVerify() {
949 CHECK(IsOddball());
950 VerifyHeapPointer(to_string());
951 Object* number = to_number();
952 if (number->IsHeapObject()) {
953 ASSERT(number == Heap::nan_value());
954 } else {
955 ASSERT(number->IsSmi());
956 int value = Smi::cast(number)->value();
957 ASSERT(value == 0 || value == 1 || value == -1 ||
958 value == -2 || value == -3);
959 }
960}
961
962
963void JSGlobalPropertyCell::JSGlobalPropertyCellVerify() {
964 CHECK(IsJSGlobalPropertyCell());
965 VerifyObjectField(kValueOffset);
966}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100967#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000968
969
Ben Murdochb0fe1622011-05-05 13:52:32 +0100970#ifdef OBJECT_PRINT
971void JSGlobalPropertyCell::JSGlobalPropertyCellPrint(FILE* out) {
972 HeapObject::PrintHeader(out, "JSGlobalPropertyCell");
Steve Blocka7e24c12009-10-30 11:49:00 +0000973}
974
975
Ben Murdochb0fe1622011-05-05 13:52:32 +0100976void Code::CodePrint(FILE* out) {
977 HeapObject::PrintHeader(out, "Code");
Steve Blocka7e24c12009-10-30 11:49:00 +0000978#ifdef ENABLE_DISASSEMBLER
Ben Murdochb0fe1622011-05-05 13:52:32 +0100979 if (FLAG_use_verbose_printer) {
980 Disassemble(NULL, out);
981 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000982#endif
983}
Ben Murdochb0fe1622011-05-05 13:52:32 +0100984#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000985
986
Ben Murdochb0fe1622011-05-05 13:52:32 +0100987#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000988void Code::CodeVerify() {
989 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100990 kCodeAlignment));
Steve Blocka7e24c12009-10-30 11:49:00 +0000991 Address last_gc_pc = NULL;
992 for (RelocIterator it(this); !it.done(); it.next()) {
993 it.rinfo()->Verify();
994 // Ensure that GC will not iterate twice over the same pointer.
995 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
996 CHECK(it.rinfo()->pc() != last_gc_pc);
997 last_gc_pc = it.rinfo()->pc();
998 }
999 }
1000}
1001
1002
1003void JSArray::JSArrayVerify() {
1004 JSObjectVerify();
1005 ASSERT(length()->IsNumber() || length()->IsUndefined());
1006 ASSERT(elements()->IsUndefined() || elements()->IsFixedArray());
1007}
1008
1009
1010void JSRegExp::JSRegExpVerify() {
1011 JSObjectVerify();
1012 ASSERT(data()->IsUndefined() || data()->IsFixedArray());
1013 switch (TypeTag()) {
1014 case JSRegExp::ATOM: {
1015 FixedArray* arr = FixedArray::cast(data());
1016 ASSERT(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
1017 break;
1018 }
1019 case JSRegExp::IRREGEXP: {
1020 bool is_native = RegExpImpl::UsesNativeRegExp();
1021
1022 FixedArray* arr = FixedArray::cast(data());
1023 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
1024 // TheHole : Not compiled yet.
1025 // JSObject: Compilation error.
1026 // Code/ByteArray: Compiled code.
1027 ASSERT(ascii_data->IsTheHole() || ascii_data->IsJSObject() ||
1028 (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray()));
1029 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
1030 ASSERT(uc16_data->IsTheHole() || ascii_data->IsJSObject() ||
1031 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
1032 ASSERT(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
1033 ASSERT(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
1034 break;
1035 }
1036 default:
1037 ASSERT_EQ(JSRegExp::NOT_COMPILED, TypeTag());
1038 ASSERT(data()->IsUndefined());
1039 break;
1040 }
1041}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001042#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001043
1044
Ben Murdochb0fe1622011-05-05 13:52:32 +01001045#ifdef OBJECT_PRINT
1046void Proxy::ProxyPrint(FILE* out) {
1047 PrintF(out, "proxy to %p", proxy());
Steve Blocka7e24c12009-10-30 11:49:00 +00001048}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001049#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001050
1051
Ben Murdochb0fe1622011-05-05 13:52:32 +01001052#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001053void Proxy::ProxyVerify() {
1054 ASSERT(IsProxy());
1055}
1056
1057
1058void AccessorInfo::AccessorInfoVerify() {
1059 CHECK(IsAccessorInfo());
1060 VerifyPointer(getter());
1061 VerifyPointer(setter());
1062 VerifyPointer(name());
1063 VerifyPointer(data());
1064 VerifyPointer(flag());
1065}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001066#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001067
Ben Murdochb0fe1622011-05-05 13:52:32 +01001068
1069#ifdef OBJECT_PRINT
1070void AccessorInfo::AccessorInfoPrint(FILE* out) {
1071 HeapObject::PrintHeader(out, "AccessorInfo");
1072 PrintF(out, "\n - getter: ");
1073 getter()->ShortPrint(out);
1074 PrintF(out, "\n - setter: ");
1075 setter()->ShortPrint(out);
1076 PrintF(out, "\n - name: ");
1077 name()->ShortPrint(out);
1078 PrintF(out, "\n - data: ");
1079 data()->ShortPrint(out);
1080 PrintF(out, "\n - flag: ");
1081 flag()->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001082}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001083#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001084
Ben Murdochb0fe1622011-05-05 13:52:32 +01001085
1086#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001087void AccessCheckInfo::AccessCheckInfoVerify() {
1088 CHECK(IsAccessCheckInfo());
1089 VerifyPointer(named_callback());
1090 VerifyPointer(indexed_callback());
1091 VerifyPointer(data());
1092}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001093#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001094
Ben Murdochb0fe1622011-05-05 13:52:32 +01001095
1096#ifdef OBJECT_PRINT
1097void AccessCheckInfo::AccessCheckInfoPrint(FILE* out) {
1098 HeapObject::PrintHeader(out, "AccessCheckInfo");
1099 PrintF(out, "\n - named_callback: ");
1100 named_callback()->ShortPrint(out);
1101 PrintF(out, "\n - indexed_callback: ");
1102 indexed_callback()->ShortPrint(out);
1103 PrintF(out, "\n - data: ");
1104 data()->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001105}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001106#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001107
Ben Murdochb0fe1622011-05-05 13:52:32 +01001108
1109#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001110void InterceptorInfo::InterceptorInfoVerify() {
1111 CHECK(IsInterceptorInfo());
1112 VerifyPointer(getter());
1113 VerifyPointer(setter());
1114 VerifyPointer(query());
1115 VerifyPointer(deleter());
1116 VerifyPointer(enumerator());
1117 VerifyPointer(data());
1118}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001119#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001120
Ben Murdochb0fe1622011-05-05 13:52:32 +01001121
1122#ifdef OBJECT_PRINT
1123void InterceptorInfo::InterceptorInfoPrint(FILE* out) {
1124 HeapObject::PrintHeader(out, "InterceptorInfo");
1125 PrintF(out, "\n - getter: ");
1126 getter()->ShortPrint(out);
1127 PrintF(out, "\n - setter: ");
1128 setter()->ShortPrint(out);
1129 PrintF(out, "\n - query: ");
1130 query()->ShortPrint(out);
1131 PrintF(out, "\n - deleter: ");
1132 deleter()->ShortPrint(out);
1133 PrintF(out, "\n - enumerator: ");
1134 enumerator()->ShortPrint(out);
1135 PrintF(out, "\n - data: ");
1136 data()->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001137}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001138#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001139
Ben Murdochb0fe1622011-05-05 13:52:32 +01001140
1141#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001142void CallHandlerInfo::CallHandlerInfoVerify() {
1143 CHECK(IsCallHandlerInfo());
1144 VerifyPointer(callback());
1145 VerifyPointer(data());
1146}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001147#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001148
Ben Murdochb0fe1622011-05-05 13:52:32 +01001149
1150#ifdef OBJECT_PRINT
1151void CallHandlerInfo::CallHandlerInfoPrint(FILE* out) {
1152 HeapObject::PrintHeader(out, "CallHandlerInfo");
1153 PrintF(out, "\n - callback: ");
1154 callback()->ShortPrint(out);
1155 PrintF(out, "\n - data: ");
1156 data()->ShortPrint(out);
1157 PrintF(out, "\n - call_stub_cache: ");
Steve Blocka7e24c12009-10-30 11:49:00 +00001158}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001159#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001160
Ben Murdochb0fe1622011-05-05 13:52:32 +01001161
1162#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001163void TemplateInfo::TemplateInfoVerify() {
1164 VerifyPointer(tag());
1165 VerifyPointer(property_list());
1166}
1167
1168void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
1169 CHECK(IsFunctionTemplateInfo());
1170 TemplateInfoVerify();
1171 VerifyPointer(serial_number());
1172 VerifyPointer(call_code());
1173 VerifyPointer(property_accessors());
1174 VerifyPointer(prototype_template());
1175 VerifyPointer(parent_template());
1176 VerifyPointer(named_property_handler());
1177 VerifyPointer(indexed_property_handler());
1178 VerifyPointer(instance_template());
1179 VerifyPointer(signature());
1180 VerifyPointer(access_check_info());
1181}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001182#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001183
Ben Murdochb0fe1622011-05-05 13:52:32 +01001184
1185#ifdef OBJECT_PRINT
1186void FunctionTemplateInfo::FunctionTemplateInfoPrint(FILE* out) {
1187 HeapObject::PrintHeader(out, "FunctionTemplateInfo");
1188 PrintF(out, "\n - class name: ");
1189 class_name()->ShortPrint(out);
1190 PrintF(out, "\n - tag: ");
1191 tag()->ShortPrint(out);
1192 PrintF(out, "\n - property_list: ");
1193 property_list()->ShortPrint(out);
1194 PrintF(out, "\n - serial_number: ");
1195 serial_number()->ShortPrint(out);
1196 PrintF(out, "\n - call_code: ");
1197 call_code()->ShortPrint(out);
1198 PrintF(out, "\n - property_accessors: ");
1199 property_accessors()->ShortPrint(out);
1200 PrintF(out, "\n - prototype_template: ");
1201 prototype_template()->ShortPrint(out);
1202 PrintF(out, "\n - parent_template: ");
1203 parent_template()->ShortPrint(out);
1204 PrintF(out, "\n - named_property_handler: ");
1205 named_property_handler()->ShortPrint(out);
1206 PrintF(out, "\n - indexed_property_handler: ");
1207 indexed_property_handler()->ShortPrint(out);
1208 PrintF(out, "\n - instance_template: ");
1209 instance_template()->ShortPrint(out);
1210 PrintF(out, "\n - signature: ");
1211 signature()->ShortPrint(out);
1212 PrintF(out, "\n - access_check_info: ");
1213 access_check_info()->ShortPrint(out);
1214 PrintF(out, "\n - hidden_prototype: %s",
1215 hidden_prototype() ? "true" : "false");
1216 PrintF(out, "\n - undetectable: %s", undetectable() ? "true" : "false");
1217 PrintF(out, "\n - need_access_check: %s",
1218 needs_access_check() ? "true" : "false");
Steve Blocka7e24c12009-10-30 11:49:00 +00001219}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001220#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001221
Ben Murdochb0fe1622011-05-05 13:52:32 +01001222
1223#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001224void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
1225 CHECK(IsObjectTemplateInfo());
1226 TemplateInfoVerify();
1227 VerifyPointer(constructor());
1228 VerifyPointer(internal_field_count());
1229}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001230#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001231
Ben Murdochb0fe1622011-05-05 13:52:32 +01001232
1233#ifdef OBJECT_PRINT
1234void ObjectTemplateInfo::ObjectTemplateInfoPrint(FILE* out) {
1235 HeapObject::PrintHeader(out, "ObjectTemplateInfo");
1236 PrintF(out, "\n - constructor: ");
1237 constructor()->ShortPrint(out);
1238 PrintF(out, "\n - internal_field_count: ");
1239 internal_field_count()->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001240}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001241#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001242
Ben Murdochb0fe1622011-05-05 13:52:32 +01001243
1244#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001245void SignatureInfo::SignatureInfoVerify() {
1246 CHECK(IsSignatureInfo());
1247 VerifyPointer(receiver());
1248 VerifyPointer(args());
1249}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001250#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001251
Ben Murdochb0fe1622011-05-05 13:52:32 +01001252
1253#ifdef OBJECT_PRINT
1254void SignatureInfo::SignatureInfoPrint(FILE* out) {
1255 HeapObject::PrintHeader(out, "SignatureInfo");
1256 PrintF(out, "\n - receiver: ");
1257 receiver()->ShortPrint(out);
1258 PrintF(out, "\n - args: ");
1259 args()->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001260}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001261#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001262
Ben Murdochb0fe1622011-05-05 13:52:32 +01001263
1264#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001265void TypeSwitchInfo::TypeSwitchInfoVerify() {
1266 CHECK(IsTypeSwitchInfo());
1267 VerifyPointer(types());
1268}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001269#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001270
Ben Murdochb0fe1622011-05-05 13:52:32 +01001271
1272#ifdef OBJECT_PRINT
1273void TypeSwitchInfo::TypeSwitchInfoPrint(FILE* out) {
1274 HeapObject::PrintHeader(out, "TypeSwitchInfo");
1275 PrintF(out, "\n - types: ");
1276 types()->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001277}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001278#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001279
1280
Ben Murdochb0fe1622011-05-05 13:52:32 +01001281#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001282void Script::ScriptVerify() {
1283 CHECK(IsScript());
1284 VerifyPointer(source());
1285 VerifyPointer(name());
1286 line_offset()->SmiVerify();
1287 column_offset()->SmiVerify();
1288 VerifyPointer(data());
1289 VerifyPointer(wrapper());
1290 type()->SmiVerify();
1291 VerifyPointer(line_ends());
1292 VerifyPointer(id());
1293}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001294#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001295
1296
Ben Murdochb0fe1622011-05-05 13:52:32 +01001297#ifdef OBJECT_PRINT
1298void Script::ScriptPrint(FILE* out) {
1299 HeapObject::PrintHeader(out, "Script");
1300 PrintF(out, "\n - source: ");
1301 source()->ShortPrint(out);
1302 PrintF(out, "\n - name: ");
1303 name()->ShortPrint(out);
1304 PrintF(out, "\n - line_offset: ");
1305 line_offset()->ShortPrint(out);
1306 PrintF(out, "\n - column_offset: ");
1307 column_offset()->ShortPrint(out);
1308 PrintF(out, "\n - type: ");
1309 type()->ShortPrint(out);
1310 PrintF(out, "\n - id: ");
1311 id()->ShortPrint(out);
1312 PrintF(out, "\n - data: ");
1313 data()->ShortPrint(out);
1314 PrintF(out, "\n - context data: ");
1315 context_data()->ShortPrint(out);
1316 PrintF(out, "\n - wrapper: ");
1317 wrapper()->ShortPrint(out);
1318 PrintF(out, "\n - compilation type: ");
1319 compilation_type()->ShortPrint(out);
1320 PrintF(out, "\n - line ends: ");
1321 line_ends()->ShortPrint(out);
1322 PrintF(out, "\n - eval from shared: ");
1323 eval_from_shared()->ShortPrint(out);
1324 PrintF(out, "\n - eval from instructions offset: ");
1325 eval_from_instructions_offset()->ShortPrint(out);
1326 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +00001327}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001328#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001329
1330
1331#ifdef ENABLE_DEBUGGER_SUPPORT
Ben Murdochb0fe1622011-05-05 13:52:32 +01001332#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001333void DebugInfo::DebugInfoVerify() {
1334 CHECK(IsDebugInfo());
1335 VerifyPointer(shared());
1336 VerifyPointer(original_code());
1337 VerifyPointer(code());
1338 VerifyPointer(break_points());
1339}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001340#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001341
1342
Ben Murdochb0fe1622011-05-05 13:52:32 +01001343#ifdef OBJECT_PRINT
1344void DebugInfo::DebugInfoPrint(FILE* out) {
1345 HeapObject::PrintHeader(out, "DebugInfo");
1346 PrintF(out, "\n - shared: ");
1347 shared()->ShortPrint(out);
1348 PrintF(out, "\n - original_code: ");
1349 original_code()->ShortPrint(out);
1350 PrintF(out, "\n - code: ");
1351 code()->ShortPrint(out);
1352 PrintF(out, "\n - break_points: ");
1353 break_points()->Print(out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001354}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001355#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001356
1357
Ben Murdochb0fe1622011-05-05 13:52:32 +01001358#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001359void BreakPointInfo::BreakPointInfoVerify() {
1360 CHECK(IsBreakPointInfo());
1361 code_position()->SmiVerify();
1362 source_position()->SmiVerify();
1363 statement_position()->SmiVerify();
1364 VerifyPointer(break_point_objects());
1365}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001366#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001367
1368
Ben Murdochb0fe1622011-05-05 13:52:32 +01001369#ifdef OBJECT_PRINT
1370void BreakPointInfo::BreakPointInfoPrint(FILE* out) {
1371 HeapObject::PrintHeader(out, "BreakPointInfo");
1372 PrintF(out, "\n - code_position: %d", code_position()->value());
1373 PrintF(out, "\n - source_position: %d", source_position()->value());
1374 PrintF(out, "\n - statement_position: %d", statement_position()->value());
1375 PrintF(out, "\n - break_point_objects: ");
1376 break_point_objects()->ShortPrint(out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001377}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001378#endif // OBJECT_PRINT
1379#endif // ENABLE_DEBUGGER_SUPPORT
Steve Blocka7e24c12009-10-30 11:49:00 +00001380
1381
Ben Murdochb0fe1622011-05-05 13:52:32 +01001382#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001383void JSObject::IncrementSpillStatistics(SpillInformation* info) {
1384 info->number_of_objects_++;
1385 // Named properties
1386 if (HasFastProperties()) {
1387 info->number_of_objects_with_fast_properties_++;
1388 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
1389 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
1390 } else {
1391 StringDictionary* dict = property_dictionary();
1392 info->number_of_slow_used_properties_ += dict->NumberOfElements();
1393 info->number_of_slow_unused_properties_ +=
1394 dict->Capacity() - dict->NumberOfElements();
1395 }
1396 // Indexed properties
1397 switch (GetElementsKind()) {
1398 case FAST_ELEMENTS: {
1399 info->number_of_objects_with_fast_elements_++;
1400 int holes = 0;
1401 FixedArray* e = FixedArray::cast(elements());
1402 int len = e->length();
1403 for (int i = 0; i < len; i++) {
1404 if (e->get(i) == Heap::the_hole_value()) holes++;
1405 }
1406 info->number_of_fast_used_elements_ += len - holes;
1407 info->number_of_fast_unused_elements_ += holes;
1408 break;
1409 }
1410 case PIXEL_ELEMENTS: {
1411 info->number_of_objects_with_fast_elements_++;
1412 PixelArray* e = PixelArray::cast(elements());
1413 info->number_of_fast_used_elements_ += e->length();
1414 break;
1415 }
1416 case DICTIONARY_ELEMENTS: {
1417 NumberDictionary* dict = element_dictionary();
1418 info->number_of_slow_used_elements_ += dict->NumberOfElements();
1419 info->number_of_slow_unused_elements_ +=
1420 dict->Capacity() - dict->NumberOfElements();
1421 break;
1422 }
1423 default:
1424 UNREACHABLE();
1425 break;
1426 }
1427}
1428
1429
1430void JSObject::SpillInformation::Clear() {
1431 number_of_objects_ = 0;
1432 number_of_objects_with_fast_properties_ = 0;
1433 number_of_objects_with_fast_elements_ = 0;
1434 number_of_fast_used_fields_ = 0;
1435 number_of_fast_unused_fields_ = 0;
1436 number_of_slow_used_properties_ = 0;
1437 number_of_slow_unused_properties_ = 0;
1438 number_of_fast_used_elements_ = 0;
1439 number_of_fast_unused_elements_ = 0;
1440 number_of_slow_used_elements_ = 0;
1441 number_of_slow_unused_elements_ = 0;
1442}
1443
1444void JSObject::SpillInformation::Print() {
1445 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
1446
1447 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
1448 number_of_objects_with_fast_properties_,
1449 number_of_fast_used_fields_, number_of_fast_unused_fields_);
1450
1451 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
1452 number_of_objects_ - number_of_objects_with_fast_properties_,
1453 number_of_slow_used_properties_, number_of_slow_unused_properties_);
1454
1455 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
1456 number_of_objects_with_fast_elements_,
1457 number_of_fast_used_elements_, number_of_fast_unused_elements_);
1458
1459 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
1460 number_of_objects_ - number_of_objects_with_fast_elements_,
1461 number_of_slow_used_elements_, number_of_slow_unused_elements_);
1462
1463 PrintF("\n");
1464}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001465#endif // DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001466
1467
Ben Murdochb0fe1622011-05-05 13:52:32 +01001468#ifdef OBJECT_PRINT
1469void DescriptorArray::PrintDescriptors(FILE* out) {
1470 PrintF(out, "Descriptor array %d\n", number_of_descriptors());
Steve Blocka7e24c12009-10-30 11:49:00 +00001471 for (int i = 0; i < number_of_descriptors(); i++) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001472 PrintF(out, " %d: ", i);
Steve Blocka7e24c12009-10-30 11:49:00 +00001473 Descriptor desc;
1474 Get(i, &desc);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001475 desc.Print(out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001476 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001477 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +00001478}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001479#endif // OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00001480
1481
Ben Murdochb0fe1622011-05-05 13:52:32 +01001482#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00001483bool DescriptorArray::IsSortedNoDuplicates() {
1484 String* current_key = NULL;
1485 uint32_t current = 0;
1486 for (int i = 0; i < number_of_descriptors(); i++) {
1487 String* key = GetKey(i);
1488 if (key == current_key) {
1489 PrintDescriptors();
1490 return false;
1491 }
1492 current_key = key;
1493 uint32_t hash = GetKey(i)->Hash();
1494 if (hash < current) {
1495 PrintDescriptors();
1496 return false;
1497 }
1498 current = hash;
1499 }
1500 return true;
1501}
1502
1503
Steve Block6ded16b2010-05-10 14:33:55 +01001504void JSFunctionResultCache::JSFunctionResultCacheVerify() {
1505 JSFunction::cast(get(kFactoryIndex))->Verify();
1506
1507 int size = Smi::cast(get(kCacheSizeIndex))->value();
1508 ASSERT(kEntriesIndex <= size);
1509 ASSERT(size <= length());
1510 ASSERT_EQ(0, size % kEntrySize);
1511
1512 int finger = Smi::cast(get(kFingerIndex))->value();
1513 ASSERT(kEntriesIndex <= finger);
1514 ASSERT(finger < size || finger == kEntriesIndex);
1515 ASSERT_EQ(0, finger % kEntrySize);
1516
1517 if (FLAG_enable_slow_asserts) {
1518 for (int i = kEntriesIndex; i < size; i++) {
1519 ASSERT(!get(i)->IsTheHole());
1520 get(i)->Verify();
1521 }
1522 for (int i = size; i < length(); i++) {
1523 ASSERT(get(i)->IsTheHole());
1524 get(i)->Verify();
1525 }
1526 }
1527}
1528
1529
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001530void NormalizedMapCache::NormalizedMapCacheVerify() {
1531 FixedArray::cast(this)->Verify();
1532 if (FLAG_enable_slow_asserts) {
1533 for (int i = 0; i < length(); i++) {
1534 Object* e = get(i);
1535 if (e->IsMap()) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001536 Map::cast(e)->SharedMapVerify();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001537 } else {
1538 ASSERT(e->IsUndefined());
1539 }
1540 }
1541 }
1542}
1543
1544
Steve Blocka7e24c12009-10-30 11:49:00 +00001545#endif // DEBUG
1546
1547} } // namespace v8::internal