blob: 6349c028aafcc2bdc6b8738d84f5ae60a6d30aaf [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
verwaest@chromium.org753aee42012-07-17 16:15:42 +0000181// Indicates whether transitions can be added to a source map or not.
182enum TransitionFlag {
183 INSERT_TRANSITION,
184 OMIT_TRANSITION
185};
186
187
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000188// Instance size sentinel for objects of variable size.
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000189const int kVariableSizeSentinel = 0;
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000190
danno@chromium.org81cac2b2012-07-10 11:28:27 +0000191const int kStubMajorKeyBits = 6;
192const int kStubMinorKeyBits = kBitsPerInt - kSmiTagSize - kStubMajorKeyBits;
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000193
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000194// All Maps have a field instance_type containing a InstanceType.
195// It describes the type of the instances.
196//
197// As an example, a JavaScript object is a heap object and its map
198// instance_type is JS_OBJECT_TYPE.
199//
200// The names of the string instance types are intended to systematically
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000201// mirror their encoding in the instance_type field of the map. The default
202// encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII
203// encoding is mentioned explicitly in the name. Likewise, the default
204// representation is considered sequential. It is not mentioned in the
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000205// name. The other representations (e.g. CONS, EXTERNAL) are explicitly
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000206// mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a
207// symbol) or a STRING_TYPE (if it is not a symbol).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000208//
209// NOTE: The following things are some that depend on the string types having
210// instance_types that are less than those of all other types:
211// HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
212// Object::IsString.
213//
ager@chromium.orgc27e4e72008-09-04 13:52:27 +0000214// NOTE: Everything following JS_VALUE_TYPE is considered a
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000215// JSObject for GC purposes. The first four entries here have typeof
216// 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000217#define INSTANCE_TYPE_LIST_ALL(V) \
218 V(SYMBOL_TYPE) \
219 V(ASCII_SYMBOL_TYPE) \
220 V(CONS_SYMBOL_TYPE) \
221 V(CONS_ASCII_SYMBOL_TYPE) \
222 V(EXTERNAL_SYMBOL_TYPE) \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000223 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000224 V(EXTERNAL_ASCII_SYMBOL_TYPE) \
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000225 V(SHORT_EXTERNAL_SYMBOL_TYPE) \
226 V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \
227 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000228 V(STRING_TYPE) \
229 V(ASCII_STRING_TYPE) \
230 V(CONS_STRING_TYPE) \
231 V(CONS_ASCII_STRING_TYPE) \
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000232 V(SLICED_STRING_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000233 V(EXTERNAL_STRING_TYPE) \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000234 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000235 V(EXTERNAL_ASCII_STRING_TYPE) \
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000236 V(SHORT_EXTERNAL_STRING_TYPE) \
237 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \
238 V(SHORT_EXTERNAL_ASCII_STRING_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000239 V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \
240 \
241 V(MAP_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000242 V(CODE_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000243 V(ODDBALL_TYPE) \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000244 V(JS_GLOBAL_PROPERTY_CELL_TYPE) \
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000245 \
246 V(HEAP_NUMBER_TYPE) \
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000247 V(FOREIGN_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000248 V(BYTE_ARRAY_TYPE) \
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000249 V(FREE_SPACE_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000250 /* Note: the order of these external array */ \
251 /* types is relied upon in */ \
252 /* Object::IsExternalArray(). */ \
253 V(EXTERNAL_BYTE_ARRAY_TYPE) \
254 V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \
255 V(EXTERNAL_SHORT_ARRAY_TYPE) \
256 V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \
257 V(EXTERNAL_INT_ARRAY_TYPE) \
258 V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \
259 V(EXTERNAL_FLOAT_ARRAY_TYPE) \
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000260 V(EXTERNAL_PIXEL_ARRAY_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000261 V(FILLER_TYPE) \
262 \
263 V(ACCESSOR_INFO_TYPE) \
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000264 V(ACCESSOR_PAIR_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000265 V(ACCESS_CHECK_INFO_TYPE) \
266 V(INTERCEPTOR_INFO_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000267 V(CALL_HANDLER_INFO_TYPE) \
268 V(FUNCTION_TEMPLATE_INFO_TYPE) \
269 V(OBJECT_TEMPLATE_INFO_TYPE) \
270 V(SIGNATURE_INFO_TYPE) \
271 V(TYPE_SWITCH_INFO_TYPE) \
272 V(SCRIPT_TYPE) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000273 V(CODE_CACHE_TYPE) \
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000274 V(POLYMORPHIC_CODE_CACHE_TYPE) \
mstarzinger@chromium.org3233d2f2012-03-14 11:16:03 +0000275 V(TYPE_FEEDBACK_INFO_TYPE) \
276 V(ALIASED_ARGUMENTS_ENTRY_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000277 \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000278 V(FIXED_ARRAY_TYPE) \
danno@chromium.orgb6451162011-08-17 14:33:23 +0000279 V(FIXED_DOUBLE_ARRAY_TYPE) \
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000280 V(SHARED_FUNCTION_INFO_TYPE) \
281 \
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000282 V(JS_MESSAGE_OBJECT_TYPE) \
283 \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000284 V(JS_VALUE_TYPE) \
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000285 V(JS_DATE_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000286 V(JS_OBJECT_TYPE) \
287 V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000288 V(JS_MODULE_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000289 V(JS_GLOBAL_OBJECT_TYPE) \
290 V(JS_BUILTINS_OBJECT_TYPE) \
291 V(JS_GLOBAL_PROXY_TYPE) \
292 V(JS_ARRAY_TYPE) \
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000293 V(JS_PROXY_TYPE) \
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000294 V(JS_WEAK_MAP_TYPE) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000295 V(JS_REGEXP_TYPE) \
296 \
297 V(JS_FUNCTION_TYPE) \
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000298 V(JS_FUNCTION_PROXY_TYPE) \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000299
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000300#ifdef ENABLE_DEBUGGER_SUPPORT
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000301#define INSTANCE_TYPE_LIST_DEBUGGER(V) \
302 V(DEBUG_INFO_TYPE) \
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000303 V(BREAK_POINT_INFO_TYPE)
304#else
305#define INSTANCE_TYPE_LIST_DEBUGGER(V)
306#endif
307
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000308#define INSTANCE_TYPE_LIST(V) \
309 INSTANCE_TYPE_LIST_ALL(V) \
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000310 INSTANCE_TYPE_LIST_DEBUGGER(V)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000311
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000312
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000313// Since string types are not consecutive, this macro is used to
314// iterate over them.
315#define STRING_TYPE_LIST(V) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000316 V(SYMBOL_TYPE, \
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000317 kVariableSizeSentinel, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000318 symbol, \
319 Symbol) \
320 V(ASCII_SYMBOL_TYPE, \
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000321 kVariableSizeSentinel, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000322 ascii_symbol, \
323 AsciiSymbol) \
324 V(CONS_SYMBOL_TYPE, \
325 ConsString::kSize, \
326 cons_symbol, \
327 ConsSymbol) \
328 V(CONS_ASCII_SYMBOL_TYPE, \
329 ConsString::kSize, \
330 cons_ascii_symbol, \
331 ConsAsciiSymbol) \
332 V(EXTERNAL_SYMBOL_TYPE, \
333 ExternalTwoByteString::kSize, \
334 external_symbol, \
335 ExternalSymbol) \
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000336 V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
337 ExternalTwoByteString::kSize, \
338 external_symbol_with_ascii_data, \
339 ExternalSymbolWithAsciiData) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000340 V(EXTERNAL_ASCII_SYMBOL_TYPE, \
341 ExternalAsciiString::kSize, \
342 external_ascii_symbol, \
343 ExternalAsciiSymbol) \
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000344 V(SHORT_EXTERNAL_SYMBOL_TYPE, \
345 ExternalTwoByteString::kShortSize, \
346 short_external_symbol, \
347 ShortExternalSymbol) \
348 V(SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \
349 ExternalTwoByteString::kShortSize, \
350 short_external_symbol_with_ascii_data, \
351 ShortExternalSymbolWithAsciiData) \
352 V(SHORT_EXTERNAL_ASCII_SYMBOL_TYPE, \
353 ExternalAsciiString::kShortSize, \
354 short_external_ascii_symbol, \
355 ShortExternalAsciiSymbol) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000356 V(STRING_TYPE, \
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000357 kVariableSizeSentinel, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000358 string, \
359 String) \
360 V(ASCII_STRING_TYPE, \
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000361 kVariableSizeSentinel, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000362 ascii_string, \
363 AsciiString) \
364 V(CONS_STRING_TYPE, \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000365 ConsString::kSize, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000366 cons_string, \
367 ConsString) \
368 V(CONS_ASCII_STRING_TYPE, \
kasperl@chromium.org68ac0092009-07-09 06:00:35 +0000369 ConsString::kSize, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000370 cons_ascii_string, \
371 ConsAsciiString) \
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000372 V(SLICED_STRING_TYPE, \
373 SlicedString::kSize, \
374 sliced_string, \
375 SlicedString) \
376 V(SLICED_ASCII_STRING_TYPE, \
377 SlicedString::kSize, \
378 sliced_ascii_string, \
379 SlicedAsciiString) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000380 V(EXTERNAL_STRING_TYPE, \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000381 ExternalTwoByteString::kSize, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000382 external_string, \
383 ExternalString) \
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000384 V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
385 ExternalTwoByteString::kSize, \
386 external_string_with_ascii_data, \
387 ExternalStringWithAsciiData) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000388 V(EXTERNAL_ASCII_STRING_TYPE, \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000389 ExternalAsciiString::kSize, \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000390 external_ascii_string, \
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000391 ExternalAsciiString) \
392 V(SHORT_EXTERNAL_STRING_TYPE, \
393 ExternalTwoByteString::kShortSize, \
394 short_external_string, \
395 ShortExternalString) \
396 V(SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \
397 ExternalTwoByteString::kShortSize, \
398 short_external_string_with_ascii_data, \
399 ShortExternalStringWithAsciiData) \
400 V(SHORT_EXTERNAL_ASCII_STRING_TYPE, \
401 ExternalAsciiString::kShortSize, \
402 short_external_ascii_string, \
403 ShortExternalAsciiString)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000404
405// A struct is a simple object a set of object-valued fields. Including an
406// object type in this causes the compiler to generate most of the boilerplate
407// code for the class including allocation and garbage collection routines,
408// casts and predicates. All you need to define is the class, methods and
409// object verification routines. Easy, no?
410//
411// Note that for subtle reasons related to the ordering or numerical values of
412// type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
413// manually.
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000414#define STRUCT_LIST_ALL(V) \
415 V(ACCESSOR_INFO, AccessorInfo, accessor_info) \
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000416 V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000417 V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \
418 V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \
419 V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \
420 V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \
421 V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \
422 V(SIGNATURE_INFO, SignatureInfo, signature_info) \
423 V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000424 V(SCRIPT, Script, script) \
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000425 V(CODE_CACHE, CodeCache, code_cache) \
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000426 V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +0000427 V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \
428 V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000429
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000430#ifdef ENABLE_DEBUGGER_SUPPORT
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000431#define STRUCT_LIST_DEBUGGER(V) \
432 V(DEBUG_INFO, DebugInfo, debug_info) \
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000433 V(BREAK_POINT_INFO, BreakPointInfo, break_point_info)
434#else
435#define STRUCT_LIST_DEBUGGER(V)
436#endif
437
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000438#define STRUCT_LIST(V) \
439 STRUCT_LIST_ALL(V) \
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000440 STRUCT_LIST_DEBUGGER(V)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000441
442// We use the full 8 bits of the instance_type field to encode heap object
443// instance types. The high-order bit (bit 7) is set if the object is not a
444// string, and cleared if it is a string.
445const uint32_t kIsNotStringMask = 0x80;
446const uint32_t kStringTag = 0x0;
447const uint32_t kNotStringTag = 0x80;
448
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000449// Bit 6 indicates that the object is a symbol (if set) or not (if cleared).
450// There are not enough types that the non-string types (with bit 7 set) can
451// have bit 6 set too.
452const uint32_t kIsSymbolMask = 0x40;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000453const uint32_t kNotSymbolTag = 0x0;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000454const uint32_t kSymbolTag = 0x40;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000455
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000456// If bit 7 is clear then bit 2 indicates whether the string consists of
457// two-byte characters or one-byte characters.
458const uint32_t kStringEncodingMask = 0x4;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000459const uint32_t kTwoByteStringTag = 0x0;
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000460const uint32_t kAsciiStringTag = 0x4;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000461
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000462// If bit 7 is clear, the low-order 2 bits indicate the representation
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000463// of the string.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +0000464const uint32_t kStringRepresentationMask = 0x03;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000465enum StringRepresentationTag {
466 kSeqStringTag = 0x0,
467 kConsStringTag = 0x1,
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000468 kExternalStringTag = 0x2,
469 kSlicedStringTag = 0x3
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000470};
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000471const uint32_t kIsIndirectStringMask = 0x1;
472const uint32_t kIsIndirectStringTag = 0x1;
473STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0);
474STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0);
475STATIC_ASSERT(
476 (kConsStringTag & kIsIndirectStringMask) == kIsIndirectStringTag);
477STATIC_ASSERT(
478 (kSlicedStringTag & kIsIndirectStringMask) == kIsIndirectStringTag);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000479
yangguo@chromium.org80c42ed2011-08-31 09:03:56 +0000480// Use this mask to distinguish between cons and slice only after making
481// sure that the string is one of the two (an indirect string).
482const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag;
483STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask) && kSlicedNotConsMask != 0);
484
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000485// If bit 7 is clear, then bit 3 indicates whether this two-byte
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000486// string actually contains ASCII data.
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000487const uint32_t kAsciiDataHintMask = 0x08;
488const uint32_t kAsciiDataHintTag = 0x08;
489
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000490// If bit 7 is clear and string representation indicates an external string,
491// then bit 4 indicates whether the data pointer is cached.
492const uint32_t kShortExternalStringMask = 0x10;
493const uint32_t kShortExternalStringTag = 0x10;
494
kasperl@chromium.orgd1e3e722009-04-14 13:38:25 +0000495
496// A ConsString with an empty string as the right side is a candidate
497// for being shortcut by the garbage collector unless it is a
498// symbol. It's not common to have non-flat symbols, so we do not
499// shortcut them thereby avoiding turning symbols into strings. See
500// heap.cc and mark-compact.cc.
501const uint32_t kShortcutTypeMask =
502 kIsNotStringMask |
503 kIsSymbolMask |
504 kStringRepresentationMask;
505const uint32_t kShortcutTypeTag = kConsStringTag;
506
507
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000508enum InstanceType {
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000509 // String types.
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000510 SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000511 ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000512 CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000513 CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000514 SHORT_EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag |
515 kExternalStringTag | kShortExternalStringTag,
516 SHORT_EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
517 kTwoByteStringTag | kSymbolTag | kExternalStringTag |
518 kAsciiDataHintTag | kShortExternalStringTag,
519 SHORT_EXTERNAL_ASCII_SYMBOL_TYPE = kAsciiStringTag | kExternalStringTag |
520 kSymbolTag | kShortExternalStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000521 EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag,
522 EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
523 kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000524 EXTERNAL_ASCII_SYMBOL_TYPE =
525 kAsciiStringTag | kSymbolTag | kExternalStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000526 STRING_TYPE = kTwoByteStringTag | kSeqStringTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000527 ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000528 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag,
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000529 CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag,
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000530 SLICED_STRING_TYPE = kTwoByteStringTag | kSlicedStringTag,
531 SLICED_ASCII_STRING_TYPE = kAsciiStringTag | kSlicedStringTag,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000532 SHORT_EXTERNAL_STRING_TYPE =
533 kTwoByteStringTag | kExternalStringTag | kShortExternalStringTag,
534 SHORT_EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
535 kTwoByteStringTag | kExternalStringTag |
536 kAsciiDataHintTag | kShortExternalStringTag,
537 SHORT_EXTERNAL_ASCII_STRING_TYPE =
538 kAsciiStringTag | kExternalStringTag | kShortExternalStringTag,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000539 EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag,
540 EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
541 kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag,
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000542 // LAST_STRING_TYPE
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000543 EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag,
544 PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000545
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000546 // Objects allocated in their own spaces (never in new space).
547 MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000548 CODE_TYPE,
549 ODDBALL_TYPE,
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000550 JS_GLOBAL_PROPERTY_CELL_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000551
552 // "Data", objects that cannot contain non-map-word pointers to heap
553 // objects.
554 HEAP_NUMBER_TYPE,
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000555 FOREIGN_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000556 BYTE_ARRAY_TYPE,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000557 FREE_SPACE_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000558 EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE
ager@chromium.org3811b432009-10-28 14:53:37 +0000559 EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
560 EXTERNAL_SHORT_ARRAY_TYPE,
561 EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
562 EXTERNAL_INT_ARRAY_TYPE,
563 EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000564 EXTERNAL_FLOAT_ARRAY_TYPE,
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000565 EXTERNAL_DOUBLE_ARRAY_TYPE,
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000566 EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000567 FIXED_DOUBLE_ARRAY_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000568 FILLER_TYPE, // LAST_DATA_TYPE
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000569
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000570 // Structs.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000571 ACCESSOR_INFO_TYPE,
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +0000572 ACCESSOR_PAIR_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000573 ACCESS_CHECK_INFO_TYPE,
574 INTERCEPTOR_INFO_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000575 CALL_HANDLER_INFO_TYPE,
576 FUNCTION_TEMPLATE_INFO_TYPE,
577 OBJECT_TEMPLATE_INFO_TYPE,
578 SIGNATURE_INFO_TYPE,
579 TYPE_SWITCH_INFO_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000580 SCRIPT_TYPE,
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000581 CODE_CACHE_TYPE,
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000582 POLYMORPHIC_CODE_CACHE_TYPE,
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000583 TYPE_FEEDBACK_INFO_TYPE,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +0000584 ALIASED_ARGUMENTS_ENTRY_TYPE,
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000585 // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT
586 // is defined. However as include/v8.h contain some of the instance type
587 // constants always having them avoids them getting different numbers
588 // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000589 DEBUG_INFO_TYPE,
590 BREAK_POINT_INFO_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000591
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000592 FIXED_ARRAY_TYPE,
593 SHARED_FUNCTION_INFO_TYPE,
594
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000595 JS_MESSAGE_OBJECT_TYPE,
596
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000597 // All the following types are subtypes of JSReceiver, which corresponds to
598 // objects in the JS sense. The first and the last type in this range are
599 // the two forms of function. This organization enables using the same
600 // compares for checking the JS_RECEIVER/SPEC_OBJECT range and the
601 // NONCALLABLE_JS_OBJECT range.
602 JS_FUNCTION_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE, FIRST_JS_PROXY_TYPE
603 JS_PROXY_TYPE, // LAST_JS_PROXY_TYPE
604
605 JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000606 JS_DATE_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000607 JS_OBJECT_TYPE,
ager@chromium.org32912102009-01-16 10:38:43 +0000608 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000609 JS_MODULE_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000610 JS_GLOBAL_OBJECT_TYPE,
611 JS_BUILTINS_OBJECT_TYPE,
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000612 JS_GLOBAL_PROXY_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000613 JS_ARRAY_TYPE,
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000614 JS_SET_TYPE,
615 JS_MAP_TYPE,
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000616 JS_WEAK_MAP_TYPE,
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000617
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000618 JS_REGEXP_TYPE,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000619
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000620 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000621
622 // Pseudo-types
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000623 FIRST_TYPE = 0x0,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000624 LAST_TYPE = JS_FUNCTION_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000625 INVALID_TYPE = FIRST_TYPE - 1,
626 FIRST_NONSTRING_TYPE = MAP_TYPE,
627 // Boundaries for testing for an external array.
628 FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE,
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000629 LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE,
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000630 // Boundary for promotion to old data space/old pointer space.
631 LAST_DATA_TYPE = FILLER_TYPE,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000632 // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy).
633 // Note that there is no range for JSObject or JSProxy, since their subtypes
634 // are not continuous in this enum! The enum ranges instead reflect the
635 // external class names, where proxies are treated as either ordinary objects,
636 // or functions.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000637 FIRST_JS_RECEIVER_TYPE = JS_FUNCTION_PROXY_TYPE,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000638 LAST_JS_RECEIVER_TYPE = LAST_TYPE,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000639 // Boundaries for testing the types represented as JSObject
640 FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE,
641 LAST_JS_OBJECT_TYPE = LAST_TYPE,
642 // Boundaries for testing the types represented as JSProxy
643 FIRST_JS_PROXY_TYPE = JS_FUNCTION_PROXY_TYPE,
644 LAST_JS_PROXY_TYPE = JS_PROXY_TYPE,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000645 // Boundaries for testing whether the type is a JavaScript object.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000646 FIRST_SPEC_OBJECT_TYPE = FIRST_JS_RECEIVER_TYPE,
647 LAST_SPEC_OBJECT_TYPE = LAST_JS_RECEIVER_TYPE,
648 // Boundaries for testing the types for which typeof is "object".
649 FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_PROXY_TYPE,
650 LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE,
651 // Note that the types for which typeof is "function" are not continuous.
652 // Define this so that we can put assertions on discrete checks.
653 NUM_OF_CALLABLE_SPEC_OBJECT_TYPES = 2
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000654};
655
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +0000656const int kExternalArrayTypeCount =
657 LAST_EXTERNAL_ARRAY_TYPE - FIRST_EXTERNAL_ARRAY_TYPE + 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000658
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000659STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType);
660STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType);
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +0000661STATIC_CHECK(ODDBALL_TYPE == Internals::kOddballType);
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000662STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType);
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +0000663
664
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000665enum CompareResult {
666 LESS = -1,
667 EQUAL = 0,
668 GREATER = 1,
669
670 NOT_EQUAL = GREATER
671};
672
673
674#define DECL_BOOLEAN_ACCESSORS(name) \
675 inline bool name(); \
676 inline void set_##name(bool value); \
677
678
ager@chromium.org32912102009-01-16 10:38:43 +0000679#define DECL_ACCESSORS(name, type) \
680 inline type* name(); \
681 inline void set_##name(type* value, \
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000682 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000683
684
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000685class AccessorPair;
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000686class DictionaryElementsAccessor;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000687class ElementsAccessor;
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +0000688class Failure;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000689class FixedArrayBase;
690class ObjectVisitor;
691class StringStream;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000692
693struct ValueInfo : public Malloced {
694 ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { }
695 InstanceType type;
696 Object* ptr;
697 const char* str;
698 double number;
699};
700
701
702// A template-ized version of the IsXXX functions.
703template <class C> static inline bool Is(Object* obj);
704
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000705
lrn@chromium.org303ada72010-10-27 09:33:13 +0000706class MaybeObject BASE_EMBEDDED {
707 public:
708 inline bool IsFailure();
709 inline bool IsRetryAfterGC();
710 inline bool IsOutOfMemory();
711 inline bool IsException();
712 INLINE(bool IsTheHole());
713 inline bool ToObject(Object** obj) {
714 if (IsFailure()) return false;
715 *obj = reinterpret_cast<Object*>(this);
716 return true;
717 }
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000718 inline Failure* ToFailureUnchecked() {
719 ASSERT(IsFailure());
720 return reinterpret_cast<Failure*>(this);
721 }
lrn@chromium.org303ada72010-10-27 09:33:13 +0000722 inline Object* ToObjectUnchecked() {
723 ASSERT(!IsFailure());
724 return reinterpret_cast<Object*>(this);
725 }
726 inline Object* ToObjectChecked() {
727 CHECK(!IsFailure());
728 return reinterpret_cast<Object*>(this);
729 }
730
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000731 template<typename T>
732 inline bool To(T** obj) {
733 if (IsFailure()) return false;
734 *obj = T::cast(reinterpret_cast<Object*>(this));
735 return true;
736 }
737
whesse@chromium.org023421e2010-12-21 12:19:12 +0000738#ifdef OBJECT_PRINT
lrn@chromium.org303ada72010-10-27 09:33:13 +0000739 // Prints this object with details.
whesse@chromium.org023421e2010-12-21 12:19:12 +0000740 inline void Print() {
741 Print(stdout);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000742 }
whesse@chromium.org023421e2010-12-21 12:19:12 +0000743 inline void PrintLn() {
744 PrintLn(stdout);
745 }
746 void Print(FILE* out);
747 void PrintLn(FILE* out);
748#endif
749#ifdef DEBUG
lrn@chromium.org303ada72010-10-27 09:33:13 +0000750 // Verifies the object.
751 void Verify();
752#endif
753};
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000754
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000755
756#define OBJECT_TYPE_LIST(V) \
757 V(Smi) \
758 V(HeapObject) \
759 V(Number) \
760
761#define HEAP_OBJECT_TYPE_LIST(V) \
762 V(HeapNumber) \
763 V(String) \
764 V(Symbol) \
765 V(SeqString) \
766 V(ExternalString) \
767 V(ConsString) \
ricow@chromium.org4668a2c2011-08-29 10:41:00 +0000768 V(SlicedString) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000769 V(ExternalTwoByteString) \
770 V(ExternalAsciiString) \
771 V(SeqTwoByteString) \
772 V(SeqAsciiString) \
773 \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000774 V(ExternalArray) \
775 V(ExternalByteArray) \
776 V(ExternalUnsignedByteArray) \
777 V(ExternalShortArray) \
778 V(ExternalUnsignedShortArray) \
779 V(ExternalIntArray) \
780 V(ExternalUnsignedIntArray) \
781 V(ExternalFloatArray) \
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +0000782 V(ExternalDoubleArray) \
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +0000783 V(ExternalPixelArray) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000784 V(ByteArray) \
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000785 V(FreeSpace) \
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000786 V(JSReceiver) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000787 V(JSObject) \
788 V(JSContextExtensionObject) \
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000789 V(JSModule) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000790 V(Map) \
791 V(DescriptorArray) \
yangguo@chromium.org99aa4902012-07-06 16:21:55 +0000792 V(TransitionArray) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000793 V(DeoptimizationInputData) \
794 V(DeoptimizationOutputData) \
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000795 V(TypeFeedbackCells) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000796 V(FixedArray) \
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000797 V(FixedDoubleArray) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000798 V(Context) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000799 V(GlobalContext) \
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000800 V(ModuleContext) \
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000801 V(ScopeInfo) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000802 V(JSFunction) \
803 V(Code) \
804 V(Oddball) \
805 V(SharedFunctionInfo) \
806 V(JSValue) \
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000807 V(JSDate) \
kmillikin@chromium.org31b12772011-02-02 16:08:26 +0000808 V(JSMessageObject) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000809 V(StringWrapper) \
ager@chromium.orgea91cc52011-05-23 06:06:11 +0000810 V(Foreign) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000811 V(Boolean) \
812 V(JSArray) \
vegorov@chromium.org7304bca2011-05-16 12:14:13 +0000813 V(JSProxy) \
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000814 V(JSFunctionProxy) \
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000815 V(JSSet) \
816 V(JSMap) \
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +0000817 V(JSWeakMap) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000818 V(JSRegExp) \
819 V(HashTable) \
820 V(Dictionary) \
821 V(SymbolTable) \
822 V(JSFunctionResultCache) \
823 V(NormalizedMapCache) \
824 V(CompilationCacheTable) \
825 V(CodeCacheHashTable) \
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000826 V(PolymorphicCodeCacheHashTable) \
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000827 V(MapCache) \
828 V(Primitive) \
829 V(GlobalObject) \
830 V(JSGlobalObject) \
831 V(JSBuiltinsObject) \
832 V(JSGlobalProxy) \
833 V(UndetectableObject) \
834 V(AccessCheckNeeded) \
835 V(JSGlobalPropertyCell) \
836
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000837
838class JSReceiver;
839
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000840// Object is the abstract superclass for all classes in the
841// object hierarchy.
842// Object does not use any virtual functions to avoid the
843// allocation of the C++ vtable.
844// Since Smi and Failure are subclasses of Object no
845// data members can be present in Object.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000846class Object : public MaybeObject {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000847 public:
848 // Type testing.
erik.corry@gmail.combbceb572012-03-09 10:52:05 +0000849 bool IsObject() { return true; }
850
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000851#define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_();
852 OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
853 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
854#undef IS_TYPE_FUNCTION_DECL
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000855
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000856 inline bool IsFixedArrayBase();
857
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000858 // Returns true if this object is an instance of the specified
859 // function template.
sgjesse@chromium.org900d3b72009-08-07 11:24:25 +0000860 inline bool IsInstanceOf(FunctionTemplateInfo* type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000861
862 inline bool IsStruct();
863#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name();
864 STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
865#undef DECLARE_STRUCT_PREDICATE
866
ricow@chromium.org9fa09672011-07-25 11:05:35 +0000867 INLINE(bool IsSpecObject());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000868 INLINE(bool IsSpecFunction());
ricow@chromium.org9fa09672011-07-25 11:05:35 +0000869
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000870 // Oddball testing.
871 INLINE(bool IsUndefined());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000872 INLINE(bool IsNull());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000873 INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000874 INLINE(bool IsTrue());
875 INLINE(bool IsFalse());
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +0000876 inline bool IsArgumentsMarker();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000877 inline bool NonFailureIsHeapObject();
878
879 // Filler objects (fillers and free space objects).
880 inline bool IsFiller();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000881
882 // Extract the number.
883 inline double Number();
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000884 inline bool IsNaN();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000885
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000886 // Returns true if the object is of the correct type to be used as a
887 // implementation of a JSObject's elements.
888 inline bool HasValidElements();
889
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000890 inline bool HasSpecificClassOf(String* name);
891
lrn@chromium.org303ada72010-10-27 09:33:13 +0000892 MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9.
893 Object* ToBoolean(); // ECMA-262 9.2.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000894
895 // Convert to a JSObject if needed.
896 // global_context is used when creating wrapper object.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000897 MUST_USE_RESULT MaybeObject* ToObject(Context* global_context);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000898
899 // Converts this to a Smi if possible.
900 // Failure is returned otherwise.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000901 MUST_USE_RESULT inline MaybeObject* ToSmi();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000902
903 void Lookup(String* name, LookupResult* result);
904
905 // Property access.
lrn@chromium.org303ada72010-10-27 09:33:13 +0000906 MUST_USE_RESULT inline MaybeObject* GetProperty(String* key);
907 MUST_USE_RESULT inline MaybeObject* GetProperty(
908 String* key,
909 PropertyAttributes* attributes);
910 MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver(
911 Object* receiver,
912 String* key,
913 PropertyAttributes* attributes);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000914
915 static Handle<Object> GetProperty(Handle<Object> object,
916 Handle<Object> receiver,
917 LookupResult* result,
918 Handle<String> key,
919 PropertyAttributes* attributes);
920
lrn@chromium.org303ada72010-10-27 09:33:13 +0000921 MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver,
922 LookupResult* result,
923 String* key,
924 PropertyAttributes* attributes);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000925
lrn@chromium.org303ada72010-10-27 09:33:13 +0000926 MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000927 JSReceiver* getter);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000928
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000929 static Handle<Object> GetElement(Handle<Object> object, uint32_t index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000930 MUST_USE_RESULT inline MaybeObject* GetElement(uint32_t index);
lrn@chromium.org303ada72010-10-27 09:33:13 +0000931 // For use when we know that no exception can be thrown.
932 inline Object* GetElementNoExceptionThrown(uint32_t index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000933 MUST_USE_RESULT MaybeObject* GetElementWithReceiver(Object* receiver,
934 uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000935
936 // Return the object's prototype (might be Heap::null_value()).
937 Object* GetPrototype();
938
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000939 // Returns the permanent hash code associated with this object depending on
940 // the actual object type. Might return a failure in case no hash was
941 // created yet or GC was caused by creation.
942 MUST_USE_RESULT MaybeObject* GetHash(CreationFlag flag);
943
944 // Checks whether this object has the same value as the given one. This
945 // function is implemented according to ES5, section 9.12 and can be used
946 // to implement the Harmony "egal" function.
947 bool SameValue(Object* other);
948
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000949 // Tries to convert an object to an array index. Returns true and sets
950 // the output parameter if it succeeds.
951 inline bool ToArrayIndex(uint32_t* index);
952
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000953 // Returns true if this is a JSValue containing a string and the index is
954 // < the length of the string. Used to implement [] on strings.
955 inline bool IsStringObjectWithCharacterAt(uint32_t index);
956
957#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000958 // Verify a pointer is a valid object pointer.
959 static void VerifyPointer(Object* p);
960#endif
961
962 // Prints this object without details.
whesse@chromium.org023421e2010-12-21 12:19:12 +0000963 inline void ShortPrint() {
964 ShortPrint(stdout);
965 }
966 void ShortPrint(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000967
968 // Prints this object without details to a message accumulator.
969 void ShortPrint(StringStream* accumulator);
970
971 // Casting: This cast is only needed to satisfy macros in objects-inl.h.
972 static Object* cast(Object* value) { return value; }
973
974 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +0000975 static const int kHeaderSize = 0; // Object does not take up any space.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000976
977 private:
978 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
979};
980
981
982// Smi represents integer Numbers that can be stored in 31 bits.
983// Smis are immediate which means they are NOT allocated in the heap.
ager@chromium.org4af710e2009-09-15 12:20:11 +0000984// The this pointer has the following format: [31 bit signed int] 0
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000985// For long smis it has the following format:
986// [32 bit signed int] [31 bits zero padding] 0
987// Smi stands for small integer.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000988class Smi: public Object {
989 public:
990 // Returns the integer value.
991 inline int value();
992
993 // Convert a value to a Smi object.
994 static inline Smi* FromInt(int value);
995
ager@chromium.org9085a012009-05-11 19:22:57 +0000996 static inline Smi* FromIntptr(intptr_t value);
997
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +0000998 // Returns whether value can be represented in a Smi.
ager@chromium.orgab99eea2009-08-25 07:05:41 +0000999 static inline bool IsValid(intptr_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001000
1001 // Casting.
1002 static inline Smi* cast(Object* object);
1003
1004 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00001005 inline void SmiPrint() {
1006 SmiPrint(stdout);
1007 }
1008 void SmiPrint(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001009 void SmiPrint(StringStream* accumulator);
1010#ifdef DEBUG
1011 void SmiVerify();
1012#endif
1013
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001014 static const int kMinValue =
1015 (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001016 static const int kMaxValue = -(kMinValue + 1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001017
1018 private:
1019 DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);
1020};
1021
1022
ager@chromium.org6f10e412009-02-13 10:11:16 +00001023// Failure is used for reporting out of memory situations and
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001024// propagating exceptions through the runtime system. Failure objects
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001025// are transient and cannot occur as part of the object graph.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001026//
1027// Failures are a single word, encoded as follows:
1028// +-------------------------+---+--+--+
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00001029// |.........unused..........|sss|tt|11|
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001030// +-------------------------+---+--+--+
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001031// 7 6 4 32 10
1032//
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001033//
1034// The low two bits, 0-1, are the failure tag, 11. The next two bits,
1035// 2-3, are a failure type tag 'tt' with possible values:
1036// 00 RETRY_AFTER_GC
1037// 01 EXCEPTION
1038// 10 INTERNAL_ERROR
1039// 11 OUT_OF_MEMORY_EXCEPTION
1040//
1041// The next three bits, 4-6, are an allocation space tag 'sss'. The
1042// allocation space tag is 000 for all failure types except
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001043// RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the
1044// allocation spaces (the encoding is found in globals.h).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001045
1046// Failure type tag info.
1047const int kFailureTypeTagSize = 2;
1048const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1;
1049
lrn@chromium.org303ada72010-10-27 09:33:13 +00001050class Failure: public MaybeObject {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001051 public:
1052 // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code.
1053 enum Type {
1054 RETRY_AFTER_GC = 0,
1055 EXCEPTION = 1, // Returning this marker tells the real exception
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001056 // is in Isolate::pending_exception.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001057 INTERNAL_ERROR = 2,
1058 OUT_OF_MEMORY_EXCEPTION = 3
1059 };
1060
1061 inline Type type() const;
1062
1063 // Returns the space that needs to be collected for RetryAfterGC failures.
1064 inline AllocationSpace allocation_space() const;
1065
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001066 inline bool IsInternalError() const;
1067 inline bool IsOutOfMemoryException() const;
1068
whesse@chromium.org4a5224e2010-10-20 12:37:07 +00001069 static inline Failure* RetryAfterGC(AllocationSpace space);
1070 static inline Failure* RetryAfterGC(); // NEW_SPACE
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001071 static inline Failure* Exception();
1072 static inline Failure* InternalError();
1073 static inline Failure* OutOfMemoryException();
1074 // Casting.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001075 static inline Failure* cast(MaybeObject* object);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001076
1077 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00001078 inline void FailurePrint() {
1079 FailurePrint(stdout);
1080 }
1081 void FailurePrint(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001082 void FailurePrint(StringStream* accumulator);
1083#ifdef DEBUG
1084 void FailureVerify();
1085#endif
1086
1087 private:
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00001088 inline intptr_t value() const;
1089 static inline Failure* Construct(Type type, intptr_t value = 0);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001090
1091 DISALLOW_IMPLICIT_CONSTRUCTORS(Failure);
1092};
1093
1094
kasper.lund7276f142008-07-30 08:49:36 +00001095// Heap objects typically have a map pointer in their first word. However,
ulan@chromium.org2efb9002012-01-19 15:36:35 +00001096// during GC other data (e.g. mark bits, forwarding addresses) is sometimes
kasper.lund7276f142008-07-30 08:49:36 +00001097// encoded in the first word. The class MapWord is an abstraction of the
1098// value in a heap object's first word.
1099class MapWord BASE_EMBEDDED {
1100 public:
1101 // Normal state: the map word contains a map pointer.
1102
1103 // Create a map word from a map pointer.
1104 static inline MapWord FromMap(Map* map);
1105
1106 // View this map word as a map pointer.
1107 inline Map* ToMap();
1108
1109
1110 // Scavenge collection: the map word of live objects in the from space
1111 // contains a forwarding address (a heap object pointer in the to space).
1112
1113 // True if this map word is a forwarding address for a scavenge
1114 // collection. Only valid during a scavenge collection (specifically,
ulan@chromium.org2efb9002012-01-19 15:36:35 +00001115 // when all map words are heap object pointers, i.e. not during a full GC).
kasper.lund7276f142008-07-30 08:49:36 +00001116 inline bool IsForwardingAddress();
1117
1118 // Create a map word from a forwarding address.
1119 static inline MapWord FromForwardingAddress(HeapObject* object);
1120
1121 // View this map word as a forwarding address.
1122 inline HeapObject* ToForwardingAddress();
1123
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001124 static inline MapWord FromRawValue(uintptr_t value) {
1125 return MapWord(value);
1126 }
kasper.lund7276f142008-07-30 08:49:36 +00001127
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001128 inline uintptr_t ToRawValue() {
1129 return value_;
1130 }
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00001131
1132 private:
1133 // HeapObject calls the private constructor and directly reads the value.
1134 friend class HeapObject;
1135
1136 explicit MapWord(uintptr_t value) : value_(value) {}
1137
1138 uintptr_t value_;
kasper.lund7276f142008-07-30 08:49:36 +00001139};
1140
1141
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001142// HeapObject is the superclass for all classes describing heap allocated
1143// objects.
1144class HeapObject: public Object {
1145 public:
kasper.lund7276f142008-07-30 08:49:36 +00001146 // [map]: Contains a map which contains the object's reflective
1147 // information.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001148 inline Map* map();
1149 inline void set_map(Map* value);
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001150 // The no-write-barrier version. This is OK if the object is white and in
1151 // new space, or if the value is an immortal immutable object, like the maps
1152 // of primitive (non-JS) objects like strings, heap numbers etc.
1153 inline void set_map_no_write_barrier(Map* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001154
kasper.lund7276f142008-07-30 08:49:36 +00001155 // During garbage collection, the map word of a heap object does not
1156 // necessarily contain a map pointer.
1157 inline MapWord map_word();
1158 inline void set_map_word(MapWord map_word);
1159
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001160 // The Heap the object was allocated in. Used also to access Isolate.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001161 inline Heap* GetHeap();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001162
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001163 // Convenience method to get current isolate. This method can be
1164 // accessed only when its result is the same as
1165 // Isolate::Current(), it ASSERTs this. See also comment for GetHeap.
1166 inline Isolate* GetIsolate();
1167
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001168 // Converts an address to a HeapObject pointer.
1169 static inline HeapObject* FromAddress(Address address);
1170
1171 // Returns the address of this HeapObject.
1172 inline Address address();
1173
1174 // Iterates over pointers contained in the object (including the Map)
1175 void Iterate(ObjectVisitor* v);
1176
1177 // Iterates over all pointers contained in the object except the
1178 // first map pointer. The object type is given in the first
1179 // parameter. This function does not access the map pointer in the
1180 // object, and so is safe to call while the map pointer is modified.
1181 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1182
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001183 // Returns the heap object's size in bytes
1184 inline int Size();
1185
1186 // Given a heap object's map pointer, returns the heap size in bytes
1187 // Useful when the map pointer field is used for other purposes.
1188 // GC internal.
1189 inline int SizeFromMap(Map* map);
1190
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +00001191 // Returns the field at offset in obj, as a read/write Object* reference.
1192 // Does no checking, and is safe to use during GC, while maps are invalid.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00001193 // Does not invoke write barrier, so should only be assigned to
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +00001194 // during marking GC.
1195 static inline Object** RawField(HeapObject* obj, int offset);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001196
1197 // Casting.
1198 static inline HeapObject* cast(Object* obj);
1199
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001200 // Return the write barrier mode for this. Callers of this function
1201 // must be able to present a reference to an AssertNoAllocation
1202 // object as a sign that they are not going to use this function
1203 // from code that allocates and thus invalidates the returned write
1204 // barrier mode.
1205 inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00001206
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001207 // Dispatched behavior.
1208 void HeapObjectShortPrint(StringStream* accumulator);
whesse@chromium.org023421e2010-12-21 12:19:12 +00001209#ifdef OBJECT_PRINT
1210 inline void HeapObjectPrint() {
1211 HeapObjectPrint(stdout);
1212 }
1213 void HeapObjectPrint(FILE* out);
whesse@chromium.org023421e2010-12-21 12:19:12 +00001214 void PrintHeader(FILE* out, const char* id);
1215#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001216
whesse@chromium.org023421e2010-12-21 12:19:12 +00001217#ifdef DEBUG
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001218 void HeapObjectVerify();
1219 inline void VerifyObjectField(int offset);
1220 inline void VerifySmiField(int offset);
1221
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001222 // Verify a pointer is a valid HeapObject pointer that points to object
1223 // areas in the heap.
1224 static void VerifyHeapPointer(Object* p);
1225#endif
1226
1227 // Layout description.
1228 // First field in a heap object is map.
ager@chromium.org236ad962008-09-25 09:45:57 +00001229 static const int kMapOffset = Object::kHeaderSize;
1230 static const int kHeaderSize = kMapOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001231
ager@chromium.org18ad94b2009-09-02 08:22:29 +00001232 STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset);
1233
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001234 protected:
1235 // helpers for calling an ObjectVisitor to iterate over pointers in the
1236 // half-open range [start, end) specified as integer offsets
1237 inline void IteratePointers(ObjectVisitor* v, int start, int end);
1238 // as above, for the single element at "offset"
1239 inline void IteratePointer(ObjectVisitor* v, int offset);
1240
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001241 private:
1242 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1243};
1244
1245
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00001246#define SLOT_ADDR(obj, offset) \
1247 reinterpret_cast<Object**>((obj)->address() + offset)
1248
1249// This class describes a body of an object of a fixed size
1250// in which all pointer fields are located in the [start_offset, end_offset)
1251// interval.
1252template<int start_offset, int end_offset, int size>
1253class FixedBodyDescriptor {
1254 public:
1255 static const int kStartOffset = start_offset;
1256 static const int kEndOffset = end_offset;
1257 static const int kSize = size;
1258
1259 static inline void IterateBody(HeapObject* obj, ObjectVisitor* v);
1260
1261 template<typename StaticVisitor>
1262 static inline void IterateBody(HeapObject* obj) {
1263 StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset),
1264 SLOT_ADDR(obj, end_offset));
1265 }
1266};
1267
1268
1269// This class describes a body of an object of a variable size
1270// in which all pointer fields are located in the [start_offset, object_size)
1271// interval.
1272template<int start_offset>
1273class FlexibleBodyDescriptor {
1274 public:
1275 static const int kStartOffset = start_offset;
1276
1277 static inline void IterateBody(HeapObject* obj,
1278 int object_size,
1279 ObjectVisitor* v);
1280
1281 template<typename StaticVisitor>
1282 static inline void IterateBody(HeapObject* obj, int object_size) {
1283 StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset),
1284 SLOT_ADDR(obj, object_size));
1285 }
1286};
1287
1288#undef SLOT_ADDR
1289
1290
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001291// The HeapNumber class describes heap allocated numbers that cannot be
1292// represented in a Smi (small integer)
1293class HeapNumber: public HeapObject {
1294 public:
1295 // [value]: number value.
1296 inline double value();
1297 inline void set_value(double value);
1298
1299 // Casting.
1300 static inline HeapNumber* cast(Object* obj);
1301
1302 // Dispatched behavior.
1303 Object* HeapNumberToBoolean();
whesse@chromium.org023421e2010-12-21 12:19:12 +00001304 inline void HeapNumberPrint() {
1305 HeapNumberPrint(stdout);
1306 }
1307 void HeapNumberPrint(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001308 void HeapNumberPrint(StringStream* accumulator);
1309#ifdef DEBUG
1310 void HeapNumberVerify();
1311#endif
1312
whesse@chromium.orgcec079d2010-03-22 14:44:04 +00001313 inline int get_exponent();
1314 inline int get_sign();
1315
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001316 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00001317 static const int kValueOffset = HeapObject::kHeaderSize;
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001318 // IEEE doubles are two 32 bit words. The first is just mantissa, the second
1319 // is a mixture of sign, exponent and mantissa. Our current platforms are all
1320 // little endian apart from non-EABI arm which is little endian with big
1321 // endian floating point word ordering!
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001322 static const int kMantissaOffset = kValueOffset;
1323 static const int kExponentOffset = kValueOffset + 4;
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001324
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001325 static const int kSize = kValueOffset + kDoubleSize;
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001326 static const uint32_t kSignMask = 0x80000000u;
1327 static const uint32_t kExponentMask = 0x7ff00000u;
1328 static const uint32_t kMantissaMask = 0xfffffu;
ager@chromium.orgac091b72010-05-05 07:34:42 +00001329 static const int kMantissaBits = 52;
whesse@chromium.org2c186ca2010-06-16 11:32:39 +00001330 static const int kExponentBits = 11;
ager@chromium.orgeadaf222009-06-16 09:43:10 +00001331 static const int kExponentBias = 1023;
1332 static const int kExponentShift = 20;
1333 static const int kMantissaBitsInTopWord = 20;
1334 static const int kNonMantissaBitsInTopWord = 12;
1335
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001336 private:
1337 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
1338};
1339
1340
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001341enum EnsureElementsMode {
1342 DONT_ALLOW_DOUBLE_ELEMENTS,
1343 ALLOW_COPIED_DOUBLE_ELEMENTS,
1344 ALLOW_CONVERTED_DOUBLE_ELEMENTS
1345};
1346
1347
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001348// Indicates whether a property should be set or (re)defined. Setting of a
1349// property causes attributes to remain unchanged, writability to be checked
1350// and callbacks to be called. Defining of a property causes attributes to
1351// be updated and callbacks to be overridden.
1352enum SetPropertyMode {
1353 SET_PROPERTY,
1354 DEFINE_PROPERTY
1355};
1356
1357
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00001358// Indicator for one component of an AccessorPair.
1359enum AccessorComponent {
1360 ACCESSOR_GETTER,
1361 ACCESSOR_SETTER
1362};
1363
1364
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001365// JSReceiver includes types on which properties can be defined, i.e.,
1366// JSObject and JSProxy.
1367class JSReceiver: public HeapObject {
1368 public:
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001369 enum DeleteMode {
1370 NORMAL_DELETION,
1371 STRICT_DELETION,
1372 FORCE_DELETION
1373 };
1374
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001375 // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
1376 // a keyed store is of the form a[expression] = foo.
1377 enum StoreFromKeyed {
1378 MAY_BE_STORE_FROM_KEYED,
1379 CERTAINLY_NOT_STORE_FROM_KEYED
1380 };
1381
mstarzinger@chromium.orgccab3672012-06-14 15:01:16 +00001382 // Internal properties (e.g. the hidden properties dictionary) might
1383 // be added even though the receiver is non-extensible.
1384 enum ExtensibilityCheck {
1385 PERFORM_EXTENSIBILITY_CHECK,
1386 OMIT_EXTENSIBILITY_CHECK
1387 };
1388
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001389 // Casting.
1390 static inline JSReceiver* cast(Object* obj);
1391
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001392 static Handle<Object> SetProperty(Handle<JSReceiver> object,
1393 Handle<String> key,
1394 Handle<Object> value,
1395 PropertyAttributes attributes,
1396 StrictModeFlag strict_mode);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001397 // Can cause GC.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001398 MUST_USE_RESULT MaybeObject* SetProperty(
1399 String* key,
1400 Object* value,
1401 PropertyAttributes attributes,
1402 StrictModeFlag strict_mode,
1403 StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED);
1404 MUST_USE_RESULT MaybeObject* SetProperty(
1405 LookupResult* result,
1406 String* key,
1407 Object* value,
1408 PropertyAttributes attributes,
1409 StrictModeFlag strict_mode,
1410 StoreFromKeyed store_from_keyed = MAY_BE_STORE_FROM_KEYED);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001411 MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSReceiver* setter,
1412 Object* value);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001413
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001414 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001415 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1416
1417 // Set the index'th array element.
1418 // Can cause GC, or return failure if GC is required.
1419 MUST_USE_RESULT MaybeObject* SetElement(uint32_t index,
1420 Object* value,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001421 PropertyAttributes attributes,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001422 StrictModeFlag strict_mode,
1423 bool check_prototype);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00001424
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001425 // Tests for the fast common case for property enumeration.
1426 bool IsSimpleEnum();
1427
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001428 // Returns the class name ([[Class]] property in the specification).
1429 String* class_name();
1430
1431 // Returns the constructor name (the name (possibly, inferred name) of the
1432 // function that was used to instantiate the object).
1433 String* constructor_name();
1434
1435 inline PropertyAttributes GetPropertyAttribute(String* name);
1436 PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver,
1437 String* name);
1438 PropertyAttributes GetLocalPropertyAttribute(String* name);
1439
1440 // Can cause a GC.
rossberg@chromium.org717967f2011-07-20 13:44:42 +00001441 inline bool HasProperty(String* name);
1442 inline bool HasLocalProperty(String* name);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001443 inline bool HasElement(uint32_t index);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001444
1445 // Return the object's prototype (might be Heap::null_value()).
1446 inline Object* GetPrototype();
1447
yangguo@chromium.orgc74d6742012-06-29 15:15:45 +00001448 // Return the constructor function (may be Heap::null_value()).
1449 inline Object* GetConstructor();
1450
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001451 // Set the object's prototype (only JSReceiver and null are allowed).
1452 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value,
1453 bool skip_hidden_prototypes);
1454
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001455 // Retrieves a permanent object identity hash code. The undefined value might
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001456 // be returned in case no hash was created yet and OMIT_CREATION was used.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001457 inline MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1458
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001459 // Lookup a property. If found, the result is valid and has
1460 // detailed information.
1461 void LocalLookup(String* name, LookupResult* result);
1462 void Lookup(String* name, LookupResult* result);
1463
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001464 protected:
1465 Smi* GenerateIdentityHash();
1466
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001467 private:
1468 PropertyAttributes GetPropertyAttribute(JSReceiver* receiver,
1469 LookupResult* result,
1470 String* name,
1471 bool continue_search);
1472
1473 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver);
1474};
1475
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001476// The JSObject describes real heap allocated JavaScript objects with
1477// properties.
1478// Note that the map of JSObject changes during execution to enable inline
1479// caching.
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001480class JSObject: public JSReceiver {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001481 public:
1482 // [properties]: Backing storage for properties.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00001483 // properties is a FixedArray in the fast case and a Dictionary in the
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001484 // slow case.
1485 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001486 inline void initialize_properties();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001487 inline bool HasFastProperties();
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00001488 inline StringDictionary* property_dictionary(); // Gets slow properties.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001489
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001490 // [elements]: The elements (properties with names that are integers).
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001491 //
1492 // Elements can be in two general modes: fast and slow. Each mode
1493 // corrensponds to a set of object representations of elements that
1494 // have something in common.
1495 //
1496 // In the fast mode elements is a FixedArray and so each element can
1497 // be quickly accessed. This fact is used in the generated code. The
whesse@chromium.org7b260152011-06-20 15:33:18 +00001498 // elements array can have one of three maps in this mode:
1499 // fixed_array_map, non_strict_arguments_elements_map or
1500 // fixed_cow_array_map (for copy-on-write arrays). In the latter case
1501 // the elements array may be shared by a few objects and so before
1502 // writing to any element the array must be copied. Use
1503 // EnsureWritableFastElements in this case.
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00001504 //
whesse@chromium.org7b260152011-06-20 15:33:18 +00001505 // In the slow mode the elements is either a NumberDictionary, an
1506 // ExternalArray, or a FixedArray parameter map for a (non-strict)
1507 // arguments object.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001508 DECL_ACCESSORS(elements, FixedArrayBase)
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001509 inline void initialize_elements();
lrn@chromium.org303ada72010-10-27 09:33:13 +00001510 MUST_USE_RESULT inline MaybeObject* ResetElements();
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001511 inline ElementsKind GetElementsKind();
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00001512 inline ElementsAccessor* GetElementsAccessor();
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001513 // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind.
1514 inline bool HasFastSmiElements();
1515 // Returns true if an object has elements of FAST_ELEMENTS ElementsKind.
1516 inline bool HasFastObjectElements();
1517 // Returns true if an object has elements of FAST_ELEMENTS or
1518 // FAST_SMI_ONLY_ELEMENTS.
1519 inline bool HasFastSmiOrObjectElements();
1520 // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS
1521 // ElementsKind.
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001522 inline bool HasFastDoubleElements();
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001523 // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS
1524 // ElementsKind.
1525 inline bool HasFastHoleyElements();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001526 inline bool HasNonStrictArgumentsElements();
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001527 inline bool HasDictionaryElements();
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00001528 inline bool HasExternalPixelElements();
ager@chromium.org3811b432009-10-28 14:53:37 +00001529 inline bool HasExternalArrayElements();
1530 inline bool HasExternalByteElements();
1531 inline bool HasExternalUnsignedByteElements();
1532 inline bool HasExternalShortElements();
1533 inline bool HasExternalUnsignedShortElements();
1534 inline bool HasExternalIntElements();
1535 inline bool HasExternalUnsignedIntElements();
1536 inline bool HasExternalFloatElements();
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00001537 inline bool HasExternalDoubleElements();
whesse@chromium.org7b260152011-06-20 15:33:18 +00001538 bool HasFastArgumentsElements();
1539 bool HasDictionaryArgumentsElements();
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001540 inline SeededNumberDictionary* element_dictionary(); // Gets slow elements.
whesse@chromium.org7b260152011-06-20 15:33:18 +00001541
svenpanne@chromium.org3c93e772012-01-02 09:26:59 +00001542 inline void set_map_and_elements(
1543 Map* map,
1544 FixedArrayBase* value,
1545 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
1546
whesse@chromium.org7b260152011-06-20 15:33:18 +00001547 // Requires: HasFastElements().
lrn@chromium.org303ada72010-10-27 09:33:13 +00001548 MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001549
ager@chromium.org5ec48922009-05-05 07:25:34 +00001550 // Collects elements starting at index 0.
1551 // Undefined values are placed after non-undefined values.
1552 // Returns the number of non-undefined values.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001553 MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit);
ager@chromium.org5ec48922009-05-05 07:25:34 +00001554 // As PrepareElementsForSort, but only on objects where elements is
1555 // a dictionary, and it will stay a dictionary.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001556 MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit);
ager@chromium.org5ec48922009-05-05 07:25:34 +00001557
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001558 MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver,
1559 Object* structure,
1560 String* name);
1561
1562 // Can cause GC.
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001563 MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result,
lrn@chromium.org303ada72010-10-27 09:33:13 +00001564 String* key,
1565 Object* value,
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001566 PropertyAttributes attributes,
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001567 StrictModeFlag strict_mode,
1568 StoreFromKeyed store_mode);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001569 MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck(
1570 LookupResult* result,
1571 String* name,
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001572 Object* value,
ricow@chromium.orgc54d3652011-05-30 09:20:16 +00001573 bool check_prototype,
1574 StrictModeFlag strict_mode);
1575 MUST_USE_RESULT MaybeObject* SetPropertyWithCallback(
1576 Object* structure,
1577 String* name,
1578 Object* value,
1579 JSObject* holder,
1580 StrictModeFlag strict_mode);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001581 MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor(
1582 String* name,
1583 Object* value,
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001584 PropertyAttributes attributes,
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00001585 StrictModeFlag strict_mode);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001586 MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor(
1587 String* name,
1588 Object* value,
ager@chromium.org9ee27ae2011-03-02 13:43:26 +00001589 PropertyAttributes attributes,
mstarzinger@chromium.orgccab3672012-06-14 15:01:16 +00001590 StrictModeFlag strict_mode,
1591 ExtensibilityCheck extensibility_check);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001592
1593 static Handle<Object> SetLocalPropertyIgnoreAttributes(
1594 Handle<JSObject> object,
1595 Handle<String> key,
1596 Handle<Object> value,
1597 PropertyAttributes attributes);
1598
1599 // Can cause GC.
kmillikin@chromium.orgd2c22f02011-01-10 08:15:37 +00001600 MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes(
lrn@chromium.org303ada72010-10-27 09:33:13 +00001601 String* key,
1602 Object* value,
1603 PropertyAttributes attributes);
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001604
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001605 // Retrieve a value in a normalized object given a lookup result.
1606 // Handles the special representation of JS global objects.
1607 Object* GetNormalizedProperty(LookupResult* result);
1608
1609 // Sets the property value in a normalized object given a lookup result.
1610 // Handles the special representation of JS global objects.
1611 Object* SetNormalizedProperty(LookupResult* result, Object* value);
1612
1613 // Sets the property value in a normalized object given (key, value, details).
1614 // Handles the special representation of JS global objects.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001615 static Handle<Object> SetNormalizedProperty(Handle<JSObject> object,
1616 Handle<String> key,
1617 Handle<Object> value,
1618 PropertyDetails details);
1619
lrn@chromium.org303ada72010-10-27 09:33:13 +00001620 MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name,
1621 Object* value,
1622 PropertyDetails details);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001623
1624 // Deletes the named property in a normalized object.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001625 MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name,
1626 DeleteMode mode);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00001627
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001628 MUST_USE_RESULT MaybeObject* OptimizeAsPrototype();
1629
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001630 // Retrieve interceptors.
1631 InterceptorInfo* GetNamedInterceptor();
1632 InterceptorInfo* GetIndexedInterceptor();
1633
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001634 // Used from JSReceiver.
1635 PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver,
1636 String* name,
1637 bool continue_search);
1638 PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver,
1639 String* name,
1640 bool continue_search);
1641 PropertyAttributes GetPropertyAttributeWithFailedAccessCheck(
1642 Object* receiver,
1643 LookupResult* result,
1644 String* name,
1645 bool continue_search);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001646
danno@chromium.org88aa0582012-03-23 15:11:57 +00001647 static void DefineAccessor(Handle<JSObject> object,
1648 Handle<String> name,
1649 Handle<Object> getter,
1650 Handle<Object> setter,
1651 PropertyAttributes attributes);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001652 MUST_USE_RESULT MaybeObject* DefineAccessor(String* name,
danno@chromium.org88aa0582012-03-23 15:11:57 +00001653 Object* getter,
1654 Object* setter,
lrn@chromium.org303ada72010-10-27 09:33:13 +00001655 PropertyAttributes attributes);
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001656 // Try to define a single accessor paying attention to map transitions.
1657 // Returns a JavaScript null if this was not possible and we have to use the
1658 // slow case. Note that we can fail due to allocations, too.
1659 MUST_USE_RESULT MaybeObject* DefineFastAccessor(
1660 String* name,
1661 AccessorComponent component,
1662 Object* accessor,
1663 PropertyAttributes attributes);
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00001664 Object* LookupAccessor(String* name, AccessorComponent component);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001665
lrn@chromium.org303ada72010-10-27 09:33:13 +00001666 MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info);
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00001667
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001668 // Used from Object::GetProperty().
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001669 MUST_USE_RESULT MaybeObject* GetPropertyWithFailedAccessCheck(
lrn@chromium.org303ada72010-10-27 09:33:13 +00001670 Object* receiver,
1671 LookupResult* result,
1672 String* name,
1673 PropertyAttributes* attributes);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001674 MUST_USE_RESULT MaybeObject* GetPropertyWithInterceptor(
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001675 JSReceiver* receiver,
lrn@chromium.org303ada72010-10-27 09:33:13 +00001676 String* name,
1677 PropertyAttributes* attributes);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001678 MUST_USE_RESULT MaybeObject* GetPropertyPostInterceptor(
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001679 JSReceiver* receiver,
lrn@chromium.org303ada72010-10-27 09:33:13 +00001680 String* name,
1681 PropertyAttributes* attributes);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001682 MUST_USE_RESULT MaybeObject* GetLocalPropertyPostInterceptor(
1683 JSReceiver* receiver,
1684 String* name,
1685 PropertyAttributes* attributes);
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00001686
christian.plesner.hansen@gmail.com2bc58ef2009-09-22 10:00:30 +00001687 // Returns true if this is an instance of an api function and has
1688 // been modified since it was created. May give false positives.
1689 bool IsDirty();
1690
ager@chromium.orgc4c92722009-11-18 14:12:51 +00001691 // If the receiver is a JSGlobalProxy this method will return its prototype,
1692 // otherwise the result is the receiver itself.
1693 inline Object* BypassGlobalProxy();
1694
1695 // Accessors for hidden properties object.
1696 //
1697 // Hidden properties are not local properties of the object itself.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001698 // Instead they are stored in an auxiliary structure kept as a local
ager@chromium.orgc4c92722009-11-18 14:12:51 +00001699 // property with a special name Heap::hidden_symbol(). But if the
1700 // receiver is a JSGlobalProxy then the auxiliary object is a property
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001701 // of its prototype, and if it's a detached proxy, then you can't have
1702 // hidden properties.
ager@chromium.orgc4c92722009-11-18 14:12:51 +00001703
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001704 // Sets a hidden property on this object. Returns this object if successful,
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001705 // undefined if called on a detached proxy.
1706 static Handle<Object> SetHiddenProperty(Handle<JSObject> obj,
1707 Handle<String> key,
1708 Handle<Object> value);
1709 // Returns a failure if a GC is required.
jkummerow@chromium.orgab7dad42012-02-07 12:07:34 +00001710 MUST_USE_RESULT MaybeObject* SetHiddenProperty(String* key, Object* value);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001711 // Gets the value of a hidden property with the given key. Returns undefined
1712 // if the property doesn't exist (or if called on a detached proxy),
1713 // otherwise returns the value set for the key.
1714 Object* GetHiddenProperty(String* key);
1715 // Deletes a hidden property. Deleting a non-existing property is
1716 // considered successful.
1717 void DeleteHiddenProperty(String* key);
1718 // Returns true if the object has a property with the hidden symbol as name.
1719 bool HasHiddenProperties();
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001720
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001721 static int GetIdentityHash(Handle<JSObject> obj);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001722 MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
1723 MUST_USE_RESULT MaybeObject* SetIdentityHash(Object* hash, CreationFlag flag);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001724
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001725 static Handle<Object> DeleteProperty(Handle<JSObject> obj,
1726 Handle<String> name);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001727 MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001728
1729 static Handle<Object> DeleteElement(Handle<JSObject> obj, uint32_t index);
lrn@chromium.org303ada72010-10-27 09:33:13 +00001730 MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001731
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001732 inline void ValidateElements();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001733
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00001734 // Makes sure that this object can contain HeapObject as elements.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001735 MUST_USE_RESULT inline MaybeObject* EnsureCanContainHeapObjectElements();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001736
1737 // Makes sure that this object can contain the specified elements.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001738 MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
1739 Object** elements,
1740 uint32_t count,
1741 EnsureElementsMode mode);
1742 MUST_USE_RESULT inline MaybeObject* EnsureCanContainElements(
1743 FixedArrayBase* elements,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001744 uint32_t length,
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001745 EnsureElementsMode mode);
1746 MUST_USE_RESULT MaybeObject* EnsureCanContainElements(
1747 Arguments* arguments,
1748 uint32_t first_arg,
1749 uint32_t arg_count,
1750 EnsureElementsMode mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001751
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001752 // Do we want to keep the elements in fast case when increasing the
1753 // capacity?
1754 bool ShouldConvertToSlowElements(int new_capacity);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001755 // Returns true if the backing storage for the slow-case elements of
1756 // this object takes up nearly as much space as a fast-case backing
1757 // storage would. In that case the JSObject should have fast
1758 // elements.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00001759 bool ShouldConvertToFastElements();
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001760 // Returns true if the elements of JSObject contains only values that can be
svenpanne@chromium.org3c93e772012-01-02 09:26:59 +00001761 // represented in a FixedDoubleArray and has at least one value that can only
1762 // be represented as a double and not a Smi.
1763 bool ShouldConvertToFastDoubleElements(bool* has_smi_only_elements);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001764
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001765 // Tells whether the index'th element is present.
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001766 bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001767
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00001768 // Computes the new capacity when expanding the elements of a JSObject.
1769 static int NewElementsCapacity(int old_capacity) {
1770 // (old_capacity + 50%) + 16
1771 return old_capacity + (old_capacity >> 1) + 16;
1772 }
1773
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001774 // Tells whether the index'th element is present and how it is stored.
1775 enum LocalElementType {
1776 // There is no element with given index.
1777 UNDEFINED_ELEMENT,
1778
1779 // Element with given index is handled by interceptor.
1780 INTERCEPTED_ELEMENT,
1781
1782 // Element with given index is character in string.
1783 STRING_CHARACTER_ELEMENT,
1784
1785 // Element with given index is stored in fast backing store.
1786 FAST_ELEMENT,
1787
1788 // Element with given index is stored in slow backing store.
1789 DICTIONARY_ELEMENT
1790 };
1791
1792 LocalElementType HasLocalElement(uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001793
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001794 bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001795
lrn@chromium.org5d00b602011-01-05 09:51:43 +00001796 MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index,
1797 Object* value,
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00001798 StrictModeFlag strict_mode,
whesse@chromium.org7b260152011-06-20 15:33:18 +00001799 bool check_prototype);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001800
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001801 MUST_USE_RESULT MaybeObject* SetDictionaryElement(
1802 uint32_t index,
1803 Object* value,
1804 PropertyAttributes attributes,
1805 StrictModeFlag strict_mode,
1806 bool check_prototype,
1807 SetPropertyMode set_mode = SET_PROPERTY);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001808
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001809 MUST_USE_RESULT MaybeObject* SetFastDoubleElement(
1810 uint32_t index,
1811 Object* value,
1812 StrictModeFlag strict_mode,
1813 bool check_prototype = true);
1814
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001815 static Handle<Object> SetOwnElement(Handle<JSObject> object,
1816 uint32_t index,
1817 Handle<Object> value,
1818 StrictModeFlag strict_mode);
1819
1820 // Empty handle is returned if the element cannot be set to the given value.
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001821 static MUST_USE_RESULT Handle<Object> SetElement(
1822 Handle<JSObject> object,
1823 uint32_t index,
1824 Handle<Object> value,
1825 PropertyAttributes attr,
1826 StrictModeFlag strict_mode,
1827 SetPropertyMode set_mode = SET_PROPERTY);
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001828
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001829 // A Failure object is returned if GC is needed.
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00001830 MUST_USE_RESULT MaybeObject* SetElement(
1831 uint32_t index,
1832 Object* value,
1833 PropertyAttributes attributes,
1834 StrictModeFlag strict_mode,
1835 bool check_prototype = true,
1836 SetPropertyMode set_mode = SET_PROPERTY);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001837
1838 // Returns the index'th element.
1839 // The undefined object if index is out of bounds.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00001840 MUST_USE_RESULT MaybeObject* GetElementWithInterceptor(Object* receiver,
1841 uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001842
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001843 enum SetFastElementsCapacitySmiMode {
1844 kAllowSmiElements,
1845 kForceSmiElements,
1846 kDontAllowSmiElements
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001847 };
1848
whesse@chromium.org7b260152011-06-20 15:33:18 +00001849 // Replace the elements' backing store with fast elements of the given
1850 // capacity. Update the length for JSArrays. Returns the new backing
1851 // store.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001852 MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(
1853 int capacity,
1854 int length,
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00001855 SetFastElementsCapacitySmiMode smi_mode);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001856 MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength(
1857 int capacity,
1858 int length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001859
1860 // Lookup interceptors are used for handling properties controlled by host
1861 // objects.
1862 inline bool HasNamedInterceptor();
1863 inline bool HasIndexedInterceptor();
1864
1865 // Support functions for v8 api (needed for correct interceptor behavior).
1866 bool HasRealNamedProperty(String* key);
1867 bool HasRealElementProperty(uint32_t index);
1868 bool HasRealNamedCallbackProperty(String* key);
1869
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001870 // Get the header size for a JSObject. Used to compute the index of
1871 // internal fields as well as the number of internal fields.
1872 inline int GetHeaderSize();
1873
1874 inline int GetInternalFieldCount();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00001875 inline int GetInternalFieldOffset(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001876 inline Object* GetInternalField(int index);
1877 inline void SetInternalField(int index, Object* value);
ricow@chromium.org27bf2882011-11-17 08:34:43 +00001878 inline void SetInternalField(int index, Smi* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001879
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001880 // The following lookup functions skip interceptors.
1881 void LocalLookupRealNamedProperty(String* name, LookupResult* result);
1882 void LookupRealNamedProperty(String* name, LookupResult* result);
1883 void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result);
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +00001884 MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes(
ricow@chromium.orgc54d3652011-05-30 09:20:16 +00001885 uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode);
verwaest@chromium.org753aee42012-07-17 16:15:42 +00001886 void LookupCallbackProperty(String* name, LookupResult* result);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001887
1888 // Returns the number of properties on this object filtering out properties
1889 // with the specified attributes (ignoring interceptors).
jkummerow@chromium.orgab7dad42012-02-07 12:07:34 +00001890 int NumberOfLocalProperties(PropertyAttributes filter = NONE);
ager@chromium.orgddb913d2009-01-27 10:01:48 +00001891 // Fill in details for properties into storage starting at the specified
1892 // index.
1893 void GetLocalPropertyNames(FixedArray* storage, int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001894
1895 // Returns the number of properties on this object filtering out properties
1896 // with the specified attributes (ignoring interceptors).
1897 int NumberOfLocalElements(PropertyAttributes filter);
1898 // Returns the number of enumerable elements (ignoring interceptors).
1899 int NumberOfEnumElements();
1900 // Returns the number of elements on this object filtering out elements
1901 // with the specified attributes (ignoring interceptors).
1902 int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter);
1903 // Count and fill in the enumerable elements into storage.
1904 // (storage->length() == NumberOfEnumElements()).
1905 // If storage is NULL, will count the elements without adding
1906 // them to any storage.
1907 // Returns the number of enumerable elements.
1908 int GetEnumElementKeys(FixedArray* storage);
1909
1910 // Add a property to a fast-case object using a map transition to
1911 // new_map.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001912 MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map,
1913 String* name,
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00001914 Object* value,
1915 int field_index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001916
1917 // Add a constant function property to a fast-case object.
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00001918 // This leaves a CONSTANT_TRANSITION in the old map, and
1919 // if it is called on a second object with this map, a
1920 // normal property is added instead, with a map transition.
1921 // This avoids the creation of many maps with the same constant
1922 // function, all orphaned.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001923 MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty(
1924 String* name,
1925 JSFunction* function,
1926 PropertyAttributes attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001927
lrn@chromium.org303ada72010-10-27 09:33:13 +00001928 MUST_USE_RESULT MaybeObject* ReplaceSlowProperty(
1929 String* name,
1930 Object* value,
1931 PropertyAttributes attributes);
ager@chromium.org7c537e22008-10-16 08:43:32 +00001932
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001933 // Returns a new map with all transitions dropped from the object's current
1934 // map and the ElementsKind set.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001935 static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
1936 ElementsKind to_kind);
danno@chromium.orgfa458e42012-02-01 10:48:36 +00001937 inline MUST_USE_RESULT MaybeObject* GetElementsTransitionMap(
1938 Isolate* isolate,
1939 ElementsKind elements_kind);
1940 MUST_USE_RESULT MaybeObject* GetElementsTransitionMapSlow(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001941 ElementsKind elements_kind);
1942
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001943 static Handle<Object> TransitionElementsKind(Handle<JSObject> object,
1944 ElementsKind to_kind);
1945
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00001946 MUST_USE_RESULT MaybeObject* TransitionElementsKind(ElementsKind to_kind);
1947
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00001948 // Replaces an existing transition with a transition to a map with a FIELD.
1949 MUST_USE_RESULT MaybeObject* ConvertTransitionToMapTransition(
1950 int transition_index,
ager@chromium.org7c537e22008-10-16 08:43:32 +00001951 String* name,
1952 Object* new_value,
1953 PropertyAttributes attributes);
1954
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00001955 // Converts a descriptor of any other type to a real field, backed by the
1956 // properties array.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001957 MUST_USE_RESULT MaybeObject* ConvertDescriptorToField(
1958 String* name,
1959 Object* new_value,
1960 PropertyAttributes attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001961
1962 // Add a property to a fast-case object.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001963 MUST_USE_RESULT MaybeObject* AddFastProperty(
1964 String* name,
1965 Object* value,
1966 PropertyAttributes attributes,
1967 StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001968
1969 // Add a property to a slow-case object.
lrn@chromium.org303ada72010-10-27 09:33:13 +00001970 MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name,
1971 Object* value,
1972 PropertyAttributes attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001973
1974 // Add a property to an object.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00001975 MUST_USE_RESULT MaybeObject* AddProperty(
1976 String* name,
1977 Object* value,
1978 PropertyAttributes attributes,
1979 StrictModeFlag strict_mode,
mstarzinger@chromium.orgccab3672012-06-14 15:01:16 +00001980 StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED,
1981 ExtensibilityCheck extensibility_check = PERFORM_EXTENSIBILITY_CHECK);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00001982
1983 // Convert the object to use the canonical dictionary
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00001984 // representation. If the object is expected to have additional properties
1985 // added this number can be indicated to have the backing store allocated to
1986 // an initial capacity for holding these properties.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001987 static void NormalizeProperties(Handle<JSObject> object,
1988 PropertyNormalizationMode mode,
1989 int expected_additional_properties);
1990
lrn@chromium.org303ada72010-10-27 09:33:13 +00001991 MUST_USE_RESULT MaybeObject* NormalizeProperties(
1992 PropertyNormalizationMode mode,
1993 int expected_additional_properties);
whesse@chromium.org7b260152011-06-20 15:33:18 +00001994
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00001995 // Convert and update the elements backing store to be a
1996 // SeededNumberDictionary dictionary. Returns the backing after conversion.
1997 static Handle<SeededNumberDictionary> NormalizeElements(
1998 Handle<JSObject> object);
1999
lrn@chromium.org303ada72010-10-27 09:33:13 +00002000 MUST_USE_RESULT MaybeObject* NormalizeElements();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002001
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002002 static void UpdateMapCodeCache(Handle<JSObject> object,
2003 Handle<String> name,
2004 Handle<Code> code);
2005
lrn@chromium.org303ada72010-10-27 09:33:13 +00002006 MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code);
ricow@chromium.org65fae842010-08-25 15:26:24 +00002007
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002008 // Transform slow named properties to fast variants.
2009 // Returns failure if allocation failed.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002010 static void TransformToFastProperties(Handle<JSObject> object,
2011 int unused_property_fields);
2012
lrn@chromium.org303ada72010-10-27 09:33:13 +00002013 MUST_USE_RESULT MaybeObject* TransformToFastProperties(
2014 int unused_property_fields);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002015
ager@chromium.org7c537e22008-10-16 08:43:32 +00002016 // Access fast-case object properties at index.
2017 inline Object* FastPropertyAt(int index);
2018 inline Object* FastPropertyAtPut(int index, Object* value);
2019
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002020 // Access to in object properties.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002021 inline int GetInObjectPropertyOffset(int index);
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00002022 inline Object* InObjectPropertyAt(int index);
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002023 inline Object* InObjectPropertyAtPut(int index,
2024 Object* value,
2025 WriteBarrierMode mode
2026 = UPDATE_WRITE_BARRIER);
ager@chromium.org7c537e22008-10-16 08:43:32 +00002027
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002028 // Initializes the body after properties slot, properties slot is
2029 // initialized by set_properties. Fill the pre-allocated fields with
2030 // pre_allocated_value and the rest with filler_value.
2031 // Note: this call does not update write barrier, the caller is responsible
2032 // to ensure that |filler_value| can be collected without WB here.
2033 inline void InitializeBody(Map* map,
2034 Object* pre_allocated_value,
2035 Object* filler_value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002036
2037 // Check whether this object references another object
2038 bool ReferencesObject(Object* obj);
2039
2040 // Casting.
2041 static inline JSObject* cast(Object* obj);
2042
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00002043 // Disalow further properties to be added to the object.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002044 static Handle<Object> PreventExtensions(Handle<JSObject> object);
lrn@chromium.org303ada72010-10-27 09:33:13 +00002045 MUST_USE_RESULT MaybeObject* PreventExtensions();
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00002046
2047
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002048 // Dispatched behavior.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002049 void JSObjectShortPrint(StringStream* accumulator);
whesse@chromium.org023421e2010-12-21 12:19:12 +00002050#ifdef OBJECT_PRINT
2051 inline void JSObjectPrint() {
2052 JSObjectPrint(stdout);
2053 }
2054 void JSObjectPrint(FILE* out);
2055#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002056#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002057 void JSObjectVerify();
whesse@chromium.org023421e2010-12-21 12:19:12 +00002058#endif
2059#ifdef OBJECT_PRINT
2060 inline void PrintProperties() {
2061 PrintProperties(stdout);
2062 }
2063 void PrintProperties(FILE* out);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002064
whesse@chromium.org023421e2010-12-21 12:19:12 +00002065 inline void PrintElements() {
2066 PrintElements(stdout);
2067 }
2068 void PrintElements(FILE* out);
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002069 inline void PrintTransitions() {
2070 PrintTransitions(stdout);
2071 }
2072 void PrintTransitions(FILE* out);
whesse@chromium.org023421e2010-12-21 12:19:12 +00002073#endif
2074
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002075 void PrintElementsTransition(
2076 FILE* file, ElementsKind from_kind, FixedArrayBase* from_elements,
2077 ElementsKind to_kind, FixedArrayBase* to_elements);
2078
whesse@chromium.org023421e2010-12-21 12:19:12 +00002079#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002080 // Structure for collecting spill information about JSObjects.
2081 class SpillInformation {
2082 public:
2083 void Clear();
2084 void Print();
2085 int number_of_objects_;
2086 int number_of_objects_with_fast_properties_;
2087 int number_of_objects_with_fast_elements_;
2088 int number_of_fast_used_fields_;
2089 int number_of_fast_unused_fields_;
2090 int number_of_slow_used_properties_;
2091 int number_of_slow_unused_properties_;
2092 int number_of_fast_used_elements_;
2093 int number_of_fast_unused_elements_;
2094 int number_of_slow_used_elements_;
2095 int number_of_slow_unused_elements_;
2096 };
2097
2098 void IncrementSpillStatistics(SpillInformation* info);
2099#endif
2100 Object* SlowReverseLookup(Object* value);
2101
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00002102 // Maximal number of fast properties for the JSObject. Used to
2103 // restrict the number of map transitions to avoid an explosion in
2104 // the number of maps for objects used as dictionaries.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002105 inline bool TooManyFastProperties(int properties, StoreFromKeyed store_mode);
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00002106
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002107 // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
2108 // Also maximal value of JSArray's length property.
2109 static const uint32_t kMaxElementCount = 0xffffffffu;
2110
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002111 // Constants for heuristics controlling conversion of fast elements
2112 // to slow elements.
2113
2114 // Maximal gap that can be introduced by adding an element beyond
2115 // the current elements length.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002116 static const uint32_t kMaxGap = 1024;
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002117
2118 // Maximal length of fast elements array that won't be checked for
2119 // being dense enough on expansion.
2120 static const int kMaxUncheckedFastElementsLength = 5000;
2121
2122 // Same as above but for old arrays. This limit is more strict. We
2123 // don't want to be wasteful with long lived objects.
2124 static const int kMaxUncheckedOldFastElementsLength = 500;
2125
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00002126 static const int kInitialMaxFastElementArray = 100000;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002127 static const int kFastPropertiesSoftLimit = 12;
2128 static const int kMaxFastProperties = 64;
ager@chromium.org7c537e22008-10-16 08:43:32 +00002129 static const int kMaxInstanceSize = 255 * kPointerSize;
2130 // When extending the backing storage for property values, we increase
2131 // its size by more than the 1 entry necessary, so sequentially adding fields
2132 // to the same object requires fewer allocations and copies.
2133 static const int kFieldsAdded = 3;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002134
2135 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00002136 static const int kPropertiesOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002137 static const int kElementsOffset = kPropertiesOffset + kPointerSize;
2138 static const int kHeaderSize = kElementsOffset + kPointerSize;
2139
ager@chromium.org18ad94b2009-09-02 08:22:29 +00002140 STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize);
2141
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002142 class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> {
2143 public:
2144 static inline int SizeOf(Map* map, HeapObject* object);
2145 };
2146
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002147 private:
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00002148 friend class DictionaryElementsAccessor;
2149
lrn@chromium.org303ada72010-10-27 09:33:13 +00002150 MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver,
2151 Object* structure,
2152 uint32_t index,
2153 Object* holder);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002154 MUST_USE_RESULT MaybeObject* SetElementWithCallback(
2155 Object* structure,
2156 uint32_t index,
2157 Object* value,
2158 JSObject* holder,
2159 StrictModeFlag strict_mode);
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00002160 MUST_USE_RESULT MaybeObject* SetElementWithInterceptor(
2161 uint32_t index,
2162 Object* value,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00002163 PropertyAttributes attributes,
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00002164 StrictModeFlag strict_mode,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00002165 bool check_prototype,
2166 SetPropertyMode set_mode);
lrn@chromium.org5d00b602011-01-05 09:51:43 +00002167 MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor(
2168 uint32_t index,
2169 Object* value,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00002170 PropertyAttributes attributes,
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00002171 StrictModeFlag strict_mode,
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00002172 bool check_prototype,
2173 SetPropertyMode set_mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002174
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002175 // Searches the prototype chain for property 'name'. If it is found and
2176 // has a setter, invoke it and set '*done' to true. If it is found and is
2177 // read-only, reject and set '*done' to true. Otherwise, set '*done' to
2178 // false. Can cause GC and can return a failure result with '*done==true'.
2179 MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypes(
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002180 String* name,
2181 Object* value,
2182 PropertyAttributes attributes,
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002183 StrictModeFlag strict_mode,
2184 bool* done);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002185
lrn@chromium.org303ada72010-10-27 09:33:13 +00002186 MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name,
2187 DeleteMode mode);
2188 MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002189
lrn@chromium.org303ada72010-10-27 09:33:13 +00002190 MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002191
whesse@chromium.org7b260152011-06-20 15:33:18 +00002192 MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index);
2193 MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index,
2194 DeleteMode mode);
2195
2196 bool ReferencesObjectFromElements(FixedArray* elements,
2197 ElementsKind kind,
2198 Object* object);
whesse@chromium.org7b260152011-06-20 15:33:18 +00002199
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002200 // Returns true if most of the elements backing storage is used.
2201 bool HasDenseElements();
2202
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002203 // Gets the current elements capacity and the number of used elements.
2204 void GetElementsCapacityAndUsage(int* capacity, int* used);
2205
kmillikin@chromium.org9155e252010-05-26 13:27:57 +00002206 bool CanSetCallback(String* name);
lrn@chromium.org303ada72010-10-27 09:33:13 +00002207 MUST_USE_RESULT MaybeObject* SetElementCallback(
2208 uint32_t index,
2209 Object* structure,
2210 PropertyAttributes attributes);
2211 MUST_USE_RESULT MaybeObject* SetPropertyCallback(
2212 String* name,
2213 Object* structure,
2214 PropertyAttributes attributes);
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002215 MUST_USE_RESULT MaybeObject* DefineElementAccessor(
2216 uint32_t index,
danno@chromium.org88aa0582012-03-23 15:11:57 +00002217 Object* getter,
2218 Object* setter,
lrn@chromium.org303ada72010-10-27 09:33:13 +00002219 PropertyAttributes attributes);
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00002220 MUST_USE_RESULT MaybeObject* CreateAccessorPairFor(String* name);
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002221 MUST_USE_RESULT MaybeObject* DefinePropertyAccessor(
2222 String* name,
danno@chromium.org88aa0582012-03-23 15:11:57 +00002223 Object* getter,
2224 Object* setter,
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002225 PropertyAttributes attributes);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002226
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002227 // Returns the hidden properties backing store object, currently
2228 // a StringDictionary, stored on this object.
2229 // If no hidden properties object has been put on this object,
2230 // return undefined, unless create_if_absent is true, in which case
2231 // a new dictionary is created, added to this object, and returned.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002232 MUST_USE_RESULT MaybeObject* GetHiddenPropertiesDictionary(
2233 bool create_if_absent);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002234 // Updates the existing hidden properties dictionary.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002235 MUST_USE_RESULT MaybeObject* SetHiddenPropertiesDictionary(
2236 StringDictionary* dictionary);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00002237
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002238 DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
2239};
2240
2241
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002242// Common superclass for FixedArrays that allow implementations to share
2243// common accessors and some code paths.
2244class FixedArrayBase: public HeapObject {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002245 public:
2246 // [length]: length of the array.
2247 inline int length();
2248 inline void set_length(int value);
2249
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002250 inline static FixedArrayBase* cast(Object* object);
2251
2252 // Layout description.
2253 // Length is smi tagged when it is stored.
2254 static const int kLengthOffset = HeapObject::kHeaderSize;
2255 static const int kHeaderSize = kLengthOffset + kPointerSize;
2256};
2257
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00002258
ricow@chromium.org9fa09672011-07-25 11:05:35 +00002259class FixedDoubleArray;
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002260class IncrementalMarking;
2261
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002262
2263// FixedArray describes fixed-sized arrays with element type Object*.
2264class FixedArray: public FixedArrayBase {
2265 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002266 // Setter and getter for elements.
2267 inline Object* get(int index);
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002268 // Setter that uses write barrier.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002269 inline void set(int index, Object* value);
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00002270 inline bool is_the_hole(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002271
ager@chromium.orga74f0da2008-12-03 16:05:52 +00002272 // Setter that doesn't need write barrier).
2273 inline void set(int index, Smi* value);
2274 // Setter with explicit barrier mode.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00002275 inline void set(int index, Object* value, WriteBarrierMode mode);
2276
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002277 // Setters for frequently used oddballs located in old space.
2278 inline void set_undefined(int index);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002279 // TODO(isolates): duplicate.
2280 inline void set_undefined(Heap* heap, int index);
ager@chromium.org236ad962008-09-25 09:45:57 +00002281 inline void set_null(int index);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002282 // TODO(isolates): duplicate.
2283 inline void set_null(Heap* heap, int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002284 inline void set_the_hole(int index);
2285
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00002286 // Setters with less debug checks for the GC to use.
2287 inline void set_unchecked(int index, Smi* value);
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002288 inline void set_null_unchecked(Heap* heap, int index);
2289 inline void set_unchecked(Heap* heap, int index, Object* value,
2290 WriteBarrierMode mode);
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00002291
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00002292 // Gives access to raw memory which stores the array's data.
2293 inline Object** data_start();
2294
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002295 inline Object** GetFirstElementAddress();
2296 inline bool ContainsOnlySmisOrHoles();
2297
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002298 // Copy operations.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002299 MUST_USE_RESULT inline MaybeObject* Copy();
2300 MUST_USE_RESULT MaybeObject* CopySize(int new_length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002301
2302 // Add the elements of a JSArray to this FixedArray.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002303 MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002304
2305 // Compute the union of this and other.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002306 MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002307
2308 // Copy a sub array from the receiver to dest.
2309 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
2310
2311 // Garbage collection support.
2312 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; }
2313
ager@chromium.org3e875802009-06-29 08:26:34 +00002314 // Code Generation support.
2315 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2316
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002317 // Casting.
2318 static inline FixedArray* cast(Object* obj);
2319
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002320 // Maximal allowed size, in bytes, of a single FixedArray.
2321 // Prevents overflowing size computations, as well as extreme memory
2322 // consumption.
mstarzinger@chromium.orgf8c6bd52011-11-23 12:13:52 +00002323 static const int kMaxSize = 128 * MB * kPointerSize;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002324 // Maximally allowed length of a FixedArray.
2325 static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize;
kasperl@chromium.org71affb52009-05-26 05:44:31 +00002326
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002327 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00002328#ifdef OBJECT_PRINT
2329 inline void FixedArrayPrint() {
2330 FixedArrayPrint(stdout);
2331 }
2332 void FixedArrayPrint(FILE* out);
2333#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002334#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002335 void FixedArrayVerify();
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002336 // Checks if two FixedArrays have identical contents.
2337 bool IsEqualTo(FixedArray* other);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002338#endif
2339
ager@chromium.org65dad4b2009-04-23 08:48:43 +00002340 // Swap two elements in a pair of arrays. If this array and the
2341 // numbers array are the same object, the elements are only swapped
2342 // once.
2343 void SwapPairs(FixedArray* numbers, int i, int j);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002344
ager@chromium.org65dad4b2009-04-23 08:48:43 +00002345 // Sort prefix of this array and the numbers array as pairs wrt. the
2346 // numbers. If the numbers array and the this array are the same
2347 // object, the prefix of this array is sorted.
2348 void SortPairs(FixedArray* numbers, uint32_t len);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002349
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002350 class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> {
2351 public:
2352 static inline int SizeOf(Map* map, HeapObject* object) {
2353 return SizeFor(reinterpret_cast<FixedArray*>(object)->length());
2354 }
2355 };
2356
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002357 // WhitenessWitness is used to prove that a descriptor array is white
2358 // (unmarked), so incremental write barriers can be skipped because the
2359 // marking invariant cannot be broken and slots pointing into evacuation
2360 // candidates will be discovered when the object is scanned. A witness is
2361 // always stack-allocated right after creating an array. By allocating a
2362 // witness, incremental marking is globally disabled. The witness is then
2363 // passed along wherever needed to statically prove that the array is known to
2364 // be white.
2365 class WhitenessWitness {
2366 public:
2367 inline explicit WhitenessWitness(FixedArray* array);
2368 inline ~WhitenessWitness();
2369
2370 private:
2371 IncrementalMarking* marking_;
2372 };
2373
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002374 protected:
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00002375 // Set operation on FixedArray without using write barriers. Can
2376 // only be used for storing old space objects or smis.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002377 static inline void NoWriteBarrierSet(FixedArray* array,
2378 int index,
2379 Object* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002380
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002381 // Set operation on FixedArray without incremental write barrier. Can
2382 // only be used if the object is guaranteed to be white (whiteness witness
2383 // is present).
2384 static inline void NoIncrementalWriteBarrierSet(FixedArray* array,
2385 int index,
2386 Object* value);
2387
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002388 private:
2389 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray);
2390};
2391
2392
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002393// FixedDoubleArray describes fixed-sized arrays with element type double.
2394class FixedDoubleArray: public FixedArrayBase {
2395 public:
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002396 // Setter and getter for elements.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00002397 inline double get_scalar(int index);
danno@chromium.org88aa0582012-03-23 15:11:57 +00002398 inline int64_t get_representation(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00002399 MUST_USE_RESULT inline MaybeObject* get(int index);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002400 inline void set(int index, double value);
2401 inline void set_the_hole(int index);
2402
2403 // Checking for the hole.
2404 inline bool is_the_hole(int index);
2405
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002406 // Copy operations
2407 MUST_USE_RESULT inline MaybeObject* Copy();
2408
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002409 // Garbage collection support.
2410 inline static int SizeFor(int length) {
2411 return kHeaderSize + length * kDoubleSize;
2412 }
2413
rossberg@chromium.org717967f2011-07-20 13:44:42 +00002414 // Code Generation support.
2415 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2416
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00002417 inline static bool is_the_hole_nan(double value);
2418 inline static double hole_nan_as_double();
2419 inline static double canonical_not_the_hole_nan_as_double();
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00002420
2421 // Casting.
2422 static inline FixedDoubleArray* cast(Object* obj);
2423
2424 // Maximal allowed size, in bytes, of a single FixedDoubleArray.
2425 // Prevents overflowing size computations, as well as extreme memory
2426 // consumption.
2427 static const int kMaxSize = 512 * MB;
2428 // Maximally allowed length of a FixedArray.
2429 static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize;
2430
2431 // Dispatched behavior.
2432#ifdef OBJECT_PRINT
2433 inline void FixedDoubleArrayPrint() {
2434 FixedDoubleArrayPrint(stdout);
2435 }
2436 void FixedDoubleArrayPrint(FILE* out);
2437#endif
2438
2439#ifdef DEBUG
2440 void FixedDoubleArrayVerify();
2441#endif
2442
2443 private:
2444 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray);
2445};
2446
2447
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002448// DescriptorArrays are fixed arrays used to hold instance descriptors.
2449// The format of the these objects is:
danno@chromium.org40cb8782011-05-25 07:58:50 +00002450// TODO(1399): It should be possible to make room for bit_field3 in the map
2451// without overloading the instance descriptors field in the map
2452// (and storing it in the DescriptorArray when the map has one).
2453// [0]: storage for bit_field3 for Map owning this object (Smi)
2454// [1]: point to a fixed array with (value, detail) pairs.
2455// [2]: next enumeration index (Smi), or pointer to small fixed array:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002456// [0]: next enumeration index (Smi)
2457// [1]: pointer to fixed array with enum cache
danno@chromium.org40cb8782011-05-25 07:58:50 +00002458// [3]: first key
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002459// [length() - kDescriptorSize]: last key
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002460//
2461class DescriptorArray: public FixedArray {
2462 public:
danno@chromium.org40cb8782011-05-25 07:58:50 +00002463 // Returns true for both shared empty_descriptor_array and for smis, which the
2464 // map uses to encode additional bit fields when the descriptor array is not
2465 // yet used.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002466 inline bool IsEmpty();
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002467 inline bool MayContainTransitions();
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002468 inline bool HasTransitionArray();
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002469
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002470 DECL_ACCESSORS(transitions, TransitionArray)
2471 inline void ClearTransitions();
sgjesse@chromium.org846fb742009-12-18 08:56:33 +00002472
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002473 // Returns the number of descriptors in the array.
2474 int number_of_descriptors() {
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002475 ASSERT(MayContainTransitions() || IsEmpty());
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002476 int len = length();
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002477 return len <= kFirstIndex ? 0 : (len - kFirstIndex) / kDescriptorSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002478 }
2479
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002480 inline int number_of_entries() { return number_of_descriptors(); }
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00002481 inline int NextEnumerationIndex() { return number_of_descriptors() + 1; }
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002482
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002483 int LastAdded() {
2484 ASSERT(!IsEmpty());
2485 Object* obj = get(kLastAddedIndex);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002486 if (obj->IsSmi()) {
2487 return Smi::cast(obj)->value();
2488 } else {
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002489 Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeLastAdded);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002490 return Smi::cast(index)->value();
2491 }
2492 }
2493
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002494 // Set index of the last added descriptor and flush any enum cache.
2495 void SetLastAdded(int index) {
2496 ASSERT(!IsEmpty() || index > 0);
2497 set(kLastAddedIndex, Smi::FromInt(index));
2498 }
2499
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00002500 int NumberOfSetDescriptors() {
2501 ASSERT(!IsEmpty());
2502 if (LastAdded() == kNoneAdded) return 0;
2503 return GetDetails(LastAdded()).index();
2504 }
2505
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002506 bool HasEnumCache() {
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002507 return !IsEmpty() && !get(kLastAddedIndex)->IsSmi();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002508 }
2509
2510 Object* GetEnumCache() {
2511 ASSERT(HasEnumCache());
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002512 FixedArray* bridge = FixedArray::cast(get(kLastAddedIndex));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002513 return bridge->get(kEnumCacheBridgeCacheIndex);
2514 }
2515
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002516 Object** GetEnumCacheSlot() {
2517 ASSERT(HasEnumCache());
2518 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002519 kLastAddedOffset);
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002520 }
2521
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002522 Object** GetTransitionsSlot() {
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002523 return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
2524 kTransitionsOffset);
2525 }
2526
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002527 DECL_ACCESSORS(back_pointer_storage, Object)
danno@chromium.org40cb8782011-05-25 07:58:50 +00002528
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002529 // Initialize or change the enum cache,
2530 // using the supplied storage for the small "bridge".
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002531 void SetEnumCache(FixedArray* bridge_storage,
2532 FixedArray* new_cache,
2533 Object* new_index_cache);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002534
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00002535 // Accessors for fetching instance descriptor at descriptor number.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002536 inline String* GetKey(int descriptor_number);
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002537 inline Object** GetKeySlot(int descriptor_number);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002538 inline Object* GetValue(int descriptor_number);
verwaest@chromium.org37141392012-05-31 13:27:02 +00002539 inline Object** GetValueSlot(int descriptor_number);
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00002540 inline PropertyDetails GetDetails(int descriptor_number);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00002541 inline PropertyType GetType(int descriptor_number);
2542 inline int GetFieldIndex(int descriptor_number);
2543 inline JSFunction* GetConstantFunction(int descriptor_number);
2544 inline Object* GetCallbacksObject(int descriptor_number);
2545 inline AccessorDescriptor* GetCallbacks(int descriptor_number);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002546
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002547 // Accessor for complete descriptor.
2548 inline void Get(int descriptor_number, Descriptor* desc);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002549 inline void Set(int descriptor_number,
2550 Descriptor* desc,
2551 const WhitenessWitness&);
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00002552 // Append automatically sets the enumeration index. This should only be used
2553 // to add descriptors in bulk at the end, followed by sorting the descriptor
2554 // array.
2555 inline void Append(Descriptor* desc,
2556 const WhitenessWitness&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002557
ulan@chromium.org65a89c22012-02-14 11:46:07 +00002558 // Transfer a complete descriptor from the src descriptor array to this
verwaest@chromium.org753aee42012-07-17 16:15:42 +00002559 // descriptor array.
2560 void CopyFrom(int dst_index,
2561 DescriptorArray* src,
2562 int src_index,
2563 const WhitenessWitness&);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00002564
verwaest@chromium.org753aee42012-07-17 16:15:42 +00002565 // Copy the descriptor array, inserting new descriptor. Its enumeration index
2566 // is automatically set to the size of the descriptor array to which it was
2567 // added first.
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00002568 MUST_USE_RESULT MaybeObject* CopyAdd(Descriptor* descriptor);
verwaest@chromium.org753aee42012-07-17 16:15:42 +00002569
2570 // Copy the descriptor array, replacing a descriptor. Its enumeration index is
2571 // kept.
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00002572 MUST_USE_RESULT MaybeObject* CopyReplace(Descriptor* descriptor,
2573 int insertion_index);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002574
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002575 // Indicates whether the search function should expect a sorted or an unsorted
2576 // descriptor array as input.
2577 enum SharedMode {
2578 MAY_BE_SHARED,
2579 CANNOT_BE_SHARED
2580 };
2581
erik.corry@gmail.combbceb572012-03-09 10:52:05 +00002582 // Return a copy of the array with all transitions and null descriptors
2583 // removed. Return a Failure object in case of an allocation failure.
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002584 MUST_USE_RESULT MaybeObject* Copy(SharedMode shared_mode);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002585
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002586 // Sort the instance descriptors by the hash codes of their keys.
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +00002587 // Does not check for duplicates.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002588 void SortUnchecked(const WhitenessWitness&);
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +00002589
2590 // Sort the instance descriptors by the hash codes of their keys.
2591 // Checks the result for duplicates.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002592 void Sort(const WhitenessWitness&);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002593
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002594 // Search the instance descriptors for given name.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002595 INLINE(int Search(String* name));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002596
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002597 // As the above, but uses DescriptorLookupCache and updates it when
2598 // necessary.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002599 INLINE(int SearchWithCache(String* name));
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00002600
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002601 // Tells whether the name is present int the array.
2602 bool Contains(String* name) { return kNotFound != Search(name); }
2603
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002604 // Allocates a DescriptorArray, but returns the singleton
2605 // empty descriptor array object if number_of_descriptors is 0.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002606 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors,
2607 SharedMode shared_mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002608
2609 // Casting.
2610 static inline DescriptorArray* cast(Object* obj);
2611
2612 // Constant for denoting key was not found.
2613 static const int kNotFound = -1;
2614
jkummerow@chromium.org28583c92012-07-16 11:31:55 +00002615 // Constant for denoting that the LastAdded field was not yet set.
2616 static const int kNoneAdded = -1;
2617
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002618 static const int kBackPointerStorageIndex = 0;
2619 static const int kLastAddedIndex = 1;
verwaest@chromium.org50915592012-06-18 12:15:44 +00002620 static const int kTransitionsIndex = 2;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00002621 static const int kFirstIndex = 3;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002622
2623 // The length of the "bridge" to the enum cache.
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002624 static const int kEnumCacheBridgeLength = 3;
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002625 static const int kEnumCacheBridgeLastAdded = 0;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002626 static const int kEnumCacheBridgeCacheIndex = 1;
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00002627 static const int kEnumCacheBridgeIndicesCacheIndex = 2;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002628
2629 // Layout description.
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002630 static const int kBackPointerStorageOffset = FixedArray::kHeaderSize;
2631 static const int kLastAddedOffset = kBackPointerStorageOffset +
2632 kPointerSize;
2633 static const int kTransitionsOffset = kLastAddedOffset + kPointerSize;
verwaest@chromium.org50915592012-06-18 12:15:44 +00002634 static const int kFirstOffset = kTransitionsOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002635
2636 // Layout description for the bridge array.
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002637 static const int kEnumCacheBridgeLastAddedOffset = FixedArray::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002638 static const int kEnumCacheBridgeCacheOffset =
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00002639 kEnumCacheBridgeLastAddedOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002640
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002641 // Layout of descriptor.
2642 static const int kDescriptorKey = 0;
2643 static const int kDescriptorDetails = 1;
2644 static const int kDescriptorValue = 2;
2645 static const int kDescriptorSize = 3;
2646
whesse@chromium.org023421e2010-12-21 12:19:12 +00002647#ifdef OBJECT_PRINT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002648 // Print all the descriptors.
whesse@chromium.org023421e2010-12-21 12:19:12 +00002649 inline void PrintDescriptors() {
2650 PrintDescriptors(stdout);
2651 }
2652 void PrintDescriptors(FILE* out);
2653#endif
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00002654
whesse@chromium.org023421e2010-12-21 12:19:12 +00002655#ifdef DEBUG
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00002656 // Is the descriptor array sorted and without duplicates?
2657 bool IsSortedNoDuplicates();
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002658
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00002659 // Is the descriptor array consistent with the back pointers in targets?
2660 bool IsConsistentWithBackPointers(Map* current_map);
2661
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00002662 // Are two DescriptorArrays equal?
2663 bool IsEqualTo(DescriptorArray* other);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002664#endif
2665
2666 // The maximum number of descriptors we want in a descriptor array (should
2667 // fit in a page).
2668 static const int kMaxNumberOfDescriptors = 1024 + 512;
2669
2670 private:
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00002671 // An entry in a DescriptorArray, represented as an (array, index) pair.
2672 class Entry {
2673 public:
2674 inline explicit Entry(DescriptorArray* descs, int index) :
2675 descs_(descs), index_(index) { }
2676
2677 inline PropertyType type() { return descs_->GetType(index_); }
2678 inline Object* GetCallbackObject() { return descs_->GetValue(index_); }
2679
2680 private:
2681 DescriptorArray* descs_;
2682 int index_;
2683 };
2684
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002685 // Conversion from descriptor number to array indices.
2686 static int ToKeyIndex(int descriptor_number) {
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002687 return kFirstIndex +
2688 (descriptor_number * kDescriptorSize) +
2689 kDescriptorKey;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002690 }
sgjesse@chromium.org846fb742009-12-18 08:56:33 +00002691
2692 static int ToDetailsIndex(int descriptor_number) {
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002693 return kFirstIndex +
2694 (descriptor_number * kDescriptorSize) +
2695 kDescriptorDetails;
sgjesse@chromium.org846fb742009-12-18 08:56:33 +00002696 }
2697
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002698 static int ToValueIndex(int descriptor_number) {
rossberg@chromium.org400388e2012-06-06 09:29:22 +00002699 return kFirstIndex +
2700 (descriptor_number * kDescriptorSize) +
2701 kDescriptorValue;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002702 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002703
2704 // Swap operation on FixedArray without using write barriers.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002705 static inline void NoIncrementalWriteBarrierSwap(
2706 FixedArray* array, int first, int second);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002707
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002708 // Swap first and second descriptor.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00002709 inline void NoIncrementalWriteBarrierSwapDescriptors(
2710 int first, int second);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002711
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002712 DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray);
2713};
2714
2715
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00002716template<typename T>
2717inline int LinearSearch(T* array, SearchMode mode, String* name, int len);
2718
2719
2720template<typename T>
2721inline int Search(T* array, String* name);
2722
2723
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002724// HashTable is a subclass of FixedArray that implements a hash table
2725// that uses open addressing and quadratic probing.
2726//
2727// In order for the quadratic probing to work, elements that have not
2728// yet been used and elements that have been deleted are
2729// distinguished. Probing continues when deleted elements are
2730// encountered and stops when unused elements are encountered.
2731//
2732// - Elements with key == undefined have not been used yet.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002733// - Elements with key == the_hole have been deleted.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002734//
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002735// The hash table class is parameterized with a Shape and a Key.
2736// Shape must be a class with the following interface:
2737// class ExampleShape {
2738// public:
2739// // Tells whether key matches other.
2740// static bool IsMatch(Key key, Object* other);
2741// // Returns the hash value for key.
2742// static uint32_t Hash(Key key);
2743// // Returns the hash value for object.
2744// static uint32_t HashForObject(Key key, Object* object);
2745// // Convert key to an object.
2746// static inline Object* AsObject(Key key);
2747// // The prefix size indicates number of elements in the beginning
2748// // of the backing storage.
2749// static const int kPrefixSize = ..;
2750// // The Element size indicates number of elements per entry.
2751// static const int kEntrySize = ..;
2752// };
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002753// The prefix size indicates an amount of memory in the
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002754// beginning of the backing storage that can be used for non-element
2755// information by subclasses.
ager@chromium.org9258b6b2008-09-11 09:11:10 +00002756
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002757template<typename Key>
2758class BaseShape {
2759 public:
2760 static const bool UsesSeed = false;
2761 static uint32_t Hash(Key key) { return 0; }
2762 static uint32_t SeededHash(Key key, uint32_t seed) {
2763 ASSERT(UsesSeed);
2764 return Hash(key);
2765 }
2766 static uint32_t HashForObject(Key key, Object* object) { return 0; }
2767 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) {
2768 ASSERT(UsesSeed);
2769 return HashForObject(key, object);
2770 }
2771};
2772
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002773template<typename Shape, typename Key>
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002774class HashTable: public FixedArray {
2775 public:
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002776 // Wrapper methods
2777 inline uint32_t Hash(Key key) {
2778 if (Shape::UsesSeed) {
2779 return Shape::SeededHash(key,
2780 GetHeap()->HashSeed());
2781 } else {
2782 return Shape::Hash(key);
2783 }
2784 }
2785
2786 inline uint32_t HashForObject(Key key, Object* object) {
2787 if (Shape::UsesSeed) {
2788 return Shape::SeededHashForObject(key,
2789 GetHeap()->HashSeed(), object);
2790 } else {
2791 return Shape::HashForObject(key, object);
2792 }
2793 }
2794
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002795 // Returns the number of elements in the hash table.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002796 int NumberOfElements() {
2797 return Smi::cast(get(kNumberOfElementsIndex))->value();
2798 }
2799
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002800 // Returns the number of deleted elements in the hash table.
2801 int NumberOfDeletedElements() {
2802 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
2803 }
2804
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002805 // Returns the capacity of the hash table.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002806 int Capacity() {
2807 return Smi::cast(get(kCapacityIndex))->value();
2808 }
2809
2810 // ElementAdded should be called whenever an element is added to a
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002811 // hash table.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002812 void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); }
2813
2814 // ElementRemoved should be called whenever an element is removed from
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002815 // a hash table.
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002816 void ElementRemoved() {
2817 SetNumberOfElements(NumberOfElements() - 1);
2818 SetNumberOfDeletedElements(NumberOfDeletedElements() + 1);
2819 }
2820 void ElementsRemoved(int n) {
2821 SetNumberOfElements(NumberOfElements() - n);
2822 SetNumberOfDeletedElements(NumberOfDeletedElements() + n);
2823 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002824
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002825 // Returns a new HashTable object. Might return Failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002826 MUST_USE_RESULT static MaybeObject* Allocate(
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00002827 int at_least_space_for,
2828 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002829
ricow@chromium.org2c99e282011-07-28 09:15:17 +00002830 // Computes the required capacity for a table holding the given
2831 // number of elements. May be more than HashTable::kMaxCapacity.
2832 static int ComputeCapacity(int at_least_space_for);
2833
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002834 // Returns the key at entry.
2835 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
2836
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002837 // Tells whether k is a real key. The hole and undefined are not allowed
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002838 // as keys and can be used to indicate missing or deleted elements.
2839 bool IsKey(Object* k) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00002840 return !k->IsTheHole() && !k->IsUndefined();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002841 }
2842
2843 // Garbage collection support.
2844 void IteratePrefix(ObjectVisitor* visitor);
2845 void IterateElements(ObjectVisitor* visitor);
2846
2847 // Casting.
2848 static inline HashTable* cast(Object* obj);
2849
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002850 // Compute the probe offset (quadratic probing).
2851 INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
2852 return (n + n * n) >> 1;
2853 }
2854
2855 static const int kNumberOfElementsIndex = 0;
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002856 static const int kNumberOfDeletedElementsIndex = 1;
2857 static const int kCapacityIndex = 2;
2858 static const int kPrefixStartIndex = 3;
2859 static const int kElementsStartIndex =
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002860 kPrefixStartIndex + Shape::kPrefixSize;
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002861 static const int kEntrySize = Shape::kEntrySize;
2862 static const int kElementsStartOffset =
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002863 kHeaderSize + kElementsStartIndex * kPointerSize;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00002864 static const int kCapacityOffset =
2865 kHeaderSize + kCapacityIndex * kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002866
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00002867 // Constant used for denoting a absent entry.
2868 static const int kNotFound = -1;
2869
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002870 // Maximal capacity of HashTable. Based on maximal length of underlying
2871 // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
2872 // cannot overflow.
2873 static const int kMaxCapacity =
2874 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
2875
ricow@chromium.org4980dff2010-07-19 08:33:45 +00002876 // Find entry for key otherwise return kNotFound.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002877 inline int FindEntry(Key key);
2878 int FindEntry(Isolate* isolate, Key key);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002879
2880 protected:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002881 // Find the entry at which to insert element with the given key that
2882 // has the given hash value.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002883 uint32_t FindInsertionEntry(uint32_t hash);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002884
2885 // Returns the index for an entry (of the key)
2886 static inline int EntryToIndex(int entry) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002887 return (entry * kEntrySize) + kElementsStartIndex;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002888 }
2889
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002890 // Update the number of elements in the hash table.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002891 void SetNumberOfElements(int nof) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002892 set(kNumberOfElementsIndex, Smi::FromInt(nof));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002893 }
2894
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002895 // Update the number of deleted elements in the hash table.
2896 void SetNumberOfDeletedElements(int nod) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002897 set(kNumberOfDeletedElementsIndex, Smi::FromInt(nod));
kasperl@chromium.orgedf0cd12010-01-05 13:29:12 +00002898 }
2899
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002900 // Sets the capacity of the hash table.
2901 void SetCapacity(int capacity) {
2902 // To scale a computed hash code to fit within the hash table, we
2903 // use bit-wise AND with a mask, so the capacity must be positive
2904 // and non-zero.
2905 ASSERT(capacity > 0);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002906 ASSERT(capacity <= kMaxCapacity);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00002907 set(kCapacityIndex, Smi::FromInt(capacity));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002908 }
2909
2910
2911 // Returns probe entry.
2912 static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
2913 ASSERT(IsPowerOf2(size));
2914 return (hash + GetProbeOffset(number)) & (size - 1);
2915 }
2916
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00002917 static uint32_t FirstProbe(uint32_t hash, uint32_t size) {
2918 return hash & (size - 1);
2919 }
2920
2921 static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) {
2922 return (last + number) & (size - 1);
2923 }
2924
ager@chromium.org04921a82011-06-27 13:21:41 +00002925 // Rehashes this hash-table into the new table.
2926 MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key);
2927
2928 // Attempt to shrink hash table after removal of key.
2929 MUST_USE_RESULT MaybeObject* Shrink(Key key);
2930
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002931 // Ensure enough space for n additional elements.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002932 MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002933};
2934
2935
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002936// HashTableKey is an abstract superclass for virtual key behavior.
2937class HashTableKey {
2938 public:
2939 // Returns whether the other object matches this key.
2940 virtual bool IsMatch(Object* other) = 0;
2941 // Returns the hash value for this key.
2942 virtual uint32_t Hash() = 0;
2943 // Returns the hash value for object.
2944 virtual uint32_t HashForObject(Object* key) = 0;
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00002945 // Returns the key object for storing into the hash table.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002946 // If allocations fails a failure object is returned.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002947 MUST_USE_RESULT virtual MaybeObject* AsObject() = 0;
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002948 // Required.
2949 virtual ~HashTableKey() {}
2950};
2951
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00002952
2953class SymbolTableShape : public BaseShape<HashTableKey*> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002954 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002955 static inline bool IsMatch(HashTableKey* key, Object* value) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002956 return key->IsMatch(value);
2957 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002958 static inline uint32_t Hash(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002959 return key->Hash();
2960 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002961 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002962 return key->HashForObject(object);
2963 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00002964 MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002965 return key->AsObject();
2966 }
2967
2968 static const int kPrefixSize = 0;
2969 static const int kEntrySize = 1;
2970};
2971
danno@chromium.org40cb8782011-05-25 07:58:50 +00002972class SeqAsciiString;
2973
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002974// SymbolTable.
2975//
2976// No special elements in the prefix and the element size is 1
2977// because only the symbol itself (the key) needs to be stored.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00002978class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002979 public:
2980 // Find symbol in the symbol table. If it is not there yet, it is
2981 // added. The return value is the symbol table which might have
2982 // been enlarged. If the return value is not a failure, the symbol
2983 // pointer *s is set to the symbol found.
lrn@chromium.org303ada72010-10-27 09:33:13 +00002984 MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s);
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00002985 MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str,
2986 Object** s);
danno@chromium.org40cb8782011-05-25 07:58:50 +00002987 MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol(
2988 Handle<SeqAsciiString> str,
2989 int from,
2990 int length,
2991 Object** s);
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00002992 MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str,
2993 Object** s);
lrn@chromium.org303ada72010-10-27 09:33:13 +00002994 MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00002995
ager@chromium.org7c537e22008-10-16 08:43:32 +00002996 // Looks up a symbol that is equal to the given string and returns
2997 // true if it is found, assigning the symbol to the given output
2998 // parameter.
2999 bool LookupSymbolIfExists(String* str, String** symbol);
ager@chromium.org6141cbe2009-11-20 12:14:52 +00003000 bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol);
ager@chromium.org7c537e22008-10-16 08:43:32 +00003001
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003002 // Casting.
3003 static inline SymbolTable* cast(Object* obj);
3004
3005 private:
lrn@chromium.org303ada72010-10-27 09:33:13 +00003006 MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003007
3008 DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable);
3009};
3010
3011
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003012class MapCacheShape : public BaseShape<HashTableKey*> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003013 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003014 static inline bool IsMatch(HashTableKey* key, Object* value) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003015 return key->IsMatch(value);
3016 }
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003017 static inline uint32_t Hash(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003018 return key->Hash();
3019 }
3020
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003021 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003022 return key->HashForObject(object);
3023 }
3024
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00003025 MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003026 return key->AsObject();
3027 }
3028
3029 static const int kPrefixSize = 0;
3030 static const int kEntrySize = 2;
3031};
3032
3033
ager@chromium.org236ad962008-09-25 09:45:57 +00003034// MapCache.
3035//
3036// Maps keys that are a fixed array of symbols to a map.
3037// Used for canonicalize maps for object literals.
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003038class MapCache: public HashTable<MapCacheShape, HashTableKey*> {
ager@chromium.org236ad962008-09-25 09:45:57 +00003039 public:
3040 // Find cached value for a string key, otherwise return null.
3041 Object* Lookup(FixedArray* key);
lrn@chromium.org303ada72010-10-27 09:33:13 +00003042 MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value);
ager@chromium.org236ad962008-09-25 09:45:57 +00003043 static inline MapCache* cast(Object* obj);
3044
3045 private:
3046 DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache);
3047};
3048
3049
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003050template <typename Shape, typename Key>
3051class Dictionary: public HashTable<Shape, Key> {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003052 public:
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003053 static inline Dictionary<Shape, Key>* cast(Object* obj) {
3054 return reinterpret_cast<Dictionary<Shape, Key>*>(obj);
3055 }
3056
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003057 // Returns the value at entry.
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00003058 Object* ValueAt(int entry) {
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003059 return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00003060 }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003061
3062 // Set the value for entry.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003063 void ValueAtPut(int entry, Object* value) {
karlklose@chromium.org8f806e82011-03-07 14:06:08 +00003064 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003065 }
3066
3067 // Returns the property details for the property at entry.
3068 PropertyDetails DetailsAt(int entry) {
ager@chromium.org5aa501c2009-06-23 07:57:28 +00003069 ASSERT(entry >= 0); // Not found is -1, which is not caught by get().
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003070 return PropertyDetails(
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00003071 Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2)));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003072 }
3073
3074 // Set the details for entry.
3075 void DetailsAtPut(int entry, PropertyDetails value) {
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00003076 this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi());
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003077 }
3078
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003079 // Sorting support
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003080 void CopyValuesTo(FixedArray* elements);
3081
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003082 // Delete a property from the dictionary.
ager@chromium.orge2902be2009-06-08 12:21:35 +00003083 Object* DeleteProperty(int entry, JSObject::DeleteMode mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003084
ager@chromium.org04921a82011-06-27 13:21:41 +00003085 // Attempt to shrink the dictionary after deletion of key.
3086 MUST_USE_RESULT MaybeObject* Shrink(Key key);
3087
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003088 // Returns the number of elements in the dictionary filtering out properties
3089 // with the specified attributes.
3090 int NumberOfElementsFilterAttributes(PropertyAttributes filter);
3091
3092 // Returns the number of enumerable elements in the dictionary.
3093 int NumberOfEnumElements();
3094
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003095 enum SortMode { UNSORTED, SORTED };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003096 // Copies keys to preallocated fixed array.
sgjesse@chromium.org6db88712011-07-11 11:41:22 +00003097 void CopyKeysTo(FixedArray* storage,
3098 PropertyAttributes filter,
3099 SortMode sort_mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003100 // Fill in details for properties into storage.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003101 void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003102
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003103 // Accessors for next enumeration index.
3104 void SetNextEnumerationIndex(int index) {
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00003105 ASSERT(index != 0);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003106 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003107 }
3108
3109 int NextEnumerationIndex() {
3110 return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value();
3111 }
3112
3113 // Returns a new array for dictionary usage. Might return Failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003114 MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003115
3116 // Ensure enough space for n additional elements.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003117 MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003118
whesse@chromium.org023421e2010-12-21 12:19:12 +00003119#ifdef OBJECT_PRINT
3120 inline void Print() {
3121 Print(stdout);
3122 }
3123 void Print(FILE* out);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003124#endif
3125 // Returns the key (slow).
3126 Object* SlowReverseLookup(Object* value);
3127
3128 // Sets the entry to (key, value) pair.
3129 inline void SetEntry(int entry,
3130 Object* key,
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00003131 Object* value);
3132 inline void SetEntry(int entry,
3133 Object* key,
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003134 Object* value,
3135 PropertyDetails details);
3136
lrn@chromium.org303ada72010-10-27 09:33:13 +00003137 MUST_USE_RESULT MaybeObject* Add(Key key,
3138 Object* value,
3139 PropertyDetails details);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003140
3141 protected:
3142 // Generic at put operation.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003143 MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003144
3145 // Add entry to dictionary.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003146 MUST_USE_RESULT MaybeObject* AddEntry(Key key,
3147 Object* value,
3148 PropertyDetails details,
3149 uint32_t hash);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003150
3151 // Generate new enumeration indices to avoid enumeration index overflow.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003152 MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices();
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003153 static const int kMaxNumberKeyIndex =
3154 HashTable<Shape, Key>::kPrefixStartIndex;
3155 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
3156};
3157
3158
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003159class StringDictionaryShape : public BaseShape<String*> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003160 public:
3161 static inline bool IsMatch(String* key, Object* other);
3162 static inline uint32_t Hash(String* key);
3163 static inline uint32_t HashForObject(String* key, Object* object);
lrn@chromium.org303ada72010-10-27 09:33:13 +00003164 MUST_USE_RESULT static inline MaybeObject* AsObject(String* key);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003165 static const int kPrefixSize = 2;
3166 static const int kEntrySize = 3;
3167 static const bool kIsEnumerable = true;
3168};
3169
3170
3171class StringDictionary: public Dictionary<StringDictionaryShape, String*> {
3172 public:
3173 static inline StringDictionary* cast(Object* obj) {
3174 ASSERT(obj->IsDictionary());
3175 return reinterpret_cast<StringDictionary*>(obj);
3176 }
3177
3178 // Copies enumerable keys to preallocated fixed array.
3179 void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array);
3180
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003181 // For transforming properties of a JSObject.
lrn@chromium.org303ada72010-10-27 09:33:13 +00003182 MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor(
3183 JSObject* obj,
3184 int unused_property_fields);
ricow@chromium.org4980dff2010-07-19 08:33:45 +00003185
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003186 // Find entry for key, otherwise return kNotFound. Optimized version of
ricow@chromium.org4980dff2010-07-19 08:33:45 +00003187 // HashTable::FindEntry.
3188 int FindEntry(String* key);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003189};
3190
3191
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003192class NumberDictionaryShape : public BaseShape<uint32_t> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003193 public:
3194 static inline bool IsMatch(uint32_t key, Object* other);
lrn@chromium.org303ada72010-10-27 09:33:13 +00003195 MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003196 static const int kEntrySize = 3;
3197 static const bool kIsEnumerable = false;
3198};
3199
3200
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003201class SeededNumberDictionaryShape : public NumberDictionaryShape {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003202 public:
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003203 static const bool UsesSeed = true;
3204 static const int kPrefixSize = 2;
3205
3206 static inline uint32_t SeededHash(uint32_t key, uint32_t seed);
3207 static inline uint32_t SeededHashForObject(uint32_t key,
3208 uint32_t seed,
3209 Object* object);
3210};
3211
3212
3213class UnseededNumberDictionaryShape : public NumberDictionaryShape {
3214 public:
3215 static const int kPrefixSize = 0;
3216
3217 static inline uint32_t Hash(uint32_t key);
3218 static inline uint32_t HashForObject(uint32_t key, Object* object);
3219};
3220
3221
3222class SeededNumberDictionary
3223 : public Dictionary<SeededNumberDictionaryShape, uint32_t> {
3224 public:
3225 static SeededNumberDictionary* cast(Object* obj) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003226 ASSERT(obj->IsDictionary());
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003227 return reinterpret_cast<SeededNumberDictionary*>(obj);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003228 }
3229
3230 // Type specific at put (default NONE attributes is used when adding).
lrn@chromium.org303ada72010-10-27 09:33:13 +00003231 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value);
3232 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key,
3233 Object* value,
3234 PropertyDetails details);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003235
3236 // Set an existing entry or add a new one if needed.
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003237 // Return the updated dictionary.
3238 MUST_USE_RESULT static Handle<SeededNumberDictionary> Set(
3239 Handle<SeededNumberDictionary> dictionary,
3240 uint32_t index,
3241 Handle<Object> value,
3242 PropertyDetails details);
3243
lrn@chromium.org303ada72010-10-27 09:33:13 +00003244 MUST_USE_RESULT MaybeObject* Set(uint32_t key,
3245 Object* value,
3246 PropertyDetails details);
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00003247
3248 void UpdateMaxNumberKey(uint32_t key);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003249
3250 // If slow elements are required we will never go back to fast-case
3251 // for the elements kept in this dictionary. We require slow
3252 // elements if an element has been added at an index larger than
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003253 // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called
3254 // when defining a getter or setter with a number key.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003255 inline bool requires_slow_elements();
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00003256 inline void set_requires_slow_elements();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003257
3258 // Get the value of the max number key that has been added to this
3259 // dictionary. max_number_key can only be called if
3260 // requires_slow_elements returns false.
3261 inline uint32_t max_number_key();
3262
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003263 // Bit masks.
3264 static const int kRequiresSlowElementsMask = 1;
3265 static const int kRequiresSlowElementsTagSize = 1;
3266 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003267};
3268
3269
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003270class UnseededNumberDictionary
3271 : public Dictionary<UnseededNumberDictionaryShape, uint32_t> {
3272 public:
3273 static UnseededNumberDictionary* cast(Object* obj) {
3274 ASSERT(obj->IsDictionary());
3275 return reinterpret_cast<UnseededNumberDictionary*>(obj);
3276 }
3277
3278 // Type specific at put (default NONE attributes is used when adding).
3279 MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value);
3280 MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, Object* value);
3281
3282 // Set an existing entry or add a new one if needed.
3283 // Return the updated dictionary.
3284 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set(
3285 Handle<UnseededNumberDictionary> dictionary,
3286 uint32_t index,
3287 Handle<Object> value);
3288
3289 MUST_USE_RESULT MaybeObject* Set(uint32_t key, Object* value);
3290};
3291
3292
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003293template <int entrysize>
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00003294class ObjectHashTableShape : public BaseShape<Object*> {
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003295 public:
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003296 static inline bool IsMatch(Object* key, Object* other);
3297 static inline uint32_t Hash(Object* key);
3298 static inline uint32_t HashForObject(Object* key, Object* object);
3299 MUST_USE_RESULT static inline MaybeObject* AsObject(Object* key);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003300 static const int kPrefixSize = 0;
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003301 static const int kEntrySize = entrysize;
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003302};
3303
3304
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003305// ObjectHashSet holds keys that are arbitrary objects by using the identity
3306// hash of the key for hashing purposes.
3307class ObjectHashSet: public HashTable<ObjectHashTableShape<1>, Object*> {
3308 public:
3309 static inline ObjectHashSet* cast(Object* obj) {
3310 ASSERT(obj->IsHashTable());
3311 return reinterpret_cast<ObjectHashSet*>(obj);
3312 }
3313
3314 // Looks up whether the given key is part of this hash set.
3315 bool Contains(Object* key);
3316
3317 // Adds the given key to this hash set.
3318 MUST_USE_RESULT MaybeObject* Add(Object* key);
3319
3320 // Removes the given key from this hash set.
3321 MUST_USE_RESULT MaybeObject* Remove(Object* key);
3322};
3323
3324
3325// ObjectHashTable maps keys that are arbitrary objects to object values by
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003326// using the identity hash of the key for hashing purposes.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003327class ObjectHashTable: public HashTable<ObjectHashTableShape<2>, Object*> {
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003328 public:
3329 static inline ObjectHashTable* cast(Object* obj) {
3330 ASSERT(obj->IsHashTable());
3331 return reinterpret_cast<ObjectHashTable*>(obj);
3332 }
3333
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00003334 // Looks up the value associated with the given key. The hole value is
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003335 // returned in case the key is not present.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003336 Object* Lookup(Object* key);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003337
3338 // Adds (or overwrites) the value associated with the given key. Mapping a
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00003339 // key to the hole value causes removal of the whole entry.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003340 MUST_USE_RESULT MaybeObject* Put(Object* key, Object* value);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003341
3342 private:
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003343 friend class MarkCompactCollector;
3344
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003345 void AddEntry(int entry, Object* key, Object* value);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003346 void RemoveEntry(int entry);
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003347
3348 // Returns the index to the value of an entry.
3349 static inline int EntryToValueIndex(int entry) {
3350 return EntryToIndex(entry) + 1;
3351 }
vegorov@chromium.org7943d462011-08-01 11:41:52 +00003352};
3353
3354
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00003355// JSFunctionResultCache caches results of some JSFunction invocation.
3356// It is a fixed array with fixed structure:
3357// [0]: factory function
3358// [1]: finger index
3359// [2]: current cache size
3360// [3]: dummy field.
3361// The rest of array are key/value pairs.
3362class JSFunctionResultCache: public FixedArray {
3363 public:
3364 static const int kFactoryIndex = 0;
3365 static const int kFingerIndex = kFactoryIndex + 1;
3366 static const int kCacheSizeIndex = kFingerIndex + 1;
3367 static const int kDummyIndex = kCacheSizeIndex + 1;
3368 static const int kEntriesIndex = kDummyIndex + 1;
antonm@chromium.org397e23c2010-04-21 12:00:05 +00003369
3370 static const int kEntrySize = 2; // key + value
ager@chromium.orgac091b72010-05-05 07:34:42 +00003371
sgjesse@chromium.org720dc0b2010-05-10 09:25:39 +00003372 static const int kFactoryOffset = kHeaderSize;
3373 static const int kFingerOffset = kFactoryOffset + kPointerSize;
3374 static const int kCacheSizeOffset = kFingerOffset + kPointerSize;
3375
ager@chromium.orgac091b72010-05-05 07:34:42 +00003376 inline void MakeZeroSize();
3377 inline void Clear();
3378
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00003379 inline int size();
3380 inline void set_size(int size);
3381 inline int finger_index();
3382 inline void set_finger_index(int finger_index);
3383
ager@chromium.orgac091b72010-05-05 07:34:42 +00003384 // Casting
3385 static inline JSFunctionResultCache* cast(Object* obj);
3386
3387#ifdef DEBUG
3388 void JSFunctionResultCacheVerify();
3389#endif
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00003390};
3391
3392
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003393// ScopeInfo represents information about different scopes of a source
3394// program and the allocation of the scope's variables. Scope information
3395// is stored in a compressed form in ScopeInfo objects and is used
3396// at runtime (stack dumps, deoptimization, etc.).
3397
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003398// This object provides quick access to scope info details for runtime
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003399// routines.
3400class ScopeInfo : public FixedArray {
3401 public:
3402 static inline ScopeInfo* cast(Object* object);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003403
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003404 // Return the type of this scope.
3405 ScopeType Type();
3406
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003407 // Does this scope call eval?
3408 bool CallsEval();
3409
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00003410 // Return the language mode of this scope.
3411 LanguageMode language_mode();
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003412
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003413 // Does this scope make a non-strict eval call?
3414 bool CallsNonStrictEval() {
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00003415 return CallsEval() && (language_mode() == CLASSIC_MODE);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003416 }
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003417
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003418 // Return the total number of locals allocated on the stack and in the
3419 // context. This includes the parameters that are allocated in the context.
3420 int LocalCount();
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003421
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003422 // Return the number of stack slots for code. This number consists of two
3423 // parts:
3424 // 1. One stack slot per stack allocated local.
3425 // 2. One stack slot for the function name if it is stack allocated.
3426 int StackSlotCount();
3427
3428 // Return the number of context slots for code if a context is allocated. This
3429 // number consists of three parts:
3430 // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS
3431 // 2. One context slot per context allocated local.
3432 // 3. One context slot for the function name if it is context allocated.
3433 // Parameters allocated in the context count as context allocated locals. If
3434 // no contexts are allocated for this scope ContextLength returns 0.
3435 int ContextLength();
3436
3437 // Is this scope the scope of a named function expression?
3438 bool HasFunctionName();
3439
3440 // Return if this has context allocated locals.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003441 bool HasHeapAllocatedLocals();
3442
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003443 // Return if contexts are allocated for this scope.
3444 bool HasContext();
3445
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003446 // Return the function_name if present.
3447 String* FunctionName();
3448
3449 // Return the name of the given parameter.
3450 String* ParameterName(int var);
3451
3452 // Return the name of the given local.
3453 String* LocalName(int var);
3454
3455 // Return the name of the given stack local.
3456 String* StackLocalName(int var);
3457
3458 // Return the name of the given context local.
3459 String* ContextLocalName(int var);
3460
3461 // Return the mode of the given context local.
3462 VariableMode ContextLocalMode(int var);
3463
3464 // Return the initialization flag of the given context local.
3465 InitializationFlag ContextLocalInitFlag(int var);
3466
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003467 // Lookup support for serialized scope info. Returns the
3468 // the stack slot index for a given slot name if the slot is
3469 // present; otherwise returns a value < 0. The name must be a symbol
3470 // (canonicalized).
3471 int StackSlotIndex(String* name);
3472
3473 // Lookup support for serialized scope info. Returns the
3474 // context slot index for a given slot name if the slot is present; otherwise
3475 // returns a value < 0. The name must be a symbol (canonicalized).
3476 // If the slot is present and mode != NULL, sets *mode to the corresponding
3477 // mode for that variable.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003478 int ContextSlotIndex(String* name,
3479 VariableMode* mode,
3480 InitializationFlag* init_flag);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003481
3482 // Lookup support for serialized scope info. Returns the
3483 // parameter index for a given parameter name if the parameter is present;
3484 // otherwise returns a value < 0. The name must be a symbol (canonicalized).
3485 int ParameterIndex(String* name);
3486
jkummerow@chromium.org28faa982012-04-13 09:58:30 +00003487 // Lookup support for serialized scope info. Returns the function context
3488 // slot index if the function name is present and context-allocated (named
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003489 // function expressions, only), otherwise returns a value < 0. The name
3490 // must be a symbol (canonicalized).
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00003491 int FunctionContextSlotIndex(String* name, VariableMode* mode);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003492
mmassi@chromium.org7028c052012-06-13 11:51:58 +00003493 static Handle<ScopeInfo> Create(Scope* scope, Zone* zone);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003494
3495 // Serializes empty scope info.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003496 static ScopeInfo* Empty();
3497
3498#ifdef DEBUG
3499 void Print();
3500#endif
3501
3502 // The layout of the static part of a ScopeInfo is as follows. Each entry is
3503 // numeric and occupies one array slot.
3504 // 1. A set of properties of the scope
3505 // 2. The number of parameters. This only applies to function scopes. For
3506 // non-function scopes this is 0.
3507 // 3. The number of non-parameter variables allocated on the stack.
3508 // 4. The number of non-parameter and parameter variables allocated in the
3509 // context.
3510#define FOR_EACH_NUMERIC_FIELD(V) \
3511 V(Flags) \
3512 V(ParameterCount) \
3513 V(StackLocalCount) \
3514 V(ContextLocalCount)
3515
3516#define FIELD_ACCESSORS(name) \
3517 void Set##name(int value) { \
3518 set(k##name, Smi::FromInt(value)); \
3519 } \
3520 int name() { \
3521 if (length() > 0) { \
3522 return Smi::cast(get(k##name))->value(); \
3523 } else { \
3524 return 0; \
3525 } \
3526 }
3527 FOR_EACH_NUMERIC_FIELD(FIELD_ACCESSORS)
3528#undef FIELD_ACCESSORS
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003529
3530 private:
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003531 enum {
3532#define DECL_INDEX(name) k##name,
3533 FOR_EACH_NUMERIC_FIELD(DECL_INDEX)
3534#undef DECL_INDEX
3535#undef FOR_EACH_NUMERIC_FIELD
danno@chromium.org81cac2b2012-07-10 11:28:27 +00003536 kVariablePartIndex
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003537 };
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003538
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003539 // The layout of the variable part of a ScopeInfo is as follows:
3540 // 1. ParameterEntries:
3541 // This part stores the names of the parameters for function scopes. One
3542 // slot is used per parameter, so in total this part occupies
3543 // ParameterCount() slots in the array. For other scopes than function
3544 // scopes ParameterCount() is 0.
3545 // 2. StackLocalEntries:
3546 // Contains the names of local variables that are allocated on the stack,
3547 // in increasing order of the stack slot index. One slot is used per stack
3548 // local, so in total this part occupies StackLocalCount() slots in the
3549 // array.
3550 // 3. ContextLocalNameEntries:
3551 // Contains the names of local variables and parameters that are allocated
3552 // in the context. They are stored in increasing order of the context slot
3553 // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per
3554 // context local, so in total this part occupies ContextLocalCount() slots
3555 // in the array.
3556 // 4. ContextLocalInfoEntries:
3557 // Contains the variable modes and initialization flags corresponding to
3558 // the context locals in ContextLocalNameEntries. One slot is used per
3559 // context local, so in total this part occupies ContextLocalCount()
3560 // slots in the array.
3561 // 5. FunctionNameEntryIndex:
3562 // If the scope belongs to a named function expression this part contains
3563 // information about the function variable. It always occupies two array
3564 // slots: a. The name of the function variable.
3565 // b. The context or stack slot index for the variable.
3566 int ParameterEntriesIndex();
3567 int StackLocalEntriesIndex();
3568 int ContextLocalNameEntriesIndex();
3569 int ContextLocalInfoEntriesIndex();
3570 int FunctionNameEntryIndex();
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003571
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003572 // Location of the function variable for named function expressions.
3573 enum FunctionVariableInfo {
3574 NONE, // No function name present.
3575 STACK, // Function
3576 CONTEXT,
3577 UNUSED
3578 };
3579
3580 // Properties of scopes.
3581 class TypeField: public BitField<ScopeType, 0, 3> {};
3582 class CallsEvalField: public BitField<bool, 3, 1> {};
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00003583 class LanguageModeField: public BitField<LanguageMode, 4, 2> {};
3584 class FunctionVariableField: public BitField<FunctionVariableInfo, 6, 2> {};
3585 class FunctionVariableMode: public BitField<VariableMode, 8, 3> {};
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00003586
3587 // BitFields representing the encoded information for context locals in the
3588 // ContextLocalInfoEntries part.
3589 class ContextLocalMode: public BitField<VariableMode, 0, 3> {};
3590 class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {};
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00003591};
3592
3593
ricow@chromium.org65fae842010-08-25 15:26:24 +00003594// The cache for maps used by normalized (dictionary mode) objects.
3595// Such maps do not have property descriptors, so a typical program
3596// needs very limited number of distinct normalized maps.
3597class NormalizedMapCache: public FixedArray {
3598 public:
3599 static const int kEntries = 64;
3600
lrn@chromium.org303ada72010-10-27 09:33:13 +00003601 MUST_USE_RESULT MaybeObject* Get(JSObject* object,
3602 PropertyNormalizationMode mode);
ricow@chromium.org65fae842010-08-25 15:26:24 +00003603
ricow@chromium.org65fae842010-08-25 15:26:24 +00003604 void Clear();
3605
3606 // Casting
3607 static inline NormalizedMapCache* cast(Object* obj);
3608
3609#ifdef DEBUG
3610 void NormalizedMapCacheVerify();
3611#endif
ricow@chromium.org65fae842010-08-25 15:26:24 +00003612};
3613
3614
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003615// ByteArray represents fixed sized byte arrays. Used for the relocation info
3616// that is attached to code objects.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003617class ByteArray: public FixedArrayBase {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003618 public:
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003619 inline int Size() { return RoundUp(length() + kHeaderSize, kPointerSize); }
3620
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003621 // Setter and getter.
3622 inline byte get(int index);
3623 inline void set(int index, byte value);
3624
3625 // Treat contents as an int array.
3626 inline int get_int(int index);
3627
3628 static int SizeFor(int length) {
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003629 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003630 }
3631 // We use byte arrays for free blocks in the heap. Given a desired size in
3632 // bytes that is a multiple of the word size and big enough to hold a byte
3633 // array, this function returns the number of elements a byte array should
3634 // have.
3635 static int LengthFor(int size_in_bytes) {
3636 ASSERT(IsAligned(size_in_bytes, kPointerSize));
3637 ASSERT(size_in_bytes >= kHeaderSize);
3638 return size_in_bytes - kHeaderSize;
3639 }
3640
3641 // Returns data start address.
3642 inline Address GetDataStartAddress();
3643
3644 // Returns a pointer to the ByteArray object for a given data start address.
3645 static inline ByteArray* FromDataStartAddress(Address address);
3646
3647 // Casting.
3648 static inline ByteArray* cast(Object* obj);
3649
3650 // Dispatched behavior.
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00003651 inline int ByteArraySize() {
3652 return SizeFor(this->length());
3653 }
whesse@chromium.org023421e2010-12-21 12:19:12 +00003654#ifdef OBJECT_PRINT
3655 inline void ByteArrayPrint() {
3656 ByteArrayPrint(stdout);
3657 }
3658 void ByteArrayPrint(FILE* out);
3659#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003660#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003661 void ByteArrayVerify();
3662#endif
3663
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003664 // Layout description.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003665 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
kasperl@chromium.orge959c182009-07-27 08:59:04 +00003666
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00003667 // Maximal memory consumption for a single ByteArray.
3668 static const int kMaxSize = 512 * MB;
3669 // Maximal length of a single ByteArray.
3670 static const int kMaxLength = kMaxSize - kHeaderSize;
3671
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00003672 private:
3673 DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray);
3674};
3675
3676
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003677// FreeSpace represents fixed sized areas of the heap that are not currently in
3678// use. Used by the heap and GC.
3679class FreeSpace: public HeapObject {
3680 public:
3681 // [size]: size of the free space including the header.
3682 inline int size();
3683 inline void set_size(int value);
3684
3685 inline int Size() { return size(); }
3686
3687 // Casting.
3688 static inline FreeSpace* cast(Object* obj);
3689
3690#ifdef OBJECT_PRINT
3691 inline void FreeSpacePrint() {
3692 FreeSpacePrint(stdout);
3693 }
3694 void FreeSpacePrint(FILE* out);
3695#endif
3696#ifdef DEBUG
3697 void FreeSpaceVerify();
3698#endif
3699
3700 // Layout description.
3701 // Size is smi tagged when it is stored.
3702 static const int kSizeOffset = HeapObject::kHeaderSize;
3703 static const int kHeaderSize = kSizeOffset + kPointerSize;
3704
3705 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
3706
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00003707 private:
3708 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace);
3709};
3710
3711
ager@chromium.org3811b432009-10-28 14:53:37 +00003712// An ExternalArray represents a fixed-size array of primitive values
3713// which live outside the JavaScript heap. Its subclasses are used to
3714// implement the CanvasArray types being defined in the WebGL
3715// specification. As of this writing the first public draft is not yet
3716// available, but Khronos members can access the draft at:
3717// https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html
3718//
3719// The semantics of these arrays differ from CanvasPixelArray.
3720// Out-of-range values passed to the setter are converted via a C
3721// cast, not clamping. Out-of-range indices cause exceptions to be
3722// raised rather than being silently ignored.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003723class ExternalArray: public FixedArrayBase {
ager@chromium.org3811b432009-10-28 14:53:37 +00003724 public:
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003725 inline bool is_the_hole(int index) { return false; }
3726
ager@chromium.org3811b432009-10-28 14:53:37 +00003727 // [external_pointer]: The pointer to the external memory area backing this
3728 // external array.
3729 DECL_ACCESSORS(external_pointer, void) // Pointer to the data store.
3730
3731 // Casting.
3732 static inline ExternalArray* cast(Object* obj);
3733
3734 // Maximal acceptable length for an external array.
3735 static const int kMaxLength = 0x3fffffff;
3736
3737 // ExternalArray headers are not quadword aligned.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003738 static const int kExternalPointerOffset =
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00003739 POINTER_SIZE_ALIGN(FixedArrayBase::kLengthOffset + kPointerSize);
ager@chromium.org3811b432009-10-28 14:53:37 +00003740 static const int kHeaderSize = kExternalPointerOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00003741 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
ager@chromium.org3811b432009-10-28 14:53:37 +00003742
3743 private:
3744 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray);
3745};
3746
3747
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00003748// A ExternalPixelArray represents a fixed-size byte array with special
3749// semantics used for implementing the CanvasPixelArray object. Please see the
3750// specification at:
3751
3752// http://www.whatwg.org/specs/web-apps/current-work/
3753// multipage/the-canvas-element.html#canvaspixelarray
3754// In particular, write access clamps the value written to 0 or 255 if the
3755// value written is outside this range.
3756class ExternalPixelArray: public ExternalArray {
3757 public:
3758 inline uint8_t* external_pixel_pointer();
3759
3760 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003761 inline uint8_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003762 MUST_USE_RESULT inline MaybeObject* get(int index);
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00003763 inline void set(int index, uint8_t value);
3764
3765 // This accessor applies the correct conversion from Smi, HeapNumber and
3766 // undefined and clamps the converted value between 0 and 255.
3767 Object* SetValue(uint32_t index, Object* value);
3768
3769 // Casting.
3770 static inline ExternalPixelArray* cast(Object* obj);
3771
3772#ifdef OBJECT_PRINT
3773 inline void ExternalPixelArrayPrint() {
3774 ExternalPixelArrayPrint(stdout);
3775 }
3776 void ExternalPixelArrayPrint(FILE* out);
3777#endif
3778#ifdef DEBUG
3779 void ExternalPixelArrayVerify();
3780#endif // DEBUG
3781
3782 private:
3783 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray);
3784};
3785
3786
ager@chromium.org3811b432009-10-28 14:53:37 +00003787class ExternalByteArray: public ExternalArray {
3788 public:
3789 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003790 inline int8_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003791 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003792 inline void set(int index, int8_t value);
3793
3794 // This accessor applies the correct conversion from Smi, HeapNumber
3795 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003796 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003797
3798 // Casting.
3799 static inline ExternalByteArray* cast(Object* obj);
3800
whesse@chromium.org023421e2010-12-21 12:19:12 +00003801#ifdef OBJECT_PRINT
3802 inline void ExternalByteArrayPrint() {
3803 ExternalByteArrayPrint(stdout);
3804 }
3805 void ExternalByteArrayPrint(FILE* out);
3806#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003807#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003808 void ExternalByteArrayVerify();
3809#endif // DEBUG
3810
3811 private:
3812 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray);
3813};
3814
3815
3816class ExternalUnsignedByteArray: public ExternalArray {
3817 public:
3818 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003819 inline uint8_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003820 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003821 inline void set(int index, uint8_t value);
3822
3823 // This accessor applies the correct conversion from Smi, HeapNumber
3824 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003825 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003826
3827 // Casting.
3828 static inline ExternalUnsignedByteArray* cast(Object* obj);
3829
whesse@chromium.org023421e2010-12-21 12:19:12 +00003830#ifdef OBJECT_PRINT
3831 inline void ExternalUnsignedByteArrayPrint() {
3832 ExternalUnsignedByteArrayPrint(stdout);
3833 }
3834 void ExternalUnsignedByteArrayPrint(FILE* out);
3835#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003836#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003837 void ExternalUnsignedByteArrayVerify();
3838#endif // DEBUG
3839
3840 private:
3841 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray);
3842};
3843
3844
3845class ExternalShortArray: public ExternalArray {
3846 public:
3847 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003848 inline int16_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003849 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003850 inline void set(int index, int16_t value);
3851
3852 // This accessor applies the correct conversion from Smi, HeapNumber
3853 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003854 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003855
3856 // Casting.
3857 static inline ExternalShortArray* cast(Object* obj);
3858
whesse@chromium.org023421e2010-12-21 12:19:12 +00003859#ifdef OBJECT_PRINT
3860 inline void ExternalShortArrayPrint() {
3861 ExternalShortArrayPrint(stdout);
3862 }
3863 void ExternalShortArrayPrint(FILE* out);
3864#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003865#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003866 void ExternalShortArrayVerify();
3867#endif // DEBUG
3868
3869 private:
3870 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray);
3871};
3872
3873
3874class ExternalUnsignedShortArray: public ExternalArray {
3875 public:
3876 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003877 inline uint16_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003878 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003879 inline void set(int index, uint16_t value);
3880
3881 // This accessor applies the correct conversion from Smi, HeapNumber
3882 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003883 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003884
3885 // Casting.
3886 static inline ExternalUnsignedShortArray* cast(Object* obj);
3887
whesse@chromium.org023421e2010-12-21 12:19:12 +00003888#ifdef OBJECT_PRINT
3889 inline void ExternalUnsignedShortArrayPrint() {
3890 ExternalUnsignedShortArrayPrint(stdout);
3891 }
3892 void ExternalUnsignedShortArrayPrint(FILE* out);
3893#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003894#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003895 void ExternalUnsignedShortArrayVerify();
3896#endif // DEBUG
3897
3898 private:
3899 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray);
3900};
3901
3902
3903class ExternalIntArray: public ExternalArray {
3904 public:
3905 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003906 inline int32_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003907 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003908 inline void set(int index, int32_t value);
3909
3910 // This accessor applies the correct conversion from Smi, HeapNumber
3911 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003912 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003913
3914 // Casting.
3915 static inline ExternalIntArray* cast(Object* obj);
3916
whesse@chromium.org023421e2010-12-21 12:19:12 +00003917#ifdef OBJECT_PRINT
3918 inline void ExternalIntArrayPrint() {
3919 ExternalIntArrayPrint(stdout);
3920 }
3921 void ExternalIntArrayPrint(FILE* out);
3922#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003923#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003924 void ExternalIntArrayVerify();
3925#endif // DEBUG
3926
3927 private:
3928 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray);
3929};
3930
3931
3932class ExternalUnsignedIntArray: public ExternalArray {
3933 public:
3934 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003935 inline uint32_t get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003936 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003937 inline void set(int index, uint32_t value);
3938
3939 // This accessor applies the correct conversion from Smi, HeapNumber
3940 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003941 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003942
3943 // Casting.
3944 static inline ExternalUnsignedIntArray* cast(Object* obj);
3945
whesse@chromium.org023421e2010-12-21 12:19:12 +00003946#ifdef OBJECT_PRINT
3947 inline void ExternalUnsignedIntArrayPrint() {
3948 ExternalUnsignedIntArrayPrint(stdout);
3949 }
3950 void ExternalUnsignedIntArrayPrint(FILE* out);
3951#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003952#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003953 void ExternalUnsignedIntArrayVerify();
3954#endif // DEBUG
3955
3956 private:
3957 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray);
3958};
3959
3960
3961class ExternalFloatArray: public ExternalArray {
3962 public:
3963 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003964 inline float get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003965 MUST_USE_RESULT inline MaybeObject* get(int index);
ager@chromium.org3811b432009-10-28 14:53:37 +00003966 inline void set(int index, float value);
3967
3968 // This accessor applies the correct conversion from Smi, HeapNumber
3969 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003970 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
ager@chromium.org3811b432009-10-28 14:53:37 +00003971
3972 // Casting.
3973 static inline ExternalFloatArray* cast(Object* obj);
3974
whesse@chromium.org023421e2010-12-21 12:19:12 +00003975#ifdef OBJECT_PRINT
3976 inline void ExternalFloatArrayPrint() {
3977 ExternalFloatArrayPrint(stdout);
3978 }
3979 void ExternalFloatArrayPrint(FILE* out);
3980#endif
ager@chromium.org3811b432009-10-28 14:53:37 +00003981#ifdef DEBUG
ager@chromium.org3811b432009-10-28 14:53:37 +00003982 void ExternalFloatArrayVerify();
3983#endif // DEBUG
3984
3985 private:
3986 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray);
3987};
3988
3989
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00003990class ExternalDoubleArray: public ExternalArray {
3991 public:
3992 // Setter and getter.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00003993 inline double get_scalar(int index);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003994 MUST_USE_RESULT inline MaybeObject* get(int index);
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00003995 inline void set(int index, double value);
3996
3997 // This accessor applies the correct conversion from Smi, HeapNumber
3998 // and undefined.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00003999 MUST_USE_RESULT MaybeObject* SetValue(uint32_t index, Object* value);
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004000
4001 // Casting.
4002 static inline ExternalDoubleArray* cast(Object* obj);
4003
4004#ifdef OBJECT_PRINT
4005 inline void ExternalDoubleArrayPrint() {
4006 ExternalDoubleArrayPrint(stdout);
4007 }
4008 void ExternalDoubleArrayPrint(FILE* out);
4009#endif // OBJECT_PRINT
4010#ifdef DEBUG
4011 void ExternalDoubleArrayVerify();
4012#endif // DEBUG
4013
4014 private:
4015 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray);
4016};
4017
4018
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004019// DeoptimizationInputData is a fixed array used to hold the deoptimization
4020// data for code generated by the Hydrogen/Lithium compiler. It also
4021// contains information about functions that were inlined. If N different
4022// functions were inlined then first N elements of the literal array will
4023// contain these functions.
4024//
4025// It can be empty.
4026class DeoptimizationInputData: public FixedArray {
4027 public:
4028 // Layout description. Indices in the array.
4029 static const int kTranslationByteArrayIndex = 0;
4030 static const int kInlinedFunctionCountIndex = 1;
4031 static const int kLiteralArrayIndex = 2;
4032 static const int kOsrAstIdIndex = 3;
4033 static const int kOsrPcOffsetIndex = 4;
4034 static const int kFirstDeoptEntryIndex = 5;
4035
4036 // Offsets of deopt entry elements relative to the start of the entry.
4037 static const int kAstIdOffset = 0;
4038 static const int kTranslationIndexOffset = 1;
4039 static const int kArgumentsStackHeightOffset = 2;
ricow@chromium.org27bf2882011-11-17 08:34:43 +00004040 static const int kPcOffset = 3;
4041 static const int kDeoptEntrySize = 4;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004042
4043 // Simple element accessors.
4044#define DEFINE_ELEMENT_ACCESSORS(name, type) \
4045 type* name() { \
4046 return type::cast(get(k##name##Index)); \
4047 } \
4048 void Set##name(type* value) { \
4049 set(k##name##Index, value); \
4050 }
4051
4052 DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
4053 DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
4054 DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
4055 DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi)
4056 DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
4057
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004058#undef DEFINE_ELEMENT_ACCESSORS
4059
4060 // Accessors for elements of the ith deoptimization entry.
4061#define DEFINE_ENTRY_ACCESSORS(name, type) \
4062 type* name(int i) { \
4063 return type::cast(get(IndexForEntry(i) + k##name##Offset)); \
4064 } \
4065 void Set##name(int i, type* value) { \
4066 set(IndexForEntry(i) + k##name##Offset, value); \
4067 }
4068
4069 DEFINE_ENTRY_ACCESSORS(AstId, Smi)
4070 DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi)
4071 DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi)
ricow@chromium.org27bf2882011-11-17 08:34:43 +00004072 DEFINE_ENTRY_ACCESSORS(Pc, Smi)
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004073
4074#undef DEFINE_ENTRY_ACCESSORS
4075
4076 int DeoptCount() {
4077 return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize;
4078 }
4079
4080 // Allocates a DeoptimizationInputData.
4081 MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count,
4082 PretenureFlag pretenure);
4083
4084 // Casting.
4085 static inline DeoptimizationInputData* cast(Object* obj);
4086
ricow@chromium.org4f693d62011-07-04 14:01:31 +00004087#ifdef ENABLE_DISASSEMBLER
whesse@chromium.org023421e2010-12-21 12:19:12 +00004088 void DeoptimizationInputDataPrint(FILE* out);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004089#endif
4090
4091 private:
4092 static int IndexForEntry(int i) {
4093 return kFirstDeoptEntryIndex + (i * kDeoptEntrySize);
4094 }
4095
4096 static int LengthFor(int entry_count) {
4097 return IndexForEntry(entry_count);
4098 }
4099};
4100
4101
4102// DeoptimizationOutputData is a fixed array used to hold the deoptimization
4103// data for code generated by the full compiler.
4104// The format of the these objects is
4105// [i * 2]: Ast ID for ith deoptimization.
4106// [i * 2 + 1]: PC and state of ith deoptimization
4107class DeoptimizationOutputData: public FixedArray {
4108 public:
4109 int DeoptPoints() { return length() / 2; }
4110 Smi* AstId(int index) { return Smi::cast(get(index * 2)); }
4111 void SetAstId(int index, Smi* id) { set(index * 2, id); }
4112 Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); }
4113 void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); }
4114
4115 static int LengthOfFixedArray(int deopt_points) {
4116 return deopt_points * 2;
4117 }
4118
4119 // Allocates a DeoptimizationOutputData.
4120 MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points,
4121 PretenureFlag pretenure);
4122
4123 // Casting.
4124 static inline DeoptimizationOutputData* cast(Object* obj);
4125
whesse@chromium.org7b260152011-06-20 15:33:18 +00004126#if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER)
whesse@chromium.org023421e2010-12-21 12:19:12 +00004127 void DeoptimizationOutputDataPrint(FILE* out);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004128#endif
4129};
4130
4131
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004132// Forward declaration.
4133class JSGlobalPropertyCell;
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004134
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004135// TypeFeedbackCells is a fixed array used to hold the association between
4136// cache cells and AST ids for code generated by the full compiler.
4137// The format of the these objects is
4138// [i * 2]: Global property cell of ith cache cell.
4139// [i * 2 + 1]: Ast ID for ith cache cell.
4140class TypeFeedbackCells: public FixedArray {
4141 public:
4142 int CellCount() { return length() / 2; }
4143 static int LengthOfFixedArray(int cell_count) { return cell_count * 2; }
4144
4145 // Accessors for AST ids associated with cache values.
4146 inline Smi* AstId(int index);
4147 inline void SetAstId(int index, Smi* id);
4148
4149 // Accessors for global property cells holding the cache values.
4150 inline JSGlobalPropertyCell* Cell(int index);
4151 inline void SetCell(int index, JSGlobalPropertyCell* cell);
4152
4153 // The object that indicates an uninitialized cache.
4154 static inline Handle<Object> UninitializedSentinel(Isolate* isolate);
4155
4156 // The object that indicates a megamorphic state.
4157 static inline Handle<Object> MegamorphicSentinel(Isolate* isolate);
4158
4159 // A raw version of the uninitialized sentinel that's safe to read during
4160 // garbage collection (e.g., for patching the cache).
4161 static inline Object* RawUninitializedSentinel(Heap* heap);
4162
4163 // Casting.
4164 static inline TypeFeedbackCells* cast(Object* obj);
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00004165
4166 static const int kForInFastCaseMarker = 0;
4167 static const int kForInSlowCaseMarker = 1;
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004168};
4169
4170
4171// Forward declaration.
4172class SafepointEntry;
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00004173class TypeFeedbackInfo;
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004174
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004175// Code describes objects with on-the-fly generated machine code.
4176class Code: public HeapObject {
4177 public:
4178 // Opaque data type for encapsulating code flags like kind, inline
4179 // cache state, and arguments count.
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00004180 // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that
4181 // enumeration type has correct value range (see Issue 830 for more details).
4182 enum Flags {
4183 FLAGS_MIN_VALUE = kMinInt,
4184 FLAGS_MAX_VALUE = kMaxInt
4185 };
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004186
verwaest@chromium.org753aee42012-07-17 16:15:42 +00004187#define CODE_KIND_LIST(V) \
4188 V(FUNCTION) \
4189 V(OPTIMIZED_FUNCTION) \
4190 V(STUB) \
4191 V(BUILTIN) \
4192 V(LOAD_IC) \
4193 V(KEYED_LOAD_IC) \
4194 V(CALL_IC) \
4195 V(KEYED_CALL_IC) \
4196 V(STORE_IC) \
4197 V(KEYED_STORE_IC) \
4198 V(UNARY_OP_IC) \
4199 V(BINARY_OP_IC) \
4200 V(COMPARE_IC) \
4201 V(TO_BOOLEAN_IC)
4202
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004203 enum Kind {
verwaest@chromium.org753aee42012-07-17 16:15:42 +00004204#define DEFINE_CODE_KIND_ENUM(name) name,
4205 CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM)
4206#undef DEFINE_CODE_KIND_ENUM
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004207
4208 // Pseudo-kinds.
verwaest@chromium.org753aee42012-07-17 16:15:42 +00004209 LAST_CODE_KIND = TO_BOOLEAN_IC,
ager@chromium.orga74f0da2008-12-03 16:05:52 +00004210 REGEXP = BUILTIN,
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004211 FIRST_IC_KIND = LOAD_IC,
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004212 LAST_IC_KIND = TO_BOOLEAN_IC
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004213 };
4214
verwaest@chromium.org753aee42012-07-17 16:15:42 +00004215 // No more than 16 kinds. The value is currently encoded in four bits in
4216 // Flags.
4217 STATIC_ASSERT(LAST_CODE_KIND < 16);
4218
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004219 // Types of stubs.
4220 enum StubType {
4221 NORMAL,
4222 FIELD,
4223 CONSTANT_FUNCTION,
4224 CALLBACKS,
4225 INTERCEPTOR,
4226 MAP_TRANSITION,
4227 NONEXISTENT
4228 };
4229
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004230 enum {
fschneider@chromium.orged78ffd2010-07-21 11:05:19 +00004231 NUMBER_OF_KINDS = LAST_IC_KIND + 1
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004232 };
4233
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004234 typedef int ExtraICState;
4235
4236 static const ExtraICState kNoExtraICState = 0;
4237
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00004238#ifdef ENABLE_DISASSEMBLER
4239 // Printing
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004240 static const char* Kind2String(Kind kind);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00004241 static const char* ICState2String(InlineCacheState state);
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004242 static const char* StubType2String(StubType type);
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00004243 static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra);
whesse@chromium.org023421e2010-12-21 12:19:12 +00004244 inline void Disassemble(const char* name) {
4245 Disassemble(name, stdout);
4246 }
4247 void Disassemble(const char* name, FILE* out);
mads.s.ager@gmail.com769cc962008-08-06 10:02:49 +00004248#endif // ENABLE_DISASSEMBLER
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004249
4250 // [instruction_size]: Size of the native instructions
4251 inline int instruction_size();
4252 inline void set_instruction_size(int value);
4253
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004254 // [relocation_info]: Code relocation information
4255 DECL_ACCESSORS(relocation_info, ByteArray)
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004256 void InvalidateRelocation();
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004257
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00004258 // [handler_table]: Fixed array containing offsets of exception handlers.
4259 DECL_ACCESSORS(handler_table, FixedArray)
4260
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004261 // [deoptimization_data]: Array containing data for deopt.
4262 DECL_ACCESSORS(deoptimization_data, FixedArray)
4263
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00004264 // [type_feedback_info]: Struct containing type feedback information.
4265 // Will contain either a TypeFeedbackInfo object, or undefined.
4266 DECL_ACCESSORS(type_feedback_info, Object)
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004267
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00004268 // [gc_metadata]: Field used to hold GC related metadata. The contents of this
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00004269 // field does not have to be traced during garbage collection since
4270 // it is only used by the garbage collector itself.
yangguo@chromium.org659ceec2012-01-26 07:37:54 +00004271 DECL_ACCESSORS(gc_metadata, Object)
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00004272
danno@chromium.org88aa0582012-03-23 15:11:57 +00004273 // [ic_age]: Inline caching age: the value of the Heap::global_ic_age
4274 // at the moment when this object was created.
4275 inline void set_ic_age(int count);
4276 inline int ic_age();
4277
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004278 // Unchecked accessors to be used during GC.
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004279 inline ByteArray* unchecked_relocation_info();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004280 inline FixedArray* unchecked_deoptimization_data();
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004281
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004282 inline int relocation_size();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004283
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004284 // [flags]: Various code flags.
4285 inline Flags flags();
4286 inline void set_flags(Flags flags);
4287
4288 // [flags]: Access to specific code flags.
4289 inline Kind kind();
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004290 inline InlineCacheState ic_state(); // Only valid for IC stubs.
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004291 inline ExtraICState extra_ic_state(); // Only valid for IC stubs.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004292 inline StubType type(); // Only valid for monomorphic IC stubs.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004293 inline int arguments_count(); // Only valid for call IC stubs.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004294
4295 // Testers for IC stub kinds.
4296 inline bool is_inline_cache_stub();
4297 inline bool is_load_stub() { return kind() == LOAD_IC; }
4298 inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; }
4299 inline bool is_store_stub() { return kind() == STORE_IC; }
4300 inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; }
4301 inline bool is_call_stub() { return kind() == CALL_IC; }
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00004302 inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; }
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004303 inline bool is_unary_op_stub() { return kind() == UNARY_OP_IC; }
4304 inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; }
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004305 inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; }
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004306 inline bool is_to_boolean_ic_stub() { return kind() == TO_BOOLEAN_IC; }
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004307
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00004308 // [major_key]: For kind STUB or BINARY_OP_IC, the major key.
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00004309 inline int major_key();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004310 inline void set_major_key(int value);
4311
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004312 // For stubs, tells whether they should always exist, so that they can be
4313 // called from other stubs.
4314 inline bool is_pregenerated();
4315 inline void set_is_pregenerated(bool value);
4316
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004317 // [optimizable]: For FUNCTION kind, tells if it is optimizable.
4318 inline bool optimizable();
4319 inline void set_optimizable(bool value);
4320
4321 // [has_deoptimization_support]: For FUNCTION kind, tells if it has
4322 // deoptimization support.
4323 inline bool has_deoptimization_support();
4324 inline void set_has_deoptimization_support(bool value);
4325
lrn@chromium.org34e60782011-09-15 07:25:40 +00004326 // [has_debug_break_slots]: For FUNCTION kind, tells if it has
4327 // been compiled with debug break slots.
4328 inline bool has_debug_break_slots();
4329 inline void set_has_debug_break_slots(bool value);
4330
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004331 // [compiled_with_optimizing]: For FUNCTION kind, tells if it has
4332 // been compiled with IsOptimizing set to true.
4333 inline bool is_compiled_optimizable();
4334 inline void set_compiled_optimizable(bool value);
4335
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004336 // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for
4337 // how long the function has been marked for OSR and therefore which
4338 // level of loop nesting we are willing to do on-stack replacement
4339 // for.
4340 inline void set_allow_osr_at_loop_nesting_level(int level);
4341 inline int allow_osr_at_loop_nesting_level();
4342
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00004343 // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks
4344 // the code object was seen on the stack with no IC patching going on.
4345 inline int profiler_ticks();
4346 inline void set_profiler_ticks(int ticks);
4347
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004348 // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots
4349 // reserved in the code prologue.
4350 inline unsigned stack_slots();
4351 inline void set_stack_slots(unsigned slots);
4352
4353 // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in
4354 // the instruction stream where the safepoint table starts.
ricow@chromium.org83aa5492011-02-07 12:42:56 +00004355 inline unsigned safepoint_table_offset();
4356 inline void set_safepoint_table_offset(unsigned offset);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004357
4358 // [stack_check_table_start]: For kind FUNCTION, the offset in the
4359 // instruction stream where the stack check table starts.
ricow@chromium.org83aa5492011-02-07 12:42:56 +00004360 inline unsigned stack_check_table_offset();
4361 inline void set_stack_check_table_offset(unsigned offset);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004362
4363 // [check type]: For kind CALL_IC, tells how to check if the
4364 // receiver is valid for the given call.
4365 inline CheckType check_type();
4366 inline void set_check_type(CheckType value);
4367
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004368 // [type-recording unary op type]: For kind UNARY_OP_IC.
danno@chromium.org40cb8782011-05-25 07:58:50 +00004369 inline byte unary_op_type();
4370 inline void set_unary_op_type(byte value);
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +00004371
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004372 // [type-recording binary op type]: For kind BINARY_OP_IC.
danno@chromium.org40cb8782011-05-25 07:58:50 +00004373 inline byte binary_op_type();
4374 inline void set_binary_op_type(byte value);
4375 inline byte binary_op_result_type();
4376 inline void set_binary_op_result_type(byte value);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004377
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004378 // [compare state]: For kind COMPARE_IC, tells what state the stub is in.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004379 inline byte compare_state();
4380 inline void set_compare_state(byte value);
4381
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004382 // [compare_operation]: For kind COMPARE_IC tells what compare operation the
4383 // stub was generated for.
4384 inline byte compare_operation();
4385 inline void set_compare_operation(byte value);
4386
ricow@chromium.org9fa09672011-07-25 11:05:35 +00004387 // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in.
4388 inline byte to_boolean_state();
4389 inline void set_to_boolean_state(byte value);
4390
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004391 // [has_function_cache]: For kind STUB tells whether there is a function
4392 // cache is passed to the stub.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004393 inline bool has_function_cache();
4394 inline void set_has_function_cache(bool flag);
4395
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004396 bool allowed_in_shared_map_code_cache();
4397
sgjesse@chromium.orgc6c57182011-01-17 12:24:25 +00004398 // Get the safepoint entry for the given pc.
4399 SafepointEntry GetSafepointEntry(Address pc);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004400
4401 // Mark this code object as not having a stack check table. Assumes kind
4402 // is FUNCTION.
4403 void SetNoStackCheckTable();
4404
4405 // Find the first map in an IC stub.
4406 Map* FindFirstMap();
kasper.lund7276f142008-07-30 08:49:36 +00004407
ulan@chromium.org65a89c22012-02-14 11:46:07 +00004408 class ExtraICStateStrictMode: public BitField<StrictModeFlag, 0, 1> {};
4409 class ExtraICStateKeyedAccessGrowMode:
4410 public BitField<KeyedAccessGrowMode, 1, 1> {}; // NOLINT
4411
4412 static const int kExtraICStateGrowModeShift = 1;
4413
4414 static inline StrictModeFlag GetStrictMode(ExtraICState extra_ic_state) {
4415 return ExtraICStateStrictMode::decode(extra_ic_state);
4416 }
4417
4418 static inline KeyedAccessGrowMode GetKeyedAccessGrowMode(
4419 ExtraICState extra_ic_state) {
4420 return ExtraICStateKeyedAccessGrowMode::decode(extra_ic_state);
4421 }
4422
4423 static inline ExtraICState ComputeExtraICState(
4424 KeyedAccessGrowMode grow_mode,
4425 StrictModeFlag strict_mode) {
4426 return ExtraICStateKeyedAccessGrowMode::encode(grow_mode) |
4427 ExtraICStateStrictMode::encode(strict_mode);
4428 }
4429
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004430 // Flags operations.
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004431 static inline Flags ComputeFlags(
4432 Kind kind,
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004433 InlineCacheState ic_state = UNINITIALIZED,
4434 ExtraICState extra_ic_state = kNoExtraICState,
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004435 StubType type = NORMAL,
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004436 int argc = -1,
4437 InlineCacheHolderFlag holder = OWN_MAP);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004438
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004439 static inline Flags ComputeMonomorphicFlags(
4440 Kind kind,
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004441 StubType type,
erik.corry@gmail.com0511e242011-01-19 11:11:08 +00004442 ExtraICState extra_ic_state = kNoExtraICState,
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004443 InlineCacheHolderFlag holder = OWN_MAP,
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004444 int argc = -1);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004445
kasper.lund7276f142008-07-30 08:49:36 +00004446 static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004447 static inline StubType ExtractTypeFromFlags(Flags flags);
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004448 static inline Kind ExtractKindFromFlags(Flags flags);
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004449 static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004450 static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags);
4451 static inline int ExtractArgumentsCountFromFlags(Flags flags);
4452
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004453 static inline Flags RemoveTypeFromFlags(Flags flags);
4454
ager@chromium.org8bb60582008-12-11 12:02:20 +00004455 // Convert a target address into a code object.
4456 static inline Code* GetCodeFromTargetAddress(Address address);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004457
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00004458 // Convert an entry address into an object.
4459 static inline Object* GetObjectFromEntryAddress(Address location_of_address);
4460
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004461 // Returns the address of the first instruction.
4462 inline byte* instruction_start();
4463
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004464 // Returns the address right after the last instruction.
4465 inline byte* instruction_end();
4466
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004467 // Returns the size of the instructions, padding, and relocation information.
4468 inline int body_size();
4469
4470 // Returns the address of the first relocation info (read backwards!).
4471 inline byte* relocation_start();
4472
4473 // Code entry point.
4474 inline byte* entry();
4475
4476 // Returns true if pc is inside this object's instructions.
4477 inline bool contains(byte* pc);
4478
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004479 // Relocate the code by delta bytes. Called to signal that this code
4480 // object has been moved by delta bytes.
ager@chromium.orgc4c92722009-11-18 14:12:51 +00004481 void Relocate(intptr_t delta);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004482
4483 // Migrate code described by desc.
4484 void CopyFrom(const CodeDesc& desc);
4485
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00004486 // Returns the object size for a given body (used for allocation).
4487 static int SizeFor(int body_size) {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004488 ASSERT_SIZE_TAG_ALIGNED(body_size);
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00004489 return RoundUp(kHeaderSize + body_size, kCodeAlignment);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004490 }
4491
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00004492 // Calculate the size of the code object to report for log events. This takes
4493 // the layout of the code object into account.
4494 int ExecutableSize() {
4495 // Check that the assumptions about the layout of the code object holds.
ager@chromium.orga1645e22009-09-09 19:27:10 +00004496 ASSERT_EQ(static_cast<int>(instruction_start() - address()),
4497 Code::kHeaderSize);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00004498 return instruction_size() + Code::kHeaderSize;
4499 }
4500
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004501 // Locating source position.
4502 int SourcePosition(Address pc);
4503 int SourceStatementPosition(Address pc);
4504
4505 // Casting.
4506 static inline Code* cast(Object* obj);
4507
4508 // Dispatched behavior.
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00004509 int CodeSize() { return SizeFor(body_size()); }
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00004510 inline void CodeIterateBody(ObjectVisitor* v);
4511
4512 template<typename StaticVisitor>
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004513 inline void CodeIterateBody(Heap* heap);
whesse@chromium.org023421e2010-12-21 12:19:12 +00004514#ifdef OBJECT_PRINT
4515 inline void CodePrint() {
4516 CodePrint(stdout);
4517 }
4518 void CodePrint(FILE* out);
4519#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004520#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004521 void CodeVerify();
4522#endif
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00004523 void ClearInlineCaches();
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004524 void ClearTypeFeedbackCells(Heap* heap);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004525
4526 // Max loop nesting marker used to postpose OSR. We don't take loop
4527 // nesting that is deeper than 5 levels into account.
4528 static const int kMaxLoopNestingMarker = 6;
4529
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004530 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00004531 static const int kInstructionSizeOffset = HeapObject::kHeaderSize;
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00004532 static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize;
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00004533 static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004534 static const int kDeoptimizationDataOffset =
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00004535 kHandlerTableOffset + kPointerSize;
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00004536 static const int kTypeFeedbackInfoOffset =
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004537 kDeoptimizationDataOffset + kPointerSize;
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00004538 static const int kGCMetadataOffset = kTypeFeedbackInfoOffset + kPointerSize;
danno@chromium.org88aa0582012-03-23 15:11:57 +00004539 static const int kICAgeOffset =
4540 kGCMetadataOffset + kPointerSize;
4541 static const int kFlagsOffset = kICAgeOffset + kIntSize;
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004542 static const int kKindSpecificFlags1Offset = kFlagsOffset + kIntSize;
4543 static const int kKindSpecificFlags2Offset =
4544 kKindSpecificFlags1Offset + kIntSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004545
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004546 static const int kHeaderPaddingStart = kKindSpecificFlags2Offset + kIntSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004547
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004548 // Add padding to align the instruction start following right after
kasperl@chromium.org061ef742009-02-27 12:16:20 +00004549 // the Code object header.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004550 static const int kHeaderSize =
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004551 (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask;
kasper.lund7276f142008-07-30 08:49:36 +00004552
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004553 // Byte offsets within kKindSpecificFlags1Offset.
4554 static const int kOptimizableOffset = kKindSpecificFlags1Offset;
4555 static const int kCheckTypeOffset = kKindSpecificFlags1Offset;
lrn@chromium.org34e60782011-09-15 07:25:40 +00004556
4557 static const int kFullCodeFlags = kOptimizableOffset + 1;
4558 class FullCodeFlagsHasDeoptimizationSupportField:
4559 public BitField<bool, 0, 1> {}; // NOLINT
4560 class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {};
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004561 class FullCodeFlagsIsCompiledOptimizable: public BitField<bool, 2, 1> {};
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004562
lrn@chromium.org34e60782011-09-15 07:25:40 +00004563 static const int kAllowOSRAtLoopNestingLevelOffset = kFullCodeFlags + 1;
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00004564 static const int kProfilerTicksOffset = kAllowOSRAtLoopNestingLevelOffset + 1;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004565
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004566 // Flags layout. BitField<type, shift, size>.
4567 class ICStateField: public BitField<InlineCacheState, 0, 3> {};
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004568 class TypeField: public BitField<StubType, 3, 3> {};
4569 class CacheHolderField: public BitField<InlineCacheHolderFlag, 6, 1> {};
4570 class KindField: public BitField<Kind, 7, 4> {};
4571 class ExtraICStateField: public BitField<ExtraICState, 11, 2> {};
4572 class IsPregeneratedField: public BitField<bool, 13, 1> {};
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004573
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004574 // KindSpecificFlags1 layout (STUB and OPTIMIZED_FUNCTION)
4575 static const int kStackSlotsFirstBit = 0;
4576 static const int kStackSlotsBitCount = 24;
4577 static const int kUnaryOpTypeFirstBit =
4578 kStackSlotsFirstBit + kStackSlotsBitCount;
4579 static const int kUnaryOpTypeBitCount = 3;
4580 static const int kBinaryOpTypeFirstBit =
4581 kStackSlotsFirstBit + kStackSlotsBitCount;
4582 static const int kBinaryOpTypeBitCount = 3;
4583 static const int kBinaryOpResultTypeFirstBit =
4584 kBinaryOpTypeFirstBit + kBinaryOpTypeBitCount;
4585 static const int kBinaryOpResultTypeBitCount = 3;
4586 static const int kCompareStateFirstBit =
4587 kStackSlotsFirstBit + kStackSlotsBitCount;
4588 static const int kCompareStateBitCount = 3;
4589 static const int kCompareOperationFirstBit =
4590 kCompareStateFirstBit + kCompareStateBitCount;
4591 static const int kCompareOperationBitCount = 4;
4592 static const int kToBooleanStateFirstBit =
4593 kStackSlotsFirstBit + kStackSlotsBitCount;
4594 static const int kToBooleanStateBitCount = 8;
4595 static const int kHasFunctionCacheFirstBit =
4596 kStackSlotsFirstBit + kStackSlotsBitCount;
4597 static const int kHasFunctionCacheBitCount = 1;
4598
4599 STATIC_ASSERT(kStackSlotsFirstBit + kStackSlotsBitCount <= 32);
4600 STATIC_ASSERT(kUnaryOpTypeFirstBit + kUnaryOpTypeBitCount <= 32);
4601 STATIC_ASSERT(kBinaryOpTypeFirstBit + kBinaryOpTypeBitCount <= 32);
4602 STATIC_ASSERT(kBinaryOpResultTypeFirstBit +
4603 kBinaryOpResultTypeBitCount <= 32);
4604 STATIC_ASSERT(kCompareStateFirstBit + kCompareStateBitCount <= 32);
4605 STATIC_ASSERT(kCompareOperationFirstBit + kCompareOperationBitCount <= 32);
4606 STATIC_ASSERT(kToBooleanStateFirstBit + kToBooleanStateBitCount <= 32);
4607 STATIC_ASSERT(kHasFunctionCacheFirstBit + kHasFunctionCacheBitCount <= 32);
4608
4609 class StackSlotsField: public BitField<int,
4610 kStackSlotsFirstBit, kStackSlotsBitCount> {}; // NOLINT
4611 class UnaryOpTypeField: public BitField<int,
4612 kUnaryOpTypeFirstBit, kUnaryOpTypeBitCount> {}; // NOLINT
4613 class BinaryOpTypeField: public BitField<int,
4614 kBinaryOpTypeFirstBit, kBinaryOpTypeBitCount> {}; // NOLINT
4615 class BinaryOpResultTypeField: public BitField<int,
4616 kBinaryOpResultTypeFirstBit, kBinaryOpResultTypeBitCount> {}; // NOLINT
4617 class CompareStateField: public BitField<int,
4618 kCompareStateFirstBit, kCompareStateBitCount> {}; // NOLINT
4619 class CompareOperationField: public BitField<int,
4620 kCompareOperationFirstBit, kCompareOperationBitCount> {}; // NOLINT
4621 class ToBooleanStateField: public BitField<int,
4622 kToBooleanStateFirstBit, kToBooleanStateBitCount> {}; // NOLINT
4623 class HasFunctionCacheField: public BitField<bool,
4624 kHasFunctionCacheFirstBit, kHasFunctionCacheBitCount> {}; // NOLINT
4625
4626 // KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION)
4627 static const int kStubMajorKeyFirstBit = 0;
4628 static const int kSafepointTableOffsetFirstBit =
4629 kStubMajorKeyFirstBit + kStubMajorKeyBits;
4630 static const int kSafepointTableOffsetBitCount = 26;
4631
4632 STATIC_ASSERT(kStubMajorKeyFirstBit + kStubMajorKeyBits <= 32);
4633 STATIC_ASSERT(kSafepointTableOffsetFirstBit +
4634 kSafepointTableOffsetBitCount <= 32);
4635
4636 class SafepointTableOffsetField: public BitField<int,
4637 kSafepointTableOffsetFirstBit,
4638 kSafepointTableOffsetBitCount> {}; // NOLINT
4639 class StubMajorKeyField: public BitField<int,
4640 kStubMajorKeyFirstBit, kStubMajorKeyBits> {}; // NOLINT
4641
4642 // KindSpecificFlags2 layout (FUNCTION)
4643 class StackCheckTableOffsetField: public BitField<int, 0, 31> {};
4644
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004645 // Signed field cannot be encoded using the BitField class.
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004646 static const int kArgumentsCountShift = 14;
lrn@chromium.org34e60782011-09-15 07:25:40 +00004647 static const int kArgumentsCountMask = ~((1 << kArgumentsCountShift) - 1);
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004648
jkummerow@chromium.org1145ef82012-02-02 16:21:15 +00004649 // This constant should be encodable in an ARM instruction.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00004650 static const int kFlagsNotUsedInLookup =
lrn@chromium.org34e60782011-09-15 07:25:40 +00004651 TypeField::kMask | CacheHolderField::kMask;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004652
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004653 private:
4654 DISALLOW_IMPLICIT_CONSTRUCTORS(Code);
4655};
4656
4657
4658// All heap objects have a Map that describes their structure.
4659// A Map contains information about:
4660// - Size information about the object
4661// - How to iterate over an object (for garbage collection)
4662class Map: public HeapObject {
4663 public:
ager@chromium.org32912102009-01-16 10:38:43 +00004664 // Instance size.
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00004665 // Size in bytes or kVariableSizeSentinel if instances do not have
4666 // a fixed size.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004667 inline int instance_size();
4668 inline void set_instance_size(int value);
4669
ager@chromium.org7c537e22008-10-16 08:43:32 +00004670 // Count of properties allocated in the object.
4671 inline int inobject_properties();
4672 inline void set_inobject_properties(int value);
4673
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00004674 // Count of property fields pre-allocated in the object when first allocated.
4675 inline int pre_allocated_property_fields();
4676 inline void set_pre_allocated_property_fields(int value);
4677
ager@chromium.org32912102009-01-16 10:38:43 +00004678 // Instance type.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004679 inline InstanceType instance_type();
4680 inline void set_instance_type(InstanceType value);
4681
ager@chromium.org32912102009-01-16 10:38:43 +00004682 // Tells how many unused property fields are available in the
4683 // instance (only used for JSObject in fast mode).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004684 inline int unused_property_fields();
4685 inline void set_unused_property_fields(int value);
4686
ager@chromium.org32912102009-01-16 10:38:43 +00004687 // Bit field.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004688 inline byte bit_field();
4689 inline void set_bit_field(byte value);
4690
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00004691 // Bit field 2.
4692 inline byte bit_field2();
4693 inline void set_bit_field2(byte value);
4694
danno@chromium.org40cb8782011-05-25 07:58:50 +00004695 // Bit field 3.
danno@chromium.org40cb8782011-05-25 07:58:50 +00004696 inline int bit_field3();
4697 inline void set_bit_field3(int value);
4698
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004699 // Tells whether the object in the prototype property will be used
4700 // for instances created from this function. If the prototype
4701 // property is set to a value that is not a JSObject, the prototype
4702 // property will not be used to create instances of the function.
4703 // See ECMA-262, 13.2.2.
4704 inline void set_non_instance_prototype(bool value);
4705 inline bool has_non_instance_prototype();
4706
kmillikin@chromium.org4111b802010-05-03 10:34:42 +00004707 // Tells whether function has special prototype property. If not, prototype
4708 // property will not be created when accessed (will return undefined),
4709 // and construction from this function will not be allowed.
4710 inline void set_function_with_prototype(bool value);
4711 inline bool function_with_prototype();
4712
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004713 // Tells whether the instance with this map should be ignored by the
4714 // __proto__ accessor.
4715 inline void set_is_hidden_prototype() {
4716 set_bit_field(bit_field() | (1 << kIsHiddenPrototype));
4717 }
4718
4719 inline bool is_hidden_prototype() {
4720 return ((1 << kIsHiddenPrototype) & bit_field()) != 0;
4721 }
4722
ager@chromium.orgeadaf222009-06-16 09:43:10 +00004723 // Records and queries whether the instance has a named interceptor.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004724 inline void set_has_named_interceptor() {
4725 set_bit_field(bit_field() | (1 << kHasNamedInterceptor));
4726 }
4727
4728 inline bool has_named_interceptor() {
4729 return ((1 << kHasNamedInterceptor) & bit_field()) != 0;
4730 }
4731
ager@chromium.orgeadaf222009-06-16 09:43:10 +00004732 // Records and queries whether the instance has an indexed interceptor.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004733 inline void set_has_indexed_interceptor() {
4734 set_bit_field(bit_field() | (1 << kHasIndexedInterceptor));
4735 }
4736
4737 inline bool has_indexed_interceptor() {
4738 return ((1 << kHasIndexedInterceptor) & bit_field()) != 0;
4739 }
4740
4741 // Tells whether the instance is undetectable.
4742 // An undetectable object is a special class of JSObject: 'typeof' operator
4743 // returns undefined, ToBoolean returns false. Otherwise it behaves like
4744 // a normal JS object. It is useful for implementing undetectable
4745 // document.all in Firefox & Safari.
4746 // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
4747 inline void set_is_undetectable() {
4748 set_bit_field(bit_field() | (1 << kIsUndetectable));
4749 }
4750
4751 inline bool is_undetectable() {
4752 return ((1 << kIsUndetectable) & bit_field()) != 0;
4753 }
4754
4755 // Tells whether the instance has a call-as-function handler.
4756 inline void set_has_instance_call_handler() {
4757 set_bit_field(bit_field() | (1 << kHasInstanceCallHandler));
4758 }
4759
4760 inline bool has_instance_call_handler() {
4761 return ((1 << kHasInstanceCallHandler) & bit_field()) != 0;
4762 }
4763
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +00004764 inline void set_is_extensible(bool value);
4765 inline bool is_extensible();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00004766
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004767 inline void set_elements_kind(ElementsKind elements_kind) {
4768 ASSERT(elements_kind < kElementsKindCount);
4769 ASSERT(kElementsKindCount <= (1 << kElementsKindBitCount));
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004770 set_bit_field2((bit_field2() & ~kElementsKindMask) |
4771 (elements_kind << kElementsKindShift));
4772 ASSERT(this->elements_kind() == elements_kind);
4773 }
4774
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00004775 inline ElementsKind elements_kind() {
4776 return static_cast<ElementsKind>(
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004777 (bit_field2() & kElementsKindMask) >> kElementsKindShift);
fschneider@chromium.org40b9da32010-06-28 11:29:21 +00004778 }
4779
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004780 // Tells whether the instance has fast elements that are only Smis.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004781 inline bool has_fast_smi_elements() {
4782 return IsFastSmiElementsKind(elements_kind());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004783 }
4784
whesse@chromium.org7b260152011-06-20 15:33:18 +00004785 // Tells whether the instance has fast elements.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004786 inline bool has_fast_object_elements() {
4787 return IsFastObjectElementsKind(elements_kind());
4788 }
4789
4790 inline bool has_fast_smi_or_object_elements() {
4791 return IsFastSmiOrObjectElementsKind(elements_kind());
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00004792 }
4793
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004794 inline bool has_fast_double_elements() {
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00004795 return IsFastDoubleElementsKind(elements_kind());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00004796 }
4797
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004798 inline bool has_non_strict_arguments_elements() {
4799 return elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4800 }
4801
danno@chromium.org4d3fe4e2011-03-10 10:14:28 +00004802 inline bool has_external_array_elements() {
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004803 return IsExternalArrayElementsKind(elements_kind());
sgjesse@chromium.org496c03a2011-02-14 12:05:43 +00004804 }
4805
ricow@chromium.org4f693d62011-07-04 14:01:31 +00004806 inline bool has_dictionary_elements() {
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004807 return IsDictionaryElementsKind(elements_kind());
ricow@chromium.org4f693d62011-07-04 14:01:31 +00004808 }
4809
ulan@chromium.org2efb9002012-01-19 15:36:35 +00004810 inline bool has_slow_elements_kind() {
4811 return elements_kind() == DICTIONARY_ELEMENTS
4812 || elements_kind() == NON_STRICT_ARGUMENTS_ELEMENTS;
4813 }
4814
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004815 static bool IsValidElementsTransition(ElementsKind from_kind,
4816 ElementsKind to_kind);
4817
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00004818 inline bool HasTransitionArray();
4819 inline bool HasElementsTransition();
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004820 inline Map* elements_transition_map();
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00004821 MUST_USE_RESULT inline MaybeObject* set_elements_transition_map(
4822 Map* transitioned_map);
4823 inline TransitionArray* transitions();
verwaest@chromium.org753aee42012-07-17 16:15:42 +00004824 inline void SetTransition(int index, Map* target);
4825 MUST_USE_RESULT inline MaybeObject* AddTransition(String* key, Map* target);
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00004826 MUST_USE_RESULT inline MaybeObject* set_transitions(
4827 TransitionArray* transitions);
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00004828 inline void ClearTransitions(Heap* heap,
4829 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004830
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00004831 // Tells whether the map is attached to SharedFunctionInfo
4832 // (for inobject slack tracking).
4833 inline void set_attached_to_shared_function_info(bool value);
4834
4835 inline bool attached_to_shared_function_info();
4836
4837 // Tells whether the map is shared between objects that may have different
4838 // behavior. If true, the map should never be modified, instead a clone
4839 // should be created and modified.
4840 inline void set_is_shared(bool value);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00004841 inline bool is_shared();
4842
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004843 // Tells whether the instance needs security checks when accessing its
4844 // properties.
ager@chromium.org870a0b62008-11-04 11:43:05 +00004845 inline void set_is_access_check_needed(bool access_check_needed);
4846 inline bool is_access_check_needed();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004847
4848 // [prototype]: implicit prototype object.
4849 DECL_ACCESSORS(prototype, Object)
4850
4851 // [constructor]: points back to the function responsible for this map.
4852 DECL_ACCESSORS(constructor, Object)
4853
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00004854 inline JSFunction* unchecked_constructor();
4855
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004856 // [instance descriptors]: describes the object.
4857 DECL_ACCESSORS(instance_descriptors, DescriptorArray)
4858
jkummerow@chromium.org7a6fc812012-06-27 11:12:38 +00004859 // Should only be called to clear a descriptor array that was only used to
4860 // store transitions and does not contain any live transitions anymore.
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00004861 inline void ClearDescriptorArray(Heap* heap, WriteBarrierMode mode);
danno@chromium.org40cb8782011-05-25 07:58:50 +00004862
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004863 // [stub cache]: contains stubs compiled for this map.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00004864 DECL_ACCESSORS(code_cache, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004865
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004866 // [back pointer]: points back to the parent map from which a transition
4867 // leads to this map. The field overlaps with prototype transitions and the
4868 // back pointer will be moved into the prototype transitions array if
4869 // required.
4870 inline Object* GetBackPointer();
4871 inline void SetBackPointer(Object* value,
4872 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004873 inline void init_back_pointer(Object* undefined);
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004874
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004875 // [prototype transitions]: cache of prototype transitions.
4876 // Prototype transition is a transition that happens
4877 // when we change object's prototype to a new one.
4878 // Cache format:
4879 // 0: finger - index of the first free cell in the cache
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004880 // 1: back pointer that overlaps with prototype transitions field.
4881 // 2 + 2 * i: prototype
4882 // 3 + 2 * i: target map
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004883 inline FixedArray* GetPrototypeTransitions();
4884 MUST_USE_RESULT inline MaybeObject* SetPrototypeTransitions(
4885 FixedArray* prototype_transitions);
4886 inline bool HasPrototypeTransitions();
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00004887
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004888 inline HeapObject* UncheckedPrototypeTransitions();
4889 inline TransitionArray* unchecked_transition_array();
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00004890
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004891 static const int kProtoTransitionHeaderSize = 1;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004892 static const int kProtoTransitionNumberOfEntriesOffset = 0;
4893 static const int kProtoTransitionElementsPerEntry = 2;
4894 static const int kProtoTransitionPrototypeOffset = 0;
4895 static const int kProtoTransitionMapOffset = 1;
4896
4897 inline int NumberOfProtoTransitions() {
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004898 FixedArray* cache = GetPrototypeTransitions();
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004899 if (cache->length() == 0) return 0;
4900 return
4901 Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value();
4902 }
4903
4904 inline void SetNumberOfProtoTransitions(int value) {
danno@chromium.org81cac2b2012-07-10 11:28:27 +00004905 FixedArray* cache = GetPrototypeTransitions();
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00004906 ASSERT(cache->length() != 0);
4907 cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset,
4908 Smi::FromInt(value));
4909 }
4910
kasperl@chromium.orga5551262010-12-07 12:49:48 +00004911 // Lookup in the map's instance descriptors and fill out the result
4912 // with the given holder if the name is found. The holder may be
4913 // NULL when this function is used from the compiler.
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00004914 void LookupDescriptor(JSObject* holder,
4915 String* name,
4916 LookupResult* result);
4917
4918 void LookupTransition(JSObject* holder,
4919 String* name,
4920 LookupResult* result);
4921
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00004922 MUST_USE_RESULT MaybeObject* RawCopy(int instance_size);
4923 MUST_USE_RESULT MaybeObject* CopyWithPreallocatedFieldDescriptors();
lrn@chromium.org303ada72010-10-27 09:33:13 +00004924 MUST_USE_RESULT MaybeObject* CopyDropDescriptors();
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00004925 MUST_USE_RESULT MaybeObject* CopyReplaceDescriptors(
verwaest@chromium.org753aee42012-07-17 16:15:42 +00004926 DescriptorArray* descriptors, String* name, TransitionFlag flag);
4927 MUST_USE_RESULT MaybeObject* CopyAddDescriptor(Descriptor* descriptor,
4928 TransitionFlag flag);
4929 MUST_USE_RESULT MaybeObject* CopyInsertDescriptor(Descriptor* descriptor,
4930 TransitionFlag flag);
4931 MUST_USE_RESULT MaybeObject* CopyReplaceDescriptor(Descriptor* descriptor,
4932 int index,
4933 TransitionFlag flag);
4934 MUST_USE_RESULT MaybeObject* CopyAsElementsKind(ElementsKind kind,
4935 TransitionFlag flag);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004936
lrn@chromium.org303ada72010-10-27 09:33:13 +00004937 MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode,
4938 NormalizedMapSharingMode sharing);
ricow@chromium.org65fae842010-08-25 15:26:24 +00004939
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00004940 // Returns a copy of the map, with all transitions dropped from the
4941 // instance descriptors.
verwaest@chromium.org753aee42012-07-17 16:15:42 +00004942 MUST_USE_RESULT MaybeObject* Copy(DescriptorArray::SharedMode shared_mode);
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00004943
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004944 // Returns the property index for name (only valid for FAST MODE).
4945 int PropertyIndexFor(String* name);
4946
4947 // Returns the next free property index (only valid for FAST MODE).
4948 int NextFreePropertyIndex();
4949
jkummerow@chromium.orgab7dad42012-02-07 12:07:34 +00004950 // Returns the number of properties described in instance_descriptors
4951 // filtering out properties with the specified attributes.
4952 int NumberOfDescribedProperties(PropertyAttributes filter = NONE);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004953
4954 // Casting.
4955 static inline Map* cast(Object* obj);
4956
4957 // Locate an accessor in the instance descriptor.
4958 AccessorDescriptor* FindAccessor(String* name);
4959
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004960 // Code cache operations.
4961
4962 // Clears the code cache.
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00004963 inline void ClearCodeCache(Heap* heap);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004964
4965 // Update code cache.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00004966 static void UpdateCodeCache(Handle<Map> map,
4967 Handle<String> name,
4968 Handle<Code> code);
lrn@chromium.org303ada72010-10-27 09:33:13 +00004969 MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004970
4971 // Returns the found code or undefined if absent.
4972 Object* FindInCodeCache(String* name, Code::Flags flags);
4973
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00004974 // Returns the non-negative index of the code object if it is in the
4975 // cache and -1 otherwise.
sgjesse@chromium.org99a37fa2010-03-11 09:23:46 +00004976 int IndexInCodeCache(Object* name, Code* code);
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00004977
4978 // Removes a code object from the code cache at the given index.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00004979 void RemoveFromCodeCache(String* name, Code* code, int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00004980
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00004981 // Set all map transitions from this map to dead maps to null. Also clear
4982 // back pointers in transition targets so that we do not process this map
4983 // again while following back pointers.
4984 void ClearNonLiveTransitions(Heap* heap);
danno@chromium.orgfa458e42012-02-01 10:48:36 +00004985
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00004986 // Computes a hash value for this map, to be used in HashTables and such.
4987 int Hash();
4988
4989 // Compares this map to another to see if they describe equivalent objects.
4990 // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
4991 // it had exactly zero inobject properties.
4992 // The "shared" flags of both this map and |other| are ignored.
4993 bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
4994
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00004995 // Returns the map that this map transitions to if its elements_kind
4996 // is changed to |elements_kind|, or NULL if no such map is cached yet.
4997 // |safe_to_add_transitions| is set to false if adding transitions is not
4998 // allowed.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00004999 Map* LookupElementsTransitionMap(ElementsKind elements_kind);
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00005000
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005001 // Returns the transitioned map for this map with the most generic
5002 // elements_kind that's found in |candidates|, or null handle if no match is
5003 // found at all.
5004 Handle<Map> FindTransitionedMap(MapHandleList* candidates);
5005 Map* FindTransitionedMap(MapList* candidates);
5006
yangguo@chromium.org5f0b8ea2012-05-16 12:37:04 +00005007 // Zaps the contents of backing data structures in debug mode. Note that the
5008 // heap verifier (i.e. VerifyMarkingVisitor) relies on zapping of objects
5009 // holding weak references when incremental marking is used, because it also
5010 // iterates over objects that are otherwise unreachable.
5011#ifdef DEBUG
yangguo@chromium.org5f0b8ea2012-05-16 12:37:04 +00005012 void ZapPrototypeTransitions();
yangguo@chromium.org99aa4902012-07-06 16:21:55 +00005013 void ZapTransitions();
yangguo@chromium.org5f0b8ea2012-05-16 12:37:04 +00005014#endif
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005015
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005016 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00005017#ifdef OBJECT_PRINT
5018 inline void MapPrint() {
5019 MapPrint(stdout);
5020 }
5021 void MapPrint(FILE* out);
5022#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005023#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005024 void MapVerify();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005025 void SharedMapVerify();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005026#endif
5027
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00005028 inline int visitor_id();
5029 inline void set_visitor_id(int visitor_id);
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00005030
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005031 typedef void (*TraverseCallback)(Map* map, void* data);
5032
5033 void TraverseTransitionTree(TraverseCallback callback, void* data);
5034
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005035 // When you set the prototype of an object using the __proto__ accessor you
5036 // need a new map for the object (the prototype is stored in the map). In
5037 // order not to multiply maps unnecessarily we store these as transitions in
5038 // the original map. That way we can transition to the same map if the same
5039 // prototype is set, rather than creating a new map every time. The
5040 // transitions are in the form of a map where the keys are prototype objects
ulan@chromium.orgf6a0c412012-06-15 12:31:06 +00005041 // and the values are the maps the are transitioned to.
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00005042 static const int kMaxCachedPrototypeTransitions = 256;
5043
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005044 Map* GetPrototypeTransition(Object* prototype);
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00005045
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00005046 MUST_USE_RESULT MaybeObject* PutPrototypeTransition(Object* prototype,
5047 Map* map);
erik.corry@gmail.com3847bd52011-04-27 10:38:56 +00005048
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005049 static const int kMaxPreAllocatedPropertyFields = 255;
5050
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005051 // Layout description.
ager@chromium.org7c537e22008-10-16 08:43:32 +00005052 static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
5053 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005054 static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize;
5055 static const int kConstructorOffset = kPrototypeOffset + kPointerSize;
danno@chromium.org40cb8782011-05-25 07:58:50 +00005056 // Storage for instance descriptors is overloaded to also contain additional
5057 // map flags when unused (bit_field3). When the map has instance descriptors,
5058 // the flags are transferred to the instance descriptor array and accessed
5059 // through an extra indirection.
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00005060 static const int kInstanceDescriptorsOrBackPointerOffset =
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005061 kConstructorOffset + kPointerSize;
danno@chromium.org40cb8782011-05-25 07:58:50 +00005062 static const int kCodeCacheOffset =
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00005063 kInstanceDescriptorsOrBackPointerOffset + kPointerSize;
5064 static const int kBitField3Offset = kCodeCacheOffset + kPointerSize;
5065 static const int kPadStart = kBitField3Offset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005066 static const int kSize = MAP_POINTER_ALIGN(kPadStart);
5067
5068 // Layout of pointer fields. Heap iteration code relies on them
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00005069 // being continuously allocated.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005070 static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset;
rossberg@chromium.org657d53b2012-07-12 11:06:03 +00005071 static const int kPointerFieldsEndOffset = kBitField3Offset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005072
ager@chromium.org7c537e22008-10-16 08:43:32 +00005073 // Byte offsets within kInstanceSizesOffset.
5074 static const int kInstanceSizeOffset = kInstanceSizesOffset + 0;
ager@chromium.orga1645e22009-09-09 19:27:10 +00005075 static const int kInObjectPropertiesByte = 1;
5076 static const int kInObjectPropertiesOffset =
5077 kInstanceSizesOffset + kInObjectPropertiesByte;
5078 static const int kPreAllocatedPropertyFieldsByte = 2;
5079 static const int kPreAllocatedPropertyFieldsOffset =
5080 kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte;
ager@chromium.org5b2fbee2010-09-08 06:38:15 +00005081 static const int kVisitorIdByte = 3;
5082 static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte;
ager@chromium.org7c537e22008-10-16 08:43:32 +00005083
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005084 // Byte offsets within kInstanceAttributesOffset attributes.
ager@chromium.org7c537e22008-10-16 08:43:32 +00005085 static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0;
5086 static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1;
5087 static const int kBitFieldOffset = kInstanceAttributesOffset + 2;
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00005088 static const int kBitField2Offset = kInstanceAttributesOffset + 3;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005089
ager@chromium.org18ad94b2009-09-02 08:22:29 +00005090 STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset);
5091
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005092 // Bit positions for bit field.
mads.s.ager31e71382008-08-13 09:32:07 +00005093 static const int kUnused = 0; // To be used for marking recently used maps.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005094 static const int kHasNonInstancePrototype = 1;
5095 static const int kIsHiddenPrototype = 2;
5096 static const int kHasNamedInterceptor = 3;
5097 static const int kHasIndexedInterceptor = 4;
5098 static const int kIsUndetectable = 5;
5099 static const int kHasInstanceCallHandler = 6;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00005100 static const int kIsAccessCheckNeeded = 7;
ager@chromium.org3a37e9b2009-04-27 09:26:21 +00005101
ager@chromium.orge2902be2009-06-08 12:21:35 +00005102 // Bit positions for bit field 2
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00005103 static const int kIsExtensible = 0;
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00005104 static const int kStringWrapperSafeForDefaultValueOf = 1;
5105 static const int kAttachedToSharedFunctionInfo = 2;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00005106 // No bits can be used after kElementsKindFirstBit, they are all reserved for
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00005107 // storing ElementKind.
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00005108 static const int kElementsKindShift = 3;
5109 static const int kElementsKindBitCount = 5;
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00005110
5111 // Derived values from bit field 2
5112 static const int kElementsKindMask = (-1 << kElementsKindShift) &
5113 ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1);
5114 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00005115 (FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1;
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00005116 static const int8_t kMaximumBitField2FastSmiElementValue =
5117 static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) <<
5118 Map::kElementsKindShift) - 1;
5119 static const int8_t kMaximumBitField2FastHoleyElementValue =
5120 static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) <<
5121 Map::kElementsKindShift) - 1;
5122 static const int8_t kMaximumBitField2FastHoleySmiElementValue =
5123 static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) <<
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00005124 Map::kElementsKindShift) - 1;
danno@chromium.org40cb8782011-05-25 07:58:50 +00005125
5126 // Bit positions for bit field 3
erik.corry@gmail.comd6076d92011-06-06 09:39:18 +00005127 static const int kIsShared = 0;
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00005128 static const int kFunctionWithPrototype = 1;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005129
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00005130 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
5131 kPointerFieldsEndOffset,
5132 kSize> BodyDescriptor;
5133
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005134 private:
5135 DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
5136};
5137
5138
5139// An abstract superclass, a marker class really, for simple structure classes.
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00005140// It doesn't carry much functionality but allows struct classes to be
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005141// identified in the type system.
5142class Struct: public HeapObject {
5143 public:
5144 inline void InitializeBody(int object_size);
5145 static inline Struct* cast(Object* that);
5146};
5147
5148
mads.s.ager31e71382008-08-13 09:32:07 +00005149// Script describes a script which has been added to the VM.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005150class Script: public Struct {
5151 public:
ager@chromium.orge2902be2009-06-08 12:21:35 +00005152 // Script types.
5153 enum Type {
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00005154 TYPE_NATIVE = 0,
5155 TYPE_EXTENSION = 1,
5156 TYPE_NORMAL = 2
ager@chromium.orge2902be2009-06-08 12:21:35 +00005157 };
5158
5159 // Script compilation types.
5160 enum CompilationType {
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00005161 COMPILATION_TYPE_HOST = 0,
fschneider@chromium.orge03fb642010-11-01 12:34:09 +00005162 COMPILATION_TYPE_EVAL = 1
ager@chromium.orge2902be2009-06-08 12:21:35 +00005163 };
5164
rossberg@chromium.org2c067b12012-03-19 11:01:52 +00005165 // Script compilation state.
5166 enum CompilationState {
5167 COMPILATION_STATE_INITIAL = 0,
5168 COMPILATION_STATE_COMPILED = 1
5169 };
5170
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005171 // [source]: the script source.
5172 DECL_ACCESSORS(source, Object)
5173
5174 // [name]: the script name.
5175 DECL_ACCESSORS(name, Object)
5176
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00005177 // [id]: the script id.
5178 DECL_ACCESSORS(id, Object)
5179
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005180 // [line_offset]: script line offset in resource from where it was extracted.
5181 DECL_ACCESSORS(line_offset, Smi)
5182
5183 // [column_offset]: script column offset in resource from where it was
5184 // extracted.
5185 DECL_ACCESSORS(column_offset, Smi)
5186
ager@chromium.org65dad4b2009-04-23 08:48:43 +00005187 // [data]: additional data associated with this script.
5188 DECL_ACCESSORS(data, Object)
5189
ager@chromium.org9085a012009-05-11 19:22:57 +00005190 // [context_data]: context data for the context this script was compiled in.
5191 DECL_ACCESSORS(context_data, Object)
5192
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005193 // [wrapper]: the wrapper cache.
ager@chromium.orgea91cc52011-05-23 06:06:11 +00005194 DECL_ACCESSORS(wrapper, Foreign)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005195
5196 // [type]: the script type.
5197 DECL_ACCESSORS(type, Smi)
5198
ager@chromium.orge2902be2009-06-08 12:21:35 +00005199 // [compilation]: how the the script was compiled.
5200 DECL_ACCESSORS(compilation_type, Smi)
5201
rossberg@chromium.org2c067b12012-03-19 11:01:52 +00005202 // [is_compiled]: determines whether the script has already been compiled.
5203 DECL_ACCESSORS(compilation_state, Smi)
5204
ager@chromium.orgc4c92722009-11-18 14:12:51 +00005205 // [line_ends]: FixedArray of line ends positions.
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +00005206 DECL_ACCESSORS(line_ends, Object)
iposva@chromium.org245aa852009-02-10 00:49:54 +00005207
sgjesse@chromium.org98180592009-12-02 08:17:28 +00005208 // [eval_from_shared]: for eval scripts the shared funcion info for the
5209 // function from which eval was called.
5210 DECL_ACCESSORS(eval_from_shared, Object)
ager@chromium.orge2902be2009-06-08 12:21:35 +00005211
5212 // [eval_from_instructions_offset]: the instruction offset in the code for the
5213 // function from which eval was called where eval was called.
5214 DECL_ACCESSORS(eval_from_instructions_offset, Smi)
5215
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005216 static inline Script* cast(Object* obj);
5217
sgjesse@chromium.org152a0b02009-10-07 13:50:16 +00005218 // If script source is an external string, check that the underlying
5219 // resource is accessible. Otherwise, always return true.
5220 inline bool HasValidSource();
5221
whesse@chromium.org023421e2010-12-21 12:19:12 +00005222#ifdef OBJECT_PRINT
5223 inline void ScriptPrint() {
5224 ScriptPrint(stdout);
5225 }
5226 void ScriptPrint(FILE* out);
5227#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005228#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005229 void ScriptVerify();
5230#endif
5231
ager@chromium.org236ad962008-09-25 09:45:57 +00005232 static const int kSourceOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005233 static const int kNameOffset = kSourceOffset + kPointerSize;
5234 static const int kLineOffsetOffset = kNameOffset + kPointerSize;
5235 static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
ager@chromium.org65dad4b2009-04-23 08:48:43 +00005236 static const int kDataOffset = kColumnOffsetOffset + kPointerSize;
ager@chromium.org9085a012009-05-11 19:22:57 +00005237 static const int kContextOffset = kDataOffset + kPointerSize;
5238 static const int kWrapperOffset = kContextOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005239 static const int kTypeOffset = kWrapperOffset + kPointerSize;
ager@chromium.orge2902be2009-06-08 12:21:35 +00005240 static const int kCompilationTypeOffset = kTypeOffset + kPointerSize;
rossberg@chromium.org2c067b12012-03-19 11:01:52 +00005241 static const int kCompilationStateOffset =
5242 kCompilationTypeOffset + kPointerSize;
5243 static const int kLineEndsOffset = kCompilationStateOffset + kPointerSize;
sgjesse@chromium.org499aaa52009-11-30 08:07:20 +00005244 static const int kIdOffset = kLineEndsOffset + kPointerSize;
sgjesse@chromium.org98180592009-12-02 08:17:28 +00005245 static const int kEvalFromSharedOffset = kIdOffset + kPointerSize;
ager@chromium.orge2902be2009-06-08 12:21:35 +00005246 static const int kEvalFrominstructionsOffsetOffset =
sgjesse@chromium.org98180592009-12-02 08:17:28 +00005247 kEvalFromSharedOffset + kPointerSize;
ager@chromium.orge2902be2009-06-08 12:21:35 +00005248 static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005249
5250 private:
5251 DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
5252};
5253
5254
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005255// List of builtin functions we want to identify to improve code
5256// generation.
5257//
5258// Each entry has a name of a global object property holding an object
5259// optionally followed by ".prototype", a name of a builtin function
5260// on the object (the one the id is set for), and a label.
5261//
5262// Installation of ids for the selected builtin functions is handled
5263// by the bootstrapper.
5264//
5265// NOTE: Order is important: math functions should be at the end of
5266// the list and MathFloor should be the first math function.
5267#define FUNCTIONS_WITH_ID_LIST(V) \
5268 V(Array.prototype, push, ArrayPush) \
5269 V(Array.prototype, pop, ArrayPop) \
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00005270 V(Function.prototype, apply, FunctionApply) \
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005271 V(String.prototype, charCodeAt, StringCharCodeAt) \
5272 V(String.prototype, charAt, StringCharAt) \
5273 V(String, fromCharCode, StringFromCharCode) \
5274 V(Math, floor, MathFloor) \
5275 V(Math, round, MathRound) \
5276 V(Math, ceil, MathCeil) \
5277 V(Math, abs, MathAbs) \
5278 V(Math, log, MathLog) \
5279 V(Math, sin, MathSin) \
5280 V(Math, cos, MathCos) \
5281 V(Math, tan, MathTan) \
5282 V(Math, asin, MathASin) \
5283 V(Math, acos, MathACos) \
5284 V(Math, atan, MathATan) \
5285 V(Math, exp, MathExp) \
5286 V(Math, sqrt, MathSqrt) \
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00005287 V(Math, pow, MathPow) \
5288 V(Math, random, MathRandom) \
5289 V(Math, max, MathMax) \
5290 V(Math, min, MathMin)
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005291
5292
5293enum BuiltinFunctionId {
5294#define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \
5295 k##name,
5296 FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID)
5297#undef DECLARE_FUNCTION_ID
5298 // Fake id for a special case of Math.pow. Note, it continues the
5299 // list of math functions.
5300 kMathPowHalf,
5301 kFirstMathFunctionId = kMathFloor
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005302};
5303
5304
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005305// SharedFunctionInfo describes the JSFunction information that can be
5306// shared by multiple instances of the function.
5307class SharedFunctionInfo: public HeapObject {
5308 public:
5309 // [name]: Function name.
5310 DECL_ACCESSORS(name, Object)
5311
5312 // [code]: Function code.
5313 DECL_ACCESSORS(code, Code)
5314
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005315 // [optimized_code_map]: Map from global context to optimized code
5316 // and a shared literals array or Smi 0 if none.
5317 DECL_ACCESSORS(optimized_code_map, Object)
5318
5319 // Returns index i of the entry with the specified context. At position
5320 // i - 1 is the context, position i the code, and i + 1 the literals array.
5321 // Returns -1 when no matching entry is found.
5322 int SearchOptimizedCodeMap(Context* global_context);
5323
ulan@chromium.orgd9e468a2012-06-25 09:47:40 +00005324 // Installs optimized code from the code map on the given closure. The
5325 // index has to be consistent with a search result as defined above.
5326 void InstallFromOptimizedCodeMap(JSFunction* function, int index);
5327
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005328 // Clear optimized code map.
5329 void ClearOptimizedCodeMap();
5330
5331 // Add a new entry to the optimized code map.
5332 static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
5333 Handle<Context> global_context,
5334 Handle<Code> code,
5335 Handle<FixedArray> literals);
5336 static const int kEntryLength = 3;
5337
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00005338 // [scope_info]: Scope info.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00005339 DECL_ACCESSORS(scope_info, ScopeInfo)
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00005340
ager@chromium.org5aa501c2009-06-23 07:57:28 +00005341 // [construct stub]: Code stub for constructing instances of this function.
5342 DECL_ACCESSORS(construct_stub, Code)
5343
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005344 inline Code* unchecked_code();
5345
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005346 // Returns if this function has been compiled to native code yet.
5347 inline bool is_compiled();
5348
5349 // [length]: The function length - usually the number of declared parameters.
5350 // Use up to 2^30 parameters.
5351 inline int length();
5352 inline void set_length(int value);
5353
5354 // [formal parameter count]: The declared number of parameters.
5355 inline int formal_parameter_count();
5356 inline void set_formal_parameter_count(int value);
5357
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00005358 // Set the formal parameter count so the function code will be
5359 // called without using argument adaptor frames.
5360 inline void DontAdaptArguments();
5361
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005362 // [expected_nof_properties]: Expected number of properties for the function.
5363 inline int expected_nof_properties();
5364 inline void set_expected_nof_properties(int value);
5365
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005366 // Inobject slack tracking is the way to reclaim unused inobject space.
5367 //
5368 // The instance size is initially determined by adding some slack to
5369 // expected_nof_properties (to allow for a few extra properties added
5370 // after the constructor). There is no guarantee that the extra space
5371 // will not be wasted.
5372 //
5373 // Here is the algorithm to reclaim the unused inobject space:
5374 // - Detect the first constructor call for this SharedFunctionInfo.
5375 // When it happens enter the "in progress" state: remember the
5376 // constructor's initial_map and install a special construct stub that
5377 // counts constructor calls.
5378 // - While the tracking is in progress create objects filled with
5379 // one_pointer_filler_map instead of undefined_value. This way they can be
5380 // resized quickly and safely.
5381 // - Once enough (kGenerousAllocationCount) objects have been created
5382 // compute the 'slack' (traverse the map transition tree starting from the
5383 // initial_map and find the lowest value of unused_property_fields).
5384 // - Traverse the transition tree again and decrease the instance size
5385 // of every map. Existing objects will resize automatically (they are
5386 // filled with one_pointer_filler_map). All further allocations will
5387 // use the adjusted instance size.
5388 // - Decrease expected_nof_properties so that an allocations made from
5389 // another context will use the adjusted instance size too.
5390 // - Exit "in progress" state by clearing the reference to the initial_map
5391 // and setting the regular construct stub (generic or inline).
5392 //
5393 // The above is the main event sequence. Some special cases are possible
5394 // while the tracking is in progress:
5395 //
5396 // - GC occurs.
5397 // Check if the initial_map is referenced by any live objects (except this
5398 // SharedFunctionInfo). If it is, continue tracking as usual.
5399 // If it is not, clear the reference and reset the tracking state. The
5400 // tracking will be initiated again on the next constructor call.
5401 //
5402 // - The constructor is called from another context.
5403 // Immediately complete the tracking, perform all the necessary changes
5404 // to maps. This is necessary because there is no efficient way to track
5405 // multiple initial_maps.
5406 // Proceed to create an object in the current context (with the adjusted
5407 // size).
5408 //
5409 // - A different constructor function sharing the same SharedFunctionInfo is
5410 // called in the same context. This could be another closure in the same
5411 // context, or the first function could have been disposed.
5412 // This is handled the same way as the previous case.
5413 //
5414 // Important: inobject slack tracking is not attempted during the snapshot
5415 // creation.
5416
ricow@chromium.orgeb7c1442010-10-04 08:54:21 +00005417 static const int kGenerousAllocationCount = 8;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005418
5419 // [construction_count]: Counter for constructor calls made during
5420 // the tracking phase.
5421 inline int construction_count();
5422 inline void set_construction_count(int value);
5423
5424 // [initial_map]: initial map of the first function called as a constructor.
5425 // Saved for the duration of the tracking phase.
5426 // This is a weak link (GC resets it to undefined_value if no other live
5427 // object reference this map).
5428 DECL_ACCESSORS(initial_map, Object)
5429
5430 // True if the initial_map is not undefined and the countdown stub is
5431 // installed.
5432 inline bool IsInobjectSlackTrackingInProgress();
5433
5434 // Starts the tracking.
5435 // Stores the initial map and installs the countdown stub.
5436 // IsInobjectSlackTrackingInProgress is normally true after this call,
5437 // except when tracking have not been started (e.g. the map has no unused
5438 // properties or the snapshot is being built).
5439 void StartInobjectSlackTracking(Map* map);
5440
5441 // Completes the tracking.
5442 // IsInobjectSlackTrackingInProgress is false after this call.
5443 void CompleteInobjectSlackTracking();
5444
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005445 // Invoked before pointers in SharedFunctionInfo are being marked.
5446 // Also clears the optimized code map.
5447 inline void BeforeVisitingPointers();
5448
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005449 // Clears the initial_map before the GC marking phase to ensure the reference
5450 // is weak. IsInobjectSlackTrackingInProgress is false after this call.
5451 void DetachInitialMap();
5452
5453 // Restores the link to the initial map after the GC marking phase.
5454 // IsInobjectSlackTrackingInProgress is true after this call.
5455 void AttachInitialMap(Map* map);
5456
5457 // False if there are definitely no live objects created from this function.
5458 // True if live objects _may_ exist (existence not guaranteed).
5459 // May go back from true to false after GC.
whesse@chromium.org7b260152011-06-20 15:33:18 +00005460 DECL_BOOLEAN_ACCESSORS(live_objects_may_exist)
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005461
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005462 // [instance class name]: class name for instances.
5463 DECL_ACCESSORS(instance_class_name, Object)
5464
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005465 // [function data]: This field holds some additional data for function.
5466 // Currently it either has FunctionTemplateInfo to make benefit the API
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005467 // or Smi identifying a builtin function.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005468 // In the long run we don't want all functions to have this field but
5469 // we can fix that when we have a better model for storing hidden data
5470 // on objects.
5471 DECL_ACCESSORS(function_data, Object)
5472
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005473 inline bool IsApiFunction();
5474 inline FunctionTemplateInfo* get_api_func_data();
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005475 inline bool HasBuiltinFunctionId();
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00005476 inline BuiltinFunctionId builtin_function_id();
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005477
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005478 // [script info]: Script from which the function originates.
5479 DECL_ACCESSORS(script, Object)
5480
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00005481 // [num_literals]: Number of literals used by this function.
5482 inline int num_literals();
5483 inline void set_num_literals(int value);
5484
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005485 // [start_position_and_type]: Field used to store both the source code
5486 // position, whether or not the function is a function expression,
5487 // and whether or not the function is a toplevel function. The two
5488 // least significants bit indicates whether the function is an
5489 // expression and the rest contains the source code position.
5490 inline int start_position_and_type();
5491 inline void set_start_position_and_type(int value);
5492
5493 // [debug info]: Debug information.
5494 DECL_ACCESSORS(debug_info, Object)
5495
kasperl@chromium.orgd1e3e722009-04-14 13:38:25 +00005496 // [inferred name]: Name inferred from variable or property
5497 // assignment of this function. Used to facilitate debugging and
5498 // profiling of JavaScript code written in OO style, where almost
5499 // all functions are anonymous but are assigned to object
5500 // properties.
5501 DECL_ACCESSORS(inferred_name, String)
5502
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00005503 // The function's name if it is non-empty, otherwise the inferred name.
5504 String* DebugName();
5505
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005506 // Position of the 'function' token in the script source.
5507 inline int function_token_position();
5508 inline void set_function_token_position(int function_token_position);
5509
5510 // Position of this function in the script source.
5511 inline int start_position();
5512 inline void set_start_position(int start_position);
5513
5514 // End position of this function in the script source.
5515 inline int end_position();
5516 inline void set_end_position(int end_position);
5517
5518 // Is this function a function expression in the source code.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005519 DECL_BOOLEAN_ACCESSORS(is_expression)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005520
ager@chromium.orga1645e22009-09-09 19:27:10 +00005521 // Is this function a top-level function (scripts, evals).
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005522 DECL_BOOLEAN_ACCESSORS(is_toplevel)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005523
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005524 // Bit field containing various information collected by the compiler to
5525 // drive optimization.
5526 inline int compiler_hints();
5527 inline void set_compiler_hints(int value);
5528
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00005529 inline int ast_node_count();
5530 inline void set_ast_node_count(int count);
5531
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005532 // A counter used to determine when to stress the deoptimizer with a
5533 // deopt.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005534 inline int stress_deopt_counter();
5535 inline void set_stress_deopt_counter(int counter);
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00005536
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00005537 inline int profiler_ticks();
5538
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00005539 // Inline cache age is used to infer whether the function survived a context
5540 // disposal or not. In the former case we reset the opt_count.
5541 inline int ic_age();
5542 inline void set_ic_age(int age);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005543
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005544 // Add information on assignments of the form this.x = ...;
5545 void SetThisPropertyAssignmentsInfo(
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005546 bool has_only_simple_this_property_assignments,
5547 FixedArray* this_property_assignments);
5548
ager@chromium.org18ad94b2009-09-02 08:22:29 +00005549 // Clear information on assignments of the form this.x = ...;
5550 void ClearThisPropertyAssignmentsInfo();
5551
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005552 // Indicate that this function only consists of assignments of the form
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005553 // this.x = y; where y is either a constant or refers to an argument.
5554 inline bool has_only_simple_this_property_assignments();
5555
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00005556 // Indicates if this function can be lazy compiled.
5557 // This is used to determine if we can safely flush code from a function
5558 // when doing GC if we expect that the function will no longer be used.
whesse@chromium.org7b260152011-06-20 15:33:18 +00005559 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation)
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00005560
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005561 // Indicates if this function can be lazy compiled without a context.
5562 // This is used to determine if we can force compilation without reaching
5563 // the function through program execution but through other means (e.g. heap
5564 // iteration by the debugger).
5565 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context)
5566
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005567 // Indicates how many full GCs this function has survived with assigned
5568 // code object. Used to determine when it is relatively safe to flush
5569 // this code object and replace it with lazy compilation stub.
5570 // Age is reset when GC notices that the code object is referenced
5571 // from the stack or compilation cache.
5572 inline int code_age();
5573 inline void set_code_age(int age);
5574
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005575 // Indicates whether optimizations have been disabled for this
5576 // shared function info. If a function is repeatedly optimized or if
5577 // we cannot optimize the function we disable optimization to avoid
5578 // spending time attempting to optimize it again.
whesse@chromium.org7b260152011-06-20 15:33:18 +00005579 DECL_BOOLEAN_ACCESSORS(optimization_disabled)
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005580
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005581 // Indicates the language mode of the function's code as defined by the
5582 // current harmony drafts for the next ES language standard. Possible
5583 // values are:
5584 // 1. CLASSIC_MODE - Unrestricted syntax and semantics, same as in ES5.
5585 // 2. STRICT_MODE - Restricted syntax and semantics, same as in ES5.
5586 // 3. EXTENDED_MODE - Only available under the harmony flag, not part of ES5.
5587 inline LanguageMode language_mode();
5588 inline void set_language_mode(LanguageMode language_mode);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005589
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005590 // Indicates whether the language mode of this function is CLASSIC_MODE.
5591 inline bool is_classic_mode();
5592
5593 // Indicates whether the language mode of this function is EXTENDED_MODE.
5594 inline bool is_extended_mode();
whesse@chromium.org7b260152011-06-20 15:33:18 +00005595
5596 // False if the function definitely does not allocate an arguments object.
5597 DECL_BOOLEAN_ACCESSORS(uses_arguments)
5598
5599 // True if the function has any duplicated parameter names.
5600 DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
ricow@chromium.org83aa5492011-02-07 12:42:56 +00005601
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005602 // Indicates whether the function is a native function.
lrn@chromium.org34e60782011-09-15 07:25:40 +00005603 // These needs special treatment in .call and .apply since
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005604 // null passed as the receiver should not be translated to the
5605 // global object.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005606 DECL_BOOLEAN_ACCESSORS(native)
5607
5608 // Indicates that the function was created by the Function function.
5609 // Though it's anonymous, toString should treat it as if it had the name
5610 // "anonymous". We don't set the name itself so that the system does not
5611 // see a binding for it.
5612 DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous)
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005613
whesse@chromium.org7b260152011-06-20 15:33:18 +00005614 // Indicates whether the function is a bound function created using
5615 // the bind function.
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005616 DECL_BOOLEAN_ACCESSORS(bound)
5617
5618 // Indicates that the function is anonymous (the name field can be set
5619 // through the API, which does not change this flag).
5620 DECL_BOOLEAN_ACCESSORS(is_anonymous)
whesse@chromium.org7b260152011-06-20 15:33:18 +00005621
yangguo@chromium.org56454712012-02-16 15:33:53 +00005622 // Is this a function or top-level/eval code.
5623 DECL_BOOLEAN_ACCESSORS(is_function)
5624
5625 // Indicates that the function cannot be optimized.
5626 DECL_BOOLEAN_ACCESSORS(dont_optimize)
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00005627
5628 // Indicates that the function cannot be inlined.
5629 DECL_BOOLEAN_ACCESSORS(dont_inline)
5630
danno@chromium.org81cac2b2012-07-10 11:28:27 +00005631 // Indicates that code for this function cannot be cached.
5632 DECL_BOOLEAN_ACCESSORS(dont_cache)
5633
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005634 // Indicates whether or not the code in the shared function support
5635 // deoptimization.
5636 inline bool has_deoptimization_support();
5637
5638 // Enable deoptimization support through recompiled code.
5639 void EnableDeoptimizationSupport(Code* recompiled);
5640
ager@chromium.orgea91cc52011-05-23 06:06:11 +00005641 // Disable (further) attempted optimization of all functions sharing this
yangguo@chromium.org56454712012-02-16 15:33:53 +00005642 // shared function info.
5643 void DisableOptimization();
ager@chromium.orgea91cc52011-05-23 06:06:11 +00005644
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005645 // Lookup the bailout ID and ASSERT that it exists in the non-optimized
5646 // code, returns whether it asserted (i.e., always true if assertions are
5647 // disabled).
5648 bool VerifyBailoutId(int id);
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005649
ager@chromium.org5c838252010-02-19 08:53:10 +00005650 // Check whether a inlined constructor can be generated with the given
5651 // prototype.
5652 bool CanGenerateInlineConstructor(Object* prototype);
5653
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +00005654 // Prevents further attempts to generate inline constructors.
5655 // To be called if generation failed for any reason.
5656 void ForbidInlineConstructor();
5657
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005658 // For functions which only contains this property assignments this provides
5659 // access to the names for the properties assigned.
5660 DECL_ACCESSORS(this_property_assignments, Object)
5661 inline int this_property_assignments_count();
5662 inline void set_this_property_assignments_count(int value);
5663 String* GetThisPropertyAssignmentName(int index);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00005664 bool IsThisPropertyAssignmentArgument(int index);
5665 int GetThisPropertyAssignmentArgument(int index);
5666 Object* GetThisPropertyAssignmentConstant(int index);
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005667
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005668 // [source code]: Source code for the function.
5669 bool HasSourceCode();
yangguo@chromium.org78d1ad42012-02-09 13:53:47 +00005670 Handle<Object> GetSourceCode();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005671
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005672 // Number of times the function was optimized.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005673 inline int opt_count();
5674 inline void set_opt_count(int opt_count);
5675
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005676 // Number of times the function was deoptimized.
5677 inline void set_deopt_count(int value);
5678 inline int deopt_count();
5679 inline void increment_deopt_count();
5680
5681 // Number of time we tried to re-enable optimization after it
5682 // was disabled due to high number of deoptimizations.
5683 inline void set_opt_reenable_tries(int value);
5684 inline int opt_reenable_tries();
5685
5686 inline void TryReenableOptimization();
5687
5688 // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields.
5689 inline void set_counters(int value);
5690 inline int counters();
5691
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005692 // Source size of this function.
5693 int SourceSize();
5694
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005695 // Calculate the instance size.
5696 int CalculateInstanceSize();
5697
5698 // Calculate the number of in-object properties.
5699 int CalculateInObjectProperties();
5700
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005701 // Dispatched behavior.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005702 // Set max_length to -1 for unlimited length.
5703 void SourceCodePrint(StringStream* accumulator, int max_length);
whesse@chromium.org023421e2010-12-21 12:19:12 +00005704#ifdef OBJECT_PRINT
5705 inline void SharedFunctionInfoPrint() {
5706 SharedFunctionInfoPrint(stdout);
5707 }
5708 void SharedFunctionInfoPrint(FILE* out);
5709#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005710#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005711 void SharedFunctionInfoVerify();
5712#endif
5713
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00005714 void ResetForNewContext(int new_ic_age);
5715
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005716 // Helper to compile the shared code. Returns true on success, false on
5717 // failure (e.g., stack overflow during compilation). This is only used by
5718 // the debugger, it is not possible to compile without a context otherwise.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005719 static bool CompileLazy(Handle<SharedFunctionInfo> shared,
5720 ClearExceptionFlag flag);
5721
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00005722 void SharedFunctionInfoIterateBody(ObjectVisitor* v);
5723
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005724 // Casting.
5725 static inline SharedFunctionInfo* cast(Object* obj);
5726
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00005727 // Constants.
5728 static const int kDontAdaptArgumentsSentinel = -1;
5729
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005730 // Layout description.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005731 // Pointer fields.
ager@chromium.org236ad962008-09-25 09:45:57 +00005732 static const int kNameOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005733 static const int kCodeOffset = kNameOffset + kPointerSize;
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005734 static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize;
5735 static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize;
ager@chromium.org6a2b0aa2010-07-13 20:58:03 +00005736 static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005737 static const int kInstanceClassNameOffset =
5738 kConstructStubOffset + kPointerSize;
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005739 static const int kFunctionDataOffset =
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005740 kInstanceClassNameOffset + kPointerSize;
vegorov@chromium.orgf8372902010-03-15 10:26:20 +00005741 static const int kScriptOffset = kFunctionDataOffset + kPointerSize;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005742 static const int kDebugInfoOffset = kScriptOffset + kPointerSize;
5743 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005744 static const int kInitialMapOffset =
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005745 kInferredNameOffset + kPointerSize;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005746 static const int kThisPropertyAssignmentsOffset =
5747 kInitialMapOffset + kPointerSize;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005748 // ast_node_count is a Smi field. It could be grouped with another Smi field
5749 // into a PSEUDO_SMI_ACCESSORS pair (on x64), if one becomes available.
5750 static const int kAstNodeCountOffset =
5751 kThisPropertyAssignmentsOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005752#if V8_HOST_ARCH_32_BIT
5753 // Smi fields.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005754 static const int kLengthOffset =
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005755 kAstNodeCountOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005756 static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize;
5757 static const int kExpectedNofPropertiesOffset =
5758 kFormalParameterCountOffset + kPointerSize;
5759 static const int kNumLiteralsOffset =
5760 kExpectedNofPropertiesOffset + kPointerSize;
5761 static const int kStartPositionAndTypeOffset =
5762 kNumLiteralsOffset + kPointerSize;
5763 static const int kEndPositionOffset =
5764 kStartPositionAndTypeOffset + kPointerSize;
5765 static const int kFunctionTokenPositionOffset =
5766 kEndPositionOffset + kPointerSize;
5767 static const int kCompilerHintsOffset =
5768 kFunctionTokenPositionOffset + kPointerSize;
5769 static const int kThisPropertyAssignmentsCountOffset =
5770 kCompilerHintsOffset + kPointerSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005771 static const int kOptCountOffset =
5772 kThisPropertyAssignmentsCountOffset + kPointerSize;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005773 static const int kCountersOffset = kOptCountOffset + kPointerSize;
5774 static const int kStressDeoptCounterOffset = kCountersOffset + kPointerSize;
danno@chromium.org1044a4d2012-04-30 12:34:39 +00005775
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005776 // Total size.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005777 static const int kSize = kStressDeoptCounterOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005778#else
5779 // The only reason to use smi fields instead of int fields
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005780 // is to allow iteration without maps decoding during
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005781 // garbage collections.
5782 // To avoid wasting space on 64-bit architectures we use
5783 // the following trick: we group integer fields into pairs
5784 // First integer in each pair is shifted left by 1.
5785 // By doing this we guarantee that LSB of each kPointerSize aligned
5786 // word is not set and thus this word cannot be treated as pointer
5787 // to HeapObject during old space traversal.
5788 static const int kLengthOffset =
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005789 kAstNodeCountOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005790 static const int kFormalParameterCountOffset =
5791 kLengthOffset + kIntSize;
5792
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005793 static const int kExpectedNofPropertiesOffset =
5794 kFormalParameterCountOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005795 static const int kNumLiteralsOffset =
5796 kExpectedNofPropertiesOffset + kIntSize;
5797
5798 static const int kEndPositionOffset =
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00005799 kNumLiteralsOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005800 static const int kStartPositionAndTypeOffset =
5801 kEndPositionOffset + kIntSize;
5802
5803 static const int kFunctionTokenPositionOffset =
5804 kStartPositionAndTypeOffset + kIntSize;
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005805 static const int kCompilerHintsOffset =
kasperl@chromium.org71affb52009-05-26 05:44:31 +00005806 kFunctionTokenPositionOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005807
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005808 static const int kThisPropertyAssignmentsCountOffset =
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005809 kCompilerHintsOffset + kIntSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005810 static const int kOptCountOffset =
5811 kThisPropertyAssignmentsCountOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005812
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005813 static const int kCountersOffset = kOptCountOffset + kIntSize;
5814 static const int kStressDeoptCounterOffset = kCountersOffset + kIntSize;
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00005815
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00005816 // Total size.
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005817 static const int kSize = kStressDeoptCounterOffset + kIntSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00005818
5819#endif
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00005820
5821 // The construction counter for inobject slack tracking is stored in the
5822 // most significant byte of compiler_hints which is otherwise unused.
5823 // Its offset depends on the endian-ness of the architecture.
5824#if __BYTE_ORDER == __LITTLE_ENDIAN
5825 static const int kConstructionCountOffset = kCompilerHintsOffset + 3;
5826#elif __BYTE_ORDER == __BIG_ENDIAN
5827 static const int kConstructionCountOffset = kCompilerHintsOffset + 0;
5828#else
5829#error Unknown byte ordering
5830#endif
5831
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +00005832 static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005833
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00005834 typedef FixedBodyDescriptor<kNameOffset,
5835 kThisPropertyAssignmentsOffset + kPointerSize,
5836 kSize> BodyDescriptor;
5837
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005838 // Bit positions in start_position_and_type.
5839 // The source code start position is in the 30 most significant bits of
5840 // the start_position_and_type field.
5841 static const int kIsExpressionBit = 0;
5842 static const int kIsTopLevelBit = 1;
5843 static const int kStartPositionShift = 2;
5844 static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
mads.s.ager31e71382008-08-13 09:32:07 +00005845
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005846 // Bit positions in compiler_hints.
whesse@chromium.org7b260152011-06-20 15:33:18 +00005847 static const int kCodeAgeSize = 3;
5848 static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1;
whesse@chromium.org7b260152011-06-20 15:33:18 +00005849
5850 enum CompilerHints {
5851 kHasOnlySimpleThisPropertyAssignments,
5852 kAllowLazyCompilation,
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00005853 kAllowLazyCompilationWithoutContext,
whesse@chromium.org7b260152011-06-20 15:33:18 +00005854 kLiveObjectsMayExist,
5855 kCodeAgeShift,
5856 kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize,
5857 kStrictModeFunction,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005858 kExtendedModeFunction,
whesse@chromium.org7b260152011-06-20 15:33:18 +00005859 kUsesArguments,
5860 kHasDuplicateParameters,
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005861 kNative,
5862 kBoundFunction,
5863 kIsAnonymous,
5864 kNameShouldPrintAsAnonymous,
yangguo@chromium.org56454712012-02-16 15:33:53 +00005865 kIsFunction,
5866 kDontOptimize,
svenpanne@chromium.orgb1df11d2012-02-08 10:26:21 +00005867 kDontInline,
danno@chromium.org81cac2b2012-07-10 11:28:27 +00005868 kDontCache,
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005869 kCompilerHintsCount // Pseudo entry
whesse@chromium.org7b260152011-06-20 15:33:18 +00005870 };
sgjesse@chromium.org911335c2009-08-19 12:59:44 +00005871
mmassi@chromium.org7028c052012-06-13 11:51:58 +00005872 class DeoptCountBits: public BitField<int, 0, 4> {};
5873 class OptReenableTriesBits: public BitField<int, 4, 18> {};
5874 class ICAgeBits: public BitField<int, 22, 8> {};
5875
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005876 private:
5877#if V8_HOST_ARCH_32_BIT
5878 // On 32 bit platforms, compiler hints is a smi.
5879 static const int kCompilerHintsSmiTagSize = kSmiTagSize;
5880 static const int kCompilerHintsSize = kPointerSize;
5881#else
5882 // On 64 bit platforms, compiler hints is not a smi, see comment above.
5883 static const int kCompilerHintsSmiTagSize = 0;
5884 static const int kCompilerHintsSize = kIntSize;
5885#endif
5886
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00005887 STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <=
5888 SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte);
5889
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005890 public:
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005891 // Constants for optimizing codegen for strict mode function and
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005892 // native tests.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00005893 // Allows to use byte-width instructions.
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005894 static const int kStrictModeBitWithinByte =
5895 (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
5896
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005897 static const int kExtendedModeBitWithinByte =
5898 (kExtendedModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
5899
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005900 static const int kNativeBitWithinByte =
5901 (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte;
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005902
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005903#if __BYTE_ORDER == __LITTLE_ENDIAN
5904 static const int kStrictModeByteOffset = kCompilerHintsOffset +
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005905 (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005906 static const int kExtendedModeByteOffset = kCompilerHintsOffset +
5907 (kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005908 static const int kNativeByteOffset = kCompilerHintsOffset +
5909 (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte;
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005910#elif __BYTE_ORDER == __BIG_ENDIAN
5911 static const int kStrictModeByteOffset = kCompilerHintsOffset +
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005912 (kCompilerHintsSize - 1) -
5913 ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00005914 static const int kExtendedModeByteOffset = kCompilerHintsOffset +
5915 (kCompilerHintsSize - 1) -
5916 ((kExtendedModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005917 static const int kNativeByteOffset = kCompilerHintsOffset +
ricow@chromium.org6fe7a8e2011-05-13 07:57:29 +00005918 (kCompilerHintsSize - 1) -
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00005919 ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte);
kmillikin@chromium.org49edbdf2011-02-16 12:32:18 +00005920#else
5921#error Unknown byte ordering
5922#endif
5923
5924 private:
mads.s.ager31e71382008-08-13 09:32:07 +00005925 DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005926};
5927
5928
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00005929// Representation for module instance objects.
5930class JSModule: public JSObject {
5931 public:
5932 // [context]: the context holding the module's locals, or undefined if none.
5933 DECL_ACCESSORS(context, Object)
5934
danno@chromium.org81cac2b2012-07-10 11:28:27 +00005935 // [scope_info]: Scope info.
5936 DECL_ACCESSORS(scope_info, ScopeInfo)
5937
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00005938 // Casting.
5939 static inline JSModule* cast(Object* obj);
5940
5941 // Dispatched behavior.
5942#ifdef OBJECT_PRINT
5943 inline void JSModulePrint() {
5944 JSModulePrint(stdout);
5945 }
5946 void JSModulePrint(FILE* out);
5947#endif
5948#ifdef DEBUG
5949 void JSModuleVerify();
5950#endif
5951
5952 // Layout description.
5953 static const int kContextOffset = JSObject::kHeaderSize;
danno@chromium.org81cac2b2012-07-10 11:28:27 +00005954 static const int kScopeInfoOffset = kContextOffset + kPointerSize;
5955 static const int kSize = kScopeInfoOffset + kPointerSize;
erik.corry@gmail.comed49e962012-04-17 11:57:53 +00005956
5957 private:
5958 DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule);
5959};
5960
5961
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005962// JSFunction describes JavaScript functions.
5963class JSFunction: public JSObject {
5964 public:
5965 // [prototype_or_initial_map]:
5966 DECL_ACCESSORS(prototype_or_initial_map, Object)
5967
lrn@chromium.org34e60782011-09-15 07:25:40 +00005968 // [shared]: The information about the function that
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005969 // can be shared by instances.
5970 DECL_ACCESSORS(shared, SharedFunctionInfo)
5971
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005972 inline SharedFunctionInfo* unchecked_shared();
5973
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005974 // [context]: The context for this function.
5975 inline Context* context();
5976 inline Object* unchecked_context();
5977 inline void set_context(Object* context);
5978
5979 // [code]: The generated code object for this function. Executed
5980 // when the function is invoked, e.g. foo() or new foo(). See
5981 // [[Call]] and [[Construct]] description in ECMA-262, section
5982 // 8.6.2, page 27.
5983 inline Code* code();
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005984 inline void set_code(Code* code);
5985 inline void ReplaceCode(Code* code);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00005986
ricow@chromium.org0b9f8502010-08-18 07:45:01 +00005987 inline Code* unchecked_code();
5988
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +00005989 // Tells whether this function is builtin.
5990 inline bool IsBuiltin();
5991
kasperl@chromium.orga5551262010-12-07 12:49:48 +00005992 // Tells whether or not the function needs arguments adaption.
5993 inline bool NeedsArgumentsAdaption();
5994
5995 // Tells whether or not this function has been optimized.
5996 inline bool IsOptimized();
5997
ager@chromium.orga9aa5fa2011-04-13 08:46:07 +00005998 // Tells whether or not this function can be optimized.
5999 inline bool IsOptimizable();
6000
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006001 // Mark this function for lazy recompilation. The function will be
6002 // recompiled the next time it is executed.
6003 void MarkForLazyRecompilation();
6004
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006005 // Helpers to compile this function. Returns true on success, false on
6006 // failure (e.g., stack overflow during compilation).
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +00006007 static bool EnsureCompiled(Handle<JSFunction> function,
6008 ClearExceptionFlag flag);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006009 static bool CompileLazy(Handle<JSFunction> function,
6010 ClearExceptionFlag flag);
6011 static bool CompileOptimized(Handle<JSFunction> function,
6012 int osr_ast_id,
6013 ClearExceptionFlag flag);
6014
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006015 // Tells whether or not the function is already marked for lazy
6016 // recompilation.
6017 inline bool IsMarkedForLazyRecompilation();
6018
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006019 // Check whether or not this function is inlineable.
6020 bool IsInlineable();
6021
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006022 // [literals_or_bindings]: Fixed array holding either
6023 // the materialized literals or the bindings of a bound function.
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00006024 //
6025 // If the function contains object, regexp or array literals, the
6026 // literals array prefix contains the object, regexp, and array
6027 // function to be used when creating these literals. This is
6028 // necessary so that we do not dynamically lookup the object, regexp
6029 // or array functions. Performing a dynamic lookup, we might end up
6030 // using the functions from a new context that we should not have
6031 // access to.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006032 //
6033 // On bound functions, the array is a (copy-on-write) fixed-array containing
6034 // the function that was bound, bound this-value and any bound
6035 // arguments. Bound functions never contain literals.
6036 DECL_ACCESSORS(literals_or_bindings, FixedArray)
6037
6038 inline FixedArray* literals();
6039 inline void set_literals(FixedArray* literals);
6040
6041 inline FixedArray* function_bindings();
6042 inline void set_function_bindings(FixedArray* bindings);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006043
6044 // The initial map for an object created by this constructor.
6045 inline Map* initial_map();
6046 inline void set_initial_map(Map* value);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00006047 MUST_USE_RESULT inline MaybeObject* set_initial_map_and_cache_transitions(
6048 Map* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006049 inline bool has_initial_map();
6050
6051 // Get and set the prototype property on a JSFunction. If the
6052 // function has an initial map the prototype is set on the initial
6053 // map. Otherwise, the prototype is put in the initial map field
6054 // until an initial map is needed.
6055 inline bool has_prototype();
6056 inline bool has_instance_prototype();
6057 inline Object* prototype();
6058 inline Object* instance_prototype();
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00006059 MUST_USE_RESULT MaybeObject* SetInstancePrototype(Object* value);
lrn@chromium.org303ada72010-10-27 09:33:13 +00006060 MUST_USE_RESULT MaybeObject* SetPrototype(Object* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006061
kmillikin@chromium.org4111b802010-05-03 10:34:42 +00006062 // After prototype is removed, it will not be created when accessed, and
6063 // [[Construct]] from this function will not be allowed.
6064 Object* RemovePrototype();
6065 inline bool should_have_prototype();
6066
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006067 // Accessor for this function's initial map's [[class]]
6068 // property. This is primarily used by ECMA native functions. This
6069 // method sets the class_name field of this function's initial map
6070 // to a given value. It creates an initial map if this function does
6071 // not have one. Note that this method does not copy the initial map
6072 // if it has one already, but simply replaces it with the new value.
6073 // Instances created afterwards will have a map whose [[class]] is
6074 // set to 'value', but there is no guarantees on instances created
6075 // before.
6076 Object* SetInstanceClassName(String* name);
6077
6078 // Returns if this function has been compiled to native code yet.
6079 inline bool is_compiled();
6080
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006081 // [next_function_link]: Field for linking functions. This list is treated as
6082 // a weak list by the GC.
6083 DECL_ACCESSORS(next_function_link, Object)
6084
6085 // Prints the name of the function using PrintF.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006086 inline void PrintName() {
6087 PrintName(stdout);
6088 }
6089 void PrintName(FILE* out);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006090
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006091 // Casting.
6092 static inline JSFunction* cast(Object* obj);
6093
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00006094 // Iterates the objects, including code objects indirectly referenced
6095 // through pointers to the first instruction in the code object.
6096 void JSFunctionIterateBody(int object_size, ObjectVisitor* v);
6097
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006098 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006099#ifdef OBJECT_PRINT
6100 inline void JSFunctionPrint() {
6101 JSFunctionPrint(stdout);
6102 }
6103 void JSFunctionPrint(FILE* out);
6104#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006105#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006106 void JSFunctionVerify();
6107#endif
6108
6109 // Returns the number of allocated literals.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006110 inline int NumberOfLiterals();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006111
ager@chromium.org236ad962008-09-25 09:45:57 +00006112 // Retrieve the global context from a function's literal array.
6113 static Context* GlobalContextFromLiterals(FixedArray* literals);
6114
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006115 // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to
6116 // kSize) is weak and has special handling during garbage collection.
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00006117 static const int kCodeEntryOffset = JSObject::kHeaderSize;
vegorov@chromium.org26c16f82010-08-11 13:41:03 +00006118 static const int kPrototypeOrInitialMapOffset =
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00006119 kCodeEntryOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006120 static const int kSharedFunctionInfoOffset =
6121 kPrototypeOrInitialMapOffset + kPointerSize;
6122 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
6123 static const int kLiteralsOffset = kContextOffset + kPointerSize;
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006124 static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize;
6125 static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset;
6126 static const int kSize = kNextFunctionLinkOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006127
mads.s.ager@gmail.com9a4089a2008-09-01 08:55:01 +00006128 // Layout of the literals array.
ager@chromium.org236ad962008-09-25 09:45:57 +00006129 static const int kLiteralsPrefixSize = 1;
6130 static const int kLiteralGlobalContextIndex = 0;
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006131
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006132 // Layout of the bound-function binding array.
6133 static const int kBoundFunctionIndex = 0;
6134 static const int kBoundThisIndex = 1;
6135 static const int kBoundArgumentsStartIndex = 2;
6136
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006137 private:
6138 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
6139};
6140
6141
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006142// JSGlobalProxy's prototype must be a JSGlobalObject or null,
6143// and the prototype is hidden. JSGlobalProxy always delegates
6144// property accesses to its prototype if the prototype is not null.
6145//
6146// A JSGlobalProxy can be reinitialized which will preserve its identity.
6147//
6148// Accessing a JSGlobalProxy requires security check.
6149
6150class JSGlobalProxy : public JSObject {
6151 public:
ager@chromium.orgea91cc52011-05-23 06:06:11 +00006152 // [context]: the owner global context of this global proxy object.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006153 // It is null value if this object is not used by any context.
6154 DECL_ACCESSORS(context, Object)
6155
6156 // Casting.
6157 static inline JSGlobalProxy* cast(Object* obj);
6158
6159 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006160#ifdef OBJECT_PRINT
6161 inline void JSGlobalProxyPrint() {
6162 JSGlobalProxyPrint(stdout);
6163 }
6164 void JSGlobalProxyPrint(FILE* out);
6165#endif
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006166#ifdef DEBUG
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006167 void JSGlobalProxyVerify();
6168#endif
6169
6170 // Layout description.
6171 static const int kContextOffset = JSObject::kHeaderSize;
6172 static const int kSize = kContextOffset + kPointerSize;
6173
6174 private:
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006175 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
6176};
6177
6178
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006179// Forward declaration.
6180class JSBuiltinsObject;
6181
6182// Common super class for JavaScript global objects and the special
6183// builtins global objects.
6184class GlobalObject: public JSObject {
6185 public:
6186 // [builtins]: the object holding the runtime routines written in JS.
6187 DECL_ACCESSORS(builtins, JSBuiltinsObject)
6188
kasperl@chromium.org9bbf9682008-10-30 11:53:07 +00006189 // [global context]: the global context corresponding to this global object.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006190 DECL_ACCESSORS(global_context, Context)
6191
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006192 // [global receiver]: the global receiver object of the context
6193 DECL_ACCESSORS(global_receiver, JSObject)
6194
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00006195 // Retrieve the property cell used to store a property.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006196 JSGlobalPropertyCell* GetPropertyCell(LookupResult* result);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00006197
lrn@chromium.org303ada72010-10-27 09:33:13 +00006198 // This is like GetProperty, but is used when you know the lookup won't fail
6199 // by throwing an exception. This is for the debug and builtins global
6200 // objects, where it is known which properties can be expected to be present
6201 // on the object.
6202 Object* GetPropertyNoExceptionThrown(String* key) {
6203 Object* answer = GetProperty(key)->ToObjectUnchecked();
6204 return answer;
6205 }
6206
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00006207 // Ensure that the global object has a cell for the given property name.
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006208 static Handle<JSGlobalPropertyCell> EnsurePropertyCell(
6209 Handle<GlobalObject> global,
6210 Handle<String> name);
6211 // TODO(kmillikin): This function can be eliminated once the stub cache is
6212 // full handlified (and the static helper can be written directly).
lrn@chromium.org303ada72010-10-27 09:33:13 +00006213 MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name);
kasperl@chromium.orgdefbd102009-07-13 14:04:26 +00006214
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006215 // Casting.
6216 static inline GlobalObject* cast(Object* obj);
6217
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006218 // Layout description.
6219 static const int kBuiltinsOffset = JSObject::kHeaderSize;
6220 static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006221 static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize;
6222 static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006223
6224 private:
mads.s.ager31e71382008-08-13 09:32:07 +00006225 DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006226};
6227
6228
6229// JavaScript global object.
6230class JSGlobalObject: public GlobalObject {
6231 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006232 // Casting.
6233 static inline JSGlobalObject* cast(Object* obj);
6234
6235 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006236#ifdef OBJECT_PRINT
6237 inline void JSGlobalObjectPrint() {
6238 JSGlobalObjectPrint(stdout);
6239 }
6240 void JSGlobalObjectPrint(FILE* out);
6241#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006242#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006243 void JSGlobalObjectVerify();
6244#endif
6245
6246 // Layout description.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00006247 static const int kSize = GlobalObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006248
6249 private:
6250 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject);
6251};
6252
6253
6254// Builtins global object which holds the runtime routines written in
6255// JavaScript.
6256class JSBuiltinsObject: public GlobalObject {
6257 public:
6258 // Accessors for the runtime routines written in JavaScript.
6259 inline Object* javascript_builtin(Builtins::JavaScript id);
6260 inline void set_javascript_builtin(Builtins::JavaScript id, Object* value);
6261
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00006262 // Accessors for code of the runtime routines written in JavaScript.
6263 inline Code* javascript_builtin_code(Builtins::JavaScript id);
6264 inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value);
6265
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006266 // Casting.
6267 static inline JSBuiltinsObject* cast(Object* obj);
6268
6269 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006270#ifdef OBJECT_PRINT
6271 inline void JSBuiltinsObjectPrint() {
6272 JSBuiltinsObjectPrint(stdout);
6273 }
6274 void JSBuiltinsObjectPrint(FILE* out);
6275#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006276#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006277 void JSBuiltinsObjectVerify();
6278#endif
6279
6280 // Layout description. The size of the builtins object includes
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00006281 // room for two pointers per runtime routine written in javascript
6282 // (function and code object).
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006283 static const int kJSBuiltinsCount = Builtins::id_count;
6284 static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize;
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00006285 static const int kJSBuiltinsCodeOffset =
6286 GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006287 static const int kSize =
ricow@chromium.orgc9c80822010-04-21 08:22:37 +00006288 kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize);
6289
6290 static int OffsetOfFunctionWithId(Builtins::JavaScript id) {
6291 return kJSBuiltinsOffset + id * kPointerSize;
6292 }
6293
6294 static int OffsetOfCodeWithId(Builtins::JavaScript id) {
6295 return kJSBuiltinsCodeOffset + id * kPointerSize;
6296 }
6297
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006298 private:
6299 DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject);
6300};
6301
6302
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +00006303// Representation for JS Wrapper objects, String, Number, Boolean, etc.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006304class JSValue: public JSObject {
6305 public:
6306 // [value]: the object being wrapped.
6307 DECL_ACCESSORS(value, Object)
6308
6309 // Casting.
6310 static inline JSValue* cast(Object* obj);
6311
6312 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00006313#ifdef OBJECT_PRINT
6314 inline void JSValuePrint() {
6315 JSValuePrint(stdout);
6316 }
6317 void JSValuePrint(FILE* out);
6318#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006319#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006320 void JSValueVerify();
6321#endif
6322
6323 // Layout description.
6324 static const int kValueOffset = JSObject::kHeaderSize;
6325 static const int kSize = kValueOffset + kPointerSize;
6326
6327 private:
6328 DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue);
6329};
6330
kmillikin@chromium.org31b12772011-02-02 16:08:26 +00006331
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +00006332class DateCache;
6333
6334// Representation for JS date objects.
6335class JSDate: public JSObject {
6336 public:
6337 // If one component is NaN, all of them are, indicating a NaN time value.
6338 // [value]: the time value.
6339 DECL_ACCESSORS(value, Object)
6340 // [year]: caches year. Either undefined, smi, or NaN.
6341 DECL_ACCESSORS(year, Object)
6342 // [month]: caches month. Either undefined, smi, or NaN.
6343 DECL_ACCESSORS(month, Object)
6344 // [day]: caches day. Either undefined, smi, or NaN.
6345 DECL_ACCESSORS(day, Object)
6346 // [weekday]: caches day of week. Either undefined, smi, or NaN.
6347 DECL_ACCESSORS(weekday, Object)
6348 // [hour]: caches hours. Either undefined, smi, or NaN.
6349 DECL_ACCESSORS(hour, Object)
6350 // [min]: caches minutes. Either undefined, smi, or NaN.
6351 DECL_ACCESSORS(min, Object)
6352 // [sec]: caches seconds. Either undefined, smi, or NaN.
6353 DECL_ACCESSORS(sec, Object)
6354 // [cache stamp]: sample of the date cache stamp at the
6355 // moment when local fields were cached.
6356 DECL_ACCESSORS(cache_stamp, Object)
6357
6358 // Casting.
6359 static inline JSDate* cast(Object* obj);
6360
6361 // Returns the date field with the specified index.
6362 // See FieldIndex for the list of date fields.
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00006363 static Object* GetField(Object* date, Smi* index);
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +00006364
6365 void SetValue(Object* value, bool is_value_nan);
6366
6367
6368 // Dispatched behavior.
6369#ifdef OBJECT_PRINT
6370 inline void JSDatePrint() {
6371 JSDatePrint(stdout);
6372 }
6373 void JSDatePrint(FILE* out);
6374#endif
6375#ifdef DEBUG
6376 void JSDateVerify();
6377#endif
6378 // The order is important. It must be kept in sync with date macros
6379 // in macros.py.
6380 enum FieldIndex {
6381 kDateValue,
6382 kYear,
6383 kMonth,
6384 kDay,
6385 kWeekday,
6386 kHour,
6387 kMinute,
6388 kSecond,
6389 kFirstUncachedField,
6390 kMillisecond = kFirstUncachedField,
6391 kDays,
6392 kTimeInDay,
6393 kFirstUTCField,
6394 kYearUTC = kFirstUTCField,
6395 kMonthUTC,
6396 kDayUTC,
6397 kWeekdayUTC,
6398 kHourUTC,
6399 kMinuteUTC,
6400 kSecondUTC,
6401 kMillisecondUTC,
6402 kDaysUTC,
6403 kTimeInDayUTC,
6404 kTimezoneOffset
6405 };
6406
6407 // Layout description.
6408 static const int kValueOffset = JSObject::kHeaderSize;
6409 static const int kYearOffset = kValueOffset + kPointerSize;
6410 static const int kMonthOffset = kYearOffset + kPointerSize;
6411 static const int kDayOffset = kMonthOffset + kPointerSize;
6412 static const int kWeekdayOffset = kDayOffset + kPointerSize;
6413 static const int kHourOffset = kWeekdayOffset + kPointerSize;
6414 static const int kMinOffset = kHourOffset + kPointerSize;
6415 static const int kSecOffset = kMinOffset + kPointerSize;
6416 static const int kCacheStampOffset = kSecOffset + kPointerSize;
6417 static const int kSize = kCacheStampOffset + kPointerSize;
6418
6419 private:
6420 inline Object* DoGetField(FieldIndex index);
6421
6422 Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache);
6423
6424 // Computes and caches the cacheable fields of the date.
6425 inline void SetLocalFields(int64_t local_time_ms, DateCache* date_cache);
6426
6427
6428 DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate);
6429};
6430
6431
kmillikin@chromium.org31b12772011-02-02 16:08:26 +00006432// Representation of message objects used for error reporting through
6433// the API. The messages are formatted in JavaScript so this object is
6434// a real JavaScript object. The information used for formatting the
6435// error messages are not directly accessible from JavaScript to
6436// prevent leaking information to user code called during error
6437// formatting.
6438class JSMessageObject: public JSObject {
6439 public:
6440 // [type]: the type of error message.
6441 DECL_ACCESSORS(type, String)
6442
6443 // [arguments]: the arguments for formatting the error message.
6444 DECL_ACCESSORS(arguments, JSArray)
6445
6446 // [script]: the script from which the error message originated.
6447 DECL_ACCESSORS(script, Object)
6448
6449 // [stack_trace]: the stack trace for this error message.
6450 DECL_ACCESSORS(stack_trace, Object)
6451
6452 // [stack_frames]: an array of stack frames for this error object.
6453 DECL_ACCESSORS(stack_frames, Object)
6454
6455 // [start_position]: the start position in the script for the error message.
6456 inline int start_position();
6457 inline void set_start_position(int value);
6458
6459 // [end_position]: the end position in the script for the error message.
6460 inline int end_position();
6461 inline void set_end_position(int value);
6462
6463 // Casting.
6464 static inline JSMessageObject* cast(Object* obj);
6465
6466 // Dispatched behavior.
6467#ifdef OBJECT_PRINT
6468 inline void JSMessageObjectPrint() {
6469 JSMessageObjectPrint(stdout);
6470 }
6471 void JSMessageObjectPrint(FILE* out);
6472#endif
6473#ifdef DEBUG
6474 void JSMessageObjectVerify();
6475#endif
6476
6477 // Layout description.
6478 static const int kTypeOffset = JSObject::kHeaderSize;
6479 static const int kArgumentsOffset = kTypeOffset + kPointerSize;
6480 static const int kScriptOffset = kArgumentsOffset + kPointerSize;
6481 static const int kStackTraceOffset = kScriptOffset + kPointerSize;
6482 static const int kStackFramesOffset = kStackTraceOffset + kPointerSize;
6483 static const int kStartPositionOffset = kStackFramesOffset + kPointerSize;
6484 static const int kEndPositionOffset = kStartPositionOffset + kPointerSize;
6485 static const int kSize = kEndPositionOffset + kPointerSize;
6486
6487 typedef FixedBodyDescriptor<HeapObject::kMapOffset,
6488 kStackFramesOffset + kPointerSize,
6489 kSize> BodyDescriptor;
6490};
6491
6492
ager@chromium.org236ad962008-09-25 09:45:57 +00006493// Regular expressions
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006494// The regular expression holds a single reference to a FixedArray in
6495// the kDataOffset field.
6496// The FixedArray contains the following data:
6497// - tag : type of regexp implementation (not compiled yet, atom or irregexp)
6498// - reference to the original source string
6499// - reference to the original flag string
6500// If it is an atom regexp
6501// - a reference to a literal string to search for
6502// If it is an irregexp regexp:
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006503// - a reference to code for ASCII inputs (bytecode or compiled), or a smi
6504// used for tracking the last usage (used for code flushing).
6505// - a reference to code for UC16 inputs (bytecode or compiled), or a smi
6506// used for tracking the last usage (used for code flushing)..
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006507// - max number of registers used by irregexp implementations.
6508// - number of capture registers (output values) of the regexp.
ager@chromium.org236ad962008-09-25 09:45:57 +00006509class JSRegExp: public JSObject {
6510 public:
ager@chromium.orga74f0da2008-12-03 16:05:52 +00006511 // Meaning of Type:
6512 // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
ager@chromium.orga74f0da2008-12-03 16:05:52 +00006513 // ATOM: A simple string to match against using an indexOf operation.
6514 // IRREGEXP: Compiled with Irregexp.
6515 // IRREGEXP_NATIVE: Compiled to native code with Irregexp.
ager@chromium.org381abbb2009-02-25 13:23:22 +00006516 enum Type { NOT_COMPILED, ATOM, IRREGEXP };
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006517 enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 };
ager@chromium.org236ad962008-09-25 09:45:57 +00006518
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006519 class Flags {
6520 public:
6521 explicit Flags(uint32_t value) : value_(value) { }
6522 bool is_global() { return (value_ & GLOBAL) != 0; }
6523 bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; }
6524 bool is_multiline() { return (value_ & MULTILINE) != 0; }
6525 uint32_t value() { return value_; }
6526 private:
6527 uint32_t value_;
6528 };
ager@chromium.org236ad962008-09-25 09:45:57 +00006529
ager@chromium.org236ad962008-09-25 09:45:57 +00006530 DECL_ACCESSORS(data, Object)
6531
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006532 inline Type TypeTag();
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00006533 inline int CaptureCount();
ager@chromium.orga74f0da2008-12-03 16:05:52 +00006534 inline Flags GetFlags();
6535 inline String* Pattern();
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006536 inline Object* DataAt(int index);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006537 // Set implementation data after the object has been prepared.
6538 inline void SetDataAt(int index, Object* value);
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006539
6540 // Used during GC when flushing code or setting age.
6541 inline Object* DataAtUnchecked(int index);
6542 inline void SetDataAtUnchecked(int index, Object* value, Heap* heap);
6543 inline Type TypeTagUnchecked();
6544
kasperl@chromium.org68ac0092009-07-09 06:00:35 +00006545 static int code_index(bool is_ascii) {
6546 if (is_ascii) {
6547 return kIrregexpASCIICodeIndex;
6548 } else {
6549 return kIrregexpUC16CodeIndex;
6550 }
6551 }
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006552
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006553 static int saved_code_index(bool is_ascii) {
6554 if (is_ascii) {
6555 return kIrregexpASCIICodeSavedIndex;
6556 } else {
6557 return kIrregexpUC16CodeSavedIndex;
6558 }
6559 }
6560
ager@chromium.org236ad962008-09-25 09:45:57 +00006561 static inline JSRegExp* cast(Object* obj);
6562
6563 // Dispatched behavior.
6564#ifdef DEBUG
ager@chromium.org236ad962008-09-25 09:45:57 +00006565 void JSRegExpVerify();
6566#endif
6567
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006568 static const int kDataOffset = JSObject::kHeaderSize;
kasperl@chromium.org71affb52009-05-26 05:44:31 +00006569 static const int kSize = kDataOffset + kPointerSize;
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006570
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006571 // Indices in the data array.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006572 static const int kTagIndex = 0;
6573 static const int kSourceIndex = kTagIndex + 1;
6574 static const int kFlagsIndex = kSourceIndex + 1;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006575 static const int kDataIndex = kFlagsIndex + 1;
6576 // The data fields are used in different ways depending on the
6577 // value of the tag.
6578 // Atom regexps (literal strings).
6579 static const int kAtomPatternIndex = kDataIndex;
6580
6581 static const int kAtomDataSize = kAtomPatternIndex + 1;
6582
ager@chromium.orga1645e22009-09-09 19:27:10 +00006583 // Irregexp compiled code or bytecode for ASCII. If compilation
6584 // fails, this fields hold an exception object that should be
6585 // thrown if the regexp is used again.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006586 static const int kIrregexpASCIICodeIndex = kDataIndex;
ager@chromium.orga1645e22009-09-09 19:27:10 +00006587 // Irregexp compiled code or bytecode for UC16. If compilation
6588 // fails, this fields hold an exception object that should be
6589 // thrown if the regexp is used again.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006590 static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006591
6592 // Saved instance of Irregexp compiled code or bytecode for ASCII that
6593 // is a potential candidate for flushing.
6594 static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2;
6595 // Saved instance of Irregexp compiled code or bytecode for UC16 that is
6596 // a potential candidate for flushing.
6597 static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3;
6598
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006599 // Maximal number of registers used by either ASCII or UC16.
6600 // Only used to check that there is enough stack space
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006601 static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006602 // Number of captures in the compiled regexp.
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006603 static const int kIrregexpCaptureCountIndex = kDataIndex + 5;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00006604
6605 static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00006606
6607 // Offsets directly into the data fixed array.
6608 static const int kDataTagOffset =
6609 FixedArray::kHeaderSize + kTagIndex * kPointerSize;
6610 static const int kDataAsciiCodeOffset =
6611 FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00006612 static const int kDataUC16CodeOffset =
6613 FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00006614 static const int kIrregexpCaptureCountOffset =
6615 FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
lrn@chromium.org25156de2010-04-06 13:10:27 +00006616
6617 // In-object fields.
6618 static const int kSourceFieldIndex = 0;
6619 static const int kGlobalFieldIndex = 1;
6620 static const int kIgnoreCaseFieldIndex = 2;
6621 static const int kMultilineFieldIndex = 3;
6622 static const int kLastIndexFieldIndex = 4;
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +00006623 static const int kInObjectFieldCount = 5;
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +00006624
6625 // The uninitialized value for a regexp code object.
6626 static const int kUninitializedValue = -1;
6627
6628 // The compilation error value for the regexp code object. The real error
6629 // object is in the saved code field.
6630 static const int kCompilationErrorValue = -2;
6631
6632 // When we store the sweep generation at which we moved the code from the
6633 // code index to the saved code index we mask it of to be in the [0:255]
6634 // range.
6635 static const int kCodeAgeMask = 0xff;
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006636};
6637
6638
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00006639class CompilationCacheShape : public BaseShape<HashTableKey*> {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00006640 public:
6641 static inline bool IsMatch(HashTableKey* key, Object* value) {
6642 return key->IsMatch(value);
6643 }
6644
6645 static inline uint32_t Hash(HashTableKey* key) {
6646 return key->Hash();
6647 }
6648
6649 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
6650 return key->HashForObject(object);
6651 }
6652
lrn@chromium.org303ada72010-10-27 09:33:13 +00006653 MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00006654 return key->AsObject();
6655 }
6656
6657 static const int kPrefixSize = 0;
6658 static const int kEntrySize = 2;
6659};
6660
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +00006661
kasperl@chromium.org86f77b72009-07-06 08:21:57 +00006662class CompilationCacheTable: public HashTable<CompilationCacheShape,
6663 HashTableKey*> {
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006664 public:
6665 // Find cached value for a string key, otherwise return null.
6666 Object* Lookup(String* src);
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00006667 Object* LookupEval(String* src,
6668 Context* context,
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00006669 LanguageMode language_mode,
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00006670 int scope_position);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006671 Object* LookupRegExp(String* source, JSRegExp::Flags flags);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00006672 MUST_USE_RESULT MaybeObject* Put(String* src, Object* value);
6673 MUST_USE_RESULT MaybeObject* PutEval(String* src,
6674 Context* context,
6675 SharedFunctionInfo* value,
6676 int scope_position);
6677 MUST_USE_RESULT MaybeObject* PutRegExp(String* src,
6678 JSRegExp::Flags flags,
6679 FixedArray* value);
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006680
kasperl@chromium.orga5551262010-12-07 12:49:48 +00006681 // Remove given value from cache.
6682 void Remove(Object* value);
6683
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00006684 static inline CompilationCacheTable* cast(Object* obj);
6685
6686 private:
6687 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable);
ager@chromium.org236ad962008-09-25 09:45:57 +00006688};
6689
6690
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006691class CodeCache: public Struct {
6692 public:
6693 DECL_ACCESSORS(default_cache, FixedArray)
6694 DECL_ACCESSORS(normal_type_cache, Object)
6695
6696 // Add the code object to the cache.
lrn@chromium.org303ada72010-10-27 09:33:13 +00006697 MUST_USE_RESULT MaybeObject* Update(String* name, Code* code);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006698
6699 // Lookup code object in the cache. Returns code object if found and undefined
6700 // if not.
6701 Object* Lookup(String* name, Code::Flags flags);
6702
6703 // Get the internal index of a code object in the cache. Returns -1 if the
6704 // code object is not in that cache. This index can be used to later call
6705 // RemoveByIndex. The cache cannot be modified between a call to GetIndex and
6706 // RemoveByIndex.
sgjesse@chromium.org99a37fa2010-03-11 09:23:46 +00006707 int GetIndex(Object* name, Code* code);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006708
6709 // Remove an object from the cache with the provided internal index.
sgjesse@chromium.org99a37fa2010-03-11 09:23:46 +00006710 void RemoveByIndex(Object* name, Code* code, int index);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006711
6712 static inline CodeCache* cast(Object* obj);
6713
whesse@chromium.org023421e2010-12-21 12:19:12 +00006714#ifdef OBJECT_PRINT
6715 inline void CodeCachePrint() {
6716 CodeCachePrint(stdout);
6717 }
6718 void CodeCachePrint(FILE* out);
6719#endif
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006720#ifdef DEBUG
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006721 void CodeCacheVerify();
6722#endif
6723
6724 static const int kDefaultCacheOffset = HeapObject::kHeaderSize;
6725 static const int kNormalTypeCacheOffset =
6726 kDefaultCacheOffset + kPointerSize;
6727 static const int kSize = kNormalTypeCacheOffset + kPointerSize;
6728
6729 private:
lrn@chromium.org303ada72010-10-27 09:33:13 +00006730 MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code);
6731 MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006732 Object* LookupDefaultCache(String* name, Code::Flags flags);
6733 Object* LookupNormalTypeCache(String* name, Code::Flags flags);
6734
6735 // Code cache layout of the default cache. Elements are alternating name and
6736 // code objects for non normal load/store/call IC's.
6737 static const int kCodeCacheEntrySize = 2;
6738 static const int kCodeCacheEntryNameOffset = 0;
6739 static const int kCodeCacheEntryCodeOffset = 1;
6740
6741 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache);
6742};
6743
6744
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00006745class CodeCacheHashTableShape : public BaseShape<HashTableKey*> {
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006746 public:
6747 static inline bool IsMatch(HashTableKey* key, Object* value) {
6748 return key->IsMatch(value);
6749 }
6750
6751 static inline uint32_t Hash(HashTableKey* key) {
6752 return key->Hash();
6753 }
6754
6755 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
6756 return key->HashForObject(object);
6757 }
6758
lrn@chromium.org303ada72010-10-27 09:33:13 +00006759 MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006760 return key->AsObject();
6761 }
6762
6763 static const int kPrefixSize = 0;
6764 static const int kEntrySize = 2;
6765};
6766
6767
6768class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape,
6769 HashTableKey*> {
6770 public:
6771 Object* Lookup(String* name, Code::Flags flags);
lrn@chromium.org303ada72010-10-27 09:33:13 +00006772 MUST_USE_RESULT MaybeObject* Put(String* name, Code* code);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +00006773
6774 int GetIndex(String* name, Code::Flags flags);
6775 void RemoveByIndex(int index);
6776
6777 static inline CodeCacheHashTable* cast(Object* obj);
6778
6779 // Initial size of the fixed array backing the hash table.
6780 static const int kInitialSize = 64;
6781
6782 private:
6783 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable);
6784};
6785
6786
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006787class PolymorphicCodeCache: public Struct {
6788 public:
6789 DECL_ACCESSORS(cache, Object)
6790
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006791 static void Update(Handle<PolymorphicCodeCache> cache,
6792 MapHandleList* maps,
6793 Code::Flags flags,
6794 Handle<Code> code);
6795
6796 MUST_USE_RESULT MaybeObject* Update(MapHandleList* maps,
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006797 Code::Flags flags,
6798 Code* code);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006799
6800 // Returns an undefined value if the entry is not found.
6801 Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags);
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006802
6803 static inline PolymorphicCodeCache* cast(Object* obj);
6804
6805#ifdef OBJECT_PRINT
6806 inline void PolymorphicCodeCachePrint() {
6807 PolymorphicCodeCachePrint(stdout);
6808 }
6809 void PolymorphicCodeCachePrint(FILE* out);
6810#endif
6811#ifdef DEBUG
6812 void PolymorphicCodeCacheVerify();
6813#endif
6814
6815 static const int kCacheOffset = HeapObject::kHeaderSize;
6816 static const int kSize = kCacheOffset + kPointerSize;
6817
6818 private:
6819 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache);
6820};
6821
6822
6823class PolymorphicCodeCacheHashTable
6824 : public HashTable<CodeCacheHashTableShape, HashTableKey*> {
6825 public:
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00006826 Object* Lookup(MapHandleList* maps, int code_kind);
6827
6828 MUST_USE_RESULT MaybeObject* Put(MapHandleList* maps,
6829 int code_kind,
6830 Code* code);
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00006831
6832 static inline PolymorphicCodeCacheHashTable* cast(Object* obj);
6833
6834 static const int kInitialSize = 64;
6835 private:
6836 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable);
6837};
6838
6839
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00006840class TypeFeedbackInfo: public Struct {
6841 public:
6842 inline int ic_total_count();
6843 inline void set_ic_total_count(int count);
6844
jkummerow@chromium.org1456e702012-03-30 08:38:13 +00006845 inline int ic_with_type_info_count();
6846 inline void set_ic_with_type_info_count(int count);
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00006847
6848 DECL_ACCESSORS(type_feedback_cells, TypeFeedbackCells)
6849
6850 static inline TypeFeedbackInfo* cast(Object* obj);
6851
6852#ifdef OBJECT_PRINT
6853 inline void TypeFeedbackInfoPrint() {
6854 TypeFeedbackInfoPrint(stdout);
6855 }
6856 void TypeFeedbackInfoPrint(FILE* out);
6857#endif
6858#ifdef DEBUG
6859 void TypeFeedbackInfoVerify();
6860#endif
6861
6862 static const int kIcTotalCountOffset = HeapObject::kHeaderSize;
6863 static const int kIcWithTypeinfoCountOffset =
6864 kIcTotalCountOffset + kPointerSize;
6865 static const int kTypeFeedbackCellsOffset =
6866 kIcWithTypeinfoCountOffset + kPointerSize;
6867 static const int kSize = kTypeFeedbackCellsOffset + kPointerSize;
6868
6869 private:
6870 DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo);
6871};
6872
6873
yangguo@chromium.orgab30bb82012-02-24 14:41:46 +00006874// Representation of a slow alias as part of a non-strict arguments objects.
6875// For fast aliases (if HasNonStrictArgumentsElements()):
6876// - the parameter map contains an index into the context
6877// - all attributes of the element have default values
6878// For slow aliases (if HasDictionaryArgumentsElements()):
6879// - the parameter map contains no fast alias mapping (i.e. the hole)
6880// - this struct (in the slow backing store) contains an index into the context
6881// - all attributes are available as part if the property details
6882class AliasedArgumentsEntry: public Struct {
6883 public:
6884 inline int aliased_context_slot();
6885 inline void set_aliased_context_slot(int count);
6886
6887 static inline AliasedArgumentsEntry* cast(Object* obj);
6888
6889#ifdef OBJECT_PRINT
6890 inline void AliasedArgumentsEntryPrint() {
6891 AliasedArgumentsEntryPrint(stdout);
6892 }
6893 void AliasedArgumentsEntryPrint(FILE* out);
6894#endif
6895#ifdef DEBUG
6896 void AliasedArgumentsEntryVerify();
6897#endif
6898
6899 static const int kAliasedContextSlot = HeapObject::kHeaderSize;
6900 static const int kSize = kAliasedContextSlot + kPointerSize;
6901
6902 private:
6903 DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry);
6904};
6905
6906
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00006907enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS};
6908enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL};
6909
6910
ager@chromium.org7c537e22008-10-16 08:43:32 +00006911class StringHasher {
6912 public:
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00006913 explicit inline StringHasher(int length, uint32_t seed);
ager@chromium.org7c537e22008-10-16 08:43:32 +00006914
6915 // Returns true if the hash of this string can be computed without
6916 // looking at the contents.
6917 inline bool has_trivial_hash();
6918
6919 // Add a character to the hash and update the array index calculation.
yangguo@chromium.org154ff992012-03-13 08:09:54 +00006920 inline void AddCharacter(uint32_t c);
ager@chromium.org7c537e22008-10-16 08:43:32 +00006921
6922 // Adds a character to the hash but does not update the array index
6923 // calculation. This can only be called when it has been verified
6924 // that the input is not an array index.
yangguo@chromium.org154ff992012-03-13 08:09:54 +00006925 inline void AddCharacterNoIndex(uint32_t c);
6926
6927 // Add a character above 0xffff as a surrogate pair. These can get into
6928 // the hasher through the routines that take a UTF-8 string and make a symbol.
6929 void AddSurrogatePair(uc32 c);
6930 void AddSurrogatePairNoIndex(uc32 c);
ager@chromium.org7c537e22008-10-16 08:43:32 +00006931
6932 // Returns the value to store in the hash field of a string with
6933 // the given length and contents.
6934 uint32_t GetHashField();
6935
6936 // Returns true if the characters seen so far make up a legal array
6937 // index.
6938 bool is_array_index() { return is_array_index_; }
6939
6940 bool is_valid() { return is_valid_; }
6941
6942 void invalidate() { is_valid_ = false; }
6943
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00006944 // Calculated hash value for a string consisting of 1 to
6945 // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
6946 // value is represented decimal value.
ager@chromium.org5b2fbee2010-09-08 06:38:15 +00006947 static uint32_t MakeArrayIndexHash(uint32_t value, int length);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +00006948
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00006949 // No string is allowed to have a hash of zero. That value is reserved
6950 // for internal properties. If the hash calculation yields zero then we
6951 // use 27 instead.
6952 static const int kZeroHash = 27;
6953
ager@chromium.org7c537e22008-10-16 08:43:32 +00006954 private:
ager@chromium.org7c537e22008-10-16 08:43:32 +00006955 uint32_t array_index() {
6956 ASSERT(is_array_index());
6957 return array_index_;
6958 }
6959
6960 inline uint32_t GetHash();
6961
6962 int length_;
6963 uint32_t raw_running_hash_;
6964 uint32_t array_index_;
6965 bool is_array_index_;
6966 bool is_first_char_;
6967 bool is_valid_;
ager@chromium.org6141cbe2009-11-20 12:14:52 +00006968 friend class TwoCharHashTableKey;
ager@chromium.org7c537e22008-10-16 08:43:32 +00006969};
6970
6971
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00006972// Calculates string hash.
6973template <typename schar>
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00006974inline uint32_t HashSequentialString(const schar* chars,
6975 int length,
6976 uint32_t seed);
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00006977
6978
ager@chromium.org870a0b62008-11-04 11:43:05 +00006979// The characteristics of a string are stored in its map. Retrieving these
6980// few bits of information is moderately expensive, involving two memory
6981// loads where the second is dependent on the first. To improve efficiency
6982// the shape of the string is given its own class so that it can be retrieved
6983// once and used for several string operations. A StringShape is small enough
6984// to be passed by value and is immutable, but be aware that flattening a
ager@chromium.orgc3e50d82008-11-05 11:53:10 +00006985// string can potentially alter its shape. Also be aware that a GC caused by
6986// something else can alter the shape of a string due to ConsString
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00006987// shortcutting. Keeping these restrictions in mind has proven to be error-
6988// prone and so we no longer put StringShapes in variables unless there is a
6989// concrete performance benefit at that particular point in the code.
ager@chromium.org870a0b62008-11-04 11:43:05 +00006990class StringShape BASE_EMBEDDED {
6991 public:
6992 inline explicit StringShape(String* s);
6993 inline explicit StringShape(Map* s);
6994 inline explicit StringShape(InstanceType t);
ager@chromium.org870a0b62008-11-04 11:43:05 +00006995 inline bool IsSequential();
6996 inline bool IsExternal();
6997 inline bool IsCons();
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00006998 inline bool IsSliced();
6999 inline bool IsIndirect();
ager@chromium.org870a0b62008-11-04 11:43:05 +00007000 inline bool IsExternalAscii();
7001 inline bool IsExternalTwoByte();
7002 inline bool IsSequentialAscii();
7003 inline bool IsSequentialTwoByte();
7004 inline bool IsSymbol();
7005 inline StringRepresentationTag representation_tag();
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00007006 inline uint32_t encoding_tag();
ager@chromium.org870a0b62008-11-04 11:43:05 +00007007 inline uint32_t full_representation_tag();
7008 inline uint32_t size_tag();
7009#ifdef DEBUG
7010 inline uint32_t type() { return type_; }
7011 inline void invalidate() { valid_ = false; }
7012 inline bool valid() { return valid_; }
7013#else
7014 inline void invalidate() { }
7015#endif
jkummerow@chromium.orge297f592011-06-08 10:05:15 +00007016
ager@chromium.org870a0b62008-11-04 11:43:05 +00007017 private:
7018 uint32_t type_;
7019#ifdef DEBUG
7020 inline void set_valid() { valid_ = true; }
7021 bool valid_;
7022#else
7023 inline void set_valid() { }
7024#endif
7025};
7026
7027
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007028// The String abstract class captures JavaScript string values:
7029//
7030// Ecma-262:
7031// 4.3.16 String Value
7032// A string value is a member of the type String and is a finite
7033// ordered sequence of zero or more 16-bit unsigned integer values.
7034//
7035// All string values have a length field.
7036class String: public HeapObject {
7037 public:
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00007038 // Representation of the flat content of a String.
7039 // A non-flat string doesn't have flat content.
7040 // A flat string has content that's encoded as a sequence of either
7041 // ASCII chars or two-byte UC16.
7042 // Returned by String::GetFlatContent().
7043 class FlatContent {
7044 public:
7045 // Returns true if the string is flat and this structure contains content.
7046 bool IsFlat() { return state_ != NON_FLAT; }
7047 // Returns true if the structure contains ASCII content.
7048 bool IsAscii() { return state_ == ASCII; }
7049 // Returns true if the structure contains two-byte content.
7050 bool IsTwoByte() { return state_ == TWO_BYTE; }
7051
7052 // Return the ASCII content of the string. Only use if IsAscii() returns
7053 // true.
7054 Vector<const char> ToAsciiVector() {
7055 ASSERT_EQ(ASCII, state_);
7056 return Vector<const char>::cast(buffer_);
7057 }
7058 // Return the two-byte content of the string. Only use if IsTwoByte()
7059 // returns true.
7060 Vector<const uc16> ToUC16Vector() {
7061 ASSERT_EQ(TWO_BYTE, state_);
7062 return Vector<const uc16>::cast(buffer_);
7063 }
7064
7065 private:
7066 enum State { NON_FLAT, ASCII, TWO_BYTE };
7067
7068 // Constructors only used by String::GetFlatContent().
7069 explicit FlatContent(Vector<const char> chars)
7070 : buffer_(Vector<const byte>::cast(chars)),
7071 state_(ASCII) { }
7072 explicit FlatContent(Vector<const uc16> chars)
7073 : buffer_(Vector<const byte>::cast(chars)),
7074 state_(TWO_BYTE) { }
7075 FlatContent() : buffer_(), state_(NON_FLAT) { }
7076
7077 Vector<const byte> buffer_;
7078 State state_;
7079
7080 friend class String;
7081 };
7082
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007083 // Get and set the length of the string.
7084 inline int length();
7085 inline void set_length(int value);
7086
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007087 // Get and set the hash field of the string.
7088 inline uint32_t hash_field();
7089 inline void set_hash_field(uint32_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007090
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00007091 // Returns whether this string has only ASCII chars, i.e. all of them can
7092 // be ASCII encoded. This might be the case even if the string is
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +00007093 // two-byte. Such strings may appear when the embedder prefers
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00007094 // two-byte external representations even for ASCII data.
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007095 inline bool IsAsciiRepresentation();
7096 inline bool IsTwoByteRepresentation();
7097
7098 // Cons and slices have an encoding flag that may not represent the actual
7099 // encoding of the underlying string. This is taken into account here.
7100 // Requires: this->IsFlat()
7101 inline bool IsAsciiRepresentationUnderneath();
7102 inline bool IsTwoByteRepresentationUnderneath();
7103
ricow@chromium.org5ad5ace2010-06-23 09:06:43 +00007104 // NOTE: this should be considered only a hint. False negatives are
7105 // possible.
7106 inline bool HasOnlyAsciiChars();
ricow@chromium.orgaa1b6162010-03-29 07:44:58 +00007107
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007108 // Get and set individual two byte chars in the string.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007109 inline void Set(int index, uint16_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007110 // Get individual two byte char in the string. Repeated calls
7111 // to this method are not efficient unless the string is flat.
jkummerow@chromium.org212d9642012-05-11 15:02:09 +00007112 INLINE(uint16_t Get(int index));
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007113
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00007114 // Try to flatten the string. Checks first inline to see if it is
7115 // necessary. Does nothing if the string is not a cons string.
7116 // Flattening allocates a sequential string with the same data as
7117 // the given string and mutates the cons string to a degenerate
7118 // form, where the first component is the new sequential string and
7119 // the second component is the empty string. If allocation fails,
7120 // this function returns a failure. If flattening succeeds, this
7121 // function returns the sequential string that is now the first
7122 // component of the cons string.
7123 //
7124 // Degenerate cons strings are handled specially by the garbage
7125 // collector (see IsShortcutCandidate).
7126 //
7127 // Use FlattenString from Handles.cc to flatten even in case an
7128 // allocation failure happens.
lrn@chromium.org303ada72010-10-27 09:33:13 +00007129 inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007130
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00007131 // Convenience function. Has exactly the same behavior as
7132 // TryFlatten(), except in the case of failure returns the original
7133 // string.
7134 inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED);
7135
ricow@chromium.orgddd545c2011-08-24 12:02:41 +00007136 // Tries to return the content of a flat string as a structure holding either
7137 // a flat vector of char or of uc16.
7138 // If the string isn't flat, and therefore doesn't have flat content, the
7139 // returned structure will report so, and can't provide a vector of either
7140 // kind.
7141 FlatContent GetFlatContent();
ager@chromium.org7c537e22008-10-16 08:43:32 +00007142
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007143 // Returns the parent of a sliced string or first part of a flat cons string.
7144 // Requires: StringShape(this).IsIndirect() && this->IsFlat()
7145 inline String* GetUnderlying();
7146
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007147 // Mark the string as an undetectable object. It only applies to
ulan@chromium.org2efb9002012-01-19 15:36:35 +00007148 // ASCII and two byte string types.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007149 bool MarkAsUndetectable();
7150
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007151 // Return a substring.
lrn@chromium.org303ada72010-10-27 09:33:13 +00007152 MUST_USE_RESULT MaybeObject* SubString(int from,
7153 int to,
7154 PretenureFlag pretenure = NOT_TENURED);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007155
7156 // String equality operations.
7157 inline bool Equals(String* other);
7158 bool IsEqualTo(Vector<const char> str);
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00007159 bool IsAsciiEqualTo(Vector<const char> str);
7160 bool IsTwoByteEqualTo(Vector<const uc16> str);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007161
7162 // Return a UTF8 representation of the string. The string is null
7163 // terminated but may optionally contain nulls. Length is returned
7164 // in length_output if length_output is not a null pointer The string
7165 // should be nearly flat, otherwise the performance of this method may
7166 // be very slow (quadratic in the length). Setting robustness_flag to
7167 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
7168 // handles unexpected data without causing assert failures and it does not
7169 // do any heap allocations. This is useful when printing stack traces.
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00007170 SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls,
7171 RobustnessFlag robustness_flag,
7172 int offset,
7173 int length,
7174 int* length_output = 0);
7175 SmartArrayPointer<char> ToCString(
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007176 AllowNullsFlag allow_nulls = DISALLOW_NULLS,
7177 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL,
7178 int* length_output = 0);
7179
7180 // Return a 16 bit Unicode representation of the string.
7181 // The string should be nearly flat, otherwise the performance of
7182 // of this method may be very bad. Setting robustness_flag to
7183 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
7184 // handles unexpected data without causing assert failures and it does not
7185 // do any heap allocations. This is useful when printing stack traces.
kmillikin@chromium.org83e16822011-09-13 08:21:47 +00007186 SmartArrayPointer<uc16> ToWideCString(
kasperl@chromium.orgb9123622008-09-17 14:05:56 +00007187 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007188
7189 // Tells whether the hash code has been computed.
7190 inline bool HasHashCode();
7191
7192 // Returns a hash value used for the property table
7193 inline uint32_t Hash();
7194
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007195 static uint32_t ComputeHashField(unibrow::CharacterStream* buffer,
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00007196 int length,
7197 uint32_t seed);
ager@chromium.org7c537e22008-10-16 08:43:32 +00007198
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007199 static bool ComputeArrayIndex(unibrow::CharacterStream* buffer,
7200 uint32_t* index,
7201 int length);
7202
ager@chromium.org6f10e412009-02-13 10:11:16 +00007203 // Externalization.
7204 bool MakeExternal(v8::String::ExternalStringResource* resource);
7205 bool MakeExternal(v8::String::ExternalAsciiStringResource* resource);
7206
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007207 // Conversion.
7208 inline bool AsArrayIndex(uint32_t* index);
7209
7210 // Casting.
7211 static inline String* cast(Object* obj);
7212
7213 void PrintOn(FILE* out);
7214
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007215 // For use during stack traces. Performs rudimentary sanity check.
7216 bool LooksValid();
7217
7218 // Dispatched behavior.
7219 void StringShortPrint(StringStream* accumulator);
whesse@chromium.org023421e2010-12-21 12:19:12 +00007220#ifdef OBJECT_PRINT
7221 inline void StringPrint() {
7222 StringPrint(stdout);
7223 }
7224 void StringPrint(FILE* out);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00007225
7226 char* ToAsciiArray();
whesse@chromium.org023421e2010-12-21 12:19:12 +00007227#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007228#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007229 void StringVerify();
7230#endif
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007231 inline bool IsFlat();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007232
7233 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00007234 static const int kLengthOffset = HeapObject::kHeaderSize;
ager@chromium.orgac091b72010-05-05 07:34:42 +00007235 static const int kHashFieldOffset = kLengthOffset + kPointerSize;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007236 static const int kSize = kHashFieldOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007237
ager@chromium.org3811b432009-10-28 14:53:37 +00007238 // Maximum number of characters to consider when trying to convert a string
7239 // value into an array index.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007240 static const int kMaxArrayIndexSize = 10;
7241
ulan@chromium.org2efb9002012-01-19 15:36:35 +00007242 // Max ASCII char code.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007243 static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar;
ager@chromium.org381abbb2009-02-25 13:23:22 +00007244 static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar;
yangguo@chromium.org154ff992012-03-13 08:09:54 +00007245 static const int kMaxUtf16CodeUnit = 0xffff;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007246
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007247 // Mask constant for checking if a string has a computed hash code
7248 // and if it is an array index. The least significant bit indicates
7249 // whether a hash code has been computed. If the hash code has been
7250 // computed the 2nd bit tells whether the string can be used as an
7251 // array index.
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007252 static const int kHashNotComputedMask = 1;
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007253 static const int kIsNotArrayIndexMask = 1 << 1;
7254 static const int kNofHashBitFields = 2;
ager@chromium.org7c537e22008-10-16 08:43:32 +00007255
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007256 // Shift constant retrieving hash code from hash field.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007257 static const int kHashShift = kNofHashBitFields;
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007258
rossberg@chromium.orgfab14982012-01-05 15:02:15 +00007259 // Only these bits are relevant in the hash, since the top two are shifted
7260 // out.
7261 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift;
7262
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007263 // Array index strings this short can keep their index in the hash
7264 // field.
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00007265 static const int kMaxCachedArrayIndexLength = 7;
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007266
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007267 // For strings which are array indexes the hash value has the string length
7268 // mixed into the hash, mainly to avoid a hash value of zero which would be
7269 // the case for the string '0'. 24 bits are used for the array index value.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007270 static const int kArrayIndexValueBits = 24;
7271 static const int kArrayIndexLengthBits =
7272 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
7273
7274 STATIC_CHECK((kArrayIndexLengthBits > 0));
ager@chromium.org5b2fbee2010-09-08 06:38:15 +00007275 STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007276
7277 static const int kArrayIndexHashLengthShift =
7278 kArrayIndexValueBits + kNofHashBitFields;
7279
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007280 static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1;
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007281
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007282 static const int kArrayIndexValueMask =
7283 ((1 << kArrayIndexValueBits) - 1) << kHashShift;
ager@chromium.org3811b432009-10-28 14:53:37 +00007284
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007285 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
7286 // could use a mask to test if the length of string is less than or equal to
7287 // kMaxCachedArrayIndexLength.
7288 STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
7289
7290 static const int kContainsCachedArrayIndexMask =
7291 (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) |
7292 kIsNotArrayIndexMask;
7293
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007294 // Value of empty hash field indicating that the hash is not computed.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007295 static const int kEmptyHashField =
7296 kIsNotArrayIndexMask | kHashNotComputedMask;
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007297
7298 // Value of hash field containing computed hash equal to zero.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +00007299 static const int kZeroHash = kIsNotArrayIndexMask;
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +00007300
7301 // Maximal string length.
7302 static const int kMaxLength = (1 << (32 - 2)) - 1;
7303
7304 // Max length for computing hash. For strings longer than this limit the
7305 // string length is used as the hash value.
7306 static const int kMaxHashCalcLength = 16383;
ager@chromium.org7c537e22008-10-16 08:43:32 +00007307
kasper.lund7276f142008-07-30 08:49:36 +00007308 // Limit for truncation in short printing.
7309 static const int kMaxShortPrintLength = 1024;
7310
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007311 // Support for regular expressions.
7312 const uc16* GetTwoByteData();
7313 const uc16* GetTwoByteData(unsigned start);
7314
7315 // Support for StringInputBuffer
7316 static const unibrow::byte* ReadBlock(String* input,
7317 unibrow::byte* util_buffer,
7318 unsigned capacity,
7319 unsigned* remaining,
7320 unsigned* offset);
7321 static const unibrow::byte* ReadBlock(String** input,
7322 unibrow::byte* util_buffer,
7323 unsigned capacity,
7324 unsigned* remaining,
7325 unsigned* offset);
7326
7327 // Helper function for flattening strings.
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007328 template <typename sinkchar>
7329 static void WriteToFlat(String* source,
7330 sinkchar* sink,
7331 int from,
7332 int to);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007333
fschneider@chromium.org9e3e0b62011-01-03 10:16:46 +00007334 static inline bool IsAscii(const char* chars, int length) {
7335 const char* limit = chars + length;
7336#ifdef V8_HOST_CAN_READ_UNALIGNED
7337 ASSERT(kMaxAsciiCharCode == 0x7F);
7338 const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80;
7339 while (chars <= limit - sizeof(uintptr_t)) {
7340 if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
7341 return false;
7342 }
7343 chars += sizeof(uintptr_t);
7344 }
7345#endif
7346 while (chars < limit) {
7347 if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false;
7348 ++chars;
7349 }
7350 return true;
7351 }
7352
7353 static inline bool IsAscii(const uc16* chars, int length) {
7354 const uc16* limit = chars + length;
7355 while (chars < limit) {
7356 if (*chars > kMaxAsciiCharCodeU) return false;
7357 ++chars;
7358 }
7359 return true;
7360 }
7361
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007362 protected:
7363 class ReadBlockBuffer {
7364 public:
7365 ReadBlockBuffer(unibrow::byte* util_buffer_,
7366 unsigned cursor_,
7367 unsigned capacity_,
7368 unsigned remaining_) :
7369 util_buffer(util_buffer_),
7370 cursor(cursor_),
7371 capacity(capacity_),
7372 remaining(remaining_) {
7373 }
7374 unibrow::byte* util_buffer;
7375 unsigned cursor;
7376 unsigned capacity;
7377 unsigned remaining;
7378 };
7379
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007380 static inline const unibrow::byte* ReadBlock(String* input,
7381 ReadBlockBuffer* buffer,
7382 unsigned* offset,
7383 unsigned max_chars);
7384 static void ReadBlockIntoBuffer(String* input,
7385 ReadBlockBuffer* buffer,
7386 unsigned* offset_ptr,
7387 unsigned max_chars);
7388
7389 private:
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00007390 // Try to flatten the top level ConsString that is hiding behind this
7391 // string. This is a no-op unless the string is a ConsString. Flatten
7392 // mutates the ConsString and might return a failure.
lrn@chromium.org303ada72010-10-27 09:33:13 +00007393 MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00007394
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007395 static inline bool IsHashFieldComputed(uint32_t field);
7396
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007397 // Slow case of String::Equals. This implementation works on any strings
7398 // but it is most efficient on strings that are almost flat.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007399 bool SlowEquals(String* other);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007400
7401 // Slow case of AsArrayIndex.
7402 bool SlowAsArrayIndex(uint32_t* index);
7403
7404 // Compute and set the hash code.
7405 uint32_t ComputeAndSetHash();
7406
7407 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
7408};
7409
7410
7411// The SeqString abstract class captures sequential string values.
7412class SeqString: public String {
7413 public:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007414 // Casting.
7415 static inline SeqString* cast(Object* obj);
7416
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007417 // Layout description.
7418 static const int kHeaderSize = String::kSize;
7419
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007420 private:
7421 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
7422};
7423
7424
ulan@chromium.org2efb9002012-01-19 15:36:35 +00007425// The AsciiString class captures sequential ASCII string objects.
7426// Each character in the AsciiString is an ASCII character.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007427class SeqAsciiString: public SeqString {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007428 public:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00007429 static const bool kHasAsciiEncoding = true;
7430
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007431 // Dispatched behavior.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007432 inline uint16_t SeqAsciiStringGet(int index);
7433 inline void SeqAsciiStringSet(int index, uint16_t value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007434
7435 // Get the address of the characters in this string.
7436 inline Address GetCharsAddress();
7437
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007438 inline char* GetChars();
7439
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007440 // Casting
ager@chromium.org7c537e22008-10-16 08:43:32 +00007441 static inline SeqAsciiString* cast(Object* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007442
7443 // Garbage collection support. This method is called by the
7444 // garbage collector to compute the actual size of an AsciiString
7445 // instance.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007446 inline int SeqAsciiStringSize(InstanceType instance_type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007447
7448 // Computes the size for an AsciiString instance of a given length.
7449 static int SizeFor(int length) {
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007450 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007451 }
7452
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00007453 // Maximal memory usage for a single sequential ASCII string.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007454 static const int kMaxSize = 512 * MB - 1;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00007455 // Maximal length of a single sequential ASCII string.
7456 // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7457 static const int kMaxLength = (kMaxSize - kHeaderSize);
7458
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007459 // Support for StringInputBuffer.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007460 inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7461 unsigned* offset,
7462 unsigned chars);
7463 inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining,
7464 unsigned* offset,
7465 unsigned chars);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007466
mstarzinger@chromium.org15613d02012-05-23 12:04:37 +00007467#ifdef DEBUG
7468 void SeqAsciiStringVerify();
7469#endif
7470
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007471 private:
ager@chromium.org7c537e22008-10-16 08:43:32 +00007472 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007473};
7474
7475
7476// The TwoByteString class captures sequential unicode string objects.
7477// Each character in the TwoByteString is a two-byte uint16_t.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007478class SeqTwoByteString: public SeqString {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007479 public:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00007480 static const bool kHasAsciiEncoding = false;
7481
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007482 // Dispatched behavior.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007483 inline uint16_t SeqTwoByteStringGet(int index);
7484 inline void SeqTwoByteStringSet(int index, uint16_t value);
7485
7486 // Get the address of the characters in this string.
7487 inline Address GetCharsAddress();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007488
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007489 inline uc16* GetChars();
7490
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007491 // For regexp code.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007492 const uint16_t* SeqTwoByteStringGetData(unsigned start);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007493
7494 // Casting
ager@chromium.org7c537e22008-10-16 08:43:32 +00007495 static inline SeqTwoByteString* cast(Object* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007496
7497 // Garbage collection support. This method is called by the
7498 // garbage collector to compute the actual size of a TwoByteString
7499 // instance.
ager@chromium.orgbb29dc92009-03-24 13:25:23 +00007500 inline int SeqTwoByteStringSize(InstanceType instance_type);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007501
7502 // Computes the size for a TwoByteString instance of a given length.
7503 static int SizeFor(int length) {
ricow@chromium.org30ce4112010-05-31 10:38:25 +00007504 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007505 }
7506
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00007507 // Maximal memory usage for a single sequential two-byte string.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007508 static const int kMaxSize = 512 * MB - 1;
fschneider@chromium.org0c20e672010-01-14 15:28:53 +00007509 // Maximal length of a single sequential two-byte string.
7510 // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
7511 static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t);
7512
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007513 // Support for StringInputBuffer.
ager@chromium.org7c537e22008-10-16 08:43:32 +00007514 inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7515 unsigned* offset_ptr,
7516 unsigned chars);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007517
7518 private:
ager@chromium.org7c537e22008-10-16 08:43:32 +00007519 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007520};
7521
7522
7523// The ConsString class describes string values built by using the
7524// addition operator on strings. A ConsString is a pair where the
7525// first and second components are pointers to other string values.
7526// One or both components of a ConsString can be pointers to other
7527// ConsStrings, creating a binary tree of ConsStrings where the leaves
7528// are non-ConsString string values. The string value represented by
7529// a ConsString can be obtained by concatenating the leaf string
7530// values in a left-to-right depth-first traversal of the tree.
7531class ConsString: public String {
7532 public:
ager@chromium.org870a0b62008-11-04 11:43:05 +00007533 // First string of the cons cell.
7534 inline String* first();
7535 // Doesn't check that the result is a string, even in debug mode. This is
7536 // useful during GC where the mark bits confuse the checks.
7537 inline Object* unchecked_first();
7538 inline void set_first(String* first,
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00007539 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007540
ager@chromium.org870a0b62008-11-04 11:43:05 +00007541 // Second string of the cons cell.
7542 inline String* second();
7543 // Doesn't check that the result is a string, even in debug mode. This is
7544 // useful during GC where the mark bits confuse the checks.
7545 inline Object* unchecked_second();
7546 inline void set_second(String* second,
kasperl@chromium.org9fe21c62008-10-28 08:53:51 +00007547 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007548
7549 // Dispatched behavior.
7550 uint16_t ConsStringGet(int index);
7551
7552 // Casting.
7553 static inline ConsString* cast(Object* obj);
7554
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007555 // Layout description.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00007556 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007557 static const int kSecondOffset = kFirstOffset + kPointerSize;
7558 static const int kSize = kSecondOffset + kPointerSize;
7559
7560 // Support for StringInputBuffer.
7561 inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer,
7562 unsigned* offset_ptr,
7563 unsigned chars);
7564 inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7565 unsigned* offset_ptr,
7566 unsigned chars);
7567
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +00007568 // Minimum length for a cons string.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007569 static const int kMinLength = 13;
7570
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007571 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
7572 BodyDescriptor;
7573
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007574#ifdef DEBUG
7575 void ConsStringVerify();
7576#endif
7577
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007578 private:
7579 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
7580};
7581
7582
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007583// The Sliced String class describes strings that are substrings of another
7584// sequential string. The motivation is to save time and memory when creating
7585// a substring. A Sliced String is described as a pointer to the parent,
7586// the offset from the start of the parent string and the length. Using
7587// a Sliced String therefore requires unpacking of the parent string and
7588// adding the offset to the start address. A substring of a Sliced String
7589// are not nested since the double indirection is simplified when creating
7590// such a substring.
7591// Currently missing features are:
7592// - handling externalized parent strings
7593// - external strings as parent
7594// - truncating sliced string to enable otherwise unneeded parent to be GC'ed.
7595class SlicedString: public String {
7596 public:
ricow@chromium.org4668a2c2011-08-29 10:41:00 +00007597 inline String* parent();
7598 inline void set_parent(String* parent);
7599 inline int offset();
7600 inline void set_offset(int offset);
7601
7602 // Dispatched behavior.
7603 uint16_t SlicedStringGet(int index);
7604
7605 // Casting.
7606 static inline SlicedString* cast(Object* obj);
7607
7608 // Layout description.
7609 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
7610 static const int kOffsetOffset = kParentOffset + kPointerSize;
7611 static const int kSize = kOffsetOffset + kPointerSize;
7612
7613 // Support for StringInputBuffer
7614 inline const unibrow::byte* SlicedStringReadBlock(ReadBlockBuffer* buffer,
7615 unsigned* offset_ptr,
7616 unsigned chars);
7617 inline void SlicedStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7618 unsigned* offset_ptr,
7619 unsigned chars);
7620 // Minimum length for a sliced string.
7621 static const int kMinLength = 13;
7622
7623 typedef FixedBodyDescriptor<kParentOffset,
7624 kOffsetOffset + kPointerSize, kSize>
7625 BodyDescriptor;
7626
7627#ifdef DEBUG
7628 void SlicedStringVerify();
7629#endif
7630
7631 private:
7632 DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString);
7633};
7634
7635
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007636// The ExternalString class describes string values that are backed by
7637// a string resource that lies outside the V8 heap. ExternalStrings
7638// consist of the length field common to all strings, a pointer to the
7639// external resource. It is important to ensure (externally) that the
7640// resource is not deallocated while the ExternalString is live in the
7641// V8 heap.
7642//
7643// The API expects that all ExternalStrings are created through the
7644// API. Therefore, ExternalStrings should not be used internally.
7645class ExternalString: public String {
7646 public:
7647 // Casting
7648 static inline ExternalString* cast(Object* obj);
7649
7650 // Layout description.
kasperl@chromium.org71affb52009-05-26 05:44:31 +00007651 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00007652 static const int kShortSize = kResourceOffset + kPointerSize;
erikcorry0ad885c2011-11-21 13:51:57 +00007653 static const int kResourceDataOffset = kResourceOffset + kPointerSize;
7654 static const int kSize = kResourceDataOffset + kPointerSize;
7655
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00007656 // Return whether external string is short (data pointer is not cached).
7657 inline bool is_short();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007658
ager@chromium.org18ad94b2009-09-02 08:22:29 +00007659 STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset);
7660
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007661 private:
7662 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
7663};
7664
7665
7666// The ExternalAsciiString class is an external string backed by an
7667// ASCII string.
7668class ExternalAsciiString: public ExternalString {
7669 public:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00007670 static const bool kHasAsciiEncoding = true;
7671
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007672 typedef v8::String::ExternalAsciiStringResource Resource;
7673
7674 // The underlying resource.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007675 inline const Resource* resource();
7676 inline void set_resource(const Resource* buffer);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007677
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00007678 // Update the pointer cache to the external character array.
7679 // The cached pointer is always valid, as the external character array does =
7680 // not move during lifetime. Deserialization is the only exception, after
7681 // which the pointer cache has to be refreshed.
7682 inline void update_data_cache();
7683
erikcorry0ad885c2011-11-21 13:51:57 +00007684 inline const char* GetChars();
7685
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007686 // Dispatched behavior.
erikcorry0ad885c2011-11-21 13:51:57 +00007687 inline uint16_t ExternalAsciiStringGet(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007688
7689 // Casting.
7690 static inline ExternalAsciiString* cast(Object* obj);
7691
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007692 // Garbage collection support.
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007693 inline void ExternalAsciiStringIterateBody(ObjectVisitor* v);
7694
7695 template<typename StaticVisitor>
7696 inline void ExternalAsciiStringIterateBody();
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007697
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007698 // Support for StringInputBuffer.
7699 const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining,
7700 unsigned* offset,
7701 unsigned chars);
7702 inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7703 unsigned* offset,
7704 unsigned chars);
7705
7706 private:
7707 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString);
7708};
7709
7710
7711// The ExternalTwoByteString class is an external string backed by a UTF-16
7712// encoded string.
7713class ExternalTwoByteString: public ExternalString {
7714 public:
erik.corry@gmail.com4a2e25e2010-07-07 12:22:46 +00007715 static const bool kHasAsciiEncoding = false;
7716
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007717 typedef v8::String::ExternalStringResource Resource;
7718
7719 // The underlying string resource.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007720 inline const Resource* resource();
7721 inline void set_resource(const Resource* buffer);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007722
mstarzinger@chromium.org1b3afd12011-11-29 14:28:56 +00007723 // Update the pointer cache to the external character array.
7724 // The cached pointer is always valid, as the external character array does =
7725 // not move during lifetime. Deserialization is the only exception, after
7726 // which the pointer cache has to be refreshed.
7727 inline void update_data_cache();
7728
erikcorry0ad885c2011-11-21 13:51:57 +00007729 inline const uint16_t* GetChars();
7730
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007731 // Dispatched behavior.
erikcorry0ad885c2011-11-21 13:51:57 +00007732 inline uint16_t ExternalTwoByteStringGet(int index);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007733
7734 // For regexp code.
erikcorry0ad885c2011-11-21 13:51:57 +00007735 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007736
7737 // Casting.
7738 static inline ExternalTwoByteString* cast(Object* obj);
7739
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007740 // Garbage collection support.
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007741 inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v);
7742
7743 template<typename StaticVisitor>
7744 inline void ExternalTwoByteStringIterateBody();
7745
ager@chromium.orgc4c92722009-11-18 14:12:51 +00007746
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007747 // Support for StringInputBuffer.
7748 void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
7749 unsigned* offset_ptr,
7750 unsigned chars);
7751
7752 private:
7753 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString);
7754};
7755
7756
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007757// Utility superclass for stack-allocated objects that must be updated
7758// on gc. It provides two ways for the gc to update instances, either
7759// iterating or updating after gc.
7760class Relocatable BASE_EMBEDDED {
7761 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007762 explicit inline Relocatable(Isolate* isolate);
7763 inline virtual ~Relocatable();
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007764 virtual void IterateInstance(ObjectVisitor* v) { }
7765 virtual void PostGarbageCollection() { }
7766
7767 static void PostGarbageCollectionProcessing();
7768 static int ArchiveSpacePerThread();
lrn@chromium.org1c092762011-05-09 09:42:16 +00007769 static char* ArchiveState(Isolate* isolate, char* to);
7770 static char* RestoreState(Isolate* isolate, char* from);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007771 static void Iterate(ObjectVisitor* v);
7772 static void Iterate(ObjectVisitor* v, Relocatable* top);
7773 static char* Iterate(ObjectVisitor* v, char* t);
7774 private:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007775 Isolate* isolate_;
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007776 Relocatable* prev_;
7777};
7778
7779
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007780// A flat string reader provides random access to the contents of a
7781// string independent of the character width of the string. The handle
7782// must be valid as long as the reader is being used.
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007783class FlatStringReader : public Relocatable {
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007784 public:
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007785 FlatStringReader(Isolate* isolate, Handle<String> str);
7786 FlatStringReader(Isolate* isolate, Vector<const char> input);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00007787 void PostGarbageCollection();
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007788 inline uc32 Get(int index);
7789 int length() { return length_; }
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007790 private:
7791 String** str_;
7792 bool is_ascii_;
7793 int length_;
7794 const void* start_;
ager@chromium.orga74f0da2008-12-03 16:05:52 +00007795};
7796
7797
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007798// Note that StringInputBuffers are not valid across a GC! To fix this
7799// it would have to store a String Handle instead of a String* and
7800// AsciiStringReadBlock would have to be modified to use memcpy.
7801//
7802// StringInputBuffer is able to traverse any string regardless of how
7803// deeply nested a sequence of ConsStrings it is made of. However,
7804// performance will be better if deep strings are flattened before they
7805// are traversed. Since flattening requires memory allocation this is
7806// not always desirable, however (esp. in debugging situations).
7807class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> {
7808 public:
7809 virtual void Seek(unsigned pos);
7810 inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {}
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00007811 explicit inline StringInputBuffer(String* backing):
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007812 unibrow::InputBuffer<String, String*, 1024>(backing) {}
7813};
7814
7815
7816class SafeStringInputBuffer
7817 : public unibrow::InputBuffer<String, String**, 256> {
7818 public:
7819 virtual void Seek(unsigned pos);
7820 inline SafeStringInputBuffer()
7821 : unibrow::InputBuffer<String, String**, 256>() {}
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00007822 explicit inline SafeStringInputBuffer(String** backing)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007823 : unibrow::InputBuffer<String, String**, 256>(backing) {}
7824};
7825
7826
ager@chromium.org7c537e22008-10-16 08:43:32 +00007827template <typename T>
7828class VectorIterator {
7829 public:
7830 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { }
7831 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { }
7832 T GetNext() { return data_[index_++]; }
7833 bool has_more() { return index_ < data_.length(); }
7834 private:
7835 Vector<const T> data_;
7836 int index_;
7837};
7838
7839
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007840// The Oddball describes objects null, undefined, true, and false.
7841class Oddball: public HeapObject {
7842 public:
7843 // [to_string]: Cached to_string computed at startup.
7844 DECL_ACCESSORS(to_string, String)
7845
7846 // [to_number]: Cached to_number computed at startup.
7847 DECL_ACCESSORS(to_number, Object)
7848
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007849 inline byte kind();
7850 inline void set_kind(byte kind);
7851
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007852 // Casting.
7853 static inline Oddball* cast(Object* obj);
7854
7855 // Dispatched behavior.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007856#ifdef DEBUG
7857 void OddballVerify();
7858#endif
7859
7860 // Initialize the fields.
lrn@chromium.org303ada72010-10-27 09:33:13 +00007861 MUST_USE_RESULT MaybeObject* Initialize(const char* to_string,
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007862 Object* to_number,
7863 byte kind);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007864
7865 // Layout description.
ager@chromium.org236ad962008-09-25 09:45:57 +00007866 static const int kToStringOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007867 static const int kToNumberOffset = kToStringOffset + kPointerSize;
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +00007868 static const int kKindOffset = kToNumberOffset + kPointerSize;
7869 static const int kSize = kKindOffset + kPointerSize;
7870
7871 static const byte kFalse = 0;
7872 static const byte kTrue = 1;
7873 static const byte kNotBooleanMask = ~1;
7874 static const byte kTheHole = 2;
7875 static const byte kNull = 3;
7876 static const byte kArgumentMarker = 4;
7877 static const byte kUndefined = 5;
7878 static const byte kOther = 6;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007879
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007880 typedef FixedBodyDescriptor<kToStringOffset,
7881 kToNumberOffset + kPointerSize,
7882 kSize> BodyDescriptor;
7883
svenpanne@chromium.orgfb046332012-04-19 12:02:44 +00007884 STATIC_CHECK(kKindOffset == Internals::kOddballKindOffset);
7885 STATIC_CHECK(kNull == Internals::kNullOddballKind);
7886 STATIC_CHECK(kUndefined == Internals::kUndefinedOddballKind);
7887
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00007888 private:
7889 DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball);
7890};
7891
7892
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00007893class JSGlobalPropertyCell: public HeapObject {
7894 public:
7895 // [value]: value of the global property.
7896 DECL_ACCESSORS(value, Object)
7897
7898 // Casting.
7899 static inline JSGlobalPropertyCell* cast(Object* obj);
7900
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00007901#ifdef DEBUG
7902 void JSGlobalPropertyCellVerify();
whesse@chromium.org023421e2010-12-21 12:19:12 +00007903#endif
7904#ifdef OBJECT_PRINT
7905 inline void JSGlobalPropertyCellPrint() {
7906 JSGlobalPropertyCellPrint(stdout);
7907 }
7908 void JSGlobalPropertyCellPrint(FILE* out);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00007909#endif
7910
7911 // Layout description.
7912 static const int kValueOffset = HeapObject::kHeaderSize;
7913 static const int kSize = kValueOffset + kPointerSize;
7914
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00007915 typedef FixedBodyDescriptor<kValueOffset,
7916 kValueOffset + kPointerSize,
7917 kSize> BodyDescriptor;
7918
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00007919 private:
7920 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell);
7921};
7922
7923
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007924// The JSProxy describes EcmaScript Harmony proxies
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007925class JSProxy: public JSReceiver {
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007926 public:
7927 // [handler]: The handler property.
7928 DECL_ACCESSORS(handler, Object)
7929
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007930 // [hash]: The hash code property (undefined if not initialized yet).
7931 DECL_ACCESSORS(hash, Object)
7932
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007933 // Casting.
7934 static inline JSProxy* cast(Object* obj);
7935
rossberg@chromium.org717967f2011-07-20 13:44:42 +00007936 bool HasPropertyWithHandler(String* name);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007937 bool HasElementWithHandler(uint32_t index);
7938
7939 MUST_USE_RESULT MaybeObject* GetPropertyWithHandler(
7940 Object* receiver,
7941 String* name);
7942 MUST_USE_RESULT MaybeObject* GetElementWithHandler(
7943 Object* receiver,
7944 uint32_t index);
rossberg@chromium.org717967f2011-07-20 13:44:42 +00007945
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007946 MUST_USE_RESULT MaybeObject* SetPropertyWithHandler(
verwaest@chromium.org37141392012-05-31 13:27:02 +00007947 JSReceiver* receiver,
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00007948 String* name,
7949 Object* value,
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007950 PropertyAttributes attributes,
7951 StrictModeFlag strict_mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007952 MUST_USE_RESULT MaybeObject* SetElementWithHandler(
verwaest@chromium.org37141392012-05-31 13:27:02 +00007953 JSReceiver* receiver,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007954 uint32_t index,
7955 Object* value,
7956 StrictModeFlag strict_mode);
7957
mmassi@chromium.org7028c052012-06-13 11:51:58 +00007958 // If the handler defines an accessor property with a setter, invoke it.
7959 // If it defines an accessor property without a setter, or a data property
7960 // that is read-only, throw. In all these cases set '*done' to true,
7961 // otherwise set it to false.
7962 MUST_USE_RESULT MaybeObject* SetPropertyViaPrototypesWithHandler(
verwaest@chromium.org37141392012-05-31 13:27:02 +00007963 JSReceiver* receiver,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007964 String* name,
7965 Object* value,
7966 PropertyAttributes attributes,
7967 StrictModeFlag strict_mode,
mmassi@chromium.org7028c052012-06-13 11:51:58 +00007968 bool* done);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007969
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00007970 MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler(
7971 String* name,
7972 DeleteMode mode);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007973 MUST_USE_RESULT MaybeObject* DeleteElementWithHandler(
7974 uint32_t index,
7975 DeleteMode mode);
svenpanne@chromium.org84bcc552011-07-18 09:50:57 +00007976
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007977 MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler(
7978 JSReceiver* receiver,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007979 String* name);
7980 MUST_USE_RESULT PropertyAttributes GetElementAttributeWithHandler(
7981 JSReceiver* receiver,
7982 uint32_t index);
7983
7984 MUST_USE_RESULT MaybeObject* GetIdentityHash(CreationFlag flag);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00007985
rossberg@chromium.org717967f2011-07-20 13:44:42 +00007986 // Turn this into an (empty) JSObject.
7987 void Fix();
7988
lrn@chromium.org34e60782011-09-15 07:25:40 +00007989 // Initializes the body after the handler slot.
7990 inline void InitializeBody(int object_size, Object* value);
7991
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00007992 // Invoke a trap by name. If the trap does not exist on this's handler,
7993 // but derived_trap is non-NULL, invoke that instead. May cause GC.
7994 Handle<Object> CallTrap(const char* name,
7995 Handle<Object> derived_trap,
7996 int argc,
7997 Handle<Object> args[]);
7998
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00007999 // Dispatched behavior.
8000#ifdef OBJECT_PRINT
8001 inline void JSProxyPrint() {
8002 JSProxyPrint(stdout);
8003 }
8004 void JSProxyPrint(FILE* out);
8005#endif
8006#ifdef DEBUG
8007 void JSProxyVerify();
8008#endif
8009
rossberg@chromium.org717967f2011-07-20 13:44:42 +00008010 // Layout description. We add padding so that a proxy has the same
8011 // size as a virgin JSObject. This is essential for becoming a JSObject
8012 // upon freeze.
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00008013 static const int kHandlerOffset = HeapObject::kHeaderSize;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00008014 static const int kHashOffset = kHandlerOffset + kPointerSize;
8015 static const int kPaddingOffset = kHashOffset + kPointerSize;
lrn@chromium.org34e60782011-09-15 07:25:40 +00008016 static const int kSize = JSObject::kHeaderSize;
8017 static const int kHeaderSize = kPaddingOffset;
8018 static const int kPaddingSize = kSize - kPaddingOffset;
rossberg@chromium.org717967f2011-07-20 13:44:42 +00008019
lrn@chromium.org34e60782011-09-15 07:25:40 +00008020 STATIC_CHECK(kPaddingSize >= 0);
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00008021
8022 typedef FixedBodyDescriptor<kHandlerOffset,
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00008023 kPaddingOffset,
vegorov@chromium.org7304bca2011-05-16 12:14:13 +00008024 kSize> BodyDescriptor;
8025
8026 private:
8027 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
8028};
8029
8030
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00008031class JSFunctionProxy: public JSProxy {
8032 public:
lrn@chromium.org34e60782011-09-15 07:25:40 +00008033 // [call_trap]: The call trap.
8034 DECL_ACCESSORS(call_trap, Object)
8035
8036 // [construct_trap]: The construct trap.
8037 DECL_ACCESSORS(construct_trap, Object)
8038
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00008039 // Casting.
8040 static inline JSFunctionProxy* cast(Object* obj);
8041
lrn@chromium.org34e60782011-09-15 07:25:40 +00008042 // Dispatched behavior.
8043#ifdef OBJECT_PRINT
8044 inline void JSFunctionProxyPrint() {
8045 JSFunctionProxyPrint(stdout);
8046 }
8047 void JSFunctionProxyPrint(FILE* out);
8048#endif
8049#ifdef DEBUG
8050 void JSFunctionProxyVerify();
8051#endif
8052
8053 // Layout description.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00008054 static const int kCallTrapOffset = JSProxy::kPaddingOffset;
lrn@chromium.org34e60782011-09-15 07:25:40 +00008055 static const int kConstructTrapOffset = kCallTrapOffset + kPointerSize;
8056 static const int kPaddingOffset = kConstructTrapOffset + kPointerSize;
8057 static const int kSize = JSFunction::kSize;
8058 static const int kPaddingSize = kSize - kPaddingOffset;
8059
8060 STATIC_CHECK(kPaddingSize >= 0);
8061
8062 typedef FixedBodyDescriptor<kHandlerOffset,
8063 kConstructTrapOffset + kPointerSize,
8064 kSize> BodyDescriptor;
8065
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00008066 private:
8067 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy);
8068};
8069
kasperl@chromium.org2abc4502009-07-02 07:00:29 +00008070
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00008071// The JSSet describes EcmaScript Harmony sets
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +00008072class JSSet: public JSObject {
8073 public:
8074 // [set]: the backing hash set containing keys.
8075 DECL_ACCESSORS(table, Object)
8076
8077 // Casting.
8078 static inline JSSet* cast(Object* obj);
8079
8080#ifdef OBJECT_PRINT
8081 inline void JSSetPrint() {
8082 JSSetPrint(stdout);
8083 }
8084 void JSSetPrint(FILE* out);
8085#endif
8086#ifdef DEBUG
8087 void JSSetVerify();
8088#endif
8089
8090 static const int kTableOffset = JSObject::kHeaderSize;
8091 static const int kSize = kTableOffset + kPointerSize;
8092
8093 private:
8094 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet);
8095};
8096
8097
8098// The JSMap describes EcmaScript Harmony maps
8099class JSMap: public JSObject {
8100 public:
8101 // [table]: the backing hash table mapping keys to values.
8102 DECL_ACCESSORS(table, Object)
8103
8104 // Casting.
8105 static inline JSMap* cast(Object* obj);
8106
8107#ifdef OBJECT_PRINT
8108 inline void JSMapPrint() {
8109 JSMapPrint(stdout);
8110 }
8111 void JSMapPrint(FILE* out);
8112#endif
8113#ifdef DEBUG
8114 void JSMapVerify();
8115#endif
8116
8117 static const int kTableOffset = JSObject::kHeaderSize;
8118 static const int kSize = kTableOffset + kPointerSize;
8119
8120 private:
8121 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
8122};
8123
8124
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00008125// The JSWeakMap describes EcmaScript Harmony weak maps
8126class JSWeakMap: public JSObject {
8127 public:
8128 // [table]: the backing hash table mapping keys to values.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00008129 DECL_ACCESSORS(table, Object)
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00008130
8131 // [next]: linked list of encountered weak maps during GC.
8132 DECL_ACCESSORS(next, Object)
8133
kmillikin@chromium.org7c2628c2011-08-10 11:27:35 +00008134 // Casting.
8135 static inline JSWeakMap* cast(Object* obj);
8136
8137#ifdef OBJECT_PRINT
8138 inline void JSWeakMapPrint() {
8139 JSWeakMapPrint(stdout);
8140 }
8141 void JSWeakMapPrint(FILE* out);
8142#endif
8143#ifdef DEBUG
8144 void JSWeakMapVerify();
8145#endif
8146
8147 static const int kTableOffset = JSObject::kHeaderSize;
8148 static const int kNextOffset = kTableOffset + kPointerSize;
8149 static const int kSize = kNextOffset + kPointerSize;
8150
8151 private:
8152 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap);
8153};
8154
8155
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008156// Foreign describes objects pointing from JavaScript to C structures.
ager@chromium.org9258b6b2008-09-11 09:11:10 +00008157// Since they cannot contain references to JS HeapObjects they can be
8158// placed in old_data_space.
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008159class Foreign: public HeapObject {
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008160 public:
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008161 // [address]: field containing the address.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00008162 inline Address foreign_address();
8163 inline void set_foreign_address(Address value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008164
8165 // Casting.
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008166 static inline Foreign* cast(Object* obj);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008167
8168 // Dispatched behavior.
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008169 inline void ForeignIterateBody(ObjectVisitor* v);
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00008170
8171 template<typename StaticVisitor>
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008172 inline void ForeignIterateBody();
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00008173
whesse@chromium.org023421e2010-12-21 12:19:12 +00008174#ifdef OBJECT_PRINT
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008175 inline void ForeignPrint() {
8176 ForeignPrint(stdout);
whesse@chromium.org023421e2010-12-21 12:19:12 +00008177 }
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008178 void ForeignPrint(FILE* out);
whesse@chromium.org023421e2010-12-21 12:19:12 +00008179#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008180#ifdef DEBUG
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008181 void ForeignVerify();
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008182#endif
8183
8184 // Layout description.
8185
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00008186 static const int kForeignAddressOffset = HeapObject::kHeaderSize;
8187 static const int kSize = kForeignAddressOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008188
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00008189 STATIC_CHECK(kForeignAddressOffset == Internals::kForeignAddressOffset);
ager@chromium.org18ad94b2009-09-02 08:22:29 +00008190
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008191 private:
ager@chromium.orgea91cc52011-05-23 06:06:11 +00008192 DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008193};
8194
8195
8196// The JSArray describes JavaScript Arrays
8197// Such an array can be in one of two modes:
8198// - fast, backing storage is a FixedArray and length <= elements.length();
8199// Please note: push and pop can be used to grow and shrink the array.
8200// - slow, backing storage is a HashTable with numbers as keys.
8201class JSArray: public JSObject {
8202 public:
8203 // [length]: The length property.
8204 DECL_ACCESSORS(length, Object)
8205
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00008206 // Overload the length setter to skip write barrier when the length
8207 // is set to a smi. This matches the set function on FixedArray.
8208 inline void set_length(Smi* length);
8209
lrn@chromium.org303ada72010-10-27 09:33:13 +00008210 MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index,
8211 Object* value);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008212
8213 // Initialize the array with the given capacity. The function may
8214 // fail due to out-of-memory situations, but only if the requested
8215 // capacity is non-zero.
lrn@chromium.org303ada72010-10-27 09:33:13 +00008216 MUST_USE_RESULT MaybeObject* Initialize(int capacity);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008217
ricow@chromium.org7ad65222011-12-19 12:13:11 +00008218 // Initializes the array to a certain length.
8219 inline bool AllowsSetElementsLength();
8220 MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length);
8221
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008222 // Set the content of the array to the content of storage.
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +00008223 MUST_USE_RESULT inline MaybeObject* SetContent(FixedArrayBase* storage);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008224
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008225 // Casting.
8226 static inline JSArray* cast(Object* obj);
8227
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00008228 // Uses handles. Ensures that the fixed array backing the JSArray has at
8229 // least the stated size.
ager@chromium.org5aa501c2009-06-23 07:57:28 +00008230 inline void EnsureSize(int minimum_size_of_backing_fixed_array);
kasperl@chromium.org7be3c992009-03-12 07:19:55 +00008231
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008232 // Dispatched behavior.
whesse@chromium.org023421e2010-12-21 12:19:12 +00008233#ifdef OBJECT_PRINT
8234 inline void JSArrayPrint() {
8235 JSArrayPrint(stdout);
8236 }
8237 void JSArrayPrint(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 JSArrayVerify();
8241#endif
8242
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +00008243 // Number of element slots to pre-allocate for an empty array.
8244 static const int kPreallocatedArrayElements = 4;
8245
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008246 // Layout description.
8247 static const int kLengthOffset = JSObject::kHeaderSize;
8248 static const int kSize = kLengthOffset + kPointerSize;
8249
8250 private:
ager@chromium.org5aa501c2009-06-23 07:57:28 +00008251 // Expand the fixed array backing of a fast-case JSArray to at least
8252 // the requested size.
8253 void Expand(int minimum_size_of_backing_fixed_array);
8254
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008255 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
8256};
8257
8258
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +00008259// JSRegExpResult is just a JSArray with a specific initial map.
8260// This initial map adds in-object properties for "index" and "input"
8261// properties, as assigned by RegExp.prototype.exec, which allows
8262// faster creation of RegExp exec results.
8263// This class just holds constants used when creating the result.
8264// After creation the result must be treated as a JSArray in all regards.
8265class JSRegExpResult: public JSArray {
8266 public:
8267 // Offsets of object fields.
8268 static const int kIndexOffset = JSArray::kSize;
8269 static const int kInputOffset = kIndexOffset + kPointerSize;
8270 static const int kSize = kInputOffset + kPointerSize;
8271 // Indices of in-object properties.
8272 static const int kIndexIndex = 0;
8273 static const int kInputIndex = 1;
8274 private:
8275 DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult);
8276};
8277
8278
ager@chromium.org32912102009-01-16 10:38:43 +00008279// An accessor must have a getter, but can have no setter.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008280//
8281// When setting a property, V8 searches accessors in prototypes.
8282// If an accessor was found and it does not have a setter,
8283// the request is ignored.
8284//
ager@chromium.orgeadaf222009-06-16 09:43:10 +00008285// If the accessor in the prototype has the READ_ONLY property attribute, then
8286// a new value is added to the local object when the property is set.
8287// This shadows the accessor in the prototype.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008288class AccessorInfo: public Struct {
8289 public:
8290 DECL_ACCESSORS(getter, Object)
8291 DECL_ACCESSORS(setter, Object)
8292 DECL_ACCESSORS(data, Object)
8293 DECL_ACCESSORS(name, Object)
8294 DECL_ACCESSORS(flag, Smi)
mmassi@chromium.org7028c052012-06-13 11:51:58 +00008295 DECL_ACCESSORS(expected_receiver_type, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008296
8297 inline bool all_can_read();
8298 inline void set_all_can_read(bool value);
8299
8300 inline bool all_can_write();
8301 inline void set_all_can_write(bool value);
8302
ager@chromium.org870a0b62008-11-04 11:43:05 +00008303 inline bool prohibits_overwriting();
8304 inline void set_prohibits_overwriting(bool value);
8305
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008306 inline PropertyAttributes property_attributes();
8307 inline void set_property_attributes(PropertyAttributes attributes);
8308
mmassi@chromium.org7028c052012-06-13 11:51:58 +00008309 // Checks whether the given receiver is compatible with this accessor.
8310 inline bool IsCompatibleReceiver(Object* receiver);
8311
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008312 static inline AccessorInfo* cast(Object* obj);
8313
whesse@chromium.org023421e2010-12-21 12:19:12 +00008314#ifdef OBJECT_PRINT
8315 inline void AccessorInfoPrint() {
8316 AccessorInfoPrint(stdout);
8317 }
8318 void AccessorInfoPrint(FILE* out);
8319#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008320#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008321 void AccessorInfoVerify();
8322#endif
8323
ager@chromium.org236ad962008-09-25 09:45:57 +00008324 static const int kGetterOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008325 static const int kSetterOffset = kGetterOffset + kPointerSize;
8326 static const int kDataOffset = kSetterOffset + kPointerSize;
8327 static const int kNameOffset = kDataOffset + kPointerSize;
8328 static const int kFlagOffset = kNameOffset + kPointerSize;
mmassi@chromium.org7028c052012-06-13 11:51:58 +00008329 static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize;
8330 static const int kSize = kExpectedReceiverTypeOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008331
8332 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008333 // Bit positions in flag.
ager@chromium.org870a0b62008-11-04 11:43:05 +00008334 static const int kAllCanReadBit = 0;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008335 static const int kAllCanWriteBit = 1;
ager@chromium.org870a0b62008-11-04 11:43:05 +00008336 static const int kProhibitsOverwritingBit = 2;
8337 class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
mads.s.ager31e71382008-08-13 09:32:07 +00008338
8339 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008340};
8341
8342
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00008343// Support for JavaScript accessors: A pair of a getter and a setter. Each
8344// accessor can either be
8345// * a pointer to a JavaScript function or proxy: a real accessor
8346// * undefined: considered an accessor by the spec, too, strangely enough
8347// * the hole: an accessor which has not been set
8348// * a pointer to a map: a transition used to ensure map sharing
8349class AccessorPair: public Struct {
8350 public:
8351 DECL_ACCESSORS(getter, Object)
8352 DECL_ACCESSORS(setter, Object)
8353
8354 static inline AccessorPair* cast(Object* obj);
8355
verwaest@chromium.org753aee42012-07-17 16:15:42 +00008356 MUST_USE_RESULT MaybeObject* Copy();
ulan@chromium.org65a89c22012-02-14 11:46:07 +00008357
svenpanne@chromium.org830d30c2012-05-29 13:20:14 +00008358 Object* get(AccessorComponent component) {
8359 return component == ACCESSOR_GETTER ? getter() : setter();
8360 }
8361
8362 void set(AccessorComponent component, Object* value) {
8363 if (component == ACCESSOR_GETTER) {
8364 set_getter(value);
8365 } else {
8366 set_setter(value);
8367 }
8368 }
8369
danno@chromium.org88aa0582012-03-23 15:11:57 +00008370 // Note: Returns undefined instead in case of a hole.
8371 Object* GetComponent(AccessorComponent component);
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00008372
danno@chromium.org88aa0582012-03-23 15:11:57 +00008373 // Set both components, skipping arguments which are a JavaScript null.
8374 void SetComponents(Object* getter, Object* setter) {
8375 if (!getter->IsNull()) set_getter(getter);
8376 if (!setter->IsNull()) set_setter(setter);
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +00008377 }
8378
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00008379 bool ContainsAccessor() {
8380 return IsJSAccessor(getter()) || IsJSAccessor(setter());
8381 }
8382
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00008383#ifdef OBJECT_PRINT
8384 void AccessorPairPrint(FILE* out = stdout);
8385#endif
8386#ifdef DEBUG
8387 void AccessorPairVerify();
8388#endif
8389
8390 static const int kGetterOffset = HeapObject::kHeaderSize;
8391 static const int kSetterOffset = kGetterOffset + kPointerSize;
8392 static const int kSize = kSetterOffset + kPointerSize;
8393
8394 private:
ulan@chromium.org9a21ec42012-03-06 08:42:24 +00008395 // Strangely enough, in addition to functions and harmony proxies, the spec
8396 // requires us to consider undefined as a kind of accessor, too:
8397 // var obj = {};
8398 // Object.defineProperty(obj, "foo", {get: undefined});
8399 // assertTrue("foo" in obj);
8400 bool IsJSAccessor(Object* obj) {
8401 return obj->IsSpecFunction() || obj->IsUndefined();
8402 }
8403
erik.corry@gmail.comf2038fb2012-01-16 11:42:08 +00008404 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair);
8405};
8406
8407
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008408class AccessCheckInfo: public Struct {
8409 public:
8410 DECL_ACCESSORS(named_callback, Object)
8411 DECL_ACCESSORS(indexed_callback, Object)
8412 DECL_ACCESSORS(data, Object)
8413
8414 static inline AccessCheckInfo* cast(Object* obj);
8415
whesse@chromium.org023421e2010-12-21 12:19:12 +00008416#ifdef OBJECT_PRINT
8417 inline void AccessCheckInfoPrint() {
8418 AccessCheckInfoPrint(stdout);
8419 }
8420 void AccessCheckInfoPrint(FILE* out);
8421#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008422#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008423 void AccessCheckInfoVerify();
8424#endif
8425
ager@chromium.org236ad962008-09-25 09:45:57 +00008426 static const int kNamedCallbackOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008427 static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize;
8428 static const int kDataOffset = kIndexedCallbackOffset + kPointerSize;
8429 static const int kSize = kDataOffset + kPointerSize;
8430
8431 private:
8432 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo);
8433};
8434
8435
8436class InterceptorInfo: public Struct {
8437 public:
8438 DECL_ACCESSORS(getter, Object)
8439 DECL_ACCESSORS(setter, Object)
8440 DECL_ACCESSORS(query, Object)
8441 DECL_ACCESSORS(deleter, Object)
8442 DECL_ACCESSORS(enumerator, Object)
8443 DECL_ACCESSORS(data, Object)
8444
8445 static inline InterceptorInfo* cast(Object* obj);
8446
whesse@chromium.org023421e2010-12-21 12:19:12 +00008447#ifdef OBJECT_PRINT
8448 inline void InterceptorInfoPrint() {
8449 InterceptorInfoPrint(stdout);
8450 }
8451 void InterceptorInfoPrint(FILE* out);
8452#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008453#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008454 void InterceptorInfoVerify();
8455#endif
8456
ager@chromium.org236ad962008-09-25 09:45:57 +00008457 static const int kGetterOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008458 static const int kSetterOffset = kGetterOffset + kPointerSize;
8459 static const int kQueryOffset = kSetterOffset + kPointerSize;
8460 static const int kDeleterOffset = kQueryOffset + kPointerSize;
8461 static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
8462 static const int kDataOffset = kEnumeratorOffset + kPointerSize;
8463 static const int kSize = kDataOffset + kPointerSize;
8464
8465 private:
8466 DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
8467};
8468
8469
8470class CallHandlerInfo: public Struct {
8471 public:
8472 DECL_ACCESSORS(callback, Object)
8473 DECL_ACCESSORS(data, Object)
8474
8475 static inline CallHandlerInfo* cast(Object* obj);
8476
whesse@chromium.org023421e2010-12-21 12:19:12 +00008477#ifdef OBJECT_PRINT
8478 inline void CallHandlerInfoPrint() {
8479 CallHandlerInfoPrint(stdout);
8480 }
8481 void CallHandlerInfoPrint(FILE* out);
8482#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008483#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008484 void CallHandlerInfoVerify();
8485#endif
8486
ager@chromium.org236ad962008-09-25 09:45:57 +00008487 static const int kCallbackOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008488 static const int kDataOffset = kCallbackOffset + kPointerSize;
erik.corry@gmail.com4a6c3272010-11-18 12:04:40 +00008489 static const int kSize = kDataOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008490
8491 private:
8492 DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
8493};
8494
8495
8496class TemplateInfo: public Struct {
8497 public:
8498 DECL_ACCESSORS(tag, Object)
8499 DECL_ACCESSORS(property_list, Object)
8500
8501#ifdef DEBUG
8502 void TemplateInfoVerify();
8503#endif
8504
ager@chromium.org236ad962008-09-25 09:45:57 +00008505 static const int kTagOffset = HeapObject::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008506 static const int kPropertyListOffset = kTagOffset + kPointerSize;
8507 static const int kHeaderSize = kPropertyListOffset + kPointerSize;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00008508
8509 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008510 DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
8511};
8512
8513
8514class FunctionTemplateInfo: public TemplateInfo {
8515 public:
8516 DECL_ACCESSORS(serial_number, Object)
8517 DECL_ACCESSORS(call_code, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008518 DECL_ACCESSORS(property_accessors, Object)
8519 DECL_ACCESSORS(prototype_template, Object)
8520 DECL_ACCESSORS(parent_template, Object)
8521 DECL_ACCESSORS(named_property_handler, Object)
8522 DECL_ACCESSORS(indexed_property_handler, Object)
8523 DECL_ACCESSORS(instance_template, Object)
8524 DECL_ACCESSORS(class_name, Object)
8525 DECL_ACCESSORS(signature, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008526 DECL_ACCESSORS(instance_call_handler, Object)
8527 DECL_ACCESSORS(access_check_info, Object)
8528 DECL_ACCESSORS(flag, Smi)
8529
8530 // Following properties use flag bits.
8531 DECL_BOOLEAN_ACCESSORS(hidden_prototype)
8532 DECL_BOOLEAN_ACCESSORS(undetectable)
8533 // If the bit is set, object instances created by this function
8534 // requires access check.
8535 DECL_BOOLEAN_ACCESSORS(needs_access_check)
ricow@chromium.org2c99e282011-07-28 09:15:17 +00008536 DECL_BOOLEAN_ACCESSORS(read_only_prototype)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008537
8538 static inline FunctionTemplateInfo* cast(Object* obj);
8539
whesse@chromium.org023421e2010-12-21 12:19:12 +00008540#ifdef OBJECT_PRINT
8541 inline void FunctionTemplateInfoPrint() {
8542 FunctionTemplateInfoPrint(stdout);
8543 }
8544 void FunctionTemplateInfoPrint(FILE* out);
8545#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008546#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008547 void FunctionTemplateInfoVerify();
8548#endif
8549
8550 static const int kSerialNumberOffset = TemplateInfo::kHeaderSize;
8551 static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize;
kasper.lund212ac232008-07-16 07:07:30 +00008552 static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008553 static const int kPrototypeTemplateOffset =
8554 kPropertyAccessorsOffset + kPointerSize;
8555 static const int kParentTemplateOffset =
8556 kPrototypeTemplateOffset + kPointerSize;
8557 static const int kNamedPropertyHandlerOffset =
8558 kParentTemplateOffset + kPointerSize;
8559 static const int kIndexedPropertyHandlerOffset =
8560 kNamedPropertyHandlerOffset + kPointerSize;
8561 static const int kInstanceTemplateOffset =
8562 kIndexedPropertyHandlerOffset + kPointerSize;
8563 static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
8564 static const int kSignatureOffset = kClassNameOffset + kPointerSize;
v8.team.kasperl727e9952008-09-02 14:56:44 +00008565 static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008566 static const int kAccessCheckInfoOffset =
8567 kInstanceCallHandlerOffset + kPointerSize;
8568 static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize;
ricow@chromium.org2c99e282011-07-28 09:15:17 +00008569 static const int kSize = kFlagOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008570
8571 private:
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008572 // Bit position in the flag, from least significant bit position.
8573 static const int kHiddenPrototypeBit = 0;
8574 static const int kUndetectableBit = 1;
8575 static const int kNeedsAccessCheckBit = 2;
ricow@chromium.org2c99e282011-07-28 09:15:17 +00008576 static const int kReadOnlyPrototypeBit = 3;
mads.s.ager31e71382008-08-13 09:32:07 +00008577
8578 DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008579};
8580
8581
8582class ObjectTemplateInfo: public TemplateInfo {
8583 public:
8584 DECL_ACCESSORS(constructor, Object)
kasper.lund212ac232008-07-16 07:07:30 +00008585 DECL_ACCESSORS(internal_field_count, Object)
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008586
8587 static inline ObjectTemplateInfo* cast(Object* obj);
8588
whesse@chromium.org023421e2010-12-21 12:19:12 +00008589#ifdef OBJECT_PRINT
8590 inline void ObjectTemplateInfoPrint() {
8591 ObjectTemplateInfoPrint(stdout);
8592 }
8593 void ObjectTemplateInfoPrint(FILE* out);
8594#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008595#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008596 void ObjectTemplateInfoVerify();
8597#endif
8598
8599 static const int kConstructorOffset = TemplateInfo::kHeaderSize;
kasper.lund212ac232008-07-16 07:07:30 +00008600 static const int kInternalFieldCountOffset =
8601 kConstructorOffset + kPointerSize;
kasperl@chromium.org71affb52009-05-26 05:44:31 +00008602 static const int kSize = kInternalFieldCountOffset + kPointerSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008603};
8604
8605
8606class SignatureInfo: public Struct {
8607 public:
8608 DECL_ACCESSORS(receiver, Object)
8609 DECL_ACCESSORS(args, Object)
8610
8611 static inline SignatureInfo* cast(Object* obj);
8612
whesse@chromium.org023421e2010-12-21 12:19:12 +00008613#ifdef OBJECT_PRINT
8614 inline void SignatureInfoPrint() {
8615 SignatureInfoPrint(stdout);
8616 }
8617 void SignatureInfoPrint(FILE* out);
8618#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008619#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008620 void SignatureInfoVerify();
8621#endif
8622
ager@chromium.org236ad962008-09-25 09:45:57 +00008623 static const int kReceiverOffset = Struct::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008624 static const int kArgsOffset = kReceiverOffset + kPointerSize;
8625 static const int kSize = kArgsOffset + kPointerSize;
8626
8627 private:
8628 DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo);
8629};
8630
8631
8632class TypeSwitchInfo: public Struct {
8633 public:
8634 DECL_ACCESSORS(types, Object)
8635
8636 static inline TypeSwitchInfo* cast(Object* obj);
8637
whesse@chromium.org023421e2010-12-21 12:19:12 +00008638#ifdef OBJECT_PRINT
8639 inline void TypeSwitchInfoPrint() {
8640 TypeSwitchInfoPrint(stdout);
8641 }
8642 void TypeSwitchInfoPrint(FILE* out);
8643#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008644#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008645 void TypeSwitchInfoVerify();
8646#endif
8647
ager@chromium.org236ad962008-09-25 09:45:57 +00008648 static const int kTypesOffset = Struct::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008649 static const int kSize = kTypesOffset + kPointerSize;
8650};
8651
8652
ager@chromium.org65dad4b2009-04-23 08:48:43 +00008653#ifdef ENABLE_DEBUGGER_SUPPORT
ager@chromium.org32912102009-01-16 10:38:43 +00008654// The DebugInfo class holds additional information for a function being
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008655// debugged.
8656class DebugInfo: public Struct {
8657 public:
ager@chromium.org32912102009-01-16 10:38:43 +00008658 // The shared function info for the source being debugged.
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008659 DECL_ACCESSORS(shared, SharedFunctionInfo)
8660 // Code object for the original code.
8661 DECL_ACCESSORS(original_code, Code)
8662 // Code object for the patched code. This code object is the code object
8663 // currently active for the function.
8664 DECL_ACCESSORS(code, Code)
8665 // Fixed array holding status information for each active break point.
8666 DECL_ACCESSORS(break_points, FixedArray)
8667
8668 // Check if there is a break point at a code position.
8669 bool HasBreakPoint(int code_position);
8670 // Get the break point info object for a code position.
8671 Object* GetBreakPointInfo(int code_position);
8672 // Clear a break point.
8673 static void ClearBreakPoint(Handle<DebugInfo> debug_info,
8674 int code_position,
8675 Handle<Object> break_point_object);
8676 // Set a break point.
8677 static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position,
8678 int source_position, int statement_position,
8679 Handle<Object> break_point_object);
8680 // Get the break point objects for a code position.
8681 Object* GetBreakPointObjects(int code_position);
8682 // Find the break point info holding this break point object.
8683 static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info,
8684 Handle<Object> break_point_object);
8685 // Get the number of break points for this function.
8686 int GetBreakPointCount();
8687
8688 static inline DebugInfo* cast(Object* obj);
8689
whesse@chromium.org023421e2010-12-21 12:19:12 +00008690#ifdef OBJECT_PRINT
8691 inline void DebugInfoPrint() {
8692 DebugInfoPrint(stdout);
8693 }
8694 void DebugInfoPrint(FILE* out);
8695#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008696#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008697 void DebugInfoVerify();
8698#endif
8699
ager@chromium.org236ad962008-09-25 09:45:57 +00008700 static const int kSharedFunctionInfoIndex = Struct::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008701 static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize;
8702 static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize;
8703 static const int kActiveBreakPointsCountIndex =
8704 kPatchedCodeIndex + kPointerSize;
8705 static const int kBreakPointsStateIndex =
8706 kActiveBreakPointsCountIndex + kPointerSize;
8707 static const int kSize = kBreakPointsStateIndex + kPointerSize;
8708
8709 private:
8710 static const int kNoBreakPointInfo = -1;
8711
8712 // Lookup the index in the break_points array for a code position.
8713 int GetBreakPointInfoIndex(int code_position);
8714
8715 DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo);
8716};
8717
8718
8719// The BreakPointInfo class holds information for break points set in a
8720// function. The DebugInfo object holds a BreakPointInfo object for each code
8721// position with one or more break points.
8722class BreakPointInfo: public Struct {
8723 public:
8724 // The position in the code for the break point.
8725 DECL_ACCESSORS(code_position, Smi)
8726 // The position in the source for the break position.
8727 DECL_ACCESSORS(source_position, Smi)
8728 // The position in the source for the last statement before this break
8729 // position.
8730 DECL_ACCESSORS(statement_position, Smi)
8731 // List of related JavaScript break points.
8732 DECL_ACCESSORS(break_point_objects, Object)
8733
8734 // Removes a break point.
8735 static void ClearBreakPoint(Handle<BreakPointInfo> info,
8736 Handle<Object> break_point_object);
8737 // Set a break point.
8738 static void SetBreakPoint(Handle<BreakPointInfo> info,
8739 Handle<Object> break_point_object);
8740 // Check if break point info has this break point object.
8741 static bool HasBreakPointObject(Handle<BreakPointInfo> info,
8742 Handle<Object> break_point_object);
8743 // Get the number of break points for this code position.
8744 int GetBreakPointCount();
8745
8746 static inline BreakPointInfo* cast(Object* obj);
8747
whesse@chromium.org023421e2010-12-21 12:19:12 +00008748#ifdef OBJECT_PRINT
8749 inline void BreakPointInfoPrint() {
8750 BreakPointInfoPrint(stdout);
8751 }
8752 void BreakPointInfoPrint(FILE* out);
8753#endif
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008754#ifdef DEBUG
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008755 void BreakPointInfoVerify();
8756#endif
8757
ager@chromium.org236ad962008-09-25 09:45:57 +00008758 static const int kCodePositionIndex = Struct::kHeaderSize;
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008759 static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize;
8760 static const int kStatementPositionIndex =
8761 kSourcePositionIndex + kPointerSize;
8762 static const int kBreakPointObjectsIndex =
8763 kStatementPositionIndex + kPointerSize;
8764 static const int kSize = kBreakPointObjectsIndex + kPointerSize;
8765
8766 private:
8767 DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo);
8768};
ager@chromium.org65dad4b2009-04-23 08:48:43 +00008769#endif // ENABLE_DEBUGGER_SUPPORT
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008770
8771
8772#undef DECL_BOOLEAN_ACCESSORS
8773#undef DECL_ACCESSORS
8774
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00008775#define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \
8776 V(kSymbolTable, "symbol_table", "(Symbols)") \
8777 V(kExternalStringsTable, "external_strings_table", "(External strings)") \
8778 V(kStrongRootList, "strong_root_list", "(Strong roots)") \
8779 V(kSymbol, "symbol", "(Symbol)") \
8780 V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \
8781 V(kTop, "top", "(Isolate)") \
8782 V(kRelocatable, "relocatable", "(Relocatable)") \
8783 V(kDebug, "debug", "(Debugger)") \
8784 V(kCompilationCache, "compilationcache", "(Compilation cache)") \
8785 V(kHandleScope, "handlescope", "(Handle scope)") \
8786 V(kBuiltins, "builtins", "(Builtins)") \
8787 V(kGlobalHandles, "globalhandles", "(Global handles)") \
8788 V(kThreadManager, "threadmanager", "(Thread manager)") \
8789 V(kExtensions, "Extensions", "(Extensions)")
8790
8791class VisitorSynchronization : public AllStatic {
8792 public:
8793#define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item,
8794 enum SyncTag {
8795 VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM)
8796 kNumberOfSyncTags
8797 };
8798#undef DECLARE_ENUM
8799
8800 static const char* const kTags[kNumberOfSyncTags];
8801 static const char* const kTagNames[kNumberOfSyncTags];
8802};
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008803
8804// Abstract base class for visiting, and optionally modifying, the
8805// pointers contained in Objects. Used in GC and serialization/deserialization.
8806class ObjectVisitor BASE_EMBEDDED {
8807 public:
8808 virtual ~ObjectVisitor() {}
8809
8810 // Visits a contiguous arrays of pointers in the half-open range
8811 // [start, end). Any or all of the values may be modified on return.
8812 virtual void VisitPointers(Object** start, Object** end) = 0;
8813
8814 // To allow lazy clearing of inline caches the visitor has
8815 // a rich interface for iterating over Code objects..
8816
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008817 // Visits a code target in the instruction stream.
8818 virtual void VisitCodeTarget(RelocInfo* rinfo);
8819
erik.corry@gmail.com145eff52010-08-23 11:36:18 +00008820 // Visits a code entry in a JS function.
8821 virtual void VisitCodeEntry(Address entry_address);
8822
kasperl@chromium.orga5551262010-12-07 12:49:48 +00008823 // Visits a global property cell reference in the instruction stream.
8824 virtual void VisitGlobalPropertyCell(RelocInfo* rinfo);
8825
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008826 // Visits a runtime entry in the instruction stream.
8827 virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
8828
ager@chromium.orgc4c92722009-11-18 14:12:51 +00008829 // Visits the resource of an ASCII or two-byte string.
8830 virtual void VisitExternalAsciiString(
8831 v8::String::ExternalAsciiStringResource** resource) {}
8832 virtual void VisitExternalTwoByteString(
8833 v8::String::ExternalStringResource** resource) {}
8834
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008835 // Visits a debug call target in the instruction stream.
8836 virtual void VisitDebugTarget(RelocInfo* rinfo);
8837
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008838 // Handy shorthand for visiting a single pointer.
8839 virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); }
8840
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00008841 // Visit pointer embedded into a code object.
rossberg@chromium.orgb4b2aa62011-10-13 09:49:59 +00008842 virtual void VisitEmbeddedPointer(RelocInfo* rinfo);
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00008843
fschneider@chromium.org7d10be52012-04-10 12:30:14 +00008844 virtual void VisitSharedFunctionInfo(SharedFunctionInfo* shared) {}
8845
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008846 // Visits a contiguous arrays of external references (references to the C++
8847 // heap) in the half-open range [start, end). Any or all of the values
8848 // may be modified on return.
8849 virtual void VisitExternalReferences(Address* start, Address* end) {}
8850
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00008851 virtual void VisitExternalReference(RelocInfo* rinfo);
8852
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008853 inline void VisitExternalReference(Address* p) {
8854 VisitExternalReferences(p, p + 1);
8855 }
8856
whesse@chromium.orgb08986c2011-03-14 16:13:42 +00008857 // Visits a handle that has an embedder-assigned class ID.
8858 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {}
8859
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008860 // Intended for serialization/deserialization checking: insert, or
8861 // check for the presence of, a tag at this position in the stream.
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +00008862 // Also used for marking up GC roots in heap snapshots.
8863 virtual void Synchronize(VisitorSynchronization::SyncTag tag) {}
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008864};
8865
8866
ager@chromium.orgea4f62e2010-08-16 16:28:43 +00008867class StructBodyDescriptor : public
8868 FlexibleBodyDescriptor<HeapObject::kHeaderSize> {
8869 public:
8870 static inline int SizeOf(Map* map, HeapObject* object) {
8871 return map->instance_size();
8872 }
8873};
8874
8875
christian.plesner.hansen43d26ec2008-07-03 15:10:15 +00008876// BooleanBit is a helper class for setting and getting a bit in an
8877// integer or Smi.
8878class BooleanBit : public AllStatic {
8879 public:
8880 static inline bool get(Smi* smi, int bit_position) {
8881 return get(smi->value(), bit_position);
8882 }
8883
8884 static inline bool get(int value, int bit_position) {
8885 return (value & (1 << bit_position)) != 0;
8886 }
8887
8888 static inline Smi* set(Smi* smi, int bit_position, bool v) {
8889 return Smi::FromInt(set(smi->value(), bit_position, v));
8890 }
8891
8892 static inline int set(int value, int bit_position, bool v) {
8893 if (v) {
8894 value |= (1 << bit_position);
8895 } else {
8896 value &= ~(1 << bit_position);
8897 }
8898 return value;
8899 }
8900};
8901
8902} } // namespace v8::internal
8903
8904#endif // V8_OBJECTS_H_