blob: 53296d9272fae5a1ad093b002da99c0410cdf680 [file] [log] [blame]
ager@chromium.org9258b6b2008-09-11 09:11:10 +00001// Copyright 2006-2008 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// 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"
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000032#include "jsregexp.h"
ricow@chromium.org65fae842010-08-25 15:26:24 +000033#include "objects-visiting.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000034
kasperl@chromium.org71affb52009-05-26 05:44:31 +000035namespace v8 {
36namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000037
whesse@chromium.org023421e2010-12-21 12:19:12 +000038#ifdef OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000039
40static const char* TypeToString(InstanceType type);
41
42
whesse@chromium.org023421e2010-12-21 12:19:12 +000043void MaybeObject::Print(FILE* out) {
lrn@chromium.org303ada72010-10-27 09:33:13 +000044 Object* this_as_object;
45 if (ToObject(&this_as_object)) {
46 if (this_as_object->IsSmi()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +000047 Smi::cast(this_as_object)->SmiPrint(out);
lrn@chromium.org303ada72010-10-27 09:33:13 +000048 } else {
whesse@chromium.org023421e2010-12-21 12:19:12 +000049 HeapObject::cast(this_as_object)->HeapObjectPrint(out);
lrn@chromium.org303ada72010-10-27 09:33:13 +000050 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000051 } else {
whesse@chromium.org023421e2010-12-21 12:19:12 +000052 Failure::cast(this)->FailurePrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000053 }
whesse@chromium.org023421e2010-12-21 12:19:12 +000054 Flush(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000055}
56
57
whesse@chromium.org023421e2010-12-21 12:19:12 +000058void MaybeObject::PrintLn(FILE* out) {
59 Print(out);
60 PrintF(out, "\n");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000061}
whesse@chromium.org023421e2010-12-21 12:19:12 +000062#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000063
64
whesse@chromium.org023421e2010-12-21 12:19:12 +000065#ifdef DEBUG
lrn@chromium.org303ada72010-10-27 09:33:13 +000066void 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 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000074 } else {
lrn@chromium.org303ada72010-10-27 09:33:13 +000075 Failure::cast(this)->FailureVerify();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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}
whesse@chromium.org023421e2010-12-21 12:19:12 +000097#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000098
99
whesse@chromium.org023421e2010-12-21 12:19:12 +0000100#ifdef OBJECT_PRINT
101void HeapObject::PrintHeader(FILE* out, const char* id) {
102 PrintF(out, "%p: [%s]\n", reinterpret_cast<void*>(this), id);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000103}
104
105
whesse@chromium.org023421e2010-12-21 12:19:12 +0000106void HeapObject::HeapObjectPrint(FILE* out) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000107 InstanceType instance_type = map()->instance_type();
108
109 HandleScope scope;
110 if (instance_type < FIRST_NONSTRING_TYPE) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000111 String::cast(this)->StringPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000112 return;
113 }
114
115 switch (instance_type) {
116 case MAP_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000117 Map::cast(this)->MapPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000118 break;
119 case HEAP_NUMBER_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000120 HeapNumber::cast(this)->HeapNumberPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000121 break;
122 case FIXED_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000123 FixedArray::cast(this)->FixedArrayPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000124 break;
125 case BYTE_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000126 ByteArray::cast(this)->ByteArrayPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000127 break;
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000128 case PIXEL_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000129 PixelArray::cast(this)->PixelArrayPrint(out);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000130 break;
ager@chromium.org3811b432009-10-28 14:53:37 +0000131 case EXTERNAL_BYTE_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000132 ExternalByteArray::cast(this)->ExternalByteArrayPrint(out);
ager@chromium.org3811b432009-10-28 14:53:37 +0000133 break;
134 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000135 ExternalUnsignedByteArray::cast(this)
136 ->ExternalUnsignedByteArrayPrint(out);
ager@chromium.org3811b432009-10-28 14:53:37 +0000137 break;
138 case EXTERNAL_SHORT_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000139 ExternalShortArray::cast(this)->ExternalShortArrayPrint(out);
ager@chromium.org3811b432009-10-28 14:53:37 +0000140 break;
141 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000142 ExternalUnsignedShortArray::cast(this)
143 ->ExternalUnsignedShortArrayPrint(out);
ager@chromium.org3811b432009-10-28 14:53:37 +0000144 break;
145 case EXTERNAL_INT_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000146 ExternalIntArray::cast(this)->ExternalIntArrayPrint(out);
ager@chromium.org3811b432009-10-28 14:53:37 +0000147 break;
148 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000149 ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayPrint(out);
ager@chromium.org3811b432009-10-28 14:53:37 +0000150 break;
151 case EXTERNAL_FLOAT_ARRAY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000152 ExternalFloatArray::cast(this)->ExternalFloatArrayPrint(out);
ager@chromium.org3811b432009-10-28 14:53:37 +0000153 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000154 case FILLER_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000155 PrintF(out, "filler");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000156 break;
157 case JS_OBJECT_TYPE: // fall through
ager@chromium.org32912102009-01-16 10:38:43 +0000158 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000159 case JS_ARRAY_TYPE:
ager@chromium.org236ad962008-09-25 09:45:57 +0000160 case JS_REGEXP_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000161 JSObject::cast(this)->JSObjectPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000162 break;
163 case ODDBALL_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000164 Oddball::cast(this)->to_string()->Print(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000165 break;
166 case JS_FUNCTION_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000167 JSFunction::cast(this)->JSFunctionPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000168 break;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000169 case JS_GLOBAL_PROXY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000170 JSGlobalProxy::cast(this)->JSGlobalProxyPrint(out);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000171 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000172 case JS_GLOBAL_OBJECT_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000173 JSGlobalObject::cast(this)->JSGlobalObjectPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000174 break;
175 case JS_BUILTINS_OBJECT_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000176 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000177 break;
178 case JS_VALUE_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000179 PrintF(out, "Value wrapper around:");
180 JSValue::cast(this)->value()->Print(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000181 break;
182 case CODE_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000183 Code::cast(this)->CodePrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000184 break;
185 case PROXY_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000186 Proxy::cast(this)->ProxyPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000187 break;
188 case SHARED_FUNCTION_INFO_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000189 SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000190 break;
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000191 case JS_GLOBAL_PROPERTY_CELL_TYPE:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000192 JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellPrint(out);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000193 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000194#define MAKE_STRUCT_CASE(NAME, Name, name) \
195 case NAME##_TYPE: \
whesse@chromium.org023421e2010-12-21 12:19:12 +0000196 Name::cast(this)->Name##Print(out); \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000197 break;
198 STRUCT_LIST(MAKE_STRUCT_CASE)
199#undef MAKE_STRUCT_CASE
200
201 default:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000202 PrintF(out, "UNKNOWN TYPE %d", map()->instance_type());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000203 UNREACHABLE();
204 break;
205 }
206}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000207#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000208
209
whesse@chromium.org023421e2010-12-21 12:19:12 +0000210#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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;
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000232 case PIXEL_ARRAY_TYPE:
233 PixelArray::cast(this)->PixelArrayVerify();
234 break;
ager@chromium.org3811b432009-10-28 14:53:37 +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;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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:
ager@chromium.org32912102009-01-16 10:38:43 +0000264 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000265 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;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000273 case JS_GLOBAL_PROXY_TYPE:
274 JSGlobalProxy::cast(this)->JSGlobalProxyVerify();
275 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000276 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;
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000282 case JS_GLOBAL_PROPERTY_CELL_TYPE:
283 JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellVerify();
284 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000285 case JS_ARRAY_TYPE:
286 JSArray::cast(this)->JSArrayVerify();
287 break;
ager@chromium.org236ad962008-09-25 09:45:57 +0000288 case JS_REGEXP_TYPE:
289 JSRegExp::cast(this)->JSRegExpVerify();
290 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000291 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}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000323#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000324
325
whesse@chromium.org023421e2010-12-21 12:19:12 +0000326#ifdef OBJECT_PRINT
327void ByteArray::ByteArrayPrint(FILE* out) {
328 PrintF(out, "byte array, data starts at %p", GetDataStartAddress());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000329}
330
331
whesse@chromium.org023421e2010-12-21 12:19:12 +0000332void PixelArray::PixelArrayPrint(FILE* out) {
333 PrintF(out, "pixel array");
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000334}
335
336
whesse@chromium.org023421e2010-12-21 12:19:12 +0000337void ExternalByteArray::ExternalByteArrayPrint(FILE* out) {
338 PrintF(out, "external byte array");
ager@chromium.org3811b432009-10-28 14:53:37 +0000339}
340
341
whesse@chromium.org023421e2010-12-21 12:19:12 +0000342void ExternalUnsignedByteArray::ExternalUnsignedByteArrayPrint(FILE* out) {
343 PrintF(out, "external unsigned byte array");
ager@chromium.org3811b432009-10-28 14:53:37 +0000344}
345
346
whesse@chromium.org023421e2010-12-21 12:19:12 +0000347void ExternalShortArray::ExternalShortArrayPrint(FILE* out) {
348 PrintF(out, "external short array");
ager@chromium.org3811b432009-10-28 14:53:37 +0000349}
350
351
whesse@chromium.org023421e2010-12-21 12:19:12 +0000352void ExternalUnsignedShortArray::ExternalUnsignedShortArrayPrint(FILE* out) {
353 PrintF(out, "external unsigned short array");
ager@chromium.org3811b432009-10-28 14:53:37 +0000354}
355
356
whesse@chromium.org023421e2010-12-21 12:19:12 +0000357void ExternalIntArray::ExternalIntArrayPrint(FILE* out) {
358 PrintF(out, "external int array");
ager@chromium.org3811b432009-10-28 14:53:37 +0000359}
360
361
whesse@chromium.org023421e2010-12-21 12:19:12 +0000362void ExternalUnsignedIntArray::ExternalUnsignedIntArrayPrint(FILE* out) {
363 PrintF(out, "external unsigned int array");
ager@chromium.org3811b432009-10-28 14:53:37 +0000364}
365
366
whesse@chromium.org023421e2010-12-21 12:19:12 +0000367void ExternalFloatArray::ExternalFloatArrayPrint(FILE* out) {
368 PrintF(out, "external float array");
ager@chromium.org3811b432009-10-28 14:53:37 +0000369}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000370#endif // OBJECT_PRINT
ager@chromium.org3811b432009-10-28 14:53:37 +0000371
372
whesse@chromium.org023421e2010-12-21 12:19:12 +0000373#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000374void ByteArray::ByteArrayVerify() {
375 ASSERT(IsByteArray());
376}
377
378
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000379void PixelArray::PixelArrayVerify() {
380 ASSERT(IsPixelArray());
381}
382
383
ager@chromium.org3811b432009-10-28 14:53:37 +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}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000417#endif // DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +0000418
419
whesse@chromium.org023421e2010-12-21 12:19:12 +0000420#ifdef OBJECT_PRINT
421void JSObject::PrintProperties(FILE* out) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000422 if (HasFastProperties()) {
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000423 DescriptorArray* descs = map()->instance_descriptors();
424 for (int i = 0; i < descs->number_of_descriptors(); i++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000425 PrintF(out, " ");
426 descs->GetKey(i)->StringPrint(out);
427 PrintF(out, ": ");
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000428 switch (descs->GetType(i)) {
429 case FIELD: {
430 int index = descs->GetFieldIndex(i);
whesse@chromium.org023421e2010-12-21 12:19:12 +0000431 FastPropertyAt(index)->ShortPrint(out);
432 PrintF(out, " (field at offset %d)\n", index);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000433 break;
434 }
435 case CONSTANT_FUNCTION:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000436 descs->GetConstantFunction(i)->ShortPrint(out);
437 PrintF(out, " (constant function)\n");
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000438 break;
439 case CALLBACKS:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000440 descs->GetCallbacksObject(i)->ShortPrint(out);
441 PrintF(out, " (callback)\n");
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000442 break;
443 case MAP_TRANSITION:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000444 PrintF(out, " (map transition)\n");
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000445 break;
446 case CONSTANT_TRANSITION:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000447 PrintF(out, " (constant transition)\n");
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000448 break;
449 case NULL_DESCRIPTOR:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000450 PrintF(out, " (null descriptor)\n");
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000451 break;
452 default:
453 UNREACHABLE();
454 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000455 }
456 }
457 } else {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000458 property_dictionary()->Print(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000459 }
460}
461
462
whesse@chromium.org023421e2010-12-21 12:19:12 +0000463void JSObject::PrintElements(FILE* out) {
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +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++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000469 PrintF(out, " %d: ", i);
470 p->get(i)->ShortPrint(out);
471 PrintF(out, "\n");
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000472 }
473 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000474 }
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000475 case PIXEL_ELEMENTS: {
476 PixelArray* p = PixelArray::cast(elements());
477 for (int i = 0; i < p->length(); i++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000478 PrintF(out, " %d: %d\n", i, p->get(i));
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000479 }
480 break;
481 }
ager@chromium.org3811b432009-10-28 14:53:37 +0000482 case EXTERNAL_BYTE_ELEMENTS: {
483 ExternalByteArray* p = ExternalByteArray::cast(elements());
484 for (int i = 0; i < p->length(); i++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000485 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
ager@chromium.org3811b432009-10-28 14:53:37 +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++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000493 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
ager@chromium.org3811b432009-10-28 14:53:37 +0000494 }
495 break;
496 }
497 case EXTERNAL_SHORT_ELEMENTS: {
498 ExternalShortArray* p = ExternalShortArray::cast(elements());
499 for (int i = 0; i < p->length(); i++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000500 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
ager@chromium.org3811b432009-10-28 14:53:37 +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++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000508 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
ager@chromium.org3811b432009-10-28 14:53:37 +0000509 }
510 break;
511 }
512 case EXTERNAL_INT_ELEMENTS: {
513 ExternalIntArray* p = ExternalIntArray::cast(elements());
514 for (int i = 0; i < p->length(); i++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000515 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
ager@chromium.org3811b432009-10-28 14:53:37 +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++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000523 PrintF(out, " %d: %d\n", i, static_cast<int>(p->get(i)));
ager@chromium.org3811b432009-10-28 14:53:37 +0000524 }
525 break;
526 }
527 case EXTERNAL_FLOAT_ELEMENTS: {
528 ExternalFloatArray* p = ExternalFloatArray::cast(elements());
529 for (int i = 0; i < p->length(); i++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000530 PrintF(out, " %d: %f\n", i, p->get(i));
ager@chromium.org3811b432009-10-28 14:53:37 +0000531 }
532 break;
533 }
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000534 case DICTIONARY_ELEMENTS:
whesse@chromium.org023421e2010-12-21 12:19:12 +0000535 elements()->Print(out);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000536 break;
537 default:
538 UNREACHABLE();
539 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000540 }
541}
542
543
whesse@chromium.org023421e2010-12-21 12:19:12 +0000544void 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");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000552}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000553#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000554
555
whesse@chromium.org023421e2010-12-21 12:19:12 +0000556#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000557void JSObject::JSObjectVerify() {
558 VerifyHeapPointer(properties());
559 VerifyHeapPointer(elements());
560 if (HasFastProperties()) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000561 CHECK_EQ(map()->unused_property_fields(),
562 (map()->inobject_properties() + properties()->length() -
563 map()->NextFreePropertyIndex()));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000564 }
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000565 ASSERT(map()->has_fast_elements() ==
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000566 (elements()->map() == Heap::fixed_array_map() ||
567 elements()->map() == Heap::fixed_cow_array_map()));
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000568 ASSERT(map()->has_fast_elements() == HasFastElements());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000569}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000570#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000571
572
whesse@chromium.org023421e2010-12-21 12:19:12 +0000573#ifdef OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000574static const char* TypeToString(InstanceType type) {
575 switch (type) {
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000576 case INVALID_TYPE: return "INVALID";
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000577 case MAP_TYPE: return "MAP";
578 case HEAP_NUMBER_TYPE: return "HEAP_NUMBER";
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +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:
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000584 case EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE:
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +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:
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000591 case EXTERNAL_STRING_WITH_ASCII_DATA_TYPE:
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000592 case EXTERNAL_STRING_TYPE: return "EXTERNAL_STRING";
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000593 case FIXED_ARRAY_TYPE: return "FIXED_ARRAY";
594 case BYTE_ARRAY_TYPE: return "BYTE_ARRAY";
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000595 case PIXEL_ARRAY_TYPE: return "PIXEL_ARRAY";
ager@chromium.org3811b432009-10-28 14:53:37 +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";
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000606 case FILLER_TYPE: return "FILLER";
607 case JS_OBJECT_TYPE: return "JS_OBJECT";
ager@chromium.org32912102009-01-16 10:38:43 +0000608 case JS_CONTEXT_EXTENSION_OBJECT_TYPE: return "JS_CONTEXT_EXTENSION_OBJECT";
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000609 case ODDBALL_TYPE: return "ODDBALL";
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000610 case JS_GLOBAL_PROPERTY_CELL_TYPE: return "JS_GLOBAL_PROPERTY_CELL";
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000611 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";
ager@chromium.org236ad962008-09-25 09:45:57 +0000615 case JS_REGEXP_TYPE: return "JS_REGEXP";
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000616 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";
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000619 case JS_GLOBAL_PROXY_TYPE: return "JS_GLOBAL_PROXY";
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000620 case PROXY_TYPE: return "PROXY";
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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
whesse@chromium.org023421e2010-12-21 12:19:12 +0000629void 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",
ager@chromium.org18ad94b2009-09-02 08:22:29 +0000635 pre_allocated_property_fields());
whesse@chromium.org023421e2010-12-21 12:19:12 +0000636 PrintF(out, " - unused property fields: %d\n", unused_property_fields());
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000637 if (is_hidden_prototype()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000638 PrintF(out, " - hidden_prototype\n");
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000639 }
640 if (has_named_interceptor()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000641 PrintF(out, " - named_interceptor\n");
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000642 }
643 if (has_indexed_interceptor()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000644 PrintF(out, " - indexed_interceptor\n");
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000645 }
646 if (is_undetectable()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000647 PrintF(out, " - undetectable\n");
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000648 }
649 if (has_instance_call_handler()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000650 PrintF(out, " - instance_call_handler\n");
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000651 }
652 if (is_access_check_needed()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000653 PrintF(out, " - access_check_needed\n");
ager@chromium.orgddb913d2009-01-27 10:01:48 +0000654 }
whesse@chromium.org023421e2010-12-21 12:19:12 +0000655 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");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000662}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000663#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000664
665
whesse@chromium.org023421e2010-12-21 12:19:12 +0000666#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000667void Map::MapVerify() {
668 ASSERT(!Heap::InNewSpace(this));
669 ASSERT(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000670 ASSERT(instance_size() == kVariableSizeSentinel ||
671 (kPointerSize <= instance_size() &&
672 instance_size() < Heap::Capacity()));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000673 VerifyHeapPointer(prototype());
674 VerifyHeapPointer(instance_descriptors());
675}
676
677
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000678void Map::SharedMapVerify() {
ricow@chromium.org65fae842010-08-25 15:26:24 +0000679 MapVerify();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000680 ASSERT(is_shared());
ricow@chromium.org65fae842010-08-25 15:26:24 +0000681 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}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000688#endif // DEBUG
ricow@chromium.org65fae842010-08-25 15:26:24 +0000689
690
whesse@chromium.org023421e2010-12-21 12:19:12 +0000691#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);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000698}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000699#endif // OBJECT_PRINT
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000700
701
whesse@chromium.org023421e2010-12-21 12:19:12 +0000702#ifdef DEBUG
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000703void 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}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000710#endif // DEBUG
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000711
712
whesse@chromium.org023421e2010-12-21 12:19:12 +0000713#ifdef OBJECT_PRINT
714void FixedArray::FixedArrayPrint(FILE* out) {
715 HeapObject::PrintHeader(out, "FixedArray");
716 PrintF(out, " - length: %d", length());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000717 for (int i = 0; i < length(); i++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000718 PrintF(out, "\n [%d]: ", i);
719 get(i)->ShortPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000720 }
whesse@chromium.org023421e2010-12-21 12:19:12 +0000721 PrintF(out, "\n");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000722}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000723#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000724
725
whesse@chromium.org023421e2010-12-21 12:19:12 +0000726#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000737#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000738
739
whesse@chromium.org023421e2010-12-21 12:19:12 +0000740#ifdef OBJECT_PRINT
741void JSValue::JSValuePrint(FILE* out) {
742 HeapObject::PrintHeader(out, "ValueObject");
743 value()->Print(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000744}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000745#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000746
747
whesse@chromium.org023421e2010-12-21 12:19:12 +0000748#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000749void JSValue::JSValueVerify() {
750 Object* v = value();
751 if (v->IsHeapObject()) {
752 VerifyHeapPointer(v);
753 }
754}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000755#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000756
757
whesse@chromium.org023421e2010-12-21 12:19:12 +0000758#ifdef OBJECT_PRINT
759void String::StringPrint(FILE* out) {
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000760 if (StringShape(this).IsSymbol()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000761 PrintF(out, "#");
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000762 } else if (StringShape(this).IsCons()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000763 PrintF(out, "c\"");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000764 } else {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000765 PrintF(out, "\"");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000766 }
767
whesse@chromium.org023421e2010-12-21 12:19:12 +0000768 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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000780 }
781
whesse@chromium.org023421e2010-12-21 12:19:12 +0000782 if (!StringShape(this).IsSymbol()) PrintF(out, "\"");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000783}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000784#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000785
786
whesse@chromium.org023421e2010-12-21 12:19:12 +0000787#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000788void String::StringVerify() {
789 CHECK(IsString());
790 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
791 if (IsSymbol()) {
792 CHECK(!Heap::InNewSpace(this));
793 }
794}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000795#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000796
797
whesse@chromium.org023421e2010-12-21 12:19:12 +0000798#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 = ");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000803 if (has_initial_map()) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000804 initial_map()->ShortPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000805 }
whesse@chromium.org023421e2010-12-21 12:19:12 +0000806 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");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000815
whesse@chromium.org023421e2010-12-21 12:19:12 +0000816 PrintProperties(out);
817 PrintElements(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000818
whesse@chromium.org023421e2010-12-21 12:19:12 +0000819 PrintF(out, "\n");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000820}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000821#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000822
823
whesse@chromium.org023421e2010-12-21 12:19:12 +0000824#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000825void JSFunction::JSFunctionVerify() {
826 CHECK(IsJSFunction());
827 VerifyObjectField(kPrototypeOrInitialMapOffset);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000828 VerifyObjectField(kNextFunctionLinkOffset);
829 CHECK(next_function_link()->IsUndefined() ||
830 next_function_link()->IsJSFunction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000831}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000832#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000833
834
whesse@chromium.org023421e2010-12-21 12:19:12 +0000835#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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000847 // Script files are often large, hard to read.
whesse@chromium.org023421e2010-12-21 12:19:12 +0000848 // 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",
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000858 has_only_simple_this_property_assignments());
whesse@chromium.org023421e2010-12-21 12:19:12 +0000859 PrintF(out, "\n - this_property_assignments = ");
860 this_property_assignments()->ShortPrint(out);
861 PrintF(out, "\n");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000862}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000863#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000864
whesse@chromium.org023421e2010-12-21 12:19:12 +0000865
866#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000867void SharedFunctionInfo::SharedFunctionInfoVerify() {
868 CHECK(IsSharedFunctionInfo());
869 VerifyObjectField(kNameOffset);
870 VerifyObjectField(kCodeOffset);
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000871 VerifyObjectField(kScopeInfoOffset);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000872 VerifyObjectField(kInstanceClassNameOffset);
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000873 VerifyObjectField(kFunctionDataOffset);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000874 VerifyObjectField(kScriptOffset);
875 VerifyObjectField(kDebugInfoOffset);
876}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000877#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000878
879
whesse@chromium.org023421e2010-12-21 12:19:12 +0000880#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");
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000887}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000888#endif // OBJECT_PRINT
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000889
890
whesse@chromium.org023421e2010-12-21 12:19:12 +0000891#ifdef DEBUG
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +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());
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000898 CHECK(HasFastElements());
899 CHECK_EQ(0, FixedArray::cast(elements())->length());
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000900}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000901#endif // DEBUG
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000902
903
whesse@chromium.org023421e2010-12-21 12:19:12 +0000904#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");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000911}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000912#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000913
914
whesse@chromium.org023421e2010-12-21 12:19:12 +0000915#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000925#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000926
927
whesse@chromium.org023421e2010-12-21 12:19:12 +0000928#ifdef OBJECT_PRINT
929void JSBuiltinsObject::JSBuiltinsObjectPrint(FILE* out) {
930 PrintF(out, "builtins ");
931 JSObjectPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000932}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000933#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000934
935
whesse@chromium.org023421e2010-12-21 12:19:12 +0000936#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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();
sgjesse@chromium.orgc81c8942009-08-21 10:54:26 +0000957 ASSERT(value == 0 || value == 1 || value == -1 ||
958 value == -2 || value == -3);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000959 }
960}
961
962
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000963void JSGlobalPropertyCell::JSGlobalPropertyCellVerify() {
964 CHECK(IsJSGlobalPropertyCell());
965 VerifyObjectField(kValueOffset);
966}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000967#endif // DEBUG
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000968
969
whesse@chromium.org023421e2010-12-21 12:19:12 +0000970#ifdef OBJECT_PRINT
971void JSGlobalPropertyCell::JSGlobalPropertyCellPrint(FILE* out) {
972 HeapObject::PrintHeader(out, "JSGlobalPropertyCell");
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000973}
974
975
whesse@chromium.org023421e2010-12-21 12:19:12 +0000976void Code::CodePrint(FILE* out) {
977 HeapObject::PrintHeader(out, "Code");
mads.s.ager31e71382008-08-13 09:32:07 +0000978#ifdef ENABLE_DISASSEMBLER
whesse@chromium.org023421e2010-12-21 12:19:12 +0000979 if (FLAG_use_verbose_printer) {
980 Disassemble(NULL, out);
981 }
mads.s.ager31e71382008-08-13 09:32:07 +0000982#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000983}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000984#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000985
986
whesse@chromium.org023421e2010-12-21 12:19:12 +0000987#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000988void Code::CodeVerify() {
kasperl@chromium.org061ef742009-02-27 12:16:20 +0000989 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000990 kCodeAlignment));
kasper.lund7276f142008-07-30 08:49:36 +0000991 Address last_gc_pc = NULL;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000992 for (RelocIterator it(this); !it.done(); it.next()) {
993 it.rinfo()->Verify();
kasper.lund7276f142008-07-30 08:49:36 +0000994 // Ensure that GC will not iterate twice over the same pointer.
ager@chromium.org236ad962008-09-25 09:45:57 +0000995 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
kasper.lund7276f142008-07-30 08:49:36 +0000996 CHECK(it.rinfo()->pc() != last_gc_pc);
997 last_gc_pc = it.rinfo()->pc();
998 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000999 }
1000}
1001
1002
1003void JSArray::JSArrayVerify() {
1004 JSObjectVerify();
1005 ASSERT(length()->IsNumber() || length()->IsUndefined());
1006 ASSERT(elements()->IsUndefined() || elements()->IsFixedArray());
1007}
1008
1009
ager@chromium.org236ad962008-09-25 09:45:57 +00001010void JSRegExp::JSRegExpVerify() {
1011 JSObjectVerify();
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00001012 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;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00001018 }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00001019 case JSRegExp::IRREGEXP: {
kasperl@chromium.org68ac0092009-07-09 06:00:35 +00001020 bool is_native = RegExpImpl::UsesNativeRegExp();
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00001021
ager@chromium.orga74f0da2008-12-03 16:05:52 +00001022 FixedArray* arr = FixedArray::cast(data());
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001023 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
ager@chromium.orga1645e22009-09-09 19:27:10 +00001024 // 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()));
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001029 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
ager@chromium.orga1645e22009-09-09 19:27:10 +00001030 ASSERT(uc16_data->IsTheHole() || ascii_data->IsJSObject() ||
1031 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00001032 ASSERT(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
1033 ASSERT(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00001034 break;
1035 }
1036 default:
1037 ASSERT_EQ(JSRegExp::NOT_COMPILED, TypeTag());
1038 ASSERT(data()->IsUndefined());
1039 break;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +00001040 }
ager@chromium.org236ad962008-09-25 09:45:57 +00001041}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001042#endif // DEBUG
ager@chromium.org236ad962008-09-25 09:45:57 +00001043
1044
whesse@chromium.org023421e2010-12-21 12:19:12 +00001045#ifdef OBJECT_PRINT
1046void Proxy::ProxyPrint(FILE* out) {
1047 PrintF(out, "proxy to %p", proxy());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001048}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001049#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001050
1051
whesse@chromium.org023421e2010-12-21 12:19:12 +00001052#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001053void Proxy::ProxyVerify() {
1054 ASSERT(IsProxy());
1055}
1056
1057
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001058void AccessorInfo::AccessorInfoVerify() {
1059 CHECK(IsAccessorInfo());
1060 VerifyPointer(getter());
1061 VerifyPointer(setter());
1062 VerifyPointer(name());
1063 VerifyPointer(data());
1064 VerifyPointer(flag());
1065}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001066#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001067
whesse@chromium.org023421e2010-12-21 12:19:12 +00001068
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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001082}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001083#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001084
whesse@chromium.org023421e2010-12-21 12:19:12 +00001085
1086#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001087void AccessCheckInfo::AccessCheckInfoVerify() {
1088 CHECK(IsAccessCheckInfo());
1089 VerifyPointer(named_callback());
1090 VerifyPointer(indexed_callback());
1091 VerifyPointer(data());
1092}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001093#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001094
whesse@chromium.org023421e2010-12-21 12:19:12 +00001095
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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001105}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001106#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001107
whesse@chromium.org023421e2010-12-21 12:19:12 +00001108
1109#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001119#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001120
whesse@chromium.org023421e2010-12-21 12:19:12 +00001121
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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001137}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001138#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001139
whesse@chromium.org023421e2010-12-21 12:19:12 +00001140
1141#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001142void CallHandlerInfo::CallHandlerInfoVerify() {
1143 CHECK(IsCallHandlerInfo());
1144 VerifyPointer(callback());
1145 VerifyPointer(data());
1146}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001147#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001148
whesse@chromium.org023421e2010-12-21 12:19:12 +00001149
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: ");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001158}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001159#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001160
whesse@chromium.org023421e2010-12-21 12:19:12 +00001161
1162#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001173 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}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001182#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001183
whesse@chromium.org023421e2010-12-21 12:19:12 +00001184
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");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001219}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001220#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001221
whesse@chromium.org023421e2010-12-21 12:19:12 +00001222
1223#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001224void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
1225 CHECK(IsObjectTemplateInfo());
1226 TemplateInfoVerify();
1227 VerifyPointer(constructor());
kasper.lund212ac232008-07-16 07:07:30 +00001228 VerifyPointer(internal_field_count());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001229}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001230#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001231
whesse@chromium.org023421e2010-12-21 12:19:12 +00001232
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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001240}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001241#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001242
whesse@chromium.org023421e2010-12-21 12:19:12 +00001243
1244#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001245void SignatureInfo::SignatureInfoVerify() {
1246 CHECK(IsSignatureInfo());
1247 VerifyPointer(receiver());
1248 VerifyPointer(args());
1249}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001250#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001251
whesse@chromium.org023421e2010-12-21 12:19:12 +00001252
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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001260}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001261#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001262
whesse@chromium.org023421e2010-12-21 12:19:12 +00001263
1264#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001265void TypeSwitchInfo::TypeSwitchInfoVerify() {
1266 CHECK(IsTypeSwitchInfo());
1267 VerifyPointer(types());
1268}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001269#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001270
whesse@chromium.org023421e2010-12-21 12:19:12 +00001271
1272#ifdef OBJECT_PRINT
1273void TypeSwitchInfo::TypeSwitchInfoPrint(FILE* out) {
1274 HeapObject::PrintHeader(out, "TypeSwitchInfo");
1275 PrintF(out, "\n - types: ");
1276 types()->ShortPrint(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001277}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001278#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001279
1280
whesse@chromium.org023421e2010-12-21 12:19:12 +00001281#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001282void Script::ScriptVerify() {
1283 CHECK(IsScript());
1284 VerifyPointer(source());
1285 VerifyPointer(name());
1286 line_offset()->SmiVerify();
1287 column_offset()->SmiVerify();
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001288 VerifyPointer(data());
1289 VerifyPointer(wrapper());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001290 type()->SmiVerify();
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +00001291 VerifyPointer(line_ends());
ager@chromium.org65dad4b2009-04-23 08:48:43 +00001292 VerifyPointer(id());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001293}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001294#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001295
1296
whesse@chromium.org023421e2010-12-21 12:19:12 +00001297#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");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001327}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001328#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001329
1330
kasperl@chromium.orge959c182009-07-27 08:59:04 +00001331#ifdef ENABLE_DEBUGGER_SUPPORT
whesse@chromium.org023421e2010-12-21 12:19:12 +00001332#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001333void DebugInfo::DebugInfoVerify() {
1334 CHECK(IsDebugInfo());
1335 VerifyPointer(shared());
1336 VerifyPointer(original_code());
1337 VerifyPointer(code());
1338 VerifyPointer(break_points());
1339}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001340#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001341
1342
whesse@chromium.org023421e2010-12-21 12:19:12 +00001343#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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001354}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001355#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001356
1357
whesse@chromium.org023421e2010-12-21 12:19:12 +00001358#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001359void BreakPointInfo::BreakPointInfoVerify() {
1360 CHECK(IsBreakPointInfo());
1361 code_position()->SmiVerify();
1362 source_position()->SmiVerify();
1363 statement_position()->SmiVerify();
1364 VerifyPointer(break_point_objects());
1365}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001366#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001367
1368
whesse@chromium.org023421e2010-12-21 12:19:12 +00001369#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);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001377}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001378#endif // OBJECT_PRINT
1379#endif // ENABLE_DEBUGGER_SUPPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001380
1381
whesse@chromium.org023421e2010-12-21 12:19:12 +00001382#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +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 {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001391 StringDictionary* dict = property_dictionary();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001392 info->number_of_slow_used_properties_ += dict->NumberOfElements();
1393 info->number_of_slow_unused_properties_ +=
1394 dict->Capacity() - dict->NumberOfElements();
1395 }
1396 // Indexed properties
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001397 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;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001409 }
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001410 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;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001426 }
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}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001465#endif // DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001466
1467
whesse@chromium.org023421e2010-12-21 12:19:12 +00001468#ifdef OBJECT_PRINT
1469void DescriptorArray::PrintDescriptors(FILE* out) {
1470 PrintF(out, "Descriptor array %d\n", number_of_descriptors());
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001471 for (int i = 0; i < number_of_descriptors(); i++) {
whesse@chromium.org023421e2010-12-21 12:19:12 +00001472 PrintF(out, " %d: ", i);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001473 Descriptor desc;
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001474 Get(i, &desc);
whesse@chromium.org023421e2010-12-21 12:19:12 +00001475 desc.Print(out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001476 }
whesse@chromium.org023421e2010-12-21 12:19:12 +00001477 PrintF(out, "\n");
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001478}
whesse@chromium.org023421e2010-12-21 12:19:12 +00001479#endif // OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001480
1481
whesse@chromium.org023421e2010-12-21 12:19:12 +00001482#ifdef DEBUG
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001483bool DescriptorArray::IsSortedNoDuplicates() {
1484 String* current_key = NULL;
1485 uint32_t current = 0;
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001486 for (int i = 0; i < number_of_descriptors(); i++) {
1487 String* key = GetKey(i);
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001488 if (key == current_key) {
1489 PrintDescriptors();
1490 return false;
1491 }
1492 current_key = key;
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001493 uint32_t hash = GetKey(i)->Hash();
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001494 if (hash < current) {
1495 PrintDescriptors();
1496 return false;
1497 }
1498 current = hash;
1499 }
1500 return true;
1501}
1502
1503
ager@chromium.orgac091b72010-05-05 07:34:42 +00001504void 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
ricow@chromium.org65fae842010-08-25 15:26:24 +00001530void 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()) {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001536 Map::cast(e)->SharedMapVerify();
ricow@chromium.org65fae842010-08-25 15:26:24 +00001537 } else {
1538 ASSERT(e->IsUndefined());
1539 }
1540 }
1541 }
1542}
1543
1544
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001545#endif // DEBUG
1546
1547} } // namespace v8::internal