blob: a9cb8e0db6bebb65dd3fb145df8583b29b5b6e93 [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright 2012 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_OBJECTS_H_
29#define V8_OBJECTS_H_
30
Ben Murdoch257744e2011-11-30 15:57:28 +000031#include "allocation.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000032#include "builtins.h"
Ben Murdoch257744e2011-11-30 15:57:28 +000033#include "list.h"
Ben Murdoch3ef787d2012-04-12 10:51:47 +010034#include "property-details.h"
Ben Murdoch589d6972011-11-30 16:04:58 +000035#include "smart-array-pointer.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000036#include "unicode-inl.h"
Steve Block3ce2e202009-11-05 08:53:23 +000037#if V8_TARGET_ARCH_ARM
38#include "arm/constants-arm.h"
Andrei Popescu31002712010-02-23 13:46:05 +000039#elif V8_TARGET_ARCH_MIPS
40#include "mips/constants-mips.h"
Steve Block3ce2e202009-11-05 08:53:23 +000041#endif
Ben Murdoch3ef787d2012-04-12 10:51:47 +010042#include "v8checks.h"
43
Steve Blocka7e24c12009-10-30 11:49:00 +000044
45//
Kristian Monsen50ef84f2010-07-29 15:18:00 +010046// Most object types in the V8 JavaScript are described in this file.
Steve Blocka7e24c12009-10-30 11:49:00 +000047//
48// Inheritance hierarchy:
John Reck59135872010-11-02 12:39:01 -070049// - MaybeObject (an object or a failure)
50// - Failure (immediate for marking failed operation)
Steve Blocka7e24c12009-10-30 11:49:00 +000051// - Object
52// - Smi (immediate small integer)
Steve Blocka7e24c12009-10-30 11:49:00 +000053// - HeapObject (superclass for everything allocated in the heap)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000054// - JSReceiver (suitable for property access)
55// - JSObject
56// - JSArray
Ben Murdoch3ef787d2012-04-12 10:51:47 +010057// - JSSet
58// - JSMap
Ben Murdoch69a99ed2011-11-30 16:03:39 +000059// - JSWeakMap
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000060// - JSRegExp
61// - JSFunction
62// - GlobalObject
63// - JSGlobalObject
64// - JSBuiltinsObject
65// - JSGlobalProxy
66// - JSValue
Ben Murdoch3ef787d2012-04-12 10:51:47 +010067// - JSDate
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000068// - JSMessageObject
69// - JSProxy
70// - JSFunctionProxy
Ben Murdoch69a99ed2011-11-30 16:03:39 +000071// - FixedArrayBase
72// - ByteArray
73// - FixedArray
74// - DescriptorArray
75// - HashTable
76// - Dictionary
77// - SymbolTable
78// - CompilationCacheTable
79// - CodeCacheHashTable
80// - MapCache
81// - Context
82// - JSFunctionResultCache
Ben Murdoch3ef787d2012-04-12 10:51:47 +010083// - ScopeInfo
Ben Murdoch69a99ed2011-11-30 16:03:39 +000084// - FixedDoubleArray
85// - ExternalArray
86// - ExternalPixelArray
87// - ExternalByteArray
88// - ExternalUnsignedByteArray
89// - ExternalShortArray
90// - ExternalUnsignedShortArray
91// - ExternalIntArray
92// - ExternalUnsignedIntArray
93// - ExternalFloatArray
Steve Blocka7e24c12009-10-30 11:49:00 +000094// - String
95// - SeqString
96// - SeqAsciiString
97// - SeqTwoByteString
Ben Murdoch69a99ed2011-11-30 16:03:39 +000098// - SlicedString
Steve Blocka7e24c12009-10-30 11:49:00 +000099// - ConsString
Steve Blocka7e24c12009-10-30 11:49:00 +0000100// - ExternalString
101// - ExternalAsciiString
102// - ExternalTwoByteString
103// - HeapNumber
104// - Code
105// - Map
106// - Oddball
Ben Murdoch257744e2011-11-30 15:57:28 +0000107// - Foreign
Steve Blocka7e24c12009-10-30 11:49:00 +0000108// - SharedFunctionInfo
109// - Struct
110// - AccessorInfo
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100111// - AccessorPair
Steve Blocka7e24c12009-10-30 11:49:00 +0000112// - AccessCheckInfo
113// - InterceptorInfo
114// - CallHandlerInfo
115// - TemplateInfo
116// - FunctionTemplateInfo
117// - ObjectTemplateInfo
118// - Script
119// - SignatureInfo
120// - TypeSwitchInfo
121// - DebugInfo
122// - BreakPointInfo
Steve Block6ded16b2010-05-10 14:33:55 +0100123// - CodeCache
Steve Blocka7e24c12009-10-30 11:49:00 +0000124//
125// Formats of Object*:
126// Smi: [31 bit signed int] 0
127// HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
128// Failure: [30 bit signed int] 11
129
Steve Blocka7e24c12009-10-30 11:49:00 +0000130namespace v8 {
131namespace internal {
132
Ben Murdoch589d6972011-11-30 16:04:58 +0000133enum ElementsKind {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100134 // The "fast" kind for elements that only contain SMI values. Must be first
135 // to make it possible to efficiently check maps for this kind.
136 FAST_SMI_ONLY_ELEMENTS,
137
138 // The "fast" kind for tagged values. Must be second to make it possible to
139 // efficiently check maps for this and the FAST_SMI_ONLY_ELEMENTS kind
140 // together at once.
Ben Murdoch589d6972011-11-30 16:04:58 +0000141 FAST_ELEMENTS,
142
143 // The "fast" kind for unwrapped, non-tagged double values.
144 FAST_DOUBLE_ELEMENTS,
145
146 // The "slow" kind.
147 DICTIONARY_ELEMENTS,
148 NON_STRICT_ARGUMENTS_ELEMENTS,
149 // The "fast" kind for external arrays
150 EXTERNAL_BYTE_ELEMENTS,
151 EXTERNAL_UNSIGNED_BYTE_ELEMENTS,
152 EXTERNAL_SHORT_ELEMENTS,
153 EXTERNAL_UNSIGNED_SHORT_ELEMENTS,
154 EXTERNAL_INT_ELEMENTS,
155 EXTERNAL_UNSIGNED_INT_ELEMENTS,
156 EXTERNAL_FLOAT_ELEMENTS,
157 EXTERNAL_DOUBLE_ELEMENTS,
158 EXTERNAL_PIXEL_ELEMENTS,
159
160 // Derived constants from ElementsKind
161 FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS,
162 LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100163 FIRST_ELEMENTS_KIND = FAST_SMI_ONLY_ELEMENTS,
Ben Murdoch589d6972011-11-30 16:04:58 +0000164 LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS
165};
166
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100167enum CompareMapMode {
168 REQUIRE_EXACT_MAP,
169 ALLOW_ELEMENT_TRANSITION_MAPS
Ben Murdochc7cc0282012-03-05 14:35:55 +0000170};
171
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100172enum KeyedAccessGrowMode {
173 DO_NOT_ALLOW_JSARRAY_GROWTH,
174 ALLOW_JSARRAY_GROWTH
175};
176
177const int kElementsKindCount = LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1;
178
179void PrintElementsKind(FILE* out, ElementsKind kind);
180
181inline bool IsMoreGeneralElementsKindTransition(ElementsKind from_kind,
182 ElementsKind to_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +0000183
184// Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER.
185enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER };
186
187
188// PropertyNormalizationMode is used to specify whether to keep
189// inobject properties when normalizing properties of a JSObject.
190enum PropertyNormalizationMode {
191 CLEAR_INOBJECT_PROPERTIES,
192 KEEP_INOBJECT_PROPERTIES
193};
194
195
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100196// NormalizedMapSharingMode is used to specify whether a map may be shared
197// by different objects with normalized properties.
198enum NormalizedMapSharingMode {
199 UNIQUE_NORMALIZED_MAP,
200 SHARED_NORMALIZED_MAP
201};
202
203
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100204// Indicates whether a get method should implicitly create the object looked up.
205enum CreationFlag {
206 ALLOW_CREATION,
207 OMIT_CREATION
208};
209
210
Steve Block791712a2010-08-27 10:21:07 +0100211// Instance size sentinel for objects of variable size.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100212const int kVariableSizeSentinel = 0;
Steve Block791712a2010-08-27 10:21:07 +0100213
214
Steve Blocka7e24c12009-10-30 11:49:00 +0000215// All Maps have a field instance_type containing a InstanceType.
216// It describes the type of the instances.
217//
218// As an example, a JavaScript object is a heap object and its map
219// instance_type is JS_OBJECT_TYPE.
220//
221// The names of the string instance types are intended to systematically
Leon Clarkee46be812010-01-19 14:06:41 +0000222// mirror their encoding in the instance_type field of the map. The default
223// encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII
224// encoding is mentioned explicitly in the name. Likewise, the default
225// representation is considered sequential. It is not mentioned in the
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100226// name. The other representations (e.g. CONS, EXTERNAL) are explicitly
Leon Clarkee46be812010-01-19 14:06:41 +0000227// mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a
228// symbol) or a STRING_TYPE (if it is not a symbol).
Steve Blocka7e24c12009-10-30 11:49:00 +0000229//
230// NOTE: The following things are some that depend on the string types having
231// instance_types that are less than those of all other types:
232// HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
233// Object::IsString.
234//
235// NOTE: Everything following JS_VALUE_TYPE is considered a
236// JSObject for GC purposes. The first four entries here have typeof
237// 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
Steve Blockd0582a62009-12-15 09:54:21 +0000238#define INSTANCE_TYPE_LIST_ALL(V) \
239 V(SYMBOL_TYPE) \
240 V(ASCII_SYMBOL_TYPE) \
241 V(CONS_SYMBOL_TYPE) \
242 V(CONS_ASCII_SYMBOL_TYPE) \
243 V(EXTERNAL_SYMBOL_TYPE) \
Iain Merrick75681382010-08-19 15:07:18 +0100244 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000245 V(EXTERNAL_ASCII_SYMBOL_TYPE) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100246 V(SHORT_EXTERNAL_SYMBOL_TYPE) \
247 V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
248 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000249 V(STRING_TYPE) \
250 V(ASCII_STRING_TYPE) \
251 V(CONS_STRING_TYPE) \
252 V(CONS_ASCII_STRING_TYPE) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000253 V(SLICED_STRING_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000254 V(EXTERNAL_STRING_TYPE) \
Iain Merrick75681382010-08-19 15:07:18 +0100255 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000256 V(EXTERNAL_ASCII_STRING_TYPE) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100257 V(SHORT_EXTERNAL_STRING_TYPE) \
258 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
259 V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000260 V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \
261 \
262 V(MAP_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000263 V(CODE_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000264 V(ODDBALL_TYPE) \
Iain Merrick75681382010-08-19 15:07:18 +0100265 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \
Leon Clarkee46be812010-01-19 14:06:41 +0000266 \
267 V(HEAP_NUMBER_TYPE) \
Ben Murdoch257744e2011-11-30 15:57:28 +0000268 V(FOREIGN_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000269 V(BYTE_ARRAY_TYPE) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100270 V(FREE_SPACE_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000271 /* Note: the order of these external array */ \
272 /* types is relied upon in */ \
273 /* Object::IsExternalArray(). */ \
274 V(EXTERNAL_BYTE_ARRAY_TYPE) \
275 V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \
276 V(EXTERNAL_SHORT_ARRAY_TYPE) \
277 V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \
278 V(EXTERNAL_INT_ARRAY_TYPE) \
279 V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \
280 V(EXTERNAL_FLOAT_ARRAY_TYPE) \
Steve Block44f0eee2011-05-26 01:26:41 +0100281 V(EXTERNAL_PIXEL_ARRAY_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000282 V(FILLER_TYPE) \
283 \
284 V(ACCESSOR_INFO_TYPE) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100285 V(ACCESSOR_PAIR_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000286 V(ACCESS_CHECK_INFO_TYPE) \
287 V(INTERCEPTOR_INFO_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000288 V(CALL_HANDLER_INFO_TYPE) \
289 V(FUNCTION_TEMPLATE_INFO_TYPE) \
290 V(OBJECT_TEMPLATE_INFO_TYPE) \
291 V(SIGNATURE_INFO_TYPE) \
292 V(TYPE_SWITCH_INFO_TYPE) \
293 V(SCRIPT_TYPE) \
Steve Block6ded16b2010-05-10 14:33:55 +0100294 V(CODE_CACHE_TYPE) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000295 V(POLYMORPHIC_CODE_CACHE_TYPE) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100296 V(TYPE_FEEDBACK_INFO_TYPE) \
297 V(ALIASED_ARGUMENTS_ENTRY_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000298 \
Iain Merrick75681382010-08-19 15:07:18 +0100299 V(FIXED_ARRAY_TYPE) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000300 V(FIXED_DOUBLE_ARRAY_TYPE) \
Iain Merrick75681382010-08-19 15:07:18 +0100301 V(SHARED_FUNCTION_INFO_TYPE) \
302 \
Steve Block1e0659c2011-05-24 12:43:12 +0100303 V(JS_MESSAGE_OBJECT_TYPE) \
304 \
Steve Blockd0582a62009-12-15 09:54:21 +0000305 V(JS_VALUE_TYPE) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100306 V(JS_DATE_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000307 V(JS_OBJECT_TYPE) \
308 V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \
309 V(JS_GLOBAL_OBJECT_TYPE) \
310 V(JS_BUILTINS_OBJECT_TYPE) \
311 V(JS_GLOBAL_PROXY_TYPE) \
312 V(JS_ARRAY_TYPE) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000313 V(JS_PROXY_TYPE) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000314 V(JS_WEAK_MAP_TYPE) \
Steve Blockd0582a62009-12-15 09:54:21 +0000315 V(JS_REGEXP_TYPE) \
316 \
317 V(JS_FUNCTION_TYPE) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000318 V(JS_FUNCTION_PROXY_TYPE) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000319
320#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Blockd0582a62009-12-15 09:54:21 +0000321#define INSTANCE_TYPE_LIST_DEBUGGER(V) \
322 V(DEBUG_INFO_TYPE) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 V(BREAK_POINT_INFO_TYPE)
324#else
325#define INSTANCE_TYPE_LIST_DEBUGGER(V)
326#endif
327
Steve Blockd0582a62009-12-15 09:54:21 +0000328#define INSTANCE_TYPE_LIST(V) \
329 INSTANCE_TYPE_LIST_ALL(V) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000330 INSTANCE_TYPE_LIST_DEBUGGER(V)
331
332
333// Since string types are not consecutive, this macro is used to
334// iterate over them.
335#define STRING_TYPE_LIST(V) \
Steve Blockd0582a62009-12-15 09:54:21 +0000336 V(SYMBOL_TYPE, \
Steve Block791712a2010-08-27 10:21:07 +0100337 kVariableSizeSentinel, \
Steve Blockd0582a62009-12-15 09:54:21 +0000338 symbol, \
339 Symbol) \
340 V(ASCII_SYMBOL_TYPE, \
Steve Block791712a2010-08-27 10:21:07 +0100341 kVariableSizeSentinel, \
Steve Blockd0582a62009-12-15 09:54:21 +0000342 ascii_symbol, \
343 AsciiSymbol) \
344 V(CONS_SYMBOL_TYPE, \
345 ConsString::kSize, \
346 cons_symbol, \
347 ConsSymbol) \
348 V(CONS_ASCII_SYMBOL_TYPE, \
349 ConsString::kSize, \
350 cons_ascii_symbol, \
351 ConsAsciiSymbol) \
352 V(EXTERNAL_SYMBOL_TYPE, \
353 ExternalTwoByteString::kSize, \
354 external_symbol, \
355 ExternalSymbol) \
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100356 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
357 ExternalTwoByteString::kSize, \
358 external_symbol_with_ascii_data, \
359 ExternalSymbolWithAsciiData) \
Steve Blockd0582a62009-12-15 09:54:21 +0000360 V(EXTERNAL_ASCII_SYMBOL_TYPE, \
361 ExternalAsciiString::kSize, \
362 external_ascii_symbol, \
363 ExternalAsciiSymbol) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100364 V(SHORT_EXTERNAL_SYMBOL_TYPE, \
365 ExternalTwoByteString::kShortSize, \
366 short_external_symbol, \
367 ShortExternalSymbol) \
368 V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
369 ExternalTwoByteString::kShortSize, \
370 short_external_symbol_with_ascii_data, \
371 ShortExternalSymbolWithAsciiData) \
372 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \
373 ExternalAsciiString::kShortSize, \
374 short_external_ascii_symbol, \
375 ShortExternalAsciiSymbol) \
Steve Blockd0582a62009-12-15 09:54:21 +0000376 V(STRING_TYPE, \
Steve Block791712a2010-08-27 10:21:07 +0100377 kVariableSizeSentinel, \
Steve Blockd0582a62009-12-15 09:54:21 +0000378 string, \
379 String) \
380 V(ASCII_STRING_TYPE, \
Steve Block791712a2010-08-27 10:21:07 +0100381 kVariableSizeSentinel, \
Steve Blockd0582a62009-12-15 09:54:21 +0000382 ascii_string, \
383 AsciiString) \
384 V(CONS_STRING_TYPE, \
Steve Blocka7e24c12009-10-30 11:49:00 +0000385 ConsString::kSize, \
Steve Blockd0582a62009-12-15 09:54:21 +0000386 cons_string, \
387 ConsString) \
388 V(CONS_ASCII_STRING_TYPE, \
Steve Blocka7e24c12009-10-30 11:49:00 +0000389 ConsString::kSize, \
Steve Blockd0582a62009-12-15 09:54:21 +0000390 cons_ascii_string, \
391 ConsAsciiString) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000392 V(SLICED_STRING_TYPE, \
393 SlicedString::kSize, \
394 sliced_string, \
395 SlicedString) \
396 V(SLICED_ASCII_STRING_TYPE, \
397 SlicedString::kSize, \
398 sliced_ascii_string, \
399 SlicedAsciiString) \
Steve Blockd0582a62009-12-15 09:54:21 +0000400 V(EXTERNAL_STRING_TYPE, \
Steve Blocka7e24c12009-10-30 11:49:00 +0000401 ExternalTwoByteString::kSize, \
Steve Blockd0582a62009-12-15 09:54:21 +0000402 external_string, \
403 ExternalString) \
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100404 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
405 ExternalTwoByteString::kSize, \
406 external_string_with_ascii_data, \
407 ExternalStringWithAsciiData) \
Steve Blockd0582a62009-12-15 09:54:21 +0000408 V(EXTERNAL_ASCII_STRING_TYPE, \
Steve Blocka7e24c12009-10-30 11:49:00 +0000409 ExternalAsciiString::kSize, \
Steve Blockd0582a62009-12-15 09:54:21 +0000410 external_ascii_string, \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100411 ExternalAsciiString) \
412 V(SHORT_EXTERNAL_STRING_TYPE, \
413 ExternalTwoByteString::kShortSize, \
414 short_external_string, \
415 ShortExternalString) \
416 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
417 ExternalTwoByteString::kShortSize, \
418 short_external_string_with_ascii_data, \
419 ShortExternalStringWithAsciiData) \
420 V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \
421 ExternalAsciiString::kShortSize, \
422 short_external_ascii_string, \
423 ShortExternalAsciiString)
Steve Blocka7e24c12009-10-30 11:49:00 +0000424
425// A struct is a simple object a set of object-valued fields. Including an
426// object type in this causes the compiler to generate most of the boilerplate
427// code for the class including allocation and garbage collection routines,
428// casts and predicates. All you need to define is the class, methods and
429// object verification routines. Easy, no?
430//
431// Note that for subtle reasons related to the ordering or numerical values of
432// type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
433// manually.
Steve Blockd0582a62009-12-15 09:54:21 +0000434#define STRUCT_LIST_ALL(V) \
435 V(ACCESSOR_INFO, AccessorInfo, accessor_info) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100436 V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \
Steve Blockd0582a62009-12-15 09:54:21 +0000437 V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \
438 V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \
439 V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \
440 V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \
441 V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \
442 V(SIGNATURE_INFO, SignatureInfo, signature_info) \
443 V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \
Steve Block6ded16b2010-05-10 14:33:55 +0100444 V(SCRIPT, Script, script) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000445 V(CODE_CACHE, CodeCache, code_cache) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100446 V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \
447 V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \
448 V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry)
Steve Blocka7e24c12009-10-30 11:49:00 +0000449
450#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Blockd0582a62009-12-15 09:54:21 +0000451#define STRUCT_LIST_DEBUGGER(V) \
452 V(DEBUG_INFO, DebugInfo, debug_info) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000453 V(BREAK_POINT_INFO, BreakPointInfo, break_point_info)
454#else
455#define STRUCT_LIST_DEBUGGER(V)
456#endif
457
Steve Blockd0582a62009-12-15 09:54:21 +0000458#define STRUCT_LIST(V) \
459 STRUCT_LIST_ALL(V) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000460 STRUCT_LIST_DEBUGGER(V)
461
462// We use the full 8 bits of the instance_type field to encode heap object
463// instance types. The high-order bit (bit 7) is set if the object is not a
464// string, and cleared if it is a string.
465const uint32_t kIsNotStringMask = 0x80;
466const uint32_t kStringTag = 0x0;
467const uint32_t kNotStringTag = 0x80;
468
Leon Clarkee46be812010-01-19 14:06:41 +0000469// Bit 6 indicates that the object is a symbol (if set) or not (if cleared).
470// There are not enough types that the non-string types (with bit 7 set) can
471// have bit 6 set too.
472const uint32_t kIsSymbolMask = 0x40;
Steve Blocka7e24c12009-10-30 11:49:00 +0000473const uint32_t kNotSymbolTag = 0x0;
Leon Clarkee46be812010-01-19 14:06:41 +0000474const uint32_t kSymbolTag = 0x40;
Steve Blocka7e24c12009-10-30 11:49:00 +0000475
Steve Blocka7e24c12009-10-30 11:49:00 +0000476// If bit 7 is clear then bit 2 indicates whether the string consists of
477// two-byte characters or one-byte characters.
478const uint32_t kStringEncodingMask = 0x4;
479const uint32_t kTwoByteStringTag = 0x0;
480const uint32_t kAsciiStringTag = 0x4;
481
482// If bit 7 is clear, the low-order 2 bits indicate the representation
483// of the string.
484const uint32_t kStringRepresentationMask = 0x03;
485enum StringRepresentationTag {
486 kSeqStringTag = 0x0,
487 kConsStringTag = 0x1,
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000488 kExternalStringTag = 0x2,
489 kSlicedStringTag = 0x3
Steve Blocka7e24c12009-10-30 11:49:00 +0000490};
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000491const uint32_t kIsIndirectStringMask = 0x1;
492const uint32_t kIsIndirectStringTag = 0x1;
493STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0);
494STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0);
495STATIC_ASSERT(
496 (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag);
497STATIC_ASSERT(
498 (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag);
499
500// Use this mask to distinguish between cons and slice only after making
501// sure that the string is one of the two (an indirect string).
502const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag;
503STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000504
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100505// If bit 7 is clear, then bit 3 indicates whether this two-byte
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100506// string actually contains ASCII data.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100507const uint32_t kAsciiDataHintMask = 0x08;
508const uint32_t kAsciiDataHintTag = 0x08;
509
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100510// If bit 7 is clear and string representation indicates an external string,
511// then bit 4 indicates whether the data pointer is cached.
512const uint32_t kShortExternalStringMask = 0x10;
513const uint32_t kShortExternalStringTag = 0x10;
514
Steve Blocka7e24c12009-10-30 11:49:00 +0000515
516// A ConsString with an empty string as the right side is a candidate
517// for being shortcut by the garbage collector unless it is a
518// symbol. It's not common to have non-flat symbols, so we do not
519// shortcut them thereby avoiding turning symbols into strings. See
520// heap.cc and mark-compact.cc.
521const uint32_t kShortcutTypeMask =
522 kIsNotStringMask |
523 kIsSymbolMask |
524 kStringRepresentationMask;
525const uint32_t kShortcutTypeTag = kConsStringTag;
526
527
528enum InstanceType {
Leon Clarkee46be812010-01-19 14:06:41 +0000529 // String types.
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100530 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag,
Steve Blockd0582a62009-12-15 09:54:21 +0000531 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100532 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag,
Steve Blockd0582a62009-12-15 09:54:21 +0000533 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100534 SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag |
535 kExternalStringTag | kShortExternalStringTag,
536 SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
537 kTwoByteStringTag | kSymbolTag | kExternalStringTag |
538 kAsciiDataHintTag | kShortExternalStringTag,
539 SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kAsciiStringTag | kExternalStringTag |
540 kSymbolTag | kShortExternalStringTag,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100541 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag,
542 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
543 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag,
Steve Blockd0582a62009-12-15 09:54:21 +0000544 EXTERNAL_ASCII_SYMBOL_TYPE =
545 kAsciiStringTag | kSymbolTag | kExternalStringTag,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100546 STRING_TYPE = kTwoByteStringTag | kSeqStringTag,
Steve Blockd0582a62009-12-15 09:54:21 +0000547 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100548 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag,
Steve Blockd0582a62009-12-15 09:54:21 +0000549 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag,
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000550 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag,
551 SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100552 SHORT_EXTERNAL_STRING_TYPE =
553 kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag,
554 SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
555 kTwoByteStringTag | kExternalStringTag |
556 kAsciiDataHintTag | kShortExternalStringTag,
557 SHORT_EXTERNAL_ASCII_STRING_TYPE =
558 kAsciiStringTag | kExternalStringTag | kShortExternalStringTag,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100559 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag,
560 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
561 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag,
Steve Block1e0659c2011-05-24 12:43:12 +0100562 // LAST_STRING_TYPE
Steve Blockd0582a62009-12-15 09:54:21 +0000563 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag,
564 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000565
Leon Clarkee46be812010-01-19 14:06:41 +0000566 // Objects allocated in their own spaces (never in new space).
567 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE
Steve Blocka7e24c12009-10-30 11:49:00 +0000568 CODE_TYPE,
569 ODDBALL_TYPE,
570 JS_GLOBAL_PROPERTY_CELL_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000571
572 // "Data", objects that cannot contain non-map-word pointers to heap
573 // objects.
574 HEAP_NUMBER_TYPE,
Ben Murdoch257744e2011-11-30 15:57:28 +0000575 FOREIGN_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000576 BYTE_ARRAY_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100577 FREE_SPACE_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000578 EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE
Steve Block3ce2e202009-11-05 08:53:23 +0000579 EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
580 EXTERNAL_SHORT_ARRAY_TYPE,
581 EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
582 EXTERNAL_INT_ARRAY_TYPE,
583 EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
Steve Block44f0eee2011-05-26 01:26:41 +0100584 EXTERNAL_FLOAT_ARRAY_TYPE,
Ben Murdoch257744e2011-11-30 15:57:28 +0000585 EXTERNAL_DOUBLE_ARRAY_TYPE,
Steve Block44f0eee2011-05-26 01:26:41 +0100586 EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000587 FIXED_DOUBLE_ARRAY_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000588 FILLER_TYPE, // LAST_DATA_TYPE
Steve Blocka7e24c12009-10-30 11:49:00 +0000589
Leon Clarkee46be812010-01-19 14:06:41 +0000590 // Structs.
Steve Blocka7e24c12009-10-30 11:49:00 +0000591 ACCESSOR_INFO_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100592 ACCESSOR_PAIR_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000593 ACCESS_CHECK_INFO_TYPE,
594 INTERCEPTOR_INFO_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000595 CALL_HANDLER_INFO_TYPE,
596 FUNCTION_TEMPLATE_INFO_TYPE,
597 OBJECT_TEMPLATE_INFO_TYPE,
598 SIGNATURE_INFO_TYPE,
599 TYPE_SWITCH_INFO_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000600 SCRIPT_TYPE,
Steve Block6ded16b2010-05-10 14:33:55 +0100601 CODE_CACHE_TYPE,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000602 POLYMORPHIC_CODE_CACHE_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100603 TYPE_FEEDBACK_INFO_TYPE,
604 ALIASED_ARGUMENTS_ENTRY_TYPE,
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100605 // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT
606 // is defined. However as include/v8.h contain some of the instance type
607 // constants always having them avoids them getting different numbers
608 // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not.
Steve Blocka7e24c12009-10-30 11:49:00 +0000609 DEBUG_INFO_TYPE,
610 BREAK_POINT_INFO_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000611
Leon Clarkee46be812010-01-19 14:06:41 +0000612 FIXED_ARRAY_TYPE,
613 SHARED_FUNCTION_INFO_TYPE,
614
Steve Block1e0659c2011-05-24 12:43:12 +0100615 JS_MESSAGE_OBJECT_TYPE,
616
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100617 // All the following types are subtypes of JSReceiver, which corresponds to
618 // objects in the JS sense. The first and the last type in this range are
619 // the two forms of function. This organization enables using the same
620 // compares for checking the JS_RECEIVER/SPEC_OBJECT range and the
621 // NONCALLABLE_JS_OBJECT range.
622 JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE
623 JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE
624
625 JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE
626 JS_DATE_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000627 JS_OBJECT_TYPE,
628 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
629 JS_GLOBAL_OBJECT_TYPE,
630 JS_BUILTINS_OBJECT_TYPE,
631 JS_GLOBAL_PROXY_TYPE,
632 JS_ARRAY_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100633 JS_SET_TYPE,
634 JS_MAP_TYPE,
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000635 JS_WEAK_MAP_TYPE,
Steve Block1e0659c2011-05-24 12:43:12 +0100636
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100637 JS_REGEXP_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000638
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100639 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
Steve Blocka7e24c12009-10-30 11:49:00 +0000640
641 // Pseudo-types
Steve Blocka7e24c12009-10-30 11:49:00 +0000642 FIRST_TYPE = 0x0,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100643 LAST_TYPE = JS_FUNCTION_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000644 INVALID_TYPE = FIRST_TYPE - 1,
645 FIRST_NONSTRING_TYPE = MAP_TYPE,
646 // Boundaries for testing for an external array.
647 FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE,
Steve Block44f0eee2011-05-26 01:26:41 +0100648 LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000649 // Boundary for promotion to old data space/old pointer space.
650 LAST_DATA_TYPE = FILLER_TYPE,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000651 // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy).
652 // Note that there is no range for JSObject or JSProxy, since their subtypes
653 // are not continuous in this enum! The enum ranges instead reflect the
654 // external class names, where proxies are treated as either ordinary objects,
655 // or functions.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100656 FIRST_JS_RECEIVER_TYPE = JS_FUNCTION_PROXY_TYPE,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000657 LAST_JS_RECEIVER_TYPE = LAST_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100658 // Boundaries for testing the types represented as JSObject
659 FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE,
660 LAST_JS_OBJECT_TYPE = LAST_TYPE,
661 // Boundaries for testing the types represented as JSProxy
662 FIRST_JS_PROXY_TYPE = JS_FUNCTION_PROXY_TYPE,
663 LAST_JS_PROXY_TYPE = JS_PROXY_TYPE,
Ben Murdoch85b71792012-04-11 18:30:58 +0100664 // Boundaries for testing whether the type is a JavaScript object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100665 FIRST_SPEC_OBJECT_TYPE = FIRST_JS_RECEIVER_TYPE,
666 LAST_SPEC_OBJECT_TYPE = LAST_JS_RECEIVER_TYPE,
667 // Boundaries for testing the types for which typeof is "object".
668 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_PROXY_TYPE,
669 LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE,
670 // Note that the types for which typeof is "function" are not continuous.
671 // Define this so that we can put assertions on discrete checks.
672 NUM_OF_CALLABLE_SPEC_OBJECT_TYPES = 2
Steve Blocka7e24c12009-10-30 11:49:00 +0000673};
674
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100675const int kExternalArrayTypeCount =
676 LAST_EXTERNAL_ARRAY_TYPE - FIRST_EXTERNAL_ARRAY_TYPE + 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000677
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100678STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType);
679STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType);
Ben Murdoch257744e2011-11-30 15:57:28 +0000680STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType);
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100681
682
Steve Blocka7e24c12009-10-30 11:49:00 +0000683enum CompareResult {
684 LESS = -1,
685 EQUAL = 0,
686 GREATER = 1,
687
688 NOT_EQUAL = GREATER
689};
690
691
692#define DECL_BOOLEAN_ACCESSORS(name) \
693 inline bool name(); \
694 inline void set_##name(bool value); \
695
696
697#define DECL_ACCESSORS(name, type) \
698 inline type* name(); \
699 inline void set_##name(type* value, \
700 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \
701
702
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000703class DictionaryElementsAccessor;
704class ElementsAccessor;
705class FixedArrayBase;
Steve Blocka7e24c12009-10-30 11:49:00 +0000706class ObjectVisitor;
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000707class StringStream;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100708class Failure;
Steve Blocka7e24c12009-10-30 11:49:00 +0000709
710struct ValueInfo : public Malloced {
711 ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { }
712 InstanceType type;
713 Object* ptr;
714 const char* str;
715 double number;
716};
717
718
719// A template-ized version of the IsXXX functions.
720template <class C> static inline bool Is(Object* obj);
721
Ben Murdochb0fe1622011-05-05 13:52:32 +0100722
John Reck59135872010-11-02 12:39:01 -0700723class MaybeObject BASE_EMBEDDED {
724 public:
725 inline bool IsFailure();
726 inline bool IsRetryAfterGC();
727 inline bool IsOutOfMemory();
728 inline bool IsException();
729 INLINE(bool IsTheHole());
730 inline bool ToObject(Object** obj) {
731 if (IsFailure()) return false;
732 *obj = reinterpret_cast<Object*>(this);
733 return true;
734 }
Steve Block053d10c2011-06-13 19:13:29 +0100735 inline Failure* ToFailureUnchecked() {
736 ASSERT(IsFailure());
737 return reinterpret_cast<Failure*>(this);
738 }
John Reck59135872010-11-02 12:39:01 -0700739 inline Object* ToObjectUnchecked() {
740 ASSERT(!IsFailure());
741 return reinterpret_cast<Object*>(this);
742 }
743 inline Object* ToObjectChecked() {
744 CHECK(!IsFailure());
745 return reinterpret_cast<Object*>(this);
746 }
747
Steve Block053d10c2011-06-13 19:13:29 +0100748 template<typename T>
749 inline bool To(T** obj) {
750 if (IsFailure()) return false;
751 *obj = T::cast(reinterpret_cast<Object*>(this));
752 return true;
753 }
754
Ben Murdochb0fe1622011-05-05 13:52:32 +0100755#ifdef OBJECT_PRINT
John Reck59135872010-11-02 12:39:01 -0700756 // Prints this object with details.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100757 inline void Print() {
758 Print(stdout);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100759 }
Ben Murdochb0fe1622011-05-05 13:52:32 +0100760 inline void PrintLn() {
761 PrintLn(stdout);
762 }
763 void Print(FILE* out);
764 void PrintLn(FILE* out);
765#endif
766#ifdef DEBUG
John Reck59135872010-11-02 12:39:01 -0700767 // Verifies the object.
768 void Verify();
769#endif
770};
Steve Blocka7e24c12009-10-30 11:49:00 +0000771
Ben Murdochb8e0da22011-05-16 14:20:40 +0100772
773#define OBJECT_TYPE_LIST(V) \
774 V(Smi) \
775 V(HeapObject) \
776 V(Number) \
777
778#define HEAP_OBJECT_TYPE_LIST(V) \
779 V(HeapNumber) \
780 V(String) \
781 V(Symbol) \
782 V(SeqString) \
783 V(ExternalString) \
784 V(ConsString) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000785 V(SlicedString) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100786 V(ExternalTwoByteString) \
787 V(ExternalAsciiString) \
788 V(SeqTwoByteString) \
789 V(SeqAsciiString) \
790 \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100791 V(ExternalArray) \
792 V(ExternalByteArray) \
793 V(ExternalUnsignedByteArray) \
794 V(ExternalShortArray) \
795 V(ExternalUnsignedShortArray) \
796 V(ExternalIntArray) \
797 V(ExternalUnsignedIntArray) \
798 V(ExternalFloatArray) \
Ben Murdoch257744e2011-11-30 15:57:28 +0000799 V(ExternalDoubleArray) \
Steve Block44f0eee2011-05-26 01:26:41 +0100800 V(ExternalPixelArray) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100801 V(ByteArray) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100802 V(FreeSpace) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000803 V(JSReceiver) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100804 V(JSObject) \
805 V(JSContextExtensionObject) \
806 V(Map) \
807 V(DescriptorArray) \
808 V(DeoptimizationInputData) \
809 V(DeoptimizationOutputData) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100810 V(TypeFeedbackCells) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100811 V(FixedArray) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000812 V(FixedDoubleArray) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100813 V(Context) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100814 V(GlobalContext) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100815 V(ScopeInfo) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100816 V(JSFunction) \
817 V(Code) \
818 V(Oddball) \
819 V(SharedFunctionInfo) \
820 V(JSValue) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100821 V(JSDate) \
Steve Block1e0659c2011-05-24 12:43:12 +0100822 V(JSMessageObject) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100823 V(StringWrapper) \
Ben Murdoch257744e2011-11-30 15:57:28 +0000824 V(Foreign) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100825 V(Boolean) \
826 V(JSArray) \
Ben Murdoch257744e2011-11-30 15:57:28 +0000827 V(JSProxy) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000828 V(JSFunctionProxy) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100829 V(JSSet) \
830 V(JSMap) \
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000831 V(JSWeakMap) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100832 V(JSRegExp) \
833 V(HashTable) \
834 V(Dictionary) \
835 V(SymbolTable) \
836 V(JSFunctionResultCache) \
837 V(NormalizedMapCache) \
838 V(CompilationCacheTable) \
839 V(CodeCacheHashTable) \
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000840 V(PolymorphicCodeCacheHashTable) \
Ben Murdochb8e0da22011-05-16 14:20:40 +0100841 V(MapCache) \
842 V(Primitive) \
843 V(GlobalObject) \
844 V(JSGlobalObject) \
845 V(JSBuiltinsObject) \
846 V(JSGlobalProxy) \
847 V(UndetectableObject) \
848 V(AccessCheckNeeded) \
849 V(JSGlobalPropertyCell) \
850
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100851
852class JSReceiver;
853
Steve Blocka7e24c12009-10-30 11:49:00 +0000854// Object is the abstract superclass for all classes in the
855// object hierarchy.
856// Object does not use any virtual functions to avoid the
857// allocation of the C++ vtable.
858// Since Smi and Failure are subclasses of Object no
859// data members can be present in Object.
John Reck59135872010-11-02 12:39:01 -0700860class Object : public MaybeObject {
Steve Blocka7e24c12009-10-30 11:49:00 +0000861 public:
862 // Type testing.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100863 bool IsObject() { return true; }
864
Ben Murdochb8e0da22011-05-16 14:20:40 +0100865#define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_();
866 OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
867 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
868#undef IS_TYPE_FUNCTION_DECL
Steve Blocka7e24c12009-10-30 11:49:00 +0000869
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100870 inline bool IsFixedArrayBase();
871
Steve Blocka7e24c12009-10-30 11:49:00 +0000872 // Returns true if this object is an instance of the specified
873 // function template.
874 inline bool IsInstanceOf(FunctionTemplateInfo* type);
875
876 inline bool IsStruct();
877#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name();
878 STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
879#undef DECLARE_STRUCT_PREDICATE
880
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000881 INLINE(bool IsSpecObject());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100882 INLINE(bool IsSpecFunction());
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000883
Steve Blocka7e24c12009-10-30 11:49:00 +0000884 // Oddball testing.
885 INLINE(bool IsUndefined());
Steve Blocka7e24c12009-10-30 11:49:00 +0000886 INLINE(bool IsNull());
Steve Block44f0eee2011-05-26 01:26:41 +0100887 INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation.
Steve Blocka7e24c12009-10-30 11:49:00 +0000888 INLINE(bool IsTrue());
889 INLINE(bool IsFalse());
Ben Murdoch086aeea2011-05-13 15:57:08 +0100890 inline bool IsArgumentsMarker();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100891 inline bool NonFailureIsHeapObject();
892
893 // Filler objects (fillers and free space objects).
894 inline bool IsFiller();
Steve Blocka7e24c12009-10-30 11:49:00 +0000895
896 // Extract the number.
897 inline double Number();
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100898 inline bool IsNaN();
Steve Blocka7e24c12009-10-30 11:49:00 +0000899
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000900 // Returns true if the object is of the correct type to be used as a
901 // implementation of a JSObject's elements.
902 inline bool HasValidElements();
903
Steve Blocka7e24c12009-10-30 11:49:00 +0000904 inline bool HasSpecificClassOf(String* name);
905
John Reck59135872010-11-02 12:39:01 -0700906 MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9.
907 Object* ToBoolean(); // ECMA-262 9.2.
Steve Blocka7e24c12009-10-30 11:49:00 +0000908
909 // Convert to a JSObject if needed.
910 // global_context is used when creating wrapper object.
John Reck59135872010-11-02 12:39:01 -0700911 MUST_USE_RESULT MaybeObject* ToObject(Context* global_context);
Steve Blocka7e24c12009-10-30 11:49:00 +0000912
913 // Converts this to a Smi if possible.
914 // Failure is returned otherwise.
John Reck59135872010-11-02 12:39:01 -0700915 MUST_USE_RESULT inline MaybeObject* ToSmi();
Steve Blocka7e24c12009-10-30 11:49:00 +0000916
917 void Lookup(String* name, LookupResult* result);
918
919 // Property access.
John Reck59135872010-11-02 12:39:01 -0700920 MUST_USE_RESULT inline MaybeObject* GetProperty(String* key);
921 MUST_USE_RESULT inline MaybeObject* GetProperty(
922 String* key,
923 PropertyAttributes* attributes);
924 MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver(
925 Object* receiver,
926 String* key,
927 PropertyAttributes* attributes);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100928
929 static Handle<Object> GetProperty(Handle<Object> object,
930 Handle<Object> receiver,
931 LookupResult* result,
932 Handle<String> key,
933 PropertyAttributes* attributes);
934
John Reck59135872010-11-02 12:39:01 -0700935 MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver,
936 LookupResult* result,
937 String* key,
938 PropertyAttributes* attributes);
Ben Murdoch592a9fc2012-03-05 11:04:45 +0000939
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100940 MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver,
941 JSReceiver* getter);
942
943 static Handle<Object> GetElement(Handle<Object> object, uint32_t index);
944 MUST_USE_RESULT inline MaybeObject* GetElement(uint32_t index);
John Reck59135872010-11-02 12:39:01 -0700945 // For use when we know that no exception can be thrown.
946 inline Object* GetElementNoExceptionThrown(uint32_t index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100947 MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Object* receiver,
948 uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +0000949
950 // Return the object's prototype (might be Heap::null_value()).
951 Object* GetPrototype();
952
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100953 // Returns the permanent hash code associated with this object depending on
954 // the actual object type. Might return a failure in case no hash was
955 // created yet or GC was caused by creation.
956 MUST_USE_RESULT MaybeObject* GetHash(CreationFlag flag);
957
958 // Checks whether this object has the same value as the given one. This
959 // function is implemented according to ES5, section 9.12 and can be used
960 // to implement the Harmony "egal" function.
961 bool SameValue(Object* other);
962
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100963 // Tries to convert an object to an array index. Returns true and sets
964 // the output parameter if it succeeds.
965 inline bool ToArrayIndex(uint32_t* index);
966
Steve Blocka7e24c12009-10-30 11:49:00 +0000967 // Returns true if this is a JSValue containing a string and the index is
968 // < the length of the string. Used to implement [] on strings.
969 inline bool IsStringObjectWithCharacterAt(uint32_t index);
970
971#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +0000972 // Verify a pointer is a valid object pointer.
973 static void VerifyPointer(Object* p);
974#endif
975
976 // Prints this object without details.
Ben Murdochb0fe1622011-05-05 13:52:32 +0100977 inline void ShortPrint() {
978 ShortPrint(stdout);
979 }
980 void ShortPrint(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000981
982 // Prints this object without details to a message accumulator.
983 void ShortPrint(StringStream* accumulator);
984
985 // Casting: This cast is only needed to satisfy macros in objects-inl.h.
986 static Object* cast(Object* value) { return value; }
987
988 // Layout description.
989 static const int kHeaderSize = 0; // Object does not take up any space.
990
991 private:
992 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
993};
994
995
996// Smi represents integer Numbers that can be stored in 31 bits.
997// Smis are immediate which means they are NOT allocated in the heap.
Steve Blocka7e24c12009-10-30 11:49:00 +0000998// The this pointer has the following format: [31 bit signed int] 0
Steve Block3ce2e202009-11-05 08:53:23 +0000999// For long smis it has the following format:
1000// [32 bit signed int] [31 bits zero padding] 0
1001// Smi stands for small integer.
Steve Blocka7e24c12009-10-30 11:49:00 +00001002class Smi: public Object {
1003 public:
1004 // Returns the integer value.
1005 inline int value();
1006
1007 // Convert a value to a Smi object.
1008 static inline Smi* FromInt(int value);
1009
1010 static inline Smi* FromIntptr(intptr_t value);
1011
1012 // Returns whether value can be represented in a Smi.
1013 static inline bool IsValid(intptr_t value);
1014
Steve Blocka7e24c12009-10-30 11:49:00 +00001015 // Casting.
1016 static inline Smi* cast(Object* object);
1017
1018 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001019 inline void SmiPrint() {
1020 SmiPrint(stdout);
1021 }
1022 void SmiPrint(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001023 void SmiPrint(StringStream* accumulator);
1024#ifdef DEBUG
1025 void SmiVerify();
1026#endif
1027
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001028 static const int kMinValue =
1029 (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
Steve Block3ce2e202009-11-05 08:53:23 +00001030 static const int kMaxValue = -(kMinValue + 1);
Steve Blocka7e24c12009-10-30 11:49:00 +00001031
1032 private:
1033 DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);
1034};
1035
1036
1037// Failure is used for reporting out of memory situations and
1038// propagating exceptions through the runtime system. Failure objects
1039// are transient and cannot occur as part of the object graph.
1040//
1041// Failures are a single word, encoded as follows:
1042// +-------------------------+---+--+--+
Ben Murdochf87a2032010-10-22 12:50:53 +01001043// |.........unused..........|sss|tt|11|
Steve Blocka7e24c12009-10-30 11:49:00 +00001044// +-------------------------+---+--+--+
Steve Block3ce2e202009-11-05 08:53:23 +00001045// 7 6 4 32 10
1046//
Steve Blocka7e24c12009-10-30 11:49:00 +00001047//
1048// The low two bits, 0-1, are the failure tag, 11. The next two bits,
1049// 2-3, are a failure type tag 'tt' with possible values:
1050// 00 RETRY_AFTER_GC
1051// 01 EXCEPTION
1052// 10 INTERNAL_ERROR
1053// 11 OUT_OF_MEMORY_EXCEPTION
1054//
1055// The next three bits, 4-6, are an allocation space tag 'sss'. The
1056// allocation space tag is 000 for all failure types except
1057// RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the
1058// allocation spaces (the encoding is found in globals.h).
Steve Blocka7e24c12009-10-30 11:49:00 +00001059
1060// Failure type tag info.
1061const int kFailureTypeTagSize = 2;
1062const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1;
1063
John Reck59135872010-11-02 12:39:01 -07001064class Failure: public MaybeObject {
Steve Blocka7e24c12009-10-30 11:49:00 +00001065 public:
1066 // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code.
1067 enum Type {
1068 RETRY_AFTER_GC = 0,
1069 EXCEPTION = 1, // Returning this marker tells the real exception
Steve Block44f0eee2011-05-26 01:26:41 +01001070 // is in Isolate::pending_exception.
Steve Blocka7e24c12009-10-30 11:49:00 +00001071 INTERNAL_ERROR = 2,
1072 OUT_OF_MEMORY_EXCEPTION = 3
1073 };
1074
1075 inline Type type() const;
1076
1077 // Returns the space that needs to be collected for RetryAfterGC failures.
1078 inline AllocationSpace allocation_space() const;
1079
Steve Blocka7e24c12009-10-30 11:49:00 +00001080 inline bool IsInternalError() const;
1081 inline bool IsOutOfMemoryException() const;
1082
Ben Murdochf87a2032010-10-22 12:50:53 +01001083 static inline Failure* RetryAfterGC(AllocationSpace space);
1084 static inline Failure* RetryAfterGC(); // NEW_SPACE
Steve Blocka7e24c12009-10-30 11:49:00 +00001085 static inline Failure* Exception();
1086 static inline Failure* InternalError();
1087 static inline Failure* OutOfMemoryException();
1088 // Casting.
John Reck59135872010-11-02 12:39:01 -07001089 static inline Failure* cast(MaybeObject* object);
Steve Blocka7e24c12009-10-30 11:49:00 +00001090
1091 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001092 inline void FailurePrint() {
1093 FailurePrint(stdout);
1094 }
1095 void FailurePrint(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001096 void FailurePrint(StringStream* accumulator);
1097#ifdef DEBUG
1098 void FailureVerify();
1099#endif
1100
1101 private:
Steve Block3ce2e202009-11-05 08:53:23 +00001102 inline intptr_t value() const;
1103 static inline Failure* Construct(Type type, intptr_t value = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00001104
1105 DISALLOW_IMPLICIT_CONSTRUCTORS(Failure);
1106};
1107
1108
1109// Heap objects typically have a map pointer in their first word. However,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001110// during GC other data (e.g. mark bits, forwarding addresses) is sometimes
Steve Blocka7e24c12009-10-30 11:49:00 +00001111// encoded in the first word. The class MapWord is an abstraction of the
1112// value in a heap object's first word.
1113class MapWord BASE_EMBEDDED {
1114 public:
1115 // Normal state: the map word contains a map pointer.
1116
1117 // Create a map word from a map pointer.
1118 static inline MapWord FromMap(Map* map);
1119
1120 // View this map word as a map pointer.
1121 inline Map* ToMap();
1122
1123
1124 // Scavenge collection: the map word of live objects in the from space
1125 // contains a forwarding address (a heap object pointer in the to space).
1126
1127 // True if this map word is a forwarding address for a scavenge
1128 // collection. Only valid during a scavenge collection (specifically,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001129 // when all map words are heap object pointers, i.e. not during a full GC).
Steve Blocka7e24c12009-10-30 11:49:00 +00001130 inline bool IsForwardingAddress();
1131
1132 // Create a map word from a forwarding address.
1133 static inline MapWord FromForwardingAddress(HeapObject* object);
1134
1135 // View this map word as a forwarding address.
1136 inline HeapObject* ToForwardingAddress();
1137
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001138 static inline MapWord FromRawValue(uintptr_t value) {
1139 return MapWord(value);
1140 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001141
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001142 inline uintptr_t ToRawValue() {
1143 return value_;
1144 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001145
1146 private:
1147 // HeapObject calls the private constructor and directly reads the value.
1148 friend class HeapObject;
1149
1150 explicit MapWord(uintptr_t value) : value_(value) {}
1151
1152 uintptr_t value_;
1153};
1154
1155
1156// HeapObject is the superclass for all classes describing heap allocated
1157// objects.
1158class HeapObject: public Object {
1159 public:
1160 // [map]: Contains a map which contains the object's reflective
1161 // information.
1162 inline Map* map();
1163 inline void set_map(Map* value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001164 // The no-write-barrier version. This is OK if the object is white and in
1165 // new space, or if the value is an immortal immutable object, like the maps
1166 // of primitive (non-JS) objects like strings, heap numbers etc.
1167 inline void set_map_no_write_barrier(Map* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00001168
1169 // During garbage collection, the map word of a heap object does not
1170 // necessarily contain a map pointer.
1171 inline MapWord map_word();
1172 inline void set_map_word(MapWord map_word);
1173
Steve Block44f0eee2011-05-26 01:26:41 +01001174 // The Heap the object was allocated in. Used also to access Isolate.
Steve Block44f0eee2011-05-26 01:26:41 +01001175 inline Heap* GetHeap();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001176
Steve Block44f0eee2011-05-26 01:26:41 +01001177 // Convenience method to get current isolate. This method can be
1178 // accessed only when its result is the same as
1179 // Isolate::Current(), it ASSERTs this. See also comment for GetHeap.
1180 inline Isolate* GetIsolate();
1181
Steve Blocka7e24c12009-10-30 11:49:00 +00001182 // Converts an address to a HeapObject pointer.
1183 static inline HeapObject* FromAddress(Address address);
1184
1185 // Returns the address of this HeapObject.
1186 inline Address address();
1187
1188 // Iterates over pointers contained in the object (including the Map)
1189 void Iterate(ObjectVisitor* v);
1190
1191 // Iterates over all pointers contained in the object except the
1192 // first map pointer. The object type is given in the first
1193 // parameter. This function does not access the map pointer in the
1194 // object, and so is safe to call while the map pointer is modified.
1195 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1196
Steve Blocka7e24c12009-10-30 11:49:00 +00001197 // Returns the heap object's size in bytes
1198 inline int Size();
1199
1200 // Given a heap object's map pointer, returns the heap size in bytes
1201 // Useful when the map pointer field is used for other purposes.
1202 // GC internal.
1203 inline int SizeFromMap(Map* map);
1204
Steve Blocka7e24c12009-10-30 11:49:00 +00001205 // Returns the field at offset in obj, as a read/write Object* reference.
1206 // Does no checking, and is safe to use during GC, while maps are invalid.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001207 // Does not invoke write barrier, so should only be assigned to
Steve Blocka7e24c12009-10-30 11:49:00 +00001208 // during marking GC.
1209 static inline Object** RawField(HeapObject* obj, int offset);
1210
1211 // Casting.
1212 static inline HeapObject* cast(Object* obj);
1213
Leon Clarke4515c472010-02-03 11:58:03 +00001214 // Return the write barrier mode for this. Callers of this function
1215 // must be able to present a reference to an AssertNoAllocation
1216 // object as a sign that they are not going to use this function
1217 // from code that allocates and thus invalidates the returned write
1218 // barrier mode.
1219 inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&);
Steve Blocka7e24c12009-10-30 11:49:00 +00001220
1221 // Dispatched behavior.
1222 void HeapObjectShortPrint(StringStream* accumulator);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001223#ifdef OBJECT_PRINT
1224 inline void HeapObjectPrint() {
1225 HeapObjectPrint(stdout);
1226 }
1227 void HeapObjectPrint(FILE* out);
Ben Murdoch85b71792012-04-11 18:30:58 +01001228 void PrintHeader(FILE* out, const char* id);
1229#endif
1230
1231#ifdef DEBUG
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001232 void HeapObjectVerify();
1233 inline void VerifyObjectField(int offset);
1234 inline void VerifySmiField(int offset);
1235
Steve Blocka7e24c12009-10-30 11:49:00 +00001236 // Verify a pointer is a valid HeapObject pointer that points to object
1237 // areas in the heap.
1238 static void VerifyHeapPointer(Object* p);
1239#endif
1240
1241 // Layout description.
1242 // First field in a heap object is map.
1243 static const int kMapOffset = Object::kHeaderSize;
1244 static const int kHeaderSize = kMapOffset + kPointerSize;
1245
1246 STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset);
1247
1248 protected:
1249 // helpers for calling an ObjectVisitor to iterate over pointers in the
1250 // half-open range [start, end) specified as integer offsets
1251 inline void IteratePointers(ObjectVisitor* v, int start, int end);
1252 // as above, for the single element at "offset"
1253 inline void IteratePointer(ObjectVisitor* v, int offset);
1254
Steve Blocka7e24c12009-10-30 11:49:00 +00001255 private:
1256 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1257};
1258
1259
Iain Merrick75681382010-08-19 15:07:18 +01001260#define SLOT_ADDR(obj, offset) \
1261 reinterpret_cast<Object**>((obj)->address() + offset)
1262
1263// This class describes a body of an object of a fixed size
1264// in which all pointer fields are located in the [start_offset, end_offset)
1265// interval.
1266template<int start_offset, int end_offset, int size>
1267class FixedBodyDescriptor {
1268 public:
1269 static const int kStartOffset = start_offset;
1270 static const int kEndOffset = end_offset;
1271 static const int kSize = size;
1272
1273 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v);
1274
1275 template<typename StaticVisitor>
1276 static inline void IterateBody(HeapObject* obj) {
1277 StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset),
1278 SLOT_ADDR(obj, end_offset));
1279 }
1280};
1281
1282
1283// This class describes a body of an object of a variable size
1284// in which all pointer fields are located in the [start_offset, object_size)
1285// interval.
1286template<int start_offset>
1287class FlexibleBodyDescriptor {
1288 public:
1289 static const int kStartOffset = start_offset;
1290
1291 static inline void IterateBody(HeapObject* obj,
1292 int object_size,
1293 ObjectVisitor* v);
1294
1295 template<typename StaticVisitor>
1296 static inline void IterateBody(HeapObject* obj, int object_size) {
1297 StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset),
1298 SLOT_ADDR(obj, object_size));
1299 }
1300};
1301
1302#undef SLOT_ADDR
1303
1304
Steve Blocka7e24c12009-10-30 11:49:00 +00001305// The HeapNumber class describes heap allocated numbers that cannot be
1306// represented in a Smi (small integer)
1307class HeapNumber: public HeapObject {
1308 public:
1309 // [value]: number value.
1310 inline double value();
1311 inline void set_value(double value);
1312
1313 // Casting.
1314 static inline HeapNumber* cast(Object* obj);
1315
1316 // Dispatched behavior.
1317 Object* HeapNumberToBoolean();
Ben Murdochb0fe1622011-05-05 13:52:32 +01001318 inline void HeapNumberPrint() {
1319 HeapNumberPrint(stdout);
1320 }
1321 void HeapNumberPrint(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +00001322 void HeapNumberPrint(StringStream* accumulator);
1323#ifdef DEBUG
1324 void HeapNumberVerify();
1325#endif
1326
Steve Block6ded16b2010-05-10 14:33:55 +01001327 inline int get_exponent();
1328 inline int get_sign();
1329
Steve Blocka7e24c12009-10-30 11:49:00 +00001330 // Layout description.
1331 static const int kValueOffset = HeapObject::kHeaderSize;
1332 // IEEE doubles are two 32 bit words. The first is just mantissa, the second
1333 // is a mixture of sign, exponent and mantissa. Our current platforms are all
1334 // little endian apart from non-EABI arm which is little endian with big
1335 // endian floating point word ordering!
Steve Blocka7e24c12009-10-30 11:49:00 +00001336 static const int kMantissaOffset = kValueOffset;
1337 static const int kExponentOffset = kValueOffset + 4;
Ben Murdoch8b112d22011-06-08 16:22:53 +01001338
Steve Blocka7e24c12009-10-30 11:49:00 +00001339 static const int kSize = kValueOffset + kDoubleSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00001340 static const uint32_t kSignMask = 0x80000000u;
1341 static const uint32_t kExponentMask = 0x7ff00000u;
1342 static const uint32_t kMantissaMask = 0xfffffu;
Steve Block6ded16b2010-05-10 14:33:55 +01001343 static const int kMantissaBits = 52;
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01001344 static const int kExponentBits = 11;
Steve Blocka7e24c12009-10-30 11:49:00 +00001345 static const int kExponentBias = 1023;
1346 static const int kExponentShift = 20;
1347 static const int kMantissaBitsInTopWord = 20;
1348 static const int kNonMantissaBitsInTopWord = 12;
1349
1350 private:
1351 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
1352};
1353
1354
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001355enum EnsureElementsMode {
1356 DONT_ALLOW_DOUBLE_ELEMENTS,
1357 ALLOW_COPIED_DOUBLE_ELEMENTS,
1358 ALLOW_CONVERTED_DOUBLE_ELEMENTS
1359};
1360
1361
1362// Indicates whether a property should be set or (re)defined. Setting of a
1363// property causes attributes to remain unchanged, writability to be checked
1364// and callbacks to be called. Defining of a property causes attributes to
1365// be updated and callbacks to be overridden.
1366enum SetPropertyMode {
1367 SET_PROPERTY,
1368 DEFINE_PROPERTY
1369};
1370
1371
1372// Indicator for one component of an AccessorPair.
1373enum AccessorComponent {
1374 ACCESSOR_GETTER,
1375 ACCESSOR_SETTER
1376};
1377
1378
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001379// JSReceiver includes types on which properties can be defined, i.e.,
1380// JSObject and JSProxy.
1381class JSReceiver: public HeapObject {
Steve Blocka7e24c12009-10-30 11:49:00 +00001382 public:
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001383 enum DeleteMode {
1384 NORMAL_DELETION,
1385 STRICT_DELETION,
1386 FORCE_DELETION
1387 };
1388
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001389 // Casting.
1390 static inline JSReceiver* cast(Object* obj);
1391
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001392 static Handle<Object> SetProperty(Handle<JSReceiver> object,
1393 Handle<String> key,
1394 Handle<Object> value,
1395 PropertyAttributes attributes,
1396 StrictModeFlag strict_mode);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001397 // Can cause GC.
1398 MUST_USE_RESULT MaybeObject* SetProperty(String* key,
1399 Object* value,
1400 PropertyAttributes attributes,
1401 StrictModeFlag strict_mode);
1402 MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result,
1403 String* key,
1404 Object* value,
1405 PropertyAttributes attributes,
1406 StrictModeFlag strict_mode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001407 MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSReceiver* setter,
1408 Object* value);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001409
1410 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001411 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1412
1413 // Set the index'th array element.
1414 // Can cause GC, or return failure if GC is required.
1415 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index,
1416 Object* value,
1417 PropertyAttributes attributes,
1418 StrictModeFlag strict_mode,
1419 bool check_prototype);
1420
1421 // Tests for the fast common case for property enumeration.
1422 bool IsSimpleEnum();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001423
1424 // Returns the class name ([[Class]] property in the specification).
1425 String* class_name();
1426
1427 // Returns the constructor name (the name (possibly, inferred name) of the
1428 // function that was used to instantiate the object).
1429 String* constructor_name();
1430
1431 inline PropertyAttributes GetPropertyAttribute(String* name);
1432 PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver,
1433 String* name);
1434 PropertyAttributes GetLocalPropertyAttribute(String* name);
1435
1436 // Can cause a GC.
1437 inline bool HasProperty(String* name);
1438 inline bool HasLocalProperty(String* name);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001439 inline bool HasElement(uint32_t index);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001440
1441 // Return the object's prototype (might be Heap::null_value()).
1442 inline Object* GetPrototype();
1443
1444 // Set the object's prototype (only JSReceiver and null are allowed).
1445 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value,
1446 bool skip_hidden_prototypes);
1447
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001448 // Retrieves a permanent object identity hash code. The undefined value might
1449 // be returned in case no hash was created yet and OMIT_CREATION was used.
1450 inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1451
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001452 // Lookup a property. If found, the result is valid and has
1453 // detailed information.
1454 void LocalLookup(String* name, LookupResult* result);
1455 void Lookup(String* name, LookupResult* result);
1456
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001457 protected:
1458 Smi* GenerateIdentityHash();
1459
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001460 private:
1461 PropertyAttributes GetPropertyAttribute(JSReceiver* receiver,
1462 LookupResult* result,
1463 String* name,
1464 bool continue_search);
1465
1466 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver);
1467};
1468
1469// The JSObject describes real heap allocated JavaScript objects with
1470// properties.
1471// Note that the map of JSObject changes during execution to enable inline
1472// caching.
1473class JSObject: public JSReceiver {
1474 public:
Steve Blocka7e24c12009-10-30 11:49:00 +00001475 // [properties]: Backing storage for properties.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001476 // properties is a FixedArray in the fast case and a Dictionary in the
Steve Blocka7e24c12009-10-30 11:49:00 +00001477 // slow case.
1478 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
1479 inline void initialize_properties();
1480 inline bool HasFastProperties();
1481 inline StringDictionary* property_dictionary(); // Gets slow properties.
1482
1483 // [elements]: The elements (properties with names that are integers).
Iain Merrick75681382010-08-19 15:07:18 +01001484 //
1485 // Elements can be in two general modes: fast and slow. Each mode
1486 // corrensponds to a set of object representations of elements that
1487 // have something in common.
1488 //
1489 // In the fast mode elements is a FixedArray and so each element can
1490 // be quickly accessed. This fact is used in the generated code. The
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001491 // elements array can have one of three maps in this mode:
1492 // fixed_array_map, non_strict_arguments_elements_map or
1493 // fixed_cow_array_map (for copy-on-write arrays). In the latter case
1494 // the elements array may be shared by a few objects and so before
1495 // writing to any element the array must be copied. Use
1496 // EnsureWritableFastElements in this case.
Iain Merrick75681382010-08-19 15:07:18 +01001497 //
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001498 // In the slow mode the elements is either a NumberDictionary, an
1499 // ExternalArray, or a FixedArray parameter map for a (non-strict)
1500 // arguments object.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001501 DECL_ACCESSORS(elements, FixedArrayBase)
Steve Blocka7e24c12009-10-30 11:49:00 +00001502 inline void initialize_elements();
John Reck59135872010-11-02 12:39:01 -07001503 MUST_USE_RESULT inline MaybeObject* ResetElements();
Steve Blocka7e24c12009-10-30 11:49:00 +00001504 inline ElementsKind GetElementsKind();
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001505 inline ElementsAccessor* GetElementsAccessor();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001506 inline bool HasFastSmiOnlyElements();
Steve Blocka7e24c12009-10-30 11:49:00 +00001507 inline bool HasFastElements();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001508 // Returns if an object has either FAST_ELEMENT or FAST_SMI_ONLY_ELEMENT
1509 // elements. TODO(danno): Rename HasFastTypeElements to HasFastElements() and
1510 // HasFastElements to HasFastObjectElements.
1511 inline bool HasFastTypeElements();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001512 inline bool HasFastDoubleElements();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001513 inline bool HasNonStrictArgumentsElements();
Steve Blocka7e24c12009-10-30 11:49:00 +00001514 inline bool HasDictionaryElements();
Steve Block44f0eee2011-05-26 01:26:41 +01001515 inline bool HasExternalPixelElements();
Steve Block3ce2e202009-11-05 08:53:23 +00001516 inline bool HasExternalArrayElements();
1517 inline bool HasExternalByteElements();
1518 inline bool HasExternalUnsignedByteElements();
1519 inline bool HasExternalShortElements();
1520 inline bool HasExternalUnsignedShortElements();
1521 inline bool HasExternalIntElements();
1522 inline bool HasExternalUnsignedIntElements();
1523 inline bool HasExternalFloatElements();
Ben Murdoch257744e2011-11-30 15:57:28 +00001524 inline bool HasExternalDoubleElements();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001525 bool HasFastArgumentsElements();
1526 bool HasDictionaryArgumentsElements();
Ben Murdochc7cc0282012-03-05 14:35:55 +00001527 inline SeededNumberDictionary* element_dictionary(); // Gets slow elements.
1528
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001529 inline void set_map_and_elements(
1530 Map* map,
1531 FixedArrayBase* value,
1532 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
1533
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001534 // Requires: HasFastElements().
John Reck59135872010-11-02 12:39:01 -07001535 MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements();
Steve Blocka7e24c12009-10-30 11:49:00 +00001536
1537 // Collects elements starting at index 0.
1538 // Undefined values are placed after non-undefined values.
1539 // Returns the number of non-undefined values.
John Reck59135872010-11-02 12:39:01 -07001540 MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit);
Steve Blocka7e24c12009-10-30 11:49:00 +00001541 // As PrepareElementsForSort, but only on objects where elements is
1542 // a dictionary, and it will stay a dictionary.
John Reck59135872010-11-02 12:39:01 -07001543 MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit);
Steve Blocka7e24c12009-10-30 11:49:00 +00001544
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001545 MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver,
1546 Object* structure,
1547 String* name);
1548
1549 // Can cause GC.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001550 MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result,
John Reck59135872010-11-02 12:39:01 -07001551 String* key,
1552 Object* value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001553 PropertyAttributes attributes,
1554 StrictModeFlag strict_mode);
John Reck59135872010-11-02 12:39:01 -07001555 MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck(
1556 LookupResult* result,
1557 String* name,
Ben Murdoch086aeea2011-05-13 15:57:08 +01001558 Object* value,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001559 bool check_prototype,
1560 StrictModeFlag strict_mode);
1561 MUST_USE_RESULT MaybeObject* SetPropertyWithCallback(
1562 Object* structure,
1563 String* name,
1564 Object* value,
1565 JSObject* holder,
1566 StrictModeFlag strict_mode);
John Reck59135872010-11-02 12:39:01 -07001567 MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor(
1568 String* name,
1569 Object* value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001570 PropertyAttributes attributes,
1571 StrictModeFlag strict_mode);
John Reck59135872010-11-02 12:39:01 -07001572 MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor(
1573 String* name,
1574 Object* value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001575 PropertyAttributes attributes,
1576 StrictModeFlag strict_mode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001577
1578 static Handle<Object> SetLocalPropertyIgnoreAttributes(
1579 Handle<JSObject> object,
1580 Handle<String> key,
1581 Handle<Object> value,
1582 PropertyAttributes attributes);
1583
1584 // Can cause GC.
Ben Murdoch086aeea2011-05-13 15:57:08 +01001585 MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes(
John Reck59135872010-11-02 12:39:01 -07001586 String* key,
1587 Object* value,
1588 PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +00001589
1590 // Retrieve a value in a normalized object given a lookup result.
1591 // Handles the special representation of JS global objects.
1592 Object* GetNormalizedProperty(LookupResult* result);
1593
1594 // Sets the property value in a normalized object given a lookup result.
1595 // Handles the special representation of JS global objects.
1596 Object* SetNormalizedProperty(LookupResult* result, Object* value);
1597
1598 // Sets the property value in a normalized object given (key, value, details).
1599 // Handles the special representation of JS global objects.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001600 static Handle<Object> SetNormalizedProperty(Handle<JSObject> object,
1601 Handle<String> key,
1602 Handle<Object> value,
1603 PropertyDetails details);
1604
John Reck59135872010-11-02 12:39:01 -07001605 MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name,
1606 Object* value,
1607 PropertyDetails details);
Steve Blocka7e24c12009-10-30 11:49:00 +00001608
1609 // Deletes the named property in a normalized object.
John Reck59135872010-11-02 12:39:01 -07001610 MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name,
1611 DeleteMode mode);
Steve Blocka7e24c12009-10-30 11:49:00 +00001612
Steve Blocka7e24c12009-10-30 11:49:00 +00001613 // Retrieve interceptors.
1614 InterceptorInfo* GetNamedInterceptor();
1615 InterceptorInfo* GetIndexedInterceptor();
1616
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001617 // Used from JSReceiver.
1618 PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver,
1619 String* name,
1620 bool continue_search);
1621 PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver,
1622 String* name,
1623 bool continue_search);
1624 PropertyAttributes GetPropertyAttributeWithFailedAccessCheck(
1625 Object* receiver,
1626 LookupResult* result,
1627 String* name,
1628 bool continue_search);
Steve Blocka7e24c12009-10-30 11:49:00 +00001629
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001630 static void DefineAccessor(Handle<JSObject> object,
1631 Handle<String> name,
1632 Handle<Object> getter,
1633 Handle<Object> setter,
1634 PropertyAttributes attributes);
John Reck59135872010-11-02 12:39:01 -07001635 MUST_USE_RESULT MaybeObject* DefineAccessor(String* name,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001636 Object* getter,
1637 Object* setter,
John Reck59135872010-11-02 12:39:01 -07001638 PropertyAttributes attributes);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001639 Object* LookupAccessor(String* name, AccessorComponent component);
Steve Blocka7e24c12009-10-30 11:49:00 +00001640
John Reck59135872010-11-02 12:39:01 -07001641 MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info);
Leon Clarkef7060e22010-06-03 12:02:55 +01001642
Steve Blocka7e24c12009-10-30 11:49:00 +00001643 // Used from Object::GetProperty().
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001644 MUST_USE_RESULT MaybeObject* GetPropertyWithFailedAccessCheck(
John Reck59135872010-11-02 12:39:01 -07001645 Object* receiver,
1646 LookupResult* result,
1647 String* name,
1648 PropertyAttributes* attributes);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001649 MUST_USE_RESULT MaybeObject* GetPropertyWithInterceptor(
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001650 JSReceiver* receiver,
John Reck59135872010-11-02 12:39:01 -07001651 String* name,
1652 PropertyAttributes* attributes);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001653 MUST_USE_RESULT MaybeObject* GetPropertyPostInterceptor(
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001654 JSReceiver* receiver,
John Reck59135872010-11-02 12:39:01 -07001655 String* name,
1656 PropertyAttributes* attributes);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001657 MUST_USE_RESULT MaybeObject* GetLocalPropertyPostInterceptor(
1658 JSReceiver* receiver,
1659 String* name,
1660 PropertyAttributes* attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +00001661
1662 // Returns true if this is an instance of an api function and has
1663 // been modified since it was created. May give false positives.
1664 bool IsDirty();
1665
Steve Blockd0582a62009-12-15 09:54:21 +00001666 // If the receiver is a JSGlobalProxy this method will return its prototype,
1667 // otherwise the result is the receiver itself.
1668 inline Object* BypassGlobalProxy();
1669
1670 // Accessors for hidden properties object.
1671 //
1672 // Hidden properties are not local properties of the object itself.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001673 // Instead they are stored in an auxiliary structure kept as a local
Steve Blockd0582a62009-12-15 09:54:21 +00001674 // property with a special name Heap::hidden_symbol(). But if the
1675 // receiver is a JSGlobalProxy then the auxiliary object is a property
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001676 // of its prototype, and if it's a detached proxy, then you can't have
1677 // hidden properties.
Steve Blockd0582a62009-12-15 09:54:21 +00001678
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001679 // Sets a hidden property on this object. Returns this object if successful,
1680 // undefined if called on a detached proxy.
1681 static Handle<Object> SetHiddenProperty(Handle<JSObject> obj,
1682 Handle<String> key,
1683 Handle<Object> value);
1684 // Returns a failure if a GC is required.
1685 MUST_USE_RESULT MaybeObject* SetHiddenProperty(String* key, Object* value);
1686 // Gets the value of a hidden property with the given key. Returns undefined
1687 // if the property doesn't exist (or if called on a detached proxy),
1688 // otherwise returns the value set for the key.
1689 Object* GetHiddenProperty(String* key);
1690 // Deletes a hidden property. Deleting a non-existing property is
1691 // considered successful.
1692 void DeleteHiddenProperty(String* key);
1693 // Returns true if the object has a property with the hidden symbol as name.
1694 bool HasHiddenProperties();
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001695
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001696 static int GetIdentityHash(Handle<JSObject> obj);
1697 MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1698 MUST_USE_RESULT MaybeObject* SetIdentityHash(Object* hash, CreationFlag flag);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001699
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001700 static Handle<Object> DeleteProperty(Handle<JSObject> obj,
1701 Handle<String> name);
John Reck59135872010-11-02 12:39:01 -07001702 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001703
1704 static Handle<Object> DeleteElement(Handle<JSObject> obj, uint32_t index);
John Reck59135872010-11-02 12:39:01 -07001705 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
Steve Blocka7e24c12009-10-30 11:49:00 +00001706
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001707 inline void ValidateSmiOnlyElements();
1708
1709 // Makes sure that this object can contain HeapObject as elements.
1710 MUST_USE_RESULT inline MaybeObject* EnsureCanContainHeapObjectElements();
1711
1712 // Makes sure that this object can contain the specified elements.
1713 MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
1714 Object** elements,
1715 uint32_t count,
1716 EnsureElementsMode mode);
1717 MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
1718 FixedArrayBase* elements,
1719 EnsureElementsMode mode);
1720 MUST_USE_RESULT MaybeObject* EnsureCanContainElements(
1721 Arguments* arguments,
1722 uint32_t first_arg,
1723 uint32_t arg_count,
1724 EnsureElementsMode mode);
Steve Blocka7e24c12009-10-30 11:49:00 +00001725
1726 // Do we want to keep the elements in fast case when increasing the
1727 // capacity?
1728 bool ShouldConvertToSlowElements(int new_capacity);
1729 // Returns true if the backing storage for the slow-case elements of
1730 // this object takes up nearly as much space as a fast-case backing
1731 // storage would. In that case the JSObject should have fast
1732 // elements.
1733 bool ShouldConvertToFastElements();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001734 // Returns true if the elements of JSObject contains only values that can be
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001735 // represented in a FixedDoubleArray and has at least one value that can only
1736 // be represented as a double and not a Smi.
1737 bool ShouldConvertToFastDoubleElements(bool* has_smi_only_elements);
Andrei Popescu402d9372010-02-26 13:31:12 +00001738
Steve Blocka7e24c12009-10-30 11:49:00 +00001739 // Tells whether the index'th element is present.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001740 bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001741
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001742 // Computes the new capacity when expanding the elements of a JSObject.
1743 static int NewElementsCapacity(int old_capacity) {
1744 // (old_capacity + 50%) + 16
1745 return old_capacity + (old_capacity >> 1) + 16;
1746 }
1747
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001748 // Tells whether the index'th element is present and how it is stored.
1749 enum LocalElementType {
1750 // There is no element with given index.
1751 UNDEFINED_ELEMENT,
1752
1753 // Element with given index is handled by interceptor.
1754 INTERCEPTED_ELEMENT,
1755
1756 // Element with given index is character in string.
1757 STRING_CHARACTER_ELEMENT,
1758
1759 // Element with given index is stored in fast backing store.
1760 FAST_ELEMENT,
1761
1762 // Element with given index is stored in slow backing store.
1763 DICTIONARY_ELEMENT
1764 };
1765
1766 LocalElementType HasLocalElement(uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +00001767
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001768 bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +00001769
Steve Block9fac8402011-05-12 15:51:54 +01001770 MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index,
1771 Object* value,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001772 StrictModeFlag strict_mode,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001773 bool check_prototype);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001774
1775 MUST_USE_RESULT MaybeObject* SetDictionaryElement(
1776 uint32_t index,
1777 Object* value,
1778 PropertyAttributes attributes,
1779 StrictModeFlag strict_mode,
1780 bool check_prototype,
1781 SetPropertyMode set_mode = SET_PROPERTY);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001782
1783 MUST_USE_RESULT MaybeObject* SetFastDoubleElement(
1784 uint32_t index,
1785 Object* value,
1786 StrictModeFlag strict_mode,
1787 bool check_prototype = true);
Steve Blocka7e24c12009-10-30 11:49:00 +00001788
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001789 static Handle<Object> SetOwnElement(Handle<JSObject> object,
1790 uint32_t index,
1791 Handle<Object> value,
1792 StrictModeFlag strict_mode);
1793
1794 // Empty handle is returned if the element cannot be set to the given value.
1795 static MUST_USE_RESULT Handle<Object> SetElement(
1796 Handle<JSObject> object,
1797 uint32_t index,
1798 Handle<Object> value,
1799 PropertyAttributes attr,
1800 StrictModeFlag strict_mode,
1801 SetPropertyMode set_mode = SET_PROPERTY);
1802
Steve Blocka7e24c12009-10-30 11:49:00 +00001803 // A Failure object is returned if GC is needed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001804 MUST_USE_RESULT MaybeObject* SetElement(
1805 uint32_t index,
1806 Object* value,
1807 PropertyAttributes attributes,
1808 StrictModeFlag strict_mode,
1809 bool check_prototype = true,
1810 SetPropertyMode set_mode = SET_PROPERTY);
Steve Blocka7e24c12009-10-30 11:49:00 +00001811
1812 // Returns the index'th element.
1813 // The undefined object if index is out of bounds.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001814 MUST_USE_RESULT MaybeObject* GetElementWithInterceptor(Object* receiver,
1815 uint32_t index);
1816
1817 enum SetFastElementsCapacityMode {
1818 kAllowSmiOnlyElements,
1819 kForceSmiOnlyElements,
1820 kDontAllowSmiOnlyElements
1821 };
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001822
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001823 // Replace the elements' backing store with fast elements of the given
1824 // capacity. Update the length for JSArrays. Returns the new backing
1825 // store.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001826 MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(
1827 int capacity,
1828 int length,
1829 SetFastElementsCapacityMode set_capacity_mode);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001830 MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength(
1831 int capacity,
1832 int length);
Steve Blocka7e24c12009-10-30 11:49:00 +00001833
1834 // Lookup interceptors are used for handling properties controlled by host
1835 // objects.
1836 inline bool HasNamedInterceptor();
1837 inline bool HasIndexedInterceptor();
1838
1839 // Support functions for v8 api (needed for correct interceptor behavior).
1840 bool HasRealNamedProperty(String* key);
1841 bool HasRealElementProperty(uint32_t index);
1842 bool HasRealNamedCallbackProperty(String* key);
1843
Steve Blocka7e24c12009-10-30 11:49:00 +00001844 // Get the header size for a JSObject. Used to compute the index of
1845 // internal fields as well as the number of internal fields.
1846 inline int GetHeaderSize();
1847
1848 inline int GetInternalFieldCount();
Steve Block44f0eee2011-05-26 01:26:41 +01001849 inline int GetInternalFieldOffset(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00001850 inline Object* GetInternalField(int index);
1851 inline void SetInternalField(int index, Object* value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001852 inline void SetInternalField(int index, Smi* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00001853
1854 // The following lookup functions skip interceptors.
1855 void LocalLookupRealNamedProperty(String* name, LookupResult* result);
1856 void LookupRealNamedProperty(String* name, LookupResult* result);
1857 void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result);
1858 void LookupCallbackSetterInPrototypes(String* name, LookupResult* result);
Steve Block1e0659c2011-05-24 12:43:12 +01001859 MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes(
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001860 uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +00001861 void LookupCallback(String* name, LookupResult* result);
1862
1863 // Returns the number of properties on this object filtering out properties
1864 // with the specified attributes (ignoring interceptors).
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001865 int NumberOfLocalProperties(PropertyAttributes filter = NONE);
Steve Blocka7e24c12009-10-30 11:49:00 +00001866 // Fill in details for properties into storage starting at the specified
1867 // index.
1868 void GetLocalPropertyNames(FixedArray* storage, int index);
1869
1870 // Returns the number of properties on this object filtering out properties
1871 // with the specified attributes (ignoring interceptors).
1872 int NumberOfLocalElements(PropertyAttributes filter);
1873 // Returns the number of enumerable elements (ignoring interceptors).
1874 int NumberOfEnumElements();
1875 // Returns the number of elements on this object filtering out elements
1876 // with the specified attributes (ignoring interceptors).
1877 int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter);
1878 // Count and fill in the enumerable elements into storage.
1879 // (storage->length() == NumberOfEnumElements()).
1880 // If storage is NULL, will count the elements without adding
1881 // them to any storage.
1882 // Returns the number of enumerable elements.
1883 int GetEnumElementKeys(FixedArray* storage);
1884
1885 // Add a property to a fast-case object using a map transition to
1886 // new_map.
John Reck59135872010-11-02 12:39:01 -07001887 MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map,
1888 String* name,
1889 Object* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00001890
1891 // Add a constant function property to a fast-case object.
1892 // This leaves a CONSTANT_TRANSITION in the old map, and
1893 // if it is called on a second object with this map, a
1894 // normal property is added instead, with a map transition.
1895 // This avoids the creation of many maps with the same constant
1896 // function, all orphaned.
John Reck59135872010-11-02 12:39:01 -07001897 MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty(
1898 String* name,
1899 JSFunction* function,
1900 PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +00001901
John Reck59135872010-11-02 12:39:01 -07001902 MUST_USE_RESULT MaybeObject* ReplaceSlowProperty(
1903 String* name,
1904 Object* value,
1905 PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +00001906
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001907 // Returns a new map with all transitions dropped from the object's current
1908 // map and the ElementsKind set.
1909 static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
1910 ElementsKind to_kind);
1911 inline MUST_USE_RESULT MaybeObject* GetElementsTransitionMap(
1912 Isolate* isolate,
1913 ElementsKind elements_kind);
1914 MUST_USE_RESULT MaybeObject* GetElementsTransitionMapSlow(
1915 ElementsKind elements_kind);
1916
1917 static Handle<Object> TransitionElementsKind(Handle<JSObject> object,
1918 ElementsKind to_kind);
1919
1920 MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind);
1921
Steve Blocka7e24c12009-10-30 11:49:00 +00001922 // Converts a descriptor of any other type to a real field,
1923 // backed by the properties array. Descriptors of visible
1924 // types, such as CONSTANT_FUNCTION, keep their enumeration order.
1925 // Converts the descriptor on the original object's map to a
1926 // map transition, and the the new field is on the object's new map.
John Reck59135872010-11-02 12:39:01 -07001927 MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition(
Steve Blocka7e24c12009-10-30 11:49:00 +00001928 String* name,
1929 Object* new_value,
1930 PropertyAttributes attributes);
1931
1932 // Converts a descriptor of any other type to a real field,
1933 // backed by the properties array. Descriptors of visible
1934 // types, such as CONSTANT_FUNCTION, keep their enumeration order.
John Reck59135872010-11-02 12:39:01 -07001935 MUST_USE_RESULT MaybeObject* ConvertDescriptorToField(
1936 String* name,
1937 Object* new_value,
1938 PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +00001939
1940 // Add a property to a fast-case object.
John Reck59135872010-11-02 12:39:01 -07001941 MUST_USE_RESULT MaybeObject* AddFastProperty(String* name,
1942 Object* value,
1943 PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +00001944
1945 // Add a property to a slow-case object.
John Reck59135872010-11-02 12:39:01 -07001946 MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name,
1947 Object* value,
1948 PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +00001949
1950 // Add a property to an object.
John Reck59135872010-11-02 12:39:01 -07001951 MUST_USE_RESULT MaybeObject* AddProperty(String* name,
1952 Object* value,
Steve Block44f0eee2011-05-26 01:26:41 +01001953 PropertyAttributes attributes,
1954 StrictModeFlag strict_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +00001955
1956 // Convert the object to use the canonical dictionary
1957 // representation. If the object is expected to have additional properties
1958 // added this number can be indicated to have the backing store allocated to
1959 // an initial capacity for holding these properties.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001960 static void NormalizeProperties(Handle<JSObject> object,
1961 PropertyNormalizationMode mode,
1962 int expected_additional_properties);
1963
John Reck59135872010-11-02 12:39:01 -07001964 MUST_USE_RESULT MaybeObject* NormalizeProperties(
1965 PropertyNormalizationMode mode,
1966 int expected_additional_properties);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001967
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001968 // Convert and update the elements backing store to be a
1969 // SeededNumberDictionary dictionary. Returns the backing after conversion.
1970 static Handle<SeededNumberDictionary> NormalizeElements(
1971 Handle<JSObject> object);
1972
John Reck59135872010-11-02 12:39:01 -07001973 MUST_USE_RESULT MaybeObject* NormalizeElements();
Steve Blocka7e24c12009-10-30 11:49:00 +00001974
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001975 static void UpdateMapCodeCache(Handle<JSObject> object,
1976 Handle<String> name,
1977 Handle<Code> code);
1978
John Reck59135872010-11-02 12:39:01 -07001979 MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001980
Steve Blocka7e24c12009-10-30 11:49:00 +00001981 // Transform slow named properties to fast variants.
1982 // Returns failure if allocation failed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001983 static void TransformToFastProperties(Handle<JSObject> object,
1984 int unused_property_fields);
1985
John Reck59135872010-11-02 12:39:01 -07001986 MUST_USE_RESULT MaybeObject* TransformToFastProperties(
1987 int unused_property_fields);
Steve Blocka7e24c12009-10-30 11:49:00 +00001988
1989 // Access fast-case object properties at index.
1990 inline Object* FastPropertyAt(int index);
1991 inline Object* FastPropertyAtPut(int index, Object* value);
1992
1993 // Access to in object properties.
Steve Block44f0eee2011-05-26 01:26:41 +01001994 inline int GetInObjectPropertyOffset(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00001995 inline Object* InObjectPropertyAt(int index);
1996 inline Object* InObjectPropertyAtPut(int index,
1997 Object* value,
1998 WriteBarrierMode mode
1999 = UPDATE_WRITE_BARRIER);
2000
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002001 // Initializes the body after properties slot, properties slot is
2002 // initialized by set_properties. Fill the pre-allocated fields with
2003 // pre_allocated_value and the rest with filler_value.
2004 // Note: this call does not update write barrier, the caller is responsible
2005 // to ensure that |filler_value| can be collected without WB here.
2006 inline void InitializeBody(Map* map,
2007 Object* pre_allocated_value,
2008 Object* filler_value);
Steve Blocka7e24c12009-10-30 11:49:00 +00002009
2010 // Check whether this object references another object
2011 bool ReferencesObject(Object* obj);
2012
2013 // Casting.
2014 static inline JSObject* cast(Object* obj);
2015
Steve Block8defd9f2010-07-08 12:39:36 +01002016 // Disalow further properties to be added to the object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002017 static Handle<Object> PreventExtensions(Handle<JSObject> object);
John Reck59135872010-11-02 12:39:01 -07002018 MUST_USE_RESULT MaybeObject* PreventExtensions();
Steve Block8defd9f2010-07-08 12:39:36 +01002019
2020
Steve Blocka7e24c12009-10-30 11:49:00 +00002021 // Dispatched behavior.
Steve Blocka7e24c12009-10-30 11:49:00 +00002022 void JSObjectShortPrint(StringStream* accumulator);
Ben Murdochb0fe1622011-05-05 13:52:32 +01002023#ifdef OBJECT_PRINT
2024 inline void JSObjectPrint() {
2025 JSObjectPrint(stdout);
2026 }
2027 void JSObjectPrint(FILE* out);
2028#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00002029#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00002030 void JSObjectVerify();
Ben Murdochb0fe1622011-05-05 13:52:32 +01002031#endif
2032#ifdef OBJECT_PRINT
2033 inline void PrintProperties() {
2034 PrintProperties(stdout);
2035 }
2036 void PrintProperties(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +00002037
Ben Murdochb0fe1622011-05-05 13:52:32 +01002038 inline void PrintElements() {
2039 PrintElements(stdout);
2040 }
2041 void PrintElements(FILE* out);
2042#endif
2043
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002044 void PrintElementsTransition(
2045 FILE* file, ElementsKind from_kind, FixedArrayBase* from_elements,
2046 ElementsKind to_kind, FixedArrayBase* to_elements);
2047
Ben Murdochb0fe1622011-05-05 13:52:32 +01002048#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00002049 // Structure for collecting spill information about JSObjects.
2050 class SpillInformation {
2051 public:
2052 void Clear();
2053 void Print();
2054 int number_of_objects_;
2055 int number_of_objects_with_fast_properties_;
2056 int number_of_objects_with_fast_elements_;
2057 int number_of_fast_used_fields_;
2058 int number_of_fast_unused_fields_;
2059 int number_of_slow_used_properties_;
2060 int number_of_slow_unused_properties_;
2061 int number_of_fast_used_elements_;
2062 int number_of_fast_unused_elements_;
2063 int number_of_slow_used_elements_;
2064 int number_of_slow_unused_elements_;
2065 };
2066
2067 void IncrementSpillStatistics(SpillInformation* info);
2068#endif
2069 Object* SlowReverseLookup(Object* value);
2070
Steve Block8defd9f2010-07-08 12:39:36 +01002071 // Maximal number of fast properties for the JSObject. Used to
2072 // restrict the number of map transitions to avoid an explosion in
2073 // the number of maps for objects used as dictionaries.
2074 inline int MaxFastProperties();
2075
Leon Clarkee46be812010-01-19 14:06:41 +00002076 // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
2077 // Also maximal value of JSArray's length property.
2078 static const uint32_t kMaxElementCount = 0xffffffffu;
2079
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002080 // Constants for heuristics controlling conversion of fast elements
2081 // to slow elements.
2082
2083 // Maximal gap that can be introduced by adding an element beyond
2084 // the current elements length.
Steve Blocka7e24c12009-10-30 11:49:00 +00002085 static const uint32_t kMaxGap = 1024;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002086
2087 // Maximal length of fast elements array that won't be checked for
2088 // being dense enough on expansion.
2089 static const int kMaxUncheckedFastElementsLength = 5000;
2090
2091 // Same as above but for old arrays. This limit is more strict. We
2092 // don't want to be wasteful with long lived objects.
2093 static const int kMaxUncheckedOldFastElementsLength = 500;
2094
Steve Blocka7e24c12009-10-30 11:49:00 +00002095 static const int kInitialMaxFastElementArray = 100000;
Ben Murdochb0fe1622011-05-05 13:52:32 +01002096 static const int kMaxFastProperties = 12;
Steve Blocka7e24c12009-10-30 11:49:00 +00002097 static const int kMaxInstanceSize = 255 * kPointerSize;
2098 // When extending the backing storage for property values, we increase
2099 // its size by more than the 1 entry necessary, so sequentially adding fields
2100 // to the same object requires fewer allocations and copies.
2101 static const int kFieldsAdded = 3;
2102
2103 // Layout description.
2104 static const int kPropertiesOffset = HeapObject::kHeaderSize;
2105 static const int kElementsOffset = kPropertiesOffset + kPointerSize;
2106 static const int kHeaderSize = kElementsOffset + kPointerSize;
2107
2108 STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize);
2109
Iain Merrick75681382010-08-19 15:07:18 +01002110 class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> {
2111 public:
2112 static inline int SizeOf(Map* map, HeapObject* object);
2113 };
2114
Steve Blocka7e24c12009-10-30 11:49:00 +00002115 private:
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002116 friend class DictionaryElementsAccessor;
2117
John Reck59135872010-11-02 12:39:01 -07002118 MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver,
2119 Object* structure,
2120 uint32_t index,
2121 Object* holder);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002122 MUST_USE_RESULT MaybeObject* SetElementWithCallback(
2123 Object* structure,
2124 uint32_t index,
2125 Object* value,
2126 JSObject* holder,
2127 StrictModeFlag strict_mode);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002128 MUST_USE_RESULT MaybeObject* SetElementWithInterceptor(
2129 uint32_t index,
2130 Object* value,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002131 PropertyAttributes attributes,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002132 StrictModeFlag strict_mode,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002133 bool check_prototype,
2134 SetPropertyMode set_mode);
Steve Block9fac8402011-05-12 15:51:54 +01002135 MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor(
2136 uint32_t index,
2137 Object* value,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002138 PropertyAttributes attributes,
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002139 StrictModeFlag strict_mode,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002140 bool check_prototype,
2141 SetPropertyMode set_mode);
2142
2143 // Searches the prototype chain for a callback setter and sets the property
2144 // with the setter if it finds one. The '*found' flag indicates whether
2145 // a setter was found or not.
2146 // This function can cause GC and can return a failure result with
2147 // '*found==true'.
2148 MUST_USE_RESULT MaybeObject* SetPropertyWithCallbackSetterInPrototypes(
2149 String* name,
2150 Object* value,
2151 PropertyAttributes attributes,
2152 bool* found,
2153 StrictModeFlag strict_mode);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00002154
John Reck59135872010-11-02 12:39:01 -07002155 MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name,
2156 DeleteMode mode);
2157 MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name);
Steve Blocka7e24c12009-10-30 11:49:00 +00002158
John Reck59135872010-11-02 12:39:01 -07002159 MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +00002160
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002161 MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index);
2162 MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index,
2163 DeleteMode mode);
2164
2165 bool ReferencesObjectFromElements(FixedArray* elements,
2166 ElementsKind kind,
2167 Object* object);
Steve Blocka7e24c12009-10-30 11:49:00 +00002168
2169 // Returns true if most of the elements backing storage is used.
2170 bool HasDenseElements();
2171
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002172 // Gets the current elements capacity and the number of used elements.
2173 void GetElementsCapacityAndUsage(int* capacity, int* used);
2174
Leon Clarkef7060e22010-06-03 12:02:55 +01002175 bool CanSetCallback(String* name);
John Reck59135872010-11-02 12:39:01 -07002176 MUST_USE_RESULT MaybeObject* SetElementCallback(
2177 uint32_t index,
2178 Object* structure,
2179 PropertyAttributes attributes);
2180 MUST_USE_RESULT MaybeObject* SetPropertyCallback(
2181 String* name,
2182 Object* structure,
2183 PropertyAttributes attributes);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002184 MUST_USE_RESULT MaybeObject* DefineElementAccessor(
2185 uint32_t index,
2186 Object* getter,
2187 Object* setter,
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +01002188 PropertyAttributes attributes);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002189 MUST_USE_RESULT MaybeObject* DefinePropertyAccessor(
2190 String* name,
2191 Object* getter,
2192 Object* setter,
2193 PropertyAttributes attributes);
Ben Murdoch85b71792012-04-11 18:30:58 +01002194 void LookupInDescriptor(String* name, LookupResult* result);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00002195
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002196 // Returns the hidden properties backing store object, currently
2197 // a StringDictionary, stored on this object.
2198 // If no hidden properties object has been put on this object,
2199 // return undefined, unless create_if_absent is true, in which case
2200 // a new dictionary is created, added to this object, and returned.
2201 MUST_USE_RESULT MaybeObject* GetHiddenPropertiesDictionary(
2202 bool create_if_absent);
2203 // Updates the existing hidden properties dictionary.
2204 MUST_USE_RESULT MaybeObject* SetHiddenPropertiesDictionary(
2205 StringDictionary* dictionary);
2206
Steve Blocka7e24c12009-10-30 11:49:00 +00002207 DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
2208};
2209
2210
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002211// Common superclass for FixedArrays that allow implementations to share
2212// common accessors and some code paths.
2213class FixedArrayBase: public HeapObject {
Steve Blocka7e24c12009-10-30 11:49:00 +00002214 public:
2215 // [length]: length of the array.
2216 inline int length();
2217 inline void set_length(int value);
2218
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002219 inline static FixedArrayBase* cast(Object* object);
2220
2221 // Layout description.
2222 // Length is smi tagged when it is stored.
2223 static const int kLengthOffset = HeapObject::kHeaderSize;
2224 static const int kHeaderSize = kLengthOffset + kPointerSize;
2225};
2226
2227
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002228class FixedDoubleArray;
2229
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002230// FixedArray describes fixed-sized arrays with element type Object*.
2231class FixedArray: public FixedArrayBase {
2232 public:
Steve Blocka7e24c12009-10-30 11:49:00 +00002233 // Setter and getter for elements.
2234 inline Object* get(int index);
2235 // Setter that uses write barrier.
2236 inline void set(int index, Object* value);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002237 inline bool is_the_hole(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00002238
2239 // Setter that doesn't need write barrier).
2240 inline void set(int index, Smi* value);
2241 // Setter with explicit barrier mode.
2242 inline void set(int index, Object* value, WriteBarrierMode mode);
2243
2244 // Setters for frequently used oddballs located in old space.
2245 inline void set_undefined(int index);
Steve Block44f0eee2011-05-26 01:26:41 +01002246 // TODO(isolates): duplicate.
2247 inline void set_undefined(Heap* heap, int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00002248 inline void set_null(int index);
Steve Block44f0eee2011-05-26 01:26:41 +01002249 // TODO(isolates): duplicate.
2250 inline void set_null(Heap* heap, int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00002251 inline void set_the_hole(int index);
2252
Iain Merrick75681382010-08-19 15:07:18 +01002253 // Setters with less debug checks for the GC to use.
2254 inline void set_unchecked(int index, Smi* value);
Steve Block44f0eee2011-05-26 01:26:41 +01002255 inline void set_null_unchecked(Heap* heap, int index);
2256 inline void set_unchecked(Heap* heap, int index, Object* value,
2257 WriteBarrierMode mode);
Iain Merrick75681382010-08-19 15:07:18 +01002258
Steve Block6ded16b2010-05-10 14:33:55 +01002259 // Gives access to raw memory which stores the array's data.
2260 inline Object** data_start();
2261
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002262 inline Object** GetFirstElementAddress();
2263 inline bool ContainsOnlySmisOrHoles();
2264
Steve Blocka7e24c12009-10-30 11:49:00 +00002265 // Copy operations.
John Reck59135872010-11-02 12:39:01 -07002266 MUST_USE_RESULT inline MaybeObject* Copy();
2267 MUST_USE_RESULT MaybeObject* CopySize(int new_length);
Steve Blocka7e24c12009-10-30 11:49:00 +00002268
2269 // Add the elements of a JSArray to this FixedArray.
John Reck59135872010-11-02 12:39:01 -07002270 MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array);
Steve Blocka7e24c12009-10-30 11:49:00 +00002271
2272 // Compute the union of this and other.
John Reck59135872010-11-02 12:39:01 -07002273 MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other);
Steve Blocka7e24c12009-10-30 11:49:00 +00002274
2275 // Copy a sub array from the receiver to dest.
2276 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
2277
2278 // Garbage collection support.
2279 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; }
2280
2281 // Code Generation support.
2282 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2283
2284 // Casting.
2285 static inline FixedArray* cast(Object* obj);
2286
Leon Clarkee46be812010-01-19 14:06:41 +00002287 // Maximal allowed size, in bytes, of a single FixedArray.
2288 // Prevents overflowing size computations, as well as extreme memory
2289 // consumption.
Ben Murdoch692be652012-01-10 18:47:50 +00002290 static const int kMaxSize = 128 * MB * kPointerSize;
Leon Clarkee46be812010-01-19 14:06:41 +00002291 // Maximally allowed length of a FixedArray.
2292 static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00002293
2294 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01002295#ifdef OBJECT_PRINT
2296 inline void FixedArrayPrint() {
2297 FixedArrayPrint(stdout);
2298 }
2299 void FixedArrayPrint(FILE* out);
2300#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00002301#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00002302 void FixedArrayVerify();
2303 // Checks if two FixedArrays have identical contents.
2304 bool IsEqualTo(FixedArray* other);
2305#endif
2306
2307 // Swap two elements in a pair of arrays. If this array and the
2308 // numbers array are the same object, the elements are only swapped
2309 // once.
2310 void SwapPairs(FixedArray* numbers, int i, int j);
2311
2312 // Sort prefix of this array and the numbers array as pairs wrt. the
2313 // numbers. If the numbers array and the this array are the same
2314 // object, the prefix of this array is sorted.
2315 void SortPairs(FixedArray* numbers, uint32_t len);
2316
Iain Merrick75681382010-08-19 15:07:18 +01002317 class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> {
2318 public:
2319 static inline int SizeOf(Map* map, HeapObject* object) {
2320 return SizeFor(reinterpret_cast<FixedArray*>(object)->length());
2321 }
2322 };
2323
Steve Blocka7e24c12009-10-30 11:49:00 +00002324 protected:
Leon Clarke4515c472010-02-03 11:58:03 +00002325 // Set operation on FixedArray without using write barriers. Can
2326 // only be used for storing old space objects or smis.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002327 static inline void NoWriteBarrierSet(FixedArray* array,
2328 int index,
2329 Object* value);
2330
2331 // Set operation on FixedArray without incremental write barrier. Can
2332 // only be used if the object is guaranteed to be white (whiteness witness
2333 // is present).
2334 static inline void NoIncrementalWriteBarrierSet(FixedArray* array,
2335 int index,
2336 Object* value);
Ben Murdochc7cc0282012-03-05 14:35:55 +00002337
Steve Blocka7e24c12009-10-30 11:49:00 +00002338 private:
2339 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray);
2340};
2341
2342
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002343// FixedDoubleArray describes fixed-sized arrays with element type double.
2344class FixedDoubleArray: public FixedArrayBase {
2345 public:
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002346 // Setter and getter for elements.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002347 inline double get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002348 inline int64_t get_representation(int index);
2349 MUST_USE_RESULT inline MaybeObject* get(int index);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002350 inline void set(int index, double value);
2351 inline void set_the_hole(int index);
2352
2353 // Checking for the hole.
2354 inline bool is_the_hole(int index);
2355
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002356 // Copy operations
2357 MUST_USE_RESULT inline MaybeObject* Copy();
2358
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002359 // Garbage collection support.
2360 inline static int SizeFor(int length) {
2361 return kHeaderSize + length * kDoubleSize;
2362 }
2363
2364 // Code Generation support.
2365 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2366
2367 inline static bool is_the_hole_nan(double value);
2368 inline static double hole_nan_as_double();
2369 inline static double canonical_not_the_hole_nan_as_double();
2370
2371 // Casting.
2372 static inline FixedDoubleArray* cast(Object* obj);
2373
2374 // Maximal allowed size, in bytes, of a single FixedDoubleArray.
2375 // Prevents overflowing size computations, as well as extreme memory
2376 // consumption.
2377 static const int kMaxSize = 512 * MB;
2378 // Maximally allowed length of a FixedArray.
2379 static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize;
2380
2381 // Dispatched behavior.
2382#ifdef OBJECT_PRINT
2383 inline void FixedDoubleArrayPrint() {
2384 FixedDoubleArrayPrint(stdout);
2385 }
2386 void FixedDoubleArrayPrint(FILE* out);
2387#endif
2388
2389#ifdef DEBUG
2390 void FixedDoubleArrayVerify();
2391#endif
2392
2393 private:
2394 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray);
2395};
2396
2397
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002398class IncrementalMarking;
2399
2400
Steve Blocka7e24c12009-10-30 11:49:00 +00002401// DescriptorArrays are fixed arrays used to hold instance descriptors.
2402// The format of the these objects is:
Ben Murdoch257744e2011-11-30 15:57:28 +00002403// TODO(1399): It should be possible to make room for bit_field3 in the map
2404// without overloading the instance descriptors field in the map
2405// (and storing it in the DescriptorArray when the map has one).
2406// [0]: storage for bit_field3 for Map owning this object (Smi)
2407// [1]: point to a fixed array with (value, detail) pairs.
2408// [2]: next enumeration index (Smi), or pointer to small fixed array:
Steve Blocka7e24c12009-10-30 11:49:00 +00002409// [0]: next enumeration index (Smi)
2410// [1]: pointer to fixed array with enum cache
Ben Murdoch257744e2011-11-30 15:57:28 +00002411// [3]: first key
Steve Blocka7e24c12009-10-30 11:49:00 +00002412// [length() - 1]: last key
2413//
2414class DescriptorArray: public FixedArray {
2415 public:
Ben Murdoch257744e2011-11-30 15:57:28 +00002416 // Returns true for both shared empty_descriptor_array and for smis, which the
2417 // map uses to encode additional bit fields when the descriptor array is not
2418 // yet used.
Steve Blocka7e24c12009-10-30 11:49:00 +00002419 inline bool IsEmpty();
Leon Clarkee46be812010-01-19 14:06:41 +00002420
Steve Blocka7e24c12009-10-30 11:49:00 +00002421 // Returns the number of descriptors in the array.
2422 int number_of_descriptors() {
Steve Block44f0eee2011-05-26 01:26:41 +01002423 ASSERT(length() > kFirstIndex || IsEmpty());
2424 int len = length();
2425 return len <= kFirstIndex ? 0 : len - kFirstIndex;
Steve Blocka7e24c12009-10-30 11:49:00 +00002426 }
2427
2428 int NextEnumerationIndex() {
2429 if (IsEmpty()) return PropertyDetails::kInitialIndex;
2430 Object* obj = get(kEnumerationIndexIndex);
2431 if (obj->IsSmi()) {
2432 return Smi::cast(obj)->value();
2433 } else {
2434 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex);
2435 return Smi::cast(index)->value();
2436 }
2437 }
2438
2439 // Set next enumeration index and flush any enum cache.
2440 void SetNextEnumerationIndex(int value) {
2441 if (!IsEmpty()) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002442 set(kEnumerationIndexIndex, Smi::FromInt(value));
Steve Blocka7e24c12009-10-30 11:49:00 +00002443 }
2444 }
2445 bool HasEnumCache() {
2446 return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi();
2447 }
2448
2449 Object* GetEnumCache() {
2450 ASSERT(HasEnumCache());
2451 FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex));
2452 return bridge->get(kEnumCacheBridgeCacheIndex);
2453 }
2454
Ben Murdoch257744e2011-11-30 15:57:28 +00002455 // TODO(1399): It should be possible to make room for bit_field3 in the map
2456 // without overloading the instance descriptors field in the map
2457 // (and storing it in the DescriptorArray when the map has one).
2458 inline int bit_field3_storage();
2459 inline void set_bit_field3_storage(int value);
2460
Steve Blocka7e24c12009-10-30 11:49:00 +00002461 // Initialize or change the enum cache,
2462 // using the supplied storage for the small "bridge".
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002463 void SetEnumCache(FixedArray* bridge_storage,
2464 FixedArray* new_cache,
2465 Object* new_index_cache);
Steve Blocka7e24c12009-10-30 11:49:00 +00002466
2467 // Accessors for fetching instance descriptor at descriptor number.
2468 inline String* GetKey(int descriptor_number);
2469 inline Object* GetValue(int descriptor_number);
2470 inline Smi* GetDetails(int descriptor_number);
2471 inline PropertyType GetType(int descriptor_number);
2472 inline int GetFieldIndex(int descriptor_number);
2473 inline JSFunction* GetConstantFunction(int descriptor_number);
2474 inline Object* GetCallbacksObject(int descriptor_number);
2475 inline AccessorDescriptor* GetCallbacks(int descriptor_number);
2476 inline bool IsProperty(int descriptor_number);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002477 inline bool IsTransitionOnly(int descriptor_number);
Steve Blocka7e24c12009-10-30 11:49:00 +00002478 inline bool IsNullDescriptor(int descriptor_number);
2479 inline bool IsDontEnum(int descriptor_number);
2480
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002481 class WhitenessWitness {
2482 public:
2483 inline explicit WhitenessWitness(DescriptorArray* array);
2484 inline ~WhitenessWitness();
2485
2486 private:
2487 IncrementalMarking* marking_;
2488 };
2489
Steve Blocka7e24c12009-10-30 11:49:00 +00002490 // Accessor for complete descriptor.
2491 inline void Get(int descriptor_number, Descriptor* desc);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002492 inline void Set(int descriptor_number,
2493 Descriptor* desc,
2494 const WhitenessWitness&);
Steve Blocka7e24c12009-10-30 11:49:00 +00002495
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002496 // Transfer a complete descriptor from the src descriptor array to the dst
2497 // one, dropping map transitions in CALLBACKS.
2498 static void CopyFrom(Handle<DescriptorArray> dst,
2499 int dst_index,
2500 Handle<DescriptorArray> src,
2501 int src_index,
2502 const WhitenessWitness& witness);
2503
2504 // Transfer a complete descriptor from the src descriptor array to this
2505 // descriptor array, dropping map transitions in CALLBACKS.
2506 MUST_USE_RESULT MaybeObject* CopyFrom(int dst_index,
2507 DescriptorArray* src,
2508 int src_index,
2509 const WhitenessWitness&);
Steve Blocka7e24c12009-10-30 11:49:00 +00002510
2511 // Copy the descriptor array, insert a new descriptor and optionally
2512 // remove map transitions. If the descriptor is already present, it is
2513 // replaced. If a replaced descriptor is a real property (not a transition
2514 // or null), its enumeration index is kept as is.
2515 // If adding a real property, map transitions must be removed. If adding
2516 // a transition, they must not be removed. All null descriptors are removed.
John Reck59135872010-11-02 12:39:01 -07002517 MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor,
2518 TransitionFlag transition_flag);
Steve Blocka7e24c12009-10-30 11:49:00 +00002519
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002520 // Return a copy of the array with all transitions and null descriptors
2521 // removed. Return a Failure object in case of an allocation failure.
John Reck59135872010-11-02 12:39:01 -07002522 MUST_USE_RESULT MaybeObject* RemoveTransitions();
Steve Blocka7e24c12009-10-30 11:49:00 +00002523
2524 // Sort the instance descriptors by the hash codes of their keys.
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002525 // Does not check for duplicates.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002526 void SortUnchecked(const WhitenessWitness&);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01002527
2528 // Sort the instance descriptors by the hash codes of their keys.
2529 // Checks the result for duplicates.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002530 void Sort(const WhitenessWitness&);
Steve Blocka7e24c12009-10-30 11:49:00 +00002531
2532 // Search the instance descriptors for given name.
2533 inline int Search(String* name);
2534
Iain Merrick75681382010-08-19 15:07:18 +01002535 // As the above, but uses DescriptorLookupCache and updates it when
2536 // necessary.
2537 inline int SearchWithCache(String* name);
2538
Steve Blocka7e24c12009-10-30 11:49:00 +00002539 // Tells whether the name is present int the array.
2540 bool Contains(String* name) { return kNotFound != Search(name); }
2541
2542 // Perform a binary search in the instance descriptors represented
2543 // by this fixed array. low and high are descriptor indices. If there
2544 // are three instance descriptors in this array it should be called
2545 // with low=0 and high=2.
2546 int BinarySearch(String* name, int low, int high);
2547
2548 // Perform a linear search in the instance descriptors represented
2549 // by this fixed array. len is the number of descriptor indices that are
2550 // valid. Does not require the descriptors to be sorted.
2551 int LinearSearch(String* name, int len);
2552
2553 // Allocates a DescriptorArray, but returns the singleton
2554 // empty descriptor array object if number_of_descriptors is 0.
John Reck59135872010-11-02 12:39:01 -07002555 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors);
Steve Blocka7e24c12009-10-30 11:49:00 +00002556
2557 // Casting.
2558 static inline DescriptorArray* cast(Object* obj);
2559
2560 // Constant for denoting key was not found.
2561 static const int kNotFound = -1;
2562
Ben Murdoch257744e2011-11-30 15:57:28 +00002563 static const int kBitField3StorageIndex = 0;
2564 static const int kContentArrayIndex = 1;
2565 static const int kEnumerationIndexIndex = 2;
2566 static const int kFirstIndex = 3;
Steve Blocka7e24c12009-10-30 11:49:00 +00002567
2568 // The length of the "bridge" to the enum cache.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002569 static const int kEnumCacheBridgeLength = 3;
Steve Blocka7e24c12009-10-30 11:49:00 +00002570 static const int kEnumCacheBridgeEnumIndex = 0;
2571 static const int kEnumCacheBridgeCacheIndex = 1;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002572 static const int kEnumCacheBridgeIndicesCacheIndex = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +00002573
2574 // Layout description.
Ben Murdoch257744e2011-11-30 15:57:28 +00002575 static const int kBitField3StorageOffset = FixedArray::kHeaderSize;
2576 static const int kContentArrayOffset = kBitField3StorageOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00002577 static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize;
2578 static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize;
2579
2580 // Layout description for the bridge array.
2581 static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize;
2582 static const int kEnumCacheBridgeCacheOffset =
2583 kEnumCacheBridgeEnumOffset + kPointerSize;
2584
Ben Murdochb0fe1622011-05-05 13:52:32 +01002585#ifdef OBJECT_PRINT
Steve Blocka7e24c12009-10-30 11:49:00 +00002586 // Print all the descriptors.
Ben Murdochb0fe1622011-05-05 13:52:32 +01002587 inline void PrintDescriptors() {
2588 PrintDescriptors(stdout);
2589 }
2590 void PrintDescriptors(FILE* out);
2591#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00002592
Ben Murdochb0fe1622011-05-05 13:52:32 +01002593#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00002594 // Is the descriptor array sorted and without duplicates?
2595 bool IsSortedNoDuplicates();
2596
2597 // Are two DescriptorArrays equal?
2598 bool IsEqualTo(DescriptorArray* other);
2599#endif
2600
2601 // The maximum number of descriptors we want in a descriptor array (should
2602 // fit in a page).
2603 static const int kMaxNumberOfDescriptors = 1024 + 512;
2604
2605 private:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002606 // An entry in a DescriptorArray, represented as an (array, index) pair.
2607 class Entry {
2608 public:
2609 inline explicit Entry(DescriptorArray* descs, int index) :
2610 descs_(descs), index_(index) { }
2611
2612 inline PropertyType type() { return descs_->GetType(index_); }
2613 inline Object* GetCallbackObject() { return descs_->GetValue(index_); }
2614
2615 private:
2616 DescriptorArray* descs_;
2617 int index_;
2618 };
2619
Steve Blocka7e24c12009-10-30 11:49:00 +00002620 // Conversion from descriptor number to array indices.
2621 static int ToKeyIndex(int descriptor_number) {
2622 return descriptor_number+kFirstIndex;
2623 }
Leon Clarkee46be812010-01-19 14:06:41 +00002624
2625 static int ToDetailsIndex(int descriptor_number) {
2626 return (descriptor_number << 1) + 1;
2627 }
2628
Steve Blocka7e24c12009-10-30 11:49:00 +00002629 static int ToValueIndex(int descriptor_number) {
2630 return descriptor_number << 1;
2631 }
Steve Blocka7e24c12009-10-30 11:49:00 +00002632
2633 bool is_null_descriptor(int descriptor_number) {
2634 return PropertyDetails(GetDetails(descriptor_number)).type() ==
2635 NULL_DESCRIPTOR;
2636 }
2637 // Swap operation on FixedArray without using write barriers.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002638 static inline void NoIncrementalWriteBarrierSwap(
2639 FixedArray* array, int first, int second);
Steve Blocka7e24c12009-10-30 11:49:00 +00002640
2641 // Swap descriptor first and second.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002642 inline void NoIncrementalWriteBarrierSwapDescriptors(
2643 int first, int second);
Steve Blocka7e24c12009-10-30 11:49:00 +00002644
2645 FixedArray* GetContentArray() {
2646 return FixedArray::cast(get(kContentArrayIndex));
2647 }
2648 DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray);
2649};
2650
2651
2652// HashTable is a subclass of FixedArray that implements a hash table
2653// that uses open addressing and quadratic probing.
2654//
2655// In order for the quadratic probing to work, elements that have not
2656// yet been used and elements that have been deleted are
2657// distinguished. Probing continues when deleted elements are
2658// encountered and stops when unused elements are encountered.
2659//
2660// - Elements with key == undefined have not been used yet.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002661// - Elements with key == the_hole have been deleted.
Steve Blocka7e24c12009-10-30 11:49:00 +00002662//
2663// The hash table class is parameterized with a Shape and a Key.
2664// Shape must be a class with the following interface:
2665// class ExampleShape {
2666// public:
2667// // Tells whether key matches other.
2668// static bool IsMatch(Key key, Object* other);
2669// // Returns the hash value for key.
2670// static uint32_t Hash(Key key);
2671// // Returns the hash value for object.
2672// static uint32_t HashForObject(Key key, Object* object);
2673// // Convert key to an object.
2674// static inline Object* AsObject(Key key);
2675// // The prefix size indicates number of elements in the beginning
2676// // of the backing storage.
2677// static const int kPrefixSize = ..;
2678// // The Element size indicates number of elements per entry.
2679// static const int kEntrySize = ..;
2680// };
Steve Block3ce2e202009-11-05 08:53:23 +00002681// The prefix size indicates an amount of memory in the
Steve Blocka7e24c12009-10-30 11:49:00 +00002682// beginning of the backing storage that can be used for non-element
2683// information by subclasses.
2684
Ben Murdochc7cc0282012-03-05 14:35:55 +00002685template<typename Key>
2686class BaseShape {
2687 public:
2688 static const bool UsesSeed = false;
2689 static uint32_t Hash(Key key) { return 0; }
2690 static uint32_t SeededHash(Key key, uint32_t seed) {
2691 ASSERT(UsesSeed);
2692 return Hash(key);
2693 }
2694 static uint32_t HashForObject(Key key, Object* object) { return 0; }
2695 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002696 ASSERT(UsesSeed);
Ben Murdochc7cc0282012-03-05 14:35:55 +00002697 return HashForObject(key, object);
2698 }
2699};
2700
Steve Blocka7e24c12009-10-30 11:49:00 +00002701template<typename Shape, typename Key>
2702class HashTable: public FixedArray {
2703 public:
Ben Murdochc7cc0282012-03-05 14:35:55 +00002704 // Wrapper methods
2705 inline uint32_t Hash(Key key) {
2706 if (Shape::UsesSeed) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002707 return Shape::SeededHash(key,
2708 GetHeap()->HashSeed());
Ben Murdochc7cc0282012-03-05 14:35:55 +00002709 } else {
2710 return Shape::Hash(key);
2711 }
2712 }
2713
2714 inline uint32_t HashForObject(Key key, Object* object) {
2715 if (Shape::UsesSeed) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002716 return Shape::SeededHashForObject(key,
2717 GetHeap()->HashSeed(), object);
Ben Murdochc7cc0282012-03-05 14:35:55 +00002718 } else {
2719 return Shape::HashForObject(key, object);
2720 }
2721 }
2722
Steve Block3ce2e202009-11-05 08:53:23 +00002723 // Returns the number of elements in the hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002724 int NumberOfElements() {
2725 return Smi::cast(get(kNumberOfElementsIndex))->value();
2726 }
2727
Leon Clarkee46be812010-01-19 14:06:41 +00002728 // Returns the number of deleted elements in the hash table.
2729 int NumberOfDeletedElements() {
2730 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
2731 }
2732
Steve Block3ce2e202009-11-05 08:53:23 +00002733 // Returns the capacity of the hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002734 int Capacity() {
2735 return Smi::cast(get(kCapacityIndex))->value();
2736 }
2737
2738 // ElementAdded should be called whenever an element is added to a
Steve Block3ce2e202009-11-05 08:53:23 +00002739 // hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002740 void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); }
2741
2742 // ElementRemoved should be called whenever an element is removed from
Steve Block3ce2e202009-11-05 08:53:23 +00002743 // a hash table.
Leon Clarkee46be812010-01-19 14:06:41 +00002744 void ElementRemoved() {
2745 SetNumberOfElements(NumberOfElements() - 1);
2746 SetNumberOfDeletedElements(NumberOfDeletedElements() + 1);
2747 }
2748 void ElementsRemoved(int n) {
2749 SetNumberOfElements(NumberOfElements() - n);
2750 SetNumberOfDeletedElements(NumberOfDeletedElements() + n);
2751 }
Steve Blocka7e24c12009-10-30 11:49:00 +00002752
Steve Block3ce2e202009-11-05 08:53:23 +00002753 // Returns a new HashTable object. Might return Failure.
John Reck59135872010-11-02 12:39:01 -07002754 MUST_USE_RESULT static MaybeObject* Allocate(
Kristian Monsen80d68ea2010-09-08 11:05:35 +01002755 int at_least_space_for,
2756 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +00002757
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002758 // Computes the required capacity for a table holding the given
2759 // number of elements. May be more than HashTable::kMaxCapacity.
2760 static int ComputeCapacity(int at_least_space_for);
2761
Steve Blocka7e24c12009-10-30 11:49:00 +00002762 // Returns the key at entry.
2763 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
2764
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002765 // Tells whether k is a real key. The hole and undefined are not allowed
Steve Blocka7e24c12009-10-30 11:49:00 +00002766 // as keys and can be used to indicate missing or deleted elements.
2767 bool IsKey(Object* k) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002768 return !k->IsTheHole() && !k->IsUndefined();
Steve Blocka7e24c12009-10-30 11:49:00 +00002769 }
2770
2771 // Garbage collection support.
2772 void IteratePrefix(ObjectVisitor* visitor);
2773 void IterateElements(ObjectVisitor* visitor);
2774
2775 // Casting.
2776 static inline HashTable* cast(Object* obj);
2777
2778 // Compute the probe offset (quadratic probing).
2779 INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
2780 return (n + n * n) >> 1;
2781 }
2782
2783 static const int kNumberOfElementsIndex = 0;
Leon Clarkee46be812010-01-19 14:06:41 +00002784 static const int kNumberOfDeletedElementsIndex = 1;
2785 static const int kCapacityIndex = 2;
2786 static const int kPrefixStartIndex = 3;
2787 static const int kElementsStartIndex =
Steve Blocka7e24c12009-10-30 11:49:00 +00002788 kPrefixStartIndex + Shape::kPrefixSize;
Leon Clarkee46be812010-01-19 14:06:41 +00002789 static const int kEntrySize = Shape::kEntrySize;
2790 static const int kElementsStartOffset =
Steve Blocka7e24c12009-10-30 11:49:00 +00002791 kHeaderSize + kElementsStartIndex * kPointerSize;
Steve Block6ded16b2010-05-10 14:33:55 +01002792 static const int kCapacityOffset =
2793 kHeaderSize + kCapacityIndex * kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00002794
2795 // Constant used for denoting a absent entry.
2796 static const int kNotFound = -1;
2797
Leon Clarkee46be812010-01-19 14:06:41 +00002798 // Maximal capacity of HashTable. Based on maximal length of underlying
2799 // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
2800 // cannot overflow.
2801 static const int kMaxCapacity =
2802 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
2803
Ben Murdoch3bec4d22010-07-22 14:51:16 +01002804 // Find entry for key otherwise return kNotFound.
Steve Block44f0eee2011-05-26 01:26:41 +01002805 inline int FindEntry(Key key);
2806 int FindEntry(Isolate* isolate, Key key);
Steve Blocka7e24c12009-10-30 11:49:00 +00002807
2808 protected:
Steve Blocka7e24c12009-10-30 11:49:00 +00002809 // Find the entry at which to insert element with the given key that
2810 // has the given hash value.
2811 uint32_t FindInsertionEntry(uint32_t hash);
2812
2813 // Returns the index for an entry (of the key)
2814 static inline int EntryToIndex(int entry) {
2815 return (entry * kEntrySize) + kElementsStartIndex;
2816 }
2817
Steve Block3ce2e202009-11-05 08:53:23 +00002818 // Update the number of elements in the hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002819 void SetNumberOfElements(int nof) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002820 set(kNumberOfElementsIndex, Smi::FromInt(nof));
Steve Blocka7e24c12009-10-30 11:49:00 +00002821 }
2822
Leon Clarkee46be812010-01-19 14:06:41 +00002823 // Update the number of deleted elements in the hash table.
2824 void SetNumberOfDeletedElements(int nod) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002825 set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod));
Leon Clarkee46be812010-01-19 14:06:41 +00002826 }
2827
Steve Blocka7e24c12009-10-30 11:49:00 +00002828 // Sets the capacity of the hash table.
2829 void SetCapacity(int capacity) {
2830 // To scale a computed hash code to fit within the hash table, we
2831 // use bit-wise AND with a mask, so the capacity must be positive
2832 // and non-zero.
2833 ASSERT(capacity > 0);
Leon Clarkee46be812010-01-19 14:06:41 +00002834 ASSERT(capacity <= kMaxCapacity);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002835 set(kCapacityIndex, Smi::FromInt(capacity));
Steve Blocka7e24c12009-10-30 11:49:00 +00002836 }
2837
2838
2839 // Returns probe entry.
2840 static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
2841 ASSERT(IsPowerOf2(size));
2842 return (hash + GetProbeOffset(number)) & (size - 1);
2843 }
2844
Leon Clarkee46be812010-01-19 14:06:41 +00002845 static uint32_t FirstProbe(uint32_t hash, uint32_t size) {
2846 return hash & (size - 1);
2847 }
2848
2849 static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) {
2850 return (last + number) & (size - 1);
2851 }
2852
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002853 // Rehashes this hash-table into the new table.
2854 MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key);
2855
2856 // Attempt to shrink hash table after removal of key.
2857 MUST_USE_RESULT MaybeObject* Shrink(Key key);
2858
Steve Blocka7e24c12009-10-30 11:49:00 +00002859 // Ensure enough space for n additional elements.
John Reck59135872010-11-02 12:39:01 -07002860 MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
Steve Blocka7e24c12009-10-30 11:49:00 +00002861};
2862
2863
Steve Blocka7e24c12009-10-30 11:49:00 +00002864// HashTableKey is an abstract superclass for virtual key behavior.
2865class HashTableKey {
2866 public:
2867 // Returns whether the other object matches this key.
2868 virtual bool IsMatch(Object* other) = 0;
2869 // Returns the hash value for this key.
2870 virtual uint32_t Hash() = 0;
2871 // Returns the hash value for object.
2872 virtual uint32_t HashForObject(Object* key) = 0;
Steve Block3ce2e202009-11-05 08:53:23 +00002873 // Returns the key object for storing into the hash table.
Steve Blocka7e24c12009-10-30 11:49:00 +00002874 // If allocations fails a failure object is returned.
John Reck59135872010-11-02 12:39:01 -07002875 MUST_USE_RESULT virtual MaybeObject* AsObject() = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +00002876 // Required.
2877 virtual ~HashTableKey() {}
2878};
2879
Ben Murdochc7cc0282012-03-05 14:35:55 +00002880
2881class SymbolTableShape : public BaseShape<HashTableKey*> {
Steve Blocka7e24c12009-10-30 11:49:00 +00002882 public:
Steve Block44f0eee2011-05-26 01:26:41 +01002883 static inline bool IsMatch(HashTableKey* key, Object* value) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002884 return key->IsMatch(value);
2885 }
Steve Block44f0eee2011-05-26 01:26:41 +01002886 static inline uint32_t Hash(HashTableKey* key) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002887 return key->Hash();
2888 }
Steve Block44f0eee2011-05-26 01:26:41 +01002889 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002890 return key->HashForObject(object);
2891 }
Steve Block44f0eee2011-05-26 01:26:41 +01002892 MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002893 return key->AsObject();
2894 }
2895
2896 static const int kPrefixSize = 0;
2897 static const int kEntrySize = 1;
2898};
2899
Ben Murdoch257744e2011-11-30 15:57:28 +00002900class SeqAsciiString;
2901
Steve Blocka7e24c12009-10-30 11:49:00 +00002902// SymbolTable.
2903//
2904// No special elements in the prefix and the element size is 1
2905// because only the symbol itself (the key) needs to be stored.
2906class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> {
2907 public:
2908 // Find symbol in the symbol table. If it is not there yet, it is
2909 // added. The return value is the symbol table which might have
2910 // been enlarged. If the return value is not a failure, the symbol
2911 // pointer *s is set to the symbol found.
John Reck59135872010-11-02 12:39:01 -07002912 MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s);
Steve Block9fac8402011-05-12 15:51:54 +01002913 MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str,
2914 Object** s);
Ben Murdoch257744e2011-11-30 15:57:28 +00002915 MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol(
2916 Handle<SeqAsciiString> str,
2917 int from,
2918 int length,
2919 Object** s);
Steve Block9fac8402011-05-12 15:51:54 +01002920 MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str,
2921 Object** s);
John Reck59135872010-11-02 12:39:01 -07002922 MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s);
Steve Blocka7e24c12009-10-30 11:49:00 +00002923
2924 // Looks up a symbol that is equal to the given string and returns
2925 // true if it is found, assigning the symbol to the given output
2926 // parameter.
2927 bool LookupSymbolIfExists(String* str, String** symbol);
Steve Blockd0582a62009-12-15 09:54:21 +00002928 bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol);
Steve Blocka7e24c12009-10-30 11:49:00 +00002929
2930 // Casting.
2931 static inline SymbolTable* cast(Object* obj);
2932
2933 private:
John Reck59135872010-11-02 12:39:01 -07002934 MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s);
Steve Blocka7e24c12009-10-30 11:49:00 +00002935
2936 DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable);
2937};
2938
2939
Ben Murdochc7cc0282012-03-05 14:35:55 +00002940class MapCacheShape : public BaseShape<HashTableKey*> {
Steve Blocka7e24c12009-10-30 11:49:00 +00002941 public:
Steve Block44f0eee2011-05-26 01:26:41 +01002942 static inline bool IsMatch(HashTableKey* key, Object* value) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002943 return key->IsMatch(value);
2944 }
Steve Block44f0eee2011-05-26 01:26:41 +01002945 static inline uint32_t Hash(HashTableKey* key) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002946 return key->Hash();
2947 }
2948
Steve Block44f0eee2011-05-26 01:26:41 +01002949 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002950 return key->HashForObject(object);
2951 }
2952
Steve Block44f0eee2011-05-26 01:26:41 +01002953 MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
Steve Blocka7e24c12009-10-30 11:49:00 +00002954 return key->AsObject();
2955 }
2956
2957 static const int kPrefixSize = 0;
2958 static const int kEntrySize = 2;
2959};
2960
2961
2962// MapCache.
2963//
2964// Maps keys that are a fixed array of symbols to a map.
2965// Used for canonicalize maps for object literals.
2966class MapCache: public HashTable<MapCacheShape, HashTableKey*> {
2967 public:
2968 // Find cached value for a string key, otherwise return null.
2969 Object* Lookup(FixedArray* key);
John Reck59135872010-11-02 12:39:01 -07002970 MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00002971 static inline MapCache* cast(Object* obj);
2972
2973 private:
2974 DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache);
2975};
2976
2977
2978template <typename Shape, typename Key>
2979class Dictionary: public HashTable<Shape, Key> {
2980 public:
Steve Blocka7e24c12009-10-30 11:49:00 +00002981 static inline Dictionary<Shape, Key>* cast(Object* obj) {
2982 return reinterpret_cast<Dictionary<Shape, Key>*>(obj);
2983 }
2984
2985 // Returns the value at entry.
2986 Object* ValueAt(int entry) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002987 return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1);
Steve Blocka7e24c12009-10-30 11:49:00 +00002988 }
2989
2990 // Set the value for entry.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002991 void ValueAtPut(int entry, Object* value) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002992 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value);
Steve Blocka7e24c12009-10-30 11:49:00 +00002993 }
2994
2995 // Returns the property details for the property at entry.
2996 PropertyDetails DetailsAt(int entry) {
2997 ASSERT(entry >= 0); // Not found is -1, which is not caught by get().
2998 return PropertyDetails(
Steve Block6ded16b2010-05-10 14:33:55 +01002999 Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2)));
Steve Blocka7e24c12009-10-30 11:49:00 +00003000 }
3001
3002 // Set the details for entry.
3003 void DetailsAtPut(int entry, PropertyDetails value) {
Steve Block6ded16b2010-05-10 14:33:55 +01003004 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi());
Steve Blocka7e24c12009-10-30 11:49:00 +00003005 }
3006
3007 // Sorting support
3008 void CopyValuesTo(FixedArray* elements);
3009
3010 // Delete a property from the dictionary.
3011 Object* DeleteProperty(int entry, JSObject::DeleteMode mode);
3012
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003013 // Attempt to shrink the dictionary after deletion of key.
3014 MUST_USE_RESULT MaybeObject* Shrink(Key key);
3015
Steve Blocka7e24c12009-10-30 11:49:00 +00003016 // Returns the number of elements in the dictionary filtering out properties
3017 // with the specified attributes.
3018 int NumberOfElementsFilterAttributes(PropertyAttributes filter);
3019
3020 // Returns the number of enumerable elements in the dictionary.
3021 int NumberOfEnumElements();
3022
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003023 enum SortMode { UNSORTED, SORTED };
Steve Blocka7e24c12009-10-30 11:49:00 +00003024 // Copies keys to preallocated fixed array.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003025 void CopyKeysTo(FixedArray* storage,
3026 PropertyAttributes filter,
3027 SortMode sort_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +00003028 // Fill in details for properties into storage.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003029 void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +00003030
3031 // Accessors for next enumeration index.
3032 void SetNextEnumerationIndex(int index) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003033 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
Steve Blocka7e24c12009-10-30 11:49:00 +00003034 }
3035
3036 int NextEnumerationIndex() {
3037 return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value();
3038 }
3039
3040 // Returns a new array for dictionary usage. Might return Failure.
John Reck59135872010-11-02 12:39:01 -07003041 MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for);
Steve Blocka7e24c12009-10-30 11:49:00 +00003042
3043 // Ensure enough space for n additional elements.
John Reck59135872010-11-02 12:39:01 -07003044 MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003045
Ben Murdochb0fe1622011-05-05 13:52:32 +01003046#ifdef OBJECT_PRINT
3047 inline void Print() {
3048 Print(stdout);
3049 }
3050 void Print(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +00003051#endif
3052 // Returns the key (slow).
3053 Object* SlowReverseLookup(Object* value);
3054
3055 // Sets the entry to (key, value) pair.
3056 inline void SetEntry(int entry,
3057 Object* key,
Ben Murdoch8b112d22011-06-08 16:22:53 +01003058 Object* value);
3059 inline void SetEntry(int entry,
3060 Object* key,
Steve Blocka7e24c12009-10-30 11:49:00 +00003061 Object* value,
3062 PropertyDetails details);
3063
John Reck59135872010-11-02 12:39:01 -07003064 MUST_USE_RESULT MaybeObject* Add(Key key,
3065 Object* value,
3066 PropertyDetails details);
Steve Blocka7e24c12009-10-30 11:49:00 +00003067
3068 protected:
3069 // Generic at put operation.
John Reck59135872010-11-02 12:39:01 -07003070 MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00003071
3072 // Add entry to dictionary.
John Reck59135872010-11-02 12:39:01 -07003073 MUST_USE_RESULT MaybeObject* AddEntry(Key key,
3074 Object* value,
3075 PropertyDetails details,
3076 uint32_t hash);
Steve Blocka7e24c12009-10-30 11:49:00 +00003077
3078 // Generate new enumeration indices to avoid enumeration index overflow.
John Reck59135872010-11-02 12:39:01 -07003079 MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices();
Steve Blocka7e24c12009-10-30 11:49:00 +00003080 static const int kMaxNumberKeyIndex =
3081 HashTable<Shape, Key>::kPrefixStartIndex;
3082 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
3083};
3084
3085
Ben Murdochc7cc0282012-03-05 14:35:55 +00003086class StringDictionaryShape : public BaseShape<String*> {
Steve Blocka7e24c12009-10-30 11:49:00 +00003087 public:
3088 static inline bool IsMatch(String* key, Object* other);
3089 static inline uint32_t Hash(String* key);
3090 static inline uint32_t HashForObject(String* key, Object* object);
John Reck59135872010-11-02 12:39:01 -07003091 MUST_USE_RESULT static inline MaybeObject* AsObject(String* key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003092 static const int kPrefixSize = 2;
3093 static const int kEntrySize = 3;
3094 static const bool kIsEnumerable = true;
3095};
3096
3097
3098class StringDictionary: public Dictionary<StringDictionaryShape, String*> {
3099 public:
3100 static inline StringDictionary* cast(Object* obj) {
3101 ASSERT(obj->IsDictionary());
3102 return reinterpret_cast<StringDictionary*>(obj);
3103 }
3104
3105 // Copies enumerable keys to preallocated fixed array.
3106 void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array);
3107
3108 // For transforming properties of a JSObject.
John Reck59135872010-11-02 12:39:01 -07003109 MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor(
3110 JSObject* obj,
3111 int unused_property_fields);
Ben Murdoch3bec4d22010-07-22 14:51:16 +01003112
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003113 // Find entry for key, otherwise return kNotFound. Optimized version of
Ben Murdoch3bec4d22010-07-22 14:51:16 +01003114 // HashTable::FindEntry.
3115 int FindEntry(String* key);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003116
3117 bool ContainsTransition(int entry);
Steve Blocka7e24c12009-10-30 11:49:00 +00003118};
3119
3120
Ben Murdochc7cc0282012-03-05 14:35:55 +00003121class NumberDictionaryShape : public BaseShape<uint32_t> {
Steve Blocka7e24c12009-10-30 11:49:00 +00003122 public:
3123 static inline bool IsMatch(uint32_t key, Object* other);
John Reck59135872010-11-02 12:39:01 -07003124 MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003125 static const int kEntrySize = 3;
3126 static const bool kIsEnumerable = false;
3127};
3128
3129
Ben Murdochc7cc0282012-03-05 14:35:55 +00003130class SeededNumberDictionaryShape : public NumberDictionaryShape {
Steve Blocka7e24c12009-10-30 11:49:00 +00003131 public:
Ben Murdochc7cc0282012-03-05 14:35:55 +00003132 static const bool UsesSeed = true;
3133 static const int kPrefixSize = 2;
3134
3135 static inline uint32_t SeededHash(uint32_t key, uint32_t seed);
3136 static inline uint32_t SeededHashForObject(uint32_t key,
3137 uint32_t seed,
3138 Object* object);
3139};
3140
3141
3142class UnseededNumberDictionaryShape : public NumberDictionaryShape {
3143 public:
3144 static const int kPrefixSize = 0;
3145
3146 static inline uint32_t Hash(uint32_t key);
3147 static inline uint32_t HashForObject(uint32_t key, Object* object);
3148};
3149
3150
3151class SeededNumberDictionary
3152 : public Dictionary<SeededNumberDictionaryShape, uint32_t> {
3153 public:
3154 static SeededNumberDictionary* cast(Object* obj) {
Steve Blocka7e24c12009-10-30 11:49:00 +00003155 ASSERT(obj->IsDictionary());
Ben Murdochc7cc0282012-03-05 14:35:55 +00003156 return reinterpret_cast<SeededNumberDictionary*>(obj);
Steve Blocka7e24c12009-10-30 11:49:00 +00003157 }
3158
3159 // Type specific at put (default NONE attributes is used when adding).
John Reck59135872010-11-02 12:39:01 -07003160 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value);
3161 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key,
3162 Object* value,
3163 PropertyDetails details);
Steve Blocka7e24c12009-10-30 11:49:00 +00003164
3165 // Set an existing entry or add a new one if needed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003166 // Return the updated dictionary.
3167 MUST_USE_RESULT static Handle<SeededNumberDictionary> Set(
3168 Handle<SeededNumberDictionary> dictionary,
3169 uint32_t index,
3170 Handle<Object> value,
3171 PropertyDetails details);
3172
John Reck59135872010-11-02 12:39:01 -07003173 MUST_USE_RESULT MaybeObject* Set(uint32_t key,
3174 Object* value,
3175 PropertyDetails details);
Steve Blocka7e24c12009-10-30 11:49:00 +00003176
3177 void UpdateMaxNumberKey(uint32_t key);
3178
3179 // If slow elements are required we will never go back to fast-case
3180 // for the elements kept in this dictionary. We require slow
3181 // elements if an element has been added at an index larger than
3182 // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called
3183 // when defining a getter or setter with a number key.
3184 inline bool requires_slow_elements();
3185 inline void set_requires_slow_elements();
3186
3187 // Get the value of the max number key that has been added to this
3188 // dictionary. max_number_key can only be called if
3189 // requires_slow_elements returns false.
3190 inline uint32_t max_number_key();
3191
Steve Blocka7e24c12009-10-30 11:49:00 +00003192 // Bit masks.
3193 static const int kRequiresSlowElementsMask = 1;
3194 static const int kRequiresSlowElementsTagSize = 1;
3195 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
3196};
3197
3198
Ben Murdochc7cc0282012-03-05 14:35:55 +00003199class UnseededNumberDictionary
3200 : public Dictionary<UnseededNumberDictionaryShape, uint32_t> {
3201 public:
3202 static UnseededNumberDictionary* cast(Object* obj) {
3203 ASSERT(obj->IsDictionary());
3204 return reinterpret_cast<UnseededNumberDictionary*>(obj);
3205 }
3206
3207 // Type specific at put (default NONE attributes is used when adding).
3208 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value);
3209 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value);
3210
3211 // Set an existing entry or add a new one if needed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003212 // Return the updated dictionary.
3213 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set(
3214 Handle<UnseededNumberDictionary> dictionary,
3215 uint32_t index,
3216 Handle<Object> value);
3217
Ben Murdochc7cc0282012-03-05 14:35:55 +00003218 MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value);
3219};
3220
3221
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003222template <int entrysize>
Ben Murdochc7cc0282012-03-05 14:35:55 +00003223class ObjectHashTableShape : public BaseShape<Object*> {
Ben Murdoch2b4ba112012-01-20 14:57:15 +00003224 public:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003225 static inline bool IsMatch(Object* key, Object* other);
3226 static inline uint32_t Hash(Object* key);
3227 static inline uint32_t HashForObject(Object* key, Object* object);
3228 MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00003229 static const int kPrefixSize = 0;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003230 static const int kEntrySize = entrysize;
Ben Murdoch592a9fc2012-03-05 11:04:45 +00003231};
3232
3233
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003234// ObjectHashSet holds keys that are arbitrary objects by using the identity
3235// hash of the key for hashing purposes.
3236class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> {
3237 public:
3238 static inline ObjectHashSet* cast(Object* obj) {
3239 ASSERT(obj->IsHashTable());
3240 return reinterpret_cast<ObjectHashSet*>(obj);
3241 }
3242
3243 // Looks up whether the given key is part of this hash set.
3244 bool Contains(Object* key);
3245
3246 // Adds the given key to this hash set.
3247 MUST_USE_RESULT MaybeObject* Add(Object* key);
3248
3249 // Removes the given key from this hash set.
3250 MUST_USE_RESULT MaybeObject* Remove(Object* key);
3251};
3252
3253
3254// ObjectHashTable maps keys that are arbitrary objects to object values by
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003255// using the identity hash of the key for hashing purposes.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003256class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> {
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003257 public:
3258 static inline ObjectHashTable* cast(Object* obj) {
3259 ASSERT(obj->IsHashTable());
3260 return reinterpret_cast<ObjectHashTable*>(obj);
3261 }
3262
3263 // Looks up the value associated with the given key. The undefined value is
3264 // returned in case the key is not present.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003265 Object* Lookup(Object* key);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003266
3267 // Adds (or overwrites) the value associated with the given key. Mapping a
3268 // key to the undefined value causes removal of the whole entry.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003269 MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003270
3271 private:
3272 friend class MarkCompactCollector;
3273
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003274 void AddEntry(int entry, Object* key, Object* value);
3275 void RemoveEntry(int entry);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003276
3277 // Returns the index to the value of an entry.
3278 static inline int EntryToValueIndex(int entry) {
3279 return EntryToIndex(entry) + 1;
3280 }
3281};
3282
3283
Steve Block6ded16b2010-05-10 14:33:55 +01003284// JSFunctionResultCache caches results of some JSFunction invocation.
3285// It is a fixed array with fixed structure:
3286// [0]: factory function
3287// [1]: finger index
3288// [2]: current cache size
3289// [3]: dummy field.
3290// The rest of array are key/value pairs.
3291class JSFunctionResultCache: public FixedArray {
3292 public:
3293 static const int kFactoryIndex = 0;
3294 static const int kFingerIndex = kFactoryIndex + 1;
3295 static const int kCacheSizeIndex = kFingerIndex + 1;
3296 static const int kDummyIndex = kCacheSizeIndex + 1;
3297 static const int kEntriesIndex = kDummyIndex + 1;
3298
3299 static const int kEntrySize = 2; // key + value
3300
Kristian Monsen25f61362010-05-21 11:50:48 +01003301 static const int kFactoryOffset = kHeaderSize;
3302 static const int kFingerOffset = kFactoryOffset + kPointerSize;
3303 static const int kCacheSizeOffset = kFingerOffset + kPointerSize;
3304
Steve Block6ded16b2010-05-10 14:33:55 +01003305 inline void MakeZeroSize();
3306 inline void Clear();
3307
Ben Murdochb8e0da22011-05-16 14:20:40 +01003308 inline int size();
3309 inline void set_size(int size);
3310 inline int finger_index();
3311 inline void set_finger_index(int finger_index);
3312
Steve Block6ded16b2010-05-10 14:33:55 +01003313 // Casting
3314 static inline JSFunctionResultCache* cast(Object* obj);
3315
3316#ifdef DEBUG
3317 void JSFunctionResultCacheVerify();
3318#endif
3319};
3320
3321
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003322// ScopeInfo represents information about different scopes of a source
3323// program and the allocation of the scope's variables. Scope information
3324// is stored in a compressed form in ScopeInfo objects and is used
3325// at runtime (stack dumps, deoptimization, etc.).
3326
3327// This object provides quick access to scope info details for runtime
3328// routines.
3329class ScopeInfo : public FixedArray {
3330 public:
3331 static inline ScopeInfo* cast(Object* object);
3332
3333 // Return the type of this scope.
3334 ScopeType Type();
3335
3336 // Does this scope call eval?
3337 bool CallsEval();
3338
3339 // Return the language mode of this scope.
3340 LanguageMode language_mode();
3341
3342 // Does this scope make a non-strict eval call?
3343 bool CallsNonStrictEval() {
3344 return CallsEval() && (language_mode() == CLASSIC_MODE);
3345 }
3346
3347 // Return the total number of locals allocated on the stack and in the
3348 // context. This includes the parameters that are allocated in the context.
3349 int LocalCount();
3350
3351 // Return the number of stack slots for code. This number consists of two
3352 // parts:
3353 // 1. One stack slot per stack allocated local.
3354 // 2. One stack slot for the function name if it is stack allocated.
3355 int StackSlotCount();
3356
3357 // Return the number of context slots for code if a context is allocated. This
3358 // number consists of three parts:
3359 // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS
3360 // 2. One context slot per context allocated local.
3361 // 3. One context slot for the function name if it is context allocated.
3362 // Parameters allocated in the context count as context allocated locals. If
3363 // no contexts are allocated for this scope ContextLength returns 0.
3364 int ContextLength();
3365
3366 // Is this scope the scope of a named function expression?
3367 bool HasFunctionName();
3368
3369 // Return if this has context allocated locals.
3370 bool HasHeapAllocatedLocals();
3371
3372 // Return if contexts are allocated for this scope.
3373 bool HasContext();
3374
3375 // Return the function_name if present.
3376 String* FunctionName();
3377
3378 // Return the name of the given parameter.
3379 String* ParameterName(int var);
3380
3381 // Return the name of the given local.
3382 String* LocalName(int var);
3383
3384 // Return the name of the given stack local.
3385 String* StackLocalName(int var);
3386
3387 // Return the name of the given context local.
3388 String* ContextLocalName(int var);
3389
3390 // Return the mode of the given context local.
3391 VariableMode ContextLocalMode(int var);
3392
3393 // Return the initialization flag of the given context local.
3394 InitializationFlag ContextLocalInitFlag(int var);
3395
3396 // Lookup support for serialized scope info. Returns the
3397 // the stack slot index for a given slot name if the slot is
3398 // present; otherwise returns a value < 0. The name must be a symbol
3399 // (canonicalized).
3400 int StackSlotIndex(String* name);
3401
3402 // Lookup support for serialized scope info. Returns the
3403 // context slot index for a given slot name if the slot is present; otherwise
3404 // returns a value < 0. The name must be a symbol (canonicalized).
3405 // If the slot is present and mode != NULL, sets *mode to the corresponding
3406 // mode for that variable.
3407 int ContextSlotIndex(String* name,
3408 VariableMode* mode,
3409 InitializationFlag* init_flag);
3410
3411 // Lookup support for serialized scope info. Returns the
3412 // parameter index for a given parameter name if the parameter is present;
3413 // otherwise returns a value < 0. The name must be a symbol (canonicalized).
3414 int ParameterIndex(String* name);
3415
3416 // Lookup support for serialized scope info. Returns the
3417 // function context slot index if the function name is present (named
3418 // function expressions, only), otherwise returns a value < 0. The name
3419 // must be a symbol (canonicalized).
3420 int FunctionContextSlotIndex(String* name, VariableMode* mode);
3421
3422 static Handle<ScopeInfo> Create(Scope* scope);
3423
3424 // Serializes empty scope info.
3425 static ScopeInfo* Empty();
3426
3427#ifdef DEBUG
3428 void Print();
3429#endif
3430
3431 // The layout of the static part of a ScopeInfo is as follows. Each entry is
3432 // numeric and occupies one array slot.
3433 // 1. A set of properties of the scope
3434 // 2. The number of parameters. This only applies to function scopes. For
3435 // non-function scopes this is 0.
3436 // 3. The number of non-parameter variables allocated on the stack.
3437 // 4. The number of non-parameter and parameter variables allocated in the
3438 // context.
3439#define FOR_EACH_NUMERIC_FIELD(V) \
3440 V(Flags) \
3441 V(ParameterCount) \
3442 V(StackLocalCount) \
3443 V(ContextLocalCount)
3444
3445#define FIELD_ACCESSORS(name) \
3446 void Set##name(int value) { \
3447 set(k##name, Smi::FromInt(value)); \
3448 } \
3449 int name() { \
3450 if (length() > 0) { \
3451 return Smi::cast(get(k##name))->value(); \
3452 } else { \
3453 return 0; \
3454 } \
3455 }
3456 FOR_EACH_NUMERIC_FIELD(FIELD_ACCESSORS)
3457#undef FIELD_ACCESSORS
3458
3459 private:
3460 enum {
3461#define DECL_INDEX(name) k##name,
3462 FOR_EACH_NUMERIC_FIELD(DECL_INDEX)
3463#undef DECL_INDEX
3464#undef FOR_EACH_NUMERIC_FIELD
3465 kVariablePartIndex
3466 };
3467
3468 // The layout of the variable part of a ScopeInfo is as follows:
3469 // 1. ParameterEntries:
3470 // This part stores the names of the parameters for function scopes. One
3471 // slot is used per parameter, so in total this part occupies
3472 // ParameterCount() slots in the array. For other scopes than function
3473 // scopes ParameterCount() is 0.
3474 // 2. StackLocalEntries:
3475 // Contains the names of local variables that are allocated on the stack,
3476 // in increasing order of the stack slot index. One slot is used per stack
3477 // local, so in total this part occupies StackLocalCount() slots in the
3478 // array.
3479 // 3. ContextLocalNameEntries:
3480 // Contains the names of local variables and parameters that are allocated
3481 // in the context. They are stored in increasing order of the context slot
3482 // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per
3483 // context local, so in total this part occupies ContextLocalCount() slots
3484 // in the array.
3485 // 4. ContextLocalInfoEntries:
3486 // Contains the variable modes and initialization flags corresponding to
3487 // the context locals in ContextLocalNameEntries. One slot is used per
3488 // context local, so in total this part occupies ContextLocalCount()
3489 // slots in the array.
3490 // 5. FunctionNameEntryIndex:
3491 // If the scope belongs to a named function expression this part contains
3492 // information about the function variable. It always occupies two array
3493 // slots: a. The name of the function variable.
3494 // b. The context or stack slot index for the variable.
3495 int ParameterEntriesIndex();
3496 int StackLocalEntriesIndex();
3497 int ContextLocalNameEntriesIndex();
3498 int ContextLocalInfoEntriesIndex();
3499 int FunctionNameEntryIndex();
3500
3501 // Location of the function variable for named function expressions.
3502 enum FunctionVariableInfo {
3503 NONE, // No function name present.
3504 STACK, // Function
3505 CONTEXT,
3506 UNUSED
3507 };
3508
3509 // Properties of scopes.
3510 class TypeField: public BitField<ScopeType, 0, 3> {};
3511 class CallsEvalField: public BitField<bool, 3, 1> {};
3512 class LanguageModeField: public BitField<LanguageMode, 4, 2> {};
3513 class FunctionVariableField: public BitField<FunctionVariableInfo, 6, 2> {};
3514 class FunctionVariableMode: public BitField<VariableMode, 8, 3> {};
3515
3516 // BitFields representing the encoded information for context locals in the
3517 // ContextLocalInfoEntries part.
3518 class ContextLocalMode: public BitField<VariableMode, 0, 3> {};
3519 class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {};
3520};
3521
3522
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003523// The cache for maps used by normalized (dictionary mode) objects.
3524// Such maps do not have property descriptors, so a typical program
3525// needs very limited number of distinct normalized maps.
3526class NormalizedMapCache: public FixedArray {
3527 public:
3528 static const int kEntries = 64;
3529
John Reck59135872010-11-02 12:39:01 -07003530 MUST_USE_RESULT MaybeObject* Get(JSObject* object,
3531 PropertyNormalizationMode mode);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003532
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003533 void Clear();
3534
3535 // Casting
3536 static inline NormalizedMapCache* cast(Object* obj);
3537
3538#ifdef DEBUG
3539 void NormalizedMapCacheVerify();
3540#endif
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003541};
3542
3543
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003544// ByteArray represents fixed sized byte arrays. Used for the relocation info
3545// that is attached to code objects.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003546class ByteArray: public FixedArrayBase {
Steve Blocka7e24c12009-10-30 11:49:00 +00003547 public:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003548 inline int Size() { return RoundUp(length() + kHeaderSize, kPointerSize); }
3549
Steve Blocka7e24c12009-10-30 11:49:00 +00003550 // Setter and getter.
3551 inline byte get(int index);
3552 inline void set(int index, byte value);
3553
3554 // Treat contents as an int array.
3555 inline int get_int(int index);
3556
3557 static int SizeFor(int length) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01003558 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
Steve Blocka7e24c12009-10-30 11:49:00 +00003559 }
3560 // We use byte arrays for free blocks in the heap. Given a desired size in
3561 // bytes that is a multiple of the word size and big enough to hold a byte
3562 // array, this function returns the number of elements a byte array should
3563 // have.
3564 static int LengthFor(int size_in_bytes) {
3565 ASSERT(IsAligned(size_in_bytes, kPointerSize));
3566 ASSERT(size_in_bytes >= kHeaderSize);
3567 return size_in_bytes - kHeaderSize;
3568 }
3569
3570 // Returns data start address.
3571 inline Address GetDataStartAddress();
3572
3573 // Returns a pointer to the ByteArray object for a given data start address.
3574 static inline ByteArray* FromDataStartAddress(Address address);
3575
3576 // Casting.
3577 static inline ByteArray* cast(Object* obj);
3578
3579 // Dispatched behavior.
Iain Merrick75681382010-08-19 15:07:18 +01003580 inline int ByteArraySize() {
3581 return SizeFor(this->length());
3582 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01003583#ifdef OBJECT_PRINT
3584 inline void ByteArrayPrint() {
3585 ByteArrayPrint(stdout);
3586 }
3587 void ByteArrayPrint(FILE* out);
3588#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00003589#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00003590 void ByteArrayVerify();
3591#endif
3592
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01003593 // Layout description.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01003594 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00003595
Leon Clarkee46be812010-01-19 14:06:41 +00003596 // Maximal memory consumption for a single ByteArray.
3597 static const int kMaxSize = 512 * MB;
3598 // Maximal length of a single ByteArray.
3599 static const int kMaxLength = kMaxSize - kHeaderSize;
3600
Steve Blocka7e24c12009-10-30 11:49:00 +00003601 private:
3602 DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray);
3603};
3604
3605
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003606// FreeSpace represents fixed sized areas of the heap that are not currently in
3607// use. Used by the heap and GC.
3608class FreeSpace: public HeapObject {
3609 public:
3610 // [size]: size of the free space including the header.
3611 inline int size();
3612 inline void set_size(int value);
3613
3614 inline int Size() { return size(); }
3615
3616 // Casting.
3617 static inline FreeSpace* cast(Object* obj);
3618
3619#ifdef OBJECT_PRINT
3620 inline void FreeSpacePrint() {
3621 FreeSpacePrint(stdout);
3622 }
3623 void FreeSpacePrint(FILE* out);
3624#endif
3625#ifdef DEBUG
3626 void FreeSpaceVerify();
3627#endif
3628
3629 // Layout description.
3630 // Size is smi tagged when it is stored.
3631 static const int kSizeOffset = HeapObject::kHeaderSize;
3632 static const int kHeaderSize = kSizeOffset + kPointerSize;
3633
3634 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
3635
3636 private:
3637 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace);
3638};
3639
3640
Steve Block3ce2e202009-11-05 08:53:23 +00003641// An ExternalArray represents a fixed-size array of primitive values
3642// which live outside the JavaScript heap. Its subclasses are used to
3643// implement the CanvasArray types being defined in the WebGL
3644// specification. As of this writing the first public draft is not yet
3645// available, but Khronos members can access the draft at:
3646// https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html
3647//
3648// The semantics of these arrays differ from CanvasPixelArray.
3649// Out-of-range values passed to the setter are converted via a C
3650// cast, not clamping. Out-of-range indices cause exceptions to be
3651// raised rather than being silently ignored.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003652class ExternalArray: public FixedArrayBase {
Steve Block3ce2e202009-11-05 08:53:23 +00003653 public:
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003654 inline bool is_the_hole(int index) { return false; }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01003655
Steve Block3ce2e202009-11-05 08:53:23 +00003656 // [external_pointer]: The pointer to the external memory area backing this
3657 // external array.
3658 DECL_ACCESSORS(external_pointer, void) // Pointer to the data store.
3659
3660 // Casting.
3661 static inline ExternalArray* cast(Object* obj);
3662
3663 // Maximal acceptable length for an external array.
3664 static const int kMaxLength = 0x3fffffff;
3665
3666 // ExternalArray headers are not quadword aligned.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01003667 static const int kExternalPointerOffset =
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003668 POINTER_SIZE_ALIGN(FixedArrayBase::kLengthOffset + kPointerSize);
Steve Block3ce2e202009-11-05 08:53:23 +00003669 static const int kHeaderSize = kExternalPointerOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01003670 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
Steve Block3ce2e202009-11-05 08:53:23 +00003671
3672 private:
3673 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray);
3674};
3675
3676
Steve Block44f0eee2011-05-26 01:26:41 +01003677// A ExternalPixelArray represents a fixed-size byte array with special
3678// semantics used for implementing the CanvasPixelArray object. Please see the
3679// specification at:
3680
3681// http://www.whatwg.org/specs/web-apps/current-work/
3682// multipage/the-canvas-element.html#canvaspixelarray
3683// In particular, write access clamps the value written to 0 or 255 if the
3684// value written is outside this range.
3685class ExternalPixelArray: public ExternalArray {
3686 public:
3687 inline uint8_t* external_pixel_pointer();
3688
3689 // Setter and getter.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003690 inline uint8_t get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003691 MUST_USE_RESULT inline MaybeObject* get(int index);
Steve Block44f0eee2011-05-26 01:26:41 +01003692 inline void set(int index, uint8_t value);
3693
3694 // This accessor applies the correct conversion from Smi, HeapNumber and
3695 // undefined and clamps the converted value between 0 and 255.
3696 Object* SetValue(uint32_t index, Object* value);
3697
3698 // Casting.
3699 static inline ExternalPixelArray* cast(Object* obj);
3700
3701#ifdef OBJECT_PRINT
3702 inline void ExternalPixelArrayPrint() {
3703 ExternalPixelArrayPrint(stdout);
3704 }
3705 void ExternalPixelArrayPrint(FILE* out);
3706#endif
3707#ifdef DEBUG
3708 void ExternalPixelArrayVerify();
3709#endif // DEBUG
3710
3711 private:
3712 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray);
3713};
3714
3715
Steve Block3ce2e202009-11-05 08:53:23 +00003716class ExternalByteArray: public ExternalArray {
3717 public:
3718 // Setter and getter.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003719 inline int8_t get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003720 MUST_USE_RESULT inline MaybeObject* get(int index);
Steve Block3ce2e202009-11-05 08:53:23 +00003721 inline void set(int index, int8_t value);
3722
3723 // This accessor applies the correct conversion from Smi, HeapNumber
3724 // and undefined.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003725 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
Steve Block3ce2e202009-11-05 08:53:23 +00003726
3727 // Casting.
3728 static inline ExternalByteArray* cast(Object* obj);
3729
Ben Murdochb0fe1622011-05-05 13:52:32 +01003730#ifdef OBJECT_PRINT
3731 inline void ExternalByteArrayPrint() {
3732 ExternalByteArrayPrint(stdout);
3733 }
3734 void ExternalByteArrayPrint(FILE* out);
3735#endif
Steve Block3ce2e202009-11-05 08:53:23 +00003736#ifdef DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +00003737 void ExternalByteArrayVerify();
3738#endif // DEBUG
3739
3740 private:
3741 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray);
3742};
3743
3744
3745class ExternalUnsignedByteArray: public ExternalArray {
3746 public:
3747 // Setter and getter.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003748 inline uint8_t get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003749 MUST_USE_RESULT inline MaybeObject* get(int index);
Steve Block3ce2e202009-11-05 08:53:23 +00003750 inline void set(int index, uint8_t value);
3751
3752 // This accessor applies the correct conversion from Smi, HeapNumber
3753 // and undefined.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003754 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
Steve Block3ce2e202009-11-05 08:53:23 +00003755
3756 // Casting.
3757 static inline ExternalUnsignedByteArray* cast(Object* obj);
3758
Ben Murdochb0fe1622011-05-05 13:52:32 +01003759#ifdef OBJECT_PRINT
3760 inline void ExternalUnsignedByteArrayPrint() {
3761 ExternalUnsignedByteArrayPrint(stdout);
3762 }
3763 void ExternalUnsignedByteArrayPrint(FILE* out);
3764#endif
Steve Block3ce2e202009-11-05 08:53:23 +00003765#ifdef DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +00003766 void ExternalUnsignedByteArrayVerify();
3767#endif // DEBUG
3768
3769 private:
3770 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray);
3771};
3772
3773
3774class ExternalShortArray: public ExternalArray {
3775 public:
3776 // Setter and getter.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003777 inline int16_t get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003778 MUST_USE_RESULT inline MaybeObject* get(int index);
Steve Block3ce2e202009-11-05 08:53:23 +00003779 inline void set(int index, int16_t value);
3780
3781 // This accessor applies the correct conversion from Smi, HeapNumber
3782 // and undefined.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003783 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
Steve Block3ce2e202009-11-05 08:53:23 +00003784
3785 // Casting.
3786 static inline ExternalShortArray* cast(Object* obj);
3787
Ben Murdochb0fe1622011-05-05 13:52:32 +01003788#ifdef OBJECT_PRINT
3789 inline void ExternalShortArrayPrint() {
3790 ExternalShortArrayPrint(stdout);
3791 }
3792 void ExternalShortArrayPrint(FILE* out);
3793#endif
Steve Block3ce2e202009-11-05 08:53:23 +00003794#ifdef DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +00003795 void ExternalShortArrayVerify();
3796#endif // DEBUG
3797
3798 private:
3799 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray);
3800};
3801
3802
3803class ExternalUnsignedShortArray: public ExternalArray {
3804 public:
3805 // Setter and getter.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003806 inline uint16_t get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003807 MUST_USE_RESULT inline MaybeObject* get(int index);
Steve Block3ce2e202009-11-05 08:53:23 +00003808 inline void set(int index, uint16_t value);
3809
3810 // This accessor applies the correct conversion from Smi, HeapNumber
3811 // and undefined.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003812 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
Steve Block3ce2e202009-11-05 08:53:23 +00003813
3814 // Casting.
3815 static inline ExternalUnsignedShortArray* cast(Object* obj);
3816
Ben Murdochb0fe1622011-05-05 13:52:32 +01003817#ifdef OBJECT_PRINT
3818 inline void ExternalUnsignedShortArrayPrint() {
3819 ExternalUnsignedShortArrayPrint(stdout);
3820 }
3821 void ExternalUnsignedShortArrayPrint(FILE* out);
3822#endif
Steve Block3ce2e202009-11-05 08:53:23 +00003823#ifdef DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +00003824 void ExternalUnsignedShortArrayVerify();
3825#endif // DEBUG
3826
3827 private:
3828 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray);
3829};
3830
3831
3832class ExternalIntArray: public ExternalArray {
3833 public:
3834 // Setter and getter.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003835 inline int32_t get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003836 MUST_USE_RESULT inline MaybeObject* get(int index);
Steve Block3ce2e202009-11-05 08:53:23 +00003837 inline void set(int index, int32_t value);
3838
3839 // This accessor applies the correct conversion from Smi, HeapNumber
3840 // and undefined.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003841 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
Steve Block3ce2e202009-11-05 08:53:23 +00003842
3843 // Casting.
3844 static inline ExternalIntArray* cast(Object* obj);
3845
Ben Murdochb0fe1622011-05-05 13:52:32 +01003846#ifdef OBJECT_PRINT
3847 inline void ExternalIntArrayPrint() {
3848 ExternalIntArrayPrint(stdout);
3849 }
3850 void ExternalIntArrayPrint(FILE* out);
3851#endif
Steve Block3ce2e202009-11-05 08:53:23 +00003852#ifdef DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +00003853 void ExternalIntArrayVerify();
3854#endif // DEBUG
3855
3856 private:
3857 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray);
3858};
3859
3860
3861class ExternalUnsignedIntArray: public ExternalArray {
3862 public:
3863 // Setter and getter.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003864 inline uint32_t get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003865 MUST_USE_RESULT inline MaybeObject* get(int index);
Steve Block3ce2e202009-11-05 08:53:23 +00003866 inline void set(int index, uint32_t value);
3867
3868 // This accessor applies the correct conversion from Smi, HeapNumber
3869 // and undefined.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003870 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
Steve Block3ce2e202009-11-05 08:53:23 +00003871
3872 // Casting.
3873 static inline ExternalUnsignedIntArray* cast(Object* obj);
3874
Ben Murdochb0fe1622011-05-05 13:52:32 +01003875#ifdef OBJECT_PRINT
3876 inline void ExternalUnsignedIntArrayPrint() {
3877 ExternalUnsignedIntArrayPrint(stdout);
3878 }
3879 void ExternalUnsignedIntArrayPrint(FILE* out);
3880#endif
Steve Block3ce2e202009-11-05 08:53:23 +00003881#ifdef DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +00003882 void ExternalUnsignedIntArrayVerify();
3883#endif // DEBUG
3884
3885 private:
3886 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray);
3887};
3888
3889
3890class ExternalFloatArray: public ExternalArray {
3891 public:
3892 // Setter and getter.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003893 inline float get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003894 MUST_USE_RESULT inline MaybeObject* get(int index);
Steve Block3ce2e202009-11-05 08:53:23 +00003895 inline void set(int index, float value);
3896
3897 // This accessor applies the correct conversion from Smi, HeapNumber
3898 // and undefined.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003899 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
Steve Block3ce2e202009-11-05 08:53:23 +00003900
3901 // Casting.
3902 static inline ExternalFloatArray* cast(Object* obj);
3903
Ben Murdochb0fe1622011-05-05 13:52:32 +01003904#ifdef OBJECT_PRINT
3905 inline void ExternalFloatArrayPrint() {
3906 ExternalFloatArrayPrint(stdout);
3907 }
3908 void ExternalFloatArrayPrint(FILE* out);
3909#endif
Steve Block3ce2e202009-11-05 08:53:23 +00003910#ifdef DEBUG
Steve Block3ce2e202009-11-05 08:53:23 +00003911 void ExternalFloatArrayVerify();
3912#endif // DEBUG
3913
3914 private:
3915 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray);
3916};
3917
3918
Ben Murdoch257744e2011-11-30 15:57:28 +00003919class ExternalDoubleArray: public ExternalArray {
3920 public:
3921 // Setter and getter.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003922 inline double get_scalar(int index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003923 MUST_USE_RESULT inline MaybeObject* get(int index);
Ben Murdoch257744e2011-11-30 15:57:28 +00003924 inline void set(int index, double value);
3925
3926 // This accessor applies the correct conversion from Smi, HeapNumber
3927 // and undefined.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003928 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
Ben Murdoch257744e2011-11-30 15:57:28 +00003929
3930 // Casting.
3931 static inline ExternalDoubleArray* cast(Object* obj);
3932
3933#ifdef OBJECT_PRINT
3934 inline void ExternalDoubleArrayPrint() {
3935 ExternalDoubleArrayPrint(stdout);
3936 }
3937 void ExternalDoubleArrayPrint(FILE* out);
3938#endif // OBJECT_PRINT
3939#ifdef DEBUG
3940 void ExternalDoubleArrayVerify();
3941#endif // DEBUG
3942
3943 private:
3944 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray);
3945};
3946
3947
Ben Murdochb0fe1622011-05-05 13:52:32 +01003948// DeoptimizationInputData is a fixed array used to hold the deoptimization
3949// data for code generated by the Hydrogen/Lithium compiler. It also
3950// contains information about functions that were inlined. If N different
3951// functions were inlined then first N elements of the literal array will
3952// contain these functions.
3953//
3954// It can be empty.
3955class DeoptimizationInputData: public FixedArray {
3956 public:
3957 // Layout description. Indices in the array.
3958 static const int kTranslationByteArrayIndex = 0;
3959 static const int kInlinedFunctionCountIndex = 1;
3960 static const int kLiteralArrayIndex = 2;
3961 static const int kOsrAstIdIndex = 3;
3962 static const int kOsrPcOffsetIndex = 4;
3963 static const int kFirstDeoptEntryIndex = 5;
3964
3965 // Offsets of deopt entry elements relative to the start of the entry.
3966 static const int kAstIdOffset = 0;
3967 static const int kTranslationIndexOffset = 1;
3968 static const int kArgumentsStackHeightOffset = 2;
Ben Murdoch2b4ba112012-01-20 14:57:15 +00003969 static const int kPcOffset = 3;
3970 static const int kDeoptEntrySize = 4;
Ben Murdochb0fe1622011-05-05 13:52:32 +01003971
3972 // Simple element accessors.
3973#define DEFINE_ELEMENT_ACCESSORS(name, type) \
3974 type* name() { \
3975 return type::cast(get(k##name##Index)); \
3976 } \
3977 void Set##name(type* value) { \
3978 set(k##name##Index, value); \
3979 }
3980
3981 DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
3982 DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
3983 DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
3984 DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi)
3985 DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
3986
Ben Murdochb0fe1622011-05-05 13:52:32 +01003987#undef DEFINE_ELEMENT_ACCESSORS
3988
3989 // Accessors for elements of the ith deoptimization entry.
3990#define DEFINE_ENTRY_ACCESSORS(name, type) \
3991 type* name(int i) { \
3992 return type::cast(get(IndexForEntry(i) + k##name##Offset)); \
3993 } \
3994 void Set##name(int i, type* value) { \
3995 set(IndexForEntry(i) + k##name##Offset, value); \
3996 }
3997
3998 DEFINE_ENTRY_ACCESSORS(AstId, Smi)
3999 DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi)
4000 DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi)
Ben Murdoch2b4ba112012-01-20 14:57:15 +00004001 DEFINE_ENTRY_ACCESSORS(Pc, Smi)
Ben Murdochb0fe1622011-05-05 13:52:32 +01004002
4003#undef DEFINE_ENTRY_ACCESSORS
4004
4005 int DeoptCount() {
4006 return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize;
4007 }
4008
4009 // Allocates a DeoptimizationInputData.
4010 MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count,
4011 PretenureFlag pretenure);
4012
4013 // Casting.
4014 static inline DeoptimizationInputData* cast(Object* obj);
4015
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004016#ifdef ENABLE_DISASSEMBLER
Ben Murdochb0fe1622011-05-05 13:52:32 +01004017 void DeoptimizationInputDataPrint(FILE* out);
4018#endif
4019
4020 private:
4021 static int IndexForEntry(int i) {
4022 return kFirstDeoptEntryIndex + (i * kDeoptEntrySize);
4023 }
4024
4025 static int LengthFor(int entry_count) {
4026 return IndexForEntry(entry_count);
4027 }
4028};
4029
4030
4031// DeoptimizationOutputData is a fixed array used to hold the deoptimization
4032// data for code generated by the full compiler.
4033// The format of the these objects is
4034// [i * 2]: Ast ID for ith deoptimization.
4035// [i * 2 + 1]: PC and state of ith deoptimization
4036class DeoptimizationOutputData: public FixedArray {
4037 public:
4038 int DeoptPoints() { return length() / 2; }
4039 Smi* AstId(int index) { return Smi::cast(get(index * 2)); }
4040 void SetAstId(int index, Smi* id) { set(index * 2, id); }
4041 Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); }
4042 void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); }
4043
4044 static int LengthOfFixedArray(int deopt_points) {
4045 return deopt_points * 2;
4046 }
4047
4048 // Allocates a DeoptimizationOutputData.
4049 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points,
4050 PretenureFlag pretenure);
4051
4052 // Casting.
4053 static inline DeoptimizationOutputData* cast(Object* obj);
4054
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004055#if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
Ben Murdochb0fe1622011-05-05 13:52:32 +01004056 void DeoptimizationOutputDataPrint(FILE* out);
4057#endif
4058};
4059
4060
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004061// Forward declaration.
4062class JSGlobalPropertyCell;
Ben Murdoch85b71792012-04-11 18:30:58 +01004063
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004064// TypeFeedbackCells is a fixed array used to hold the association between
4065// cache cells and AST ids for code generated by the full compiler.
4066// The format of the these objects is
4067// [i * 2]: Global property cell of ith cache cell.
4068// [i * 2 + 1]: Ast ID for ith cache cell.
4069class TypeFeedbackCells: public FixedArray {
4070 public:
4071 int CellCount() { return length() / 2; }
4072 static int LengthOfFixedArray(int cell_count) { return cell_count * 2; }
4073
4074 // Accessors for AST ids associated with cache values.
4075 inline Smi* AstId(int index);
4076 inline void SetAstId(int index, Smi* id);
4077
4078 // Accessors for global property cells holding the cache values.
4079 inline JSGlobalPropertyCell* Cell(int index);
4080 inline void SetCell(int index, JSGlobalPropertyCell* cell);
4081
4082 // The object that indicates an uninitialized cache.
4083 static inline Handle<Object> UninitializedSentinel(Isolate* isolate);
4084
4085 // The object that indicates a megamorphic state.
4086 static inline Handle<Object> MegamorphicSentinel(Isolate* isolate);
4087
4088 // A raw version of the uninitialized sentinel that's safe to read during
4089 // garbage collection (e.g., for patching the cache).
4090 static inline Object* RawUninitializedSentinel(Heap* heap);
4091
4092 // Casting.
4093 static inline TypeFeedbackCells* cast(Object* obj);
4094
4095 static const int kForInFastCaseMarker = 0;
4096 static const int kForInSlowCaseMarker = 1;
4097};
4098
4099
4100// Forward declaration.
4101class SafepointEntry;
4102class TypeFeedbackInfo;
Ben Murdochb8e0da22011-05-16 14:20:40 +01004103
Steve Blocka7e24c12009-10-30 11:49:00 +00004104// Code describes objects with on-the-fly generated machine code.
4105class Code: public HeapObject {
4106 public:
4107 // Opaque data type for encapsulating code flags like kind, inline
4108 // cache state, and arguments count.
Iain Merrick75681382010-08-19 15:07:18 +01004109 // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that
4110 // enumeration type has correct value range (see Issue 830 for more details).
4111 enum Flags {
4112 FLAGS_MIN_VALUE = kMinInt,
4113 FLAGS_MAX_VALUE = kMaxInt
4114 };
Steve Blocka7e24c12009-10-30 11:49:00 +00004115
4116 enum Kind {
4117 FUNCTION,
Ben Murdochb0fe1622011-05-05 13:52:32 +01004118 OPTIMIZED_FUNCTION,
Steve Blocka7e24c12009-10-30 11:49:00 +00004119 STUB,
4120 BUILTIN,
4121 LOAD_IC,
4122 KEYED_LOAD_IC,
4123 CALL_IC,
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01004124 KEYED_CALL_IC,
Steve Blocka7e24c12009-10-30 11:49:00 +00004125 STORE_IC,
4126 KEYED_STORE_IC,
Ben Murdoch257744e2011-11-30 15:57:28 +00004127 UNARY_OP_IC,
4128 BINARY_OP_IC,
Ben Murdochb0fe1622011-05-05 13:52:32 +01004129 COMPARE_IC,
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004130 TO_BOOLEAN_IC,
Steve Block6ded16b2010-05-10 14:33:55 +01004131 // No more than 16 kinds. The value currently encoded in four bits in
Steve Blocka7e24c12009-10-30 11:49:00 +00004132 // Flags.
4133
4134 // Pseudo-kinds.
4135 REGEXP = BUILTIN,
4136 FIRST_IC_KIND = LOAD_IC,
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004137 LAST_IC_KIND = TO_BOOLEAN_IC
Steve Blocka7e24c12009-10-30 11:49:00 +00004138 };
4139
4140 enum {
Kristian Monsen50ef84f2010-07-29 15:18:00 +01004141 NUMBER_OF_KINDS = LAST_IC_KIND + 1
Steve Blocka7e24c12009-10-30 11:49:00 +00004142 };
4143
Ben Murdochb8e0da22011-05-16 14:20:40 +01004144 typedef int ExtraICState;
4145
4146 static const ExtraICState kNoExtraICState = 0;
4147
Steve Blocka7e24c12009-10-30 11:49:00 +00004148#ifdef ENABLE_DISASSEMBLER
4149 // Printing
4150 static const char* Kind2String(Kind kind);
4151 static const char* ICState2String(InlineCacheState state);
4152 static const char* PropertyType2String(PropertyType type);
Steve Block1e0659c2011-05-24 12:43:12 +01004153 static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004154 inline void Disassemble(const char* name) {
4155 Disassemble(name, stdout);
4156 }
4157 void Disassemble(const char* name, FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +00004158#endif // ENABLE_DISASSEMBLER
4159
4160 // [instruction_size]: Size of the native instructions
4161 inline int instruction_size();
4162 inline void set_instruction_size(int value);
4163
Leon Clarkeac952652010-07-15 11:15:24 +01004164 // [relocation_info]: Code relocation information
4165 DECL_ACCESSORS(relocation_info, ByteArray)
Ben Murdochb0fe1622011-05-05 13:52:32 +01004166 void InvalidateRelocation();
Leon Clarkeac952652010-07-15 11:15:24 +01004167
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004168 // [handler_table]: Fixed array containing offsets of exception handlers.
4169 DECL_ACCESSORS(handler_table, FixedArray)
4170
Ben Murdochb0fe1622011-05-05 13:52:32 +01004171 // [deoptimization_data]: Array containing data for deopt.
4172 DECL_ACCESSORS(deoptimization_data, FixedArray)
4173
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004174 // [type_feedback_info]: Struct containing type feedback information.
4175 // Will contain either a TypeFeedbackInfo object, or undefined.
4176 DECL_ACCESSORS(type_feedback_info, Object)
4177
4178 // [gc_metadata]: Field used to hold GC related metadata. The contents of this
Ben Murdoch257744e2011-11-30 15:57:28 +00004179 // field does not have to be traced during garbage collection since
4180 // it is only used by the garbage collector itself.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004181 DECL_ACCESSORS(gc_metadata, Object)
4182
4183 // [ic_age]: Inline caching age: the value of the Heap::global_ic_age
4184 // at the moment when this object was created.
4185 inline void set_ic_age(int count);
4186 inline int ic_age();
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +01004187
Ben Murdochb0fe1622011-05-05 13:52:32 +01004188 // Unchecked accessors to be used during GC.
Leon Clarkeac952652010-07-15 11:15:24 +01004189 inline ByteArray* unchecked_relocation_info();
Ben Murdochb0fe1622011-05-05 13:52:32 +01004190 inline FixedArray* unchecked_deoptimization_data();
Leon Clarkeac952652010-07-15 11:15:24 +01004191
Steve Blocka7e24c12009-10-30 11:49:00 +00004192 inline int relocation_size();
Steve Blocka7e24c12009-10-30 11:49:00 +00004193
Steve Blocka7e24c12009-10-30 11:49:00 +00004194 // [flags]: Various code flags.
4195 inline Flags flags();
4196 inline void set_flags(Flags flags);
4197
4198 // [flags]: Access to specific code flags.
4199 inline Kind kind();
4200 inline InlineCacheState ic_state(); // Only valid for IC stubs.
Ben Murdochb8e0da22011-05-16 14:20:40 +01004201 inline ExtraICState extra_ic_state(); // Only valid for IC stubs.
Steve Blocka7e24c12009-10-30 11:49:00 +00004202 inline PropertyType type(); // Only valid for monomorphic IC stubs.
4203 inline int arguments_count(); // Only valid for call IC stubs.
4204
4205 // Testers for IC stub kinds.
4206 inline bool is_inline_cache_stub();
4207 inline bool is_load_stub() { return kind() == LOAD_IC; }
4208 inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; }
4209 inline bool is_store_stub() { return kind() == STORE_IC; }
4210 inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; }
4211 inline bool is_call_stub() { return kind() == CALL_IC; }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01004212 inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; }
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004213 inline bool is_unary_op_stub() { return kind() == UNARY_OP_IC; }
4214 inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; }
Ben Murdochb0fe1622011-05-05 13:52:32 +01004215 inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; }
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004216 inline bool is_to_boolean_ic_stub() { return kind() == TO_BOOLEAN_IC; }
Steve Blocka7e24c12009-10-30 11:49:00 +00004217
Steve Block6ded16b2010-05-10 14:33:55 +01004218 // [major_key]: For kind STUB or BINARY_OP_IC, the major key.
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004219 inline int major_key();
Ben Murdochb0fe1622011-05-05 13:52:32 +01004220 inline void set_major_key(int value);
4221
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004222 // For stubs, tells whether they should always exist, so that they can be
4223 // called from other stubs.
4224 inline bool is_pregenerated();
4225 inline void set_is_pregenerated(bool value);
4226
Ben Murdochb0fe1622011-05-05 13:52:32 +01004227 // [optimizable]: For FUNCTION kind, tells if it is optimizable.
4228 inline bool optimizable();
4229 inline void set_optimizable(bool value);
4230
4231 // [has_deoptimization_support]: For FUNCTION kind, tells if it has
4232 // deoptimization support.
4233 inline bool has_deoptimization_support();
4234 inline void set_has_deoptimization_support(bool value);
4235
Ben Murdoch589d6972011-11-30 16:04:58 +00004236 // [has_debug_break_slots]: For FUNCTION kind, tells if it has
4237 // been compiled with debug break slots.
4238 inline bool has_debug_break_slots();
4239 inline void set_has_debug_break_slots(bool value);
4240
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004241 // [compiled_with_optimizing]: For FUNCTION kind, tells if it has
4242 // been compiled with IsOptimizing set to true.
4243 inline bool is_compiled_optimizable();
4244 inline void set_compiled_optimizable(bool value);
4245
4246 // [has_self_optimization_header]: For FUNCTION kind, tells if it has
4247 // a self-optimization header.
4248 inline bool has_self_optimization_header();
4249 inline void set_self_optimization_header(bool value);
4250
Ben Murdochb0fe1622011-05-05 13:52:32 +01004251 // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for
4252 // how long the function has been marked for OSR and therefore which
4253 // level of loop nesting we are willing to do on-stack replacement
4254 // for.
4255 inline void set_allow_osr_at_loop_nesting_level(int level);
4256 inline int allow_osr_at_loop_nesting_level();
4257
4258 // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots
4259 // reserved in the code prologue.
4260 inline unsigned stack_slots();
4261 inline void set_stack_slots(unsigned slots);
4262
4263 // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in
4264 // the instruction stream where the safepoint table starts.
Steve Block1e0659c2011-05-24 12:43:12 +01004265 inline unsigned safepoint_table_offset();
4266 inline void set_safepoint_table_offset(unsigned offset);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004267
4268 // [stack_check_table_start]: For kind FUNCTION, the offset in the
4269 // instruction stream where the stack check table starts.
Steve Block1e0659c2011-05-24 12:43:12 +01004270 inline unsigned stack_check_table_offset();
4271 inline void set_stack_check_table_offset(unsigned offset);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004272
4273 // [check type]: For kind CALL_IC, tells how to check if the
4274 // receiver is valid for the given call.
4275 inline CheckType check_type();
4276 inline void set_check_type(CheckType value);
4277
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004278 // [type-recording unary op type]: For kind UNARY_OP_IC.
Ben Murdoch257744e2011-11-30 15:57:28 +00004279 inline byte unary_op_type();
4280 inline void set_unary_op_type(byte value);
4281
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004282 // [type-recording binary op type]: For kind BINARY_OP_IC.
Ben Murdoch257744e2011-11-30 15:57:28 +00004283 inline byte binary_op_type();
4284 inline void set_binary_op_type(byte value);
4285 inline byte binary_op_result_type();
4286 inline void set_binary_op_result_type(byte value);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004287
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004288 // [compare state]: For kind COMPARE_IC, tells what state the stub is in.
Ben Murdochb0fe1622011-05-05 13:52:32 +01004289 inline byte compare_state();
4290 inline void set_compare_state(byte value);
4291
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004292 // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in.
4293 inline byte to_boolean_state();
4294 inline void set_to_boolean_state(byte value);
4295
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004296 // [has_function_cache]: For kind STUB tells whether there is a function
4297 // cache is passed to the stub.
4298 inline bool has_function_cache();
4299 inline void set_has_function_cache(bool flag);
4300
Ben Murdochb8e0da22011-05-16 14:20:40 +01004301 // Get the safepoint entry for the given pc.
4302 SafepointEntry GetSafepointEntry(Address pc);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004303
4304 // Mark this code object as not having a stack check table. Assumes kind
4305 // is FUNCTION.
4306 void SetNoStackCheckTable();
4307
4308 // Find the first map in an IC stub.
4309 Map* FindFirstMap();
Steve Blocka7e24c12009-10-30 11:49:00 +00004310
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004311 class ExtraICStateStrictMode: public BitField<StrictModeFlag, 0, 1> {};
4312 class ExtraICStateKeyedAccessGrowMode:
4313 public BitField<KeyedAccessGrowMode, 1, 1> {}; // NOLINT
4314
4315 static const int kExtraICStateGrowModeShift = 1;
4316
4317 static inline StrictModeFlag GetStrictMode(ExtraICState extra_ic_state) {
4318 return ExtraICStateStrictMode::decode(extra_ic_state);
4319 }
4320
4321 static inline KeyedAccessGrowMode GetKeyedAccessGrowMode(
4322 ExtraICState extra_ic_state) {
4323 return ExtraICStateKeyedAccessGrowMode::decode(extra_ic_state);
4324 }
4325
4326 static inline ExtraICState ComputeExtraICState(
4327 KeyedAccessGrowMode grow_mode,
4328 StrictModeFlag strict_mode) {
4329 return ExtraICStateKeyedAccessGrowMode::encode(grow_mode) |
4330 ExtraICStateStrictMode::encode(strict_mode);
4331 }
4332
Steve Blocka7e24c12009-10-30 11:49:00 +00004333 // Flags operations.
Ben Murdochb8e0da22011-05-16 14:20:40 +01004334 static inline Flags ComputeFlags(
4335 Kind kind,
Ben Murdochb8e0da22011-05-16 14:20:40 +01004336 InlineCacheState ic_state = UNINITIALIZED,
4337 ExtraICState extra_ic_state = kNoExtraICState,
4338 PropertyType type = NORMAL,
4339 int argc = -1,
4340 InlineCacheHolderFlag holder = OWN_MAP);
Steve Blocka7e24c12009-10-30 11:49:00 +00004341
4342 static inline Flags ComputeMonomorphicFlags(
4343 Kind kind,
4344 PropertyType type,
Ben Murdochb8e0da22011-05-16 14:20:40 +01004345 ExtraICState extra_ic_state = kNoExtraICState,
Steve Block8defd9f2010-07-08 12:39:36 +01004346 InlineCacheHolderFlag holder = OWN_MAP,
Steve Blocka7e24c12009-10-30 11:49:00 +00004347 int argc = -1);
4348
Steve Blocka7e24c12009-10-30 11:49:00 +00004349 static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +00004350 static inline PropertyType ExtractTypeFromFlags(Flags flags);
Ben Murdoch589d6972011-11-30 16:04:58 +00004351 static inline Kind ExtractKindFromFlags(Flags flags);
Steve Block8defd9f2010-07-08 12:39:36 +01004352 static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
Ben Murdoch589d6972011-11-30 16:04:58 +00004353 static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags);
4354 static inline int ExtractArgumentsCountFromFlags(Flags flags);
4355
Steve Blocka7e24c12009-10-30 11:49:00 +00004356 static inline Flags RemoveTypeFromFlags(Flags flags);
4357
4358 // Convert a target address into a code object.
4359 static inline Code* GetCodeFromTargetAddress(Address address);
4360
Steve Block791712a2010-08-27 10:21:07 +01004361 // Convert an entry address into an object.
4362 static inline Object* GetObjectFromEntryAddress(Address location_of_address);
4363
Steve Blocka7e24c12009-10-30 11:49:00 +00004364 // Returns the address of the first instruction.
4365 inline byte* instruction_start();
4366
Leon Clarkeac952652010-07-15 11:15:24 +01004367 // Returns the address right after the last instruction.
4368 inline byte* instruction_end();
4369
Steve Blocka7e24c12009-10-30 11:49:00 +00004370 // Returns the size of the instructions, padding, and relocation information.
4371 inline int body_size();
4372
4373 // Returns the address of the first relocation info (read backwards!).
4374 inline byte* relocation_start();
4375
4376 // Code entry point.
4377 inline byte* entry();
4378
4379 // Returns true if pc is inside this object's instructions.
4380 inline bool contains(byte* pc);
4381
Steve Blocka7e24c12009-10-30 11:49:00 +00004382 // Relocate the code by delta bytes. Called to signal that this code
4383 // object has been moved by delta bytes.
Steve Blockd0582a62009-12-15 09:54:21 +00004384 void Relocate(intptr_t delta);
Steve Blocka7e24c12009-10-30 11:49:00 +00004385
4386 // Migrate code described by desc.
4387 void CopyFrom(const CodeDesc& desc);
4388
Ben Murdoch3bec4d22010-07-22 14:51:16 +01004389 // Returns the object size for a given body (used for allocation).
4390 static int SizeFor(int body_size) {
Steve Blocka7e24c12009-10-30 11:49:00 +00004391 ASSERT_SIZE_TAG_ALIGNED(body_size);
Ben Murdoch3bec4d22010-07-22 14:51:16 +01004392 return RoundUp(kHeaderSize + body_size, kCodeAlignment);
Steve Blocka7e24c12009-10-30 11:49:00 +00004393 }
4394
4395 // Calculate the size of the code object to report for log events. This takes
4396 // the layout of the code object into account.
4397 int ExecutableSize() {
4398 // Check that the assumptions about the layout of the code object holds.
4399 ASSERT_EQ(static_cast<int>(instruction_start() - address()),
4400 Code::kHeaderSize);
4401 return instruction_size() + Code::kHeaderSize;
4402 }
4403
4404 // Locating source position.
4405 int SourcePosition(Address pc);
4406 int SourceStatementPosition(Address pc);
4407
4408 // Casting.
4409 static inline Code* cast(Object* obj);
4410
4411 // Dispatched behavior.
Ben Murdoch3bec4d22010-07-22 14:51:16 +01004412 int CodeSize() { return SizeFor(body_size()); }
Iain Merrick75681382010-08-19 15:07:18 +01004413 inline void CodeIterateBody(ObjectVisitor* v);
4414
4415 template<typename StaticVisitor>
Steve Block44f0eee2011-05-26 01:26:41 +01004416 inline void CodeIterateBody(Heap* heap);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004417#ifdef OBJECT_PRINT
4418 inline void CodePrint() {
4419 CodePrint(stdout);
4420 }
4421 void CodePrint(FILE* out);
4422#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00004423#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00004424 void CodeVerify();
4425#endif
Ben Murdochb0fe1622011-05-05 13:52:32 +01004426
4427 // Max loop nesting marker used to postpose OSR. We don't take loop
4428 // nesting that is deeper than 5 levels into account.
4429 static const int kMaxLoopNestingMarker = 6;
4430
Steve Blocka7e24c12009-10-30 11:49:00 +00004431 // Layout description.
4432 static const int kInstructionSizeOffset = HeapObject::kHeaderSize;
Leon Clarkeac952652010-07-15 11:15:24 +01004433 static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004434 static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize;
Ben Murdochb0fe1622011-05-05 13:52:32 +01004435 static const int kDeoptimizationDataOffset =
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004436 kHandlerTableOffset + kPointerSize;
4437 static const int kTypeFeedbackInfoOffset =
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +01004438 kDeoptimizationDataOffset + kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004439 static const int kGCMetadataOffset = kTypeFeedbackInfoOffset + kPointerSize;
4440 static const int kICAgeOffset =
4441 kGCMetadataOffset + kPointerSize;
4442 static const int kFlagsOffset = kICAgeOffset + kIntSize;
Ben Murdoch257744e2011-11-30 15:57:28 +00004443 static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize;
Ben Murdochb0fe1622011-05-05 13:52:32 +01004444 static const int kKindSpecificFlagsSize = 2 * kIntSize;
4445
4446 static const int kHeaderPaddingStart = kKindSpecificFlagsOffset +
4447 kKindSpecificFlagsSize;
4448
Steve Blocka7e24c12009-10-30 11:49:00 +00004449 // Add padding to align the instruction start following right after
4450 // the Code object header.
4451 static const int kHeaderSize =
Ben Murdochb0fe1622011-05-05 13:52:32 +01004452 (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask;
Steve Blocka7e24c12009-10-30 11:49:00 +00004453
4454 // Byte offsets within kKindSpecificFlagsOffset.
Ben Murdochb0fe1622011-05-05 13:52:32 +01004455 static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset;
4456 static const int kOptimizableOffset = kKindSpecificFlagsOffset;
4457 static const int kStackSlotsOffset = kKindSpecificFlagsOffset;
4458 static const int kCheckTypeOffset = kKindSpecificFlagsOffset;
4459
Ben Murdoch257744e2011-11-30 15:57:28 +00004460 static const int kUnaryOpTypeOffset = kStubMajorKeyOffset + 1;
Ben Murdochb0fe1622011-05-05 13:52:32 +01004461 static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004462 static const int kCompareStateOffset = kStubMajorKeyOffset + 1;
4463 static const int kToBooleanTypeOffset = kStubMajorKeyOffset + 1;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004464 static const int kHasFunctionCacheOffset = kStubMajorKeyOffset + 1;
Ben Murdoch589d6972011-11-30 16:04:58 +00004465
4466 static const int kFullCodeFlags = kOptimizableOffset + 1;
4467 class FullCodeFlagsHasDeoptimizationSupportField:
4468 public BitField<bool, 0, 1> {}; // NOLINT
4469 class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004470 class FullCodeFlagsIsCompiledOptimizable: public BitField<bool, 2, 1> {};
4471 class FullCodeFlagsHasSelfOptimizationHeader: public BitField<bool, 3, 1> {};
Ben Murdochb0fe1622011-05-05 13:52:32 +01004472
4473 static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1;
Ben Murdoch589d6972011-11-30 16:04:58 +00004474
4475 static const int kAllowOSRAtLoopNestingLevelOffset = kFullCodeFlags + 1;
Ben Murdochb0fe1622011-05-05 13:52:32 +01004476
Steve Block1e0659c2011-05-24 12:43:12 +01004477 static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize;
4478 static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00004479
Ben Murdoch589d6972011-11-30 16:04:58 +00004480 // Flags layout. BitField<type, shift, size>.
4481 class ICStateField: public BitField<InlineCacheState, 0, 3> {};
4482 class TypeField: public BitField<PropertyType, 3, 4> {};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004483 class CacheHolderField: public BitField<InlineCacheHolderFlag, 7, 1> {};
4484 class KindField: public BitField<Kind, 8, 4> {};
Ben Murdoch589d6972011-11-30 16:04:58 +00004485 class ExtraICStateField: public BitField<ExtraICState, 12, 2> {};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004486 class IsPregeneratedField: public BitField<bool, 14, 1> {};
Steve Blocka7e24c12009-10-30 11:49:00 +00004487
Ben Murdoch589d6972011-11-30 16:04:58 +00004488 // Signed field cannot be encoded using the BitField class.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004489 static const int kArgumentsCountShift = 15;
Ben Murdoch589d6972011-11-30 16:04:58 +00004490 static const int kArgumentsCountMask = ~((1 << kArgumentsCountShift) - 1);
Steve Blocka7e24c12009-10-30 11:49:00 +00004491
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004492 // This constant should be encodable in an ARM instruction.
Steve Blocka7e24c12009-10-30 11:49:00 +00004493 static const int kFlagsNotUsedInLookup =
Ben Murdoch589d6972011-11-30 16:04:58 +00004494 TypeField::kMask | CacheHolderField::kMask;
Steve Blocka7e24c12009-10-30 11:49:00 +00004495
4496 private:
4497 DISALLOW_IMPLICIT_CONSTRUCTORS(Code);
4498};
4499
4500
4501// All heap objects have a Map that describes their structure.
4502// A Map contains information about:
4503// - Size information about the object
4504// - How to iterate over an object (for garbage collection)
4505class Map: public HeapObject {
4506 public:
4507 // Instance size.
Steve Block791712a2010-08-27 10:21:07 +01004508 // Size in bytes or kVariableSizeSentinel if instances do not have
4509 // a fixed size.
Steve Blocka7e24c12009-10-30 11:49:00 +00004510 inline int instance_size();
4511 inline void set_instance_size(int value);
4512
4513 // Count of properties allocated in the object.
4514 inline int inobject_properties();
4515 inline void set_inobject_properties(int value);
4516
4517 // Count of property fields pre-allocated in the object when first allocated.
4518 inline int pre_allocated_property_fields();
4519 inline void set_pre_allocated_property_fields(int value);
4520
4521 // Instance type.
4522 inline InstanceType instance_type();
4523 inline void set_instance_type(InstanceType value);
4524
4525 // Tells how many unused property fields are available in the
4526 // instance (only used for JSObject in fast mode).
4527 inline int unused_property_fields();
4528 inline void set_unused_property_fields(int value);
4529
4530 // Bit field.
4531 inline byte bit_field();
4532 inline void set_bit_field(byte value);
4533
4534 // Bit field 2.
4535 inline byte bit_field2();
4536 inline void set_bit_field2(byte value);
4537
Ben Murdoch257744e2011-11-30 15:57:28 +00004538 // Bit field 3.
4539 // TODO(1399): It should be possible to make room for bit_field3 in the map
4540 // without overloading the instance descriptors field (and storing it in the
4541 // DescriptorArray when the map has one).
4542 inline int bit_field3();
4543 inline void set_bit_field3(int value);
4544
Steve Blocka7e24c12009-10-30 11:49:00 +00004545 // Tells whether the object in the prototype property will be used
4546 // for instances created from this function. If the prototype
4547 // property is set to a value that is not a JSObject, the prototype
4548 // property will not be used to create instances of the function.
4549 // See ECMA-262, 13.2.2.
4550 inline void set_non_instance_prototype(bool value);
4551 inline bool has_non_instance_prototype();
4552
Steve Block6ded16b2010-05-10 14:33:55 +01004553 // Tells whether function has special prototype property. If not, prototype
4554 // property will not be created when accessed (will return undefined),
4555 // and construction from this function will not be allowed.
4556 inline void set_function_with_prototype(bool value);
4557 inline bool function_with_prototype();
4558
Steve Blocka7e24c12009-10-30 11:49:00 +00004559 // Tells whether the instance with this map should be ignored by the
4560 // __proto__ accessor.
4561 inline void set_is_hidden_prototype() {
4562 set_bit_field(bit_field() | (1 << kIsHiddenPrototype));
4563 }
4564
4565 inline bool is_hidden_prototype() {
4566 return ((1 << kIsHiddenPrototype) & bit_field()) != 0;
4567 }
4568
4569 // Records and queries whether the instance has a named interceptor.
4570 inline void set_has_named_interceptor() {
4571 set_bit_field(bit_field() | (1 << kHasNamedInterceptor));
4572 }
4573
4574 inline bool has_named_interceptor() {
4575 return ((1 << kHasNamedInterceptor) & bit_field()) != 0;
4576 }
4577
4578 // Records and queries whether the instance has an indexed interceptor.
4579 inline void set_has_indexed_interceptor() {
4580 set_bit_field(bit_field() | (1 << kHasIndexedInterceptor));
4581 }
4582
4583 inline bool has_indexed_interceptor() {
4584 return ((1 << kHasIndexedInterceptor) & bit_field()) != 0;
4585 }
4586
4587 // Tells whether the instance is undetectable.
4588 // An undetectable object is a special class of JSObject: 'typeof' operator
4589 // returns undefined, ToBoolean returns false. Otherwise it behaves like
4590 // a normal JS object. It is useful for implementing undetectable
4591 // document.all in Firefox & Safari.
4592 // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
4593 inline void set_is_undetectable() {
4594 set_bit_field(bit_field() | (1 << kIsUndetectable));
4595 }
4596
4597 inline bool is_undetectable() {
4598 return ((1 << kIsUndetectable) & bit_field()) != 0;
4599 }
4600
Steve Blocka7e24c12009-10-30 11:49:00 +00004601 // Tells whether the instance has a call-as-function handler.
4602 inline void set_has_instance_call_handler() {
4603 set_bit_field(bit_field() | (1 << kHasInstanceCallHandler));
4604 }
4605
4606 inline bool has_instance_call_handler() {
4607 return ((1 << kHasInstanceCallHandler) & bit_field()) != 0;
4608 }
4609
Steve Block8defd9f2010-07-08 12:39:36 +01004610 inline void set_is_extensible(bool value);
4611 inline bool is_extensible();
4612
Ben Murdoch589d6972011-11-30 16:04:58 +00004613 inline void set_elements_kind(ElementsKind elements_kind) {
4614 ASSERT(elements_kind < kElementsKindCount);
4615 ASSERT(kElementsKindCount <= (1 << kElementsKindBitCount));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004616 set_bit_field2((bit_field2() & ~kElementsKindMask) |
4617 (elements_kind << kElementsKindShift));
4618 ASSERT(this->elements_kind() == elements_kind);
4619 }
4620
Ben Murdoch589d6972011-11-30 16:04:58 +00004621 inline ElementsKind elements_kind() {
4622 return static_cast<ElementsKind>(
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004623 (bit_field2() & kElementsKindMask) >> kElementsKindShift);
4624 }
4625
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004626 // Tells whether the instance has fast elements that are only Smis.
4627 inline bool has_fast_smi_only_elements() {
4628 return elements_kind() == FAST_SMI_ONLY_ELEMENTS;
4629 }
4630
Steve Block8defd9f2010-07-08 12:39:36 +01004631 // Tells whether the instance has fast elements.
Iain Merrick75681382010-08-19 15:07:18 +01004632 inline bool has_fast_elements() {
Ben Murdoch589d6972011-11-30 16:04:58 +00004633 return elements_kind() == FAST_ELEMENTS;
Leon Clarkee46be812010-01-19 14:06:41 +00004634 }
4635
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004636 inline bool has_fast_double_elements() {
Ben Murdoch589d6972011-11-30 16:04:58 +00004637 return elements_kind() == FAST_DOUBLE_ELEMENTS;
Steve Block1e0659c2011-05-24 12:43:12 +01004638 }
4639
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004640 inline bool has_non_strict_arguments_elements() {
4641 return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4642 }
4643
Steve Block44f0eee2011-05-26 01:26:41 +01004644 inline bool has_external_array_elements() {
Ben Murdoch589d6972011-11-30 16:04:58 +00004645 ElementsKind kind(elements_kind());
4646 return kind >= FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND &&
4647 kind <= LAST_EXTERNAL_ARRAY_ELEMENTS_KIND;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004648 }
4649
4650 inline bool has_dictionary_elements() {
Ben Murdoch589d6972011-11-30 16:04:58 +00004651 return elements_kind() == DICTIONARY_ELEMENTS;
Steve Block1e0659c2011-05-24 12:43:12 +01004652 }
4653
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004654 inline bool has_slow_elements_kind() {
4655 return elements_kind() == DICTIONARY_ELEMENTS
4656 || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4657 }
4658
4659 static bool IsValidElementsTransition(ElementsKind from_kind,
4660 ElementsKind to_kind);
4661
Kristian Monsen0d5e1162010-09-30 15:31:59 +01004662 // Tells whether the map is attached to SharedFunctionInfo
4663 // (for inobject slack tracking).
4664 inline void set_attached_to_shared_function_info(bool value);
4665
4666 inline bool attached_to_shared_function_info();
4667
4668 // Tells whether the map is shared between objects that may have different
4669 // behavior. If true, the map should never be modified, instead a clone
4670 // should be created and modified.
4671 inline void set_is_shared(bool value);
4672
4673 inline bool is_shared();
4674
Steve Blocka7e24c12009-10-30 11:49:00 +00004675 // Tells whether the instance needs security checks when accessing its
4676 // properties.
4677 inline void set_is_access_check_needed(bool access_check_needed);
4678 inline bool is_access_check_needed();
4679
4680 // [prototype]: implicit prototype object.
4681 DECL_ACCESSORS(prototype, Object)
4682
4683 // [constructor]: points back to the function responsible for this map.
4684 DECL_ACCESSORS(constructor, Object)
4685
Kristian Monsen0d5e1162010-09-30 15:31:59 +01004686 inline JSFunction* unchecked_constructor();
4687
Ben Murdoch257744e2011-11-30 15:57:28 +00004688 // Should only be called by the code that initializes map to set initial valid
4689 // value of the instance descriptor member.
4690 inline void init_instance_descriptors();
4691
Steve Blocka7e24c12009-10-30 11:49:00 +00004692 // [instance descriptors]: describes the object.
4693 DECL_ACCESSORS(instance_descriptors, DescriptorArray)
4694
Ben Murdoch257744e2011-11-30 15:57:28 +00004695 // Sets the instance descriptor array for the map to be an empty descriptor
4696 // array.
4697 inline void clear_instance_descriptors();
4698
Steve Blocka7e24c12009-10-30 11:49:00 +00004699 // [stub cache]: contains stubs compiled for this map.
Steve Block6ded16b2010-05-10 14:33:55 +01004700 DECL_ACCESSORS(code_cache, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +00004701
Steve Block053d10c2011-06-13 19:13:29 +01004702 // [prototype transitions]: cache of prototype transitions.
4703 // Prototype transition is a transition that happens
4704 // when we change object's prototype to a new one.
4705 // Cache format:
4706 // 0: finger - index of the first free cell in the cache
4707 // 1 + 2 * i: prototype
4708 // 2 + 2 * i: target map
4709 DECL_ACCESSORS(prototype_transitions, FixedArray)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004710
Steve Block053d10c2011-06-13 19:13:29 +01004711 inline FixedArray* unchecked_prototype_transitions();
4712
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004713 static const int kProtoTransitionHeaderSize = 1;
4714 static const int kProtoTransitionNumberOfEntriesOffset = 0;
4715 static const int kProtoTransitionElementsPerEntry = 2;
4716 static const int kProtoTransitionPrototypeOffset = 0;
4717 static const int kProtoTransitionMapOffset = 1;
4718
4719 inline int NumberOfProtoTransitions() {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004720 FixedArray* cache = prototype_transitions();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004721 if (cache->length() == 0) return 0;
4722 return
4723 Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value();
4724 }
4725
4726 inline void SetNumberOfProtoTransitions(int value) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004727 FixedArray* cache = prototype_transitions();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004728 ASSERT(cache->length() != 0);
4729 cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset,
4730 Smi::FromInt(value));
4731 }
4732
Ben Murdochb0fe1622011-05-05 13:52:32 +01004733 // Lookup in the map's instance descriptors and fill out the result
4734 // with the given holder if the name is found. The holder may be
4735 // NULL when this function is used from the compiler.
4736 void LookupInDescriptors(JSObject* holder,
4737 String* name,
4738 LookupResult* result);
4739
John Reck59135872010-11-02 12:39:01 -07004740 MUST_USE_RESULT MaybeObject* CopyDropDescriptors();
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004741
John Reck59135872010-11-02 12:39:01 -07004742 MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode,
4743 NormalizedMapSharingMode sharing);
Steve Blocka7e24c12009-10-30 11:49:00 +00004744
4745 // Returns a copy of the map, with all transitions dropped from the
4746 // instance descriptors.
John Reck59135872010-11-02 12:39:01 -07004747 MUST_USE_RESULT MaybeObject* CopyDropTransitions();
Steve Blocka7e24c12009-10-30 11:49:00 +00004748
4749 // Returns the property index for name (only valid for FAST MODE).
4750 int PropertyIndexFor(String* name);
4751
4752 // Returns the next free property index (only valid for FAST MODE).
4753 int NextFreePropertyIndex();
4754
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004755 // Returns the number of properties described in instance_descriptors
4756 // filtering out properties with the specified attributes.
4757 int NumberOfDescribedProperties(PropertyAttributes filter = NONE);
Steve Blocka7e24c12009-10-30 11:49:00 +00004758
4759 // Casting.
4760 static inline Map* cast(Object* obj);
4761
4762 // Locate an accessor in the instance descriptor.
4763 AccessorDescriptor* FindAccessor(String* name);
4764
4765 // Code cache operations.
4766
4767 // Clears the code cache.
Steve Block44f0eee2011-05-26 01:26:41 +01004768 inline void ClearCodeCache(Heap* heap);
Steve Blocka7e24c12009-10-30 11:49:00 +00004769
4770 // Update code cache.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004771 static void UpdateCodeCache(Handle<Map> map,
4772 Handle<String> name,
4773 Handle<Code> code);
John Reck59135872010-11-02 12:39:01 -07004774 MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code);
Steve Blocka7e24c12009-10-30 11:49:00 +00004775
4776 // Returns the found code or undefined if absent.
4777 Object* FindInCodeCache(String* name, Code::Flags flags);
4778
4779 // Returns the non-negative index of the code object if it is in the
4780 // cache and -1 otherwise.
Steve Block6ded16b2010-05-10 14:33:55 +01004781 int IndexInCodeCache(Object* name, Code* code);
Steve Blocka7e24c12009-10-30 11:49:00 +00004782
4783 // Removes a code object from the code cache at the given index.
Steve Block6ded16b2010-05-10 14:33:55 +01004784 void RemoveFromCodeCache(String* name, Code* code, int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00004785
4786 // For every transition in this map, makes the transition's
4787 // target's prototype pointer point back to this map.
4788 // This is undone in MarkCompactCollector::ClearNonLiveTransitions().
4789 void CreateBackPointers();
4790
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004791 void CreateOneBackPointer(Object* transition_target);
4792
Steve Blocka7e24c12009-10-30 11:49:00 +00004793 // Set all map transitions from this map to dead maps to null.
4794 // Also, restore the original prototype on the targets of these
4795 // transitions, so that we do not process this map again while
4796 // following back pointers.
Steve Block44f0eee2011-05-26 01:26:41 +01004797 void ClearNonLiveTransitions(Heap* heap, Object* real_prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +00004798
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004799 // Restore a possible back pointer in the prototype field of object.
4800 // Return true in that case and false otherwise. Set *keep_entry to
4801 // true when a live map transition has been found.
4802 bool RestoreOneBackPointer(Object* object,
4803 Object* real_prototype,
4804 bool* keep_entry);
4805
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004806 // Computes a hash value for this map, to be used in HashTables and such.
4807 int Hash();
4808
4809 // Compares this map to another to see if they describe equivalent objects.
4810 // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
4811 // it had exactly zero inobject properties.
4812 // The "shared" flags of both this map and |other| are ignored.
4813 bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
4814
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004815 // Returns the contents of this map's descriptor array for the given string.
4816 // May return NULL. |safe_to_add_transition| is set to false and NULL
4817 // is returned if adding transitions is not allowed.
4818 Object* GetDescriptorContents(String* sentinel_name,
4819 bool* safe_to_add_transitions);
4820
4821 // Returns the map that this map transitions to if its elements_kind
4822 // is changed to |elements_kind|, or NULL if no such map is cached yet.
4823 // |safe_to_add_transitions| is set to false if adding transitions is not
4824 // allowed.
4825 Map* LookupElementsTransitionMap(ElementsKind elements_kind,
4826 bool* safe_to_add_transition);
4827
4828 // Adds an entry to this map's descriptor array for a transition to
4829 // |transitioned_map| when its elements_kind is changed to |elements_kind|.
4830 MUST_USE_RESULT MaybeObject* AddElementsTransition(
4831 ElementsKind elements_kind, Map* transitioned_map);
4832
4833 // Returns the transitioned map for this map with the most generic
4834 // elements_kind that's found in |candidates|, or null handle if no match is
4835 // found at all.
4836 Handle<Map> FindTransitionedMap(MapHandleList* candidates);
4837 Map* FindTransitionedMap(MapList* candidates);
4838
Ben Murdoch592a9fc2012-03-05 11:04:45 +00004839
Steve Blocka7e24c12009-10-30 11:49:00 +00004840 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01004841#ifdef OBJECT_PRINT
4842 inline void MapPrint() {
4843 MapPrint(stdout);
4844 }
4845 void MapPrint(FILE* out);
4846#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00004847#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00004848 void MapVerify();
Kristian Monsen0d5e1162010-09-30 15:31:59 +01004849 void SharedMapVerify();
Steve Blocka7e24c12009-10-30 11:49:00 +00004850#endif
4851
Iain Merrick75681382010-08-19 15:07:18 +01004852 inline int visitor_id();
4853 inline void set_visitor_id(int visitor_id);
Ben Murdoch3bec4d22010-07-22 14:51:16 +01004854
Kristian Monsen0d5e1162010-09-30 15:31:59 +01004855 typedef void (*TraverseCallback)(Map* map, void* data);
4856
4857 void TraverseTransitionTree(TraverseCallback callback, void* data);
4858
Steve Block053d10c2011-06-13 19:13:29 +01004859 static const int kMaxCachedPrototypeTransitions = 256;
4860
4861 Object* GetPrototypeTransition(Object* prototype);
4862
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004863 MUST_USE_RESULT MaybeObject* PutPrototypeTransition(Object* prototype,
4864 Map* map);
Steve Block053d10c2011-06-13 19:13:29 +01004865
Steve Blocka7e24c12009-10-30 11:49:00 +00004866 static const int kMaxPreAllocatedPropertyFields = 255;
4867
4868 // Layout description.
4869 static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
4870 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
4871 static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize;
4872 static const int kConstructorOffset = kPrototypeOffset + kPointerSize;
Ben Murdoch257744e2011-11-30 15:57:28 +00004873 // Storage for instance descriptors is overloaded to also contain additional
4874 // map flags when unused (bit_field3). When the map has instance descriptors,
4875 // the flags are transferred to the instance descriptor array and accessed
4876 // through an extra indirection.
4877 // TODO(1399): It should be possible to make room for bit_field3 in the map
4878 // without overloading the instance descriptors field, but the map is
4879 // currently perfectly aligned to 32 bytes and extending it at all would
4880 // double its size. After the increment GC work lands, this size restriction
4881 // could be loosened and bit_field3 moved directly back in the map.
4882 static const int kInstanceDescriptorsOrBitField3Offset =
Steve Blocka7e24c12009-10-30 11:49:00 +00004883 kConstructorOffset + kPointerSize;
Ben Murdoch257744e2011-11-30 15:57:28 +00004884 static const int kCodeCacheOffset =
4885 kInstanceDescriptorsOrBitField3Offset + kPointerSize;
Steve Block053d10c2011-06-13 19:13:29 +01004886 static const int kPrototypeTransitionsOffset =
4887 kCodeCacheOffset + kPointerSize;
4888 static const int kPadStart = kPrototypeTransitionsOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01004889 static const int kSize = MAP_POINTER_ALIGN(kPadStart);
4890
4891 // Layout of pointer fields. Heap iteration code relies on them
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004892 // being continuously allocated.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01004893 static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset;
4894 static const int kPointerFieldsEndOffset =
Steve Block053d10c2011-06-13 19:13:29 +01004895 Map::kPrototypeTransitionsOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00004896
4897 // Byte offsets within kInstanceSizesOffset.
4898 static const int kInstanceSizeOffset = kInstanceSizesOffset + 0;
4899 static const int kInObjectPropertiesByte = 1;
4900 static const int kInObjectPropertiesOffset =
4901 kInstanceSizesOffset + kInObjectPropertiesByte;
4902 static const int kPreAllocatedPropertyFieldsByte = 2;
4903 static const int kPreAllocatedPropertyFieldsOffset =
4904 kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte;
Iain Merrick9ac36c92010-09-13 15:29:50 +01004905 static const int kVisitorIdByte = 3;
4906 static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte;
Steve Blocka7e24c12009-10-30 11:49:00 +00004907
4908 // Byte offsets within kInstanceAttributesOffset attributes.
4909 static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0;
4910 static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1;
4911 static const int kBitFieldOffset = kInstanceAttributesOffset + 2;
4912 static const int kBitField2Offset = kInstanceAttributesOffset + 3;
4913
4914 STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset);
4915
4916 // Bit positions for bit field.
4917 static const int kUnused = 0; // To be used for marking recently used maps.
4918 static const int kHasNonInstancePrototype = 1;
4919 static const int kIsHiddenPrototype = 2;
4920 static const int kHasNamedInterceptor = 3;
4921 static const int kHasIndexedInterceptor = 4;
4922 static const int kIsUndetectable = 5;
4923 static const int kHasInstanceCallHandler = 6;
4924 static const int kIsAccessCheckNeeded = 7;
4925
4926 // Bit positions for bit field 2
Andrei Popescu31002712010-02-23 13:46:05 +00004927 static const int kIsExtensible = 0;
Steve Block6ded16b2010-05-10 14:33:55 +01004928 static const int kFunctionWithPrototype = 1;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004929 static const int kStringWrapperSafeForDefaultValueOf = 2;
4930 static const int kAttachedToSharedFunctionInfo = 3;
4931 // No bits can be used after kElementsKindFirstBit, they are all reserved for
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004932 // storing ElementKind.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004933 static const int kElementsKindShift = 4;
4934 static const int kElementsKindBitCount = 4;
4935
4936 // Derived values from bit field 2
4937 static const int kElementsKindMask = (-1 << kElementsKindShift) &
4938 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1);
4939 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
Ben Murdoch589d6972011-11-30 16:04:58 +00004940 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004941 static const int8_t kMaximumBitField2FastSmiOnlyElementValue =
4942 static_cast<int8_t>((FAST_SMI_ONLY_ELEMENTS + 1) <<
4943 Map::kElementsKindShift) - 1;
Ben Murdoch257744e2011-11-30 15:57:28 +00004944
4945 // Bit positions for bit field 3
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004946 static const int kIsShared = 0;
Steve Block6ded16b2010-05-10 14:33:55 +01004947
4948 // Layout of the default cache. It holds alternating name and code objects.
4949 static const int kCodeCacheEntrySize = 2;
4950 static const int kCodeCacheEntryNameOffset = 0;
4951 static const int kCodeCacheEntryCodeOffset = 1;
Steve Blocka7e24c12009-10-30 11:49:00 +00004952
Iain Merrick75681382010-08-19 15:07:18 +01004953 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
4954 kPointerFieldsEndOffset,
4955 kSize> BodyDescriptor;
4956
Steve Blocka7e24c12009-10-30 11:49:00 +00004957 private:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004958 String* elements_transition_sentinel_name();
Steve Blocka7e24c12009-10-30 11:49:00 +00004959 DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
4960};
4961
4962
4963// An abstract superclass, a marker class really, for simple structure classes.
Ben Murdoch257744e2011-11-30 15:57:28 +00004964// It doesn't carry much functionality but allows struct classes to be
Steve Blocka7e24c12009-10-30 11:49:00 +00004965// identified in the type system.
4966class Struct: public HeapObject {
4967 public:
4968 inline void InitializeBody(int object_size);
4969 static inline Struct* cast(Object* that);
4970};
4971
4972
4973// Script describes a script which has been added to the VM.
4974class Script: public Struct {
4975 public:
4976 // Script types.
4977 enum Type {
4978 TYPE_NATIVE = 0,
4979 TYPE_EXTENSION = 1,
4980 TYPE_NORMAL = 2
4981 };
4982
4983 // Script compilation types.
4984 enum CompilationType {
4985 COMPILATION_TYPE_HOST = 0,
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08004986 COMPILATION_TYPE_EVAL = 1
Steve Blocka7e24c12009-10-30 11:49:00 +00004987 };
4988
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004989 // Script compilation state.
4990 enum CompilationState {
4991 COMPILATION_STATE_INITIAL = 0,
4992 COMPILATION_STATE_COMPILED = 1
4993 };
4994
Steve Blocka7e24c12009-10-30 11:49:00 +00004995 // [source]: the script source.
4996 DECL_ACCESSORS(source, Object)
4997
4998 // [name]: the script name.
4999 DECL_ACCESSORS(name, Object)
5000
5001 // [id]: the script id.
5002 DECL_ACCESSORS(id, Object)
5003
5004 // [line_offset]: script line offset in resource from where it was extracted.
5005 DECL_ACCESSORS(line_offset, Smi)
5006
5007 // [column_offset]: script column offset in resource from where it was
5008 // extracted.
5009 DECL_ACCESSORS(column_offset, Smi)
5010
5011 // [data]: additional data associated with this script.
5012 DECL_ACCESSORS(data, Object)
5013
5014 // [context_data]: context data for the context this script was compiled in.
5015 DECL_ACCESSORS(context_data, Object)
5016
5017 // [wrapper]: the wrapper cache.
Ben Murdoch257744e2011-11-30 15:57:28 +00005018 DECL_ACCESSORS(wrapper, Foreign)
Steve Blocka7e24c12009-10-30 11:49:00 +00005019
5020 // [type]: the script type.
5021 DECL_ACCESSORS(type, Smi)
5022
5023 // [compilation]: how the the script was compiled.
5024 DECL_ACCESSORS(compilation_type, Smi)
5025
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005026 // [is_compiled]: determines whether the script has already been compiled.
5027 DECL_ACCESSORS(compilation_state, Smi)
5028
Steve Blockd0582a62009-12-15 09:54:21 +00005029 // [line_ends]: FixedArray of line ends positions.
Steve Blocka7e24c12009-10-30 11:49:00 +00005030 DECL_ACCESSORS(line_ends, Object)
5031
Steve Blockd0582a62009-12-15 09:54:21 +00005032 // [eval_from_shared]: for eval scripts the shared funcion info for the
5033 // function from which eval was called.
5034 DECL_ACCESSORS(eval_from_shared, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +00005035
5036 // [eval_from_instructions_offset]: the instruction offset in the code for the
5037 // function from which eval was called where eval was called.
5038 DECL_ACCESSORS(eval_from_instructions_offset, Smi)
5039
5040 static inline Script* cast(Object* obj);
5041
Steve Block3ce2e202009-11-05 08:53:23 +00005042 // If script source is an external string, check that the underlying
5043 // resource is accessible. Otherwise, always return true.
5044 inline bool HasValidSource();
5045
Ben Murdochb0fe1622011-05-05 13:52:32 +01005046#ifdef OBJECT_PRINT
5047 inline void ScriptPrint() {
5048 ScriptPrint(stdout);
5049 }
5050 void ScriptPrint(FILE* out);
5051#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00005052#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00005053 void ScriptVerify();
5054#endif
5055
5056 static const int kSourceOffset = HeapObject::kHeaderSize;
5057 static const int kNameOffset = kSourceOffset + kPointerSize;
5058 static const int kLineOffsetOffset = kNameOffset + kPointerSize;
5059 static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
5060 static const int kDataOffset = kColumnOffsetOffset + kPointerSize;
5061 static const int kContextOffset = kDataOffset + kPointerSize;
5062 static const int kWrapperOffset = kContextOffset + kPointerSize;
5063 static const int kTypeOffset = kWrapperOffset + kPointerSize;
5064 static const int kCompilationTypeOffset = kTypeOffset + kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005065 static const int kCompilationStateOffset =
5066 kCompilationTypeOffset + kPointerSize;
5067 static const int kLineEndsOffset = kCompilationStateOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00005068 static const int kIdOffset = kLineEndsOffset + kPointerSize;
Steve Blockd0582a62009-12-15 09:54:21 +00005069 static const int kEvalFromSharedOffset = kIdOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00005070 static const int kEvalFrominstructionsOffsetOffset =
Steve Blockd0582a62009-12-15 09:54:21 +00005071 kEvalFromSharedOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00005072 static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize;
5073
5074 private:
5075 DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
5076};
5077
5078
Ben Murdochb0fe1622011-05-05 13:52:32 +01005079// List of builtin functions we want to identify to improve code
5080// generation.
5081//
5082// Each entry has a name of a global object property holding an object
5083// optionally followed by ".prototype", a name of a builtin function
5084// on the object (the one the id is set for), and a label.
5085//
5086// Installation of ids for the selected builtin functions is handled
5087// by the bootstrapper.
5088//
5089// NOTE: Order is important: math functions should be at the end of
5090// the list and MathFloor should be the first math function.
5091#define FUNCTIONS_WITH_ID_LIST(V) \
5092 V(Array.prototype, push, ArrayPush) \
5093 V(Array.prototype, pop, ArrayPop) \
Ben Murdoch42effa52011-08-19 16:40:31 +01005094 V(Function.prototype, apply, FunctionApply) \
Ben Murdochb0fe1622011-05-05 13:52:32 +01005095 V(String.prototype, charCodeAt, StringCharCodeAt) \
5096 V(String.prototype, charAt, StringCharAt) \
5097 V(String, fromCharCode, StringFromCharCode) \
5098 V(Math, floor, MathFloor) \
5099 V(Math, round, MathRound) \
5100 V(Math, ceil, MathCeil) \
5101 V(Math, abs, MathAbs) \
5102 V(Math, log, MathLog) \
5103 V(Math, sin, MathSin) \
5104 V(Math, cos, MathCos) \
5105 V(Math, tan, MathTan) \
5106 V(Math, asin, MathASin) \
5107 V(Math, acos, MathACos) \
5108 V(Math, atan, MathATan) \
5109 V(Math, exp, MathExp) \
5110 V(Math, sqrt, MathSqrt) \
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005111 V(Math, pow, MathPow) \
5112 V(Math, random, MathRandom) \
5113 V(Math, max, MathMax) \
5114 V(Math, min, MathMin)
Ben Murdochb0fe1622011-05-05 13:52:32 +01005115
5116
5117enum BuiltinFunctionId {
5118#define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \
5119 k##name,
5120 FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID)
5121#undef DECLARE_FUNCTION_ID
5122 // Fake id for a special case of Math.pow. Note, it continues the
5123 // list of math functions.
5124 kMathPowHalf,
5125 kFirstMathFunctionId = kMathFloor
5126};
5127
5128
Steve Blocka7e24c12009-10-30 11:49:00 +00005129// SharedFunctionInfo describes the JSFunction information that can be
5130// shared by multiple instances of the function.
5131class SharedFunctionInfo: public HeapObject {
5132 public:
5133 // [name]: Function name.
5134 DECL_ACCESSORS(name, Object)
5135
5136 // [code]: Function code.
5137 DECL_ACCESSORS(code, Code)
5138
Ben Murdoch3bec4d22010-07-22 14:51:16 +01005139 // [scope_info]: Scope info.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005140 DECL_ACCESSORS(scope_info, ScopeInfo)
Ben Murdoch3bec4d22010-07-22 14:51:16 +01005141
Steve Blocka7e24c12009-10-30 11:49:00 +00005142 // [construct stub]: Code stub for constructing instances of this function.
5143 DECL_ACCESSORS(construct_stub, Code)
5144
Iain Merrick75681382010-08-19 15:07:18 +01005145 inline Code* unchecked_code();
5146
Steve Blocka7e24c12009-10-30 11:49:00 +00005147 // Returns if this function has been compiled to native code yet.
5148 inline bool is_compiled();
5149
5150 // [length]: The function length - usually the number of declared parameters.
5151 // Use up to 2^30 parameters.
5152 inline int length();
5153 inline void set_length(int value);
5154
5155 // [formal parameter count]: The declared number of parameters.
5156 inline int formal_parameter_count();
5157 inline void set_formal_parameter_count(int value);
5158
5159 // Set the formal parameter count so the function code will be
5160 // called without using argument adaptor frames.
5161 inline void DontAdaptArguments();
5162
5163 // [expected_nof_properties]: Expected number of properties for the function.
5164 inline int expected_nof_properties();
5165 inline void set_expected_nof_properties(int value);
5166
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005167 // Inobject slack tracking is the way to reclaim unused inobject space.
5168 //
5169 // The instance size is initially determined by adding some slack to
5170 // expected_nof_properties (to allow for a few extra properties added
5171 // after the constructor). There is no guarantee that the extra space
5172 // will not be wasted.
5173 //
5174 // Here is the algorithm to reclaim the unused inobject space:
5175 // - Detect the first constructor call for this SharedFunctionInfo.
5176 // When it happens enter the "in progress" state: remember the
5177 // constructor's initial_map and install a special construct stub that
5178 // counts constructor calls.
5179 // - While the tracking is in progress create objects filled with
5180 // one_pointer_filler_map instead of undefined_value. This way they can be
5181 // resized quickly and safely.
5182 // - Once enough (kGenerousAllocationCount) objects have been created
5183 // compute the 'slack' (traverse the map transition tree starting from the
5184 // initial_map and find the lowest value of unused_property_fields).
5185 // - Traverse the transition tree again and decrease the instance size
5186 // of every map. Existing objects will resize automatically (they are
5187 // filled with one_pointer_filler_map). All further allocations will
5188 // use the adjusted instance size.
5189 // - Decrease expected_nof_properties so that an allocations made from
5190 // another context will use the adjusted instance size too.
5191 // - Exit "in progress" state by clearing the reference to the initial_map
5192 // and setting the regular construct stub (generic or inline).
5193 //
5194 // The above is the main event sequence. Some special cases are possible
5195 // while the tracking is in progress:
5196 //
5197 // - GC occurs.
5198 // Check if the initial_map is referenced by any live objects (except this
5199 // SharedFunctionInfo). If it is, continue tracking as usual.
5200 // If it is not, clear the reference and reset the tracking state. The
5201 // tracking will be initiated again on the next constructor call.
5202 //
5203 // - The constructor is called from another context.
5204 // Immediately complete the tracking, perform all the necessary changes
5205 // to maps. This is necessary because there is no efficient way to track
5206 // multiple initial_maps.
5207 // Proceed to create an object in the current context (with the adjusted
5208 // size).
5209 //
5210 // - A different constructor function sharing the same SharedFunctionInfo is
5211 // called in the same context. This could be another closure in the same
5212 // context, or the first function could have been disposed.
5213 // This is handled the same way as the previous case.
5214 //
5215 // Important: inobject slack tracking is not attempted during the snapshot
5216 // creation.
5217
Ben Murdochf87a2032010-10-22 12:50:53 +01005218 static const int kGenerousAllocationCount = 8;
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005219
5220 // [construction_count]: Counter for constructor calls made during
5221 // the tracking phase.
5222 inline int construction_count();
5223 inline void set_construction_count(int value);
5224
5225 // [initial_map]: initial map of the first function called as a constructor.
5226 // Saved for the duration of the tracking phase.
5227 // This is a weak link (GC resets it to undefined_value if no other live
5228 // object reference this map).
5229 DECL_ACCESSORS(initial_map, Object)
5230
5231 // True if the initial_map is not undefined and the countdown stub is
5232 // installed.
5233 inline bool IsInobjectSlackTrackingInProgress();
5234
5235 // Starts the tracking.
5236 // Stores the initial map and installs the countdown stub.
5237 // IsInobjectSlackTrackingInProgress is normally true after this call,
5238 // except when tracking have not been started (e.g. the map has no unused
5239 // properties or the snapshot is being built).
5240 void StartInobjectSlackTracking(Map* map);
5241
5242 // Completes the tracking.
5243 // IsInobjectSlackTrackingInProgress is false after this call.
5244 void CompleteInobjectSlackTracking();
5245
5246 // Clears the initial_map before the GC marking phase to ensure the reference
5247 // is weak. IsInobjectSlackTrackingInProgress is false after this call.
5248 void DetachInitialMap();
5249
5250 // Restores the link to the initial map after the GC marking phase.
5251 // IsInobjectSlackTrackingInProgress is true after this call.
5252 void AttachInitialMap(Map* map);
5253
5254 // False if there are definitely no live objects created from this function.
5255 // True if live objects _may_ exist (existence not guaranteed).
5256 // May go back from true to false after GC.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005257 DECL_BOOLEAN_ACCESSORS(live_objects_may_exist)
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005258
Steve Blocka7e24c12009-10-30 11:49:00 +00005259 // [instance class name]: class name for instances.
5260 DECL_ACCESSORS(instance_class_name, Object)
5261
Steve Block6ded16b2010-05-10 14:33:55 +01005262 // [function data]: This field holds some additional data for function.
5263 // Currently it either has FunctionTemplateInfo to make benefit the API
Ben Murdochb0fe1622011-05-05 13:52:32 +01005264 // or Smi identifying a builtin function.
Steve Blocka7e24c12009-10-30 11:49:00 +00005265 // In the long run we don't want all functions to have this field but
5266 // we can fix that when we have a better model for storing hidden data
5267 // on objects.
5268 DECL_ACCESSORS(function_data, Object)
5269
Steve Block6ded16b2010-05-10 14:33:55 +01005270 inline bool IsApiFunction();
5271 inline FunctionTemplateInfo* get_api_func_data();
Ben Murdochb0fe1622011-05-05 13:52:32 +01005272 inline bool HasBuiltinFunctionId();
Ben Murdochb0fe1622011-05-05 13:52:32 +01005273 inline BuiltinFunctionId builtin_function_id();
Steve Block6ded16b2010-05-10 14:33:55 +01005274
Steve Blocka7e24c12009-10-30 11:49:00 +00005275 // [script info]: Script from which the function originates.
5276 DECL_ACCESSORS(script, Object)
5277
Steve Block6ded16b2010-05-10 14:33:55 +01005278 // [num_literals]: Number of literals used by this function.
5279 inline int num_literals();
5280 inline void set_num_literals(int value);
5281
Steve Blocka7e24c12009-10-30 11:49:00 +00005282 // [start_position_and_type]: Field used to store both the source code
5283 // position, whether or not the function is a function expression,
5284 // and whether or not the function is a toplevel function. The two
5285 // least significants bit indicates whether the function is an
5286 // expression and the rest contains the source code position.
5287 inline int start_position_and_type();
5288 inline void set_start_position_and_type(int value);
5289
5290 // [debug info]: Debug information.
5291 DECL_ACCESSORS(debug_info, Object)
5292
5293 // [inferred name]: Name inferred from variable or property
5294 // assignment of this function. Used to facilitate debugging and
5295 // profiling of JavaScript code written in OO style, where almost
5296 // all functions are anonymous but are assigned to object
5297 // properties.
5298 DECL_ACCESSORS(inferred_name, String)
5299
Ben Murdochf87a2032010-10-22 12:50:53 +01005300 // The function's name if it is non-empty, otherwise the inferred name.
5301 String* DebugName();
5302
Steve Blocka7e24c12009-10-30 11:49:00 +00005303 // Position of the 'function' token in the script source.
5304 inline int function_token_position();
5305 inline void set_function_token_position(int function_token_position);
5306
5307 // Position of this function in the script source.
5308 inline int start_position();
5309 inline void set_start_position(int start_position);
5310
5311 // End position of this function in the script source.
5312 inline int end_position();
5313 inline void set_end_position(int end_position);
5314
5315 // Is this function a function expression in the source code.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005316 DECL_BOOLEAN_ACCESSORS(is_expression)
Steve Blocka7e24c12009-10-30 11:49:00 +00005317
5318 // Is this function a top-level function (scripts, evals).
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005319 DECL_BOOLEAN_ACCESSORS(is_toplevel)
Steve Blocka7e24c12009-10-30 11:49:00 +00005320
5321 // Bit field containing various information collected by the compiler to
5322 // drive optimization.
5323 inline int compiler_hints();
5324 inline void set_compiler_hints(int value);
5325
Ben Murdochb0fe1622011-05-05 13:52:32 +01005326 // A counter used to determine when to stress the deoptimizer with a
5327 // deopt.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005328 inline int deopt_counter();
5329 inline void set_deopt_counter(int counter);
5330
5331 inline int profiler_ticks();
5332 inline void set_profiler_ticks(int ticks);
5333
5334 inline int ast_node_count();
5335 inline void set_ast_node_count(int count);
Ben Murdochb0fe1622011-05-05 13:52:32 +01005336
Steve Blocka7e24c12009-10-30 11:49:00 +00005337 // Add information on assignments of the form this.x = ...;
5338 void SetThisPropertyAssignmentsInfo(
Steve Blocka7e24c12009-10-30 11:49:00 +00005339 bool has_only_simple_this_property_assignments,
5340 FixedArray* this_property_assignments);
5341
5342 // Clear information on assignments of the form this.x = ...;
5343 void ClearThisPropertyAssignmentsInfo();
5344
5345 // Indicate that this function only consists of assignments of the form
Steve Blocka7e24c12009-10-30 11:49:00 +00005346 // this.x = y; where y is either a constant or refers to an argument.
5347 inline bool has_only_simple_this_property_assignments();
5348
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005349 // Indicates if this function can be lazy compiled.
5350 // This is used to determine if we can safely flush code from a function
5351 // when doing GC if we expect that the function will no longer be used.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005352 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation)
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005353
Iain Merrick75681382010-08-19 15:07:18 +01005354 // Indicates how many full GCs this function has survived with assigned
5355 // code object. Used to determine when it is relatively safe to flush
5356 // this code object and replace it with lazy compilation stub.
5357 // Age is reset when GC notices that the code object is referenced
5358 // from the stack or compilation cache.
5359 inline int code_age();
5360 inline void set_code_age(int age);
5361
Ben Murdochb0fe1622011-05-05 13:52:32 +01005362 // Indicates whether optimizations have been disabled for this
5363 // shared function info. If a function is repeatedly optimized or if
5364 // we cannot optimize the function we disable optimization to avoid
5365 // spending time attempting to optimize it again.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005366 DECL_BOOLEAN_ACCESSORS(optimization_disabled)
Ben Murdochb0fe1622011-05-05 13:52:32 +01005367
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005368 // Indicates the language mode of the function's code as defined by the
5369 // current harmony drafts for the next ES language standard. Possible
5370 // values are:
5371 // 1. CLASSIC_MODE - Unrestricted syntax and semantics, same as in ES5.
5372 // 2. STRICT_MODE - Restricted syntax and semantics, same as in ES5.
5373 // 3. EXTENDED_MODE - Only available under the harmony flag, not part of ES5.
5374 inline LanguageMode language_mode();
5375 inline void set_language_mode(LanguageMode language_mode);
5376
5377 // Indicates whether the language mode of this function is CLASSIC_MODE.
5378 inline bool is_classic_mode();
5379
5380 // Indicates whether the language mode of this function is EXTENDED_MODE.
5381 inline bool is_extended_mode();
Steve Block1e0659c2011-05-24 12:43:12 +01005382
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005383 // False if the function definitely does not allocate an arguments object.
5384 DECL_BOOLEAN_ACCESSORS(uses_arguments)
5385
5386 // True if the function has any duplicated parameter names.
5387 DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
5388
5389 // Indicates whether the function is a native function.
Ben Murdoch589d6972011-11-30 16:04:58 +00005390 // These needs special treatment in .call and .apply since
Ben Murdoch257744e2011-11-30 15:57:28 +00005391 // null passed as the receiver should not be translated to the
5392 // global object.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005393 DECL_BOOLEAN_ACCESSORS(native)
5394
5395 // Indicates that the function was created by the Function function.
5396 // Though it's anonymous, toString should treat it as if it had the name
5397 // "anonymous". We don't set the name itself so that the system does not
5398 // see a binding for it.
5399 DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous)
5400
5401 // Indicates whether the function is a bound function created using
5402 // the bind function.
5403 DECL_BOOLEAN_ACCESSORS(bound)
5404
5405 // Indicates that the function is anonymous (the name field can be set
5406 // through the API, which does not change this flag).
5407 DECL_BOOLEAN_ACCESSORS(is_anonymous)
Ben Murdoch257744e2011-11-30 15:57:28 +00005408
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005409 // Is this a function or top-level/eval code.
5410 DECL_BOOLEAN_ACCESSORS(is_function)
5411
5412 // Indicates that the function cannot be optimized.
5413 DECL_BOOLEAN_ACCESSORS(dont_optimize)
5414
5415 // Indicates that the function cannot be inlined.
5416 DECL_BOOLEAN_ACCESSORS(dont_inline)
5417
Ben Murdochb0fe1622011-05-05 13:52:32 +01005418 // Indicates whether or not the code in the shared function support
5419 // deoptimization.
5420 inline bool has_deoptimization_support();
5421
5422 // Enable deoptimization support through recompiled code.
5423 void EnableDeoptimizationSupport(Code* recompiled);
5424
Ben Murdoch257744e2011-11-30 15:57:28 +00005425 // Disable (further) attempted optimization of all functions sharing this
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005426 // shared function info.
5427 void DisableOptimization();
Ben Murdoch257744e2011-11-30 15:57:28 +00005428
Ben Murdochb0fe1622011-05-05 13:52:32 +01005429 // Lookup the bailout ID and ASSERT that it exists in the non-optimized
5430 // code, returns whether it asserted (i.e., always true if assertions are
5431 // disabled).
5432 bool VerifyBailoutId(int id);
Iain Merrick75681382010-08-19 15:07:18 +01005433
Andrei Popescu402d9372010-02-26 13:31:12 +00005434 // Check whether a inlined constructor can be generated with the given
5435 // prototype.
5436 bool CanGenerateInlineConstructor(Object* prototype);
5437
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005438 // Prevents further attempts to generate inline constructors.
5439 // To be called if generation failed for any reason.
5440 void ForbidInlineConstructor();
5441
Steve Blocka7e24c12009-10-30 11:49:00 +00005442 // For functions which only contains this property assignments this provides
5443 // access to the names for the properties assigned.
5444 DECL_ACCESSORS(this_property_assignments, Object)
5445 inline int this_property_assignments_count();
5446 inline void set_this_property_assignments_count(int value);
5447 String* GetThisPropertyAssignmentName(int index);
5448 bool IsThisPropertyAssignmentArgument(int index);
5449 int GetThisPropertyAssignmentArgument(int index);
5450 Object* GetThisPropertyAssignmentConstant(int index);
5451
5452 // [source code]: Source code for the function.
5453 bool HasSourceCode();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005454 Handle<Object> GetSourceCode();
Steve Blocka7e24c12009-10-30 11:49:00 +00005455
Ben Murdochb0fe1622011-05-05 13:52:32 +01005456 inline int opt_count();
5457 inline void set_opt_count(int opt_count);
5458
5459 // Source size of this function.
5460 int SourceSize();
5461
Steve Blocka7e24c12009-10-30 11:49:00 +00005462 // Calculate the instance size.
5463 int CalculateInstanceSize();
5464
5465 // Calculate the number of in-object properties.
5466 int CalculateInObjectProperties();
5467
5468 // Dispatched behavior.
Steve Blocka7e24c12009-10-30 11:49:00 +00005469 // Set max_length to -1 for unlimited length.
5470 void SourceCodePrint(StringStream* accumulator, int max_length);
Ben Murdochb0fe1622011-05-05 13:52:32 +01005471#ifdef OBJECT_PRINT
5472 inline void SharedFunctionInfoPrint() {
5473 SharedFunctionInfoPrint(stdout);
5474 }
5475 void SharedFunctionInfoPrint(FILE* out);
5476#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00005477#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00005478 void SharedFunctionInfoVerify();
5479#endif
5480
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005481 // Helpers to compile the shared code. Returns true on success, false on
5482 // failure (e.g., stack overflow during compilation).
5483 static bool EnsureCompiled(Handle<SharedFunctionInfo> shared,
5484 ClearExceptionFlag flag);
5485 static bool CompileLazy(Handle<SharedFunctionInfo> shared,
5486 ClearExceptionFlag flag);
5487
Steve Blocka7e24c12009-10-30 11:49:00 +00005488 // Casting.
5489 static inline SharedFunctionInfo* cast(Object* obj);
5490
5491 // Constants.
5492 static const int kDontAdaptArgumentsSentinel = -1;
5493
5494 // Layout description.
Steve Block6ded16b2010-05-10 14:33:55 +01005495 // Pointer fields.
Steve Blocka7e24c12009-10-30 11:49:00 +00005496 static const int kNameOffset = HeapObject::kHeaderSize;
5497 static const int kCodeOffset = kNameOffset + kPointerSize;
Ben Murdoch3bec4d22010-07-22 14:51:16 +01005498 static const int kScopeInfoOffset = kCodeOffset + kPointerSize;
5499 static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize;
Steve Block6ded16b2010-05-10 14:33:55 +01005500 static const int kInstanceClassNameOffset =
5501 kConstructStubOffset + kPointerSize;
5502 static const int kFunctionDataOffset =
5503 kInstanceClassNameOffset + kPointerSize;
5504 static const int kScriptOffset = kFunctionDataOffset + kPointerSize;
5505 static const int kDebugInfoOffset = kScriptOffset + kPointerSize;
5506 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize;
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005507 static const int kInitialMapOffset =
Steve Block6ded16b2010-05-10 14:33:55 +01005508 kInferredNameOffset + kPointerSize;
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005509 static const int kThisPropertyAssignmentsOffset =
5510 kInitialMapOffset + kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005511 static const int kProfilerTicksOffset =
Ben Murdochb0fe1622011-05-05 13:52:32 +01005512 kThisPropertyAssignmentsOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005513#if V8_HOST_ARCH_32_BIT
5514 // Smi fields.
Steve Block6ded16b2010-05-10 14:33:55 +01005515 static const int kLengthOffset =
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005516 kProfilerTicksOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005517 static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize;
5518 static const int kExpectedNofPropertiesOffset =
5519 kFormalParameterCountOffset + kPointerSize;
5520 static const int kNumLiteralsOffset =
5521 kExpectedNofPropertiesOffset + kPointerSize;
5522 static const int kStartPositionAndTypeOffset =
5523 kNumLiteralsOffset + kPointerSize;
5524 static const int kEndPositionOffset =
5525 kStartPositionAndTypeOffset + kPointerSize;
5526 static const int kFunctionTokenPositionOffset =
5527 kEndPositionOffset + kPointerSize;
5528 static const int kCompilerHintsOffset =
5529 kFunctionTokenPositionOffset + kPointerSize;
5530 static const int kThisPropertyAssignmentsCountOffset =
5531 kCompilerHintsOffset + kPointerSize;
Ben Murdochb0fe1622011-05-05 13:52:32 +01005532 static const int kOptCountOffset =
5533 kThisPropertyAssignmentsCountOffset + kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005534 static const int kAstNodeCountOffset = kOptCountOffset + kPointerSize;
5535 static const int kDeoptCounterOffset =
5536 kAstNodeCountOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005537 // Total size.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005538 static const int kSize = kDeoptCounterOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005539#else
5540 // The only reason to use smi fields instead of int fields
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005541 // is to allow iteration without maps decoding during
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005542 // garbage collections.
5543 // To avoid wasting space on 64-bit architectures we use
5544 // the following trick: we group integer fields into pairs
5545 // First integer in each pair is shifted left by 1.
5546 // By doing this we guarantee that LSB of each kPointerSize aligned
5547 // word is not set and thus this word cannot be treated as pointer
5548 // to HeapObject during old space traversal.
5549 static const int kLengthOffset =
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005550 kProfilerTicksOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005551 static const int kFormalParameterCountOffset =
5552 kLengthOffset + kIntSize;
5553
Steve Blocka7e24c12009-10-30 11:49:00 +00005554 static const int kExpectedNofPropertiesOffset =
5555 kFormalParameterCountOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005556 static const int kNumLiteralsOffset =
5557 kExpectedNofPropertiesOffset + kIntSize;
5558
5559 static const int kEndPositionOffset =
Steve Block6ded16b2010-05-10 14:33:55 +01005560 kNumLiteralsOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005561 static const int kStartPositionAndTypeOffset =
5562 kEndPositionOffset + kIntSize;
5563
5564 static const int kFunctionTokenPositionOffset =
5565 kStartPositionAndTypeOffset + kIntSize;
Steve Block6ded16b2010-05-10 14:33:55 +01005566 static const int kCompilerHintsOffset =
Steve Blocka7e24c12009-10-30 11:49:00 +00005567 kFunctionTokenPositionOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005568
Steve Blocka7e24c12009-10-30 11:49:00 +00005569 static const int kThisPropertyAssignmentsCountOffset =
Steve Block6ded16b2010-05-10 14:33:55 +01005570 kCompilerHintsOffset + kIntSize;
Ben Murdochb0fe1622011-05-05 13:52:32 +01005571 static const int kOptCountOffset =
5572 kThisPropertyAssignmentsCountOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005573
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005574 static const int kAstNodeCountOffset = kOptCountOffset + kIntSize;
5575 static const int kDeoptCounterOffset = kAstNodeCountOffset + kIntSize;
5576
Steve Block6ded16b2010-05-10 14:33:55 +01005577 // Total size.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005578 static const int kSize = kDeoptCounterOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01005579
5580#endif
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005581
5582 // The construction counter for inobject slack tracking is stored in the
5583 // most significant byte of compiler_hints which is otherwise unused.
5584 // Its offset depends on the endian-ness of the architecture.
5585#if __BYTE_ORDER == __LITTLE_ENDIAN
5586 static const int kConstructionCountOffset = kCompilerHintsOffset + 3;
5587#elif __BYTE_ORDER == __BIG_ENDIAN
5588 static const int kConstructionCountOffset = kCompilerHintsOffset + 0;
5589#else
5590#error Unknown byte ordering
5591#endif
5592
Steve Block6ded16b2010-05-10 14:33:55 +01005593 static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00005594
Iain Merrick75681382010-08-19 15:07:18 +01005595 typedef FixedBodyDescriptor<kNameOffset,
5596 kThisPropertyAssignmentsOffset + kPointerSize,
5597 kSize> BodyDescriptor;
5598
Steve Blocka7e24c12009-10-30 11:49:00 +00005599 // Bit positions in start_position_and_type.
5600 // The source code start position is in the 30 most significant bits of
5601 // the start_position_and_type field.
5602 static const int kIsExpressionBit = 0;
5603 static const int kIsTopLevelBit = 1;
5604 static const int kStartPositionShift = 2;
5605 static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
5606
5607 // Bit positions in compiler_hints.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005608 static const int kCodeAgeSize = 3;
5609 static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1;
5610
5611 enum CompilerHints {
5612 kHasOnlySimpleThisPropertyAssignments,
5613 kAllowLazyCompilation,
5614 kLiveObjectsMayExist,
5615 kCodeAgeShift,
5616 kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize,
5617 kStrictModeFunction,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005618 kExtendedModeFunction,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005619 kUsesArguments,
5620 kHasDuplicateParameters,
5621 kNative,
5622 kBoundFunction,
5623 kIsAnonymous,
5624 kNameShouldPrintAsAnonymous,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005625 kIsFunction,
5626 kDontOptimize,
5627 kDontInline,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005628 kCompilerHintsCount // Pseudo entry
5629 };
Steve Blocka7e24c12009-10-30 11:49:00 +00005630
Ben Murdoche0cee9b2011-05-25 10:26:03 +01005631 private:
5632#if V8_HOST_ARCH_32_BIT
5633 // On 32 bit platforms, compiler hints is a smi.
5634 static const int kCompilerHintsSmiTagSize = kSmiTagSize;
5635 static const int kCompilerHintsSize = kPointerSize;
5636#else
5637 // On 64 bit platforms, compiler hints is not a smi, see comment above.
5638 static const int kCompilerHintsSmiTagSize = 0;
5639 static const int kCompilerHintsSize = kIntSize;
5640#endif
5641
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005642 STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <=
5643 SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte);
5644
Ben Murdoche0cee9b2011-05-25 10:26:03 +01005645 public:
Ben Murdoch257744e2011-11-30 15:57:28 +00005646 // Constants for optimizing codegen for strict mode function and
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005647 // native tests.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005648 // Allows to use byte-width instructions.
Ben Murdoche0cee9b2011-05-25 10:26:03 +01005649 static const int kStrictModeBitWithinByte =
5650 (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
5651
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005652 static const int kExtendedModeBitWithinByte =
5653 (kExtendedModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
5654
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005655 static const int kNativeBitWithinByte =
5656 (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte;
Ben Murdoch257744e2011-11-30 15:57:28 +00005657
Ben Murdoche0cee9b2011-05-25 10:26:03 +01005658#if __BYTE_ORDER == __LITTLE_ENDIAN
5659 static const int kStrictModeByteOffset = kCompilerHintsOffset +
Ben Murdoch257744e2011-11-30 15:57:28 +00005660 (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005661 static const int kExtendedModeByteOffset = kCompilerHintsOffset +
5662 (kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005663 static const int kNativeByteOffset = kCompilerHintsOffset +
5664 (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01005665#elif __BYTE_ORDER == __BIG_ENDIAN
5666 static const int kStrictModeByteOffset = kCompilerHintsOffset +
Ben Murdoch257744e2011-11-30 15:57:28 +00005667 (kCompilerHintsSize - 1) -
5668 ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005669 static const int kExtendedModeByteOffset = kCompilerHintsOffset +
5670 (kCompilerHintsSize - 1) -
5671 ((kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005672 static const int kNativeByteOffset = kCompilerHintsOffset +
Ben Murdoch257744e2011-11-30 15:57:28 +00005673 (kCompilerHintsSize - 1) -
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005674 ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01005675#else
5676#error Unknown byte ordering
5677#endif
5678
5679 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00005680 DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo);
5681};
5682
5683
5684// JSFunction describes JavaScript functions.
5685class JSFunction: public JSObject {
5686 public:
5687 // [prototype_or_initial_map]:
5688 DECL_ACCESSORS(prototype_or_initial_map, Object)
5689
Ben Murdoch589d6972011-11-30 16:04:58 +00005690 // [shared]: The information about the function that
Steve Blocka7e24c12009-10-30 11:49:00 +00005691 // can be shared by instances.
5692 DECL_ACCESSORS(shared, SharedFunctionInfo)
5693
Iain Merrick75681382010-08-19 15:07:18 +01005694 inline SharedFunctionInfo* unchecked_shared();
5695
Steve Blocka7e24c12009-10-30 11:49:00 +00005696 // [context]: The context for this function.
5697 inline Context* context();
5698 inline Object* unchecked_context();
5699 inline void set_context(Object* context);
5700
5701 // [code]: The generated code object for this function. Executed
5702 // when the function is invoked, e.g. foo() or new foo(). See
5703 // [[Call]] and [[Construct]] description in ECMA-262, section
5704 // 8.6.2, page 27.
5705 inline Code* code();
Ben Murdochb0fe1622011-05-05 13:52:32 +01005706 inline void set_code(Code* code);
5707 inline void ReplaceCode(Code* code);
Steve Blocka7e24c12009-10-30 11:49:00 +00005708
Iain Merrick75681382010-08-19 15:07:18 +01005709 inline Code* unchecked_code();
5710
Steve Blocka7e24c12009-10-30 11:49:00 +00005711 // Tells whether this function is builtin.
5712 inline bool IsBuiltin();
5713
Ben Murdochb0fe1622011-05-05 13:52:32 +01005714 // Tells whether or not the function needs arguments adaption.
5715 inline bool NeedsArgumentsAdaption();
5716
5717 // Tells whether or not this function has been optimized.
5718 inline bool IsOptimized();
5719
Ben Murdoch8b112d22011-06-08 16:22:53 +01005720 // Tells whether or not this function can be optimized.
5721 inline bool IsOptimizable();
5722
Ben Murdochb0fe1622011-05-05 13:52:32 +01005723 // Mark this function for lazy recompilation. The function will be
5724 // recompiled the next time it is executed.
5725 void MarkForLazyRecompilation();
5726
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005727 // Helpers to compile this function. Returns true on success, false on
5728 // failure (e.g., stack overflow during compilation).
5729 static bool CompileLazy(Handle<JSFunction> function,
5730 ClearExceptionFlag flag);
5731 static bool CompileOptimized(Handle<JSFunction> function,
5732 int osr_ast_id,
5733 ClearExceptionFlag flag);
5734
Ben Murdochb0fe1622011-05-05 13:52:32 +01005735 // Tells whether or not the function is already marked for lazy
5736 // recompilation.
5737 inline bool IsMarkedForLazyRecompilation();
5738
Ben Murdochb0fe1622011-05-05 13:52:32 +01005739 // Check whether or not this function is inlineable.
5740 bool IsInlineable();
5741
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005742 // [literals_or_bindings]: Fixed array holding either
5743 // the materialized literals or the bindings of a bound function.
Steve Blocka7e24c12009-10-30 11:49:00 +00005744 //
5745 // If the function contains object, regexp or array literals, the
5746 // literals array prefix contains the object, regexp, and array
5747 // function to be used when creating these literals. This is
5748 // necessary so that we do not dynamically lookup the object, regexp
5749 // or array functions. Performing a dynamic lookup, we might end up
5750 // using the functions from a new context that we should not have
5751 // access to.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005752 //
5753 // On bound functions, the array is a (copy-on-write) fixed-array containing
5754 // the function that was bound, bound this-value and any bound
5755 // arguments. Bound functions never contain literals.
5756 DECL_ACCESSORS(literals_or_bindings, FixedArray)
5757
5758 inline FixedArray* literals();
5759 inline void set_literals(FixedArray* literals);
5760
5761 inline FixedArray* function_bindings();
5762 inline void set_function_bindings(FixedArray* bindings);
Steve Blocka7e24c12009-10-30 11:49:00 +00005763
5764 // The initial map for an object created by this constructor.
5765 inline Map* initial_map();
5766 inline void set_initial_map(Map* value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005767 MUST_USE_RESULT inline MaybeObject* set_initial_map_and_cache_transitions(
5768 Map* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00005769 inline bool has_initial_map();
5770
5771 // Get and set the prototype property on a JSFunction. If the
5772 // function has an initial map the prototype is set on the initial
5773 // map. Otherwise, the prototype is put in the initial map field
5774 // until an initial map is needed.
5775 inline bool has_prototype();
5776 inline bool has_instance_prototype();
5777 inline Object* prototype();
5778 inline Object* instance_prototype();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005779 MUST_USE_RESULT MaybeObject* SetInstancePrototype(Object* value);
John Reck59135872010-11-02 12:39:01 -07005780 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00005781
Steve Block6ded16b2010-05-10 14:33:55 +01005782 // After prototype is removed, it will not be created when accessed, and
5783 // [[Construct]] from this function will not be allowed.
5784 Object* RemovePrototype();
5785 inline bool should_have_prototype();
5786
Steve Blocka7e24c12009-10-30 11:49:00 +00005787 // Accessor for this function's initial map's [[class]]
5788 // property. This is primarily used by ECMA native functions. This
5789 // method sets the class_name field of this function's initial map
5790 // to a given value. It creates an initial map if this function does
5791 // not have one. Note that this method does not copy the initial map
5792 // if it has one already, but simply replaces it with the new value.
5793 // Instances created afterwards will have a map whose [[class]] is
5794 // set to 'value', but there is no guarantees on instances created
5795 // before.
5796 Object* SetInstanceClassName(String* name);
5797
5798 // Returns if this function has been compiled to native code yet.
5799 inline bool is_compiled();
5800
Ben Murdochb0fe1622011-05-05 13:52:32 +01005801 // [next_function_link]: Field for linking functions. This list is treated as
5802 // a weak list by the GC.
5803 DECL_ACCESSORS(next_function_link, Object)
5804
5805 // Prints the name of the function using PrintF.
5806 inline void PrintName() {
5807 PrintName(stdout);
5808 }
5809 void PrintName(FILE* out);
5810
Steve Blocka7e24c12009-10-30 11:49:00 +00005811 // Casting.
5812 static inline JSFunction* cast(Object* obj);
5813
Steve Block791712a2010-08-27 10:21:07 +01005814 // Iterates the objects, including code objects indirectly referenced
5815 // through pointers to the first instruction in the code object.
5816 void JSFunctionIterateBody(int object_size, ObjectVisitor* v);
5817
Steve Blocka7e24c12009-10-30 11:49:00 +00005818 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01005819#ifdef OBJECT_PRINT
5820 inline void JSFunctionPrint() {
5821 JSFunctionPrint(stdout);
5822 }
5823 void JSFunctionPrint(FILE* out);
5824#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00005825#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00005826 void JSFunctionVerify();
5827#endif
5828
5829 // Returns the number of allocated literals.
5830 inline int NumberOfLiterals();
5831
5832 // Retrieve the global context from a function's literal array.
5833 static Context* GlobalContextFromLiterals(FixedArray* literals);
5834
Ben Murdochb0fe1622011-05-05 13:52:32 +01005835 // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to
5836 // kSize) is weak and has special handling during garbage collection.
Steve Block791712a2010-08-27 10:21:07 +01005837 static const int kCodeEntryOffset = JSObject::kHeaderSize;
Iain Merrick75681382010-08-19 15:07:18 +01005838 static const int kPrototypeOrInitialMapOffset =
Steve Block791712a2010-08-27 10:21:07 +01005839 kCodeEntryOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00005840 static const int kSharedFunctionInfoOffset =
5841 kPrototypeOrInitialMapOffset + kPointerSize;
5842 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
5843 static const int kLiteralsOffset = kContextOffset + kPointerSize;
Ben Murdochb0fe1622011-05-05 13:52:32 +01005844 static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize;
5845 static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset;
5846 static const int kSize = kNextFunctionLinkOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00005847
5848 // Layout of the literals array.
5849 static const int kLiteralsPrefixSize = 1;
5850 static const int kLiteralGlobalContextIndex = 0;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005851
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005852 // Layout of the bound-function binding array.
5853 static const int kBoundFunctionIndex = 0;
5854 static const int kBoundThisIndex = 1;
5855 static const int kBoundArgumentsStartIndex = 2;
5856
Steve Blocka7e24c12009-10-30 11:49:00 +00005857 private:
5858 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
5859};
5860
5861
5862// JSGlobalProxy's prototype must be a JSGlobalObject or null,
5863// and the prototype is hidden. JSGlobalProxy always delegates
5864// property accesses to its prototype if the prototype is not null.
5865//
5866// A JSGlobalProxy can be reinitialized which will preserve its identity.
5867//
5868// Accessing a JSGlobalProxy requires security check.
5869
5870class JSGlobalProxy : public JSObject {
5871 public:
Ben Murdoch257744e2011-11-30 15:57:28 +00005872 // [context]: the owner global context of this global proxy object.
Steve Blocka7e24c12009-10-30 11:49:00 +00005873 // It is null value if this object is not used by any context.
5874 DECL_ACCESSORS(context, Object)
5875
5876 // Casting.
5877 static inline JSGlobalProxy* cast(Object* obj);
5878
5879 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01005880#ifdef OBJECT_PRINT
5881 inline void JSGlobalProxyPrint() {
5882 JSGlobalProxyPrint(stdout);
5883 }
5884 void JSGlobalProxyPrint(FILE* out);
5885#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00005886#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00005887 void JSGlobalProxyVerify();
5888#endif
5889
5890 // Layout description.
5891 static const int kContextOffset = JSObject::kHeaderSize;
5892 static const int kSize = kContextOffset + kPointerSize;
5893
5894 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00005895 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
5896};
5897
5898
5899// Forward declaration.
5900class JSBuiltinsObject;
5901
5902// Common super class for JavaScript global objects and the special
5903// builtins global objects.
5904class GlobalObject: public JSObject {
5905 public:
5906 // [builtins]: the object holding the runtime routines written in JS.
5907 DECL_ACCESSORS(builtins, JSBuiltinsObject)
5908
5909 // [global context]: the global context corresponding to this global object.
5910 DECL_ACCESSORS(global_context, Context)
5911
5912 // [global receiver]: the global receiver object of the context
5913 DECL_ACCESSORS(global_receiver, JSObject)
5914
5915 // Retrieve the property cell used to store a property.
Ben Murdochb0fe1622011-05-05 13:52:32 +01005916 JSGlobalPropertyCell* GetPropertyCell(LookupResult* result);
Steve Blocka7e24c12009-10-30 11:49:00 +00005917
John Reck59135872010-11-02 12:39:01 -07005918 // This is like GetProperty, but is used when you know the lookup won't fail
5919 // by throwing an exception. This is for the debug and builtins global
5920 // objects, where it is known which properties can be expected to be present
5921 // on the object.
5922 Object* GetPropertyNoExceptionThrown(String* key) {
5923 Object* answer = GetProperty(key)->ToObjectUnchecked();
5924 return answer;
5925 }
5926
Steve Blocka7e24c12009-10-30 11:49:00 +00005927 // Ensure that the global object has a cell for the given property name.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005928 static Handle<JSGlobalPropertyCell> EnsurePropertyCell(
5929 Handle<GlobalObject> global,
5930 Handle<String> name);
5931 // TODO(kmillikin): This function can be eliminated once the stub cache is
5932 // full handlified (and the static helper can be written directly).
John Reck59135872010-11-02 12:39:01 -07005933 MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name);
Steve Blocka7e24c12009-10-30 11:49:00 +00005934
5935 // Casting.
5936 static inline GlobalObject* cast(Object* obj);
5937
5938 // Layout description.
5939 static const int kBuiltinsOffset = JSObject::kHeaderSize;
5940 static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize;
5941 static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize;
5942 static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize;
5943
5944 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00005945 DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject);
5946};
5947
5948
5949// JavaScript global object.
5950class JSGlobalObject: public GlobalObject {
5951 public:
Steve Blocka7e24c12009-10-30 11:49:00 +00005952 // Casting.
5953 static inline JSGlobalObject* cast(Object* obj);
5954
5955 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01005956#ifdef OBJECT_PRINT
5957 inline void JSGlobalObjectPrint() {
5958 JSGlobalObjectPrint(stdout);
5959 }
5960 void JSGlobalObjectPrint(FILE* out);
5961#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00005962#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00005963 void JSGlobalObjectVerify();
5964#endif
5965
5966 // Layout description.
5967 static const int kSize = GlobalObject::kHeaderSize;
5968
5969 private:
5970 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject);
5971};
5972
5973
5974// Builtins global object which holds the runtime routines written in
5975// JavaScript.
5976class JSBuiltinsObject: public GlobalObject {
5977 public:
5978 // Accessors for the runtime routines written in JavaScript.
5979 inline Object* javascript_builtin(Builtins::JavaScript id);
5980 inline void set_javascript_builtin(Builtins::JavaScript id, Object* value);
5981
Steve Block6ded16b2010-05-10 14:33:55 +01005982 // Accessors for code of the runtime routines written in JavaScript.
5983 inline Code* javascript_builtin_code(Builtins::JavaScript id);
5984 inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value);
5985
Steve Blocka7e24c12009-10-30 11:49:00 +00005986 // Casting.
5987 static inline JSBuiltinsObject* cast(Object* obj);
5988
5989 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01005990#ifdef OBJECT_PRINT
5991 inline void JSBuiltinsObjectPrint() {
5992 JSBuiltinsObjectPrint(stdout);
5993 }
5994 void JSBuiltinsObjectPrint(FILE* out);
5995#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00005996#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00005997 void JSBuiltinsObjectVerify();
5998#endif
5999
6000 // Layout description. The size of the builtins object includes
Steve Block6ded16b2010-05-10 14:33:55 +01006001 // room for two pointers per runtime routine written in javascript
6002 // (function and code object).
Steve Blocka7e24c12009-10-30 11:49:00 +00006003 static const int kJSBuiltinsCount = Builtins::id_count;
6004 static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize;
Steve Block6ded16b2010-05-10 14:33:55 +01006005 static const int kJSBuiltinsCodeOffset =
6006 GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00006007 static const int kSize =
Steve Block6ded16b2010-05-10 14:33:55 +01006008 kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize);
6009
6010 static int OffsetOfFunctionWithId(Builtins::JavaScript id) {
6011 return kJSBuiltinsOffset + id * kPointerSize;
6012 }
6013
6014 static int OffsetOfCodeWithId(Builtins::JavaScript id) {
6015 return kJSBuiltinsCodeOffset + id * kPointerSize;
6016 }
6017
Steve Blocka7e24c12009-10-30 11:49:00 +00006018 private:
6019 DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject);
6020};
6021
6022
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006023// Representation for JS Wrapper objects, String, Number, Boolean, etc.
Steve Blocka7e24c12009-10-30 11:49:00 +00006024class JSValue: public JSObject {
6025 public:
6026 // [value]: the object being wrapped.
6027 DECL_ACCESSORS(value, Object)
6028
6029 // Casting.
6030 static inline JSValue* cast(Object* obj);
6031
6032 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01006033#ifdef OBJECT_PRINT
6034 inline void JSValuePrint() {
6035 JSValuePrint(stdout);
6036 }
6037 void JSValuePrint(FILE* out);
6038#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00006039#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00006040 void JSValueVerify();
6041#endif
6042
6043 // Layout description.
6044 static const int kValueOffset = JSObject::kHeaderSize;
6045 static const int kSize = kValueOffset + kPointerSize;
6046
6047 private:
6048 DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue);
6049};
6050
Steve Block1e0659c2011-05-24 12:43:12 +01006051
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006052class DateCache;
6053
6054// Representation for JS date objects.
6055class JSDate: public JSObject {
6056 public:
6057 // If one component is NaN, all of them are, indicating a NaN time value.
6058 // [value]: the time value.
6059 DECL_ACCESSORS(value, Object)
6060 // [year]: caches year. Either undefined, smi, or NaN.
6061 DECL_ACCESSORS(year, Object)
6062 // [month]: caches month. Either undefined, smi, or NaN.
6063 DECL_ACCESSORS(month, Object)
6064 // [day]: caches day. Either undefined, smi, or NaN.
6065 DECL_ACCESSORS(day, Object)
6066 // [weekday]: caches day of week. Either undefined, smi, or NaN.
6067 DECL_ACCESSORS(weekday, Object)
6068 // [hour]: caches hours. Either undefined, smi, or NaN.
6069 DECL_ACCESSORS(hour, Object)
6070 // [min]: caches minutes. Either undefined, smi, or NaN.
6071 DECL_ACCESSORS(min, Object)
6072 // [sec]: caches seconds. Either undefined, smi, or NaN.
6073 DECL_ACCESSORS(sec, Object)
6074 // [cache stamp]: sample of the date cache stamp at the
6075 // moment when local fields were cached.
6076 DECL_ACCESSORS(cache_stamp, Object)
6077
6078 // Casting.
6079 static inline JSDate* cast(Object* obj);
6080
6081 // Returns the date field with the specified index.
6082 // See FieldIndex for the list of date fields.
6083 static MaybeObject* GetField(Object* date, Smi* index);
6084
6085 void SetValue(Object* value, bool is_value_nan);
6086
6087
6088 // Dispatched behavior.
6089#ifdef OBJECT_PRINT
6090 inline void JSDatePrint() {
6091 JSDatePrint(stdout);
6092 }
6093 void JSDatePrint(FILE* out);
6094#endif
6095#ifdef DEBUG
6096 void JSDateVerify();
6097#endif
6098 // The order is important. It must be kept in sync with date macros
6099 // in macros.py.
6100 enum FieldIndex {
6101 kDateValue,
6102 kYear,
6103 kMonth,
6104 kDay,
6105 kWeekday,
6106 kHour,
6107 kMinute,
6108 kSecond,
6109 kFirstUncachedField,
6110 kMillisecond = kFirstUncachedField,
6111 kDays,
6112 kTimeInDay,
6113 kFirstUTCField,
6114 kYearUTC = kFirstUTCField,
6115 kMonthUTC,
6116 kDayUTC,
6117 kWeekdayUTC,
6118 kHourUTC,
6119 kMinuteUTC,
6120 kSecondUTC,
6121 kMillisecondUTC,
6122 kDaysUTC,
6123 kTimeInDayUTC,
6124 kTimezoneOffset
6125 };
6126
6127 // Layout description.
6128 static const int kValueOffset = JSObject::kHeaderSize;
6129 static const int kYearOffset = kValueOffset + kPointerSize;
6130 static const int kMonthOffset = kYearOffset + kPointerSize;
6131 static const int kDayOffset = kMonthOffset + kPointerSize;
6132 static const int kWeekdayOffset = kDayOffset + kPointerSize;
6133 static const int kHourOffset = kWeekdayOffset + kPointerSize;
6134 static const int kMinOffset = kHourOffset + kPointerSize;
6135 static const int kSecOffset = kMinOffset + kPointerSize;
6136 static const int kCacheStampOffset = kSecOffset + kPointerSize;
6137 static const int kSize = kCacheStampOffset + kPointerSize;
6138
6139 private:
6140 inline Object* DoGetField(FieldIndex index);
6141
6142 Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache);
6143
6144 // Computes and caches the cacheable fields of the date.
6145 inline void SetLocalFields(int64_t local_time_ms, DateCache* date_cache);
6146
6147
6148 DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate);
6149};
6150
6151
Steve Block1e0659c2011-05-24 12:43:12 +01006152// Representation of message objects used for error reporting through
6153// the API. The messages are formatted in JavaScript so this object is
6154// a real JavaScript object. The information used for formatting the
6155// error messages are not directly accessible from JavaScript to
6156// prevent leaking information to user code called during error
6157// formatting.
6158class JSMessageObject: public JSObject {
6159 public:
6160 // [type]: the type of error message.
6161 DECL_ACCESSORS(type, String)
6162
6163 // [arguments]: the arguments for formatting the error message.
6164 DECL_ACCESSORS(arguments, JSArray)
6165
6166 // [script]: the script from which the error message originated.
6167 DECL_ACCESSORS(script, Object)
6168
6169 // [stack_trace]: the stack trace for this error message.
6170 DECL_ACCESSORS(stack_trace, Object)
6171
6172 // [stack_frames]: an array of stack frames for this error object.
6173 DECL_ACCESSORS(stack_frames, Object)
6174
6175 // [start_position]: the start position in the script for the error message.
6176 inline int start_position();
6177 inline void set_start_position(int value);
6178
6179 // [end_position]: the end position in the script for the error message.
6180 inline int end_position();
6181 inline void set_end_position(int value);
6182
6183 // Casting.
6184 static inline JSMessageObject* cast(Object* obj);
6185
6186 // Dispatched behavior.
6187#ifdef OBJECT_PRINT
6188 inline void JSMessageObjectPrint() {
6189 JSMessageObjectPrint(stdout);
6190 }
6191 void JSMessageObjectPrint(FILE* out);
6192#endif
6193#ifdef DEBUG
6194 void JSMessageObjectVerify();
6195#endif
6196
6197 // Layout description.
6198 static const int kTypeOffset = JSObject::kHeaderSize;
6199 static const int kArgumentsOffset = kTypeOffset + kPointerSize;
6200 static const int kScriptOffset = kArgumentsOffset + kPointerSize;
6201 static const int kStackTraceOffset = kScriptOffset + kPointerSize;
6202 static const int kStackFramesOffset = kStackTraceOffset + kPointerSize;
6203 static const int kStartPositionOffset = kStackFramesOffset + kPointerSize;
6204 static const int kEndPositionOffset = kStartPositionOffset + kPointerSize;
6205 static const int kSize = kEndPositionOffset + kPointerSize;
6206
6207 typedef FixedBodyDescriptor<HeapObject::kMapOffset,
6208 kStackFramesOffset + kPointerSize,
6209 kSize> BodyDescriptor;
6210};
6211
6212
Steve Blocka7e24c12009-10-30 11:49:00 +00006213// Regular expressions
6214// The regular expression holds a single reference to a FixedArray in
6215// the kDataOffset field.
6216// The FixedArray contains the following data:
6217// - tag : type of regexp implementation (not compiled yet, atom or irregexp)
6218// - reference to the original source string
6219// - reference to the original flag string
6220// If it is an atom regexp
6221// - a reference to a literal string to search for
6222// If it is an irregexp regexp:
Ben Murdoch257744e2011-11-30 15:57:28 +00006223// - a reference to code for ASCII inputs (bytecode or compiled), or a smi
6224// used for tracking the last usage (used for code flushing).
6225// - a reference to code for UC16 inputs (bytecode or compiled), or a smi
6226// used for tracking the last usage (used for code flushing)..
Steve Blocka7e24c12009-10-30 11:49:00 +00006227// - max number of registers used by irregexp implementations.
6228// - number of capture registers (output values) of the regexp.
6229class JSRegExp: public JSObject {
6230 public:
6231 // Meaning of Type:
6232 // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
6233 // ATOM: A simple string to match against using an indexOf operation.
6234 // IRREGEXP: Compiled with Irregexp.
6235 // IRREGEXP_NATIVE: Compiled to native code with Irregexp.
6236 enum Type { NOT_COMPILED, ATOM, IRREGEXP };
6237 enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 };
6238
6239 class Flags {
6240 public:
6241 explicit Flags(uint32_t value) : value_(value) { }
6242 bool is_global() { return (value_ & GLOBAL) != 0; }
6243 bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; }
6244 bool is_multiline() { return (value_ & MULTILINE) != 0; }
6245 uint32_t value() { return value_; }
6246 private:
6247 uint32_t value_;
6248 };
6249
6250 DECL_ACCESSORS(data, Object)
6251
6252 inline Type TypeTag();
6253 inline int CaptureCount();
6254 inline Flags GetFlags();
6255 inline String* Pattern();
6256 inline Object* DataAt(int index);
6257 // Set implementation data after the object has been prepared.
6258 inline void SetDataAt(int index, Object* value);
Ben Murdoch257744e2011-11-30 15:57:28 +00006259
6260 // Used during GC when flushing code or setting age.
6261 inline Object* DataAtUnchecked(int index);
6262 inline void SetDataAtUnchecked(int index, Object* value, Heap* heap);
6263 inline Type TypeTagUnchecked();
6264
Steve Blocka7e24c12009-10-30 11:49:00 +00006265 static int code_index(bool is_ascii) {
6266 if (is_ascii) {
6267 return kIrregexpASCIICodeIndex;
6268 } else {
6269 return kIrregexpUC16CodeIndex;
6270 }
6271 }
6272
Ben Murdoch257744e2011-11-30 15:57:28 +00006273 static int saved_code_index(bool is_ascii) {
6274 if (is_ascii) {
6275 return kIrregexpASCIICodeSavedIndex;
6276 } else {
6277 return kIrregexpUC16CodeSavedIndex;
6278 }
6279 }
6280
Steve Blocka7e24c12009-10-30 11:49:00 +00006281 static inline JSRegExp* cast(Object* obj);
6282
6283 // Dispatched behavior.
6284#ifdef DEBUG
6285 void JSRegExpVerify();
6286#endif
6287
6288 static const int kDataOffset = JSObject::kHeaderSize;
6289 static const int kSize = kDataOffset + kPointerSize;
6290
6291 // Indices in the data array.
6292 static const int kTagIndex = 0;
6293 static const int kSourceIndex = kTagIndex + 1;
6294 static const int kFlagsIndex = kSourceIndex + 1;
6295 static const int kDataIndex = kFlagsIndex + 1;
6296 // The data fields are used in different ways depending on the
6297 // value of the tag.
6298 // Atom regexps (literal strings).
6299 static const int kAtomPatternIndex = kDataIndex;
6300
6301 static const int kAtomDataSize = kAtomPatternIndex + 1;
6302
6303 // Irregexp compiled code or bytecode for ASCII. If compilation
6304 // fails, this fields hold an exception object that should be
6305 // thrown if the regexp is used again.
6306 static const int kIrregexpASCIICodeIndex = kDataIndex;
6307 // Irregexp compiled code or bytecode for UC16. If compilation
6308 // fails, this fields hold an exception object that should be
6309 // thrown if the regexp is used again.
6310 static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
Ben Murdoch257744e2011-11-30 15:57:28 +00006311
6312 // Saved instance of Irregexp compiled code or bytecode for ASCII that
6313 // is a potential candidate for flushing.
6314 static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2;
6315 // Saved instance of Irregexp compiled code or bytecode for UC16 that is
6316 // a potential candidate for flushing.
6317 static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3;
6318
Steve Blocka7e24c12009-10-30 11:49:00 +00006319 // Maximal number of registers used by either ASCII or UC16.
6320 // Only used to check that there is enough stack space
Ben Murdoch257744e2011-11-30 15:57:28 +00006321 static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4;
Steve Blocka7e24c12009-10-30 11:49:00 +00006322 // Number of captures in the compiled regexp.
Ben Murdoch257744e2011-11-30 15:57:28 +00006323 static const int kIrregexpCaptureCountIndex = kDataIndex + 5;
Steve Blocka7e24c12009-10-30 11:49:00 +00006324
6325 static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1;
Leon Clarkee46be812010-01-19 14:06:41 +00006326
6327 // Offsets directly into the data fixed array.
6328 static const int kDataTagOffset =
6329 FixedArray::kHeaderSize + kTagIndex * kPointerSize;
6330 static const int kDataAsciiCodeOffset =
6331 FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize;
Leon Clarked91b9f72010-01-27 17:25:45 +00006332 static const int kDataUC16CodeOffset =
6333 FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize;
Leon Clarkee46be812010-01-19 14:06:41 +00006334 static const int kIrregexpCaptureCountOffset =
6335 FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
Steve Block6ded16b2010-05-10 14:33:55 +01006336
6337 // In-object fields.
6338 static const int kSourceFieldIndex = 0;
6339 static const int kGlobalFieldIndex = 1;
6340 static const int kIgnoreCaseFieldIndex = 2;
6341 static const int kMultilineFieldIndex = 3;
6342 static const int kLastIndexFieldIndex = 4;
Ben Murdochbb769b22010-08-11 14:56:33 +01006343 static const int kInObjectFieldCount = 5;
Ben Murdoch257744e2011-11-30 15:57:28 +00006344
6345 // The uninitialized value for a regexp code object.
6346 static const int kUninitializedValue = -1;
6347
6348 // The compilation error value for the regexp code object. The real error
6349 // object is in the saved code field.
6350 static const int kCompilationErrorValue = -2;
6351
6352 // When we store the sweep generation at which we moved the code from the
6353 // code index to the saved code index we mask it of to be in the [0:255]
6354 // range.
6355 static const int kCodeAgeMask = 0xff;
Steve Blocka7e24c12009-10-30 11:49:00 +00006356};
6357
6358
Ben Murdochc7cc0282012-03-05 14:35:55 +00006359class CompilationCacheShape : public BaseShape<HashTableKey*> {
Steve Blocka7e24c12009-10-30 11:49:00 +00006360 public:
6361 static inline bool IsMatch(HashTableKey* key, Object* value) {
6362 return key->IsMatch(value);
6363 }
6364
6365 static inline uint32_t Hash(HashTableKey* key) {
6366 return key->Hash();
6367 }
6368
6369 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
6370 return key->HashForObject(object);
6371 }
6372
John Reck59135872010-11-02 12:39:01 -07006373 MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
Steve Blocka7e24c12009-10-30 11:49:00 +00006374 return key->AsObject();
6375 }
6376
6377 static const int kPrefixSize = 0;
6378 static const int kEntrySize = 2;
6379};
6380
Steve Block3ce2e202009-11-05 08:53:23 +00006381
Steve Blocka7e24c12009-10-30 11:49:00 +00006382class CompilationCacheTable: public HashTable<CompilationCacheShape,
6383 HashTableKey*> {
6384 public:
6385 // Find cached value for a string key, otherwise return null.
6386 Object* Lookup(String* src);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006387 Object* LookupEval(String* src,
6388 Context* context,
6389 LanguageMode language_mode,
6390 int scope_position);
Steve Blocka7e24c12009-10-30 11:49:00 +00006391 Object* LookupRegExp(String* source, JSRegExp::Flags flags);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006392 MUST_USE_RESULT MaybeObject* Put(String* src, Object* value);
6393 MUST_USE_RESULT MaybeObject* PutEval(String* src,
6394 Context* context,
6395 SharedFunctionInfo* value,
6396 int scope_position);
6397 MUST_USE_RESULT MaybeObject* PutRegExp(String* src,
6398 JSRegExp::Flags flags,
6399 FixedArray* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00006400
Ben Murdochb0fe1622011-05-05 13:52:32 +01006401 // Remove given value from cache.
6402 void Remove(Object* value);
6403
Steve Blocka7e24c12009-10-30 11:49:00 +00006404 static inline CompilationCacheTable* cast(Object* obj);
6405
6406 private:
6407 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable);
6408};
6409
6410
Steve Block6ded16b2010-05-10 14:33:55 +01006411class CodeCache: public Struct {
6412 public:
6413 DECL_ACCESSORS(default_cache, FixedArray)
6414 DECL_ACCESSORS(normal_type_cache, Object)
6415
6416 // Add the code object to the cache.
John Reck59135872010-11-02 12:39:01 -07006417 MUST_USE_RESULT MaybeObject* Update(String* name, Code* code);
Steve Block6ded16b2010-05-10 14:33:55 +01006418
6419 // Lookup code object in the cache. Returns code object if found and undefined
6420 // if not.
6421 Object* Lookup(String* name, Code::Flags flags);
6422
6423 // Get the internal index of a code object in the cache. Returns -1 if the
6424 // code object is not in that cache. This index can be used to later call
6425 // RemoveByIndex. The cache cannot be modified between a call to GetIndex and
6426 // RemoveByIndex.
6427 int GetIndex(Object* name, Code* code);
6428
6429 // Remove an object from the cache with the provided internal index.
6430 void RemoveByIndex(Object* name, Code* code, int index);
6431
6432 static inline CodeCache* cast(Object* obj);
6433
Ben Murdochb0fe1622011-05-05 13:52:32 +01006434#ifdef OBJECT_PRINT
6435 inline void CodeCachePrint() {
6436 CodeCachePrint(stdout);
6437 }
6438 void CodeCachePrint(FILE* out);
6439#endif
Steve Block6ded16b2010-05-10 14:33:55 +01006440#ifdef DEBUG
Steve Block6ded16b2010-05-10 14:33:55 +01006441 void CodeCacheVerify();
6442#endif
6443
6444 static const int kDefaultCacheOffset = HeapObject::kHeaderSize;
6445 static const int kNormalTypeCacheOffset =
6446 kDefaultCacheOffset + kPointerSize;
6447 static const int kSize = kNormalTypeCacheOffset + kPointerSize;
6448
6449 private:
John Reck59135872010-11-02 12:39:01 -07006450 MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code);
6451 MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code);
Steve Block6ded16b2010-05-10 14:33:55 +01006452 Object* LookupDefaultCache(String* name, Code::Flags flags);
6453 Object* LookupNormalTypeCache(String* name, Code::Flags flags);
6454
6455 // Code cache layout of the default cache. Elements are alternating name and
6456 // code objects for non normal load/store/call IC's.
6457 static const int kCodeCacheEntrySize = 2;
6458 static const int kCodeCacheEntryNameOffset = 0;
6459 static const int kCodeCacheEntryCodeOffset = 1;
6460
6461 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache);
6462};
6463
6464
Ben Murdochc7cc0282012-03-05 14:35:55 +00006465class CodeCacheHashTableShape : public BaseShape<HashTableKey*> {
Steve Block6ded16b2010-05-10 14:33:55 +01006466 public:
6467 static inline bool IsMatch(HashTableKey* key, Object* value) {
6468 return key->IsMatch(value);
6469 }
6470
6471 static inline uint32_t Hash(HashTableKey* key) {
6472 return key->Hash();
6473 }
6474
6475 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
6476 return key->HashForObject(object);
6477 }
6478
John Reck59135872010-11-02 12:39:01 -07006479 MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
Steve Block6ded16b2010-05-10 14:33:55 +01006480 return key->AsObject();
6481 }
6482
6483 static const int kPrefixSize = 0;
6484 static const int kEntrySize = 2;
6485};
6486
6487
6488class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape,
6489 HashTableKey*> {
6490 public:
6491 Object* Lookup(String* name, Code::Flags flags);
John Reck59135872010-11-02 12:39:01 -07006492 MUST_USE_RESULT MaybeObject* Put(String* name, Code* code);
Steve Block6ded16b2010-05-10 14:33:55 +01006493
6494 int GetIndex(String* name, Code::Flags flags);
6495 void RemoveByIndex(int index);
6496
6497 static inline CodeCacheHashTable* cast(Object* obj);
6498
6499 // Initial size of the fixed array backing the hash table.
6500 static const int kInitialSize = 64;
6501
6502 private:
6503 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable);
6504};
6505
6506
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006507class PolymorphicCodeCache: public Struct {
6508 public:
6509 DECL_ACCESSORS(cache, Object)
6510
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006511 static void Update(Handle<PolymorphicCodeCache> cache,
6512 MapHandleList* maps,
6513 Code::Flags flags,
6514 Handle<Code> code);
6515
6516 MUST_USE_RESULT MaybeObject* Update(MapHandleList* maps,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006517 Code::Flags flags,
6518 Code* code);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006519
6520 // Returns an undefined value if the entry is not found.
6521 Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006522
6523 static inline PolymorphicCodeCache* cast(Object* obj);
6524
6525#ifdef OBJECT_PRINT
6526 inline void PolymorphicCodeCachePrint() {
6527 PolymorphicCodeCachePrint(stdout);
6528 }
6529 void PolymorphicCodeCachePrint(FILE* out);
6530#endif
6531#ifdef DEBUG
6532 void PolymorphicCodeCacheVerify();
6533#endif
6534
6535 static const int kCacheOffset = HeapObject::kHeaderSize;
6536 static const int kSize = kCacheOffset + kPointerSize;
6537
6538 private:
6539 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache);
6540};
6541
6542
6543class PolymorphicCodeCacheHashTable
6544 : public HashTable<CodeCacheHashTableShape, HashTableKey*> {
6545 public:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006546 Object* Lookup(MapHandleList* maps, int code_kind);
6547
6548 MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps,
6549 int code_kind,
6550 Code* code);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006551
6552 static inline PolymorphicCodeCacheHashTable* cast(Object* obj);
6553
6554 static const int kInitialSize = 64;
6555 private:
6556 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable);
6557};
6558
6559
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006560class TypeFeedbackInfo: public Struct {
6561 public:
6562 inline int ic_total_count();
6563 inline void set_ic_total_count(int count);
6564
6565 inline int ic_with_typeinfo_count();
6566 inline void set_ic_with_typeinfo_count(int count);
6567
6568 DECL_ACCESSORS(type_feedback_cells, TypeFeedbackCells)
6569
6570 static inline TypeFeedbackInfo* cast(Object* obj);
6571
6572#ifdef OBJECT_PRINT
6573 inline void TypeFeedbackInfoPrint() {
6574 TypeFeedbackInfoPrint(stdout);
6575 }
6576 void TypeFeedbackInfoPrint(FILE* out);
6577#endif
6578#ifdef DEBUG
6579 void TypeFeedbackInfoVerify();
6580#endif
6581
6582 static const int kIcTotalCountOffset = HeapObject::kHeaderSize;
6583 static const int kIcWithTypeinfoCountOffset =
6584 kIcTotalCountOffset + kPointerSize;
6585 static const int kTypeFeedbackCellsOffset =
6586 kIcWithTypeinfoCountOffset + kPointerSize;
6587 static const int kSize = kTypeFeedbackCellsOffset + kPointerSize;
6588
6589 private:
6590 DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo);
6591};
6592
6593
6594// Representation of a slow alias as part of a non-strict arguments objects.
6595// For fast aliases (if HasNonStrictArgumentsElements()):
6596// - the parameter map contains an index into the context
6597// - all attributes of the element have default values
6598// For slow aliases (if HasDictionaryArgumentsElements()):
6599// - the parameter map contains no fast alias mapping (i.e. the hole)
6600// - this struct (in the slow backing store) contains an index into the context
6601// - all attributes are available as part if the property details
6602class AliasedArgumentsEntry: public Struct {
6603 public:
6604 inline int aliased_context_slot();
6605 inline void set_aliased_context_slot(int count);
6606
6607 static inline AliasedArgumentsEntry* cast(Object* obj);
6608
6609#ifdef OBJECT_PRINT
6610 inline void AliasedArgumentsEntryPrint() {
6611 AliasedArgumentsEntryPrint(stdout);
6612 }
6613 void AliasedArgumentsEntryPrint(FILE* out);
6614#endif
6615#ifdef DEBUG
6616 void AliasedArgumentsEntryVerify();
6617#endif
6618
6619 static const int kAliasedContextSlot = HeapObject::kHeaderSize;
6620 static const int kSize = kAliasedContextSlot + kPointerSize;
6621
6622 private:
6623 DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry);
6624};
6625
6626
Steve Blocka7e24c12009-10-30 11:49:00 +00006627enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS};
6628enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL};
6629
6630
6631class StringHasher {
6632 public:
Ben Murdochc7cc0282012-03-05 14:35:55 +00006633 explicit inline StringHasher(int length, uint32_t seed);
Steve Blocka7e24c12009-10-30 11:49:00 +00006634
6635 // Returns true if the hash of this string can be computed without
6636 // looking at the contents.
6637 inline bool has_trivial_hash();
6638
6639 // Add a character to the hash and update the array index calculation.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006640 inline void AddCharacter(uint32_t c);
Steve Blocka7e24c12009-10-30 11:49:00 +00006641
6642 // Adds a character to the hash but does not update the array index
6643 // calculation. This can only be called when it has been verified
6644 // that the input is not an array index.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006645 inline void AddCharacterNoIndex(uint32_t c);
6646
6647 // Add a character above 0xffff as a surrogate pair. These can get into
6648 // the hasher through the routines that take a UTF-8 string and make a symbol.
6649 void AddSurrogatePair(uc32 c);
6650 void AddSurrogatePairNoIndex(uc32 c);
Steve Blocka7e24c12009-10-30 11:49:00 +00006651
6652 // Returns the value to store in the hash field of a string with
6653 // the given length and contents.
6654 uint32_t GetHashField();
6655
6656 // Returns true if the characters seen so far make up a legal array
6657 // index.
6658 bool is_array_index() { return is_array_index_; }
6659
6660 bool is_valid() { return is_valid_; }
6661
6662 void invalidate() { is_valid_ = false; }
6663
Kristian Monsen80d68ea2010-09-08 11:05:35 +01006664 // Calculated hash value for a string consisting of 1 to
6665 // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
6666 // value is represented decimal value.
Iain Merrick9ac36c92010-09-13 15:29:50 +01006667 static uint32_t MakeArrayIndexHash(uint32_t value, int length);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01006668
Ben Murdochc7cc0282012-03-05 14:35:55 +00006669 // No string is allowed to have a hash of zero. That value is reserved
6670 // for internal properties. If the hash calculation yields zero then we
6671 // use 27 instead.
6672 static const int kZeroHash = 27;
6673
Steve Blocka7e24c12009-10-30 11:49:00 +00006674 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00006675 uint32_t array_index() {
6676 ASSERT(is_array_index());
6677 return array_index_;
6678 }
6679
6680 inline uint32_t GetHash();
6681
6682 int length_;
6683 uint32_t raw_running_hash_;
6684 uint32_t array_index_;
6685 bool is_array_index_;
6686 bool is_first_char_;
6687 bool is_valid_;
Steve Blockd0582a62009-12-15 09:54:21 +00006688 friend class TwoCharHashTableKey;
Steve Blocka7e24c12009-10-30 11:49:00 +00006689};
6690
6691
Steve Block44f0eee2011-05-26 01:26:41 +01006692// Calculates string hash.
6693template <typename schar>
Ben Murdochc7cc0282012-03-05 14:35:55 +00006694inline uint32_t HashSequentialString(const schar* chars,
6695 int length,
6696 uint32_t seed);
Steve Block44f0eee2011-05-26 01:26:41 +01006697
6698
Steve Blocka7e24c12009-10-30 11:49:00 +00006699// The characteristics of a string are stored in its map. Retrieving these
6700// few bits of information is moderately expensive, involving two memory
6701// loads where the second is dependent on the first. To improve efficiency
6702// the shape of the string is given its own class so that it can be retrieved
6703// once and used for several string operations. A StringShape is small enough
6704// to be passed by value and is immutable, but be aware that flattening a
6705// string can potentially alter its shape. Also be aware that a GC caused by
6706// something else can alter the shape of a string due to ConsString
6707// shortcutting. Keeping these restrictions in mind has proven to be error-
6708// prone and so we no longer put StringShapes in variables unless there is a
6709// concrete performance benefit at that particular point in the code.
6710class StringShape BASE_EMBEDDED {
6711 public:
6712 inline explicit StringShape(String* s);
6713 inline explicit StringShape(Map* s);
6714 inline explicit StringShape(InstanceType t);
6715 inline bool IsSequential();
6716 inline bool IsExternal();
6717 inline bool IsCons();
Ben Murdoch69a99ed2011-11-30 16:03:39 +00006718 inline bool IsSliced();
6719 inline bool IsIndirect();
Steve Blocka7e24c12009-10-30 11:49:00 +00006720 inline bool IsExternalAscii();
6721 inline bool IsExternalTwoByte();
6722 inline bool IsSequentialAscii();
6723 inline bool IsSequentialTwoByte();
6724 inline bool IsSymbol();
6725 inline StringRepresentationTag representation_tag();
Ben Murdoch69a99ed2011-11-30 16:03:39 +00006726 inline uint32_t encoding_tag();
Steve Blocka7e24c12009-10-30 11:49:00 +00006727 inline uint32_t full_representation_tag();
6728 inline uint32_t size_tag();
6729#ifdef DEBUG
6730 inline uint32_t type() { return type_; }
6731 inline void invalidate() { valid_ = false; }
6732 inline bool valid() { return valid_; }
6733#else
6734 inline void invalidate() { }
6735#endif
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006736
Steve Blocka7e24c12009-10-30 11:49:00 +00006737 private:
6738 uint32_t type_;
6739#ifdef DEBUG
6740 inline void set_valid() { valid_ = true; }
6741 bool valid_;
6742#else
6743 inline void set_valid() { }
6744#endif
6745};
6746
6747
6748// The String abstract class captures JavaScript string values:
6749//
6750// Ecma-262:
6751// 4.3.16 String Value
6752// A string value is a member of the type String and is a finite
6753// ordered sequence of zero or more 16-bit unsigned integer values.
6754//
6755// All string values have a length field.
6756class String: public HeapObject {
6757 public:
Ben Murdoch69a99ed2011-11-30 16:03:39 +00006758 // Representation of the flat content of a String.
6759 // A non-flat string doesn't have flat content.
6760 // A flat string has content that's encoded as a sequence of either
6761 // ASCII chars or two-byte UC16.
6762 // Returned by String::GetFlatContent().
6763 class FlatContent {
6764 public:
6765 // Returns true if the string is flat and this structure contains content.
6766 bool IsFlat() { return state_ != NON_FLAT; }
6767 // Returns true if the structure contains ASCII content.
6768 bool IsAscii() { return state_ == ASCII; }
6769 // Returns true if the structure contains two-byte content.
6770 bool IsTwoByte() { return state_ == TWO_BYTE; }
6771
6772 // Return the ASCII content of the string. Only use if IsAscii() returns
6773 // true.
6774 Vector<const char> ToAsciiVector() {
6775 ASSERT_EQ(ASCII, state_);
6776 return Vector<const char>::cast(buffer_);
6777 }
6778 // Return the two-byte content of the string. Only use if IsTwoByte()
6779 // returns true.
6780 Vector<const uc16> ToUC16Vector() {
6781 ASSERT_EQ(TWO_BYTE, state_);
6782 return Vector<const uc16>::cast(buffer_);
6783 }
6784
6785 private:
6786 enum State { NON_FLAT, ASCII, TWO_BYTE };
6787
6788 // Constructors only used by String::GetFlatContent().
6789 explicit FlatContent(Vector<const char> chars)
6790 : buffer_(Vector<const byte>::cast(chars)),
6791 state_(ASCII) { }
6792 explicit FlatContent(Vector<const uc16> chars)
6793 : buffer_(Vector<const byte>::cast(chars)),
6794 state_(TWO_BYTE) { }
6795 FlatContent() : buffer_(), state_(NON_FLAT) { }
6796
6797 Vector<const byte> buffer_;
6798 State state_;
6799
6800 friend class String;
6801 };
6802
Steve Blocka7e24c12009-10-30 11:49:00 +00006803 // Get and set the length of the string.
6804 inline int length();
6805 inline void set_length(int value);
6806
Steve Blockd0582a62009-12-15 09:54:21 +00006807 // Get and set the hash field of the string.
6808 inline uint32_t hash_field();
6809 inline void set_hash_field(uint32_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +00006810
Ben Murdoch69a99ed2011-11-30 16:03:39 +00006811 // Returns whether this string has only ASCII chars, i.e. all of them can
6812 // be ASCII encoded. This might be the case even if the string is
6813 // two-byte. Such strings may appear when the embedder prefers
6814 // two-byte external representations even for ASCII data.
Steve Blocka7e24c12009-10-30 11:49:00 +00006815 inline bool IsAsciiRepresentation();
6816 inline bool IsTwoByteRepresentation();
6817
Ben Murdoch69a99ed2011-11-30 16:03:39 +00006818 // Cons and slices have an encoding flag that may not represent the actual
6819 // encoding of the underlying string. This is taken into account here.
6820 // Requires: this->IsFlat()
6821 inline bool IsAsciiRepresentationUnderneath();
6822 inline bool IsTwoByteRepresentationUnderneath();
6823
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01006824 // NOTE: this should be considered only a hint. False negatives are
6825 // possible.
6826 inline bool HasOnlyAsciiChars();
Steve Block6ded16b2010-05-10 14:33:55 +01006827
Steve Blocka7e24c12009-10-30 11:49:00 +00006828 // Get and set individual two byte chars in the string.
6829 inline void Set(int index, uint16_t value);
6830 // Get individual two byte char in the string. Repeated calls
6831 // to this method are not efficient unless the string is flat.
6832 inline uint16_t Get(int index);
6833
Leon Clarkef7060e22010-06-03 12:02:55 +01006834 // Try to flatten the string. Checks first inline to see if it is
6835 // necessary. Does nothing if the string is not a cons string.
6836 // Flattening allocates a sequential string with the same data as
6837 // the given string and mutates the cons string to a degenerate
6838 // form, where the first component is the new sequential string and
6839 // the second component is the empty string. If allocation fails,
6840 // this function returns a failure. If flattening succeeds, this
6841 // function returns the sequential string that is now the first
6842 // component of the cons string.
6843 //
6844 // Degenerate cons strings are handled specially by the garbage
6845 // collector (see IsShortcutCandidate).
6846 //
6847 // Use FlattenString from Handles.cc to flatten even in case an
6848 // allocation failure happens.
John Reck59135872010-11-02 12:39:01 -07006849 inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +00006850
Leon Clarkef7060e22010-06-03 12:02:55 +01006851 // Convenience function. Has exactly the same behavior as
6852 // TryFlatten(), except in the case of failure returns the original
6853 // string.
6854 inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED);
6855
Ben Murdoch69a99ed2011-11-30 16:03:39 +00006856 // Tries to return the content of a flat string as a structure holding either
6857 // a flat vector of char or of uc16.
6858 // If the string isn't flat, and therefore doesn't have flat content, the
6859 // returned structure will report so, and can't provide a vector of either
6860 // kind.
6861 FlatContent GetFlatContent();
6862
6863 // Returns the parent of a sliced string or first part of a flat cons string.
6864 // Requires: StringShape(this).IsIndirect() && this->IsFlat()
6865 inline String* GetUnderlying();
Steve Blocka7e24c12009-10-30 11:49:00 +00006866
6867 // Mark the string as an undetectable object. It only applies to
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006868 // ASCII and two byte string types.
Steve Blocka7e24c12009-10-30 11:49:00 +00006869 bool MarkAsUndetectable();
6870
Steve Blockd0582a62009-12-15 09:54:21 +00006871 // Return a substring.
John Reck59135872010-11-02 12:39:01 -07006872 MUST_USE_RESULT MaybeObject* SubString(int from,
6873 int to,
6874 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +00006875
6876 // String equality operations.
6877 inline bool Equals(String* other);
6878 bool IsEqualTo(Vector<const char> str);
Steve Block9fac8402011-05-12 15:51:54 +01006879 bool IsAsciiEqualTo(Vector<const char> str);
6880 bool IsTwoByteEqualTo(Vector<const uc16> str);
Steve Blocka7e24c12009-10-30 11:49:00 +00006881
6882 // Return a UTF8 representation of the string. The string is null
6883 // terminated but may optionally contain nulls. Length is returned
6884 // in length_output if length_output is not a null pointer The string
6885 // should be nearly flat, otherwise the performance of this method may
6886 // be very slow (quadratic in the length). Setting robustness_flag to
6887 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
6888 // handles unexpected data without causing assert failures and it does not
6889 // do any heap allocations. This is useful when printing stack traces.
Ben Murdoch589d6972011-11-30 16:04:58 +00006890 SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls,
6891 RobustnessFlag robustness_flag,
6892 int offset,
6893 int length,
6894 int* length_output = 0);
6895 SmartArrayPointer<char> ToCString(
Steve Blocka7e24c12009-10-30 11:49:00 +00006896 AllowNullsFlag allow_nulls = DISALLOW_NULLS,
6897 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL,
6898 int* length_output = 0);
6899
Steve Blocka7e24c12009-10-30 11:49:00 +00006900 // Return a 16 bit Unicode representation of the string.
6901 // The string should be nearly flat, otherwise the performance of
6902 // of this method may be very bad. Setting robustness_flag to
6903 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
6904 // handles unexpected data without causing assert failures and it does not
6905 // do any heap allocations. This is useful when printing stack traces.
Ben Murdoch589d6972011-11-30 16:04:58 +00006906 SmartArrayPointer<uc16> ToWideCString(
Steve Blocka7e24c12009-10-30 11:49:00 +00006907 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
6908
6909 // Tells whether the hash code has been computed.
6910 inline bool HasHashCode();
6911
6912 // Returns a hash value used for the property table
6913 inline uint32_t Hash();
6914
Steve Blockd0582a62009-12-15 09:54:21 +00006915 static uint32_t ComputeHashField(unibrow::CharacterStream* buffer,
Ben Murdochc7cc0282012-03-05 14:35:55 +00006916 int length,
6917 uint32_t seed);
Steve Blocka7e24c12009-10-30 11:49:00 +00006918
6919 static bool ComputeArrayIndex(unibrow::CharacterStream* buffer,
6920 uint32_t* index,
6921 int length);
6922
6923 // Externalization.
6924 bool MakeExternal(v8::String::ExternalStringResource* resource);
6925 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource);
6926
6927 // Conversion.
6928 inline bool AsArrayIndex(uint32_t* index);
6929
6930 // Casting.
6931 static inline String* cast(Object* obj);
6932
6933 void PrintOn(FILE* out);
6934
6935 // For use during stack traces. Performs rudimentary sanity check.
6936 bool LooksValid();
6937
6938 // Dispatched behavior.
6939 void StringShortPrint(StringStream* accumulator);
Ben Murdochb0fe1622011-05-05 13:52:32 +01006940#ifdef OBJECT_PRINT
6941 inline void StringPrint() {
6942 StringPrint(stdout);
6943 }
6944 void StringPrint(FILE* out);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00006945
6946 char* ToAsciiArray();
Ben Murdochb0fe1622011-05-05 13:52:32 +01006947#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00006948#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00006949 void StringVerify();
6950#endif
6951 inline bool IsFlat();
6952
6953 // Layout description.
6954 static const int kLengthOffset = HeapObject::kHeaderSize;
Steve Block6ded16b2010-05-10 14:33:55 +01006955 static const int kHashFieldOffset = kLengthOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01006956 static const int kSize = kHashFieldOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00006957
Steve Blockd0582a62009-12-15 09:54:21 +00006958 // Maximum number of characters to consider when trying to convert a string
6959 // value into an array index.
Steve Blocka7e24c12009-10-30 11:49:00 +00006960 static const int kMaxArrayIndexSize = 10;
6961
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006962 // Max ASCII char code.
Steve Blocka7e24c12009-10-30 11:49:00 +00006963 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar;
6964 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006965 static const int kMaxUtf16CodeUnit = 0xffff;
Steve Blocka7e24c12009-10-30 11:49:00 +00006966
Steve Blocka7e24c12009-10-30 11:49:00 +00006967 // Mask constant for checking if a string has a computed hash code
6968 // and if it is an array index. The least significant bit indicates
6969 // whether a hash code has been computed. If the hash code has been
6970 // computed the 2nd bit tells whether the string can be used as an
6971 // array index.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01006972 static const int kHashNotComputedMask = 1;
6973 static const int kIsNotArrayIndexMask = 1 << 1;
6974 static const int kNofHashBitFields = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +00006975
Steve Blockd0582a62009-12-15 09:54:21 +00006976 // Shift constant retrieving hash code from hash field.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01006977 static const int kHashShift = kNofHashBitFields;
Steve Blockd0582a62009-12-15 09:54:21 +00006978
Ben Murdochc7cc0282012-03-05 14:35:55 +00006979 // Only these bits are relevant in the hash, since the top two are shifted
6980 // out.
6981 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift;
6982
Steve Blocka7e24c12009-10-30 11:49:00 +00006983 // Array index strings this short can keep their index in the hash
6984 // field.
6985 static const int kMaxCachedArrayIndexLength = 7;
6986
Steve Blockd0582a62009-12-15 09:54:21 +00006987 // For strings which are array indexes the hash value has the string length
6988 // mixed into the hash, mainly to avoid a hash value of zero which would be
6989 // the case for the string '0'. 24 bits are used for the array index value.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01006990 static const int kArrayIndexValueBits = 24;
6991 static const int kArrayIndexLengthBits =
6992 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
6993
6994 STATIC_CHECK((kArrayIndexLengthBits > 0));
Iain Merrick9ac36c92010-09-13 15:29:50 +01006995 STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01006996
6997 static const int kArrayIndexHashLengthShift =
6998 kArrayIndexValueBits + kNofHashBitFields;
6999
Steve Blockd0582a62009-12-15 09:54:21 +00007000 static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007001
7002 static const int kArrayIndexValueMask =
7003 ((1 << kArrayIndexValueBits) - 1) << kHashShift;
7004
7005 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
7006 // could use a mask to test if the length of string is less than or equal to
7007 // kMaxCachedArrayIndexLength.
7008 STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
7009
7010 static const int kContainsCachedArrayIndexMask =
7011 (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) |
7012 kIsNotArrayIndexMask;
Steve Blockd0582a62009-12-15 09:54:21 +00007013
7014 // Value of empty hash field indicating that the hash is not computed.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007015 static const int kEmptyHashField =
7016 kIsNotArrayIndexMask | kHashNotComputedMask;
7017
7018 // Value of hash field containing computed hash equal to zero.
7019 static const int kZeroHash = kIsNotArrayIndexMask;
Steve Blockd0582a62009-12-15 09:54:21 +00007020
7021 // Maximal string length.
7022 static const int kMaxLength = (1 << (32 - 2)) - 1;
7023
7024 // Max length for computing hash. For strings longer than this limit the
7025 // string length is used as the hash value.
7026 static const int kMaxHashCalcLength = 16383;
Steve Blocka7e24c12009-10-30 11:49:00 +00007027
7028 // Limit for truncation in short printing.
7029 static const int kMaxShortPrintLength = 1024;
7030
7031 // Support for regular expressions.
7032 const uc16* GetTwoByteData();
7033 const uc16* GetTwoByteData(unsigned start);
7034
7035 // Support for StringInputBuffer
7036 static const unibrow::byte* ReadBlock(String* input,
7037 unibrow::byte* util_buffer,
7038 unsigned capacity,
7039 unsigned* remaining,
7040 unsigned* offset);
7041 static const unibrow::byte* ReadBlock(String** input,
7042 unibrow::byte* util_buffer,
7043 unsigned capacity,
7044 unsigned* remaining,
7045 unsigned* offset);
7046
7047 // Helper function for flattening strings.
7048 template <typename sinkchar>
7049 static void WriteToFlat(String* source,
7050 sinkchar* sink,
7051 int from,
7052 int to);
7053
Steve Block9fac8402011-05-12 15:51:54 +01007054 static inline bool IsAscii(const char* chars, int length) {
7055 const char* limit = chars + length;
7056#ifdef V8_HOST_CAN_READ_UNALIGNED
7057 ASSERT(kMaxAsciiCharCode == 0x7F);
7058 const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80;
7059 while (chars <= limit - sizeof(uintptr_t)) {
7060 if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
7061 return false;
7062 }
7063 chars += sizeof(uintptr_t);
7064 }
7065#endif
7066 while (chars < limit) {
7067 if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false;
7068 ++chars;
7069 }
7070 return true;
7071 }
7072
7073 static inline bool IsAscii(const uc16* chars, int length) {
7074 const uc16* limit = chars + length;
7075 while (chars < limit) {
7076 if (*chars > kMaxAsciiCharCodeU) return false;
7077 ++chars;
7078 }
7079 return true;
7080 }
7081
Steve Blocka7e24c12009-10-30 11:49:00 +00007082 protected:
7083 class ReadBlockBuffer {
7084 public:
7085 ReadBlockBuffer(unibrow::byte* util_buffer_,
7086 unsigned cursor_,
7087 unsigned capacity_,
7088 unsigned remaining_) :
7089 util_buffer(util_buffer_),
7090 cursor(cursor_),
7091 capacity(capacity_),
7092 remaining(remaining_) {
7093 }
7094 unibrow::byte* util_buffer;
7095 unsigned cursor;
7096 unsigned capacity;
7097 unsigned remaining;
7098 };
7099
Steve Blocka7e24c12009-10-30 11:49:00 +00007100 static inline const unibrow::byte* ReadBlock(String* input,
7101 ReadBlockBuffer* buffer,
7102 unsigned* offset,
7103 unsigned max_chars);
7104 static void ReadBlockIntoBuffer(String* input,
7105 ReadBlockBuffer* buffer,
7106 unsigned* offset_ptr,
7107 unsigned max_chars);
7108
7109 private:
Leon Clarkef7060e22010-06-03 12:02:55 +01007110 // Try to flatten the top level ConsString that is hiding behind this
7111 // string. This is a no-op unless the string is a ConsString. Flatten
7112 // mutates the ConsString and might return a failure.
John Reck59135872010-11-02 12:39:01 -07007113 MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure);
Leon Clarkef7060e22010-06-03 12:02:55 +01007114
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007115 static inline bool IsHashFieldComputed(uint32_t field);
7116
Steve Blocka7e24c12009-10-30 11:49:00 +00007117 // Slow case of String::Equals. This implementation works on any strings
7118 // but it is most efficient on strings that are almost flat.
7119 bool SlowEquals(String* other);
7120
7121 // Slow case of AsArrayIndex.
7122 bool SlowAsArrayIndex(uint32_t* index);
7123
7124 // Compute and set the hash code.
7125 uint32_t ComputeAndSetHash();
7126
7127 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
7128};
7129
7130
7131// The SeqString abstract class captures sequential string values.
7132class SeqString: public String {
7133 public:
Steve Blocka7e24c12009-10-30 11:49:00 +00007134 // Casting.
7135 static inline SeqString* cast(Object* obj);
7136
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007137 // Layout description.
7138 static const int kHeaderSize = String::kSize;
7139
Steve Blocka7e24c12009-10-30 11:49:00 +00007140 private:
7141 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
7142};
7143
7144
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007145// The AsciiString class captures sequential ASCII string objects.
7146// Each character in the AsciiString is an ASCII character.
Steve Blocka7e24c12009-10-30 11:49:00 +00007147class SeqAsciiString: public SeqString {
7148 public:
Leon Clarkeac952652010-07-15 11:15:24 +01007149 static const bool kHasAsciiEncoding = true;
7150
Steve Blocka7e24c12009-10-30 11:49:00 +00007151 // Dispatched behavior.
7152 inline uint16_t SeqAsciiStringGet(int index);
7153 inline void SeqAsciiStringSet(int index, uint16_t value);
7154
7155 // Get the address of the characters in this string.
7156 inline Address GetCharsAddress();
7157
7158 inline char* GetChars();
7159
7160 // Casting
7161 static inline SeqAsciiString* cast(Object* obj);
7162
7163 // Garbage collection support. This method is called by the
7164 // garbage collector to compute the actual size of an AsciiString
7165 // instance.
7166 inline int SeqAsciiStringSize(InstanceType instance_type);
7167
7168 // Computes the size for an AsciiString instance of a given length.
7169 static int SizeFor(int length) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007170 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00007171 }
7172
Leon Clarkee46be812010-01-19 14:06:41 +00007173 // Maximal memory usage for a single sequential ASCII string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007174 static const int kMaxSize = 512 * MB - 1;
Leon Clarkee46be812010-01-19 14:06:41 +00007175 // Maximal length of a single sequential ASCII string.
7176 // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7177 static const int kMaxLength = (kMaxSize - kHeaderSize);
7178
Steve Blocka7e24c12009-10-30 11:49:00 +00007179 // Support for StringInputBuffer.
7180 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7181 unsigned* offset,
7182 unsigned chars);
7183 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining,
7184 unsigned* offset,
7185 unsigned chars);
7186
7187 private:
7188 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString);
7189};
7190
7191
7192// The TwoByteString class captures sequential unicode string objects.
7193// Each character in the TwoByteString is a two-byte uint16_t.
7194class SeqTwoByteString: public SeqString {
7195 public:
Leon Clarkeac952652010-07-15 11:15:24 +01007196 static const bool kHasAsciiEncoding = false;
7197
Steve Blocka7e24c12009-10-30 11:49:00 +00007198 // Dispatched behavior.
7199 inline uint16_t SeqTwoByteStringGet(int index);
7200 inline void SeqTwoByteStringSet(int index, uint16_t value);
7201
7202 // Get the address of the characters in this string.
7203 inline Address GetCharsAddress();
7204
7205 inline uc16* GetChars();
7206
7207 // For regexp code.
7208 const uint16_t* SeqTwoByteStringGetData(unsigned start);
7209
7210 // Casting
7211 static inline SeqTwoByteString* cast(Object* obj);
7212
7213 // Garbage collection support. This method is called by the
7214 // garbage collector to compute the actual size of a TwoByteString
7215 // instance.
7216 inline int SeqTwoByteStringSize(InstanceType instance_type);
7217
7218 // Computes the size for a TwoByteString instance of a given length.
7219 static int SizeFor(int length) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007220 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00007221 }
7222
Leon Clarkee46be812010-01-19 14:06:41 +00007223 // Maximal memory usage for a single sequential two-byte string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007224 static const int kMaxSize = 512 * MB - 1;
Leon Clarkee46be812010-01-19 14:06:41 +00007225 // Maximal length of a single sequential two-byte string.
7226 // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7227 static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t);
7228
Steve Blocka7e24c12009-10-30 11:49:00 +00007229 // Support for StringInputBuffer.
7230 inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7231 unsigned* offset_ptr,
7232 unsigned chars);
7233
7234 private:
7235 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
7236};
7237
7238
7239// The ConsString class describes string values built by using the
7240// addition operator on strings. A ConsString is a pair where the
7241// first and second components are pointers to other string values.
7242// One or both components of a ConsString can be pointers to other
7243// ConsStrings, creating a binary tree of ConsStrings where the leaves
7244// are non-ConsString string values. The string value represented by
7245// a ConsString can be obtained by concatenating the leaf string
7246// values in a left-to-right depth-first traversal of the tree.
7247class ConsString: public String {
7248 public:
7249 // First string of the cons cell.
7250 inline String* first();
7251 // Doesn't check that the result is a string, even in debug mode. This is
7252 // useful during GC where the mark bits confuse the checks.
7253 inline Object* unchecked_first();
7254 inline void set_first(String* first,
7255 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
7256
7257 // Second string of the cons cell.
7258 inline String* second();
7259 // Doesn't check that the result is a string, even in debug mode. This is
7260 // useful during GC where the mark bits confuse the checks.
7261 inline Object* unchecked_second();
7262 inline void set_second(String* second,
7263 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
7264
7265 // Dispatched behavior.
7266 uint16_t ConsStringGet(int index);
7267
7268 // Casting.
7269 static inline ConsString* cast(Object* obj);
7270
Steve Blocka7e24c12009-10-30 11:49:00 +00007271 // Layout description.
7272 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
7273 static const int kSecondOffset = kFirstOffset + kPointerSize;
7274 static const int kSize = kSecondOffset + kPointerSize;
7275
7276 // Support for StringInputBuffer.
7277 inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer,
7278 unsigned* offset_ptr,
7279 unsigned chars);
7280 inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7281 unsigned* offset_ptr,
7282 unsigned chars);
7283
7284 // Minimum length for a cons string.
7285 static const int kMinLength = 13;
7286
Iain Merrick75681382010-08-19 15:07:18 +01007287 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
7288 BodyDescriptor;
7289
Ben Murdoch69a99ed2011-11-30 16:03:39 +00007290#ifdef DEBUG
7291 void ConsStringVerify();
7292#endif
7293
Steve Blocka7e24c12009-10-30 11:49:00 +00007294 private:
7295 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
7296};
7297
7298
Ben Murdoch69a99ed2011-11-30 16:03:39 +00007299// The Sliced String class describes strings that are substrings of another
7300// sequential string. The motivation is to save time and memory when creating
7301// a substring. A Sliced String is described as a pointer to the parent,
7302// the offset from the start of the parent string and the length. Using
7303// a Sliced String therefore requires unpacking of the parent string and
7304// adding the offset to the start address. A substring of a Sliced String
7305// are not nested since the double indirection is simplified when creating
7306// such a substring.
7307// Currently missing features are:
7308// - handling externalized parent strings
7309// - external strings as parent
7310// - truncating sliced string to enable otherwise unneeded parent to be GC'ed.
7311class SlicedString: public String {
7312 public:
Ben Murdoch69a99ed2011-11-30 16:03:39 +00007313 inline String* parent();
7314 inline void set_parent(String* parent);
7315 inline int offset();
7316 inline void set_offset(int offset);
7317
7318 // Dispatched behavior.
7319 uint16_t SlicedStringGet(int index);
7320
7321 // Casting.
7322 static inline SlicedString* cast(Object* obj);
7323
7324 // Layout description.
7325 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
7326 static const int kOffsetOffset = kParentOffset + kPointerSize;
7327 static const int kSize = kOffsetOffset + kPointerSize;
7328
7329 // Support for StringInputBuffer
7330 inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer,
7331 unsigned* offset_ptr,
7332 unsigned chars);
7333 inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7334 unsigned* offset_ptr,
7335 unsigned chars);
7336 // Minimum length for a sliced string.
7337 static const int kMinLength = 13;
7338
7339 typedef FixedBodyDescriptor<kParentOffset,
7340 kOffsetOffset + kPointerSize, kSize>
7341 BodyDescriptor;
7342
7343#ifdef DEBUG
7344 void SlicedStringVerify();
7345#endif
7346
7347 private:
7348 DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString);
7349};
7350
7351
Steve Blocka7e24c12009-10-30 11:49:00 +00007352// The ExternalString class describes string values that are backed by
7353// a string resource that lies outside the V8 heap. ExternalStrings
7354// consist of the length field common to all strings, a pointer to the
7355// external resource. It is important to ensure (externally) that the
7356// resource is not deallocated while the ExternalString is live in the
7357// V8 heap.
7358//
7359// The API expects that all ExternalStrings are created through the
7360// API. Therefore, ExternalStrings should not be used internally.
7361class ExternalString: public String {
7362 public:
7363 // Casting
7364 static inline ExternalString* cast(Object* obj);
7365
7366 // Layout description.
7367 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007368 static const int kShortSize = kResourceOffset + kPointerSize;
7369 static const int kResourceDataOffset = kResourceOffset + kPointerSize;
7370 static const int kSize = kResourceDataOffset + kPointerSize;
7371
7372 // Return whether external string is short (data pointer is not cached).
7373 inline bool is_short();
Steve Blocka7e24c12009-10-30 11:49:00 +00007374
7375 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset);
7376
7377 private:
7378 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
7379};
7380
7381
7382// The ExternalAsciiString class is an external string backed by an
7383// ASCII string.
7384class ExternalAsciiString: public ExternalString {
7385 public:
Leon Clarkeac952652010-07-15 11:15:24 +01007386 static const bool kHasAsciiEncoding = true;
7387
Steve Blocka7e24c12009-10-30 11:49:00 +00007388 typedef v8::String::ExternalAsciiStringResource Resource;
7389
7390 // The underlying resource.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007391 inline const Resource* resource();
7392 inline void set_resource(const Resource* buffer);
7393
7394 // Update the pointer cache to the external character array.
7395 // The cached pointer is always valid, as the external character array does =
7396 // not move during lifetime. Deserialization is the only exception, after
7397 // which the pointer cache has to be refreshed.
7398 inline void update_data_cache();
7399
7400 inline const char* GetChars();
Steve Blocka7e24c12009-10-30 11:49:00 +00007401
7402 // Dispatched behavior.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007403 inline uint16_t ExternalAsciiStringGet(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00007404
7405 // Casting.
7406 static inline ExternalAsciiString* cast(Object* obj);
7407
Steve Blockd0582a62009-12-15 09:54:21 +00007408 // Garbage collection support.
Iain Merrick75681382010-08-19 15:07:18 +01007409 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v);
7410
7411 template<typename StaticVisitor>
7412 inline void ExternalAsciiStringIterateBody();
Steve Blockd0582a62009-12-15 09:54:21 +00007413
Steve Blocka7e24c12009-10-30 11:49:00 +00007414 // Support for StringInputBuffer.
7415 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining,
7416 unsigned* offset,
7417 unsigned chars);
7418 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7419 unsigned* offset,
7420 unsigned chars);
7421
Steve Blocka7e24c12009-10-30 11:49:00 +00007422 private:
7423 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString);
7424};
7425
7426
7427// The ExternalTwoByteString class is an external string backed by a UTF-16
7428// encoded string.
7429class ExternalTwoByteString: public ExternalString {
7430 public:
Leon Clarkeac952652010-07-15 11:15:24 +01007431 static const bool kHasAsciiEncoding = false;
7432
Steve Blocka7e24c12009-10-30 11:49:00 +00007433 typedef v8::String::ExternalStringResource Resource;
7434
7435 // The underlying string resource.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007436 inline const Resource* resource();
7437 inline void set_resource(const Resource* buffer);
7438
7439 // Update the pointer cache to the external character array.
7440 // The cached pointer is always valid, as the external character array does =
7441 // not move during lifetime. Deserialization is the only exception, after
7442 // which the pointer cache has to be refreshed.
7443 inline void update_data_cache();
7444
7445 inline const uint16_t* GetChars();
Steve Blocka7e24c12009-10-30 11:49:00 +00007446
7447 // Dispatched behavior.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007448 inline uint16_t ExternalTwoByteStringGet(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00007449
7450 // For regexp code.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007451 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
Steve Blocka7e24c12009-10-30 11:49:00 +00007452
7453 // Casting.
7454 static inline ExternalTwoByteString* cast(Object* obj);
7455
Steve Blockd0582a62009-12-15 09:54:21 +00007456 // Garbage collection support.
Iain Merrick75681382010-08-19 15:07:18 +01007457 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v);
7458
7459 template<typename StaticVisitor>
7460 inline void ExternalTwoByteStringIterateBody();
7461
Steve Blockd0582a62009-12-15 09:54:21 +00007462
Steve Blocka7e24c12009-10-30 11:49:00 +00007463 // Support for StringInputBuffer.
7464 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7465 unsigned* offset_ptr,
7466 unsigned chars);
7467
Steve Blocka7e24c12009-10-30 11:49:00 +00007468 private:
7469 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString);
7470};
7471
7472
7473// Utility superclass for stack-allocated objects that must be updated
7474// on gc. It provides two ways for the gc to update instances, either
7475// iterating or updating after gc.
7476class Relocatable BASE_EMBEDDED {
7477 public:
Steve Block44f0eee2011-05-26 01:26:41 +01007478 explicit inline Relocatable(Isolate* isolate);
7479 inline virtual ~Relocatable();
Steve Blocka7e24c12009-10-30 11:49:00 +00007480 virtual void IterateInstance(ObjectVisitor* v) { }
7481 virtual void PostGarbageCollection() { }
7482
7483 static void PostGarbageCollectionProcessing();
7484 static int ArchiveSpacePerThread();
Ben Murdoch257744e2011-11-30 15:57:28 +00007485 static char* ArchiveState(Isolate* isolate, char* to);
7486 static char* RestoreState(Isolate* isolate, char* from);
Steve Blocka7e24c12009-10-30 11:49:00 +00007487 static void Iterate(ObjectVisitor* v);
7488 static void Iterate(ObjectVisitor* v, Relocatable* top);
7489 static char* Iterate(ObjectVisitor* v, char* t);
7490 private:
Steve Block44f0eee2011-05-26 01:26:41 +01007491 Isolate* isolate_;
Steve Blocka7e24c12009-10-30 11:49:00 +00007492 Relocatable* prev_;
7493};
7494
7495
7496// A flat string reader provides random access to the contents of a
7497// string independent of the character width of the string. The handle
7498// must be valid as long as the reader is being used.
7499class FlatStringReader : public Relocatable {
7500 public:
Steve Block44f0eee2011-05-26 01:26:41 +01007501 FlatStringReader(Isolate* isolate, Handle<String> str);
7502 FlatStringReader(Isolate* isolate, Vector<const char> input);
Steve Blocka7e24c12009-10-30 11:49:00 +00007503 void PostGarbageCollection();
7504 inline uc32 Get(int index);
7505 int length() { return length_; }
7506 private:
7507 String** str_;
7508 bool is_ascii_;
7509 int length_;
7510 const void* start_;
7511};
7512
7513
7514// Note that StringInputBuffers are not valid across a GC! To fix this
7515// it would have to store a String Handle instead of a String* and
7516// AsciiStringReadBlock would have to be modified to use memcpy.
7517//
7518// StringInputBuffer is able to traverse any string regardless of how
7519// deeply nested a sequence of ConsStrings it is made of. However,
7520// performance will be better if deep strings are flattened before they
7521// are traversed. Since flattening requires memory allocation this is
7522// not always desirable, however (esp. in debugging situations).
7523class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> {
7524 public:
7525 virtual void Seek(unsigned pos);
7526 inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {}
Ben Murdoch8b112d22011-06-08 16:22:53 +01007527 explicit inline StringInputBuffer(String* backing):
Steve Blocka7e24c12009-10-30 11:49:00 +00007528 unibrow::InputBuffer<String, String*, 1024>(backing) {}
7529};
7530
7531
7532class SafeStringInputBuffer
7533 : public unibrow::InputBuffer<String, String**, 256> {
7534 public:
7535 virtual void Seek(unsigned pos);
7536 inline SafeStringInputBuffer()
7537 : unibrow::InputBuffer<String, String**, 256>() {}
Ben Murdoch8b112d22011-06-08 16:22:53 +01007538 explicit inline SafeStringInputBuffer(String** backing)
Steve Blocka7e24c12009-10-30 11:49:00 +00007539 : unibrow::InputBuffer<String, String**, 256>(backing) {}
7540};
7541
7542
7543template <typename T>
7544class VectorIterator {
7545 public:
7546 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { }
7547 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { }
7548 T GetNext() { return data_[index_++]; }
7549 bool has_more() { return index_ < data_.length(); }
7550 private:
7551 Vector<const T> data_;
7552 int index_;
7553};
7554
7555
7556// The Oddball describes objects null, undefined, true, and false.
7557class Oddball: public HeapObject {
7558 public:
7559 // [to_string]: Cached to_string computed at startup.
7560 DECL_ACCESSORS(to_string, String)
7561
7562 // [to_number]: Cached to_number computed at startup.
7563 DECL_ACCESSORS(to_number, Object)
7564
Steve Block44f0eee2011-05-26 01:26:41 +01007565 inline byte kind();
7566 inline void set_kind(byte kind);
7567
Steve Blocka7e24c12009-10-30 11:49:00 +00007568 // Casting.
7569 static inline Oddball* cast(Object* obj);
7570
7571 // Dispatched behavior.
Steve Blocka7e24c12009-10-30 11:49:00 +00007572#ifdef DEBUG
7573 void OddballVerify();
7574#endif
7575
7576 // Initialize the fields.
John Reck59135872010-11-02 12:39:01 -07007577 MUST_USE_RESULT MaybeObject* Initialize(const char* to_string,
Steve Block44f0eee2011-05-26 01:26:41 +01007578 Object* to_number,
7579 byte kind);
Steve Blocka7e24c12009-10-30 11:49:00 +00007580
7581 // Layout description.
7582 static const int kToStringOffset = HeapObject::kHeaderSize;
7583 static const int kToNumberOffset = kToStringOffset + kPointerSize;
Steve Block44f0eee2011-05-26 01:26:41 +01007584 static const int kKindOffset = kToNumberOffset + kPointerSize;
7585 static const int kSize = kKindOffset + kPointerSize;
7586
7587 static const byte kFalse = 0;
7588 static const byte kTrue = 1;
7589 static const byte kNotBooleanMask = ~1;
7590 static const byte kTheHole = 2;
7591 static const byte kNull = 3;
7592 static const byte kArgumentMarker = 4;
7593 static const byte kUndefined = 5;
7594 static const byte kOther = 6;
Steve Blocka7e24c12009-10-30 11:49:00 +00007595
Iain Merrick75681382010-08-19 15:07:18 +01007596 typedef FixedBodyDescriptor<kToStringOffset,
7597 kToNumberOffset + kPointerSize,
7598 kSize> BodyDescriptor;
7599
Steve Blocka7e24c12009-10-30 11:49:00 +00007600 private:
7601 DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball);
7602};
7603
7604
7605class JSGlobalPropertyCell: public HeapObject {
7606 public:
7607 // [value]: value of the global property.
7608 DECL_ACCESSORS(value, Object)
7609
7610 // Casting.
7611 static inline JSGlobalPropertyCell* cast(Object* obj);
7612
Steve Blocka7e24c12009-10-30 11:49:00 +00007613#ifdef DEBUG
7614 void JSGlobalPropertyCellVerify();
Ben Murdochb0fe1622011-05-05 13:52:32 +01007615#endif
7616#ifdef OBJECT_PRINT
7617 inline void JSGlobalPropertyCellPrint() {
7618 JSGlobalPropertyCellPrint(stdout);
7619 }
7620 void JSGlobalPropertyCellPrint(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +00007621#endif
7622
7623 // Layout description.
7624 static const int kValueOffset = HeapObject::kHeaderSize;
7625 static const int kSize = kValueOffset + kPointerSize;
7626
Iain Merrick75681382010-08-19 15:07:18 +01007627 typedef FixedBodyDescriptor<kValueOffset,
7628 kValueOffset + kPointerSize,
7629 kSize> BodyDescriptor;
7630
Steve Blocka7e24c12009-10-30 11:49:00 +00007631 private:
7632 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell);
7633};
7634
7635
Ben Murdoch257744e2011-11-30 15:57:28 +00007636// The JSProxy describes EcmaScript Harmony proxies
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007637class JSProxy: public JSReceiver {
Steve Blocka7e24c12009-10-30 11:49:00 +00007638 public:
Ben Murdoch257744e2011-11-30 15:57:28 +00007639 // [handler]: The handler property.
7640 DECL_ACCESSORS(handler, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +00007641
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007642 // [hash]: The hash code property (undefined if not initialized yet).
7643 DECL_ACCESSORS(hash, Object)
7644
Steve Blocka7e24c12009-10-30 11:49:00 +00007645 // Casting.
Ben Murdoch257744e2011-11-30 15:57:28 +00007646 static inline JSProxy* cast(Object* obj);
Steve Blocka7e24c12009-10-30 11:49:00 +00007647
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007648 bool HasPropertyWithHandler(String* name);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007649 bool HasElementWithHandler(uint32_t index);
7650
7651 MUST_USE_RESULT MaybeObject* GetPropertyWithHandler(
7652 Object* receiver,
7653 String* name);
7654 MUST_USE_RESULT MaybeObject* GetElementWithHandler(
7655 Object* receiver,
7656 uint32_t index);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007657
7658 MUST_USE_RESULT MaybeObject* SetPropertyWithHandler(
7659 String* name,
7660 Object* value,
7661 PropertyAttributes attributes,
7662 StrictModeFlag strict_mode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007663 MUST_USE_RESULT MaybeObject* SetElementWithHandler(
7664 uint32_t index,
7665 Object* value,
7666 StrictModeFlag strict_mode);
7667
7668 // If the handler defines an accessor property, invoke its setter
7669 // (or throw if only a getter exists) and set *found to true. Otherwise false.
7670 MUST_USE_RESULT MaybeObject* SetPropertyWithHandlerIfDefiningSetter(
7671 String* name,
7672 Object* value,
7673 PropertyAttributes attributes,
7674 StrictModeFlag strict_mode,
7675 bool* found);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007676
7677 MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler(
7678 String* name,
7679 DeleteMode mode);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007680 MUST_USE_RESULT MaybeObject* DeleteElementWithHandler(
7681 uint32_t index,
7682 DeleteMode mode);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007683
7684 MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler(
7685 JSReceiver* receiver,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007686 String* name);
7687 MUST_USE_RESULT PropertyAttributes GetElementAttributeWithHandler(
7688 JSReceiver* receiver,
7689 uint32_t index);
7690
7691 MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007692
7693 // Turn this into an (empty) JSObject.
7694 void Fix();
7695
Ben Murdoch589d6972011-11-30 16:04:58 +00007696 // Initializes the body after the handler slot.
7697 inline void InitializeBody(int object_size, Object* value);
7698
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007699 // Invoke a trap by name. If the trap does not exist on this's handler,
7700 // but derived_trap is non-NULL, invoke that instead. May cause GC.
7701 Handle<Object> CallTrap(const char* name,
7702 Handle<Object> derived_trap,
7703 int argc,
7704 Handle<Object> args[]);
7705
Steve Blocka7e24c12009-10-30 11:49:00 +00007706 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01007707#ifdef OBJECT_PRINT
Ben Murdoch257744e2011-11-30 15:57:28 +00007708 inline void JSProxyPrint() {
7709 JSProxyPrint(stdout);
Ben Murdochb0fe1622011-05-05 13:52:32 +01007710 }
Ben Murdoch257744e2011-11-30 15:57:28 +00007711 void JSProxyPrint(FILE* out);
Ben Murdochb0fe1622011-05-05 13:52:32 +01007712#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00007713#ifdef DEBUG
Ben Murdoch257744e2011-11-30 15:57:28 +00007714 void JSProxyVerify();
7715#endif
7716
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007717 // Layout description. We add padding so that a proxy has the same
7718 // size as a virgin JSObject. This is essential for becoming a JSObject
7719 // upon freeze.
Ben Murdoch257744e2011-11-30 15:57:28 +00007720 static const int kHandlerOffset = HeapObject::kHeaderSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007721 static const int kHashOffset = kHandlerOffset + kPointerSize;
7722 static const int kPaddingOffset = kHashOffset + kPointerSize;
Ben Murdoch589d6972011-11-30 16:04:58 +00007723 static const int kSize = JSObject::kHeaderSize;
7724 static const int kHeaderSize = kPaddingOffset;
7725 static const int kPaddingSize = kSize - kPaddingOffset;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007726
Ben Murdoch589d6972011-11-30 16:04:58 +00007727 STATIC_CHECK(kPaddingSize >= 0);
Ben Murdoch257744e2011-11-30 15:57:28 +00007728
7729 typedef FixedBodyDescriptor<kHandlerOffset,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007730 kPaddingOffset,
Ben Murdoch257744e2011-11-30 15:57:28 +00007731 kSize> BodyDescriptor;
7732
7733 private:
7734 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
7735};
7736
7737
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007738class JSFunctionProxy: public JSProxy {
7739 public:
Ben Murdoch589d6972011-11-30 16:04:58 +00007740 // [call_trap]: The call trap.
7741 DECL_ACCESSORS(call_trap, Object)
7742
7743 // [construct_trap]: The construct trap.
7744 DECL_ACCESSORS(construct_trap, Object)
7745
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007746 // Casting.
7747 static inline JSFunctionProxy* cast(Object* obj);
7748
Ben Murdoch589d6972011-11-30 16:04:58 +00007749 // Dispatched behavior.
7750#ifdef OBJECT_PRINT
7751 inline void JSFunctionProxyPrint() {
7752 JSFunctionProxyPrint(stdout);
7753 }
7754 void JSFunctionProxyPrint(FILE* out);
7755#endif
7756#ifdef DEBUG
7757 void JSFunctionProxyVerify();
7758#endif
7759
7760 // Layout description.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007761 static const int kCallTrapOffset = JSProxy::kPaddingOffset;
Ben Murdoch589d6972011-11-30 16:04:58 +00007762 static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize;
7763 static const int kPaddingOffset = kConstructTrapOffset + kPointerSize;
7764 static const int kSize = JSFunction::kSize;
7765 static const int kPaddingSize = kSize - kPaddingOffset;
7766
7767 STATIC_CHECK(kPaddingSize >= 0);
7768
7769 typedef FixedBodyDescriptor<kHandlerOffset,
7770 kConstructTrapOffset + kPointerSize,
7771 kSize> BodyDescriptor;
7772
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007773 private:
7774 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy);
7775};
7776
Ben Murdoch257744e2011-11-30 15:57:28 +00007777
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007778// The JSSet describes EcmaScript Harmony sets
7779class JSSet: public JSObject {
7780 public:
7781 // [set]: the backing hash set containing keys.
7782 DECL_ACCESSORS(table, Object)
7783
7784 // Casting.
7785 static inline JSSet* cast(Object* obj);
7786
7787#ifdef OBJECT_PRINT
7788 inline void JSSetPrint() {
7789 JSSetPrint(stdout);
7790 }
7791 void JSSetPrint(FILE* out);
7792#endif
7793#ifdef DEBUG
7794 void JSSetVerify();
7795#endif
7796
7797 static const int kTableOffset = JSObject::kHeaderSize;
7798 static const int kSize = kTableOffset + kPointerSize;
7799
7800 private:
7801 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet);
7802};
7803
7804
7805// The JSMap describes EcmaScript Harmony maps
7806class JSMap: public JSObject {
7807 public:
7808 // [table]: the backing hash table mapping keys to values.
7809 DECL_ACCESSORS(table, Object)
7810
7811 // Casting.
7812 static inline JSMap* cast(Object* obj);
7813
7814#ifdef OBJECT_PRINT
7815 inline void JSMapPrint() {
7816 JSMapPrint(stdout);
7817 }
7818 void JSMapPrint(FILE* out);
7819#endif
7820#ifdef DEBUG
7821 void JSMapVerify();
7822#endif
7823
7824 static const int kTableOffset = JSObject::kHeaderSize;
7825 static const int kSize = kTableOffset + kPointerSize;
7826
7827 private:
7828 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
7829};
7830
7831
Ben Murdoch69a99ed2011-11-30 16:03:39 +00007832// The JSWeakMap describes EcmaScript Harmony weak maps
7833class JSWeakMap: public JSObject {
7834 public:
7835 // [table]: the backing hash table mapping keys to values.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007836 DECL_ACCESSORS(table, Object)
Ben Murdoch69a99ed2011-11-30 16:03:39 +00007837
7838 // [next]: linked list of encountered weak maps during GC.
7839 DECL_ACCESSORS(next, Object)
7840
Ben Murdoch69a99ed2011-11-30 16:03:39 +00007841 // Casting.
7842 static inline JSWeakMap* cast(Object* obj);
7843
7844#ifdef OBJECT_PRINT
7845 inline void JSWeakMapPrint() {
7846 JSWeakMapPrint(stdout);
7847 }
7848 void JSWeakMapPrint(FILE* out);
7849#endif
7850#ifdef DEBUG
7851 void JSWeakMapVerify();
7852#endif
7853
7854 static const int kTableOffset = JSObject::kHeaderSize;
7855 static const int kNextOffset = kTableOffset + kPointerSize;
7856 static const int kSize = kNextOffset + kPointerSize;
7857
7858 private:
7859 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap);
7860};
7861
7862
Ben Murdoch257744e2011-11-30 15:57:28 +00007863// Foreign describes objects pointing from JavaScript to C structures.
7864// Since they cannot contain references to JS HeapObjects they can be
7865// placed in old_data_space.
7866class Foreign: public HeapObject {
7867 public:
7868 // [address]: field containing the address.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007869 inline Address foreign_address();
7870 inline void set_foreign_address(Address value);
Ben Murdoch257744e2011-11-30 15:57:28 +00007871
7872 // Casting.
7873 static inline Foreign* cast(Object* obj);
7874
7875 // Dispatched behavior.
7876 inline void ForeignIterateBody(ObjectVisitor* v);
7877
7878 template<typename StaticVisitor>
7879 inline void ForeignIterateBody();
7880
7881#ifdef OBJECT_PRINT
7882 inline void ForeignPrint() {
7883 ForeignPrint(stdout);
7884 }
7885 void ForeignPrint(FILE* out);
7886#endif
7887#ifdef DEBUG
7888 void ForeignVerify();
Steve Blocka7e24c12009-10-30 11:49:00 +00007889#endif
7890
7891 // Layout description.
7892
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007893 static const int kForeignAddressOffset = HeapObject::kHeaderSize;
7894 static const int kSize = kForeignAddressOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00007895
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007896 STATIC_CHECK(kForeignAddressOffset == Internals::kForeignAddressOffset);
Steve Blocka7e24c12009-10-30 11:49:00 +00007897
7898 private:
Ben Murdoch257744e2011-11-30 15:57:28 +00007899 DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign);
Steve Blocka7e24c12009-10-30 11:49:00 +00007900};
7901
7902
7903// The JSArray describes JavaScript Arrays
7904// Such an array can be in one of two modes:
7905// - fast, backing storage is a FixedArray and length <= elements.length();
7906// Please note: push and pop can be used to grow and shrink the array.
7907// - slow, backing storage is a HashTable with numbers as keys.
7908class JSArray: public JSObject {
7909 public:
7910 // [length]: The length property.
7911 DECL_ACCESSORS(length, Object)
7912
Leon Clarke4515c472010-02-03 11:58:03 +00007913 // Overload the length setter to skip write barrier when the length
7914 // is set to a smi. This matches the set function on FixedArray.
7915 inline void set_length(Smi* length);
7916
John Reck59135872010-11-02 12:39:01 -07007917 MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index,
7918 Object* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00007919
7920 // Initialize the array with the given capacity. The function may
7921 // fail due to out-of-memory situations, but only if the requested
7922 // capacity is non-zero.
John Reck59135872010-11-02 12:39:01 -07007923 MUST_USE_RESULT MaybeObject* Initialize(int capacity);
Steve Blocka7e24c12009-10-30 11:49:00 +00007924
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007925 // Initializes the array to a certain length.
7926 inline bool AllowsSetElementsLength();
7927 MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length);
7928
Steve Blocka7e24c12009-10-30 11:49:00 +00007929 // Set the content of the array to the content of storage.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007930 MUST_USE_RESULT inline MaybeObject* SetContent(FixedArrayBase* storage);
Steve Blocka7e24c12009-10-30 11:49:00 +00007931
7932 // Casting.
7933 static inline JSArray* cast(Object* obj);
7934
7935 // Uses handles. Ensures that the fixed array backing the JSArray has at
7936 // least the stated size.
7937 inline void EnsureSize(int minimum_size_of_backing_fixed_array);
7938
7939 // Dispatched behavior.
Ben Murdochb0fe1622011-05-05 13:52:32 +01007940#ifdef OBJECT_PRINT
7941 inline void JSArrayPrint() {
7942 JSArrayPrint(stdout);
7943 }
7944 void JSArrayPrint(FILE* out);
7945#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00007946#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00007947 void JSArrayVerify();
7948#endif
7949
7950 // Number of element slots to pre-allocate for an empty array.
7951 static const int kPreallocatedArrayElements = 4;
7952
7953 // Layout description.
7954 static const int kLengthOffset = JSObject::kHeaderSize;
7955 static const int kSize = kLengthOffset + kPointerSize;
7956
7957 private:
7958 // Expand the fixed array backing of a fast-case JSArray to at least
7959 // the requested size.
7960 void Expand(int minimum_size_of_backing_fixed_array);
7961
7962 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
7963};
7964
7965
Steve Block6ded16b2010-05-10 14:33:55 +01007966// JSRegExpResult is just a JSArray with a specific initial map.
7967// This initial map adds in-object properties for "index" and "input"
7968// properties, as assigned by RegExp.prototype.exec, which allows
7969// faster creation of RegExp exec results.
7970// This class just holds constants used when creating the result.
7971// After creation the result must be treated as a JSArray in all regards.
7972class JSRegExpResult: public JSArray {
7973 public:
7974 // Offsets of object fields.
7975 static const int kIndexOffset = JSArray::kSize;
7976 static const int kInputOffset = kIndexOffset + kPointerSize;
7977 static const int kSize = kInputOffset + kPointerSize;
7978 // Indices of in-object properties.
7979 static const int kIndexIndex = 0;
7980 static const int kInputIndex = 1;
7981 private:
7982 DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult);
7983};
7984
7985
Steve Blocka7e24c12009-10-30 11:49:00 +00007986// An accessor must have a getter, but can have no setter.
7987//
7988// When setting a property, V8 searches accessors in prototypes.
7989// If an accessor was found and it does not have a setter,
7990// the request is ignored.
7991//
7992// If the accessor in the prototype has the READ_ONLY property attribute, then
7993// a new value is added to the local object when the property is set.
7994// This shadows the accessor in the prototype.
7995class AccessorInfo: public Struct {
7996 public:
7997 DECL_ACCESSORS(getter, Object)
7998 DECL_ACCESSORS(setter, Object)
7999 DECL_ACCESSORS(data, Object)
8000 DECL_ACCESSORS(name, Object)
8001 DECL_ACCESSORS(flag, Smi)
8002
8003 inline bool all_can_read();
8004 inline void set_all_can_read(bool value);
8005
8006 inline bool all_can_write();
8007 inline void set_all_can_write(bool value);
8008
8009 inline bool prohibits_overwriting();
8010 inline void set_prohibits_overwriting(bool value);
8011
8012 inline PropertyAttributes property_attributes();
8013 inline void set_property_attributes(PropertyAttributes attributes);
8014
8015 static inline AccessorInfo* cast(Object* obj);
8016
Ben Murdochb0fe1622011-05-05 13:52:32 +01008017#ifdef OBJECT_PRINT
8018 inline void AccessorInfoPrint() {
8019 AccessorInfoPrint(stdout);
8020 }
8021 void AccessorInfoPrint(FILE* out);
8022#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008023#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008024 void AccessorInfoVerify();
8025#endif
8026
8027 static const int kGetterOffset = HeapObject::kHeaderSize;
8028 static const int kSetterOffset = kGetterOffset + kPointerSize;
8029 static const int kDataOffset = kSetterOffset + kPointerSize;
8030 static const int kNameOffset = kDataOffset + kPointerSize;
8031 static const int kFlagOffset = kNameOffset + kPointerSize;
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08008032 static const int kSize = kFlagOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00008033
8034 private:
8035 // Bit positions in flag.
8036 static const int kAllCanReadBit = 0;
8037 static const int kAllCanWriteBit = 1;
8038 static const int kProhibitsOverwritingBit = 2;
8039 class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
8040
8041 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo);
8042};
8043
8044
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008045// Support for JavaScript accessors: A pair of a getter and a setter. Each
8046// accessor can either be
8047// * a pointer to a JavaScript function or proxy: a real accessor
8048// * undefined: considered an accessor by the spec, too, strangely enough
8049// * the hole: an accessor which has not been set
8050// * a pointer to a map: a transition used to ensure map sharing
8051class AccessorPair: public Struct {
8052 public:
8053 DECL_ACCESSORS(getter, Object)
8054 DECL_ACCESSORS(setter, Object)
8055
8056 static inline AccessorPair* cast(Object* obj);
8057
8058 MUST_USE_RESULT MaybeObject* CopyWithoutTransitions();
8059
8060 // Note: Returns undefined instead in case of a hole.
8061 Object* GetComponent(AccessorComponent component);
8062
8063 // Set both components, skipping arguments which are a JavaScript null.
8064 void SetComponents(Object* getter, Object* setter) {
8065 if (!getter->IsNull()) set_getter(getter);
8066 if (!setter->IsNull()) set_setter(setter);
8067 }
8068
8069 bool ContainsAccessor() {
8070 return IsJSAccessor(getter()) || IsJSAccessor(setter());
8071 }
8072
8073#ifdef OBJECT_PRINT
8074 void AccessorPairPrint(FILE* out = stdout);
8075#endif
8076#ifdef DEBUG
8077 void AccessorPairVerify();
8078#endif
8079
8080 static const int kGetterOffset = HeapObject::kHeaderSize;
8081 static const int kSetterOffset = kGetterOffset + kPointerSize;
8082 static const int kSize = kSetterOffset + kPointerSize;
8083
8084 private:
8085 // Strangely enough, in addition to functions and harmony proxies, the spec
8086 // requires us to consider undefined as a kind of accessor, too:
8087 // var obj = {};
8088 // Object.defineProperty(obj, "foo", {get: undefined});
8089 // assertTrue("foo" in obj);
8090 bool IsJSAccessor(Object* obj) {
8091 return obj->IsSpecFunction() || obj->IsUndefined();
8092 }
8093
8094 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair);
8095};
8096
8097
Steve Blocka7e24c12009-10-30 11:49:00 +00008098class AccessCheckInfo: public Struct {
8099 public:
8100 DECL_ACCESSORS(named_callback, Object)
8101 DECL_ACCESSORS(indexed_callback, Object)
8102 DECL_ACCESSORS(data, Object)
8103
8104 static inline AccessCheckInfo* cast(Object* obj);
8105
Ben Murdochb0fe1622011-05-05 13:52:32 +01008106#ifdef OBJECT_PRINT
8107 inline void AccessCheckInfoPrint() {
8108 AccessCheckInfoPrint(stdout);
8109 }
8110 void AccessCheckInfoPrint(FILE* out);
8111#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008112#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008113 void AccessCheckInfoVerify();
8114#endif
8115
8116 static const int kNamedCallbackOffset = HeapObject::kHeaderSize;
8117 static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize;
8118 static const int kDataOffset = kIndexedCallbackOffset + kPointerSize;
8119 static const int kSize = kDataOffset + kPointerSize;
8120
8121 private:
8122 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo);
8123};
8124
8125
8126class InterceptorInfo: public Struct {
8127 public:
8128 DECL_ACCESSORS(getter, Object)
8129 DECL_ACCESSORS(setter, Object)
8130 DECL_ACCESSORS(query, Object)
8131 DECL_ACCESSORS(deleter, Object)
8132 DECL_ACCESSORS(enumerator, Object)
8133 DECL_ACCESSORS(data, Object)
8134
8135 static inline InterceptorInfo* cast(Object* obj);
8136
Ben Murdochb0fe1622011-05-05 13:52:32 +01008137#ifdef OBJECT_PRINT
8138 inline void InterceptorInfoPrint() {
8139 InterceptorInfoPrint(stdout);
8140 }
8141 void InterceptorInfoPrint(FILE* out);
8142#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008143#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008144 void InterceptorInfoVerify();
8145#endif
8146
8147 static const int kGetterOffset = HeapObject::kHeaderSize;
8148 static const int kSetterOffset = kGetterOffset + kPointerSize;
8149 static const int kQueryOffset = kSetterOffset + kPointerSize;
8150 static const int kDeleterOffset = kQueryOffset + kPointerSize;
8151 static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
8152 static const int kDataOffset = kEnumeratorOffset + kPointerSize;
8153 static const int kSize = kDataOffset + kPointerSize;
8154
8155 private:
8156 DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
8157};
8158
8159
8160class CallHandlerInfo: public Struct {
8161 public:
8162 DECL_ACCESSORS(callback, Object)
8163 DECL_ACCESSORS(data, Object)
8164
8165 static inline CallHandlerInfo* cast(Object* obj);
8166
Ben Murdochb0fe1622011-05-05 13:52:32 +01008167#ifdef OBJECT_PRINT
8168 inline void CallHandlerInfoPrint() {
8169 CallHandlerInfoPrint(stdout);
8170 }
8171 void CallHandlerInfoPrint(FILE* out);
8172#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008173#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008174 void CallHandlerInfoVerify();
8175#endif
8176
8177 static const int kCallbackOffset = HeapObject::kHeaderSize;
8178 static const int kDataOffset = kCallbackOffset + kPointerSize;
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -08008179 static const int kSize = kDataOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00008180
8181 private:
8182 DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
8183};
8184
8185
8186class TemplateInfo: public Struct {
8187 public:
8188 DECL_ACCESSORS(tag, Object)
8189 DECL_ACCESSORS(property_list, Object)
8190
8191#ifdef DEBUG
8192 void TemplateInfoVerify();
8193#endif
8194
8195 static const int kTagOffset = HeapObject::kHeaderSize;
8196 static const int kPropertyListOffset = kTagOffset + kPointerSize;
8197 static const int kHeaderSize = kPropertyListOffset + kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008198
8199 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00008200 DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
8201};
8202
8203
8204class FunctionTemplateInfo: public TemplateInfo {
8205 public:
8206 DECL_ACCESSORS(serial_number, Object)
8207 DECL_ACCESSORS(call_code, Object)
8208 DECL_ACCESSORS(property_accessors, Object)
8209 DECL_ACCESSORS(prototype_template, Object)
8210 DECL_ACCESSORS(parent_template, Object)
8211 DECL_ACCESSORS(named_property_handler, Object)
8212 DECL_ACCESSORS(indexed_property_handler, Object)
8213 DECL_ACCESSORS(instance_template, Object)
8214 DECL_ACCESSORS(class_name, Object)
8215 DECL_ACCESSORS(signature, Object)
8216 DECL_ACCESSORS(instance_call_handler, Object)
8217 DECL_ACCESSORS(access_check_info, Object)
8218 DECL_ACCESSORS(flag, Smi)
8219
8220 // Following properties use flag bits.
8221 DECL_BOOLEAN_ACCESSORS(hidden_prototype)
8222 DECL_BOOLEAN_ACCESSORS(undetectable)
8223 // If the bit is set, object instances created by this function
8224 // requires access check.
8225 DECL_BOOLEAN_ACCESSORS(needs_access_check)
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008226 DECL_BOOLEAN_ACCESSORS(read_only_prototype)
Steve Blocka7e24c12009-10-30 11:49:00 +00008227
8228 static inline FunctionTemplateInfo* cast(Object* obj);
8229
Ben Murdochb0fe1622011-05-05 13:52:32 +01008230#ifdef OBJECT_PRINT
8231 inline void FunctionTemplateInfoPrint() {
8232 FunctionTemplateInfoPrint(stdout);
8233 }
8234 void FunctionTemplateInfoPrint(FILE* out);
8235#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008236#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008237 void FunctionTemplateInfoVerify();
8238#endif
8239
8240 static const int kSerialNumberOffset = TemplateInfo::kHeaderSize;
8241 static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize;
8242 static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize;
8243 static const int kPrototypeTemplateOffset =
8244 kPropertyAccessorsOffset + kPointerSize;
8245 static const int kParentTemplateOffset =
8246 kPrototypeTemplateOffset + kPointerSize;
8247 static const int kNamedPropertyHandlerOffset =
8248 kParentTemplateOffset + kPointerSize;
8249 static const int kIndexedPropertyHandlerOffset =
8250 kNamedPropertyHandlerOffset + kPointerSize;
8251 static const int kInstanceTemplateOffset =
8252 kIndexedPropertyHandlerOffset + kPointerSize;
8253 static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
8254 static const int kSignatureOffset = kClassNameOffset + kPointerSize;
8255 static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
8256 static const int kAccessCheckInfoOffset =
8257 kInstanceCallHandlerOffset + kPointerSize;
8258 static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008259 static const int kSize = kFlagOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00008260
8261 private:
8262 // Bit position in the flag, from least significant bit position.
8263 static const int kHiddenPrototypeBit = 0;
8264 static const int kUndetectableBit = 1;
8265 static const int kNeedsAccessCheckBit = 2;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008266 static const int kReadOnlyPrototypeBit = 3;
Steve Blocka7e24c12009-10-30 11:49:00 +00008267
8268 DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
8269};
8270
8271
8272class ObjectTemplateInfo: public TemplateInfo {
8273 public:
8274 DECL_ACCESSORS(constructor, Object)
8275 DECL_ACCESSORS(internal_field_count, Object)
8276
8277 static inline ObjectTemplateInfo* cast(Object* obj);
8278
Ben Murdochb0fe1622011-05-05 13:52:32 +01008279#ifdef OBJECT_PRINT
8280 inline void ObjectTemplateInfoPrint() {
8281 ObjectTemplateInfoPrint(stdout);
8282 }
8283 void ObjectTemplateInfoPrint(FILE* out);
8284#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008285#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008286 void ObjectTemplateInfoVerify();
8287#endif
8288
8289 static const int kConstructorOffset = TemplateInfo::kHeaderSize;
8290 static const int kInternalFieldCountOffset =
8291 kConstructorOffset + kPointerSize;
8292 static const int kSize = kInternalFieldCountOffset + kPointerSize;
8293};
8294
8295
8296class SignatureInfo: public Struct {
8297 public:
8298 DECL_ACCESSORS(receiver, Object)
8299 DECL_ACCESSORS(args, Object)
8300
8301 static inline SignatureInfo* cast(Object* obj);
8302
Ben Murdochb0fe1622011-05-05 13:52:32 +01008303#ifdef OBJECT_PRINT
8304 inline void SignatureInfoPrint() {
8305 SignatureInfoPrint(stdout);
8306 }
8307 void SignatureInfoPrint(FILE* out);
8308#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008309#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008310 void SignatureInfoVerify();
8311#endif
8312
8313 static const int kReceiverOffset = Struct::kHeaderSize;
8314 static const int kArgsOffset = kReceiverOffset + kPointerSize;
8315 static const int kSize = kArgsOffset + kPointerSize;
8316
8317 private:
8318 DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo);
8319};
8320
8321
8322class TypeSwitchInfo: public Struct {
8323 public:
8324 DECL_ACCESSORS(types, Object)
8325
8326 static inline TypeSwitchInfo* cast(Object* obj);
8327
Ben Murdochb0fe1622011-05-05 13:52:32 +01008328#ifdef OBJECT_PRINT
8329 inline void TypeSwitchInfoPrint() {
8330 TypeSwitchInfoPrint(stdout);
8331 }
8332 void TypeSwitchInfoPrint(FILE* out);
8333#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008334#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008335 void TypeSwitchInfoVerify();
8336#endif
8337
8338 static const int kTypesOffset = Struct::kHeaderSize;
8339 static const int kSize = kTypesOffset + kPointerSize;
8340};
8341
8342
8343#ifdef ENABLE_DEBUGGER_SUPPORT
8344// The DebugInfo class holds additional information for a function being
8345// debugged.
8346class DebugInfo: public Struct {
8347 public:
8348 // The shared function info for the source being debugged.
8349 DECL_ACCESSORS(shared, SharedFunctionInfo)
8350 // Code object for the original code.
8351 DECL_ACCESSORS(original_code, Code)
8352 // Code object for the patched code. This code object is the code object
8353 // currently active for the function.
8354 DECL_ACCESSORS(code, Code)
8355 // Fixed array holding status information for each active break point.
8356 DECL_ACCESSORS(break_points, FixedArray)
8357
8358 // Check if there is a break point at a code position.
8359 bool HasBreakPoint(int code_position);
8360 // Get the break point info object for a code position.
8361 Object* GetBreakPointInfo(int code_position);
8362 // Clear a break point.
8363 static void ClearBreakPoint(Handle<DebugInfo> debug_info,
8364 int code_position,
8365 Handle<Object> break_point_object);
8366 // Set a break point.
8367 static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position,
8368 int source_position, int statement_position,
8369 Handle<Object> break_point_object);
8370 // Get the break point objects for a code position.
8371 Object* GetBreakPointObjects(int code_position);
8372 // Find the break point info holding this break point object.
8373 static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info,
8374 Handle<Object> break_point_object);
8375 // Get the number of break points for this function.
8376 int GetBreakPointCount();
8377
8378 static inline DebugInfo* cast(Object* obj);
8379
Ben Murdochb0fe1622011-05-05 13:52:32 +01008380#ifdef OBJECT_PRINT
8381 inline void DebugInfoPrint() {
8382 DebugInfoPrint(stdout);
8383 }
8384 void DebugInfoPrint(FILE* out);
8385#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008386#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008387 void DebugInfoVerify();
8388#endif
8389
8390 static const int kSharedFunctionInfoIndex = Struct::kHeaderSize;
8391 static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize;
8392 static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize;
8393 static const int kActiveBreakPointsCountIndex =
8394 kPatchedCodeIndex + kPointerSize;
8395 static const int kBreakPointsStateIndex =
8396 kActiveBreakPointsCountIndex + kPointerSize;
8397 static const int kSize = kBreakPointsStateIndex + kPointerSize;
8398
8399 private:
8400 static const int kNoBreakPointInfo = -1;
8401
8402 // Lookup the index in the break_points array for a code position.
8403 int GetBreakPointInfoIndex(int code_position);
8404
8405 DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo);
8406};
8407
8408
8409// The BreakPointInfo class holds information for break points set in a
8410// function. The DebugInfo object holds a BreakPointInfo object for each code
8411// position with one or more break points.
8412class BreakPointInfo: public Struct {
8413 public:
8414 // The position in the code for the break point.
8415 DECL_ACCESSORS(code_position, Smi)
8416 // The position in the source for the break position.
8417 DECL_ACCESSORS(source_position, Smi)
8418 // The position in the source for the last statement before this break
8419 // position.
8420 DECL_ACCESSORS(statement_position, Smi)
8421 // List of related JavaScript break points.
8422 DECL_ACCESSORS(break_point_objects, Object)
8423
8424 // Removes a break point.
8425 static void ClearBreakPoint(Handle<BreakPointInfo> info,
8426 Handle<Object> break_point_object);
8427 // Set a break point.
8428 static void SetBreakPoint(Handle<BreakPointInfo> info,
8429 Handle<Object> break_point_object);
8430 // Check if break point info has this break point object.
8431 static bool HasBreakPointObject(Handle<BreakPointInfo> info,
8432 Handle<Object> break_point_object);
8433 // Get the number of break points for this code position.
8434 int GetBreakPointCount();
8435
8436 static inline BreakPointInfo* cast(Object* obj);
8437
Ben Murdochb0fe1622011-05-05 13:52:32 +01008438#ifdef OBJECT_PRINT
8439 inline void BreakPointInfoPrint() {
8440 BreakPointInfoPrint(stdout);
8441 }
8442 void BreakPointInfoPrint(FILE* out);
8443#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00008444#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00008445 void BreakPointInfoVerify();
8446#endif
8447
8448 static const int kCodePositionIndex = Struct::kHeaderSize;
8449 static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize;
8450 static const int kStatementPositionIndex =
8451 kSourcePositionIndex + kPointerSize;
8452 static const int kBreakPointObjectsIndex =
8453 kStatementPositionIndex + kPointerSize;
8454 static const int kSize = kBreakPointObjectsIndex + kPointerSize;
8455
8456 private:
8457 DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo);
8458};
8459#endif // ENABLE_DEBUGGER_SUPPORT
8460
8461
8462#undef DECL_BOOLEAN_ACCESSORS
8463#undef DECL_ACCESSORS
8464
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008465#define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \
8466 V(kSymbolTable, "symbol_table", "(Symbols)") \
8467 V(kExternalStringsTable, "external_strings_table", "(External strings)") \
8468 V(kStrongRootList, "strong_root_list", "(Strong roots)") \
8469 V(kSymbol, "symbol", "(Symbol)") \
8470 V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \
8471 V(kTop, "top", "(Isolate)") \
8472 V(kRelocatable, "relocatable", "(Relocatable)") \
8473 V(kDebug, "debug", "(Debugger)") \
8474 V(kCompilationCache, "compilationcache", "(Compilation cache)") \
8475 V(kHandleScope, "handlescope", "(Handle scope)") \
8476 V(kBuiltins, "builtins", "(Builtins)") \
8477 V(kGlobalHandles, "globalhandles", "(Global handles)") \
8478 V(kThreadManager, "threadmanager", "(Thread manager)") \
8479 V(kExtensions, "Extensions", "(Extensions)")
8480
8481class VisitorSynchronization : public AllStatic {
8482 public:
8483#define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item,
8484 enum SyncTag {
8485 VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM)
8486 kNumberOfSyncTags
8487 };
8488#undef DECLARE_ENUM
8489
8490 static const char* const kTags[kNumberOfSyncTags];
8491 static const char* const kTagNames[kNumberOfSyncTags];
8492};
Steve Blocka7e24c12009-10-30 11:49:00 +00008493
8494// Abstract base class for visiting, and optionally modifying, the
8495// pointers contained in Objects. Used in GC and serialization/deserialization.
8496class ObjectVisitor BASE_EMBEDDED {
8497 public:
8498 virtual ~ObjectVisitor() {}
8499
8500 // Visits a contiguous arrays of pointers in the half-open range
8501 // [start, end). Any or all of the values may be modified on return.
8502 virtual void VisitPointers(Object** start, Object** end) = 0;
8503
8504 // To allow lazy clearing of inline caches the visitor has
8505 // a rich interface for iterating over Code objects..
8506
8507 // Visits a code target in the instruction stream.
8508 virtual void VisitCodeTarget(RelocInfo* rinfo);
8509
Steve Block791712a2010-08-27 10:21:07 +01008510 // Visits a code entry in a JS function.
8511 virtual void VisitCodeEntry(Address entry_address);
8512
Ben Murdochb0fe1622011-05-05 13:52:32 +01008513 // Visits a global property cell reference in the instruction stream.
8514 virtual void VisitGlobalPropertyCell(RelocInfo* rinfo);
8515
Steve Blocka7e24c12009-10-30 11:49:00 +00008516 // Visits a runtime entry in the instruction stream.
8517 virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
8518
Steve Blockd0582a62009-12-15 09:54:21 +00008519 // Visits the resource of an ASCII or two-byte string.
8520 virtual void VisitExternalAsciiString(
8521 v8::String::ExternalAsciiStringResource** resource) {}
8522 virtual void VisitExternalTwoByteString(
8523 v8::String::ExternalStringResource** resource) {}
8524
Steve Blocka7e24c12009-10-30 11:49:00 +00008525 // Visits a debug call target in the instruction stream.
8526 virtual void VisitDebugTarget(RelocInfo* rinfo);
8527
8528 // Handy shorthand for visiting a single pointer.
8529 virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); }
8530
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008531 // Visit pointer embedded into a code object.
8532 virtual void VisitEmbeddedPointer(RelocInfo* rinfo);
8533
Steve Blocka7e24c12009-10-30 11:49:00 +00008534 // Visits a contiguous arrays of external references (references to the C++
8535 // heap) in the half-open range [start, end). Any or all of the values
8536 // may be modified on return.
8537 virtual void VisitExternalReferences(Address* start, Address* end) {}
8538
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008539 virtual void VisitExternalReference(RelocInfo* rinfo);
8540
Steve Blocka7e24c12009-10-30 11:49:00 +00008541 inline void VisitExternalReference(Address* p) {
8542 VisitExternalReferences(p, p + 1);
8543 }
8544
Steve Block44f0eee2011-05-26 01:26:41 +01008545 // Visits a handle that has an embedder-assigned class ID.
8546 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {}
8547
Steve Blocka7e24c12009-10-30 11:49:00 +00008548 // Intended for serialization/deserialization checking: insert, or
8549 // check for the presence of, a tag at this position in the stream.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008550 // Also used for marking up GC roots in heap snapshots.
8551 virtual void Synchronize(VisitorSynchronization::SyncTag tag) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00008552};
8553
8554
Iain Merrick75681382010-08-19 15:07:18 +01008555class StructBodyDescriptor : public
8556 FlexibleBodyDescriptor<HeapObject::kHeaderSize> {
8557 public:
8558 static inline int SizeOf(Map* map, HeapObject* object) {
8559 return map->instance_size();
8560 }
8561};
8562
8563
Steve Blocka7e24c12009-10-30 11:49:00 +00008564// BooleanBit is a helper class for setting and getting a bit in an
8565// integer or Smi.
8566class BooleanBit : public AllStatic {
8567 public:
8568 static inline bool get(Smi* smi, int bit_position) {
8569 return get(smi->value(), bit_position);
8570 }
8571
8572 static inline bool get(int value, int bit_position) {
8573 return (value & (1 << bit_position)) != 0;
8574 }
8575
8576 static inline Smi* set(Smi* smi, int bit_position, bool v) {
8577 return Smi::FromInt(set(smi->value(), bit_position, v));
8578 }
8579
8580 static inline int set(int value, int bit_position, bool v) {
8581 if (v) {
8582 value |= (1 << bit_position);
8583 } else {
8584 value &= ~(1 << bit_position);
8585 }
8586 return value;
8587 }
8588};
8589
8590} } // namespace v8::internal
8591
8592#endif // V8_OBJECTS_H_