blob: 6f009970dabc8fbc91ff1bc3bfafc6f26db9b187 [file] [log] [blame]
ulan@chromium.org65a89c22012-02-14 11:46:07 +00001// Copyright 2012 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 DEBUG
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +000039
lrn@chromium.org303ada72010-10-27 09:33:13 +000040void MaybeObject::Verify() {
41 Object* this_as_object;
42 if (ToObject(&this_as_object)) {
43 if (this_as_object->IsSmi()) {
44 Smi::cast(this_as_object)->SmiVerify();
45 } else {
46 HeapObject::cast(this_as_object)->HeapObjectVerify();
47 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000048 } else {
lrn@chromium.org303ada72010-10-27 09:33:13 +000049 Failure::cast(this)->FailureVerify();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000050 }
51}
52
53
54void Object::VerifyPointer(Object* p) {
55 if (p->IsHeapObject()) {
56 HeapObject::VerifyHeapPointer(p);
57 } else {
58 ASSERT(p->IsSmi());
59 }
60}
61
62
63void Smi::SmiVerify() {
64 ASSERT(IsSmi());
65}
66
67
68void Failure::FailureVerify() {
69 ASSERT(IsFailure());
70}
71
72
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000073void HeapObject::HeapObjectVerify() {
74 InstanceType instance_type = map()->instance_type();
75
76 if (instance_type < FIRST_NONSTRING_TYPE) {
77 String::cast(this)->StringVerify();
78 return;
79 }
80
81 switch (instance_type) {
82 case MAP_TYPE:
83 Map::cast(this)->MapVerify();
84 break;
85 case HEAP_NUMBER_TYPE:
86 HeapNumber::cast(this)->HeapNumberVerify();
87 break;
88 case FIXED_ARRAY_TYPE:
89 FixedArray::cast(this)->FixedArrayVerify();
90 break;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +000091 case FIXED_DOUBLE_ARRAY_TYPE:
92 FixedDoubleArray::cast(this)->FixedDoubleArrayVerify();
93 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000094 case BYTE_ARRAY_TYPE:
95 ByteArray::cast(this)->ByteArrayVerify();
96 break;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000097 case FREE_SPACE_TYPE:
98 FreeSpace::cast(this)->FreeSpaceVerify();
99 break;
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000100 case EXTERNAL_PIXEL_ARRAY_TYPE:
101 ExternalPixelArray::cast(this)->ExternalPixelArrayVerify();
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000102 break;
ager@chromium.org3811b432009-10-28 14:53:37 +0000103 case EXTERNAL_BYTE_ARRAY_TYPE:
104 ExternalByteArray::cast(this)->ExternalByteArrayVerify();
105 break;
106 case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE:
107 ExternalUnsignedByteArray::cast(this)->ExternalUnsignedByteArrayVerify();
108 break;
109 case EXTERNAL_SHORT_ARRAY_TYPE:
110 ExternalShortArray::cast(this)->ExternalShortArrayVerify();
111 break;
112 case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE:
113 ExternalUnsignedShortArray::cast(this)->
114 ExternalUnsignedShortArrayVerify();
115 break;
116 case EXTERNAL_INT_ARRAY_TYPE:
117 ExternalIntArray::cast(this)->ExternalIntArrayVerify();
118 break;
119 case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE:
120 ExternalUnsignedIntArray::cast(this)->ExternalUnsignedIntArrayVerify();
121 break;
122 case EXTERNAL_FLOAT_ARRAY_TYPE:
123 ExternalFloatArray::cast(this)->ExternalFloatArrayVerify();
124 break;
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000125 case EXTERNAL_DOUBLE_ARRAY_TYPE:
126 ExternalDoubleArray::cast(this)->ExternalDoubleArrayVerify();
127 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000128 case CODE_TYPE:
129 Code::cast(this)->CodeVerify();
130 break;
131 case ODDBALL_TYPE:
132 Oddball::cast(this)->OddballVerify();
133 break;
134 case JS_OBJECT_TYPE:
ager@chromium.org32912102009-01-16 10:38:43 +0000135 case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000136 JSObject::cast(this)->JSObjectVerify();
137 break;
138 case JS_VALUE_TYPE:
139 JSValue::cast(this)->JSValueVerify();
140 break;
141 case JS_FUNCTION_TYPE:
142 JSFunction::cast(this)->JSFunctionVerify();
143 break;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000144 case JS_GLOBAL_PROXY_TYPE:
145 JSGlobalProxy::cast(this)->JSGlobalProxyVerify();
146 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000147 case JS_GLOBAL_OBJECT_TYPE:
148 JSGlobalObject::cast(this)->JSGlobalObjectVerify();
149 break;
150 case JS_BUILTINS_OBJECT_TYPE:
151 JSBuiltinsObject::cast(this)->JSBuiltinsObjectVerify();
152 break;
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000153 case JS_GLOBAL_PROPERTY_CELL_TYPE:
154 JSGlobalPropertyCell::cast(this)->JSGlobalPropertyCellVerify();
155 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000156 case JS_ARRAY_TYPE:
157 JSArray::cast(this)->JSArrayVerify();
158 break;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000159 case JS_SET_TYPE:
160 JSSet::cast(this)->JSSetVerify();
161 break;
162 case JS_MAP_TYPE:
163 JSMap::cast(this)->JSMapVerify();
164 break;
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000165 case JS_WEAK_MAP_TYPE:
166 JSWeakMap::cast(this)->JSWeakMapVerify();
167 break;
ager@chromium.org236ad962008-09-25 09:45:57 +0000168 case JS_REGEXP_TYPE:
169 JSRegExp::cast(this)->JSRegExpVerify();
170 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000171 case FILLER_TYPE:
172 break;
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000173 case JS_PROXY_TYPE:
174 JSProxy::cast(this)->JSProxyVerify();
175 break;
lrn@chromium.org34e60782011-09-15 07:25:40 +0000176 case JS_FUNCTION_PROXY_TYPE:
177 JSFunctionProxy::cast(this)->JSFunctionProxyVerify();
178 break;
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000179 case FOREIGN_TYPE:
180 Foreign::cast(this)->ForeignVerify();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000181 break;
182 case SHARED_FUNCTION_INFO_TYPE:
183 SharedFunctionInfo::cast(this)->SharedFunctionInfoVerify();
184 break;
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000185 case JS_MESSAGE_OBJECT_TYPE:
186 JSMessageObject::cast(this)->JSMessageObjectVerify();
187 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000188
189#define MAKE_STRUCT_CASE(NAME, Name, name) \
190 case NAME##_TYPE: \
191 Name::cast(this)->Name##Verify(); \
192 break;
193 STRUCT_LIST(MAKE_STRUCT_CASE)
194#undef MAKE_STRUCT_CASE
195
196 default:
197 UNREACHABLE();
198 break;
199 }
200}
201
202
203void HeapObject::VerifyHeapPointer(Object* p) {
204 ASSERT(p->IsHeapObject());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000205 ASSERT(HEAP->Contains(HeapObject::cast(p)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000206}
207
208
209void HeapNumber::HeapNumberVerify() {
210 ASSERT(IsHeapNumber());
211}
212
213
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000214void ByteArray::ByteArrayVerify() {
215 ASSERT(IsByteArray());
216}
217
218
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000219void FreeSpace::FreeSpaceVerify() {
220 ASSERT(IsFreeSpace());
221}
222
223
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000224void ExternalPixelArray::ExternalPixelArrayVerify() {
225 ASSERT(IsExternalPixelArray());
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000226}
227
228
ager@chromium.org3811b432009-10-28 14:53:37 +0000229void ExternalByteArray::ExternalByteArrayVerify() {
230 ASSERT(IsExternalByteArray());
231}
232
233
234void ExternalUnsignedByteArray::ExternalUnsignedByteArrayVerify() {
235 ASSERT(IsExternalUnsignedByteArray());
236}
237
238
239void ExternalShortArray::ExternalShortArrayVerify() {
240 ASSERT(IsExternalShortArray());
241}
242
243
244void ExternalUnsignedShortArray::ExternalUnsignedShortArrayVerify() {
245 ASSERT(IsExternalUnsignedShortArray());
246}
247
248
249void ExternalIntArray::ExternalIntArrayVerify() {
250 ASSERT(IsExternalIntArray());
251}
252
253
254void ExternalUnsignedIntArray::ExternalUnsignedIntArrayVerify() {
255 ASSERT(IsExternalUnsignedIntArray());
256}
257
258
259void ExternalFloatArray::ExternalFloatArrayVerify() {
260 ASSERT(IsExternalFloatArray());
261}
262
263
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000264void ExternalDoubleArray::ExternalDoubleArrayVerify() {
265 ASSERT(IsExternalDoubleArray());
266}
267
268
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000269void JSObject::JSObjectVerify() {
270 VerifyHeapPointer(properties());
271 VerifyHeapPointer(elements());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000272
273 if (GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS) {
274 ASSERT(this->elements()->IsFixedArray());
275 ASSERT(this->elements()->length() >= 2);
276 }
277
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000278 if (HasFastProperties()) {
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000279 CHECK_EQ(map()->unused_property_fields(),
280 (map()->inobject_properties() + properties()->length() -
281 map()->NextFreePropertyIndex()));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000282 }
ulan@chromium.org65a89c22012-02-14 11:46:07 +0000283 ASSERT_EQ((map()->has_fast_elements() ||
284 map()->has_fast_smi_only_elements() ||
285 (elements() == GetHeap()->empty_fixed_array())),
ricow@chromium.org55ee8072011-09-08 16:33:10 +0000286 (elements()->map() == GetHeap()->fixed_array_map() ||
287 elements()->map() == GetHeap()->fixed_cow_array_map()));
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000288 ASSERT(map()->has_fast_elements() == HasFastElements());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000289}
290
291
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000292void Map::MapVerify() {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000293 ASSERT(!HEAP->InNewSpace(this));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000294 ASSERT(FIRST_TYPE <= instance_type() && instance_type() <= LAST_TYPE);
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000295 ASSERT(instance_size() == kVariableSizeSentinel ||
296 (kPointerSize <= instance_size() &&
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000297 instance_size() < HEAP->Capacity()));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000298 VerifyHeapPointer(prototype());
299 VerifyHeapPointer(instance_descriptors());
300}
301
302
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000303void Map::SharedMapVerify() {
ricow@chromium.org65fae842010-08-25 15:26:24 +0000304 MapVerify();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000305 ASSERT(is_shared());
danno@chromium.org40cb8782011-05-25 07:58:50 +0000306 ASSERT(instance_descriptors()->IsEmpty());
ricow@chromium.org65fae842010-08-25 15:26:24 +0000307 ASSERT_EQ(0, pre_allocated_property_fields());
308 ASSERT_EQ(0, unused_property_fields());
309 ASSERT_EQ(StaticVisitorBase::GetVisitorId(instance_type(), instance_size()),
310 visitor_id());
311}
312
313
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000314void CodeCache::CodeCacheVerify() {
315 VerifyHeapPointer(default_cache());
316 VerifyHeapPointer(normal_type_cache());
317 ASSERT(default_cache()->IsFixedArray());
318 ASSERT(normal_type_cache()->IsUndefined()
319 || normal_type_cache()->IsCodeCacheHashTable());
320}
321
322
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000323void PolymorphicCodeCache::PolymorphicCodeCacheVerify() {
324 VerifyHeapPointer(cache());
325 ASSERT(cache()->IsUndefined() || cache()->IsPolymorphicCodeCacheHashTable());
326}
327
328
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000329void TypeFeedbackInfo::TypeFeedbackInfoVerify() {
330 VerifyObjectField(kIcTotalCountOffset);
331 VerifyObjectField(kIcWithTypeinfoCountOffset);
332 VerifyHeapPointer(type_feedback_cells());
333}
334
335
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000336void FixedArray::FixedArrayVerify() {
337 for (int i = 0; i < length(); i++) {
338 Object* e = get(i);
339 if (e->IsHeapObject()) {
340 VerifyHeapPointer(e);
341 } else {
342 e->Verify();
343 }
344 }
345}
346
347
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000348void FixedDoubleArray::FixedDoubleArrayVerify() {
349 for (int i = 0; i < length(); i++) {
350 if (!is_the_hole(i)) {
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000351 double value = get_scalar(i);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000352 ASSERT(!isnan(value) ||
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +0000353 (BitCast<uint64_t>(value) ==
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000354 BitCast<uint64_t>(canonical_not_the_hole_nan_as_double())) ||
355 ((BitCast<uint64_t>(value) & Double::kSignMask) != 0));
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000356 }
357 }
358}
359
360
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000361void JSValue::JSValueVerify() {
362 Object* v = value();
363 if (v->IsHeapObject()) {
364 VerifyHeapPointer(v);
365 }
366}
367
368
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000369void JSMessageObject::JSMessageObjectVerify() {
370 CHECK(IsJSMessageObject());
371 CHECK(type()->IsString());
372 CHECK(arguments()->IsJSArray());
373 VerifyObjectField(kStartPositionOffset);
374 VerifyObjectField(kEndPositionOffset);
375 VerifyObjectField(kArgumentsOffset);
376 VerifyObjectField(kScriptOffset);
377 VerifyObjectField(kStackTraceOffset);
378 VerifyObjectField(kStackFramesOffset);
379}
380
381
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000382void String::StringVerify() {
383 CHECK(IsString());
384 CHECK(length() >= 0 && length() <= Smi::kMaxValue);
385 if (IsSymbol()) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000386 CHECK(!HEAP->InNewSpace(this));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000387 }
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000388 if (IsConsString()) {
389 ConsString::cast(this)->ConsStringVerify();
390 } else if (IsSlicedString()) {
391 SlicedString::cast(this)->SlicedStringVerify();
392 }
393}
394
395
396void ConsString::ConsStringVerify() {
397 CHECK(this->first()->IsString());
398 CHECK(this->second() == GetHeap()->empty_string() ||
399 this->second()->IsString());
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000400 CHECK(this->length() >= ConsString::kMinLength);
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000401 if (this->IsFlat()) {
402 // A flat cons can only be created by String::SlowTryFlatten.
403 // Afterwards, the first part may be externalized.
404 CHECK(this->first()->IsSeqString() || this->first()->IsExternalString());
405 }
406}
407
408
409void SlicedString::SlicedStringVerify() {
410 CHECK(!this->parent()->IsConsString());
411 CHECK(!this->parent()->IsSlicedString());
412 CHECK(this->length() >= SlicedString::kMinLength);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000413}
414
415
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000416void JSFunction::JSFunctionVerify() {
417 CHECK(IsJSFunction());
418 VerifyObjectField(kPrototypeOrInitialMapOffset);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000419 VerifyObjectField(kNextFunctionLinkOffset);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000420 CHECK(code()->IsCode());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000421 CHECK(next_function_link()->IsUndefined() ||
422 next_function_link()->IsJSFunction());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000423}
424
425
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000426void SharedFunctionInfo::SharedFunctionInfoVerify() {
427 CHECK(IsSharedFunctionInfo());
428 VerifyObjectField(kNameOffset);
429 VerifyObjectField(kCodeOffset);
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +0000430 VerifyObjectField(kScopeInfoOffset);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000431 VerifyObjectField(kInstanceClassNameOffset);
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000432 VerifyObjectField(kFunctionDataOffset);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000433 VerifyObjectField(kScriptOffset);
434 VerifyObjectField(kDebugInfoOffset);
435}
436
437
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000438void JSGlobalProxy::JSGlobalProxyVerify() {
439 CHECK(IsJSGlobalProxy());
440 JSObjectVerify();
441 VerifyObjectField(JSGlobalProxy::kContextOffset);
442 // Make sure that this object has no properties, elements.
443 CHECK_EQ(0, properties()->length());
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000444 CHECK(HasFastElements());
445 CHECK_EQ(0, FixedArray::cast(elements())->length());
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000446}
447
448
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000449void JSGlobalObject::JSGlobalObjectVerify() {
450 CHECK(IsJSGlobalObject());
451 JSObjectVerify();
452 for (int i = GlobalObject::kBuiltinsOffset;
453 i < JSGlobalObject::kSize;
454 i += kPointerSize) {
455 VerifyObjectField(i);
456 }
457}
458
459
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000460void JSBuiltinsObject::JSBuiltinsObjectVerify() {
461 CHECK(IsJSBuiltinsObject());
462 JSObjectVerify();
463 for (int i = GlobalObject::kBuiltinsOffset;
464 i < JSBuiltinsObject::kSize;
465 i += kPointerSize) {
466 VerifyObjectField(i);
467 }
468}
469
470
471void Oddball::OddballVerify() {
472 CHECK(IsOddball());
473 VerifyHeapPointer(to_string());
474 Object* number = to_number();
475 if (number->IsHeapObject()) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000476 ASSERT(number == HEAP->nan_value());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000477 } else {
478 ASSERT(number->IsSmi());
479 int value = Smi::cast(number)->value();
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000480 ASSERT(value <= 1);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000481 // Hidden oddballs have negative smis.
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000482 ASSERT(value >= kLeastHiddenOddballNumber);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000483 }
484}
485
486
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000487void JSGlobalPropertyCell::JSGlobalPropertyCellVerify() {
488 CHECK(IsJSGlobalPropertyCell());
489 VerifyObjectField(kValueOffset);
490}
491
492
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000493void Code::CodeVerify() {
kasperl@chromium.org061ef742009-02-27 12:16:20 +0000494 CHECK(IsAligned(reinterpret_cast<intptr_t>(instruction_start()),
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000495 kCodeAlignment));
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000496 relocation_info()->Verify();
kasper.lund7276f142008-07-30 08:49:36 +0000497 Address last_gc_pc = NULL;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000498 for (RelocIterator it(this); !it.done(); it.next()) {
499 it.rinfo()->Verify();
kasper.lund7276f142008-07-30 08:49:36 +0000500 // Ensure that GC will not iterate twice over the same pointer.
ager@chromium.org236ad962008-09-25 09:45:57 +0000501 if (RelocInfo::IsGCRelocMode(it.rinfo()->rmode())) {
kasper.lund7276f142008-07-30 08:49:36 +0000502 CHECK(it.rinfo()->pc() != last_gc_pc);
503 last_gc_pc = it.rinfo()->pc();
504 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000505 }
506}
507
508
509void JSArray::JSArrayVerify() {
510 JSObjectVerify();
511 ASSERT(length()->IsNumber() || length()->IsUndefined());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000512 ASSERT(elements()->IsUndefined() ||
513 elements()->IsFixedArray() ||
514 elements()->IsFixedDoubleArray());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000515}
516
517
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000518void JSSet::JSSetVerify() {
519 CHECK(IsJSSet());
520 JSObjectVerify();
521 VerifyHeapPointer(table());
522 ASSERT(table()->IsHashTable() || table()->IsUndefined());
523}
524
525
526void JSMap::JSMapVerify() {
527 CHECK(IsJSMap());
528 JSObjectVerify();
529 VerifyHeapPointer(table());
530 ASSERT(table()->IsHashTable() || table()->IsUndefined());
531}
532
533
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000534void JSWeakMap::JSWeakMapVerify() {
535 CHECK(IsJSWeakMap());
536 JSObjectVerify();
537 VerifyHeapPointer(table());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000538 ASSERT(table()->IsHashTable() || table()->IsUndefined());
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000539}
540
541
ager@chromium.org236ad962008-09-25 09:45:57 +0000542void JSRegExp::JSRegExpVerify() {
543 JSObjectVerify();
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000544 ASSERT(data()->IsUndefined() || data()->IsFixedArray());
545 switch (TypeTag()) {
546 case JSRegExp::ATOM: {
547 FixedArray* arr = FixedArray::cast(data());
548 ASSERT(arr->get(JSRegExp::kAtomPatternIndex)->IsString());
549 break;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000550 }
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000551 case JSRegExp::IRREGEXP: {
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000552 bool is_native = RegExpImpl::UsesNativeRegExp();
ager@chromium.orgbb29dc92009-03-24 13:25:23 +0000553
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000554 FixedArray* arr = FixedArray::cast(data());
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000555 Object* ascii_data = arr->get(JSRegExp::kIrregexpASCIICodeIndex);
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +0000556 // Smi : Not compiled yet (-1) or code prepared for flushing.
ager@chromium.orga1645e22009-09-09 19:27:10 +0000557 // JSObject: Compilation error.
558 // Code/ByteArray: Compiled code.
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +0000559 ASSERT(ascii_data->IsSmi() ||
560 (is_native ? ascii_data->IsCode() : ascii_data->IsByteArray()));
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000561 Object* uc16_data = arr->get(JSRegExp::kIrregexpUC16CodeIndex);
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +0000562 ASSERT(uc16_data->IsSmi() ||
563 (is_native ? uc16_data->IsCode() : uc16_data->IsByteArray()));
564
565 Object* ascii_saved = arr->get(JSRegExp::kIrregexpASCIICodeSavedIndex);
566 ASSERT(ascii_saved->IsSmi() || ascii_saved->IsString() ||
567 ascii_saved->IsCode());
568 Object* uc16_saved = arr->get(JSRegExp::kIrregexpUC16CodeSavedIndex);
569 ASSERT(uc16_saved->IsSmi() || uc16_saved->IsString() ||
570 uc16_saved->IsCode());
571
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000572 ASSERT(arr->get(JSRegExp::kIrregexpCaptureCountIndex)->IsSmi());
573 ASSERT(arr->get(JSRegExp::kIrregexpMaxRegisterCountIndex)->IsSmi());
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000574 break;
575 }
576 default:
577 ASSERT_EQ(JSRegExp::NOT_COMPILED, TypeTag());
578 ASSERT(data()->IsUndefined());
579 break;
kasperl@chromium.org41044eb2008-10-06 08:24:46 +0000580 }
ager@chromium.org236ad962008-09-25 09:45:57 +0000581}
582
583
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000584void JSProxy::JSProxyVerify() {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000585 CHECK(IsJSProxy());
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000586 VerifyPointer(handler());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000587 ASSERT(hash()->IsSmi() || hash()->IsUndefined());
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000588}
589
lrn@chromium.org34e60782011-09-15 07:25:40 +0000590
591void JSFunctionProxy::JSFunctionProxyVerify() {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000592 CHECK(IsJSFunctionProxy());
lrn@chromium.org34e60782011-09-15 07:25:40 +0000593 JSProxyVerify();
594 VerifyPointer(call_trap());
595 VerifyPointer(construct_trap());
596}
597
598
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000599void Foreign::ForeignVerify() {
600 ASSERT(IsForeign());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000601}
602
603
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000604void AccessorInfo::AccessorInfoVerify() {
605 CHECK(IsAccessorInfo());
606 VerifyPointer(getter());
607 VerifyPointer(setter());
608 VerifyPointer(name());
609 VerifyPointer(data());
610 VerifyPointer(flag());
611}
612
whesse@chromium.org023421e2010-12-21 12:19:12 +0000613
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000614void AccessorPair::AccessorPairVerify() {
615 CHECK(IsAccessorPair());
616 VerifyPointer(getter());
617 VerifyPointer(setter());
618}
619
620
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000621void AccessCheckInfo::AccessCheckInfoVerify() {
622 CHECK(IsAccessCheckInfo());
623 VerifyPointer(named_callback());
624 VerifyPointer(indexed_callback());
625 VerifyPointer(data());
626}
627
whesse@chromium.org023421e2010-12-21 12:19:12 +0000628
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000629void InterceptorInfo::InterceptorInfoVerify() {
630 CHECK(IsInterceptorInfo());
631 VerifyPointer(getter());
632 VerifyPointer(setter());
633 VerifyPointer(query());
634 VerifyPointer(deleter());
635 VerifyPointer(enumerator());
636 VerifyPointer(data());
637}
638
whesse@chromium.org023421e2010-12-21 12:19:12 +0000639
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000640void CallHandlerInfo::CallHandlerInfoVerify() {
641 CHECK(IsCallHandlerInfo());
642 VerifyPointer(callback());
643 VerifyPointer(data());
644}
645
whesse@chromium.org023421e2010-12-21 12:19:12 +0000646
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000647void TemplateInfo::TemplateInfoVerify() {
648 VerifyPointer(tag());
649 VerifyPointer(property_list());
650}
651
652void FunctionTemplateInfo::FunctionTemplateInfoVerify() {
653 CHECK(IsFunctionTemplateInfo());
654 TemplateInfoVerify();
655 VerifyPointer(serial_number());
656 VerifyPointer(call_code());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000657 VerifyPointer(property_accessors());
658 VerifyPointer(prototype_template());
659 VerifyPointer(parent_template());
660 VerifyPointer(named_property_handler());
661 VerifyPointer(indexed_property_handler());
662 VerifyPointer(instance_template());
663 VerifyPointer(signature());
664 VerifyPointer(access_check_info());
665}
666
whesse@chromium.org023421e2010-12-21 12:19:12 +0000667
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000668void ObjectTemplateInfo::ObjectTemplateInfoVerify() {
669 CHECK(IsObjectTemplateInfo());
670 TemplateInfoVerify();
671 VerifyPointer(constructor());
kasper.lund212ac232008-07-16 07:07:30 +0000672 VerifyPointer(internal_field_count());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000673}
674
whesse@chromium.org023421e2010-12-21 12:19:12 +0000675
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000676void SignatureInfo::SignatureInfoVerify() {
677 CHECK(IsSignatureInfo());
678 VerifyPointer(receiver());
679 VerifyPointer(args());
680}
681
whesse@chromium.org023421e2010-12-21 12:19:12 +0000682
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000683void TypeSwitchInfo::TypeSwitchInfoVerify() {
684 CHECK(IsTypeSwitchInfo());
685 VerifyPointer(types());
686}
687
whesse@chromium.org023421e2010-12-21 12:19:12 +0000688
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000689void Script::ScriptVerify() {
690 CHECK(IsScript());
691 VerifyPointer(source());
692 VerifyPointer(name());
693 line_offset()->SmiVerify();
694 column_offset()->SmiVerify();
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000695 VerifyPointer(data());
696 VerifyPointer(wrapper());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000697 type()->SmiVerify();
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +0000698 VerifyPointer(line_ends());
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000699 VerifyPointer(id());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000700}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000701
702
kasperl@chromium.orge959c182009-07-27 08:59:04 +0000703#ifdef ENABLE_DEBUGGER_SUPPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000704void DebugInfo::DebugInfoVerify() {
705 CHECK(IsDebugInfo());
706 VerifyPointer(shared());
707 VerifyPointer(original_code());
708 VerifyPointer(code());
709 VerifyPointer(break_points());
710}
711
712
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000713void BreakPointInfo::BreakPointInfoVerify() {
714 CHECK(IsBreakPointInfo());
715 code_position()->SmiVerify();
716 source_position()->SmiVerify();
717 statement_position()->SmiVerify();
718 VerifyPointer(break_point_objects());
719}
whesse@chromium.org023421e2010-12-21 12:19:12 +0000720#endif // ENABLE_DEBUGGER_SUPPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000721
722
723void JSObject::IncrementSpillStatistics(SpillInformation* info) {
724 info->number_of_objects_++;
725 // Named properties
726 if (HasFastProperties()) {
727 info->number_of_objects_with_fast_properties_++;
728 info->number_of_fast_used_fields_ += map()->NextFreePropertyIndex();
729 info->number_of_fast_unused_fields_ += map()->unused_property_fields();
730 } else {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000731 StringDictionary* dict = property_dictionary();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000732 info->number_of_slow_used_properties_ += dict->NumberOfElements();
733 info->number_of_slow_unused_properties_ +=
734 dict->Capacity() - dict->NumberOfElements();
735 }
736 // Indexed properties
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000737 switch (GetElementsKind()) {
738 case FAST_ELEMENTS: {
739 info->number_of_objects_with_fast_elements_++;
740 int holes = 0;
741 FixedArray* e = FixedArray::cast(elements());
742 int len = e->length();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000743 Heap* heap = HEAP;
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000744 for (int i = 0; i < len; i++) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000745 if (e->get(i) == heap->the_hole_value()) holes++;
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000746 }
747 info->number_of_fast_used_elements_ += len - holes;
748 info->number_of_fast_unused_elements_ += holes;
749 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000750 }
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000751 case EXTERNAL_PIXEL_ELEMENTS: {
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000752 info->number_of_objects_with_fast_elements_++;
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000753 ExternalPixelArray* e = ExternalPixelArray::cast(elements());
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000754 info->number_of_fast_used_elements_ += e->length();
755 break;
756 }
757 case DICTIONARY_ELEMENTS: {
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000758 SeededNumberDictionary* dict = element_dictionary();
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000759 info->number_of_slow_used_elements_ += dict->NumberOfElements();
760 info->number_of_slow_unused_elements_ +=
761 dict->Capacity() - dict->NumberOfElements();
762 break;
763 }
764 default:
765 UNREACHABLE();
766 break;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000767 }
768}
769
770
771void JSObject::SpillInformation::Clear() {
772 number_of_objects_ = 0;
773 number_of_objects_with_fast_properties_ = 0;
774 number_of_objects_with_fast_elements_ = 0;
775 number_of_fast_used_fields_ = 0;
776 number_of_fast_unused_fields_ = 0;
777 number_of_slow_used_properties_ = 0;
778 number_of_slow_unused_properties_ = 0;
779 number_of_fast_used_elements_ = 0;
780 number_of_fast_unused_elements_ = 0;
781 number_of_slow_used_elements_ = 0;
782 number_of_slow_unused_elements_ = 0;
783}
784
785void JSObject::SpillInformation::Print() {
786 PrintF("\n JSObject Spill Statistics (#%d):\n", number_of_objects_);
787
788 PrintF(" - fast properties (#%d): %d (used) %d (unused)\n",
789 number_of_objects_with_fast_properties_,
790 number_of_fast_used_fields_, number_of_fast_unused_fields_);
791
792 PrintF(" - slow properties (#%d): %d (used) %d (unused)\n",
793 number_of_objects_ - number_of_objects_with_fast_properties_,
794 number_of_slow_used_properties_, number_of_slow_unused_properties_);
795
796 PrintF(" - fast elements (#%d): %d (used) %d (unused)\n",
797 number_of_objects_with_fast_elements_,
798 number_of_fast_used_elements_, number_of_fast_unused_elements_);
799
800 PrintF(" - slow elements (#%d): %d (used) %d (unused)\n",
801 number_of_objects_ - number_of_objects_with_fast_elements_,
802 number_of_slow_used_elements_, number_of_slow_unused_elements_);
803
804 PrintF("\n");
805}
806
807
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000808bool DescriptorArray::IsSortedNoDuplicates() {
809 String* current_key = NULL;
810 uint32_t current = 0;
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000811 for (int i = 0; i < number_of_descriptors(); i++) {
812 String* key = GetKey(i);
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000813 if (key == current_key) {
814 PrintDescriptors();
815 return false;
816 }
817 current_key = key;
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +0000818 uint32_t hash = GetKey(i)->Hash();
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +0000819 if (hash < current) {
820 PrintDescriptors();
821 return false;
822 }
823 current = hash;
824 }
825 return true;
826}
827
828
ager@chromium.orgac091b72010-05-05 07:34:42 +0000829void JSFunctionResultCache::JSFunctionResultCacheVerify() {
830 JSFunction::cast(get(kFactoryIndex))->Verify();
831
832 int size = Smi::cast(get(kCacheSizeIndex))->value();
833 ASSERT(kEntriesIndex <= size);
834 ASSERT(size <= length());
835 ASSERT_EQ(0, size % kEntrySize);
836
837 int finger = Smi::cast(get(kFingerIndex))->value();
838 ASSERT(kEntriesIndex <= finger);
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000839 ASSERT((finger < size) || (finger == kEntriesIndex && finger == size));
ager@chromium.orgac091b72010-05-05 07:34:42 +0000840 ASSERT_EQ(0, finger % kEntrySize);
841
842 if (FLAG_enable_slow_asserts) {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000843 for (int i = kEntriesIndex; i < size; i++) {
844 ASSERT(!get(i)->IsTheHole());
ager@chromium.orgac091b72010-05-05 07:34:42 +0000845 get(i)->Verify();
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000846 }
847 for (int i = size; i < length(); i++) {
848 ASSERT(get(i)->IsTheHole());
849 get(i)->Verify();
ager@chromium.orgac091b72010-05-05 07:34:42 +0000850 }
851 }
852}
853
854
ricow@chromium.org65fae842010-08-25 15:26:24 +0000855void NormalizedMapCache::NormalizedMapCacheVerify() {
856 FixedArray::cast(this)->Verify();
857 if (FLAG_enable_slow_asserts) {
858 for (int i = 0; i < length(); i++) {
859 Object* e = get(i);
860 if (e->IsMap()) {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000861 Map::cast(e)->SharedMapVerify();
ricow@chromium.org65fae842010-08-25 15:26:24 +0000862 } else {
863 ASSERT(e->IsUndefined());
864 }
865 }
866 }
867}
868
869
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000870#endif // DEBUG
871
872} } // namespace v8::internal