blob: 68bed6c6ec65044a9eca7089741b1e876f3b6eaf [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright 2006-2009 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_OBJECTS_H_
29#define V8_OBJECTS_H_
30
31#include "builtins.h"
32#include "code-stubs.h"
33#include "smart-pointer.h"
34#include "unicode-inl.h"
Steve Block3ce2e202009-11-05 08:53:23 +000035#if V8_TARGET_ARCH_ARM
36#include "arm/constants-arm.h"
37#endif
Steve Blocka7e24c12009-10-30 11:49:00 +000038
39//
40// All object types in the V8 JavaScript are described in this file.
41//
42// Inheritance hierarchy:
43// - Object
44// - Smi (immediate small integer)
45// - Failure (immediate for marking failed operation)
46// - HeapObject (superclass for everything allocated in the heap)
47// - JSObject
48// - JSArray
49// - JSRegExp
50// - JSFunction
51// - GlobalObject
52// - JSGlobalObject
53// - JSBuiltinsObject
54// - JSGlobalProxy
55// - JSValue
56// - Array
57// - ByteArray
58// - PixelArray
Steve Block3ce2e202009-11-05 08:53:23 +000059// - ExternalArray
60// - ExternalByteArray
61// - ExternalUnsignedByteArray
62// - ExternalShortArray
63// - ExternalUnsignedShortArray
64// - ExternalIntArray
65// - ExternalUnsignedIntArray
66// - ExternalFloatArray
Steve Blocka7e24c12009-10-30 11:49:00 +000067// - FixedArray
68// - DescriptorArray
69// - HashTable
70// - Dictionary
71// - SymbolTable
72// - CompilationCacheTable
73// - MapCache
74// - Context
75// - GlobalContext
76// - String
77// - SeqString
78// - SeqAsciiString
79// - SeqTwoByteString
80// - ConsString
81// - SlicedString
82// - ExternalString
83// - ExternalAsciiString
84// - ExternalTwoByteString
85// - HeapNumber
86// - Code
87// - Map
88// - Oddball
89// - Proxy
90// - SharedFunctionInfo
91// - Struct
92// - AccessorInfo
93// - AccessCheckInfo
94// - InterceptorInfo
95// - CallHandlerInfo
96// - TemplateInfo
97// - FunctionTemplateInfo
98// - ObjectTemplateInfo
99// - Script
100// - SignatureInfo
101// - TypeSwitchInfo
102// - DebugInfo
103// - BreakPointInfo
104//
105// Formats of Object*:
106// Smi: [31 bit signed int] 0
107// HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
108// Failure: [30 bit signed int] 11
109
110// Ecma-262 3rd 8.6.1
111enum PropertyAttributes {
112 NONE = v8::None,
113 READ_ONLY = v8::ReadOnly,
114 DONT_ENUM = v8::DontEnum,
115 DONT_DELETE = v8::DontDelete,
116 ABSENT = 16 // Used in runtime to indicate a property is absent.
117 // ABSENT can never be stored in or returned from a descriptor's attributes
118 // bitfield. It is only used as a return value meaning the attributes of
119 // a non-existent property.
120};
121
122namespace v8 {
123namespace internal {
124
125
126// PropertyDetails captures type and attributes for a property.
127// They are used both in property dictionaries and instance descriptors.
128class PropertyDetails BASE_EMBEDDED {
129 public:
130
131 PropertyDetails(PropertyAttributes attributes,
132 PropertyType type,
133 int index = 0) {
134 ASSERT(TypeField::is_valid(type));
135 ASSERT(AttributesField::is_valid(attributes));
136 ASSERT(IndexField::is_valid(index));
137
138 value_ = TypeField::encode(type)
139 | AttributesField::encode(attributes)
140 | IndexField::encode(index);
141
142 ASSERT(type == this->type());
143 ASSERT(attributes == this->attributes());
144 ASSERT(index == this->index());
145 }
146
147 // Conversion for storing details as Object*.
148 inline PropertyDetails(Smi* smi);
149 inline Smi* AsSmi();
150
151 PropertyType type() { return TypeField::decode(value_); }
152
153 bool IsTransition() {
154 PropertyType t = type();
155 ASSERT(t != INTERCEPTOR);
156 return t == MAP_TRANSITION || t == CONSTANT_TRANSITION;
157 }
158
159 bool IsProperty() {
160 return type() < FIRST_PHANTOM_PROPERTY_TYPE;
161 }
162
163 PropertyAttributes attributes() { return AttributesField::decode(value_); }
164
165 int index() { return IndexField::decode(value_); }
166
167 inline PropertyDetails AsDeleted();
168
169 static bool IsValidIndex(int index) { return IndexField::is_valid(index); }
170
171 bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; }
172 bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; }
173 bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; }
174 bool IsDeleted() { return DeletedField::decode(value_) != 0;}
175
176 // Bit fields in value_ (type, shift, size). Must be public so the
177 // constants can be embedded in generated code.
178 class TypeField: public BitField<PropertyType, 0, 3> {};
179 class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
180 class DeletedField: public BitField<uint32_t, 6, 1> {};
181 class IndexField: public BitField<uint32_t, 7, 31-7> {};
182
183 static const int kInitialIndex = 1;
184 private:
185 uint32_t value_;
186};
187
188
189// Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER.
190enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER };
191
192
193// PropertyNormalizationMode is used to specify whether to keep
194// inobject properties when normalizing properties of a JSObject.
195enum PropertyNormalizationMode {
196 CLEAR_INOBJECT_PROPERTIES,
197 KEEP_INOBJECT_PROPERTIES
198};
199
200
201// All Maps have a field instance_type containing a InstanceType.
202// It describes the type of the instances.
203//
204// As an example, a JavaScript object is a heap object and its map
205// instance_type is JS_OBJECT_TYPE.
206//
207// The names of the string instance types are intended to systematically
208// mirror their encoding in the instance_type field of the map. The length
209// (SHORT, MEDIUM, or LONG) is always mentioned. The default encoding is
210// considered TWO_BYTE. It is not mentioned in the name. ASCII encoding is
211// mentioned explicitly in the name. Likewise, the default representation is
212// considered sequential. It is not mentioned in the name. The other
213// representations (eg, CONS, SLICED, EXTERNAL) are explicitly mentioned.
214// Finally, the string is either a SYMBOL_TYPE (if it is a symbol) or a
215// STRING_TYPE (if it is not a symbol).
216//
217// NOTE: The following things are some that depend on the string types having
218// instance_types that are less than those of all other types:
219// HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
220// Object::IsString.
221//
222// NOTE: Everything following JS_VALUE_TYPE is considered a
223// JSObject for GC purposes. The first four entries here have typeof
224// 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
225#define INSTANCE_TYPE_LIST_ALL(V) \
226 V(SHORT_SYMBOL_TYPE) \
227 V(MEDIUM_SYMBOL_TYPE) \
228 V(LONG_SYMBOL_TYPE) \
229 V(SHORT_ASCII_SYMBOL_TYPE) \
230 V(MEDIUM_ASCII_SYMBOL_TYPE) \
231 V(LONG_ASCII_SYMBOL_TYPE) \
232 V(SHORT_CONS_SYMBOL_TYPE) \
233 V(MEDIUM_CONS_SYMBOL_TYPE) \
234 V(LONG_CONS_SYMBOL_TYPE) \
235 V(SHORT_CONS_ASCII_SYMBOL_TYPE) \
236 V(MEDIUM_CONS_ASCII_SYMBOL_TYPE) \
237 V(LONG_CONS_ASCII_SYMBOL_TYPE) \
238 V(SHORT_SLICED_SYMBOL_TYPE) \
239 V(MEDIUM_SLICED_SYMBOL_TYPE) \
240 V(LONG_SLICED_SYMBOL_TYPE) \
241 V(SHORT_SLICED_ASCII_SYMBOL_TYPE) \
242 V(MEDIUM_SLICED_ASCII_SYMBOL_TYPE) \
243 V(LONG_SLICED_ASCII_SYMBOL_TYPE) \
244 V(SHORT_EXTERNAL_SYMBOL_TYPE) \
245 V(MEDIUM_EXTERNAL_SYMBOL_TYPE) \
246 V(LONG_EXTERNAL_SYMBOL_TYPE) \
247 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \
248 V(MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE) \
249 V(LONG_EXTERNAL_ASCII_SYMBOL_TYPE) \
250 V(SHORT_STRING_TYPE) \
251 V(MEDIUM_STRING_TYPE) \
252 V(LONG_STRING_TYPE) \
253 V(SHORT_ASCII_STRING_TYPE) \
254 V(MEDIUM_ASCII_STRING_TYPE) \
255 V(LONG_ASCII_STRING_TYPE) \
256 V(SHORT_CONS_STRING_TYPE) \
257 V(MEDIUM_CONS_STRING_TYPE) \
258 V(LONG_CONS_STRING_TYPE) \
259 V(SHORT_CONS_ASCII_STRING_TYPE) \
260 V(MEDIUM_CONS_ASCII_STRING_TYPE) \
261 V(LONG_CONS_ASCII_STRING_TYPE) \
262 V(SHORT_SLICED_STRING_TYPE) \
263 V(MEDIUM_SLICED_STRING_TYPE) \
264 V(LONG_SLICED_STRING_TYPE) \
265 V(SHORT_SLICED_ASCII_STRING_TYPE) \
266 V(MEDIUM_SLICED_ASCII_STRING_TYPE) \
267 V(LONG_SLICED_ASCII_STRING_TYPE) \
268 V(SHORT_EXTERNAL_STRING_TYPE) \
269 V(MEDIUM_EXTERNAL_STRING_TYPE) \
270 V(LONG_EXTERNAL_STRING_TYPE) \
271 V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \
272 V(MEDIUM_EXTERNAL_ASCII_STRING_TYPE) \
273 V(LONG_EXTERNAL_ASCII_STRING_TYPE) \
274 V(LONG_PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \
275 \
276 V(MAP_TYPE) \
277 V(HEAP_NUMBER_TYPE) \
278 V(FIXED_ARRAY_TYPE) \
279 V(CODE_TYPE) \
280 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \
281 V(ODDBALL_TYPE) \
282 V(PROXY_TYPE) \
283 V(BYTE_ARRAY_TYPE) \
284 V(PIXEL_ARRAY_TYPE) \
Steve Block3ce2e202009-11-05 08:53:23 +0000285 /* Note: the order of these external array */ \
286 /* types is relied upon in */ \
287 /* Object::IsExternalArray(). */ \
288 V(EXTERNAL_BYTE_ARRAY_TYPE) \
289 V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \
290 V(EXTERNAL_SHORT_ARRAY_TYPE) \
291 V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \
292 V(EXTERNAL_INT_ARRAY_TYPE) \
293 V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \
294 V(EXTERNAL_FLOAT_ARRAY_TYPE) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000295 V(FILLER_TYPE) \
296 \
297 V(ACCESSOR_INFO_TYPE) \
298 V(ACCESS_CHECK_INFO_TYPE) \
299 V(INTERCEPTOR_INFO_TYPE) \
300 V(SHARED_FUNCTION_INFO_TYPE) \
301 V(CALL_HANDLER_INFO_TYPE) \
302 V(FUNCTION_TEMPLATE_INFO_TYPE) \
303 V(OBJECT_TEMPLATE_INFO_TYPE) \
304 V(SIGNATURE_INFO_TYPE) \
305 V(TYPE_SWITCH_INFO_TYPE) \
306 V(SCRIPT_TYPE) \
307 \
308 V(JS_VALUE_TYPE) \
309 V(JS_OBJECT_TYPE) \
310 V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \
311 V(JS_GLOBAL_OBJECT_TYPE) \
312 V(JS_BUILTINS_OBJECT_TYPE) \
313 V(JS_GLOBAL_PROXY_TYPE) \
314 V(JS_ARRAY_TYPE) \
315 V(JS_REGEXP_TYPE) \
316 \
317 V(JS_FUNCTION_TYPE) \
318
319#ifdef ENABLE_DEBUGGER_SUPPORT
320#define INSTANCE_TYPE_LIST_DEBUGGER(V) \
321 V(DEBUG_INFO_TYPE) \
322 V(BREAK_POINT_INFO_TYPE)
323#else
324#define INSTANCE_TYPE_LIST_DEBUGGER(V)
325#endif
326
327#define INSTANCE_TYPE_LIST(V) \
328 INSTANCE_TYPE_LIST_ALL(V) \
329 INSTANCE_TYPE_LIST_DEBUGGER(V)
330
331
332// Since string types are not consecutive, this macro is used to
333// iterate over them.
334#define STRING_TYPE_LIST(V) \
335 V(SHORT_SYMBOL_TYPE, \
336 SeqTwoByteString::kAlignedSize, \
337 short_symbol, \
338 ShortSymbol) \
339 V(MEDIUM_SYMBOL_TYPE, \
340 SeqTwoByteString::kAlignedSize, \
341 medium_symbol, \
342 MediumSymbol) \
343 V(LONG_SYMBOL_TYPE, \
344 SeqTwoByteString::kAlignedSize, \
345 long_symbol, \
346 LongSymbol) \
347 V(SHORT_ASCII_SYMBOL_TYPE, \
348 SeqAsciiString::kAlignedSize, \
349 short_ascii_symbol, \
350 ShortAsciiSymbol) \
351 V(MEDIUM_ASCII_SYMBOL_TYPE, \
352 SeqAsciiString::kAlignedSize, \
353 medium_ascii_symbol, \
354 MediumAsciiSymbol) \
355 V(LONG_ASCII_SYMBOL_TYPE, \
356 SeqAsciiString::kAlignedSize, \
357 long_ascii_symbol, \
358 LongAsciiSymbol) \
359 V(SHORT_CONS_SYMBOL_TYPE, \
360 ConsString::kSize, \
361 short_cons_symbol, \
362 ShortConsSymbol) \
363 V(MEDIUM_CONS_SYMBOL_TYPE, \
364 ConsString::kSize, \
365 medium_cons_symbol, \
366 MediumConsSymbol) \
367 V(LONG_CONS_SYMBOL_TYPE, \
368 ConsString::kSize, \
369 long_cons_symbol, \
370 LongConsSymbol) \
371 V(SHORT_CONS_ASCII_SYMBOL_TYPE, \
372 ConsString::kSize, \
373 short_cons_ascii_symbol, \
374 ShortConsAsciiSymbol) \
375 V(MEDIUM_CONS_ASCII_SYMBOL_TYPE, \
376 ConsString::kSize, \
377 medium_cons_ascii_symbol, \
378 MediumConsAsciiSymbol) \
379 V(LONG_CONS_ASCII_SYMBOL_TYPE, \
380 ConsString::kSize, \
381 long_cons_ascii_symbol, \
382 LongConsAsciiSymbol) \
383 V(SHORT_SLICED_SYMBOL_TYPE, \
384 SlicedString::kSize, \
385 short_sliced_symbol, \
386 ShortSlicedSymbol) \
387 V(MEDIUM_SLICED_SYMBOL_TYPE, \
388 SlicedString::kSize, \
389 medium_sliced_symbol, \
390 MediumSlicedSymbol) \
391 V(LONG_SLICED_SYMBOL_TYPE, \
392 SlicedString::kSize, \
393 long_sliced_symbol, \
394 LongSlicedSymbol) \
395 V(SHORT_SLICED_ASCII_SYMBOL_TYPE, \
396 SlicedString::kSize, \
397 short_sliced_ascii_symbol, \
398 ShortSlicedAsciiSymbol) \
399 V(MEDIUM_SLICED_ASCII_SYMBOL_TYPE, \
400 SlicedString::kSize, \
401 medium_sliced_ascii_symbol, \
402 MediumSlicedAsciiSymbol) \
403 V(LONG_SLICED_ASCII_SYMBOL_TYPE, \
404 SlicedString::kSize, \
405 long_sliced_ascii_symbol, \
406 LongSlicedAsciiSymbol) \
407 V(SHORT_EXTERNAL_SYMBOL_TYPE, \
408 ExternalTwoByteString::kSize, \
409 short_external_symbol, \
410 ShortExternalSymbol) \
411 V(MEDIUM_EXTERNAL_SYMBOL_TYPE, \
412 ExternalTwoByteString::kSize, \
413 medium_external_symbol, \
414 MediumExternalSymbol) \
415 V(LONG_EXTERNAL_SYMBOL_TYPE, \
416 ExternalTwoByteString::kSize, \
417 long_external_symbol, \
418 LongExternalSymbol) \
419 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \
420 ExternalAsciiString::kSize, \
421 short_external_ascii_symbol, \
422 ShortExternalAsciiSymbol) \
423 V(MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE, \
424 ExternalAsciiString::kSize, \
425 medium_external_ascii_symbol, \
426 MediumExternalAsciiSymbol) \
427 V(LONG_EXTERNAL_ASCII_SYMBOL_TYPE, \
428 ExternalAsciiString::kSize, \
429 long_external_ascii_symbol, \
430 LongExternalAsciiSymbol) \
431 V(SHORT_STRING_TYPE, \
432 SeqTwoByteString::kAlignedSize, \
433 short_string, \
434 ShortString) \
435 V(MEDIUM_STRING_TYPE, \
436 SeqTwoByteString::kAlignedSize, \
437 medium_string, \
438 MediumString) \
439 V(LONG_STRING_TYPE, \
440 SeqTwoByteString::kAlignedSize, \
441 long_string, \
442 LongString) \
443 V(SHORT_ASCII_STRING_TYPE, \
444 SeqAsciiString::kAlignedSize, \
445 short_ascii_string, \
446 ShortAsciiString) \
447 V(MEDIUM_ASCII_STRING_TYPE, \
448 SeqAsciiString::kAlignedSize, \
449 medium_ascii_string, \
450 MediumAsciiString) \
451 V(LONG_ASCII_STRING_TYPE, \
452 SeqAsciiString::kAlignedSize, \
453 long_ascii_string, \
454 LongAsciiString) \
455 V(SHORT_CONS_STRING_TYPE, \
456 ConsString::kSize, \
457 short_cons_string, \
458 ShortConsString) \
459 V(MEDIUM_CONS_STRING_TYPE, \
460 ConsString::kSize, \
461 medium_cons_string, \
462 MediumConsString) \
463 V(LONG_CONS_STRING_TYPE, \
464 ConsString::kSize, \
465 long_cons_string, \
466 LongConsString) \
467 V(SHORT_CONS_ASCII_STRING_TYPE, \
468 ConsString::kSize, \
469 short_cons_ascii_string, \
470 ShortConsAsciiString) \
471 V(MEDIUM_CONS_ASCII_STRING_TYPE, \
472 ConsString::kSize, \
473 medium_cons_ascii_string, \
474 MediumConsAsciiString) \
475 V(LONG_CONS_ASCII_STRING_TYPE, \
476 ConsString::kSize, \
477 long_cons_ascii_string, \
478 LongConsAsciiString) \
479 V(SHORT_SLICED_STRING_TYPE, \
480 SlicedString::kSize, \
481 short_sliced_string, \
482 ShortSlicedString) \
483 V(MEDIUM_SLICED_STRING_TYPE, \
484 SlicedString::kSize, \
485 medium_sliced_string, \
486 MediumSlicedString) \
487 V(LONG_SLICED_STRING_TYPE, \
488 SlicedString::kSize, \
489 long_sliced_string, \
490 LongSlicedString) \
491 V(SHORT_SLICED_ASCII_STRING_TYPE, \
492 SlicedString::kSize, \
493 short_sliced_ascii_string, \
494 ShortSlicedAsciiString) \
495 V(MEDIUM_SLICED_ASCII_STRING_TYPE, \
496 SlicedString::kSize, \
497 medium_sliced_ascii_string, \
498 MediumSlicedAsciiString) \
499 V(LONG_SLICED_ASCII_STRING_TYPE, \
500 SlicedString::kSize, \
501 long_sliced_ascii_string, \
502 LongSlicedAsciiString) \
503 V(SHORT_EXTERNAL_STRING_TYPE, \
504 ExternalTwoByteString::kSize, \
505 short_external_string, \
506 ShortExternalString) \
507 V(MEDIUM_EXTERNAL_STRING_TYPE, \
508 ExternalTwoByteString::kSize, \
509 medium_external_string, \
510 MediumExternalString) \
511 V(LONG_EXTERNAL_STRING_TYPE, \
512 ExternalTwoByteString::kSize, \
513 long_external_string, \
514 LongExternalString) \
515 V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \
516 ExternalAsciiString::kSize, \
517 short_external_ascii_string, \
518 ShortExternalAsciiString) \
519 V(MEDIUM_EXTERNAL_ASCII_STRING_TYPE, \
520 ExternalAsciiString::kSize, \
521 medium_external_ascii_string, \
522 MediumExternalAsciiString) \
523 V(LONG_EXTERNAL_ASCII_STRING_TYPE, \
524 ExternalAsciiString::kSize, \
525 long_external_ascii_string, \
526 LongExternalAsciiString)
527
528// A struct is a simple object a set of object-valued fields. Including an
529// object type in this causes the compiler to generate most of the boilerplate
530// code for the class including allocation and garbage collection routines,
531// casts and predicates. All you need to define is the class, methods and
532// object verification routines. Easy, no?
533//
534// Note that for subtle reasons related to the ordering or numerical values of
535// type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
536// manually.
537#define STRUCT_LIST_ALL(V) \
538 V(ACCESSOR_INFO, AccessorInfo, accessor_info) \
539 V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \
540 V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \
541 V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \
542 V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \
543 V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \
544 V(SIGNATURE_INFO, SignatureInfo, signature_info) \
545 V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \
546 V(SCRIPT, Script, script)
547
548#ifdef ENABLE_DEBUGGER_SUPPORT
549#define STRUCT_LIST_DEBUGGER(V) \
550 V(DEBUG_INFO, DebugInfo, debug_info) \
551 V(BREAK_POINT_INFO, BreakPointInfo, break_point_info)
552#else
553#define STRUCT_LIST_DEBUGGER(V)
554#endif
555
556#define STRUCT_LIST(V) \
557 STRUCT_LIST_ALL(V) \
558 STRUCT_LIST_DEBUGGER(V)
559
560// We use the full 8 bits of the instance_type field to encode heap object
561// instance types. The high-order bit (bit 7) is set if the object is not a
562// string, and cleared if it is a string.
563const uint32_t kIsNotStringMask = 0x80;
564const uint32_t kStringTag = 0x0;
565const uint32_t kNotStringTag = 0x80;
566
567// If bit 7 is clear, bit 5 indicates that the string is a symbol (if set) or
568// not (if cleared).
569const uint32_t kIsSymbolMask = 0x20;
570const uint32_t kNotSymbolTag = 0x0;
571const uint32_t kSymbolTag = 0x20;
572
573// If bit 7 is clear, bits 3 and 4 are the string's size (short, medium or
574// long). These values are very special in that they are also used to shift
575// the length field to get the length, removing the hash value. This avoids
576// using if or switch when getting the length of a string.
577const uint32_t kStringSizeMask = 0x18;
578const uint32_t kShortStringTag = 0x18;
579const uint32_t kMediumStringTag = 0x10;
580const uint32_t kLongStringTag = 0x00;
581
582// If bit 7 is clear then bit 2 indicates whether the string consists of
583// two-byte characters or one-byte characters.
584const uint32_t kStringEncodingMask = 0x4;
585const uint32_t kTwoByteStringTag = 0x0;
586const uint32_t kAsciiStringTag = 0x4;
587
588// If bit 7 is clear, the low-order 2 bits indicate the representation
589// of the string.
590const uint32_t kStringRepresentationMask = 0x03;
591enum StringRepresentationTag {
592 kSeqStringTag = 0x0,
593 kConsStringTag = 0x1,
594 kSlicedStringTag = 0x2,
595 kExternalStringTag = 0x3
596};
597
598
599// A ConsString with an empty string as the right side is a candidate
600// for being shortcut by the garbage collector unless it is a
601// symbol. It's not common to have non-flat symbols, so we do not
602// shortcut them thereby avoiding turning symbols into strings. See
603// heap.cc and mark-compact.cc.
604const uint32_t kShortcutTypeMask =
605 kIsNotStringMask |
606 kIsSymbolMask |
607 kStringRepresentationMask;
608const uint32_t kShortcutTypeTag = kConsStringTag;
609
610
611enum InstanceType {
612 SHORT_SYMBOL_TYPE = kShortStringTag | kSymbolTag | kSeqStringTag,
613 MEDIUM_SYMBOL_TYPE = kMediumStringTag | kSymbolTag | kSeqStringTag,
614 LONG_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kSeqStringTag,
615 SHORT_ASCII_SYMBOL_TYPE =
616 kShortStringTag | kAsciiStringTag | kSymbolTag | kSeqStringTag,
617 MEDIUM_ASCII_SYMBOL_TYPE =
618 kMediumStringTag | kAsciiStringTag | kSymbolTag | kSeqStringTag,
619 LONG_ASCII_SYMBOL_TYPE =
620 kLongStringTag | kAsciiStringTag | kSymbolTag | kSeqStringTag,
621 SHORT_CONS_SYMBOL_TYPE = kShortStringTag | kSymbolTag | kConsStringTag,
622 MEDIUM_CONS_SYMBOL_TYPE = kMediumStringTag | kSymbolTag | kConsStringTag,
623 LONG_CONS_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kConsStringTag,
624 SHORT_CONS_ASCII_SYMBOL_TYPE =
625 kShortStringTag | kAsciiStringTag | kSymbolTag | kConsStringTag,
626 MEDIUM_CONS_ASCII_SYMBOL_TYPE =
627 kMediumStringTag | kAsciiStringTag | kSymbolTag | kConsStringTag,
628 LONG_CONS_ASCII_SYMBOL_TYPE =
629 kLongStringTag | kAsciiStringTag | kSymbolTag | kConsStringTag,
630 SHORT_SLICED_SYMBOL_TYPE = kShortStringTag | kSymbolTag | kSlicedStringTag,
631 MEDIUM_SLICED_SYMBOL_TYPE = kMediumStringTag | kSymbolTag | kSlicedStringTag,
632 LONG_SLICED_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kSlicedStringTag,
633 SHORT_SLICED_ASCII_SYMBOL_TYPE =
634 kShortStringTag | kAsciiStringTag | kSymbolTag | kSlicedStringTag,
635 MEDIUM_SLICED_ASCII_SYMBOL_TYPE =
636 kMediumStringTag | kAsciiStringTag | kSymbolTag | kSlicedStringTag,
637 LONG_SLICED_ASCII_SYMBOL_TYPE =
638 kLongStringTag | kAsciiStringTag | kSymbolTag | kSlicedStringTag,
639 SHORT_EXTERNAL_SYMBOL_TYPE =
640 kShortStringTag | kSymbolTag | kExternalStringTag,
641 MEDIUM_EXTERNAL_SYMBOL_TYPE =
642 kMediumStringTag | kSymbolTag | kExternalStringTag,
643 LONG_EXTERNAL_SYMBOL_TYPE = kLongStringTag | kSymbolTag | kExternalStringTag,
644 SHORT_EXTERNAL_ASCII_SYMBOL_TYPE =
645 kShortStringTag | kAsciiStringTag | kSymbolTag | kExternalStringTag,
646 MEDIUM_EXTERNAL_ASCII_SYMBOL_TYPE =
647 kMediumStringTag | kAsciiStringTag | kSymbolTag | kExternalStringTag,
648 LONG_EXTERNAL_ASCII_SYMBOL_TYPE =
649 kLongStringTag | kAsciiStringTag | kSymbolTag | kExternalStringTag,
650 SHORT_STRING_TYPE = kShortStringTag | kSeqStringTag,
651 MEDIUM_STRING_TYPE = kMediumStringTag | kSeqStringTag,
652 LONG_STRING_TYPE = kLongStringTag | kSeqStringTag,
653 SHORT_ASCII_STRING_TYPE = kShortStringTag | kAsciiStringTag | kSeqStringTag,
654 MEDIUM_ASCII_STRING_TYPE = kMediumStringTag | kAsciiStringTag | kSeqStringTag,
655 LONG_ASCII_STRING_TYPE = kLongStringTag | kAsciiStringTag | kSeqStringTag,
656 SHORT_CONS_STRING_TYPE = kShortStringTag | kConsStringTag,
657 MEDIUM_CONS_STRING_TYPE = kMediumStringTag | kConsStringTag,
658 LONG_CONS_STRING_TYPE = kLongStringTag | kConsStringTag,
659 SHORT_CONS_ASCII_STRING_TYPE =
660 kShortStringTag | kAsciiStringTag | kConsStringTag,
661 MEDIUM_CONS_ASCII_STRING_TYPE =
662 kMediumStringTag | kAsciiStringTag | kConsStringTag,
663 LONG_CONS_ASCII_STRING_TYPE =
664 kLongStringTag | kAsciiStringTag | kConsStringTag,
665 SHORT_SLICED_STRING_TYPE = kShortStringTag | kSlicedStringTag,
666 MEDIUM_SLICED_STRING_TYPE = kMediumStringTag | kSlicedStringTag,
667 LONG_SLICED_STRING_TYPE = kLongStringTag | kSlicedStringTag,
668 SHORT_SLICED_ASCII_STRING_TYPE =
669 kShortStringTag | kAsciiStringTag | kSlicedStringTag,
670 MEDIUM_SLICED_ASCII_STRING_TYPE =
671 kMediumStringTag | kAsciiStringTag | kSlicedStringTag,
672 LONG_SLICED_ASCII_STRING_TYPE =
673 kLongStringTag | kAsciiStringTag | kSlicedStringTag,
674 SHORT_EXTERNAL_STRING_TYPE = kShortStringTag | kExternalStringTag,
675 MEDIUM_EXTERNAL_STRING_TYPE = kMediumStringTag | kExternalStringTag,
676 LONG_EXTERNAL_STRING_TYPE = kLongStringTag | kExternalStringTag,
677 SHORT_EXTERNAL_ASCII_STRING_TYPE =
678 kShortStringTag | kAsciiStringTag | kExternalStringTag,
679 MEDIUM_EXTERNAL_ASCII_STRING_TYPE =
680 kMediumStringTag | kAsciiStringTag | kExternalStringTag,
681 LONG_EXTERNAL_ASCII_STRING_TYPE =
682 kLongStringTag | kAsciiStringTag | kExternalStringTag,
683 LONG_PRIVATE_EXTERNAL_ASCII_STRING_TYPE = LONG_EXTERNAL_ASCII_STRING_TYPE,
684
685 MAP_TYPE = kNotStringTag,
686 HEAP_NUMBER_TYPE,
687 FIXED_ARRAY_TYPE,
688 CODE_TYPE,
689 ODDBALL_TYPE,
690 JS_GLOBAL_PROPERTY_CELL_TYPE,
691 PROXY_TYPE,
692 BYTE_ARRAY_TYPE,
693 PIXEL_ARRAY_TYPE,
Steve Block3ce2e202009-11-05 08:53:23 +0000694 EXTERNAL_BYTE_ARRAY_TYPE,
695 EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
696 EXTERNAL_SHORT_ARRAY_TYPE,
697 EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
698 EXTERNAL_INT_ARRAY_TYPE,
699 EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
700 EXTERNAL_FLOAT_ARRAY_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000701 FILLER_TYPE,
702 SMI_TYPE,
703
704 ACCESSOR_INFO_TYPE,
705 ACCESS_CHECK_INFO_TYPE,
706 INTERCEPTOR_INFO_TYPE,
707 SHARED_FUNCTION_INFO_TYPE,
708 CALL_HANDLER_INFO_TYPE,
709 FUNCTION_TEMPLATE_INFO_TYPE,
710 OBJECT_TEMPLATE_INFO_TYPE,
711 SIGNATURE_INFO_TYPE,
712 TYPE_SWITCH_INFO_TYPE,
713#ifdef ENABLE_DEBUGGER_SUPPORT
714 DEBUG_INFO_TYPE,
715 BREAK_POINT_INFO_TYPE,
716#endif
717 SCRIPT_TYPE,
718
719 JS_VALUE_TYPE,
720 JS_OBJECT_TYPE,
721 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
722 JS_GLOBAL_OBJECT_TYPE,
723 JS_BUILTINS_OBJECT_TYPE,
724 JS_GLOBAL_PROXY_TYPE,
725 JS_ARRAY_TYPE,
726 JS_REGEXP_TYPE,
727
728 JS_FUNCTION_TYPE,
729
730 // Pseudo-types
731 FIRST_NONSTRING_TYPE = MAP_TYPE,
732 FIRST_TYPE = 0x0,
733 INVALID_TYPE = FIRST_TYPE - 1,
734 LAST_TYPE = JS_FUNCTION_TYPE,
735 // Boundaries for testing the type is a JavaScript "object". Note that
736 // function objects are not counted as objects, even though they are
737 // implemented as such; only values whose typeof is "object" are included.
738 FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE,
739 LAST_JS_OBJECT_TYPE = JS_REGEXP_TYPE
740};
741
742
743enum CompareResult {
744 LESS = -1,
745 EQUAL = 0,
746 GREATER = 1,
747
748 NOT_EQUAL = GREATER
749};
750
751
752#define DECL_BOOLEAN_ACCESSORS(name) \
753 inline bool name(); \
754 inline void set_##name(bool value); \
755
756
757#define DECL_ACCESSORS(name, type) \
758 inline type* name(); \
759 inline void set_##name(type* value, \
760 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \
761
762
763class StringStream;
764class ObjectVisitor;
765
766struct ValueInfo : public Malloced {
767 ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { }
768 InstanceType type;
769 Object* ptr;
770 const char* str;
771 double number;
772};
773
774
775// A template-ized version of the IsXXX functions.
776template <class C> static inline bool Is(Object* obj);
777
778
779// Object is the abstract superclass for all classes in the
780// object hierarchy.
781// Object does not use any virtual functions to avoid the
782// allocation of the C++ vtable.
783// Since Smi and Failure are subclasses of Object no
784// data members can be present in Object.
785class Object BASE_EMBEDDED {
786 public:
787 // Type testing.
788 inline bool IsSmi();
789 inline bool IsHeapObject();
790 inline bool IsHeapNumber();
791 inline bool IsString();
792 inline bool IsSymbol();
793#ifdef DEBUG
794 // See objects-inl.h for more details
795 inline bool IsSeqString();
796 inline bool IsSlicedString();
797 inline bool IsExternalString();
798 inline bool IsExternalTwoByteString();
799 inline bool IsExternalAsciiString();
800 inline bool IsSeqTwoByteString();
801 inline bool IsSeqAsciiString();
802#endif // DEBUG
803 inline bool IsConsString();
804
805 inline bool IsNumber();
806 inline bool IsByteArray();
807 inline bool IsPixelArray();
Steve Block3ce2e202009-11-05 08:53:23 +0000808 inline bool IsExternalArray();
809 inline bool IsExternalByteArray();
810 inline bool IsExternalUnsignedByteArray();
811 inline bool IsExternalShortArray();
812 inline bool IsExternalUnsignedShortArray();
813 inline bool IsExternalIntArray();
814 inline bool IsExternalUnsignedIntArray();
815 inline bool IsExternalFloatArray();
Steve Blocka7e24c12009-10-30 11:49:00 +0000816 inline bool IsFailure();
817 inline bool IsRetryAfterGC();
818 inline bool IsOutOfMemoryFailure();
819 inline bool IsException();
820 inline bool IsJSObject();
821 inline bool IsJSContextExtensionObject();
822 inline bool IsMap();
823 inline bool IsFixedArray();
824 inline bool IsDescriptorArray();
825 inline bool IsContext();
826 inline bool IsCatchContext();
827 inline bool IsGlobalContext();
828 inline bool IsJSFunction();
829 inline bool IsCode();
830 inline bool IsOddball();
831 inline bool IsSharedFunctionInfo();
832 inline bool IsJSValue();
833 inline bool IsStringWrapper();
834 inline bool IsProxy();
835 inline bool IsBoolean();
836 inline bool IsJSArray();
837 inline bool IsJSRegExp();
838 inline bool IsHashTable();
839 inline bool IsDictionary();
840 inline bool IsSymbolTable();
841 inline bool IsCompilationCacheTable();
842 inline bool IsMapCache();
843 inline bool IsPrimitive();
844 inline bool IsGlobalObject();
845 inline bool IsJSGlobalObject();
846 inline bool IsJSBuiltinsObject();
847 inline bool IsJSGlobalProxy();
848 inline bool IsUndetectableObject();
849 inline bool IsAccessCheckNeeded();
850 inline bool IsJSGlobalPropertyCell();
851
852 // Returns true if this object is an instance of the specified
853 // function template.
854 inline bool IsInstanceOf(FunctionTemplateInfo* type);
855
856 inline bool IsStruct();
857#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name();
858 STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
859#undef DECLARE_STRUCT_PREDICATE
860
861 // Oddball testing.
862 INLINE(bool IsUndefined());
863 INLINE(bool IsTheHole());
864 INLINE(bool IsNull());
865 INLINE(bool IsTrue());
866 INLINE(bool IsFalse());
867
868 // Extract the number.
869 inline double Number();
870
871 inline bool HasSpecificClassOf(String* name);
872
873 Object* ToObject(); // ECMA-262 9.9.
874 Object* ToBoolean(); // ECMA-262 9.2.
875
876 // Convert to a JSObject if needed.
877 // global_context is used when creating wrapper object.
878 Object* ToObject(Context* global_context);
879
880 // Converts this to a Smi if possible.
881 // Failure is returned otherwise.
882 inline Object* ToSmi();
883
884 void Lookup(String* name, LookupResult* result);
885
886 // Property access.
887 inline Object* GetProperty(String* key);
888 inline Object* GetProperty(String* key, PropertyAttributes* attributes);
889 Object* GetPropertyWithReceiver(Object* receiver,
890 String* key,
891 PropertyAttributes* attributes);
892 Object* GetProperty(Object* receiver,
893 LookupResult* result,
894 String* key,
895 PropertyAttributes* attributes);
896 Object* GetPropertyWithCallback(Object* receiver,
897 Object* structure,
898 String* name,
899 Object* holder);
900 Object* GetPropertyWithDefinedGetter(Object* receiver,
901 JSFunction* getter);
902
903 inline Object* GetElement(uint32_t index);
904 Object* GetElementWithReceiver(Object* receiver, uint32_t index);
905
906 // Return the object's prototype (might be Heap::null_value()).
907 Object* GetPrototype();
908
909 // Returns true if this is a JSValue containing a string and the index is
910 // < the length of the string. Used to implement [] on strings.
911 inline bool IsStringObjectWithCharacterAt(uint32_t index);
912
913#ifdef DEBUG
914 // Prints this object with details.
915 void Print();
916 void PrintLn();
917 // Verifies the object.
918 void Verify();
919
920 // Verify a pointer is a valid object pointer.
921 static void VerifyPointer(Object* p);
922#endif
923
924 // Prints this object without details.
925 void ShortPrint();
926
927 // Prints this object without details to a message accumulator.
928 void ShortPrint(StringStream* accumulator);
929
930 // Casting: This cast is only needed to satisfy macros in objects-inl.h.
931 static Object* cast(Object* value) { return value; }
932
933 // Layout description.
934 static const int kHeaderSize = 0; // Object does not take up any space.
935
936 private:
937 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
938};
939
940
941// Smi represents integer Numbers that can be stored in 31 bits.
942// Smis are immediate which means they are NOT allocated in the heap.
Steve Blocka7e24c12009-10-30 11:49:00 +0000943// The this pointer has the following format: [31 bit signed int] 0
Steve Block3ce2e202009-11-05 08:53:23 +0000944// For long smis it has the following format:
945// [32 bit signed int] [31 bits zero padding] 0
946// Smi stands for small integer.
Steve Blocka7e24c12009-10-30 11:49:00 +0000947class Smi: public Object {
948 public:
949 // Returns the integer value.
950 inline int value();
951
952 // Convert a value to a Smi object.
953 static inline Smi* FromInt(int value);
954
955 static inline Smi* FromIntptr(intptr_t value);
956
957 // Returns whether value can be represented in a Smi.
958 static inline bool IsValid(intptr_t value);
959
Steve Blocka7e24c12009-10-30 11:49:00 +0000960 // Casting.
961 static inline Smi* cast(Object* object);
962
963 // Dispatched behavior.
964 void SmiPrint();
965 void SmiPrint(StringStream* accumulator);
966#ifdef DEBUG
967 void SmiVerify();
968#endif
969
Steve Block3ce2e202009-11-05 08:53:23 +0000970 static const int kMinValue = (-1 << (kSmiValueSize - 1));
971 static const int kMaxValue = -(kMinValue + 1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000972
973 private:
974 DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);
975};
976
977
978// Failure is used for reporting out of memory situations and
979// propagating exceptions through the runtime system. Failure objects
980// are transient and cannot occur as part of the object graph.
981//
982// Failures are a single word, encoded as follows:
983// +-------------------------+---+--+--+
Steve Block3ce2e202009-11-05 08:53:23 +0000984// |...rrrrrrrrrrrrrrrrrrrrrr|sss|tt|11|
Steve Blocka7e24c12009-10-30 11:49:00 +0000985// +-------------------------+---+--+--+
Steve Block3ce2e202009-11-05 08:53:23 +0000986// 7 6 4 32 10
987//
Steve Blocka7e24c12009-10-30 11:49:00 +0000988//
989// The low two bits, 0-1, are the failure tag, 11. The next two bits,
990// 2-3, are a failure type tag 'tt' with possible values:
991// 00 RETRY_AFTER_GC
992// 01 EXCEPTION
993// 10 INTERNAL_ERROR
994// 11 OUT_OF_MEMORY_EXCEPTION
995//
996// The next three bits, 4-6, are an allocation space tag 'sss'. The
997// allocation space tag is 000 for all failure types except
998// RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the
999// allocation spaces (the encoding is found in globals.h).
1000//
1001// The remaining bits is the size of the allocation request in units
1002// of the pointer size, and is zeroed except for RETRY_AFTER_GC
1003// failures. The 25 bits (on a 32 bit platform) gives a representable
1004// range of 2^27 bytes (128MB).
1005
1006// Failure type tag info.
1007const int kFailureTypeTagSize = 2;
1008const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1;
1009
1010class Failure: public Object {
1011 public:
1012 // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code.
1013 enum Type {
1014 RETRY_AFTER_GC = 0,
1015 EXCEPTION = 1, // Returning this marker tells the real exception
1016 // is in Top::pending_exception.
1017 INTERNAL_ERROR = 2,
1018 OUT_OF_MEMORY_EXCEPTION = 3
1019 };
1020
1021 inline Type type() const;
1022
1023 // Returns the space that needs to be collected for RetryAfterGC failures.
1024 inline AllocationSpace allocation_space() const;
1025
1026 // Returns the number of bytes requested (up to the representable maximum)
1027 // for RetryAfterGC failures.
1028 inline int requested() const;
1029
1030 inline bool IsInternalError() const;
1031 inline bool IsOutOfMemoryException() const;
1032
1033 static Failure* RetryAfterGC(int requested_bytes, AllocationSpace space);
1034 static inline Failure* RetryAfterGC(int requested_bytes); // NEW_SPACE
1035 static inline Failure* Exception();
1036 static inline Failure* InternalError();
1037 static inline Failure* OutOfMemoryException();
1038 // Casting.
1039 static inline Failure* cast(Object* object);
1040
1041 // Dispatched behavior.
1042 void FailurePrint();
1043 void FailurePrint(StringStream* accumulator);
1044#ifdef DEBUG
1045 void FailureVerify();
1046#endif
1047
1048 private:
Steve Block3ce2e202009-11-05 08:53:23 +00001049 inline intptr_t value() const;
1050 static inline Failure* Construct(Type type, intptr_t value = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00001051
1052 DISALLOW_IMPLICIT_CONSTRUCTORS(Failure);
1053};
1054
1055
1056// Heap objects typically have a map pointer in their first word. However,
1057// during GC other data (eg, mark bits, forwarding addresses) is sometimes
1058// encoded in the first word. The class MapWord is an abstraction of the
1059// value in a heap object's first word.
1060class MapWord BASE_EMBEDDED {
1061 public:
1062 // Normal state: the map word contains a map pointer.
1063
1064 // Create a map word from a map pointer.
1065 static inline MapWord FromMap(Map* map);
1066
1067 // View this map word as a map pointer.
1068 inline Map* ToMap();
1069
1070
1071 // Scavenge collection: the map word of live objects in the from space
1072 // contains a forwarding address (a heap object pointer in the to space).
1073
1074 // True if this map word is a forwarding address for a scavenge
1075 // collection. Only valid during a scavenge collection (specifically,
1076 // when all map words are heap object pointers, ie. not during a full GC).
1077 inline bool IsForwardingAddress();
1078
1079 // Create a map word from a forwarding address.
1080 static inline MapWord FromForwardingAddress(HeapObject* object);
1081
1082 // View this map word as a forwarding address.
1083 inline HeapObject* ToForwardingAddress();
1084
1085
1086 // Marking phase of full collection: the map word of live objects is
1087 // marked, and may be marked as overflowed (eg, the object is live, its
1088 // children have not been visited, and it does not fit in the marking
1089 // stack).
1090
1091 // True if this map word's mark bit is set.
1092 inline bool IsMarked();
1093
1094 // Return this map word but with its mark bit set.
1095 inline void SetMark();
1096
1097 // Return this map word but with its mark bit cleared.
1098 inline void ClearMark();
1099
1100 // True if this map word's overflow bit is set.
1101 inline bool IsOverflowed();
1102
1103 // Return this map word but with its overflow bit set.
1104 inline void SetOverflow();
1105
1106 // Return this map word but with its overflow bit cleared.
1107 inline void ClearOverflow();
1108
1109
1110 // Compacting phase of a full compacting collection: the map word of live
1111 // objects contains an encoding of the original map address along with the
1112 // forwarding address (represented as an offset from the first live object
1113 // in the same page as the (old) object address).
1114
1115 // Create a map word from a map address and a forwarding address offset.
1116 static inline MapWord EncodeAddress(Address map_address, int offset);
1117
1118 // Return the map address encoded in this map word.
1119 inline Address DecodeMapAddress(MapSpace* map_space);
1120
1121 // Return the forwarding offset encoded in this map word.
1122 inline int DecodeOffset();
1123
1124
1125 // During serialization: the map word is used to hold an encoded
1126 // address, and possibly a mark bit (set and cleared with SetMark
1127 // and ClearMark).
1128
1129 // Create a map word from an encoded address.
1130 static inline MapWord FromEncodedAddress(Address address);
1131
1132 inline Address ToEncodedAddress();
1133
1134 // Bits used by the marking phase of the garbage collector.
1135 //
1136 // The first word of a heap object is normally a map pointer. The last two
1137 // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to
1138 // mark an object as live and/or overflowed:
1139 // last bit = 0, marked as alive
1140 // second bit = 1, overflowed
1141 // An object is only marked as overflowed when it is marked as live while
1142 // the marking stack is overflowed.
1143 static const int kMarkingBit = 0; // marking bit
1144 static const int kMarkingMask = (1 << kMarkingBit); // marking mask
1145 static const int kOverflowBit = 1; // overflow bit
1146 static const int kOverflowMask = (1 << kOverflowBit); // overflow mask
1147
1148 // Forwarding pointers and map pointer encoding
1149 // 31 21 20 10 9 0
1150 // +-----------------+------------------+-----------------+
1151 // |forwarding offset|page offset of map|page index of map|
1152 // +-----------------+------------------+-----------------+
1153 // 11 bits 11 bits 10 bits
1154 static const int kMapPageIndexBits = 10;
1155 static const int kMapPageOffsetBits = 11;
1156 static const int kForwardingOffsetBits = 11;
1157
1158 static const int kMapPageIndexShift = 0;
1159 static const int kMapPageOffsetShift =
1160 kMapPageIndexShift + kMapPageIndexBits;
1161 static const int kForwardingOffsetShift =
1162 kMapPageOffsetShift + kMapPageOffsetBits;
1163
1164 // 0x000003FF
1165 static const uint32_t kMapPageIndexMask =
1166 (1 << kMapPageOffsetShift) - 1;
1167
1168 // 0x001FFC00
1169 static const uint32_t kMapPageOffsetMask =
1170 ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask;
1171
1172 // 0xFFE00000
1173 static const uint32_t kForwardingOffsetMask =
1174 ~(kMapPageIndexMask | kMapPageOffsetMask);
1175
1176 private:
1177 // HeapObject calls the private constructor and directly reads the value.
1178 friend class HeapObject;
1179
1180 explicit MapWord(uintptr_t value) : value_(value) {}
1181
1182 uintptr_t value_;
1183};
1184
1185
1186// HeapObject is the superclass for all classes describing heap allocated
1187// objects.
1188class HeapObject: public Object {
1189 public:
1190 // [map]: Contains a map which contains the object's reflective
1191 // information.
1192 inline Map* map();
1193 inline void set_map(Map* value);
1194
1195 // During garbage collection, the map word of a heap object does not
1196 // necessarily contain a map pointer.
1197 inline MapWord map_word();
1198 inline void set_map_word(MapWord map_word);
1199
1200 // Converts an address to a HeapObject pointer.
1201 static inline HeapObject* FromAddress(Address address);
1202
1203 // Returns the address of this HeapObject.
1204 inline Address address();
1205
1206 // Iterates over pointers contained in the object (including the Map)
1207 void Iterate(ObjectVisitor* v);
1208
1209 // Iterates over all pointers contained in the object except the
1210 // first map pointer. The object type is given in the first
1211 // parameter. This function does not access the map pointer in the
1212 // object, and so is safe to call while the map pointer is modified.
1213 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1214
1215 // This method only applies to struct objects. Iterates over all the fields
1216 // of this struct.
1217 void IterateStructBody(int object_size, ObjectVisitor* v);
1218
1219 // Returns the heap object's size in bytes
1220 inline int Size();
1221
1222 // Given a heap object's map pointer, returns the heap size in bytes
1223 // Useful when the map pointer field is used for other purposes.
1224 // GC internal.
1225 inline int SizeFromMap(Map* map);
1226
1227 // Support for the marking heap objects during the marking phase of GC.
1228 // True if the object is marked live.
1229 inline bool IsMarked();
1230
1231 // Mutate this object's map pointer to indicate that the object is live.
1232 inline void SetMark();
1233
1234 // Mutate this object's map pointer to remove the indication that the
1235 // object is live (ie, partially restore the map pointer).
1236 inline void ClearMark();
1237
1238 // True if this object is marked as overflowed. Overflowed objects have
1239 // been reached and marked during marking of the heap, but their children
1240 // have not necessarily been marked and they have not been pushed on the
1241 // marking stack.
1242 inline bool IsOverflowed();
1243
1244 // Mutate this object's map pointer to indicate that the object is
1245 // overflowed.
1246 inline void SetOverflow();
1247
1248 // Mutate this object's map pointer to remove the indication that the
1249 // object is overflowed (ie, partially restore the map pointer).
1250 inline void ClearOverflow();
1251
1252 // Returns the field at offset in obj, as a read/write Object* reference.
1253 // Does no checking, and is safe to use during GC, while maps are invalid.
1254 // Does not update remembered sets, so should only be assigned to
1255 // during marking GC.
1256 static inline Object** RawField(HeapObject* obj, int offset);
1257
1258 // Casting.
1259 static inline HeapObject* cast(Object* obj);
1260
1261 // Return the write barrier mode for this.
1262 inline WriteBarrierMode GetWriteBarrierMode();
1263
1264 // Dispatched behavior.
1265 void HeapObjectShortPrint(StringStream* accumulator);
1266#ifdef DEBUG
1267 void HeapObjectPrint();
1268 void HeapObjectVerify();
1269 inline void VerifyObjectField(int offset);
1270
1271 void PrintHeader(const char* id);
1272
1273 // Verify a pointer is a valid HeapObject pointer that points to object
1274 // areas in the heap.
1275 static void VerifyHeapPointer(Object* p);
1276#endif
1277
1278 // Layout description.
1279 // First field in a heap object is map.
1280 static const int kMapOffset = Object::kHeaderSize;
1281 static const int kHeaderSize = kMapOffset + kPointerSize;
1282
1283 STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset);
1284
1285 protected:
1286 // helpers for calling an ObjectVisitor to iterate over pointers in the
1287 // half-open range [start, end) specified as integer offsets
1288 inline void IteratePointers(ObjectVisitor* v, int start, int end);
1289 // as above, for the single element at "offset"
1290 inline void IteratePointer(ObjectVisitor* v, int offset);
1291
1292 // Computes the object size from the map.
1293 // Should only be used from SizeFromMap.
1294 int SlowSizeFromMap(Map* map);
1295
1296 private:
1297 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1298};
1299
1300
1301// The HeapNumber class describes heap allocated numbers that cannot be
1302// represented in a Smi (small integer)
1303class HeapNumber: public HeapObject {
1304 public:
1305 // [value]: number value.
1306 inline double value();
1307 inline void set_value(double value);
1308
1309 // Casting.
1310 static inline HeapNumber* cast(Object* obj);
1311
1312 // Dispatched behavior.
1313 Object* HeapNumberToBoolean();
1314 void HeapNumberPrint();
1315 void HeapNumberPrint(StringStream* accumulator);
1316#ifdef DEBUG
1317 void HeapNumberVerify();
1318#endif
1319
1320 // Layout description.
1321 static const int kValueOffset = HeapObject::kHeaderSize;
1322 // IEEE doubles are two 32 bit words. The first is just mantissa, the second
1323 // is a mixture of sign, exponent and mantissa. Our current platforms are all
1324 // little endian apart from non-EABI arm which is little endian with big
1325 // endian floating point word ordering!
Steve Block3ce2e202009-11-05 08:53:23 +00001326#if !defined(V8_HOST_ARCH_ARM) || defined(USE_ARM_EABI)
Steve Blocka7e24c12009-10-30 11:49:00 +00001327 static const int kMantissaOffset = kValueOffset;
1328 static const int kExponentOffset = kValueOffset + 4;
1329#else
1330 static const int kMantissaOffset = kValueOffset + 4;
1331 static const int kExponentOffset = kValueOffset;
1332# define BIG_ENDIAN_FLOATING_POINT 1
1333#endif
1334 static const int kSize = kValueOffset + kDoubleSize;
1335
1336 static const uint32_t kSignMask = 0x80000000u;
1337 static const uint32_t kExponentMask = 0x7ff00000u;
1338 static const uint32_t kMantissaMask = 0xfffffu;
1339 static const int kExponentBias = 1023;
1340 static const int kExponentShift = 20;
1341 static const int kMantissaBitsInTopWord = 20;
1342 static const int kNonMantissaBitsInTopWord = 12;
1343
1344 private:
1345 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
1346};
1347
1348
1349// The JSObject describes real heap allocated JavaScript objects with
1350// properties.
1351// Note that the map of JSObject changes during execution to enable inline
1352// caching.
1353class JSObject: public HeapObject {
1354 public:
1355 enum DeleteMode { NORMAL_DELETION, FORCE_DELETION };
1356 enum ElementsKind {
1357 FAST_ELEMENTS,
1358 DICTIONARY_ELEMENTS,
Steve Block3ce2e202009-11-05 08:53:23 +00001359 PIXEL_ELEMENTS,
1360 EXTERNAL_BYTE_ELEMENTS,
1361 EXTERNAL_UNSIGNED_BYTE_ELEMENTS,
1362 EXTERNAL_SHORT_ELEMENTS,
1363 EXTERNAL_UNSIGNED_SHORT_ELEMENTS,
1364 EXTERNAL_INT_ELEMENTS,
1365 EXTERNAL_UNSIGNED_INT_ELEMENTS,
1366 EXTERNAL_FLOAT_ELEMENTS
Steve Blocka7e24c12009-10-30 11:49:00 +00001367 };
1368
1369 // [properties]: Backing storage for properties.
1370 // properties is a FixedArray in the fast case, and a Dictionary in the
1371 // slow case.
1372 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
1373 inline void initialize_properties();
1374 inline bool HasFastProperties();
1375 inline StringDictionary* property_dictionary(); // Gets slow properties.
1376
1377 // [elements]: The elements (properties with names that are integers).
1378 // elements is a FixedArray in the fast case, and a Dictionary in the slow
1379 // case or a PixelArray in a special case.
1380 DECL_ACCESSORS(elements, Array) // Get and set fast elements.
1381 inline void initialize_elements();
1382 inline ElementsKind GetElementsKind();
1383 inline bool HasFastElements();
1384 inline bool HasDictionaryElements();
1385 inline bool HasPixelElements();
Steve Block3ce2e202009-11-05 08:53:23 +00001386 inline bool HasExternalArrayElements();
1387 inline bool HasExternalByteElements();
1388 inline bool HasExternalUnsignedByteElements();
1389 inline bool HasExternalShortElements();
1390 inline bool HasExternalUnsignedShortElements();
1391 inline bool HasExternalIntElements();
1392 inline bool HasExternalUnsignedIntElements();
1393 inline bool HasExternalFloatElements();
Steve Blocka7e24c12009-10-30 11:49:00 +00001394 inline NumberDictionary* element_dictionary(); // Gets slow elements.
1395
1396 // Collects elements starting at index 0.
1397 // Undefined values are placed after non-undefined values.
1398 // Returns the number of non-undefined values.
1399 Object* PrepareElementsForSort(uint32_t limit);
1400 // As PrepareElementsForSort, but only on objects where elements is
1401 // a dictionary, and it will stay a dictionary.
1402 Object* PrepareSlowElementsForSort(uint32_t limit);
1403
1404 Object* SetProperty(String* key,
1405 Object* value,
1406 PropertyAttributes attributes);
1407 Object* SetProperty(LookupResult* result,
1408 String* key,
1409 Object* value,
1410 PropertyAttributes attributes);
1411 Object* SetPropertyWithFailedAccessCheck(LookupResult* result,
1412 String* name,
1413 Object* value);
1414 Object* SetPropertyWithCallback(Object* structure,
1415 String* name,
1416 Object* value,
1417 JSObject* holder);
1418 Object* SetPropertyWithDefinedSetter(JSFunction* setter,
1419 Object* value);
1420 Object* SetPropertyWithInterceptor(String* name,
1421 Object* value,
1422 PropertyAttributes attributes);
1423 Object* SetPropertyPostInterceptor(String* name,
1424 Object* value,
1425 PropertyAttributes attributes);
1426 Object* IgnoreAttributesAndSetLocalProperty(String* key,
1427 Object* value,
1428 PropertyAttributes attributes);
1429
1430 // Retrieve a value in a normalized object given a lookup result.
1431 // Handles the special representation of JS global objects.
1432 Object* GetNormalizedProperty(LookupResult* result);
1433
1434 // Sets the property value in a normalized object given a lookup result.
1435 // Handles the special representation of JS global objects.
1436 Object* SetNormalizedProperty(LookupResult* result, Object* value);
1437
1438 // Sets the property value in a normalized object given (key, value, details).
1439 // Handles the special representation of JS global objects.
1440 Object* SetNormalizedProperty(String* name,
1441 Object* value,
1442 PropertyDetails details);
1443
1444 // Deletes the named property in a normalized object.
1445 Object* DeleteNormalizedProperty(String* name, DeleteMode mode);
1446
1447 // Sets a property that currently has lazy loading.
1448 Object* SetLazyProperty(LookupResult* result,
1449 String* name,
1450 Object* value,
1451 PropertyAttributes attributes);
1452
1453 // Returns the class name ([[Class]] property in the specification).
1454 String* class_name();
1455
1456 // Returns the constructor name (the name (possibly, inferred name) of the
1457 // function that was used to instantiate the object).
1458 String* constructor_name();
1459
1460 // Retrieve interceptors.
1461 InterceptorInfo* GetNamedInterceptor();
1462 InterceptorInfo* GetIndexedInterceptor();
1463
1464 inline PropertyAttributes GetPropertyAttribute(String* name);
1465 PropertyAttributes GetPropertyAttributeWithReceiver(JSObject* receiver,
1466 String* name);
1467 PropertyAttributes GetLocalPropertyAttribute(String* name);
1468
1469 Object* DefineAccessor(String* name, bool is_getter, JSFunction* fun,
1470 PropertyAttributes attributes);
1471 Object* LookupAccessor(String* name, bool is_getter);
1472
1473 // Used from Object::GetProperty().
1474 Object* GetPropertyWithFailedAccessCheck(Object* receiver,
1475 LookupResult* result,
1476 String* name,
1477 PropertyAttributes* attributes);
1478 Object* GetPropertyWithInterceptor(JSObject* receiver,
1479 String* name,
1480 PropertyAttributes* attributes);
1481 Object* GetPropertyPostInterceptor(JSObject* receiver,
1482 String* name,
1483 PropertyAttributes* attributes);
1484 Object* GetLazyProperty(Object* receiver,
1485 LookupResult* result,
1486 String* name,
1487 PropertyAttributes* attributes);
1488
1489 // Tells whether this object needs to be loaded.
1490 inline bool IsLoaded();
1491
1492 // Returns true if this is an instance of an api function and has
1493 // been modified since it was created. May give false positives.
1494 bool IsDirty();
1495
1496 bool HasProperty(String* name) {
1497 return GetPropertyAttribute(name) != ABSENT;
1498 }
1499
1500 // Can cause a GC if it hits an interceptor.
1501 bool HasLocalProperty(String* name) {
1502 return GetLocalPropertyAttribute(name) != ABSENT;
1503 }
1504
1505 Object* DeleteProperty(String* name, DeleteMode mode);
1506 Object* DeleteElement(uint32_t index, DeleteMode mode);
1507 Object* DeleteLazyProperty(LookupResult* result,
1508 String* name,
1509 DeleteMode mode);
1510
1511 // Tests for the fast common case for property enumeration.
1512 bool IsSimpleEnum();
1513
1514 // Do we want to keep the elements in fast case when increasing the
1515 // capacity?
1516 bool ShouldConvertToSlowElements(int new_capacity);
1517 // Returns true if the backing storage for the slow-case elements of
1518 // this object takes up nearly as much space as a fast-case backing
1519 // storage would. In that case the JSObject should have fast
1520 // elements.
1521 bool ShouldConvertToFastElements();
1522
1523 // Return the object's prototype (might be Heap::null_value()).
1524 inline Object* GetPrototype();
1525
1526 // Tells whether the index'th element is present.
1527 inline bool HasElement(uint32_t index);
1528 bool HasElementWithReceiver(JSObject* receiver, uint32_t index);
1529 bool HasLocalElement(uint32_t index);
1530
1531 bool HasElementWithInterceptor(JSObject* receiver, uint32_t index);
1532 bool HasElementPostInterceptor(JSObject* receiver, uint32_t index);
1533
1534 Object* SetFastElement(uint32_t index, Object* value);
1535
1536 // Set the index'th array element.
1537 // A Failure object is returned if GC is needed.
1538 Object* SetElement(uint32_t index, Object* value);
1539
1540 // Returns the index'th element.
1541 // The undefined object if index is out of bounds.
1542 Object* GetElementWithReceiver(JSObject* receiver, uint32_t index);
1543
1544 void SetFastElements(FixedArray* elements);
1545 Object* SetSlowElements(Object* length);
1546
1547 // Lookup interceptors are used for handling properties controlled by host
1548 // objects.
1549 inline bool HasNamedInterceptor();
1550 inline bool HasIndexedInterceptor();
1551
1552 // Support functions for v8 api (needed for correct interceptor behavior).
1553 bool HasRealNamedProperty(String* key);
1554 bool HasRealElementProperty(uint32_t index);
1555 bool HasRealNamedCallbackProperty(String* key);
1556
1557 // Initializes the array to a certain length
1558 Object* SetElementsLength(Object* length);
1559
1560 // Get the header size for a JSObject. Used to compute the index of
1561 // internal fields as well as the number of internal fields.
1562 inline int GetHeaderSize();
1563
1564 inline int GetInternalFieldCount();
1565 inline Object* GetInternalField(int index);
1566 inline void SetInternalField(int index, Object* value);
1567
1568 // Lookup a property. If found, the result is valid and has
1569 // detailed information.
1570 void LocalLookup(String* name, LookupResult* result);
1571 void Lookup(String* name, LookupResult* result);
1572
1573 // The following lookup functions skip interceptors.
1574 void LocalLookupRealNamedProperty(String* name, LookupResult* result);
1575 void LookupRealNamedProperty(String* name, LookupResult* result);
1576 void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result);
1577 void LookupCallbackSetterInPrototypes(String* name, LookupResult* result);
1578 Object* LookupCallbackSetterInPrototypes(uint32_t index);
1579 void LookupCallback(String* name, LookupResult* result);
1580
1581 // Returns the number of properties on this object filtering out properties
1582 // with the specified attributes (ignoring interceptors).
1583 int NumberOfLocalProperties(PropertyAttributes filter);
1584 // Returns the number of enumerable properties (ignoring interceptors).
1585 int NumberOfEnumProperties();
1586 // Fill in details for properties into storage starting at the specified
1587 // index.
1588 void GetLocalPropertyNames(FixedArray* storage, int index);
1589
1590 // Returns the number of properties on this object filtering out properties
1591 // with the specified attributes (ignoring interceptors).
1592 int NumberOfLocalElements(PropertyAttributes filter);
1593 // Returns the number of enumerable elements (ignoring interceptors).
1594 int NumberOfEnumElements();
1595 // Returns the number of elements on this object filtering out elements
1596 // with the specified attributes (ignoring interceptors).
1597 int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter);
1598 // Count and fill in the enumerable elements into storage.
1599 // (storage->length() == NumberOfEnumElements()).
1600 // If storage is NULL, will count the elements without adding
1601 // them to any storage.
1602 // Returns the number of enumerable elements.
1603 int GetEnumElementKeys(FixedArray* storage);
1604
1605 // Add a property to a fast-case object using a map transition to
1606 // new_map.
1607 Object* AddFastPropertyUsingMap(Map* new_map,
1608 String* name,
1609 Object* value);
1610
1611 // Add a constant function property to a fast-case object.
1612 // This leaves a CONSTANT_TRANSITION in the old map, and
1613 // if it is called on a second object with this map, a
1614 // normal property is added instead, with a map transition.
1615 // This avoids the creation of many maps with the same constant
1616 // function, all orphaned.
1617 Object* AddConstantFunctionProperty(String* name,
1618 JSFunction* function,
1619 PropertyAttributes attributes);
1620
1621 Object* ReplaceSlowProperty(String* name,
1622 Object* value,
1623 PropertyAttributes attributes);
1624
1625 // Converts a descriptor of any other type to a real field,
1626 // backed by the properties array. Descriptors of visible
1627 // types, such as CONSTANT_FUNCTION, keep their enumeration order.
1628 // Converts the descriptor on the original object's map to a
1629 // map transition, and the the new field is on the object's new map.
1630 Object* ConvertDescriptorToFieldAndMapTransition(
1631 String* name,
1632 Object* new_value,
1633 PropertyAttributes attributes);
1634
1635 // Converts a descriptor of any other type to a real field,
1636 // backed by the properties array. Descriptors of visible
1637 // types, such as CONSTANT_FUNCTION, keep their enumeration order.
1638 Object* ConvertDescriptorToField(String* name,
1639 Object* new_value,
1640 PropertyAttributes attributes);
1641
1642 // Add a property to a fast-case object.
1643 Object* AddFastProperty(String* name,
1644 Object* value,
1645 PropertyAttributes attributes);
1646
1647 // Add a property to a slow-case object.
1648 Object* AddSlowProperty(String* name,
1649 Object* value,
1650 PropertyAttributes attributes);
1651
1652 // Add a property to an object.
1653 Object* AddProperty(String* name,
1654 Object* value,
1655 PropertyAttributes attributes);
1656
1657 // Convert the object to use the canonical dictionary
1658 // representation. If the object is expected to have additional properties
1659 // added this number can be indicated to have the backing store allocated to
1660 // an initial capacity for holding these properties.
1661 Object* NormalizeProperties(PropertyNormalizationMode mode,
1662 int expected_additional_properties);
1663 Object* NormalizeElements();
1664
1665 // Transform slow named properties to fast variants.
1666 // Returns failure if allocation failed.
1667 Object* TransformToFastProperties(int unused_property_fields);
1668
1669 // Access fast-case object properties at index.
1670 inline Object* FastPropertyAt(int index);
1671 inline Object* FastPropertyAtPut(int index, Object* value);
1672
1673 // Access to in object properties.
1674 inline Object* InObjectPropertyAt(int index);
1675 inline Object* InObjectPropertyAtPut(int index,
1676 Object* value,
1677 WriteBarrierMode mode
1678 = UPDATE_WRITE_BARRIER);
1679
1680 // initializes the body after properties slot, properties slot is
1681 // initialized by set_properties
1682 // Note: this call does not update write barrier, it is caller's
1683 // reponsibility to ensure that *v* can be collected without WB here.
1684 inline void InitializeBody(int object_size);
1685
1686 // Check whether this object references another object
1687 bool ReferencesObject(Object* obj);
1688
1689 // Casting.
1690 static inline JSObject* cast(Object* obj);
1691
1692 // Dispatched behavior.
1693 void JSObjectIterateBody(int object_size, ObjectVisitor* v);
1694 void JSObjectShortPrint(StringStream* accumulator);
1695#ifdef DEBUG
1696 void JSObjectPrint();
1697 void JSObjectVerify();
1698 void PrintProperties();
1699 void PrintElements();
1700
1701 // Structure for collecting spill information about JSObjects.
1702 class SpillInformation {
1703 public:
1704 void Clear();
1705 void Print();
1706 int number_of_objects_;
1707 int number_of_objects_with_fast_properties_;
1708 int number_of_objects_with_fast_elements_;
1709 int number_of_fast_used_fields_;
1710 int number_of_fast_unused_fields_;
1711 int number_of_slow_used_properties_;
1712 int number_of_slow_unused_properties_;
1713 int number_of_fast_used_elements_;
1714 int number_of_fast_unused_elements_;
1715 int number_of_slow_used_elements_;
1716 int number_of_slow_unused_elements_;
1717 };
1718
1719 void IncrementSpillStatistics(SpillInformation* info);
1720#endif
1721 Object* SlowReverseLookup(Object* value);
1722
1723 static const uint32_t kMaxGap = 1024;
1724 static const int kMaxFastElementsLength = 5000;
1725 static const int kInitialMaxFastElementArray = 100000;
1726 static const int kMaxFastProperties = 8;
1727 static const int kMaxInstanceSize = 255 * kPointerSize;
1728 // When extending the backing storage for property values, we increase
1729 // its size by more than the 1 entry necessary, so sequentially adding fields
1730 // to the same object requires fewer allocations and copies.
1731 static const int kFieldsAdded = 3;
1732
1733 // Layout description.
1734 static const int kPropertiesOffset = HeapObject::kHeaderSize;
1735 static const int kElementsOffset = kPropertiesOffset + kPointerSize;
1736 static const int kHeaderSize = kElementsOffset + kPointerSize;
1737
1738 STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize);
1739
1740 Object* GetElementWithInterceptor(JSObject* receiver, uint32_t index);
1741
1742 private:
1743 Object* SetElementWithInterceptor(uint32_t index, Object* value);
1744 Object* SetElementWithoutInterceptor(uint32_t index, Object* value);
1745
1746 Object* GetElementPostInterceptor(JSObject* receiver, uint32_t index);
1747
1748 Object* DeletePropertyPostInterceptor(String* name, DeleteMode mode);
1749 Object* DeletePropertyWithInterceptor(String* name);
1750
1751 Object* DeleteElementPostInterceptor(uint32_t index, DeleteMode mode);
1752 Object* DeleteElementWithInterceptor(uint32_t index);
1753
1754 PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver,
1755 String* name,
1756 bool continue_search);
1757 PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver,
1758 String* name,
1759 bool continue_search);
1760 PropertyAttributes GetPropertyAttributeWithFailedAccessCheck(
1761 Object* receiver,
1762 LookupResult* result,
1763 String* name,
1764 bool continue_search);
1765 PropertyAttributes GetPropertyAttribute(JSObject* receiver,
1766 LookupResult* result,
1767 String* name,
1768 bool continue_search);
1769
1770 // Returns true if most of the elements backing storage is used.
1771 bool HasDenseElements();
1772
1773 Object* DefineGetterSetter(String* name, PropertyAttributes attributes);
1774
1775 void LookupInDescriptor(String* name, LookupResult* result);
1776
1777 DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
1778};
1779
1780
1781// Abstract super class arrays. It provides length behavior.
1782class Array: public HeapObject {
1783 public:
1784 // [length]: length of the array.
1785 inline int length();
1786 inline void set_length(int value);
1787
1788 // Convert an object to an array index.
1789 // Returns true if the conversion succeeded.
1790 static inline bool IndexFromObject(Object* object, uint32_t* index);
1791
1792 // Layout descriptor.
1793 static const int kLengthOffset = HeapObject::kHeaderSize;
1794
1795 protected:
1796 // No code should use the Array class directly, only its subclasses.
1797 // Use the kHeaderSize of the appropriate subclass, which may be aligned.
1798 static const int kHeaderSize = kLengthOffset + kIntSize;
1799 static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize);
1800
1801 private:
1802 DISALLOW_IMPLICIT_CONSTRUCTORS(Array);
1803};
1804
1805
1806// FixedArray describes fixed sized arrays where element
1807// type is Object*.
1808
1809class FixedArray: public Array {
1810 public:
1811
1812 // Setter and getter for elements.
1813 inline Object* get(int index);
1814 // Setter that uses write barrier.
1815 inline void set(int index, Object* value);
1816
1817 // Setter that doesn't need write barrier).
1818 inline void set(int index, Smi* value);
1819 // Setter with explicit barrier mode.
1820 inline void set(int index, Object* value, WriteBarrierMode mode);
1821
1822 // Setters for frequently used oddballs located in old space.
1823 inline void set_undefined(int index);
1824 inline void set_null(int index);
1825 inline void set_the_hole(int index);
1826
1827 // Copy operations.
1828 inline Object* Copy();
1829 Object* CopySize(int new_length);
1830
1831 // Add the elements of a JSArray to this FixedArray.
1832 Object* AddKeysFromJSArray(JSArray* array);
1833
1834 // Compute the union of this and other.
1835 Object* UnionOfKeys(FixedArray* other);
1836
1837 // Copy a sub array from the receiver to dest.
1838 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
1839
1840 // Garbage collection support.
1841 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; }
1842
1843 // Code Generation support.
1844 static int OffsetOfElementAt(int index) { return SizeFor(index); }
1845
1846 // Casting.
1847 static inline FixedArray* cast(Object* obj);
1848
1849 // Align data at kPointerSize, even if Array.kHeaderSize isn't aligned.
1850 static const int kHeaderSize = POINTER_SIZE_ALIGN(Array::kHeaderSize);
1851
1852 // Dispatched behavior.
1853 int FixedArraySize() { return SizeFor(length()); }
1854 void FixedArrayIterateBody(ObjectVisitor* v);
1855#ifdef DEBUG
1856 void FixedArrayPrint();
1857 void FixedArrayVerify();
1858 // Checks if two FixedArrays have identical contents.
1859 bool IsEqualTo(FixedArray* other);
1860#endif
1861
1862 // Swap two elements in a pair of arrays. If this array and the
1863 // numbers array are the same object, the elements are only swapped
1864 // once.
1865 void SwapPairs(FixedArray* numbers, int i, int j);
1866
1867 // Sort prefix of this array and the numbers array as pairs wrt. the
1868 // numbers. If the numbers array and the this array are the same
1869 // object, the prefix of this array is sorted.
1870 void SortPairs(FixedArray* numbers, uint32_t len);
1871
1872 protected:
1873 // Set operation on FixedArray without using write barriers.
1874 static inline void fast_set(FixedArray* array, int index, Object* value);
1875
1876 private:
1877 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray);
1878};
1879
1880
1881// DescriptorArrays are fixed arrays used to hold instance descriptors.
1882// The format of the these objects is:
1883// [0]: point to a fixed array with (value, detail) pairs.
1884// [1]: next enumeration index (Smi), or pointer to small fixed array:
1885// [0]: next enumeration index (Smi)
1886// [1]: pointer to fixed array with enum cache
1887// [2]: first key
1888// [length() - 1]: last key
1889//
1890class DescriptorArray: public FixedArray {
1891 public:
1892 // Is this the singleton empty_descriptor_array?
1893 inline bool IsEmpty();
1894 // Returns the number of descriptors in the array.
1895 int number_of_descriptors() {
1896 return IsEmpty() ? 0 : length() - kFirstIndex;
1897 }
1898
1899 int NextEnumerationIndex() {
1900 if (IsEmpty()) return PropertyDetails::kInitialIndex;
1901 Object* obj = get(kEnumerationIndexIndex);
1902 if (obj->IsSmi()) {
1903 return Smi::cast(obj)->value();
1904 } else {
1905 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex);
1906 return Smi::cast(index)->value();
1907 }
1908 }
1909
1910 // Set next enumeration index and flush any enum cache.
1911 void SetNextEnumerationIndex(int value) {
1912 if (!IsEmpty()) {
1913 fast_set(this, kEnumerationIndexIndex, Smi::FromInt(value));
1914 }
1915 }
1916 bool HasEnumCache() {
1917 return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi();
1918 }
1919
1920 Object* GetEnumCache() {
1921 ASSERT(HasEnumCache());
1922 FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex));
1923 return bridge->get(kEnumCacheBridgeCacheIndex);
1924 }
1925
1926 // Initialize or change the enum cache,
1927 // using the supplied storage for the small "bridge".
1928 void SetEnumCache(FixedArray* bridge_storage, FixedArray* new_cache);
1929
1930 // Accessors for fetching instance descriptor at descriptor number.
1931 inline String* GetKey(int descriptor_number);
1932 inline Object* GetValue(int descriptor_number);
1933 inline Smi* GetDetails(int descriptor_number);
1934 inline PropertyType GetType(int descriptor_number);
1935 inline int GetFieldIndex(int descriptor_number);
1936 inline JSFunction* GetConstantFunction(int descriptor_number);
1937 inline Object* GetCallbacksObject(int descriptor_number);
1938 inline AccessorDescriptor* GetCallbacks(int descriptor_number);
1939 inline bool IsProperty(int descriptor_number);
1940 inline bool IsTransition(int descriptor_number);
1941 inline bool IsNullDescriptor(int descriptor_number);
1942 inline bool IsDontEnum(int descriptor_number);
1943
1944 // Accessor for complete descriptor.
1945 inline void Get(int descriptor_number, Descriptor* desc);
1946 inline void Set(int descriptor_number, Descriptor* desc);
1947
1948 // Transfer complete descriptor from another descriptor array to
1949 // this one.
1950 inline void CopyFrom(int index, DescriptorArray* src, int src_index);
1951
1952 // Copy the descriptor array, insert a new descriptor and optionally
1953 // remove map transitions. If the descriptor is already present, it is
1954 // replaced. If a replaced descriptor is a real property (not a transition
1955 // or null), its enumeration index is kept as is.
1956 // If adding a real property, map transitions must be removed. If adding
1957 // a transition, they must not be removed. All null descriptors are removed.
1958 Object* CopyInsert(Descriptor* descriptor, TransitionFlag transition_flag);
1959
1960 // Remove all transitions. Return a copy of the array with all transitions
1961 // removed, or a Failure object if the new array could not be allocated.
1962 Object* RemoveTransitions();
1963
1964 // Sort the instance descriptors by the hash codes of their keys.
1965 void Sort();
1966
1967 // Search the instance descriptors for given name.
1968 inline int Search(String* name);
1969
1970 // Tells whether the name is present int the array.
1971 bool Contains(String* name) { return kNotFound != Search(name); }
1972
1973 // Perform a binary search in the instance descriptors represented
1974 // by this fixed array. low and high are descriptor indices. If there
1975 // are three instance descriptors in this array it should be called
1976 // with low=0 and high=2.
1977 int BinarySearch(String* name, int low, int high);
1978
1979 // Perform a linear search in the instance descriptors represented
1980 // by this fixed array. len is the number of descriptor indices that are
1981 // valid. Does not require the descriptors to be sorted.
1982 int LinearSearch(String* name, int len);
1983
1984 // Allocates a DescriptorArray, but returns the singleton
1985 // empty descriptor array object if number_of_descriptors is 0.
1986 static Object* Allocate(int number_of_descriptors);
1987
1988 // Casting.
1989 static inline DescriptorArray* cast(Object* obj);
1990
1991 // Constant for denoting key was not found.
1992 static const int kNotFound = -1;
1993
1994 static const int kContentArrayIndex = 0;
1995 static const int kEnumerationIndexIndex = 1;
1996 static const int kFirstIndex = 2;
1997
1998 // The length of the "bridge" to the enum cache.
1999 static const int kEnumCacheBridgeLength = 2;
2000 static const int kEnumCacheBridgeEnumIndex = 0;
2001 static const int kEnumCacheBridgeCacheIndex = 1;
2002
2003 // Layout description.
2004 static const int kContentArrayOffset = FixedArray::kHeaderSize;
2005 static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize;
2006 static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize;
2007
2008 // Layout description for the bridge array.
2009 static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize;
2010 static const int kEnumCacheBridgeCacheOffset =
2011 kEnumCacheBridgeEnumOffset + kPointerSize;
2012
2013#ifdef DEBUG
2014 // Print all the descriptors.
2015 void PrintDescriptors();
2016
2017 // Is the descriptor array sorted and without duplicates?
2018 bool IsSortedNoDuplicates();
2019
2020 // Are two DescriptorArrays equal?
2021 bool IsEqualTo(DescriptorArray* other);
2022#endif
2023
2024 // The maximum number of descriptors we want in a descriptor array (should
2025 // fit in a page).
2026 static const int kMaxNumberOfDescriptors = 1024 + 512;
2027
2028 private:
2029 // Conversion from descriptor number to array indices.
2030 static int ToKeyIndex(int descriptor_number) {
2031 return descriptor_number+kFirstIndex;
2032 }
2033 static int ToValueIndex(int descriptor_number) {
2034 return descriptor_number << 1;
2035 }
2036 static int ToDetailsIndex(int descriptor_number) {
2037 return( descriptor_number << 1) + 1;
2038 }
2039
2040 bool is_null_descriptor(int descriptor_number) {
2041 return PropertyDetails(GetDetails(descriptor_number)).type() ==
2042 NULL_DESCRIPTOR;
2043 }
2044 // Swap operation on FixedArray without using write barriers.
2045 static inline void fast_swap(FixedArray* array, int first, int second);
2046
2047 // Swap descriptor first and second.
2048 inline void Swap(int first, int second);
2049
2050 FixedArray* GetContentArray() {
2051 return FixedArray::cast(get(kContentArrayIndex));
2052 }
2053 DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray);
2054};
2055
2056
2057// HashTable is a subclass of FixedArray that implements a hash table
2058// that uses open addressing and quadratic probing.
2059//
2060// In order for the quadratic probing to work, elements that have not
2061// yet been used and elements that have been deleted are
2062// distinguished. Probing continues when deleted elements are
2063// encountered and stops when unused elements are encountered.
2064//
2065// - Elements with key == undefined have not been used yet.
2066// - Elements with key == null have been deleted.
2067//
2068// The hash table class is parameterized with a Shape and a Key.
2069// Shape must be a class with the following interface:
2070// class ExampleShape {
2071// public:
2072// // Tells whether key matches other.
2073// static bool IsMatch(Key key, Object* other);
2074// // Returns the hash value for key.
2075// static uint32_t Hash(Key key);
2076// // Returns the hash value for object.
2077// static uint32_t HashForObject(Key key, Object* object);
2078// // Convert key to an object.
2079// static inline Object* AsObject(Key key);
2080// // The prefix size indicates number of elements in the beginning
2081// // of the backing storage.
2082// static const int kPrefixSize = ..;
2083// // The Element size indicates number of elements per entry.
2084// static const int kEntrySize = ..;
2085// };
Steve Block3ce2e202009-11-05 08:53:23 +00002086// The prefix size indicates an amount of memory in the
Steve Blocka7e24c12009-10-30 11:49:00 +00002087// beginning of the backing storage that can be used for non-element
2088// information by subclasses.
2089
2090template<typename Shape, typename Key>
2091class HashTable: public FixedArray {
2092 public:
Steve Block3ce2e202009-11-05 08:53:23 +00002093 // Returns the number of elements in the hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002094 int NumberOfElements() {
2095 return Smi::cast(get(kNumberOfElementsIndex))->value();
2096 }
2097
Steve Block3ce2e202009-11-05 08:53:23 +00002098 // Returns the capacity of the hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002099 int Capacity() {
2100 return Smi::cast(get(kCapacityIndex))->value();
2101 }
2102
2103 // ElementAdded should be called whenever an element is added to a
Steve Block3ce2e202009-11-05 08:53:23 +00002104 // hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002105 void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); }
2106
2107 // ElementRemoved should be called whenever an element is removed from
Steve Block3ce2e202009-11-05 08:53:23 +00002108 // a hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002109 void ElementRemoved() { SetNumberOfElements(NumberOfElements() - 1); }
2110 void ElementsRemoved(int n) { SetNumberOfElements(NumberOfElements() - n); }
2111
Steve Block3ce2e202009-11-05 08:53:23 +00002112 // Returns a new HashTable object. Might return Failure.
Steve Blocka7e24c12009-10-30 11:49:00 +00002113 static Object* Allocate(int at_least_space_for);
2114
2115 // Returns the key at entry.
2116 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
2117
2118 // Tells whether k is a real key. Null and undefined are not allowed
2119 // as keys and can be used to indicate missing or deleted elements.
2120 bool IsKey(Object* k) {
2121 return !k->IsNull() && !k->IsUndefined();
2122 }
2123
2124 // Garbage collection support.
2125 void IteratePrefix(ObjectVisitor* visitor);
2126 void IterateElements(ObjectVisitor* visitor);
2127
2128 // Casting.
2129 static inline HashTable* cast(Object* obj);
2130
2131 // Compute the probe offset (quadratic probing).
2132 INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
2133 return (n + n * n) >> 1;
2134 }
2135
2136 static const int kNumberOfElementsIndex = 0;
2137 static const int kCapacityIndex = 1;
2138 static const int kPrefixStartIndex = 2;
2139 static const int kElementsStartIndex =
2140 kPrefixStartIndex + Shape::kPrefixSize;
2141 static const int kEntrySize = Shape::kEntrySize;
2142 static const int kElementsStartOffset =
2143 kHeaderSize + kElementsStartIndex * kPointerSize;
2144
2145 // Constant used for denoting a absent entry.
2146 static const int kNotFound = -1;
2147
2148 // Find entry for key otherwise return -1.
2149 int FindEntry(Key key);
2150
2151 protected:
2152
2153 // Find the entry at which to insert element with the given key that
2154 // has the given hash value.
2155 uint32_t FindInsertionEntry(uint32_t hash);
2156
2157 // Returns the index for an entry (of the key)
2158 static inline int EntryToIndex(int entry) {
2159 return (entry * kEntrySize) + kElementsStartIndex;
2160 }
2161
Steve Block3ce2e202009-11-05 08:53:23 +00002162 // Update the number of elements in the hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002163 void SetNumberOfElements(int nof) {
2164 fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof));
2165 }
2166
2167 // Sets the capacity of the hash table.
2168 void SetCapacity(int capacity) {
2169 // To scale a computed hash code to fit within the hash table, we
2170 // use bit-wise AND with a mask, so the capacity must be positive
2171 // and non-zero.
2172 ASSERT(capacity > 0);
2173 fast_set(this, kCapacityIndex, Smi::FromInt(capacity));
2174 }
2175
2176
2177 // Returns probe entry.
2178 static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
2179 ASSERT(IsPowerOf2(size));
2180 return (hash + GetProbeOffset(number)) & (size - 1);
2181 }
2182
2183 // Ensure enough space for n additional elements.
2184 Object* EnsureCapacity(int n, Key key);
2185};
2186
2187
2188
2189// HashTableKey is an abstract superclass for virtual key behavior.
2190class HashTableKey {
2191 public:
2192 // Returns whether the other object matches this key.
2193 virtual bool IsMatch(Object* other) = 0;
2194 // Returns the hash value for this key.
2195 virtual uint32_t Hash() = 0;
2196 // Returns the hash value for object.
2197 virtual uint32_t HashForObject(Object* key) = 0;
Steve Block3ce2e202009-11-05 08:53:23 +00002198 // Returns the key object for storing into the hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002199 // If allocations fails a failure object is returned.
2200 virtual Object* AsObject() = 0;
2201 // Required.
2202 virtual ~HashTableKey() {}
2203};
2204
2205class SymbolTableShape {
2206 public:
2207 static bool IsMatch(HashTableKey* key, Object* value) {
2208 return key->IsMatch(value);
2209 }
2210 static uint32_t Hash(HashTableKey* key) {
2211 return key->Hash();
2212 }
2213 static uint32_t HashForObject(HashTableKey* key, Object* object) {
2214 return key->HashForObject(object);
2215 }
2216 static Object* AsObject(HashTableKey* key) {
2217 return key->AsObject();
2218 }
2219
2220 static const int kPrefixSize = 0;
2221 static const int kEntrySize = 1;
2222};
2223
2224// SymbolTable.
2225//
2226// No special elements in the prefix and the element size is 1
2227// because only the symbol itself (the key) needs to be stored.
2228class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> {
2229 public:
2230 // Find symbol in the symbol table. If it is not there yet, it is
2231 // added. The return value is the symbol table which might have
2232 // been enlarged. If the return value is not a failure, the symbol
2233 // pointer *s is set to the symbol found.
2234 Object* LookupSymbol(Vector<const char> str, Object** s);
2235 Object* LookupString(String* key, Object** s);
2236
2237 // Looks up a symbol that is equal to the given string and returns
2238 // true if it is found, assigning the symbol to the given output
2239 // parameter.
2240 bool LookupSymbolIfExists(String* str, String** symbol);
2241
2242 // Casting.
2243 static inline SymbolTable* cast(Object* obj);
2244
2245 private:
2246 Object* LookupKey(HashTableKey* key, Object** s);
2247
2248 DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable);
2249};
2250
2251
2252class MapCacheShape {
2253 public:
2254 static bool IsMatch(HashTableKey* key, Object* value) {
2255 return key->IsMatch(value);
2256 }
2257 static uint32_t Hash(HashTableKey* key) {
2258 return key->Hash();
2259 }
2260
2261 static uint32_t HashForObject(HashTableKey* key, Object* object) {
2262 return key->HashForObject(object);
2263 }
2264
2265 static Object* AsObject(HashTableKey* key) {
2266 return key->AsObject();
2267 }
2268
2269 static const int kPrefixSize = 0;
2270 static const int kEntrySize = 2;
2271};
2272
2273
2274// MapCache.
2275//
2276// Maps keys that are a fixed array of symbols to a map.
2277// Used for canonicalize maps for object literals.
2278class MapCache: public HashTable<MapCacheShape, HashTableKey*> {
2279 public:
2280 // Find cached value for a string key, otherwise return null.
2281 Object* Lookup(FixedArray* key);
2282 Object* Put(FixedArray* key, Map* value);
2283 static inline MapCache* cast(Object* obj);
2284
2285 private:
2286 DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache);
2287};
2288
2289
2290template <typename Shape, typename Key>
2291class Dictionary: public HashTable<Shape, Key> {
2292 public:
2293
2294 static inline Dictionary<Shape, Key>* cast(Object* obj) {
2295 return reinterpret_cast<Dictionary<Shape, Key>*>(obj);
2296 }
2297
2298 // Returns the value at entry.
2299 Object* ValueAt(int entry) {
2300 return get(HashTable<Shape, Key>::EntryToIndex(entry)+1);
2301 }
2302
2303 // Set the value for entry.
2304 void ValueAtPut(int entry, Object* value) {
2305 set(HashTable<Shape, Key>::EntryToIndex(entry)+1, value);
2306 }
2307
2308 // Returns the property details for the property at entry.
2309 PropertyDetails DetailsAt(int entry) {
2310 ASSERT(entry >= 0); // Not found is -1, which is not caught by get().
2311 return PropertyDetails(
2312 Smi::cast(get(HashTable<Shape, Key>::EntryToIndex(entry) + 2)));
2313 }
2314
2315 // Set the details for entry.
2316 void DetailsAtPut(int entry, PropertyDetails value) {
2317 set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi());
2318 }
2319
2320 // Sorting support
2321 void CopyValuesTo(FixedArray* elements);
2322
2323 // Delete a property from the dictionary.
2324 Object* DeleteProperty(int entry, JSObject::DeleteMode mode);
2325
2326 // Returns the number of elements in the dictionary filtering out properties
2327 // with the specified attributes.
2328 int NumberOfElementsFilterAttributes(PropertyAttributes filter);
2329
2330 // Returns the number of enumerable elements in the dictionary.
2331 int NumberOfEnumElements();
2332
2333 // Copies keys to preallocated fixed array.
2334 void CopyKeysTo(FixedArray* storage, PropertyAttributes filter);
2335 // Fill in details for properties into storage.
2336 void CopyKeysTo(FixedArray* storage);
2337
2338 // Accessors for next enumeration index.
2339 void SetNextEnumerationIndex(int index) {
2340 fast_set(this, kNextEnumerationIndexIndex, Smi::FromInt(index));
2341 }
2342
2343 int NextEnumerationIndex() {
2344 return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value();
2345 }
2346
2347 // Returns a new array for dictionary usage. Might return Failure.
2348 static Object* Allocate(int at_least_space_for);
2349
2350 // Ensure enough space for n additional elements.
2351 Object* EnsureCapacity(int n, Key key);
2352
2353#ifdef DEBUG
2354 void Print();
2355#endif
2356 // Returns the key (slow).
2357 Object* SlowReverseLookup(Object* value);
2358
2359 // Sets the entry to (key, value) pair.
2360 inline void SetEntry(int entry,
2361 Object* key,
2362 Object* value,
2363 PropertyDetails details);
2364
2365 Object* Add(Key key, Object* value, PropertyDetails details);
2366
2367 protected:
2368 // Generic at put operation.
2369 Object* AtPut(Key key, Object* value);
2370
2371 // Add entry to dictionary.
2372 Object* AddEntry(Key key,
2373 Object* value,
2374 PropertyDetails details,
2375 uint32_t hash);
2376
2377 // Generate new enumeration indices to avoid enumeration index overflow.
2378 Object* GenerateNewEnumerationIndices();
2379 static const int kMaxNumberKeyIndex =
2380 HashTable<Shape, Key>::kPrefixStartIndex;
2381 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
2382};
2383
2384
2385class StringDictionaryShape {
2386 public:
2387 static inline bool IsMatch(String* key, Object* other);
2388 static inline uint32_t Hash(String* key);
2389 static inline uint32_t HashForObject(String* key, Object* object);
2390 static inline Object* AsObject(String* key);
2391 static const int kPrefixSize = 2;
2392 static const int kEntrySize = 3;
2393 static const bool kIsEnumerable = true;
2394};
2395
2396
2397class StringDictionary: public Dictionary<StringDictionaryShape, String*> {
2398 public:
2399 static inline StringDictionary* cast(Object* obj) {
2400 ASSERT(obj->IsDictionary());
2401 return reinterpret_cast<StringDictionary*>(obj);
2402 }
2403
2404 // Copies enumerable keys to preallocated fixed array.
2405 void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array);
2406
2407 // For transforming properties of a JSObject.
2408 Object* TransformPropertiesToFastFor(JSObject* obj,
2409 int unused_property_fields);
2410};
2411
2412
2413class NumberDictionaryShape {
2414 public:
2415 static inline bool IsMatch(uint32_t key, Object* other);
2416 static inline uint32_t Hash(uint32_t key);
2417 static inline uint32_t HashForObject(uint32_t key, Object* object);
2418 static inline Object* AsObject(uint32_t key);
2419 static const int kPrefixSize = 2;
2420 static const int kEntrySize = 3;
2421 static const bool kIsEnumerable = false;
2422};
2423
2424
2425class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> {
2426 public:
2427 static NumberDictionary* cast(Object* obj) {
2428 ASSERT(obj->IsDictionary());
2429 return reinterpret_cast<NumberDictionary*>(obj);
2430 }
2431
2432 // Type specific at put (default NONE attributes is used when adding).
2433 Object* AtNumberPut(uint32_t key, Object* value);
2434 Object* AddNumberEntry(uint32_t key,
2435 Object* value,
2436 PropertyDetails details);
2437
2438 // Set an existing entry or add a new one if needed.
2439 Object* Set(uint32_t key, Object* value, PropertyDetails details);
2440
2441 void UpdateMaxNumberKey(uint32_t key);
2442
2443 // If slow elements are required we will never go back to fast-case
2444 // for the elements kept in this dictionary. We require slow
2445 // elements if an element has been added at an index larger than
2446 // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called
2447 // when defining a getter or setter with a number key.
2448 inline bool requires_slow_elements();
2449 inline void set_requires_slow_elements();
2450
2451 // Get the value of the max number key that has been added to this
2452 // dictionary. max_number_key can only be called if
2453 // requires_slow_elements returns false.
2454 inline uint32_t max_number_key();
2455
2456 // Remove all entries were key is a number and (from <= key && key < to).
2457 void RemoveNumberEntries(uint32_t from, uint32_t to);
2458
2459 // Bit masks.
2460 static const int kRequiresSlowElementsMask = 1;
2461 static const int kRequiresSlowElementsTagSize = 1;
2462 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
2463};
2464
2465
2466// ByteArray represents fixed sized byte arrays. Used by the outside world,
2467// such as PCRE, and also by the memory allocator and garbage collector to
2468// fill in free blocks in the heap.
2469class ByteArray: public Array {
2470 public:
2471 // Setter and getter.
2472 inline byte get(int index);
2473 inline void set(int index, byte value);
2474
2475 // Treat contents as an int array.
2476 inline int get_int(int index);
2477
2478 static int SizeFor(int length) {
2479 return OBJECT_SIZE_ALIGN(kHeaderSize + length);
2480 }
2481 // We use byte arrays for free blocks in the heap. Given a desired size in
2482 // bytes that is a multiple of the word size and big enough to hold a byte
2483 // array, this function returns the number of elements a byte array should
2484 // have.
2485 static int LengthFor(int size_in_bytes) {
2486 ASSERT(IsAligned(size_in_bytes, kPointerSize));
2487 ASSERT(size_in_bytes >= kHeaderSize);
2488 return size_in_bytes - kHeaderSize;
2489 }
2490
2491 // Returns data start address.
2492 inline Address GetDataStartAddress();
2493
2494 // Returns a pointer to the ByteArray object for a given data start address.
2495 static inline ByteArray* FromDataStartAddress(Address address);
2496
2497 // Casting.
2498 static inline ByteArray* cast(Object* obj);
2499
2500 // Dispatched behavior.
2501 int ByteArraySize() { return SizeFor(length()); }
2502#ifdef DEBUG
2503 void ByteArrayPrint();
2504 void ByteArrayVerify();
2505#endif
2506
2507 // ByteArray headers are not quadword aligned.
2508 static const int kHeaderSize = Array::kHeaderSize;
2509 static const int kAlignedSize = Array::kAlignedSize;
2510
2511 private:
2512 DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray);
2513};
2514
2515
2516// A PixelArray represents a fixed-size byte array with special semantics
2517// used for implementing the CanvasPixelArray object. Please see the
2518// specification at:
2519// http://www.whatwg.org/specs/web-apps/current-work/
2520// multipage/the-canvas-element.html#canvaspixelarray
2521// In particular, write access clamps the value written to 0 or 255 if the
2522// value written is outside this range.
2523class PixelArray: public Array {
2524 public:
2525 // [external_pointer]: The pointer to the external memory area backing this
2526 // pixel array.
2527 DECL_ACCESSORS(external_pointer, uint8_t) // Pointer to the data store.
2528
2529 // Setter and getter.
2530 inline uint8_t get(int index);
2531 inline void set(int index, uint8_t value);
2532
2533 // This accessor applies the correct conversion from Smi, HeapNumber and
2534 // undefined and clamps the converted value between 0 and 255.
2535 Object* SetValue(uint32_t index, Object* value);
2536
2537 // Casting.
2538 static inline PixelArray* cast(Object* obj);
2539
2540#ifdef DEBUG
2541 void PixelArrayPrint();
2542 void PixelArrayVerify();
2543#endif // DEBUG
2544
Steve Block3ce2e202009-11-05 08:53:23 +00002545 // Maximal acceptable length for a pixel array.
2546 static const int kMaxLength = 0x3fffffff;
2547
Steve Blocka7e24c12009-10-30 11:49:00 +00002548 // PixelArray headers are not quadword aligned.
2549 static const int kExternalPointerOffset = Array::kAlignedSize;
2550 static const int kHeaderSize = kExternalPointerOffset + kPointerSize;
2551 static const int kAlignedSize = OBJECT_SIZE_ALIGN(kHeaderSize);
2552
2553 private:
2554 DISALLOW_IMPLICIT_CONSTRUCTORS(PixelArray);
2555};
2556
2557
Steve Block3ce2e202009-11-05 08:53:23 +00002558// An ExternalArray represents a fixed-size array of primitive values
2559// which live outside the JavaScript heap. Its subclasses are used to
2560// implement the CanvasArray types being defined in the WebGL
2561// specification. As of this writing the first public draft is not yet
2562// available, but Khronos members can access the draft at:
2563// https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html
2564//
2565// The semantics of these arrays differ from CanvasPixelArray.
2566// Out-of-range values passed to the setter are converted via a C
2567// cast, not clamping. Out-of-range indices cause exceptions to be
2568// raised rather than being silently ignored.
2569class ExternalArray: public Array {
2570 public:
2571 // [external_pointer]: The pointer to the external memory area backing this
2572 // external array.
2573 DECL_ACCESSORS(external_pointer, void) // Pointer to the data store.
2574
2575 // Casting.
2576 static inline ExternalArray* cast(Object* obj);
2577
2578 // Maximal acceptable length for an external array.
2579 static const int kMaxLength = 0x3fffffff;
2580
2581 // ExternalArray headers are not quadword aligned.
2582 static const int kExternalPointerOffset = Array::kAlignedSize;
2583 static const int kHeaderSize = kExternalPointerOffset + kPointerSize;
2584 static const int kAlignedSize = OBJECT_SIZE_ALIGN(kHeaderSize);
2585
2586 private:
2587 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray);
2588};
2589
2590
2591class ExternalByteArray: public ExternalArray {
2592 public:
2593 // Setter and getter.
2594 inline int8_t get(int index);
2595 inline void set(int index, int8_t value);
2596
2597 // This accessor applies the correct conversion from Smi, HeapNumber
2598 // and undefined.
2599 Object* SetValue(uint32_t index, Object* value);
2600
2601 // Casting.
2602 static inline ExternalByteArray* cast(Object* obj);
2603
2604#ifdef DEBUG
2605 void ExternalByteArrayPrint();
2606 void ExternalByteArrayVerify();
2607#endif // DEBUG
2608
2609 private:
2610 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray);
2611};
2612
2613
2614class ExternalUnsignedByteArray: public ExternalArray {
2615 public:
2616 // Setter and getter.
2617 inline uint8_t get(int index);
2618 inline void set(int index, uint8_t value);
2619
2620 // This accessor applies the correct conversion from Smi, HeapNumber
2621 // and undefined.
2622 Object* SetValue(uint32_t index, Object* value);
2623
2624 // Casting.
2625 static inline ExternalUnsignedByteArray* cast(Object* obj);
2626
2627#ifdef DEBUG
2628 void ExternalUnsignedByteArrayPrint();
2629 void ExternalUnsignedByteArrayVerify();
2630#endif // DEBUG
2631
2632 private:
2633 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray);
2634};
2635
2636
2637class ExternalShortArray: public ExternalArray {
2638 public:
2639 // Setter and getter.
2640 inline int16_t get(int index);
2641 inline void set(int index, int16_t value);
2642
2643 // This accessor applies the correct conversion from Smi, HeapNumber
2644 // and undefined.
2645 Object* SetValue(uint32_t index, Object* value);
2646
2647 // Casting.
2648 static inline ExternalShortArray* cast(Object* obj);
2649
2650#ifdef DEBUG
2651 void ExternalShortArrayPrint();
2652 void ExternalShortArrayVerify();
2653#endif // DEBUG
2654
2655 private:
2656 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray);
2657};
2658
2659
2660class ExternalUnsignedShortArray: public ExternalArray {
2661 public:
2662 // Setter and getter.
2663 inline uint16_t get(int index);
2664 inline void set(int index, uint16_t value);
2665
2666 // This accessor applies the correct conversion from Smi, HeapNumber
2667 // and undefined.
2668 Object* SetValue(uint32_t index, Object* value);
2669
2670 // Casting.
2671 static inline ExternalUnsignedShortArray* cast(Object* obj);
2672
2673#ifdef DEBUG
2674 void ExternalUnsignedShortArrayPrint();
2675 void ExternalUnsignedShortArrayVerify();
2676#endif // DEBUG
2677
2678 private:
2679 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray);
2680};
2681
2682
2683class ExternalIntArray: public ExternalArray {
2684 public:
2685 // Setter and getter.
2686 inline int32_t get(int index);
2687 inline void set(int index, int32_t value);
2688
2689 // This accessor applies the correct conversion from Smi, HeapNumber
2690 // and undefined.
2691 Object* SetValue(uint32_t index, Object* value);
2692
2693 // Casting.
2694 static inline ExternalIntArray* cast(Object* obj);
2695
2696#ifdef DEBUG
2697 void ExternalIntArrayPrint();
2698 void ExternalIntArrayVerify();
2699#endif // DEBUG
2700
2701 private:
2702 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray);
2703};
2704
2705
2706class ExternalUnsignedIntArray: public ExternalArray {
2707 public:
2708 // Setter and getter.
2709 inline uint32_t get(int index);
2710 inline void set(int index, uint32_t value);
2711
2712 // This accessor applies the correct conversion from Smi, HeapNumber
2713 // and undefined.
2714 Object* SetValue(uint32_t index, Object* value);
2715
2716 // Casting.
2717 static inline ExternalUnsignedIntArray* cast(Object* obj);
2718
2719#ifdef DEBUG
2720 void ExternalUnsignedIntArrayPrint();
2721 void ExternalUnsignedIntArrayVerify();
2722#endif // DEBUG
2723
2724 private:
2725 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray);
2726};
2727
2728
2729class ExternalFloatArray: public ExternalArray {
2730 public:
2731 // Setter and getter.
2732 inline float get(int index);
2733 inline void set(int index, float value);
2734
2735 // This accessor applies the correct conversion from Smi, HeapNumber
2736 // and undefined.
2737 Object* SetValue(uint32_t index, Object* value);
2738
2739 // Casting.
2740 static inline ExternalFloatArray* cast(Object* obj);
2741
2742#ifdef DEBUG
2743 void ExternalFloatArrayPrint();
2744 void ExternalFloatArrayVerify();
2745#endif // DEBUG
2746
2747 private:
2748 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray);
2749};
2750
2751
Steve Blocka7e24c12009-10-30 11:49:00 +00002752// Code describes objects with on-the-fly generated machine code.
2753class Code: public HeapObject {
2754 public:
2755 // Opaque data type for encapsulating code flags like kind, inline
2756 // cache state, and arguments count.
2757 enum Flags { };
2758
2759 enum Kind {
2760 FUNCTION,
2761 STUB,
2762 BUILTIN,
2763 LOAD_IC,
2764 KEYED_LOAD_IC,
2765 CALL_IC,
2766 STORE_IC,
2767 KEYED_STORE_IC,
2768 // No more than eight kinds. The value currently encoded in three bits in
2769 // Flags.
2770
2771 // Pseudo-kinds.
2772 REGEXP = BUILTIN,
2773 FIRST_IC_KIND = LOAD_IC,
2774 LAST_IC_KIND = KEYED_STORE_IC
2775 };
2776
2777 enum {
2778 NUMBER_OF_KINDS = KEYED_STORE_IC + 1
2779 };
2780
2781#ifdef ENABLE_DISASSEMBLER
2782 // Printing
2783 static const char* Kind2String(Kind kind);
2784 static const char* ICState2String(InlineCacheState state);
2785 static const char* PropertyType2String(PropertyType type);
2786 void Disassemble(const char* name);
2787#endif // ENABLE_DISASSEMBLER
2788
2789 // [instruction_size]: Size of the native instructions
2790 inline int instruction_size();
2791 inline void set_instruction_size(int value);
2792
2793 // [relocation_size]: Size of relocation information.
2794 inline int relocation_size();
2795 inline void set_relocation_size(int value);
2796
2797 // [sinfo_size]: Size of scope information.
2798 inline int sinfo_size();
2799 inline void set_sinfo_size(int value);
2800
2801 // [flags]: Various code flags.
2802 inline Flags flags();
2803 inline void set_flags(Flags flags);
2804
2805 // [flags]: Access to specific code flags.
2806 inline Kind kind();
2807 inline InlineCacheState ic_state(); // Only valid for IC stubs.
2808 inline InLoopFlag ic_in_loop(); // Only valid for IC stubs.
2809 inline PropertyType type(); // Only valid for monomorphic IC stubs.
2810 inline int arguments_count(); // Only valid for call IC stubs.
2811
2812 // Testers for IC stub kinds.
2813 inline bool is_inline_cache_stub();
2814 inline bool is_load_stub() { return kind() == LOAD_IC; }
2815 inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; }
2816 inline bool is_store_stub() { return kind() == STORE_IC; }
2817 inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; }
2818 inline bool is_call_stub() { return kind() == CALL_IC; }
2819
2820 // [major_key]: For kind STUB, the major key.
2821 inline CodeStub::Major major_key();
2822 inline void set_major_key(CodeStub::Major major);
2823
2824 // Flags operations.
2825 static inline Flags ComputeFlags(Kind kind,
2826 InLoopFlag in_loop = NOT_IN_LOOP,
2827 InlineCacheState ic_state = UNINITIALIZED,
2828 PropertyType type = NORMAL,
2829 int argc = -1);
2830
2831 static inline Flags ComputeMonomorphicFlags(
2832 Kind kind,
2833 PropertyType type,
2834 InLoopFlag in_loop = NOT_IN_LOOP,
2835 int argc = -1);
2836
2837 static inline Kind ExtractKindFromFlags(Flags flags);
2838 static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
2839 static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags);
2840 static inline PropertyType ExtractTypeFromFlags(Flags flags);
2841 static inline int ExtractArgumentsCountFromFlags(Flags flags);
2842 static inline Flags RemoveTypeFromFlags(Flags flags);
2843
2844 // Convert a target address into a code object.
2845 static inline Code* GetCodeFromTargetAddress(Address address);
2846
2847 // Returns the address of the first instruction.
2848 inline byte* instruction_start();
2849
2850 // Returns the size of the instructions, padding, and relocation information.
2851 inline int body_size();
2852
2853 // Returns the address of the first relocation info (read backwards!).
2854 inline byte* relocation_start();
2855
2856 // Code entry point.
2857 inline byte* entry();
2858
2859 // Returns true if pc is inside this object's instructions.
2860 inline bool contains(byte* pc);
2861
2862 // Returns the address of the scope information.
2863 inline byte* sinfo_start();
2864
2865 // Relocate the code by delta bytes. Called to signal that this code
2866 // object has been moved by delta bytes.
2867 void Relocate(int delta);
2868
2869 // Migrate code described by desc.
2870 void CopyFrom(const CodeDesc& desc);
2871
2872 // Returns the object size for a given body and sinfo size (Used for
2873 // allocation).
2874 static int SizeFor(int body_size, int sinfo_size) {
2875 ASSERT_SIZE_TAG_ALIGNED(body_size);
2876 ASSERT_SIZE_TAG_ALIGNED(sinfo_size);
2877 return RoundUp(kHeaderSize + body_size + sinfo_size, kCodeAlignment);
2878 }
2879
2880 // Calculate the size of the code object to report for log events. This takes
2881 // the layout of the code object into account.
2882 int ExecutableSize() {
2883 // Check that the assumptions about the layout of the code object holds.
2884 ASSERT_EQ(static_cast<int>(instruction_start() - address()),
2885 Code::kHeaderSize);
2886 return instruction_size() + Code::kHeaderSize;
2887 }
2888
2889 // Locating source position.
2890 int SourcePosition(Address pc);
2891 int SourceStatementPosition(Address pc);
2892
2893 // Casting.
2894 static inline Code* cast(Object* obj);
2895
2896 // Dispatched behavior.
2897 int CodeSize() { return SizeFor(body_size(), sinfo_size()); }
2898 void CodeIterateBody(ObjectVisitor* v);
2899#ifdef DEBUG
2900 void CodePrint();
2901 void CodeVerify();
2902#endif
2903 // Code entry points are aligned to 32 bytes.
2904 static const int kCodeAlignment = 32;
2905 static const int kCodeAlignmentMask = kCodeAlignment - 1;
2906
2907 // Layout description.
2908 static const int kInstructionSizeOffset = HeapObject::kHeaderSize;
2909 static const int kRelocationSizeOffset = kInstructionSizeOffset + kIntSize;
2910 static const int kSInfoSizeOffset = kRelocationSizeOffset + kIntSize;
2911 static const int kFlagsOffset = kSInfoSizeOffset + kIntSize;
2912 static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize;
2913 // Add padding to align the instruction start following right after
2914 // the Code object header.
2915 static const int kHeaderSize =
2916 (kKindSpecificFlagsOffset + kIntSize + kCodeAlignmentMask) &
2917 ~kCodeAlignmentMask;
2918
2919 // Byte offsets within kKindSpecificFlagsOffset.
2920 static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset + 1;
2921
2922 // Flags layout.
2923 static const int kFlagsICStateShift = 0;
2924 static const int kFlagsICInLoopShift = 3;
2925 static const int kFlagsKindShift = 4;
2926 static const int kFlagsTypeShift = 7;
2927 static const int kFlagsArgumentsCountShift = 10;
2928
2929 static const int kFlagsICStateMask = 0x00000007; // 0000000111
2930 static const int kFlagsICInLoopMask = 0x00000008; // 0000001000
2931 static const int kFlagsKindMask = 0x00000070; // 0001110000
2932 static const int kFlagsTypeMask = 0x00000380; // 1110000000
2933 static const int kFlagsArgumentsCountMask = 0xFFFFFC00;
2934
2935 static const int kFlagsNotUsedInLookup =
2936 (kFlagsICInLoopMask | kFlagsTypeMask);
2937
2938 private:
2939 DISALLOW_IMPLICIT_CONSTRUCTORS(Code);
2940};
2941
2942
2943// All heap objects have a Map that describes their structure.
2944// A Map contains information about:
2945// - Size information about the object
2946// - How to iterate over an object (for garbage collection)
2947class Map: public HeapObject {
2948 public:
2949 // Instance size.
2950 inline int instance_size();
2951 inline void set_instance_size(int value);
2952
2953 // Count of properties allocated in the object.
2954 inline int inobject_properties();
2955 inline void set_inobject_properties(int value);
2956
2957 // Count of property fields pre-allocated in the object when first allocated.
2958 inline int pre_allocated_property_fields();
2959 inline void set_pre_allocated_property_fields(int value);
2960
2961 // Instance type.
2962 inline InstanceType instance_type();
2963 inline void set_instance_type(InstanceType value);
2964
2965 // Tells how many unused property fields are available in the
2966 // instance (only used for JSObject in fast mode).
2967 inline int unused_property_fields();
2968 inline void set_unused_property_fields(int value);
2969
2970 // Bit field.
2971 inline byte bit_field();
2972 inline void set_bit_field(byte value);
2973
2974 // Bit field 2.
2975 inline byte bit_field2();
2976 inline void set_bit_field2(byte value);
2977
2978 // Tells whether the object in the prototype property will be used
2979 // for instances created from this function. If the prototype
2980 // property is set to a value that is not a JSObject, the prototype
2981 // property will not be used to create instances of the function.
2982 // See ECMA-262, 13.2.2.
2983 inline void set_non_instance_prototype(bool value);
2984 inline bool has_non_instance_prototype();
2985
2986 // Tells whether the instance with this map should be ignored by the
2987 // __proto__ accessor.
2988 inline void set_is_hidden_prototype() {
2989 set_bit_field(bit_field() | (1 << kIsHiddenPrototype));
2990 }
2991
2992 inline bool is_hidden_prototype() {
2993 return ((1 << kIsHiddenPrototype) & bit_field()) != 0;
2994 }
2995
2996 // Records and queries whether the instance has a named interceptor.
2997 inline void set_has_named_interceptor() {
2998 set_bit_field(bit_field() | (1 << kHasNamedInterceptor));
2999 }
3000
3001 inline bool has_named_interceptor() {
3002 return ((1 << kHasNamedInterceptor) & bit_field()) != 0;
3003 }
3004
3005 // Records and queries whether the instance has an indexed interceptor.
3006 inline void set_has_indexed_interceptor() {
3007 set_bit_field(bit_field() | (1 << kHasIndexedInterceptor));
3008 }
3009
3010 inline bool has_indexed_interceptor() {
3011 return ((1 << kHasIndexedInterceptor) & bit_field()) != 0;
3012 }
3013
3014 // Tells whether the instance is undetectable.
3015 // An undetectable object is a special class of JSObject: 'typeof' operator
3016 // returns undefined, ToBoolean returns false. Otherwise it behaves like
3017 // a normal JS object. It is useful for implementing undetectable
3018 // document.all in Firefox & Safari.
3019 // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
3020 inline void set_is_undetectable() {
3021 set_bit_field(bit_field() | (1 << kIsUndetectable));
3022 }
3023
3024 inline bool is_undetectable() {
3025 return ((1 << kIsUndetectable) & bit_field()) != 0;
3026 }
3027
3028 inline void set_needs_loading(bool value) {
3029 if (value) {
3030 set_bit_field2(bit_field2() | (1 << kNeedsLoading));
3031 } else {
3032 set_bit_field2(bit_field2() & ~(1 << kNeedsLoading));
3033 }
3034 }
3035
3036 // Does this object or function require a lazily loaded script to be
3037 // run before being used?
3038 inline bool needs_loading() {
3039 return ((1 << kNeedsLoading) & bit_field2()) != 0;
3040 }
3041
3042 // Tells whether the instance has a call-as-function handler.
3043 inline void set_has_instance_call_handler() {
3044 set_bit_field(bit_field() | (1 << kHasInstanceCallHandler));
3045 }
3046
3047 inline bool has_instance_call_handler() {
3048 return ((1 << kHasInstanceCallHandler) & bit_field()) != 0;
3049 }
3050
3051 // Tells whether the instance needs security checks when accessing its
3052 // properties.
3053 inline void set_is_access_check_needed(bool access_check_needed);
3054 inline bool is_access_check_needed();
3055
3056 // [prototype]: implicit prototype object.
3057 DECL_ACCESSORS(prototype, Object)
3058
3059 // [constructor]: points back to the function responsible for this map.
3060 DECL_ACCESSORS(constructor, Object)
3061
3062 // [instance descriptors]: describes the object.
3063 DECL_ACCESSORS(instance_descriptors, DescriptorArray)
3064
3065 // [stub cache]: contains stubs compiled for this map.
3066 DECL_ACCESSORS(code_cache, FixedArray)
3067
3068 // Returns a copy of the map.
3069 Object* CopyDropDescriptors();
3070
3071 // Returns a copy of the map, with all transitions dropped from the
3072 // instance descriptors.
3073 Object* CopyDropTransitions();
3074
3075 // Returns the property index for name (only valid for FAST MODE).
3076 int PropertyIndexFor(String* name);
3077
3078 // Returns the next free property index (only valid for FAST MODE).
3079 int NextFreePropertyIndex();
3080
3081 // Returns the number of properties described in instance_descriptors.
3082 int NumberOfDescribedProperties();
3083
3084 // Casting.
3085 static inline Map* cast(Object* obj);
3086
3087 // Locate an accessor in the instance descriptor.
3088 AccessorDescriptor* FindAccessor(String* name);
3089
3090 // Code cache operations.
3091
3092 // Clears the code cache.
3093 inline void ClearCodeCache();
3094
3095 // Update code cache.
3096 Object* UpdateCodeCache(String* name, Code* code);
3097
3098 // Returns the found code or undefined if absent.
3099 Object* FindInCodeCache(String* name, Code::Flags flags);
3100
3101 // Returns the non-negative index of the code object if it is in the
3102 // cache and -1 otherwise.
3103 int IndexInCodeCache(Code* code);
3104
3105 // Removes a code object from the code cache at the given index.
3106 void RemoveFromCodeCache(int index);
3107
3108 // For every transition in this map, makes the transition's
3109 // target's prototype pointer point back to this map.
3110 // This is undone in MarkCompactCollector::ClearNonLiveTransitions().
3111 void CreateBackPointers();
3112
3113 // Set all map transitions from this map to dead maps to null.
3114 // Also, restore the original prototype on the targets of these
3115 // transitions, so that we do not process this map again while
3116 // following back pointers.
3117 void ClearNonLiveTransitions(Object* real_prototype);
3118
3119 // Dispatched behavior.
3120 void MapIterateBody(ObjectVisitor* v);
3121#ifdef DEBUG
3122 void MapPrint();
3123 void MapVerify();
3124#endif
3125
3126 static const int kMaxPreAllocatedPropertyFields = 255;
3127
3128 // Layout description.
3129 static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
3130 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
3131 static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize;
3132 static const int kConstructorOffset = kPrototypeOffset + kPointerSize;
3133 static const int kInstanceDescriptorsOffset =
3134 kConstructorOffset + kPointerSize;
3135 static const int kCodeCacheOffset = kInstanceDescriptorsOffset + kPointerSize;
3136 static const int kSize = kCodeCacheOffset + kPointerSize;
3137
3138 // Byte offsets within kInstanceSizesOffset.
3139 static const int kInstanceSizeOffset = kInstanceSizesOffset + 0;
3140 static const int kInObjectPropertiesByte = 1;
3141 static const int kInObjectPropertiesOffset =
3142 kInstanceSizesOffset + kInObjectPropertiesByte;
3143 static const int kPreAllocatedPropertyFieldsByte = 2;
3144 static const int kPreAllocatedPropertyFieldsOffset =
3145 kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte;
3146 // The byte at position 3 is not in use at the moment.
3147
3148 // Byte offsets within kInstanceAttributesOffset attributes.
3149 static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0;
3150 static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1;
3151 static const int kBitFieldOffset = kInstanceAttributesOffset + 2;
3152 static const int kBitField2Offset = kInstanceAttributesOffset + 3;
3153
3154 STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset);
3155
3156 // Bit positions for bit field.
3157 static const int kUnused = 0; // To be used for marking recently used maps.
3158 static const int kHasNonInstancePrototype = 1;
3159 static const int kIsHiddenPrototype = 2;
3160 static const int kHasNamedInterceptor = 3;
3161 static const int kHasIndexedInterceptor = 4;
3162 static const int kIsUndetectable = 5;
3163 static const int kHasInstanceCallHandler = 6;
3164 static const int kIsAccessCheckNeeded = 7;
3165
3166 // Bit positions for bit field 2
3167 static const int kNeedsLoading = 0;
3168
3169 private:
3170 DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
3171};
3172
3173
3174// An abstract superclass, a marker class really, for simple structure classes.
3175// It doesn't carry much functionality but allows struct classes to me
3176// identified in the type system.
3177class Struct: public HeapObject {
3178 public:
3179 inline void InitializeBody(int object_size);
3180 static inline Struct* cast(Object* that);
3181};
3182
3183
3184// Script describes a script which has been added to the VM.
3185class Script: public Struct {
3186 public:
3187 // Script types.
3188 enum Type {
3189 TYPE_NATIVE = 0,
3190 TYPE_EXTENSION = 1,
3191 TYPE_NORMAL = 2
3192 };
3193
3194 // Script compilation types.
3195 enum CompilationType {
3196 COMPILATION_TYPE_HOST = 0,
3197 COMPILATION_TYPE_EVAL = 1,
3198 COMPILATION_TYPE_JSON = 2
3199 };
3200
3201 // [source]: the script source.
3202 DECL_ACCESSORS(source, Object)
3203
3204 // [name]: the script name.
3205 DECL_ACCESSORS(name, Object)
3206
3207 // [id]: the script id.
3208 DECL_ACCESSORS(id, Object)
3209
3210 // [line_offset]: script line offset in resource from where it was extracted.
3211 DECL_ACCESSORS(line_offset, Smi)
3212
3213 // [column_offset]: script column offset in resource from where it was
3214 // extracted.
3215 DECL_ACCESSORS(column_offset, Smi)
3216
3217 // [data]: additional data associated with this script.
3218 DECL_ACCESSORS(data, Object)
3219
3220 // [context_data]: context data for the context this script was compiled in.
3221 DECL_ACCESSORS(context_data, Object)
3222
3223 // [wrapper]: the wrapper cache.
3224 DECL_ACCESSORS(wrapper, Proxy)
3225
3226 // [type]: the script type.
3227 DECL_ACCESSORS(type, Smi)
3228
3229 // [compilation]: how the the script was compiled.
3230 DECL_ACCESSORS(compilation_type, Smi)
3231
3232 // [line_ends]: array of line ends positions.
3233 DECL_ACCESSORS(line_ends, Object)
3234
3235 // [eval_from_function]: for eval scripts the funcion from which eval was
3236 // called.
3237 DECL_ACCESSORS(eval_from_function, Object)
3238
3239 // [eval_from_instructions_offset]: the instruction offset in the code for the
3240 // function from which eval was called where eval was called.
3241 DECL_ACCESSORS(eval_from_instructions_offset, Smi)
3242
3243 static inline Script* cast(Object* obj);
3244
Steve Block3ce2e202009-11-05 08:53:23 +00003245 // If script source is an external string, check that the underlying
3246 // resource is accessible. Otherwise, always return true.
3247 inline bool HasValidSource();
3248
Steve Blocka7e24c12009-10-30 11:49:00 +00003249#ifdef DEBUG
3250 void ScriptPrint();
3251 void ScriptVerify();
3252#endif
3253
3254 static const int kSourceOffset = HeapObject::kHeaderSize;
3255 static const int kNameOffset = kSourceOffset + kPointerSize;
3256 static const int kLineOffsetOffset = kNameOffset + kPointerSize;
3257 static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
3258 static const int kDataOffset = kColumnOffsetOffset + kPointerSize;
3259 static const int kContextOffset = kDataOffset + kPointerSize;
3260 static const int kWrapperOffset = kContextOffset + kPointerSize;
3261 static const int kTypeOffset = kWrapperOffset + kPointerSize;
3262 static const int kCompilationTypeOffset = kTypeOffset + kPointerSize;
3263 static const int kLineEndsOffset = kCompilationTypeOffset + kPointerSize;
3264 static const int kIdOffset = kLineEndsOffset + kPointerSize;
3265 static const int kEvalFromFunctionOffset = kIdOffset + kPointerSize;
3266 static const int kEvalFrominstructionsOffsetOffset =
3267 kEvalFromFunctionOffset + kPointerSize;
3268 static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize;
3269
3270 private:
3271 DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
3272};
3273
3274
3275// SharedFunctionInfo describes the JSFunction information that can be
3276// shared by multiple instances of the function.
3277class SharedFunctionInfo: public HeapObject {
3278 public:
3279 // [name]: Function name.
3280 DECL_ACCESSORS(name, Object)
3281
3282 // [code]: Function code.
3283 DECL_ACCESSORS(code, Code)
3284
3285 // [construct stub]: Code stub for constructing instances of this function.
3286 DECL_ACCESSORS(construct_stub, Code)
3287
3288 // Returns if this function has been compiled to native code yet.
3289 inline bool is_compiled();
3290
3291 // [length]: The function length - usually the number of declared parameters.
3292 // Use up to 2^30 parameters.
3293 inline int length();
3294 inline void set_length(int value);
3295
3296 // [formal parameter count]: The declared number of parameters.
3297 inline int formal_parameter_count();
3298 inline void set_formal_parameter_count(int value);
3299
3300 // Set the formal parameter count so the function code will be
3301 // called without using argument adaptor frames.
3302 inline void DontAdaptArguments();
3303
3304 // [expected_nof_properties]: Expected number of properties for the function.
3305 inline int expected_nof_properties();
3306 inline void set_expected_nof_properties(int value);
3307
3308 // [instance class name]: class name for instances.
3309 DECL_ACCESSORS(instance_class_name, Object)
3310
3311 // [function data]: This field has been added for make benefit the API.
3312 // In the long run we don't want all functions to have this field but
3313 // we can fix that when we have a better model for storing hidden data
3314 // on objects.
3315 DECL_ACCESSORS(function_data, Object)
3316
3317 // [script info]: Script from which the function originates.
3318 DECL_ACCESSORS(script, Object)
3319
3320 // [start_position_and_type]: Field used to store both the source code
3321 // position, whether or not the function is a function expression,
3322 // and whether or not the function is a toplevel function. The two
3323 // least significants bit indicates whether the function is an
3324 // expression and the rest contains the source code position.
3325 inline int start_position_and_type();
3326 inline void set_start_position_and_type(int value);
3327
3328 // [debug info]: Debug information.
3329 DECL_ACCESSORS(debug_info, Object)
3330
3331 // [inferred name]: Name inferred from variable or property
3332 // assignment of this function. Used to facilitate debugging and
3333 // profiling of JavaScript code written in OO style, where almost
3334 // all functions are anonymous but are assigned to object
3335 // properties.
3336 DECL_ACCESSORS(inferred_name, String)
3337
3338 // Position of the 'function' token in the script source.
3339 inline int function_token_position();
3340 inline void set_function_token_position(int function_token_position);
3341
3342 // Position of this function in the script source.
3343 inline int start_position();
3344 inline void set_start_position(int start_position);
3345
3346 // End position of this function in the script source.
3347 inline int end_position();
3348 inline void set_end_position(int end_position);
3349
3350 // Is this function a function expression in the source code.
3351 inline bool is_expression();
3352 inline void set_is_expression(bool value);
3353
3354 // Is this function a top-level function (scripts, evals).
3355 inline bool is_toplevel();
3356 inline void set_is_toplevel(bool value);
3357
3358 // Bit field containing various information collected by the compiler to
3359 // drive optimization.
3360 inline int compiler_hints();
3361 inline void set_compiler_hints(int value);
3362
3363 // Add information on assignments of the form this.x = ...;
3364 void SetThisPropertyAssignmentsInfo(
3365 bool has_only_this_property_assignments,
3366 bool has_only_simple_this_property_assignments,
3367 FixedArray* this_property_assignments);
3368
3369 // Clear information on assignments of the form this.x = ...;
3370 void ClearThisPropertyAssignmentsInfo();
3371
3372 // Indicate that this function only consists of assignments of the form
3373 // this.x = ...;.
3374 inline bool has_only_this_property_assignments();
3375
3376 // Indicate that this function only consists of assignments of the form
3377 // this.x = y; where y is either a constant or refers to an argument.
3378 inline bool has_only_simple_this_property_assignments();
3379
3380 // For functions which only contains this property assignments this provides
3381 // access to the names for the properties assigned.
3382 DECL_ACCESSORS(this_property_assignments, Object)
3383 inline int this_property_assignments_count();
3384 inline void set_this_property_assignments_count(int value);
3385 String* GetThisPropertyAssignmentName(int index);
3386 bool IsThisPropertyAssignmentArgument(int index);
3387 int GetThisPropertyAssignmentArgument(int index);
3388 Object* GetThisPropertyAssignmentConstant(int index);
3389
3390 // [source code]: Source code for the function.
3391 bool HasSourceCode();
3392 Object* GetSourceCode();
3393
3394 // Calculate the instance size.
3395 int CalculateInstanceSize();
3396
3397 // Calculate the number of in-object properties.
3398 int CalculateInObjectProperties();
3399
3400 // Dispatched behavior.
3401 void SharedFunctionInfoIterateBody(ObjectVisitor* v);
3402 // Set max_length to -1 for unlimited length.
3403 void SourceCodePrint(StringStream* accumulator, int max_length);
3404#ifdef DEBUG
3405 void SharedFunctionInfoPrint();
3406 void SharedFunctionInfoVerify();
3407#endif
3408
3409 // Casting.
3410 static inline SharedFunctionInfo* cast(Object* obj);
3411
3412 // Constants.
3413 static const int kDontAdaptArgumentsSentinel = -1;
3414
3415 // Layout description.
3416 // (An even number of integers has a size that is a multiple of a pointer.)
3417 static const int kNameOffset = HeapObject::kHeaderSize;
3418 static const int kCodeOffset = kNameOffset + kPointerSize;
3419 static const int kConstructStubOffset = kCodeOffset + kPointerSize;
3420 static const int kLengthOffset = kConstructStubOffset + kPointerSize;
3421 static const int kFormalParameterCountOffset = kLengthOffset + kIntSize;
3422 static const int kExpectedNofPropertiesOffset =
3423 kFormalParameterCountOffset + kIntSize;
3424 static const int kStartPositionAndTypeOffset =
3425 kExpectedNofPropertiesOffset + kIntSize;
3426 static const int kEndPositionOffset = kStartPositionAndTypeOffset + kIntSize;
3427 static const int kFunctionTokenPositionOffset = kEndPositionOffset + kIntSize;
3428 static const int kInstanceClassNameOffset =
3429 kFunctionTokenPositionOffset + kIntSize;
3430 static const int kExternalReferenceDataOffset =
3431 kInstanceClassNameOffset + kPointerSize;
3432 static const int kScriptOffset = kExternalReferenceDataOffset + kPointerSize;
3433 static const int kDebugInfoOffset = kScriptOffset + kPointerSize;
3434 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize;
3435 static const int kCompilerHintsOffset = kInferredNameOffset + kPointerSize;
3436 static const int kThisPropertyAssignmentsOffset =
3437 kCompilerHintsOffset + kPointerSize;
3438 static const int kThisPropertyAssignmentsCountOffset =
3439 kThisPropertyAssignmentsOffset + kPointerSize;
3440 static const int kSize = kThisPropertyAssignmentsCountOffset + kPointerSize;
3441
3442 private:
3443 // Bit positions in length_and_flg.
3444 // The least significant bit is used as the flag.
3445 static const int kFlagBit = 0;
3446 static const int kLengthShift = 1;
3447 static const int kLengthMask = ~((1 << kLengthShift) - 1);
3448
3449 // Bit positions in start_position_and_type.
3450 // The source code start position is in the 30 most significant bits of
3451 // the start_position_and_type field.
3452 static const int kIsExpressionBit = 0;
3453 static const int kIsTopLevelBit = 1;
3454 static const int kStartPositionShift = 2;
3455 static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
3456
3457 // Bit positions in compiler_hints.
3458 static const int kHasOnlyThisPropertyAssignments = 0;
3459 static const int kHasOnlySimpleThisPropertyAssignments = 1;
3460
3461 DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo);
3462};
3463
3464
3465// JSFunction describes JavaScript functions.
3466class JSFunction: public JSObject {
3467 public:
3468 // [prototype_or_initial_map]:
3469 DECL_ACCESSORS(prototype_or_initial_map, Object)
3470
3471 // [shared_function_info]: The information about the function that
3472 // can be shared by instances.
3473 DECL_ACCESSORS(shared, SharedFunctionInfo)
3474
3475 // [context]: The context for this function.
3476 inline Context* context();
3477 inline Object* unchecked_context();
3478 inline void set_context(Object* context);
3479
3480 // [code]: The generated code object for this function. Executed
3481 // when the function is invoked, e.g. foo() or new foo(). See
3482 // [[Call]] and [[Construct]] description in ECMA-262, section
3483 // 8.6.2, page 27.
3484 inline Code* code();
3485 inline void set_code(Code* value);
3486
3487 // Tells whether this function is a context-independent boilerplate
3488 // function.
3489 inline bool IsBoilerplate();
3490
3491 // Tells whether this function is builtin.
3492 inline bool IsBuiltin();
3493
3494 // [literals]: Fixed array holding the materialized literals.
3495 //
3496 // If the function contains object, regexp or array literals, the
3497 // literals array prefix contains the object, regexp, and array
3498 // function to be used when creating these literals. This is
3499 // necessary so that we do not dynamically lookup the object, regexp
3500 // or array functions. Performing a dynamic lookup, we might end up
3501 // using the functions from a new context that we should not have
3502 // access to.
3503 DECL_ACCESSORS(literals, FixedArray)
3504
3505 // The initial map for an object created by this constructor.
3506 inline Map* initial_map();
3507 inline void set_initial_map(Map* value);
3508 inline bool has_initial_map();
3509
3510 // Get and set the prototype property on a JSFunction. If the
3511 // function has an initial map the prototype is set on the initial
3512 // map. Otherwise, the prototype is put in the initial map field
3513 // until an initial map is needed.
3514 inline bool has_prototype();
3515 inline bool has_instance_prototype();
3516 inline Object* prototype();
3517 inline Object* instance_prototype();
3518 Object* SetInstancePrototype(Object* value);
3519 Object* SetPrototype(Object* value);
3520
3521 // Accessor for this function's initial map's [[class]]
3522 // property. This is primarily used by ECMA native functions. This
3523 // method sets the class_name field of this function's initial map
3524 // to a given value. It creates an initial map if this function does
3525 // not have one. Note that this method does not copy the initial map
3526 // if it has one already, but simply replaces it with the new value.
3527 // Instances created afterwards will have a map whose [[class]] is
3528 // set to 'value', but there is no guarantees on instances created
3529 // before.
3530 Object* SetInstanceClassName(String* name);
3531
3532 // Returns if this function has been compiled to native code yet.
3533 inline bool is_compiled();
3534
3535 // Casting.
3536 static inline JSFunction* cast(Object* obj);
3537
3538 // Dispatched behavior.
3539#ifdef DEBUG
3540 void JSFunctionPrint();
3541 void JSFunctionVerify();
3542#endif
3543
3544 // Returns the number of allocated literals.
3545 inline int NumberOfLiterals();
3546
3547 // Retrieve the global context from a function's literal array.
3548 static Context* GlobalContextFromLiterals(FixedArray* literals);
3549
3550 // Layout descriptors.
3551 static const int kPrototypeOrInitialMapOffset = JSObject::kHeaderSize;
3552 static const int kSharedFunctionInfoOffset =
3553 kPrototypeOrInitialMapOffset + kPointerSize;
3554 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
3555 static const int kLiteralsOffset = kContextOffset + kPointerSize;
3556 static const int kSize = kLiteralsOffset + kPointerSize;
3557
3558 // Layout of the literals array.
3559 static const int kLiteralsPrefixSize = 1;
3560 static const int kLiteralGlobalContextIndex = 0;
3561 private:
3562 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
3563};
3564
3565
3566// JSGlobalProxy's prototype must be a JSGlobalObject or null,
3567// and the prototype is hidden. JSGlobalProxy always delegates
3568// property accesses to its prototype if the prototype is not null.
3569//
3570// A JSGlobalProxy can be reinitialized which will preserve its identity.
3571//
3572// Accessing a JSGlobalProxy requires security check.
3573
3574class JSGlobalProxy : public JSObject {
3575 public:
3576 // [context]: the owner global context of this proxy object.
3577 // It is null value if this object is not used by any context.
3578 DECL_ACCESSORS(context, Object)
3579
3580 // Casting.
3581 static inline JSGlobalProxy* cast(Object* obj);
3582
3583 // Dispatched behavior.
3584#ifdef DEBUG
3585 void JSGlobalProxyPrint();
3586 void JSGlobalProxyVerify();
3587#endif
3588
3589 // Layout description.
3590 static const int kContextOffset = JSObject::kHeaderSize;
3591 static const int kSize = kContextOffset + kPointerSize;
3592
3593 private:
3594
3595 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
3596};
3597
3598
3599// Forward declaration.
3600class JSBuiltinsObject;
3601
3602// Common super class for JavaScript global objects and the special
3603// builtins global objects.
3604class GlobalObject: public JSObject {
3605 public:
3606 // [builtins]: the object holding the runtime routines written in JS.
3607 DECL_ACCESSORS(builtins, JSBuiltinsObject)
3608
3609 // [global context]: the global context corresponding to this global object.
3610 DECL_ACCESSORS(global_context, Context)
3611
3612 // [global receiver]: the global receiver object of the context
3613 DECL_ACCESSORS(global_receiver, JSObject)
3614
3615 // Retrieve the property cell used to store a property.
3616 Object* GetPropertyCell(LookupResult* result);
3617
3618 // Ensure that the global object has a cell for the given property name.
3619 Object* EnsurePropertyCell(String* name);
3620
3621 // Casting.
3622 static inline GlobalObject* cast(Object* obj);
3623
3624 // Layout description.
3625 static const int kBuiltinsOffset = JSObject::kHeaderSize;
3626 static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize;
3627 static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize;
3628 static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize;
3629
3630 private:
3631 friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs;
3632
3633 DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject);
3634};
3635
3636
3637// JavaScript global object.
3638class JSGlobalObject: public GlobalObject {
3639 public:
3640
3641 // Casting.
3642 static inline JSGlobalObject* cast(Object* obj);
3643
3644 // Dispatched behavior.
3645#ifdef DEBUG
3646 void JSGlobalObjectPrint();
3647 void JSGlobalObjectVerify();
3648#endif
3649
3650 // Layout description.
3651 static const int kSize = GlobalObject::kHeaderSize;
3652
3653 private:
3654 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject);
3655};
3656
3657
3658// Builtins global object which holds the runtime routines written in
3659// JavaScript.
3660class JSBuiltinsObject: public GlobalObject {
3661 public:
3662 // Accessors for the runtime routines written in JavaScript.
3663 inline Object* javascript_builtin(Builtins::JavaScript id);
3664 inline void set_javascript_builtin(Builtins::JavaScript id, Object* value);
3665
3666 // Casting.
3667 static inline JSBuiltinsObject* cast(Object* obj);
3668
3669 // Dispatched behavior.
3670#ifdef DEBUG
3671 void JSBuiltinsObjectPrint();
3672 void JSBuiltinsObjectVerify();
3673#endif
3674
3675 // Layout description. The size of the builtins object includes
3676 // room for one pointer per runtime routine written in javascript.
3677 static const int kJSBuiltinsCount = Builtins::id_count;
3678 static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize;
3679 static const int kSize =
3680 kJSBuiltinsOffset + (kJSBuiltinsCount * kPointerSize);
3681 private:
3682 DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject);
3683};
3684
3685
3686// Representation for JS Wrapper objects, String, Number, Boolean, Date, etc.
3687class JSValue: public JSObject {
3688 public:
3689 // [value]: the object being wrapped.
3690 DECL_ACCESSORS(value, Object)
3691
3692 // Casting.
3693 static inline JSValue* cast(Object* obj);
3694
3695 // Dispatched behavior.
3696#ifdef DEBUG
3697 void JSValuePrint();
3698 void JSValueVerify();
3699#endif
3700
3701 // Layout description.
3702 static const int kValueOffset = JSObject::kHeaderSize;
3703 static const int kSize = kValueOffset + kPointerSize;
3704
3705 private:
3706 DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue);
3707};
3708
3709// Regular expressions
3710// The regular expression holds a single reference to a FixedArray in
3711// the kDataOffset field.
3712// The FixedArray contains the following data:
3713// - tag : type of regexp implementation (not compiled yet, atom or irregexp)
3714// - reference to the original source string
3715// - reference to the original flag string
3716// If it is an atom regexp
3717// - a reference to a literal string to search for
3718// If it is an irregexp regexp:
3719// - a reference to code for ASCII inputs (bytecode or compiled).
3720// - a reference to code for UC16 inputs (bytecode or compiled).
3721// - max number of registers used by irregexp implementations.
3722// - number of capture registers (output values) of the regexp.
3723class JSRegExp: public JSObject {
3724 public:
3725 // Meaning of Type:
3726 // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
3727 // ATOM: A simple string to match against using an indexOf operation.
3728 // IRREGEXP: Compiled with Irregexp.
3729 // IRREGEXP_NATIVE: Compiled to native code with Irregexp.
3730 enum Type { NOT_COMPILED, ATOM, IRREGEXP };
3731 enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 };
3732
3733 class Flags {
3734 public:
3735 explicit Flags(uint32_t value) : value_(value) { }
3736 bool is_global() { return (value_ & GLOBAL) != 0; }
3737 bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; }
3738 bool is_multiline() { return (value_ & MULTILINE) != 0; }
3739 uint32_t value() { return value_; }
3740 private:
3741 uint32_t value_;
3742 };
3743
3744 DECL_ACCESSORS(data, Object)
3745
3746 inline Type TypeTag();
3747 inline int CaptureCount();
3748 inline Flags GetFlags();
3749 inline String* Pattern();
3750 inline Object* DataAt(int index);
3751 // Set implementation data after the object has been prepared.
3752 inline void SetDataAt(int index, Object* value);
3753 static int code_index(bool is_ascii) {
3754 if (is_ascii) {
3755 return kIrregexpASCIICodeIndex;
3756 } else {
3757 return kIrregexpUC16CodeIndex;
3758 }
3759 }
3760
3761 static inline JSRegExp* cast(Object* obj);
3762
3763 // Dispatched behavior.
3764#ifdef DEBUG
3765 void JSRegExpVerify();
3766#endif
3767
3768 static const int kDataOffset = JSObject::kHeaderSize;
3769 static const int kSize = kDataOffset + kPointerSize;
3770
3771 // Indices in the data array.
3772 static const int kTagIndex = 0;
3773 static const int kSourceIndex = kTagIndex + 1;
3774 static const int kFlagsIndex = kSourceIndex + 1;
3775 static const int kDataIndex = kFlagsIndex + 1;
3776 // The data fields are used in different ways depending on the
3777 // value of the tag.
3778 // Atom regexps (literal strings).
3779 static const int kAtomPatternIndex = kDataIndex;
3780
3781 static const int kAtomDataSize = kAtomPatternIndex + 1;
3782
3783 // Irregexp compiled code or bytecode for ASCII. If compilation
3784 // fails, this fields hold an exception object that should be
3785 // thrown if the regexp is used again.
3786 static const int kIrregexpASCIICodeIndex = kDataIndex;
3787 // Irregexp compiled code or bytecode for UC16. If compilation
3788 // fails, this fields hold an exception object that should be
3789 // thrown if the regexp is used again.
3790 static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
3791 // Maximal number of registers used by either ASCII or UC16.
3792 // Only used to check that there is enough stack space
3793 static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 2;
3794 // Number of captures in the compiled regexp.
3795 static const int kIrregexpCaptureCountIndex = kDataIndex + 3;
3796
3797 static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1;
3798};
3799
3800
3801class CompilationCacheShape {
3802 public:
3803 static inline bool IsMatch(HashTableKey* key, Object* value) {
3804 return key->IsMatch(value);
3805 }
3806
3807 static inline uint32_t Hash(HashTableKey* key) {
3808 return key->Hash();
3809 }
3810
3811 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
3812 return key->HashForObject(object);
3813 }
3814
3815 static Object* AsObject(HashTableKey* key) {
3816 return key->AsObject();
3817 }
3818
3819 static const int kPrefixSize = 0;
3820 static const int kEntrySize = 2;
3821};
3822
Steve Block3ce2e202009-11-05 08:53:23 +00003823
Steve Blocka7e24c12009-10-30 11:49:00 +00003824class CompilationCacheTable: public HashTable<CompilationCacheShape,
3825 HashTableKey*> {
3826 public:
3827 // Find cached value for a string key, otherwise return null.
3828 Object* Lookup(String* src);
3829 Object* LookupEval(String* src, Context* context);
3830 Object* LookupRegExp(String* source, JSRegExp::Flags flags);
3831 Object* Put(String* src, Object* value);
3832 Object* PutEval(String* src, Context* context, Object* value);
3833 Object* PutRegExp(String* src, JSRegExp::Flags flags, FixedArray* value);
3834
3835 static inline CompilationCacheTable* cast(Object* obj);
3836
3837 private:
3838 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable);
3839};
3840
3841
3842enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS};
3843enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL};
3844
3845
3846class StringHasher {
3847 public:
3848 inline StringHasher(int length);
3849
3850 // Returns true if the hash of this string can be computed without
3851 // looking at the contents.
3852 inline bool has_trivial_hash();
3853
3854 // Add a character to the hash and update the array index calculation.
3855 inline void AddCharacter(uc32 c);
3856
3857 // Adds a character to the hash but does not update the array index
3858 // calculation. This can only be called when it has been verified
3859 // that the input is not an array index.
3860 inline void AddCharacterNoIndex(uc32 c);
3861
3862 // Returns the value to store in the hash field of a string with
3863 // the given length and contents.
3864 uint32_t GetHashField();
3865
3866 // Returns true if the characters seen so far make up a legal array
3867 // index.
3868 bool is_array_index() { return is_array_index_; }
3869
3870 bool is_valid() { return is_valid_; }
3871
3872 void invalidate() { is_valid_ = false; }
3873
3874 private:
3875
3876 uint32_t array_index() {
3877 ASSERT(is_array_index());
3878 return array_index_;
3879 }
3880
3881 inline uint32_t GetHash();
3882
3883 int length_;
3884 uint32_t raw_running_hash_;
3885 uint32_t array_index_;
3886 bool is_array_index_;
3887 bool is_first_char_;
3888 bool is_valid_;
3889};
3890
3891
3892// The characteristics of a string are stored in its map. Retrieving these
3893// few bits of information is moderately expensive, involving two memory
3894// loads where the second is dependent on the first. To improve efficiency
3895// the shape of the string is given its own class so that it can be retrieved
3896// once and used for several string operations. A StringShape is small enough
3897// to be passed by value and is immutable, but be aware that flattening a
3898// string can potentially alter its shape. Also be aware that a GC caused by
3899// something else can alter the shape of a string due to ConsString
3900// shortcutting. Keeping these restrictions in mind has proven to be error-
3901// prone and so we no longer put StringShapes in variables unless there is a
3902// concrete performance benefit at that particular point in the code.
3903class StringShape BASE_EMBEDDED {
3904 public:
3905 inline explicit StringShape(String* s);
3906 inline explicit StringShape(Map* s);
3907 inline explicit StringShape(InstanceType t);
3908 inline bool IsSequential();
3909 inline bool IsExternal();
3910 inline bool IsCons();
3911 inline bool IsSliced();
3912 inline bool IsExternalAscii();
3913 inline bool IsExternalTwoByte();
3914 inline bool IsSequentialAscii();
3915 inline bool IsSequentialTwoByte();
3916 inline bool IsSymbol();
3917 inline StringRepresentationTag representation_tag();
3918 inline uint32_t full_representation_tag();
3919 inline uint32_t size_tag();
3920#ifdef DEBUG
3921 inline uint32_t type() { return type_; }
3922 inline void invalidate() { valid_ = false; }
3923 inline bool valid() { return valid_; }
3924#else
3925 inline void invalidate() { }
3926#endif
3927 private:
3928 uint32_t type_;
3929#ifdef DEBUG
3930 inline void set_valid() { valid_ = true; }
3931 bool valid_;
3932#else
3933 inline void set_valid() { }
3934#endif
3935};
3936
3937
3938// The String abstract class captures JavaScript string values:
3939//
3940// Ecma-262:
3941// 4.3.16 String Value
3942// A string value is a member of the type String and is a finite
3943// ordered sequence of zero or more 16-bit unsigned integer values.
3944//
3945// All string values have a length field.
3946class String: public HeapObject {
3947 public:
3948 // Get and set the length of the string.
3949 inline int length();
3950 inline void set_length(int value);
3951
3952 // Get and set the uninterpreted length field of the string. Notice
3953 // that the length field is also used to cache the hash value of
3954 // strings. In order to get or set the actual length of the string
3955 // use the length() and set_length methods.
3956 inline uint32_t length_field();
3957 inline void set_length_field(uint32_t value);
3958
3959 inline bool IsAsciiRepresentation();
3960 inline bool IsTwoByteRepresentation();
3961
3962 // Get and set individual two byte chars in the string.
3963 inline void Set(int index, uint16_t value);
3964 // Get individual two byte char in the string. Repeated calls
3965 // to this method are not efficient unless the string is flat.
3966 inline uint16_t Get(int index);
3967
3968 // Try to flatten the top level ConsString that is hiding behind this
3969 // string. This is a no-op unless the string is a ConsString or a
3970 // SlicedString. Flatten mutates the ConsString and might return a
3971 // failure.
3972 Object* TryFlatten();
3973
3974 // Try to flatten the string. Checks first inline to see if it is necessary.
3975 // Do not handle allocation failures. After calling TryFlattenIfNotFlat, the
3976 // string could still be a ConsString, in which case a failure is returned.
3977 // Use FlattenString from Handles.cc to be sure to flatten.
3978 inline Object* TryFlattenIfNotFlat();
3979
3980 Vector<const char> ToAsciiVector();
3981 Vector<const uc16> ToUC16Vector();
3982
3983 // Mark the string as an undetectable object. It only applies to
3984 // ascii and two byte string types.
3985 bool MarkAsUndetectable();
3986
3987 // Slice the string and return a substring.
3988 Object* Slice(int from, int to);
3989
3990 // String equality operations.
3991 inline bool Equals(String* other);
3992 bool IsEqualTo(Vector<const char> str);
3993
3994 // Return a UTF8 representation of the string. The string is null
3995 // terminated but may optionally contain nulls. Length is returned
3996 // in length_output if length_output is not a null pointer The string
3997 // should be nearly flat, otherwise the performance of this method may
3998 // be very slow (quadratic in the length). Setting robustness_flag to
3999 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
4000 // handles unexpected data without causing assert failures and it does not
4001 // do any heap allocations. This is useful when printing stack traces.
4002 SmartPointer<char> ToCString(AllowNullsFlag allow_nulls,
4003 RobustnessFlag robustness_flag,
4004 int offset,
4005 int length,
4006 int* length_output = 0);
4007 SmartPointer<char> ToCString(
4008 AllowNullsFlag allow_nulls = DISALLOW_NULLS,
4009 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL,
4010 int* length_output = 0);
4011
4012 int Utf8Length();
4013
4014 // Return a 16 bit Unicode representation of the string.
4015 // The string should be nearly flat, otherwise the performance of
4016 // of this method may be very bad. Setting robustness_flag to
4017 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
4018 // handles unexpected data without causing assert failures and it does not
4019 // do any heap allocations. This is useful when printing stack traces.
4020 SmartPointer<uc16> ToWideCString(
4021 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
4022
4023 // Tells whether the hash code has been computed.
4024 inline bool HasHashCode();
4025
4026 // Returns a hash value used for the property table
4027 inline uint32_t Hash();
4028
4029 static uint32_t ComputeLengthAndHashField(unibrow::CharacterStream* buffer,
4030 int length);
4031
4032 static bool ComputeArrayIndex(unibrow::CharacterStream* buffer,
4033 uint32_t* index,
4034 int length);
4035
4036 // Externalization.
4037 bool MakeExternal(v8::String::ExternalStringResource* resource);
4038 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource);
4039
4040 // Conversion.
4041 inline bool AsArrayIndex(uint32_t* index);
4042
4043 // Casting.
4044 static inline String* cast(Object* obj);
4045
4046 void PrintOn(FILE* out);
4047
4048 // For use during stack traces. Performs rudimentary sanity check.
4049 bool LooksValid();
4050
4051 // Dispatched behavior.
4052 void StringShortPrint(StringStream* accumulator);
4053#ifdef DEBUG
4054 void StringPrint();
4055 void StringVerify();
4056#endif
4057 inline bool IsFlat();
4058
4059 // Layout description.
4060 static const int kLengthOffset = HeapObject::kHeaderSize;
4061 static const int kSize = kLengthOffset + kIntSize;
4062 // Notice: kSize is not pointer-size aligned if pointers are 64-bit.
4063
4064 // Limits on sizes of different types of strings.
4065 static const int kMaxShortStringSize = 63;
4066 static const int kMaxMediumStringSize = 16383;
4067
4068 static const int kMaxArrayIndexSize = 10;
4069
4070 // Max ascii char code.
4071 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar;
4072 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar;
4073 static const int kMaxUC16CharCode = 0xffff;
4074
4075 // Minimum length for a cons or sliced string.
4076 static const int kMinNonFlatLength = 13;
4077
4078 // Mask constant for checking if a string has a computed hash code
4079 // and if it is an array index. The least significant bit indicates
4080 // whether a hash code has been computed. If the hash code has been
4081 // computed the 2nd bit tells whether the string can be used as an
4082 // array index.
4083 static const int kHashComputedMask = 1;
4084 static const int kIsArrayIndexMask = 1 << 1;
4085 static const int kNofLengthBitFields = 2;
4086
4087 // Array index strings this short can keep their index in the hash
4088 // field.
4089 static const int kMaxCachedArrayIndexLength = 7;
4090
4091 // Shift constants for retriving length and hash code from
4092 // length/hash field.
4093 static const int kHashShift = kNofLengthBitFields;
4094 static const int kShortLengthShift = kHashShift + kShortStringTag;
4095 static const int kMediumLengthShift = kHashShift + kMediumStringTag;
4096 static const int kLongLengthShift = kHashShift + kLongStringTag;
Steve Block3ce2e202009-11-05 08:53:23 +00004097 // Maximal string length that can be stored in the hash/length field.
4098 static const int kMaxLength = (1 << (32 - kLongLengthShift)) - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +00004099
4100 // Limit for truncation in short printing.
4101 static const int kMaxShortPrintLength = 1024;
4102
4103 // Support for regular expressions.
4104 const uc16* GetTwoByteData();
4105 const uc16* GetTwoByteData(unsigned start);
4106
4107 // Support for StringInputBuffer
4108 static const unibrow::byte* ReadBlock(String* input,
4109 unibrow::byte* util_buffer,
4110 unsigned capacity,
4111 unsigned* remaining,
4112 unsigned* offset);
4113 static const unibrow::byte* ReadBlock(String** input,
4114 unibrow::byte* util_buffer,
4115 unsigned capacity,
4116 unsigned* remaining,
4117 unsigned* offset);
4118
4119 // Helper function for flattening strings.
4120 template <typename sinkchar>
4121 static void WriteToFlat(String* source,
4122 sinkchar* sink,
4123 int from,
4124 int to);
4125
4126 protected:
4127 class ReadBlockBuffer {
4128 public:
4129 ReadBlockBuffer(unibrow::byte* util_buffer_,
4130 unsigned cursor_,
4131 unsigned capacity_,
4132 unsigned remaining_) :
4133 util_buffer(util_buffer_),
4134 cursor(cursor_),
4135 capacity(capacity_),
4136 remaining(remaining_) {
4137 }
4138 unibrow::byte* util_buffer;
4139 unsigned cursor;
4140 unsigned capacity;
4141 unsigned remaining;
4142 };
4143
4144 // NOTE: If you call StringInputBuffer routines on strings that are
4145 // too deeply nested trees of cons and slice strings, then this
4146 // routine will overflow the stack. Strings that are merely deeply
4147 // nested trees of cons strings do not have a problem apart from
4148 // performance.
4149
4150 static inline const unibrow::byte* ReadBlock(String* input,
4151 ReadBlockBuffer* buffer,
4152 unsigned* offset,
4153 unsigned max_chars);
4154 static void ReadBlockIntoBuffer(String* input,
4155 ReadBlockBuffer* buffer,
4156 unsigned* offset_ptr,
4157 unsigned max_chars);
4158
4159 private:
4160 // Slow case of String::Equals. This implementation works on any strings
4161 // but it is most efficient on strings that are almost flat.
4162 bool SlowEquals(String* other);
4163
4164 // Slow case of AsArrayIndex.
4165 bool SlowAsArrayIndex(uint32_t* index);
4166
4167 // Compute and set the hash code.
4168 uint32_t ComputeAndSetHash();
4169
4170 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
4171};
4172
4173
4174// The SeqString abstract class captures sequential string values.
4175class SeqString: public String {
4176 public:
4177
4178 // Casting.
4179 static inline SeqString* cast(Object* obj);
4180
4181 // Dispatched behaviour.
4182 // For regexp code.
4183 uint16_t* SeqStringGetTwoByteAddress();
4184
4185 private:
4186 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
4187};
4188
4189
4190// The AsciiString class captures sequential ascii string objects.
4191// Each character in the AsciiString is an ascii character.
4192class SeqAsciiString: public SeqString {
4193 public:
4194 // Dispatched behavior.
4195 inline uint16_t SeqAsciiStringGet(int index);
4196 inline void SeqAsciiStringSet(int index, uint16_t value);
4197
4198 // Get the address of the characters in this string.
4199 inline Address GetCharsAddress();
4200
4201 inline char* GetChars();
4202
4203 // Casting
4204 static inline SeqAsciiString* cast(Object* obj);
4205
4206 // Garbage collection support. This method is called by the
4207 // garbage collector to compute the actual size of an AsciiString
4208 // instance.
4209 inline int SeqAsciiStringSize(InstanceType instance_type);
4210
4211 // Computes the size for an AsciiString instance of a given length.
4212 static int SizeFor(int length) {
4213 return OBJECT_SIZE_ALIGN(kHeaderSize + length * kCharSize);
4214 }
4215
4216 // Layout description.
4217 static const int kHeaderSize = String::kSize;
4218 static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize);
4219
4220 // Support for StringInputBuffer.
4221 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
4222 unsigned* offset,
4223 unsigned chars);
4224 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining,
4225 unsigned* offset,
4226 unsigned chars);
4227
4228 private:
4229 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString);
4230};
4231
4232
4233// The TwoByteString class captures sequential unicode string objects.
4234// Each character in the TwoByteString is a two-byte uint16_t.
4235class SeqTwoByteString: public SeqString {
4236 public:
4237 // Dispatched behavior.
4238 inline uint16_t SeqTwoByteStringGet(int index);
4239 inline void SeqTwoByteStringSet(int index, uint16_t value);
4240
4241 // Get the address of the characters in this string.
4242 inline Address GetCharsAddress();
4243
4244 inline uc16* GetChars();
4245
4246 // For regexp code.
4247 const uint16_t* SeqTwoByteStringGetData(unsigned start);
4248
4249 // Casting
4250 static inline SeqTwoByteString* cast(Object* obj);
4251
4252 // Garbage collection support. This method is called by the
4253 // garbage collector to compute the actual size of a TwoByteString
4254 // instance.
4255 inline int SeqTwoByteStringSize(InstanceType instance_type);
4256
4257 // Computes the size for a TwoByteString instance of a given length.
4258 static int SizeFor(int length) {
4259 return OBJECT_SIZE_ALIGN(kHeaderSize + length * kShortSize);
4260 }
4261
4262 // Layout description.
4263 static const int kHeaderSize = String::kSize;
4264 static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize);
4265
4266 // Support for StringInputBuffer.
4267 inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
4268 unsigned* offset_ptr,
4269 unsigned chars);
4270
4271 private:
4272 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
4273};
4274
4275
4276// The ConsString class describes string values built by using the
4277// addition operator on strings. A ConsString is a pair where the
4278// first and second components are pointers to other string values.
4279// One or both components of a ConsString can be pointers to other
4280// ConsStrings, creating a binary tree of ConsStrings where the leaves
4281// are non-ConsString string values. The string value represented by
4282// a ConsString can be obtained by concatenating the leaf string
4283// values in a left-to-right depth-first traversal of the tree.
4284class ConsString: public String {
4285 public:
4286 // First string of the cons cell.
4287 inline String* first();
4288 // Doesn't check that the result is a string, even in debug mode. This is
4289 // useful during GC where the mark bits confuse the checks.
4290 inline Object* unchecked_first();
4291 inline void set_first(String* first,
4292 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
4293
4294 // Second string of the cons cell.
4295 inline String* second();
4296 // Doesn't check that the result is a string, even in debug mode. This is
4297 // useful during GC where the mark bits confuse the checks.
4298 inline Object* unchecked_second();
4299 inline void set_second(String* second,
4300 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
4301
4302 // Dispatched behavior.
4303 uint16_t ConsStringGet(int index);
4304
4305 // Casting.
4306 static inline ConsString* cast(Object* obj);
4307
4308 // Garbage collection support. This method is called during garbage
4309 // collection to iterate through the heap pointers in the body of
4310 // the ConsString.
4311 void ConsStringIterateBody(ObjectVisitor* v);
4312
4313 // Layout description.
4314 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
4315 static const int kSecondOffset = kFirstOffset + kPointerSize;
4316 static const int kSize = kSecondOffset + kPointerSize;
4317
4318 // Support for StringInputBuffer.
4319 inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer,
4320 unsigned* offset_ptr,
4321 unsigned chars);
4322 inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
4323 unsigned* offset_ptr,
4324 unsigned chars);
4325
4326 // Minimum length for a cons string.
4327 static const int kMinLength = 13;
4328
4329 private:
4330 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
4331};
4332
4333
4334// The SlicedString class describes string values that are slices of
4335// some other string. SlicedStrings consist of a reference to an
4336// underlying heap-allocated string value, a start index, and the
4337// length field common to all strings.
4338class SlicedString: public String {
4339 public:
4340 // The underlying string buffer.
4341 inline String* buffer();
4342 inline void set_buffer(String* buffer);
4343
4344 // The start index of the slice.
4345 inline int start();
4346 inline void set_start(int start);
4347
4348 // Dispatched behavior.
4349 uint16_t SlicedStringGet(int index);
4350
4351 // Casting.
4352 static inline SlicedString* cast(Object* obj);
4353
4354 // Garbage collection support.
4355 void SlicedStringIterateBody(ObjectVisitor* v);
4356
4357 // Layout description
4358#if V8_HOST_ARCH_64_BIT
4359 // Optimizations expect buffer to be located at same offset as a ConsString's
4360 // first substring. In 64 bit mode we have room for the start offset before
4361 // the buffer.
4362 static const int kStartOffset = String::kSize;
4363 static const int kBufferOffset = kStartOffset + kIntSize;
4364 static const int kSize = kBufferOffset + kPointerSize;
4365#else
4366 static const int kBufferOffset = String::kSize;
4367 static const int kStartOffset = kBufferOffset + kPointerSize;
4368 static const int kSize = kStartOffset + kIntSize;
4369#endif
4370
4371 // Support for StringInputBuffer.
4372 inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer,
4373 unsigned* offset_ptr,
4374 unsigned chars);
4375 inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
4376 unsigned* offset_ptr,
4377 unsigned chars);
4378
4379 private:
4380 DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString);
4381};
4382
4383
4384// The ExternalString class describes string values that are backed by
4385// a string resource that lies outside the V8 heap. ExternalStrings
4386// consist of the length field common to all strings, a pointer to the
4387// external resource. It is important to ensure (externally) that the
4388// resource is not deallocated while the ExternalString is live in the
4389// V8 heap.
4390//
4391// The API expects that all ExternalStrings are created through the
4392// API. Therefore, ExternalStrings should not be used internally.
4393class ExternalString: public String {
4394 public:
4395 // Casting
4396 static inline ExternalString* cast(Object* obj);
4397
4398 // Layout description.
4399 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
4400 static const int kSize = kResourceOffset + kPointerSize;
4401
4402 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset);
4403
4404 private:
4405 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
4406};
4407
4408
4409// The ExternalAsciiString class is an external string backed by an
4410// ASCII string.
4411class ExternalAsciiString: public ExternalString {
4412 public:
4413 typedef v8::String::ExternalAsciiStringResource Resource;
4414
4415 // The underlying resource.
4416 inline Resource* resource();
4417 inline void set_resource(Resource* buffer);
4418
4419 // Dispatched behavior.
4420 uint16_t ExternalAsciiStringGet(int index);
4421
4422 // Casting.
4423 static inline ExternalAsciiString* cast(Object* obj);
4424
4425 // Support for StringInputBuffer.
4426 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining,
4427 unsigned* offset,
4428 unsigned chars);
4429 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
4430 unsigned* offset,
4431 unsigned chars);
4432
4433 // Identify the map for the external string/symbol with a particular length.
4434 static inline Map* StringMap(int length);
4435 static inline Map* SymbolMap(int length);
4436 private:
4437 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString);
4438};
4439
4440
4441// The ExternalTwoByteString class is an external string backed by a UTF-16
4442// encoded string.
4443class ExternalTwoByteString: public ExternalString {
4444 public:
4445 typedef v8::String::ExternalStringResource Resource;
4446
4447 // The underlying string resource.
4448 inline Resource* resource();
4449 inline void set_resource(Resource* buffer);
4450
4451 // Dispatched behavior.
4452 uint16_t ExternalTwoByteStringGet(int index);
4453
4454 // For regexp code.
4455 const uint16_t* ExternalTwoByteStringGetData(unsigned start);
4456
4457 // Casting.
4458 static inline ExternalTwoByteString* cast(Object* obj);
4459
4460 // Support for StringInputBuffer.
4461 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
4462 unsigned* offset_ptr,
4463 unsigned chars);
4464
4465 // Identify the map for the external string/symbol with a particular length.
4466 static inline Map* StringMap(int length);
4467 static inline Map* SymbolMap(int length);
4468 private:
4469 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString);
4470};
4471
4472
4473// Utility superclass for stack-allocated objects that must be updated
4474// on gc. It provides two ways for the gc to update instances, either
4475// iterating or updating after gc.
4476class Relocatable BASE_EMBEDDED {
4477 public:
4478 inline Relocatable() : prev_(top_) { top_ = this; }
4479 virtual ~Relocatable() {
4480 ASSERT_EQ(top_, this);
4481 top_ = prev_;
4482 }
4483 virtual void IterateInstance(ObjectVisitor* v) { }
4484 virtual void PostGarbageCollection() { }
4485
4486 static void PostGarbageCollectionProcessing();
4487 static int ArchiveSpacePerThread();
4488 static char* ArchiveState(char* to);
4489 static char* RestoreState(char* from);
4490 static void Iterate(ObjectVisitor* v);
4491 static void Iterate(ObjectVisitor* v, Relocatable* top);
4492 static char* Iterate(ObjectVisitor* v, char* t);
4493 private:
4494 static Relocatable* top_;
4495 Relocatable* prev_;
4496};
4497
4498
4499// A flat string reader provides random access to the contents of a
4500// string independent of the character width of the string. The handle
4501// must be valid as long as the reader is being used.
4502class FlatStringReader : public Relocatable {
4503 public:
4504 explicit FlatStringReader(Handle<String> str);
4505 explicit FlatStringReader(Vector<const char> input);
4506 void PostGarbageCollection();
4507 inline uc32 Get(int index);
4508 int length() { return length_; }
4509 private:
4510 String** str_;
4511 bool is_ascii_;
4512 int length_;
4513 const void* start_;
4514};
4515
4516
4517// Note that StringInputBuffers are not valid across a GC! To fix this
4518// it would have to store a String Handle instead of a String* and
4519// AsciiStringReadBlock would have to be modified to use memcpy.
4520//
4521// StringInputBuffer is able to traverse any string regardless of how
4522// deeply nested a sequence of ConsStrings it is made of. However,
4523// performance will be better if deep strings are flattened before they
4524// are traversed. Since flattening requires memory allocation this is
4525// not always desirable, however (esp. in debugging situations).
4526class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> {
4527 public:
4528 virtual void Seek(unsigned pos);
4529 inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {}
4530 inline StringInputBuffer(String* backing):
4531 unibrow::InputBuffer<String, String*, 1024>(backing) {}
4532};
4533
4534
4535class SafeStringInputBuffer
4536 : public unibrow::InputBuffer<String, String**, 256> {
4537 public:
4538 virtual void Seek(unsigned pos);
4539 inline SafeStringInputBuffer()
4540 : unibrow::InputBuffer<String, String**, 256>() {}
4541 inline SafeStringInputBuffer(String** backing)
4542 : unibrow::InputBuffer<String, String**, 256>(backing) {}
4543};
4544
4545
4546template <typename T>
4547class VectorIterator {
4548 public:
4549 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { }
4550 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { }
4551 T GetNext() { return data_[index_++]; }
4552 bool has_more() { return index_ < data_.length(); }
4553 private:
4554 Vector<const T> data_;
4555 int index_;
4556};
4557
4558
4559// The Oddball describes objects null, undefined, true, and false.
4560class Oddball: public HeapObject {
4561 public:
4562 // [to_string]: Cached to_string computed at startup.
4563 DECL_ACCESSORS(to_string, String)
4564
4565 // [to_number]: Cached to_number computed at startup.
4566 DECL_ACCESSORS(to_number, Object)
4567
4568 // Casting.
4569 static inline Oddball* cast(Object* obj);
4570
4571 // Dispatched behavior.
4572 void OddballIterateBody(ObjectVisitor* v);
4573#ifdef DEBUG
4574 void OddballVerify();
4575#endif
4576
4577 // Initialize the fields.
4578 Object* Initialize(const char* to_string, Object* to_number);
4579
4580 // Layout description.
4581 static const int kToStringOffset = HeapObject::kHeaderSize;
4582 static const int kToNumberOffset = kToStringOffset + kPointerSize;
4583 static const int kSize = kToNumberOffset + kPointerSize;
4584
4585 private:
4586 DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball);
4587};
4588
4589
4590class JSGlobalPropertyCell: public HeapObject {
4591 public:
4592 // [value]: value of the global property.
4593 DECL_ACCESSORS(value, Object)
4594
4595 // Casting.
4596 static inline JSGlobalPropertyCell* cast(Object* obj);
4597
4598 // Dispatched behavior.
4599 void JSGlobalPropertyCellIterateBody(ObjectVisitor* v);
4600#ifdef DEBUG
4601 void JSGlobalPropertyCellVerify();
4602 void JSGlobalPropertyCellPrint();
4603#endif
4604
4605 // Layout description.
4606 static const int kValueOffset = HeapObject::kHeaderSize;
4607 static const int kSize = kValueOffset + kPointerSize;
4608
4609 private:
4610 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell);
4611};
4612
4613
4614
4615// Proxy describes objects pointing from JavaScript to C structures.
4616// Since they cannot contain references to JS HeapObjects they can be
4617// placed in old_data_space.
4618class Proxy: public HeapObject {
4619 public:
4620 // [proxy]: field containing the address.
4621 inline Address proxy();
4622 inline void set_proxy(Address value);
4623
4624 // Casting.
4625 static inline Proxy* cast(Object* obj);
4626
4627 // Dispatched behavior.
4628 inline void ProxyIterateBody(ObjectVisitor* v);
4629#ifdef DEBUG
4630 void ProxyPrint();
4631 void ProxyVerify();
4632#endif
4633
4634 // Layout description.
4635
4636 static const int kProxyOffset = HeapObject::kHeaderSize;
4637 static const int kSize = kProxyOffset + kPointerSize;
4638
4639 STATIC_CHECK(kProxyOffset == Internals::kProxyProxyOffset);
4640
4641 private:
4642 DISALLOW_IMPLICIT_CONSTRUCTORS(Proxy);
4643};
4644
4645
4646// The JSArray describes JavaScript Arrays
4647// Such an array can be in one of two modes:
4648// - fast, backing storage is a FixedArray and length <= elements.length();
4649// Please note: push and pop can be used to grow and shrink the array.
4650// - slow, backing storage is a HashTable with numbers as keys.
4651class JSArray: public JSObject {
4652 public:
4653 // [length]: The length property.
4654 DECL_ACCESSORS(length, Object)
4655
4656 Object* JSArrayUpdateLengthFromIndex(uint32_t index, Object* value);
4657
4658 // Initialize the array with the given capacity. The function may
4659 // fail due to out-of-memory situations, but only if the requested
4660 // capacity is non-zero.
4661 Object* Initialize(int capacity);
4662
4663 // Set the content of the array to the content of storage.
4664 inline void SetContent(FixedArray* storage);
4665
4666 // Casting.
4667 static inline JSArray* cast(Object* obj);
4668
4669 // Uses handles. Ensures that the fixed array backing the JSArray has at
4670 // least the stated size.
4671 inline void EnsureSize(int minimum_size_of_backing_fixed_array);
4672
4673 // Dispatched behavior.
4674#ifdef DEBUG
4675 void JSArrayPrint();
4676 void JSArrayVerify();
4677#endif
4678
4679 // Number of element slots to pre-allocate for an empty array.
4680 static const int kPreallocatedArrayElements = 4;
4681
4682 // Layout description.
4683 static const int kLengthOffset = JSObject::kHeaderSize;
4684 static const int kSize = kLengthOffset + kPointerSize;
4685
4686 private:
4687 // Expand the fixed array backing of a fast-case JSArray to at least
4688 // the requested size.
4689 void Expand(int minimum_size_of_backing_fixed_array);
4690
4691 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
4692};
4693
4694
4695// An accessor must have a getter, but can have no setter.
4696//
4697// When setting a property, V8 searches accessors in prototypes.
4698// If an accessor was found and it does not have a setter,
4699// the request is ignored.
4700//
4701// If the accessor in the prototype has the READ_ONLY property attribute, then
4702// a new value is added to the local object when the property is set.
4703// This shadows the accessor in the prototype.
4704class AccessorInfo: public Struct {
4705 public:
4706 DECL_ACCESSORS(getter, Object)
4707 DECL_ACCESSORS(setter, Object)
4708 DECL_ACCESSORS(data, Object)
4709 DECL_ACCESSORS(name, Object)
4710 DECL_ACCESSORS(flag, Smi)
4711
4712 inline bool all_can_read();
4713 inline void set_all_can_read(bool value);
4714
4715 inline bool all_can_write();
4716 inline void set_all_can_write(bool value);
4717
4718 inline bool prohibits_overwriting();
4719 inline void set_prohibits_overwriting(bool value);
4720
4721 inline PropertyAttributes property_attributes();
4722 inline void set_property_attributes(PropertyAttributes attributes);
4723
4724 static inline AccessorInfo* cast(Object* obj);
4725
4726#ifdef DEBUG
4727 void AccessorInfoPrint();
4728 void AccessorInfoVerify();
4729#endif
4730
4731 static const int kGetterOffset = HeapObject::kHeaderSize;
4732 static const int kSetterOffset = kGetterOffset + kPointerSize;
4733 static const int kDataOffset = kSetterOffset + kPointerSize;
4734 static const int kNameOffset = kDataOffset + kPointerSize;
4735 static const int kFlagOffset = kNameOffset + kPointerSize;
4736 static const int kSize = kFlagOffset + kPointerSize;
4737
4738 private:
4739 // Bit positions in flag.
4740 static const int kAllCanReadBit = 0;
4741 static const int kAllCanWriteBit = 1;
4742 static const int kProhibitsOverwritingBit = 2;
4743 class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
4744
4745 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo);
4746};
4747
4748
4749class AccessCheckInfo: public Struct {
4750 public:
4751 DECL_ACCESSORS(named_callback, Object)
4752 DECL_ACCESSORS(indexed_callback, Object)
4753 DECL_ACCESSORS(data, Object)
4754
4755 static inline AccessCheckInfo* cast(Object* obj);
4756
4757#ifdef DEBUG
4758 void AccessCheckInfoPrint();
4759 void AccessCheckInfoVerify();
4760#endif
4761
4762 static const int kNamedCallbackOffset = HeapObject::kHeaderSize;
4763 static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize;
4764 static const int kDataOffset = kIndexedCallbackOffset + kPointerSize;
4765 static const int kSize = kDataOffset + kPointerSize;
4766
4767 private:
4768 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo);
4769};
4770
4771
4772class InterceptorInfo: public Struct {
4773 public:
4774 DECL_ACCESSORS(getter, Object)
4775 DECL_ACCESSORS(setter, Object)
4776 DECL_ACCESSORS(query, Object)
4777 DECL_ACCESSORS(deleter, Object)
4778 DECL_ACCESSORS(enumerator, Object)
4779 DECL_ACCESSORS(data, Object)
4780
4781 static inline InterceptorInfo* cast(Object* obj);
4782
4783#ifdef DEBUG
4784 void InterceptorInfoPrint();
4785 void InterceptorInfoVerify();
4786#endif
4787
4788 static const int kGetterOffset = HeapObject::kHeaderSize;
4789 static const int kSetterOffset = kGetterOffset + kPointerSize;
4790 static const int kQueryOffset = kSetterOffset + kPointerSize;
4791 static const int kDeleterOffset = kQueryOffset + kPointerSize;
4792 static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
4793 static const int kDataOffset = kEnumeratorOffset + kPointerSize;
4794 static const int kSize = kDataOffset + kPointerSize;
4795
4796 private:
4797 DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
4798};
4799
4800
4801class CallHandlerInfo: public Struct {
4802 public:
4803 DECL_ACCESSORS(callback, Object)
4804 DECL_ACCESSORS(data, Object)
4805
4806 static inline CallHandlerInfo* cast(Object* obj);
4807
4808#ifdef DEBUG
4809 void CallHandlerInfoPrint();
4810 void CallHandlerInfoVerify();
4811#endif
4812
4813 static const int kCallbackOffset = HeapObject::kHeaderSize;
4814 static const int kDataOffset = kCallbackOffset + kPointerSize;
4815 static const int kSize = kDataOffset + kPointerSize;
4816
4817 private:
4818 DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
4819};
4820
4821
4822class TemplateInfo: public Struct {
4823 public:
4824 DECL_ACCESSORS(tag, Object)
4825 DECL_ACCESSORS(property_list, Object)
4826
4827#ifdef DEBUG
4828 void TemplateInfoVerify();
4829#endif
4830
4831 static const int kTagOffset = HeapObject::kHeaderSize;
4832 static const int kPropertyListOffset = kTagOffset + kPointerSize;
4833 static const int kHeaderSize = kPropertyListOffset + kPointerSize;
4834 protected:
4835 friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs;
4836 DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
4837};
4838
4839
4840class FunctionTemplateInfo: public TemplateInfo {
4841 public:
4842 DECL_ACCESSORS(serial_number, Object)
4843 DECL_ACCESSORS(call_code, Object)
4844 DECL_ACCESSORS(property_accessors, Object)
4845 DECL_ACCESSORS(prototype_template, Object)
4846 DECL_ACCESSORS(parent_template, Object)
4847 DECL_ACCESSORS(named_property_handler, Object)
4848 DECL_ACCESSORS(indexed_property_handler, Object)
4849 DECL_ACCESSORS(instance_template, Object)
4850 DECL_ACCESSORS(class_name, Object)
4851 DECL_ACCESSORS(signature, Object)
4852 DECL_ACCESSORS(instance_call_handler, Object)
4853 DECL_ACCESSORS(access_check_info, Object)
4854 DECL_ACCESSORS(flag, Smi)
4855
4856 // Following properties use flag bits.
4857 DECL_BOOLEAN_ACCESSORS(hidden_prototype)
4858 DECL_BOOLEAN_ACCESSORS(undetectable)
4859 // If the bit is set, object instances created by this function
4860 // requires access check.
4861 DECL_BOOLEAN_ACCESSORS(needs_access_check)
4862
4863 static inline FunctionTemplateInfo* cast(Object* obj);
4864
4865#ifdef DEBUG
4866 void FunctionTemplateInfoPrint();
4867 void FunctionTemplateInfoVerify();
4868#endif
4869
4870 static const int kSerialNumberOffset = TemplateInfo::kHeaderSize;
4871 static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize;
4872 static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize;
4873 static const int kPrototypeTemplateOffset =
4874 kPropertyAccessorsOffset + kPointerSize;
4875 static const int kParentTemplateOffset =
4876 kPrototypeTemplateOffset + kPointerSize;
4877 static const int kNamedPropertyHandlerOffset =
4878 kParentTemplateOffset + kPointerSize;
4879 static const int kIndexedPropertyHandlerOffset =
4880 kNamedPropertyHandlerOffset + kPointerSize;
4881 static const int kInstanceTemplateOffset =
4882 kIndexedPropertyHandlerOffset + kPointerSize;
4883 static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
4884 static const int kSignatureOffset = kClassNameOffset + kPointerSize;
4885 static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
4886 static const int kAccessCheckInfoOffset =
4887 kInstanceCallHandlerOffset + kPointerSize;
4888 static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize;
4889 static const int kSize = kFlagOffset + kPointerSize;
4890
4891 private:
4892 // Bit position in the flag, from least significant bit position.
4893 static const int kHiddenPrototypeBit = 0;
4894 static const int kUndetectableBit = 1;
4895 static const int kNeedsAccessCheckBit = 2;
4896
4897 DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
4898};
4899
4900
4901class ObjectTemplateInfo: public TemplateInfo {
4902 public:
4903 DECL_ACCESSORS(constructor, Object)
4904 DECL_ACCESSORS(internal_field_count, Object)
4905
4906 static inline ObjectTemplateInfo* cast(Object* obj);
4907
4908#ifdef DEBUG
4909 void ObjectTemplateInfoPrint();
4910 void ObjectTemplateInfoVerify();
4911#endif
4912
4913 static const int kConstructorOffset = TemplateInfo::kHeaderSize;
4914 static const int kInternalFieldCountOffset =
4915 kConstructorOffset + kPointerSize;
4916 static const int kSize = kInternalFieldCountOffset + kPointerSize;
4917};
4918
4919
4920class SignatureInfo: public Struct {
4921 public:
4922 DECL_ACCESSORS(receiver, Object)
4923 DECL_ACCESSORS(args, Object)
4924
4925 static inline SignatureInfo* cast(Object* obj);
4926
4927#ifdef DEBUG
4928 void SignatureInfoPrint();
4929 void SignatureInfoVerify();
4930#endif
4931
4932 static const int kReceiverOffset = Struct::kHeaderSize;
4933 static const int kArgsOffset = kReceiverOffset + kPointerSize;
4934 static const int kSize = kArgsOffset + kPointerSize;
4935
4936 private:
4937 DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo);
4938};
4939
4940
4941class TypeSwitchInfo: public Struct {
4942 public:
4943 DECL_ACCESSORS(types, Object)
4944
4945 static inline TypeSwitchInfo* cast(Object* obj);
4946
4947#ifdef DEBUG
4948 void TypeSwitchInfoPrint();
4949 void TypeSwitchInfoVerify();
4950#endif
4951
4952 static const int kTypesOffset = Struct::kHeaderSize;
4953 static const int kSize = kTypesOffset + kPointerSize;
4954};
4955
4956
4957#ifdef ENABLE_DEBUGGER_SUPPORT
4958// The DebugInfo class holds additional information for a function being
4959// debugged.
4960class DebugInfo: public Struct {
4961 public:
4962 // The shared function info for the source being debugged.
4963 DECL_ACCESSORS(shared, SharedFunctionInfo)
4964 // Code object for the original code.
4965 DECL_ACCESSORS(original_code, Code)
4966 // Code object for the patched code. This code object is the code object
4967 // currently active for the function.
4968 DECL_ACCESSORS(code, Code)
4969 // Fixed array holding status information for each active break point.
4970 DECL_ACCESSORS(break_points, FixedArray)
4971
4972 // Check if there is a break point at a code position.
4973 bool HasBreakPoint(int code_position);
4974 // Get the break point info object for a code position.
4975 Object* GetBreakPointInfo(int code_position);
4976 // Clear a break point.
4977 static void ClearBreakPoint(Handle<DebugInfo> debug_info,
4978 int code_position,
4979 Handle<Object> break_point_object);
4980 // Set a break point.
4981 static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position,
4982 int source_position, int statement_position,
4983 Handle<Object> break_point_object);
4984 // Get the break point objects for a code position.
4985 Object* GetBreakPointObjects(int code_position);
4986 // Find the break point info holding this break point object.
4987 static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info,
4988 Handle<Object> break_point_object);
4989 // Get the number of break points for this function.
4990 int GetBreakPointCount();
4991
4992 static inline DebugInfo* cast(Object* obj);
4993
4994#ifdef DEBUG
4995 void DebugInfoPrint();
4996 void DebugInfoVerify();
4997#endif
4998
4999 static const int kSharedFunctionInfoIndex = Struct::kHeaderSize;
5000 static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize;
5001 static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize;
5002 static const int kActiveBreakPointsCountIndex =
5003 kPatchedCodeIndex + kPointerSize;
5004 static const int kBreakPointsStateIndex =
5005 kActiveBreakPointsCountIndex + kPointerSize;
5006 static const int kSize = kBreakPointsStateIndex + kPointerSize;
5007
5008 private:
5009 static const int kNoBreakPointInfo = -1;
5010
5011 // Lookup the index in the break_points array for a code position.
5012 int GetBreakPointInfoIndex(int code_position);
5013
5014 DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo);
5015};
5016
5017
5018// The BreakPointInfo class holds information for break points set in a
5019// function. The DebugInfo object holds a BreakPointInfo object for each code
5020// position with one or more break points.
5021class BreakPointInfo: public Struct {
5022 public:
5023 // The position in the code for the break point.
5024 DECL_ACCESSORS(code_position, Smi)
5025 // The position in the source for the break position.
5026 DECL_ACCESSORS(source_position, Smi)
5027 // The position in the source for the last statement before this break
5028 // position.
5029 DECL_ACCESSORS(statement_position, Smi)
5030 // List of related JavaScript break points.
5031 DECL_ACCESSORS(break_point_objects, Object)
5032
5033 // Removes a break point.
5034 static void ClearBreakPoint(Handle<BreakPointInfo> info,
5035 Handle<Object> break_point_object);
5036 // Set a break point.
5037 static void SetBreakPoint(Handle<BreakPointInfo> info,
5038 Handle<Object> break_point_object);
5039 // Check if break point info has this break point object.
5040 static bool HasBreakPointObject(Handle<BreakPointInfo> info,
5041 Handle<Object> break_point_object);
5042 // Get the number of break points for this code position.
5043 int GetBreakPointCount();
5044
5045 static inline BreakPointInfo* cast(Object* obj);
5046
5047#ifdef DEBUG
5048 void BreakPointInfoPrint();
5049 void BreakPointInfoVerify();
5050#endif
5051
5052 static const int kCodePositionIndex = Struct::kHeaderSize;
5053 static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize;
5054 static const int kStatementPositionIndex =
5055 kSourcePositionIndex + kPointerSize;
5056 static const int kBreakPointObjectsIndex =
5057 kStatementPositionIndex + kPointerSize;
5058 static const int kSize = kBreakPointObjectsIndex + kPointerSize;
5059
5060 private:
5061 DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo);
5062};
5063#endif // ENABLE_DEBUGGER_SUPPORT
5064
5065
5066#undef DECL_BOOLEAN_ACCESSORS
5067#undef DECL_ACCESSORS
5068
5069
5070// Abstract base class for visiting, and optionally modifying, the
5071// pointers contained in Objects. Used in GC and serialization/deserialization.
5072class ObjectVisitor BASE_EMBEDDED {
5073 public:
5074 virtual ~ObjectVisitor() {}
5075
5076 // Visits a contiguous arrays of pointers in the half-open range
5077 // [start, end). Any or all of the values may be modified on return.
5078 virtual void VisitPointers(Object** start, Object** end) = 0;
5079
5080 // To allow lazy clearing of inline caches the visitor has
5081 // a rich interface for iterating over Code objects..
5082
5083 // Visits a code target in the instruction stream.
5084 virtual void VisitCodeTarget(RelocInfo* rinfo);
5085
5086 // Visits a runtime entry in the instruction stream.
5087 virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
5088
5089 // Visits a debug call target in the instruction stream.
5090 virtual void VisitDebugTarget(RelocInfo* rinfo);
5091
5092 // Handy shorthand for visiting a single pointer.
5093 virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); }
5094
5095 // Visits a contiguous arrays of external references (references to the C++
5096 // heap) in the half-open range [start, end). Any or all of the values
5097 // may be modified on return.
5098 virtual void VisitExternalReferences(Address* start, Address* end) {}
5099
5100 inline void VisitExternalReference(Address* p) {
5101 VisitExternalReferences(p, p + 1);
5102 }
5103
5104#ifdef DEBUG
5105 // Intended for serialization/deserialization checking: insert, or
5106 // check for the presence of, a tag at this position in the stream.
5107 virtual void Synchronize(const char* tag) {}
5108#endif
5109};
5110
5111
5112// BooleanBit is a helper class for setting and getting a bit in an
5113// integer or Smi.
5114class BooleanBit : public AllStatic {
5115 public:
5116 static inline bool get(Smi* smi, int bit_position) {
5117 return get(smi->value(), bit_position);
5118 }
5119
5120 static inline bool get(int value, int bit_position) {
5121 return (value & (1 << bit_position)) != 0;
5122 }
5123
5124 static inline Smi* set(Smi* smi, int bit_position, bool v) {
5125 return Smi::FromInt(set(smi->value(), bit_position, v));
5126 }
5127
5128 static inline int set(int value, int bit_position, bool v) {
5129 if (v) {
5130 value |= (1 << bit_position);
5131 } else {
5132 value &= ~(1 << bit_position);
5133 }
5134 return value;
5135 }
5136};
5137
5138} } // namespace v8::internal
5139
5140#endif // V8_OBJECTS_H_