blob: 274f1dccae9ec19980bea3be09cced6db9b4ac1c [file] [log] [blame]
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001// Copyright 2012 the V8 project authors. All rights reserved.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_OBJECTS_H_
29#define V8_OBJECTS_H_
30
lrn@chromium.org1c092762011-05-09 09:42:16 +000031#include "allocation.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000032#include "builtins.h"
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +000033#include "elements-kind.h"
ager@chromium.orgea91cc52011-05-23 06:06:11 +000034#include "list.h"
danno@chromium.orgc612e022011-11-10 11:38:15 +000035#include "property-details.h"
kmillikin@chromium.org83e16822011-09-13 08:21:47 +000036#include "smart-array-pointer.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000037#include "unicode-inl.h"
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +000038#if V8_TARGET_ARCH_ARM
39#include "arm/constants-arm.h"
ager@chromium.org5c838252010-02-19 08:53:10 +000040#elif V8_TARGET_ARCH_MIPS
41#include "mips/constants-mips.h"
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +000042#endif
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +000043#include "v8checks.h"
mmassi@chromium.org7028c052012-06-13 11:51:58 +000044#include "zone.h"
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000045
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +000046
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000047//
fschneider@chromium.orged78ffd2010-07-21 11:05:19 +000048// Most object types in the V8 JavaScript are described in this file.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000049//
50// Inheritance hierarchy:
lrn@chromium.org303ada72010-10-27 09:33:13 +000051// - MaybeObject (an object or a failure)
52// - Failure (immediate for marking failed operation)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000053// - Object
54// - Smi (immediate small integer)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000055// - HeapObject (superclass for everything allocated in the heap)
ricow@chromium.orgd2be9012011-06-01 06:00:58 +000056// - JSReceiver (suitable for property access)
57// - JSObject
58// - JSArray
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +000059// - JSSet
60// - JSMap
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +000061// - JSWeakMap
ricow@chromium.orgd2be9012011-06-01 06:00:58 +000062// - JSRegExp
63// - JSFunction
erik.corry@gmail.comed49e962012-04-17 11:57:53 +000064// - JSModule
ricow@chromium.orgd2be9012011-06-01 06:00:58 +000065// - GlobalObject
66// - JSGlobalObject
67// - JSBuiltinsObject
68// - JSGlobalProxy
69// - JSValue
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +000070// - JSDate
ricow@chromium.orgd2be9012011-06-01 06:00:58 +000071// - JSMessageObject
72// - JSProxy
73// - JSFunctionProxy
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +000074// - FixedArrayBase
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +000075// - ByteArray
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +000076// - FixedArray
77// - DescriptorArray
78// - HashTable
79// - Dictionary
80// - SymbolTable
81// - CompilationCacheTable
82// - CodeCacheHashTable
83// - MapCache
84// - Context
85// - JSFunctionResultCache
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +000086// - ScopeInfo
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +000087// - FixedDoubleArray
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +000088// - ExternalArray
89// - ExternalPixelArray
90// - ExternalByteArray
91// - ExternalUnsignedByteArray
92// - ExternalShortArray
93// - ExternalUnsignedShortArray
94// - ExternalIntArray
95// - ExternalUnsignedIntArray
96// - ExternalFloatArray
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +000097// - String
98// - SeqString
ager@chromium.org7c537e22008-10-16 08:43:32 +000099// - SeqAsciiString
100// - SeqTwoByteString
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000101// - SlicedString
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000102// - ConsString
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000103// - ExternalString
104// - ExternalAsciiString
105// - ExternalTwoByteString
106// - HeapNumber
107// - Code
108// - Map
109// - Oddball
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000110// - Foreign
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000111// - SharedFunctionInfo
112// - Struct
113// - AccessorInfo
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000114// - AccessorPair
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000115// - AccessCheckInfo
116// - InterceptorInfo
117// - CallHandlerInfo
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000118// - TemplateInfo
119// - FunctionTemplateInfo
120// - ObjectTemplateInfo
121// - Script
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000122// - SignatureInfo
123// - TypeSwitchInfo
124// - DebugInfo
125// - BreakPointInfo
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000126// - CodeCache
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000127//
128// Formats of Object*:
129// Smi: [31 bit signed int] 0
130// HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
131// Failure: [30 bit signed int] 11
132
kasperl@chromium.org71affb52009-05-26 05:44:31 +0000133namespace v8 {
134namespace internal {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000135
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000136enum CompareMapMode {
137 REQUIRE_EXACT_MAP,
138 ALLOW_ELEMENT_TRANSITION_MAPS
139};
140
ulan@chromium.org65a89c22012-02-14 11:46:07 +0000141enum KeyedAccessGrowMode {
142 DO_NOT_ALLOW_JSARRAY_GROWTH,
143 ALLOW_JSARRAY_GROWTH
144};
145
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000146// Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER.
147enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER };
148
ager@chromium.org32912102009-01-16 10:38:43 +0000149
150// PropertyNormalizationMode is used to specify whether to keep
151// inobject properties when normalizing properties of a JSObject.
152enum PropertyNormalizationMode {
153 CLEAR_INOBJECT_PROPERTIES,
154 KEEP_INOBJECT_PROPERTIES
155};
156
157
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000158// NormalizedMapSharingMode is used to specify whether a map may be shared
159// by different objects with normalized properties.
160enum NormalizedMapSharingMode {
161 UNIQUE_NORMALIZED_MAP,
162 SHARED_NORMALIZED_MAP
163};
164
165
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000166// Indicates whether a get method should implicitly create the object looked up.
167enum CreationFlag {
168 ALLOW_CREATION,
169 OMIT_CREATION
170};
171
172
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000173// Indicates whether the search function should expect a sorted or an unsorted
174// array as input.
175enum SearchMode {
176 EXPECT_SORTED,
177 EXPECT_UNSORTED
178};
179
180
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000181// Instance size sentinel for objects of variable size.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000182const int kVariableSizeSentinel = 0;
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000183
184
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000185// All Maps have a field instance_type containing a InstanceType.
186// It describes the type of the instances.
187//
188// As an example, a JavaScript object is a heap object and its map
189// instance_type is JS_OBJECT_TYPE.
190//
191// The names of the string instance types are intended to systematically
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000192// mirror their encoding in the instance_type field of the map. The default
193// encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII
194// encoding is mentioned explicitly in the name. Likewise, the default
195// representation is considered sequential. It is not mentioned in the
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000196// name. The other representations (e.g. CONS, EXTERNAL) are explicitly
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000197// mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a
198// symbol) or a STRING_TYPE (if it is not a symbol).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000199//
200// NOTE: The following things are some that depend on the string types having
201// instance_types that are less than those of all other types:
202// HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
203// Object::IsString.
204//
ager@chromium.orgc27e4e72008-09-04 13:52:27 +0000205// NOTE: Everything following JS_VALUE_TYPE is considered a
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000206// JSObject for GC purposes. The first four entries here have typeof
207// 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000208#define INSTANCE_TYPE_LIST_ALL(V) \
209 V(SYMBOL_TYPE) \
210 V(ASCII_SYMBOL_TYPE) \
211 V(CONS_SYMBOL_TYPE) \
212 V(CONS_ASCII_SYMBOL_TYPE) \
213 V(EXTERNAL_SYMBOL_TYPE) \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000214 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000215 V(EXTERNAL_ASCII_SYMBOL_TYPE) \
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000216 V(SHORT_EXTERNAL_SYMBOL_TYPE) \
217 V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
218 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000219 V(STRING_TYPE) \
220 V(ASCII_STRING_TYPE) \
221 V(CONS_STRING_TYPE) \
222 V(CONS_ASCII_STRING_TYPE) \
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000223 V(SLICED_STRING_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000224 V(EXTERNAL_STRING_TYPE) \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000225 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000226 V(EXTERNAL_ASCII_STRING_TYPE) \
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000227 V(SHORT_EXTERNAL_STRING_TYPE) \
228 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
229 V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000230 V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \
231 \
232 V(MAP_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000233 V(CODE_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000234 V(ODDBALL_TYPE) \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000235 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000236 \
237 V(HEAP_NUMBER_TYPE) \
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000238 V(FOREIGN_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000239 V(BYTE_ARRAY_TYPE) \
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000240 V(FREE_SPACE_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000241 /* Note: the order of these external array */ \
242 /* types is relied upon in */ \
243 /* Object::IsExternalArray(). */ \
244 V(EXTERNAL_BYTE_ARRAY_TYPE) \
245 V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \
246 V(EXTERNAL_SHORT_ARRAY_TYPE) \
247 V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \
248 V(EXTERNAL_INT_ARRAY_TYPE) \
249 V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \
250 V(EXTERNAL_FLOAT_ARRAY_TYPE) \
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000251 V(EXTERNAL_PIXEL_ARRAY_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000252 V(FILLER_TYPE) \
253 \
254 V(ACCESSOR_INFO_TYPE) \
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000255 V(ACCESSOR_PAIR_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000256 V(ACCESS_CHECK_INFO_TYPE) \
257 V(INTERCEPTOR_INFO_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000258 V(CALL_HANDLER_INFO_TYPE) \
259 V(FUNCTION_TEMPLATE_INFO_TYPE) \
260 V(OBJECT_TEMPLATE_INFO_TYPE) \
261 V(SIGNATURE_INFO_TYPE) \
262 V(TYPE_SWITCH_INFO_TYPE) \
263 V(SCRIPT_TYPE) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000264 V(CODE_CACHE_TYPE) \
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000265 V(POLYMORPHIC_CODE_CACHE_TYPE) \
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +0000266 V(TYPE_FEEDBACK_INFO_TYPE) \
267 V(ALIASED_ARGUMENTS_ENTRY_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000268 \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000269 V(FIXED_ARRAY_TYPE) \
danno@chromium.orgb6451162011-08-17 14:33:23 +0000270 V(FIXED_DOUBLE_ARRAY_TYPE) \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000271 V(SHARED_FUNCTION_INFO_TYPE) \
272 \
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000273 V(JS_MESSAGE_OBJECT_TYPE) \
274 \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000275 V(JS_VALUE_TYPE) \
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000276 V(JS_DATE_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000277 V(JS_OBJECT_TYPE) \
278 V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000279 V(JS_MODULE_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000280 V(JS_GLOBAL_OBJECT_TYPE) \
281 V(JS_BUILTINS_OBJECT_TYPE) \
282 V(JS_GLOBAL_PROXY_TYPE) \
283 V(JS_ARRAY_TYPE) \
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000284 V(JS_PROXY_TYPE) \
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000285 V(JS_WEAK_MAP_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000286 V(JS_REGEXP_TYPE) \
287 \
288 V(JS_FUNCTION_TYPE) \
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000289 V(JS_FUNCTION_PROXY_TYPE) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000290
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000291#ifdef ENABLE_DEBUGGER_SUPPORT
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000292#define INSTANCE_TYPE_LIST_DEBUGGER(V) \
293 V(DEBUG_INFO_TYPE) \
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000294 V(BREAK_POINT_INFO_TYPE)
295#else
296#define INSTANCE_TYPE_LIST_DEBUGGER(V)
297#endif
298
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000299#define INSTANCE_TYPE_LIST(V) \
300 INSTANCE_TYPE_LIST_ALL(V) \
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000301 INSTANCE_TYPE_LIST_DEBUGGER(V)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000302
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000303
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000304// Since string types are not consecutive, this macro is used to
305// iterate over them.
306#define STRING_TYPE_LIST(V) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000307 V(SYMBOL_TYPE, \
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000308 kVariableSizeSentinel, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000309 symbol, \
310 Symbol) \
311 V(ASCII_SYMBOL_TYPE, \
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000312 kVariableSizeSentinel, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000313 ascii_symbol, \
314 AsciiSymbol) \
315 V(CONS_SYMBOL_TYPE, \
316 ConsString::kSize, \
317 cons_symbol, \
318 ConsSymbol) \
319 V(CONS_ASCII_SYMBOL_TYPE, \
320 ConsString::kSize, \
321 cons_ascii_symbol, \
322 ConsAsciiSymbol) \
323 V(EXTERNAL_SYMBOL_TYPE, \
324 ExternalTwoByteString::kSize, \
325 external_symbol, \
326 ExternalSymbol) \
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000327 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
328 ExternalTwoByteString::kSize, \
329 external_symbol_with_ascii_data, \
330 ExternalSymbolWithAsciiData) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000331 V(EXTERNAL_ASCII_SYMBOL_TYPE, \
332 ExternalAsciiString::kSize, \
333 external_ascii_symbol, \
334 ExternalAsciiSymbol) \
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000335 V(SHORT_EXTERNAL_SYMBOL_TYPE, \
336 ExternalTwoByteString::kShortSize, \
337 short_external_symbol, \
338 ShortExternalSymbol) \
339 V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
340 ExternalTwoByteString::kShortSize, \
341 short_external_symbol_with_ascii_data, \
342 ShortExternalSymbolWithAsciiData) \
343 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \
344 ExternalAsciiString::kShortSize, \
345 short_external_ascii_symbol, \
346 ShortExternalAsciiSymbol) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000347 V(STRING_TYPE, \
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000348 kVariableSizeSentinel, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000349 string, \
350 String) \
351 V(ASCII_STRING_TYPE, \
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000352 kVariableSizeSentinel, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000353 ascii_string, \
354 AsciiString) \
355 V(CONS_STRING_TYPE, \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000356 ConsString::kSize, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000357 cons_string, \
358 ConsString) \
359 V(CONS_ASCII_STRING_TYPE, \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000360 ConsString::kSize, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000361 cons_ascii_string, \
362 ConsAsciiString) \
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000363 V(SLICED_STRING_TYPE, \
364 SlicedString::kSize, \
365 sliced_string, \
366 SlicedString) \
367 V(SLICED_ASCII_STRING_TYPE, \
368 SlicedString::kSize, \
369 sliced_ascii_string, \
370 SlicedAsciiString) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000371 V(EXTERNAL_STRING_TYPE, \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000372 ExternalTwoByteString::kSize, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000373 external_string, \
374 ExternalString) \
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000375 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
376 ExternalTwoByteString::kSize, \
377 external_string_with_ascii_data, \
378 ExternalStringWithAsciiData) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000379 V(EXTERNAL_ASCII_STRING_TYPE, \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000380 ExternalAsciiString::kSize, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000381 external_ascii_string, \
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000382 ExternalAsciiString) \
383 V(SHORT_EXTERNAL_STRING_TYPE, \
384 ExternalTwoByteString::kShortSize, \
385 short_external_string, \
386 ShortExternalString) \
387 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
388 ExternalTwoByteString::kShortSize, \
389 short_external_string_with_ascii_data, \
390 ShortExternalStringWithAsciiData) \
391 V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \
392 ExternalAsciiString::kShortSize, \
393 short_external_ascii_string, \
394 ShortExternalAsciiString)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000395
396// A struct is a simple object a set of object-valued fields. Including an
397// object type in this causes the compiler to generate most of the boilerplate
398// code for the class including allocation and garbage collection routines,
399// casts and predicates. All you need to define is the class, methods and
400// object verification routines. Easy, no?
401//
402// Note that for subtle reasons related to the ordering or numerical values of
403// type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
404// manually.
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000405#define STRUCT_LIST_ALL(V) \
406 V(ACCESSOR_INFO, AccessorInfo, accessor_info) \
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000407 V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000408 V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \
409 V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \
410 V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \
411 V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \
412 V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \
413 V(SIGNATURE_INFO, SignatureInfo, signature_info) \
414 V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000415 V(SCRIPT, Script, script) \
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000416 V(CODE_CACHE, CodeCache, code_cache) \
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000417 V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +0000418 V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \
419 V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000420
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000421#ifdef ENABLE_DEBUGGER_SUPPORT
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000422#define STRUCT_LIST_DEBUGGER(V) \
423 V(DEBUG_INFO, DebugInfo, debug_info) \
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000424 V(BREAK_POINT_INFO, BreakPointInfo, break_point_info)
425#else
426#define STRUCT_LIST_DEBUGGER(V)
427#endif
428
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000429#define STRUCT_LIST(V) \
430 STRUCT_LIST_ALL(V) \
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000431 STRUCT_LIST_DEBUGGER(V)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000432
433// We use the full 8 bits of the instance_type field to encode heap object
434// instance types. The high-order bit (bit 7) is set if the object is not a
435// string, and cleared if it is a string.
436const uint32_t kIsNotStringMask = 0x80;
437const uint32_t kStringTag = 0x0;
438const uint32_t kNotStringTag = 0x80;
439
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000440// Bit 6 indicates that the object is a symbol (if set) or not (if cleared).
441// There are not enough types that the non-string types (with bit 7 set) can
442// have bit 6 set too.
443const uint32_t kIsSymbolMask = 0x40;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000444const uint32_t kNotSymbolTag = 0x0;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000445const uint32_t kSymbolTag = 0x40;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000446
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000447// If bit 7 is clear then bit 2 indicates whether the string consists of
448// two-byte characters or one-byte characters.
449const uint32_t kStringEncodingMask = 0x4;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000450const uint32_t kTwoByteStringTag = 0x0;
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000451const uint32_t kAsciiStringTag = 0x4;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000452
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000453// If bit 7 is clear, the low-order 2 bits indicate the representation
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000454// of the string.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000455const uint32_t kStringRepresentationMask = 0x03;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000456enum StringRepresentationTag {
457 kSeqStringTag = 0x0,
458 kConsStringTag = 0x1,
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000459 kExternalStringTag = 0x2,
460 kSlicedStringTag = 0x3
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000461};
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000462const uint32_t kIsIndirectStringMask = 0x1;
463const uint32_t kIsIndirectStringTag = 0x1;
464STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0);
465STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0);
466STATIC_ASSERT(
467 (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag);
468STATIC_ASSERT(
469 (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000470
yangguo@chromium.org80c42ed2011-08-31 09:03:56 +0000471// Use this mask to distinguish between cons and slice only after making
472// sure that the string is one of the two (an indirect string).
473const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag;
474STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0);
475
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000476// If bit 7 is clear, then bit 3 indicates whether this two-byte
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000477// string actually contains ASCII data.
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000478const uint32_t kAsciiDataHintMask = 0x08;
479const uint32_t kAsciiDataHintTag = 0x08;
480
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000481// If bit 7 is clear and string representation indicates an external string,
482// then bit 4 indicates whether the data pointer is cached.
483const uint32_t kShortExternalStringMask = 0x10;
484const uint32_t kShortExternalStringTag = 0x10;
485
kasperl@chromium.orgd1e3e722009-04-14 13:38:25 +0000486
487// A ConsString with an empty string as the right side is a candidate
488// for being shortcut by the garbage collector unless it is a
489// symbol. It's not common to have non-flat symbols, so we do not
490// shortcut them thereby avoiding turning symbols into strings. See
491// heap.cc and mark-compact.cc.
492const uint32_t kShortcutTypeMask =
493 kIsNotStringMask |
494 kIsSymbolMask |
495 kStringRepresentationMask;
496const uint32_t kShortcutTypeTag = kConsStringTag;
497
498
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000499enum InstanceType {
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000500 // String types.
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000501 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000502 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000503 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000504 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000505 SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag |
506 kExternalStringTag | kShortExternalStringTag,
507 SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
508 kTwoByteStringTag | kSymbolTag | kExternalStringTag |
509 kAsciiDataHintTag | kShortExternalStringTag,
510 SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kAsciiStringTag | kExternalStringTag |
511 kSymbolTag | kShortExternalStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000512 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag,
513 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
514 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000515 EXTERNAL_ASCII_SYMBOL_TYPE =
516 kAsciiStringTag | kSymbolTag | kExternalStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000517 STRING_TYPE = kTwoByteStringTag | kSeqStringTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000518 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000519 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000520 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag,
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000521 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag,
522 SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000523 SHORT_EXTERNAL_STRING_TYPE =
524 kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag,
525 SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
526 kTwoByteStringTag | kExternalStringTag |
527 kAsciiDataHintTag | kShortExternalStringTag,
528 SHORT_EXTERNAL_ASCII_STRING_TYPE =
529 kAsciiStringTag | kExternalStringTag | kShortExternalStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000530 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag,
531 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
532 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag,
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000533 // LAST_STRING_TYPE
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000534 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag,
535 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000536
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000537 // Objects allocated in their own spaces (never in new space).
538 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000539 CODE_TYPE,
540 ODDBALL_TYPE,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000541 JS_GLOBAL_PROPERTY_CELL_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000542
543 // "Data", objects that cannot contain non-map-word pointers to heap
544 // objects.
545 HEAP_NUMBER_TYPE,
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000546 FOREIGN_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000547 BYTE_ARRAY_TYPE,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000548 FREE_SPACE_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000549 EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE
ager@chromium.org3811b432009-10-28 14:53:37 +0000550 EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
551 EXTERNAL_SHORT_ARRAY_TYPE,
552 EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
553 EXTERNAL_INT_ARRAY_TYPE,
554 EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000555 EXTERNAL_FLOAT_ARRAY_TYPE,
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000556 EXTERNAL_DOUBLE_ARRAY_TYPE,
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000557 EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000558 FIXED_DOUBLE_ARRAY_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000559 FILLER_TYPE, // LAST_DATA_TYPE
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000560
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000561 // Structs.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000562 ACCESSOR_INFO_TYPE,
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000563 ACCESSOR_PAIR_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000564 ACCESS_CHECK_INFO_TYPE,
565 INTERCEPTOR_INFO_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000566 CALL_HANDLER_INFO_TYPE,
567 FUNCTION_TEMPLATE_INFO_TYPE,
568 OBJECT_TEMPLATE_INFO_TYPE,
569 SIGNATURE_INFO_TYPE,
570 TYPE_SWITCH_INFO_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000571 SCRIPT_TYPE,
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000572 CODE_CACHE_TYPE,
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000573 POLYMORPHIC_CODE_CACHE_TYPE,
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000574 TYPE_FEEDBACK_INFO_TYPE,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +0000575 ALIASED_ARGUMENTS_ENTRY_TYPE,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000576 // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT
577 // is defined. However as include/v8.h contain some of the instance type
578 // constants always having them avoids them getting different numbers
579 // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000580 DEBUG_INFO_TYPE,
581 BREAK_POINT_INFO_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000582
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000583 FIXED_ARRAY_TYPE,
584 SHARED_FUNCTION_INFO_TYPE,
585
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000586 JS_MESSAGE_OBJECT_TYPE,
587
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000588 // All the following types are subtypes of JSReceiver, which corresponds to
589 // objects in the JS sense. The first and the last type in this range are
590 // the two forms of function. This organization enables using the same
591 // compares for checking the JS_RECEIVER/SPEC_OBJECT range and the
592 // NONCALLABLE_JS_OBJECT range.
593 JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE
594 JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE
595
596 JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000597 JS_DATE_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000598 JS_OBJECT_TYPE,
ager@chromium.org32912102009-01-16 10:38:43 +0000599 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000600 JS_MODULE_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000601 JS_GLOBAL_OBJECT_TYPE,
602 JS_BUILTINS_OBJECT_TYPE,
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000603 JS_GLOBAL_PROXY_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000604 JS_ARRAY_TYPE,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000605 JS_SET_TYPE,
606 JS_MAP_TYPE,
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000607 JS_WEAK_MAP_TYPE,
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000608
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000609 JS_REGEXP_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000610
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000611 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000612
613 // Pseudo-types
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000614 FIRST_TYPE = 0x0,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000615 LAST_TYPE = JS_FUNCTION_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000616 INVALID_TYPE = FIRST_TYPE - 1,
617 FIRST_NONSTRING_TYPE = MAP_TYPE,
618 // Boundaries for testing for an external array.
619 FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE,
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000620 LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000621 // Boundary for promotion to old data space/old pointer space.
622 LAST_DATA_TYPE = FILLER_TYPE,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000623 // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy).
624 // Note that there is no range for JSObject or JSProxy, since their subtypes
625 // are not continuous in this enum! The enum ranges instead reflect the
626 // external class names, where proxies are treated as either ordinary objects,
627 // or functions.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000628 FIRST_JS_RECEIVER_TYPE = JS_FUNCTION_PROXY_TYPE,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000629 LAST_JS_RECEIVER_TYPE = LAST_TYPE,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000630 // Boundaries for testing the types represented as JSObject
631 FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE,
632 LAST_JS_OBJECT_TYPE = LAST_TYPE,
633 // Boundaries for testing the types represented as JSProxy
634 FIRST_JS_PROXY_TYPE = JS_FUNCTION_PROXY_TYPE,
635 LAST_JS_PROXY_TYPE = JS_PROXY_TYPE,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000636 // Boundaries for testing whether the type is a JavaScript object.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000637 FIRST_SPEC_OBJECT_TYPE = FIRST_JS_RECEIVER_TYPE,
638 LAST_SPEC_OBJECT_TYPE = LAST_JS_RECEIVER_TYPE,
639 // Boundaries for testing the types for which typeof is "object".
640 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_PROXY_TYPE,
641 LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE,
642 // Note that the types for which typeof is "function" are not continuous.
643 // Define this so that we can put assertions on discrete checks.
644 NUM_OF_CALLABLE_SPEC_OBJECT_TYPES = 2
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000645};
646
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000647const int kExternalArrayTypeCount =
648 LAST_EXTERNAL_ARRAY_TYPE - FIRST_EXTERNAL_ARRAY_TYPE + 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000649
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000650STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType);
651STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType);
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +0000652STATIC_CHECK(ODDBALL_TYPE == Internals::kOddballType);
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000653STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000654
655
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000656enum CompareResult {
657 LESS = -1,
658 EQUAL = 0,
659 GREATER = 1,
660
661 NOT_EQUAL = GREATER
662};
663
664
665#define DECL_BOOLEAN_ACCESSORS(name) \
666 inline bool name(); \
667 inline void set_##name(bool value); \
668
669
ager@chromium.org32912102009-01-16 10:38:43 +0000670#define DECL_ACCESSORS(name, type) \
671 inline type* name(); \
672 inline void set_##name(type* value, \
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000673 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000674
675
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000676class AccessorPair;
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000677class DictionaryElementsAccessor;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000678class ElementsAccessor;
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000679class Failure;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000680class FixedArrayBase;
681class ObjectVisitor;
682class StringStream;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000683
684struct ValueInfo : public Malloced {
685 ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { }
686 InstanceType type;
687 Object* ptr;
688 const char* str;
689 double number;
690};
691
692
693// A template-ized version of the IsXXX functions.
694template <class C> static inline bool Is(Object* obj);
695
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000696
lrn@chromium.org303ada72010-10-27 09:33:13 +0000697class MaybeObject BASE_EMBEDDED {
698 public:
699 inline bool IsFailure();
700 inline bool IsRetryAfterGC();
701 inline bool IsOutOfMemory();
702 inline bool IsException();
703 INLINE(bool IsTheHole());
704 inline bool ToObject(Object** obj) {
705 if (IsFailure()) return false;
706 *obj = reinterpret_cast<Object*>(this);
707 return true;
708 }
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000709 inline Failure* ToFailureUnchecked() {
710 ASSERT(IsFailure());
711 return reinterpret_cast<Failure*>(this);
712 }
lrn@chromium.org303ada72010-10-27 09:33:13 +0000713 inline Object* ToObjectUnchecked() {
714 ASSERT(!IsFailure());
715 return reinterpret_cast<Object*>(this);
716 }
717 inline Object* ToObjectChecked() {
718 CHECK(!IsFailure());
719 return reinterpret_cast<Object*>(this);
720 }
721
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000722 template<typename T>
723 inline bool To(T** obj) {
724 if (IsFailure()) return false;
725 *obj = T::cast(reinterpret_cast<Object*>(this));
726 return true;
727 }
728
whesse@chromium.org023421e2010-12-21 12:19:12 +0000729#ifdef OBJECT_PRINT
lrn@chromium.org303ada72010-10-27 09:33:13 +0000730 // Prints this object with details.
whesse@chromium.org023421e2010-12-21 12:19:12 +0000731 inline void Print() {
732 Print(stdout);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000733 }
whesse@chromium.org023421e2010-12-21 12:19:12 +0000734 inline void PrintLn() {
735 PrintLn(stdout);
736 }
737 void Print(FILE* out);
738 void PrintLn(FILE* out);
739#endif
740#ifdef DEBUG
lrn@chromium.org303ada72010-10-27 09:33:13 +0000741 // Verifies the object.
742 void Verify();
743#endif
744};
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000745
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000746
747#define OBJECT_TYPE_LIST(V) \
748 V(Smi) \
749 V(HeapObject) \
750 V(Number) \
751
752#define HEAP_OBJECT_TYPE_LIST(V) \
753 V(HeapNumber) \
754 V(String) \
755 V(Symbol) \
756 V(SeqString) \
757 V(ExternalString) \
758 V(ConsString) \
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000759 V(SlicedString) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000760 V(ExternalTwoByteString) \
761 V(ExternalAsciiString) \
762 V(SeqTwoByteString) \
763 V(SeqAsciiString) \
764 \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000765 V(ExternalArray) \
766 V(ExternalByteArray) \
767 V(ExternalUnsignedByteArray) \
768 V(ExternalShortArray) \
769 V(ExternalUnsignedShortArray) \
770 V(ExternalIntArray) \
771 V(ExternalUnsignedIntArray) \
772 V(ExternalFloatArray) \
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000773 V(ExternalDoubleArray) \
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000774 V(ExternalPixelArray) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000775 V(ByteArray) \
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000776 V(FreeSpace) \
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000777 V(JSReceiver) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000778 V(JSObject) \
779 V(JSContextExtensionObject) \
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000780 V(JSModule) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000781 V(Map) \
782 V(DescriptorArray) \
783 V(DeoptimizationInputData) \
784 V(DeoptimizationOutputData) \
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000785 V(TypeFeedbackCells) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000786 V(FixedArray) \
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000787 V(FixedDoubleArray) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000788 V(Context) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000789 V(GlobalContext) \
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000790 V(ModuleContext) \
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000791 V(ScopeInfo) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000792 V(JSFunction) \
793 V(Code) \
794 V(Oddball) \
795 V(SharedFunctionInfo) \
796 V(JSValue) \
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000797 V(JSDate) \
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000798 V(JSMessageObject) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000799 V(StringWrapper) \
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000800 V(Foreign) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000801 V(Boolean) \
802 V(JSArray) \
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000803 V(JSProxy) \
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000804 V(JSFunctionProxy) \
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000805 V(JSSet) \
806 V(JSMap) \
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000807 V(JSWeakMap) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000808 V(JSRegExp) \
809 V(HashTable) \
810 V(Dictionary) \
811 V(SymbolTable) \
812 V(JSFunctionResultCache) \
813 V(NormalizedMapCache) \
814 V(CompilationCacheTable) \
815 V(CodeCacheHashTable) \
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000816 V(PolymorphicCodeCacheHashTable) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000817 V(MapCache) \
818 V(Primitive) \
819 V(GlobalObject) \
820 V(JSGlobalObject) \
821 V(JSBuiltinsObject) \
822 V(JSGlobalProxy) \
823 V(UndetectableObject) \
824 V(AccessCheckNeeded) \
825 V(JSGlobalPropertyCell) \
826
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000827
828class JSReceiver;
829
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000830// Object is the abstract superclass for all classes in the
831// object hierarchy.
832// Object does not use any virtual functions to avoid the
833// allocation of the C++ vtable.
834// Since Smi and Failure are subclasses of Object no
835// data members can be present in Object.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000836class Object : public MaybeObject {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000837 public:
838 // Type testing.
erik.corry@gmail.combbceb572012-03-09 10:52:05 +0000839 bool IsObject() { return true; }
840
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000841#define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_();
842 OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
843 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
844#undef IS_TYPE_FUNCTION_DECL
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000845
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000846 inline bool IsFixedArrayBase();
847
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000848 // Returns true if this object is an instance of the specified
849 // function template.
sgjesse@chromium.org900d3b72009-08-07 11:24:25 +0000850 inline bool IsInstanceOf(FunctionTemplateInfo* type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000851
852 inline bool IsStruct();
853#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name();
854 STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
855#undef DECLARE_STRUCT_PREDICATE
856
ricow@chromium.org9fa09672011-07-25 11:05:35 +0000857 INLINE(bool IsSpecObject());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000858 INLINE(bool IsSpecFunction());
ricow@chromium.org9fa09672011-07-25 11:05:35 +0000859
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000860 // Oddball testing.
861 INLINE(bool IsUndefined());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000862 INLINE(bool IsNull());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000863 INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000864 INLINE(bool IsTrue());
865 INLINE(bool IsFalse());
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000866 inline bool IsArgumentsMarker();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000867 inline bool NonFailureIsHeapObject();
868
869 // Filler objects (fillers and free space objects).
870 inline bool IsFiller();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000871
872 // Extract the number.
873 inline double Number();
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000874 inline bool IsNaN();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000875
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000876 // Returns true if the object is of the correct type to be used as a
877 // implementation of a JSObject's elements.
878 inline bool HasValidElements();
879
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000880 inline bool HasSpecificClassOf(String* name);
881
lrn@chromium.org303ada72010-10-27 09:33:13 +0000882 MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9.
883 Object* ToBoolean(); // ECMA-262 9.2.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000884
885 // Convert to a JSObject if needed.
886 // global_context is used when creating wrapper object.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000887 MUST_USE_RESULT MaybeObject* ToObject(Context* global_context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000888
889 // Converts this to a Smi if possible.
890 // Failure is returned otherwise.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000891 MUST_USE_RESULT inline MaybeObject* ToSmi();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000892
893 void Lookup(String* name, LookupResult* result);
894
895 // Property access.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000896 MUST_USE_RESULT inline MaybeObject* GetProperty(String* key);
897 MUST_USE_RESULT inline MaybeObject* GetProperty(
898 String* key,
899 PropertyAttributes* attributes);
900 MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver(
901 Object* receiver,
902 String* key,
903 PropertyAttributes* attributes);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000904
905 static Handle<Object> GetProperty(Handle<Object> object,
906 Handle<Object> receiver,
907 LookupResult* result,
908 Handle<String> key,
909 PropertyAttributes* attributes);
910
lrn@chromium.org303ada72010-10-27 09:33:13 +0000911 MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver,
912 LookupResult* result,
913 String* key,
914 PropertyAttributes* attributes);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000915
lrn@chromium.org303ada72010-10-27 09:33:13 +0000916 MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000917 JSReceiver* getter);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000918
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000919 static Handle<Object> GetElement(Handle<Object> object, uint32_t index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000920 MUST_USE_RESULT inline MaybeObject* GetElement(uint32_t index);
lrn@chromium.org303ada72010-10-27 09:33:13 +0000921 // For use when we know that no exception can be thrown.
922 inline Object* GetElementNoExceptionThrown(uint32_t index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000923 MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Object* receiver,
924 uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000925
926 // Return the object's prototype (might be Heap::null_value()).
927 Object* GetPrototype();
928
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000929 // Returns the permanent hash code associated with this object depending on
930 // the actual object type. Might return a failure in case no hash was
931 // created yet or GC was caused by creation.
932 MUST_USE_RESULT MaybeObject* GetHash(CreationFlag flag);
933
934 // Checks whether this object has the same value as the given one. This
935 // function is implemented according to ES5, section 9.12 and can be used
936 // to implement the Harmony "egal" function.
937 bool SameValue(Object* other);
938
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000939 // Tries to convert an object to an array index. Returns true and sets
940 // the output parameter if it succeeds.
941 inline bool ToArrayIndex(uint32_t* index);
942
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000943 // Returns true if this is a JSValue containing a string and the index is
944 // < the length of the string. Used to implement [] on strings.
945 inline bool IsStringObjectWithCharacterAt(uint32_t index);
946
947#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000948 // Verify a pointer is a valid object pointer.
949 static void VerifyPointer(Object* p);
950#endif
951
952 // Prints this object without details.
whesse@chromium.org023421e2010-12-21 12:19:12 +0000953 inline void ShortPrint() {
954 ShortPrint(stdout);
955 }
956 void ShortPrint(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000957
958 // Prints this object without details to a message accumulator.
959 void ShortPrint(StringStream* accumulator);
960
961 // Casting: This cast is only needed to satisfy macros in objects-inl.h.
962 static Object* cast(Object* value) { return value; }
963
964 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +0000965 static const int kHeaderSize = 0; // Object does not take up any space.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000966
967 private:
968 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
969};
970
971
972// Smi represents integer Numbers that can be stored in 31 bits.
973// Smis are immediate which means they are NOT allocated in the heap.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000974// The this pointer has the following format: [31 bit signed int] 0
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000975// For long smis it has the following format:
976// [32 bit signed int] [31 bits zero padding] 0
977// Smi stands for small integer.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000978class Smi: public Object {
979 public:
980 // Returns the integer value.
981 inline int value();
982
983 // Convert a value to a Smi object.
984 static inline Smi* FromInt(int value);
985
ager@chromium.org9085a012009-05-11 19:22:57 +0000986 static inline Smi* FromIntptr(intptr_t value);
987
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000988 // Returns whether value can be represented in a Smi.
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000989 static inline bool IsValid(intptr_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000990
991 // Casting.
992 static inline Smi* cast(Object* object);
993
994 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +0000995 inline void SmiPrint() {
996 SmiPrint(stdout);
997 }
998 void SmiPrint(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000999 void SmiPrint(StringStream* accumulator);
1000#ifdef DEBUG
1001 void SmiVerify();
1002#endif
1003
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001004 static const int kMinValue =
1005 (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001006 static const int kMaxValue = -(kMinValue + 1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001007
1008 private:
1009 DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);
1010};
1011
1012
ager@chromium.org6f10e412009-02-13 10:11:16 +00001013// Failure is used for reporting out of memory situations and
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001014// propagating exceptions through the runtime system. Failure objects
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001015// are transient and cannot occur as part of the object graph.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001016//
1017// Failures are a single word, encoded as follows:
1018// +-------------------------+---+--+--+
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00001019// |.........unused..........|sss|tt|11|
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001020// +-------------------------+---+--+--+
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001021// 7 6 4 32 10
1022//
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001023//
1024// The low two bits, 0-1, are the failure tag, 11. The next two bits,
1025// 2-3, are a failure type tag 'tt' with possible values:
1026// 00 RETRY_AFTER_GC
1027// 01 EXCEPTION
1028// 10 INTERNAL_ERROR
1029// 11 OUT_OF_MEMORY_EXCEPTION
1030//
1031// The next three bits, 4-6, are an allocation space tag 'sss'. The
1032// allocation space tag is 000 for all failure types except
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001033// RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the
1034// allocation spaces (the encoding is found in globals.h).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001035
1036// Failure type tag info.
1037const int kFailureTypeTagSize = 2;
1038const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1;
1039
lrn@chromium.org303ada72010-10-27 09:33:13 +00001040class Failure: public MaybeObject {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001041 public:
1042 // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code.
1043 enum Type {
1044 RETRY_AFTER_GC = 0,
1045 EXCEPTION = 1, // Returning this marker tells the real exception
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001046 // is in Isolate::pending_exception.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001047 INTERNAL_ERROR = 2,
1048 OUT_OF_MEMORY_EXCEPTION = 3
1049 };
1050
1051 inline Type type() const;
1052
1053 // Returns the space that needs to be collected for RetryAfterGC failures.
1054 inline AllocationSpace allocation_space() const;
1055
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001056 inline bool IsInternalError() const;
1057 inline bool IsOutOfMemoryException() const;
1058
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00001059 static inline Failure* RetryAfterGC(AllocationSpace space);
1060 static inline Failure* RetryAfterGC(); // NEW_SPACE
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001061 static inline Failure* Exception();
1062 static inline Failure* InternalError();
1063 static inline Failure* OutOfMemoryException();
1064 // Casting.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001065 static inline Failure* cast(MaybeObject* object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001066
1067 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00001068 inline void FailurePrint() {
1069 FailurePrint(stdout);
1070 }
1071 void FailurePrint(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001072 void FailurePrint(StringStream* accumulator);
1073#ifdef DEBUG
1074 void FailureVerify();
1075#endif
1076
1077 private:
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001078 inline intptr_t value() const;
1079 static inline Failure* Construct(Type type, intptr_t value = 0);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001080
1081 DISALLOW_IMPLICIT_CONSTRUCTORS(Failure);
1082};
1083
1084
kasper.lund7276f142008-07-30 08:49:36 +00001085// Heap objects typically have a map pointer in their first word. However,
ulan@chromium.org2efb9002012-01-19 15:36:35 +00001086// during GC other data (e.g. mark bits, forwarding addresses) is sometimes
kasper.lund7276f142008-07-30 08:49:36 +00001087// encoded in the first word. The class MapWord is an abstraction of the
1088// value in a heap object's first word.
1089class MapWord BASE_EMBEDDED {
1090 public:
1091 // Normal state: the map word contains a map pointer.
1092
1093 // Create a map word from a map pointer.
1094 static inline MapWord FromMap(Map* map);
1095
1096 // View this map word as a map pointer.
1097 inline Map* ToMap();
1098
1099
1100 // Scavenge collection: the map word of live objects in the from space
1101 // contains a forwarding address (a heap object pointer in the to space).
1102
1103 // True if this map word is a forwarding address for a scavenge
1104 // collection. Only valid during a scavenge collection (specifically,
ulan@chromium.org2efb9002012-01-19 15:36:35 +00001105 // when all map words are heap object pointers, i.e. not during a full GC).
kasper.lund7276f142008-07-30 08:49:36 +00001106 inline bool IsForwardingAddress();
1107
1108 // Create a map word from a forwarding address.
1109 static inline MapWord FromForwardingAddress(HeapObject* object);
1110
1111 // View this map word as a forwarding address.
1112 inline HeapObject* ToForwardingAddress();
1113
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001114 static inline MapWord FromRawValue(uintptr_t value) {
1115 return MapWord(value);
1116 }
kasper.lund7276f142008-07-30 08:49:36 +00001117
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001118 inline uintptr_t ToRawValue() {
1119 return value_;
1120 }
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001121
1122 private:
1123 // HeapObject calls the private constructor and directly reads the value.
1124 friend class HeapObject;
1125
1126 explicit MapWord(uintptr_t value) : value_(value) {}
1127
1128 uintptr_t value_;
kasper.lund7276f142008-07-30 08:49:36 +00001129};
1130
1131
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001132// HeapObject is the superclass for all classes describing heap allocated
1133// objects.
1134class HeapObject: public Object {
1135 public:
kasper.lund7276f142008-07-30 08:49:36 +00001136 // [map]: Contains a map which contains the object's reflective
1137 // information.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001138 inline Map* map();
1139 inline void set_map(Map* value);
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001140 // The no-write-barrier version. This is OK if the object is white and in
1141 // new space, or if the value is an immortal immutable object, like the maps
1142 // of primitive (non-JS) objects like strings, heap numbers etc.
1143 inline void set_map_no_write_barrier(Map* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001144
kasper.lund7276f142008-07-30 08:49:36 +00001145 // During garbage collection, the map word of a heap object does not
1146 // necessarily contain a map pointer.
1147 inline MapWord map_word();
1148 inline void set_map_word(MapWord map_word);
1149
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001150 // The Heap the object was allocated in. Used also to access Isolate.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001151 inline Heap* GetHeap();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001152
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001153 // Convenience method to get current isolate. This method can be
1154 // accessed only when its result is the same as
1155 // Isolate::Current(), it ASSERTs this. See also comment for GetHeap.
1156 inline Isolate* GetIsolate();
1157
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001158 // Converts an address to a HeapObject pointer.
1159 static inline HeapObject* FromAddress(Address address);
1160
1161 // Returns the address of this HeapObject.
1162 inline Address address();
1163
1164 // Iterates over pointers contained in the object (including the Map)
1165 void Iterate(ObjectVisitor* v);
1166
1167 // Iterates over all pointers contained in the object except the
1168 // first map pointer. The object type is given in the first
1169 // parameter. This function does not access the map pointer in the
1170 // object, and so is safe to call while the map pointer is modified.
1171 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1172
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001173 // Returns the heap object's size in bytes
1174 inline int Size();
1175
1176 // Given a heap object's map pointer, returns the heap size in bytes
1177 // Useful when the map pointer field is used for other purposes.
1178 // GC internal.
1179 inline int SizeFromMap(Map* map);
1180
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +00001181 // Returns the field at offset in obj, as a read/write Object* reference.
1182 // Does no checking, and is safe to use during GC, while maps are invalid.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00001183 // Does not invoke write barrier, so should only be assigned to
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +00001184 // during marking GC.
1185 static inline Object** RawField(HeapObject* obj, int offset);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001186
1187 // Casting.
1188 static inline HeapObject* cast(Object* obj);
1189
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001190 // Return the write barrier mode for this. Callers of this function
1191 // must be able to present a reference to an AssertNoAllocation
1192 // object as a sign that they are not going to use this function
1193 // from code that allocates and thus invalidates the returned write
1194 // barrier mode.
1195 inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001196
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001197 // Dispatched behavior.
1198 void HeapObjectShortPrint(StringStream* accumulator);
whesse@chromium.org023421e2010-12-21 12:19:12 +00001199#ifdef OBJECT_PRINT
1200 inline void HeapObjectPrint() {
1201 HeapObjectPrint(stdout);
1202 }
1203 void HeapObjectPrint(FILE* out);
whesse@chromium.org023421e2010-12-21 12:19:12 +00001204 void PrintHeader(FILE* out, const char* id);
1205#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001206
whesse@chromium.org023421e2010-12-21 12:19:12 +00001207#ifdef DEBUG
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001208 void HeapObjectVerify();
1209 inline void VerifyObjectField(int offset);
1210 inline void VerifySmiField(int offset);
1211
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001212 // Verify a pointer is a valid HeapObject pointer that points to object
1213 // areas in the heap.
1214 static void VerifyHeapPointer(Object* p);
1215#endif
1216
1217 // Layout description.
1218 // First field in a heap object is map.
ager@chromium.org236ad962008-09-25 09:45:57 +00001219 static const int kMapOffset = Object::kHeaderSize;
1220 static const int kHeaderSize = kMapOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001221
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001222 STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset);
1223
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001224 protected:
1225 // helpers for calling an ObjectVisitor to iterate over pointers in the
1226 // half-open range [start, end) specified as integer offsets
1227 inline void IteratePointers(ObjectVisitor* v, int start, int end);
1228 // as above, for the single element at "offset"
1229 inline void IteratePointer(ObjectVisitor* v, int offset);
1230
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001231 private:
1232 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1233};
1234
1235
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00001236#define SLOT_ADDR(obj, offset) \
1237 reinterpret_cast<Object**>((obj)->address() + offset)
1238
1239// This class describes a body of an object of a fixed size
1240// in which all pointer fields are located in the [start_offset, end_offset)
1241// interval.
1242template<int start_offset, int end_offset, int size>
1243class FixedBodyDescriptor {
1244 public:
1245 static const int kStartOffset = start_offset;
1246 static const int kEndOffset = end_offset;
1247 static const int kSize = size;
1248
1249 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v);
1250
1251 template<typename StaticVisitor>
1252 static inline void IterateBody(HeapObject* obj) {
1253 StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset),
1254 SLOT_ADDR(obj, end_offset));
1255 }
1256};
1257
1258
1259// This class describes a body of an object of a variable size
1260// in which all pointer fields are located in the [start_offset, object_size)
1261// interval.
1262template<int start_offset>
1263class FlexibleBodyDescriptor {
1264 public:
1265 static const int kStartOffset = start_offset;
1266
1267 static inline void IterateBody(HeapObject* obj,
1268 int object_size,
1269 ObjectVisitor* v);
1270
1271 template<typename StaticVisitor>
1272 static inline void IterateBody(HeapObject* obj, int object_size) {
1273 StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset),
1274 SLOT_ADDR(obj, object_size));
1275 }
1276};
1277
1278#undef SLOT_ADDR
1279
1280
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001281// The HeapNumber class describes heap allocated numbers that cannot be
1282// represented in a Smi (small integer)
1283class HeapNumber: public HeapObject {
1284 public:
1285 // [value]: number value.
1286 inline double value();
1287 inline void set_value(double value);
1288
1289 // Casting.
1290 static inline HeapNumber* cast(Object* obj);
1291
1292 // Dispatched behavior.
1293 Object* HeapNumberToBoolean();
whesse@chromium.org023421e2010-12-21 12:19:12 +00001294 inline void HeapNumberPrint() {
1295 HeapNumberPrint(stdout);
1296 }
1297 void HeapNumberPrint(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001298 void HeapNumberPrint(StringStream* accumulator);
1299#ifdef DEBUG
1300 void HeapNumberVerify();
1301#endif
1302
whesse@chromium.orgcec079d2010-03-22 14:44:04 +00001303 inline int get_exponent();
1304 inline int get_sign();
1305
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001306 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00001307 static const int kValueOffset = HeapObject::kHeaderSize;
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001308 // IEEE doubles are two 32 bit words. The first is just mantissa, the second
1309 // is a mixture of sign, exponent and mantissa. Our current platforms are all
1310 // little endian apart from non-EABI arm which is little endian with big
1311 // endian floating point word ordering!
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001312 static const int kMantissaOffset = kValueOffset;
1313 static const int kExponentOffset = kValueOffset + 4;
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001314
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001315 static const int kSize = kValueOffset + kDoubleSize;
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001316 static const uint32_t kSignMask = 0x80000000u;
1317 static const uint32_t kExponentMask = 0x7ff00000u;
1318 static const uint32_t kMantissaMask = 0xfffffu;
ager@chromium.orgac091b72010-05-05 07:34:42 +00001319 static const int kMantissaBits = 52;
whesse@chromium.org2c186ca2010-06-16 11:32:39 +00001320 static const int kExponentBits = 11;
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001321 static const int kExponentBias = 1023;
1322 static const int kExponentShift = 20;
1323 static const int kMantissaBitsInTopWord = 20;
1324 static const int kNonMantissaBitsInTopWord = 12;
1325
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001326 private:
1327 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
1328};
1329
1330
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001331enum EnsureElementsMode {
1332 DONT_ALLOW_DOUBLE_ELEMENTS,
1333 ALLOW_COPIED_DOUBLE_ELEMENTS,
1334 ALLOW_CONVERTED_DOUBLE_ELEMENTS
1335};
1336
1337
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001338// Indicates whether a property should be set or (re)defined. Setting of a
1339// property causes attributes to remain unchanged, writability to be checked
1340// and callbacks to be called. Defining of a property causes attributes to
1341// be updated and callbacks to be overridden.
1342enum SetPropertyMode {
1343 SET_PROPERTY,
1344 DEFINE_PROPERTY
1345};
1346
1347
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00001348// Indicator for one component of an AccessorPair.
1349enum AccessorComponent {
1350 ACCESSOR_GETTER,
1351 ACCESSOR_SETTER
1352};
1353
1354
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001355// JSReceiver includes types on which properties can be defined, i.e.,
1356// JSObject and JSProxy.
1357class JSReceiver: public HeapObject {
1358 public:
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001359 enum DeleteMode {
1360 NORMAL_DELETION,
1361 STRICT_DELETION,
1362 FORCE_DELETION
1363 };
1364
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001365 // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
1366 // a keyed store is of the form a[expression] = foo.
1367 enum StoreFromKeyed {
1368 MAY_BE_STORE_FROM_KEYED,
1369 CERTAINLY_NOT_STORE_FROM_KEYED
1370 };
1371
mstarzinger@chromium.orgccab3672012-06-14 15:01:16 +00001372 // Internal properties (e.g. the hidden properties dictionary) might
1373 // be added even though the receiver is non-extensible.
1374 enum ExtensibilityCheck {
1375 PERFORM_EXTENSIBILITY_CHECK,
1376 OMIT_EXTENSIBILITY_CHECK
1377 };
1378
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001379 // Casting.
1380 static inline JSReceiver* cast(Object* obj);
1381
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001382 static Handle<Object> SetProperty(Handle<JSReceiver> object,
1383 Handle<String> key,
1384 Handle<Object> value,
1385 PropertyAttributes attributes,
1386 StrictModeFlag strict_mode);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001387 // Can cause GC.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001388 MUST_USE_RESULT MaybeObject* SetProperty(
1389 String* key,
1390 Object* value,
1391 PropertyAttributes attributes,
1392 StrictModeFlag strict_mode,
1393 StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED);
1394 MUST_USE_RESULT MaybeObject* SetProperty(
1395 LookupResult* result,
1396 String* key,
1397 Object* value,
1398 PropertyAttributes attributes,
1399 StrictModeFlag strict_mode,
1400 StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001401 MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSReceiver* setter,
1402 Object* value);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001403
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001404 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001405 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1406
1407 // Set the index'th array element.
1408 // Can cause GC, or return failure if GC is required.
1409 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index,
1410 Object* value,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001411 PropertyAttributes attributes,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001412 StrictModeFlag strict_mode,
1413 bool check_prototype);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001414
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001415 // Tests for the fast common case for property enumeration.
1416 bool IsSimpleEnum();
1417
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001418 // Returns the class name ([[Class]] property in the specification).
1419 String* class_name();
1420
1421 // Returns the constructor name (the name (possibly, inferred name) of the
1422 // function that was used to instantiate the object).
1423 String* constructor_name();
1424
1425 inline PropertyAttributes GetPropertyAttribute(String* name);
1426 PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver,
1427 String* name);
1428 PropertyAttributes GetLocalPropertyAttribute(String* name);
1429
1430 // Can cause a GC.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001431 inline bool HasProperty(String* name);
1432 inline bool HasLocalProperty(String* name);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001433 inline bool HasElement(uint32_t index);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001434
1435 // Return the object's prototype (might be Heap::null_value()).
1436 inline Object* GetPrototype();
1437
yangguo@chromium.orgc74d6742012-06-29 15:15:45 +00001438 // Return the constructor function (may be Heap::null_value()).
1439 inline Object* GetConstructor();
1440
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001441 // Set the object's prototype (only JSReceiver and null are allowed).
1442 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value,
1443 bool skip_hidden_prototypes);
1444
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001445 // Retrieves a permanent object identity hash code. The undefined value might
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001446 // be returned in case no hash was created yet and OMIT_CREATION was used.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001447 inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1448
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001449 // Lookup a property. If found, the result is valid and has
1450 // detailed information.
1451 void LocalLookup(String* name, LookupResult* result);
1452 void Lookup(String* name, LookupResult* result);
1453
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001454 protected:
1455 Smi* GenerateIdentityHash();
1456
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001457 private:
1458 PropertyAttributes GetPropertyAttribute(JSReceiver* receiver,
1459 LookupResult* result,
1460 String* name,
1461 bool continue_search);
1462
1463 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver);
1464};
1465
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001466// The JSObject describes real heap allocated JavaScript objects with
1467// properties.
1468// Note that the map of JSObject changes during execution to enable inline
1469// caching.
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001470class JSObject: public JSReceiver {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001471 public:
1472 // [properties]: Backing storage for properties.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00001473 // properties is a FixedArray in the fast case and a Dictionary in the
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001474 // slow case.
1475 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001476 inline void initialize_properties();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001477 inline bool HasFastProperties();
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001478 inline StringDictionary* property_dictionary(); // Gets slow properties.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001479
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001480 // [elements]: The elements (properties with names that are integers).
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001481 //
1482 // Elements can be in two general modes: fast and slow. Each mode
1483 // corrensponds to a set of object representations of elements that
1484 // have something in common.
1485 //
1486 // In the fast mode elements is a FixedArray and so each element can
1487 // be quickly accessed. This fact is used in the generated code. The
whesse@chromium.org7b260152011-06-20 15:33:18 +00001488 // elements array can have one of three maps in this mode:
1489 // fixed_array_map, non_strict_arguments_elements_map or
1490 // fixed_cow_array_map (for copy-on-write arrays). In the latter case
1491 // the elements array may be shared by a few objects and so before
1492 // writing to any element the array must be copied. Use
1493 // EnsureWritableFastElements in this case.
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001494 //
whesse@chromium.org7b260152011-06-20 15:33:18 +00001495 // In the slow mode the elements is either a NumberDictionary, an
1496 // ExternalArray, or a FixedArray parameter map for a (non-strict)
1497 // arguments object.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001498 DECL_ACCESSORS(elements, FixedArrayBase)
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001499 inline void initialize_elements();
lrn@chromium.org303ada72010-10-27 09:33:13 +00001500 MUST_USE_RESULT inline MaybeObject* ResetElements();
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001501 inline ElementsKind GetElementsKind();
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00001502 inline ElementsAccessor* GetElementsAccessor();
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001503 // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind.
1504 inline bool HasFastSmiElements();
1505 // Returns true if an object has elements of FAST_ELEMENTS ElementsKind.
1506 inline bool HasFastObjectElements();
1507 // Returns true if an object has elements of FAST_ELEMENTS or
1508 // FAST_SMI_ONLY_ELEMENTS.
1509 inline bool HasFastSmiOrObjectElements();
1510 // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS
1511 // ElementsKind.
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001512 inline bool HasFastDoubleElements();
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001513 // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS
1514 // ElementsKind.
1515 inline bool HasFastHoleyElements();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001516 inline bool HasNonStrictArgumentsElements();
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001517 inline bool HasDictionaryElements();
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00001518 inline bool HasExternalPixelElements();
ager@chromium.org3811b432009-10-28 14:53:37 +00001519 inline bool HasExternalArrayElements();
1520 inline bool HasExternalByteElements();
1521 inline bool HasExternalUnsignedByteElements();
1522 inline bool HasExternalShortElements();
1523 inline bool HasExternalUnsignedShortElements();
1524 inline bool HasExternalIntElements();
1525 inline bool HasExternalUnsignedIntElements();
1526 inline bool HasExternalFloatElements();
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00001527 inline bool HasExternalDoubleElements();
whesse@chromium.org7b260152011-06-20 15:33:18 +00001528 bool HasFastArgumentsElements();
1529 bool HasDictionaryArgumentsElements();
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001530 inline SeededNumberDictionary* element_dictionary(); // Gets slow elements.
whesse@chromium.org7b260152011-06-20 15:33:18 +00001531
svenpanne@chromium.org3c93e772012-01-02 09:26:59 +00001532 inline void set_map_and_elements(
1533 Map* map,
1534 FixedArrayBase* value,
1535 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
1536
whesse@chromium.org7b260152011-06-20 15:33:18 +00001537 // Requires: HasFastElements().
lrn@chromium.org303ada72010-10-27 09:33:13 +00001538 MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001539
ager@chromium.org5ec48922009-05-05 07:25:34 +00001540 // Collects elements starting at index 0.
1541 // Undefined values are placed after non-undefined values.
1542 // Returns the number of non-undefined values.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001543 MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit);
ager@chromium.org5ec48922009-05-05 07:25:34 +00001544 // As PrepareElementsForSort, but only on objects where elements is
1545 // a dictionary, and it will stay a dictionary.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001546 MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit);
ager@chromium.org5ec48922009-05-05 07:25:34 +00001547
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001548 MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver,
1549 Object* structure,
1550 String* name);
1551
1552 // Can cause GC.
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001553 MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result,
lrn@chromium.org303ada72010-10-27 09:33:13 +00001554 String* key,
1555 Object* value,
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001556 PropertyAttributes attributes,
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001557 StrictModeFlag strict_mode,
1558 StoreFromKeyed store_mode);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001559 MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck(
1560 LookupResult* result,
1561 String* name,
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001562 Object* value,
ricow@chromium.orgc54d3652011-05-30 09:20:16 +00001563 bool check_prototype,
1564 StrictModeFlag strict_mode);
1565 MUST_USE_RESULT MaybeObject* SetPropertyWithCallback(
1566 Object* structure,
1567 String* name,
1568 Object* value,
1569 JSObject* holder,
1570 StrictModeFlag strict_mode);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001571 MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor(
1572 String* name,
1573 Object* value,
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001574 PropertyAttributes attributes,
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00001575 StrictModeFlag strict_mode);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001576 MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor(
1577 String* name,
1578 Object* value,
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001579 PropertyAttributes attributes,
mstarzinger@chromium.orgccab3672012-06-14 15:01:16 +00001580 StrictModeFlag strict_mode,
1581 ExtensibilityCheck extensibility_check);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001582
1583 static Handle<Object> SetLocalPropertyIgnoreAttributes(
1584 Handle<JSObject> object,
1585 Handle<String> key,
1586 Handle<Object> value,
1587 PropertyAttributes attributes);
1588
1589 // Can cause GC.
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001590 MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes(
lrn@chromium.org303ada72010-10-27 09:33:13 +00001591 String* key,
1592 Object* value,
1593 PropertyAttributes attributes);
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001594
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001595 // Retrieve a value in a normalized object given a lookup result.
1596 // Handles the special representation of JS global objects.
1597 Object* GetNormalizedProperty(LookupResult* result);
1598
1599 // Sets the property value in a normalized object given a lookup result.
1600 // Handles the special representation of JS global objects.
1601 Object* SetNormalizedProperty(LookupResult* result, Object* value);
1602
1603 // Sets the property value in a normalized object given (key, value, details).
1604 // Handles the special representation of JS global objects.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001605 static Handle<Object> SetNormalizedProperty(Handle<JSObject> object,
1606 Handle<String> key,
1607 Handle<Object> value,
1608 PropertyDetails details);
1609
lrn@chromium.org303ada72010-10-27 09:33:13 +00001610 MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name,
1611 Object* value,
1612 PropertyDetails details);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001613
1614 // Deletes the named property in a normalized object.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001615 MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name,
1616 DeleteMode mode);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001617
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001618 MUST_USE_RESULT MaybeObject* OptimizeAsPrototype();
1619
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001620 // Retrieve interceptors.
1621 InterceptorInfo* GetNamedInterceptor();
1622 InterceptorInfo* GetIndexedInterceptor();
1623
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001624 // Used from JSReceiver.
1625 PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver,
1626 String* name,
1627 bool continue_search);
1628 PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver,
1629 String* name,
1630 bool continue_search);
1631 PropertyAttributes GetPropertyAttributeWithFailedAccessCheck(
1632 Object* receiver,
1633 LookupResult* result,
1634 String* name,
1635 bool continue_search);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001636
danno@chromium.org88aa0582012-03-23 15:11:57 +00001637 static void DefineAccessor(Handle<JSObject> object,
1638 Handle<String> name,
1639 Handle<Object> getter,
1640 Handle<Object> setter,
1641 PropertyAttributes attributes);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001642 MUST_USE_RESULT MaybeObject* DefineAccessor(String* name,
danno@chromium.org88aa0582012-03-23 15:11:57 +00001643 Object* getter,
1644 Object* setter,
lrn@chromium.org303ada72010-10-27 09:33:13 +00001645 PropertyAttributes attributes);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001646 // Try to define a single accessor paying attention to map transitions.
1647 // Returns a JavaScript null if this was not possible and we have to use the
1648 // slow case. Note that we can fail due to allocations, too.
1649 MUST_USE_RESULT MaybeObject* DefineFastAccessor(
1650 String* name,
1651 AccessorComponent component,
1652 Object* accessor,
1653 PropertyAttributes attributes);
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00001654 Object* LookupAccessor(String* name, AccessorComponent component);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001655
lrn@chromium.org303ada72010-10-27 09:33:13 +00001656 MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info);
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00001657
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001658 // Used from Object::GetProperty().
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001659 MUST_USE_RESULT MaybeObject* GetPropertyWithFailedAccessCheck(
lrn@chromium.org303ada72010-10-27 09:33:13 +00001660 Object* receiver,
1661 LookupResult* result,
1662 String* name,
1663 PropertyAttributes* attributes);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001664 MUST_USE_RESULT MaybeObject* GetPropertyWithInterceptor(
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001665 JSReceiver* receiver,
lrn@chromium.org303ada72010-10-27 09:33:13 +00001666 String* name,
1667 PropertyAttributes* attributes);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001668 MUST_USE_RESULT MaybeObject* GetPropertyPostInterceptor(
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001669 JSReceiver* receiver,
lrn@chromium.org303ada72010-10-27 09:33:13 +00001670 String* name,
1671 PropertyAttributes* attributes);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001672 MUST_USE_RESULT MaybeObject* GetLocalPropertyPostInterceptor(
1673 JSReceiver* receiver,
1674 String* name,
1675 PropertyAttributes* attributes);
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00001676
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00001677 // Returns true if this is an instance of an api function and has
1678 // been modified since it was created. May give false positives.
1679 bool IsDirty();
1680
ager@chromium.orgc4c92722009-11-18 14:12:51 +00001681 // If the receiver is a JSGlobalProxy this method will return its prototype,
1682 // otherwise the result is the receiver itself.
1683 inline Object* BypassGlobalProxy();
1684
1685 // Accessors for hidden properties object.
1686 //
1687 // Hidden properties are not local properties of the object itself.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001688 // Instead they are stored in an auxiliary structure kept as a local
ager@chromium.orgc4c92722009-11-18 14:12:51 +00001689 // property with a special name Heap::hidden_symbol(). But if the
1690 // receiver is a JSGlobalProxy then the auxiliary object is a property
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001691 // of its prototype, and if it's a detached proxy, then you can't have
1692 // hidden properties.
ager@chromium.orgc4c92722009-11-18 14:12:51 +00001693
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001694 // Sets a hidden property on this object. Returns this object if successful,
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001695 // undefined if called on a detached proxy.
1696 static Handle<Object> SetHiddenProperty(Handle<JSObject> obj,
1697 Handle<String> key,
1698 Handle<Object> value);
1699 // Returns a failure if a GC is required.
jkummerow@chromium.orgab7dad42012-02-07 12:07:34 +00001700 MUST_USE_RESULT MaybeObject* SetHiddenProperty(String* key, Object* value);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001701 // Gets the value of a hidden property with the given key. Returns undefined
1702 // if the property doesn't exist (or if called on a detached proxy),
1703 // otherwise returns the value set for the key.
1704 Object* GetHiddenProperty(String* key);
1705 // Deletes a hidden property. Deleting a non-existing property is
1706 // considered successful.
1707 void DeleteHiddenProperty(String* key);
1708 // Returns true if the object has a property with the hidden symbol as name.
1709 bool HasHiddenProperties();
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001710
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001711 static int GetIdentityHash(Handle<JSObject> obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001712 MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1713 MUST_USE_RESULT MaybeObject* SetIdentityHash(Object* hash, CreationFlag flag);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001714
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001715 static Handle<Object> DeleteProperty(Handle<JSObject> obj,
1716 Handle<String> name);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001717 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001718
1719 static Handle<Object> DeleteElement(Handle<JSObject> obj, uint32_t index);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001720 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001721
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001722 inline void ValidateElements();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001723
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001724 // Makes sure that this object can contain HeapObject as elements.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001725 MUST_USE_RESULT inline MaybeObject* EnsureCanContainHeapObjectElements();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001726
1727 // Makes sure that this object can contain the specified elements.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001728 MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
1729 Object** elements,
1730 uint32_t count,
1731 EnsureElementsMode mode);
1732 MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
1733 FixedArrayBase* elements,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001734 uint32_t length,
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001735 EnsureElementsMode mode);
1736 MUST_USE_RESULT MaybeObject* EnsureCanContainElements(
1737 Arguments* arguments,
1738 uint32_t first_arg,
1739 uint32_t arg_count,
1740 EnsureElementsMode mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001741
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001742 // Do we want to keep the elements in fast case when increasing the
1743 // capacity?
1744 bool ShouldConvertToSlowElements(int new_capacity);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001745 // Returns true if the backing storage for the slow-case elements of
1746 // this object takes up nearly as much space as a fast-case backing
1747 // storage would. In that case the JSObject should have fast
1748 // elements.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001749 bool ShouldConvertToFastElements();
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001750 // Returns true if the elements of JSObject contains only values that can be
svenpanne@chromium.org3c93e772012-01-02 09:26:59 +00001751 // represented in a FixedDoubleArray and has at least one value that can only
1752 // be represented as a double and not a Smi.
1753 bool ShouldConvertToFastDoubleElements(bool* has_smi_only_elements);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001754
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001755 // Tells whether the index'th element is present.
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001756 bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001757
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00001758 // Computes the new capacity when expanding the elements of a JSObject.
1759 static int NewElementsCapacity(int old_capacity) {
1760 // (old_capacity + 50%) + 16
1761 return old_capacity + (old_capacity >> 1) + 16;
1762 }
1763
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001764 // Tells whether the index'th element is present and how it is stored.
1765 enum LocalElementType {
1766 // There is no element with given index.
1767 UNDEFINED_ELEMENT,
1768
1769 // Element with given index is handled by interceptor.
1770 INTERCEPTED_ELEMENT,
1771
1772 // Element with given index is character in string.
1773 STRING_CHARACTER_ELEMENT,
1774
1775 // Element with given index is stored in fast backing store.
1776 FAST_ELEMENT,
1777
1778 // Element with given index is stored in slow backing store.
1779 DICTIONARY_ELEMENT
1780 };
1781
1782 LocalElementType HasLocalElement(uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001783
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001784 bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001785
lrn@chromium.org5d00b602011-01-05 09:51:43 +00001786 MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index,
1787 Object* value,
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00001788 StrictModeFlag strict_mode,
whesse@chromium.org7b260152011-06-20 15:33:18 +00001789 bool check_prototype);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001790
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001791 MUST_USE_RESULT MaybeObject* SetDictionaryElement(
1792 uint32_t index,
1793 Object* value,
1794 PropertyAttributes attributes,
1795 StrictModeFlag strict_mode,
1796 bool check_prototype,
1797 SetPropertyMode set_mode = SET_PROPERTY);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001798
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001799 MUST_USE_RESULT MaybeObject* SetFastDoubleElement(
1800 uint32_t index,
1801 Object* value,
1802 StrictModeFlag strict_mode,
1803 bool check_prototype = true);
1804
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001805 static Handle<Object> SetOwnElement(Handle<JSObject> object,
1806 uint32_t index,
1807 Handle<Object> value,
1808 StrictModeFlag strict_mode);
1809
1810 // Empty handle is returned if the element cannot be set to the given value.
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001811 static MUST_USE_RESULT Handle<Object> SetElement(
1812 Handle<JSObject> object,
1813 uint32_t index,
1814 Handle<Object> value,
1815 PropertyAttributes attr,
1816 StrictModeFlag strict_mode,
1817 SetPropertyMode set_mode = SET_PROPERTY);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001818
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001819 // A Failure object is returned if GC is needed.
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001820 MUST_USE_RESULT MaybeObject* SetElement(
1821 uint32_t index,
1822 Object* value,
1823 PropertyAttributes attributes,
1824 StrictModeFlag strict_mode,
1825 bool check_prototype = true,
1826 SetPropertyMode set_mode = SET_PROPERTY);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001827
1828 // Returns the index'th element.
1829 // The undefined object if index is out of bounds.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001830 MUST_USE_RESULT MaybeObject* GetElementWithInterceptor(Object* receiver,
1831 uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001832
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001833 enum SetFastElementsCapacitySmiMode {
1834 kAllowSmiElements,
1835 kForceSmiElements,
1836 kDontAllowSmiElements
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001837 };
1838
whesse@chromium.org7b260152011-06-20 15:33:18 +00001839 // Replace the elements' backing store with fast elements of the given
1840 // capacity. Update the length for JSArrays. Returns the new backing
1841 // store.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001842 MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(
1843 int capacity,
1844 int length,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001845 SetFastElementsCapacitySmiMode smi_mode);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001846 MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength(
1847 int capacity,
1848 int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001849
1850 // Lookup interceptors are used for handling properties controlled by host
1851 // objects.
1852 inline bool HasNamedInterceptor();
1853 inline bool HasIndexedInterceptor();
1854
1855 // Support functions for v8 api (needed for correct interceptor behavior).
1856 bool HasRealNamedProperty(String* key);
1857 bool HasRealElementProperty(uint32_t index);
1858 bool HasRealNamedCallbackProperty(String* key);
1859
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001860 // Get the header size for a JSObject. Used to compute the index of
1861 // internal fields as well as the number of internal fields.
1862 inline int GetHeaderSize();
1863
1864 inline int GetInternalFieldCount();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001865 inline int GetInternalFieldOffset(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001866 inline Object* GetInternalField(int index);
1867 inline void SetInternalField(int index, Object* value);
ricow@chromium.org27bf2882011-11-17 08:34:43 +00001868 inline void SetInternalField(int index, Smi* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001869
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001870 // The following lookup functions skip interceptors.
1871 void LocalLookupRealNamedProperty(String* name, LookupResult* result);
1872 void LookupRealNamedProperty(String* name, LookupResult* result);
1873 void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result);
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001874 MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes(
ricow@chromium.orgc54d3652011-05-30 09:20:16 +00001875 uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode);
ager@chromium.org870a0b62008-11-04 11:43:05 +00001876 void LookupCallback(String* name, LookupResult* result);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001877
1878 // Returns the number of properties on this object filtering out properties
1879 // with the specified attributes (ignoring interceptors).
jkummerow@chromium.orgab7dad42012-02-07 12:07:34 +00001880 int NumberOfLocalProperties(PropertyAttributes filter = NONE);
ager@chromium.orgddb913d2009-01-27 10:01:48 +00001881 // Fill in details for properties into storage starting at the specified
1882 // index.
1883 void GetLocalPropertyNames(FixedArray* storage, int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001884
1885 // Returns the number of properties on this object filtering out properties
1886 // with the specified attributes (ignoring interceptors).
1887 int NumberOfLocalElements(PropertyAttributes filter);
1888 // Returns the number of enumerable elements (ignoring interceptors).
1889 int NumberOfEnumElements();
1890 // Returns the number of elements on this object filtering out elements
1891 // with the specified attributes (ignoring interceptors).
1892 int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter);
1893 // Count and fill in the enumerable elements into storage.
1894 // (storage->length() == NumberOfEnumElements()).
1895 // If storage is NULL, will count the elements without adding
1896 // them to any storage.
1897 // Returns the number of enumerable elements.
1898 int GetEnumElementKeys(FixedArray* storage);
1899
1900 // Add a property to a fast-case object using a map transition to
1901 // new_map.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001902 MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map,
1903 String* name,
1904 Object* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001905
1906 // Add a constant function property to a fast-case object.
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001907 // This leaves a CONSTANT_TRANSITION in the old map, and
1908 // if it is called on a second object with this map, a
1909 // normal property is added instead, with a map transition.
1910 // This avoids the creation of many maps with the same constant
1911 // function, all orphaned.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001912 MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty(
1913 String* name,
1914 JSFunction* function,
1915 PropertyAttributes attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001916
lrn@chromium.org303ada72010-10-27 09:33:13 +00001917 MUST_USE_RESULT MaybeObject* ReplaceSlowProperty(
1918 String* name,
1919 Object* value,
1920 PropertyAttributes attributes);
ager@chromium.org7c537e22008-10-16 08:43:32 +00001921
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001922 // Returns a new map with all transitions dropped from the object's current
1923 // map and the ElementsKind set.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001924 static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
1925 ElementsKind to_kind);
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001926 inline MUST_USE_RESULT MaybeObject* GetElementsTransitionMap(
1927 Isolate* isolate,
1928 ElementsKind elements_kind);
1929 MUST_USE_RESULT MaybeObject* GetElementsTransitionMapSlow(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001930 ElementsKind elements_kind);
1931
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001932 static Handle<Object> TransitionElementsKind(Handle<JSObject> object,
1933 ElementsKind to_kind);
1934
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001935 MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind);
1936
ager@chromium.org7c537e22008-10-16 08:43:32 +00001937 // Converts a descriptor of any other type to a real field,
1938 // backed by the properties array. Descriptors of visible
1939 // types, such as CONSTANT_FUNCTION, keep their enumeration order.
1940 // Converts the descriptor on the original object's map to a
1941 // map transition, and the the new field is on the object's new map.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001942 MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition(
ager@chromium.org7c537e22008-10-16 08:43:32 +00001943 String* name,
1944 Object* new_value,
1945 PropertyAttributes attributes);
1946
1947 // Converts a descriptor of any other type to a real field,
1948 // backed by the properties array. Descriptors of visible
1949 // types, such as CONSTANT_FUNCTION, keep their enumeration order.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001950 MUST_USE_RESULT MaybeObject* ConvertDescriptorToField(
1951 String* name,
1952 Object* new_value,
1953 PropertyAttributes attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001954
1955 // Add a property to a fast-case object.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001956 MUST_USE_RESULT MaybeObject* AddFastProperty(
1957 String* name,
1958 Object* value,
1959 PropertyAttributes attributes,
1960 StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001961
1962 // Add a property to a slow-case object.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001963 MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name,
1964 Object* value,
1965 PropertyAttributes attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001966
1967 // Add a property to an object.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001968 MUST_USE_RESULT MaybeObject* AddProperty(
1969 String* name,
1970 Object* value,
1971 PropertyAttributes attributes,
1972 StrictModeFlag strict_mode,
mstarzinger@chromium.orgccab3672012-06-14 15:01:16 +00001973 StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED,
1974 ExtensibilityCheck extensibility_check = PERFORM_EXTENSIBILITY_CHECK);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001975
1976 // Convert the object to use the canonical dictionary
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001977 // representation. If the object is expected to have additional properties
1978 // added this number can be indicated to have the backing store allocated to
1979 // an initial capacity for holding these properties.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001980 static void NormalizeProperties(Handle<JSObject> object,
1981 PropertyNormalizationMode mode,
1982 int expected_additional_properties);
1983
lrn@chromium.org303ada72010-10-27 09:33:13 +00001984 MUST_USE_RESULT MaybeObject* NormalizeProperties(
1985 PropertyNormalizationMode mode,
1986 int expected_additional_properties);
whesse@chromium.org7b260152011-06-20 15:33:18 +00001987
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001988 // Convert and update the elements backing store to be a
1989 // SeededNumberDictionary dictionary. Returns the backing after conversion.
1990 static Handle<SeededNumberDictionary> NormalizeElements(
1991 Handle<JSObject> object);
1992
lrn@chromium.org303ada72010-10-27 09:33:13 +00001993 MUST_USE_RESULT MaybeObject* NormalizeElements();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001994
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001995 static void UpdateMapCodeCache(Handle<JSObject> object,
1996 Handle<String> name,
1997 Handle<Code> code);
1998
lrn@chromium.org303ada72010-10-27 09:33:13 +00001999 MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code);
ricow@chromium.org65fae842010-08-25 15:26:24 +00002000
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002001 // Transform slow named properties to fast variants.
2002 // Returns failure if allocation failed.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002003 static void TransformToFastProperties(Handle<JSObject> object,
2004 int unused_property_fields);
2005
lrn@chromium.org303ada72010-10-27 09:33:13 +00002006 MUST_USE_RESULT MaybeObject* TransformToFastProperties(
2007 int unused_property_fields);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002008
ager@chromium.org7c537e22008-10-16 08:43:32 +00002009 // Access fast-case object properties at index.
2010 inline Object* FastPropertyAt(int index);
2011 inline Object* FastPropertyAtPut(int index, Object* value);
2012
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002013 // Access to in object properties.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002014 inline int GetInObjectPropertyOffset(int index);
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002015 inline Object* InObjectPropertyAt(int index);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002016 inline Object* InObjectPropertyAtPut(int index,
2017 Object* value,
2018 WriteBarrierMode mode
2019 = UPDATE_WRITE_BARRIER);
ager@chromium.org7c537e22008-10-16 08:43:32 +00002020
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002021 // Initializes the body after properties slot, properties slot is
2022 // initialized by set_properties. Fill the pre-allocated fields with
2023 // pre_allocated_value and the rest with filler_value.
2024 // Note: this call does not update write barrier, the caller is responsible
2025 // to ensure that |filler_value| can be collected without WB here.
2026 inline void InitializeBody(Map* map,
2027 Object* pre_allocated_value,
2028 Object* filler_value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002029
2030 // Check whether this object references another object
2031 bool ReferencesObject(Object* obj);
2032
2033 // Casting.
2034 static inline JSObject* cast(Object* obj);
2035
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00002036 // Disalow further properties to be added to the object.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002037 static Handle<Object> PreventExtensions(Handle<JSObject> object);
lrn@chromium.org303ada72010-10-27 09:33:13 +00002038 MUST_USE_RESULT MaybeObject* PreventExtensions();
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00002039
2040
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002041 // Dispatched behavior.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002042 void JSObjectShortPrint(StringStream* accumulator);
whesse@chromium.org023421e2010-12-21 12:19:12 +00002043#ifdef OBJECT_PRINT
2044 inline void JSObjectPrint() {
2045 JSObjectPrint(stdout);
2046 }
2047 void JSObjectPrint(FILE* out);
2048#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002049#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002050 void JSObjectVerify();
whesse@chromium.org023421e2010-12-21 12:19:12 +00002051#endif
2052#ifdef OBJECT_PRINT
2053 inline void PrintProperties() {
2054 PrintProperties(stdout);
2055 }
2056 void PrintProperties(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002057
whesse@chromium.org023421e2010-12-21 12:19:12 +00002058 inline void PrintElements() {
2059 PrintElements(stdout);
2060 }
2061 void PrintElements(FILE* out);
2062#endif
2063
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002064 void PrintElementsTransition(
2065 FILE* file, ElementsKind from_kind, FixedArrayBase* from_elements,
2066 ElementsKind to_kind, FixedArrayBase* to_elements);
2067
whesse@chromium.org023421e2010-12-21 12:19:12 +00002068#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002069 // Structure for collecting spill information about JSObjects.
2070 class SpillInformation {
2071 public:
2072 void Clear();
2073 void Print();
2074 int number_of_objects_;
2075 int number_of_objects_with_fast_properties_;
2076 int number_of_objects_with_fast_elements_;
2077 int number_of_fast_used_fields_;
2078 int number_of_fast_unused_fields_;
2079 int number_of_slow_used_properties_;
2080 int number_of_slow_unused_properties_;
2081 int number_of_fast_used_elements_;
2082 int number_of_fast_unused_elements_;
2083 int number_of_slow_used_elements_;
2084 int number_of_slow_unused_elements_;
2085 };
2086
2087 void IncrementSpillStatistics(SpillInformation* info);
2088#endif
2089 Object* SlowReverseLookup(Object* value);
2090
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00002091 // Maximal number of fast properties for the JSObject. Used to
2092 // restrict the number of map transitions to avoid an explosion in
2093 // the number of maps for objects used as dictionaries.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002094 inline bool TooManyFastProperties(int properties, StoreFromKeyed store_mode);
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00002095
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002096 // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
2097 // Also maximal value of JSArray's length property.
2098 static const uint32_t kMaxElementCount = 0xffffffffu;
2099
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002100 // Constants for heuristics controlling conversion of fast elements
2101 // to slow elements.
2102
2103 // Maximal gap that can be introduced by adding an element beyond
2104 // the current elements length.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002105 static const uint32_t kMaxGap = 1024;
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002106
2107 // Maximal length of fast elements array that won't be checked for
2108 // being dense enough on expansion.
2109 static const int kMaxUncheckedFastElementsLength = 5000;
2110
2111 // Same as above but for old arrays. This limit is more strict. We
2112 // don't want to be wasteful with long lived objects.
2113 static const int kMaxUncheckedOldFastElementsLength = 500;
2114
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00002115 static const int kInitialMaxFastElementArray = 100000;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002116 static const int kFastPropertiesSoftLimit = 12;
2117 static const int kMaxFastProperties = 64;
ager@chromium.org7c537e22008-10-16 08:43:32 +00002118 static const int kMaxInstanceSize = 255 * kPointerSize;
2119 // When extending the backing storage for property values, we increase
2120 // its size by more than the 1 entry necessary, so sequentially adding fields
2121 // to the same object requires fewer allocations and copies.
2122 static const int kFieldsAdded = 3;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002123
2124 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00002125 static const int kPropertiesOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002126 static const int kElementsOffset = kPropertiesOffset + kPointerSize;
2127 static const int kHeaderSize = kElementsOffset + kPointerSize;
2128
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002129 STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize);
2130
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002131 class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> {
2132 public:
2133 static inline int SizeOf(Map* map, HeapObject* object);
2134 };
2135
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002136 private:
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00002137 friend class DictionaryElementsAccessor;
2138
lrn@chromium.org303ada72010-10-27 09:33:13 +00002139 MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver,
2140 Object* structure,
2141 uint32_t index,
2142 Object* holder);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002143 MUST_USE_RESULT MaybeObject* SetElementWithCallback(
2144 Object* structure,
2145 uint32_t index,
2146 Object* value,
2147 JSObject* holder,
2148 StrictModeFlag strict_mode);
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00002149 MUST_USE_RESULT MaybeObject* SetElementWithInterceptor(
2150 uint32_t index,
2151 Object* value,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00002152 PropertyAttributes attributes,
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00002153 StrictModeFlag strict_mode,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00002154 bool check_prototype,
2155 SetPropertyMode set_mode);
lrn@chromium.org5d00b602011-01-05 09:51:43 +00002156 MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor(
2157 uint32_t index,
2158 Object* value,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00002159 PropertyAttributes attributes,
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00002160 StrictModeFlag strict_mode,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00002161 bool check_prototype,
2162 SetPropertyMode set_mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002163
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002164 // Searches the prototype chain for property 'name'. If it is found and
2165 // has a setter, invoke it and set '*done' to true. If it is found and is
2166 // read-only, reject and set '*done' to true. Otherwise, set '*done' to
2167 // false. Can cause GC and can return a failure result with '*done==true'.
2168 MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypes(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002169 String* name,
2170 Object* value,
2171 PropertyAttributes attributes,
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002172 StrictModeFlag strict_mode,
2173 bool* done);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002174
lrn@chromium.org303ada72010-10-27 09:33:13 +00002175 MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name,
2176 DeleteMode mode);
2177 MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002178
lrn@chromium.org303ada72010-10-27 09:33:13 +00002179 MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002180
whesse@chromium.org7b260152011-06-20 15:33:18 +00002181 MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index);
2182 MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index,
2183 DeleteMode mode);
2184
2185 bool ReferencesObjectFromElements(FixedArray* elements,
2186 ElementsKind kind,
2187 Object* object);
whesse@chromium.org7b260152011-06-20 15:33:18 +00002188
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002189 // Returns true if most of the elements backing storage is used.
2190 bool HasDenseElements();
2191
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002192 // Gets the current elements capacity and the number of used elements.
2193 void GetElementsCapacityAndUsage(int* capacity, int* used);
2194
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00002195 bool CanSetCallback(String* name);
lrn@chromium.org303ada72010-10-27 09:33:13 +00002196 MUST_USE_RESULT MaybeObject* SetElementCallback(
2197 uint32_t index,
2198 Object* structure,
2199 PropertyAttributes attributes);
2200 MUST_USE_RESULT MaybeObject* SetPropertyCallback(
2201 String* name,
2202 Object* structure,
2203 PropertyAttributes attributes);
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002204 MUST_USE_RESULT MaybeObject* DefineElementAccessor(
2205 uint32_t index,
danno@chromium.org88aa0582012-03-23 15:11:57 +00002206 Object* getter,
2207 Object* setter,
lrn@chromium.org303ada72010-10-27 09:33:13 +00002208 PropertyAttributes attributes);
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00002209 MUST_USE_RESULT MaybeObject* CreateAccessorPairFor(String* name);
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002210 MUST_USE_RESULT MaybeObject* DefinePropertyAccessor(
2211 String* name,
danno@chromium.org88aa0582012-03-23 15:11:57 +00002212 Object* getter,
2213 Object* setter,
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002214 PropertyAttributes attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002215 void LookupInDescriptor(String* name, LookupResult* result);
2216
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002217 // Returns the hidden properties backing store object, currently
2218 // a StringDictionary, stored on this object.
2219 // If no hidden properties object has been put on this object,
2220 // return undefined, unless create_if_absent is true, in which case
2221 // a new dictionary is created, added to this object, and returned.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002222 MUST_USE_RESULT MaybeObject* GetHiddenPropertiesDictionary(
2223 bool create_if_absent);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002224 // Updates the existing hidden properties dictionary.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002225 MUST_USE_RESULT MaybeObject* SetHiddenPropertiesDictionary(
2226 StringDictionary* dictionary);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002227
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002228 DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
2229};
2230
2231
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002232// Common superclass for FixedArrays that allow implementations to share
2233// common accessors and some code paths.
2234class FixedArrayBase: public HeapObject {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002235 public:
2236 // [length]: length of the array.
2237 inline int length();
2238 inline void set_length(int value);
2239
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002240 inline static FixedArrayBase* cast(Object* object);
2241
2242 // Layout description.
2243 // Length is smi tagged when it is stored.
2244 static const int kLengthOffset = HeapObject::kHeaderSize;
2245 static const int kHeaderSize = kLengthOffset + kPointerSize;
2246};
2247
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00002248
ricow@chromium.org9fa09672011-07-25 11:05:35 +00002249class FixedDoubleArray;
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002250
2251// FixedArray describes fixed-sized arrays with element type Object*.
2252class FixedArray: public FixedArrayBase {
2253 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002254 // Setter and getter for elements.
2255 inline Object* get(int index);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002256 // Setter that uses write barrier.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002257 inline void set(int index, Object* value);
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00002258 inline bool is_the_hole(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002259
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002260 // Setter that doesn't need write barrier).
2261 inline void set(int index, Smi* value);
2262 // Setter with explicit barrier mode.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002263 inline void set(int index, Object* value, WriteBarrierMode mode);
2264
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002265 // Setters for frequently used oddballs located in old space.
2266 inline void set_undefined(int index);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002267 // TODO(isolates): duplicate.
2268 inline void set_undefined(Heap* heap, int index);
ager@chromium.org236ad962008-09-25 09:45:57 +00002269 inline void set_null(int index);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002270 // TODO(isolates): duplicate.
2271 inline void set_null(Heap* heap, int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002272 inline void set_the_hole(int index);
2273
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00002274 // Setters with less debug checks for the GC to use.
2275 inline void set_unchecked(int index, Smi* value);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002276 inline void set_null_unchecked(Heap* heap, int index);
2277 inline void set_unchecked(Heap* heap, int index, Object* value,
2278 WriteBarrierMode mode);
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00002279
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00002280 // Gives access to raw memory which stores the array's data.
2281 inline Object** data_start();
2282
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002283 inline Object** GetFirstElementAddress();
2284 inline bool ContainsOnlySmisOrHoles();
2285
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002286 // Copy operations.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002287 MUST_USE_RESULT inline MaybeObject* Copy();
2288 MUST_USE_RESULT MaybeObject* CopySize(int new_length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002289
2290 // Add the elements of a JSArray to this FixedArray.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002291 MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002292
2293 // Compute the union of this and other.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002294 MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002295
2296 // Copy a sub array from the receiver to dest.
2297 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
2298
2299 // Garbage collection support.
2300 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; }
2301
ager@chromium.org3e875802009-06-29 08:26:34 +00002302 // Code Generation support.
2303 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2304
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002305 // Casting.
2306 static inline FixedArray* cast(Object* obj);
2307
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002308 // Maximal allowed size, in bytes, of a single FixedArray.
2309 // Prevents overflowing size computations, as well as extreme memory
2310 // consumption.
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +00002311 static const int kMaxSize = 128 * MB * kPointerSize;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002312 // Maximally allowed length of a FixedArray.
2313 static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize;
kasperl@chromium.org71affb52009-05-26 05:44:31 +00002314
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002315 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00002316#ifdef OBJECT_PRINT
2317 inline void FixedArrayPrint() {
2318 FixedArrayPrint(stdout);
2319 }
2320 void FixedArrayPrint(FILE* out);
2321#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002322#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002323 void FixedArrayVerify();
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002324 // Checks if two FixedArrays have identical contents.
2325 bool IsEqualTo(FixedArray* other);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002326#endif
2327
ager@chromium.org65dad4b2009-04-23 08:48:43 +00002328 // Swap two elements in a pair of arrays. If this array and the
2329 // numbers array are the same object, the elements are only swapped
2330 // once.
2331 void SwapPairs(FixedArray* numbers, int i, int j);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002332
ager@chromium.org65dad4b2009-04-23 08:48:43 +00002333 // Sort prefix of this array and the numbers array as pairs wrt. the
2334 // numbers. If the numbers array and the this array are the same
2335 // object, the prefix of this array is sorted.
2336 void SortPairs(FixedArray* numbers, uint32_t len);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002337
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002338 class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> {
2339 public:
2340 static inline int SizeOf(Map* map, HeapObject* object) {
2341 return SizeFor(reinterpret_cast<FixedArray*>(object)->length());
2342 }
2343 };
2344
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002345 protected:
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00002346 // Set operation on FixedArray without using write barriers. Can
2347 // only be used for storing old space objects or smis.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002348 static inline void NoWriteBarrierSet(FixedArray* array,
2349 int index,
2350 Object* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002351
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002352 // Set operation on FixedArray without incremental write barrier. Can
2353 // only be used if the object is guaranteed to be white (whiteness witness
2354 // is present).
2355 static inline void NoIncrementalWriteBarrierSet(FixedArray* array,
2356 int index,
2357 Object* value);
2358
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002359 private:
2360 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray);
2361};
2362
2363
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002364// FixedDoubleArray describes fixed-sized arrays with element type double.
2365class FixedDoubleArray: public FixedArrayBase {
2366 public:
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002367 // Setter and getter for elements.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00002368 inline double get_scalar(int index);
danno@chromium.org88aa0582012-03-23 15:11:57 +00002369 inline int64_t get_representation(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002370 MUST_USE_RESULT inline MaybeObject* get(int index);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002371 inline void set(int index, double value);
2372 inline void set_the_hole(int index);
2373
2374 // Checking for the hole.
2375 inline bool is_the_hole(int index);
2376
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002377 // Copy operations
2378 MUST_USE_RESULT inline MaybeObject* Copy();
2379
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002380 // Garbage collection support.
2381 inline static int SizeFor(int length) {
2382 return kHeaderSize + length * kDoubleSize;
2383 }
2384
rossberg@chromium.org717967f2011-07-20 13:44:42 +00002385 // Code Generation support.
2386 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2387
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00002388 inline static bool is_the_hole_nan(double value);
2389 inline static double hole_nan_as_double();
2390 inline static double canonical_not_the_hole_nan_as_double();
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002391
2392 // Casting.
2393 static inline FixedDoubleArray* cast(Object* obj);
2394
2395 // Maximal allowed size, in bytes, of a single FixedDoubleArray.
2396 // Prevents overflowing size computations, as well as extreme memory
2397 // consumption.
2398 static const int kMaxSize = 512 * MB;
2399 // Maximally allowed length of a FixedArray.
2400 static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize;
2401
2402 // Dispatched behavior.
2403#ifdef OBJECT_PRINT
2404 inline void FixedDoubleArrayPrint() {
2405 FixedDoubleArrayPrint(stdout);
2406 }
2407 void FixedDoubleArrayPrint(FILE* out);
2408#endif
2409
2410#ifdef DEBUG
2411 void FixedDoubleArrayVerify();
2412#endif
2413
2414 private:
2415 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray);
2416};
2417
2418
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002419class IncrementalMarking;
2420
2421
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002422// DescriptorArrays are fixed arrays used to hold instance descriptors.
2423// The format of the these objects is:
danno@chromium.org40cb8782011-05-25 07:58:50 +00002424// TODO(1399): It should be possible to make room for bit_field3 in the map
2425// without overloading the instance descriptors field in the map
2426// (and storing it in the DescriptorArray when the map has one).
2427// [0]: storage for bit_field3 for Map owning this object (Smi)
2428// [1]: point to a fixed array with (value, detail) pairs.
2429// [2]: next enumeration index (Smi), or pointer to small fixed array:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002430// [0]: next enumeration index (Smi)
2431// [1]: pointer to fixed array with enum cache
danno@chromium.org40cb8782011-05-25 07:58:50 +00002432// [3]: first key
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002433// [length() - 1]: last key
2434//
2435class DescriptorArray: public FixedArray {
2436 public:
danno@chromium.org40cb8782011-05-25 07:58:50 +00002437 // Returns true for both shared empty_descriptor_array and for smis, which the
2438 // map uses to encode additional bit fields when the descriptor array is not
2439 // yet used.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002440 inline bool IsEmpty();
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002441 inline bool MayContainTransitions();
2442
2443 DECL_ACCESSORS(elements_transition_map, Map)
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00002444 inline void ClearElementsTransition();
sgjesse@chromium.org846fb742009-12-18 08:56:33 +00002445
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002446 // Returns the number of descriptors in the array.
2447 int number_of_descriptors() {
verwaest@chromium.org50915592012-06-18 12:15:44 +00002448 ASSERT(length() >= kFirstIndex || IsEmpty());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002449 int len = length();
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002450 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002451 }
2452
2453 int NextEnumerationIndex() {
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002454 if (IsEmpty()) return PropertyDetails::kInitialIndex;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002455 Object* obj = get(kEnumerationIndexIndex);
2456 if (obj->IsSmi()) {
2457 return Smi::cast(obj)->value();
2458 } else {
2459 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex);
2460 return Smi::cast(index)->value();
2461 }
2462 }
2463
2464 // Set next enumeration index and flush any enum cache.
2465 void SetNextEnumerationIndex(int value) {
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002466 if (!IsEmpty()) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002467 set(kEnumerationIndexIndex, Smi::FromInt(value));
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002468 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002469 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002470 bool HasEnumCache() {
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002471 return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002472 }
2473
2474 Object* GetEnumCache() {
2475 ASSERT(HasEnumCache());
2476 FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex));
2477 return bridge->get(kEnumCacheBridgeCacheIndex);
2478 }
2479
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002480 Object** GetEnumCacheSlot() {
2481 ASSERT(HasEnumCache());
2482 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
2483 kEnumerationIndexOffset);
2484 }
2485
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002486 Object** GetTransitionsSlot() {
2487 ASSERT(elements_transition_map() != NULL);
2488 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
2489 kTransitionsOffset);
2490 }
2491
danno@chromium.org40cb8782011-05-25 07:58:50 +00002492 // TODO(1399): It should be possible to make room for bit_field3 in the map
2493 // without overloading the instance descriptors field in the map
2494 // (and storing it in the DescriptorArray when the map has one).
2495 inline int bit_field3_storage();
2496 inline void set_bit_field3_storage(int value);
2497
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002498 // Initialize or change the enum cache,
2499 // using the supplied storage for the small "bridge".
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002500 void SetEnumCache(FixedArray* bridge_storage,
2501 FixedArray* new_cache,
2502 Object* new_index_cache);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002503
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00002504 // Accessors for fetching instance descriptor at descriptor number.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002505 inline String* GetKey(int descriptor_number);
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002506 inline Object** GetKeySlot(int descriptor_number);
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002507 inline void SetKeyUnchecked(Heap* heap, int descriptor_number, String* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002508 inline Object* GetValue(int descriptor_number);
verwaest@chromium.org37141392012-05-31 13:27:02 +00002509 inline Object** GetValueSlot(int descriptor_number);
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00002510 inline void SetNullValueUnchecked(Heap* heap, int descriptor_number);
2511 inline void SetValueUnchecked(Heap* heap,
2512 int descriptor_number,
2513 Object* value);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00002514 inline PropertyDetails GetDetails(int descriptor_number);
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002515 inline void SetDetailsUnchecked(int descriptor_number, Smi* value);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00002516 inline PropertyType GetType(int descriptor_number);
2517 inline int GetFieldIndex(int descriptor_number);
2518 inline JSFunction* GetConstantFunction(int descriptor_number);
2519 inline Object* GetCallbacksObject(int descriptor_number);
2520 inline AccessorDescriptor* GetCallbacks(int descriptor_number);
2521 inline bool IsProperty(int descriptor_number);
rossberg@chromium.org994edf62012-02-06 10:12:55 +00002522 inline bool IsTransitionOnly(int descriptor_number);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002523
verwaest@chromium.org37141392012-05-31 13:27:02 +00002524 // WhitenessWitness is used to prove that a specific descriptor array is white
2525 // (unmarked), so incremental write barriers can be skipped because the
2526 // marking invariant cannot be broken and slots pointing into evacuation
2527 // candidates will be discovered when the object is scanned. A witness is
2528 // always stack-allocated right after creating a descriptor array. By
2529 // allocating a witness, incremental marking is globally disabled. The witness
2530 // is then passed along wherever needed to statically prove that the
2531 // descriptor array is known to be white.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002532 class WhitenessWitness {
2533 public:
2534 inline explicit WhitenessWitness(DescriptorArray* array);
2535 inline ~WhitenessWitness();
2536
2537 private:
2538 IncrementalMarking* marking_;
2539 };
2540
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002541 // Accessor for complete descriptor.
2542 inline void Get(int descriptor_number, Descriptor* desc);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002543 inline void Set(int descriptor_number,
2544 Descriptor* desc,
2545 const WhitenessWitness&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002546
ulan@chromium.org65a89c22012-02-14 11:46:07 +00002547 // Transfer a complete descriptor from the src descriptor array to the dst
2548 // one, dropping map transitions in CALLBACKS.
2549 static void CopyFrom(Handle<DescriptorArray> dst,
2550 int dst_index,
2551 Handle<DescriptorArray> src,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002552 int src_index,
ulan@chromium.org65a89c22012-02-14 11:46:07 +00002553 const WhitenessWitness& witness);
2554
2555 // Transfer a complete descriptor from the src descriptor array to this
2556 // descriptor array, dropping map transitions in CALLBACKS.
2557 MUST_USE_RESULT MaybeObject* CopyFrom(int dst_index,
2558 DescriptorArray* src,
2559 int src_index,
2560 const WhitenessWitness&);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00002561
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002562 // Copy the descriptor array, insert a new descriptor and optionally
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002563 // remove map transitions. If the descriptor is already present, it is
2564 // replaced. If a replaced descriptor is a real property (not a transition
2565 // or null), its enumeration index is kept as is.
2566 // If adding a real property, map transitions must be removed. If adding
2567 // a transition, they must not be removed. All null descriptors are removed.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002568 MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor,
2569 TransitionFlag transition_flag);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002570
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002571 // Indicates whether the search function should expect a sorted or an unsorted
2572 // descriptor array as input.
2573 enum SharedMode {
2574 MAY_BE_SHARED,
2575 CANNOT_BE_SHARED
2576 };
2577
erik.corry@gmail.combbceb572012-03-09 10:52:05 +00002578 // Return a copy of the array with all transitions and null descriptors
2579 // removed. Return a Failure object in case of an allocation failure.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002580 MUST_USE_RESULT MaybeObject* RemoveTransitions(SharedMode shared_mode);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002581
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002582 // Sort the instance descriptors by the hash codes of their keys.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +00002583 // Does not check for duplicates.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002584 void SortUnchecked(const WhitenessWitness&);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +00002585
2586 // Sort the instance descriptors by the hash codes of their keys.
2587 // Checks the result for duplicates.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002588 void Sort(const WhitenessWitness&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002589
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002590 // Search the instance descriptors for given name.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002591 INLINE(int Search(String* name));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002592
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002593 // As the above, but uses DescriptorLookupCache and updates it when
2594 // necessary.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002595 INLINE(int SearchWithCache(String* name));
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002596
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002597 // Tells whether the name is present int the array.
2598 bool Contains(String* name) { return kNotFound != Search(name); }
2599
2600 // Perform a binary search in the instance descriptors represented
2601 // by this fixed array. low and high are descriptor indices. If there
2602 // are three instance descriptors in this array it should be called
2603 // with low=0 and high=2.
2604 int BinarySearch(String* name, int low, int high);
2605
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00002606 // Perform a linear search in the instance descriptors represented
ager@chromium.org32912102009-01-16 10:38:43 +00002607 // by this fixed array. len is the number of descriptor indices that are
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002608 // valid.
2609 int LinearSearch(SearchMode mode, String* name, int len);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002610
2611 // Allocates a DescriptorArray, but returns the singleton
2612 // empty descriptor array object if number_of_descriptors is 0.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002613 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors,
2614 SharedMode shared_mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002615
2616 // Casting.
2617 static inline DescriptorArray* cast(Object* obj);
2618
2619 // Constant for denoting key was not found.
2620 static const int kNotFound = -1;
2621
danno@chromium.org40cb8782011-05-25 07:58:50 +00002622 static const int kBitField3StorageIndex = 0;
verwaest@chromium.org50915592012-06-18 12:15:44 +00002623 static const int kEnumerationIndexIndex = 1;
2624 static const int kTransitionsIndex = 2;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002625 static const int kFirstIndex = 3;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002626
2627 // The length of the "bridge" to the enum cache.
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002628 static const int kEnumCacheBridgeLength = 3;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002629 static const int kEnumCacheBridgeEnumIndex = 0;
2630 static const int kEnumCacheBridgeCacheIndex = 1;
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002631 static const int kEnumCacheBridgeIndicesCacheIndex = 2;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002632
2633 // Layout description.
danno@chromium.org40cb8782011-05-25 07:58:50 +00002634 static const int kBitField3StorageOffset = FixedArray::kHeaderSize;
verwaest@chromium.org50915592012-06-18 12:15:44 +00002635 static const int kEnumerationIndexOffset =
2636 kBitField3StorageOffset + kPointerSize;
2637 static const int kTransitionsOffset = kEnumerationIndexOffset + kPointerSize;
2638 static const int kFirstOffset = kTransitionsOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002639
2640 // Layout description for the bridge array.
2641 static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize;
2642 static const int kEnumCacheBridgeCacheOffset =
2643 kEnumCacheBridgeEnumOffset + kPointerSize;
2644
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002645 // Layout of descriptor.
2646 static const int kDescriptorKey = 0;
2647 static const int kDescriptorDetails = 1;
2648 static const int kDescriptorValue = 2;
2649 static const int kDescriptorSize = 3;
2650
whesse@chromium.org023421e2010-12-21 12:19:12 +00002651#ifdef OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002652 // Print all the descriptors.
whesse@chromium.org023421e2010-12-21 12:19:12 +00002653 inline void PrintDescriptors() {
2654 PrintDescriptors(stdout);
2655 }
2656 void PrintDescriptors(FILE* out);
2657#endif
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00002658
whesse@chromium.org023421e2010-12-21 12:19:12 +00002659#ifdef DEBUG
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00002660 // Is the descriptor array sorted and without duplicates?
2661 bool IsSortedNoDuplicates();
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002662
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00002663 // Is the descriptor array consistent with the back pointers in targets?
2664 bool IsConsistentWithBackPointers(Map* current_map);
2665
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002666 // Are two DescriptorArrays equal?
2667 bool IsEqualTo(DescriptorArray* other);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002668#endif
2669
2670 // The maximum number of descriptors we want in a descriptor array (should
2671 // fit in a page).
2672 static const int kMaxNumberOfDescriptors = 1024 + 512;
2673
2674 private:
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00002675 // An entry in a DescriptorArray, represented as an (array, index) pair.
2676 class Entry {
2677 public:
2678 inline explicit Entry(DescriptorArray* descs, int index) :
2679 descs_(descs), index_(index) { }
2680
2681 inline PropertyType type() { return descs_->GetType(index_); }
2682 inline Object* GetCallbackObject() { return descs_->GetValue(index_); }
2683
2684 private:
2685 DescriptorArray* descs_;
2686 int index_;
2687 };
2688
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002689 // Conversion from descriptor number to array indices.
2690 static int ToKeyIndex(int descriptor_number) {
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002691 return kFirstIndex +
2692 (descriptor_number * kDescriptorSize) +
2693 kDescriptorKey;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002694 }
sgjesse@chromium.org846fb742009-12-18 08:56:33 +00002695
2696 static int ToDetailsIndex(int descriptor_number) {
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002697 return kFirstIndex +
2698 (descriptor_number * kDescriptorSize) +
2699 kDescriptorDetails;
sgjesse@chromium.org846fb742009-12-18 08:56:33 +00002700 }
2701
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002702 static int ToValueIndex(int descriptor_number) {
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002703 return kFirstIndex +
2704 (descriptor_number * kDescriptorSize) +
2705 kDescriptorValue;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002706 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002707
2708 // Swap operation on FixedArray without using write barriers.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002709 static inline void NoIncrementalWriteBarrierSwap(
2710 FixedArray* array, int first, int second);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002711
2712 // Swap descriptor first and second.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002713 inline void NoIncrementalWriteBarrierSwapDescriptors(
2714 int first, int second);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002715
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002716 DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray);
2717};
2718
2719
2720// HashTable is a subclass of FixedArray that implements a hash table
2721// that uses open addressing and quadratic probing.
2722//
2723// In order for the quadratic probing to work, elements that have not
2724// yet been used and elements that have been deleted are
2725// distinguished. Probing continues when deleted elements are
2726// encountered and stops when unused elements are encountered.
2727//
2728// - Elements with key == undefined have not been used yet.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002729// - Elements with key == the_hole have been deleted.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002730//
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002731// The hash table class is parameterized with a Shape and a Key.
2732// Shape must be a class with the following interface:
2733// class ExampleShape {
2734// public:
2735// // Tells whether key matches other.
2736// static bool IsMatch(Key key, Object* other);
2737// // Returns the hash value for key.
2738// static uint32_t Hash(Key key);
2739// // Returns the hash value for object.
2740// static uint32_t HashForObject(Key key, Object* object);
2741// // Convert key to an object.
2742// static inline Object* AsObject(Key key);
2743// // The prefix size indicates number of elements in the beginning
2744// // of the backing storage.
2745// static const int kPrefixSize = ..;
2746// // The Element size indicates number of elements per entry.
2747// static const int kEntrySize = ..;
2748// };
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002749// The prefix size indicates an amount of memory in the
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002750// beginning of the backing storage that can be used for non-element
2751// information by subclasses.
ager@chromium.org9258b6b2008-09-11 09:11:10 +00002752
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002753template<typename Key>
2754class BaseShape {
2755 public:
2756 static const bool UsesSeed = false;
2757 static uint32_t Hash(Key key) { return 0; }
2758 static uint32_t SeededHash(Key key, uint32_t seed) {
2759 ASSERT(UsesSeed);
2760 return Hash(key);
2761 }
2762 static uint32_t HashForObject(Key key, Object* object) { return 0; }
2763 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) {
2764 ASSERT(UsesSeed);
2765 return HashForObject(key, object);
2766 }
2767};
2768
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002769template<typename Shape, typename Key>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002770class HashTable: public FixedArray {
2771 public:
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002772 // Wrapper methods
2773 inline uint32_t Hash(Key key) {
2774 if (Shape::UsesSeed) {
2775 return Shape::SeededHash(key,
2776 GetHeap()->HashSeed());
2777 } else {
2778 return Shape::Hash(key);
2779 }
2780 }
2781
2782 inline uint32_t HashForObject(Key key, Object* object) {
2783 if (Shape::UsesSeed) {
2784 return Shape::SeededHashForObject(key,
2785 GetHeap()->HashSeed(), object);
2786 } else {
2787 return Shape::HashForObject(key, object);
2788 }
2789 }
2790
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002791 // Returns the number of elements in the hash table.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002792 int NumberOfElements() {
2793 return Smi::cast(get(kNumberOfElementsIndex))->value();
2794 }
2795
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002796 // Returns the number of deleted elements in the hash table.
2797 int NumberOfDeletedElements() {
2798 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
2799 }
2800
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002801 // Returns the capacity of the hash table.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002802 int Capacity() {
2803 return Smi::cast(get(kCapacityIndex))->value();
2804 }
2805
2806 // ElementAdded should be called whenever an element is added to a
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002807 // hash table.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002808 void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); }
2809
2810 // ElementRemoved should be called whenever an element is removed from
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002811 // a hash table.
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002812 void ElementRemoved() {
2813 SetNumberOfElements(NumberOfElements() - 1);
2814 SetNumberOfDeletedElements(NumberOfDeletedElements() + 1);
2815 }
2816 void ElementsRemoved(int n) {
2817 SetNumberOfElements(NumberOfElements() - n);
2818 SetNumberOfDeletedElements(NumberOfDeletedElements() + n);
2819 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002820
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002821 // Returns a new HashTable object. Might return Failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002822 MUST_USE_RESULT static MaybeObject* Allocate(
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00002823 int at_least_space_for,
2824 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002825
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002826 // Computes the required capacity for a table holding the given
2827 // number of elements. May be more than HashTable::kMaxCapacity.
2828 static int ComputeCapacity(int at_least_space_for);
2829
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002830 // Returns the key at entry.
2831 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
2832
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002833 // Tells whether k is a real key. The hole and undefined are not allowed
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002834 // as keys and can be used to indicate missing or deleted elements.
2835 bool IsKey(Object* k) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002836 return !k->IsTheHole() && !k->IsUndefined();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002837 }
2838
2839 // Garbage collection support.
2840 void IteratePrefix(ObjectVisitor* visitor);
2841 void IterateElements(ObjectVisitor* visitor);
2842
2843 // Casting.
2844 static inline HashTable* cast(Object* obj);
2845
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002846 // Compute the probe offset (quadratic probing).
2847 INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
2848 return (n + n * n) >> 1;
2849 }
2850
2851 static const int kNumberOfElementsIndex = 0;
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002852 static const int kNumberOfDeletedElementsIndex = 1;
2853 static const int kCapacityIndex = 2;
2854 static const int kPrefixStartIndex = 3;
2855 static const int kElementsStartIndex =
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002856 kPrefixStartIndex + Shape::kPrefixSize;
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002857 static const int kEntrySize = Shape::kEntrySize;
2858 static const int kElementsStartOffset =
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002859 kHeaderSize + kElementsStartIndex * kPointerSize;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00002860 static const int kCapacityOffset =
2861 kHeaderSize + kCapacityIndex * kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002862
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00002863 // Constant used for denoting a absent entry.
2864 static const int kNotFound = -1;
2865
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002866 // Maximal capacity of HashTable. Based on maximal length of underlying
2867 // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
2868 // cannot overflow.
2869 static const int kMaxCapacity =
2870 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
2871
ricow@chromium.org4980dff2010-07-19 08:33:45 +00002872 // Find entry for key otherwise return kNotFound.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002873 inline int FindEntry(Key key);
2874 int FindEntry(Isolate* isolate, Key key);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002875
2876 protected:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002877 // Find the entry at which to insert element with the given key that
2878 // has the given hash value.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002879 uint32_t FindInsertionEntry(uint32_t hash);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002880
2881 // Returns the index for an entry (of the key)
2882 static inline int EntryToIndex(int entry) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002883 return (entry * kEntrySize) + kElementsStartIndex;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002884 }
2885
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002886 // Update the number of elements in the hash table.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002887 void SetNumberOfElements(int nof) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002888 set(kNumberOfElementsIndex, Smi::FromInt(nof));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002889 }
2890
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002891 // Update the number of deleted elements in the hash table.
2892 void SetNumberOfDeletedElements(int nod) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002893 set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod));
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002894 }
2895
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002896 // Sets the capacity of the hash table.
2897 void SetCapacity(int capacity) {
2898 // To scale a computed hash code to fit within the hash table, we
2899 // use bit-wise AND with a mask, so the capacity must be positive
2900 // and non-zero.
2901 ASSERT(capacity > 0);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002902 ASSERT(capacity <= kMaxCapacity);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002903 set(kCapacityIndex, Smi::FromInt(capacity));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002904 }
2905
2906
2907 // Returns probe entry.
2908 static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
2909 ASSERT(IsPowerOf2(size));
2910 return (hash + GetProbeOffset(number)) & (size - 1);
2911 }
2912
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002913 static uint32_t FirstProbe(uint32_t hash, uint32_t size) {
2914 return hash & (size - 1);
2915 }
2916
2917 static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) {
2918 return (last + number) & (size - 1);
2919 }
2920
ager@chromium.org04921a82011-06-27 13:21:41 +00002921 // Rehashes this hash-table into the new table.
2922 MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key);
2923
2924 // Attempt to shrink hash table after removal of key.
2925 MUST_USE_RESULT MaybeObject* Shrink(Key key);
2926
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002927 // Ensure enough space for n additional elements.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002928 MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002929};
2930
2931
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002932// HashTableKey is an abstract superclass for virtual key behavior.
2933class HashTableKey {
2934 public:
2935 // Returns whether the other object matches this key.
2936 virtual bool IsMatch(Object* other) = 0;
2937 // Returns the hash value for this key.
2938 virtual uint32_t Hash() = 0;
2939 // Returns the hash value for object.
2940 virtual uint32_t HashForObject(Object* key) = 0;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002941 // Returns the key object for storing into the hash table.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002942 // If allocations fails a failure object is returned.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002943 MUST_USE_RESULT virtual MaybeObject* AsObject() = 0;
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002944 // Required.
2945 virtual ~HashTableKey() {}
2946};
2947
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002948
2949class SymbolTableShape : public BaseShape<HashTableKey*> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002950 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002951 static inline bool IsMatch(HashTableKey* key, Object* value) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002952 return key->IsMatch(value);
2953 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002954 static inline uint32_t Hash(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002955 return key->Hash();
2956 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002957 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002958 return key->HashForObject(object);
2959 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002960 MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002961 return key->AsObject();
2962 }
2963
2964 static const int kPrefixSize = 0;
2965 static const int kEntrySize = 1;
2966};
2967
danno@chromium.org40cb8782011-05-25 07:58:50 +00002968class SeqAsciiString;
2969
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002970// SymbolTable.
2971//
2972// No special elements in the prefix and the element size is 1
2973// because only the symbol itself (the key) needs to be stored.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002974class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002975 public:
2976 // Find symbol in the symbol table. If it is not there yet, it is
2977 // added. The return value is the symbol table which might have
2978 // been enlarged. If the return value is not a failure, the symbol
2979 // pointer *s is set to the symbol found.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002980 MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s);
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00002981 MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str,
2982 Object** s);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002983 MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol(
2984 Handle<SeqAsciiString> str,
2985 int from,
2986 int length,
2987 Object** s);
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00002988 MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str,
2989 Object** s);
lrn@chromium.org303ada72010-10-27 09:33:13 +00002990 MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002991
ager@chromium.org7c537e22008-10-16 08:43:32 +00002992 // Looks up a symbol that is equal to the given string and returns
2993 // true if it is found, assigning the symbol to the given output
2994 // parameter.
2995 bool LookupSymbolIfExists(String* str, String** symbol);
ager@chromium.org6141cbe2009-11-20 12:14:52 +00002996 bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol);
ager@chromium.org7c537e22008-10-16 08:43:32 +00002997
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002998 // Casting.
2999 static inline SymbolTable* cast(Object* obj);
3000
3001 private:
lrn@chromium.org303ada72010-10-27 09:33:13 +00003002 MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003003
3004 DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable);
3005};
3006
3007
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003008class MapCacheShape : public BaseShape<HashTableKey*> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003009 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003010 static inline bool IsMatch(HashTableKey* key, Object* value) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003011 return key->IsMatch(value);
3012 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003013 static inline uint32_t Hash(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003014 return key->Hash();
3015 }
3016
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003017 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003018 return key->HashForObject(object);
3019 }
3020
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003021 MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003022 return key->AsObject();
3023 }
3024
3025 static const int kPrefixSize = 0;
3026 static const int kEntrySize = 2;
3027};
3028
3029
ager@chromium.org236ad962008-09-25 09:45:57 +00003030// MapCache.
3031//
3032// Maps keys that are a fixed array of symbols to a map.
3033// Used for canonicalize maps for object literals.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003034class MapCache: public HashTable<MapCacheShape, HashTableKey*> {
ager@chromium.org236ad962008-09-25 09:45:57 +00003035 public:
3036 // Find cached value for a string key, otherwise return null.
3037 Object* Lookup(FixedArray* key);
lrn@chromium.org303ada72010-10-27 09:33:13 +00003038 MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value);
ager@chromium.org236ad962008-09-25 09:45:57 +00003039 static inline MapCache* cast(Object* obj);
3040
3041 private:
3042 DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache);
3043};
3044
3045
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003046template <typename Shape, typename Key>
3047class Dictionary: public HashTable<Shape, Key> {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003048 public:
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003049 static inline Dictionary<Shape, Key>* cast(Object* obj) {
3050 return reinterpret_cast<Dictionary<Shape, Key>*>(obj);
3051 }
3052
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003053 // Returns the value at entry.
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00003054 Object* ValueAt(int entry) {
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003055 return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00003056 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003057
3058 // Set the value for entry.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003059 void ValueAtPut(int entry, Object* value) {
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00003060 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003061 }
3062
3063 // Returns the property details for the property at entry.
3064 PropertyDetails DetailsAt(int entry) {
ager@chromium.org5aa501c2009-06-23 07:57:28 +00003065 ASSERT(entry >= 0); // Not found is -1, which is not caught by get().
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003066 return PropertyDetails(
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00003067 Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003068 }
3069
3070 // Set the details for entry.
3071 void DetailsAtPut(int entry, PropertyDetails value) {
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00003072 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003073 }
3074
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003075 // Sorting support
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003076 void CopyValuesTo(FixedArray* elements);
3077
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003078 // Delete a property from the dictionary.
ager@chromium.orge2902be2009-06-08 12:21:35 +00003079 Object* DeleteProperty(int entry, JSObject::DeleteMode mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003080
ager@chromium.org04921a82011-06-27 13:21:41 +00003081 // Attempt to shrink the dictionary after deletion of key.
3082 MUST_USE_RESULT MaybeObject* Shrink(Key key);
3083
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003084 // Returns the number of elements in the dictionary filtering out properties
3085 // with the specified attributes.
3086 int NumberOfElementsFilterAttributes(PropertyAttributes filter);
3087
3088 // Returns the number of enumerable elements in the dictionary.
3089 int NumberOfEnumElements();
3090
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003091 enum SortMode { UNSORTED, SORTED };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003092 // Copies keys to preallocated fixed array.
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003093 void CopyKeysTo(FixedArray* storage,
3094 PropertyAttributes filter,
3095 SortMode sort_mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003096 // Fill in details for properties into storage.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003097 void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003098
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003099 // Accessors for next enumeration index.
3100 void SetNextEnumerationIndex(int index) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003101 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003102 }
3103
3104 int NextEnumerationIndex() {
3105 return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value();
3106 }
3107
3108 // Returns a new array for dictionary usage. Might return Failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003109 MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003110
3111 // Ensure enough space for n additional elements.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003112 MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003113
whesse@chromium.org023421e2010-12-21 12:19:12 +00003114#ifdef OBJECT_PRINT
3115 inline void Print() {
3116 Print(stdout);
3117 }
3118 void Print(FILE* out);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003119#endif
3120 // Returns the key (slow).
3121 Object* SlowReverseLookup(Object* value);
3122
3123 // Sets the entry to (key, value) pair.
3124 inline void SetEntry(int entry,
3125 Object* key,
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00003126 Object* value);
3127 inline void SetEntry(int entry,
3128 Object* key,
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003129 Object* value,
3130 PropertyDetails details);
3131
lrn@chromium.org303ada72010-10-27 09:33:13 +00003132 MUST_USE_RESULT MaybeObject* Add(Key key,
3133 Object* value,
3134 PropertyDetails details);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003135
3136 protected:
3137 // Generic at put operation.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003138 MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003139
3140 // Add entry to dictionary.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003141 MUST_USE_RESULT MaybeObject* AddEntry(Key key,
3142 Object* value,
3143 PropertyDetails details,
3144 uint32_t hash);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003145
3146 // Generate new enumeration indices to avoid enumeration index overflow.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003147 MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices();
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003148 static const int kMaxNumberKeyIndex =
3149 HashTable<Shape, Key>::kPrefixStartIndex;
3150 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
3151};
3152
3153
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003154class StringDictionaryShape : public BaseShape<String*> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003155 public:
3156 static inline bool IsMatch(String* key, Object* other);
3157 static inline uint32_t Hash(String* key);
3158 static inline uint32_t HashForObject(String* key, Object* object);
lrn@chromium.org303ada72010-10-27 09:33:13 +00003159 MUST_USE_RESULT static inline MaybeObject* AsObject(String* key);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003160 static const int kPrefixSize = 2;
3161 static const int kEntrySize = 3;
3162 static const bool kIsEnumerable = true;
3163};
3164
3165
3166class StringDictionary: public Dictionary<StringDictionaryShape, String*> {
3167 public:
3168 static inline StringDictionary* cast(Object* obj) {
3169 ASSERT(obj->IsDictionary());
3170 return reinterpret_cast<StringDictionary*>(obj);
3171 }
3172
3173 // Copies enumerable keys to preallocated fixed array.
3174 void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array);
3175
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003176 // For transforming properties of a JSObject.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003177 MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor(
3178 JSObject* obj,
3179 int unused_property_fields);
ricow@chromium.org4980dff2010-07-19 08:33:45 +00003180
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003181 // Find entry for key, otherwise return kNotFound. Optimized version of
ricow@chromium.org4980dff2010-07-19 08:33:45 +00003182 // HashTable::FindEntry.
3183 int FindEntry(String* key);
rossberg@chromium.org994edf62012-02-06 10:12:55 +00003184
3185 bool ContainsTransition(int entry);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003186};
3187
3188
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003189class NumberDictionaryShape : public BaseShape<uint32_t> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003190 public:
3191 static inline bool IsMatch(uint32_t key, Object* other);
lrn@chromium.org303ada72010-10-27 09:33:13 +00003192 MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003193 static const int kEntrySize = 3;
3194 static const bool kIsEnumerable = false;
3195};
3196
3197
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003198class SeededNumberDictionaryShape : public NumberDictionaryShape {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003199 public:
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003200 static const bool UsesSeed = true;
3201 static const int kPrefixSize = 2;
3202
3203 static inline uint32_t SeededHash(uint32_t key, uint32_t seed);
3204 static inline uint32_t SeededHashForObject(uint32_t key,
3205 uint32_t seed,
3206 Object* object);
3207};
3208
3209
3210class UnseededNumberDictionaryShape : public NumberDictionaryShape {
3211 public:
3212 static const int kPrefixSize = 0;
3213
3214 static inline uint32_t Hash(uint32_t key);
3215 static inline uint32_t HashForObject(uint32_t key, Object* object);
3216};
3217
3218
3219class SeededNumberDictionary
3220 : public Dictionary<SeededNumberDictionaryShape, uint32_t> {
3221 public:
3222 static SeededNumberDictionary* cast(Object* obj) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003223 ASSERT(obj->IsDictionary());
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003224 return reinterpret_cast<SeededNumberDictionary*>(obj);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003225 }
3226
3227 // Type specific at put (default NONE attributes is used when adding).
lrn@chromium.org303ada72010-10-27 09:33:13 +00003228 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value);
3229 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key,
3230 Object* value,
3231 PropertyDetails details);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003232
3233 // Set an existing entry or add a new one if needed.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003234 // Return the updated dictionary.
3235 MUST_USE_RESULT static Handle<SeededNumberDictionary> Set(
3236 Handle<SeededNumberDictionary> dictionary,
3237 uint32_t index,
3238 Handle<Object> value,
3239 PropertyDetails details);
3240
lrn@chromium.org303ada72010-10-27 09:33:13 +00003241 MUST_USE_RESULT MaybeObject* Set(uint32_t key,
3242 Object* value,
3243 PropertyDetails details);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003244
3245 void UpdateMaxNumberKey(uint32_t key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003246
3247 // If slow elements are required we will never go back to fast-case
3248 // for the elements kept in this dictionary. We require slow
3249 // elements if an element has been added at an index larger than
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003250 // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called
3251 // when defining a getter or setter with a number key.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003252 inline bool requires_slow_elements();
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003253 inline void set_requires_slow_elements();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003254
3255 // Get the value of the max number key that has been added to this
3256 // dictionary. max_number_key can only be called if
3257 // requires_slow_elements returns false.
3258 inline uint32_t max_number_key();
3259
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003260 // Bit masks.
3261 static const int kRequiresSlowElementsMask = 1;
3262 static const int kRequiresSlowElementsTagSize = 1;
3263 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003264};
3265
3266
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003267class UnseededNumberDictionary
3268 : public Dictionary<UnseededNumberDictionaryShape, uint32_t> {
3269 public:
3270 static UnseededNumberDictionary* cast(Object* obj) {
3271 ASSERT(obj->IsDictionary());
3272 return reinterpret_cast<UnseededNumberDictionary*>(obj);
3273 }
3274
3275 // Type specific at put (default NONE attributes is used when adding).
3276 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value);
3277 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value);
3278
3279 // Set an existing entry or add a new one if needed.
3280 // Return the updated dictionary.
3281 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set(
3282 Handle<UnseededNumberDictionary> dictionary,
3283 uint32_t index,
3284 Handle<Object> value);
3285
3286 MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value);
3287};
3288
3289
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003290template <int entrysize>
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003291class ObjectHashTableShape : public BaseShape<Object*> {
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003292 public:
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003293 static inline bool IsMatch(Object* key, Object* other);
3294 static inline uint32_t Hash(Object* key);
3295 static inline uint32_t HashForObject(Object* key, Object* object);
3296 MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003297 static const int kPrefixSize = 0;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003298 static const int kEntrySize = entrysize;
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003299};
3300
3301
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003302// ObjectHashSet holds keys that are arbitrary objects by using the identity
3303// hash of the key for hashing purposes.
3304class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> {
3305 public:
3306 static inline ObjectHashSet* cast(Object* obj) {
3307 ASSERT(obj->IsHashTable());
3308 return reinterpret_cast<ObjectHashSet*>(obj);
3309 }
3310
3311 // Looks up whether the given key is part of this hash set.
3312 bool Contains(Object* key);
3313
3314 // Adds the given key to this hash set.
3315 MUST_USE_RESULT MaybeObject* Add(Object* key);
3316
3317 // Removes the given key from this hash set.
3318 MUST_USE_RESULT MaybeObject* Remove(Object* key);
3319};
3320
3321
3322// ObjectHashTable maps keys that are arbitrary objects to object values by
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003323// using the identity hash of the key for hashing purposes.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003324class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> {
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003325 public:
3326 static inline ObjectHashTable* cast(Object* obj) {
3327 ASSERT(obj->IsHashTable());
3328 return reinterpret_cast<ObjectHashTable*>(obj);
3329 }
3330
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00003331 // Looks up the value associated with the given key. The hole value is
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003332 // returned in case the key is not present.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003333 Object* Lookup(Object* key);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003334
3335 // Adds (or overwrites) the value associated with the given key. Mapping a
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00003336 // key to the hole value causes removal of the whole entry.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003337 MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003338
3339 private:
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003340 friend class MarkCompactCollector;
3341
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003342 void AddEntry(int entry, Object* key, Object* value);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003343 void RemoveEntry(int entry);
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003344
3345 // Returns the index to the value of an entry.
3346 static inline int EntryToValueIndex(int entry) {
3347 return EntryToIndex(entry) + 1;
3348 }
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003349};
3350
3351
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00003352// JSFunctionResultCache caches results of some JSFunction invocation.
3353// It is a fixed array with fixed structure:
3354// [0]: factory function
3355// [1]: finger index
3356// [2]: current cache size
3357// [3]: dummy field.
3358// The rest of array are key/value pairs.
3359class JSFunctionResultCache: public FixedArray {
3360 public:
3361 static const int kFactoryIndex = 0;
3362 static const int kFingerIndex = kFactoryIndex + 1;
3363 static const int kCacheSizeIndex = kFingerIndex + 1;
3364 static const int kDummyIndex = kCacheSizeIndex + 1;
3365 static const int kEntriesIndex = kDummyIndex + 1;
antonm@chromium.org397e23c2010-04-21 12:00:05 +00003366
3367 static const int kEntrySize = 2; // key + value
ager@chromium.orgac091b72010-05-05 07:34:42 +00003368
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +00003369 static const int kFactoryOffset = kHeaderSize;
3370 static const int kFingerOffset = kFactoryOffset + kPointerSize;
3371 static const int kCacheSizeOffset = kFingerOffset + kPointerSize;
3372
ager@chromium.orgac091b72010-05-05 07:34:42 +00003373 inline void MakeZeroSize();
3374 inline void Clear();
3375
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00003376 inline int size();
3377 inline void set_size(int size);
3378 inline int finger_index();
3379 inline void set_finger_index(int finger_index);
3380
ager@chromium.orgac091b72010-05-05 07:34:42 +00003381 // Casting
3382 static inline JSFunctionResultCache* cast(Object* obj);
3383
3384#ifdef DEBUG
3385 void JSFunctionResultCacheVerify();
3386#endif
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00003387};
3388
3389
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003390// ScopeInfo represents information about different scopes of a source
3391// program and the allocation of the scope's variables. Scope information
3392// is stored in a compressed form in ScopeInfo objects and is used
3393// at runtime (stack dumps, deoptimization, etc.).
3394
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003395// This object provides quick access to scope info details for runtime
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003396// routines.
3397class ScopeInfo : public FixedArray {
3398 public:
3399 static inline ScopeInfo* cast(Object* object);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003400
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003401 // Return the type of this scope.
3402 ScopeType Type();
3403
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003404 // Does this scope call eval?
3405 bool CallsEval();
3406
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00003407 // Return the language mode of this scope.
3408 LanguageMode language_mode();
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003409
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003410 // Does this scope make a non-strict eval call?
3411 bool CallsNonStrictEval() {
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00003412 return CallsEval() && (language_mode() == CLASSIC_MODE);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003413 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003414
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003415 // Return the total number of locals allocated on the stack and in the
3416 // context. This includes the parameters that are allocated in the context.
3417 int LocalCount();
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003418
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003419 // Return the number of stack slots for code. This number consists of two
3420 // parts:
3421 // 1. One stack slot per stack allocated local.
3422 // 2. One stack slot for the function name if it is stack allocated.
3423 int StackSlotCount();
3424
3425 // Return the number of context slots for code if a context is allocated. This
3426 // number consists of three parts:
3427 // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS
3428 // 2. One context slot per context allocated local.
3429 // 3. One context slot for the function name if it is context allocated.
3430 // Parameters allocated in the context count as context allocated locals. If
3431 // no contexts are allocated for this scope ContextLength returns 0.
3432 int ContextLength();
3433
3434 // Is this scope the scope of a named function expression?
3435 bool HasFunctionName();
3436
3437 // Return if this has context allocated locals.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003438 bool HasHeapAllocatedLocals();
3439
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003440 // Return if contexts are allocated for this scope.
3441 bool HasContext();
3442
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003443 // Return the function_name if present.
3444 String* FunctionName();
3445
3446 // Return the name of the given parameter.
3447 String* ParameterName(int var);
3448
3449 // Return the name of the given local.
3450 String* LocalName(int var);
3451
3452 // Return the name of the given stack local.
3453 String* StackLocalName(int var);
3454
3455 // Return the name of the given context local.
3456 String* ContextLocalName(int var);
3457
3458 // Return the mode of the given context local.
3459 VariableMode ContextLocalMode(int var);
3460
3461 // Return the initialization flag of the given context local.
3462 InitializationFlag ContextLocalInitFlag(int var);
3463
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003464 // Lookup support for serialized scope info. Returns the
3465 // the stack slot index for a given slot name if the slot is
3466 // present; otherwise returns a value < 0. The name must be a symbol
3467 // (canonicalized).
3468 int StackSlotIndex(String* name);
3469
3470 // Lookup support for serialized scope info. Returns the
3471 // context slot index for a given slot name if the slot is present; otherwise
3472 // returns a value < 0. The name must be a symbol (canonicalized).
3473 // If the slot is present and mode != NULL, sets *mode to the corresponding
3474 // mode for that variable.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003475 int ContextSlotIndex(String* name,
3476 VariableMode* mode,
3477 InitializationFlag* init_flag);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003478
3479 // Lookup support for serialized scope info. Returns the
3480 // parameter index for a given parameter name if the parameter is present;
3481 // otherwise returns a value < 0. The name must be a symbol (canonicalized).
3482 int ParameterIndex(String* name);
3483
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00003484 // Lookup support for serialized scope info. Returns the function context
3485 // slot index if the function name is present and context-allocated (named
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003486 // function expressions, only), otherwise returns a value < 0. The name
3487 // must be a symbol (canonicalized).
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003488 int FunctionContextSlotIndex(String* name, VariableMode* mode);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003489
mmassi@chromium.org7028c052012-06-13 11:51:58 +00003490 static Handle<ScopeInfo> Create(Scope* scope, Zone* zone);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003491
3492 // Serializes empty scope info.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003493 static ScopeInfo* Empty();
3494
3495#ifdef DEBUG
3496 void Print();
3497#endif
3498
3499 // The layout of the static part of a ScopeInfo is as follows. Each entry is
3500 // numeric and occupies one array slot.
3501 // 1. A set of properties of the scope
3502 // 2. The number of parameters. This only applies to function scopes. For
3503 // non-function scopes this is 0.
3504 // 3. The number of non-parameter variables allocated on the stack.
3505 // 4. The number of non-parameter and parameter variables allocated in the
3506 // context.
3507#define FOR_EACH_NUMERIC_FIELD(V) \
3508 V(Flags) \
3509 V(ParameterCount) \
3510 V(StackLocalCount) \
3511 V(ContextLocalCount)
3512
3513#define FIELD_ACCESSORS(name) \
3514 void Set##name(int value) { \
3515 set(k##name, Smi::FromInt(value)); \
3516 } \
3517 int name() { \
3518 if (length() > 0) { \
3519 return Smi::cast(get(k##name))->value(); \
3520 } else { \
3521 return 0; \
3522 } \
3523 }
3524 FOR_EACH_NUMERIC_FIELD(FIELD_ACCESSORS)
3525#undef FIELD_ACCESSORS
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003526
3527 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003528 enum {
3529#define DECL_INDEX(name) k##name,
3530 FOR_EACH_NUMERIC_FIELD(DECL_INDEX)
3531#undef DECL_INDEX
3532#undef FOR_EACH_NUMERIC_FIELD
3533 kVariablePartIndex
3534 };
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003535
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003536 // The layout of the variable part of a ScopeInfo is as follows:
3537 // 1. ParameterEntries:
3538 // This part stores the names of the parameters for function scopes. One
3539 // slot is used per parameter, so in total this part occupies
3540 // ParameterCount() slots in the array. For other scopes than function
3541 // scopes ParameterCount() is 0.
3542 // 2. StackLocalEntries:
3543 // Contains the names of local variables that are allocated on the stack,
3544 // in increasing order of the stack slot index. One slot is used per stack
3545 // local, so in total this part occupies StackLocalCount() slots in the
3546 // array.
3547 // 3. ContextLocalNameEntries:
3548 // Contains the names of local variables and parameters that are allocated
3549 // in the context. They are stored in increasing order of the context slot
3550 // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per
3551 // context local, so in total this part occupies ContextLocalCount() slots
3552 // in the array.
3553 // 4. ContextLocalInfoEntries:
3554 // Contains the variable modes and initialization flags corresponding to
3555 // the context locals in ContextLocalNameEntries. One slot is used per
3556 // context local, so in total this part occupies ContextLocalCount()
3557 // slots in the array.
3558 // 5. FunctionNameEntryIndex:
3559 // If the scope belongs to a named function expression this part contains
3560 // information about the function variable. It always occupies two array
3561 // slots: a. The name of the function variable.
3562 // b. The context or stack slot index for the variable.
3563 int ParameterEntriesIndex();
3564 int StackLocalEntriesIndex();
3565 int ContextLocalNameEntriesIndex();
3566 int ContextLocalInfoEntriesIndex();
3567 int FunctionNameEntryIndex();
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003568
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003569 // Location of the function variable for named function expressions.
3570 enum FunctionVariableInfo {
3571 NONE, // No function name present.
3572 STACK, // Function
3573 CONTEXT,
3574 UNUSED
3575 };
3576
3577 // Properties of scopes.
3578 class TypeField: public BitField<ScopeType, 0, 3> {};
3579 class CallsEvalField: public BitField<bool, 3, 1> {};
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00003580 class LanguageModeField: public BitField<LanguageMode, 4, 2> {};
3581 class FunctionVariableField: public BitField<FunctionVariableInfo, 6, 2> {};
3582 class FunctionVariableMode: public BitField<VariableMode, 8, 3> {};
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003583
3584 // BitFields representing the encoded information for context locals in the
3585 // ContextLocalInfoEntries part.
3586 class ContextLocalMode: public BitField<VariableMode, 0, 3> {};
3587 class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {};
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003588};
3589
3590
ricow@chromium.org65fae842010-08-25 15:26:24 +00003591// The cache for maps used by normalized (dictionary mode) objects.
3592// Such maps do not have property descriptors, so a typical program
3593// needs very limited number of distinct normalized maps.
3594class NormalizedMapCache: public FixedArray {
3595 public:
3596 static const int kEntries = 64;
3597
lrn@chromium.org303ada72010-10-27 09:33:13 +00003598 MUST_USE_RESULT MaybeObject* Get(JSObject* object,
3599 PropertyNormalizationMode mode);
ricow@chromium.org65fae842010-08-25 15:26:24 +00003600
ricow@chromium.org65fae842010-08-25 15:26:24 +00003601 void Clear();
3602
3603 // Casting
3604 static inline NormalizedMapCache* cast(Object* obj);
3605
3606#ifdef DEBUG
3607 void NormalizedMapCacheVerify();
3608#endif
ricow@chromium.org65fae842010-08-25 15:26:24 +00003609};
3610
3611
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003612// ByteArray represents fixed sized byte arrays. Used for the relocation info
3613// that is attached to code objects.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003614class ByteArray: public FixedArrayBase {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003615 public:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003616 inline int Size() { return RoundUp(length() + kHeaderSize, kPointerSize); }
3617
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003618 // Setter and getter.
3619 inline byte get(int index);
3620 inline void set(int index, byte value);
3621
3622 // Treat contents as an int array.
3623 inline int get_int(int index);
3624
3625 static int SizeFor(int length) {
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003626 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003627 }
3628 // We use byte arrays for free blocks in the heap. Given a desired size in
3629 // bytes that is a multiple of the word size and big enough to hold a byte
3630 // array, this function returns the number of elements a byte array should
3631 // have.
3632 static int LengthFor(int size_in_bytes) {
3633 ASSERT(IsAligned(size_in_bytes, kPointerSize));
3634 ASSERT(size_in_bytes >= kHeaderSize);
3635 return size_in_bytes - kHeaderSize;
3636 }
3637
3638 // Returns data start address.
3639 inline Address GetDataStartAddress();
3640
3641 // Returns a pointer to the ByteArray object for a given data start address.
3642 static inline ByteArray* FromDataStartAddress(Address address);
3643
3644 // Casting.
3645 static inline ByteArray* cast(Object* obj);
3646
3647 // Dispatched behavior.
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00003648 inline int ByteArraySize() {
3649 return SizeFor(this->length());
3650 }
whesse@chromium.org023421e2010-12-21 12:19:12 +00003651#ifdef OBJECT_PRINT
3652 inline void ByteArrayPrint() {
3653 ByteArrayPrint(stdout);
3654 }
3655 void ByteArrayPrint(FILE* out);
3656#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003657#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003658 void ByteArrayVerify();
3659#endif
3660
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003661 // Layout description.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003662 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
kasperl@chromium.orge959c182009-07-27 08:59:04 +00003663
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00003664 // Maximal memory consumption for a single ByteArray.
3665 static const int kMaxSize = 512 * MB;
3666 // Maximal length of a single ByteArray.
3667 static const int kMaxLength = kMaxSize - kHeaderSize;
3668
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003669 private:
3670 DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray);
3671};
3672
3673
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003674// FreeSpace represents fixed sized areas of the heap that are not currently in
3675// use. Used by the heap and GC.
3676class FreeSpace: public HeapObject {
3677 public:
3678 // [size]: size of the free space including the header.
3679 inline int size();
3680 inline void set_size(int value);
3681
3682 inline int Size() { return size(); }
3683
3684 // Casting.
3685 static inline FreeSpace* cast(Object* obj);
3686
3687#ifdef OBJECT_PRINT
3688 inline void FreeSpacePrint() {
3689 FreeSpacePrint(stdout);
3690 }
3691 void FreeSpacePrint(FILE* out);
3692#endif
3693#ifdef DEBUG
3694 void FreeSpaceVerify();
3695#endif
3696
3697 // Layout description.
3698 // Size is smi tagged when it is stored.
3699 static const int kSizeOffset = HeapObject::kHeaderSize;
3700 static const int kHeaderSize = kSizeOffset + kPointerSize;
3701
3702 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
3703
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003704 private:
3705 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace);
3706};
3707
3708
ager@chromium.org3811b432009-10-28 14:53:37 +00003709// An ExternalArray represents a fixed-size array of primitive values
3710// which live outside the JavaScript heap. Its subclasses are used to
3711// implement the CanvasArray types being defined in the WebGL
3712// specification. As of this writing the first public draft is not yet
3713// available, but Khronos members can access the draft at:
3714// https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html
3715//
3716// The semantics of these arrays differ from CanvasPixelArray.
3717// Out-of-range values passed to the setter are converted via a C
3718// cast, not clamping. Out-of-range indices cause exceptions to be
3719// raised rather than being silently ignored.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003720class ExternalArray: public FixedArrayBase {
ager@chromium.org3811b432009-10-28 14:53:37 +00003721 public:
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003722 inline bool is_the_hole(int index) { return false; }
3723
ager@chromium.org3811b432009-10-28 14:53:37 +00003724 // [external_pointer]: The pointer to the external memory area backing this
3725 // external array.
3726 DECL_ACCESSORS(external_pointer, void) // Pointer to the data store.
3727
3728 // Casting.
3729 static inline ExternalArray* cast(Object* obj);
3730
3731 // Maximal acceptable length for an external array.
3732 static const int kMaxLength = 0x3fffffff;
3733
3734 // ExternalArray headers are not quadword aligned.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003735 static const int kExternalPointerOffset =
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003736 POINTER_SIZE_ALIGN(FixedArrayBase::kLengthOffset + kPointerSize);
ager@chromium.org3811b432009-10-28 14:53:37 +00003737 static const int kHeaderSize = kExternalPointerOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003738 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
ager@chromium.org3811b432009-10-28 14:53:37 +00003739
3740 private:
3741 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray);
3742};
3743
3744
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00003745// A ExternalPixelArray represents a fixed-size byte array with special
3746// semantics used for implementing the CanvasPixelArray object. Please see the
3747// specification at:
3748
3749// http://www.whatwg.org/specs/web-apps/current-work/
3750// multipage/the-canvas-element.html#canvaspixelarray
3751// In particular, write access clamps the value written to 0 or 255 if the
3752// value written is outside this range.
3753class ExternalPixelArray: public ExternalArray {
3754 public:
3755 inline uint8_t* external_pixel_pointer();
3756
3757 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003758 inline uint8_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003759 MUST_USE_RESULT inline MaybeObject* get(int index);
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00003760 inline void set(int index, uint8_t value);
3761
3762 // This accessor applies the correct conversion from Smi, HeapNumber and
3763 // undefined and clamps the converted value between 0 and 255.
3764 Object* SetValue(uint32_t index, Object* value);
3765
3766 // Casting.
3767 static inline ExternalPixelArray* cast(Object* obj);
3768
3769#ifdef OBJECT_PRINT
3770 inline void ExternalPixelArrayPrint() {
3771 ExternalPixelArrayPrint(stdout);
3772 }
3773 void ExternalPixelArrayPrint(FILE* out);
3774#endif
3775#ifdef DEBUG
3776 void ExternalPixelArrayVerify();
3777#endif // DEBUG
3778
3779 private:
3780 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray);
3781};
3782
3783
ager@chromium.org3811b432009-10-28 14:53:37 +00003784class ExternalByteArray: public ExternalArray {
3785 public:
3786 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003787 inline int8_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003788 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003789 inline void set(int index, int8_t value);
3790
3791 // This accessor applies the correct conversion from Smi, HeapNumber
3792 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003793 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003794
3795 // Casting.
3796 static inline ExternalByteArray* cast(Object* obj);
3797
whesse@chromium.org023421e2010-12-21 12:19:12 +00003798#ifdef OBJECT_PRINT
3799 inline void ExternalByteArrayPrint() {
3800 ExternalByteArrayPrint(stdout);
3801 }
3802 void ExternalByteArrayPrint(FILE* out);
3803#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003804#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003805 void ExternalByteArrayVerify();
3806#endif // DEBUG
3807
3808 private:
3809 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray);
3810};
3811
3812
3813class ExternalUnsignedByteArray: public ExternalArray {
3814 public:
3815 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003816 inline uint8_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003817 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003818 inline void set(int index, uint8_t value);
3819
3820 // This accessor applies the correct conversion from Smi, HeapNumber
3821 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003822 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003823
3824 // Casting.
3825 static inline ExternalUnsignedByteArray* cast(Object* obj);
3826
whesse@chromium.org023421e2010-12-21 12:19:12 +00003827#ifdef OBJECT_PRINT
3828 inline void ExternalUnsignedByteArrayPrint() {
3829 ExternalUnsignedByteArrayPrint(stdout);
3830 }
3831 void ExternalUnsignedByteArrayPrint(FILE* out);
3832#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003833#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003834 void ExternalUnsignedByteArrayVerify();
3835#endif // DEBUG
3836
3837 private:
3838 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray);
3839};
3840
3841
3842class ExternalShortArray: public ExternalArray {
3843 public:
3844 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003845 inline int16_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003846 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003847 inline void set(int index, int16_t value);
3848
3849 // This accessor applies the correct conversion from Smi, HeapNumber
3850 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003851 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003852
3853 // Casting.
3854 static inline ExternalShortArray* cast(Object* obj);
3855
whesse@chromium.org023421e2010-12-21 12:19:12 +00003856#ifdef OBJECT_PRINT
3857 inline void ExternalShortArrayPrint() {
3858 ExternalShortArrayPrint(stdout);
3859 }
3860 void ExternalShortArrayPrint(FILE* out);
3861#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003862#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003863 void ExternalShortArrayVerify();
3864#endif // DEBUG
3865
3866 private:
3867 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray);
3868};
3869
3870
3871class ExternalUnsignedShortArray: public ExternalArray {
3872 public:
3873 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003874 inline uint16_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003875 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003876 inline void set(int index, uint16_t value);
3877
3878 // This accessor applies the correct conversion from Smi, HeapNumber
3879 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003880 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003881
3882 // Casting.
3883 static inline ExternalUnsignedShortArray* cast(Object* obj);
3884
whesse@chromium.org023421e2010-12-21 12:19:12 +00003885#ifdef OBJECT_PRINT
3886 inline void ExternalUnsignedShortArrayPrint() {
3887 ExternalUnsignedShortArrayPrint(stdout);
3888 }
3889 void ExternalUnsignedShortArrayPrint(FILE* out);
3890#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003891#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003892 void ExternalUnsignedShortArrayVerify();
3893#endif // DEBUG
3894
3895 private:
3896 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray);
3897};
3898
3899
3900class ExternalIntArray: public ExternalArray {
3901 public:
3902 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003903 inline int32_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003904 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003905 inline void set(int index, int32_t value);
3906
3907 // This accessor applies the correct conversion from Smi, HeapNumber
3908 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003909 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003910
3911 // Casting.
3912 static inline ExternalIntArray* cast(Object* obj);
3913
whesse@chromium.org023421e2010-12-21 12:19:12 +00003914#ifdef OBJECT_PRINT
3915 inline void ExternalIntArrayPrint() {
3916 ExternalIntArrayPrint(stdout);
3917 }
3918 void ExternalIntArrayPrint(FILE* out);
3919#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003920#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003921 void ExternalIntArrayVerify();
3922#endif // DEBUG
3923
3924 private:
3925 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray);
3926};
3927
3928
3929class ExternalUnsignedIntArray: public ExternalArray {
3930 public:
3931 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003932 inline uint32_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003933 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003934 inline void set(int index, uint32_t value);
3935
3936 // This accessor applies the correct conversion from Smi, HeapNumber
3937 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003938 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003939
3940 // Casting.
3941 static inline ExternalUnsignedIntArray* cast(Object* obj);
3942
whesse@chromium.org023421e2010-12-21 12:19:12 +00003943#ifdef OBJECT_PRINT
3944 inline void ExternalUnsignedIntArrayPrint() {
3945 ExternalUnsignedIntArrayPrint(stdout);
3946 }
3947 void ExternalUnsignedIntArrayPrint(FILE* out);
3948#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003949#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003950 void ExternalUnsignedIntArrayVerify();
3951#endif // DEBUG
3952
3953 private:
3954 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray);
3955};
3956
3957
3958class ExternalFloatArray: public ExternalArray {
3959 public:
3960 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003961 inline float get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003962 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003963 inline void set(int index, float value);
3964
3965 // This accessor applies the correct conversion from Smi, HeapNumber
3966 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003967 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003968
3969 // Casting.
3970 static inline ExternalFloatArray* cast(Object* obj);
3971
whesse@chromium.org023421e2010-12-21 12:19:12 +00003972#ifdef OBJECT_PRINT
3973 inline void ExternalFloatArrayPrint() {
3974 ExternalFloatArrayPrint(stdout);
3975 }
3976 void ExternalFloatArrayPrint(FILE* out);
3977#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003978#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003979 void ExternalFloatArrayVerify();
3980#endif // DEBUG
3981
3982 private:
3983 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray);
3984};
3985
3986
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00003987class ExternalDoubleArray: public ExternalArray {
3988 public:
3989 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003990 inline double get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003991 MUST_USE_RESULT inline MaybeObject* get(int index);
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00003992 inline void set(int index, double value);
3993
3994 // This accessor applies the correct conversion from Smi, HeapNumber
3995 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003996 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00003997
3998 // Casting.
3999 static inline ExternalDoubleArray* cast(Object* obj);
4000
4001#ifdef OBJECT_PRINT
4002 inline void ExternalDoubleArrayPrint() {
4003 ExternalDoubleArrayPrint(stdout);
4004 }
4005 void ExternalDoubleArrayPrint(FILE* out);
4006#endif // OBJECT_PRINT
4007#ifdef DEBUG
4008 void ExternalDoubleArrayVerify();
4009#endif // DEBUG
4010
4011 private:
4012 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray);
4013};
4014
4015
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004016// DeoptimizationInputData is a fixed array used to hold the deoptimization
4017// data for code generated by the Hydrogen/Lithium compiler. It also
4018// contains information about functions that were inlined. If N different
4019// functions were inlined then first N elements of the literal array will
4020// contain these functions.
4021//
4022// It can be empty.
4023class DeoptimizationInputData: public FixedArray {
4024 public:
4025 // Layout description. Indices in the array.
4026 static const int kTranslationByteArrayIndex = 0;
4027 static const int kInlinedFunctionCountIndex = 1;
4028 static const int kLiteralArrayIndex = 2;
4029 static const int kOsrAstIdIndex = 3;
4030 static const int kOsrPcOffsetIndex = 4;
4031 static const int kFirstDeoptEntryIndex = 5;
4032
4033 // Offsets of deopt entry elements relative to the start of the entry.
4034 static const int kAstIdOffset = 0;
4035 static const int kTranslationIndexOffset = 1;
4036 static const int kArgumentsStackHeightOffset = 2;
ricow@chromium.org27bf2882011-11-17 08:34:43 +00004037 static const int kPcOffset = 3;
4038 static const int kDeoptEntrySize = 4;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004039
4040 // Simple element accessors.
4041#define DEFINE_ELEMENT_ACCESSORS(name, type) \
4042 type* name() { \
4043 return type::cast(get(k##name##Index)); \
4044 } \
4045 void Set##name(type* value) { \
4046 set(k##name##Index, value); \
4047 }
4048
4049 DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
4050 DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
4051 DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
4052 DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi)
4053 DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
4054
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004055#undef DEFINE_ELEMENT_ACCESSORS
4056
4057 // Accessors for elements of the ith deoptimization entry.
4058#define DEFINE_ENTRY_ACCESSORS(name, type) \
4059 type* name(int i) { \
4060 return type::cast(get(IndexForEntry(i) + k##name##Offset)); \
4061 } \
4062 void Set##name(int i, type* value) { \
4063 set(IndexForEntry(i) + k##name##Offset, value); \
4064 }
4065
4066 DEFINE_ENTRY_ACCESSORS(AstId, Smi)
4067 DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi)
4068 DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi)
ricow@chromium.org27bf2882011-11-17 08:34:43 +00004069 DEFINE_ENTRY_ACCESSORS(Pc, Smi)
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004070
4071#undef DEFINE_ENTRY_ACCESSORS
4072
4073 int DeoptCount() {
4074 return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize;
4075 }
4076
4077 // Allocates a DeoptimizationInputData.
4078 MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count,
4079 PretenureFlag pretenure);
4080
4081 // Casting.
4082 static inline DeoptimizationInputData* cast(Object* obj);
4083
ricow@chromium.org4f693d62011-07-04 14:01:31 +00004084#ifdef ENABLE_DISASSEMBLER
whesse@chromium.org023421e2010-12-21 12:19:12 +00004085 void DeoptimizationInputDataPrint(FILE* out);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004086#endif
4087
4088 private:
4089 static int IndexForEntry(int i) {
4090 return kFirstDeoptEntryIndex + (i * kDeoptEntrySize);
4091 }
4092
4093 static int LengthFor(int entry_count) {
4094 return IndexForEntry(entry_count);
4095 }
4096};
4097
4098
4099// DeoptimizationOutputData is a fixed array used to hold the deoptimization
4100// data for code generated by the full compiler.
4101// The format of the these objects is
4102// [i * 2]: Ast ID for ith deoptimization.
4103// [i * 2 + 1]: PC and state of ith deoptimization
4104class DeoptimizationOutputData: public FixedArray {
4105 public:
4106 int DeoptPoints() { return length() / 2; }
4107 Smi* AstId(int index) { return Smi::cast(get(index * 2)); }
4108 void SetAstId(int index, Smi* id) { set(index * 2, id); }
4109 Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); }
4110 void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); }
4111
4112 static int LengthOfFixedArray(int deopt_points) {
4113 return deopt_points * 2;
4114 }
4115
4116 // Allocates a DeoptimizationOutputData.
4117 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points,
4118 PretenureFlag pretenure);
4119
4120 // Casting.
4121 static inline DeoptimizationOutputData* cast(Object* obj);
4122
whesse@chromium.org7b260152011-06-20 15:33:18 +00004123#if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
whesse@chromium.org023421e2010-12-21 12:19:12 +00004124 void DeoptimizationOutputDataPrint(FILE* out);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004125#endif
4126};
4127
4128
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004129// Forward declaration.
4130class JSGlobalPropertyCell;
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004131
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004132// TypeFeedbackCells is a fixed array used to hold the association between
4133// cache cells and AST ids for code generated by the full compiler.
4134// The format of the these objects is
4135// [i * 2]: Global property cell of ith cache cell.
4136// [i * 2 + 1]: Ast ID for ith cache cell.
4137class TypeFeedbackCells: public FixedArray {
4138 public:
4139 int CellCount() { return length() / 2; }
4140 static int LengthOfFixedArray(int cell_count) { return cell_count * 2; }
4141
4142 // Accessors for AST ids associated with cache values.
4143 inline Smi* AstId(int index);
4144 inline void SetAstId(int index, Smi* id);
4145
4146 // Accessors for global property cells holding the cache values.
4147 inline JSGlobalPropertyCell* Cell(int index);
4148 inline void SetCell(int index, JSGlobalPropertyCell* cell);
4149
4150 // The object that indicates an uninitialized cache.
4151 static inline Handle<Object> UninitializedSentinel(Isolate* isolate);
4152
4153 // The object that indicates a megamorphic state.
4154 static inline Handle<Object> MegamorphicSentinel(Isolate* isolate);
4155
4156 // A raw version of the uninitialized sentinel that's safe to read during
4157 // garbage collection (e.g., for patching the cache).
4158 static inline Object* RawUninitializedSentinel(Heap* heap);
4159
4160 // Casting.
4161 static inline TypeFeedbackCells* cast(Object* obj);
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00004162
4163 static const int kForInFastCaseMarker = 0;
4164 static const int kForInSlowCaseMarker = 1;
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004165};
4166
4167
4168// Forward declaration.
4169class SafepointEntry;
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00004170class TypeFeedbackInfo;
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004171
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004172// Code describes objects with on-the-fly generated machine code.
4173class Code: public HeapObject {
4174 public:
4175 // Opaque data type for encapsulating code flags like kind, inline
4176 // cache state, and arguments count.
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00004177 // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that
4178 // enumeration type has correct value range (see Issue 830 for more details).
4179 enum Flags {
4180 FLAGS_MIN_VALUE = kMinInt,
4181 FLAGS_MAX_VALUE = kMaxInt
4182 };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004183
4184 enum Kind {
4185 FUNCTION,
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004186 OPTIMIZED_FUNCTION,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004187 STUB,
4188 BUILTIN,
4189 LOAD_IC,
4190 KEYED_LOAD_IC,
4191 CALL_IC,
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00004192 KEYED_CALL_IC,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004193 STORE_IC,
4194 KEYED_STORE_IC,
danno@chromium.org40cb8782011-05-25 07:58:50 +00004195 UNARY_OP_IC,
4196 BINARY_OP_IC,
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004197 COMPARE_IC,
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004198 TO_BOOLEAN_IC,
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00004199 // No more than 16 kinds. The value currently encoded in four bits in
ager@chromium.orga74f0da2008-12-03 16:05:52 +00004200 // Flags.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004201
4202 // Pseudo-kinds.
ager@chromium.orga74f0da2008-12-03 16:05:52 +00004203 REGEXP = BUILTIN,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004204 FIRST_IC_KIND = LOAD_IC,
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004205 LAST_IC_KIND = TO_BOOLEAN_IC
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004206 };
4207
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004208 // Types of stubs.
4209 enum StubType {
4210 NORMAL,
4211 FIELD,
4212 CONSTANT_FUNCTION,
4213 CALLBACKS,
4214 INTERCEPTOR,
4215 MAP_TRANSITION,
4216 NONEXISTENT
4217 };
4218
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004219 enum {
fschneider@chromium.orged78ffd2010-07-21 11:05:19 +00004220 NUMBER_OF_KINDS = LAST_IC_KIND + 1
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004221 };
4222
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004223 typedef int ExtraICState;
4224
4225 static const ExtraICState kNoExtraICState = 0;
4226
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00004227#ifdef ENABLE_DISASSEMBLER
4228 // Printing
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004229 static const char* Kind2String(Kind kind);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00004230 static const char* ICState2String(InlineCacheState state);
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004231 static const char* StubType2String(StubType type);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00004232 static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra);
whesse@chromium.org023421e2010-12-21 12:19:12 +00004233 inline void Disassemble(const char* name) {
4234 Disassemble(name, stdout);
4235 }
4236 void Disassemble(const char* name, FILE* out);
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00004237#endif // ENABLE_DISASSEMBLER
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004238
4239 // [instruction_size]: Size of the native instructions
4240 inline int instruction_size();
4241 inline void set_instruction_size(int value);
4242
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004243 // [relocation_info]: Code relocation information
4244 DECL_ACCESSORS(relocation_info, ByteArray)
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004245 void InvalidateRelocation();
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004246
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00004247 // [handler_table]: Fixed array containing offsets of exception handlers.
4248 DECL_ACCESSORS(handler_table, FixedArray)
4249
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004250 // [deoptimization_data]: Array containing data for deopt.
4251 DECL_ACCESSORS(deoptimization_data, FixedArray)
4252
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00004253 // [type_feedback_info]: Struct containing type feedback information.
4254 // Will contain either a TypeFeedbackInfo object, or undefined.
4255 DECL_ACCESSORS(type_feedback_info, Object)
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004256
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00004257 // [gc_metadata]: Field used to hold GC related metadata. The contents of this
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00004258 // field does not have to be traced during garbage collection since
4259 // it is only used by the garbage collector itself.
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00004260 DECL_ACCESSORS(gc_metadata, Object)
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00004261
danno@chromium.org88aa0582012-03-23 15:11:57 +00004262 // [ic_age]: Inline caching age: the value of the Heap::global_ic_age
4263 // at the moment when this object was created.
4264 inline void set_ic_age(int count);
4265 inline int ic_age();
4266
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004267 // Unchecked accessors to be used during GC.
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004268 inline ByteArray* unchecked_relocation_info();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004269 inline FixedArray* unchecked_deoptimization_data();
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004270
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004271 inline int relocation_size();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004272
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004273 // [flags]: Various code flags.
4274 inline Flags flags();
4275 inline void set_flags(Flags flags);
4276
4277 // [flags]: Access to specific code flags.
4278 inline Kind kind();
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004279 inline InlineCacheState ic_state(); // Only valid for IC stubs.
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004280 inline ExtraICState extra_ic_state(); // Only valid for IC stubs.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004281 inline StubType type(); // Only valid for monomorphic IC stubs.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004282 inline int arguments_count(); // Only valid for call IC stubs.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004283
4284 // Testers for IC stub kinds.
4285 inline bool is_inline_cache_stub();
4286 inline bool is_load_stub() { return kind() == LOAD_IC; }
4287 inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; }
4288 inline bool is_store_stub() { return kind() == STORE_IC; }
4289 inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; }
4290 inline bool is_call_stub() { return kind() == CALL_IC; }
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00004291 inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; }
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004292 inline bool is_unary_op_stub() { return kind() == UNARY_OP_IC; }
4293 inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004294 inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; }
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004295 inline bool is_to_boolean_ic_stub() { return kind() == TO_BOOLEAN_IC; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004296
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00004297 // [major_key]: For kind STUB or BINARY_OP_IC, the major key.
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00004298 inline int major_key();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004299 inline void set_major_key(int value);
4300
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004301 // For stubs, tells whether they should always exist, so that they can be
4302 // called from other stubs.
4303 inline bool is_pregenerated();
4304 inline void set_is_pregenerated(bool value);
4305
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004306 // [optimizable]: For FUNCTION kind, tells if it is optimizable.
4307 inline bool optimizable();
4308 inline void set_optimizable(bool value);
4309
4310 // [has_deoptimization_support]: For FUNCTION kind, tells if it has
4311 // deoptimization support.
4312 inline bool has_deoptimization_support();
4313 inline void set_has_deoptimization_support(bool value);
4314
lrn@chromium.org34e60782011-09-15 07:25:40 +00004315 // [has_debug_break_slots]: For FUNCTION kind, tells if it has
4316 // been compiled with debug break slots.
4317 inline bool has_debug_break_slots();
4318 inline void set_has_debug_break_slots(bool value);
4319
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004320 // [compiled_with_optimizing]: For FUNCTION kind, tells if it has
4321 // been compiled with IsOptimizing set to true.
4322 inline bool is_compiled_optimizable();
4323 inline void set_compiled_optimizable(bool value);
4324
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004325 // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for
4326 // how long the function has been marked for OSR and therefore which
4327 // level of loop nesting we are willing to do on-stack replacement
4328 // for.
4329 inline void set_allow_osr_at_loop_nesting_level(int level);
4330 inline int allow_osr_at_loop_nesting_level();
4331
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00004332 // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks
4333 // the code object was seen on the stack with no IC patching going on.
4334 inline int profiler_ticks();
4335 inline void set_profiler_ticks(int ticks);
4336
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004337 // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots
4338 // reserved in the code prologue.
4339 inline unsigned stack_slots();
4340 inline void set_stack_slots(unsigned slots);
4341
4342 // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in
4343 // the instruction stream where the safepoint table starts.
ricow@chromium.org83aa5492011-02-07 12:42:56 +00004344 inline unsigned safepoint_table_offset();
4345 inline void set_safepoint_table_offset(unsigned offset);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004346
4347 // [stack_check_table_start]: For kind FUNCTION, the offset in the
4348 // instruction stream where the stack check table starts.
ricow@chromium.org83aa5492011-02-07 12:42:56 +00004349 inline unsigned stack_check_table_offset();
4350 inline void set_stack_check_table_offset(unsigned offset);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004351
4352 // [check type]: For kind CALL_IC, tells how to check if the
4353 // receiver is valid for the given call.
4354 inline CheckType check_type();
4355 inline void set_check_type(CheckType value);
4356
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004357 // [type-recording unary op type]: For kind UNARY_OP_IC.
danno@chromium.org40cb8782011-05-25 07:58:50 +00004358 inline byte unary_op_type();
4359 inline void set_unary_op_type(byte value);
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00004360
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004361 // [type-recording binary op type]: For kind BINARY_OP_IC.
danno@chromium.org40cb8782011-05-25 07:58:50 +00004362 inline byte binary_op_type();
4363 inline void set_binary_op_type(byte value);
4364 inline byte binary_op_result_type();
4365 inline void set_binary_op_result_type(byte value);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004366
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004367 // [compare state]: For kind COMPARE_IC, tells what state the stub is in.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004368 inline byte compare_state();
4369 inline void set_compare_state(byte value);
4370
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004371 // [compare_operation]: For kind COMPARE_IC tells what compare operation the
4372 // stub was generated for.
4373 inline byte compare_operation();
4374 inline void set_compare_operation(byte value);
4375
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004376 // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in.
4377 inline byte to_boolean_state();
4378 inline void set_to_boolean_state(byte value);
4379
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004380 // [has_function_cache]: For kind STUB tells whether there is a function
4381 // cache is passed to the stub.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004382 inline bool has_function_cache();
4383 inline void set_has_function_cache(bool flag);
4384
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004385 bool allowed_in_shared_map_code_cache();
4386
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004387 // Get the safepoint entry for the given pc.
4388 SafepointEntry GetSafepointEntry(Address pc);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004389
4390 // Mark this code object as not having a stack check table. Assumes kind
4391 // is FUNCTION.
4392 void SetNoStackCheckTable();
4393
4394 // Find the first map in an IC stub.
4395 Map* FindFirstMap();
kasper.lund7276f142008-07-30 08:49:36 +00004396
ulan@chromium.org65a89c22012-02-14 11:46:07 +00004397 class ExtraICStateStrictMode: public BitField<StrictModeFlag, 0, 1> {};
4398 class ExtraICStateKeyedAccessGrowMode:
4399 public BitField<KeyedAccessGrowMode, 1, 1> {}; // NOLINT
4400
4401 static const int kExtraICStateGrowModeShift = 1;
4402
4403 static inline StrictModeFlag GetStrictMode(ExtraICState extra_ic_state) {
4404 return ExtraICStateStrictMode::decode(extra_ic_state);
4405 }
4406
4407 static inline KeyedAccessGrowMode GetKeyedAccessGrowMode(
4408 ExtraICState extra_ic_state) {
4409 return ExtraICStateKeyedAccessGrowMode::decode(extra_ic_state);
4410 }
4411
4412 static inline ExtraICState ComputeExtraICState(
4413 KeyedAccessGrowMode grow_mode,
4414 StrictModeFlag strict_mode) {
4415 return ExtraICStateKeyedAccessGrowMode::encode(grow_mode) |
4416 ExtraICStateStrictMode::encode(strict_mode);
4417 }
4418
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004419 // Flags operations.
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004420 static inline Flags ComputeFlags(
4421 Kind kind,
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004422 InlineCacheState ic_state = UNINITIALIZED,
4423 ExtraICState extra_ic_state = kNoExtraICState,
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004424 StubType type = NORMAL,
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004425 int argc = -1,
4426 InlineCacheHolderFlag holder = OWN_MAP);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004427
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004428 static inline Flags ComputeMonomorphicFlags(
4429 Kind kind,
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004430 StubType type,
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004431 ExtraICState extra_ic_state = kNoExtraICState,
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004432 InlineCacheHolderFlag holder = OWN_MAP,
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004433 int argc = -1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004434
kasper.lund7276f142008-07-30 08:49:36 +00004435 static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004436 static inline StubType ExtractTypeFromFlags(Flags flags);
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004437 static inline Kind ExtractKindFromFlags(Flags flags);
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004438 static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004439 static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags);
4440 static inline int ExtractArgumentsCountFromFlags(Flags flags);
4441
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004442 static inline Flags RemoveTypeFromFlags(Flags flags);
4443
ager@chromium.org8bb60582008-12-11 12:02:20 +00004444 // Convert a target address into a code object.
4445 static inline Code* GetCodeFromTargetAddress(Address address);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004446
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00004447 // Convert an entry address into an object.
4448 static inline Object* GetObjectFromEntryAddress(Address location_of_address);
4449
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004450 // Returns the address of the first instruction.
4451 inline byte* instruction_start();
4452
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004453 // Returns the address right after the last instruction.
4454 inline byte* instruction_end();
4455
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004456 // Returns the size of the instructions, padding, and relocation information.
4457 inline int body_size();
4458
4459 // Returns the address of the first relocation info (read backwards!).
4460 inline byte* relocation_start();
4461
4462 // Code entry point.
4463 inline byte* entry();
4464
4465 // Returns true if pc is inside this object's instructions.
4466 inline bool contains(byte* pc);
4467
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004468 // Relocate the code by delta bytes. Called to signal that this code
4469 // object has been moved by delta bytes.
ager@chromium.orgc4c92722009-11-18 14:12:51 +00004470 void Relocate(intptr_t delta);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004471
4472 // Migrate code described by desc.
4473 void CopyFrom(const CodeDesc& desc);
4474
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00004475 // Returns the object size for a given body (used for allocation).
4476 static int SizeFor(int body_size) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004477 ASSERT_SIZE_TAG_ALIGNED(body_size);
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00004478 return RoundUp(kHeaderSize + body_size, kCodeAlignment);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004479 }
4480
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00004481 // Calculate the size of the code object to report for log events. This takes
4482 // the layout of the code object into account.
4483 int ExecutableSize() {
4484 // Check that the assumptions about the layout of the code object holds.
ager@chromium.orga1645e22009-09-09 19:27:10 +00004485 ASSERT_EQ(static_cast<int>(instruction_start() - address()),
4486 Code::kHeaderSize);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00004487 return instruction_size() + Code::kHeaderSize;
4488 }
4489
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004490 // Locating source position.
4491 int SourcePosition(Address pc);
4492 int SourceStatementPosition(Address pc);
4493
4494 // Casting.
4495 static inline Code* cast(Object* obj);
4496
4497 // Dispatched behavior.
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00004498 int CodeSize() { return SizeFor(body_size()); }
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00004499 inline void CodeIterateBody(ObjectVisitor* v);
4500
4501 template<typename StaticVisitor>
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004502 inline void CodeIterateBody(Heap* heap);
whesse@chromium.org023421e2010-12-21 12:19:12 +00004503#ifdef OBJECT_PRINT
4504 inline void CodePrint() {
4505 CodePrint(stdout);
4506 }
4507 void CodePrint(FILE* out);
4508#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004509#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004510 void CodeVerify();
4511#endif
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00004512 void ClearInlineCaches();
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004513 void ClearTypeFeedbackCells(Heap* heap);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004514
4515 // Max loop nesting marker used to postpose OSR. We don't take loop
4516 // nesting that is deeper than 5 levels into account.
4517 static const int kMaxLoopNestingMarker = 6;
4518
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004519 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00004520 static const int kInstructionSizeOffset = HeapObject::kHeaderSize;
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004521 static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize;
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00004522 static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004523 static const int kDeoptimizationDataOffset =
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00004524 kHandlerTableOffset + kPointerSize;
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00004525 static const int kTypeFeedbackInfoOffset =
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004526 kDeoptimizationDataOffset + kPointerSize;
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00004527 static const int kGCMetadataOffset = kTypeFeedbackInfoOffset + kPointerSize;
danno@chromium.org88aa0582012-03-23 15:11:57 +00004528 static const int kICAgeOffset =
4529 kGCMetadataOffset + kPointerSize;
4530 static const int kFlagsOffset = kICAgeOffset + kIntSize;
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00004531 static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004532 static const int kKindSpecificFlagsSize = 2 * kIntSize;
4533
4534 static const int kHeaderPaddingStart = kKindSpecificFlagsOffset +
4535 kKindSpecificFlagsSize;
4536
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004537 // Add padding to align the instruction start following right after
kasperl@chromium.org061ef742009-02-27 12:16:20 +00004538 // the Code object header.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004539 static const int kHeaderSize =
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004540 (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask;
kasper.lund7276f142008-07-30 08:49:36 +00004541
4542 // Byte offsets within kKindSpecificFlagsOffset.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004543 static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset;
4544 static const int kOptimizableOffset = kKindSpecificFlagsOffset;
4545 static const int kStackSlotsOffset = kKindSpecificFlagsOffset;
4546 static const int kCheckTypeOffset = kKindSpecificFlagsOffset;
4547
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00004548 static const int kUnaryOpTypeOffset = kStubMajorKeyOffset + 1;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004549 static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1;
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004550 static const int kCompareStateOffset = kStubMajorKeyOffset + 1;
4551 static const int kToBooleanTypeOffset = kStubMajorKeyOffset + 1;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004552 static const int kHasFunctionCacheOffset = kStubMajorKeyOffset + 1;
lrn@chromium.org34e60782011-09-15 07:25:40 +00004553
4554 static const int kFullCodeFlags = kOptimizableOffset + 1;
4555 class FullCodeFlagsHasDeoptimizationSupportField:
4556 public BitField<bool, 0, 1> {}; // NOLINT
4557 class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {};
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004558 class FullCodeFlagsIsCompiledOptimizable: public BitField<bool, 2, 1> {};
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004559
4560 static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1;
lrn@chromium.org34e60782011-09-15 07:25:40 +00004561
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004562 static const int kCompareOperationOffset = kCompareStateOffset + 1;
4563
lrn@chromium.org34e60782011-09-15 07:25:40 +00004564 static const int kAllowOSRAtLoopNestingLevelOffset = kFullCodeFlags + 1;
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00004565 static const int kProfilerTicksOffset = kAllowOSRAtLoopNestingLevelOffset + 1;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004566
ricow@chromium.org83aa5492011-02-07 12:42:56 +00004567 static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize;
4568 static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004569
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004570 // Flags layout. BitField<type, shift, size>.
4571 class ICStateField: public BitField<InlineCacheState, 0, 3> {};
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004572 class TypeField: public BitField<StubType, 3, 3> {};
4573 class CacheHolderField: public BitField<InlineCacheHolderFlag, 6, 1> {};
4574 class KindField: public BitField<Kind, 7, 4> {};
4575 class ExtraICStateField: public BitField<ExtraICState, 11, 2> {};
4576 class IsPregeneratedField: public BitField<bool, 13, 1> {};
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004577
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004578 // Signed field cannot be encoded using the BitField class.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004579 static const int kArgumentsCountShift = 14;
lrn@chromium.org34e60782011-09-15 07:25:40 +00004580 static const int kArgumentsCountMask = ~((1 << kArgumentsCountShift) - 1);
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004581
jkummerow@chromium.org1145ef82012-02-02 16:21:15 +00004582 // This constant should be encodable in an ARM instruction.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004583 static const int kFlagsNotUsedInLookup =
lrn@chromium.org34e60782011-09-15 07:25:40 +00004584 TypeField::kMask | CacheHolderField::kMask;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004585
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004586 private:
4587 DISALLOW_IMPLICIT_CONSTRUCTORS(Code);
4588};
4589
4590
4591// All heap objects have a Map that describes their structure.
4592// A Map contains information about:
4593// - Size information about the object
4594// - How to iterate over an object (for garbage collection)
4595class Map: public HeapObject {
4596 public:
ager@chromium.org32912102009-01-16 10:38:43 +00004597 // Instance size.
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00004598 // Size in bytes or kVariableSizeSentinel if instances do not have
4599 // a fixed size.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004600 inline int instance_size();
4601 inline void set_instance_size(int value);
4602
ager@chromium.org7c537e22008-10-16 08:43:32 +00004603 // Count of properties allocated in the object.
4604 inline int inobject_properties();
4605 inline void set_inobject_properties(int value);
4606
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00004607 // Count of property fields pre-allocated in the object when first allocated.
4608 inline int pre_allocated_property_fields();
4609 inline void set_pre_allocated_property_fields(int value);
4610
ager@chromium.org32912102009-01-16 10:38:43 +00004611 // Instance type.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004612 inline InstanceType instance_type();
4613 inline void set_instance_type(InstanceType value);
4614
ager@chromium.org32912102009-01-16 10:38:43 +00004615 // Tells how many unused property fields are available in the
4616 // instance (only used for JSObject in fast mode).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004617 inline int unused_property_fields();
4618 inline void set_unused_property_fields(int value);
4619
ager@chromium.org32912102009-01-16 10:38:43 +00004620 // Bit field.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004621 inline byte bit_field();
4622 inline void set_bit_field(byte value);
4623
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00004624 // Bit field 2.
4625 inline byte bit_field2();
4626 inline void set_bit_field2(byte value);
4627
danno@chromium.org40cb8782011-05-25 07:58:50 +00004628 // Bit field 3.
4629 // TODO(1399): It should be possible to make room for bit_field3 in the map
4630 // without overloading the instance descriptors field (and storing it in the
4631 // DescriptorArray when the map has one).
4632 inline int bit_field3();
4633 inline void set_bit_field3(int value);
4634
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004635 // Tells whether the object in the prototype property will be used
4636 // for instances created from this function. If the prototype
4637 // property is set to a value that is not a JSObject, the prototype
4638 // property will not be used to create instances of the function.
4639 // See ECMA-262, 13.2.2.
4640 inline void set_non_instance_prototype(bool value);
4641 inline bool has_non_instance_prototype();
4642
kmillikin@chromium.org4111b802010-05-03 10:34:42 +00004643 // Tells whether function has special prototype property. If not, prototype
4644 // property will not be created when accessed (will return undefined),
4645 // and construction from this function will not be allowed.
4646 inline void set_function_with_prototype(bool value);
4647 inline bool function_with_prototype();
4648
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004649 // Tells whether the instance with this map should be ignored by the
4650 // __proto__ accessor.
4651 inline void set_is_hidden_prototype() {
4652 set_bit_field(bit_field() | (1 << kIsHiddenPrototype));
4653 }
4654
4655 inline bool is_hidden_prototype() {
4656 return ((1 << kIsHiddenPrototype) & bit_field()) != 0;
4657 }
4658
ager@chromium.orgeadaf222009-06-16 09:43:10 +00004659 // Records and queries whether the instance has a named interceptor.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004660 inline void set_has_named_interceptor() {
4661 set_bit_field(bit_field() | (1 << kHasNamedInterceptor));
4662 }
4663
4664 inline bool has_named_interceptor() {
4665 return ((1 << kHasNamedInterceptor) & bit_field()) != 0;
4666 }
4667
ager@chromium.orgeadaf222009-06-16 09:43:10 +00004668 // Records and queries whether the instance has an indexed interceptor.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004669 inline void set_has_indexed_interceptor() {
4670 set_bit_field(bit_field() | (1 << kHasIndexedInterceptor));
4671 }
4672
4673 inline bool has_indexed_interceptor() {
4674 return ((1 << kHasIndexedInterceptor) & bit_field()) != 0;
4675 }
4676
4677 // Tells whether the instance is undetectable.
4678 // An undetectable object is a special class of JSObject: 'typeof' operator
4679 // returns undefined, ToBoolean returns false. Otherwise it behaves like
4680 // a normal JS object. It is useful for implementing undetectable
4681 // document.all in Firefox & Safari.
4682 // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
4683 inline void set_is_undetectable() {
4684 set_bit_field(bit_field() | (1 << kIsUndetectable));
4685 }
4686
4687 inline bool is_undetectable() {
4688 return ((1 << kIsUndetectable) & bit_field()) != 0;
4689 }
4690
4691 // Tells whether the instance has a call-as-function handler.
4692 inline void set_has_instance_call_handler() {
4693 set_bit_field(bit_field() | (1 << kHasInstanceCallHandler));
4694 }
4695
4696 inline bool has_instance_call_handler() {
4697 return ((1 << kHasInstanceCallHandler) & bit_field()) != 0;
4698 }
4699
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004700 inline void set_is_extensible(bool value);
4701 inline bool is_extensible();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00004702
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004703 inline void set_elements_kind(ElementsKind elements_kind) {
4704 ASSERT(elements_kind < kElementsKindCount);
4705 ASSERT(kElementsKindCount <= (1 << kElementsKindBitCount));
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004706 set_bit_field2((bit_field2() & ~kElementsKindMask) |
4707 (elements_kind << kElementsKindShift));
4708 ASSERT(this->elements_kind() == elements_kind);
4709 }
4710
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004711 inline ElementsKind elements_kind() {
4712 return static_cast<ElementsKind>(
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004713 (bit_field2() & kElementsKindMask) >> kElementsKindShift);
fschneider@chromium.org40b9da32010-06-28 11:29:21 +00004714 }
4715
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004716 // Tells whether the instance has fast elements that are only Smis.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004717 inline bool has_fast_smi_elements() {
4718 return IsFastSmiElementsKind(elements_kind());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004719 }
4720
whesse@chromium.org7b260152011-06-20 15:33:18 +00004721 // Tells whether the instance has fast elements.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004722 inline bool has_fast_object_elements() {
4723 return IsFastObjectElementsKind(elements_kind());
4724 }
4725
4726 inline bool has_fast_smi_or_object_elements() {
4727 return IsFastSmiOrObjectElementsKind(elements_kind());
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00004728 }
4729
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004730 inline bool has_fast_double_elements() {
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004731 return IsFastDoubleElementsKind(elements_kind());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004732 }
4733
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004734 inline bool has_non_strict_arguments_elements() {
4735 return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4736 }
4737
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00004738 inline bool has_external_array_elements() {
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004739 return IsExternalArrayElementsKind(elements_kind());
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00004740 }
4741
ricow@chromium.org4f693d62011-07-04 14:01:31 +00004742 inline bool has_dictionary_elements() {
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004743 return IsDictionaryElementsKind(elements_kind());
ricow@chromium.org4f693d62011-07-04 14:01:31 +00004744 }
4745
ulan@chromium.org2efb9002012-01-19 15:36:35 +00004746 inline bool has_slow_elements_kind() {
4747 return elements_kind() == DICTIONARY_ELEMENTS
4748 || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4749 }
4750
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004751 static bool IsValidElementsTransition(ElementsKind from_kind,
4752 ElementsKind to_kind);
4753
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004754 inline Map* elements_transition_map();
4755 inline void set_elements_transition_map(Map* transitioned_map);
4756
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00004757 // Tells whether the map is attached to SharedFunctionInfo
4758 // (for inobject slack tracking).
4759 inline void set_attached_to_shared_function_info(bool value);
4760
4761 inline bool attached_to_shared_function_info();
4762
4763 // Tells whether the map is shared between objects that may have different
4764 // behavior. If true, the map should never be modified, instead a clone
4765 // should be created and modified.
4766 inline void set_is_shared(bool value);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00004767 inline bool is_shared();
4768
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004769 // Tells whether the instance needs security checks when accessing its
4770 // properties.
ager@chromium.org870a0b62008-11-04 11:43:05 +00004771 inline void set_is_access_check_needed(bool access_check_needed);
4772 inline bool is_access_check_needed();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004773
4774 // [prototype]: implicit prototype object.
4775 DECL_ACCESSORS(prototype, Object)
4776
4777 // [constructor]: points back to the function responsible for this map.
4778 DECL_ACCESSORS(constructor, Object)
4779
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00004780 inline JSFunction* unchecked_constructor();
4781
danno@chromium.org40cb8782011-05-25 07:58:50 +00004782 // Should only be called by the code that initializes map to set initial valid
4783 // value of the instance descriptor member.
4784 inline void init_instance_descriptors();
4785
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004786 // [instance descriptors]: describes the object.
4787 DECL_ACCESSORS(instance_descriptors, DescriptorArray)
4788
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004789 // Should only be called to clear a descriptor array that was only used to
4790 // store transitions and does not contain any live transitions anymore.
4791 inline void ClearDescriptorArray();
4792
danno@chromium.org40cb8782011-05-25 07:58:50 +00004793 // Sets the instance descriptor array for the map to be an empty descriptor
4794 // array.
4795 inline void clear_instance_descriptors();
4796
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004797 // [stub cache]: contains stubs compiled for this map.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00004798 DECL_ACCESSORS(code_cache, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004799
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004800 // [back pointer]: points back to the parent map from which a transition
4801 // leads to this map. The field overlaps with prototype transitions and the
4802 // back pointer will be moved into the prototype transitions array if
4803 // required.
4804 inline Object* GetBackPointer();
4805 inline void SetBackPointer(Object* value,
4806 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
4807
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004808 // [prototype transitions]: cache of prototype transitions.
4809 // Prototype transition is a transition that happens
4810 // when we change object's prototype to a new one.
4811 // Cache format:
4812 // 0: finger - index of the first free cell in the cache
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004813 // 1: back pointer that overlaps with prototype transitions field.
4814 // 2 + 2 * i: prototype
4815 // 3 + 2 * i: target map
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004816 DECL_ACCESSORS(prototype_transitions, FixedArray)
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004817
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004818 inline void init_prototype_transitions(Object* undefined);
4819 inline HeapObject* unchecked_prototype_transitions();
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004820
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004821 static const int kProtoTransitionHeaderSize = 2;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004822 static const int kProtoTransitionNumberOfEntriesOffset = 0;
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004823 static const int kProtoTransitionBackPointerOffset = 1;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004824 static const int kProtoTransitionElementsPerEntry = 2;
4825 static const int kProtoTransitionPrototypeOffset = 0;
4826 static const int kProtoTransitionMapOffset = 1;
4827
4828 inline int NumberOfProtoTransitions() {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004829 FixedArray* cache = prototype_transitions();
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004830 if (cache->length() == 0) return 0;
4831 return
4832 Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value();
4833 }
4834
4835 inline void SetNumberOfProtoTransitions(int value) {
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004836 FixedArray* cache = prototype_transitions();
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004837 ASSERT(cache->length() != 0);
4838 cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset,
4839 Smi::FromInt(value));
4840 }
4841
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004842 // Lookup in the map's instance descriptors and fill out the result
4843 // with the given holder if the name is found. The holder may be
4844 // NULL when this function is used from the compiler.
4845 void LookupInDescriptors(JSObject* holder,
4846 String* name,
4847 LookupResult* result);
4848
lrn@chromium.org303ada72010-10-27 09:33:13 +00004849 MUST_USE_RESULT MaybeObject* CopyDropDescriptors();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004850
lrn@chromium.org303ada72010-10-27 09:33:13 +00004851 MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode,
4852 NormalizedMapSharingMode sharing);
ricow@chromium.org65fae842010-08-25 15:26:24 +00004853
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00004854 // Returns a copy of the map, with all transitions dropped from the
4855 // instance descriptors.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004856 MUST_USE_RESULT MaybeObject* CopyDropTransitions(
4857 DescriptorArray::SharedMode shared_mode);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00004858
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004859 // Returns the property index for name (only valid for FAST MODE).
4860 int PropertyIndexFor(String* name);
4861
4862 // Returns the next free property index (only valid for FAST MODE).
4863 int NextFreePropertyIndex();
4864
jkummerow@chromium.orgab7dad42012-02-07 12:07:34 +00004865 // Returns the number of properties described in instance_descriptors
4866 // filtering out properties with the specified attributes.
4867 int NumberOfDescribedProperties(PropertyAttributes filter = NONE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004868
4869 // Casting.
4870 static inline Map* cast(Object* obj);
4871
4872 // Locate an accessor in the instance descriptor.
4873 AccessorDescriptor* FindAccessor(String* name);
4874
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004875 // Code cache operations.
4876
4877 // Clears the code cache.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004878 inline void ClearCodeCache(Heap* heap);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004879
4880 // Update code cache.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004881 static void UpdateCodeCache(Handle<Map> map,
4882 Handle<String> name,
4883 Handle<Code> code);
lrn@chromium.org303ada72010-10-27 09:33:13 +00004884 MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004885
4886 // Returns the found code or undefined if absent.
4887 Object* FindInCodeCache(String* name, Code::Flags flags);
4888
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00004889 // Returns the non-negative index of the code object if it is in the
4890 // cache and -1 otherwise.
sgjesse@chromium.org99a37fa2010-03-11 09:23:46 +00004891 int IndexInCodeCache(Object* name, Code* code);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00004892
4893 // Removes a code object from the code cache at the given index.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00004894 void RemoveFromCodeCache(String* name, Code* code, int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004895
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004896 // Set all map transitions from this map to dead maps to null. Also clear
4897 // back pointers in transition targets so that we do not process this map
4898 // again while following back pointers.
4899 void ClearNonLiveTransitions(Heap* heap);
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004900
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00004901 // Computes a hash value for this map, to be used in HashTables and such.
4902 int Hash();
4903
4904 // Compares this map to another to see if they describe equivalent objects.
4905 // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
4906 // it had exactly zero inobject properties.
4907 // The "shared" flags of both this map and |other| are ignored.
4908 bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
4909
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004910 // Returns the map that this map transitions to if its elements_kind
4911 // is changed to |elements_kind|, or NULL if no such map is cached yet.
4912 // |safe_to_add_transitions| is set to false if adding transitions is not
4913 // allowed.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004914 Map* LookupElementsTransitionMap(ElementsKind elements_kind);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004915
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004916 // Adds a new transitions for changing the elements kind to |elements_kind|.
4917 MUST_USE_RESULT MaybeObject* CreateNextElementsTransition(
4918 ElementsKind elements_kind);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004919
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004920 // Returns the transitioned map for this map with the most generic
4921 // elements_kind that's found in |candidates|, or null handle if no match is
4922 // found at all.
4923 Handle<Map> FindTransitionedMap(MapHandleList* candidates);
4924 Map* FindTransitionedMap(MapList* candidates);
4925
yangguo@chromium.org5f0b8ea2012-05-16 12:37:04 +00004926 // Zaps the contents of backing data structures in debug mode. Note that the
4927 // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects
4928 // holding weak references when incremental marking is used, because it also
4929 // iterates over objects that are otherwise unreachable.
4930#ifdef DEBUG
4931 void ZapInstanceDescriptors();
4932 void ZapPrototypeTransitions();
4933#endif
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004934
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004935 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00004936#ifdef OBJECT_PRINT
4937 inline void MapPrint() {
4938 MapPrint(stdout);
4939 }
4940 void MapPrint(FILE* out);
4941#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004942#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004943 void MapVerify();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00004944 void SharedMapVerify();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004945#endif
4946
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00004947 inline int visitor_id();
4948 inline void set_visitor_id(int visitor_id);
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00004949
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00004950 typedef void (*TraverseCallback)(Map* map, void* data);
4951
4952 void TraverseTransitionTree(TraverseCallback callback, void* data);
4953
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004954 // When you set the prototype of an object using the __proto__ accessor you
4955 // need a new map for the object (the prototype is stored in the map). In
4956 // order not to multiply maps unnecessarily we store these as transitions in
4957 // the original map. That way we can transition to the same map if the same
4958 // prototype is set, rather than creating a new map every time. The
4959 // transitions are in the form of a map where the keys are prototype objects
ulan@chromium.orgf6a0c412012-06-15 12:31:06 +00004960 // and the values are the maps the are transitioned to.
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004961 static const int kMaxCachedPrototypeTransitions = 256;
4962
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004963 Map* GetPrototypeTransition(Object* prototype);
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004964
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00004965 MUST_USE_RESULT MaybeObject* PutPrototypeTransition(Object* prototype,
4966 Map* map);
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004967
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00004968 static const int kMaxPreAllocatedPropertyFields = 255;
4969
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004970 // Layout description.
ager@chromium.org7c537e22008-10-16 08:43:32 +00004971 static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
4972 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004973 static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize;
4974 static const int kConstructorOffset = kPrototypeOffset + kPointerSize;
danno@chromium.org40cb8782011-05-25 07:58:50 +00004975 // Storage for instance descriptors is overloaded to also contain additional
4976 // map flags when unused (bit_field3). When the map has instance descriptors,
4977 // the flags are transferred to the instance descriptor array and accessed
4978 // through an extra indirection.
4979 // TODO(1399): It should be possible to make room for bit_field3 in the map
4980 // without overloading the instance descriptors field, but the map is
4981 // currently perfectly aligned to 32 bytes and extending it at all would
4982 // double its size. After the increment GC work lands, this size restriction
4983 // could be loosened and bit_field3 moved directly back in the map.
4984 static const int kInstanceDescriptorsOrBitField3Offset =
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004985 kConstructorOffset + kPointerSize;
danno@chromium.org40cb8782011-05-25 07:58:50 +00004986 static const int kCodeCacheOffset =
4987 kInstanceDescriptorsOrBitField3Offset + kPointerSize;
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004988 static const int kPrototypeTransitionsOrBackPointerOffset =
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004989 kCodeCacheOffset + kPointerSize;
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004990 static const int kPadStart =
4991 kPrototypeTransitionsOrBackPointerOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00004992 static const int kSize = MAP_POINTER_ALIGN(kPadStart);
4993
4994 // Layout of pointer fields. Heap iteration code relies on them
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004995 // being continuously allocated.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00004996 static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset;
4997 static const int kPointerFieldsEndOffset =
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004998 kPrototypeTransitionsOrBackPointerOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004999
ager@chromium.org7c537e22008-10-16 08:43:32 +00005000 // Byte offsets within kInstanceSizesOffset.
5001 static const int kInstanceSizeOffset = kInstanceSizesOffset + 0;
ager@chromium.orga1645e22009-09-09 19:27:10 +00005002 static const int kInObjectPropertiesByte = 1;
5003 static const int kInObjectPropertiesOffset =
5004 kInstanceSizesOffset + kInObjectPropertiesByte;
5005 static const int kPreAllocatedPropertyFieldsByte = 2;
5006 static const int kPreAllocatedPropertyFieldsOffset =
5007 kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte;
ager@chromium.org5b2fbee2010-09-08 06:38:15 +00005008 static const int kVisitorIdByte = 3;
5009 static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte;
ager@chromium.org7c537e22008-10-16 08:43:32 +00005010
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005011 // Byte offsets within kInstanceAttributesOffset attributes.
ager@chromium.org7c537e22008-10-16 08:43:32 +00005012 static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0;
5013 static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1;
5014 static const int kBitFieldOffset = kInstanceAttributesOffset + 2;
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00005015 static const int kBitField2Offset = kInstanceAttributesOffset + 3;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005016
ager@chromium.org18ad94b2009-09-02 08:22:29 +00005017 STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset);
5018
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005019 // Bit positions for bit field.
mads.s.ager31e71382008-08-13 09:32:07 +00005020 static const int kUnused = 0; // To be used for marking recently used maps.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005021 static const int kHasNonInstancePrototype = 1;
5022 static const int kIsHiddenPrototype = 2;
5023 static const int kHasNamedInterceptor = 3;
5024 static const int kHasIndexedInterceptor = 4;
5025 static const int kIsUndetectable = 5;
5026 static const int kHasInstanceCallHandler = 6;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00005027 static const int kIsAccessCheckNeeded = 7;
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00005028
ager@chromium.orge2902be2009-06-08 12:21:35 +00005029 // Bit positions for bit field 2
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00005030 static const int kIsExtensible = 0;
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00005031 static const int kStringWrapperSafeForDefaultValueOf = 1;
5032 static const int kAttachedToSharedFunctionInfo = 2;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00005033 // No bits can be used after kElementsKindFirstBit, they are all reserved for
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00005034 // storing ElementKind.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00005035 static const int kElementsKindShift = 3;
5036 static const int kElementsKindBitCount = 5;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00005037
5038 // Derived values from bit field 2
5039 static const int kElementsKindMask = (-1 << kElementsKindShift) &
5040 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1);
5041 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00005042 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1;
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00005043 static const int8_t kMaximumBitField2FastSmiElementValue =
5044 static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) <<
5045 Map::kElementsKindShift) - 1;
5046 static const int8_t kMaximumBitField2FastHoleyElementValue =
5047 static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) <<
5048 Map::kElementsKindShift) - 1;
5049 static const int8_t kMaximumBitField2FastHoleySmiElementValue =
5050 static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) <<
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00005051 Map::kElementsKindShift) - 1;
danno@chromium.org40cb8782011-05-25 07:58:50 +00005052
5053 // Bit positions for bit field 3
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00005054 static const int kIsShared = 0;
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00005055 static const int kFunctionWithPrototype = 1;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005056
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00005057 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
5058 kPointerFieldsEndOffset,
5059 kSize> BodyDescriptor;
5060
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005061 private:
5062 DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
5063};
5064
5065
5066// An abstract superclass, a marker class really, for simple structure classes.
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00005067// It doesn't carry much functionality but allows struct classes to be
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005068// identified in the type system.
5069class Struct: public HeapObject {
5070 public:
5071 inline void InitializeBody(int object_size);
5072 static inline Struct* cast(Object* that);
5073};
5074
5075
mads.s.ager31e71382008-08-13 09:32:07 +00005076// Script describes a script which has been added to the VM.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005077class Script: public Struct {
5078 public:
ager@chromium.orge2902be2009-06-08 12:21:35 +00005079 // Script types.
5080 enum Type {
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00005081 TYPE_NATIVE = 0,
5082 TYPE_EXTENSION = 1,
5083 TYPE_NORMAL = 2
ager@chromium.orge2902be2009-06-08 12:21:35 +00005084 };
5085
5086 // Script compilation types.
5087 enum CompilationType {
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00005088 COMPILATION_TYPE_HOST = 0,
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00005089 COMPILATION_TYPE_EVAL = 1
ager@chromium.orge2902be2009-06-08 12:21:35 +00005090 };
5091
rossberg@chromium.org2c067b12012-03-19 11:01:52 +00005092 // Script compilation state.
5093 enum CompilationState {
5094 COMPILATION_STATE_INITIAL = 0,
5095 COMPILATION_STATE_COMPILED = 1
5096 };
5097
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005098 // [source]: the script source.
5099 DECL_ACCESSORS(source, Object)
5100
5101 // [name]: the script name.
5102 DECL_ACCESSORS(name, Object)
5103
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00005104 // [id]: the script id.
5105 DECL_ACCESSORS(id, Object)
5106
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005107 // [line_offset]: script line offset in resource from where it was extracted.
5108 DECL_ACCESSORS(line_offset, Smi)
5109
5110 // [column_offset]: script column offset in resource from where it was
5111 // extracted.
5112 DECL_ACCESSORS(column_offset, Smi)
5113
ager@chromium.org65dad4b2009-04-23 08:48:43 +00005114 // [data]: additional data associated with this script.
5115 DECL_ACCESSORS(data, Object)
5116
ager@chromium.org9085a012009-05-11 19:22:57 +00005117 // [context_data]: context data for the context this script was compiled in.
5118 DECL_ACCESSORS(context_data, Object)
5119
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005120 // [wrapper]: the wrapper cache.
ager@chromium.orgea91cc52011-05-23 06:06:11 +00005121 DECL_ACCESSORS(wrapper, Foreign)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005122
5123 // [type]: the script type.
5124 DECL_ACCESSORS(type, Smi)
5125
ager@chromium.orge2902be2009-06-08 12:21:35 +00005126 // [compilation]: how the the script was compiled.
5127 DECL_ACCESSORS(compilation_type, Smi)
5128
rossberg@chromium.org2c067b12012-03-19 11:01:52 +00005129 // [is_compiled]: determines whether the script has already been compiled.
5130 DECL_ACCESSORS(compilation_state, Smi)
5131
ager@chromium.orgc4c92722009-11-18 14:12:51 +00005132 // [line_ends]: FixedArray of line ends positions.
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +00005133 DECL_ACCESSORS(line_ends, Object)
iposva@chromium.org245aa852009-02-10 00:49:54 +00005134
sgjesse@chromium.org98180592009-12-02 08:17:28 +00005135 // [eval_from_shared]: for eval scripts the shared funcion info for the
5136 // function from which eval was called.
5137 DECL_ACCESSORS(eval_from_shared, Object)
ager@chromium.orge2902be2009-06-08 12:21:35 +00005138
5139 // [eval_from_instructions_offset]: the instruction offset in the code for the
5140 // function from which eval was called where eval was called.
5141 DECL_ACCESSORS(eval_from_instructions_offset, Smi)
5142
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005143 static inline Script* cast(Object* obj);
5144
sgjesse@chromium.org152a0b02009-10-07 13:50:16 +00005145 // If script source is an external string, check that the underlying
5146 // resource is accessible. Otherwise, always return true.
5147 inline bool HasValidSource();
5148
whesse@chromium.org023421e2010-12-21 12:19:12 +00005149#ifdef OBJECT_PRINT
5150 inline void ScriptPrint() {
5151 ScriptPrint(stdout);
5152 }
5153 void ScriptPrint(FILE* out);
5154#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005155#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005156 void ScriptVerify();
5157#endif
5158
ager@chromium.org236ad962008-09-25 09:45:57 +00005159 static const int kSourceOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005160 static const int kNameOffset = kSourceOffset + kPointerSize;
5161 static const int kLineOffsetOffset = kNameOffset + kPointerSize;
5162 static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
ager@chromium.org65dad4b2009-04-23 08:48:43 +00005163 static const int kDataOffset = kColumnOffsetOffset + kPointerSize;
ager@chromium.org9085a012009-05-11 19:22:57 +00005164 static const int kContextOffset = kDataOffset + kPointerSize;
5165 static const int kWrapperOffset = kContextOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005166 static const int kTypeOffset = kWrapperOffset + kPointerSize;
ager@chromium.orge2902be2009-06-08 12:21:35 +00005167 static const int kCompilationTypeOffset = kTypeOffset + kPointerSize;
rossberg@chromium.org2c067b12012-03-19 11:01:52 +00005168 static const int kCompilationStateOffset =
5169 kCompilationTypeOffset + kPointerSize;
5170 static const int kLineEndsOffset = kCompilationStateOffset + kPointerSize;
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +00005171 static const int kIdOffset = kLineEndsOffset + kPointerSize;
sgjesse@chromium.org98180592009-12-02 08:17:28 +00005172 static const int kEvalFromSharedOffset = kIdOffset + kPointerSize;
ager@chromium.orge2902be2009-06-08 12:21:35 +00005173 static const int kEvalFrominstructionsOffsetOffset =
sgjesse@chromium.org98180592009-12-02 08:17:28 +00005174 kEvalFromSharedOffset + kPointerSize;
ager@chromium.orge2902be2009-06-08 12:21:35 +00005175 static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005176
5177 private:
5178 DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
5179};
5180
5181
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005182// List of builtin functions we want to identify to improve code
5183// generation.
5184//
5185// Each entry has a name of a global object property holding an object
5186// optionally followed by ".prototype", a name of a builtin function
5187// on the object (the one the id is set for), and a label.
5188//
5189// Installation of ids for the selected builtin functions is handled
5190// by the bootstrapper.
5191//
5192// NOTE: Order is important: math functions should be at the end of
5193// the list and MathFloor should be the first math function.
5194#define FUNCTIONS_WITH_ID_LIST(V) \
5195 V(Array.prototype, push, ArrayPush) \
5196 V(Array.prototype, pop, ArrayPop) \
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00005197 V(Function.prototype, apply, FunctionApply) \
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005198 V(String.prototype, charCodeAt, StringCharCodeAt) \
5199 V(String.prototype, charAt, StringCharAt) \
5200 V(String, fromCharCode, StringFromCharCode) \
5201 V(Math, floor, MathFloor) \
5202 V(Math, round, MathRound) \
5203 V(Math, ceil, MathCeil) \
5204 V(Math, abs, MathAbs) \
5205 V(Math, log, MathLog) \
5206 V(Math, sin, MathSin) \
5207 V(Math, cos, MathCos) \
5208 V(Math, tan, MathTan) \
5209 V(Math, asin, MathASin) \
5210 V(Math, acos, MathACos) \
5211 V(Math, atan, MathATan) \
5212 V(Math, exp, MathExp) \
5213 V(Math, sqrt, MathSqrt) \
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00005214 V(Math, pow, MathPow) \
5215 V(Math, random, MathRandom) \
5216 V(Math, max, MathMax) \
5217 V(Math, min, MathMin)
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005218
5219
5220enum BuiltinFunctionId {
5221#define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \
5222 k##name,
5223 FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID)
5224#undef DECLARE_FUNCTION_ID
5225 // Fake id for a special case of Math.pow. Note, it continues the
5226 // list of math functions.
5227 kMathPowHalf,
5228 kFirstMathFunctionId = kMathFloor
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005229};
5230
5231
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005232// SharedFunctionInfo describes the JSFunction information that can be
5233// shared by multiple instances of the function.
5234class SharedFunctionInfo: public HeapObject {
5235 public:
5236 // [name]: Function name.
5237 DECL_ACCESSORS(name, Object)
5238
5239 // [code]: Function code.
5240 DECL_ACCESSORS(code, Code)
5241
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005242 // [optimized_code_map]: Map from global context to optimized code
5243 // and a shared literals array or Smi 0 if none.
5244 DECL_ACCESSORS(optimized_code_map, Object)
5245
5246 // Returns index i of the entry with the specified context. At position
5247 // i - 1 is the context, position i the code, and i + 1 the literals array.
5248 // Returns -1 when no matching entry is found.
5249 int SearchOptimizedCodeMap(Context* global_context);
5250
ulan@chromium.orgd9e468a2012-06-25 09:47:40 +00005251 // Installs optimized code from the code map on the given closure. The
5252 // index has to be consistent with a search result as defined above.
5253 void InstallFromOptimizedCodeMap(JSFunction* function, int index);
5254
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005255 // Clear optimized code map.
5256 void ClearOptimizedCodeMap();
5257
5258 // Add a new entry to the optimized code map.
5259 static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
5260 Handle<Context> global_context,
5261 Handle<Code> code,
5262 Handle<FixedArray> literals);
5263 static const int kEntryLength = 3;
5264
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00005265 // [scope_info]: Scope info.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00005266 DECL_ACCESSORS(scope_info, ScopeInfo)
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00005267
ager@chromium.org5aa501c2009-06-23 07:57:28 +00005268 // [construct stub]: Code stub for constructing instances of this function.
5269 DECL_ACCESSORS(construct_stub, Code)
5270
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005271 inline Code* unchecked_code();
5272
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005273 // Returns if this function has been compiled to native code yet.
5274 inline bool is_compiled();
5275
5276 // [length]: The function length - usually the number of declared parameters.
5277 // Use up to 2^30 parameters.
5278 inline int length();
5279 inline void set_length(int value);
5280
5281 // [formal parameter count]: The declared number of parameters.
5282 inline int formal_parameter_count();
5283 inline void set_formal_parameter_count(int value);
5284
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00005285 // Set the formal parameter count so the function code will be
5286 // called without using argument adaptor frames.
5287 inline void DontAdaptArguments();
5288
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005289 // [expected_nof_properties]: Expected number of properties for the function.
5290 inline int expected_nof_properties();
5291 inline void set_expected_nof_properties(int value);
5292
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005293 // Inobject slack tracking is the way to reclaim unused inobject space.
5294 //
5295 // The instance size is initially determined by adding some slack to
5296 // expected_nof_properties (to allow for a few extra properties added
5297 // after the constructor). There is no guarantee that the extra space
5298 // will not be wasted.
5299 //
5300 // Here is the algorithm to reclaim the unused inobject space:
5301 // - Detect the first constructor call for this SharedFunctionInfo.
5302 // When it happens enter the "in progress" state: remember the
5303 // constructor's initial_map and install a special construct stub that
5304 // counts constructor calls.
5305 // - While the tracking is in progress create objects filled with
5306 // one_pointer_filler_map instead of undefined_value. This way they can be
5307 // resized quickly and safely.
5308 // - Once enough (kGenerousAllocationCount) objects have been created
5309 // compute the 'slack' (traverse the map transition tree starting from the
5310 // initial_map and find the lowest value of unused_property_fields).
5311 // - Traverse the transition tree again and decrease the instance size
5312 // of every map. Existing objects will resize automatically (they are
5313 // filled with one_pointer_filler_map). All further allocations will
5314 // use the adjusted instance size.
5315 // - Decrease expected_nof_properties so that an allocations made from
5316 // another context will use the adjusted instance size too.
5317 // - Exit "in progress" state by clearing the reference to the initial_map
5318 // and setting the regular construct stub (generic or inline).
5319 //
5320 // The above is the main event sequence. Some special cases are possible
5321 // while the tracking is in progress:
5322 //
5323 // - GC occurs.
5324 // Check if the initial_map is referenced by any live objects (except this
5325 // SharedFunctionInfo). If it is, continue tracking as usual.
5326 // If it is not, clear the reference and reset the tracking state. The
5327 // tracking will be initiated again on the next constructor call.
5328 //
5329 // - The constructor is called from another context.
5330 // Immediately complete the tracking, perform all the necessary changes
5331 // to maps. This is necessary because there is no efficient way to track
5332 // multiple initial_maps.
5333 // Proceed to create an object in the current context (with the adjusted
5334 // size).
5335 //
5336 // - A different constructor function sharing the same SharedFunctionInfo is
5337 // called in the same context. This could be another closure in the same
5338 // context, or the first function could have been disposed.
5339 // This is handled the same way as the previous case.
5340 //
5341 // Important: inobject slack tracking is not attempted during the snapshot
5342 // creation.
5343
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +00005344 static const int kGenerousAllocationCount = 8;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005345
5346 // [construction_count]: Counter for constructor calls made during
5347 // the tracking phase.
5348 inline int construction_count();
5349 inline void set_construction_count(int value);
5350
5351 // [initial_map]: initial map of the first function called as a constructor.
5352 // Saved for the duration of the tracking phase.
5353 // This is a weak link (GC resets it to undefined_value if no other live
5354 // object reference this map).
5355 DECL_ACCESSORS(initial_map, Object)
5356
5357 // True if the initial_map is not undefined and the countdown stub is
5358 // installed.
5359 inline bool IsInobjectSlackTrackingInProgress();
5360
5361 // Starts the tracking.
5362 // Stores the initial map and installs the countdown stub.
5363 // IsInobjectSlackTrackingInProgress is normally true after this call,
5364 // except when tracking have not been started (e.g. the map has no unused
5365 // properties or the snapshot is being built).
5366 void StartInobjectSlackTracking(Map* map);
5367
5368 // Completes the tracking.
5369 // IsInobjectSlackTrackingInProgress is false after this call.
5370 void CompleteInobjectSlackTracking();
5371
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005372 // Invoked before pointers in SharedFunctionInfo are being marked.
5373 // Also clears the optimized code map.
5374 inline void BeforeVisitingPointers();
5375
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005376 // Clears the initial_map before the GC marking phase to ensure the reference
5377 // is weak. IsInobjectSlackTrackingInProgress is false after this call.
5378 void DetachInitialMap();
5379
5380 // Restores the link to the initial map after the GC marking phase.
5381 // IsInobjectSlackTrackingInProgress is true after this call.
5382 void AttachInitialMap(Map* map);
5383
5384 // False if there are definitely no live objects created from this function.
5385 // True if live objects _may_ exist (existence not guaranteed).
5386 // May go back from true to false after GC.
whesse@chromium.org7b260152011-06-20 15:33:18 +00005387 DECL_BOOLEAN_ACCESSORS(live_objects_may_exist)
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005388
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005389 // [instance class name]: class name for instances.
5390 DECL_ACCESSORS(instance_class_name, Object)
5391
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005392 // [function data]: This field holds some additional data for function.
5393 // Currently it either has FunctionTemplateInfo to make benefit the API
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005394 // or Smi identifying a builtin function.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005395 // In the long run we don't want all functions to have this field but
5396 // we can fix that when we have a better model for storing hidden data
5397 // on objects.
5398 DECL_ACCESSORS(function_data, Object)
5399
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005400 inline bool IsApiFunction();
5401 inline FunctionTemplateInfo* get_api_func_data();
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005402 inline bool HasBuiltinFunctionId();
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005403 inline BuiltinFunctionId builtin_function_id();
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005404
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005405 // [script info]: Script from which the function originates.
5406 DECL_ACCESSORS(script, Object)
5407
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00005408 // [num_literals]: Number of literals used by this function.
5409 inline int num_literals();
5410 inline void set_num_literals(int value);
5411
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005412 // [start_position_and_type]: Field used to store both the source code
5413 // position, whether or not the function is a function expression,
5414 // and whether or not the function is a toplevel function. The two
5415 // least significants bit indicates whether the function is an
5416 // expression and the rest contains the source code position.
5417 inline int start_position_and_type();
5418 inline void set_start_position_and_type(int value);
5419
5420 // [debug info]: Debug information.
5421 DECL_ACCESSORS(debug_info, Object)
5422
kasperl@chromium.orgd1e3e722009-04-14 13:38:25 +00005423 // [inferred name]: Name inferred from variable or property
5424 // assignment of this function. Used to facilitate debugging and
5425 // profiling of JavaScript code written in OO style, where almost
5426 // all functions are anonymous but are assigned to object
5427 // properties.
5428 DECL_ACCESSORS(inferred_name, String)
5429
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00005430 // The function's name if it is non-empty, otherwise the inferred name.
5431 String* DebugName();
5432
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005433 // Position of the 'function' token in the script source.
5434 inline int function_token_position();
5435 inline void set_function_token_position(int function_token_position);
5436
5437 // Position of this function in the script source.
5438 inline int start_position();
5439 inline void set_start_position(int start_position);
5440
5441 // End position of this function in the script source.
5442 inline int end_position();
5443 inline void set_end_position(int end_position);
5444
5445 // Is this function a function expression in the source code.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005446 DECL_BOOLEAN_ACCESSORS(is_expression)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005447
ager@chromium.orga1645e22009-09-09 19:27:10 +00005448 // Is this function a top-level function (scripts, evals).
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005449 DECL_BOOLEAN_ACCESSORS(is_toplevel)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005450
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005451 // Bit field containing various information collected by the compiler to
5452 // drive optimization.
5453 inline int compiler_hints();
5454 inline void set_compiler_hints(int value);
5455
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00005456 inline int ast_node_count();
5457 inline void set_ast_node_count(int count);
5458
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005459 // A counter used to determine when to stress the deoptimizer with a
5460 // deopt.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005461 inline int stress_deopt_counter();
5462 inline void set_stress_deopt_counter(int counter);
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00005463
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00005464 inline int profiler_ticks();
5465
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00005466 // Inline cache age is used to infer whether the function survived a context
5467 // disposal or not. In the former case we reset the opt_count.
5468 inline int ic_age();
5469 inline void set_ic_age(int age);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005470
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005471 // Add information on assignments of the form this.x = ...;
5472 void SetThisPropertyAssignmentsInfo(
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005473 bool has_only_simple_this_property_assignments,
5474 FixedArray* this_property_assignments);
5475
ager@chromium.org18ad94b2009-09-02 08:22:29 +00005476 // Clear information on assignments of the form this.x = ...;
5477 void ClearThisPropertyAssignmentsInfo();
5478
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005479 // Indicate that this function only consists of assignments of the form
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005480 // this.x = y; where y is either a constant or refers to an argument.
5481 inline bool has_only_simple_this_property_assignments();
5482
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00005483 // Indicates if this function can be lazy compiled.
5484 // This is used to determine if we can safely flush code from a function
5485 // when doing GC if we expect that the function will no longer be used.
whesse@chromium.org7b260152011-06-20 15:33:18 +00005486 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation)
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00005487
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005488 // Indicates if this function can be lazy compiled without a context.
5489 // This is used to determine if we can force compilation without reaching
5490 // the function through program execution but through other means (e.g. heap
5491 // iteration by the debugger).
5492 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context)
5493
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005494 // Indicates how many full GCs this function has survived with assigned
5495 // code object. Used to determine when it is relatively safe to flush
5496 // this code object and replace it with lazy compilation stub.
5497 // Age is reset when GC notices that the code object is referenced
5498 // from the stack or compilation cache.
5499 inline int code_age();
5500 inline void set_code_age(int age);
5501
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005502 // Indicates whether optimizations have been disabled for this
5503 // shared function info. If a function is repeatedly optimized or if
5504 // we cannot optimize the function we disable optimization to avoid
5505 // spending time attempting to optimize it again.
whesse@chromium.org7b260152011-06-20 15:33:18 +00005506 DECL_BOOLEAN_ACCESSORS(optimization_disabled)
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005507
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005508 // Indicates the language mode of the function's code as defined by the
5509 // current harmony drafts for the next ES language standard. Possible
5510 // values are:
5511 // 1. CLASSIC_MODE - Unrestricted syntax and semantics, same as in ES5.
5512 // 2. STRICT_MODE - Restricted syntax and semantics, same as in ES5.
5513 // 3. EXTENDED_MODE - Only available under the harmony flag, not part of ES5.
5514 inline LanguageMode language_mode();
5515 inline void set_language_mode(LanguageMode language_mode);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005516
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005517 // Indicates whether the language mode of this function is CLASSIC_MODE.
5518 inline bool is_classic_mode();
5519
5520 // Indicates whether the language mode of this function is EXTENDED_MODE.
5521 inline bool is_extended_mode();
whesse@chromium.org7b260152011-06-20 15:33:18 +00005522
5523 // False if the function definitely does not allocate an arguments object.
5524 DECL_BOOLEAN_ACCESSORS(uses_arguments)
5525
5526 // True if the function has any duplicated parameter names.
5527 DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
ricow@chromium.org83aa5492011-02-07 12:42:56 +00005528
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005529 // Indicates whether the function is a native function.
lrn@chromium.org34e60782011-09-15 07:25:40 +00005530 // These needs special treatment in .call and .apply since
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005531 // null passed as the receiver should not be translated to the
5532 // global object.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005533 DECL_BOOLEAN_ACCESSORS(native)
5534
5535 // Indicates that the function was created by the Function function.
5536 // Though it's anonymous, toString should treat it as if it had the name
5537 // "anonymous". We don't set the name itself so that the system does not
5538 // see a binding for it.
5539 DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous)
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005540
whesse@chromium.org7b260152011-06-20 15:33:18 +00005541 // Indicates whether the function is a bound function created using
5542 // the bind function.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005543 DECL_BOOLEAN_ACCESSORS(bound)
5544
5545 // Indicates that the function is anonymous (the name field can be set
5546 // through the API, which does not change this flag).
5547 DECL_BOOLEAN_ACCESSORS(is_anonymous)
whesse@chromium.org7b260152011-06-20 15:33:18 +00005548
yangguo@chromium.org56454712012-02-16 15:33:53 +00005549 // Is this a function or top-level/eval code.
5550 DECL_BOOLEAN_ACCESSORS(is_function)
5551
5552 // Indicates that the function cannot be optimized.
5553 DECL_BOOLEAN_ACCESSORS(dont_optimize)
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00005554
5555 // Indicates that the function cannot be inlined.
5556 DECL_BOOLEAN_ACCESSORS(dont_inline)
5557
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005558 // Indicates whether or not the code in the shared function support
5559 // deoptimization.
5560 inline bool has_deoptimization_support();
5561
5562 // Enable deoptimization support through recompiled code.
5563 void EnableDeoptimizationSupport(Code* recompiled);
5564
ager@chromium.orgea91cc52011-05-23 06:06:11 +00005565 // Disable (further) attempted optimization of all functions sharing this
yangguo@chromium.org56454712012-02-16 15:33:53 +00005566 // shared function info.
5567 void DisableOptimization();
ager@chromium.orgea91cc52011-05-23 06:06:11 +00005568
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005569 // Lookup the bailout ID and ASSERT that it exists in the non-optimized
5570 // code, returns whether it asserted (i.e., always true if assertions are
5571 // disabled).
5572 bool VerifyBailoutId(int id);
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005573
ager@chromium.org5c838252010-02-19 08:53:10 +00005574 // Check whether a inlined constructor can be generated with the given
5575 // prototype.
5576 bool CanGenerateInlineConstructor(Object* prototype);
5577
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +00005578 // Prevents further attempts to generate inline constructors.
5579 // To be called if generation failed for any reason.
5580 void ForbidInlineConstructor();
5581
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005582 // For functions which only contains this property assignments this provides
5583 // access to the names for the properties assigned.
5584 DECL_ACCESSORS(this_property_assignments, Object)
5585 inline int this_property_assignments_count();
5586 inline void set_this_property_assignments_count(int value);
5587 String* GetThisPropertyAssignmentName(int index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00005588 bool IsThisPropertyAssignmentArgument(int index);
5589 int GetThisPropertyAssignmentArgument(int index);
5590 Object* GetThisPropertyAssignmentConstant(int index);
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005591
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005592 // [source code]: Source code for the function.
5593 bool HasSourceCode();
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00005594 Handle<Object> GetSourceCode();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005595
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005596 // Number of times the function was optimized.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005597 inline int opt_count();
5598 inline void set_opt_count(int opt_count);
5599
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005600 // Number of times the function was deoptimized.
5601 inline void set_deopt_count(int value);
5602 inline int deopt_count();
5603 inline void increment_deopt_count();
5604
5605 // Number of time we tried to re-enable optimization after it
5606 // was disabled due to high number of deoptimizations.
5607 inline void set_opt_reenable_tries(int value);
5608 inline int opt_reenable_tries();
5609
5610 inline void TryReenableOptimization();
5611
5612 // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields.
5613 inline void set_counters(int value);
5614 inline int counters();
5615
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005616 // Source size of this function.
5617 int SourceSize();
5618
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005619 // Calculate the instance size.
5620 int CalculateInstanceSize();
5621
5622 // Calculate the number of in-object properties.
5623 int CalculateInObjectProperties();
5624
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005625 // Dispatched behavior.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005626 // Set max_length to -1 for unlimited length.
5627 void SourceCodePrint(StringStream* accumulator, int max_length);
whesse@chromium.org023421e2010-12-21 12:19:12 +00005628#ifdef OBJECT_PRINT
5629 inline void SharedFunctionInfoPrint() {
5630 SharedFunctionInfoPrint(stdout);
5631 }
5632 void SharedFunctionInfoPrint(FILE* out);
5633#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005634#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005635 void SharedFunctionInfoVerify();
5636#endif
5637
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00005638 void ResetForNewContext(int new_ic_age);
5639
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005640 // Helper to compile the shared code. Returns true on success, false on
5641 // failure (e.g., stack overflow during compilation). This is only used by
5642 // the debugger, it is not possible to compile without a context otherwise.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005643 static bool CompileLazy(Handle<SharedFunctionInfo> shared,
5644 ClearExceptionFlag flag);
5645
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00005646 void SharedFunctionInfoIterateBody(ObjectVisitor* v);
5647
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005648 // Casting.
5649 static inline SharedFunctionInfo* cast(Object* obj);
5650
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00005651 // Constants.
5652 static const int kDontAdaptArgumentsSentinel = -1;
5653
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005654 // Layout description.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005655 // Pointer fields.
ager@chromium.org236ad962008-09-25 09:45:57 +00005656 static const int kNameOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005657 static const int kCodeOffset = kNameOffset + kPointerSize;
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005658 static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize;
5659 static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize;
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00005660 static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005661 static const int kInstanceClassNameOffset =
5662 kConstructStubOffset + kPointerSize;
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005663 static const int kFunctionDataOffset =
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005664 kInstanceClassNameOffset + kPointerSize;
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005665 static const int kScriptOffset = kFunctionDataOffset + kPointerSize;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005666 static const int kDebugInfoOffset = kScriptOffset + kPointerSize;
5667 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005668 static const int kInitialMapOffset =
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005669 kInferredNameOffset + kPointerSize;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005670 static const int kThisPropertyAssignmentsOffset =
5671 kInitialMapOffset + kPointerSize;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005672 // ast_node_count is a Smi field. It could be grouped with another Smi field
5673 // into a PSEUDO_SMI_ACCESSORS pair (on x64), if one becomes available.
5674 static const int kAstNodeCountOffset =
5675 kThisPropertyAssignmentsOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005676#if V8_HOST_ARCH_32_BIT
5677 // Smi fields.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005678 static const int kLengthOffset =
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005679 kAstNodeCountOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005680 static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize;
5681 static const int kExpectedNofPropertiesOffset =
5682 kFormalParameterCountOffset + kPointerSize;
5683 static const int kNumLiteralsOffset =
5684 kExpectedNofPropertiesOffset + kPointerSize;
5685 static const int kStartPositionAndTypeOffset =
5686 kNumLiteralsOffset + kPointerSize;
5687 static const int kEndPositionOffset =
5688 kStartPositionAndTypeOffset + kPointerSize;
5689 static const int kFunctionTokenPositionOffset =
5690 kEndPositionOffset + kPointerSize;
5691 static const int kCompilerHintsOffset =
5692 kFunctionTokenPositionOffset + kPointerSize;
5693 static const int kThisPropertyAssignmentsCountOffset =
5694 kCompilerHintsOffset + kPointerSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005695 static const int kOptCountOffset =
5696 kThisPropertyAssignmentsCountOffset + kPointerSize;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005697 static const int kCountersOffset = kOptCountOffset + kPointerSize;
5698 static const int kStressDeoptCounterOffset = kCountersOffset + kPointerSize;
danno@chromium.org1044a4d2012-04-30 12:34:39 +00005699
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005700 // Total size.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005701 static const int kSize = kStressDeoptCounterOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005702#else
5703 // The only reason to use smi fields instead of int fields
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005704 // is to allow iteration without maps decoding during
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005705 // garbage collections.
5706 // To avoid wasting space on 64-bit architectures we use
5707 // the following trick: we group integer fields into pairs
5708 // First integer in each pair is shifted left by 1.
5709 // By doing this we guarantee that LSB of each kPointerSize aligned
5710 // word is not set and thus this word cannot be treated as pointer
5711 // to HeapObject during old space traversal.
5712 static const int kLengthOffset =
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005713 kAstNodeCountOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005714 static const int kFormalParameterCountOffset =
5715 kLengthOffset + kIntSize;
5716
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005717 static const int kExpectedNofPropertiesOffset =
5718 kFormalParameterCountOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005719 static const int kNumLiteralsOffset =
5720 kExpectedNofPropertiesOffset + kIntSize;
5721
5722 static const int kEndPositionOffset =
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00005723 kNumLiteralsOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005724 static const int kStartPositionAndTypeOffset =
5725 kEndPositionOffset + kIntSize;
5726
5727 static const int kFunctionTokenPositionOffset =
5728 kStartPositionAndTypeOffset + kIntSize;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005729 static const int kCompilerHintsOffset =
kasperl@chromium.org71affb52009-05-26 05:44:31 +00005730 kFunctionTokenPositionOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005731
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005732 static const int kThisPropertyAssignmentsCountOffset =
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005733 kCompilerHintsOffset + kIntSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005734 static const int kOptCountOffset =
5735 kThisPropertyAssignmentsCountOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005736
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005737 static const int kCountersOffset = kOptCountOffset + kIntSize;
5738 static const int kStressDeoptCounterOffset = kCountersOffset + kIntSize;
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00005739
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005740 // Total size.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005741 static const int kSize = kStressDeoptCounterOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005742
5743#endif
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005744
5745 // The construction counter for inobject slack tracking is stored in the
5746 // most significant byte of compiler_hints which is otherwise unused.
5747 // Its offset depends on the endian-ness of the architecture.
5748#if __BYTE_ORDER == __LITTLE_ENDIAN
5749 static const int kConstructionCountOffset = kCompilerHintsOffset + 3;
5750#elif __BYTE_ORDER == __BIG_ENDIAN
5751 static const int kConstructionCountOffset = kCompilerHintsOffset + 0;
5752#else
5753#error Unknown byte ordering
5754#endif
5755
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00005756 static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005757
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00005758 typedef FixedBodyDescriptor<kNameOffset,
5759 kThisPropertyAssignmentsOffset + kPointerSize,
5760 kSize> BodyDescriptor;
5761
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005762 // Bit positions in start_position_and_type.
5763 // The source code start position is in the 30 most significant bits of
5764 // the start_position_and_type field.
5765 static const int kIsExpressionBit = 0;
5766 static const int kIsTopLevelBit = 1;
5767 static const int kStartPositionShift = 2;
5768 static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
mads.s.ager31e71382008-08-13 09:32:07 +00005769
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005770 // Bit positions in compiler_hints.
whesse@chromium.org7b260152011-06-20 15:33:18 +00005771 static const int kCodeAgeSize = 3;
5772 static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1;
whesse@chromium.org7b260152011-06-20 15:33:18 +00005773
5774 enum CompilerHints {
5775 kHasOnlySimpleThisPropertyAssignments,
5776 kAllowLazyCompilation,
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005777 kAllowLazyCompilationWithoutContext,
whesse@chromium.org7b260152011-06-20 15:33:18 +00005778 kLiveObjectsMayExist,
5779 kCodeAgeShift,
5780 kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize,
5781 kStrictModeFunction,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005782 kExtendedModeFunction,
whesse@chromium.org7b260152011-06-20 15:33:18 +00005783 kUsesArguments,
5784 kHasDuplicateParameters,
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005785 kNative,
5786 kBoundFunction,
5787 kIsAnonymous,
5788 kNameShouldPrintAsAnonymous,
yangguo@chromium.org56454712012-02-16 15:33:53 +00005789 kIsFunction,
5790 kDontOptimize,
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00005791 kDontInline,
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005792 kCompilerHintsCount // Pseudo entry
whesse@chromium.org7b260152011-06-20 15:33:18 +00005793 };
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005794
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005795 class DeoptCountBits: public BitField<int, 0, 4> {};
5796 class OptReenableTriesBits: public BitField<int, 4, 18> {};
5797 class ICAgeBits: public BitField<int, 22, 8> {};
5798
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005799 private:
5800#if V8_HOST_ARCH_32_BIT
5801 // On 32 bit platforms, compiler hints is a smi.
5802 static const int kCompilerHintsSmiTagSize = kSmiTagSize;
5803 static const int kCompilerHintsSize = kPointerSize;
5804#else
5805 // On 64 bit platforms, compiler hints is not a smi, see comment above.
5806 static const int kCompilerHintsSmiTagSize = 0;
5807 static const int kCompilerHintsSize = kIntSize;
5808#endif
5809
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005810 STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <=
5811 SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte);
5812
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005813 public:
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005814 // Constants for optimizing codegen for strict mode function and
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005815 // native tests.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005816 // Allows to use byte-width instructions.
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005817 static const int kStrictModeBitWithinByte =
5818 (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
5819
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005820 static const int kExtendedModeBitWithinByte =
5821 (kExtendedModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
5822
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005823 static const int kNativeBitWithinByte =
5824 (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte;
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005825
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005826#if __BYTE_ORDER == __LITTLE_ENDIAN
5827 static const int kStrictModeByteOffset = kCompilerHintsOffset +
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005828 (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005829 static const int kExtendedModeByteOffset = kCompilerHintsOffset +
5830 (kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005831 static const int kNativeByteOffset = kCompilerHintsOffset +
5832 (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte;
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005833#elif __BYTE_ORDER == __BIG_ENDIAN
5834 static const int kStrictModeByteOffset = kCompilerHintsOffset +
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005835 (kCompilerHintsSize - 1) -
5836 ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005837 static const int kExtendedModeByteOffset = kCompilerHintsOffset +
5838 (kCompilerHintsSize - 1) -
5839 ((kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005840 static const int kNativeByteOffset = kCompilerHintsOffset +
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005841 (kCompilerHintsSize - 1) -
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005842 ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte);
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005843#else
5844#error Unknown byte ordering
5845#endif
5846
5847 private:
mads.s.ager31e71382008-08-13 09:32:07 +00005848 DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005849};
5850
5851
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00005852// Representation for module instance objects.
5853class JSModule: public JSObject {
5854 public:
5855 // [context]: the context holding the module's locals, or undefined if none.
5856 DECL_ACCESSORS(context, Object)
5857
5858 // Casting.
5859 static inline JSModule* cast(Object* obj);
5860
5861 // Dispatched behavior.
5862#ifdef OBJECT_PRINT
5863 inline void JSModulePrint() {
5864 JSModulePrint(stdout);
5865 }
5866 void JSModulePrint(FILE* out);
5867#endif
5868#ifdef DEBUG
5869 void JSModuleVerify();
5870#endif
5871
5872 // Layout description.
5873 static const int kContextOffset = JSObject::kHeaderSize;
5874 static const int kSize = kContextOffset + kPointerSize;
5875
5876 private:
5877 DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule);
5878};
5879
5880
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005881// JSFunction describes JavaScript functions.
5882class JSFunction: public JSObject {
5883 public:
5884 // [prototype_or_initial_map]:
5885 DECL_ACCESSORS(prototype_or_initial_map, Object)
5886
lrn@chromium.org34e60782011-09-15 07:25:40 +00005887 // [shared]: The information about the function that
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005888 // can be shared by instances.
5889 DECL_ACCESSORS(shared, SharedFunctionInfo)
5890
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005891 inline SharedFunctionInfo* unchecked_shared();
5892
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005893 // [context]: The context for this function.
5894 inline Context* context();
5895 inline Object* unchecked_context();
5896 inline void set_context(Object* context);
5897
5898 // [code]: The generated code object for this function. Executed
5899 // when the function is invoked, e.g. foo() or new foo(). See
5900 // [[Call]] and [[Construct]] description in ECMA-262, section
5901 // 8.6.2, page 27.
5902 inline Code* code();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005903 inline void set_code(Code* code);
5904 inline void ReplaceCode(Code* code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005905
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005906 inline Code* unchecked_code();
5907
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00005908 // Tells whether this function is builtin.
5909 inline bool IsBuiltin();
5910
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005911 // Tells whether or not the function needs arguments adaption.
5912 inline bool NeedsArgumentsAdaption();
5913
5914 // Tells whether or not this function has been optimized.
5915 inline bool IsOptimized();
5916
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +00005917 // Tells whether or not this function can be optimized.
5918 inline bool IsOptimizable();
5919
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005920 // Mark this function for lazy recompilation. The function will be
5921 // recompiled the next time it is executed.
5922 void MarkForLazyRecompilation();
5923
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005924 // Helpers to compile this function. Returns true on success, false on
5925 // failure (e.g., stack overflow during compilation).
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005926 static bool EnsureCompiled(Handle<JSFunction> function,
5927 ClearExceptionFlag flag);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005928 static bool CompileLazy(Handle<JSFunction> function,
5929 ClearExceptionFlag flag);
5930 static bool CompileOptimized(Handle<JSFunction> function,
5931 int osr_ast_id,
5932 ClearExceptionFlag flag);
5933
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005934 // Tells whether or not the function is already marked for lazy
5935 // recompilation.
5936 inline bool IsMarkedForLazyRecompilation();
5937
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005938 // Check whether or not this function is inlineable.
5939 bool IsInlineable();
5940
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005941 // [literals_or_bindings]: Fixed array holding either
5942 // the materialized literals or the bindings of a bound function.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00005943 //
5944 // If the function contains object, regexp or array literals, the
5945 // literals array prefix contains the object, regexp, and array
5946 // function to be used when creating these literals. This is
5947 // necessary so that we do not dynamically lookup the object, regexp
5948 // or array functions. Performing a dynamic lookup, we might end up
5949 // using the functions from a new context that we should not have
5950 // access to.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005951 //
5952 // On bound functions, the array is a (copy-on-write) fixed-array containing
5953 // the function that was bound, bound this-value and any bound
5954 // arguments. Bound functions never contain literals.
5955 DECL_ACCESSORS(literals_or_bindings, FixedArray)
5956
5957 inline FixedArray* literals();
5958 inline void set_literals(FixedArray* literals);
5959
5960 inline FixedArray* function_bindings();
5961 inline void set_function_bindings(FixedArray* bindings);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005962
5963 // The initial map for an object created by this constructor.
5964 inline Map* initial_map();
5965 inline void set_initial_map(Map* value);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00005966 MUST_USE_RESULT inline MaybeObject* set_initial_map_and_cache_transitions(
5967 Map* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005968 inline bool has_initial_map();
5969
5970 // Get and set the prototype property on a JSFunction. If the
5971 // function has an initial map the prototype is set on the initial
5972 // map. Otherwise, the prototype is put in the initial map field
5973 // until an initial map is needed.
5974 inline bool has_prototype();
5975 inline bool has_instance_prototype();
5976 inline Object* prototype();
5977 inline Object* instance_prototype();
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00005978 MUST_USE_RESULT MaybeObject* SetInstancePrototype(Object* value);
lrn@chromium.org303ada72010-10-27 09:33:13 +00005979 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005980
kmillikin@chromium.org4111b802010-05-03 10:34:42 +00005981 // After prototype is removed, it will not be created when accessed, and
5982 // [[Construct]] from this function will not be allowed.
5983 Object* RemovePrototype();
5984 inline bool should_have_prototype();
5985
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005986 // Accessor for this function's initial map's [[class]]
5987 // property. This is primarily used by ECMA native functions. This
5988 // method sets the class_name field of this function's initial map
5989 // to a given value. It creates an initial map if this function does
5990 // not have one. Note that this method does not copy the initial map
5991 // if it has one already, but simply replaces it with the new value.
5992 // Instances created afterwards will have a map whose [[class]] is
5993 // set to 'value', but there is no guarantees on instances created
5994 // before.
5995 Object* SetInstanceClassName(String* name);
5996
5997 // Returns if this function has been compiled to native code yet.
5998 inline bool is_compiled();
5999
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006000 // [next_function_link]: Field for linking functions. This list is treated as
6001 // a weak list by the GC.
6002 DECL_ACCESSORS(next_function_link, Object)
6003
6004 // Prints the name of the function using PrintF.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006005 inline void PrintName() {
6006 PrintName(stdout);
6007 }
6008 void PrintName(FILE* out);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006009
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006010 // Casting.
6011 static inline JSFunction* cast(Object* obj);
6012
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00006013 // Iterates the objects, including code objects indirectly referenced
6014 // through pointers to the first instruction in the code object.
6015 void JSFunctionIterateBody(int object_size, ObjectVisitor* v);
6016
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006017 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006018#ifdef OBJECT_PRINT
6019 inline void JSFunctionPrint() {
6020 JSFunctionPrint(stdout);
6021 }
6022 void JSFunctionPrint(FILE* out);
6023#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006024#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006025 void JSFunctionVerify();
6026#endif
6027
6028 // Returns the number of allocated literals.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006029 inline int NumberOfLiterals();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006030
ager@chromium.org236ad962008-09-25 09:45:57 +00006031 // Retrieve the global context from a function's literal array.
6032 static Context* GlobalContextFromLiterals(FixedArray* literals);
6033
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006034 // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to
6035 // kSize) is weak and has special handling during garbage collection.
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00006036 static const int kCodeEntryOffset = JSObject::kHeaderSize;
vegorov@chromium.org26c16f82010-08-11 13:41:03 +00006037 static const int kPrototypeOrInitialMapOffset =
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00006038 kCodeEntryOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006039 static const int kSharedFunctionInfoOffset =
6040 kPrototypeOrInitialMapOffset + kPointerSize;
6041 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
6042 static const int kLiteralsOffset = kContextOffset + kPointerSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006043 static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize;
6044 static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset;
6045 static const int kSize = kNextFunctionLinkOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006046
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00006047 // Layout of the literals array.
ager@chromium.org236ad962008-09-25 09:45:57 +00006048 static const int kLiteralsPrefixSize = 1;
6049 static const int kLiteralGlobalContextIndex = 0;
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006050
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006051 // Layout of the bound-function binding array.
6052 static const int kBoundFunctionIndex = 0;
6053 static const int kBoundThisIndex = 1;
6054 static const int kBoundArgumentsStartIndex = 2;
6055
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006056 private:
6057 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
6058};
6059
6060
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006061// JSGlobalProxy's prototype must be a JSGlobalObject or null,
6062// and the prototype is hidden. JSGlobalProxy always delegates
6063// property accesses to its prototype if the prototype is not null.
6064//
6065// A JSGlobalProxy can be reinitialized which will preserve its identity.
6066//
6067// Accessing a JSGlobalProxy requires security check.
6068
6069class JSGlobalProxy : public JSObject {
6070 public:
ager@chromium.orgea91cc52011-05-23 06:06:11 +00006071 // [context]: the owner global context of this global proxy object.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006072 // It is null value if this object is not used by any context.
6073 DECL_ACCESSORS(context, Object)
6074
6075 // Casting.
6076 static inline JSGlobalProxy* cast(Object* obj);
6077
6078 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006079#ifdef OBJECT_PRINT
6080 inline void JSGlobalProxyPrint() {
6081 JSGlobalProxyPrint(stdout);
6082 }
6083 void JSGlobalProxyPrint(FILE* out);
6084#endif
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006085#ifdef DEBUG
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006086 void JSGlobalProxyVerify();
6087#endif
6088
6089 // Layout description.
6090 static const int kContextOffset = JSObject::kHeaderSize;
6091 static const int kSize = kContextOffset + kPointerSize;
6092
6093 private:
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006094 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
6095};
6096
6097
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006098// Forward declaration.
6099class JSBuiltinsObject;
6100
6101// Common super class for JavaScript global objects and the special
6102// builtins global objects.
6103class GlobalObject: public JSObject {
6104 public:
6105 // [builtins]: the object holding the runtime routines written in JS.
6106 DECL_ACCESSORS(builtins, JSBuiltinsObject)
6107
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +00006108 // [global context]: the global context corresponding to this global object.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006109 DECL_ACCESSORS(global_context, Context)
6110
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006111 // [global receiver]: the global receiver object of the context
6112 DECL_ACCESSORS(global_receiver, JSObject)
6113
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00006114 // Retrieve the property cell used to store a property.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006115 JSGlobalPropertyCell* GetPropertyCell(LookupResult* result);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00006116
lrn@chromium.org303ada72010-10-27 09:33:13 +00006117 // This is like GetProperty, but is used when you know the lookup won't fail
6118 // by throwing an exception. This is for the debug and builtins global
6119 // objects, where it is known which properties can be expected to be present
6120 // on the object.
6121 Object* GetPropertyNoExceptionThrown(String* key) {
6122 Object* answer = GetProperty(key)->ToObjectUnchecked();
6123 return answer;
6124 }
6125
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00006126 // Ensure that the global object has a cell for the given property name.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006127 static Handle<JSGlobalPropertyCell> EnsurePropertyCell(
6128 Handle<GlobalObject> global,
6129 Handle<String> name);
6130 // TODO(kmillikin): This function can be eliminated once the stub cache is
6131 // full handlified (and the static helper can be written directly).
lrn@chromium.org303ada72010-10-27 09:33:13 +00006132 MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00006133
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006134 // Casting.
6135 static inline GlobalObject* cast(Object* obj);
6136
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006137 // Layout description.
6138 static const int kBuiltinsOffset = JSObject::kHeaderSize;
6139 static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006140 static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize;
6141 static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006142
6143 private:
mads.s.ager31e71382008-08-13 09:32:07 +00006144 DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006145};
6146
6147
6148// JavaScript global object.
6149class JSGlobalObject: public GlobalObject {
6150 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006151 // Casting.
6152 static inline JSGlobalObject* cast(Object* obj);
6153
6154 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006155#ifdef OBJECT_PRINT
6156 inline void JSGlobalObjectPrint() {
6157 JSGlobalObjectPrint(stdout);
6158 }
6159 void JSGlobalObjectPrint(FILE* out);
6160#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006161#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006162 void JSGlobalObjectVerify();
6163#endif
6164
6165 // Layout description.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006166 static const int kSize = GlobalObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006167
6168 private:
6169 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject);
6170};
6171
6172
6173// Builtins global object which holds the runtime routines written in
6174// JavaScript.
6175class JSBuiltinsObject: public GlobalObject {
6176 public:
6177 // Accessors for the runtime routines written in JavaScript.
6178 inline Object* javascript_builtin(Builtins::JavaScript id);
6179 inline void set_javascript_builtin(Builtins::JavaScript id, Object* value);
6180
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00006181 // Accessors for code of the runtime routines written in JavaScript.
6182 inline Code* javascript_builtin_code(Builtins::JavaScript id);
6183 inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value);
6184
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006185 // Casting.
6186 static inline JSBuiltinsObject* cast(Object* obj);
6187
6188 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006189#ifdef OBJECT_PRINT
6190 inline void JSBuiltinsObjectPrint() {
6191 JSBuiltinsObjectPrint(stdout);
6192 }
6193 void JSBuiltinsObjectPrint(FILE* out);
6194#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006195#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006196 void JSBuiltinsObjectVerify();
6197#endif
6198
6199 // Layout description. The size of the builtins object includes
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00006200 // room for two pointers per runtime routine written in javascript
6201 // (function and code object).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006202 static const int kJSBuiltinsCount = Builtins::id_count;
6203 static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize;
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00006204 static const int kJSBuiltinsCodeOffset =
6205 GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006206 static const int kSize =
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00006207 kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize);
6208
6209 static int OffsetOfFunctionWithId(Builtins::JavaScript id) {
6210 return kJSBuiltinsOffset + id * kPointerSize;
6211 }
6212
6213 static int OffsetOfCodeWithId(Builtins::JavaScript id) {
6214 return kJSBuiltinsCodeOffset + id * kPointerSize;
6215 }
6216
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006217 private:
6218 DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject);
6219};
6220
6221
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +00006222// Representation for JS Wrapper objects, String, Number, Boolean, etc.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006223class JSValue: public JSObject {
6224 public:
6225 // [value]: the object being wrapped.
6226 DECL_ACCESSORS(value, Object)
6227
6228 // Casting.
6229 static inline JSValue* cast(Object* obj);
6230
6231 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006232#ifdef OBJECT_PRINT
6233 inline void JSValuePrint() {
6234 JSValuePrint(stdout);
6235 }
6236 void JSValuePrint(FILE* out);
6237#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006238#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006239 void JSValueVerify();
6240#endif
6241
6242 // Layout description.
6243 static const int kValueOffset = JSObject::kHeaderSize;
6244 static const int kSize = kValueOffset + kPointerSize;
6245
6246 private:
6247 DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue);
6248};
6249
kmillikin@chromium.org31b12772011-02-02 16:08:26 +00006250
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +00006251class DateCache;
6252
6253// Representation for JS date objects.
6254class JSDate: public JSObject {
6255 public:
6256 // If one component is NaN, all of them are, indicating a NaN time value.
6257 // [value]: the time value.
6258 DECL_ACCESSORS(value, Object)
6259 // [year]: caches year. Either undefined, smi, or NaN.
6260 DECL_ACCESSORS(year, Object)
6261 // [month]: caches month. Either undefined, smi, or NaN.
6262 DECL_ACCESSORS(month, Object)
6263 // [day]: caches day. Either undefined, smi, or NaN.
6264 DECL_ACCESSORS(day, Object)
6265 // [weekday]: caches day of week. Either undefined, smi, or NaN.
6266 DECL_ACCESSORS(weekday, Object)
6267 // [hour]: caches hours. Either undefined, smi, or NaN.
6268 DECL_ACCESSORS(hour, Object)
6269 // [min]: caches minutes. Either undefined, smi, or NaN.
6270 DECL_ACCESSORS(min, Object)
6271 // [sec]: caches seconds. Either undefined, smi, or NaN.
6272 DECL_ACCESSORS(sec, Object)
6273 // [cache stamp]: sample of the date cache stamp at the
6274 // moment when local fields were cached.
6275 DECL_ACCESSORS(cache_stamp, Object)
6276
6277 // Casting.
6278 static inline JSDate* cast(Object* obj);
6279
6280 // Returns the date field with the specified index.
6281 // See FieldIndex for the list of date fields.
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00006282 static Object* GetField(Object* date, Smi* index);
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +00006283
6284 void SetValue(Object* value, bool is_value_nan);
6285
6286
6287 // Dispatched behavior.
6288#ifdef OBJECT_PRINT
6289 inline void JSDatePrint() {
6290 JSDatePrint(stdout);
6291 }
6292 void JSDatePrint(FILE* out);
6293#endif
6294#ifdef DEBUG
6295 void JSDateVerify();
6296#endif
6297 // The order is important. It must be kept in sync with date macros
6298 // in macros.py.
6299 enum FieldIndex {
6300 kDateValue,
6301 kYear,
6302 kMonth,
6303 kDay,
6304 kWeekday,
6305 kHour,
6306 kMinute,
6307 kSecond,
6308 kFirstUncachedField,
6309 kMillisecond = kFirstUncachedField,
6310 kDays,
6311 kTimeInDay,
6312 kFirstUTCField,
6313 kYearUTC = kFirstUTCField,
6314 kMonthUTC,
6315 kDayUTC,
6316 kWeekdayUTC,
6317 kHourUTC,
6318 kMinuteUTC,
6319 kSecondUTC,
6320 kMillisecondUTC,
6321 kDaysUTC,
6322 kTimeInDayUTC,
6323 kTimezoneOffset
6324 };
6325
6326 // Layout description.
6327 static const int kValueOffset = JSObject::kHeaderSize;
6328 static const int kYearOffset = kValueOffset + kPointerSize;
6329 static const int kMonthOffset = kYearOffset + kPointerSize;
6330 static const int kDayOffset = kMonthOffset + kPointerSize;
6331 static const int kWeekdayOffset = kDayOffset + kPointerSize;
6332 static const int kHourOffset = kWeekdayOffset + kPointerSize;
6333 static const int kMinOffset = kHourOffset + kPointerSize;
6334 static const int kSecOffset = kMinOffset + kPointerSize;
6335 static const int kCacheStampOffset = kSecOffset + kPointerSize;
6336 static const int kSize = kCacheStampOffset + kPointerSize;
6337
6338 private:
6339 inline Object* DoGetField(FieldIndex index);
6340
6341 Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache);
6342
6343 // Computes and caches the cacheable fields of the date.
6344 inline void SetLocalFields(int64_t local_time_ms, DateCache* date_cache);
6345
6346
6347 DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate);
6348};
6349
6350
kmillikin@chromium.org31b12772011-02-02 16:08:26 +00006351// Representation of message objects used for error reporting through
6352// the API. The messages are formatted in JavaScript so this object is
6353// a real JavaScript object. The information used for formatting the
6354// error messages are not directly accessible from JavaScript to
6355// prevent leaking information to user code called during error
6356// formatting.
6357class JSMessageObject: public JSObject {
6358 public:
6359 // [type]: the type of error message.
6360 DECL_ACCESSORS(type, String)
6361
6362 // [arguments]: the arguments for formatting the error message.
6363 DECL_ACCESSORS(arguments, JSArray)
6364
6365 // [script]: the script from which the error message originated.
6366 DECL_ACCESSORS(script, Object)
6367
6368 // [stack_trace]: the stack trace for this error message.
6369 DECL_ACCESSORS(stack_trace, Object)
6370
6371 // [stack_frames]: an array of stack frames for this error object.
6372 DECL_ACCESSORS(stack_frames, Object)
6373
6374 // [start_position]: the start position in the script for the error message.
6375 inline int start_position();
6376 inline void set_start_position(int value);
6377
6378 // [end_position]: the end position in the script for the error message.
6379 inline int end_position();
6380 inline void set_end_position(int value);
6381
6382 // Casting.
6383 static inline JSMessageObject* cast(Object* obj);
6384
6385 // Dispatched behavior.
6386#ifdef OBJECT_PRINT
6387 inline void JSMessageObjectPrint() {
6388 JSMessageObjectPrint(stdout);
6389 }
6390 void JSMessageObjectPrint(FILE* out);
6391#endif
6392#ifdef DEBUG
6393 void JSMessageObjectVerify();
6394#endif
6395
6396 // Layout description.
6397 static const int kTypeOffset = JSObject::kHeaderSize;
6398 static const int kArgumentsOffset = kTypeOffset + kPointerSize;
6399 static const int kScriptOffset = kArgumentsOffset + kPointerSize;
6400 static const int kStackTraceOffset = kScriptOffset + kPointerSize;
6401 static const int kStackFramesOffset = kStackTraceOffset + kPointerSize;
6402 static const int kStartPositionOffset = kStackFramesOffset + kPointerSize;
6403 static const int kEndPositionOffset = kStartPositionOffset + kPointerSize;
6404 static const int kSize = kEndPositionOffset + kPointerSize;
6405
6406 typedef FixedBodyDescriptor<HeapObject::kMapOffset,
6407 kStackFramesOffset + kPointerSize,
6408 kSize> BodyDescriptor;
6409};
6410
6411
ager@chromium.org236ad962008-09-25 09:45:57 +00006412// Regular expressions
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006413// The regular expression holds a single reference to a FixedArray in
6414// the kDataOffset field.
6415// The FixedArray contains the following data:
6416// - tag : type of regexp implementation (not compiled yet, atom or irregexp)
6417// - reference to the original source string
6418// - reference to the original flag string
6419// If it is an atom regexp
6420// - a reference to a literal string to search for
6421// If it is an irregexp regexp:
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006422// - a reference to code for ASCII inputs (bytecode or compiled), or a smi
6423// used for tracking the last usage (used for code flushing).
6424// - a reference to code for UC16 inputs (bytecode or compiled), or a smi
6425// used for tracking the last usage (used for code flushing)..
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006426// - max number of registers used by irregexp implementations.
6427// - number of capture registers (output values) of the regexp.
ager@chromium.org236ad962008-09-25 09:45:57 +00006428class JSRegExp: public JSObject {
6429 public:
ager@chromium.orga74f0da2008-12-03 16:05:52 +00006430 // Meaning of Type:
6431 // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
ager@chromium.orga74f0da2008-12-03 16:05:52 +00006432 // ATOM: A simple string to match against using an indexOf operation.
6433 // IRREGEXP: Compiled with Irregexp.
6434 // IRREGEXP_NATIVE: Compiled to native code with Irregexp.
ager@chromium.org381abbb2009-02-25 13:23:22 +00006435 enum Type { NOT_COMPILED, ATOM, IRREGEXP };
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006436 enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 };
ager@chromium.org236ad962008-09-25 09:45:57 +00006437
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006438 class Flags {
6439 public:
6440 explicit Flags(uint32_t value) : value_(value) { }
6441 bool is_global() { return (value_ & GLOBAL) != 0; }
6442 bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; }
6443 bool is_multiline() { return (value_ & MULTILINE) != 0; }
6444 uint32_t value() { return value_; }
6445 private:
6446 uint32_t value_;
6447 };
ager@chromium.org236ad962008-09-25 09:45:57 +00006448
ager@chromium.org236ad962008-09-25 09:45:57 +00006449 DECL_ACCESSORS(data, Object)
6450
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006451 inline Type TypeTag();
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00006452 inline int CaptureCount();
ager@chromium.orga74f0da2008-12-03 16:05:52 +00006453 inline Flags GetFlags();
6454 inline String* Pattern();
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006455 inline Object* DataAt(int index);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006456 // Set implementation data after the object has been prepared.
6457 inline void SetDataAt(int index, Object* value);
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006458
6459 // Used during GC when flushing code or setting age.
6460 inline Object* DataAtUnchecked(int index);
6461 inline void SetDataAtUnchecked(int index, Object* value, Heap* heap);
6462 inline Type TypeTagUnchecked();
6463
kasperl@chromium.org68ac0092009-07-09 06:00:35 +00006464 static int code_index(bool is_ascii) {
6465 if (is_ascii) {
6466 return kIrregexpASCIICodeIndex;
6467 } else {
6468 return kIrregexpUC16CodeIndex;
6469 }
6470 }
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006471
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006472 static int saved_code_index(bool is_ascii) {
6473 if (is_ascii) {
6474 return kIrregexpASCIICodeSavedIndex;
6475 } else {
6476 return kIrregexpUC16CodeSavedIndex;
6477 }
6478 }
6479
ager@chromium.org236ad962008-09-25 09:45:57 +00006480 static inline JSRegExp* cast(Object* obj);
6481
6482 // Dispatched behavior.
6483#ifdef DEBUG
ager@chromium.org236ad962008-09-25 09:45:57 +00006484 void JSRegExpVerify();
6485#endif
6486
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006487 static const int kDataOffset = JSObject::kHeaderSize;
kasperl@chromium.org71affb52009-05-26 05:44:31 +00006488 static const int kSize = kDataOffset + kPointerSize;
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006489
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006490 // Indices in the data array.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006491 static const int kTagIndex = 0;
6492 static const int kSourceIndex = kTagIndex + 1;
6493 static const int kFlagsIndex = kSourceIndex + 1;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006494 static const int kDataIndex = kFlagsIndex + 1;
6495 // The data fields are used in different ways depending on the
6496 // value of the tag.
6497 // Atom regexps (literal strings).
6498 static const int kAtomPatternIndex = kDataIndex;
6499
6500 static const int kAtomDataSize = kAtomPatternIndex + 1;
6501
ager@chromium.orga1645e22009-09-09 19:27:10 +00006502 // Irregexp compiled code or bytecode for ASCII. If compilation
6503 // fails, this fields hold an exception object that should be
6504 // thrown if the regexp is used again.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006505 static const int kIrregexpASCIICodeIndex = kDataIndex;
ager@chromium.orga1645e22009-09-09 19:27:10 +00006506 // Irregexp compiled code or bytecode for UC16. If compilation
6507 // fails, this fields hold an exception object that should be
6508 // thrown if the regexp is used again.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006509 static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006510
6511 // Saved instance of Irregexp compiled code or bytecode for ASCII that
6512 // is a potential candidate for flushing.
6513 static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2;
6514 // Saved instance of Irregexp compiled code or bytecode for UC16 that is
6515 // a potential candidate for flushing.
6516 static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3;
6517
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006518 // Maximal number of registers used by either ASCII or UC16.
6519 // Only used to check that there is enough stack space
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006520 static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006521 // Number of captures in the compiled regexp.
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006522 static const int kIrregexpCaptureCountIndex = kDataIndex + 5;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006523
6524 static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00006525
6526 // Offsets directly into the data fixed array.
6527 static const int kDataTagOffset =
6528 FixedArray::kHeaderSize + kTagIndex * kPointerSize;
6529 static const int kDataAsciiCodeOffset =
6530 FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00006531 static const int kDataUC16CodeOffset =
6532 FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00006533 static const int kIrregexpCaptureCountOffset =
6534 FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
lrn@chromium.org25156de2010-04-06 13:10:27 +00006535
6536 // In-object fields.
6537 static const int kSourceFieldIndex = 0;
6538 static const int kGlobalFieldIndex = 1;
6539 static const int kIgnoreCaseFieldIndex = 2;
6540 static const int kMultilineFieldIndex = 3;
6541 static const int kLastIndexFieldIndex = 4;
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +00006542 static const int kInObjectFieldCount = 5;
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006543
6544 // The uninitialized value for a regexp code object.
6545 static const int kUninitializedValue = -1;
6546
6547 // The compilation error value for the regexp code object. The real error
6548 // object is in the saved code field.
6549 static const int kCompilationErrorValue = -2;
6550
6551 // When we store the sweep generation at which we moved the code from the
6552 // code index to the saved code index we mask it of to be in the [0:255]
6553 // range.
6554 static const int kCodeAgeMask = 0xff;
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006555};
6556
6557
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00006558class CompilationCacheShape : public BaseShape<HashTableKey*> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00006559 public:
6560 static inline bool IsMatch(HashTableKey* key, Object* value) {
6561 return key->IsMatch(value);
6562 }
6563
6564 static inline uint32_t Hash(HashTableKey* key) {
6565 return key->Hash();
6566 }
6567
6568 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
6569 return key->HashForObject(object);
6570 }
6571
lrn@chromium.org303ada72010-10-27 09:33:13 +00006572 MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00006573 return key->AsObject();
6574 }
6575
6576 static const int kPrefixSize = 0;
6577 static const int kEntrySize = 2;
6578};
6579
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00006580
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00006581class CompilationCacheTable: public HashTable<CompilationCacheShape,
6582 HashTableKey*> {
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006583 public:
6584 // Find cached value for a string key, otherwise return null.
6585 Object* Lookup(String* src);
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00006586 Object* LookupEval(String* src,
6587 Context* context,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00006588 LanguageMode language_mode,
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00006589 int scope_position);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006590 Object* LookupRegExp(String* source, JSRegExp::Flags flags);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00006591 MUST_USE_RESULT MaybeObject* Put(String* src, Object* value);
6592 MUST_USE_RESULT MaybeObject* PutEval(String* src,
6593 Context* context,
6594 SharedFunctionInfo* value,
6595 int scope_position);
6596 MUST_USE_RESULT MaybeObject* PutRegExp(String* src,
6597 JSRegExp::Flags flags,
6598 FixedArray* value);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006599
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006600 // Remove given value from cache.
6601 void Remove(Object* value);
6602
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006603 static inline CompilationCacheTable* cast(Object* obj);
6604
6605 private:
6606 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable);
ager@chromium.org236ad962008-09-25 09:45:57 +00006607};
6608
6609
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006610class CodeCache: public Struct {
6611 public:
6612 DECL_ACCESSORS(default_cache, FixedArray)
6613 DECL_ACCESSORS(normal_type_cache, Object)
6614
6615 // Add the code object to the cache.
lrn@chromium.org303ada72010-10-27 09:33:13 +00006616 MUST_USE_RESULT MaybeObject* Update(String* name, Code* code);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006617
6618 // Lookup code object in the cache. Returns code object if found and undefined
6619 // if not.
6620 Object* Lookup(String* name, Code::Flags flags);
6621
6622 // Get the internal index of a code object in the cache. Returns -1 if the
6623 // code object is not in that cache. This index can be used to later call
6624 // RemoveByIndex. The cache cannot be modified between a call to GetIndex and
6625 // RemoveByIndex.
sgjesse@chromium.org99a37fa2010-03-11 09:23:46 +00006626 int GetIndex(Object* name, Code* code);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006627
6628 // Remove an object from the cache with the provided internal index.
sgjesse@chromium.org99a37fa2010-03-11 09:23:46 +00006629 void RemoveByIndex(Object* name, Code* code, int index);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006630
6631 static inline CodeCache* cast(Object* obj);
6632
whesse@chromium.org023421e2010-12-21 12:19:12 +00006633#ifdef OBJECT_PRINT
6634 inline void CodeCachePrint() {
6635 CodeCachePrint(stdout);
6636 }
6637 void CodeCachePrint(FILE* out);
6638#endif
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006639#ifdef DEBUG
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006640 void CodeCacheVerify();
6641#endif
6642
6643 static const int kDefaultCacheOffset = HeapObject::kHeaderSize;
6644 static const int kNormalTypeCacheOffset =
6645 kDefaultCacheOffset + kPointerSize;
6646 static const int kSize = kNormalTypeCacheOffset + kPointerSize;
6647
6648 private:
lrn@chromium.org303ada72010-10-27 09:33:13 +00006649 MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code);
6650 MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006651 Object* LookupDefaultCache(String* name, Code::Flags flags);
6652 Object* LookupNormalTypeCache(String* name, Code::Flags flags);
6653
6654 // Code cache layout of the default cache. Elements are alternating name and
6655 // code objects for non normal load/store/call IC's.
6656 static const int kCodeCacheEntrySize = 2;
6657 static const int kCodeCacheEntryNameOffset = 0;
6658 static const int kCodeCacheEntryCodeOffset = 1;
6659
6660 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache);
6661};
6662
6663
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00006664class CodeCacheHashTableShape : public BaseShape<HashTableKey*> {
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006665 public:
6666 static inline bool IsMatch(HashTableKey* key, Object* value) {
6667 return key->IsMatch(value);
6668 }
6669
6670 static inline uint32_t Hash(HashTableKey* key) {
6671 return key->Hash();
6672 }
6673
6674 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
6675 return key->HashForObject(object);
6676 }
6677
lrn@chromium.org303ada72010-10-27 09:33:13 +00006678 MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006679 return key->AsObject();
6680 }
6681
6682 static const int kPrefixSize = 0;
6683 static const int kEntrySize = 2;
6684};
6685
6686
6687class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape,
6688 HashTableKey*> {
6689 public:
6690 Object* Lookup(String* name, Code::Flags flags);
lrn@chromium.org303ada72010-10-27 09:33:13 +00006691 MUST_USE_RESULT MaybeObject* Put(String* name, Code* code);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006692
6693 int GetIndex(String* name, Code::Flags flags);
6694 void RemoveByIndex(int index);
6695
6696 static inline CodeCacheHashTable* cast(Object* obj);
6697
6698 // Initial size of the fixed array backing the hash table.
6699 static const int kInitialSize = 64;
6700
6701 private:
6702 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable);
6703};
6704
6705
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006706class PolymorphicCodeCache: public Struct {
6707 public:
6708 DECL_ACCESSORS(cache, Object)
6709
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006710 static void Update(Handle<PolymorphicCodeCache> cache,
6711 MapHandleList* maps,
6712 Code::Flags flags,
6713 Handle<Code> code);
6714
6715 MUST_USE_RESULT MaybeObject* Update(MapHandleList* maps,
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006716 Code::Flags flags,
6717 Code* code);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006718
6719 // Returns an undefined value if the entry is not found.
6720 Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags);
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006721
6722 static inline PolymorphicCodeCache* cast(Object* obj);
6723
6724#ifdef OBJECT_PRINT
6725 inline void PolymorphicCodeCachePrint() {
6726 PolymorphicCodeCachePrint(stdout);
6727 }
6728 void PolymorphicCodeCachePrint(FILE* out);
6729#endif
6730#ifdef DEBUG
6731 void PolymorphicCodeCacheVerify();
6732#endif
6733
6734 static const int kCacheOffset = HeapObject::kHeaderSize;
6735 static const int kSize = kCacheOffset + kPointerSize;
6736
6737 private:
6738 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache);
6739};
6740
6741
6742class PolymorphicCodeCacheHashTable
6743 : public HashTable<CodeCacheHashTableShape, HashTableKey*> {
6744 public:
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006745 Object* Lookup(MapHandleList* maps, int code_kind);
6746
6747 MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps,
6748 int code_kind,
6749 Code* code);
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006750
6751 static inline PolymorphicCodeCacheHashTable* cast(Object* obj);
6752
6753 static const int kInitialSize = 64;
6754 private:
6755 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable);
6756};
6757
6758
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00006759class TypeFeedbackInfo: public Struct {
6760 public:
6761 inline int ic_total_count();
6762 inline void set_ic_total_count(int count);
6763
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00006764 inline int ic_with_type_info_count();
6765 inline void set_ic_with_type_info_count(int count);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00006766
6767 DECL_ACCESSORS(type_feedback_cells, TypeFeedbackCells)
6768
6769 static inline TypeFeedbackInfo* cast(Object* obj);
6770
6771#ifdef OBJECT_PRINT
6772 inline void TypeFeedbackInfoPrint() {
6773 TypeFeedbackInfoPrint(stdout);
6774 }
6775 void TypeFeedbackInfoPrint(FILE* out);
6776#endif
6777#ifdef DEBUG
6778 void TypeFeedbackInfoVerify();
6779#endif
6780
6781 static const int kIcTotalCountOffset = HeapObject::kHeaderSize;
6782 static const int kIcWithTypeinfoCountOffset =
6783 kIcTotalCountOffset + kPointerSize;
6784 static const int kTypeFeedbackCellsOffset =
6785 kIcWithTypeinfoCountOffset + kPointerSize;
6786 static const int kSize = kTypeFeedbackCellsOffset + kPointerSize;
6787
6788 private:
6789 DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo);
6790};
6791
6792
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00006793// Representation of a slow alias as part of a non-strict arguments objects.
6794// For fast aliases (if HasNonStrictArgumentsElements()):
6795// - the parameter map contains an index into the context
6796// - all attributes of the element have default values
6797// For slow aliases (if HasDictionaryArgumentsElements()):
6798// - the parameter map contains no fast alias mapping (i.e. the hole)
6799// - this struct (in the slow backing store) contains an index into the context
6800// - all attributes are available as part if the property details
6801class AliasedArgumentsEntry: public Struct {
6802 public:
6803 inline int aliased_context_slot();
6804 inline void set_aliased_context_slot(int count);
6805
6806 static inline AliasedArgumentsEntry* cast(Object* obj);
6807
6808#ifdef OBJECT_PRINT
6809 inline void AliasedArgumentsEntryPrint() {
6810 AliasedArgumentsEntryPrint(stdout);
6811 }
6812 void AliasedArgumentsEntryPrint(FILE* out);
6813#endif
6814#ifdef DEBUG
6815 void AliasedArgumentsEntryVerify();
6816#endif
6817
6818 static const int kAliasedContextSlot = HeapObject::kHeaderSize;
6819 static const int kSize = kAliasedContextSlot + kPointerSize;
6820
6821 private:
6822 DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry);
6823};
6824
6825
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006826enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS};
6827enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL};
6828
6829
ager@chromium.org7c537e22008-10-16 08:43:32 +00006830class StringHasher {
6831 public:
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00006832 explicit inline StringHasher(int length, uint32_t seed);
ager@chromium.org7c537e22008-10-16 08:43:32 +00006833
6834 // Returns true if the hash of this string can be computed without
6835 // looking at the contents.
6836 inline bool has_trivial_hash();
6837
6838 // Add a character to the hash and update the array index calculation.
yangguo@chromium.org154ff992012-03-13 08:09:54 +00006839 inline void AddCharacter(uint32_t c);
ager@chromium.org7c537e22008-10-16 08:43:32 +00006840
6841 // Adds a character to the hash but does not update the array index
6842 // calculation. This can only be called when it has been verified
6843 // that the input is not an array index.
yangguo@chromium.org154ff992012-03-13 08:09:54 +00006844 inline void AddCharacterNoIndex(uint32_t c);
6845
6846 // Add a character above 0xffff as a surrogate pair. These can get into
6847 // the hasher through the routines that take a UTF-8 string and make a symbol.
6848 void AddSurrogatePair(uc32 c);
6849 void AddSurrogatePairNoIndex(uc32 c);
ager@chromium.org7c537e22008-10-16 08:43:32 +00006850
6851 // Returns the value to store in the hash field of a string with
6852 // the given length and contents.
6853 uint32_t GetHashField();
6854
6855 // Returns true if the characters seen so far make up a legal array
6856 // index.
6857 bool is_array_index() { return is_array_index_; }
6858
6859 bool is_valid() { return is_valid_; }
6860
6861 void invalidate() { is_valid_ = false; }
6862
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00006863 // Calculated hash value for a string consisting of 1 to
6864 // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
6865 // value is represented decimal value.
ager@chromium.org5b2fbee2010-09-08 06:38:15 +00006866 static uint32_t MakeArrayIndexHash(uint32_t value, int length);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00006867
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00006868 // No string is allowed to have a hash of zero. That value is reserved
6869 // for internal properties. If the hash calculation yields zero then we
6870 // use 27 instead.
6871 static const int kZeroHash = 27;
6872
ager@chromium.org7c537e22008-10-16 08:43:32 +00006873 private:
ager@chromium.org7c537e22008-10-16 08:43:32 +00006874 uint32_t array_index() {
6875 ASSERT(is_array_index());
6876 return array_index_;
6877 }
6878
6879 inline uint32_t GetHash();
6880
6881 int length_;
6882 uint32_t raw_running_hash_;
6883 uint32_t array_index_;
6884 bool is_array_index_;
6885 bool is_first_char_;
6886 bool is_valid_;
ager@chromium.org6141cbe2009-11-20 12:14:52 +00006887 friend class TwoCharHashTableKey;
ager@chromium.org7c537e22008-10-16 08:43:32 +00006888};
6889
6890
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00006891// Calculates string hash.
6892template <typename schar>
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00006893inline uint32_t HashSequentialString(const schar* chars,
6894 int length,
6895 uint32_t seed);
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00006896
6897
ager@chromium.org870a0b62008-11-04 11:43:05 +00006898// The characteristics of a string are stored in its map. Retrieving these
6899// few bits of information is moderately expensive, involving two memory
6900// loads where the second is dependent on the first. To improve efficiency
6901// the shape of the string is given its own class so that it can be retrieved
6902// once and used for several string operations. A StringShape is small enough
6903// to be passed by value and is immutable, but be aware that flattening a
ager@chromium.orgc3e50d82008-11-05 11:53:10 +00006904// string can potentially alter its shape. Also be aware that a GC caused by
6905// something else can alter the shape of a string due to ConsString
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00006906// shortcutting. Keeping these restrictions in mind has proven to be error-
6907// prone and so we no longer put StringShapes in variables unless there is a
6908// concrete performance benefit at that particular point in the code.
ager@chromium.org870a0b62008-11-04 11:43:05 +00006909class StringShape BASE_EMBEDDED {
6910 public:
6911 inline explicit StringShape(String* s);
6912 inline explicit StringShape(Map* s);
6913 inline explicit StringShape(InstanceType t);
ager@chromium.org870a0b62008-11-04 11:43:05 +00006914 inline bool IsSequential();
6915 inline bool IsExternal();
6916 inline bool IsCons();
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00006917 inline bool IsSliced();
6918 inline bool IsIndirect();
ager@chromium.org870a0b62008-11-04 11:43:05 +00006919 inline bool IsExternalAscii();
6920 inline bool IsExternalTwoByte();
6921 inline bool IsSequentialAscii();
6922 inline bool IsSequentialTwoByte();
6923 inline bool IsSymbol();
6924 inline StringRepresentationTag representation_tag();
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00006925 inline uint32_t encoding_tag();
ager@chromium.org870a0b62008-11-04 11:43:05 +00006926 inline uint32_t full_representation_tag();
6927 inline uint32_t size_tag();
6928#ifdef DEBUG
6929 inline uint32_t type() { return type_; }
6930 inline void invalidate() { valid_ = false; }
6931 inline bool valid() { return valid_; }
6932#else
6933 inline void invalidate() { }
6934#endif
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006935
ager@chromium.org870a0b62008-11-04 11:43:05 +00006936 private:
6937 uint32_t type_;
6938#ifdef DEBUG
6939 inline void set_valid() { valid_ = true; }
6940 bool valid_;
6941#else
6942 inline void set_valid() { }
6943#endif
6944};
6945
6946
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006947// The String abstract class captures JavaScript string values:
6948//
6949// Ecma-262:
6950// 4.3.16 String Value
6951// A string value is a member of the type String and is a finite
6952// ordered sequence of zero or more 16-bit unsigned integer values.
6953//
6954// All string values have a length field.
6955class String: public HeapObject {
6956 public:
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00006957 // Representation of the flat content of a String.
6958 // A non-flat string doesn't have flat content.
6959 // A flat string has content that's encoded as a sequence of either
6960 // ASCII chars or two-byte UC16.
6961 // Returned by String::GetFlatContent().
6962 class FlatContent {
6963 public:
6964 // Returns true if the string is flat and this structure contains content.
6965 bool IsFlat() { return state_ != NON_FLAT; }
6966 // Returns true if the structure contains ASCII content.
6967 bool IsAscii() { return state_ == ASCII; }
6968 // Returns true if the structure contains two-byte content.
6969 bool IsTwoByte() { return state_ == TWO_BYTE; }
6970
6971 // Return the ASCII content of the string. Only use if IsAscii() returns
6972 // true.
6973 Vector<const char> ToAsciiVector() {
6974 ASSERT_EQ(ASCII, state_);
6975 return Vector<const char>::cast(buffer_);
6976 }
6977 // Return the two-byte content of the string. Only use if IsTwoByte()
6978 // returns true.
6979 Vector<const uc16> ToUC16Vector() {
6980 ASSERT_EQ(TWO_BYTE, state_);
6981 return Vector<const uc16>::cast(buffer_);
6982 }
6983
6984 private:
6985 enum State { NON_FLAT, ASCII, TWO_BYTE };
6986
6987 // Constructors only used by String::GetFlatContent().
6988 explicit FlatContent(Vector<const char> chars)
6989 : buffer_(Vector<const byte>::cast(chars)),
6990 state_(ASCII) { }
6991 explicit FlatContent(Vector<const uc16> chars)
6992 : buffer_(Vector<const byte>::cast(chars)),
6993 state_(TWO_BYTE) { }
6994 FlatContent() : buffer_(), state_(NON_FLAT) { }
6995
6996 Vector<const byte> buffer_;
6997 State state_;
6998
6999 friend class String;
7000 };
7001
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007002 // Get and set the length of the string.
7003 inline int length();
7004 inline void set_length(int value);
7005
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007006 // Get and set the hash field of the string.
7007 inline uint32_t hash_field();
7008 inline void set_hash_field(uint32_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007009
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00007010 // Returns whether this string has only ASCII chars, i.e. all of them can
7011 // be ASCII encoded. This might be the case even if the string is
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +00007012 // two-byte. Such strings may appear when the embedder prefers
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00007013 // two-byte external representations even for ASCII data.
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007014 inline bool IsAsciiRepresentation();
7015 inline bool IsTwoByteRepresentation();
7016
7017 // Cons and slices have an encoding flag that may not represent the actual
7018 // encoding of the underlying string. This is taken into account here.
7019 // Requires: this->IsFlat()
7020 inline bool IsAsciiRepresentationUnderneath();
7021 inline bool IsTwoByteRepresentationUnderneath();
7022
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +00007023 // NOTE: this should be considered only a hint. False negatives are
7024 // possible.
7025 inline bool HasOnlyAsciiChars();
ricow@chromium.orgaa1b6162010-03-29 07:44:58 +00007026
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007027 // Get and set individual two byte chars in the string.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007028 inline void Set(int index, uint16_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007029 // Get individual two byte char in the string. Repeated calls
7030 // to this method are not efficient unless the string is flat.
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00007031 INLINE(uint16_t Get(int index));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007032
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00007033 // Try to flatten the string. Checks first inline to see if it is
7034 // necessary. Does nothing if the string is not a cons string.
7035 // Flattening allocates a sequential string with the same data as
7036 // the given string and mutates the cons string to a degenerate
7037 // form, where the first component is the new sequential string and
7038 // the second component is the empty string. If allocation fails,
7039 // this function returns a failure. If flattening succeeds, this
7040 // function returns the sequential string that is now the first
7041 // component of the cons string.
7042 //
7043 // Degenerate cons strings are handled specially by the garbage
7044 // collector (see IsShortcutCandidate).
7045 //
7046 // Use FlattenString from Handles.cc to flatten even in case an
7047 // allocation failure happens.
lrn@chromium.org303ada72010-10-27 09:33:13 +00007048 inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007049
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00007050 // Convenience function. Has exactly the same behavior as
7051 // TryFlatten(), except in the case of failure returns the original
7052 // string.
7053 inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED);
7054
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00007055 // Tries to return the content of a flat string as a structure holding either
7056 // a flat vector of char or of uc16.
7057 // If the string isn't flat, and therefore doesn't have flat content, the
7058 // returned structure will report so, and can't provide a vector of either
7059 // kind.
7060 FlatContent GetFlatContent();
ager@chromium.org7c537e22008-10-16 08:43:32 +00007061
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007062 // Returns the parent of a sliced string or first part of a flat cons string.
7063 // Requires: StringShape(this).IsIndirect() && this->IsFlat()
7064 inline String* GetUnderlying();
7065
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007066 // Mark the string as an undetectable object. It only applies to
ulan@chromium.org2efb9002012-01-19 15:36:35 +00007067 // ASCII and two byte string types.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007068 bool MarkAsUndetectable();
7069
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007070 // Return a substring.
lrn@chromium.org303ada72010-10-27 09:33:13 +00007071 MUST_USE_RESULT MaybeObject* SubString(int from,
7072 int to,
7073 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007074
7075 // String equality operations.
7076 inline bool Equals(String* other);
7077 bool IsEqualTo(Vector<const char> str);
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00007078 bool IsAsciiEqualTo(Vector<const char> str);
7079 bool IsTwoByteEqualTo(Vector<const uc16> str);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007080
7081 // Return a UTF8 representation of the string. The string is null
7082 // terminated but may optionally contain nulls. Length is returned
7083 // in length_output if length_output is not a null pointer The string
7084 // should be nearly flat, otherwise the performance of this method may
7085 // be very slow (quadratic in the length). Setting robustness_flag to
7086 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
7087 // handles unexpected data without causing assert failures and it does not
7088 // do any heap allocations. This is useful when printing stack traces.
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00007089 SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls,
7090 RobustnessFlag robustness_flag,
7091 int offset,
7092 int length,
7093 int* length_output = 0);
7094 SmartArrayPointer<char> ToCString(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007095 AllowNullsFlag allow_nulls = DISALLOW_NULLS,
7096 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL,
7097 int* length_output = 0);
7098
7099 // Return a 16 bit Unicode representation of the string.
7100 // The string should be nearly flat, otherwise the performance of
7101 // of this method may be very bad. Setting robustness_flag to
7102 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
7103 // handles unexpected data without causing assert failures and it does not
7104 // do any heap allocations. This is useful when printing stack traces.
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00007105 SmartArrayPointer<uc16> ToWideCString(
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00007106 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007107
7108 // Tells whether the hash code has been computed.
7109 inline bool HasHashCode();
7110
7111 // Returns a hash value used for the property table
7112 inline uint32_t Hash();
7113
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007114 static uint32_t ComputeHashField(unibrow::CharacterStream* buffer,
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00007115 int length,
7116 uint32_t seed);
ager@chromium.org7c537e22008-10-16 08:43:32 +00007117
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007118 static bool ComputeArrayIndex(unibrow::CharacterStream* buffer,
7119 uint32_t* index,
7120 int length);
7121
ager@chromium.org6f10e412009-02-13 10:11:16 +00007122 // Externalization.
7123 bool MakeExternal(v8::String::ExternalStringResource* resource);
7124 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource);
7125
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007126 // Conversion.
7127 inline bool AsArrayIndex(uint32_t* index);
7128
7129 // Casting.
7130 static inline String* cast(Object* obj);
7131
7132 void PrintOn(FILE* out);
7133
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007134 // For use during stack traces. Performs rudimentary sanity check.
7135 bool LooksValid();
7136
7137 // Dispatched behavior.
7138 void StringShortPrint(StringStream* accumulator);
whesse@chromium.org023421e2010-12-21 12:19:12 +00007139#ifdef OBJECT_PRINT
7140 inline void StringPrint() {
7141 StringPrint(stdout);
7142 }
7143 void StringPrint(FILE* out);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00007144
7145 char* ToAsciiArray();
whesse@chromium.org023421e2010-12-21 12:19:12 +00007146#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007147#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007148 void StringVerify();
7149#endif
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007150 inline bool IsFlat();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007151
7152 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00007153 static const int kLengthOffset = HeapObject::kHeaderSize;
ager@chromium.orgac091b72010-05-05 07:34:42 +00007154 static const int kHashFieldOffset = kLengthOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007155 static const int kSize = kHashFieldOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007156
ager@chromium.org3811b432009-10-28 14:53:37 +00007157 // Maximum number of characters to consider when trying to convert a string
7158 // value into an array index.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007159 static const int kMaxArrayIndexSize = 10;
7160
ulan@chromium.org2efb9002012-01-19 15:36:35 +00007161 // Max ASCII char code.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007162 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar;
ager@chromium.org381abbb2009-02-25 13:23:22 +00007163 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar;
yangguo@chromium.org154ff992012-03-13 08:09:54 +00007164 static const int kMaxUtf16CodeUnit = 0xffff;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007165
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007166 // Mask constant for checking if a string has a computed hash code
7167 // and if it is an array index. The least significant bit indicates
7168 // whether a hash code has been computed. If the hash code has been
7169 // computed the 2nd bit tells whether the string can be used as an
7170 // array index.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007171 static const int kHashNotComputedMask = 1;
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007172 static const int kIsNotArrayIndexMask = 1 << 1;
7173 static const int kNofHashBitFields = 2;
ager@chromium.org7c537e22008-10-16 08:43:32 +00007174
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007175 // Shift constant retrieving hash code from hash field.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007176 static const int kHashShift = kNofHashBitFields;
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007177
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00007178 // Only these bits are relevant in the hash, since the top two are shifted
7179 // out.
7180 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift;
7181
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007182 // Array index strings this short can keep their index in the hash
7183 // field.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00007184 static const int kMaxCachedArrayIndexLength = 7;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007185
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007186 // For strings which are array indexes the hash value has the string length
7187 // mixed into the hash, mainly to avoid a hash value of zero which would be
7188 // the case for the string '0'. 24 bits are used for the array index value.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007189 static const int kArrayIndexValueBits = 24;
7190 static const int kArrayIndexLengthBits =
7191 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
7192
7193 STATIC_CHECK((kArrayIndexLengthBits > 0));
ager@chromium.org5b2fbee2010-09-08 06:38:15 +00007194 STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007195
7196 static const int kArrayIndexHashLengthShift =
7197 kArrayIndexValueBits + kNofHashBitFields;
7198
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007199 static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1;
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007200
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007201 static const int kArrayIndexValueMask =
7202 ((1 << kArrayIndexValueBits) - 1) << kHashShift;
ager@chromium.org3811b432009-10-28 14:53:37 +00007203
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007204 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
7205 // could use a mask to test if the length of string is less than or equal to
7206 // kMaxCachedArrayIndexLength.
7207 STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
7208
7209 static const int kContainsCachedArrayIndexMask =
7210 (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) |
7211 kIsNotArrayIndexMask;
7212
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007213 // Value of empty hash field indicating that the hash is not computed.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007214 static const int kEmptyHashField =
7215 kIsNotArrayIndexMask | kHashNotComputedMask;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007216
7217 // Value of hash field containing computed hash equal to zero.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007218 static const int kZeroHash = kIsNotArrayIndexMask;
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007219
7220 // Maximal string length.
7221 static const int kMaxLength = (1 << (32 - 2)) - 1;
7222
7223 // Max length for computing hash. For strings longer than this limit the
7224 // string length is used as the hash value.
7225 static const int kMaxHashCalcLength = 16383;
ager@chromium.org7c537e22008-10-16 08:43:32 +00007226
kasper.lund7276f142008-07-30 08:49:36 +00007227 // Limit for truncation in short printing.
7228 static const int kMaxShortPrintLength = 1024;
7229
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007230 // Support for regular expressions.
7231 const uc16* GetTwoByteData();
7232 const uc16* GetTwoByteData(unsigned start);
7233
7234 // Support for StringInputBuffer
7235 static const unibrow::byte* ReadBlock(String* input,
7236 unibrow::byte* util_buffer,
7237 unsigned capacity,
7238 unsigned* remaining,
7239 unsigned* offset);
7240 static const unibrow::byte* ReadBlock(String** input,
7241 unibrow::byte* util_buffer,
7242 unsigned capacity,
7243 unsigned* remaining,
7244 unsigned* offset);
7245
7246 // Helper function for flattening strings.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007247 template <typename sinkchar>
7248 static void WriteToFlat(String* source,
7249 sinkchar* sink,
7250 int from,
7251 int to);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007252
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00007253 static inline bool IsAscii(const char* chars, int length) {
7254 const char* limit = chars + length;
7255#ifdef V8_HOST_CAN_READ_UNALIGNED
7256 ASSERT(kMaxAsciiCharCode == 0x7F);
7257 const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80;
7258 while (chars <= limit - sizeof(uintptr_t)) {
7259 if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
7260 return false;
7261 }
7262 chars += sizeof(uintptr_t);
7263 }
7264#endif
7265 while (chars < limit) {
7266 if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false;
7267 ++chars;
7268 }
7269 return true;
7270 }
7271
7272 static inline bool IsAscii(const uc16* chars, int length) {
7273 const uc16* limit = chars + length;
7274 while (chars < limit) {
7275 if (*chars > kMaxAsciiCharCodeU) return false;
7276 ++chars;
7277 }
7278 return true;
7279 }
7280
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007281 protected:
7282 class ReadBlockBuffer {
7283 public:
7284 ReadBlockBuffer(unibrow::byte* util_buffer_,
7285 unsigned cursor_,
7286 unsigned capacity_,
7287 unsigned remaining_) :
7288 util_buffer(util_buffer_),
7289 cursor(cursor_),
7290 capacity(capacity_),
7291 remaining(remaining_) {
7292 }
7293 unibrow::byte* util_buffer;
7294 unsigned cursor;
7295 unsigned capacity;
7296 unsigned remaining;
7297 };
7298
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007299 static inline const unibrow::byte* ReadBlock(String* input,
7300 ReadBlockBuffer* buffer,
7301 unsigned* offset,
7302 unsigned max_chars);
7303 static void ReadBlockIntoBuffer(String* input,
7304 ReadBlockBuffer* buffer,
7305 unsigned* offset_ptr,
7306 unsigned max_chars);
7307
7308 private:
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00007309 // Try to flatten the top level ConsString that is hiding behind this
7310 // string. This is a no-op unless the string is a ConsString. Flatten
7311 // mutates the ConsString and might return a failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +00007312 MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00007313
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007314 static inline bool IsHashFieldComputed(uint32_t field);
7315
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007316 // Slow case of String::Equals. This implementation works on any strings
7317 // but it is most efficient on strings that are almost flat.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007318 bool SlowEquals(String* other);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007319
7320 // Slow case of AsArrayIndex.
7321 bool SlowAsArrayIndex(uint32_t* index);
7322
7323 // Compute and set the hash code.
7324 uint32_t ComputeAndSetHash();
7325
7326 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
7327};
7328
7329
7330// The SeqString abstract class captures sequential string values.
7331class SeqString: public String {
7332 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007333 // Casting.
7334 static inline SeqString* cast(Object* obj);
7335
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007336 // Layout description.
7337 static const int kHeaderSize = String::kSize;
7338
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007339 private:
7340 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
7341};
7342
7343
ulan@chromium.org2efb9002012-01-19 15:36:35 +00007344// The AsciiString class captures sequential ASCII string objects.
7345// Each character in the AsciiString is an ASCII character.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007346class SeqAsciiString: public SeqString {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007347 public:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00007348 static const bool kHasAsciiEncoding = true;
7349
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007350 // Dispatched behavior.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007351 inline uint16_t SeqAsciiStringGet(int index);
7352 inline void SeqAsciiStringSet(int index, uint16_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007353
7354 // Get the address of the characters in this string.
7355 inline Address GetCharsAddress();
7356
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007357 inline char* GetChars();
7358
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007359 // Casting
ager@chromium.org7c537e22008-10-16 08:43:32 +00007360 static inline SeqAsciiString* cast(Object* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007361
7362 // Garbage collection support. This method is called by the
7363 // garbage collector to compute the actual size of an AsciiString
7364 // instance.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007365 inline int SeqAsciiStringSize(InstanceType instance_type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007366
7367 // Computes the size for an AsciiString instance of a given length.
7368 static int SizeFor(int length) {
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007369 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007370 }
7371
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00007372 // Maximal memory usage for a single sequential ASCII string.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007373 static const int kMaxSize = 512 * MB - 1;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00007374 // Maximal length of a single sequential ASCII string.
7375 // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7376 static const int kMaxLength = (kMaxSize - kHeaderSize);
7377
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007378 // Support for StringInputBuffer.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007379 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7380 unsigned* offset,
7381 unsigned chars);
7382 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining,
7383 unsigned* offset,
7384 unsigned chars);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007385
mstarzinger@chromium.org15613d02012-05-23 12:04:37 +00007386#ifdef DEBUG
7387 void SeqAsciiStringVerify();
7388#endif
7389
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007390 private:
ager@chromium.org7c537e22008-10-16 08:43:32 +00007391 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007392};
7393
7394
7395// The TwoByteString class captures sequential unicode string objects.
7396// Each character in the TwoByteString is a two-byte uint16_t.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007397class SeqTwoByteString: public SeqString {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007398 public:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00007399 static const bool kHasAsciiEncoding = false;
7400
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007401 // Dispatched behavior.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007402 inline uint16_t SeqTwoByteStringGet(int index);
7403 inline void SeqTwoByteStringSet(int index, uint16_t value);
7404
7405 // Get the address of the characters in this string.
7406 inline Address GetCharsAddress();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007407
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007408 inline uc16* GetChars();
7409
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007410 // For regexp code.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007411 const uint16_t* SeqTwoByteStringGetData(unsigned start);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007412
7413 // Casting
ager@chromium.org7c537e22008-10-16 08:43:32 +00007414 static inline SeqTwoByteString* cast(Object* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007415
7416 // Garbage collection support. This method is called by the
7417 // garbage collector to compute the actual size of a TwoByteString
7418 // instance.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007419 inline int SeqTwoByteStringSize(InstanceType instance_type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007420
7421 // Computes the size for a TwoByteString instance of a given length.
7422 static int SizeFor(int length) {
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007423 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007424 }
7425
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00007426 // Maximal memory usage for a single sequential two-byte string.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007427 static const int kMaxSize = 512 * MB - 1;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00007428 // Maximal length of a single sequential two-byte string.
7429 // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7430 static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t);
7431
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007432 // Support for StringInputBuffer.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007433 inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7434 unsigned* offset_ptr,
7435 unsigned chars);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007436
7437 private:
ager@chromium.org7c537e22008-10-16 08:43:32 +00007438 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007439};
7440
7441
7442// The ConsString class describes string values built by using the
7443// addition operator on strings. A ConsString is a pair where the
7444// first and second components are pointers to other string values.
7445// One or both components of a ConsString can be pointers to other
7446// ConsStrings, creating a binary tree of ConsStrings where the leaves
7447// are non-ConsString string values. The string value represented by
7448// a ConsString can be obtained by concatenating the leaf string
7449// values in a left-to-right depth-first traversal of the tree.
7450class ConsString: public String {
7451 public:
ager@chromium.org870a0b62008-11-04 11:43:05 +00007452 // First string of the cons cell.
7453 inline String* first();
7454 // Doesn't check that the result is a string, even in debug mode. This is
7455 // useful during GC where the mark bits confuse the checks.
7456 inline Object* unchecked_first();
7457 inline void set_first(String* first,
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00007458 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007459
ager@chromium.org870a0b62008-11-04 11:43:05 +00007460 // Second string of the cons cell.
7461 inline String* second();
7462 // Doesn't check that the result is a string, even in debug mode. This is
7463 // useful during GC where the mark bits confuse the checks.
7464 inline Object* unchecked_second();
7465 inline void set_second(String* second,
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00007466 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007467
7468 // Dispatched behavior.
7469 uint16_t ConsStringGet(int index);
7470
7471 // Casting.
7472 static inline ConsString* cast(Object* obj);
7473
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007474 // Layout description.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00007475 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007476 static const int kSecondOffset = kFirstOffset + kPointerSize;
7477 static const int kSize = kSecondOffset + kPointerSize;
7478
7479 // Support for StringInputBuffer.
7480 inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer,
7481 unsigned* offset_ptr,
7482 unsigned chars);
7483 inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7484 unsigned* offset_ptr,
7485 unsigned chars);
7486
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007487 // Minimum length for a cons string.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007488 static const int kMinLength = 13;
7489
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007490 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
7491 BodyDescriptor;
7492
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007493#ifdef DEBUG
7494 void ConsStringVerify();
7495#endif
7496
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007497 private:
7498 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
7499};
7500
7501
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007502// The Sliced String class describes strings that are substrings of another
7503// sequential string. The motivation is to save time and memory when creating
7504// a substring. A Sliced String is described as a pointer to the parent,
7505// the offset from the start of the parent string and the length. Using
7506// a Sliced String therefore requires unpacking of the parent string and
7507// adding the offset to the start address. A substring of a Sliced String
7508// are not nested since the double indirection is simplified when creating
7509// such a substring.
7510// Currently missing features are:
7511// - handling externalized parent strings
7512// - external strings as parent
7513// - truncating sliced string to enable otherwise unneeded parent to be GC'ed.
7514class SlicedString: public String {
7515 public:
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007516 inline String* parent();
7517 inline void set_parent(String* parent);
7518 inline int offset();
7519 inline void set_offset(int offset);
7520
7521 // Dispatched behavior.
7522 uint16_t SlicedStringGet(int index);
7523
7524 // Casting.
7525 static inline SlicedString* cast(Object* obj);
7526
7527 // Layout description.
7528 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
7529 static const int kOffsetOffset = kParentOffset + kPointerSize;
7530 static const int kSize = kOffsetOffset + kPointerSize;
7531
7532 // Support for StringInputBuffer
7533 inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer,
7534 unsigned* offset_ptr,
7535 unsigned chars);
7536 inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7537 unsigned* offset_ptr,
7538 unsigned chars);
7539 // Minimum length for a sliced string.
7540 static const int kMinLength = 13;
7541
7542 typedef FixedBodyDescriptor<kParentOffset,
7543 kOffsetOffset + kPointerSize, kSize>
7544 BodyDescriptor;
7545
7546#ifdef DEBUG
7547 void SlicedStringVerify();
7548#endif
7549
7550 private:
7551 DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString);
7552};
7553
7554
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007555// The ExternalString class describes string values that are backed by
7556// a string resource that lies outside the V8 heap. ExternalStrings
7557// consist of the length field common to all strings, a pointer to the
7558// external resource. It is important to ensure (externally) that the
7559// resource is not deallocated while the ExternalString is live in the
7560// V8 heap.
7561//
7562// The API expects that all ExternalStrings are created through the
7563// API. Therefore, ExternalStrings should not be used internally.
7564class ExternalString: public String {
7565 public:
7566 // Casting
7567 static inline ExternalString* cast(Object* obj);
7568
7569 // Layout description.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00007570 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00007571 static const int kShortSize = kResourceOffset + kPointerSize;
erikcorry0ad885c2011-11-21 13:51:57 +00007572 static const int kResourceDataOffset = kResourceOffset + kPointerSize;
7573 static const int kSize = kResourceDataOffset + kPointerSize;
7574
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00007575 // Return whether external string is short (data pointer is not cached).
7576 inline bool is_short();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007577
ager@chromium.org18ad94b2009-09-02 08:22:29 +00007578 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset);
7579
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007580 private:
7581 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
7582};
7583
7584
7585// The ExternalAsciiString class is an external string backed by an
7586// ASCII string.
7587class ExternalAsciiString: public ExternalString {
7588 public:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00007589 static const bool kHasAsciiEncoding = true;
7590
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007591 typedef v8::String::ExternalAsciiStringResource Resource;
7592
7593 // The underlying resource.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007594 inline const Resource* resource();
7595 inline void set_resource(const Resource* buffer);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007596
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00007597 // Update the pointer cache to the external character array.
7598 // The cached pointer is always valid, as the external character array does =
7599 // not move during lifetime. Deserialization is the only exception, after
7600 // which the pointer cache has to be refreshed.
7601 inline void update_data_cache();
7602
erikcorry0ad885c2011-11-21 13:51:57 +00007603 inline const char* GetChars();
7604
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007605 // Dispatched behavior.
erikcorry0ad885c2011-11-21 13:51:57 +00007606 inline uint16_t ExternalAsciiStringGet(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007607
7608 // Casting.
7609 static inline ExternalAsciiString* cast(Object* obj);
7610
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007611 // Garbage collection support.
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007612 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v);
7613
7614 template<typename StaticVisitor>
7615 inline void ExternalAsciiStringIterateBody();
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007616
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007617 // Support for StringInputBuffer.
7618 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining,
7619 unsigned* offset,
7620 unsigned chars);
7621 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7622 unsigned* offset,
7623 unsigned chars);
7624
7625 private:
7626 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString);
7627};
7628
7629
7630// The ExternalTwoByteString class is an external string backed by a UTF-16
7631// encoded string.
7632class ExternalTwoByteString: public ExternalString {
7633 public:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00007634 static const bool kHasAsciiEncoding = false;
7635
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007636 typedef v8::String::ExternalStringResource Resource;
7637
7638 // The underlying string resource.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007639 inline const Resource* resource();
7640 inline void set_resource(const Resource* buffer);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007641
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00007642 // Update the pointer cache to the external character array.
7643 // The cached pointer is always valid, as the external character array does =
7644 // not move during lifetime. Deserialization is the only exception, after
7645 // which the pointer cache has to be refreshed.
7646 inline void update_data_cache();
7647
erikcorry0ad885c2011-11-21 13:51:57 +00007648 inline const uint16_t* GetChars();
7649
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007650 // Dispatched behavior.
erikcorry0ad885c2011-11-21 13:51:57 +00007651 inline uint16_t ExternalTwoByteStringGet(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007652
7653 // For regexp code.
erikcorry0ad885c2011-11-21 13:51:57 +00007654 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007655
7656 // Casting.
7657 static inline ExternalTwoByteString* cast(Object* obj);
7658
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007659 // Garbage collection support.
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007660 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v);
7661
7662 template<typename StaticVisitor>
7663 inline void ExternalTwoByteStringIterateBody();
7664
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007665
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007666 // Support for StringInputBuffer.
7667 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7668 unsigned* offset_ptr,
7669 unsigned chars);
7670
7671 private:
7672 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString);
7673};
7674
7675
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007676// Utility superclass for stack-allocated objects that must be updated
7677// on gc. It provides two ways for the gc to update instances, either
7678// iterating or updating after gc.
7679class Relocatable BASE_EMBEDDED {
7680 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007681 explicit inline Relocatable(Isolate* isolate);
7682 inline virtual ~Relocatable();
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007683 virtual void IterateInstance(ObjectVisitor* v) { }
7684 virtual void PostGarbageCollection() { }
7685
7686 static void PostGarbageCollectionProcessing();
7687 static int ArchiveSpacePerThread();
lrn@chromium.org1c092762011-05-09 09:42:16 +00007688 static char* ArchiveState(Isolate* isolate, char* to);
7689 static char* RestoreState(Isolate* isolate, char* from);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007690 static void Iterate(ObjectVisitor* v);
7691 static void Iterate(ObjectVisitor* v, Relocatable* top);
7692 static char* Iterate(ObjectVisitor* v, char* t);
7693 private:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007694 Isolate* isolate_;
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007695 Relocatable* prev_;
7696};
7697
7698
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007699// A flat string reader provides random access to the contents of a
7700// string independent of the character width of the string. The handle
7701// must be valid as long as the reader is being used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007702class FlatStringReader : public Relocatable {
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007703 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007704 FlatStringReader(Isolate* isolate, Handle<String> str);
7705 FlatStringReader(Isolate* isolate, Vector<const char> input);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007706 void PostGarbageCollection();
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007707 inline uc32 Get(int index);
7708 int length() { return length_; }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007709 private:
7710 String** str_;
7711 bool is_ascii_;
7712 int length_;
7713 const void* start_;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007714};
7715
7716
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007717// Note that StringInputBuffers are not valid across a GC! To fix this
7718// it would have to store a String Handle instead of a String* and
7719// AsciiStringReadBlock would have to be modified to use memcpy.
7720//
7721// StringInputBuffer is able to traverse any string regardless of how
7722// deeply nested a sequence of ConsStrings it is made of. However,
7723// performance will be better if deep strings are flattened before they
7724// are traversed. Since flattening requires memory allocation this is
7725// not always desirable, however (esp. in debugging situations).
7726class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> {
7727 public:
7728 virtual void Seek(unsigned pos);
7729 inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {}
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00007730 explicit inline StringInputBuffer(String* backing):
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007731 unibrow::InputBuffer<String, String*, 1024>(backing) {}
7732};
7733
7734
7735class SafeStringInputBuffer
7736 : public unibrow::InputBuffer<String, String**, 256> {
7737 public:
7738 virtual void Seek(unsigned pos);
7739 inline SafeStringInputBuffer()
7740 : unibrow::InputBuffer<String, String**, 256>() {}
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00007741 explicit inline SafeStringInputBuffer(String** backing)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007742 : unibrow::InputBuffer<String, String**, 256>(backing) {}
7743};
7744
7745
ager@chromium.org7c537e22008-10-16 08:43:32 +00007746template <typename T>
7747class VectorIterator {
7748 public:
7749 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { }
7750 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { }
7751 T GetNext() { return data_[index_++]; }
7752 bool has_more() { return index_ < data_.length(); }
7753 private:
7754 Vector<const T> data_;
7755 int index_;
7756};
7757
7758
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007759// The Oddball describes objects null, undefined, true, and false.
7760class Oddball: public HeapObject {
7761 public:
7762 // [to_string]: Cached to_string computed at startup.
7763 DECL_ACCESSORS(to_string, String)
7764
7765 // [to_number]: Cached to_number computed at startup.
7766 DECL_ACCESSORS(to_number, Object)
7767
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007768 inline byte kind();
7769 inline void set_kind(byte kind);
7770
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007771 // Casting.
7772 static inline Oddball* cast(Object* obj);
7773
7774 // Dispatched behavior.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007775#ifdef DEBUG
7776 void OddballVerify();
7777#endif
7778
7779 // Initialize the fields.
lrn@chromium.org303ada72010-10-27 09:33:13 +00007780 MUST_USE_RESULT MaybeObject* Initialize(const char* to_string,
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007781 Object* to_number,
7782 byte kind);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007783
7784 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00007785 static const int kToStringOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007786 static const int kToNumberOffset = kToStringOffset + kPointerSize;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007787 static const int kKindOffset = kToNumberOffset + kPointerSize;
7788 static const int kSize = kKindOffset + kPointerSize;
7789
7790 static const byte kFalse = 0;
7791 static const byte kTrue = 1;
7792 static const byte kNotBooleanMask = ~1;
7793 static const byte kTheHole = 2;
7794 static const byte kNull = 3;
7795 static const byte kArgumentMarker = 4;
7796 static const byte kUndefined = 5;
7797 static const byte kOther = 6;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007798
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007799 typedef FixedBodyDescriptor<kToStringOffset,
7800 kToNumberOffset + kPointerSize,
7801 kSize> BodyDescriptor;
7802
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00007803 STATIC_CHECK(kKindOffset == Internals::kOddballKindOffset);
7804 STATIC_CHECK(kNull == Internals::kNullOddballKind);
7805 STATIC_CHECK(kUndefined == Internals::kUndefinedOddballKind);
7806
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007807 private:
7808 DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball);
7809};
7810
7811
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00007812class JSGlobalPropertyCell: public HeapObject {
7813 public:
7814 // [value]: value of the global property.
7815 DECL_ACCESSORS(value, Object)
7816
7817 // Casting.
7818 static inline JSGlobalPropertyCell* cast(Object* obj);
7819
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00007820#ifdef DEBUG
7821 void JSGlobalPropertyCellVerify();
whesse@chromium.org023421e2010-12-21 12:19:12 +00007822#endif
7823#ifdef OBJECT_PRINT
7824 inline void JSGlobalPropertyCellPrint() {
7825 JSGlobalPropertyCellPrint(stdout);
7826 }
7827 void JSGlobalPropertyCellPrint(FILE* out);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00007828#endif
7829
7830 // Layout description.
7831 static const int kValueOffset = HeapObject::kHeaderSize;
7832 static const int kSize = kValueOffset + kPointerSize;
7833
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007834 typedef FixedBodyDescriptor<kValueOffset,
7835 kValueOffset + kPointerSize,
7836 kSize> BodyDescriptor;
7837
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00007838 private:
7839 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell);
7840};
7841
7842
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007843// The JSProxy describes EcmaScript Harmony proxies
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007844class JSProxy: public JSReceiver {
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007845 public:
7846 // [handler]: The handler property.
7847 DECL_ACCESSORS(handler, Object)
7848
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007849 // [hash]: The hash code property (undefined if not initialized yet).
7850 DECL_ACCESSORS(hash, Object)
7851
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007852 // Casting.
7853 static inline JSProxy* cast(Object* obj);
7854
rossberg@chromium.org717967f2011-07-20 13:44:42 +00007855 bool HasPropertyWithHandler(String* name);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007856 bool HasElementWithHandler(uint32_t index);
7857
7858 MUST_USE_RESULT MaybeObject* GetPropertyWithHandler(
7859 Object* receiver,
7860 String* name);
7861 MUST_USE_RESULT MaybeObject* GetElementWithHandler(
7862 Object* receiver,
7863 uint32_t index);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00007864
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007865 MUST_USE_RESULT MaybeObject* SetPropertyWithHandler(
verwaest@chromium.org37141392012-05-31 13:27:02 +00007866 JSReceiver* receiver,
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00007867 String* name,
7868 Object* value,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007869 PropertyAttributes attributes,
7870 StrictModeFlag strict_mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007871 MUST_USE_RESULT MaybeObject* SetElementWithHandler(
verwaest@chromium.org37141392012-05-31 13:27:02 +00007872 JSReceiver* receiver,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007873 uint32_t index,
7874 Object* value,
7875 StrictModeFlag strict_mode);
7876
mmassi@chromium.org7028c052012-06-13 11:51:58 +00007877 // If the handler defines an accessor property with a setter, invoke it.
7878 // If it defines an accessor property without a setter, or a data property
7879 // that is read-only, throw. In all these cases set '*done' to true,
7880 // otherwise set it to false.
7881 MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypesWithHandler(
verwaest@chromium.org37141392012-05-31 13:27:02 +00007882 JSReceiver* receiver,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007883 String* name,
7884 Object* value,
7885 PropertyAttributes attributes,
7886 StrictModeFlag strict_mode,
mmassi@chromium.org7028c052012-06-13 11:51:58 +00007887 bool* done);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007888
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00007889 MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler(
7890 String* name,
7891 DeleteMode mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007892 MUST_USE_RESULT MaybeObject* DeleteElementWithHandler(
7893 uint32_t index,
7894 DeleteMode mode);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00007895
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007896 MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler(
7897 JSReceiver* receiver,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007898 String* name);
7899 MUST_USE_RESULT PropertyAttributes GetElementAttributeWithHandler(
7900 JSReceiver* receiver,
7901 uint32_t index);
7902
7903 MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007904
rossberg@chromium.org717967f2011-07-20 13:44:42 +00007905 // Turn this into an (empty) JSObject.
7906 void Fix();
7907
lrn@chromium.org34e60782011-09-15 07:25:40 +00007908 // Initializes the body after the handler slot.
7909 inline void InitializeBody(int object_size, Object* value);
7910
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007911 // Invoke a trap by name. If the trap does not exist on this's handler,
7912 // but derived_trap is non-NULL, invoke that instead. May cause GC.
7913 Handle<Object> CallTrap(const char* name,
7914 Handle<Object> derived_trap,
7915 int argc,
7916 Handle<Object> args[]);
7917
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007918 // Dispatched behavior.
7919#ifdef OBJECT_PRINT
7920 inline void JSProxyPrint() {
7921 JSProxyPrint(stdout);
7922 }
7923 void JSProxyPrint(FILE* out);
7924#endif
7925#ifdef DEBUG
7926 void JSProxyVerify();
7927#endif
7928
rossberg@chromium.org717967f2011-07-20 13:44:42 +00007929 // Layout description. We add padding so that a proxy has the same
7930 // size as a virgin JSObject. This is essential for becoming a JSObject
7931 // upon freeze.
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007932 static const int kHandlerOffset = HeapObject::kHeaderSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007933 static const int kHashOffset = kHandlerOffset + kPointerSize;
7934 static const int kPaddingOffset = kHashOffset + kPointerSize;
lrn@chromium.org34e60782011-09-15 07:25:40 +00007935 static const int kSize = JSObject::kHeaderSize;
7936 static const int kHeaderSize = kPaddingOffset;
7937 static const int kPaddingSize = kSize - kPaddingOffset;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00007938
lrn@chromium.org34e60782011-09-15 07:25:40 +00007939 STATIC_CHECK(kPaddingSize >= 0);
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007940
7941 typedef FixedBodyDescriptor<kHandlerOffset,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007942 kPaddingOffset,
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007943 kSize> BodyDescriptor;
7944
7945 private:
7946 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
7947};
7948
7949
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007950class JSFunctionProxy: public JSProxy {
7951 public:
lrn@chromium.org34e60782011-09-15 07:25:40 +00007952 // [call_trap]: The call trap.
7953 DECL_ACCESSORS(call_trap, Object)
7954
7955 // [construct_trap]: The construct trap.
7956 DECL_ACCESSORS(construct_trap, Object)
7957
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007958 // Casting.
7959 static inline JSFunctionProxy* cast(Object* obj);
7960
lrn@chromium.org34e60782011-09-15 07:25:40 +00007961 // Dispatched behavior.
7962#ifdef OBJECT_PRINT
7963 inline void JSFunctionProxyPrint() {
7964 JSFunctionProxyPrint(stdout);
7965 }
7966 void JSFunctionProxyPrint(FILE* out);
7967#endif
7968#ifdef DEBUG
7969 void JSFunctionProxyVerify();
7970#endif
7971
7972 // Layout description.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007973 static const int kCallTrapOffset = JSProxy::kPaddingOffset;
lrn@chromium.org34e60782011-09-15 07:25:40 +00007974 static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize;
7975 static const int kPaddingOffset = kConstructTrapOffset + kPointerSize;
7976 static const int kSize = JSFunction::kSize;
7977 static const int kPaddingSize = kSize - kPaddingOffset;
7978
7979 STATIC_CHECK(kPaddingSize >= 0);
7980
7981 typedef FixedBodyDescriptor<kHandlerOffset,
7982 kConstructTrapOffset + kPointerSize,
7983 kSize> BodyDescriptor;
7984
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007985 private:
7986 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy);
7987};
7988
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00007989
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00007990// The JSSet describes EcmaScript Harmony sets
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00007991class JSSet: public JSObject {
7992 public:
7993 // [set]: the backing hash set containing keys.
7994 DECL_ACCESSORS(table, Object)
7995
7996 // Casting.
7997 static inline JSSet* cast(Object* obj);
7998
7999#ifdef OBJECT_PRINT
8000 inline void JSSetPrint() {
8001 JSSetPrint(stdout);
8002 }
8003 void JSSetPrint(FILE* out);
8004#endif
8005#ifdef DEBUG
8006 void JSSetVerify();
8007#endif
8008
8009 static const int kTableOffset = JSObject::kHeaderSize;
8010 static const int kSize = kTableOffset + kPointerSize;
8011
8012 private:
8013 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet);
8014};
8015
8016
8017// The JSMap describes EcmaScript Harmony maps
8018class JSMap: public JSObject {
8019 public:
8020 // [table]: the backing hash table mapping keys to values.
8021 DECL_ACCESSORS(table, Object)
8022
8023 // Casting.
8024 static inline JSMap* cast(Object* obj);
8025
8026#ifdef OBJECT_PRINT
8027 inline void JSMapPrint() {
8028 JSMapPrint(stdout);
8029 }
8030 void JSMapPrint(FILE* out);
8031#endif
8032#ifdef DEBUG
8033 void JSMapVerify();
8034#endif
8035
8036 static const int kTableOffset = JSObject::kHeaderSize;
8037 static const int kSize = kTableOffset + kPointerSize;
8038
8039 private:
8040 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
8041};
8042
8043
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00008044// The JSWeakMap describes EcmaScript Harmony weak maps
8045class JSWeakMap: public JSObject {
8046 public:
8047 // [table]: the backing hash table mapping keys to values.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00008048 DECL_ACCESSORS(table, Object)
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00008049
8050 // [next]: linked list of encountered weak maps during GC.
8051 DECL_ACCESSORS(next, Object)
8052
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00008053 // Casting.
8054 static inline JSWeakMap* cast(Object* obj);
8055
8056#ifdef OBJECT_PRINT
8057 inline void JSWeakMapPrint() {
8058 JSWeakMapPrint(stdout);
8059 }
8060 void JSWeakMapPrint(FILE* out);
8061#endif
8062#ifdef DEBUG
8063 void JSWeakMapVerify();
8064#endif
8065
8066 static const int kTableOffset = JSObject::kHeaderSize;
8067 static const int kNextOffset = kTableOffset + kPointerSize;
8068 static const int kSize = kNextOffset + kPointerSize;
8069
8070 private:
8071 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap);
8072};
8073
8074
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008075// Foreign describes objects pointing from JavaScript to C structures.
ager@chromium.org9258b6b2008-09-11 09:11:10 +00008076// Since they cannot contain references to JS HeapObjects they can be
8077// placed in old_data_space.
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008078class Foreign: public HeapObject {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008079 public:
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008080 // [address]: field containing the address.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00008081 inline Address foreign_address();
8082 inline void set_foreign_address(Address value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008083
8084 // Casting.
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008085 static inline Foreign* cast(Object* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008086
8087 // Dispatched behavior.
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008088 inline void ForeignIterateBody(ObjectVisitor* v);
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00008089
8090 template<typename StaticVisitor>
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008091 inline void ForeignIterateBody();
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00008092
whesse@chromium.org023421e2010-12-21 12:19:12 +00008093#ifdef OBJECT_PRINT
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008094 inline void ForeignPrint() {
8095 ForeignPrint(stdout);
whesse@chromium.org023421e2010-12-21 12:19:12 +00008096 }
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008097 void ForeignPrint(FILE* out);
whesse@chromium.org023421e2010-12-21 12:19:12 +00008098#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008099#ifdef DEBUG
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008100 void ForeignVerify();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008101#endif
8102
8103 // Layout description.
8104
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00008105 static const int kForeignAddressOffset = HeapObject::kHeaderSize;
8106 static const int kSize = kForeignAddressOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008107
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00008108 STATIC_CHECK(kForeignAddressOffset == Internals::kForeignAddressOffset);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00008109
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008110 private:
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008111 DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008112};
8113
8114
8115// The JSArray describes JavaScript Arrays
8116// Such an array can be in one of two modes:
8117// - fast, backing storage is a FixedArray and length <= elements.length();
8118// Please note: push and pop can be used to grow and shrink the array.
8119// - slow, backing storage is a HashTable with numbers as keys.
8120class JSArray: public JSObject {
8121 public:
8122 // [length]: The length property.
8123 DECL_ACCESSORS(length, Object)
8124
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00008125 // Overload the length setter to skip write barrier when the length
8126 // is set to a smi. This matches the set function on FixedArray.
8127 inline void set_length(Smi* length);
8128
lrn@chromium.org303ada72010-10-27 09:33:13 +00008129 MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index,
8130 Object* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008131
8132 // Initialize the array with the given capacity. The function may
8133 // fail due to out-of-memory situations, but only if the requested
8134 // capacity is non-zero.
lrn@chromium.org303ada72010-10-27 09:33:13 +00008135 MUST_USE_RESULT MaybeObject* Initialize(int capacity);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008136
ricow@chromium.org7ad65222011-12-19 12:13:11 +00008137 // Initializes the array to a certain length.
8138 inline bool AllowsSetElementsLength();
8139 MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length);
8140
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008141 // Set the content of the array to the content of storage.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00008142 MUST_USE_RESULT inline MaybeObject* SetContent(FixedArrayBase* storage);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008143
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008144 // Casting.
8145 static inline JSArray* cast(Object* obj);
8146
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00008147 // Uses handles. Ensures that the fixed array backing the JSArray has at
8148 // least the stated size.
ager@chromium.org5aa501c2009-06-23 07:57:28 +00008149 inline void EnsureSize(int minimum_size_of_backing_fixed_array);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00008150
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008151 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00008152#ifdef OBJECT_PRINT
8153 inline void JSArrayPrint() {
8154 JSArrayPrint(stdout);
8155 }
8156 void JSArrayPrint(FILE* out);
8157#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008158#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008159 void JSArrayVerify();
8160#endif
8161
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00008162 // Number of element slots to pre-allocate for an empty array.
8163 static const int kPreallocatedArrayElements = 4;
8164
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008165 // Layout description.
8166 static const int kLengthOffset = JSObject::kHeaderSize;
8167 static const int kSize = kLengthOffset + kPointerSize;
8168
8169 private:
ager@chromium.org5aa501c2009-06-23 07:57:28 +00008170 // Expand the fixed array backing of a fast-case JSArray to at least
8171 // the requested size.
8172 void Expand(int minimum_size_of_backing_fixed_array);
8173
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008174 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
8175};
8176
8177
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +00008178// JSRegExpResult is just a JSArray with a specific initial map.
8179// This initial map adds in-object properties for "index" and "input"
8180// properties, as assigned by RegExp.prototype.exec, which allows
8181// faster creation of RegExp exec results.
8182// This class just holds constants used when creating the result.
8183// After creation the result must be treated as a JSArray in all regards.
8184class JSRegExpResult: public JSArray {
8185 public:
8186 // Offsets of object fields.
8187 static const int kIndexOffset = JSArray::kSize;
8188 static const int kInputOffset = kIndexOffset + kPointerSize;
8189 static const int kSize = kInputOffset + kPointerSize;
8190 // Indices of in-object properties.
8191 static const int kIndexIndex = 0;
8192 static const int kInputIndex = 1;
8193 private:
8194 DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult);
8195};
8196
8197
ager@chromium.org32912102009-01-16 10:38:43 +00008198// An accessor must have a getter, but can have no setter.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008199//
8200// When setting a property, V8 searches accessors in prototypes.
8201// If an accessor was found and it does not have a setter,
8202// the request is ignored.
8203//
ager@chromium.orgeadaf222009-06-16 09:43:10 +00008204// If the accessor in the prototype has the READ_ONLY property attribute, then
8205// a new value is added to the local object when the property is set.
8206// This shadows the accessor in the prototype.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008207class AccessorInfo: public Struct {
8208 public:
8209 DECL_ACCESSORS(getter, Object)
8210 DECL_ACCESSORS(setter, Object)
8211 DECL_ACCESSORS(data, Object)
8212 DECL_ACCESSORS(name, Object)
8213 DECL_ACCESSORS(flag, Smi)
mmassi@chromium.org7028c052012-06-13 11:51:58 +00008214 DECL_ACCESSORS(expected_receiver_type, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008215
8216 inline bool all_can_read();
8217 inline void set_all_can_read(bool value);
8218
8219 inline bool all_can_write();
8220 inline void set_all_can_write(bool value);
8221
ager@chromium.org870a0b62008-11-04 11:43:05 +00008222 inline bool prohibits_overwriting();
8223 inline void set_prohibits_overwriting(bool value);
8224
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008225 inline PropertyAttributes property_attributes();
8226 inline void set_property_attributes(PropertyAttributes attributes);
8227
mmassi@chromium.org7028c052012-06-13 11:51:58 +00008228 // Checks whether the given receiver is compatible with this accessor.
8229 inline bool IsCompatibleReceiver(Object* receiver);
8230
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008231 static inline AccessorInfo* cast(Object* obj);
8232
whesse@chromium.org023421e2010-12-21 12:19:12 +00008233#ifdef OBJECT_PRINT
8234 inline void AccessorInfoPrint() {
8235 AccessorInfoPrint(stdout);
8236 }
8237 void AccessorInfoPrint(FILE* out);
8238#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008239#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008240 void AccessorInfoVerify();
8241#endif
8242
ager@chromium.org236ad962008-09-25 09:45:57 +00008243 static const int kGetterOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008244 static const int kSetterOffset = kGetterOffset + kPointerSize;
8245 static const int kDataOffset = kSetterOffset + kPointerSize;
8246 static const int kNameOffset = kDataOffset + kPointerSize;
8247 static const int kFlagOffset = kNameOffset + kPointerSize;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00008248 static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize;
8249 static const int kSize = kExpectedReceiverTypeOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008250
8251 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008252 // Bit positions in flag.
ager@chromium.org870a0b62008-11-04 11:43:05 +00008253 static const int kAllCanReadBit = 0;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008254 static const int kAllCanWriteBit = 1;
ager@chromium.org870a0b62008-11-04 11:43:05 +00008255 static const int kProhibitsOverwritingBit = 2;
8256 class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
mads.s.ager31e71382008-08-13 09:32:07 +00008257
8258 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008259};
8260
8261
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00008262// Support for JavaScript accessors: A pair of a getter and a setter. Each
8263// accessor can either be
8264// * a pointer to a JavaScript function or proxy: a real accessor
8265// * undefined: considered an accessor by the spec, too, strangely enough
8266// * the hole: an accessor which has not been set
8267// * a pointer to a map: a transition used to ensure map sharing
8268class AccessorPair: public Struct {
8269 public:
8270 DECL_ACCESSORS(getter, Object)
8271 DECL_ACCESSORS(setter, Object)
8272
8273 static inline AccessorPair* cast(Object* obj);
8274
ulan@chromium.org65a89c22012-02-14 11:46:07 +00008275 MUST_USE_RESULT MaybeObject* CopyWithoutTransitions();
8276
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00008277 Object* get(AccessorComponent component) {
8278 return component == ACCESSOR_GETTER ? getter() : setter();
8279 }
8280
8281 void set(AccessorComponent component, Object* value) {
8282 if (component == ACCESSOR_GETTER) {
8283 set_getter(value);
8284 } else {
8285 set_setter(value);
8286 }
8287 }
8288
danno@chromium.org88aa0582012-03-23 15:11:57 +00008289 // Note: Returns undefined instead in case of a hole.
8290 Object* GetComponent(AccessorComponent component);
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00008291
danno@chromium.org88aa0582012-03-23 15:11:57 +00008292 // Set both components, skipping arguments which are a JavaScript null.
8293 void SetComponents(Object* getter, Object* setter) {
8294 if (!getter->IsNull()) set_getter(getter);
8295 if (!setter->IsNull()) set_setter(setter);
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00008296 }
8297
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00008298 bool ContainsAccessor() {
8299 return IsJSAccessor(getter()) || IsJSAccessor(setter());
8300 }
8301
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00008302#ifdef OBJECT_PRINT
8303 void AccessorPairPrint(FILE* out = stdout);
8304#endif
8305#ifdef DEBUG
8306 void AccessorPairVerify();
8307#endif
8308
8309 static const int kGetterOffset = HeapObject::kHeaderSize;
8310 static const int kSetterOffset = kGetterOffset + kPointerSize;
8311 static const int kSize = kSetterOffset + kPointerSize;
8312
8313 private:
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00008314 // Strangely enough, in addition to functions and harmony proxies, the spec
8315 // requires us to consider undefined as a kind of accessor, too:
8316 // var obj = {};
8317 // Object.defineProperty(obj, "foo", {get: undefined});
8318 // assertTrue("foo" in obj);
8319 bool IsJSAccessor(Object* obj) {
8320 return obj->IsSpecFunction() || obj->IsUndefined();
8321 }
8322
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00008323 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair);
8324};
8325
8326
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008327class AccessCheckInfo: public Struct {
8328 public:
8329 DECL_ACCESSORS(named_callback, Object)
8330 DECL_ACCESSORS(indexed_callback, Object)
8331 DECL_ACCESSORS(data, Object)
8332
8333 static inline AccessCheckInfo* cast(Object* obj);
8334
whesse@chromium.org023421e2010-12-21 12:19:12 +00008335#ifdef OBJECT_PRINT
8336 inline void AccessCheckInfoPrint() {
8337 AccessCheckInfoPrint(stdout);
8338 }
8339 void AccessCheckInfoPrint(FILE* out);
8340#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008341#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008342 void AccessCheckInfoVerify();
8343#endif
8344
ager@chromium.org236ad962008-09-25 09:45:57 +00008345 static const int kNamedCallbackOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008346 static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize;
8347 static const int kDataOffset = kIndexedCallbackOffset + kPointerSize;
8348 static const int kSize = kDataOffset + kPointerSize;
8349
8350 private:
8351 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo);
8352};
8353
8354
8355class InterceptorInfo: public Struct {
8356 public:
8357 DECL_ACCESSORS(getter, Object)
8358 DECL_ACCESSORS(setter, Object)
8359 DECL_ACCESSORS(query, Object)
8360 DECL_ACCESSORS(deleter, Object)
8361 DECL_ACCESSORS(enumerator, Object)
8362 DECL_ACCESSORS(data, Object)
8363
8364 static inline InterceptorInfo* cast(Object* obj);
8365
whesse@chromium.org023421e2010-12-21 12:19:12 +00008366#ifdef OBJECT_PRINT
8367 inline void InterceptorInfoPrint() {
8368 InterceptorInfoPrint(stdout);
8369 }
8370 void InterceptorInfoPrint(FILE* out);
8371#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008372#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008373 void InterceptorInfoVerify();
8374#endif
8375
ager@chromium.org236ad962008-09-25 09:45:57 +00008376 static const int kGetterOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008377 static const int kSetterOffset = kGetterOffset + kPointerSize;
8378 static const int kQueryOffset = kSetterOffset + kPointerSize;
8379 static const int kDeleterOffset = kQueryOffset + kPointerSize;
8380 static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
8381 static const int kDataOffset = kEnumeratorOffset + kPointerSize;
8382 static const int kSize = kDataOffset + kPointerSize;
8383
8384 private:
8385 DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
8386};
8387
8388
8389class CallHandlerInfo: public Struct {
8390 public:
8391 DECL_ACCESSORS(callback, Object)
8392 DECL_ACCESSORS(data, Object)
8393
8394 static inline CallHandlerInfo* cast(Object* obj);
8395
whesse@chromium.org023421e2010-12-21 12:19:12 +00008396#ifdef OBJECT_PRINT
8397 inline void CallHandlerInfoPrint() {
8398 CallHandlerInfoPrint(stdout);
8399 }
8400 void CallHandlerInfoPrint(FILE* out);
8401#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008402#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008403 void CallHandlerInfoVerify();
8404#endif
8405
ager@chromium.org236ad962008-09-25 09:45:57 +00008406 static const int kCallbackOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008407 static const int kDataOffset = kCallbackOffset + kPointerSize;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00008408 static const int kSize = kDataOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008409
8410 private:
8411 DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
8412};
8413
8414
8415class TemplateInfo: public Struct {
8416 public:
8417 DECL_ACCESSORS(tag, Object)
8418 DECL_ACCESSORS(property_list, Object)
8419
8420#ifdef DEBUG
8421 void TemplateInfoVerify();
8422#endif
8423
ager@chromium.org236ad962008-09-25 09:45:57 +00008424 static const int kTagOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008425 static const int kPropertyListOffset = kTagOffset + kPointerSize;
8426 static const int kHeaderSize = kPropertyListOffset + kPointerSize;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00008427
8428 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008429 DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
8430};
8431
8432
8433class FunctionTemplateInfo: public TemplateInfo {
8434 public:
8435 DECL_ACCESSORS(serial_number, Object)
8436 DECL_ACCESSORS(call_code, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008437 DECL_ACCESSORS(property_accessors, Object)
8438 DECL_ACCESSORS(prototype_template, Object)
8439 DECL_ACCESSORS(parent_template, Object)
8440 DECL_ACCESSORS(named_property_handler, Object)
8441 DECL_ACCESSORS(indexed_property_handler, Object)
8442 DECL_ACCESSORS(instance_template, Object)
8443 DECL_ACCESSORS(class_name, Object)
8444 DECL_ACCESSORS(signature, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008445 DECL_ACCESSORS(instance_call_handler, Object)
8446 DECL_ACCESSORS(access_check_info, Object)
8447 DECL_ACCESSORS(flag, Smi)
8448
8449 // Following properties use flag bits.
8450 DECL_BOOLEAN_ACCESSORS(hidden_prototype)
8451 DECL_BOOLEAN_ACCESSORS(undetectable)
8452 // If the bit is set, object instances created by this function
8453 // requires access check.
8454 DECL_BOOLEAN_ACCESSORS(needs_access_check)
ricow@chromium.org2c99e282011-07-28 09:15:17 +00008455 DECL_BOOLEAN_ACCESSORS(read_only_prototype)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008456
8457 static inline FunctionTemplateInfo* cast(Object* obj);
8458
whesse@chromium.org023421e2010-12-21 12:19:12 +00008459#ifdef OBJECT_PRINT
8460 inline void FunctionTemplateInfoPrint() {
8461 FunctionTemplateInfoPrint(stdout);
8462 }
8463 void FunctionTemplateInfoPrint(FILE* out);
8464#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008465#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008466 void FunctionTemplateInfoVerify();
8467#endif
8468
8469 static const int kSerialNumberOffset = TemplateInfo::kHeaderSize;
8470 static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize;
kasper.lund212ac232008-07-16 07:07:30 +00008471 static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008472 static const int kPrototypeTemplateOffset =
8473 kPropertyAccessorsOffset + kPointerSize;
8474 static const int kParentTemplateOffset =
8475 kPrototypeTemplateOffset + kPointerSize;
8476 static const int kNamedPropertyHandlerOffset =
8477 kParentTemplateOffset + kPointerSize;
8478 static const int kIndexedPropertyHandlerOffset =
8479 kNamedPropertyHandlerOffset + kPointerSize;
8480 static const int kInstanceTemplateOffset =
8481 kIndexedPropertyHandlerOffset + kPointerSize;
8482 static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
8483 static const int kSignatureOffset = kClassNameOffset + kPointerSize;
v8.team.kasperl727e9952008-09-02 14:56:44 +00008484 static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008485 static const int kAccessCheckInfoOffset =
8486 kInstanceCallHandlerOffset + kPointerSize;
8487 static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize;
ricow@chromium.org2c99e282011-07-28 09:15:17 +00008488 static const int kSize = kFlagOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008489
8490 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008491 // Bit position in the flag, from least significant bit position.
8492 static const int kHiddenPrototypeBit = 0;
8493 static const int kUndetectableBit = 1;
8494 static const int kNeedsAccessCheckBit = 2;
ricow@chromium.org2c99e282011-07-28 09:15:17 +00008495 static const int kReadOnlyPrototypeBit = 3;
mads.s.ager31e71382008-08-13 09:32:07 +00008496
8497 DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008498};
8499
8500
8501class ObjectTemplateInfo: public TemplateInfo {
8502 public:
8503 DECL_ACCESSORS(constructor, Object)
kasper.lund212ac232008-07-16 07:07:30 +00008504 DECL_ACCESSORS(internal_field_count, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008505
8506 static inline ObjectTemplateInfo* cast(Object* obj);
8507
whesse@chromium.org023421e2010-12-21 12:19:12 +00008508#ifdef OBJECT_PRINT
8509 inline void ObjectTemplateInfoPrint() {
8510 ObjectTemplateInfoPrint(stdout);
8511 }
8512 void ObjectTemplateInfoPrint(FILE* out);
8513#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008514#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008515 void ObjectTemplateInfoVerify();
8516#endif
8517
8518 static const int kConstructorOffset = TemplateInfo::kHeaderSize;
kasper.lund212ac232008-07-16 07:07:30 +00008519 static const int kInternalFieldCountOffset =
8520 kConstructorOffset + kPointerSize;
kasperl@chromium.org71affb52009-05-26 05:44:31 +00008521 static const int kSize = kInternalFieldCountOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008522};
8523
8524
8525class SignatureInfo: public Struct {
8526 public:
8527 DECL_ACCESSORS(receiver, Object)
8528 DECL_ACCESSORS(args, Object)
8529
8530 static inline SignatureInfo* cast(Object* obj);
8531
whesse@chromium.org023421e2010-12-21 12:19:12 +00008532#ifdef OBJECT_PRINT
8533 inline void SignatureInfoPrint() {
8534 SignatureInfoPrint(stdout);
8535 }
8536 void SignatureInfoPrint(FILE* out);
8537#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008538#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008539 void SignatureInfoVerify();
8540#endif
8541
ager@chromium.org236ad962008-09-25 09:45:57 +00008542 static const int kReceiverOffset = Struct::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008543 static const int kArgsOffset = kReceiverOffset + kPointerSize;
8544 static const int kSize = kArgsOffset + kPointerSize;
8545
8546 private:
8547 DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo);
8548};
8549
8550
8551class TypeSwitchInfo: public Struct {
8552 public:
8553 DECL_ACCESSORS(types, Object)
8554
8555 static inline TypeSwitchInfo* cast(Object* obj);
8556
whesse@chromium.org023421e2010-12-21 12:19:12 +00008557#ifdef OBJECT_PRINT
8558 inline void TypeSwitchInfoPrint() {
8559 TypeSwitchInfoPrint(stdout);
8560 }
8561 void TypeSwitchInfoPrint(FILE* out);
8562#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008563#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008564 void TypeSwitchInfoVerify();
8565#endif
8566
ager@chromium.org236ad962008-09-25 09:45:57 +00008567 static const int kTypesOffset = Struct::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008568 static const int kSize = kTypesOffset + kPointerSize;
8569};
8570
8571
ager@chromium.org65dad4b2009-04-23 08:48:43 +00008572#ifdef ENABLE_DEBUGGER_SUPPORT
ager@chromium.org32912102009-01-16 10:38:43 +00008573// The DebugInfo class holds additional information for a function being
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008574// debugged.
8575class DebugInfo: public Struct {
8576 public:
ager@chromium.org32912102009-01-16 10:38:43 +00008577 // The shared function info for the source being debugged.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008578 DECL_ACCESSORS(shared, SharedFunctionInfo)
8579 // Code object for the original code.
8580 DECL_ACCESSORS(original_code, Code)
8581 // Code object for the patched code. This code object is the code object
8582 // currently active for the function.
8583 DECL_ACCESSORS(code, Code)
8584 // Fixed array holding status information for each active break point.
8585 DECL_ACCESSORS(break_points, FixedArray)
8586
8587 // Check if there is a break point at a code position.
8588 bool HasBreakPoint(int code_position);
8589 // Get the break point info object for a code position.
8590 Object* GetBreakPointInfo(int code_position);
8591 // Clear a break point.
8592 static void ClearBreakPoint(Handle<DebugInfo> debug_info,
8593 int code_position,
8594 Handle<Object> break_point_object);
8595 // Set a break point.
8596 static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position,
8597 int source_position, int statement_position,
8598 Handle<Object> break_point_object);
8599 // Get the break point objects for a code position.
8600 Object* GetBreakPointObjects(int code_position);
8601 // Find the break point info holding this break point object.
8602 static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info,
8603 Handle<Object> break_point_object);
8604 // Get the number of break points for this function.
8605 int GetBreakPointCount();
8606
8607 static inline DebugInfo* cast(Object* obj);
8608
whesse@chromium.org023421e2010-12-21 12:19:12 +00008609#ifdef OBJECT_PRINT
8610 inline void DebugInfoPrint() {
8611 DebugInfoPrint(stdout);
8612 }
8613 void DebugInfoPrint(FILE* out);
8614#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008615#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008616 void DebugInfoVerify();
8617#endif
8618
ager@chromium.org236ad962008-09-25 09:45:57 +00008619 static const int kSharedFunctionInfoIndex = Struct::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008620 static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize;
8621 static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize;
8622 static const int kActiveBreakPointsCountIndex =
8623 kPatchedCodeIndex + kPointerSize;
8624 static const int kBreakPointsStateIndex =
8625 kActiveBreakPointsCountIndex + kPointerSize;
8626 static const int kSize = kBreakPointsStateIndex + kPointerSize;
8627
8628 private:
8629 static const int kNoBreakPointInfo = -1;
8630
8631 // Lookup the index in the break_points array for a code position.
8632 int GetBreakPointInfoIndex(int code_position);
8633
8634 DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo);
8635};
8636
8637
8638// The BreakPointInfo class holds information for break points set in a
8639// function. The DebugInfo object holds a BreakPointInfo object for each code
8640// position with one or more break points.
8641class BreakPointInfo: public Struct {
8642 public:
8643 // The position in the code for the break point.
8644 DECL_ACCESSORS(code_position, Smi)
8645 // The position in the source for the break position.
8646 DECL_ACCESSORS(source_position, Smi)
8647 // The position in the source for the last statement before this break
8648 // position.
8649 DECL_ACCESSORS(statement_position, Smi)
8650 // List of related JavaScript break points.
8651 DECL_ACCESSORS(break_point_objects, Object)
8652
8653 // Removes a break point.
8654 static void ClearBreakPoint(Handle<BreakPointInfo> info,
8655 Handle<Object> break_point_object);
8656 // Set a break point.
8657 static void SetBreakPoint(Handle<BreakPointInfo> info,
8658 Handle<Object> break_point_object);
8659 // Check if break point info has this break point object.
8660 static bool HasBreakPointObject(Handle<BreakPointInfo> info,
8661 Handle<Object> break_point_object);
8662 // Get the number of break points for this code position.
8663 int GetBreakPointCount();
8664
8665 static inline BreakPointInfo* cast(Object* obj);
8666
whesse@chromium.org023421e2010-12-21 12:19:12 +00008667#ifdef OBJECT_PRINT
8668 inline void BreakPointInfoPrint() {
8669 BreakPointInfoPrint(stdout);
8670 }
8671 void BreakPointInfoPrint(FILE* out);
8672#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008673#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008674 void BreakPointInfoVerify();
8675#endif
8676
ager@chromium.org236ad962008-09-25 09:45:57 +00008677 static const int kCodePositionIndex = Struct::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008678 static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize;
8679 static const int kStatementPositionIndex =
8680 kSourcePositionIndex + kPointerSize;
8681 static const int kBreakPointObjectsIndex =
8682 kStatementPositionIndex + kPointerSize;
8683 static const int kSize = kBreakPointObjectsIndex + kPointerSize;
8684
8685 private:
8686 DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo);
8687};
ager@chromium.org65dad4b2009-04-23 08:48:43 +00008688#endif // ENABLE_DEBUGGER_SUPPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008689
8690
8691#undef DECL_BOOLEAN_ACCESSORS
8692#undef DECL_ACCESSORS
8693
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00008694#define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \
8695 V(kSymbolTable, "symbol_table", "(Symbols)") \
8696 V(kExternalStringsTable, "external_strings_table", "(External strings)") \
8697 V(kStrongRootList, "strong_root_list", "(Strong roots)") \
8698 V(kSymbol, "symbol", "(Symbol)") \
8699 V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \
8700 V(kTop, "top", "(Isolate)") \
8701 V(kRelocatable, "relocatable", "(Relocatable)") \
8702 V(kDebug, "debug", "(Debugger)") \
8703 V(kCompilationCache, "compilationcache", "(Compilation cache)") \
8704 V(kHandleScope, "handlescope", "(Handle scope)") \
8705 V(kBuiltins, "builtins", "(Builtins)") \
8706 V(kGlobalHandles, "globalhandles", "(Global handles)") \
8707 V(kThreadManager, "threadmanager", "(Thread manager)") \
8708 V(kExtensions, "Extensions", "(Extensions)")
8709
8710class VisitorSynchronization : public AllStatic {
8711 public:
8712#define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item,
8713 enum SyncTag {
8714 VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM)
8715 kNumberOfSyncTags
8716 };
8717#undef DECLARE_ENUM
8718
8719 static const char* const kTags[kNumberOfSyncTags];
8720 static const char* const kTagNames[kNumberOfSyncTags];
8721};
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008722
8723// Abstract base class for visiting, and optionally modifying, the
8724// pointers contained in Objects. Used in GC and serialization/deserialization.
8725class ObjectVisitor BASE_EMBEDDED {
8726 public:
8727 virtual ~ObjectVisitor() {}
8728
8729 // Visits a contiguous arrays of pointers in the half-open range
8730 // [start, end). Any or all of the values may be modified on return.
8731 virtual void VisitPointers(Object** start, Object** end) = 0;
8732
8733 // To allow lazy clearing of inline caches the visitor has
8734 // a rich interface for iterating over Code objects..
8735
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008736 // Visits a code target in the instruction stream.
8737 virtual void VisitCodeTarget(RelocInfo* rinfo);
8738
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00008739 // Visits a code entry in a JS function.
8740 virtual void VisitCodeEntry(Address entry_address);
8741
kasperl@chromium.orga5551262010-12-07 12:49:48 +00008742 // Visits a global property cell reference in the instruction stream.
8743 virtual void VisitGlobalPropertyCell(RelocInfo* rinfo);
8744
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008745 // Visits a runtime entry in the instruction stream.
8746 virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
8747
ager@chromium.orgc4c92722009-11-18 14:12:51 +00008748 // Visits the resource of an ASCII or two-byte string.
8749 virtual void VisitExternalAsciiString(
8750 v8::String::ExternalAsciiStringResource** resource) {}
8751 virtual void VisitExternalTwoByteString(
8752 v8::String::ExternalStringResource** resource) {}
8753
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008754 // Visits a debug call target in the instruction stream.
8755 virtual void VisitDebugTarget(RelocInfo* rinfo);
8756
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008757 // Handy shorthand for visiting a single pointer.
8758 virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); }
8759
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00008760 // Visit pointer embedded into a code object.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00008761 virtual void VisitEmbeddedPointer(RelocInfo* rinfo);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00008762
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00008763 virtual void VisitSharedFunctionInfo(SharedFunctionInfo* shared) {}
8764
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008765 // Visits a contiguous arrays of external references (references to the C++
8766 // heap) in the half-open range [start, end). Any or all of the values
8767 // may be modified on return.
8768 virtual void VisitExternalReferences(Address* start, Address* end) {}
8769
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00008770 virtual void VisitExternalReference(RelocInfo* rinfo);
8771
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008772 inline void VisitExternalReference(Address* p) {
8773 VisitExternalReferences(p, p + 1);
8774 }
8775
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00008776 // Visits a handle that has an embedder-assigned class ID.
8777 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {}
8778
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008779 // Intended for serialization/deserialization checking: insert, or
8780 // check for the presence of, a tag at this position in the stream.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00008781 // Also used for marking up GC roots in heap snapshots.
8782 virtual void Synchronize(VisitorSynchronization::SyncTag tag) {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008783};
8784
8785
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00008786class StructBodyDescriptor : public
8787 FlexibleBodyDescriptor<HeapObject::kHeaderSize> {
8788 public:
8789 static inline int SizeOf(Map* map, HeapObject* object) {
8790 return map->instance_size();
8791 }
8792};
8793
8794
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008795// BooleanBit is a helper class for setting and getting a bit in an
8796// integer or Smi.
8797class BooleanBit : public AllStatic {
8798 public:
8799 static inline bool get(Smi* smi, int bit_position) {
8800 return get(smi->value(), bit_position);
8801 }
8802
8803 static inline bool get(int value, int bit_position) {
8804 return (value & (1 << bit_position)) != 0;
8805 }
8806
8807 static inline Smi* set(Smi* smi, int bit_position, bool v) {
8808 return Smi::FromInt(set(smi->value(), bit_position, v));
8809 }
8810
8811 static inline int set(int value, int bit_position, bool v) {
8812 if (v) {
8813 value |= (1 << bit_position);
8814 } else {
8815 value &= ~(1 << bit_position);
8816 }
8817 return value;
8818 }
8819};
8820
8821} } // namespace v8::internal
8822
8823#endif // V8_OBJECTS_H_