blob: 61c6e5ebe1fab6711498b4bb5b53e5a30ee1cb9e [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2015 the V8 project authors. All rights reserved.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Steve Blocka7e24c12009-10-30 11:49:00 +00004
5#ifndef V8_OBJECTS_H_
6#define V8_OBJECTS_H_
7
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008#include <iosfwd>
9
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010#include "src/assert-scope.h"
11#include "src/bailout-reason.h"
12#include "src/base/bits.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000013#include "src/base/flags.h"
14#include "src/base/smart-pointers.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000015#include "src/builtins.h"
16#include "src/checks.h"
17#include "src/elements-kind.h"
18#include "src/field-index.h"
19#include "src/flags.h"
20#include "src/list.h"
21#include "src/property-details.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000022#include "src/unicode.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040023#include "src/unicode-decoder.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000024#include "src/zone.h"
25
Steve Block3ce2e202009-11-05 08:53:23 +000026#if V8_TARGET_ARCH_ARM
Ben Murdochb8a8cc12014-11-26 15:28:44 +000027#include "src/arm/constants-arm.h" // NOLINT
28#elif V8_TARGET_ARCH_ARM64
29#include "src/arm64/constants-arm64.h" // NOLINT
Andrei Popescu31002712010-02-23 13:46:05 +000030#elif V8_TARGET_ARCH_MIPS
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031#include "src/mips/constants-mips.h" // NOLINT
32#elif V8_TARGET_ARCH_MIPS64
33#include "src/mips64/constants-mips64.h" // NOLINT
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000034#elif V8_TARGET_ARCH_PPC
35#include "src/ppc/constants-ppc.h" // NOLINT
Steve Block3ce2e202009-11-05 08:53:23 +000036#endif
Ben Murdoch3ef787d2012-04-12 10:51:47 +010037
Steve Blocka7e24c12009-10-30 11:49:00 +000038
39//
Kristian Monsen50ef84f2010-07-29 15:18:00 +010040// Most object types in the V8 JavaScript are described in this file.
Steve Blocka7e24c12009-10-30 11:49:00 +000041//
42// Inheritance hierarchy:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000043// - Object
44// - Smi (immediate small integer)
45// - HeapObject (superclass for everything allocated in the heap)
46// - JSReceiver (suitable for property access)
47// - JSObject
48// - JSArray
49// - JSArrayBuffer
50// - JSArrayBufferView
51// - JSTypedArray
52// - JSDataView
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000053// - JSBoundFunction
Ben Murdochb8a8cc12014-11-26 15:28:44 +000054// - JSCollection
Ben Murdoch3ef787d2012-04-12 10:51:47 +010055// - JSSet
56// - JSMap
Ben Murdochb8a8cc12014-11-26 15:28:44 +000057// - JSSetIterator
58// - JSMapIterator
59// - JSWeakCollection
Ben Murdoch69a99ed2011-11-30 16:03:39 +000060// - JSWeakMap
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061// - JSWeakSet
62// - JSRegExp
63// - JSFunction
64// - JSGeneratorObject
65// - JSModule
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000066// - JSGlobalObject
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067// - JSGlobalProxy
68// - JSValue
69// - JSDate
70// - JSMessageObject
71// - JSProxy
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072// - FixedArrayBase
73// - ByteArray
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000074// - BytecodeArray
Ben Murdochb8a8cc12014-11-26 15:28:44 +000075// - FixedArray
76// - DescriptorArray
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000077// - LiteralsArray
Ben Murdochb8a8cc12014-11-26 15:28:44 +000078// - HashTable
79// - Dictionary
80// - StringTable
81// - CompilationCacheTable
82// - CodeCacheHashTable
83// - MapCache
84// - OrderedHashTable
85// - OrderedHashSet
86// - OrderedHashMap
87// - Context
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000088// - TypeFeedbackMetadata
Ben Murdochb8a8cc12014-11-26 15:28:44 +000089// - TypeFeedbackVector
Ben Murdochb8a8cc12014-11-26 15:28:44 +000090// - ScopeInfo
91// - TransitionArray
Emily Bernierd0a1eb72015-03-24 16:35:39 -040092// - ScriptContextTable
93// - WeakFixedArray
Ben Murdochb8a8cc12014-11-26 15:28:44 +000094// - FixedDoubleArray
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095// - Name
Steve Blocka7e24c12009-10-30 11:49:00 +000096// - String
97// - SeqString
Ben Murdochb8a8cc12014-11-26 15:28:44 +000098// - SeqOneByteString
Steve Blocka7e24c12009-10-30 11:49:00 +000099// - SeqTwoByteString
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000100// - SlicedString
Steve Blocka7e24c12009-10-30 11:49:00 +0000101// - ConsString
Steve Blocka7e24c12009-10-30 11:49:00 +0000102// - ExternalString
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000103// - ExternalOneByteString
Steve Blocka7e24c12009-10-30 11:49:00 +0000104// - ExternalTwoByteString
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105// - InternalizedString
106// - SeqInternalizedString
107// - SeqOneByteInternalizedString
108// - SeqTwoByteInternalizedString
109// - ConsInternalizedString
110// - ExternalInternalizedString
111// - ExternalOneByteInternalizedString
112// - ExternalTwoByteInternalizedString
113// - Symbol
114// - HeapNumber
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000115// - Simd128Value
116// - Float32x4
117// - Int32x4
118// - Uint32x4
119// - Bool32x4
120// - Int16x8
121// - Uint16x8
122// - Bool16x8
123// - Int8x16
124// - Uint8x16
125// - Bool8x16
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000126// - Cell
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000127// - PropertyCell
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128// - Code
Ben Murdoch097c5b22016-05-18 11:27:45 +0100129// - AbstractCode, a wrapper around Code or BytecodeArray
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000130// - Map
131// - Oddball
132// - Foreign
133// - SharedFunctionInfo
134// - Struct
135// - Box
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000136// - AccessorInfo
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137// - AccessorPair
138// - AccessCheckInfo
139// - InterceptorInfo
140// - CallHandlerInfo
141// - TemplateInfo
142// - FunctionTemplateInfo
143// - ObjectTemplateInfo
144// - Script
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000145// - DebugInfo
146// - BreakPointInfo
147// - CodeCache
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000148// - PrototypeInfo
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400149// - WeakCell
Steve Blocka7e24c12009-10-30 11:49:00 +0000150//
151// Formats of Object*:
152// Smi: [31 bit signed int] 0
153// HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
Steve Blocka7e24c12009-10-30 11:49:00 +0000154
Steve Blocka7e24c12009-10-30 11:49:00 +0000155namespace v8 {
156namespace internal {
157
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000158enum KeyedAccessStoreMode {
159 STANDARD_STORE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000160 STORE_TRANSITION_TO_OBJECT,
161 STORE_TRANSITION_TO_DOUBLE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000162 STORE_AND_GROW_NO_TRANSITION,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000163 STORE_AND_GROW_TRANSITION_TO_OBJECT,
164 STORE_AND_GROW_TRANSITION_TO_DOUBLE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000165 STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS,
166 STORE_NO_TRANSITION_HANDLE_COW
Ben Murdoch589d6972011-11-30 16:04:58 +0000167};
168
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000170// Valid hints for the abstract operation ToPrimitive,
171// implemented according to ES6, section 7.1.1.
172enum class ToPrimitiveHint { kDefault, kNumber, kString };
173
174
175// Valid hints for the abstract operation OrdinaryToPrimitive,
176// implemented according to ES6, section 7.1.1.
177enum class OrdinaryToPrimitiveHint { kNumber, kString };
178
179
180enum TypeofMode : int { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
Ben Murdochc7cc0282012-03-05 14:35:55 +0000181
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000182
183enum MutableMode {
184 MUTABLE,
185 IMMUTABLE
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100186};
187
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100188
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000189enum ExternalArrayType {
190 kExternalInt8Array = 1,
191 kExternalUint8Array,
192 kExternalInt16Array,
193 kExternalUint16Array,
194 kExternalInt32Array,
195 kExternalUint32Array,
196 kExternalFloat32Array,
197 kExternalFloat64Array,
198 kExternalUint8ClampedArray,
199};
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000200
201
202static inline bool IsTransitionStoreMode(KeyedAccessStoreMode store_mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000203 return store_mode == STORE_TRANSITION_TO_OBJECT ||
204 store_mode == STORE_TRANSITION_TO_DOUBLE ||
205 store_mode == STORE_AND_GROW_TRANSITION_TO_OBJECT ||
206 store_mode == STORE_AND_GROW_TRANSITION_TO_DOUBLE;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000207}
208
209
210static inline KeyedAccessStoreMode GetNonTransitioningStoreMode(
211 KeyedAccessStoreMode store_mode) {
212 if (store_mode >= STORE_NO_TRANSITION_IGNORE_OUT_OF_BOUNDS) {
213 return store_mode;
214 }
215 if (store_mode >= STORE_AND_GROW_NO_TRANSITION) {
216 return STORE_AND_GROW_NO_TRANSITION;
217 }
218 return STANDARD_STORE;
219}
220
221
222static inline bool IsGrowStoreMode(KeyedAccessStoreMode store_mode) {
223 return store_mode >= STORE_AND_GROW_NO_TRANSITION &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000224 store_mode <= STORE_AND_GROW_TRANSITION_TO_DOUBLE;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000225}
226
Steve Blocka7e24c12009-10-30 11:49:00 +0000227
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400228enum IcCheckType { ELEMENT, PROPERTY };
229
230
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000231// SKIP_WRITE_BARRIER skips the write barrier.
232// UPDATE_WEAK_WRITE_BARRIER skips the marking part of the write barrier and
233// only performs the generational part.
234// UPDATE_WRITE_BARRIER is doing the full barrier, marking and generational.
235enum WriteBarrierMode {
236 SKIP_WRITE_BARRIER,
237 UPDATE_WEAK_WRITE_BARRIER,
238 UPDATE_WRITE_BARRIER
239};
Steve Blocka7e24c12009-10-30 11:49:00 +0000240
241
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242// Indicates whether a value can be loaded as a constant.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000243enum StoreMode { ALLOW_IN_DESCRIPTOR, FORCE_FIELD };
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000244
245
Steve Blocka7e24c12009-10-30 11:49:00 +0000246// PropertyNormalizationMode is used to specify whether to keep
247// inobject properties when normalizing properties of a JSObject.
248enum PropertyNormalizationMode {
249 CLEAR_INOBJECT_PROPERTIES,
250 KEEP_INOBJECT_PROPERTIES
251};
252
253
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000254// Indicates how aggressively the prototype should be optimized. FAST_PROTOTYPE
255// will give the fastest result by tailoring the map to the prototype, but that
256// will cause polymorphism with other objects. REGULAR_PROTOTYPE is to be used
257// (at least for now) when dynamically modifying the prototype chain of an
258// object using __proto__ or Object.setPrototypeOf.
259enum PrototypeOptimizationMode { REGULAR_PROTOTYPE, FAST_PROTOTYPE };
260
261
262// Indicates whether transitions can be added to a source map or not.
263enum TransitionFlag {
264 INSERT_TRANSITION,
265 OMIT_TRANSITION
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100266};
267
268
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000269// Indicates whether the transition is simple: the target map of the transition
270// either extends the current map with a new property, or it modifies the
271// property that was added last to the current map.
272enum SimpleTransitionFlag {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400273 SIMPLE_PROPERTY_TRANSITION,
274 PROPERTY_TRANSITION,
275 SPECIAL_TRANSITION
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276};
277
278
279// Indicates whether we are only interested in the descriptors of a particular
280// map, or in all descriptors in the descriptor array.
281enum DescriptorFlag {
282 ALL_DESCRIPTORS,
283 OWN_DESCRIPTORS
284};
285
286// The GC maintains a bit of information, the MarkingParity, which toggles
287// from odd to even and back every time marking is completed. Incremental
288// marking can visit an object twice during a marking phase, so algorithms that
289// that piggy-back on marking can use the parity to ensure that they only
290// perform an operation on an object once per marking phase: they record the
291// MarkingParity when they visit an object, and only re-visit the object when it
292// is marked again and the MarkingParity changes.
293enum MarkingParity {
294 NO_MARKING_PARITY,
295 ODD_MARKING_PARITY,
296 EVEN_MARKING_PARITY
297};
298
299// ICs store extra state in a Code object. The default extra state is
300// kNoExtraICState.
301typedef int ExtraICState;
302static const ExtraICState kNoExtraICState = 0;
303
Steve Block791712a2010-08-27 10:21:07 +0100304// Instance size sentinel for objects of variable size.
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100305const int kVariableSizeSentinel = 0;
Steve Block791712a2010-08-27 10:21:07 +0100306
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000307// We may store the unsigned bit field as signed Smi value and do not
308// use the sign bit.
309const int kStubMajorKeyBits = 7;
310const int kStubMinorKeyBits = kSmiValueSize - kStubMajorKeyBits - 1;
Steve Block791712a2010-08-27 10:21:07 +0100311
Steve Blocka7e24c12009-10-30 11:49:00 +0000312// All Maps have a field instance_type containing a InstanceType.
313// It describes the type of the instances.
314//
315// As an example, a JavaScript object is a heap object and its map
316// instance_type is JS_OBJECT_TYPE.
317//
318// The names of the string instance types are intended to systematically
Leon Clarkee46be812010-01-19 14:06:41 +0000319// mirror their encoding in the instance_type field of the map. The default
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000320// encoding is considered TWO_BYTE. It is not mentioned in the name. ONE_BYTE
Leon Clarkee46be812010-01-19 14:06:41 +0000321// encoding is mentioned explicitly in the name. Likewise, the default
322// representation is considered sequential. It is not mentioned in the
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100323// name. The other representations (e.g. CONS, EXTERNAL) are explicitly
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000324// mentioned. Finally, the string is either a STRING_TYPE (if it is a normal
325// string) or a INTERNALIZED_STRING_TYPE (if it is a internalized string).
Steve Blocka7e24c12009-10-30 11:49:00 +0000326//
327// NOTE: The following things are some that depend on the string types having
328// instance_types that are less than those of all other types:
329// HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
330// Object::IsString.
331//
332// NOTE: Everything following JS_VALUE_TYPE is considered a
333// JSObject for GC purposes. The first four entries here have typeof
334// 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000335#define INSTANCE_TYPE_LIST(V) \
336 V(STRING_TYPE) \
337 V(ONE_BYTE_STRING_TYPE) \
338 V(CONS_STRING_TYPE) \
339 V(CONS_ONE_BYTE_STRING_TYPE) \
340 V(SLICED_STRING_TYPE) \
341 V(SLICED_ONE_BYTE_STRING_TYPE) \
342 V(EXTERNAL_STRING_TYPE) \
343 V(EXTERNAL_ONE_BYTE_STRING_TYPE) \
344 V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \
345 V(SHORT_EXTERNAL_STRING_TYPE) \
346 V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE) \
347 V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE) \
348 \
349 V(INTERNALIZED_STRING_TYPE) \
350 V(ONE_BYTE_INTERNALIZED_STRING_TYPE) \
351 V(EXTERNAL_INTERNALIZED_STRING_TYPE) \
352 V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \
353 V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \
354 V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE) \
355 V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE) \
356 V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE) \
357 \
358 V(SYMBOL_TYPE) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000359 V(SIMD128_VALUE_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000360 \
361 V(MAP_TYPE) \
362 V(CODE_TYPE) \
363 V(ODDBALL_TYPE) \
364 V(CELL_TYPE) \
365 V(PROPERTY_CELL_TYPE) \
366 \
367 V(HEAP_NUMBER_TYPE) \
368 V(MUTABLE_HEAP_NUMBER_TYPE) \
369 V(FOREIGN_TYPE) \
370 V(BYTE_ARRAY_TYPE) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000371 V(BYTECODE_ARRAY_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000372 V(FREE_SPACE_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000373 \
374 V(FIXED_INT8_ARRAY_TYPE) \
375 V(FIXED_UINT8_ARRAY_TYPE) \
376 V(FIXED_INT16_ARRAY_TYPE) \
377 V(FIXED_UINT16_ARRAY_TYPE) \
378 V(FIXED_INT32_ARRAY_TYPE) \
379 V(FIXED_UINT32_ARRAY_TYPE) \
380 V(FIXED_FLOAT32_ARRAY_TYPE) \
381 V(FIXED_FLOAT64_ARRAY_TYPE) \
382 V(FIXED_UINT8_CLAMPED_ARRAY_TYPE) \
383 \
384 V(FILLER_TYPE) \
385 \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100386 V(ACCESSOR_INFO_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000387 V(ACCESSOR_PAIR_TYPE) \
388 V(ACCESS_CHECK_INFO_TYPE) \
389 V(INTERCEPTOR_INFO_TYPE) \
390 V(CALL_HANDLER_INFO_TYPE) \
391 V(FUNCTION_TEMPLATE_INFO_TYPE) \
392 V(OBJECT_TEMPLATE_INFO_TYPE) \
393 V(SIGNATURE_INFO_TYPE) \
394 V(TYPE_SWITCH_INFO_TYPE) \
395 V(ALLOCATION_MEMENTO_TYPE) \
396 V(ALLOCATION_SITE_TYPE) \
397 V(SCRIPT_TYPE) \
398 V(CODE_CACHE_TYPE) \
399 V(POLYMORPHIC_CODE_CACHE_TYPE) \
400 V(TYPE_FEEDBACK_INFO_TYPE) \
401 V(ALIASED_ARGUMENTS_ENTRY_TYPE) \
402 V(BOX_TYPE) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000403 V(PROTOTYPE_INFO_TYPE) \
404 V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000405 \
406 V(FIXED_ARRAY_TYPE) \
407 V(FIXED_DOUBLE_ARRAY_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000408 V(SHARED_FUNCTION_INFO_TYPE) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400409 V(WEAK_CELL_TYPE) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000410 V(TRANSITION_ARRAY_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000411 \
412 V(JS_MESSAGE_OBJECT_TYPE) \
413 \
414 V(JS_VALUE_TYPE) \
415 V(JS_DATE_TYPE) \
416 V(JS_OBJECT_TYPE) \
417 V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \
418 V(JS_GENERATOR_OBJECT_TYPE) \
419 V(JS_MODULE_TYPE) \
420 V(JS_GLOBAL_OBJECT_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000421 V(JS_GLOBAL_PROXY_TYPE) \
422 V(JS_ARRAY_TYPE) \
423 V(JS_ARRAY_BUFFER_TYPE) \
424 V(JS_TYPED_ARRAY_TYPE) \
425 V(JS_DATA_VIEW_TYPE) \
426 V(JS_PROXY_TYPE) \
427 V(JS_SET_TYPE) \
428 V(JS_MAP_TYPE) \
429 V(JS_SET_ITERATOR_TYPE) \
430 V(JS_MAP_ITERATOR_TYPE) \
431 V(JS_WEAK_MAP_TYPE) \
432 V(JS_WEAK_SET_TYPE) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000433 V(JS_PROMISE_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000434 V(JS_REGEXP_TYPE) \
435 \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000436 V(JS_BOUND_FUNCTION_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000437 V(JS_FUNCTION_TYPE) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000438 V(DEBUG_INFO_TYPE) \
Steve Blocka7e24c12009-10-30 11:49:00 +0000439 V(BREAK_POINT_INFO_TYPE)
Steve Blocka7e24c12009-10-30 11:49:00 +0000440
441
442// Since string types are not consecutive, this macro is used to
443// iterate over them.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000444#define STRING_TYPE_LIST(V) \
445 V(STRING_TYPE, kVariableSizeSentinel, string, String) \
446 V(ONE_BYTE_STRING_TYPE, kVariableSizeSentinel, one_byte_string, \
447 OneByteString) \
448 V(CONS_STRING_TYPE, ConsString::kSize, cons_string, ConsString) \
449 V(CONS_ONE_BYTE_STRING_TYPE, ConsString::kSize, cons_one_byte_string, \
450 ConsOneByteString) \
451 V(SLICED_STRING_TYPE, SlicedString::kSize, sliced_string, SlicedString) \
452 V(SLICED_ONE_BYTE_STRING_TYPE, SlicedString::kSize, sliced_one_byte_string, \
453 SlicedOneByteString) \
454 V(EXTERNAL_STRING_TYPE, ExternalTwoByteString::kSize, external_string, \
455 ExternalString) \
456 V(EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kSize, \
457 external_one_byte_string, ExternalOneByteString) \
458 V(EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, ExternalTwoByteString::kSize, \
459 external_string_with_one_byte_data, ExternalStringWithOneByteData) \
460 V(SHORT_EXTERNAL_STRING_TYPE, ExternalTwoByteString::kShortSize, \
461 short_external_string, ShortExternalString) \
462 V(SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE, ExternalOneByteString::kShortSize, \
463 short_external_one_byte_string, ShortExternalOneByteString) \
464 V(SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE, \
465 ExternalTwoByteString::kShortSize, \
466 short_external_string_with_one_byte_data, \
467 ShortExternalStringWithOneByteData) \
468 \
469 V(INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, internalized_string, \
470 InternalizedString) \
471 V(ONE_BYTE_INTERNALIZED_STRING_TYPE, kVariableSizeSentinel, \
472 one_byte_internalized_string, OneByteInternalizedString) \
473 V(EXTERNAL_INTERNALIZED_STRING_TYPE, ExternalTwoByteString::kSize, \
474 external_internalized_string, ExternalInternalizedString) \
475 V(EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, ExternalOneByteString::kSize, \
476 external_one_byte_internalized_string, ExternalOneByteInternalizedString) \
477 V(EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \
478 ExternalTwoByteString::kSize, \
479 external_internalized_string_with_one_byte_data, \
480 ExternalInternalizedStringWithOneByteData) \
481 V(SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE, \
482 ExternalTwoByteString::kShortSize, short_external_internalized_string, \
483 ShortExternalInternalizedString) \
484 V(SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE, \
485 ExternalOneByteString::kShortSize, \
486 short_external_one_byte_internalized_string, \
487 ShortExternalOneByteInternalizedString) \
488 V(SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE, \
489 ExternalTwoByteString::kShortSize, \
490 short_external_internalized_string_with_one_byte_data, \
491 ShortExternalInternalizedStringWithOneByteData)
Steve Blocka7e24c12009-10-30 11:49:00 +0000492
493// A struct is a simple object a set of object-valued fields. Including an
494// object type in this causes the compiler to generate most of the boilerplate
495// code for the class including allocation and garbage collection routines,
496// casts and predicates. All you need to define is the class, methods and
497// object verification routines. Easy, no?
498//
499// Note that for subtle reasons related to the ordering or numerical values of
500// type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
501// manually.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000502#define STRUCT_LIST(V) \
503 V(BOX, Box, box) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100504 V(ACCESSOR_INFO, AccessorInfo, accessor_info) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000505 V(ACCESSOR_PAIR, AccessorPair, accessor_pair) \
506 V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \
507 V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \
508 V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \
509 V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \
510 V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \
511 V(SCRIPT, Script, script) \
512 V(ALLOCATION_SITE, AllocationSite, allocation_site) \
513 V(ALLOCATION_MEMENTO, AllocationMemento, allocation_memento) \
514 V(CODE_CACHE, CodeCache, code_cache) \
515 V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) \
516 V(TYPE_FEEDBACK_INFO, TypeFeedbackInfo, type_feedback_info) \
517 V(ALIASED_ARGUMENTS_ENTRY, AliasedArgumentsEntry, aliased_arguments_entry) \
518 V(DEBUG_INFO, DebugInfo, debug_info) \
519 V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) \
520 V(PROTOTYPE_INFO, PrototypeInfo, prototype_info) \
521 V(SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION, \
522 SloppyBlockWithEvalContextExtension, \
523 sloppy_block_with_eval_context_extension)
Steve Blocka7e24c12009-10-30 11:49:00 +0000524
525// We use the full 8 bits of the instance_type field to encode heap object
526// instance types. The high-order bit (bit 7) is set if the object is not a
527// string, and cleared if it is a string.
528const uint32_t kIsNotStringMask = 0x80;
529const uint32_t kStringTag = 0x0;
530const uint32_t kNotStringTag = 0x80;
531
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000532// Bit 6 indicates that the object is an internalized string (if set) or not.
533// Bit 7 has to be clear as well.
534const uint32_t kIsNotInternalizedMask = 0x40;
535const uint32_t kNotInternalizedTag = 0x40;
536const uint32_t kInternalizedTag = 0x0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000537
Steve Blocka7e24c12009-10-30 11:49:00 +0000538// If bit 7 is clear then bit 2 indicates whether the string consists of
539// two-byte characters or one-byte characters.
540const uint32_t kStringEncodingMask = 0x4;
541const uint32_t kTwoByteStringTag = 0x0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000542const uint32_t kOneByteStringTag = 0x4;
Steve Blocka7e24c12009-10-30 11:49:00 +0000543
544// If bit 7 is clear, the low-order 2 bits indicate the representation
545// of the string.
546const uint32_t kStringRepresentationMask = 0x03;
547enum StringRepresentationTag {
548 kSeqStringTag = 0x0,
549 kConsStringTag = 0x1,
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000550 kExternalStringTag = 0x2,
551 kSlicedStringTag = 0x3
Steve Blocka7e24c12009-10-30 11:49:00 +0000552};
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000553const uint32_t kIsIndirectStringMask = 0x1;
554const uint32_t kIsIndirectStringTag = 0x1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000555STATIC_ASSERT((kSeqStringTag & kIsIndirectStringMask) == 0); // NOLINT
556STATIC_ASSERT((kExternalStringTag & kIsIndirectStringMask) == 0); // NOLINT
557STATIC_ASSERT((kConsStringTag &
558 kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT
559STATIC_ASSERT((kSlicedStringTag &
560 kIsIndirectStringMask) == kIsIndirectStringTag); // NOLINT
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000561
562// Use this mask to distinguish between cons and slice only after making
563// sure that the string is one of the two (an indirect string).
564const uint32_t kSlicedNotConsMask = kSlicedStringTag & ~kConsStringTag;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000565STATIC_ASSERT(IS_POWER_OF_TWO(kSlicedNotConsMask));
Steve Blocka7e24c12009-10-30 11:49:00 +0000566
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100567// If bit 7 is clear, then bit 3 indicates whether this two-byte
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000568// string actually contains one byte data.
569const uint32_t kOneByteDataHintMask = 0x08;
570const uint32_t kOneByteDataHintTag = 0x08;
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100571
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100572// If bit 7 is clear and string representation indicates an external string,
573// then bit 4 indicates whether the data pointer is cached.
574const uint32_t kShortExternalStringMask = 0x10;
575const uint32_t kShortExternalStringTag = 0x10;
576
Steve Blocka7e24c12009-10-30 11:49:00 +0000577
578// A ConsString with an empty string as the right side is a candidate
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000579// for being shortcut by the garbage collector. We don't allocate any
580// non-flat internalized strings, so we do not shortcut them thereby
581// avoiding turning internalized strings into strings. The bit-masks
582// below contain the internalized bit as additional safety.
583// See heap.cc, mark-compact.cc and objects-visiting.cc.
Steve Blocka7e24c12009-10-30 11:49:00 +0000584const uint32_t kShortcutTypeMask =
585 kIsNotStringMask |
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000586 kIsNotInternalizedMask |
Steve Blocka7e24c12009-10-30 11:49:00 +0000587 kStringRepresentationMask;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000588const uint32_t kShortcutTypeTag = kConsStringTag | kNotInternalizedTag;
589
590static inline bool IsShortcutCandidate(int type) {
591 return ((type & kShortcutTypeMask) == kShortcutTypeTag);
592}
Steve Blocka7e24c12009-10-30 11:49:00 +0000593
594
595enum InstanceType {
Leon Clarkee46be812010-01-19 14:06:41 +0000596 // String types.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000597 INTERNALIZED_STRING_TYPE = kTwoByteStringTag | kSeqStringTag |
598 kInternalizedTag, // FIRST_PRIMITIVE_TYPE
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000599 ONE_BYTE_INTERNALIZED_STRING_TYPE =
600 kOneByteStringTag | kSeqStringTag | kInternalizedTag,
601 EXTERNAL_INTERNALIZED_STRING_TYPE =
602 kTwoByteStringTag | kExternalStringTag | kInternalizedTag,
603 EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE =
604 kOneByteStringTag | kExternalStringTag | kInternalizedTag,
605 EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE =
606 EXTERNAL_INTERNALIZED_STRING_TYPE | kOneByteDataHintTag |
607 kInternalizedTag,
608 SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE = EXTERNAL_INTERNALIZED_STRING_TYPE |
609 kShortExternalStringTag |
610 kInternalizedTag,
611 SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE =
612 EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kShortExternalStringTag |
613 kInternalizedTag,
614 SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE =
615 EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE |
616 kShortExternalStringTag | kInternalizedTag,
617 STRING_TYPE = INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
618 ONE_BYTE_STRING_TYPE =
619 ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
620 CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag | kNotInternalizedTag,
621 CONS_ONE_BYTE_STRING_TYPE =
622 kOneByteStringTag | kConsStringTag | kNotInternalizedTag,
623 SLICED_STRING_TYPE =
624 kTwoByteStringTag | kSlicedStringTag | kNotInternalizedTag,
625 SLICED_ONE_BYTE_STRING_TYPE =
626 kOneByteStringTag | kSlicedStringTag | kNotInternalizedTag,
627 EXTERNAL_STRING_TYPE =
628 EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
629 EXTERNAL_ONE_BYTE_STRING_TYPE =
630 EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
631 EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE =
632 EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE |
633 kNotInternalizedTag,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100634 SHORT_EXTERNAL_STRING_TYPE =
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000635 SHORT_EXTERNAL_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
636 SHORT_EXTERNAL_ONE_BYTE_STRING_TYPE =
637 SHORT_EXTERNAL_ONE_BYTE_INTERNALIZED_STRING_TYPE | kNotInternalizedTag,
638 SHORT_EXTERNAL_STRING_WITH_ONE_BYTE_DATA_TYPE =
639 SHORT_EXTERNAL_INTERNALIZED_STRING_WITH_ONE_BYTE_DATA_TYPE |
640 kNotInternalizedTag,
641
642 // Non-string names
643 SYMBOL_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE, LAST_NAME_TYPE
Steve Blocka7e24c12009-10-30 11:49:00 +0000644
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000645 // Other primitives (cannot contain non-map-word pointers to heap objects).
646 HEAP_NUMBER_TYPE,
647 SIMD128_VALUE_TYPE,
648 ODDBALL_TYPE, // LAST_PRIMITIVE_TYPE
649
Leon Clarkee46be812010-01-19 14:06:41 +0000650 // Objects allocated in their own spaces (never in new space).
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000651 MAP_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000652 CODE_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000653
654 // "Data", objects that cannot contain non-map-word pointers to heap
655 // objects.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000656 MUTABLE_HEAP_NUMBER_TYPE,
Ben Murdoch257744e2011-11-30 15:57:28 +0000657 FOREIGN_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000658 BYTE_ARRAY_TYPE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000659 BYTECODE_ARRAY_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100660 FREE_SPACE_TYPE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000661 FIXED_INT8_ARRAY_TYPE, // FIRST_FIXED_TYPED_ARRAY_TYPE
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000662 FIXED_UINT8_ARRAY_TYPE,
663 FIXED_INT16_ARRAY_TYPE,
664 FIXED_UINT16_ARRAY_TYPE,
665 FIXED_INT32_ARRAY_TYPE,
666 FIXED_UINT32_ARRAY_TYPE,
667 FIXED_FLOAT32_ARRAY_TYPE,
668 FIXED_FLOAT64_ARRAY_TYPE,
669 FIXED_UINT8_CLAMPED_ARRAY_TYPE, // LAST_FIXED_TYPED_ARRAY_TYPE
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000670 FIXED_DOUBLE_ARRAY_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000671 FILLER_TYPE, // LAST_DATA_TYPE
Steve Blocka7e24c12009-10-30 11:49:00 +0000672
Leon Clarkee46be812010-01-19 14:06:41 +0000673 // Structs.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100674 ACCESSOR_INFO_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100675 ACCESSOR_PAIR_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000676 ACCESS_CHECK_INFO_TYPE,
677 INTERCEPTOR_INFO_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000678 CALL_HANDLER_INFO_TYPE,
679 FUNCTION_TEMPLATE_INFO_TYPE,
680 OBJECT_TEMPLATE_INFO_TYPE,
681 SIGNATURE_INFO_TYPE,
682 TYPE_SWITCH_INFO_TYPE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000683 ALLOCATION_SITE_TYPE,
684 ALLOCATION_MEMENTO_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000685 SCRIPT_TYPE,
Steve Block6ded16b2010-05-10 14:33:55 +0100686 CODE_CACHE_TYPE,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000687 POLYMORPHIC_CODE_CACHE_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100688 TYPE_FEEDBACK_INFO_TYPE,
689 ALIASED_ARGUMENTS_ENTRY_TYPE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000690 BOX_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000691 DEBUG_INFO_TYPE,
692 BREAK_POINT_INFO_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000693 FIXED_ARRAY_TYPE,
694 SHARED_FUNCTION_INFO_TYPE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000695 CELL_TYPE,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400696 WEAK_CELL_TYPE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000697 TRANSITION_ARRAY_TYPE,
698 PROPERTY_CELL_TYPE,
699 PROTOTYPE_INFO_TYPE,
700 SLOPPY_BLOCK_WITH_EVAL_CONTEXT_EXTENSION_TYPE,
Leon Clarkee46be812010-01-19 14:06:41 +0000701
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100702 // All the following types are subtypes of JSReceiver, which corresponds to
703 // objects in the JS sense. The first and the last type in this range are
704 // the two forms of function. This organization enables using the same
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000705 // compares for checking the JS_RECEIVER and the NONCALLABLE_JS_OBJECT range.
706 JS_PROXY_TYPE, // FIRST_JS_RECEIVER_TYPE
707 JS_VALUE_TYPE, // FIRST_JS_OBJECT_TYPE
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000708 JS_MESSAGE_OBJECT_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100709 JS_DATE_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000710 JS_OBJECT_TYPE,
711 JS_CONTEXT_EXTENSION_OBJECT_TYPE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000712 JS_GENERATOR_OBJECT_TYPE,
713 JS_MODULE_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000714 JS_GLOBAL_OBJECT_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000715 JS_GLOBAL_PROXY_TYPE,
716 JS_ARRAY_TYPE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000717 JS_ARRAY_BUFFER_TYPE,
718 JS_TYPED_ARRAY_TYPE,
719 JS_DATA_VIEW_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100720 JS_SET_TYPE,
721 JS_MAP_TYPE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000722 JS_SET_ITERATOR_TYPE,
723 JS_MAP_ITERATOR_TYPE,
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000724 JS_WEAK_MAP_TYPE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000725 JS_WEAK_SET_TYPE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000726 JS_PROMISE_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100727 JS_REGEXP_TYPE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000728 JS_BOUND_FUNCTION_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100729 JS_FUNCTION_TYPE, // LAST_JS_OBJECT_TYPE, LAST_JS_RECEIVER_TYPE
Steve Blocka7e24c12009-10-30 11:49:00 +0000730
731 // Pseudo-types
Steve Blocka7e24c12009-10-30 11:49:00 +0000732 FIRST_TYPE = 0x0,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100733 LAST_TYPE = JS_FUNCTION_TYPE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000734 FIRST_NAME_TYPE = FIRST_TYPE,
735 LAST_NAME_TYPE = SYMBOL_TYPE,
736 FIRST_UNIQUE_NAME_TYPE = INTERNALIZED_STRING_TYPE,
737 LAST_UNIQUE_NAME_TYPE = SYMBOL_TYPE,
738 FIRST_NONSTRING_TYPE = SYMBOL_TYPE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000739 FIRST_PRIMITIVE_TYPE = FIRST_NAME_TYPE,
740 LAST_PRIMITIVE_TYPE = ODDBALL_TYPE,
741 FIRST_FUNCTION_TYPE = JS_BOUND_FUNCTION_TYPE,
742 LAST_FUNCTION_TYPE = JS_FUNCTION_TYPE,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000743 // Boundaries for testing for a fixed typed array.
744 FIRST_FIXED_TYPED_ARRAY_TYPE = FIXED_INT8_ARRAY_TYPE,
745 LAST_FIXED_TYPED_ARRAY_TYPE = FIXED_UINT8_CLAMPED_ARRAY_TYPE,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000746 // Boundary for promotion to old space.
Leon Clarkee46be812010-01-19 14:06:41 +0000747 LAST_DATA_TYPE = FILLER_TYPE,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000748 // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy).
749 // Note that there is no range for JSObject or JSProxy, since their subtypes
750 // are not continuous in this enum! The enum ranges instead reflect the
751 // external class names, where proxies are treated as either ordinary objects,
752 // or functions.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000753 FIRST_JS_RECEIVER_TYPE = JS_PROXY_TYPE,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000754 LAST_JS_RECEIVER_TYPE = LAST_TYPE,
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100755 // Boundaries for testing the types represented as JSObject
756 FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE,
757 LAST_JS_OBJECT_TYPE = LAST_TYPE,
Steve Blocka7e24c12009-10-30 11:49:00 +0000758};
759
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000760STATIC_ASSERT(JS_OBJECT_TYPE == Internals::kJSObjectType);
761STATIC_ASSERT(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType);
762STATIC_ASSERT(ODDBALL_TYPE == Internals::kOddballType);
763STATIC_ASSERT(FOREIGN_TYPE == Internals::kForeignType);
764
765
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000766std::ostream& operator<<(std::ostream& os, InstanceType instance_type);
767
768
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000769#define FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(V) \
770 V(FAST_ELEMENTS_SUB_TYPE) \
771 V(DICTIONARY_ELEMENTS_SUB_TYPE) \
772 V(FAST_PROPERTIES_SUB_TYPE) \
773 V(DICTIONARY_PROPERTIES_SUB_TYPE) \
774 V(MAP_CODE_CACHE_SUB_TYPE) \
775 V(SCOPE_INFO_SUB_TYPE) \
776 V(STRING_TABLE_SUB_TYPE) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000777 V(DESCRIPTOR_ARRAY_SUB_TYPE)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000778
779enum FixedArraySubInstanceType {
780#define DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE(name) name,
781 FIXED_ARRAY_SUB_INSTANCE_TYPE_LIST(DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE)
782#undef DEFINE_FIXED_ARRAY_SUB_INSTANCE_TYPE
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000783 LAST_FIXED_ARRAY_SUB_TYPE = DESCRIPTOR_ARRAY_SUB_TYPE
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000784};
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100785
786
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000787// TODO(bmeurer): Remove this in favor of the ComparisonResult below.
Steve Blocka7e24c12009-10-30 11:49:00 +0000788enum CompareResult {
789 LESS = -1,
790 EQUAL = 0,
791 GREATER = 1,
792
793 NOT_EQUAL = GREATER
794};
795
796
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000797// Result of an abstract relational comparison of x and y, implemented according
798// to ES6 section 7.2.11 Abstract Relational Comparison.
799enum class ComparisonResult {
800 kLessThan, // x < y
801 kEqual, // x = y
802 kGreaterThan, // x > y
803 kUndefined // at least one of x or y was undefined or NaN
804};
805
806
807#define DECL_BOOLEAN_ACCESSORS(name) \
808 inline bool name() const; \
809 inline void set_##name(bool value);
810
811#define DECL_INT_ACCESSORS(name) \
812 inline int name() const; \
813 inline void set_##name(int value);
Steve Blocka7e24c12009-10-30 11:49:00 +0000814
815
816#define DECL_ACCESSORS(name, type) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000817 inline type* name() const; \
Steve Blocka7e24c12009-10-30 11:49:00 +0000818 inline void set_##name(type* value, \
819 WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \
820
821
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000822#define DECLARE_CAST(type) \
823 INLINE(static type* cast(Object* object)); \
824 INLINE(static const type* cast(const Object* object));
825
826
827class AccessorPair;
828class AllocationSite;
829class AllocationSiteCreationContext;
830class AllocationSiteUsageContext;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000831class Cell;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400832class ConsString;
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000833class ElementsAccessor;
834class FixedArrayBase;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000835class FunctionLiteral;
836class JSGlobalObject;
837class KeyAccumulator;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400838class LayoutDescriptor;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000839class LiteralsArray;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000840class LookupIterator;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100841class FieldType;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000842class ObjectHashTable;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400843class ObjectVisitor;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000844class PropertyCell;
845class PropertyDescriptor;
846class SafepointEntry;
847class SharedFunctionInfo;
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000848class StringStream;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000849class TypeFeedbackInfo;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000850class TypeFeedbackVector;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400851class WeakCell;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000852class TransitionArray;
853
Steve Blocka7e24c12009-10-30 11:49:00 +0000854
855// A template-ized version of the IsXXX functions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000856template <class C> inline bool Is(Object* obj);
Steve Blocka7e24c12009-10-30 11:49:00 +0000857
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000858#ifdef VERIFY_HEAP
859#define DECLARE_VERIFIER(Name) void Name##Verify();
860#else
861#define DECLARE_VERIFIER(Name)
862#endif
Steve Block053d10c2011-06-13 19:13:29 +0100863
Ben Murdochb0fe1622011-05-05 13:52:32 +0100864#ifdef OBJECT_PRINT
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400865#define DECLARE_PRINTER(Name) void Name##Print(std::ostream& os); // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000866#else
867#define DECLARE_PRINTER(Name)
Ben Murdochb0fe1622011-05-05 13:52:32 +0100868#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000869
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000870#define OBJECT_TYPE_LIST(V) \
871 V(Smi) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100872 V(LayoutDescriptor) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000873 V(HeapObject) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100874 V(Primitive) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000875 V(Number)
Ben Murdochb8e0da22011-05-16 14:20:40 +0100876
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000877#define HEAP_OBJECT_TYPE_LIST(V) \
878 V(HeapNumber) \
879 V(MutableHeapNumber) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000880 V(Simd128Value) \
881 V(Float32x4) \
882 V(Int32x4) \
883 V(Uint32x4) \
884 V(Bool32x4) \
885 V(Int16x8) \
886 V(Uint16x8) \
887 V(Bool16x8) \
888 V(Int8x16) \
889 V(Uint8x16) \
890 V(Bool8x16) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000891 V(Name) \
892 V(UniqueName) \
893 V(String) \
894 V(SeqString) \
895 V(ExternalString) \
896 V(ConsString) \
897 V(SlicedString) \
898 V(ExternalTwoByteString) \
899 V(ExternalOneByteString) \
900 V(SeqTwoByteString) \
901 V(SeqOneByteString) \
902 V(InternalizedString) \
903 V(Symbol) \
904 \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000905 V(FixedTypedArrayBase) \
906 V(FixedUint8Array) \
907 V(FixedInt8Array) \
908 V(FixedUint16Array) \
909 V(FixedInt16Array) \
910 V(FixedUint32Array) \
911 V(FixedInt32Array) \
912 V(FixedFloat32Array) \
913 V(FixedFloat64Array) \
914 V(FixedUint8ClampedArray) \
915 V(ByteArray) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000916 V(BytecodeArray) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000917 V(FreeSpace) \
918 V(JSReceiver) \
919 V(JSObject) \
920 V(JSContextExtensionObject) \
921 V(JSGeneratorObject) \
922 V(JSModule) \
923 V(Map) \
924 V(DescriptorArray) \
925 V(TransitionArray) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000926 V(LiteralsArray) \
927 V(TypeFeedbackMetadata) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000928 V(TypeFeedbackVector) \
929 V(DeoptimizationInputData) \
930 V(DeoptimizationOutputData) \
931 V(DependentCode) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000932 V(HandlerTable) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000933 V(FixedArray) \
934 V(FixedDoubleArray) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400935 V(WeakFixedArray) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000936 V(ArrayList) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000937 V(Context) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400938 V(ScriptContextTable) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000939 V(NativeContext) \
940 V(ScopeInfo) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000941 V(JSBoundFunction) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000942 V(JSFunction) \
943 V(Code) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100944 V(AbstractCode) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000945 V(Oddball) \
946 V(SharedFunctionInfo) \
947 V(JSValue) \
948 V(JSDate) \
949 V(JSMessageObject) \
950 V(StringWrapper) \
951 V(Foreign) \
952 V(Boolean) \
953 V(JSArray) \
954 V(JSArrayBuffer) \
955 V(JSArrayBufferView) \
956 V(JSTypedArray) \
957 V(JSDataView) \
958 V(JSProxy) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000959 V(JSSet) \
960 V(JSMap) \
961 V(JSSetIterator) \
962 V(JSMapIterator) \
963 V(JSWeakCollection) \
964 V(JSWeakMap) \
965 V(JSWeakSet) \
966 V(JSRegExp) \
967 V(HashTable) \
968 V(Dictionary) \
969 V(StringTable) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000970 V(NormalizedMapCache) \
971 V(CompilationCacheTable) \
972 V(CodeCacheHashTable) \
973 V(PolymorphicCodeCacheHashTable) \
974 V(MapCache) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000975 V(JSGlobalObject) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000976 V(JSGlobalProxy) \
977 V(UndetectableObject) \
978 V(AccessCheckNeeded) \
Ben Murdoch097c5b22016-05-18 11:27:45 +0100979 V(Callable) \
980 V(Function) \
981 V(Constructor) \
982 V(TemplateInfo) \
983 V(Filler) \
984 V(FixedArrayBase) \
985 V(External) \
986 V(Struct) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000987 V(Cell) \
988 V(PropertyCell) \
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400989 V(WeakCell) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000990 V(ObjectHashTable) \
991 V(WeakHashTable) \
992 V(OrderedHashTable)
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100993
Ben Murdoch097c5b22016-05-18 11:27:45 +0100994#define ODDBALL_LIST(V) \
995 V(Undefined) \
996 V(Null) \
997 V(TheHole) \
998 V(Exception) \
999 V(Uninitialized) \
1000 V(True) \
1001 V(False) \
1002 V(ArgumentsMarker)
1003
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001004// The element types selection for CreateListFromArrayLike.
1005enum class ElementTypes { kAll, kStringAndSymbol };
1006
Steve Blocka7e24c12009-10-30 11:49:00 +00001007// Object is the abstract superclass for all classes in the
1008// object hierarchy.
1009// Object does not use any virtual functions to avoid the
1010// allocation of the C++ vtable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001011// Since both Smi and HeapObject are subclasses of Object no
Steve Blocka7e24c12009-10-30 11:49:00 +00001012// data members can be present in Object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001013class Object {
Steve Blocka7e24c12009-10-30 11:49:00 +00001014 public:
1015 // Type testing.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001016 bool IsObject() const { return true; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001017
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001018#define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const);
Ben Murdochb8e0da22011-05-16 14:20:40 +01001019 OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
1020 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
Ben Murdoch097c5b22016-05-18 11:27:45 +01001021 ODDBALL_LIST(IS_TYPE_FUNCTION_DECL)
Ben Murdochb8e0da22011-05-16 14:20:40 +01001022#undef IS_TYPE_FUNCTION_DECL
Steve Blocka7e24c12009-10-30 11:49:00 +00001023
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001024 // A non-keyed store is of the form a.x = foo or a["x"] = foo whereas
1025 // a keyed store is of the form a[expression] = foo.
1026 enum StoreFromKeyed {
1027 MAY_BE_STORE_FROM_KEYED,
1028 CERTAINLY_NOT_STORE_FROM_KEYED
1029 };
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001030
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001031 enum ShouldThrow { THROW_ON_ERROR, DONT_THROW };
1032
1033#define RETURN_FAILURE(isolate, should_throw, call) \
1034 do { \
1035 if ((should_throw) == DONT_THROW) { \
1036 return Just(false); \
1037 } else { \
1038 isolate->Throw(*isolate->factory()->call); \
1039 return Nothing<bool>(); \
1040 } \
1041 } while (false)
1042
1043#define MAYBE_RETURN(call, value) \
1044 do { \
1045 if ((call).IsNothing()) return value; \
1046 } while (false)
1047
1048#define MAYBE_RETURN_NULL(call) MAYBE_RETURN(call, MaybeHandle<Object>())
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001049
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001050#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \
1051 INLINE(bool Is##Name() const);
Steve Blocka7e24c12009-10-30 11:49:00 +00001052 STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
1053#undef DECLARE_STRUCT_PREDICATE
1054
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001055 // ES6, section 7.2.2 IsArray. NOT to be confused with %_IsArray.
1056 MUST_USE_RESULT static Maybe<bool> IsArray(Handle<Object> object);
1057
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001058 INLINE(bool IsNameDictionary() const);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001059 INLINE(bool IsGlobalDictionary() const);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001060 INLINE(bool IsSeededNumberDictionary() const);
1061 INLINE(bool IsUnseededNumberDictionary() const);
1062 INLINE(bool IsOrderedHashSet() const);
1063 INLINE(bool IsOrderedHashMap() const);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001064 static bool IsPromise(Handle<Object> object);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001065
Steve Blocka7e24c12009-10-30 11:49:00 +00001066 // Extract the number.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001067 inline double Number() const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001068 INLINE(bool IsNaN() const);
1069 INLINE(bool IsMinusZero() const);
1070 bool ToInt32(int32_t* value);
1071 bool ToUint32(uint32_t* value);
1072
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001073 inline Representation OptimalRepresentation();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001074
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001075 inline ElementsKind OptimalElementsKind();
1076
1077 inline bool FitsRepresentation(Representation representation);
1078
1079 // Checks whether two valid primitive encodings of a property name resolve to
1080 // the same logical property. E.g., the smi 1, the string "1" and the double
1081 // 1 all refer to the same property, so this helper will return true.
1082 inline bool KeyEquals(Object* other);
1083
1084 inline bool FilterKey(PropertyFilter filter);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001085
Ben Murdoch097c5b22016-05-18 11:27:45 +01001086 Handle<FieldType> OptimalType(Isolate* isolate,
1087 Representation representation);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001088
1089 inline static Handle<Object> NewStorageFor(Isolate* isolate,
1090 Handle<Object> object,
1091 Representation representation);
1092
1093 inline static Handle<Object> WrapForRead(Isolate* isolate,
1094 Handle<Object> object,
1095 Representation representation);
Steve Blocka7e24c12009-10-30 11:49:00 +00001096
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001097 // Returns true if the object is of the correct type to be used as a
1098 // implementation of a JSObject's elements.
1099 inline bool HasValidElements();
1100
Steve Blocka7e24c12009-10-30 11:49:00 +00001101 inline bool HasSpecificClassOf(String* name);
1102
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001103 bool BooleanValue(); // ECMA-262 9.2.
Steve Blocka7e24c12009-10-30 11:49:00 +00001104
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001105 // ES6 section 7.2.11 Abstract Relational Comparison
Ben Murdoch097c5b22016-05-18 11:27:45 +01001106 MUST_USE_RESULT static Maybe<ComparisonResult> Compare(Handle<Object> x,
1107 Handle<Object> y);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001108
1109 // ES6 section 7.2.12 Abstract Equality Comparison
1110 MUST_USE_RESULT static Maybe<bool> Equals(Handle<Object> x, Handle<Object> y);
1111
1112 // ES6 section 7.2.13 Strict Equality Comparison
1113 bool StrictEquals(Object* that);
1114
Steve Blocka7e24c12009-10-30 11:49:00 +00001115 // Convert to a JSObject if needed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001116 // native_context is used when creating wrapper object.
Ben Murdoch097c5b22016-05-18 11:27:45 +01001117 MUST_USE_RESULT static inline MaybeHandle<JSReceiver> ToObject(
1118 Isolate* isolate, Handle<Object> object);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001119 MUST_USE_RESULT static MaybeHandle<JSReceiver> ToObject(
1120 Isolate* isolate, Handle<Object> object, Handle<Context> context);
Steve Blocka7e24c12009-10-30 11:49:00 +00001121
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001122 // ES6 section 7.1.14 ToPropertyKey
1123 MUST_USE_RESULT static MaybeHandle<Name> ToName(Isolate* isolate,
1124 Handle<Object> input);
Steve Blocka7e24c12009-10-30 11:49:00 +00001125
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001126 // ES6 section 7.1.1 ToPrimitive
1127 MUST_USE_RESULT static inline MaybeHandle<Object> ToPrimitive(
1128 Handle<Object> input, ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
Steve Blocka7e24c12009-10-30 11:49:00 +00001129
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001130 // ES6 section 7.1.3 ToNumber
1131 MUST_USE_RESULT static MaybeHandle<Object> ToNumber(Handle<Object> input);
1132
1133 // ES6 section 7.1.4 ToInteger
1134 MUST_USE_RESULT static MaybeHandle<Object> ToInteger(Isolate* isolate,
1135 Handle<Object> input);
1136
1137 // ES6 section 7.1.5 ToInt32
1138 MUST_USE_RESULT static MaybeHandle<Object> ToInt32(Isolate* isolate,
1139 Handle<Object> input);
1140
1141 // ES6 section 7.1.6 ToUint32
1142 MUST_USE_RESULT static MaybeHandle<Object> ToUint32(Isolate* isolate,
1143 Handle<Object> input);
1144
1145 // ES6 section 7.1.12 ToString
1146 MUST_USE_RESULT static MaybeHandle<String> ToString(Isolate* isolate,
1147 Handle<Object> input);
1148
1149 // ES6 section 7.1.15 ToLength
1150 MUST_USE_RESULT static MaybeHandle<Object> ToLength(Isolate* isolate,
1151 Handle<Object> input);
1152
1153 // ES6 section 7.3.9 GetMethod
1154 MUST_USE_RESULT static MaybeHandle<Object> GetMethod(
1155 Handle<JSReceiver> receiver, Handle<Name> name);
1156
1157 // ES6 section 7.3.17 CreateListFromArrayLike
1158 MUST_USE_RESULT static MaybeHandle<FixedArray> CreateListFromArrayLike(
1159 Isolate* isolate, Handle<Object> object, ElementTypes element_types);
1160
1161 // Check whether |object| is an instance of Error or NativeError.
1162 static bool IsErrorObject(Isolate* isolate, Handle<Object> object);
1163
1164 // ES6 section 12.5.6 The typeof Operator
1165 static Handle<String> TypeOf(Isolate* isolate, Handle<Object> object);
1166
1167 // ES6 section 12.6 Multiplicative Operators
Ben Murdoch097c5b22016-05-18 11:27:45 +01001168 MUST_USE_RESULT static MaybeHandle<Object> Multiply(Isolate* isolate,
1169 Handle<Object> lhs,
1170 Handle<Object> rhs);
1171 MUST_USE_RESULT static MaybeHandle<Object> Divide(Isolate* isolate,
1172 Handle<Object> lhs,
1173 Handle<Object> rhs);
1174 MUST_USE_RESULT static MaybeHandle<Object> Modulus(Isolate* isolate,
1175 Handle<Object> lhs,
1176 Handle<Object> rhs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001177
1178 // ES6 section 12.7 Additive Operators
Ben Murdoch097c5b22016-05-18 11:27:45 +01001179 MUST_USE_RESULT static MaybeHandle<Object> Add(Isolate* isolate,
1180 Handle<Object> lhs,
1181 Handle<Object> rhs);
1182 MUST_USE_RESULT static MaybeHandle<Object> Subtract(Isolate* isolate,
1183 Handle<Object> lhs,
1184 Handle<Object> rhs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001185
1186 // ES6 section 12.8 Bitwise Shift Operators
Ben Murdoch097c5b22016-05-18 11:27:45 +01001187 MUST_USE_RESULT static MaybeHandle<Object> ShiftLeft(Isolate* isolate,
1188 Handle<Object> lhs,
1189 Handle<Object> rhs);
1190 MUST_USE_RESULT static MaybeHandle<Object> ShiftRight(Isolate* isolate,
1191 Handle<Object> lhs,
1192 Handle<Object> rhs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001193 MUST_USE_RESULT static MaybeHandle<Object> ShiftRightLogical(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001194 Isolate* isolate, Handle<Object> lhs, Handle<Object> rhs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001195
1196 // ES6 section 12.9 Relational Operators
Ben Murdoch097c5b22016-05-18 11:27:45 +01001197 MUST_USE_RESULT static inline Maybe<bool> GreaterThan(Handle<Object> x,
1198 Handle<Object> y);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001199 MUST_USE_RESULT static inline Maybe<bool> GreaterThanOrEqual(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001200 Handle<Object> x, Handle<Object> y);
1201 MUST_USE_RESULT static inline Maybe<bool> LessThan(Handle<Object> x,
1202 Handle<Object> y);
1203 MUST_USE_RESULT static inline Maybe<bool> LessThanOrEqual(Handle<Object> x,
1204 Handle<Object> y);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001205
1206 // ES6 section 12.11 Binary Bitwise Operators
Ben Murdoch097c5b22016-05-18 11:27:45 +01001207 MUST_USE_RESULT static MaybeHandle<Object> BitwiseAnd(Isolate* isolate,
1208 Handle<Object> lhs,
1209 Handle<Object> rhs);
1210 MUST_USE_RESULT static MaybeHandle<Object> BitwiseOr(Isolate* isolate,
1211 Handle<Object> lhs,
1212 Handle<Object> rhs);
1213 MUST_USE_RESULT static MaybeHandle<Object> BitwiseXor(Isolate* isolate,
1214 Handle<Object> lhs,
1215 Handle<Object> rhs);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001216
Ben Murdoch097c5b22016-05-18 11:27:45 +01001217 MUST_USE_RESULT static MaybeHandle<Object> GetProperty(LookupIterator* it);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001218
1219 // ES6 [[Set]] (when passed DONT_THROW)
1220 // Invariants for this and related functions (unless stated otherwise):
1221 // 1) When the result is Nothing, an exception is pending.
1222 // 2) When passed THROW_ON_ERROR, the result is never Just(false).
1223 // In some cases, an exception is thrown regardless of the ShouldThrow
1224 // argument. These cases are either in accordance with the spec or not
1225 // covered by it (eg., concerning API callbacks).
1226 MUST_USE_RESULT static Maybe<bool> SetProperty(LookupIterator* it,
1227 Handle<Object> value,
1228 LanguageMode language_mode,
1229 StoreFromKeyed store_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001230 MUST_USE_RESULT static MaybeHandle<Object> SetProperty(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001231 Handle<Object> object, Handle<Name> name, Handle<Object> value,
1232 LanguageMode language_mode,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001233 StoreFromKeyed store_mode = MAY_BE_STORE_FROM_KEYED);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001234
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001235 MUST_USE_RESULT static Maybe<bool> SetSuperProperty(
1236 LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
1237 StoreFromKeyed store_mode);
1238
1239 MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001240 LookupIterator* it);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001241 MUST_USE_RESULT static MaybeHandle<Object> ReadAbsentProperty(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001242 Isolate* isolate, Handle<Object> receiver, Handle<Object> name);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001243 MUST_USE_RESULT static Maybe<bool> CannotCreateProperty(
1244 Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
1245 Handle<Object> value, ShouldThrow should_throw);
1246 MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty(
1247 LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
1248 MUST_USE_RESULT static Maybe<bool> WriteToReadOnlyProperty(
1249 Isolate* isolate, Handle<Object> receiver, Handle<Object> name,
1250 Handle<Object> value, ShouldThrow should_throw);
1251 MUST_USE_RESULT static Maybe<bool> RedefineIncompatibleProperty(
1252 Isolate* isolate, Handle<Object> name, Handle<Object> value,
1253 ShouldThrow should_throw);
1254 MUST_USE_RESULT static Maybe<bool> SetDataProperty(LookupIterator* it,
1255 Handle<Object> value);
1256 MUST_USE_RESULT static Maybe<bool> AddDataProperty(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001257 LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001258 ShouldThrow should_throw, StoreFromKeyed store_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001259 MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001260 Handle<Object> object, Handle<Name> name);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001261 MUST_USE_RESULT static inline MaybeHandle<Object> GetPropertyOrElement(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001262 Handle<Object> receiver, Handle<Name> name, Handle<JSReceiver> holder);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001263 MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001264 Isolate* isolate, Handle<Object> object, const char* key);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001265 MUST_USE_RESULT static inline MaybeHandle<Object> GetProperty(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001266 Handle<Object> object, Handle<Name> name);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001267
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001268 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithAccessor(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001269 LookupIterator* it);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001270 MUST_USE_RESULT static Maybe<bool> SetPropertyWithAccessor(
1271 LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00001272
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001273 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithDefinedGetter(
1274 Handle<Object> receiver,
1275 Handle<JSReceiver> getter);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001276 MUST_USE_RESULT static Maybe<bool> SetPropertyWithDefinedSetter(
1277 Handle<Object> receiver, Handle<JSReceiver> setter, Handle<Object> value,
1278 ShouldThrow should_throw);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001279
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001280 MUST_USE_RESULT static inline MaybeHandle<Object> GetElement(
Ben Murdoch097c5b22016-05-18 11:27:45 +01001281 Isolate* isolate, Handle<Object> object, uint32_t index);
Steve Blocka7e24c12009-10-30 11:49:00 +00001282
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001283 MUST_USE_RESULT static inline MaybeHandle<Object> SetElement(
1284 Isolate* isolate, Handle<Object> object, uint32_t index,
1285 Handle<Object> value, LanguageMode language_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001286
1287 // Returns the permanent hash code associated with this object. May return
1288 // undefined if not yet created.
1289 Object* GetHash();
Steve Blocka7e24c12009-10-30 11:49:00 +00001290
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001291 // Returns undefined for JSObjects, but returns the hash code for simple
1292 // objects. This avoids a double lookup in the cases where we know we will
1293 // add the hash to the JSObject if it does not already exist.
1294 Object* GetSimpleHash();
1295
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001296 // Returns the permanent hash code associated with this object depending on
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001297 // the actual object type. May create and store a hash code if needed and none
1298 // exists.
1299 static Handle<Smi> GetOrCreateHash(Isolate* isolate, Handle<Object> object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001300
1301 // Checks whether this object has the same value as the given one. This
1302 // function is implemented according to ES5, section 9.12 and can be used
1303 // to implement the Harmony "egal" function.
1304 bool SameValue(Object* other);
1305
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001306 // Checks whether this object has the same value as the given one.
1307 // +0 and -0 are treated equal. Everything else is the same as SameValue.
1308 // This function is implemented according to ES6, section 7.2.4 and is used
1309 // by ES6 Map and Set.
1310 bool SameValueZero(Object* other);
1311
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001312 // ES6 section 9.4.2.3 ArraySpeciesCreate (part of it)
1313 MUST_USE_RESULT static MaybeHandle<Object> ArraySpeciesConstructor(
1314 Isolate* isolate, Handle<Object> original_array);
1315
1316 // Tries to convert an object to an array length. Returns true and sets the
1317 // output parameter if it succeeds.
1318 inline bool ToArrayLength(uint32_t* index);
1319
1320 // Tries to convert an object to an array index. Returns true and sets the
1321 // output parameter if it succeeds. Equivalent to ToArrayLength, but does not
1322 // allow kMaxUInt32.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001323 inline bool ToArrayIndex(uint32_t* index);
1324
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001325 DECLARE_VERIFIER(Object)
1326#ifdef VERIFY_HEAP
Steve Blocka7e24c12009-10-30 11:49:00 +00001327 // Verify a pointer is a valid object pointer.
1328 static void VerifyPointer(Object* p);
1329#endif
1330
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001331 inline void VerifyApiCallResultType();
1332
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001333 // ES6 19.1.3.6 Object.prototype.toString
1334 MUST_USE_RESULT static MaybeHandle<String> ObjectProtoToString(
1335 Isolate* isolate, Handle<Object> object);
1336
Steve Blocka7e24c12009-10-30 11:49:00 +00001337 // Prints this object without details.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001338 void ShortPrint(FILE* out = stdout);
Steve Blocka7e24c12009-10-30 11:49:00 +00001339
1340 // Prints this object without details to a message accumulator.
1341 void ShortPrint(StringStream* accumulator);
1342
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001343 void ShortPrint(std::ostream& os); // NOLINT
1344
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001345 DECLARE_CAST(Object)
Steve Blocka7e24c12009-10-30 11:49:00 +00001346
1347 // Layout description.
1348 static const int kHeaderSize = 0; // Object does not take up any space.
1349
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001350#ifdef OBJECT_PRINT
1351 // For our gdb macros, we should perhaps change these in the future.
1352 void Print();
1353
1354 // Prints this object with details.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001355 void Print(std::ostream& os); // NOLINT
1356#else
1357 void Print() { ShortPrint(); }
1358 void Print(std::ostream& os) { ShortPrint(os); } // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001359#endif
1360
Steve Blocka7e24c12009-10-30 11:49:00 +00001361 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001362 friend class LookupIterator;
Ben Murdoch097c5b22016-05-18 11:27:45 +01001363 friend class StringStream;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001364
1365 // Return the map of the root of object's prototype chain.
1366 Map* GetRootMap(Isolate* isolate);
1367
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001368 // Helper for SetProperty and SetSuperProperty.
1369 // Return value is only meaningful if [found] is set to true on return.
1370 MUST_USE_RESULT static Maybe<bool> SetPropertyInternal(
1371 LookupIterator* it, Handle<Object> value, LanguageMode language_mode,
1372 StoreFromKeyed store_mode, bool* found);
1373
Steve Blocka7e24c12009-10-30 11:49:00 +00001374 DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
1375};
1376
1377
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001378// In objects.h to be usable without objects-inl.h inclusion.
1379bool Object::IsSmi() const { return HAS_SMI_TAG(this); }
1380bool Object::IsHeapObject() const { return Internals::HasHeapObjectTag(this); }
1381
1382
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001383struct Brief {
1384 explicit Brief(const Object* const v) : value(v) {}
1385 const Object* value;
1386};
1387
1388
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001389std::ostream& operator<<(std::ostream& os, const Brief& v);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001390
1391
Steve Blocka7e24c12009-10-30 11:49:00 +00001392// Smi represents integer Numbers that can be stored in 31 bits.
1393// Smis are immediate which means they are NOT allocated in the heap.
Steve Blocka7e24c12009-10-30 11:49:00 +00001394// The this pointer has the following format: [31 bit signed int] 0
Steve Block3ce2e202009-11-05 08:53:23 +00001395// For long smis it has the following format:
1396// [32 bit signed int] [31 bits zero padding] 0
1397// Smi stands for small integer.
Steve Blocka7e24c12009-10-30 11:49:00 +00001398class Smi: public Object {
1399 public:
1400 // Returns the integer value.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001401 inline int value() const { return Internals::SmiValue(this); }
Steve Blocka7e24c12009-10-30 11:49:00 +00001402
1403 // Convert a value to a Smi object.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001404 static inline Smi* FromInt(int value) {
1405 DCHECK(Smi::IsValid(value));
1406 return reinterpret_cast<Smi*>(Internals::IntToSmi(value));
1407 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001408
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001409 static inline Smi* FromIntptr(intptr_t value) {
1410 DCHECK(Smi::IsValid(value));
1411 int smi_shift_bits = kSmiTagSize + kSmiShiftSize;
1412 return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag);
1413 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001414
1415 // Returns whether value can be represented in a Smi.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001416 static inline bool IsValid(intptr_t value) {
1417 bool result = Internals::IsValidSmi(value);
1418 DCHECK_EQ(result, value >= kMinValue && value <= kMaxValue);
1419 return result;
1420 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001421
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001422 DECLARE_CAST(Smi)
Steve Blocka7e24c12009-10-30 11:49:00 +00001423
1424 // Dispatched behavior.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001425 void SmiPrint(std::ostream& os) const; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001426 DECLARE_VERIFIER(Smi)
Steve Blocka7e24c12009-10-30 11:49:00 +00001427
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001428 static const int kMinValue =
1429 (static_cast<unsigned int>(-1)) << (kSmiValueSize - 1);
Steve Block3ce2e202009-11-05 08:53:23 +00001430 static const int kMaxValue = -(kMinValue + 1);
Steve Blocka7e24c12009-10-30 11:49:00 +00001431
1432 private:
1433 DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);
1434};
1435
1436
Steve Blocka7e24c12009-10-30 11:49:00 +00001437// Heap objects typically have a map pointer in their first word. However,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001438// during GC other data (e.g. mark bits, forwarding addresses) is sometimes
Steve Blocka7e24c12009-10-30 11:49:00 +00001439// encoded in the first word. The class MapWord is an abstraction of the
1440// value in a heap object's first word.
1441class MapWord BASE_EMBEDDED {
1442 public:
1443 // Normal state: the map word contains a map pointer.
1444
1445 // Create a map word from a map pointer.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001446 static inline MapWord FromMap(const Map* map);
Steve Blocka7e24c12009-10-30 11:49:00 +00001447
1448 // View this map word as a map pointer.
1449 inline Map* ToMap();
1450
1451
1452 // Scavenge collection: the map word of live objects in the from space
1453 // contains a forwarding address (a heap object pointer in the to space).
1454
1455 // True if this map word is a forwarding address for a scavenge
1456 // collection. Only valid during a scavenge collection (specifically,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001457 // when all map words are heap object pointers, i.e. not during a full GC).
Steve Blocka7e24c12009-10-30 11:49:00 +00001458 inline bool IsForwardingAddress();
1459
1460 // Create a map word from a forwarding address.
1461 static inline MapWord FromForwardingAddress(HeapObject* object);
1462
1463 // View this map word as a forwarding address.
1464 inline HeapObject* ToForwardingAddress();
1465
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001466 static inline MapWord FromRawValue(uintptr_t value) {
1467 return MapWord(value);
1468 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001469
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001470 inline uintptr_t ToRawValue() {
1471 return value_;
1472 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001473
1474 private:
1475 // HeapObject calls the private constructor and directly reads the value.
1476 friend class HeapObject;
1477
1478 explicit MapWord(uintptr_t value) : value_(value) {}
1479
1480 uintptr_t value_;
1481};
1482
1483
1484// HeapObject is the superclass for all classes describing heap allocated
1485// objects.
1486class HeapObject: public Object {
1487 public:
1488 // [map]: Contains a map which contains the object's reflective
1489 // information.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001490 inline Map* map() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00001491 inline void set_map(Map* value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001492 // The no-write-barrier version. This is OK if the object is white and in
1493 // new space, or if the value is an immortal immutable object, like the maps
1494 // of primitive (non-JS) objects like strings, heap numbers etc.
1495 inline void set_map_no_write_barrier(Map* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00001496
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001497 // Get the map using acquire load.
1498 inline Map* synchronized_map();
1499 inline MapWord synchronized_map_word() const;
1500
1501 // Set the map using release store
1502 inline void synchronized_set_map(Map* value);
1503 inline void synchronized_set_map_no_write_barrier(Map* value);
1504 inline void synchronized_set_map_word(MapWord map_word);
1505
Steve Blocka7e24c12009-10-30 11:49:00 +00001506 // During garbage collection, the map word of a heap object does not
1507 // necessarily contain a map pointer.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001508 inline MapWord map_word() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00001509 inline void set_map_word(MapWord map_word);
1510
Steve Block44f0eee2011-05-26 01:26:41 +01001511 // The Heap the object was allocated in. Used also to access Isolate.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001512 inline Heap* GetHeap() const;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001513
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001514 // Convenience method to get current isolate.
1515 inline Isolate* GetIsolate() const;
Steve Block44f0eee2011-05-26 01:26:41 +01001516
Ben Murdoch097c5b22016-05-18 11:27:45 +01001517#define IS_TYPE_FUNCTION_DECL(type_) INLINE(bool Is##type_() const);
1518 HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
1519 ODDBALL_LIST(IS_TYPE_FUNCTION_DECL)
1520#undef IS_TYPE_FUNCTION_DECL
1521#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) \
1522 INLINE(bool Is##Name() const);
1523 STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
1524#undef DECLARE_STRUCT_PREDICATE
1525
Steve Blocka7e24c12009-10-30 11:49:00 +00001526 // Converts an address to a HeapObject pointer.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001527 static inline HeapObject* FromAddress(Address address) {
1528 DCHECK_TAG_ALIGNED(address);
1529 return reinterpret_cast<HeapObject*>(address + kHeapObjectTag);
1530 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001531
1532 // Returns the address of this HeapObject.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001533 inline Address address() {
1534 return reinterpret_cast<Address>(this) - kHeapObjectTag;
1535 }
Steve Blocka7e24c12009-10-30 11:49:00 +00001536
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001537 // Iterates over pointers contained in the object (including the Map).
1538 // If it's not performance critical iteration use the non-templatized
1539 // version.
Steve Blocka7e24c12009-10-30 11:49:00 +00001540 void Iterate(ObjectVisitor* v);
1541
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001542 template <typename ObjectVisitor>
1543 inline void IterateFast(ObjectVisitor* v);
1544
Steve Blocka7e24c12009-10-30 11:49:00 +00001545 // Iterates over all pointers contained in the object except the
1546 // first map pointer. The object type is given in the first
1547 // parameter. This function does not access the map pointer in the
1548 // object, and so is safe to call while the map pointer is modified.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001549 // If it's not performance critical iteration use the non-templatized
1550 // version.
1551 void IterateBody(ObjectVisitor* v);
Steve Blocka7e24c12009-10-30 11:49:00 +00001552 void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1553
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001554 template <typename ObjectVisitor>
1555 inline void IterateBodyFast(ObjectVisitor* v);
1556
1557 template <typename ObjectVisitor>
1558 inline void IterateBodyFast(InstanceType type, int object_size,
1559 ObjectVisitor* v);
1560
1561 // Returns true if the object contains a tagged value at given offset.
1562 // It is used for invalid slots filtering. If the offset points outside
1563 // of the object or to the map word, the result is UNDEFINED (!!!).
1564 bool IsValidSlot(int offset);
1565
Steve Blocka7e24c12009-10-30 11:49:00 +00001566 // Returns the heap object's size in bytes
1567 inline int Size();
1568
1569 // Given a heap object's map pointer, returns the heap size in bytes
1570 // Useful when the map pointer field is used for other purposes.
1571 // GC internal.
1572 inline int SizeFromMap(Map* map);
1573
Steve Blocka7e24c12009-10-30 11:49:00 +00001574 // Returns the field at offset in obj, as a read/write Object* reference.
1575 // Does no checking, and is safe to use during GC, while maps are invalid.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001576 // Does not invoke write barrier, so should only be assigned to
Steve Blocka7e24c12009-10-30 11:49:00 +00001577 // during marking GC.
1578 static inline Object** RawField(HeapObject* obj, int offset);
1579
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001580 // Adds the |code| object related to |name| to the code cache of this map. If
1581 // this map is a dictionary map that is shared, the map copied and installed
1582 // onto the object.
1583 static void UpdateMapCodeCache(Handle<HeapObject> object,
1584 Handle<Name> name,
1585 Handle<Code> code);
1586
1587 DECLARE_CAST(HeapObject)
Steve Blocka7e24c12009-10-30 11:49:00 +00001588
Leon Clarke4515c472010-02-03 11:58:03 +00001589 // Return the write barrier mode for this. Callers of this function
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001590 // must be able to present a reference to an DisallowHeapAllocation
Leon Clarke4515c472010-02-03 11:58:03 +00001591 // object as a sign that they are not going to use this function
1592 // from code that allocates and thus invalidates the returned write
1593 // barrier mode.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001594 inline WriteBarrierMode GetWriteBarrierMode(
1595 const DisallowHeapAllocation& promise);
Steve Blocka7e24c12009-10-30 11:49:00 +00001596
1597 // Dispatched behavior.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001598 void HeapObjectShortPrint(std::ostream& os); // NOLINT
Ben Murdochb0fe1622011-05-05 13:52:32 +01001599#ifdef OBJECT_PRINT
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001600 void PrintHeader(std::ostream& os, const char* id); // NOLINT
Ben Murdoch85b71792012-04-11 18:30:58 +01001601#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001602 DECLARE_PRINTER(HeapObject)
1603 DECLARE_VERIFIER(HeapObject)
1604#ifdef VERIFY_HEAP
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001605 inline void VerifyObjectField(int offset);
1606 inline void VerifySmiField(int offset);
1607
Steve Blocka7e24c12009-10-30 11:49:00 +00001608 // Verify a pointer is a valid HeapObject pointer that points to object
1609 // areas in the heap.
1610 static void VerifyHeapPointer(Object* p);
1611#endif
1612
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001613 inline AllocationAlignment RequiredAlignment();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001614
Steve Blocka7e24c12009-10-30 11:49:00 +00001615 // Layout description.
1616 // First field in a heap object is map.
1617 static const int kMapOffset = Object::kHeaderSize;
1618 static const int kHeaderSize = kMapOffset + kPointerSize;
1619
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001620 STATIC_ASSERT(kMapOffset == Internals::kHeapObjectMapOffset);
Steve Blocka7e24c12009-10-30 11:49:00 +00001621
Steve Blocka7e24c12009-10-30 11:49:00 +00001622 private:
1623 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1624};
1625
1626
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001627template <int start_offset, int end_offset, int size>
1628class FixedBodyDescriptor;
Iain Merrick75681382010-08-19 15:07:18 +01001629
1630
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001631template <int start_offset>
1632class FlexibleBodyDescriptor;
Iain Merrick75681382010-08-19 15:07:18 +01001633
Iain Merrick75681382010-08-19 15:07:18 +01001634
Steve Blocka7e24c12009-10-30 11:49:00 +00001635// The HeapNumber class describes heap allocated numbers that cannot be
1636// represented in a Smi (small integer)
1637class HeapNumber: public HeapObject {
1638 public:
1639 // [value]: number value.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001640 inline double value() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00001641 inline void set_value(double value);
1642
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001643 DECLARE_CAST(HeapNumber)
Steve Blocka7e24c12009-10-30 11:49:00 +00001644
1645 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001646 bool HeapNumberBooleanValue();
1647
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001648 void HeapNumberPrint(std::ostream& os); // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001649 DECLARE_VERIFIER(HeapNumber)
Steve Blocka7e24c12009-10-30 11:49:00 +00001650
Steve Block6ded16b2010-05-10 14:33:55 +01001651 inline int get_exponent();
1652 inline int get_sign();
1653
Steve Blocka7e24c12009-10-30 11:49:00 +00001654 // Layout description.
1655 static const int kValueOffset = HeapObject::kHeaderSize;
1656 // IEEE doubles are two 32 bit words. The first is just mantissa, the second
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001657 // is a mixture of sign, exponent and mantissa. The offsets of two 32 bit
1658 // words within double numbers are endian dependent and they are set
1659 // accordingly.
1660#if defined(V8_TARGET_LITTLE_ENDIAN)
Steve Blocka7e24c12009-10-30 11:49:00 +00001661 static const int kMantissaOffset = kValueOffset;
1662 static const int kExponentOffset = kValueOffset + 4;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001663#elif defined(V8_TARGET_BIG_ENDIAN)
1664 static const int kMantissaOffset = kValueOffset + 4;
1665 static const int kExponentOffset = kValueOffset;
1666#else
1667#error Unknown byte ordering
1668#endif
Ben Murdoch8b112d22011-06-08 16:22:53 +01001669
Steve Blocka7e24c12009-10-30 11:49:00 +00001670 static const int kSize = kValueOffset + kDoubleSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00001671 static const uint32_t kSignMask = 0x80000000u;
1672 static const uint32_t kExponentMask = 0x7ff00000u;
1673 static const uint32_t kMantissaMask = 0xfffffu;
Steve Block6ded16b2010-05-10 14:33:55 +01001674 static const int kMantissaBits = 52;
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01001675 static const int kExponentBits = 11;
Steve Blocka7e24c12009-10-30 11:49:00 +00001676 static const int kExponentBias = 1023;
1677 static const int kExponentShift = 20;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001678 static const int kInfinityOrNanExponent =
1679 (kExponentMask >> kExponentShift) - kExponentBias;
Steve Blocka7e24c12009-10-30 11:49:00 +00001680 static const int kMantissaBitsInTopWord = 20;
1681 static const int kNonMantissaBitsInTopWord = 12;
1682
1683 private:
1684 DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
1685};
1686
1687
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001688// The Simd128Value class describes heap allocated 128 bit SIMD values.
1689class Simd128Value : public HeapObject {
1690 public:
1691 DECLARE_CAST(Simd128Value)
1692
1693 DECLARE_PRINTER(Simd128Value)
1694 DECLARE_VERIFIER(Simd128Value)
1695
1696 static Handle<String> ToString(Handle<Simd128Value> input);
1697
1698 // Equality operations.
1699 inline bool Equals(Simd128Value* that);
1700 static inline bool Equals(Handle<Simd128Value> one, Handle<Simd128Value> two);
1701
1702 // Checks that another instance is bit-wise equal.
1703 bool BitwiseEquals(const Simd128Value* other) const;
1704 // Computes a hash from the 128 bit value, viewed as 4 32-bit integers.
1705 uint32_t Hash() const;
1706 // Copies the 16 bytes of SIMD data to the destination address.
1707 void CopyBits(void* destination) const;
1708
1709 // Layout description.
1710 static const int kValueOffset = HeapObject::kHeaderSize;
1711 static const int kSize = kValueOffset + kSimd128Size;
1712
1713 private:
1714 DISALLOW_IMPLICIT_CONSTRUCTORS(Simd128Value);
1715};
1716
1717
1718// V has parameters (TYPE, Type, type, lane count, lane type)
1719#define SIMD128_TYPES(V) \
1720 V(FLOAT32X4, Float32x4, float32x4, 4, float) \
1721 V(INT32X4, Int32x4, int32x4, 4, int32_t) \
1722 V(UINT32X4, Uint32x4, uint32x4, 4, uint32_t) \
1723 V(BOOL32X4, Bool32x4, bool32x4, 4, bool) \
1724 V(INT16X8, Int16x8, int16x8, 8, int16_t) \
1725 V(UINT16X8, Uint16x8, uint16x8, 8, uint16_t) \
1726 V(BOOL16X8, Bool16x8, bool16x8, 8, bool) \
1727 V(INT8X16, Int8x16, int8x16, 16, int8_t) \
1728 V(UINT8X16, Uint8x16, uint8x16, 16, uint8_t) \
1729 V(BOOL8X16, Bool8x16, bool8x16, 16, bool)
1730
1731#define SIMD128_VALUE_CLASS(TYPE, Type, type, lane_count, lane_type) \
1732 class Type final : public Simd128Value { \
1733 public: \
1734 inline lane_type get_lane(int lane) const; \
1735 inline void set_lane(int lane, lane_type value); \
1736 \
1737 DECLARE_CAST(Type) \
1738 \
1739 DECLARE_PRINTER(Type) \
1740 \
1741 static Handle<String> ToString(Handle<Type> input); \
1742 \
1743 inline bool Equals(Type* that); \
1744 \
1745 private: \
1746 DISALLOW_IMPLICIT_CONSTRUCTORS(Type); \
1747 };
1748SIMD128_TYPES(SIMD128_VALUE_CLASS)
1749#undef SIMD128_VALUE_CLASS
1750
1751
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001752enum EnsureElementsMode {
1753 DONT_ALLOW_DOUBLE_ELEMENTS,
1754 ALLOW_COPIED_DOUBLE_ELEMENTS,
1755 ALLOW_CONVERTED_DOUBLE_ELEMENTS
1756};
1757
1758
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001759// Indicator for one component of an AccessorPair.
1760enum AccessorComponent {
1761 ACCESSOR_GETTER,
1762 ACCESSOR_SETTER
1763};
1764
1765
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001766enum GetKeysConversion { KEEP_NUMBERS, CONVERT_TO_STRING };
1767
Ben Murdoch097c5b22016-05-18 11:27:45 +01001768enum KeyCollectionType { OWN_ONLY, INCLUDE_PROTOS };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001769
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001770// JSReceiver includes types on which properties can be defined, i.e.,
1771// JSObject and JSProxy.
1772class JSReceiver: public HeapObject {
Steve Blocka7e24c12009-10-30 11:49:00 +00001773 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001774 // [properties]: Backing storage for properties.
1775 // properties is a FixedArray in the fast case and a Dictionary in the
1776 // slow case.
1777 DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties.
1778 inline void initialize_properties();
1779 inline bool HasFastProperties();
1780 // Gets slow properties for non-global objects.
1781 inline NameDictionary* property_dictionary();
1782
1783 // Deletes an existing named property in a normalized object.
1784 static void DeleteNormalizedProperty(Handle<JSReceiver> object,
1785 Handle<Name> name, int entry);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001786
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001787 DECLARE_CAST(JSReceiver)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001788
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001789 // ES6 section 7.1.1 ToPrimitive
1790 MUST_USE_RESULT static MaybeHandle<Object> ToPrimitive(
1791 Handle<JSReceiver> receiver,
1792 ToPrimitiveHint hint = ToPrimitiveHint::kDefault);
1793 MUST_USE_RESULT static MaybeHandle<Object> OrdinaryToPrimitive(
1794 Handle<JSReceiver> receiver, OrdinaryToPrimitiveHint hint);
1795
1796 static MaybeHandle<Context> GetFunctionRealm(Handle<JSReceiver> receiver);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001797
Ben Murdoch097c5b22016-05-18 11:27:45 +01001798 // Get the first non-hidden prototype.
1799 static inline MaybeHandle<Object> GetPrototype(Isolate* isolate,
1800 Handle<JSReceiver> receiver);
1801
1802 MUST_USE_RESULT static Maybe<bool> HasInPrototypeChain(
1803 Isolate* isolate, Handle<JSReceiver> object, Handle<Object> proto);
1804
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001805 // Implementation of [[HasProperty]], ECMA-262 5th edition, section 8.12.6.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001806 MUST_USE_RESULT static Maybe<bool> HasProperty(LookupIterator* it);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001807 MUST_USE_RESULT static inline Maybe<bool> HasProperty(
1808 Handle<JSReceiver> object, Handle<Name> name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001809 MUST_USE_RESULT static inline Maybe<bool> HasElement(
1810 Handle<JSReceiver> object, uint32_t index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001811
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001812 MUST_USE_RESULT static inline Maybe<bool> HasOwnProperty(
1813 Handle<JSReceiver> object, Handle<Name> name);
1814
1815 // Implementation of ES6 [[Delete]]
1816 MUST_USE_RESULT static Maybe<bool> DeletePropertyOrElement(
1817 Handle<JSReceiver> object, Handle<Name> name,
1818 LanguageMode language_mode = SLOPPY);
1819 MUST_USE_RESULT static Maybe<bool> DeleteProperty(
1820 Handle<JSReceiver> object, Handle<Name> name,
1821 LanguageMode language_mode = SLOPPY);
1822 MUST_USE_RESULT static Maybe<bool> DeleteProperty(LookupIterator* it,
1823 LanguageMode language_mode);
1824 MUST_USE_RESULT static Maybe<bool> DeleteElement(
1825 Handle<JSReceiver> object, uint32_t index,
1826 LanguageMode language_mode = SLOPPY);
1827
1828 MUST_USE_RESULT static Object* DefineProperty(Isolate* isolate,
1829 Handle<Object> object,
1830 Handle<Object> name,
1831 Handle<Object> attributes);
1832 MUST_USE_RESULT static MaybeHandle<Object> DefineProperties(
1833 Isolate* isolate, Handle<Object> object, Handle<Object> properties);
1834
1835 // "virtual" dispatcher to the correct [[DefineOwnProperty]] implementation.
1836 MUST_USE_RESULT static Maybe<bool> DefineOwnProperty(
1837 Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key,
1838 PropertyDescriptor* desc, ShouldThrow should_throw);
1839
1840 // ES6 7.3.4 (when passed DONT_THROW)
1841 MUST_USE_RESULT static Maybe<bool> CreateDataProperty(
1842 LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
1843
1844 // ES6 9.1.6.1
1845 MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty(
1846 Isolate* isolate, Handle<JSObject> object, Handle<Object> key,
1847 PropertyDescriptor* desc, ShouldThrow should_throw);
1848 MUST_USE_RESULT static Maybe<bool> OrdinaryDefineOwnProperty(
1849 LookupIterator* it, PropertyDescriptor* desc, ShouldThrow should_throw);
1850 // ES6 9.1.6.2
1851 MUST_USE_RESULT static Maybe<bool> IsCompatiblePropertyDescriptor(
1852 Isolate* isolate, bool extensible, PropertyDescriptor* desc,
1853 PropertyDescriptor* current, Handle<Name> property_name,
1854 ShouldThrow should_throw);
1855 // ES6 9.1.6.3
1856 // |it| can be NULL in cases where the ES spec passes |undefined| as the
1857 // receiver. Exactly one of |it| and |property_name| must be provided.
1858 MUST_USE_RESULT static Maybe<bool> ValidateAndApplyPropertyDescriptor(
1859 Isolate* isolate, LookupIterator* it, bool extensible,
1860 PropertyDescriptor* desc, PropertyDescriptor* current,
1861 ShouldThrow should_throw, Handle<Name> property_name = Handle<Name>());
1862
1863 MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor(
1864 Isolate* isolate, Handle<JSReceiver> object, Handle<Object> key,
1865 PropertyDescriptor* desc);
1866 MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor(
1867 LookupIterator* it, PropertyDescriptor* desc);
1868
1869 typedef PropertyAttributes IntegrityLevel;
1870
1871 // ES6 7.3.14 (when passed DONT_THROW)
1872 // 'level' must be SEALED or FROZEN.
1873 MUST_USE_RESULT static Maybe<bool> SetIntegrityLevel(
1874 Handle<JSReceiver> object, IntegrityLevel lvl, ShouldThrow should_throw);
1875
1876 // ES6 7.3.15
1877 // 'level' must be SEALED or FROZEN.
1878 MUST_USE_RESULT static Maybe<bool> TestIntegrityLevel(
1879 Handle<JSReceiver> object, IntegrityLevel lvl);
1880
1881 // ES6 [[PreventExtensions]] (when passed DONT_THROW)
1882 MUST_USE_RESULT static Maybe<bool> PreventExtensions(
1883 Handle<JSReceiver> object, ShouldThrow should_throw);
1884
1885 MUST_USE_RESULT static Maybe<bool> IsExtensible(Handle<JSReceiver> object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001886
1887 // Tests for the fast common case for property enumeration.
1888 bool IsSimpleEnum();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001889
1890 // Returns the class name ([[Class]] property in the specification).
1891 String* class_name();
1892
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001893 // Returns the builtin string tag used in Object.prototype.toString.
1894 MUST_USE_RESULT static MaybeHandle<String> BuiltinStringTag(
1895 Handle<JSReceiver> object);
1896
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001897 // Returns the constructor name (the name (possibly, inferred name) of the
1898 // function that was used to instantiate the object).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001899 static Handle<String> GetConstructorName(Handle<JSReceiver> receiver);
1900
1901 Context* GetCreationContext();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001902
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001903 MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetPropertyAttributes(
1904 Handle<JSReceiver> object, Handle<Name> name);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001905 MUST_USE_RESULT static inline Maybe<PropertyAttributes>
1906 GetOwnPropertyAttributes(Handle<JSReceiver> object, Handle<Name> name);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001907
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001908 MUST_USE_RESULT static inline Maybe<PropertyAttributes> GetElementAttributes(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001909 Handle<JSReceiver> object, uint32_t index);
1910 MUST_USE_RESULT static inline Maybe<PropertyAttributes>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001911 GetOwnElementAttributes(Handle<JSReceiver> object, uint32_t index);
1912
1913 MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes(
1914 LookupIterator* it);
1915
1916 // Set the object's prototype (only JSReceiver and null are allowed values).
1917 MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSReceiver> object,
1918 Handle<Object> value,
1919 bool from_javascript,
1920 ShouldThrow should_throw);
1921
1922
1923 static Handle<Object> GetDataProperty(Handle<JSReceiver> object,
1924 Handle<Name> name);
1925 static Handle<Object> GetDataProperty(LookupIterator* it);
1926
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001927
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001928 // Retrieves a permanent object identity hash code. The undefined value might
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001929 // be returned in case no hash was created yet.
1930 inline Object* GetIdentityHash();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001931
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001932 // Retrieves a permanent object identity hash code. May create and store a
1933 // hash code if needed and none exists.
1934 inline static Handle<Smi> GetOrCreateIdentityHash(
1935 Handle<JSReceiver> object);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001936
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001937 // ES6 [[OwnPropertyKeys]] (modulo return type)
1938 MUST_USE_RESULT static MaybeHandle<FixedArray> OwnPropertyKeys(
1939 Handle<JSReceiver> object) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001940 return GetKeys(object, OWN_ONLY, ALL_PROPERTIES, CONVERT_TO_STRING);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001941 }
1942
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001943 // Computes the enumerable keys for a JSObject. Used for implementing
1944 // "for (n in object) { }".
1945 MUST_USE_RESULT static MaybeHandle<FixedArray> GetKeys(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001946 Handle<JSReceiver> object, KeyCollectionType type, PropertyFilter filter,
1947 GetKeysConversion keys_conversion = KEEP_NUMBERS);
1948
Ben Murdoch097c5b22016-05-18 11:27:45 +01001949 MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnValues(
1950 Handle<JSReceiver> object, PropertyFilter filter);
1951
1952 MUST_USE_RESULT static MaybeHandle<FixedArray> GetOwnEntries(
1953 Handle<JSReceiver> object, PropertyFilter filter);
1954
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001955 // Layout description.
1956 static const int kPropertiesOffset = HeapObject::kHeaderSize;
1957 static const int kHeaderSize = HeapObject::kHeaderSize + kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001958
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001959 private:
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001960 DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver);
1961};
1962
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001963
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001964// The JSObject describes real heap allocated JavaScript objects with
1965// properties.
1966// Note that the map of JSObject changes during execution to enable inline
1967// caching.
1968class JSObject: public JSReceiver {
1969 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001970 static MUST_USE_RESULT MaybeHandle<JSObject> New(
1971 Handle<JSFunction> constructor, Handle<JSReceiver> new_target,
1972 Handle<AllocationSite> site = Handle<AllocationSite>::null());
1973
1974 // Gets global object properties.
1975 inline GlobalDictionary* global_dictionary();
1976
1977 static MaybeHandle<Context> GetFunctionRealm(Handle<JSObject> object);
Steve Blocka7e24c12009-10-30 11:49:00 +00001978
1979 // [elements]: The elements (properties with names that are integers).
Iain Merrick75681382010-08-19 15:07:18 +01001980 //
1981 // Elements can be in two general modes: fast and slow. Each mode
1982 // corrensponds to a set of object representations of elements that
1983 // have something in common.
1984 //
1985 // In the fast mode elements is a FixedArray and so each element can
1986 // be quickly accessed. This fact is used in the generated code. The
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001987 // elements array can have one of three maps in this mode:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001988 // fixed_array_map, sloppy_arguments_elements_map or
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001989 // fixed_cow_array_map (for copy-on-write arrays). In the latter case
1990 // the elements array may be shared by a few objects and so before
1991 // writing to any element the array must be copied. Use
1992 // EnsureWritableFastElements in this case.
Iain Merrick75681382010-08-19 15:07:18 +01001993 //
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001994 // In the slow mode the elements is either a NumberDictionary, a
1995 // FixedArray parameter map for a (sloppy) arguments object.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00001996 DECL_ACCESSORS(elements, FixedArrayBase)
Steve Blocka7e24c12009-10-30 11:49:00 +00001997 inline void initialize_elements();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001998 static void ResetElements(Handle<JSObject> object);
1999 static inline void SetMapAndElements(Handle<JSObject> object,
2000 Handle<Map> map,
2001 Handle<FixedArrayBase> elements);
Steve Blocka7e24c12009-10-30 11:49:00 +00002002 inline ElementsKind GetElementsKind();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002003 ElementsAccessor* GetElementsAccessor();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002004 // Returns true if an object has elements of FAST_SMI_ELEMENTS ElementsKind.
2005 inline bool HasFastSmiElements();
2006 // Returns true if an object has elements of FAST_ELEMENTS ElementsKind.
2007 inline bool HasFastObjectElements();
2008 // Returns true if an object has elements of FAST_ELEMENTS or
2009 // FAST_SMI_ONLY_ELEMENTS.
2010 inline bool HasFastSmiOrObjectElements();
2011 // Returns true if an object has any of the fast elements kinds.
Steve Blocka7e24c12009-10-30 11:49:00 +00002012 inline bool HasFastElements();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002013 // Returns true if an object has elements of FAST_DOUBLE_ELEMENTS
2014 // ElementsKind.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002015 inline bool HasFastDoubleElements();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002016 // Returns true if an object has elements of FAST_HOLEY_*_ELEMENTS
2017 // ElementsKind.
2018 inline bool HasFastHoleyElements();
2019 inline bool HasSloppyArgumentsElements();
Ben Murdoch097c5b22016-05-18 11:27:45 +01002020 inline bool HasStringWrapperElements();
Steve Blocka7e24c12009-10-30 11:49:00 +00002021 inline bool HasDictionaryElements();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002022
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002023 inline bool HasFixedTypedArrayElements();
2024
2025 inline bool HasFixedUint8ClampedElements();
2026 inline bool HasFixedArrayElements();
2027 inline bool HasFixedInt8Elements();
2028 inline bool HasFixedUint8Elements();
2029 inline bool HasFixedInt16Elements();
2030 inline bool HasFixedUint16Elements();
2031 inline bool HasFixedInt32Elements();
2032 inline bool HasFixedUint32Elements();
2033 inline bool HasFixedFloat32Elements();
2034 inline bool HasFixedFloat64Elements();
2035
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002036 inline bool HasFastArgumentsElements();
2037 inline bool HasSlowArgumentsElements();
Ben Murdoch097c5b22016-05-18 11:27:45 +01002038 inline bool HasFastStringWrapperElements();
2039 inline bool HasSlowStringWrapperElements();
Ben Murdochc7cc0282012-03-05 14:35:55 +00002040 inline SeededNumberDictionary* element_dictionary(); // Gets slow elements.
2041
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002042 // Requires: HasFastElements().
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002043 static Handle<FixedArray> EnsureWritableFastElements(
2044 Handle<JSObject> object);
Steve Blocka7e24c12009-10-30 11:49:00 +00002045
2046 // Collects elements starting at index 0.
2047 // Undefined values are placed after non-undefined values.
2048 // Returns the number of non-undefined values.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002049 static Handle<Object> PrepareElementsForSort(Handle<JSObject> object,
2050 uint32_t limit);
Steve Blocka7e24c12009-10-30 11:49:00 +00002051 // As PrepareElementsForSort, but only on objects where elements is
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002052 // a dictionary, and it will stay a dictionary. Collates undefined and
2053 // unexisting elements below limit from position zero of the elements.
2054 static Handle<Object> PrepareSlowElementsForSort(Handle<JSObject> object,
2055 uint32_t limit);
Steve Blocka7e24c12009-10-30 11:49:00 +00002056
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002057 MUST_USE_RESULT static Maybe<bool> SetPropertyWithInterceptor(
Ben Murdoch097c5b22016-05-18 11:27:45 +01002058 LookupIterator* it, ShouldThrow should_throw, Handle<Object> value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002059
Ben Murdoch097c5b22016-05-18 11:27:45 +01002060 // The API currently still wants DefineOwnPropertyIgnoreAttributes to convert
2061 // AccessorInfo objects to data fields. We allow FORCE_FIELD as an exception
2062 // to the default behavior that calls the setter.
2063 enum AccessorInfoHandling { FORCE_FIELD, DONT_FORCE_FIELD };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002064
2065 MUST_USE_RESULT static MaybeHandle<Object> DefineOwnPropertyIgnoreAttributes(
2066 LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
Ben Murdoch097c5b22016-05-18 11:27:45 +01002067 AccessorInfoHandling handling = DONT_FORCE_FIELD);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002068
2069 MUST_USE_RESULT static Maybe<bool> DefineOwnPropertyIgnoreAttributes(
2070 LookupIterator* it, Handle<Object> value, PropertyAttributes attributes,
2071 ShouldThrow should_throw,
Ben Murdoch097c5b22016-05-18 11:27:45 +01002072 AccessorInfoHandling handling = DONT_FORCE_FIELD);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002073
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002074 MUST_USE_RESULT static MaybeHandle<Object> SetOwnPropertyIgnoreAttributes(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002075 Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
Ben Murdoch097c5b22016-05-18 11:27:45 +01002076 PropertyAttributes attributes);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002077
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002078 MUST_USE_RESULT static MaybeHandle<Object> SetOwnElementIgnoreAttributes(
2079 Handle<JSObject> object, uint32_t index, Handle<Object> value,
Ben Murdoch097c5b22016-05-18 11:27:45 +01002080 PropertyAttributes attributes);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002081
2082 // Equivalent to one of the above depending on whether |name| can be converted
2083 // to an array index.
2084 MUST_USE_RESULT static MaybeHandle<Object>
Ben Murdoch097c5b22016-05-18 11:27:45 +01002085 DefinePropertyOrElementIgnoreAttributes(Handle<JSObject> object,
2086 Handle<Name> name,
2087 Handle<Object> value,
2088 PropertyAttributes attributes = NONE);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002089
2090 // Adds or reconfigures a property to attributes NONE. It will fail when it
2091 // cannot.
2092 MUST_USE_RESULT static Maybe<bool> CreateDataProperty(LookupIterator* it,
2093 Handle<Object> value);
2094
2095 static void AddProperty(Handle<JSObject> object, Handle<Name> name,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002096 Handle<Object> value, PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +00002097
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002098 MUST_USE_RESULT static Maybe<bool> AddDataElement(
2099 Handle<JSObject> receiver, uint32_t index, Handle<Object> value,
2100 PropertyAttributes attributes, ShouldThrow should_throw);
2101 MUST_USE_RESULT static MaybeHandle<Object> AddDataElement(
2102 Handle<JSObject> receiver, uint32_t index, Handle<Object> value,
2103 PropertyAttributes attributes);
2104
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002105 // Extend the receiver with a single fast property appeared first in the
2106 // passed map. This also extends the property backing store if necessary.
2107 static void AllocateStorageForMap(Handle<JSObject> object, Handle<Map> map);
Steve Blocka7e24c12009-10-30 11:49:00 +00002108
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002109 // Migrates the given object to a map whose field representations are the
2110 // lowest upper bound of all known representations for that field.
2111 static void MigrateInstance(Handle<JSObject> instance);
2112
2113 // Migrates the given object only if the target map is already available,
2114 // or returns false if such a map is not yet available.
2115 static bool TryMigrateInstance(Handle<JSObject> instance);
Steve Blocka7e24c12009-10-30 11:49:00 +00002116
2117 // Sets the property value in a normalized object given (key, value, details).
2118 // Handles the special representation of JS global objects.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002119 static void SetNormalizedProperty(Handle<JSObject> object, Handle<Name> name,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002120 Handle<Object> value,
2121 PropertyDetails details);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002122 static void SetDictionaryElement(Handle<JSObject> object, uint32_t index,
2123 Handle<Object> value,
2124 PropertyAttributes attributes);
2125 static void SetDictionaryArgumentsElement(Handle<JSObject> object,
2126 uint32_t index,
2127 Handle<Object> value,
2128 PropertyAttributes attributes);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002129
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002130 static void OptimizeAsPrototype(Handle<JSObject> object,
2131 PrototypeOptimizationMode mode);
2132 static void ReoptimizeIfPrototype(Handle<JSObject> object);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002133 static void LazyRegisterPrototypeUser(Handle<Map> user, Isolate* isolate);
2134 static void UpdatePrototypeUserRegistration(Handle<Map> old_map,
2135 Handle<Map> new_map,
2136 Isolate* isolate);
2137 static bool UnregisterPrototypeUser(Handle<Map> user, Isolate* isolate);
2138 static void InvalidatePrototypeChains(Map* map);
2139
2140 // Alternative implementation of WeakFixedArray::NullCallback.
2141 class PrototypeRegistryCompactionCallback {
2142 public:
2143 static void Callback(Object* value, int old_index, int new_index);
2144 };
Steve Blocka7e24c12009-10-30 11:49:00 +00002145
Steve Blocka7e24c12009-10-30 11:49:00 +00002146 // Retrieve interceptors.
2147 InterceptorInfo* GetNamedInterceptor();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002148 inline InterceptorInfo* GetIndexedInterceptor();
Steve Blocka7e24c12009-10-30 11:49:00 +00002149
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002150 // Used from JSReceiver.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002151 MUST_USE_RESULT static Maybe<PropertyAttributes>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002152 GetPropertyAttributesWithInterceptor(LookupIterator* it);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002153 MUST_USE_RESULT static Maybe<PropertyAttributes>
2154 GetPropertyAttributesWithFailedAccessCheck(LookupIterator* it);
Steve Blocka7e24c12009-10-30 11:49:00 +00002155
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002156 // Retrieves an AccessorPair property from the given object. Might return
2157 // undefined if the property doesn't exist or is of a different kind.
2158 MUST_USE_RESULT static MaybeHandle<Object> GetAccessor(
2159 Handle<JSObject> object,
2160 Handle<Name> name,
2161 AccessorComponent component);
Steve Blocka7e24c12009-10-30 11:49:00 +00002162
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002163 // Defines an AccessorPair property on the given object.
2164 // TODO(mstarzinger): Rename to SetAccessor().
2165 static MaybeHandle<Object> DefineAccessor(Handle<JSObject> object,
2166 Handle<Name> name,
2167 Handle<Object> getter,
2168 Handle<Object> setter,
2169 PropertyAttributes attributes);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002170 static MaybeHandle<Object> DefineAccessor(LookupIterator* it,
2171 Handle<Object> getter,
2172 Handle<Object> setter,
2173 PropertyAttributes attributes);
Leon Clarkef7060e22010-06-03 12:02:55 +01002174
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002175 // Defines an AccessorInfo property on the given object.
2176 MUST_USE_RESULT static MaybeHandle<Object> SetAccessor(
2177 Handle<JSObject> object,
2178 Handle<AccessorInfo> info);
2179
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002180 // The result must be checked first for exceptions. If there's no exception,
2181 // the output parameter |done| indicates whether the interceptor has a result
2182 // or not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002183 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithInterceptor(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002184 LookupIterator* it, bool* done);
Steve Blocka7e24c12009-10-30 11:49:00 +00002185
Steve Blockd0582a62009-12-15 09:54:21 +00002186 // Accessors for hidden properties object.
2187 //
Ben Murdoch097c5b22016-05-18 11:27:45 +01002188 // Hidden properties are not own properties of the object itself. Instead
2189 // they are stored in an auxiliary structure kept as an own property with a
2190 // special name Heap::hidden_properties_symbol(). But if the receiver is a
2191 // JSGlobalProxy then the auxiliary object is a property of its prototype, and
2192 // if it's a detached proxy, then you can't have hidden properties.
Steve Blockd0582a62009-12-15 09:54:21 +00002193
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002194 // Sets a hidden property on this object. Returns this object if successful,
2195 // undefined if called on a detached proxy.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002196 static Handle<Object> SetHiddenProperty(Handle<JSObject> object,
2197 Handle<Name> key,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002198 Handle<Object> value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002199 // Gets the value of a hidden property with the given key. Returns the hole
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002200 // if the property doesn't exist (or if called on a detached proxy),
2201 // otherwise returns the value set for the key.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002202 Object* GetHiddenProperty(Handle<Name> key);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002203 // Deletes a hidden property. Deleting a non-existing property is
2204 // considered successful.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002205 static void DeleteHiddenProperty(Handle<JSObject> object,
2206 Handle<Name> key);
2207 // Returns true if the object has a property with the hidden string as name.
2208 static bool HasHiddenProperties(Handle<JSObject> object);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002209
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002210 static void SetIdentityHash(Handle<JSObject> object, Handle<Smi> hash);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002211
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002212 static void ValidateElements(Handle<JSObject> object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002213
2214 // Makes sure that this object can contain HeapObject as elements.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002215 static inline void EnsureCanContainHeapObjectElements(Handle<JSObject> obj);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002216
2217 // Makes sure that this object can contain the specified elements.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002218 static inline void EnsureCanContainElements(
2219 Handle<JSObject> object,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002220 Object** elements,
2221 uint32_t count,
2222 EnsureElementsMode mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002223 static inline void EnsureCanContainElements(
2224 Handle<JSObject> object,
2225 Handle<FixedArrayBase> elements,
2226 uint32_t length,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002227 EnsureElementsMode mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002228 static void EnsureCanContainElements(
2229 Handle<JSObject> object,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002230 Arguments* arguments,
2231 uint32_t first_arg,
2232 uint32_t arg_count,
2233 EnsureElementsMode mode);
Steve Blocka7e24c12009-10-30 11:49:00 +00002234
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002235 // Would we convert a fast elements array to dictionary mode given
2236 // an access at key?
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002237 bool WouldConvertToSlowElements(uint32_t index);
Andrei Popescu402d9372010-02-26 13:31:12 +00002238
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002239 // Computes the new capacity when expanding the elements of a JSObject.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002240 static uint32_t NewElementsCapacity(uint32_t old_capacity) {
Ben Murdoche0cee9b2011-05-25 10:26:03 +01002241 // (old_capacity + 50%) + 16
2242 return old_capacity + (old_capacity >> 1) + 16;
2243 }
2244
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002245 // These methods do not perform access checks!
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002246 static void UpdateAllocationSite(Handle<JSObject> object,
2247 ElementsKind to_kind);
Steve Blocka7e24c12009-10-30 11:49:00 +00002248
2249 // Lookup interceptors are used for handling properties controlled by host
2250 // objects.
2251 inline bool HasNamedInterceptor();
2252 inline bool HasIndexedInterceptor();
2253
2254 // Support functions for v8 api (needed for correct interceptor behavior).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002255 MUST_USE_RESULT static Maybe<bool> HasRealNamedProperty(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002256 Handle<JSObject> object, Handle<Name> name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002257 MUST_USE_RESULT static Maybe<bool> HasRealElementProperty(
2258 Handle<JSObject> object, uint32_t index);
2259 MUST_USE_RESULT static Maybe<bool> HasRealNamedCallbackProperty(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002260 Handle<JSObject> object, Handle<Name> name);
Steve Blocka7e24c12009-10-30 11:49:00 +00002261
Steve Blocka7e24c12009-10-30 11:49:00 +00002262 // Get the header size for a JSObject. Used to compute the index of
2263 // internal fields as well as the number of internal fields.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002264 static inline int GetHeaderSize(InstanceType instance_type);
Steve Blocka7e24c12009-10-30 11:49:00 +00002265 inline int GetHeaderSize();
2266
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002267 static inline int GetInternalFieldCount(Map* map);
Steve Blocka7e24c12009-10-30 11:49:00 +00002268 inline int GetInternalFieldCount();
Steve Block44f0eee2011-05-26 01:26:41 +01002269 inline int GetInternalFieldOffset(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00002270 inline Object* GetInternalField(int index);
2271 inline void SetInternalField(int index, Object* value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002272 inline void SetInternalField(int index, Smi* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00002273
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002274 void CollectOwnPropertyNames(KeyAccumulator* keys,
2275 PropertyFilter filter = ALL_PROPERTIES);
Steve Blocka7e24c12009-10-30 11:49:00 +00002276
2277 // Returns the number of properties on this object filtering out properties
2278 // with the specified attributes (ignoring interceptors).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002279 // TODO(jkummerow): Deprecated, only used by Object.observe.
2280 int NumberOfOwnElements(PropertyFilter filter);
Steve Blocka7e24c12009-10-30 11:49:00 +00002281 // Returns the number of elements on this object filtering out elements
2282 // with the specified attributes (ignoring interceptors).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002283 // TODO(jkummerow): Deprecated, only used by Object.observe.
2284 int GetOwnElementKeys(FixedArray* storage, PropertyFilter filter);
2285
2286 static void CollectOwnElementKeys(Handle<JSObject> object,
2287 KeyAccumulator* keys,
2288 PropertyFilter filter);
2289
Ben Murdoch097c5b22016-05-18 11:27:45 +01002290 static Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object);
Steve Blocka7e24c12009-10-30 11:49:00 +00002291
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002292 // Returns a new map with all transitions dropped from the object's current
2293 // map and the ElementsKind set.
2294 static Handle<Map> GetElementsTransitionMap(Handle<JSObject> object,
2295 ElementsKind to_kind);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002296 static void TransitionElementsKind(Handle<JSObject> object,
2297 ElementsKind to_kind);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002298
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002299 // Always use this to migrate an object to a new map.
2300 // |expected_additional_properties| is only used for fast-to-slow transitions
2301 // and ignored otherwise.
2302 static void MigrateToMap(Handle<JSObject> object, Handle<Map> new_map,
2303 int expected_additional_properties = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +00002304
2305 // Convert the object to use the canonical dictionary
2306 // representation. If the object is expected to have additional properties
2307 // added this number can be indicated to have the backing store allocated to
2308 // an initial capacity for holding these properties.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002309 static void NormalizeProperties(Handle<JSObject> object,
2310 PropertyNormalizationMode mode,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002311 int expected_additional_properties,
2312 const char* reason);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002313
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002314 // Convert and update the elements backing store to be a
2315 // SeededNumberDictionary dictionary. Returns the backing after conversion.
2316 static Handle<SeededNumberDictionary> NormalizeElements(
2317 Handle<JSObject> object);
2318
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002319 void RequireSlowElements(SeededNumberDictionary* dictionary);
2320
Steve Blocka7e24c12009-10-30 11:49:00 +00002321 // Transform slow named properties to fast variants.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002322 static void MigrateSlowToFast(Handle<JSObject> object,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002323 int unused_property_fields, const char* reason);
2324
2325 inline bool IsUnboxedDoubleField(FieldIndex index);
Steve Blocka7e24c12009-10-30 11:49:00 +00002326
2327 // Access fast-case object properties at index.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002328 static Handle<Object> FastPropertyAt(Handle<JSObject> object,
2329 Representation representation,
2330 FieldIndex index);
2331 inline Object* RawFastPropertyAt(FieldIndex index);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002332 inline double RawFastDoublePropertyAt(FieldIndex index);
2333
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002334 inline void FastPropertyAtPut(FieldIndex index, Object* value);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002335 inline void RawFastPropertyAtPut(FieldIndex index, Object* value);
2336 inline void RawFastDoublePropertyAtPut(FieldIndex index, double value);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002337 inline void WriteToField(int descriptor, PropertyDetails details,
2338 Object* value);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002339 inline void WriteToField(int descriptor, Object* value);
Steve Blocka7e24c12009-10-30 11:49:00 +00002340
2341 // Access to in object properties.
Steve Block44f0eee2011-05-26 01:26:41 +01002342 inline int GetInObjectPropertyOffset(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00002343 inline Object* InObjectPropertyAt(int index);
2344 inline Object* InObjectPropertyAtPut(int index,
2345 Object* value,
2346 WriteBarrierMode mode
2347 = UPDATE_WRITE_BARRIER);
2348
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002349 // Set the object's prototype (only JSReceiver and null are allowed values).
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002350 MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSObject> object,
2351 Handle<Object> value,
2352 bool from_javascript,
2353 ShouldThrow should_throw);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002354
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002355 // Initializes the body starting at |start_offset|. It is responsibility of
2356 // the caller to initialize object header. Fill the pre-allocated fields with
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002357 // pre_allocated_value and the rest with filler_value.
2358 // Note: this call does not update write barrier, the caller is responsible
2359 // to ensure that |filler_value| can be collected without WB here.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002360 inline void InitializeBody(Map* map, int start_offset,
2361 Object* pre_allocated_value, Object* filler_value);
Steve Blocka7e24c12009-10-30 11:49:00 +00002362
2363 // Check whether this object references another object
2364 bool ReferencesObject(Object* obj);
2365
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002366 MUST_USE_RESULT static Maybe<bool> PreventExtensions(
2367 Handle<JSObject> object, ShouldThrow should_throw);
Steve Block8defd9f2010-07-08 12:39:36 +01002368
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002369 static bool IsExtensible(Handle<JSObject> object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002370
2371 // Called the first time an object is observed with ES7 Object.observe.
2372 static void SetObserved(Handle<JSObject> object);
2373
2374 // Copy object.
2375 enum DeepCopyHints { kNoHints = 0, kObjectIsShallow = 1 };
2376
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002377 MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopy(
2378 Handle<JSObject> object,
2379 AllocationSiteUsageContext* site_context,
2380 DeepCopyHints hints = kNoHints);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002381 // Deep copies given object with special handling for JSFunctions which
2382 // 1) must be Api functions and 2) are not copied but left as is.
2383 MUST_USE_RESULT static MaybeHandle<JSObject> DeepCopyApiBoilerplate(
2384 Handle<JSObject> object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002385 MUST_USE_RESULT static MaybeHandle<JSObject> DeepWalk(
2386 Handle<JSObject> object,
2387 AllocationSiteCreationContext* site_context);
2388
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002389 DECLARE_CAST(JSObject)
Steve Block8defd9f2010-07-08 12:39:36 +01002390
Steve Blocka7e24c12009-10-30 11:49:00 +00002391 // Dispatched behavior.
Steve Blocka7e24c12009-10-30 11:49:00 +00002392 void JSObjectShortPrint(StringStream* accumulator);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002393 DECLARE_PRINTER(JSObject)
2394 DECLARE_VERIFIER(JSObject)
Ben Murdochb0fe1622011-05-05 13:52:32 +01002395#ifdef OBJECT_PRINT
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002396 void PrintProperties(std::ostream& os); // NOLINT
2397 void PrintElements(std::ostream& os); // NOLINT
2398#endif
2399#if defined(DEBUG) || defined(OBJECT_PRINT)
2400 void PrintTransitions(std::ostream& os); // NOLINT
Ben Murdochb0fe1622011-05-05 13:52:32 +01002401#endif
2402
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002403 static void PrintElementsTransition(
2404 FILE* file, Handle<JSObject> object,
2405 ElementsKind from_kind, Handle<FixedArrayBase> from_elements,
2406 ElementsKind to_kind, Handle<FixedArrayBase> to_elements);
2407
2408 void PrintInstanceMigration(FILE* file, Map* original_map, Map* new_map);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002409
Ben Murdochb0fe1622011-05-05 13:52:32 +01002410#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00002411 // Structure for collecting spill information about JSObjects.
2412 class SpillInformation {
2413 public:
2414 void Clear();
2415 void Print();
2416 int number_of_objects_;
2417 int number_of_objects_with_fast_properties_;
2418 int number_of_objects_with_fast_elements_;
2419 int number_of_fast_used_fields_;
2420 int number_of_fast_unused_fields_;
2421 int number_of_slow_used_properties_;
2422 int number_of_slow_unused_properties_;
2423 int number_of_fast_used_elements_;
2424 int number_of_fast_unused_elements_;
2425 int number_of_slow_used_elements_;
2426 int number_of_slow_unused_elements_;
2427 };
2428
2429 void IncrementSpillStatistics(SpillInformation* info);
2430#endif
Steve Blocka7e24c12009-10-30 11:49:00 +00002431
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002432#ifdef VERIFY_HEAP
2433 // If a GC was caused while constructing this object, the elements pointer
2434 // may point to a one pointer filler map. The object won't be rooted, but
2435 // our heap verification code could stumble across it.
2436 bool ElementsAreSafeToExamine();
2437#endif
2438
2439 Object* SlowReverseLookup(Object* value);
Steve Block8defd9f2010-07-08 12:39:36 +01002440
Leon Clarkee46be812010-01-19 14:06:41 +00002441 // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
2442 // Also maximal value of JSArray's length property.
2443 static const uint32_t kMaxElementCount = 0xffffffffu;
2444
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002445 // Constants for heuristics controlling conversion of fast elements
2446 // to slow elements.
2447
2448 // Maximal gap that can be introduced by adding an element beyond
2449 // the current elements length.
Steve Blocka7e24c12009-10-30 11:49:00 +00002450 static const uint32_t kMaxGap = 1024;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002451
2452 // Maximal length of fast elements array that won't be checked for
2453 // being dense enough on expansion.
2454 static const int kMaxUncheckedFastElementsLength = 5000;
2455
2456 // Same as above but for old arrays. This limit is more strict. We
2457 // don't want to be wasteful with long lived objects.
2458 static const int kMaxUncheckedOldFastElementsLength = 500;
2459
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002460 // This constant applies only to the initial map of "global.Object" and
2461 // not to arbitrary other JSObject maps.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002462 static const int kInitialGlobalObjectUnusedPropertiesCount = 4;
2463
Steve Blocka7e24c12009-10-30 11:49:00 +00002464 static const int kMaxInstanceSize = 255 * kPointerSize;
2465 // When extending the backing storage for property values, we increase
2466 // its size by more than the 1 entry necessary, so sequentially adding fields
2467 // to the same object requires fewer allocations and copies.
2468 static const int kFieldsAdded = 3;
2469
2470 // Layout description.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002471 static const int kElementsOffset = JSReceiver::kHeaderSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00002472 static const int kHeaderSize = kElementsOffset + kPointerSize;
2473
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002474 STATIC_ASSERT(kHeaderSize == Internals::kJSObjectHeaderSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00002475
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002476 typedef FlexibleBodyDescriptor<JSReceiver::kPropertiesOffset> BodyDescriptor;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002477
2478 // Enqueue change record for Object.observe. May cause GC.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002479 MUST_USE_RESULT static MaybeHandle<Object> EnqueueChangeRecord(
2480 Handle<JSObject> object, const char* type, Handle<Name> name,
2481 Handle<Object> old_value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002482
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002483 // Gets the number of currently used elements.
2484 int GetFastElementsUsage();
2485
2486 static bool AllCanRead(LookupIterator* it);
2487 static bool AllCanWrite(LookupIterator* it);
2488
Steve Blocka7e24c12009-10-30 11:49:00 +00002489 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002490 friend class JSReceiver;
2491 friend class Object;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002492
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002493 // Used from Object::GetProperty().
2494 MUST_USE_RESULT static MaybeHandle<Object> GetPropertyWithFailedAccessCheck(
2495 LookupIterator* it);
2496
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002497 MUST_USE_RESULT static Maybe<bool> SetPropertyWithFailedAccessCheck(
2498 LookupIterator* it, Handle<Object> value, ShouldThrow should_throw);
Steve Blocka7e24c12009-10-30 11:49:00 +00002499
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002500 // Add a property to a slow-case object.
2501 static void AddSlowProperty(Handle<JSObject> object,
2502 Handle<Name> name,
2503 Handle<Object> value,
2504 PropertyAttributes attributes);
Steve Blocka7e24c12009-10-30 11:49:00 +00002505
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002506 MUST_USE_RESULT static Maybe<bool> DeletePropertyWithInterceptor(
Ben Murdoch097c5b22016-05-18 11:27:45 +01002507 LookupIterator* it, ShouldThrow should_throw);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002508
2509 bool ReferencesObjectFromElements(FixedArray* elements,
2510 ElementsKind kind,
2511 Object* object);
Steve Blocka7e24c12009-10-30 11:49:00 +00002512
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002513 // Return the hash table backing store or the inline stored identity hash,
2514 // whatever is found.
2515 MUST_USE_RESULT Object* GetHiddenPropertiesHashTable();
2516
2517 // Return the hash table backing store for hidden properties. If there is no
2518 // backing store, allocate one.
2519 static Handle<ObjectHashTable> GetOrCreateHiddenPropertiesHashtable(
2520 Handle<JSObject> object);
2521
2522 // Set the hidden property backing store to either a hash table or
2523 // the inline-stored identity hash.
2524 static Handle<Object> SetHiddenPropertiesHashTable(
2525 Handle<JSObject> object,
2526 Handle<Object> value);
2527
2528 MUST_USE_RESULT Object* GetIdentityHash();
2529
2530 static Handle<Smi> GetOrCreateIdentityHash(Handle<JSObject> object);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002531
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002532 static Handle<SeededNumberDictionary> GetNormalizedElementDictionary(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002533 Handle<JSObject> object, Handle<FixedArrayBase> elements);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002534
2535 // Helper for fast versions of preventExtensions, seal, and freeze.
2536 // attrs is one of NONE, SEALED, or FROZEN (depending on the operation).
2537 template <PropertyAttributes attrs>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002538 MUST_USE_RESULT static Maybe<bool> PreventExtensionsWithTransition(
2539 Handle<JSObject> object, ShouldThrow should_throw);
2540
2541 MUST_USE_RESULT static Maybe<bool> SetPrototypeUnobserved(
2542 Handle<JSObject> object, Handle<Object> value, bool from_javascript,
2543 ShouldThrow should_throw);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002544
Steve Blocka7e24c12009-10-30 11:49:00 +00002545 DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
2546};
2547
2548
Ben Murdoch097c5b22016-05-18 11:27:45 +01002549// JSAccessorPropertyDescriptor is just a JSObject with a specific initial
2550// map. This initial map adds in-object properties for "get", "set",
2551// "enumerable" and "configurable" properties, as assigned by the
2552// FromPropertyDescriptor function for regular accessor properties.
2553class JSAccessorPropertyDescriptor: public JSObject {
2554 public:
2555 // Offsets of object fields.
2556 static const int kGetOffset = JSObject::kHeaderSize;
2557 static const int kSetOffset = kGetOffset + kPointerSize;
2558 static const int kEnumerableOffset = kSetOffset + kPointerSize;
2559 static const int kConfigurableOffset = kEnumerableOffset + kPointerSize;
2560 static const int kSize = kConfigurableOffset + kPointerSize;
2561 // Indices of in-object properties.
2562 static const int kGetIndex = 0;
2563 static const int kSetIndex = 1;
2564 static const int kEnumerableIndex = 2;
2565 static const int kConfigurableIndex = 3;
2566
2567 private:
2568 DISALLOW_IMPLICIT_CONSTRUCTORS(JSAccessorPropertyDescriptor);
2569};
2570
2571
2572// JSDataPropertyDescriptor is just a JSObject with a specific initial map.
2573// This initial map adds in-object properties for "value", "writable",
2574// "enumerable" and "configurable" properties, as assigned by the
2575// FromPropertyDescriptor function for regular data properties.
2576class JSDataPropertyDescriptor: public JSObject {
2577 public:
2578 // Offsets of object fields.
2579 static const int kValueOffset = JSObject::kHeaderSize;
2580 static const int kWritableOffset = kValueOffset + kPointerSize;
2581 static const int kEnumerableOffset = kWritableOffset + kPointerSize;
2582 static const int kConfigurableOffset = kEnumerableOffset + kPointerSize;
2583 static const int kSize = kConfigurableOffset + kPointerSize;
2584 // Indices of in-object properties.
2585 static const int kValueIndex = 0;
2586 static const int kWritableIndex = 1;
2587 static const int kEnumerableIndex = 2;
2588 static const int kConfigurableIndex = 3;
2589
2590 private:
2591 DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataPropertyDescriptor);
2592};
2593
2594
2595// JSIteratorResult is just a JSObject with a specific initial map.
2596// This initial map adds in-object properties for "done" and "value",
2597// as specified by ES6 section 25.1.1.3 The IteratorResult Interface
2598class JSIteratorResult: public JSObject {
2599 public:
2600 // Offsets of object fields.
2601 static const int kValueOffset = JSObject::kHeaderSize;
2602 static const int kDoneOffset = kValueOffset + kPointerSize;
2603 static const int kSize = kDoneOffset + kPointerSize;
2604 // Indices of in-object properties.
2605 static const int kValueIndex = 0;
2606 static const int kDoneIndex = 1;
2607
2608 private:
2609 DISALLOW_IMPLICIT_CONSTRUCTORS(JSIteratorResult);
2610};
2611
2612
2613// Common superclass for JSSloppyArgumentsObject and JSStrictArgumentsObject.
2614class JSArgumentsObject: public JSObject {
2615 public:
2616 // Offsets of object fields.
2617 static const int kLengthOffset = JSObject::kHeaderSize;
2618 static const int kHeaderSize = kLengthOffset + kPointerSize;
2619 // Indices of in-object properties.
2620 static const int kLengthIndex = 0;
2621
2622 private:
2623 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArgumentsObject);
2624};
2625
2626
2627// JSSloppyArgumentsObject is just a JSObject with specific initial map.
2628// This initial map adds in-object properties for "length" and "callee".
2629class JSSloppyArgumentsObject: public JSArgumentsObject {
2630 public:
2631 // Offsets of object fields.
2632 static const int kCalleeOffset = JSArgumentsObject::kHeaderSize;
2633 static const int kSize = kCalleeOffset + kPointerSize;
2634 // Indices of in-object properties.
2635 static const int kCalleeIndex = 1;
2636
2637 private:
2638 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSloppyArgumentsObject);
2639};
2640
2641
2642// JSStrictArgumentsObject is just a JSObject with specific initial map.
2643// This initial map adds an in-object property for "length".
2644class JSStrictArgumentsObject: public JSArgumentsObject {
2645 public:
2646 // Offsets of object fields.
2647 static const int kSize = JSArgumentsObject::kHeaderSize;
2648
2649 private:
2650 DISALLOW_IMPLICIT_CONSTRUCTORS(JSStrictArgumentsObject);
2651};
2652
2653
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002654// Common superclass for FixedArrays that allow implementations to share
2655// common accessors and some code paths.
2656class FixedArrayBase: public HeapObject {
Steve Blocka7e24c12009-10-30 11:49:00 +00002657 public:
2658 // [length]: length of the array.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002659 inline int length() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00002660 inline void set_length(int value);
2661
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002662 // Get and set the length using acquire loads and release stores.
2663 inline int synchronized_length() const;
2664 inline void synchronized_set_length(int value);
2665
2666 DECLARE_CAST(FixedArrayBase)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002667
2668 // Layout description.
2669 // Length is smi tagged when it is stored.
2670 static const int kLengthOffset = HeapObject::kHeaderSize;
2671 static const int kHeaderSize = kLengthOffset + kPointerSize;
2672};
2673
2674
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002675class FixedDoubleArray;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002676class IncrementalMarking;
2677
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002678
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002679// FixedArray describes fixed-sized arrays with element type Object*.
2680class FixedArray: public FixedArrayBase {
2681 public:
Steve Blocka7e24c12009-10-30 11:49:00 +00002682 // Setter and getter for elements.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002683 inline Object* get(int index) const;
Ben Murdoch097c5b22016-05-18 11:27:45 +01002684 static inline Handle<Object> get(FixedArray* array, int index,
2685 Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00002686 // Setter that uses write barrier.
2687 inline void set(int index, Object* value);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002688 inline bool is_the_hole(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00002689
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002690 // Setter that doesn't need write barrier.
Steve Blocka7e24c12009-10-30 11:49:00 +00002691 inline void set(int index, Smi* value);
2692 // Setter with explicit barrier mode.
2693 inline void set(int index, Object* value, WriteBarrierMode mode);
2694
2695 // Setters for frequently used oddballs located in old space.
2696 inline void set_undefined(int index);
2697 inline void set_null(int index);
2698 inline void set_the_hole(int index);
2699
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002700 inline Object** GetFirstElementAddress();
2701 inline bool ContainsOnlySmisOrHoles();
2702
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002703 // Gives access to raw memory which stores the array's data.
2704 inline Object** data_start();
2705
2706 inline void FillWithHoles(int from, int to);
2707
2708 // Shrink length and insert filler objects.
2709 void Shrink(int length);
2710
Steve Blocka7e24c12009-10-30 11:49:00 +00002711 // Copy a sub array from the receiver to dest.
2712 void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
2713
2714 // Garbage collection support.
2715 static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; }
2716
2717 // Code Generation support.
2718 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2719
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002720 // Garbage collection support.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002721 inline Object** RawFieldOfElementAt(int index);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002722
2723 DECLARE_CAST(FixedArray)
Steve Blocka7e24c12009-10-30 11:49:00 +00002724
Leon Clarkee46be812010-01-19 14:06:41 +00002725 // Maximal allowed size, in bytes, of a single FixedArray.
2726 // Prevents overflowing size computations, as well as extreme memory
2727 // consumption.
Ben Murdoch692be652012-01-10 18:47:50 +00002728 static const int kMaxSize = 128 * MB * kPointerSize;
Leon Clarkee46be812010-01-19 14:06:41 +00002729 // Maximally allowed length of a FixedArray.
2730 static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00002731
2732 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002733 DECLARE_PRINTER(FixedArray)
2734 DECLARE_VERIFIER(FixedArray)
Steve Blocka7e24c12009-10-30 11:49:00 +00002735#ifdef DEBUG
Steve Blocka7e24c12009-10-30 11:49:00 +00002736 // Checks if two FixedArrays have identical contents.
2737 bool IsEqualTo(FixedArray* other);
2738#endif
2739
2740 // Swap two elements in a pair of arrays. If this array and the
2741 // numbers array are the same object, the elements are only swapped
2742 // once.
2743 void SwapPairs(FixedArray* numbers, int i, int j);
2744
2745 // Sort prefix of this array and the numbers array as pairs wrt. the
2746 // numbers. If the numbers array and the this array are the same
2747 // object, the prefix of this array is sorted.
2748 void SortPairs(FixedArray* numbers, uint32_t len);
2749
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002750 typedef FlexibleBodyDescriptor<kHeaderSize> BodyDescriptor;
Iain Merrick75681382010-08-19 15:07:18 +01002751
Steve Blocka7e24c12009-10-30 11:49:00 +00002752 protected:
Leon Clarke4515c472010-02-03 11:58:03 +00002753 // Set operation on FixedArray without using write barriers. Can
2754 // only be used for storing old space objects or smis.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002755 static inline void NoWriteBarrierSet(FixedArray* array,
2756 int index,
2757 Object* value);
2758
Steve Blocka7e24c12009-10-30 11:49:00 +00002759 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002760 STATIC_ASSERT(kHeaderSize == Internals::kFixedArrayHeaderSize);
2761
Steve Blocka7e24c12009-10-30 11:49:00 +00002762 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray);
2763};
2764
2765
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002766// FixedDoubleArray describes fixed-sized arrays with element type double.
2767class FixedDoubleArray: public FixedArrayBase {
2768 public:
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002769 // Setter and getter for elements.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00002770 inline double get_scalar(int index);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002771 inline uint64_t get_representation(int index);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002772 static inline Handle<Object> get(FixedDoubleArray* array, int index,
2773 Isolate* isolate);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002774 inline void set(int index, double value);
2775 inline void set_the_hole(int index);
2776
2777 // Checking for the hole.
2778 inline bool is_the_hole(int index);
2779
2780 // Garbage collection support.
2781 inline static int SizeFor(int length) {
2782 return kHeaderSize + length * kDoubleSize;
2783 }
2784
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002785 // Gives access to raw memory which stores the array's data.
2786 inline double* data_start();
2787
2788 inline void FillWithHoles(int from, int to);
2789
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002790 // Code Generation support.
2791 static int OffsetOfElementAt(int index) { return SizeFor(index); }
2792
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002793 DECLARE_CAST(FixedDoubleArray)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002794
2795 // Maximal allowed size, in bytes, of a single FixedDoubleArray.
2796 // Prevents overflowing size computations, as well as extreme memory
2797 // consumption.
2798 static const int kMaxSize = 512 * MB;
2799 // Maximally allowed length of a FixedArray.
2800 static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize;
2801
2802 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002803 DECLARE_PRINTER(FixedDoubleArray)
2804 DECLARE_VERIFIER(FixedDoubleArray)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00002805
2806 private:
2807 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray);
2808};
2809
2810
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002811class WeakFixedArray : public FixedArray {
2812 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002813 // If |maybe_array| is not a WeakFixedArray, a fresh one will be allocated.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002814 // This function does not check if the value exists already, callers must
2815 // ensure this themselves if necessary.
2816 static Handle<WeakFixedArray> Add(Handle<Object> maybe_array,
2817 Handle<HeapObject> value,
2818 int* assigned_index = NULL);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002819
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002820 // Returns true if an entry was found and removed.
2821 bool Remove(Handle<HeapObject> value);
2822
2823 class NullCallback {
2824 public:
2825 static void Callback(Object* value, int old_index, int new_index) {}
2826 };
2827
2828 template <class CompactionCallback>
2829 void Compact();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002830
2831 inline Object* Get(int index) const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002832 inline void Clear(int index);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002833 inline int Length() const;
2834
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002835 inline bool IsEmptySlot(int index) const;
2836 static Object* Empty() { return Smi::FromInt(0); }
2837
2838 class Iterator {
2839 public:
2840 explicit Iterator(Object* maybe_array) : list_(NULL) { Reset(maybe_array); }
2841 void Reset(Object* maybe_array);
2842
2843 template <class T>
2844 inline T* Next();
2845
2846 private:
2847 int index_;
2848 WeakFixedArray* list_;
2849#ifdef DEBUG
2850 int last_used_index_;
2851 DisallowHeapAllocation no_gc_;
2852#endif // DEBUG
2853 DISALLOW_COPY_AND_ASSIGN(Iterator);
2854 };
2855
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002856 DECLARE_CAST(WeakFixedArray)
2857
2858 private:
2859 static const int kLastUsedIndexIndex = 0;
2860 static const int kFirstIndex = 1;
2861
2862 static Handle<WeakFixedArray> Allocate(
2863 Isolate* isolate, int size, Handle<WeakFixedArray> initialize_from);
2864
2865 static void Set(Handle<WeakFixedArray> array, int index,
2866 Handle<HeapObject> value);
2867 inline void clear(int index);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002868
2869 inline int last_used_index() const;
2870 inline void set_last_used_index(int index);
2871
2872 // Disallow inherited setters.
2873 void set(int index, Smi* value);
2874 void set(int index, Object* value);
2875 void set(int index, Object* value, WriteBarrierMode mode);
2876 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakFixedArray);
2877};
2878
2879
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002880// Generic array grows dynamically with O(1) amortized insertion.
2881class ArrayList : public FixedArray {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002882 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002883 enum AddMode {
2884 kNone,
2885 // Use this if GC can delete elements from the array.
2886 kReloadLengthAfterAllocation,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002887 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002888 static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj,
2889 AddMode mode = kNone);
2890 static Handle<ArrayList> Add(Handle<ArrayList> array, Handle<Object> obj1,
2891 Handle<Object> obj2, AddMode = kNone);
2892 inline int Length();
2893 inline void SetLength(int length);
2894 inline Object* Get(int index);
2895 inline Object** Slot(int index);
2896 inline void Set(int index, Object* obj);
2897 inline void Clear(int index, Object* undefined);
2898 bool IsFull();
2899 DECLARE_CAST(ArrayList)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002900
2901 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002902 static Handle<ArrayList> EnsureSpace(Handle<ArrayList> array, int length);
2903 static const int kLengthIndex = 0;
2904 static const int kFirstIndex = 1;
2905 DISALLOW_IMPLICIT_CONSTRUCTORS(ArrayList);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002906};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01002907
2908
Steve Blocka7e24c12009-10-30 11:49:00 +00002909// DescriptorArrays are fixed arrays used to hold instance descriptors.
2910// The format of the these objects is:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002911// [0]: Number of descriptors
2912// [1]: Either Smi(0) if uninitialized, or a pointer to small fixed array:
2913// [0]: pointer to fixed array with enum cache
2914// [1]: either Smi(0) or pointer to fixed array with indices
2915// [2]: first key
2916// [2 + number of descriptors * kDescriptorSize]: start of slack
Steve Blocka7e24c12009-10-30 11:49:00 +00002917class DescriptorArray: public FixedArray {
2918 public:
Ben Murdoch257744e2011-11-30 15:57:28 +00002919 // Returns true for both shared empty_descriptor_array and for smis, which the
2920 // map uses to encode additional bit fields when the descriptor array is not
2921 // yet used.
Steve Blocka7e24c12009-10-30 11:49:00 +00002922 inline bool IsEmpty();
Leon Clarkee46be812010-01-19 14:06:41 +00002923
Steve Blocka7e24c12009-10-30 11:49:00 +00002924 // Returns the number of descriptors in the array.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002925 inline int number_of_descriptors();
Steve Blocka7e24c12009-10-30 11:49:00 +00002926
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002927 inline int number_of_descriptors_storage();
Steve Blocka7e24c12009-10-30 11:49:00 +00002928
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002929 inline int NumberOfSlackDescriptors();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002930
2931 inline void SetNumberOfDescriptors(int number_of_descriptors);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002932 inline int number_of_entries();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002933
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002934 inline bool HasEnumCache();
Steve Blocka7e24c12009-10-30 11:49:00 +00002935
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002936 inline void CopyEnumCacheFrom(DescriptorArray* array);
Steve Blocka7e24c12009-10-30 11:49:00 +00002937
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002938 inline FixedArray* GetEnumCache();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002939
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002940 inline bool HasEnumIndicesCache();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002941
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002942 inline FixedArray* GetEnumIndicesCache();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002943
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002944 inline Object** GetEnumCacheSlot();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002945
2946 void ClearEnumCache();
Ben Murdoch257744e2011-11-30 15:57:28 +00002947
Steve Blocka7e24c12009-10-30 11:49:00 +00002948 // Initialize or change the enum cache,
2949 // using the supplied storage for the small "bridge".
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002950 static void SetEnumCache(Handle<DescriptorArray> descriptors,
2951 Isolate* isolate, Handle<FixedArray> new_cache,
2952 Handle<FixedArray> new_index_cache);
Steve Blocka7e24c12009-10-30 11:49:00 +00002953
2954 // Accessors for fetching instance descriptor at descriptor number.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002955 inline Name* GetKey(int descriptor_number);
2956 inline Object** GetKeySlot(int descriptor_number);
Steve Blocka7e24c12009-10-30 11:49:00 +00002957 inline Object* GetValue(int descriptor_number);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002958 inline void SetValue(int descriptor_number, Object* value);
2959 inline Object** GetValueSlot(int descriptor_number);
2960 static inline int GetValueOffset(int descriptor_number);
2961 inline Object** GetDescriptorStartSlot(int descriptor_number);
2962 inline Object** GetDescriptorEndSlot(int descriptor_number);
2963 inline PropertyDetails GetDetails(int descriptor_number);
Steve Blocka7e24c12009-10-30 11:49:00 +00002964 inline PropertyType GetType(int descriptor_number);
2965 inline int GetFieldIndex(int descriptor_number);
Ben Murdoch097c5b22016-05-18 11:27:45 +01002966 FieldType* GetFieldType(int descriptor_number);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002967 inline Object* GetConstant(int descriptor_number);
Steve Blocka7e24c12009-10-30 11:49:00 +00002968 inline Object* GetCallbacksObject(int descriptor_number);
2969 inline AccessorDescriptor* GetCallbacks(int descriptor_number);
Steve Blocka7e24c12009-10-30 11:49:00 +00002970
Ben Murdochb8a8cc12014-11-26 15:28:44 +00002971 inline Name* GetSortedKey(int descriptor_number);
2972 inline int GetSortedKeyIndex(int descriptor_number);
2973 inline void SetSortedKey(int pointer, int descriptor_number);
2974 inline void SetRepresentation(int descriptor_number,
2975 Representation representation);
2976
2977 // Accessor for complete descriptor.
2978 inline void Get(int descriptor_number, Descriptor* desc);
2979 inline void Set(int descriptor_number, Descriptor* desc);
2980 void Replace(int descriptor_number, Descriptor* descriptor);
2981
2982 // Append automatically sets the enumeration index. This should only be used
2983 // to add descriptors in bulk at the end, followed by sorting the descriptor
2984 // array.
2985 inline void Append(Descriptor* desc);
2986
2987 static Handle<DescriptorArray> CopyUpTo(Handle<DescriptorArray> desc,
2988 int enumeration_index,
2989 int slack = 0);
2990
2991 static Handle<DescriptorArray> CopyUpToAddAttributes(
2992 Handle<DescriptorArray> desc,
2993 int enumeration_index,
2994 PropertyAttributes attributes,
2995 int slack = 0);
2996
2997 // Sort the instance descriptors by the hash codes of their keys.
2998 void Sort();
2999
3000 // Search the instance descriptors for given name.
3001 INLINE(int Search(Name* name, int number_of_own_descriptors));
3002
3003 // As the above, but uses DescriptorLookupCache and updates it when
3004 // necessary.
Ben Murdoch097c5b22016-05-18 11:27:45 +01003005 INLINE(int SearchWithCache(Isolate* isolate, Name* name, Map* map));
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003006
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003007 bool IsEqualUpTo(DescriptorArray* desc, int nof_descriptors);
3008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003009 // Allocates a DescriptorArray, but returns the singleton
3010 // empty descriptor array object if number_of_descriptors is 0.
Ben Murdoch097c5b22016-05-18 11:27:45 +01003011 static Handle<DescriptorArray> Allocate(
3012 Isolate* isolate, int number_of_descriptors, int slack,
3013 PretenureFlag pretenure = NOT_TENURED);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003014
3015 DECLARE_CAST(DescriptorArray)
3016
3017 // Constant for denoting key was not found.
3018 static const int kNotFound = -1;
3019
3020 static const int kDescriptorLengthIndex = 0;
3021 static const int kEnumCacheIndex = 1;
3022 static const int kFirstIndex = 2;
3023
3024 // The length of the "bridge" to the enum cache.
3025 static const int kEnumCacheBridgeLength = 2;
3026 static const int kEnumCacheBridgeCacheIndex = 0;
3027 static const int kEnumCacheBridgeIndicesCacheIndex = 1;
3028
3029 // Layout description.
3030 static const int kDescriptorLengthOffset = FixedArray::kHeaderSize;
3031 static const int kEnumCacheOffset = kDescriptorLengthOffset + kPointerSize;
3032 static const int kFirstOffset = kEnumCacheOffset + kPointerSize;
3033
3034 // Layout description for the bridge array.
3035 static const int kEnumCacheBridgeCacheOffset = FixedArray::kHeaderSize;
3036
3037 // Layout of descriptor.
3038 static const int kDescriptorKey = 0;
3039 static const int kDescriptorDetails = 1;
3040 static const int kDescriptorValue = 2;
3041 static const int kDescriptorSize = 3;
3042
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003043#if defined(DEBUG) || defined(OBJECT_PRINT)
3044 // For our gdb macros, we should perhaps change these in the future.
3045 void Print();
3046
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003047 // Print all the descriptors.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003048 void PrintDescriptors(std::ostream& os); // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003049#endif
3050
3051#ifdef DEBUG
3052 // Is the descriptor array sorted and without duplicates?
3053 bool IsSortedNoDuplicates(int valid_descriptors = -1);
3054
3055 // Is the descriptor array consistent with the back pointers in targets?
3056 bool IsConsistentWithBackPointers(Map* current_map);
3057
3058 // Are two DescriptorArrays equal?
3059 bool IsEqualTo(DescriptorArray* other);
3060#endif
3061
3062 // Returns the fixed array length required to hold number_of_descriptors
3063 // descriptors.
3064 static int LengthFor(int number_of_descriptors) {
3065 return ToKeyIndex(number_of_descriptors);
3066 }
3067
3068 private:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003069 // An entry in a DescriptorArray, represented as an (array, index) pair.
3070 class Entry {
3071 public:
3072 inline explicit Entry(DescriptorArray* descs, int index) :
3073 descs_(descs), index_(index) { }
3074
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003075 inline PropertyType type();
3076 inline Object* GetCallbackObject();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003077
3078 private:
3079 DescriptorArray* descs_;
3080 int index_;
3081 };
3082
Steve Blocka7e24c12009-10-30 11:49:00 +00003083 // Conversion from descriptor number to array indices.
3084 static int ToKeyIndex(int descriptor_number) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003085 return kFirstIndex +
3086 (descriptor_number * kDescriptorSize) +
3087 kDescriptorKey;
Steve Blocka7e24c12009-10-30 11:49:00 +00003088 }
Leon Clarkee46be812010-01-19 14:06:41 +00003089
3090 static int ToDetailsIndex(int descriptor_number) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003091 return kFirstIndex +
3092 (descriptor_number * kDescriptorSize) +
3093 kDescriptorDetails;
Leon Clarkee46be812010-01-19 14:06:41 +00003094 }
3095
Steve Blocka7e24c12009-10-30 11:49:00 +00003096 static int ToValueIndex(int descriptor_number) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003097 return kFirstIndex +
3098 (descriptor_number * kDescriptorSize) +
3099 kDescriptorValue;
Steve Blocka7e24c12009-10-30 11:49:00 +00003100 }
Steve Blocka7e24c12009-10-30 11:49:00 +00003101
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003102 // Transfer a complete descriptor from the src descriptor array to this
3103 // descriptor array.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003104 void CopyFrom(int index, DescriptorArray* src);
Steve Blocka7e24c12009-10-30 11:49:00 +00003105
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003106 inline void SetDescriptor(int descriptor_number, Descriptor* desc);
Steve Blocka7e24c12009-10-30 11:49:00 +00003107
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003108 // Swap first and second descriptor.
3109 inline void SwapSortedKeys(int first, int second);
3110
Steve Blocka7e24c12009-10-30 11:49:00 +00003111 DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray);
3112};
3113
3114
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003115enum SearchMode { ALL_ENTRIES, VALID_ENTRIES };
3116
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003117template <SearchMode search_mode, typename T>
3118inline int Search(T* array, Name* name, int valid_entries = 0,
3119 int* out_insertion_index = NULL);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003120
3121
Steve Blocka7e24c12009-10-30 11:49:00 +00003122// HashTable is a subclass of FixedArray that implements a hash table
3123// that uses open addressing and quadratic probing.
3124//
3125// In order for the quadratic probing to work, elements that have not
3126// yet been used and elements that have been deleted are
3127// distinguished. Probing continues when deleted elements are
3128// encountered and stops when unused elements are encountered.
3129//
3130// - Elements with key == undefined have not been used yet.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003131// - Elements with key == the_hole have been deleted.
Steve Blocka7e24c12009-10-30 11:49:00 +00003132//
3133// The hash table class is parameterized with a Shape and a Key.
3134// Shape must be a class with the following interface:
3135// class ExampleShape {
3136// public:
3137// // Tells whether key matches other.
3138// static bool IsMatch(Key key, Object* other);
3139// // Returns the hash value for key.
3140// static uint32_t Hash(Key key);
3141// // Returns the hash value for object.
3142// static uint32_t HashForObject(Key key, Object* object);
3143// // Convert key to an object.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003144// static inline Handle<Object> AsHandle(Isolate* isolate, Key key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003145// // The prefix size indicates number of elements in the beginning
3146// // of the backing storage.
3147// static const int kPrefixSize = ..;
3148// // The Element size indicates number of elements per entry.
3149// static const int kEntrySize = ..;
3150// };
Steve Block3ce2e202009-11-05 08:53:23 +00003151// The prefix size indicates an amount of memory in the
Steve Blocka7e24c12009-10-30 11:49:00 +00003152// beginning of the backing storage that can be used for non-element
3153// information by subclasses.
3154
Ben Murdochc7cc0282012-03-05 14:35:55 +00003155template<typename Key>
3156class BaseShape {
3157 public:
3158 static const bool UsesSeed = false;
3159 static uint32_t Hash(Key key) { return 0; }
3160 static uint32_t SeededHash(Key key, uint32_t seed) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003161 DCHECK(UsesSeed);
Ben Murdochc7cc0282012-03-05 14:35:55 +00003162 return Hash(key);
3163 }
3164 static uint32_t HashForObject(Key key, Object* object) { return 0; }
3165 static uint32_t SeededHashForObject(Key key, uint32_t seed, Object* object) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003166 DCHECK(UsesSeed);
Ben Murdochc7cc0282012-03-05 14:35:55 +00003167 return HashForObject(key, object);
3168 }
3169};
3170
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003171
3172class HashTableBase : public FixedArray {
3173 public:
3174 // Returns the number of elements in the hash table.
3175 inline int NumberOfElements();
3176
3177 // Returns the number of deleted elements in the hash table.
3178 inline int NumberOfDeletedElements();
3179
3180 // Returns the capacity of the hash table.
3181 inline int Capacity();
3182
3183 // ElementAdded should be called whenever an element is added to a
3184 // hash table.
3185 inline void ElementAdded();
3186
3187 // ElementRemoved should be called whenever an element is removed from
3188 // a hash table.
3189 inline void ElementRemoved();
3190 inline void ElementsRemoved(int n);
3191
3192 // Computes the required capacity for a table holding the given
3193 // number of elements. May be more than HashTable::kMaxCapacity.
3194 static inline int ComputeCapacity(int at_least_space_for);
3195
3196 // Tells whether k is a real key. The hole and undefined are not allowed
3197 // as keys and can be used to indicate missing or deleted elements.
3198 inline bool IsKey(Object* k);
3199
3200 // Compute the probe offset (quadratic probing).
3201 INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
3202 return (n + n * n) >> 1;
3203 }
3204
3205 static const int kNumberOfElementsIndex = 0;
3206 static const int kNumberOfDeletedElementsIndex = 1;
3207 static const int kCapacityIndex = 2;
3208 static const int kPrefixStartIndex = 3;
3209
3210 // Constant used for denoting a absent entry.
3211 static const int kNotFound = -1;
3212
3213 protected:
3214 // Update the number of elements in the hash table.
3215 inline void SetNumberOfElements(int nof);
3216
3217 // Update the number of deleted elements in the hash table.
3218 inline void SetNumberOfDeletedElements(int nod);
3219
3220 // Returns probe entry.
3221 static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
3222 DCHECK(base::bits::IsPowerOfTwo32(size));
3223 return (hash + GetProbeOffset(number)) & (size - 1);
3224 }
3225
3226 inline static uint32_t FirstProbe(uint32_t hash, uint32_t size) {
3227 return hash & (size - 1);
3228 }
3229
3230 inline static uint32_t NextProbe(
3231 uint32_t last, uint32_t number, uint32_t size) {
3232 return (last + number) & (size - 1);
3233 }
3234};
3235
3236
3237template <typename Derived, typename Shape, typename Key>
3238class HashTable : public HashTableBase {
Steve Blocka7e24c12009-10-30 11:49:00 +00003239 public:
Ben Murdochc7cc0282012-03-05 14:35:55 +00003240 // Wrapper methods
3241 inline uint32_t Hash(Key key) {
3242 if (Shape::UsesSeed) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003243 return Shape::SeededHash(key, GetHeap()->HashSeed());
Ben Murdochc7cc0282012-03-05 14:35:55 +00003244 } else {
3245 return Shape::Hash(key);
3246 }
3247 }
3248
3249 inline uint32_t HashForObject(Key key, Object* object) {
3250 if (Shape::UsesSeed) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003251 return Shape::SeededHashForObject(key, GetHeap()->HashSeed(), object);
Ben Murdochc7cc0282012-03-05 14:35:55 +00003252 } else {
3253 return Shape::HashForObject(key, object);
3254 }
3255 }
3256
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003257 // Returns a new HashTable object.
3258 MUST_USE_RESULT static Handle<Derived> New(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003259 Isolate* isolate, int at_least_space_for,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003260 MinimumCapacity capacity_option = USE_DEFAULT_MINIMUM_CAPACITY,
Kristian Monsen80d68ea2010-09-08 11:05:35 +01003261 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +00003262
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003263 DECLARE_CAST(HashTable)
Steve Blocka7e24c12009-10-30 11:49:00 +00003264
3265 // Garbage collection support.
3266 void IteratePrefix(ObjectVisitor* visitor);
3267 void IterateElements(ObjectVisitor* visitor);
3268
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003269 // Find entry for key otherwise return kNotFound.
3270 inline int FindEntry(Key key);
3271 inline int FindEntry(Isolate* isolate, Key key, int32_t hash);
3272 int FindEntry(Isolate* isolate, Key key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003273
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003274 // Rehashes the table in-place.
3275 void Rehash(Key key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003276
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003277 // Returns the key at entry.
3278 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
3279
3280 static const int kElementsStartIndex = kPrefixStartIndex + Shape::kPrefixSize;
Leon Clarkee46be812010-01-19 14:06:41 +00003281 static const int kEntrySize = Shape::kEntrySize;
3282 static const int kElementsStartOffset =
Steve Blocka7e24c12009-10-30 11:49:00 +00003283 kHeaderSize + kElementsStartIndex * kPointerSize;
Steve Block6ded16b2010-05-10 14:33:55 +01003284 static const int kCapacityOffset =
3285 kHeaderSize + kCapacityIndex * kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00003286
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003287 // Returns the index for an entry (of the key)
3288 static inline int EntryToIndex(int entry) {
3289 return (entry * kEntrySize) + kElementsStartIndex;
3290 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003291
Steve Blocka7e24c12009-10-30 11:49:00 +00003292 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003293 friend class ObjectHashTable;
3294
Steve Blocka7e24c12009-10-30 11:49:00 +00003295 // Find the entry at which to insert element with the given key that
3296 // has the given hash value.
3297 uint32_t FindInsertionEntry(uint32_t hash);
3298
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003299 // Attempt to shrink hash table after removal of key.
3300 MUST_USE_RESULT static Handle<Derived> Shrink(Handle<Derived> table, Key key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003301
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003302 // Ensure enough space for n additional elements.
3303 MUST_USE_RESULT static Handle<Derived> EnsureCapacity(
3304 Handle<Derived> table,
3305 int n,
3306 Key key,
3307 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +00003308
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003309 // Returns true if this table has sufficient capacity for adding n elements.
3310 bool HasSufficientCapacity(int n);
Leon Clarkee46be812010-01-19 14:06:41 +00003311
Steve Blocka7e24c12009-10-30 11:49:00 +00003312 // Sets the capacity of the hash table.
3313 void SetCapacity(int capacity) {
3314 // To scale a computed hash code to fit within the hash table, we
3315 // use bit-wise AND with a mask, so the capacity must be positive
3316 // and non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003317 DCHECK(capacity > 0);
3318 DCHECK(capacity <= kMaxCapacity);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003319 set(kCapacityIndex, Smi::FromInt(capacity));
Steve Blocka7e24c12009-10-30 11:49:00 +00003320 }
3321
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003322 // Maximal capacity of HashTable. Based on maximal length of underlying
3323 // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
3324 // cannot overflow.
3325 static const int kMaxCapacity =
3326 (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003327
3328 private:
3329 // Returns _expected_ if one of entries given by the first _probe_ probes is
3330 // equal to _expected_. Otherwise, returns the entry given by the probe
3331 // number _probe_.
3332 uint32_t EntryForProbe(Key key, Object* k, int probe, uint32_t expected);
3333
3334 void Swap(uint32_t entry1, uint32_t entry2, WriteBarrierMode mode);
3335
3336 // Rehashes this hash-table into the new table.
3337 void Rehash(Handle<Derived> new_table, Key key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003338};
3339
3340
Steve Blocka7e24c12009-10-30 11:49:00 +00003341// HashTableKey is an abstract superclass for virtual key behavior.
3342class HashTableKey {
3343 public:
3344 // Returns whether the other object matches this key.
3345 virtual bool IsMatch(Object* other) = 0;
3346 // Returns the hash value for this key.
3347 virtual uint32_t Hash() = 0;
3348 // Returns the hash value for object.
3349 virtual uint32_t HashForObject(Object* key) = 0;
Steve Block3ce2e202009-11-05 08:53:23 +00003350 // Returns the key object for storing into the hash table.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003351 MUST_USE_RESULT virtual Handle<Object> AsHandle(Isolate* isolate) = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +00003352 // Required.
3353 virtual ~HashTableKey() {}
3354};
3355
Ben Murdochc7cc0282012-03-05 14:35:55 +00003356
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003357class StringTableShape : public BaseShape<HashTableKey*> {
Steve Blocka7e24c12009-10-30 11:49:00 +00003358 public:
Steve Block44f0eee2011-05-26 01:26:41 +01003359 static inline bool IsMatch(HashTableKey* key, Object* value) {
Steve Blocka7e24c12009-10-30 11:49:00 +00003360 return key->IsMatch(value);
3361 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003362
Steve Block44f0eee2011-05-26 01:26:41 +01003363 static inline uint32_t Hash(HashTableKey* key) {
Steve Blocka7e24c12009-10-30 11:49:00 +00003364 return key->Hash();
3365 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003366
Steve Block44f0eee2011-05-26 01:26:41 +01003367 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
Steve Blocka7e24c12009-10-30 11:49:00 +00003368 return key->HashForObject(object);
3369 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003370
3371 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003372
3373 static const int kPrefixSize = 0;
3374 static const int kEntrySize = 1;
3375};
3376
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003377class SeqOneByteString;
Ben Murdoch257744e2011-11-30 15:57:28 +00003378
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003379// StringTable.
Steve Blocka7e24c12009-10-30 11:49:00 +00003380//
3381// No special elements in the prefix and the element size is 1
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003382// because only the string itself (the key) needs to be stored.
3383class StringTable: public HashTable<StringTable,
3384 StringTableShape,
3385 HashTableKey*> {
Steve Blocka7e24c12009-10-30 11:49:00 +00003386 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003387 // Find string in the string table. If it is not there yet, it is
3388 // added. The return value is the string found.
3389 static Handle<String> LookupString(Isolate* isolate, Handle<String> key);
3390 static Handle<String> LookupKey(Isolate* isolate, HashTableKey* key);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003391 static String* LookupKeyIfExists(Isolate* isolate, HashTableKey* key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003392
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003393 // Tries to internalize given string and returns string handle on success
3394 // or an empty handle otherwise.
3395 MUST_USE_RESULT static MaybeHandle<String> InternalizeStringIfExists(
3396 Isolate* isolate,
3397 Handle<String> string);
Steve Blocka7e24c12009-10-30 11:49:00 +00003398
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003399 // Looks up a string that is equal to the given string and returns
3400 // string handle if it is found, or an empty handle otherwise.
3401 MUST_USE_RESULT static MaybeHandle<String> LookupStringIfExists(
3402 Isolate* isolate,
3403 Handle<String> str);
3404 MUST_USE_RESULT static MaybeHandle<String> LookupTwoCharsStringIfExists(
3405 Isolate* isolate,
3406 uint16_t c1,
3407 uint16_t c2);
3408
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003409 static void EnsureCapacityForDeserialization(Isolate* isolate, int expected);
3410
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003411 DECLARE_CAST(StringTable)
Steve Blocka7e24c12009-10-30 11:49:00 +00003412
3413 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003414 template <bool seq_one_byte>
3415 friend class JsonParser;
Steve Blocka7e24c12009-10-30 11:49:00 +00003416
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003417 DISALLOW_IMPLICIT_CONSTRUCTORS(StringTable);
Steve Blocka7e24c12009-10-30 11:49:00 +00003418};
3419
3420
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003421template <typename Derived, typename Shape, typename Key>
3422class Dictionary: public HashTable<Derived, Shape, Key> {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003423 typedef HashTable<Derived, Shape, Key> DerivedHashTable;
Steve Blocka7e24c12009-10-30 11:49:00 +00003424
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003425 public:
Steve Blocka7e24c12009-10-30 11:49:00 +00003426 // Returns the value at entry.
3427 Object* ValueAt(int entry) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003428 return this->get(Derived::EntryToIndex(entry) + 1);
Steve Blocka7e24c12009-10-30 11:49:00 +00003429 }
3430
3431 // Set the value for entry.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003432 void ValueAtPut(int entry, Object* value) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003433 this->set(Derived::EntryToIndex(entry) + 1, value);
Steve Blocka7e24c12009-10-30 11:49:00 +00003434 }
3435
3436 // Returns the property details for the property at entry.
3437 PropertyDetails DetailsAt(int entry) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003438 return Shape::DetailsAt(static_cast<Derived*>(this), entry);
Steve Blocka7e24c12009-10-30 11:49:00 +00003439 }
3440
3441 // Set the details for entry.
3442 void DetailsAtPut(int entry, PropertyDetails value) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003443 Shape::DetailsAtPut(static_cast<Derived*>(this), entry, value);
Steve Blocka7e24c12009-10-30 11:49:00 +00003444 }
3445
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003446 // Returns true if property at given entry is deleted.
3447 bool IsDeleted(int entry) {
3448 return Shape::IsDeleted(static_cast<Derived*>(this), entry);
3449 }
Steve Blocka7e24c12009-10-30 11:49:00 +00003450
3451 // Delete a property from the dictionary.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003452 static Handle<Object> DeleteProperty(Handle<Derived> dictionary, int entry);
Steve Blocka7e24c12009-10-30 11:49:00 +00003453
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003454 // Attempt to shrink the dictionary after deletion of key.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003455 MUST_USE_RESULT static inline Handle<Derived> Shrink(
3456 Handle<Derived> dictionary,
3457 Key key) {
3458 return DerivedHashTable::Shrink(dictionary, key);
3459 }
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003460
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003461 // Sorting support
3462 // TODO(dcarney): templatize or move to SeededNumberDictionary
3463 void CopyValuesTo(FixedArray* elements);
3464
Steve Blocka7e24c12009-10-30 11:49:00 +00003465 // Returns the number of elements in the dictionary filtering out properties
3466 // with the specified attributes.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003467 // TODO(jkummerow): Deprecated, only used by Object.observe.
3468 int NumberOfElementsFilterAttributes(PropertyFilter filter);
Steve Blocka7e24c12009-10-30 11:49:00 +00003469
3470 // Returns the number of enumerable elements in the dictionary.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003471 // TODO(jkummerow): Deprecated, only used by Object.observe.
3472 int NumberOfEnumElements() {
3473 return NumberOfElementsFilterAttributes(ENUMERABLE_STRINGS);
3474 }
Steve Blocka7e24c12009-10-30 11:49:00 +00003475
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003476 // Returns true if the dictionary contains any elements that are non-writable,
3477 // non-configurable, non-enumerable, or have getters/setters.
3478 bool HasComplexElements();
3479
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00003480 enum SortMode { UNSORTED, SORTED };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003481
Steve Blocka7e24c12009-10-30 11:49:00 +00003482 // Fill in details for properties into storage.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003483 // Returns the number of properties added.
3484 // TODO(jkummerow): Deprecated, only used by Object.observe.
3485 int CopyKeysTo(FixedArray* storage, int index, PropertyFilter filter,
3486 SortMode sort_mode);
3487 // Collect the keys into the given KeyAccumulator, in ascending chronological
3488 // order of property creation.
3489 static void CollectKeysTo(Handle<Dictionary<Derived, Shape, Key> > dictionary,
3490 KeyAccumulator* keys, PropertyFilter filter);
3491
3492 // Copies enumerable keys to preallocated fixed array.
3493 void CopyEnumKeysTo(FixedArray* storage);
Steve Blocka7e24c12009-10-30 11:49:00 +00003494
3495 // Accessors for next enumeration index.
3496 void SetNextEnumerationIndex(int index) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003497 DCHECK(index != 0);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003498 this->set(kNextEnumerationIndexIndex, Smi::FromInt(index));
Steve Blocka7e24c12009-10-30 11:49:00 +00003499 }
3500
3501 int NextEnumerationIndex() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003502 return Smi::cast(this->get(kNextEnumerationIndexIndex))->value();
Steve Blocka7e24c12009-10-30 11:49:00 +00003503 }
3504
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003505 // Creates a new dictionary.
3506 MUST_USE_RESULT static Handle<Derived> New(
3507 Isolate* isolate,
3508 int at_least_space_for,
3509 PretenureFlag pretenure = NOT_TENURED);
Steve Blocka7e24c12009-10-30 11:49:00 +00003510
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003511 // Ensures that a new dictionary is created when the capacity is checked.
3512 void SetRequiresCopyOnCapacityChange();
3513
Steve Blocka7e24c12009-10-30 11:49:00 +00003514 // Ensure enough space for n additional elements.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003515 static Handle<Derived> EnsureCapacity(Handle<Derived> obj, int n, Key key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003516
Ben Murdochb0fe1622011-05-05 13:52:32 +01003517#ifdef OBJECT_PRINT
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003518 void Print(std::ostream& os); // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +00003519#endif
3520 // Returns the key (slow).
3521 Object* SlowReverseLookup(Object* value);
3522
3523 // Sets the entry to (key, value) pair.
3524 inline void SetEntry(int entry,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003525 Handle<Object> key,
3526 Handle<Object> value);
Ben Murdoch8b112d22011-06-08 16:22:53 +01003527 inline void SetEntry(int entry,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003528 Handle<Object> key,
3529 Handle<Object> value,
Steve Blocka7e24c12009-10-30 11:49:00 +00003530 PropertyDetails details);
3531
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003532 MUST_USE_RESULT static Handle<Derived> Add(
3533 Handle<Derived> dictionary,
3534 Key key,
3535 Handle<Object> value,
3536 PropertyDetails details);
Steve Blocka7e24c12009-10-30 11:49:00 +00003537
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003538 // Returns iteration indices array for the |dictionary|.
3539 // Values are direct indices in the |HashTable| array.
3540 static Handle<FixedArray> BuildIterationIndicesArray(
3541 Handle<Derived> dictionary);
3542
Steve Blocka7e24c12009-10-30 11:49:00 +00003543 protected:
3544 // Generic at put operation.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003545 MUST_USE_RESULT static Handle<Derived> AtPut(
3546 Handle<Derived> dictionary,
3547 Key key,
3548 Handle<Object> value);
Steve Blocka7e24c12009-10-30 11:49:00 +00003549
3550 // Add entry to dictionary.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003551 static void AddEntry(
3552 Handle<Derived> dictionary,
3553 Key key,
3554 Handle<Object> value,
3555 PropertyDetails details,
3556 uint32_t hash);
Steve Blocka7e24c12009-10-30 11:49:00 +00003557
3558 // Generate new enumeration indices to avoid enumeration index overflow.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003559 // Returns iteration indices array for the |dictionary|.
3560 static Handle<FixedArray> GenerateNewEnumerationIndices(
3561 Handle<Derived> dictionary);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003562 static const int kMaxNumberKeyIndex = DerivedHashTable::kPrefixStartIndex;
Steve Blocka7e24c12009-10-30 11:49:00 +00003563 static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
3564};
3565
3566
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003567template <typename Derived, typename Shape>
3568class NameDictionaryBase : public Dictionary<Derived, Shape, Handle<Name> > {
3569 typedef Dictionary<Derived, Shape, Handle<Name> > DerivedDictionary;
3570
3571 public:
3572 // Find entry for key, otherwise return kNotFound. Optimized version of
3573 // HashTable::FindEntry.
3574 int FindEntry(Handle<Name> key);
3575};
3576
3577
3578template <typename Key>
3579class BaseDictionaryShape : public BaseShape<Key> {
3580 public:
3581 template <typename Dictionary>
3582 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry) {
3583 STATIC_ASSERT(Dictionary::kEntrySize == 3);
3584 DCHECK(entry >= 0); // Not found is -1, which is not caught by get().
3585 return PropertyDetails(
3586 Smi::cast(dict->get(Dictionary::EntryToIndex(entry) + 2)));
3587 }
3588
3589 template <typename Dictionary>
3590 static inline void DetailsAtPut(Dictionary* dict, int entry,
3591 PropertyDetails value) {
3592 STATIC_ASSERT(Dictionary::kEntrySize == 3);
3593 dict->set(Dictionary::EntryToIndex(entry) + 2, value.AsSmi());
3594 }
3595
3596 template <typename Dictionary>
3597 static bool IsDeleted(Dictionary* dict, int entry) {
3598 return false;
3599 }
3600
3601 template <typename Dictionary>
3602 static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key,
3603 Handle<Object> value, PropertyDetails details);
3604};
3605
3606
3607class NameDictionaryShape : public BaseDictionaryShape<Handle<Name> > {
Steve Blocka7e24c12009-10-30 11:49:00 +00003608 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003609 static inline bool IsMatch(Handle<Name> key, Object* other);
3610 static inline uint32_t Hash(Handle<Name> key);
3611 static inline uint32_t HashForObject(Handle<Name> key, Object* object);
3612 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Name> key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003613 static const int kPrefixSize = 2;
3614 static const int kEntrySize = 3;
3615 static const bool kIsEnumerable = true;
3616};
3617
3618
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003619class NameDictionary
3620 : public NameDictionaryBase<NameDictionary, NameDictionaryShape> {
3621 typedef NameDictionaryBase<NameDictionary, NameDictionaryShape>
3622 DerivedDictionary;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003623
Steve Blocka7e24c12009-10-30 11:49:00 +00003624 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003625 DECLARE_CAST(NameDictionary)
Steve Blocka7e24c12009-10-30 11:49:00 +00003626
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003627 inline static Handle<FixedArray> DoGenerateNewEnumerationIndices(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003628 Handle<NameDictionary> dictionary);
Steve Blocka7e24c12009-10-30 11:49:00 +00003629};
3630
3631
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003632class GlobalDictionaryShape : public NameDictionaryShape {
3633 public:
3634 static const int kEntrySize = 2; // Overrides NameDictionaryShape::kEntrySize
3635
3636 template <typename Dictionary>
3637 static inline PropertyDetails DetailsAt(Dictionary* dict, int entry);
3638
3639 template <typename Dictionary>
3640 static inline void DetailsAtPut(Dictionary* dict, int entry,
3641 PropertyDetails value);
3642
3643 template <typename Dictionary>
3644 static bool IsDeleted(Dictionary* dict, int entry);
3645
3646 template <typename Dictionary>
3647 static inline void SetEntry(Dictionary* dict, int entry, Handle<Object> key,
3648 Handle<Object> value, PropertyDetails details);
3649};
3650
3651
3652class GlobalDictionary
3653 : public NameDictionaryBase<GlobalDictionary, GlobalDictionaryShape> {
3654 public:
3655 DECLARE_CAST(GlobalDictionary)
3656};
3657
3658
3659class NumberDictionaryShape : public BaseDictionaryShape<uint32_t> {
Steve Blocka7e24c12009-10-30 11:49:00 +00003660 public:
3661 static inline bool IsMatch(uint32_t key, Object* other);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003662 static inline Handle<Object> AsHandle(Isolate* isolate, uint32_t key);
Steve Blocka7e24c12009-10-30 11:49:00 +00003663 static const int kEntrySize = 3;
3664 static const bool kIsEnumerable = false;
3665};
3666
3667
Ben Murdochc7cc0282012-03-05 14:35:55 +00003668class SeededNumberDictionaryShape : public NumberDictionaryShape {
Steve Blocka7e24c12009-10-30 11:49:00 +00003669 public:
Ben Murdochc7cc0282012-03-05 14:35:55 +00003670 static const bool UsesSeed = true;
3671 static const int kPrefixSize = 2;
3672
3673 static inline uint32_t SeededHash(uint32_t key, uint32_t seed);
3674 static inline uint32_t SeededHashForObject(uint32_t key,
3675 uint32_t seed,
3676 Object* object);
3677};
3678
3679
3680class UnseededNumberDictionaryShape : public NumberDictionaryShape {
3681 public:
3682 static const int kPrefixSize = 0;
3683
3684 static inline uint32_t Hash(uint32_t key);
3685 static inline uint32_t HashForObject(uint32_t key, Object* object);
3686};
3687
3688
3689class SeededNumberDictionary
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003690 : public Dictionary<SeededNumberDictionary,
3691 SeededNumberDictionaryShape,
3692 uint32_t> {
Ben Murdochc7cc0282012-03-05 14:35:55 +00003693 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003694 DECLARE_CAST(SeededNumberDictionary)
Steve Blocka7e24c12009-10-30 11:49:00 +00003695
3696 // Type specific at put (default NONE attributes is used when adding).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003697 MUST_USE_RESULT static Handle<SeededNumberDictionary> AtNumberPut(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003698 Handle<SeededNumberDictionary> dictionary, uint32_t key,
3699 Handle<Object> value, bool used_as_prototype);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003700 MUST_USE_RESULT static Handle<SeededNumberDictionary> AddNumberEntry(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003701 Handle<SeededNumberDictionary> dictionary, uint32_t key,
3702 Handle<Object> value, PropertyDetails details, bool used_as_prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +00003703
3704 // Set an existing entry or add a new one if needed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003705 // Return the updated dictionary.
3706 MUST_USE_RESULT static Handle<SeededNumberDictionary> Set(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003707 Handle<SeededNumberDictionary> dictionary, uint32_t key,
3708 Handle<Object> value, PropertyDetails details, bool used_as_prototype);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003709
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003710 void UpdateMaxNumberKey(uint32_t key, bool used_as_prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +00003711
3712 // If slow elements are required we will never go back to fast-case
3713 // for the elements kept in this dictionary. We require slow
3714 // elements if an element has been added at an index larger than
3715 // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called
3716 // when defining a getter or setter with a number key.
3717 inline bool requires_slow_elements();
3718 inline void set_requires_slow_elements();
3719
3720 // Get the value of the max number key that has been added to this
3721 // dictionary. max_number_key can only be called if
3722 // requires_slow_elements returns false.
3723 inline uint32_t max_number_key();
3724
Steve Blocka7e24c12009-10-30 11:49:00 +00003725 // Bit masks.
3726 static const int kRequiresSlowElementsMask = 1;
3727 static const int kRequiresSlowElementsTagSize = 1;
3728 static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
3729};
3730
3731
Ben Murdochc7cc0282012-03-05 14:35:55 +00003732class UnseededNumberDictionary
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003733 : public Dictionary<UnseededNumberDictionary,
3734 UnseededNumberDictionaryShape,
3735 uint32_t> {
Ben Murdochc7cc0282012-03-05 14:35:55 +00003736 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003737 DECLARE_CAST(UnseededNumberDictionary)
Ben Murdochc7cc0282012-03-05 14:35:55 +00003738
3739 // Type specific at put (default NONE attributes is used when adding).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003740 MUST_USE_RESULT static Handle<UnseededNumberDictionary> AtNumberPut(
3741 Handle<UnseededNumberDictionary> dictionary,
3742 uint32_t key,
3743 Handle<Object> value);
3744 MUST_USE_RESULT static Handle<UnseededNumberDictionary> AddNumberEntry(
3745 Handle<UnseededNumberDictionary> dictionary,
3746 uint32_t key,
3747 Handle<Object> value);
Ben Murdochc7cc0282012-03-05 14:35:55 +00003748
3749 // Set an existing entry or add a new one if needed.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003750 // Return the updated dictionary.
3751 MUST_USE_RESULT static Handle<UnseededNumberDictionary> Set(
3752 Handle<UnseededNumberDictionary> dictionary,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003753 uint32_t key,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003754 Handle<Object> value);
Ben Murdochc7cc0282012-03-05 14:35:55 +00003755};
3756
3757
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003758class ObjectHashTableShape : public BaseShape<Handle<Object> > {
Ben Murdoch2b4ba112012-01-20 14:57:15 +00003759 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003760 static inline bool IsMatch(Handle<Object> key, Object* other);
3761 static inline uint32_t Hash(Handle<Object> key);
3762 static inline uint32_t HashForObject(Handle<Object> key, Object* object);
3763 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
Ben Murdoch592a9fc2012-03-05 11:04:45 +00003764 static const int kPrefixSize = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003765 static const int kEntrySize = 2;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003766};
3767
3768
3769// ObjectHashTable maps keys that are arbitrary objects to object values by
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003770// using the identity hash of the key for hashing purposes.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003771class ObjectHashTable: public HashTable<ObjectHashTable,
3772 ObjectHashTableShape,
3773 Handle<Object> > {
3774 typedef HashTable<
3775 ObjectHashTable, ObjectHashTableShape, Handle<Object> > DerivedHashTable;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003776 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003777 DECLARE_CAST(ObjectHashTable)
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003778
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003779 // Attempt to shrink hash table after removal of key.
3780 MUST_USE_RESULT static inline Handle<ObjectHashTable> Shrink(
3781 Handle<ObjectHashTable> table,
3782 Handle<Object> key);
3783
3784 // Looks up the value associated with the given key. The hole value is
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003785 // returned in case the key is not present.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003786 Object* Lookup(Handle<Object> key);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003787 Object* Lookup(Handle<Object> key, int32_t hash);
3788 Object* Lookup(Isolate* isolate, Handle<Object> key, int32_t hash);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003789
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003790 // Adds (or overwrites) the value associated with the given key.
3791 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table,
3792 Handle<Object> key,
3793 Handle<Object> value);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003794 static Handle<ObjectHashTable> Put(Handle<ObjectHashTable> table,
3795 Handle<Object> key, Handle<Object> value,
3796 int32_t hash);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003797
3798 // Returns an ObjectHashTable (possibly |table|) where |key| has been removed.
3799 static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table,
3800 Handle<Object> key,
3801 bool* was_present);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003802 static Handle<ObjectHashTable> Remove(Handle<ObjectHashTable> table,
3803 Handle<Object> key, bool* was_present,
3804 int32_t hash);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003805
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003806 protected:
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003807 friend class MarkCompactCollector;
3808
Ben Murdoch3ef787d2012-04-12 10:51:47 +01003809 void AddEntry(int entry, Object* key, Object* value);
3810 void RemoveEntry(int entry);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00003811
3812 // Returns the index to the value of an entry.
3813 static inline int EntryToValueIndex(int entry) {
3814 return EntryToIndex(entry) + 1;
3815 }
3816};
3817
3818
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003819// OrderedHashTable is a HashTable with Object keys that preserves
3820// insertion order. There are Map and Set interfaces (OrderedHashMap
3821// and OrderedHashTable, below). It is meant to be used by JSMap/JSSet.
3822//
3823// Only Object* keys are supported, with Object::SameValueZero() used as the
3824// equality operator and Object::GetHash() for the hash function.
3825//
3826// Based on the "Deterministic Hash Table" as described by Jason Orendorff at
3827// https://wiki.mozilla.org/User:Jorend/Deterministic_hash_tables
3828// Originally attributed to Tyler Close.
3829//
3830// Memory layout:
3831// [0]: bucket count
3832// [1]: element count
3833// [2]: deleted element count
3834// [3..(3 + NumberOfBuckets() - 1)]: "hash table", where each item is an
3835// offset into the data table (see below) where the
3836// first item in this bucket is stored.
3837// [3 + NumberOfBuckets()..length]: "data table", an array of length
3838// Capacity() * kEntrySize, where the first entrysize
3839// items are handled by the derived class and the
3840// item at kChainOffset is another entry into the
3841// data table indicating the next entry in this hash
3842// bucket.
3843//
3844// When we transition the table to a new version we obsolete it and reuse parts
3845// of the memory to store information how to transition an iterator to the new
3846// table:
3847//
3848// Memory layout for obsolete table:
3849// [0]: bucket count
3850// [1]: Next newer table
3851// [2]: Number of removed holes or -1 when the table was cleared.
3852// [3..(3 + NumberOfRemovedHoles() - 1)]: The indexes of the removed holes.
3853// [3 + NumberOfRemovedHoles()..length]: Not used
3854//
3855template<class Derived, class Iterator, int entrysize>
3856class OrderedHashTable: public FixedArray {
3857 public:
3858 // Returns an OrderedHashTable with a capacity of at least |capacity|.
3859 static Handle<Derived> Allocate(
3860 Isolate* isolate, int capacity, PretenureFlag pretenure = NOT_TENURED);
3861
3862 // Returns an OrderedHashTable (possibly |table|) with enough space
3863 // to add at least one new element.
3864 static Handle<Derived> EnsureGrowable(Handle<Derived> table);
3865
3866 // Returns an OrderedHashTable (possibly |table|) that's shrunken
3867 // if possible.
3868 static Handle<Derived> Shrink(Handle<Derived> table);
3869
3870 // Returns a new empty OrderedHashTable and records the clearing so that
3871 // exisiting iterators can be updated.
3872 static Handle<Derived> Clear(Handle<Derived> table);
3873
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003874 // Returns a true if the OrderedHashTable contains the key
3875 static bool HasKey(Handle<Derived> table, Handle<Object> key);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003876
3877 int NumberOfElements() {
3878 return Smi::cast(get(kNumberOfElementsIndex))->value();
3879 }
3880
3881 int NumberOfDeletedElements() {
3882 return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
3883 }
3884
3885 int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); }
3886
3887 int NumberOfBuckets() {
3888 return Smi::cast(get(kNumberOfBucketsIndex))->value();
3889 }
3890
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003891 // Returns an index into |this| for the given entry.
3892 int EntryToIndex(int entry) {
3893 return kHashTableStartIndex + NumberOfBuckets() + (entry * kEntrySize);
3894 }
3895
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003896 int HashToBucket(int hash) { return hash & (NumberOfBuckets() - 1); }
3897
3898 int HashToEntry(int hash) {
3899 int bucket = HashToBucket(hash);
3900 Object* entry = this->get(kHashTableStartIndex + bucket);
3901 return Smi::cast(entry)->value();
3902 }
3903
3904 int KeyToFirstEntry(Object* key) {
3905 Object* hash = key->GetHash();
3906 // If the object does not have an identity hash, it was never used as a key
3907 if (hash->IsUndefined()) return kNotFound;
3908 return HashToEntry(Smi::cast(hash)->value());
3909 }
3910
3911 int NextChainEntry(int entry) {
3912 Object* next_entry = get(EntryToIndex(entry) + kChainOffset);
3913 return Smi::cast(next_entry)->value();
3914 }
3915
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003916 Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
3917
3918 bool IsObsolete() {
3919 return !get(kNextTableIndex)->IsSmi();
3920 }
3921
3922 // The next newer table. This is only valid if the table is obsolete.
3923 Derived* NextTable() {
3924 return Derived::cast(get(kNextTableIndex));
3925 }
3926
3927 // When the table is obsolete we store the indexes of the removed holes.
3928 int RemovedIndexAt(int index) {
3929 return Smi::cast(get(kRemovedHolesIndex + index))->value();
3930 }
3931
3932 static const int kNotFound = -1;
3933 static const int kMinCapacity = 4;
3934
Emily Bernierd0a1eb72015-03-24 16:35:39 -04003935 static const int kNumberOfBucketsIndex = 0;
3936 static const int kNumberOfElementsIndex = kNumberOfBucketsIndex + 1;
3937 static const int kNumberOfDeletedElementsIndex = kNumberOfElementsIndex + 1;
3938 static const int kHashTableStartIndex = kNumberOfDeletedElementsIndex + 1;
3939 static const int kNextTableIndex = kNumberOfElementsIndex;
3940
3941 static const int kNumberOfBucketsOffset =
3942 kHeaderSize + kNumberOfBucketsIndex * kPointerSize;
3943 static const int kNumberOfElementsOffset =
3944 kHeaderSize + kNumberOfElementsIndex * kPointerSize;
3945 static const int kNumberOfDeletedElementsOffset =
3946 kHeaderSize + kNumberOfDeletedElementsIndex * kPointerSize;
3947 static const int kHashTableStartOffset =
3948 kHeaderSize + kHashTableStartIndex * kPointerSize;
3949 static const int kNextTableOffset =
3950 kHeaderSize + kNextTableIndex * kPointerSize;
3951
3952 static const int kEntrySize = entrysize + 1;
3953 static const int kChainOffset = entrysize;
3954
3955 static const int kLoadFactor = 2;
3956
3957 // NumberOfDeletedElements is set to kClearedTableSentinel when
3958 // the table is cleared, which allows iterator transitions to
3959 // optimize that case.
3960 static const int kClearedTableSentinel = -1;
3961
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00003962 protected:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003963 static Handle<Derived> Rehash(Handle<Derived> table, int new_capacity);
3964
3965 void SetNumberOfBuckets(int num) {
3966 set(kNumberOfBucketsIndex, Smi::FromInt(num));
3967 }
3968
3969 void SetNumberOfElements(int num) {
3970 set(kNumberOfElementsIndex, Smi::FromInt(num));
3971 }
3972
3973 void SetNumberOfDeletedElements(int num) {
3974 set(kNumberOfDeletedElementsIndex, Smi::FromInt(num));
3975 }
3976
3977 int Capacity() {
3978 return NumberOfBuckets() * kLoadFactor;
3979 }
3980
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003981 void SetNextTable(Derived* next_table) {
3982 set(kNextTableIndex, next_table);
3983 }
3984
3985 void SetRemovedIndexAt(int index, int removed_index) {
3986 return set(kRemovedHolesIndex + index, Smi::FromInt(removed_index));
3987 }
3988
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003989 static const int kRemovedHolesIndex = kHashTableStartIndex;
3990
Ben Murdochb8a8cc12014-11-26 15:28:44 +00003991 static const int kMaxCapacity =
3992 (FixedArray::kMaxLength - kHashTableStartIndex)
3993 / (1 + (kEntrySize * kLoadFactor));
3994};
3995
3996
3997class JSSetIterator;
3998
3999
4000class OrderedHashSet: public OrderedHashTable<
4001 OrderedHashSet, JSSetIterator, 1> {
4002 public:
4003 DECLARE_CAST(OrderedHashSet)
4004
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004005 static Handle<OrderedHashSet> Add(Handle<OrderedHashSet> table,
4006 Handle<Object> value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004007};
4008
4009
4010class JSMapIterator;
4011
4012
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004013class OrderedHashMap
4014 : public OrderedHashTable<OrderedHashMap, JSMapIterator, 2> {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004015 public:
4016 DECLARE_CAST(OrderedHashMap)
4017
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004018 inline Object* ValueAt(int entry);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004019
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004020 static const int kValueOffset = 1;
4021};
4022
4023
4024template <int entrysize>
4025class WeakHashTableShape : public BaseShape<Handle<Object> > {
4026 public:
4027 static inline bool IsMatch(Handle<Object> key, Object* other);
4028 static inline uint32_t Hash(Handle<Object> key);
4029 static inline uint32_t HashForObject(Handle<Object> key, Object* object);
4030 static inline Handle<Object> AsHandle(Isolate* isolate, Handle<Object> key);
4031 static const int kPrefixSize = 0;
4032 static const int kEntrySize = entrysize;
4033};
4034
4035
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004036// WeakHashTable maps keys that are arbitrary heap objects to heap object
4037// values. The table wraps the keys in weak cells and store values directly.
4038// Thus it references keys weakly and values strongly.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004039class WeakHashTable: public HashTable<WeakHashTable,
4040 WeakHashTableShape<2>,
4041 Handle<Object> > {
4042 typedef HashTable<
4043 WeakHashTable, WeakHashTableShape<2>, Handle<Object> > DerivedHashTable;
4044 public:
4045 DECLARE_CAST(WeakHashTable)
4046
4047 // Looks up the value associated with the given key. The hole value is
4048 // returned in case the key is not present.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004049 Object* Lookup(Handle<HeapObject> key);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004050
4051 // Adds (or overwrites) the value associated with the given key. Mapping a
4052 // key to the hole value causes removal of the whole entry.
4053 MUST_USE_RESULT static Handle<WeakHashTable> Put(Handle<WeakHashTable> table,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004054 Handle<HeapObject> key,
4055 Handle<HeapObject> value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004056
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004057 static Handle<FixedArray> GetValues(Handle<WeakHashTable> table);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004058
4059 private:
4060 friend class MarkCompactCollector;
4061
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004062 void AddEntry(int entry, Handle<WeakCell> key, Handle<HeapObject> value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004063
4064 // Returns the index to the value of an entry.
4065 static inline int EntryToValueIndex(int entry) {
4066 return EntryToIndex(entry) + 1;
4067 }
4068};
4069
4070
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004071// ScopeInfo represents information about different scopes of a source
4072// program and the allocation of the scope's variables. Scope information
4073// is stored in a compressed form in ScopeInfo objects and is used
4074// at runtime (stack dumps, deoptimization, etc.).
4075
4076// This object provides quick access to scope info details for runtime
4077// routines.
4078class ScopeInfo : public FixedArray {
4079 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004080 DECLARE_CAST(ScopeInfo)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004081
4082 // Return the type of this scope.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004083 ScopeType scope_type();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004084
4085 // Does this scope call eval?
4086 bool CallsEval();
4087
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004088 // Return the language mode of this scope.
4089 LanguageMode language_mode();
4090
4091 // True if this scope is a (var) declaration scope.
4092 bool is_declaration_scope();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004093
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004094 // Does this scope make a sloppy eval call?
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004095 bool CallsSloppyEval() { return CallsEval() && is_sloppy(language_mode()); }
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004096
4097 // Return the total number of locals allocated on the stack and in the
4098 // context. This includes the parameters that are allocated in the context.
4099 int LocalCount();
4100
4101 // Return the number of stack slots for code. This number consists of two
4102 // parts:
4103 // 1. One stack slot per stack allocated local.
4104 // 2. One stack slot for the function name if it is stack allocated.
4105 int StackSlotCount();
4106
4107 // Return the number of context slots for code if a context is allocated. This
4108 // number consists of three parts:
4109 // 1. Size of fixed header for every context: Context::MIN_CONTEXT_SLOTS
4110 // 2. One context slot per context allocated local.
4111 // 3. One context slot for the function name if it is context allocated.
4112 // Parameters allocated in the context count as context allocated locals. If
4113 // no contexts are allocated for this scope ContextLength returns 0.
4114 int ContextLength();
4115
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004116 // Does this scope declare a "this" binding?
4117 bool HasReceiver();
4118
4119 // Does this scope declare a "this" binding, and the "this" binding is stack-
4120 // or context-allocated?
4121 bool HasAllocatedReceiver();
4122
4123 // Does this scope declare a "new.target" binding?
4124 bool HasNewTarget();
4125
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004126 // Is this scope the scope of a named function expression?
4127 bool HasFunctionName();
4128
4129 // Return if this has context allocated locals.
4130 bool HasHeapAllocatedLocals();
4131
4132 // Return if contexts are allocated for this scope.
4133 bool HasContext();
4134
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004135 // Return if this is a function scope with "use asm".
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004136 inline bool IsAsmModule();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004137
4138 // Return if this is a nested function within an asm module scope.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004139 inline bool IsAsmFunction();
4140
4141 inline bool HasSimpleParameters();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004142
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004143 // Return the function_name if present.
4144 String* FunctionName();
4145
4146 // Return the name of the given parameter.
4147 String* ParameterName(int var);
4148
4149 // Return the name of the given local.
4150 String* LocalName(int var);
4151
4152 // Return the name of the given stack local.
4153 String* StackLocalName(int var);
4154
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004155 // Return the name of the given stack local.
4156 int StackLocalIndex(int var);
4157
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004158 // Return the name of the given context local.
4159 String* ContextLocalName(int var);
4160
4161 // Return the mode of the given context local.
4162 VariableMode ContextLocalMode(int var);
4163
4164 // Return the initialization flag of the given context local.
4165 InitializationFlag ContextLocalInitFlag(int var);
4166
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004167 // Return the initialization flag of the given context local.
4168 MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var);
4169
4170 // Return true if this local was introduced by the compiler, and should not be
4171 // exposed to the user in a debugger.
4172 bool LocalIsSynthetic(int var);
4173
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004174 // Lookup support for serialized scope info. Returns the
4175 // the stack slot index for a given slot name if the slot is
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004176 // present; otherwise returns a value < 0. The name must be an internalized
4177 // string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004178 int StackSlotIndex(String* name);
4179
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004180 // Lookup support for serialized scope info. Returns the local context slot
4181 // index for a given slot name if the slot is present; otherwise
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004182 // returns a value < 0. The name must be an internalized string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004183 // If the slot is present and mode != NULL, sets *mode to the corresponding
4184 // mode for that variable.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004185 static int ContextSlotIndex(Handle<ScopeInfo> scope_info, Handle<String> name,
4186 VariableMode* mode, InitializationFlag* init_flag,
4187 MaybeAssignedFlag* maybe_assigned_flag);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004188
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004189 // Similar to ContextSlotIndex() but this method searches only among
4190 // global slots of the serialized scope info. Returns the context slot index
4191 // for a given slot name if the slot is present; otherwise returns a
4192 // value < 0. The name must be an internalized string. If the slot is present
4193 // and mode != NULL, sets *mode to the corresponding mode for that variable.
4194 static int ContextGlobalSlotIndex(Handle<ScopeInfo> scope_info,
4195 Handle<String> name, VariableMode* mode,
4196 InitializationFlag* init_flag,
4197 MaybeAssignedFlag* maybe_assigned_flag);
4198
4199 // Lookup the name of a certain context slot by its index.
4200 String* ContextSlotName(int slot_index);
4201
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004202 // Lookup support for serialized scope info. Returns the
4203 // parameter index for a given parameter name if the parameter is present;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004204 // otherwise returns a value < 0. The name must be an internalized string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004205 int ParameterIndex(String* name);
4206
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004207 // Lookup support for serialized scope info. Returns the function context
4208 // slot index if the function name is present and context-allocated (named
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004209 // function expressions, only), otherwise returns a value < 0. The name
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004210 // must be an internalized string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004211 int FunctionContextSlotIndex(String* name, VariableMode* mode);
4212
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004213 // Lookup support for serialized scope info. Returns the receiver context
4214 // slot index if scope has a "this" binding, and the binding is
4215 // context-allocated. Otherwise returns a value < 0.
4216 int ReceiverContextSlotIndex();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004217
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004218 FunctionKind function_kind();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004219
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004220 static Handle<ScopeInfo> Create(Isolate* isolate, Zone* zone, Scope* scope);
4221 static Handle<ScopeInfo> CreateGlobalThisBinding(Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004222
4223 // Serializes empty scope info.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004224 static ScopeInfo* Empty(Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004225
4226#ifdef DEBUG
4227 void Print();
4228#endif
4229
4230 // The layout of the static part of a ScopeInfo is as follows. Each entry is
4231 // numeric and occupies one array slot.
4232 // 1. A set of properties of the scope
4233 // 2. The number of parameters. This only applies to function scopes. For
4234 // non-function scopes this is 0.
4235 // 3. The number of non-parameter variables allocated on the stack.
4236 // 4. The number of non-parameter and parameter variables allocated in the
4237 // context.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004238#define FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(V) \
4239 V(Flags) \
4240 V(ParameterCount) \
4241 V(StackLocalCount) \
4242 V(ContextLocalCount) \
Ben Murdoch097c5b22016-05-18 11:27:45 +01004243 V(ContextGlobalCount)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004244
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004245#define FIELD_ACCESSORS(name) \
4246 inline void Set##name(int value); \
4247 inline int name();
4248 FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(FIELD_ACCESSORS)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004249#undef FIELD_ACCESSORS
4250
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004251 enum {
4252#define DECL_INDEX(name) k##name,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004253 FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(DECL_INDEX)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004254#undef DECL_INDEX
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004255 kVariablePartIndex
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004256 };
4257
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004258 private:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004259 // The layout of the variable part of a ScopeInfo is as follows:
4260 // 1. ParameterEntries:
4261 // This part stores the names of the parameters for function scopes. One
4262 // slot is used per parameter, so in total this part occupies
4263 // ParameterCount() slots in the array. For other scopes than function
4264 // scopes ParameterCount() is 0.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004265 // 2. StackLocalFirstSlot:
4266 // Index of a first stack slot for stack local. Stack locals belonging to
4267 // this scope are located on a stack at slots starting from this index.
4268 // 3. StackLocalEntries:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004269 // Contains the names of local variables that are allocated on the stack,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004270 // in increasing order of the stack slot index. First local variable has
4271 // a stack slot index defined in StackLocalFirstSlot (point 2 above).
4272 // One slot is used per stack local, so in total this part occupies
4273 // StackLocalCount() slots in the array.
4274 // 4. ContextLocalNameEntries:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004275 // Contains the names of local variables and parameters that are allocated
4276 // in the context. They are stored in increasing order of the context slot
4277 // index starting with Context::MIN_CONTEXT_SLOTS. One slot is used per
4278 // context local, so in total this part occupies ContextLocalCount() slots
4279 // in the array.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004280 // 5. ContextLocalInfoEntries:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004281 // Contains the variable modes and initialization flags corresponding to
4282 // the context locals in ContextLocalNameEntries. One slot is used per
4283 // context local, so in total this part occupies ContextLocalCount()
4284 // slots in the array.
Ben Murdoch097c5b22016-05-18 11:27:45 +01004285 // 6. RecieverEntryIndex:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004286 // If the scope binds a "this" value, one slot is reserved to hold the
4287 // context or stack slot index for the variable.
Ben Murdoch097c5b22016-05-18 11:27:45 +01004288 // 7. FunctionNameEntryIndex:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004289 // If the scope belongs to a named function expression this part contains
4290 // information about the function variable. It always occupies two array
4291 // slots: a. The name of the function variable.
4292 // b. The context or stack slot index for the variable.
4293 int ParameterEntriesIndex();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004294 int StackLocalFirstSlotIndex();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004295 int StackLocalEntriesIndex();
4296 int ContextLocalNameEntriesIndex();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004297 int ContextGlobalNameEntriesIndex();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004298 int ContextLocalInfoEntriesIndex();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004299 int ContextGlobalInfoEntriesIndex();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004300 int ReceiverEntryIndex();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004301 int FunctionNameEntryIndex();
4302
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004303 int Lookup(Handle<String> name, int start, int end, VariableMode* mode,
4304 VariableLocation* location, InitializationFlag* init_flag,
4305 MaybeAssignedFlag* maybe_assigned_flag);
4306
4307 // Used for the function name variable for named function expressions, and for
4308 // the receiver.
4309 enum VariableAllocationInfo { NONE, STACK, CONTEXT, UNUSED };
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004310
4311 // Properties of scopes.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004312 class ScopeTypeField : public BitField<ScopeType, 0, 4> {};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004313 class CallsEvalField : public BitField<bool, ScopeTypeField::kNext, 1> {};
4314 STATIC_ASSERT(LANGUAGE_END == 3);
4315 class LanguageModeField
4316 : public BitField<LanguageMode, CallsEvalField::kNext, 2> {};
4317 class DeclarationScopeField
4318 : public BitField<bool, LanguageModeField::kNext, 1> {};
4319 class ReceiverVariableField
4320 : public BitField<VariableAllocationInfo, DeclarationScopeField::kNext,
4321 2> {};
4322 class HasNewTargetField
4323 : public BitField<bool, ReceiverVariableField::kNext, 1> {};
4324 class FunctionVariableField
4325 : public BitField<VariableAllocationInfo, HasNewTargetField::kNext, 2> {};
4326 class FunctionVariableMode
4327 : public BitField<VariableMode, FunctionVariableField::kNext, 3> {};
4328 class AsmModuleField : public BitField<bool, FunctionVariableMode::kNext, 1> {
4329 };
4330 class AsmFunctionField : public BitField<bool, AsmModuleField::kNext, 1> {};
4331 class HasSimpleParametersField
4332 : public BitField<bool, AsmFunctionField::kNext, 1> {};
4333 class FunctionKindField
4334 : public BitField<FunctionKind, HasSimpleParametersField::kNext, 8> {};
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004335
4336 // BitFields representing the encoded information for context locals in the
4337 // ContextLocalInfoEntries part.
4338 class ContextLocalMode: public BitField<VariableMode, 0, 3> {};
4339 class ContextLocalInitFlag: public BitField<InitializationFlag, 3, 1> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004340 class ContextLocalMaybeAssignedFlag
4341 : public BitField<MaybeAssignedFlag, 4, 1> {};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004342
4343 friend class ScopeIterator;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004344};
4345
4346
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004347// The cache for maps used by normalized (dictionary mode) objects.
4348// Such maps do not have property descriptors, so a typical program
4349// needs very limited number of distinct normalized maps.
4350class NormalizedMapCache: public FixedArray {
4351 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004352 static Handle<NormalizedMapCache> New(Isolate* isolate);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004353
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004354 MUST_USE_RESULT MaybeHandle<Map> Get(Handle<Map> fast_map,
4355 PropertyNormalizationMode mode);
4356 void Set(Handle<Map> fast_map, Handle<Map> normalized_map);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004357
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004358 void Clear();
4359
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004360 DECLARE_CAST(NormalizedMapCache)
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004361
Ben Murdoch097c5b22016-05-18 11:27:45 +01004362 static inline bool IsNormalizedMapCache(const HeapObject* obj);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004363
4364 DECLARE_VERIFIER(NormalizedMapCache)
4365 private:
4366 static const int kEntries = 64;
4367
4368 static inline int GetIndex(Handle<Map> map);
4369
4370 // The following declarations hide base class methods.
4371 Object* get(int index);
4372 void set(int index, Object* value);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01004373};
4374
4375
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004376// ByteArray represents fixed sized byte arrays. Used for the relocation info
4377// that is attached to code objects.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00004378class ByteArray: public FixedArrayBase {
Steve Blocka7e24c12009-10-30 11:49:00 +00004379 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004380 inline int Size();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004381
Steve Blocka7e24c12009-10-30 11:49:00 +00004382 // Setter and getter.
4383 inline byte get(int index);
4384 inline void set(int index, byte value);
4385
4386 // Treat contents as an int array.
4387 inline int get_int(int index);
4388
4389 static int SizeFor(int length) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01004390 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
Steve Blocka7e24c12009-10-30 11:49:00 +00004391 }
4392 // We use byte arrays for free blocks in the heap. Given a desired size in
4393 // bytes that is a multiple of the word size and big enough to hold a byte
4394 // array, this function returns the number of elements a byte array should
4395 // have.
4396 static int LengthFor(int size_in_bytes) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004397 DCHECK(IsAligned(size_in_bytes, kPointerSize));
4398 DCHECK(size_in_bytes >= kHeaderSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00004399 return size_in_bytes - kHeaderSize;
4400 }
4401
4402 // Returns data start address.
4403 inline Address GetDataStartAddress();
4404
4405 // Returns a pointer to the ByteArray object for a given data start address.
4406 static inline ByteArray* FromDataStartAddress(Address address);
4407
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004408 DECLARE_CAST(ByteArray)
Steve Blocka7e24c12009-10-30 11:49:00 +00004409
4410 // Dispatched behavior.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004411 inline int ByteArraySize();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004412 DECLARE_PRINTER(ByteArray)
4413 DECLARE_VERIFIER(ByteArray)
Steve Blocka7e24c12009-10-30 11:49:00 +00004414
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01004415 // Layout description.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01004416 static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00004417
Leon Clarkee46be812010-01-19 14:06:41 +00004418 // Maximal memory consumption for a single ByteArray.
4419 static const int kMaxSize = 512 * MB;
4420 // Maximal length of a single ByteArray.
4421 static const int kMaxLength = kMaxSize - kHeaderSize;
4422
Steve Blocka7e24c12009-10-30 11:49:00 +00004423 private:
4424 DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray);
4425};
4426
4427
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004428// BytecodeArray represents a sequence of interpreter bytecodes.
4429class BytecodeArray : public FixedArrayBase {
4430 public:
4431 static int SizeFor(int length) {
4432 return OBJECT_POINTER_ALIGN(kHeaderSize + length);
4433 }
4434
4435 // Setter and getter
4436 inline byte get(int index);
4437 inline void set(int index, byte value);
4438
4439 // Returns data start address.
4440 inline Address GetFirstBytecodeAddress();
4441
4442 // Accessors for frame size.
4443 inline int frame_size() const;
4444 inline void set_frame_size(int frame_size);
4445
4446 // Accessor for register count (derived from frame_size).
4447 inline int register_count() const;
4448
4449 // Accessors for parameter count (including implicit 'this' receiver).
4450 inline int parameter_count() const;
4451 inline void set_parameter_count(int number_of_parameters);
4452
Ben Murdoch097c5b22016-05-18 11:27:45 +01004453 // Accessors for profiling count.
4454 inline int interrupt_budget() const;
4455 inline void set_interrupt_budget(int interrupt_budget);
4456
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004457 // Accessors for the constant pool.
4458 DECL_ACCESSORS(constant_pool, FixedArray)
4459
Ben Murdoch097c5b22016-05-18 11:27:45 +01004460 // Accessors for handler table containing offsets of exception handlers.
4461 DECL_ACCESSORS(handler_table, FixedArray)
4462
4463 // Accessors for source position table containing mappings between byte code
4464 // offset and source position.
4465 DECL_ACCESSORS(source_position_table, FixedArray)
4466
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004467 DECLARE_CAST(BytecodeArray)
4468
4469 // Dispatched behavior.
4470 inline int BytecodeArraySize();
4471
Ben Murdoch097c5b22016-05-18 11:27:45 +01004472 inline int instruction_size();
4473
4474 int SourcePosition(int offset);
4475 int SourceStatementPosition(int offset);
4476
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004477 DECLARE_PRINTER(BytecodeArray)
4478 DECLARE_VERIFIER(BytecodeArray)
4479
4480 void Disassemble(std::ostream& os);
4481
Ben Murdoch097c5b22016-05-18 11:27:45 +01004482 void CopyBytecodesTo(BytecodeArray* to);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004483
Ben Murdoch097c5b22016-05-18 11:27:45 +01004484 // Layout description.
4485 static const int kConstantPoolOffset = FixedArrayBase::kHeaderSize;
4486 static const int kHandlerTableOffset = kConstantPoolOffset + kPointerSize;
4487 static const int kSourcePositionTableOffset =
4488 kHandlerTableOffset + kPointerSize;
4489 static const int kFrameSizeOffset = kSourcePositionTableOffset + kPointerSize;
4490 static const int kParameterSizeOffset = kFrameSizeOffset + kIntSize;
4491 static const int kInterruptBudgetOffset = kParameterSizeOffset + kIntSize;
4492 static const int kHeaderSize = kInterruptBudgetOffset + kIntSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004493
4494 // Maximal memory consumption for a single BytecodeArray.
4495 static const int kMaxSize = 512 * MB;
4496 // Maximal length of a single BytecodeArray.
4497 static const int kMaxLength = kMaxSize - kHeaderSize;
4498
4499 class BodyDescriptor;
4500
4501 private:
4502 DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeArray);
4503};
4504
4505
4506// FreeSpace are fixed-size free memory blocks used by the heap and GC.
4507// They look like heap objects (are heap object tagged and have a map) so that
4508// the heap remains iterable. They have a size and a next pointer.
4509// The next pointer is the raw address of the next FreeSpace object (or NULL)
4510// in the free list.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004511class FreeSpace: public HeapObject {
4512 public:
4513 // [size]: size of the free space including the header.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004514 inline int size() const;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004515 inline void set_size(int value);
4516
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004517 inline int nobarrier_size() const;
4518 inline void nobarrier_set_size(int value);
4519
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004520 inline int Size();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004521
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004522 // Accessors for the next field.
4523 inline FreeSpace* next();
4524 inline void set_next(FreeSpace* next);
4525
4526 inline static FreeSpace* cast(HeapObject* obj);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004527
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004528 // Dispatched behavior.
4529 DECLARE_PRINTER(FreeSpace)
4530 DECLARE_VERIFIER(FreeSpace)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004531
4532 // Layout description.
4533 // Size is smi tagged when it is stored.
4534 static const int kSizeOffset = HeapObject::kHeaderSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004535 static const int kNextOffset = POINTER_SIZE_ALIGN(kSizeOffset + kPointerSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004536
4537 private:
4538 DISALLOW_IMPLICIT_CONSTRUCTORS(FreeSpace);
4539};
4540
4541
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004542// V has parameters (Type, type, TYPE, C type, element_size)
4543#define TYPED_ARRAYS(V) \
4544 V(Uint8, uint8, UINT8, uint8_t, 1) \
4545 V(Int8, int8, INT8, int8_t, 1) \
4546 V(Uint16, uint16, UINT16, uint16_t, 2) \
4547 V(Int16, int16, INT16, int16_t, 2) \
4548 V(Uint32, uint32, UINT32, uint32_t, 4) \
4549 V(Int32, int32, INT32, int32_t, 4) \
4550 V(Float32, float32, FLOAT32, float, 4) \
4551 V(Float64, float64, FLOAT64, double, 8) \
4552 V(Uint8Clamped, uint8_clamped, UINT8_CLAMPED, uint8_t, 1)
4553
4554
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004555class FixedTypedArrayBase: public FixedArrayBase {
4556 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004557 // [base_pointer]: Either points to the FixedTypedArrayBase itself or nullptr.
4558 DECL_ACCESSORS(base_pointer, Object)
4559
4560 // [external_pointer]: Contains the offset between base_pointer and the start
4561 // of the data. If the base_pointer is a nullptr, the external_pointer
4562 // therefore points to the actual backing store.
4563 DECL_ACCESSORS(external_pointer, void)
4564
4565 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004566 DECLARE_CAST(FixedTypedArrayBase)
4567
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004568 static const int kBasePointerOffset = FixedArrayBase::kHeaderSize;
4569 static const int kExternalPointerOffset = kBasePointerOffset + kPointerSize;
4570 static const int kHeaderSize =
4571 DOUBLE_POINTER_ALIGN(kExternalPointerOffset + kPointerSize);
4572
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004573 static const int kDataOffset = kHeaderSize;
4574
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004575 class BodyDescriptor;
4576
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004577 inline int size();
4578
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004579 static inline int TypedArraySize(InstanceType type, int length);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004580 inline int TypedArraySize(InstanceType type);
4581
4582 // Use with care: returns raw pointer into heap.
4583 inline void* DataPtr();
4584
4585 inline int DataSize();
4586
4587 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004588 static inline int ElementSize(InstanceType type);
4589
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004590 inline int DataSize(InstanceType type);
4591
4592 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArrayBase);
4593};
4594
4595
4596template <class Traits>
4597class FixedTypedArray: public FixedTypedArrayBase {
4598 public:
4599 typedef typename Traits::ElementType ElementType;
4600 static const InstanceType kInstanceType = Traits::kInstanceType;
4601
4602 DECLARE_CAST(FixedTypedArray<Traits>)
4603
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004604 inline ElementType get_scalar(int index);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004605 static inline Handle<Object> get(FixedTypedArray* array, int index);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004606 inline void set(int index, ElementType value);
4607
4608 static inline ElementType from_int(int value);
4609 static inline ElementType from_double(double value);
4610
4611 // This accessor applies the correct conversion from Smi, HeapNumber
4612 // and undefined.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004613 inline void SetValue(uint32_t index, Object* value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004614
4615 DECLARE_PRINTER(FixedTypedArray)
4616 DECLARE_VERIFIER(FixedTypedArray)
4617
4618 private:
4619 DISALLOW_IMPLICIT_CONSTRUCTORS(FixedTypedArray);
4620};
4621
4622#define FIXED_TYPED_ARRAY_TRAITS(Type, type, TYPE, elementType, size) \
4623 class Type##ArrayTraits { \
4624 public: /* NOLINT */ \
4625 typedef elementType ElementType; \
4626 static const InstanceType kInstanceType = FIXED_##TYPE##_ARRAY_TYPE; \
4627 static const char* Designator() { return #type " array"; } \
4628 static inline Handle<Object> ToHandle(Isolate* isolate, \
4629 elementType scalar); \
4630 static inline elementType defaultValue(); \
4631 }; \
4632 \
4633 typedef FixedTypedArray<Type##ArrayTraits> Fixed##Type##Array;
4634
4635TYPED_ARRAYS(FIXED_TYPED_ARRAY_TRAITS)
4636
4637#undef FIXED_TYPED_ARRAY_TRAITS
4638
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004639
Ben Murdochb0fe1622011-05-05 13:52:32 +01004640// DeoptimizationInputData is a fixed array used to hold the deoptimization
4641// data for code generated by the Hydrogen/Lithium compiler. It also
4642// contains information about functions that were inlined. If N different
4643// functions were inlined then first N elements of the literal array will
4644// contain these functions.
4645//
4646// It can be empty.
4647class DeoptimizationInputData: public FixedArray {
4648 public:
4649 // Layout description. Indices in the array.
4650 static const int kTranslationByteArrayIndex = 0;
4651 static const int kInlinedFunctionCountIndex = 1;
4652 static const int kLiteralArrayIndex = 2;
4653 static const int kOsrAstIdIndex = 3;
4654 static const int kOsrPcOffsetIndex = 4;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004655 static const int kOptimizationIdIndex = 5;
4656 static const int kSharedFunctionInfoIndex = 6;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004657 static const int kWeakCellCacheIndex = 7;
4658 static const int kFirstDeoptEntryIndex = 8;
Ben Murdochb0fe1622011-05-05 13:52:32 +01004659
4660 // Offsets of deopt entry elements relative to the start of the entry.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004661 static const int kAstIdRawOffset = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +01004662 static const int kTranslationIndexOffset = 1;
4663 static const int kArgumentsStackHeightOffset = 2;
Ben Murdoch2b4ba112012-01-20 14:57:15 +00004664 static const int kPcOffset = 3;
4665 static const int kDeoptEntrySize = 4;
Ben Murdochb0fe1622011-05-05 13:52:32 +01004666
4667 // Simple element accessors.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004668#define DECLARE_ELEMENT_ACCESSORS(name, type) \
4669 inline type* name(); \
4670 inline void Set##name(type* value);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004671
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004672 DECLARE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
4673 DECLARE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
4674 DECLARE_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
4675 DECLARE_ELEMENT_ACCESSORS(OsrAstId, Smi)
4676 DECLARE_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
4677 DECLARE_ELEMENT_ACCESSORS(OptimizationId, Smi)
4678 DECLARE_ELEMENT_ACCESSORS(SharedFunctionInfo, Object)
4679 DECLARE_ELEMENT_ACCESSORS(WeakCellCache, Object)
Ben Murdochb0fe1622011-05-05 13:52:32 +01004680
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004681#undef DECLARE_ELEMENT_ACCESSORS
Ben Murdochb0fe1622011-05-05 13:52:32 +01004682
4683 // Accessors for elements of the ith deoptimization entry.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004684#define DECLARE_ENTRY_ACCESSORS(name, type) \
4685 inline type* name(int i); \
4686 inline void Set##name(int i, type* value);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004687
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004688 DECLARE_ENTRY_ACCESSORS(AstIdRaw, Smi)
4689 DECLARE_ENTRY_ACCESSORS(TranslationIndex, Smi)
4690 DECLARE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi)
4691 DECLARE_ENTRY_ACCESSORS(Pc, Smi)
Ben Murdochb0fe1622011-05-05 13:52:32 +01004692
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004693#undef DECLARE_ENTRY_ACCESSORS
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004694
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004695 inline BailoutId AstId(int i);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004696
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004697 inline void SetAstId(int i, BailoutId value);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004698
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004699 inline int DeoptCount();
Ben Murdochb0fe1622011-05-05 13:52:32 +01004700
4701 // Allocates a DeoptimizationInputData.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004702 static Handle<DeoptimizationInputData> New(Isolate* isolate,
4703 int deopt_entry_count,
4704 PretenureFlag pretenure);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004705
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004706 DECLARE_CAST(DeoptimizationInputData)
Ben Murdochb0fe1622011-05-05 13:52:32 +01004707
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00004708#ifdef ENABLE_DISASSEMBLER
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004709 void DeoptimizationInputDataPrint(std::ostream& os); // NOLINT
Ben Murdochb0fe1622011-05-05 13:52:32 +01004710#endif
4711
4712 private:
4713 static int IndexForEntry(int i) {
4714 return kFirstDeoptEntryIndex + (i * kDeoptEntrySize);
4715 }
4716
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004717
4718 static int LengthFor(int entry_count) { return IndexForEntry(entry_count); }
Ben Murdochb0fe1622011-05-05 13:52:32 +01004719};
4720
4721
4722// DeoptimizationOutputData is a fixed array used to hold the deoptimization
4723// data for code generated by the full compiler.
4724// The format of the these objects is
4725// [i * 2]: Ast ID for ith deoptimization.
4726// [i * 2 + 1]: PC and state of ith deoptimization
4727class DeoptimizationOutputData: public FixedArray {
4728 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004729 inline int DeoptPoints();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004730
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004731 inline BailoutId AstId(int index);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004732
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004733 inline void SetAstId(int index, BailoutId id);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004734
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004735 inline Smi* PcAndState(int index);
4736 inline void SetPcAndState(int index, Smi* offset);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004737
4738 static int LengthOfFixedArray(int deopt_points) {
4739 return deopt_points * 2;
4740 }
4741
4742 // Allocates a DeoptimizationOutputData.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004743 static Handle<DeoptimizationOutputData> New(Isolate* isolate,
4744 int number_of_deopt_points,
4745 PretenureFlag pretenure);
Ben Murdochb0fe1622011-05-05 13:52:32 +01004746
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004747 DECLARE_CAST(DeoptimizationOutputData)
Ben Murdochb0fe1622011-05-05 13:52:32 +01004748
Ben Murdoch097c5b22016-05-18 11:27:45 +01004749#ifdef ENABLE_DISASSEMBLER
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004750 void DeoptimizationOutputDataPrint(std::ostream& os); // NOLINT
Ben Murdochb0fe1622011-05-05 13:52:32 +01004751#endif
4752};
4753
4754
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004755// A literals array contains the literals for a JSFunction. It also holds
4756// the type feedback vector.
4757class LiteralsArray : public FixedArray {
4758 public:
4759 static const int kVectorIndex = 0;
4760 static const int kFirstLiteralIndex = 1;
4761 static const int kOffsetToFirstLiteral =
4762 FixedArray::kHeaderSize + kPointerSize;
4763
4764 static int OffsetOfLiteralAt(int index) {
4765 return SizeFor(index + kFirstLiteralIndex);
4766 }
4767
4768 inline TypeFeedbackVector* feedback_vector() const;
4769 inline void set_feedback_vector(TypeFeedbackVector* vector);
4770 inline Object* literal(int literal_index) const;
4771 inline void set_literal(int literal_index, Object* literal);
4772 inline int literals_count() const;
4773
4774 static Handle<LiteralsArray> New(Isolate* isolate,
4775 Handle<TypeFeedbackVector> vector,
4776 int number_of_literals,
4777 PretenureFlag pretenure);
4778
4779 DECLARE_CAST(LiteralsArray)
4780
4781 private:
4782 inline Object* get(int index) const;
4783 inline void set(int index, Object* value);
4784 inline void set(int index, Smi* value);
4785 inline void set(int index, Object* value, WriteBarrierMode mode);
4786};
4787
4788
4789// HandlerTable is a fixed array containing entries for exception handlers in
4790// the code object it is associated with. The tables comes in two flavors:
4791// 1) Based on ranges: Used for unoptimized code. Contains one entry per
4792// exception handler and a range representing the try-block covered by that
4793// handler. Layout looks as follows:
Ben Murdoch097c5b22016-05-18 11:27:45 +01004794// [ range-start , range-end , handler-offset , handler-data ]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004795// 2) Based on return addresses: Used for turbofanned code. Contains one entry
4796// per call-site that could throw an exception. Layout looks as follows:
4797// [ return-address-offset , handler-offset ]
4798class HandlerTable : public FixedArray {
4799 public:
4800 // Conservative prediction whether a given handler will locally catch an
4801 // exception or cause a re-throw to outside the code boundary. Since this is
4802 // undecidable it is merely an approximation (e.g. useful for debugger).
4803 enum CatchPrediction { UNCAUGHT, CAUGHT };
4804
Ben Murdoch097c5b22016-05-18 11:27:45 +01004805 // Getters for handler table based on ranges.
4806 inline int GetRangeStart(int index) const;
4807 inline int GetRangeEnd(int index) const;
4808 inline int GetRangeHandler(int index) const;
4809 inline int GetRangeData(int index) const;
4810
4811 // Setters for handler table based on ranges.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004812 inline void SetRangeStart(int index, int value);
4813 inline void SetRangeEnd(int index, int value);
4814 inline void SetRangeHandler(int index, int offset, CatchPrediction pred);
Ben Murdoch097c5b22016-05-18 11:27:45 +01004815 inline void SetRangeData(int index, int value);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004816
Ben Murdoch097c5b22016-05-18 11:27:45 +01004817 // Setters for handler table based on return addresses.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004818 inline void SetReturnOffset(int index, int value);
4819 inline void SetReturnHandler(int index, int offset, CatchPrediction pred);
4820
4821 // Lookup handler in a table based on ranges.
Ben Murdoch097c5b22016-05-18 11:27:45 +01004822 int LookupRange(int pc_offset, int* data, CatchPrediction* prediction);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004823
4824 // Lookup handler in a table based on return addresses.
4825 int LookupReturn(int pc_offset, CatchPrediction* prediction);
4826
Ben Murdoch097c5b22016-05-18 11:27:45 +01004827 // Returns the conservative catch predication.
4828 inline CatchPrediction GetRangePrediction(int index) const;
4829
4830 // Returns the number of entries in the table.
4831 inline int NumberOfRangeEntries() const;
4832
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004833 // Returns the required length of the underlying fixed array.
4834 static int LengthForRange(int entries) { return entries * kRangeEntrySize; }
4835 static int LengthForReturn(int entries) { return entries * kReturnEntrySize; }
4836
4837 DECLARE_CAST(HandlerTable)
4838
Ben Murdoch097c5b22016-05-18 11:27:45 +01004839#ifdef ENABLE_DISASSEMBLER
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004840 void HandlerTableRangePrint(std::ostream& os); // NOLINT
4841 void HandlerTableReturnPrint(std::ostream& os); // NOLINT
4842#endif
4843
4844 private:
4845 // Layout description for handler table based on ranges.
4846 static const int kRangeStartIndex = 0;
4847 static const int kRangeEndIndex = 1;
4848 static const int kRangeHandlerIndex = 2;
Ben Murdoch097c5b22016-05-18 11:27:45 +01004849 static const int kRangeDataIndex = 3;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004850 static const int kRangeEntrySize = 4;
4851
4852 // Layout description for handler table based on return addresses.
4853 static const int kReturnOffsetIndex = 0;
4854 static const int kReturnHandlerIndex = 1;
4855 static const int kReturnEntrySize = 2;
4856
4857 // Encoding of the {handler} field.
4858 class HandlerPredictionField : public BitField<CatchPrediction, 0, 1> {};
4859 class HandlerOffsetField : public BitField<int, 1, 30> {};
4860};
4861
Ben Murdochb8e0da22011-05-16 14:20:40 +01004862
Steve Blocka7e24c12009-10-30 11:49:00 +00004863// Code describes objects with on-the-fly generated machine code.
4864class Code: public HeapObject {
4865 public:
4866 // Opaque data type for encapsulating code flags like kind, inline
4867 // cache state, and arguments count.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004868 typedef uint32_t Flags;
4869
4870#define NON_IC_KIND_LIST(V) \
4871 V(FUNCTION) \
4872 V(OPTIMIZED_FUNCTION) \
4873 V(STUB) \
4874 V(HANDLER) \
4875 V(BUILTIN) \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004876 V(REGEXP) \
4877 V(WASM_FUNCTION)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004878
4879#define IC_KIND_LIST(V) \
4880 V(LOAD_IC) \
4881 V(KEYED_LOAD_IC) \
4882 V(CALL_IC) \
4883 V(STORE_IC) \
4884 V(KEYED_STORE_IC) \
4885 V(BINARY_OP_IC) \
4886 V(COMPARE_IC) \
4887 V(COMPARE_NIL_IC) \
4888 V(TO_BOOLEAN_IC)
4889
4890#define CODE_KIND_LIST(V) \
4891 NON_IC_KIND_LIST(V) \
4892 IC_KIND_LIST(V)
Steve Blocka7e24c12009-10-30 11:49:00 +00004893
4894 enum Kind {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004895#define DEFINE_CODE_KIND_ENUM(name) name,
4896 CODE_KIND_LIST(DEFINE_CODE_KIND_ENUM)
4897#undef DEFINE_CODE_KIND_ENUM
4898 NUMBER_OF_KINDS
Steve Blocka7e24c12009-10-30 11:49:00 +00004899 };
4900
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004901 // No more than 32 kinds. The value is currently encoded in five bits in
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004902 // Flags.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004903 STATIC_ASSERT(NUMBER_OF_KINDS <= 32);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004904
4905 static const char* Kind2String(Kind kind);
4906
4907 // Types of stubs.
4908 enum StubType {
4909 NORMAL,
4910 FAST
Steve Blocka7e24c12009-10-30 11:49:00 +00004911 };
4912
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004913 static const int kPrologueOffsetNotSet = -1;
Ben Murdochb8e0da22011-05-16 14:20:40 +01004914
Steve Blocka7e24c12009-10-30 11:49:00 +00004915#ifdef ENABLE_DISASSEMBLER
4916 // Printing
Steve Blocka7e24c12009-10-30 11:49:00 +00004917 static const char* ICState2String(InlineCacheState state);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004918 static const char* StubType2String(StubType type);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004919 static void PrintExtraICState(std::ostream& os, // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004920 Kind kind, ExtraICState extra);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04004921 void Disassemble(const char* name, std::ostream& os); // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +00004922#endif // ENABLE_DISASSEMBLER
4923
4924 // [instruction_size]: Size of the native instructions
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004925 inline int instruction_size() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00004926 inline void set_instruction_size(int value);
4927
Leon Clarkeac952652010-07-15 11:15:24 +01004928 // [relocation_info]: Code relocation information
4929 DECL_ACCESSORS(relocation_info, ByteArray)
Ben Murdochb0fe1622011-05-05 13:52:32 +01004930 void InvalidateRelocation();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004931 void InvalidateEmbeddedObjects();
Leon Clarkeac952652010-07-15 11:15:24 +01004932
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004933 // [handler_table]: Fixed array containing offsets of exception handlers.
4934 DECL_ACCESSORS(handler_table, FixedArray)
4935
Ben Murdochb0fe1622011-05-05 13:52:32 +01004936 // [deoptimization_data]: Array containing data for deopt.
4937 DECL_ACCESSORS(deoptimization_data, FixedArray)
4938
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004939 // [raw_type_feedback_info]: This field stores various things, depending on
4940 // the kind of the code object.
4941 // FUNCTION => type feedback information.
4942 // STUB and ICs => major/minor key as Smi.
4943 DECL_ACCESSORS(raw_type_feedback_info, Object)
4944 inline Object* type_feedback_info();
4945 inline void set_type_feedback_info(
4946 Object* value, WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
4947 inline uint32_t stub_key();
4948 inline void set_stub_key(uint32_t key);
4949
4950 // [next_code_link]: Link for lists of optimized or deoptimized code.
4951 // Note that storage for this field is overlapped with typefeedback_info.
4952 DECL_ACCESSORS(next_code_link, Object)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004953
4954 // [gc_metadata]: Field used to hold GC related metadata. The contents of this
Ben Murdoch257744e2011-11-30 15:57:28 +00004955 // field does not have to be traced during garbage collection since
4956 // it is only used by the garbage collector itself.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01004957 DECL_ACCESSORS(gc_metadata, Object)
4958
4959 // [ic_age]: Inline caching age: the value of the Heap::global_ic_age
4960 // at the moment when this object was created.
4961 inline void set_ic_age(int count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004962 inline int ic_age() const;
4963
4964 // [prologue_offset]: Offset of the function prologue, used for aging
4965 // FUNCTIONs and OPTIMIZED_FUNCTIONs.
4966 inline int prologue_offset() const;
4967 inline void set_prologue_offset(int offset);
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +01004968
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004969 // [constant_pool offset]: Offset of the constant pool.
4970 // Valid for FLAG_enable_embedded_constant_pool only
4971 inline int constant_pool_offset() const;
4972 inline void set_constant_pool_offset(int offset);
4973
Ben Murdochb0fe1622011-05-05 13:52:32 +01004974 // Unchecked accessors to be used during GC.
Leon Clarkeac952652010-07-15 11:15:24 +01004975 inline ByteArray* unchecked_relocation_info();
4976
Steve Blocka7e24c12009-10-30 11:49:00 +00004977 inline int relocation_size();
Steve Blocka7e24c12009-10-30 11:49:00 +00004978
Steve Blocka7e24c12009-10-30 11:49:00 +00004979 // [flags]: Various code flags.
4980 inline Flags flags();
4981 inline void set_flags(Flags flags);
4982
4983 // [flags]: Access to specific code flags.
4984 inline Kind kind();
4985 inline InlineCacheState ic_state(); // Only valid for IC stubs.
Ben Murdochb8e0da22011-05-16 14:20:40 +01004986 inline ExtraICState extra_ic_state(); // Only valid for IC stubs.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004987
4988 inline StubType type(); // Only valid for monomorphic IC stubs.
Steve Blocka7e24c12009-10-30 11:49:00 +00004989
4990 // Testers for IC stub kinds.
4991 inline bool is_inline_cache_stub();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00004992 inline bool is_debug_stub();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00004993 inline bool is_handler();
4994 inline bool is_load_stub();
4995 inline bool is_keyed_load_stub();
4996 inline bool is_store_stub();
4997 inline bool is_keyed_store_stub();
4998 inline bool is_call_stub();
4999 inline bool is_binary_op_stub();
5000 inline bool is_compare_ic_stub();
5001 inline bool is_compare_nil_ic_stub();
5002 inline bool is_to_boolean_ic_stub();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005003 inline bool is_keyed_stub();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005004 inline bool is_optimized_code();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005005 inline bool embeds_maps_weakly();
Ben Murdochb0fe1622011-05-05 13:52:32 +01005006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005007 inline bool IsCodeStubOrIC();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005008 inline bool IsJavaScriptCode();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005009
5010 inline void set_raw_kind_specific_flags1(int value);
5011 inline void set_raw_kind_specific_flags2(int value);
5012
Ben Murdoch097c5b22016-05-18 11:27:45 +01005013 // Testers for interpreter builtins.
5014 inline bool is_interpreter_entry_trampoline();
5015 inline bool is_interpreter_enter_bytecode_dispatch();
5016
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005017 // [is_crankshafted]: For kind STUB or ICs, tells whether or not a code
5018 // object was generated by either the hydrogen or the TurboFan optimizing
5019 // compiler (but it may not be an optimized function).
5020 inline bool is_crankshafted();
5021 inline bool is_hydrogen_stub(); // Crankshafted, but not a function.
5022 inline void set_is_crankshafted(bool value);
5023
5024 // [is_turbofanned]: For kind STUB or OPTIMIZED_FUNCTION, tells whether the
5025 // code object was generated by the TurboFan optimizing compiler.
5026 inline bool is_turbofanned();
5027 inline void set_is_turbofanned(bool value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005028
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005029 // [can_have_weak_objects]: For kind OPTIMIZED_FUNCTION, tells whether the
5030 // embedded objects in code should be treated weakly.
5031 inline bool can_have_weak_objects();
5032 inline void set_can_have_weak_objects(bool value);
Ben Murdochb0fe1622011-05-05 13:52:32 +01005033
5034 // [has_deoptimization_support]: For FUNCTION kind, tells if it has
5035 // deoptimization support.
5036 inline bool has_deoptimization_support();
5037 inline void set_has_deoptimization_support(bool value);
5038
Ben Murdoch589d6972011-11-30 16:04:58 +00005039 // [has_debug_break_slots]: For FUNCTION kind, tells if it has
5040 // been compiled with debug break slots.
5041 inline bool has_debug_break_slots();
5042 inline void set_has_debug_break_slots(bool value);
5043
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005044 // [has_reloc_info_for_serialization]: For FUNCTION kind, tells if its
5045 // reloc info includes runtime and external references to support
5046 // serialization/deserialization.
5047 inline bool has_reloc_info_for_serialization();
5048 inline void set_has_reloc_info_for_serialization(bool value);
5049
Ben Murdochb0fe1622011-05-05 13:52:32 +01005050 // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for
5051 // how long the function has been marked for OSR and therefore which
5052 // level of loop nesting we are willing to do on-stack replacement
5053 // for.
5054 inline void set_allow_osr_at_loop_nesting_level(int level);
5055 inline int allow_osr_at_loop_nesting_level();
5056
Ben Murdoch8f9999f2012-04-23 10:39:17 +01005057 // [profiler_ticks]: For FUNCTION kind, tells for how many profiler ticks
5058 // the code object was seen on the stack with no IC patching going on.
5059 inline int profiler_ticks();
5060 inline void set_profiler_ticks(int ticks);
5061
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005062 // [builtin_index]: For BUILTIN kind, tells which builtin index it has.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005063 // For builtins, tells which builtin index it has.
5064 // Note that builtins can have a code kind other than BUILTIN, which means
5065 // that for arbitrary code objects, this index value may be random garbage.
5066 // To verify in that case, compare the code object to the indexed builtin.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005067 inline int builtin_index();
5068 inline void set_builtin_index(int id);
5069
Ben Murdochb0fe1622011-05-05 13:52:32 +01005070 // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots
5071 // reserved in the code prologue.
5072 inline unsigned stack_slots();
5073 inline void set_stack_slots(unsigned slots);
5074
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005075 // [safepoint_table_start]: For kind OPTIMIZED_FUNCTION, the offset in
Ben Murdochb0fe1622011-05-05 13:52:32 +01005076 // the instruction stream where the safepoint table starts.
Steve Block1e0659c2011-05-24 12:43:12 +01005077 inline unsigned safepoint_table_offset();
5078 inline void set_safepoint_table_offset(unsigned offset);
Ben Murdochb0fe1622011-05-05 13:52:32 +01005079
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005080 // [back_edge_table_start]: For kind FUNCTION, the offset in the
5081 // instruction stream where the back edge table starts.
5082 inline unsigned back_edge_table_offset();
5083 inline void set_back_edge_table_offset(unsigned offset);
Ben Murdochb0fe1622011-05-05 13:52:32 +01005084
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005085 inline bool back_edges_patched_for_osr();
Ben Murdochb0fe1622011-05-05 13:52:32 +01005086
Ben Murdoch69a99ed2011-11-30 16:03:39 +00005087 // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005088 inline uint16_t to_boolean_state();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005089
5090 // [marked_for_deoptimization]: For kind OPTIMIZED_FUNCTION tells whether
5091 // the code is going to be deoptimized because of dead embedded maps.
5092 inline bool marked_for_deoptimization();
5093 inline void set_marked_for_deoptimization(bool flag);
5094
5095 // [constant_pool]: The constant pool for this function.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005096 inline Address constant_pool();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005097
Ben Murdochb8e0da22011-05-16 14:20:40 +01005098 // Get the safepoint entry for the given pc.
5099 SafepointEntry GetSafepointEntry(Address pc);
Ben Murdochb0fe1622011-05-05 13:52:32 +01005100
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005101 // Find an object in a stub with a specified map
5102 Object* FindNthObject(int n, Map* match_map);
5103
5104 // Find the first allocation site in an IC stub.
5105 AllocationSite* FindFirstAllocationSite();
Ben Murdochb0fe1622011-05-05 13:52:32 +01005106
5107 // Find the first map in an IC stub.
5108 Map* FindFirstMap();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005109 void FindAllMaps(MapHandleList* maps);
Steve Blocka7e24c12009-10-30 11:49:00 +00005110
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005111 // Find the first handler in an IC stub.
5112 Code* FindFirstHandler();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005113
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005114 // Find |length| handlers and put them into |code_list|. Returns false if not
5115 // enough handlers can be found.
5116 bool FindHandlers(CodeHandleList* code_list, int length = -1);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005117
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005118 // Find the handler for |map|.
5119 MaybeHandle<Code> FindHandlerForMap(Map* map);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005120
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005121 // Find the first name in an IC stub.
5122 Name* FindFirstName();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005123
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005124 class FindAndReplacePattern;
5125 // For each (map-to-find, object-to-replace) pair in the pattern, this
5126 // function replaces the corresponding placeholder in the code with the
5127 // object-to-replace. The function assumes that pairs in the pattern come in
5128 // the same order as the placeholders in the code.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005129 // If the placeholder is a weak cell, then the value of weak cell is matched
5130 // against the map-to-find.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005131 void FindAndReplace(const FindAndReplacePattern& pattern);
5132
5133 // The entire code object including its header is copied verbatim to the
5134 // snapshot so that it can be written in one, fast, memcpy during
5135 // deserialization. The deserializer will overwrite some pointers, rather
5136 // like a runtime linker, but the random allocation addresses used in the
5137 // mksnapshot process would still be present in the unlinked snapshot data,
5138 // which would make snapshot production non-reproducible. This method wipes
5139 // out the to-be-overwritten header data for reproducible snapshots.
5140 inline void WipeOutHeader();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005141
Steve Blocka7e24c12009-10-30 11:49:00 +00005142 // Flags operations.
Ben Murdochb8e0da22011-05-16 14:20:40 +01005143 static inline Flags ComputeFlags(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005144 Kind kind, InlineCacheState ic_state = UNINITIALIZED,
5145 ExtraICState extra_ic_state = kNoExtraICState, StubType type = NORMAL,
5146 CacheHolderFlag holder = kCacheOnReceiver);
Steve Blocka7e24c12009-10-30 11:49:00 +00005147
5148 static inline Flags ComputeMonomorphicFlags(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005149 Kind kind, ExtraICState extra_ic_state = kNoExtraICState,
5150 CacheHolderFlag holder = kCacheOnReceiver, StubType type = NORMAL);
5151
5152 static inline Flags ComputeHandlerFlags(
5153 Kind handler_kind, StubType type = NORMAL,
5154 CacheHolderFlag holder = kCacheOnReceiver);
Steve Blocka7e24c12009-10-30 11:49:00 +00005155
Steve Blocka7e24c12009-10-30 11:49:00 +00005156 static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005157 static inline StubType ExtractTypeFromFlags(Flags flags);
5158 static inline CacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
Ben Murdoch589d6972011-11-30 16:04:58 +00005159 static inline Kind ExtractKindFromFlags(Flags flags);
Ben Murdoch589d6972011-11-30 16:04:58 +00005160 static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags);
Ben Murdoch589d6972011-11-30 16:04:58 +00005161
Steve Blocka7e24c12009-10-30 11:49:00 +00005162 static inline Flags RemoveTypeFromFlags(Flags flags);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005163 static inline Flags RemoveTypeAndHolderFromFlags(Flags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +00005164
5165 // Convert a target address into a code object.
5166 static inline Code* GetCodeFromTargetAddress(Address address);
5167
Steve Block791712a2010-08-27 10:21:07 +01005168 // Convert an entry address into an object.
5169 static inline Object* GetObjectFromEntryAddress(Address location_of_address);
5170
Steve Blocka7e24c12009-10-30 11:49:00 +00005171 // Returns the address of the first instruction.
5172 inline byte* instruction_start();
5173
Leon Clarkeac952652010-07-15 11:15:24 +01005174 // Returns the address right after the last instruction.
5175 inline byte* instruction_end();
5176
Steve Blocka7e24c12009-10-30 11:49:00 +00005177 // Returns the size of the instructions, padding, and relocation information.
5178 inline int body_size();
5179
5180 // Returns the address of the first relocation info (read backwards!).
5181 inline byte* relocation_start();
5182
5183 // Code entry point.
5184 inline byte* entry();
5185
5186 // Returns true if pc is inside this object's instructions.
5187 inline bool contains(byte* pc);
5188
Steve Blocka7e24c12009-10-30 11:49:00 +00005189 // Relocate the code by delta bytes. Called to signal that this code
5190 // object has been moved by delta bytes.
Steve Blockd0582a62009-12-15 09:54:21 +00005191 void Relocate(intptr_t delta);
Steve Blocka7e24c12009-10-30 11:49:00 +00005192
5193 // Migrate code described by desc.
5194 void CopyFrom(const CodeDesc& desc);
5195
Ben Murdoch3bec4d22010-07-22 14:51:16 +01005196 // Returns the object size for a given body (used for allocation).
5197 static int SizeFor(int body_size) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005198 DCHECK_SIZE_TAG_ALIGNED(body_size);
Ben Murdoch3bec4d22010-07-22 14:51:16 +01005199 return RoundUp(kHeaderSize + body_size, kCodeAlignment);
Steve Blocka7e24c12009-10-30 11:49:00 +00005200 }
5201
5202 // Calculate the size of the code object to report for log events. This takes
5203 // the layout of the code object into account.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005204 inline int ExecutableSize();
Steve Blocka7e24c12009-10-30 11:49:00 +00005205
5206 // Locating source position.
Ben Murdoch097c5b22016-05-18 11:27:45 +01005207 int SourcePosition(int code_offset);
5208 int SourceStatementPosition(int code_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +00005209
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005210 DECLARE_CAST(Code)
Steve Blocka7e24c12009-10-30 11:49:00 +00005211
5212 // Dispatched behavior.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005213 inline int CodeSize();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005214
5215 DECLARE_PRINTER(Code)
5216 DECLARE_VERIFIER(Code)
5217
Ben Murdoch8f9999f2012-04-23 10:39:17 +01005218 void ClearInlineCaches();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005219 void ClearInlineCaches(Kind kind);
5220
5221 BailoutId TranslatePcOffsetToAstId(uint32_t pc_offset);
5222 uint32_t TranslateAstIdToPcOffset(BailoutId ast_id);
5223
5224#define DECLARE_CODE_AGE_ENUM(X) k##X##CodeAge,
5225 enum Age {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005226 kToBeExecutedOnceCodeAge = -3,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005227 kNotExecutedCodeAge = -2,
5228 kExecutedOnceCodeAge = -1,
5229 kNoAgeCodeAge = 0,
5230 CODE_AGE_LIST(DECLARE_CODE_AGE_ENUM)
5231 kAfterLastCodeAge,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005232 kFirstCodeAge = kToBeExecutedOnceCodeAge,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005233 kLastCodeAge = kAfterLastCodeAge - 1,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005234 kCodeAgeCount = kAfterLastCodeAge - kFirstCodeAge - 1,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005235 kIsOldCodeAge = kSexagenarianCodeAge,
5236 kPreAgedCodeAge = kIsOldCodeAge - 1
5237 };
5238#undef DECLARE_CODE_AGE_ENUM
5239
5240 // Code aging. Indicates how many full GCs this code has survived without
5241 // being entered through the prologue. Used to determine when it is
5242 // relatively safe to flush this code object and replace it with the lazy
5243 // compilation stub.
5244 static void MakeCodeAgeSequenceYoung(byte* sequence, Isolate* isolate);
5245 static void MarkCodeAsExecuted(byte* sequence, Isolate* isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005246 void MakeYoung(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005247 void MarkToBeExecutedOnce(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005248 void MakeOlder(MarkingParity);
5249 static bool IsYoungSequence(Isolate* isolate, byte* sequence);
5250 bool IsOld();
5251 Age GetAge();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005252 static inline Code* GetPreAgedCodeAgeStub(Isolate* isolate) {
5253 return GetCodeAgeStub(isolate, kNotExecutedCodeAge, NO_MARKING_PARITY);
5254 }
5255
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005256 void PrintDeoptLocation(FILE* out, Address pc);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005257 bool CanDeoptAt(Address pc);
5258
5259#ifdef VERIFY_HEAP
5260 void VerifyEmbeddedObjectsDependency();
5261#endif
5262
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005263#ifdef DEBUG
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005264 enum VerifyMode { kNoContextSpecificPointers, kNoContextRetainingPointers };
5265 void VerifyEmbeddedObjects(VerifyMode mode = kNoContextRetainingPointers);
5266 static void VerifyRecompiledCode(Code* old_code, Code* new_code);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005267#endif // DEBUG
5268
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005269 inline bool CanContainWeakObjects();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005270
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005271 inline bool IsWeakObject(Object* object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005272
5273 static inline bool IsWeakObjectInOptimizedCode(Object* object);
Ben Murdochb0fe1622011-05-05 13:52:32 +01005274
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005275 static Handle<WeakCell> WeakCellFor(Handle<Code> code);
5276 WeakCell* CachedWeakCell();
5277
Ben Murdochb0fe1622011-05-05 13:52:32 +01005278 // Max loop nesting marker used to postpose OSR. We don't take loop
5279 // nesting that is deeper than 5 levels into account.
5280 static const int kMaxLoopNestingMarker = 6;
5281
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005282 static const int kConstantPoolSize =
5283 FLAG_enable_embedded_constant_pool ? kIntSize : 0;
5284
Steve Blocka7e24c12009-10-30 11:49:00 +00005285 // Layout description.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005286 static const int kRelocationInfoOffset = HeapObject::kHeaderSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005287 static const int kHandlerTableOffset = kRelocationInfoOffset + kPointerSize;
Ben Murdochb0fe1622011-05-05 13:52:32 +01005288 static const int kDeoptimizationDataOffset =
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005289 kHandlerTableOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005290 // For FUNCTION kind, we store the type feedback info here.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005291 static const int kTypeFeedbackInfoOffset =
Ben Murdoch5d4cdbf2012-04-11 10:23:59 +01005292 kDeoptimizationDataOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005293 static const int kNextCodeLinkOffset = kTypeFeedbackInfoOffset + kPointerSize;
5294 static const int kGCMetadataOffset = kNextCodeLinkOffset + kPointerSize;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005295 static const int kInstructionSizeOffset = kGCMetadataOffset + kPointerSize;
5296 static const int kICAgeOffset = kInstructionSizeOffset + kIntSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005297 static const int kFlagsOffset = kICAgeOffset + kIntSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005298 static const int kKindSpecificFlags1Offset = kFlagsOffset + kIntSize;
5299 static const int kKindSpecificFlags2Offset =
5300 kKindSpecificFlags1Offset + kIntSize;
5301 // Note: We might be able to squeeze this into the flags above.
5302 static const int kPrologueOffset = kKindSpecificFlags2Offset + kIntSize;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005303 static const int kConstantPoolOffset = kPrologueOffset + kIntSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005304 static const int kHeaderPaddingStart =
5305 kConstantPoolOffset + kConstantPoolSize;
Ben Murdochb0fe1622011-05-05 13:52:32 +01005306
Steve Blocka7e24c12009-10-30 11:49:00 +00005307 // Add padding to align the instruction start following right after
5308 // the Code object header.
5309 static const int kHeaderSize =
Ben Murdochb0fe1622011-05-05 13:52:32 +01005310 (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005311
5312 class BodyDescriptor;
Steve Blocka7e24c12009-10-30 11:49:00 +00005313
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005314 // Byte offsets within kKindSpecificFlags1Offset.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005315 static const int kFullCodeFlags = kKindSpecificFlags1Offset;
Ben Murdoch589d6972011-11-30 16:04:58 +00005316 class FullCodeFlagsHasDeoptimizationSupportField:
5317 public BitField<bool, 0, 1> {}; // NOLINT
5318 class FullCodeFlagsHasDebugBreakSlotsField: public BitField<bool, 1, 1> {};
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005319 class FullCodeFlagsHasRelocInfoForSerialization
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005320 : public BitField<bool, 2, 1> {};
5321 // Bit 3 in this bitfield is unused.
5322 class ProfilerTicksField : public BitField<int, 4, 28> {};
Steve Blocka7e24c12009-10-30 11:49:00 +00005323
Ben Murdoch589d6972011-11-30 16:04:58 +00005324 // Flags layout. BitField<type, shift, size>.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005325 class ICStateField : public BitField<InlineCacheState, 0, 3> {};
5326 class TypeField : public BitField<StubType, 3, 1> {};
5327 class CacheHolderField : public BitField<CacheHolderFlag, 4, 2> {};
5328 class KindField : public BitField<Kind, 6, 5> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005329 class ExtraICStateField: public BitField<ExtraICState, 11,
5330 PlatformSmiTagging::kSmiValueSize - 11 + 1> {}; // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +00005331
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005332 // KindSpecificFlags1 layout (STUB and OPTIMIZED_FUNCTION)
5333 static const int kStackSlotsFirstBit = 0;
5334 static const int kStackSlotsBitCount = 24;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005335 static const int kMarkedForDeoptimizationBit =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005336 kStackSlotsFirstBit + kStackSlotsBitCount;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005337 static const int kIsTurbofannedBit = kMarkedForDeoptimizationBit + 1;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005338 static const int kCanHaveWeakObjects = kIsTurbofannedBit + 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005339
5340 STATIC_ASSERT(kStackSlotsFirstBit + kStackSlotsBitCount <= 32);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005341 STATIC_ASSERT(kCanHaveWeakObjects + 1 <= 32);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005342
5343 class StackSlotsField: public BitField<int,
5344 kStackSlotsFirstBit, kStackSlotsBitCount> {}; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005345 class MarkedForDeoptimizationField
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005346 : public BitField<bool, kMarkedForDeoptimizationBit, 1> {}; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005347 class IsTurbofannedField : public BitField<bool, kIsTurbofannedBit, 1> {
5348 }; // NOLINT
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005349 class CanHaveWeakObjectsField
5350 : public BitField<bool, kCanHaveWeakObjects, 1> {}; // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005351
5352 // KindSpecificFlags2 layout (ALL)
5353 static const int kIsCrankshaftedBit = 0;
5354 class IsCrankshaftedField: public BitField<bool,
5355 kIsCrankshaftedBit, 1> {}; // NOLINT
5356
5357 // KindSpecificFlags2 layout (STUB and OPTIMIZED_FUNCTION)
5358 static const int kSafepointTableOffsetFirstBit = kIsCrankshaftedBit + 1;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005359 static const int kSafepointTableOffsetBitCount = 30;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005360
5361 STATIC_ASSERT(kSafepointTableOffsetFirstBit +
5362 kSafepointTableOffsetBitCount <= 32);
5363 STATIC_ASSERT(1 + kSafepointTableOffsetBitCount <= 32);
5364
5365 class SafepointTableOffsetField: public BitField<int,
5366 kSafepointTableOffsetFirstBit,
5367 kSafepointTableOffsetBitCount> {}; // NOLINT
5368
5369 // KindSpecificFlags2 layout (FUNCTION)
5370 class BackEdgeTableOffsetField: public BitField<int,
5371 kIsCrankshaftedBit + 1, 27> {}; // NOLINT
5372 class AllowOSRAtLoopNestingLevelField: public BitField<int,
5373 kIsCrankshaftedBit + 1 + 27, 4> {}; // NOLINT
5374 STATIC_ASSERT(AllowOSRAtLoopNestingLevelField::kMax >= kMaxLoopNestingMarker);
5375
5376 static const int kArgumentsBits = 16;
5377 static const int kMaxArguments = (1 << kArgumentsBits) - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +00005378
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005379 // This constant should be encodable in an ARM instruction.
Steve Blocka7e24c12009-10-30 11:49:00 +00005380 static const int kFlagsNotUsedInLookup =
Ben Murdoch589d6972011-11-30 16:04:58 +00005381 TypeField::kMask | CacheHolderField::kMask;
Steve Blocka7e24c12009-10-30 11:49:00 +00005382
5383 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005384 friend class RelocIterator;
5385 friend class Deoptimizer; // For FindCodeAgeSequence.
5386
5387 void ClearInlineCaches(Kind* kind);
5388
5389 // Code aging
5390 byte* FindCodeAgeSequence();
5391 static void GetCodeAgeAndParity(Code* code, Age* age,
5392 MarkingParity* parity);
5393 static void GetCodeAgeAndParity(Isolate* isolate, byte* sequence, Age* age,
5394 MarkingParity* parity);
5395 static Code* GetCodeAgeStub(Isolate* isolate, Age age, MarkingParity parity);
5396
5397 // Code aging -- platform-specific
5398 static void PatchPlatformCodeAge(Isolate* isolate,
5399 byte* sequence, Age age,
5400 MarkingParity parity);
5401
Steve Blocka7e24c12009-10-30 11:49:00 +00005402 DISALLOW_IMPLICIT_CONSTRUCTORS(Code);
5403};
5404
Ben Murdoch097c5b22016-05-18 11:27:45 +01005405class AbstractCode : public HeapObject {
5406 public:
5407 int SourcePosition(int offset);
5408 int SourceStatementPosition(int offset);
5409
5410 DECLARE_CAST(AbstractCode)
5411 inline int Size();
5412 inline Code* GetCode();
5413 inline BytecodeArray* GetBytecodeArray();
5414};
Steve Blocka7e24c12009-10-30 11:49:00 +00005415
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005416// Dependent code is a singly linked list of fixed arrays. Each array contains
5417// code objects in weak cells for one dependent group. The suffix of the array
5418// can be filled with the undefined value if the number of codes is less than
5419// the length of the array.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005420//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005421// +------+-----------------+--------+--------+-----+--------+-----------+-----+
5422// | next | count & group 1 | code 1 | code 2 | ... | code n | undefined | ... |
5423// +------+-----------------+--------+--------+-----+--------+-----------+-----+
5424// |
5425// V
5426// +------+-----------------+--------+--------+-----+--------+-----------+-----+
5427// | next | count & group 2 | code 1 | code 2 | ... | code m | undefined | ... |
5428// +------+-----------------+--------+--------+-----+--------+-----------+-----+
5429// |
5430// V
5431// empty_fixed_array()
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005432//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005433// The list of fixed arrays is ordered by dependency groups.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005434
5435class DependentCode: public FixedArray {
5436 public:
5437 enum DependencyGroup {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005438 // Group of code that weakly embed this map and depend on being
5439 // deoptimized when the map is garbage collected.
5440 kWeakCodeGroup,
5441 // Group of code that embed a transition to this map, and depend on being
5442 // deoptimized when the transition is replaced by a new version.
5443 kTransitionGroup,
5444 // Group of code that omit run-time prototype checks for prototypes
5445 // described by this map. The group is deoptimized whenever an object
5446 // described by this map changes shape (and transitions to a new map),
5447 // possibly invalidating the assumptions embedded in the code.
5448 kPrototypeCheckGroup,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005449 // Group of code that depends on global property values in property cells
5450 // not being changed.
5451 kPropertyCellChangedGroup,
5452 // Group of code that omit run-time type checks for the field(s) introduced
5453 // by this map.
5454 kFieldTypeGroup,
5455 // Group of code that omit run-time type checks for initial maps of
5456 // constructors.
5457 kInitialMapChangedGroup,
5458 // Group of code that depends on tenuring information in AllocationSites
5459 // not being changed.
5460 kAllocationSiteTenuringChangedGroup,
5461 // Group of code that depends on element transition information in
5462 // AllocationSites not being changed.
5463 kAllocationSiteTransitionChangedGroup
5464 };
5465
5466 static const int kGroupCount = kAllocationSiteTransitionChangedGroup + 1;
5467
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005468 bool Contains(DependencyGroup group, WeakCell* code_cell);
5469 bool IsEmpty(DependencyGroup group);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005470
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005471 static Handle<DependentCode> InsertCompilationDependencies(
5472 Handle<DependentCode> entries, DependencyGroup group,
5473 Handle<Foreign> info);
5474
5475 static Handle<DependentCode> InsertWeakCode(Handle<DependentCode> entries,
5476 DependencyGroup group,
5477 Handle<WeakCell> code_cell);
5478
5479 void UpdateToFinishedCode(DependencyGroup group, Foreign* info,
5480 WeakCell* code_cell);
5481
5482 void RemoveCompilationDependencies(DependentCode::DependencyGroup group,
5483 Foreign* info);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005484
5485 void DeoptimizeDependentCodeGroup(Isolate* isolate,
5486 DependentCode::DependencyGroup group);
5487
5488 bool MarkCodeForDeoptimization(Isolate* isolate,
5489 DependentCode::DependencyGroup group);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005490
5491 // The following low-level accessors should only be used by this class
5492 // and the mark compact collector.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005493 inline DependentCode* next_link();
5494 inline void set_next_link(DependentCode* next);
5495 inline int count();
5496 inline void set_count(int value);
5497 inline DependencyGroup group();
5498 inline void set_group(DependencyGroup group);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005499 inline Object* object_at(int i);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005500 inline void set_object_at(int i, Object* object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005501 inline void clear_at(int i);
5502 inline void copy(int from, int to);
5503 DECLARE_CAST(DependentCode)
5504
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005505 static const char* DependencyGroupName(DependencyGroup group);
5506 static void SetMarkedForDeoptimization(Code* code, DependencyGroup group);
5507
5508 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005509 static Handle<DependentCode> Insert(Handle<DependentCode> entries,
5510 DependencyGroup group,
5511 Handle<Object> object);
5512 static Handle<DependentCode> New(DependencyGroup group, Handle<Object> object,
5513 Handle<DependentCode> next);
5514 static Handle<DependentCode> EnsureSpace(Handle<DependentCode> entries);
5515 // Compact by removing cleared weak cells and return true if there was
5516 // any cleared weak cell.
5517 bool Compact();
5518 static int Grow(int number_of_entries) {
5519 if (number_of_entries < 5) return number_of_entries + 1;
5520 return number_of_entries * 5 / 4;
5521 }
5522 inline int flags();
5523 inline void set_flags(int flags);
5524 class GroupField : public BitField<int, 0, 3> {};
5525 class CountField : public BitField<int, 3, 27> {};
5526 STATIC_ASSERT(kGroupCount <= GroupField::kMax + 1);
5527 static const int kNextLinkIndex = 0;
5528 static const int kFlagsIndex = 1;
5529 static const int kCodesStartIndex = 2;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005530};
5531
5532
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005533class PrototypeInfo;
5534
5535
Steve Blocka7e24c12009-10-30 11:49:00 +00005536// All heap objects have a Map that describes their structure.
5537// A Map contains information about:
5538// - Size information about the object
5539// - How to iterate over an object (for garbage collection)
5540class Map: public HeapObject {
5541 public:
5542 // Instance size.
Steve Block791712a2010-08-27 10:21:07 +01005543 // Size in bytes or kVariableSizeSentinel if instances do not have
5544 // a fixed size.
Steve Blocka7e24c12009-10-30 11:49:00 +00005545 inline int instance_size();
5546 inline void set_instance_size(int value);
5547
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005548 // Only to clear an unused byte, remove once byte is used.
5549 inline void clear_unused();
Steve Blocka7e24c12009-10-30 11:49:00 +00005550
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005551 // [inobject_properties_or_constructor_function_index]: Provides access
5552 // to the inobject properties in case of JSObject maps, or the constructor
5553 // function index in case of primitive maps.
5554 inline int inobject_properties_or_constructor_function_index();
5555 inline void set_inobject_properties_or_constructor_function_index(int value);
5556 // Count of properties allocated in the object (JSObject only).
5557 inline int GetInObjectProperties();
5558 inline void SetInObjectProperties(int value);
5559 // Index of the constructor function in the native context (primitives only),
5560 // or the special sentinel value to indicate that there is no object wrapper
5561 // for the primitive (i.e. in case of null or undefined).
5562 static const int kNoConstructorFunctionIndex = 0;
5563 inline int GetConstructorFunctionIndex();
5564 inline void SetConstructorFunctionIndex(int value);
5565 static MaybeHandle<JSFunction> GetConstructorFunction(
5566 Handle<Map> map, Handle<Context> native_context);
Steve Blocka7e24c12009-10-30 11:49:00 +00005567
5568 // Instance type.
5569 inline InstanceType instance_type();
5570 inline void set_instance_type(InstanceType value);
5571
5572 // Tells how many unused property fields are available in the
5573 // instance (only used for JSObject in fast mode).
5574 inline int unused_property_fields();
5575 inline void set_unused_property_fields(int value);
5576
5577 // Bit field.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005578 inline byte bit_field() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00005579 inline void set_bit_field(byte value);
5580
5581 // Bit field 2.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005582 inline byte bit_field2() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00005583 inline void set_bit_field2(byte value);
5584
Ben Murdoch257744e2011-11-30 15:57:28 +00005585 // Bit field 3.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005586 inline uint32_t bit_field3() const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005587 inline void set_bit_field3(uint32_t bits);
5588
5589 class EnumLengthBits: public BitField<int,
5590 0, kDescriptorIndexBitCount> {}; // NOLINT
5591 class NumberOfOwnDescriptorsBits: public BitField<int,
5592 kDescriptorIndexBitCount, kDescriptorIndexBitCount> {}; // NOLINT
5593 STATIC_ASSERT(kDescriptorIndexBitCount + kDescriptorIndexBitCount == 20);
5594 class DictionaryMap : public BitField<bool, 20, 1> {};
5595 class OwnsDescriptors : public BitField<bool, 21, 1> {};
Ben Murdoch097c5b22016-05-18 11:27:45 +01005596 class HasHiddenPrototype : public BitField<bool, 22, 1> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005597 class Deprecated : public BitField<bool, 23, 1> {};
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005598 class IsUnstable : public BitField<bool, 24, 1> {};
5599 class IsMigrationTarget : public BitField<bool, 25, 1> {};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005600 class IsStrong : public BitField<bool, 26, 1> {};
5601 class NewTargetIsBase : public BitField<bool, 27, 1> {};
5602 // Bit 28 is free.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005603
5604 // Keep this bit field at the very end for better code in
5605 // Builtins::kJSConstructStubGeneric stub.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005606 // This counter is used for in-object slack tracking.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005607 // The in-object slack tracking is considered enabled when the counter is
Ben Murdoch097c5b22016-05-18 11:27:45 +01005608 // non zero. The counter only has a valid count for initial maps. For
5609 // transitioned maps only kNoSlackTracking has a meaning, namely that inobject
5610 // slack tracking already finished for the transition tree. Any other value
5611 // indicates that either inobject slack tracking is still in progress, or that
5612 // the map isn't part of the transition tree anymore.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005613 class ConstructionCounter : public BitField<int, 29, 3> {};
5614 static const int kSlackTrackingCounterStart = 7;
5615 static const int kSlackTrackingCounterEnd = 1;
5616 static const int kNoSlackTracking = 0;
5617 STATIC_ASSERT(kSlackTrackingCounterStart <= ConstructionCounter::kMax);
5618
5619
5620 // Inobject slack tracking is the way to reclaim unused inobject space.
5621 //
5622 // The instance size is initially determined by adding some slack to
5623 // expected_nof_properties (to allow for a few extra properties added
5624 // after the constructor). There is no guarantee that the extra space
5625 // will not be wasted.
5626 //
5627 // Here is the algorithm to reclaim the unused inobject space:
5628 // - Detect the first constructor call for this JSFunction.
5629 // When it happens enter the "in progress" state: initialize construction
5630 // counter in the initial_map.
5631 // - While the tracking is in progress initialize unused properties of a new
5632 // object with one_pointer_filler_map instead of undefined_value (the "used"
5633 // part is initialized with undefined_value as usual). This way they can
5634 // be resized quickly and safely.
5635 // - Once enough objects have been created compute the 'slack'
5636 // (traverse the map transition tree starting from the
5637 // initial_map and find the lowest value of unused_property_fields).
5638 // - Traverse the transition tree again and decrease the instance size
5639 // of every map. Existing objects will resize automatically (they are
5640 // filled with one_pointer_filler_map). All further allocations will
5641 // use the adjusted instance size.
5642 // - SharedFunctionInfo's expected_nof_properties left unmodified since
5643 // allocations made using different closures could actually create different
5644 // kind of objects (see prototype inheritance pattern).
5645 //
5646 // Important: inobject slack tracking is not attempted during the snapshot
5647 // creation.
5648
5649 static const int kGenerousAllocationCount =
5650 kSlackTrackingCounterStart - kSlackTrackingCounterEnd + 1;
5651
5652 // Starts the tracking by initializing object constructions countdown counter.
5653 void StartInobjectSlackTracking();
5654
5655 // True if the object constructions countdown counter is a range
5656 // [kSlackTrackingCounterEnd, kSlackTrackingCounterStart].
5657 inline bool IsInobjectSlackTrackingInProgress();
5658
5659 // Does the tracking step.
5660 inline void InobjectSlackTrackingStep();
5661
5662 // Completes inobject slack tracking for the transition tree starting at this
5663 // initial map.
5664 void CompleteInobjectSlackTracking();
Ben Murdoch257744e2011-11-30 15:57:28 +00005665
Steve Blocka7e24c12009-10-30 11:49:00 +00005666 // Tells whether the object in the prototype property will be used
5667 // for instances created from this function. If the prototype
5668 // property is set to a value that is not a JSObject, the prototype
5669 // property will not be used to create instances of the function.
5670 // See ECMA-262, 13.2.2.
5671 inline void set_non_instance_prototype(bool value);
5672 inline bool has_non_instance_prototype();
5673
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005674 // Tells whether the instance has a [[Construct]] internal method.
5675 // This property is implemented according to ES6, section 7.2.4.
Ben Murdoch097c5b22016-05-18 11:27:45 +01005676 inline void set_is_constructor(bool value);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005677 inline bool is_constructor() const;
Steve Block6ded16b2010-05-10 14:33:55 +01005678
Ben Murdoch097c5b22016-05-18 11:27:45 +01005679 // Tells whether the instance with this map has a hidden prototype.
5680 inline void set_has_hidden_prototype(bool value);
5681 inline bool has_hidden_prototype() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00005682
5683 // Records and queries whether the instance has a named interceptor.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005684 inline void set_has_named_interceptor();
5685 inline bool has_named_interceptor();
Steve Blocka7e24c12009-10-30 11:49:00 +00005686
5687 // Records and queries whether the instance has an indexed interceptor.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005688 inline void set_has_indexed_interceptor();
5689 inline bool has_indexed_interceptor();
Steve Blocka7e24c12009-10-30 11:49:00 +00005690
5691 // Tells whether the instance is undetectable.
5692 // An undetectable object is a special class of JSObject: 'typeof' operator
5693 // returns undefined, ToBoolean returns false. Otherwise it behaves like
5694 // a normal JS object. It is useful for implementing undetectable
5695 // document.all in Firefox & Safari.
5696 // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005697 inline void set_is_undetectable();
5698 inline bool is_undetectable();
Steve Blocka7e24c12009-10-30 11:49:00 +00005699
Steve Blocka7e24c12009-10-30 11:49:00 +00005700 // Tells whether the instance has a call-as-function handler.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005701 inline void set_is_observed();
5702 inline bool is_observed();
Steve Blocka7e24c12009-10-30 11:49:00 +00005703
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005704 // Tells whether the instance has a [[Call]] internal method.
5705 // This property is implemented according to ES6, section 7.2.3.
5706 inline void set_is_callable();
5707 inline bool is_callable() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00005708
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005709 inline void set_is_strong();
5710 inline bool is_strong();
5711 inline void set_new_target_is_base(bool value);
5712 inline bool new_target_is_base();
Steve Block8defd9f2010-07-08 12:39:36 +01005713 inline void set_is_extensible(bool value);
5714 inline bool is_extensible();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005715 inline void set_is_prototype_map(bool value);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005716 inline bool is_prototype_map() const;
Steve Block8defd9f2010-07-08 12:39:36 +01005717
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005718 inline void set_elements_kind(ElementsKind elements_kind);
5719 inline ElementsKind elements_kind();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00005720
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005721 // Tells whether the instance has fast elements that are only Smis.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005722 inline bool has_fast_smi_elements();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005723
Steve Block8defd9f2010-07-08 12:39:36 +01005724 // Tells whether the instance has fast elements.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005725 inline bool has_fast_object_elements();
5726 inline bool has_fast_smi_or_object_elements();
5727 inline bool has_fast_double_elements();
5728 inline bool has_fast_elements();
5729 inline bool has_sloppy_arguments_elements();
Ben Murdoch097c5b22016-05-18 11:27:45 +01005730 inline bool has_fast_string_wrapper_elements();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005731 inline bool has_fixed_typed_array_elements();
5732 inline bool has_dictionary_elements();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005733
5734 static bool IsValidElementsTransition(ElementsKind from_kind,
5735 ElementsKind to_kind);
5736
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005737 // Returns true if the current map doesn't have DICTIONARY_ELEMENTS but if a
5738 // map with DICTIONARY_ELEMENTS was found in the prototype chain.
5739 bool DictionaryElementsInPrototypeChainOnly();
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005740
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005741 inline Map* ElementsTransitionMap();
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005742
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005743 inline FixedArrayBase* GetInitialElements();
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005744
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005745 // [raw_transitions]: Provides access to the transitions storage field.
5746 // Don't call set_raw_transitions() directly to overwrite transitions, use
5747 // the TransitionArray::ReplaceTransitions() wrapper instead!
5748 DECL_ACCESSORS(raw_transitions, Object)
5749 // [prototype_info]: Per-prototype metadata. Aliased with transitions
5750 // (which prototype maps don't have).
5751 DECL_ACCESSORS(prototype_info, Object)
5752 // PrototypeInfo is created lazily using this helper (which installs it on
5753 // the given prototype's map).
5754 static Handle<PrototypeInfo> GetOrCreatePrototypeInfo(
5755 Handle<JSObject> prototype, Isolate* isolate);
5756 static Handle<PrototypeInfo> GetOrCreatePrototypeInfo(
5757 Handle<Map> prototype_map, Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005758
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005759 // [prototype chain validity cell]: Associated with a prototype object,
5760 // stored in that object's map's PrototypeInfo, indicates that prototype
5761 // chains through this object are currently valid. The cell will be
5762 // invalidated and replaced when the prototype chain changes.
5763 static Handle<Cell> GetOrCreatePrototypeChainValidityCell(Handle<Map> map,
5764 Isolate* isolate);
5765 static const int kPrototypeChainValid = 0;
5766 static const int kPrototypeChainInvalid = 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005767
5768 Map* FindRootMap();
5769 Map* FindFieldOwner(int descriptor);
5770
5771 inline int GetInObjectPropertyOffset(int index);
5772
5773 int NumberOfFields();
5774
5775 // TODO(ishell): candidate with JSObject::MigrateToMap().
5776 bool InstancesNeedRewriting(Map* target, int target_number_of_fields,
5777 int target_inobject, int target_unused,
5778 int* old_number_of_fields);
5779 // TODO(ishell): moveit!
5780 static Handle<Map> GeneralizeAllFieldRepresentations(Handle<Map> map);
Ben Murdoch097c5b22016-05-18 11:27:45 +01005781 MUST_USE_RESULT static Handle<FieldType> GeneralizeFieldType(
5782 Representation rep1, Handle<FieldType> type1, Representation rep2,
5783 Handle<FieldType> type2, Isolate* isolate);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005784 static void GeneralizeFieldType(Handle<Map> map, int modify_index,
5785 Representation new_representation,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005786 Handle<FieldType> new_field_type);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005787 static Handle<Map> ReconfigureProperty(Handle<Map> map, int modify_index,
5788 PropertyKind new_kind,
5789 PropertyAttributes new_attributes,
5790 Representation new_representation,
Ben Murdoch097c5b22016-05-18 11:27:45 +01005791 Handle<FieldType> new_field_type,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005792 StoreMode store_mode);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005793 static Handle<Map> CopyGeneralizeAllRepresentations(
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005794 Handle<Map> map, int modify_index, StoreMode store_mode,
5795 PropertyKind kind, PropertyAttributes attributes, const char* reason);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005796
5797 static Handle<Map> PrepareForDataProperty(Handle<Map> old_map,
5798 int descriptor_number,
5799 Handle<Object> value);
5800
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005801 static Handle<Map> Normalize(Handle<Map> map, PropertyNormalizationMode mode,
5802 const char* reason);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005803
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005804 // Tells whether the map is used for JSObjects in dictionary mode (ie
5805 // normalized objects, ie objects for which HasFastProperties returns false).
5806 // A map can never be used for both dictionary mode and fast mode JSObjects.
5807 // False by default and for HeapObjects that are not JSObjects.
5808 inline void set_dictionary_map(bool value);
5809 inline bool is_dictionary_map();
Kristian Monsen0d5e1162010-09-30 15:31:59 +01005810
Steve Blocka7e24c12009-10-30 11:49:00 +00005811 // Tells whether the instance needs security checks when accessing its
5812 // properties.
5813 inline void set_is_access_check_needed(bool access_check_needed);
5814 inline bool is_access_check_needed();
5815
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005816 // Returns true if map has a non-empty stub code cache.
5817 inline bool has_code_cache();
5818
Steve Blocka7e24c12009-10-30 11:49:00 +00005819 // [prototype]: implicit prototype object.
5820 DECL_ACCESSORS(prototype, Object)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005821 // TODO(jkummerow): make set_prototype private.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005822 static void SetPrototype(
5823 Handle<Map> map, Handle<Object> prototype,
5824 PrototypeOptimizationMode proto_mode = FAST_PROTOTYPE);
Steve Blocka7e24c12009-10-30 11:49:00 +00005825
5826 // [constructor]: points back to the function responsible for this map.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005827 // The field overlaps with the back pointer. All maps in a transition tree
5828 // have the same constructor, so maps with back pointers can walk the
5829 // back pointer chain until they find the map holding their constructor.
5830 DECL_ACCESSORS(constructor_or_backpointer, Object)
5831 inline Object* GetConstructor() const;
5832 inline void SetConstructor(Object* constructor,
5833 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
5834 // [back pointer]: points back to the parent map from which a transition
5835 // leads to this map. The field overlaps with the constructor (see above).
5836 inline Object* GetBackPointer();
5837 inline void SetBackPointer(Object* value,
5838 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
Steve Blocka7e24c12009-10-30 11:49:00 +00005839
5840 // [instance descriptors]: describes the object.
5841 DECL_ACCESSORS(instance_descriptors, DescriptorArray)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005842
5843 // [layout descriptor]: describes the object layout.
5844 DECL_ACCESSORS(layout_descriptor, LayoutDescriptor)
5845 // |layout descriptor| accessor which can be used from GC.
5846 inline LayoutDescriptor* layout_descriptor_gc_safe();
5847 inline bool HasFastPointerLayout() const;
5848
5849 // |layout descriptor| accessor that is safe to call even when
5850 // FLAG_unbox_double_fields is disabled (in this case Map does not contain
5851 // |layout_descriptor| field at all).
5852 inline LayoutDescriptor* GetLayoutDescriptor();
5853
5854 inline void UpdateDescriptors(DescriptorArray* descriptors,
5855 LayoutDescriptor* layout_descriptor);
5856 inline void InitializeDescriptors(DescriptorArray* descriptors,
5857 LayoutDescriptor* layout_descriptor);
Ben Murdoch257744e2011-11-30 15:57:28 +00005858
Steve Blocka7e24c12009-10-30 11:49:00 +00005859 // [stub cache]: contains stubs compiled for this map.
Steve Block6ded16b2010-05-10 14:33:55 +01005860 DECL_ACCESSORS(code_cache, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +00005861
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005862 // [dependent code]: list of optimized codes that weakly embed this map.
5863 DECL_ACCESSORS(dependent_code, DependentCode)
5864
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005865 // [weak cell cache]: cache that stores a weak cell pointing to this map.
5866 DECL_ACCESSORS(weak_cell_cache, Object)
Kristian Monsen80d68ea2010-09-08 11:05:35 +01005867
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005868 inline PropertyDetails GetLastDescriptorDetails();
5869
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005870 inline int LastAdded();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005871
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005872 inline int NumberOfOwnDescriptors();
5873 inline void SetNumberOfOwnDescriptors(int number);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005874
5875 inline Cell* RetrieveDescriptorsPointer();
5876
Ben Murdoch097c5b22016-05-18 11:27:45 +01005877 // Checks whether all properties are stored either in the map or on the object
5878 // (inobject, properties, or elements backing store), requiring no special
5879 // checks.
5880 bool OnlyHasSimpleProperties();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005881 inline int EnumLength();
5882 inline void SetEnumLength(int length);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005883
5884 inline bool owns_descriptors();
5885 inline void set_owns_descriptors(bool owns_descriptors);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005886 inline void mark_unstable();
5887 inline bool is_stable();
5888 inline void set_migration_target(bool value);
5889 inline bool is_migration_target();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005890 inline void set_construction_counter(int value);
5891 inline int construction_counter();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005892 inline void deprecate();
5893 inline bool is_deprecated();
5894 inline bool CanBeDeprecated();
5895 // Returns a non-deprecated version of the input. If the input was not
5896 // deprecated, it is directly returned. Otherwise, the non-deprecated version
5897 // is found by re-transitioning from the root of the transition tree using the
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005898 // descriptor array of the map. Returns MaybeHandle<Map>() if no updated map
5899 // is found.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005900 static MaybeHandle<Map> TryUpdate(Handle<Map> map) WARN_UNUSED_RESULT;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005901
5902 // Returns a non-deprecated version of the input. This method may deprecate
5903 // existing maps along the way if encodings conflict. Not for use while
5904 // gathering type feedback. Use TryUpdate in those cases instead.
5905 static Handle<Map> Update(Handle<Map> map);
5906
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005907 static inline Handle<Map> CopyInitialMap(Handle<Map> map);
5908 static Handle<Map> CopyInitialMap(Handle<Map> map, int instance_size,
5909 int in_object_properties,
5910 int unused_property_fields);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005911 static Handle<Map> CopyDropDescriptors(Handle<Map> map);
5912 static Handle<Map> CopyInsertDescriptor(Handle<Map> map,
5913 Descriptor* descriptor,
5914 TransitionFlag flag);
5915
5916 MUST_USE_RESULT static MaybeHandle<Map> CopyWithField(
Ben Murdoch097c5b22016-05-18 11:27:45 +01005917 Handle<Map> map, Handle<Name> name, Handle<FieldType> type,
5918 PropertyAttributes attributes, Representation representation,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005919 TransitionFlag flag);
5920
5921 MUST_USE_RESULT static MaybeHandle<Map> CopyWithConstant(
5922 Handle<Map> map,
5923 Handle<Name> name,
5924 Handle<Object> constant,
5925 PropertyAttributes attributes,
5926 TransitionFlag flag);
5927
5928 // Returns a new map with all transitions dropped from the given map and
5929 // the ElementsKind set.
5930 static Handle<Map> TransitionElementsTo(Handle<Map> map,
5931 ElementsKind to_kind);
5932
5933 static Handle<Map> AsElementsKind(Handle<Map> map, ElementsKind kind);
5934
5935 static Handle<Map> CopyAsElementsKind(Handle<Map> map,
5936 ElementsKind kind,
5937 TransitionFlag flag);
5938
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005939 static Handle<Map> AsLanguageMode(Handle<Map> initial_map,
5940 LanguageMode language_mode,
5941 FunctionKind kind);
5942
5943
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005944 static Handle<Map> CopyForObserved(Handle<Map> map);
5945
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005946 static Handle<Map> CopyForPreventExtensions(Handle<Map> map,
5947 PropertyAttributes attrs_to_add,
5948 Handle<Symbol> transition_marker,
5949 const char* reason);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005950
5951 static Handle<Map> FixProxy(Handle<Map> map, InstanceType type, int size);
5952
5953
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005954 // Maximal number of fast properties. Used to restrict the number of map
5955 // transitions to avoid an explosion in the number of maps for objects used as
5956 // dictionaries.
5957 inline bool TooManyFastProperties(StoreFromKeyed store_mode);
5958 static Handle<Map> TransitionToDataProperty(Handle<Map> map,
5959 Handle<Name> name,
5960 Handle<Object> value,
5961 PropertyAttributes attributes,
5962 StoreFromKeyed store_mode);
5963 static Handle<Map> TransitionToAccessorProperty(
5964 Handle<Map> map, Handle<Name> name, AccessorComponent component,
5965 Handle<Object> accessor, PropertyAttributes attributes);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005966 static Handle<Map> ReconfigureExistingProperty(Handle<Map> map,
5967 int descriptor,
5968 PropertyKind kind,
5969 PropertyAttributes attributes);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005970
5971 inline void AppendDescriptor(Descriptor* desc);
Steve Blocka7e24c12009-10-30 11:49:00 +00005972
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005973 // Returns a copy of the map, prepared for inserting into the transition
5974 // tree (if the |map| owns descriptors then the new one will share
5975 // descriptors with |map|).
5976 static Handle<Map> CopyForTransition(Handle<Map> map, const char* reason);
5977
Steve Blocka7e24c12009-10-30 11:49:00 +00005978 // Returns a copy of the map, with all transitions dropped from the
5979 // instance descriptors.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005980 static Handle<Map> Copy(Handle<Map> map, const char* reason);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005981 static Handle<Map> Create(Isolate* isolate, int inobject_properties);
Steve Blocka7e24c12009-10-30 11:49:00 +00005982
5983 // Returns the next free property index (only valid for FAST MODE).
5984 int NextFreePropertyIndex();
5985
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005986 // Returns the number of properties described in instance_descriptors
5987 // filtering out properties with the specified attributes.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005988 int NumberOfDescribedProperties(DescriptorFlag which = OWN_DESCRIPTORS,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00005989 PropertyFilter filter = ALL_PROPERTIES);
Steve Blocka7e24c12009-10-30 11:49:00 +00005990
Ben Murdochb8a8cc12014-11-26 15:28:44 +00005991 DECLARE_CAST(Map)
Steve Blocka7e24c12009-10-30 11:49:00 +00005992
5993 // Code cache operations.
5994
5995 // Clears the code cache.
Steve Block44f0eee2011-05-26 01:26:41 +01005996 inline void ClearCodeCache(Heap* heap);
Steve Blocka7e24c12009-10-30 11:49:00 +00005997
5998 // Update code cache.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01005999 static void UpdateCodeCache(Handle<Map> map,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006000 Handle<Name> name,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006001 Handle<Code> code);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006002
6003 // Extend the descriptor array of the map with the list of descriptors.
6004 // In case of duplicates, the latest descriptor is used.
6005 static void AppendCallbackDescriptors(Handle<Map> map,
6006 Handle<Object> descriptors);
6007
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006008 static inline int SlackForArraySize(int old_size, int size_limit);
6009
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006010 static void EnsureDescriptorSlack(Handle<Map> map, int slack);
Steve Blocka7e24c12009-10-30 11:49:00 +00006011
6012 // Returns the found code or undefined if absent.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006013 Object* FindInCodeCache(Name* name, Code::Flags flags);
Steve Blocka7e24c12009-10-30 11:49:00 +00006014
6015 // Returns the non-negative index of the code object if it is in the
6016 // cache and -1 otherwise.
Steve Block6ded16b2010-05-10 14:33:55 +01006017 int IndexInCodeCache(Object* name, Code* code);
Steve Blocka7e24c12009-10-30 11:49:00 +00006018
6019 // Removes a code object from the code cache at the given index.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006020 void RemoveFromCodeCache(Name* name, Code* code, int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00006021
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006022 // Computes a hash value for this map, to be used in HashTables and such.
6023 int Hash();
6024
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006025 // Returns the map that this map transitions to if its elements_kind
6026 // is changed to |elements_kind|, or NULL if no such map is cached yet.
6027 // |safe_to_add_transitions| is set to false if adding transitions is not
6028 // allowed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006029 Map* LookupElementsTransitionMap(ElementsKind elements_kind);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006030
6031 // Returns the transitioned map for this map with the most generic
6032 // elements_kind that's found in |candidates|, or null handle if no match is
6033 // found at all.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006034 static Handle<Map> FindTransitionedMap(Handle<Map> map,
6035 MapHandleList* candidates);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006036
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006037 inline bool CanTransition();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006038
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006039 inline bool IsBooleanMap();
6040 inline bool IsPrimitiveMap();
6041 inline bool IsJSReceiverMap();
6042 inline bool IsJSObjectMap();
6043 inline bool IsJSArrayMap();
6044 inline bool IsJSFunctionMap();
6045 inline bool IsStringMap();
6046 inline bool IsJSProxyMap();
6047 inline bool IsJSGlobalProxyMap();
6048 inline bool IsJSGlobalObjectMap();
6049 inline bool IsJSTypedArrayMap();
6050 inline bool IsJSDataViewMap();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006051
6052 inline bool CanOmitMapChecks();
6053
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006054 static void AddDependentCode(Handle<Map> map,
6055 DependentCode::DependencyGroup group,
6056 Handle<Code> code);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006057
6058 bool IsMapInArrayPrototypeChain();
Ben Murdoch592a9fc2012-03-05 11:04:45 +00006059
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006060 static Handle<WeakCell> WeakCellForMap(Handle<Map> map);
6061
Steve Blocka7e24c12009-10-30 11:49:00 +00006062 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006063 DECLARE_PRINTER(Map)
6064 DECLARE_VERIFIER(Map)
6065
6066#ifdef VERIFY_HEAP
6067 void DictionaryMapVerify();
6068 void VerifyOmittedMapChecks();
Steve Blocka7e24c12009-10-30 11:49:00 +00006069#endif
6070
Iain Merrick75681382010-08-19 15:07:18 +01006071 inline int visitor_id();
6072 inline void set_visitor_id(int visitor_id);
Ben Murdoch3bec4d22010-07-22 14:51:16 +01006073
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006074 static Handle<Map> TransitionToPrototype(Handle<Map> map,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006075 Handle<Object> prototype,
6076 PrototypeOptimizationMode mode);
Steve Block053d10c2011-06-13 19:13:29 +01006077
Steve Blocka7e24c12009-10-30 11:49:00 +00006078 static const int kMaxPreAllocatedPropertyFields = 255;
6079
6080 // Layout description.
6081 static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
6082 static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006083 static const int kBitField3Offset = kInstanceAttributesOffset + kIntSize;
6084 static const int kPrototypeOffset = kBitField3Offset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006085 static const int kConstructorOrBackPointerOffset =
6086 kPrototypeOffset + kPointerSize;
6087 // When there is only one transition, it is stored directly in this field;
6088 // otherwise a transition array is used.
6089 // For prototype maps, this slot is used to store this map's PrototypeInfo
6090 // struct.
6091 static const int kTransitionsOrPrototypeInfoOffset =
6092 kConstructorOrBackPointerOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006093 static const int kDescriptorsOffset =
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006094 kTransitionsOrPrototypeInfoOffset + kPointerSize;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006095#if V8_DOUBLE_FIELDS_UNBOXING
6096 static const int kLayoutDecriptorOffset = kDescriptorsOffset + kPointerSize;
6097 static const int kCodeCacheOffset = kLayoutDecriptorOffset + kPointerSize;
6098#else
6099 static const int kLayoutDecriptorOffset = 1; // Must not be ever accessed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006100 static const int kCodeCacheOffset = kDescriptorsOffset + kPointerSize;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006101#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006102 static const int kDependentCodeOffset = kCodeCacheOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006103 static const int kWeakCellCacheOffset = kDependentCodeOffset + kPointerSize;
6104 static const int kSize = kWeakCellCacheOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01006105
6106 // Layout of pointer fields. Heap iteration code relies on them
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006107 // being continuously allocated.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01006108 static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006109 static const int kPointerFieldsEndOffset = kSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00006110
6111 // Byte offsets within kInstanceSizesOffset.
6112 static const int kInstanceSizeOffset = kInstanceSizesOffset + 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006113 static const int kInObjectPropertiesOrConstructorFunctionIndexByte = 1;
6114 static const int kInObjectPropertiesOrConstructorFunctionIndexOffset =
6115 kInstanceSizesOffset + kInObjectPropertiesOrConstructorFunctionIndexByte;
6116 // Note there is one byte available for use here.
6117 static const int kUnusedByte = 2;
6118 static const int kUnusedOffset = kInstanceSizesOffset + kUnusedByte;
Iain Merrick9ac36c92010-09-13 15:29:50 +01006119 static const int kVisitorIdByte = 3;
6120 static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte;
Steve Blocka7e24c12009-10-30 11:49:00 +00006121
6122 // Byte offsets within kInstanceAttributesOffset attributes.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006123#if V8_TARGET_LITTLE_ENDIAN
6124 // Order instance type and bit field together such that they can be loaded
6125 // together as a 16-bit word with instance type in the lower 8 bits regardless
6126 // of endianess. Also provide endian-independent offset to that 16-bit word.
Steve Blocka7e24c12009-10-30 11:49:00 +00006127 static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006128 static const int kBitFieldOffset = kInstanceAttributesOffset + 1;
6129#else
6130 static const int kBitFieldOffset = kInstanceAttributesOffset + 0;
6131 static const int kInstanceTypeOffset = kInstanceAttributesOffset + 1;
6132#endif
6133 static const int kInstanceTypeAndBitFieldOffset =
6134 kInstanceAttributesOffset + 0;
6135 static const int kBitField2Offset = kInstanceAttributesOffset + 2;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006136 static const int kUnusedPropertyFieldsByte = 3;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006137 static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 3;
Steve Blocka7e24c12009-10-30 11:49:00 +00006138
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006139 STATIC_ASSERT(kInstanceTypeAndBitFieldOffset ==
6140 Internals::kMapInstanceTypeAndBitFieldOffset);
Steve Blocka7e24c12009-10-30 11:49:00 +00006141
6142 // Bit positions for bit field.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006143 static const int kHasNonInstancePrototype = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006144 static const int kIsCallable = 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006145 static const int kHasNamedInterceptor = 2;
6146 static const int kHasIndexedInterceptor = 3;
6147 static const int kIsUndetectable = 4;
6148 static const int kIsObserved = 5;
6149 static const int kIsAccessCheckNeeded = 6;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006150 static const int kIsConstructor = 7;
Steve Blocka7e24c12009-10-30 11:49:00 +00006151
6152 // Bit positions for bit field 2
Andrei Popescu31002712010-02-23 13:46:05 +00006153 static const int kIsExtensible = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006154 // Bit 1 is free.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006155 class IsPrototypeMapBits : public BitField<bool, 2, 1> {};
6156 class ElementsKindBits: public BitField<ElementsKind, 3, 5> {};
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006157
6158 // Derived values from bit field 2
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006159 static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006160 (FAST_ELEMENTS + 1) << Map::ElementsKindBits::kShift) - 1;
6161 static const int8_t kMaximumBitField2FastSmiElementValue =
6162 static_cast<int8_t>((FAST_SMI_ELEMENTS + 1) <<
6163 Map::ElementsKindBits::kShift) - 1;
6164 static const int8_t kMaximumBitField2FastHoleyElementValue =
6165 static_cast<int8_t>((FAST_HOLEY_ELEMENTS + 1) <<
6166 Map::ElementsKindBits::kShift) - 1;
6167 static const int8_t kMaximumBitField2FastHoleySmiElementValue =
6168 static_cast<int8_t>((FAST_HOLEY_SMI_ELEMENTS + 1) <<
6169 Map::ElementsKindBits::kShift) - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +00006170
Iain Merrick75681382010-08-19 15:07:18 +01006171 typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
6172 kPointerFieldsEndOffset,
6173 kSize> BodyDescriptor;
6174
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006175 // Compares this map to another to see if they describe equivalent objects.
6176 // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if
6177 // it had exactly zero inobject properties.
6178 // The "shared" flags of both this map and |other| are ignored.
6179 bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode);
6180
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006181 // Returns true if given field is unboxed double.
6182 inline bool IsUnboxedDoubleField(FieldIndex index);
6183
6184#if TRACE_MAPS
6185 static void TraceTransition(const char* what, Map* from, Map* to, Name* name);
6186 static void TraceAllTransitions(Map* map);
6187#endif
6188
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006189 static inline Handle<Map> AddMissingTransitionsForTesting(
6190 Handle<Map> split_map, Handle<DescriptorArray> descriptors,
6191 Handle<LayoutDescriptor> full_layout_descriptor);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006192
Steve Blocka7e24c12009-10-30 11:49:00 +00006193 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006194 static void ConnectTransition(Handle<Map> parent, Handle<Map> child,
6195 Handle<Name> name, SimpleTransitionFlag flag);
6196
6197 bool EquivalentToForTransition(Map* other);
6198 static Handle<Map> RawCopy(Handle<Map> map, int instance_size);
6199 static Handle<Map> ShareDescriptor(Handle<Map> map,
6200 Handle<DescriptorArray> descriptors,
6201 Descriptor* descriptor);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006202 static Handle<Map> AddMissingTransitions(
6203 Handle<Map> map, Handle<DescriptorArray> descriptors,
6204 Handle<LayoutDescriptor> full_layout_descriptor);
6205 static void InstallDescriptors(
6206 Handle<Map> parent_map, Handle<Map> child_map, int new_descriptor,
6207 Handle<DescriptorArray> descriptors,
6208 Handle<LayoutDescriptor> full_layout_descriptor);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006209 static Handle<Map> CopyAddDescriptor(Handle<Map> map,
6210 Descriptor* descriptor,
6211 TransitionFlag flag);
6212 static Handle<Map> CopyReplaceDescriptors(
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006213 Handle<Map> map, Handle<DescriptorArray> descriptors,
6214 Handle<LayoutDescriptor> layout_descriptor, TransitionFlag flag,
6215 MaybeHandle<Name> maybe_name, const char* reason,
6216 SimpleTransitionFlag simple_flag);
6217
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006218 static Handle<Map> CopyReplaceDescriptor(Handle<Map> map,
6219 Handle<DescriptorArray> descriptors,
6220 Descriptor* descriptor,
6221 int index,
6222 TransitionFlag flag);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006223 static MUST_USE_RESULT MaybeHandle<Map> TryReconfigureExistingProperty(
6224 Handle<Map> map, int descriptor, PropertyKind kind,
6225 PropertyAttributes attributes, const char** reason);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006226
6227 static Handle<Map> CopyNormalized(Handle<Map> map,
6228 PropertyNormalizationMode mode);
6229
6230 // Fires when the layout of an object with a leaf map changes.
6231 // This includes adding transitions to the leaf map or changing
6232 // the descriptor array.
6233 inline void NotifyLeafMapLayoutChange();
6234
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006235 void DeprecateTransitionTree();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006236
6237 void ReplaceDescriptors(DescriptorArray* new_descriptors,
6238 LayoutDescriptor* new_layout_descriptor);
6239
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006240
6241 Map* FindLastMatchMap(int verbatim, int length, DescriptorArray* descriptors);
6242
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006243 // Update field type of the given descriptor to new representation and new
6244 // type. The type must be prepared for storing in descriptor array:
6245 // it must be either a simple type or a map wrapped in a weak cell.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006246 void UpdateFieldType(int descriptor_number, Handle<Name> name,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006247 Representation new_representation,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006248 Handle<Object> new_wrapped_type);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006249
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006250 void PrintReconfiguration(FILE* file, int modify_index, PropertyKind kind,
6251 PropertyAttributes attributes);
Ben Murdoch097c5b22016-05-18 11:27:45 +01006252 void PrintGeneralization(FILE* file, const char* reason, int modify_index,
6253 int split, int descriptors, bool constant_to_field,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006254 Representation old_representation,
6255 Representation new_representation,
Ben Murdoch097c5b22016-05-18 11:27:45 +01006256 MaybeHandle<FieldType> old_field_type,
6257 MaybeHandle<Object> old_value,
6258 MaybeHandle<FieldType> new_field_type,
6259 MaybeHandle<Object> new_value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006260
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006261 static const int kFastPropertiesSoftLimit = 12;
6262 static const int kMaxFastProperties = 128;
6263
Steve Blocka7e24c12009-10-30 11:49:00 +00006264 DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
6265};
6266
6267
6268// An abstract superclass, a marker class really, for simple structure classes.
Ben Murdoch257744e2011-11-30 15:57:28 +00006269// It doesn't carry much functionality but allows struct classes to be
Steve Blocka7e24c12009-10-30 11:49:00 +00006270// identified in the type system.
6271class Struct: public HeapObject {
6272 public:
6273 inline void InitializeBody(int object_size);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006274 DECLARE_CAST(Struct)
6275};
6276
6277
6278// A simple one-element struct, useful where smis need to be boxed.
6279class Box : public Struct {
6280 public:
6281 // [value]: the boxed contents.
6282 DECL_ACCESSORS(value, Object)
6283
6284 DECLARE_CAST(Box)
6285
6286 // Dispatched behavior.
6287 DECLARE_PRINTER(Box)
6288 DECLARE_VERIFIER(Box)
6289
6290 static const int kValueOffset = HeapObject::kHeaderSize;
6291 static const int kSize = kValueOffset + kPointerSize;
6292
6293 private:
6294 DISALLOW_IMPLICIT_CONSTRUCTORS(Box);
Steve Blocka7e24c12009-10-30 11:49:00 +00006295};
6296
6297
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006298// Container for metadata stored on each prototype map.
6299class PrototypeInfo : public Struct {
6300 public:
6301 static const int UNREGISTERED = -1;
6302
6303 // [prototype_users]: WeakFixedArray containing maps using this prototype,
6304 // or Smi(0) if uninitialized.
6305 DECL_ACCESSORS(prototype_users, Object)
6306 // [registry_slot]: Slot in prototype's user registry where this user
6307 // is stored. Returns UNREGISTERED if this prototype has not been registered.
6308 inline int registry_slot() const;
6309 inline void set_registry_slot(int slot);
6310 // [validity_cell]: Cell containing the validity bit for prototype chains
6311 // going through this object, or Smi(0) if uninitialized.
6312 // When a prototype object changes its map, then both its own validity cell
6313 // and those of all "downstream" prototypes are invalidated; handlers for a
6314 // given receiver embed the currently valid cell for that receiver's prototype
6315 // during their compilation and check it on execution.
6316 DECL_ACCESSORS(validity_cell, Object)
6317
6318 DECLARE_CAST(PrototypeInfo)
6319
6320 // Dispatched behavior.
6321 DECLARE_PRINTER(PrototypeInfo)
6322 DECLARE_VERIFIER(PrototypeInfo)
6323
6324 static const int kPrototypeUsersOffset = HeapObject::kHeaderSize;
6325 static const int kRegistrySlotOffset = kPrototypeUsersOffset + kPointerSize;
6326 static const int kValidityCellOffset = kRegistrySlotOffset + kPointerSize;
6327 static const int kConstructorNameOffset = kValidityCellOffset + kPointerSize;
6328 static const int kSize = kConstructorNameOffset + kPointerSize;
6329
6330 private:
6331 DISALLOW_IMPLICIT_CONSTRUCTORS(PrototypeInfo);
6332};
6333
6334
6335// Pair used to store both a ScopeInfo and an extension object in the extension
6336// slot of a block context. Needed in the rare case where a declaration block
6337// scope (a "varblock" as used to desugar parameter destructuring) also contains
6338// a sloppy direct eval. (In no other case both are needed at the same time.)
6339class SloppyBlockWithEvalContextExtension : public Struct {
6340 public:
6341 // [scope_info]: Scope info.
6342 DECL_ACCESSORS(scope_info, ScopeInfo)
6343 // [extension]: Extension object.
6344 DECL_ACCESSORS(extension, JSObject)
6345
6346 DECLARE_CAST(SloppyBlockWithEvalContextExtension)
6347
6348 // Dispatched behavior.
6349 DECLARE_PRINTER(SloppyBlockWithEvalContextExtension)
6350 DECLARE_VERIFIER(SloppyBlockWithEvalContextExtension)
6351
6352 static const int kScopeInfoOffset = HeapObject::kHeaderSize;
6353 static const int kExtensionOffset = kScopeInfoOffset + kPointerSize;
6354 static const int kSize = kExtensionOffset + kPointerSize;
6355
6356 private:
6357 DISALLOW_IMPLICIT_CONSTRUCTORS(SloppyBlockWithEvalContextExtension);
6358};
6359
6360
Steve Blocka7e24c12009-10-30 11:49:00 +00006361// Script describes a script which has been added to the VM.
6362class Script: public Struct {
6363 public:
6364 // Script types.
6365 enum Type {
6366 TYPE_NATIVE = 0,
6367 TYPE_EXTENSION = 1,
6368 TYPE_NORMAL = 2
6369 };
6370
6371 // Script compilation types.
6372 enum CompilationType {
6373 COMPILATION_TYPE_HOST = 0,
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08006374 COMPILATION_TYPE_EVAL = 1
Steve Blocka7e24c12009-10-30 11:49:00 +00006375 };
6376
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006377 // Script compilation state.
6378 enum CompilationState {
6379 COMPILATION_STATE_INITIAL = 0,
6380 COMPILATION_STATE_COMPILED = 1
6381 };
6382
Steve Blocka7e24c12009-10-30 11:49:00 +00006383 // [source]: the script source.
6384 DECL_ACCESSORS(source, Object)
6385
6386 // [name]: the script name.
6387 DECL_ACCESSORS(name, Object)
6388
6389 // [id]: the script id.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006390 DECL_INT_ACCESSORS(id)
Steve Blocka7e24c12009-10-30 11:49:00 +00006391
6392 // [line_offset]: script line offset in resource from where it was extracted.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006393 DECL_INT_ACCESSORS(line_offset)
Steve Blocka7e24c12009-10-30 11:49:00 +00006394
6395 // [column_offset]: script column offset in resource from where it was
6396 // extracted.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006397 DECL_INT_ACCESSORS(column_offset)
Steve Blocka7e24c12009-10-30 11:49:00 +00006398
Steve Blocka7e24c12009-10-30 11:49:00 +00006399 // [context_data]: context data for the context this script was compiled in.
6400 DECL_ACCESSORS(context_data, Object)
6401
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006402 // [wrapper]: the wrapper cache. This is either undefined or a WeakCell.
6403 DECL_ACCESSORS(wrapper, HeapObject)
Steve Blocka7e24c12009-10-30 11:49:00 +00006404
6405 // [type]: the script type.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006406 DECL_INT_ACCESSORS(type)
Steve Blocka7e24c12009-10-30 11:49:00 +00006407
Steve Blockd0582a62009-12-15 09:54:21 +00006408 // [line_ends]: FixedArray of line ends positions.
Steve Blocka7e24c12009-10-30 11:49:00 +00006409 DECL_ACCESSORS(line_ends, Object)
6410
Ben Murdoch097c5b22016-05-18 11:27:45 +01006411 // [eval_from_shared]: for eval scripts the shared function info for the
Steve Blockd0582a62009-12-15 09:54:21 +00006412 // function from which eval was called.
6413 DECL_ACCESSORS(eval_from_shared, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +00006414
6415 // [eval_from_instructions_offset]: the instruction offset in the code for the
6416 // function from which eval was called where eval was called.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006417 DECL_INT_ACCESSORS(eval_from_instructions_offset)
6418
6419 // [shared_function_infos]: weak fixed array containing all shared
6420 // function infos created from this script.
6421 DECL_ACCESSORS(shared_function_infos, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +00006422
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006423 // [flags]: Holds an exciting bitfield.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006424 DECL_INT_ACCESSORS(flags)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006425
6426 // [source_url]: sourceURL from magic comment
6427 DECL_ACCESSORS(source_url, Object)
6428
6429 // [source_url]: sourceMappingURL magic comment
6430 DECL_ACCESSORS(source_mapping_url, Object)
6431
6432 // [compilation_type]: how the the script was compiled. Encoded in the
6433 // 'flags' field.
6434 inline CompilationType compilation_type();
6435 inline void set_compilation_type(CompilationType type);
6436
6437 // [compilation_state]: determines whether the script has already been
6438 // compiled. Encoded in the 'flags' field.
6439 inline CompilationState compilation_state();
6440 inline void set_compilation_state(CompilationState state);
6441
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006442 // [hide_source]: determines whether the script source can be exposed as
6443 // function source. Encoded in the 'flags' field.
6444 inline bool hide_source();
6445 inline void set_hide_source(bool value);
6446
6447 // [origin_options]: optional attributes set by the embedder via ScriptOrigin,
6448 // and used by the embedder to make decisions about the script. V8 just passes
6449 // this through. Encoded in the 'flags' field.
6450 inline v8::ScriptOriginOptions origin_options();
6451 inline void set_origin_options(ScriptOriginOptions origin_options);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006452
6453 DECLARE_CAST(Script)
Steve Blocka7e24c12009-10-30 11:49:00 +00006454
Steve Block3ce2e202009-11-05 08:53:23 +00006455 // If script source is an external string, check that the underlying
6456 // resource is accessible. Otherwise, always return true.
6457 inline bool HasValidSource();
6458
Ben Murdoch097c5b22016-05-18 11:27:45 +01006459 // Convert code offset into column number.
6460 static int GetColumnNumber(Handle<Script> script, int code_offset);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006461
Ben Murdoch097c5b22016-05-18 11:27:45 +01006462 // Convert code offset into (zero-based) line number.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006463 // The non-handlified version does not allocate, but may be much slower.
Ben Murdoch097c5b22016-05-18 11:27:45 +01006464 static int GetLineNumber(Handle<Script> script, int code_offset);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006465 int GetLineNumber(int code_pos);
6466
6467 static Handle<Object> GetNameOrSourceURL(Handle<Script> script);
6468
Ben Murdoch097c5b22016-05-18 11:27:45 +01006469 // Init line_ends array with source code positions of line ends.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006470 static void InitLineEnds(Handle<Script> script);
6471
6472 // Get the JS object wrapping the given script; create it if none exists.
6473 static Handle<JSObject> GetWrapper(Handle<Script> script);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006474
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006475 // Look through the list of existing shared function infos to find one
6476 // that matches the function literal. Return empty handle if not found.
6477 MaybeHandle<SharedFunctionInfo> FindSharedFunctionInfo(FunctionLiteral* fun);
6478
6479 // Iterate over all script objects on the heap.
6480 class Iterator {
6481 public:
6482 explicit Iterator(Isolate* isolate);
6483 Script* Next();
6484
6485 private:
6486 WeakFixedArray::Iterator iterator_;
6487 DISALLOW_COPY_AND_ASSIGN(Iterator);
6488 };
6489
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006490 // Dispatched behavior.
6491 DECLARE_PRINTER(Script)
6492 DECLARE_VERIFIER(Script)
Steve Blocka7e24c12009-10-30 11:49:00 +00006493
6494 static const int kSourceOffset = HeapObject::kHeaderSize;
6495 static const int kNameOffset = kSourceOffset + kPointerSize;
6496 static const int kLineOffsetOffset = kNameOffset + kPointerSize;
6497 static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006498 static const int kContextOffset = kColumnOffsetOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00006499 static const int kWrapperOffset = kContextOffset + kPointerSize;
6500 static const int kTypeOffset = kWrapperOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006501 static const int kLineEndsOffset = kTypeOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00006502 static const int kIdOffset = kLineEndsOffset + kPointerSize;
Steve Blockd0582a62009-12-15 09:54:21 +00006503 static const int kEvalFromSharedOffset = kIdOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00006504 static const int kEvalFrominstructionsOffsetOffset =
Steve Blockd0582a62009-12-15 09:54:21 +00006505 kEvalFromSharedOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006506 static const int kSharedFunctionInfosOffset =
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006507 kEvalFrominstructionsOffsetOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006508 static const int kFlagsOffset = kSharedFunctionInfosOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006509 static const int kSourceUrlOffset = kFlagsOffset + kPointerSize;
6510 static const int kSourceMappingUrlOffset = kSourceUrlOffset + kPointerSize;
6511 static const int kSize = kSourceMappingUrlOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00006512
6513 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006514 int GetLineNumberWithArray(int code_pos);
6515
6516 // Bit positions in the flags field.
6517 static const int kCompilationTypeBit = 0;
6518 static const int kCompilationStateBit = 1;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006519 static const int kHideSourceBit = 2;
6520 static const int kOriginOptionsShift = 3;
6521 static const int kOriginOptionsSize = 3;
6522 static const int kOriginOptionsMask = ((1 << kOriginOptionsSize) - 1)
6523 << kOriginOptionsShift;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006524
Steve Blocka7e24c12009-10-30 11:49:00 +00006525 DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
6526};
6527
6528
Ben Murdochb0fe1622011-05-05 13:52:32 +01006529// List of builtin functions we want to identify to improve code
6530// generation.
6531//
6532// Each entry has a name of a global object property holding an object
6533// optionally followed by ".prototype", a name of a builtin function
6534// on the object (the one the id is set for), and a label.
6535//
6536// Installation of ids for the selected builtin functions is handled
6537// by the bootstrapper.
Ben Murdoch097c5b22016-05-18 11:27:45 +01006538#define FUNCTIONS_WITH_ID_LIST(V) \
6539 V(Array.prototype, indexOf, ArrayIndexOf) \
6540 V(Array.prototype, lastIndexOf, ArrayLastIndexOf) \
6541 V(Array.prototype, push, ArrayPush) \
6542 V(Array.prototype, pop, ArrayPop) \
6543 V(Array.prototype, shift, ArrayShift) \
6544 V(Function.prototype, apply, FunctionApply) \
6545 V(Function.prototype, call, FunctionCall) \
6546 V(String.prototype, charCodeAt, StringCharCodeAt) \
6547 V(String.prototype, charAt, StringCharAt) \
6548 V(String.prototype, concat, StringConcat) \
6549 V(String.prototype, toLowerCase, StringToLowerCase) \
6550 V(String.prototype, toUpperCase, StringToUpperCase) \
6551 V(String, fromCharCode, StringFromCharCode) \
6552 V(Math, random, MathRandom) \
6553 V(Math, floor, MathFloor) \
6554 V(Math, round, MathRound) \
6555 V(Math, ceil, MathCeil) \
6556 V(Math, abs, MathAbs) \
6557 V(Math, log, MathLog) \
6558 V(Math, exp, MathExp) \
6559 V(Math, sqrt, MathSqrt) \
6560 V(Math, pow, MathPow) \
6561 V(Math, max, MathMax) \
6562 V(Math, min, MathMin) \
6563 V(Math, cos, MathCos) \
6564 V(Math, sin, MathSin) \
6565 V(Math, tan, MathTan) \
6566 V(Math, acos, MathAcos) \
6567 V(Math, asin, MathAsin) \
6568 V(Math, atan, MathAtan) \
6569 V(Math, atan2, MathAtan2) \
6570 V(Math, imul, MathImul) \
6571 V(Math, clz32, MathClz32) \
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006572 V(Math, fround, MathFround)
Ben Murdochb0fe1622011-05-05 13:52:32 +01006573
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006574#define ATOMIC_FUNCTIONS_WITH_ID_LIST(V) \
6575 V(Atomics, load, AtomicsLoad) \
6576 V(Atomics, store, AtomicsStore)
6577
Ben Murdochb0fe1622011-05-05 13:52:32 +01006578enum BuiltinFunctionId {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006579 kArrayCode,
Ben Murdochb0fe1622011-05-05 13:52:32 +01006580#define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \
6581 k##name,
6582 FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006583 ATOMIC_FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID)
Ben Murdochb0fe1622011-05-05 13:52:32 +01006584#undef DECLARE_FUNCTION_ID
6585 // Fake id for a special case of Math.pow. Note, it continues the
6586 // list of math functions.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006587 kMathPowHalf
Ben Murdochb0fe1622011-05-05 13:52:32 +01006588};
6589
6590
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006591// Result of searching in an optimized code map of a SharedFunctionInfo. Note
6592// that both {code} and {literals} can be NULL to pass search result status.
6593struct CodeAndLiterals {
6594 Code* code; // Cached optimized code.
6595 LiteralsArray* literals; // Cached literals array.
6596};
6597
6598
Steve Blocka7e24c12009-10-30 11:49:00 +00006599// SharedFunctionInfo describes the JSFunction information that can be
6600// shared by multiple instances of the function.
6601class SharedFunctionInfo: public HeapObject {
6602 public:
6603 // [name]: Function name.
6604 DECL_ACCESSORS(name, Object)
6605
6606 // [code]: Function code.
6607 DECL_ACCESSORS(code, Code)
Ben Murdoch097c5b22016-05-18 11:27:45 +01006608
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006609 inline void ReplaceCode(Code* code);
6610
6611 // [optimized_code_map]: Map from native context to optimized code
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006612 // and a shared literals array.
6613 DECL_ACCESSORS(optimized_code_map, FixedArray)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006614
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006615 // Returns entry from optimized code map for specified context and OSR entry.
6616 // Note that {code == nullptr, literals == nullptr} indicates no matching
6617 // entry has been found, whereas {code, literals == nullptr} indicates that
6618 // code is context-independent.
6619 CodeAndLiterals SearchOptimizedCodeMap(Context* native_context,
6620 BailoutId osr_ast_id);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006621
6622 // Clear optimized code map.
6623 void ClearOptimizedCodeMap();
6624
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006625 // We have a special root FixedArray with the right shape and values
6626 // to represent the cleared optimized code map. This predicate checks
6627 // if that root is installed.
6628 inline bool OptimizedCodeMapIsCleared() const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006629
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006630 // Removes a specific optimized code object from the optimized code map.
6631 // In case of non-OSR the code reference is cleared from the cache entry but
6632 // the entry itself is left in the map in order to proceed sharing literals.
6633 void EvictFromOptimizedCodeMap(Code* optimized_code, const char* reason);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006634
6635 // Trims the optimized code map after entries have been removed.
6636 void TrimOptimizedCodeMap(int shrink_by);
6637
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006638 // Add a new entry to the optimized code map for context-independent code.
6639 static void AddSharedCodeToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
6640 Handle<Code> code);
6641
6642 // Add a new entry to the optimized code map for context-dependent code.
6643 inline static void AddToOptimizedCodeMap(Handle<SharedFunctionInfo> shared,
6644 Handle<Context> native_context,
6645 Handle<Code> code,
6646 Handle<LiteralsArray> literals,
6647 BailoutId osr_ast_id);
6648
6649 // We may already have cached the code, but want to store literals in the
6650 // cache.
6651 inline static void AddLiteralsToOptimizedCodeMap(
6652 Handle<SharedFunctionInfo> shared, Handle<Context> native_context,
6653 Handle<LiteralsArray> literals);
6654
6655 // Set up the link between shared function info and the script. The shared
6656 // function info is added to the list on the script.
6657 static void SetScript(Handle<SharedFunctionInfo> shared,
6658 Handle<Object> script_object);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006659
6660 // Layout description of the optimized code map.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006661 static const int kSharedCodeIndex = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006662 static const int kEntriesStart = 1;
6663 static const int kContextOffset = 0;
6664 static const int kCachedCodeOffset = 1;
6665 static const int kLiteralsOffset = 2;
6666 static const int kOsrAstIdOffset = 3;
6667 static const int kEntryLength = 4;
6668 static const int kInitialLength = kEntriesStart + kEntryLength;
Steve Blocka7e24c12009-10-30 11:49:00 +00006669
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006670 static const int kNotFound = -1;
6671
Ben Murdoch3bec4d22010-07-22 14:51:16 +01006672 // [scope_info]: Scope info.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006673 DECL_ACCESSORS(scope_info, ScopeInfo)
Ben Murdoch3bec4d22010-07-22 14:51:16 +01006674
Steve Blocka7e24c12009-10-30 11:49:00 +00006675 // [construct stub]: Code stub for constructing instances of this function.
6676 DECL_ACCESSORS(construct_stub, Code)
6677
6678 // Returns if this function has been compiled to native code yet.
6679 inline bool is_compiled();
6680
6681 // [length]: The function length - usually the number of declared parameters.
6682 // Use up to 2^30 parameters.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006683 inline int length() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00006684 inline void set_length(int value);
6685
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006686 // [internal formal parameter count]: The declared number of parameters.
6687 // For subclass constructors, also includes new.target.
6688 // The size of function's frame is internal_formal_parameter_count + 1.
6689 inline int internal_formal_parameter_count() const;
6690 inline void set_internal_formal_parameter_count(int value);
Steve Blocka7e24c12009-10-30 11:49:00 +00006691
6692 // Set the formal parameter count so the function code will be
6693 // called without using argument adaptor frames.
6694 inline void DontAdaptArguments();
6695
6696 // [expected_nof_properties]: Expected number of properties for the function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006697 inline int expected_nof_properties() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00006698 inline void set_expected_nof_properties(int value);
6699
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006700 // [feedback_vector] - accumulates ast node feedback from full-codegen and
6701 // (increasingly) from crankshafted code where sufficient feedback isn't
6702 // available.
6703 DECL_ACCESSORS(feedback_vector, TypeFeedbackVector)
Kristian Monsen0d5e1162010-09-30 15:31:59 +01006704
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006705 // Unconditionally clear the type feedback vector (including vector ICs).
6706 void ClearTypeFeedbackInfo();
6707
6708 // Clear the type feedback vector with a more subtle policy at GC time.
6709 void ClearTypeFeedbackInfoAtGCTime();
6710
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006711#if TRACE_MAPS
6712 // [unique_id] - For --trace-maps purposes, an identifier that's persistent
6713 // even if the GC moves this SharedFunctionInfo.
6714 inline int unique_id() const;
6715 inline void set_unique_id(int value);
6716#endif
6717
Steve Blocka7e24c12009-10-30 11:49:00 +00006718 // [instance class name]: class name for instances.
6719 DECL_ACCESSORS(instance_class_name, Object)
6720
Steve Block6ded16b2010-05-10 14:33:55 +01006721 // [function data]: This field holds some additional data for function.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006722 // Currently it has one of:
6723 // - a FunctionTemplateInfo to make benefit the API [IsApiFunction()].
6724 // - a Smi identifying a builtin function [HasBuiltinFunctionId()].
6725 // - a BytecodeArray for the interpreter [HasBytecodeArray()].
Steve Blocka7e24c12009-10-30 11:49:00 +00006726 // In the long run we don't want all functions to have this field but
6727 // we can fix that when we have a better model for storing hidden data
6728 // on objects.
6729 DECL_ACCESSORS(function_data, Object)
6730
Steve Block6ded16b2010-05-10 14:33:55 +01006731 inline bool IsApiFunction();
6732 inline FunctionTemplateInfo* get_api_func_data();
Ben Murdochb0fe1622011-05-05 13:52:32 +01006733 inline bool HasBuiltinFunctionId();
Ben Murdochb0fe1622011-05-05 13:52:32 +01006734 inline BuiltinFunctionId builtin_function_id();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006735 inline bool HasBytecodeArray();
6736 inline BytecodeArray* bytecode_array();
Steve Block6ded16b2010-05-10 14:33:55 +01006737
Steve Blocka7e24c12009-10-30 11:49:00 +00006738 // [script info]: Script from which the function originates.
6739 DECL_ACCESSORS(script, Object)
6740
Steve Block6ded16b2010-05-10 14:33:55 +01006741 // [num_literals]: Number of literals used by this function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006742 inline int num_literals() const;
Steve Block6ded16b2010-05-10 14:33:55 +01006743 inline void set_num_literals(int value);
6744
Steve Blocka7e24c12009-10-30 11:49:00 +00006745 // [start_position_and_type]: Field used to store both the source code
6746 // position, whether or not the function is a function expression,
6747 // and whether or not the function is a toplevel function. The two
6748 // least significants bit indicates whether the function is an
6749 // expression and the rest contains the source code position.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006750 inline int start_position_and_type() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00006751 inline void set_start_position_and_type(int value);
6752
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006753 // The function is subject to debugging if a debug info is attached.
6754 inline bool HasDebugInfo();
6755 inline DebugInfo* GetDebugInfo();
6756
6757 // A function has debug code if the compiled code has debug break slots.
6758 inline bool HasDebugCode();
6759
Steve Blocka7e24c12009-10-30 11:49:00 +00006760 // [debug info]: Debug information.
6761 DECL_ACCESSORS(debug_info, Object)
6762
6763 // [inferred name]: Name inferred from variable or property
6764 // assignment of this function. Used to facilitate debugging and
6765 // profiling of JavaScript code written in OO style, where almost
6766 // all functions are anonymous but are assigned to object
6767 // properties.
6768 DECL_ACCESSORS(inferred_name, String)
6769
Ben Murdochf87a2032010-10-22 12:50:53 +01006770 // The function's name if it is non-empty, otherwise the inferred name.
6771 String* DebugName();
6772
Steve Blocka7e24c12009-10-30 11:49:00 +00006773 // Position of the 'function' token in the script source.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006774 inline int function_token_position() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00006775 inline void set_function_token_position(int function_token_position);
6776
6777 // Position of this function in the script source.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006778 inline int start_position() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00006779 inline void set_start_position(int start_position);
6780
6781 // End position of this function in the script source.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006782 inline int end_position() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00006783 inline void set_end_position(int end_position);
6784
Ben Murdoch097c5b22016-05-18 11:27:45 +01006785 // Is this function a named function expression in the source code.
6786 DECL_BOOLEAN_ACCESSORS(is_named_expression)
Steve Blocka7e24c12009-10-30 11:49:00 +00006787
6788 // Is this function a top-level function (scripts, evals).
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006789 DECL_BOOLEAN_ACCESSORS(is_toplevel)
Steve Blocka7e24c12009-10-30 11:49:00 +00006790
6791 // Bit field containing various information collected by the compiler to
6792 // drive optimization.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006793 inline int compiler_hints() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00006794 inline void set_compiler_hints(int value);
6795
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006796 inline int ast_node_count() const;
Ben Murdoch8f9999f2012-04-23 10:39:17 +01006797 inline void set_ast_node_count(int count);
6798
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006799 inline int profiler_ticks() const;
6800 inline void set_profiler_ticks(int ticks);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006801
Ben Murdoch8f9999f2012-04-23 10:39:17 +01006802 // Inline cache age is used to infer whether the function survived a context
6803 // disposal or not. In the former case we reset the opt_count.
6804 inline int ic_age();
6805 inline void set_ic_age(int age);
Ben Murdochb0fe1622011-05-05 13:52:32 +01006806
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01006807 // Indicates if this function can be lazy compiled.
6808 // This is used to determine if we can safely flush code from a function
6809 // when doing GC if we expect that the function will no longer be used.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006810 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation)
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01006811
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006812 // Indicates if this function can be lazy compiled without a context.
6813 // This is used to determine if we can force compilation without reaching
6814 // the function through program execution but through other means (e.g. heap
6815 // iteration by the debugger).
6816 DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation_without_context)
Iain Merrick75681382010-08-19 15:07:18 +01006817
Ben Murdochb0fe1622011-05-05 13:52:32 +01006818 // Indicates whether optimizations have been disabled for this
6819 // shared function info. If a function is repeatedly optimized or if
6820 // we cannot optimize the function we disable optimization to avoid
6821 // spending time attempting to optimize it again.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006822 DECL_BOOLEAN_ACCESSORS(optimization_disabled)
Ben Murdochb0fe1622011-05-05 13:52:32 +01006823
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006824 // Indicates the language mode.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006825 inline LanguageMode language_mode();
6826 inline void set_language_mode(LanguageMode language_mode);
Steve Block1e0659c2011-05-24 12:43:12 +01006827
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006828 // False if the function definitely does not allocate an arguments object.
6829 DECL_BOOLEAN_ACCESSORS(uses_arguments)
6830
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006831 // Indicates that this function uses a super property (or an eval that may
6832 // use a super property).
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006833 // This is needed to set up the [[HomeObject]] on the function instance.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006834 DECL_BOOLEAN_ACCESSORS(needs_home_object)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006835
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006836 // True if the function has any duplicated parameter names.
6837 DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
6838
6839 // Indicates whether the function is a native function.
Ben Murdoch589d6972011-11-30 16:04:58 +00006840 // These needs special treatment in .call and .apply since
Ben Murdoch257744e2011-11-30 15:57:28 +00006841 // null passed as the receiver should not be translated to the
6842 // global object.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006843 DECL_BOOLEAN_ACCESSORS(native)
6844
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006845 // Indicate that this function should always be inlined in optimized code.
6846 DECL_BOOLEAN_ACCESSORS(force_inline)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006847
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00006848 // Indicates that the function was created by the Function function.
6849 // Though it's anonymous, toString should treat it as if it had the name
6850 // "anonymous". We don't set the name itself so that the system does not
6851 // see a binding for it.
6852 DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous)
6853
Ben Murdoch097c5b22016-05-18 11:27:45 +01006854 // Indicates that the function is either an anonymous expression
6855 // or an arrow function (the name field can be set through the API,
6856 // which does not change this flag).
6857 DECL_BOOLEAN_ACCESSORS(is_anonymous_expression)
Ben Murdoch257744e2011-11-30 15:57:28 +00006858
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006859 // Is this a function or top-level/eval code.
6860 DECL_BOOLEAN_ACCESSORS(is_function)
6861
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006862 // Indicates that code for this function cannot be compiled with Crankshaft.
6863 DECL_BOOLEAN_ACCESSORS(dont_crankshaft)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006864
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006865 // Indicates that code for this function cannot be flushed.
6866 DECL_BOOLEAN_ACCESSORS(dont_flush)
6867
6868 // Indicates that this function is a generator.
6869 DECL_BOOLEAN_ACCESSORS(is_generator)
6870
6871 // Indicates that this function is an arrow function.
6872 DECL_BOOLEAN_ACCESSORS(is_arrow)
6873
6874 // Indicates that this function is a concise method.
6875 DECL_BOOLEAN_ACCESSORS(is_concise_method)
6876
Ben Murdoch097c5b22016-05-18 11:27:45 +01006877 // Indicates that this function is a getter.
6878 DECL_BOOLEAN_ACCESSORS(is_getter_function)
6879
6880 // Indicates that this function is a setter.
6881 DECL_BOOLEAN_ACCESSORS(is_setter_function)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006882
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006883 // Indicates that this function is a default constructor.
6884 DECL_BOOLEAN_ACCESSORS(is_default_constructor)
6885
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006886 // Indicates that this function is an asm function.
6887 DECL_BOOLEAN_ACCESSORS(asm_function)
6888
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006889 // Indicates that the the shared function info is deserialized from cache.
6890 DECL_BOOLEAN_ACCESSORS(deserialized)
6891
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006892 // Indicates that the the shared function info has never been compiled before.
6893 DECL_BOOLEAN_ACCESSORS(never_compiled)
6894
Ben Murdoch097c5b22016-05-18 11:27:45 +01006895 // Whether this function was created from a FunctionDeclaration.
6896 DECL_BOOLEAN_ACCESSORS(is_declaration)
6897
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006898 inline FunctionKind kind();
6899 inline void set_kind(FunctionKind kind);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006900
Ben Murdochb0fe1622011-05-05 13:52:32 +01006901 // Indicates whether or not the code in the shared function support
6902 // deoptimization.
6903 inline bool has_deoptimization_support();
6904
6905 // Enable deoptimization support through recompiled code.
6906 void EnableDeoptimizationSupport(Code* recompiled);
6907
Ben Murdoch257744e2011-11-30 15:57:28 +00006908 // Disable (further) attempted optimization of all functions sharing this
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006909 // shared function info.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006910 void DisableOptimization(BailoutReason reason);
Ben Murdoch257744e2011-11-30 15:57:28 +00006911
Emily Bernierd0a1eb72015-03-24 16:35:39 -04006912 inline BailoutReason disable_optimization_reason();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006913
6914 // Lookup the bailout ID and DCHECK that it exists in the non-optimized
Ben Murdochb0fe1622011-05-05 13:52:32 +01006915 // code, returns whether it asserted (i.e., always true if assertions are
6916 // disabled).
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006917 bool VerifyBailoutId(BailoutId id);
Steve Blocka7e24c12009-10-30 11:49:00 +00006918
6919 // [source code]: Source code for the function.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006920 bool HasSourceCode() const;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01006921 Handle<Object> GetSourceCode();
Steve Blocka7e24c12009-10-30 11:49:00 +00006922
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006923 // Number of times the function was optimized.
Ben Murdochb0fe1622011-05-05 13:52:32 +01006924 inline int opt_count();
6925 inline void set_opt_count(int opt_count);
6926
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006927 // Number of times the function was deoptimized.
6928 inline void set_deopt_count(int value);
6929 inline int deopt_count();
6930 inline void increment_deopt_count();
6931
6932 // Number of time we tried to re-enable optimization after it
6933 // was disabled due to high number of deoptimizations.
6934 inline void set_opt_reenable_tries(int value);
6935 inline int opt_reenable_tries();
6936
6937 inline void TryReenableOptimization();
6938
6939 // Stores deopt_count, opt_reenable_tries and ic_age as bit-fields.
6940 inline void set_counters(int value);
6941 inline int counters() const;
6942
6943 // Stores opt_count and bailout_reason as bit-fields.
6944 inline void set_opt_count_and_bailout_reason(int value);
6945 inline int opt_count_and_bailout_reason() const;
6946
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006947 inline void set_disable_optimization_reason(BailoutReason reason);
6948
6949 // Tells whether this function should be subject to debugging.
6950 inline bool IsSubjectToDebugging();
6951
6952 // Whether this function is defined in native code or extensions.
6953 inline bool IsBuiltin();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006954
6955 // Check whether or not this function is inlineable.
6956 bool IsInlineable();
6957
Ben Murdochb0fe1622011-05-05 13:52:32 +01006958 // Source size of this function.
6959 int SourceSize();
6960
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006961 // Returns `false` if formal parameters include rest parameters, optional
6962 // parameters, or destructuring parameters.
6963 // TODO(caitp): make this a flag set during parsing
6964 inline bool has_simple_parameters();
Steve Blocka7e24c12009-10-30 11:49:00 +00006965
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006966 // Initialize a SharedFunctionInfo from a parsed function literal.
6967 static void InitFromFunctionLiteral(Handle<SharedFunctionInfo> shared_info,
6968 FunctionLiteral* lit);
Steve Blocka7e24c12009-10-30 11:49:00 +00006969
6970 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006971 DECLARE_PRINTER(SharedFunctionInfo)
6972 DECLARE_VERIFIER(SharedFunctionInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +00006973
Ben Murdoch8f9999f2012-04-23 10:39:17 +01006974 void ResetForNewContext(int new_ic_age);
6975
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00006976 // Iterate over all shared function infos.
6977 class Iterator {
6978 public:
6979 explicit Iterator(Isolate* isolate);
6980 SharedFunctionInfo* Next();
6981
6982 private:
6983 bool NextScript();
6984
6985 Script::Iterator script_iterator_;
6986 WeakFixedArray::Iterator sfi_iterator_;
6987 DisallowHeapAllocation no_gc_;
6988 DISALLOW_COPY_AND_ASSIGN(Iterator);
6989 };
6990
Ben Murdochb8a8cc12014-11-26 15:28:44 +00006991 DECLARE_CAST(SharedFunctionInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +00006992
6993 // Constants.
6994 static const int kDontAdaptArgumentsSentinel = -1;
6995
6996 // Layout description.
Steve Block6ded16b2010-05-10 14:33:55 +01006997 // Pointer fields.
Steve Blocka7e24c12009-10-30 11:49:00 +00006998 static const int kNameOffset = HeapObject::kHeaderSize;
6999 static const int kCodeOffset = kNameOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007000 static const int kOptimizedCodeMapOffset = kCodeOffset + kPointerSize;
7001 static const int kScopeInfoOffset = kOptimizedCodeMapOffset + kPointerSize;
Ben Murdoch3bec4d22010-07-22 14:51:16 +01007002 static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize;
Steve Block6ded16b2010-05-10 14:33:55 +01007003 static const int kInstanceClassNameOffset =
7004 kConstructStubOffset + kPointerSize;
7005 static const int kFunctionDataOffset =
7006 kInstanceClassNameOffset + kPointerSize;
7007 static const int kScriptOffset = kFunctionDataOffset + kPointerSize;
7008 static const int kDebugInfoOffset = kScriptOffset + kPointerSize;
7009 static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007010 static const int kFeedbackVectorOffset =
Steve Block6ded16b2010-05-10 14:33:55 +01007011 kInferredNameOffset + kPointerSize;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007012#if TRACE_MAPS
7013 static const int kUniqueIdOffset = kFeedbackVectorOffset + kPointerSize;
7014 static const int kLastPointerFieldOffset = kUniqueIdOffset;
7015#else
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007016 // Just to not break the postmortrem support with conditional offsets
7017 static const int kUniqueIdOffset = kFeedbackVectorOffset;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007018 static const int kLastPointerFieldOffset = kFeedbackVectorOffset;
7019#endif
7020
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007021#if V8_HOST_ARCH_32_BIT
7022 // Smi fields.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007023 static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007024 static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize;
7025 static const int kExpectedNofPropertiesOffset =
7026 kFormalParameterCountOffset + kPointerSize;
7027 static const int kNumLiteralsOffset =
7028 kExpectedNofPropertiesOffset + kPointerSize;
7029 static const int kStartPositionAndTypeOffset =
7030 kNumLiteralsOffset + kPointerSize;
7031 static const int kEndPositionOffset =
7032 kStartPositionAndTypeOffset + kPointerSize;
7033 static const int kFunctionTokenPositionOffset =
7034 kEndPositionOffset + kPointerSize;
7035 static const int kCompilerHintsOffset =
7036 kFunctionTokenPositionOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007037 static const int kOptCountAndBailoutReasonOffset =
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007038 kCompilerHintsOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007039 static const int kCountersOffset =
7040 kOptCountAndBailoutReasonOffset + kPointerSize;
7041 static const int kAstNodeCountOffset =
7042 kCountersOffset + kPointerSize;
7043 static const int kProfilerTicksOffset =
7044 kAstNodeCountOffset + kPointerSize;
Ben Murdoch8f9999f2012-04-23 10:39:17 +01007045
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007046 // Total size.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007047 static const int kSize = kProfilerTicksOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007048#else
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007049// The only reason to use smi fields instead of int fields is to allow
7050// iteration without maps decoding during garbage collections.
7051// To avoid wasting space on 64-bit architectures we use the following trick:
7052// we group integer fields into pairs
7053// The least significant integer in each pair is shifted left by 1. By doing
7054// this we guarantee that LSB of each kPointerSize aligned word is not set and
7055// thus this word cannot be treated as pointer to HeapObject during old space
7056// traversal.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007057#if V8_TARGET_LITTLE_ENDIAN
7058 static const int kLengthOffset = kLastPointerFieldOffset + kPointerSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007059 static const int kFormalParameterCountOffset =
7060 kLengthOffset + kIntSize;
7061
Steve Blocka7e24c12009-10-30 11:49:00 +00007062 static const int kExpectedNofPropertiesOffset =
7063 kFormalParameterCountOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007064 static const int kNumLiteralsOffset =
7065 kExpectedNofPropertiesOffset + kIntSize;
7066
7067 static const int kEndPositionOffset =
Steve Block6ded16b2010-05-10 14:33:55 +01007068 kNumLiteralsOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007069 static const int kStartPositionAndTypeOffset =
7070 kEndPositionOffset + kIntSize;
7071
7072 static const int kFunctionTokenPositionOffset =
7073 kStartPositionAndTypeOffset + kIntSize;
Steve Block6ded16b2010-05-10 14:33:55 +01007074 static const int kCompilerHintsOffset =
Steve Blocka7e24c12009-10-30 11:49:00 +00007075 kFunctionTokenPositionOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007076
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007077 static const int kOptCountAndBailoutReasonOffset =
Steve Block6ded16b2010-05-10 14:33:55 +01007078 kCompilerHintsOffset + kIntSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007079 static const int kCountersOffset =
7080 kOptCountAndBailoutReasonOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007081
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007082 static const int kAstNodeCountOffset =
7083 kCountersOffset + kIntSize;
7084 static const int kProfilerTicksOffset =
7085 kAstNodeCountOffset + kIntSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007086
Steve Block6ded16b2010-05-10 14:33:55 +01007087 // Total size.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007088 static const int kSize = kProfilerTicksOffset + kIntSize;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01007089
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007090#elif V8_TARGET_BIG_ENDIAN
7091 static const int kFormalParameterCountOffset =
7092 kLastPointerFieldOffset + kPointerSize;
7093 static const int kLengthOffset = kFormalParameterCountOffset + kIntSize;
7094
7095 static const int kNumLiteralsOffset = kLengthOffset + kIntSize;
7096 static const int kExpectedNofPropertiesOffset = kNumLiteralsOffset + kIntSize;
7097
7098 static const int kStartPositionAndTypeOffset =
7099 kExpectedNofPropertiesOffset + kIntSize;
7100 static const int kEndPositionOffset = kStartPositionAndTypeOffset + kIntSize;
7101
7102 static const int kCompilerHintsOffset = kEndPositionOffset + kIntSize;
7103 static const int kFunctionTokenPositionOffset =
7104 kCompilerHintsOffset + kIntSize;
7105
7106 static const int kCountersOffset = kFunctionTokenPositionOffset + kIntSize;
7107 static const int kOptCountAndBailoutReasonOffset = kCountersOffset + kIntSize;
7108
7109 static const int kProfilerTicksOffset =
7110 kOptCountAndBailoutReasonOffset + kIntSize;
7111 static const int kAstNodeCountOffset = kProfilerTicksOffset + kIntSize;
7112
7113 // Total size.
7114 static const int kSize = kAstNodeCountOffset + kIntSize;
7115
7116#else
7117#error Unknown byte ordering
7118#endif // Big endian
7119#endif // 64-bit
7120
Kristian Monsen0d5e1162010-09-30 15:31:59 +01007121
Steve Block6ded16b2010-05-10 14:33:55 +01007122 static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00007123
Iain Merrick75681382010-08-19 15:07:18 +01007124 typedef FixedBodyDescriptor<kNameOffset,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007125 kLastPointerFieldOffset + kPointerSize,
Iain Merrick75681382010-08-19 15:07:18 +01007126 kSize> BodyDescriptor;
7127
Steve Blocka7e24c12009-10-30 11:49:00 +00007128 // Bit positions in start_position_and_type.
7129 // The source code start position is in the 30 most significant bits of
7130 // the start_position_and_type field.
Ben Murdoch097c5b22016-05-18 11:27:45 +01007131 static const int kIsNamedExpressionBit = 0;
7132 static const int kIsTopLevelBit = 1;
Steve Blocka7e24c12009-10-30 11:49:00 +00007133 static const int kStartPositionShift = 2;
Ben Murdoch097c5b22016-05-18 11:27:45 +01007134 static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
Steve Blocka7e24c12009-10-30 11:49:00 +00007135
7136 // Bit positions in compiler_hints.
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007137 enum CompilerHints {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007138 // byte 0
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007139 kAllowLazyCompilation,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007140 kAllowLazyCompilationWithoutContext,
7141 kOptimizationDisabled,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007142 kNative,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007143 kStrictModeFunction,
7144 kStrongModeFunction,
7145 kUsesArguments,
7146 kNeedsHomeObject,
7147 // byte 1
7148 kHasDuplicateParameters,
7149 kForceInline,
7150 kIsAsmFunction,
Ben Murdoch097c5b22016-05-18 11:27:45 +01007151 kIsAnonymousExpression,
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007152 kNameShouldPrintAsAnonymous,
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007153 kIsFunction,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007154 kDontCrankshaft,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007155 kDontFlush,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007156 // byte 2
7157 kFunctionKind,
7158 kIsArrow = kFunctionKind,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007159 kIsGenerator,
7160 kIsConciseMethod,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007161 kIsDefaultConstructor,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007162 kIsSubclassConstructor,
7163 kIsBaseConstructor,
Ben Murdoch097c5b22016-05-18 11:27:45 +01007164 kIsGetterFunction,
7165 kIsSetterFunction,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007166 // byte 3
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007167 kDeserialized,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007168 kNeverCompiled,
Ben Murdoch097c5b22016-05-18 11:27:45 +01007169 kIsDeclaration,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007170 kCompilerHintsCount, // Pseudo entry
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007171 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007172 // Add hints for other modes when they're added.
7173 STATIC_ASSERT(LANGUAGE_END == 3);
7174 // kFunctionKind has to be byte-aligned
7175 STATIC_ASSERT((kFunctionKind % kBitsPerByte) == 0);
7176// Make sure that FunctionKind and byte 2 are in sync:
7177#define ASSERT_FUNCTION_KIND_ORDER(functionKind, compilerFunctionKind) \
7178 STATIC_ASSERT(FunctionKind::functionKind == \
7179 1 << (compilerFunctionKind - kFunctionKind))
7180 ASSERT_FUNCTION_KIND_ORDER(kArrowFunction, kIsArrow);
7181 ASSERT_FUNCTION_KIND_ORDER(kGeneratorFunction, kIsGenerator);
7182 ASSERT_FUNCTION_KIND_ORDER(kConciseMethod, kIsConciseMethod);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007183 ASSERT_FUNCTION_KIND_ORDER(kDefaultConstructor, kIsDefaultConstructor);
7184 ASSERT_FUNCTION_KIND_ORDER(kSubclassConstructor, kIsSubclassConstructor);
7185 ASSERT_FUNCTION_KIND_ORDER(kBaseConstructor, kIsBaseConstructor);
Ben Murdoch097c5b22016-05-18 11:27:45 +01007186 ASSERT_FUNCTION_KIND_ORDER(kGetterFunction, kIsGetterFunction);
7187 ASSERT_FUNCTION_KIND_ORDER(kSetterFunction, kIsSetterFunction);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007188#undef ASSERT_FUNCTION_KIND_ORDER
Steve Blocka7e24c12009-10-30 11:49:00 +00007189
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007190 class FunctionKindBits : public BitField<FunctionKind, kIsArrow, 8> {};
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007191
7192 class DeoptCountBits : public BitField<int, 0, 4> {};
7193 class OptReenableTriesBits : public BitField<int, 4, 18> {};
7194 class ICAgeBits : public BitField<int, 22, 8> {};
7195
7196 class OptCountBits : public BitField<int, 0, 22> {};
7197 class DisabledOptimizationReasonBits : public BitField<int, 22, 8> {};
7198
Ben Murdoche0cee9b2011-05-25 10:26:03 +01007199 private:
7200#if V8_HOST_ARCH_32_BIT
7201 // On 32 bit platforms, compiler hints is a smi.
7202 static const int kCompilerHintsSmiTagSize = kSmiTagSize;
7203 static const int kCompilerHintsSize = kPointerSize;
7204#else
7205 // On 64 bit platforms, compiler hints is not a smi, see comment above.
7206 static const int kCompilerHintsSmiTagSize = 0;
7207 static const int kCompilerHintsSize = kIntSize;
7208#endif
7209
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007210 STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <=
7211 SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte);
7212
Ben Murdoche0cee9b2011-05-25 10:26:03 +01007213 public:
Ben Murdoch257744e2011-11-30 15:57:28 +00007214 // Constants for optimizing codegen for strict mode function and
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007215 // native tests when using integer-width instructions.
7216 static const int kStrictModeBit =
7217 kStrictModeFunction + kCompilerHintsSmiTagSize;
7218 static const int kStrongModeBit =
7219 kStrongModeFunction + kCompilerHintsSmiTagSize;
7220 static const int kNativeBit = kNative + kCompilerHintsSmiTagSize;
7221
7222 static const int kClassConstructorBits =
7223 FunctionKind::kClassConstructor
7224 << (kFunctionKind + kCompilerHintsSmiTagSize);
7225
7226 // Constants for optimizing codegen for strict mode function and
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00007227 // native tests.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007228 // Allows to use byte-width instructions.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007229 static const int kStrictModeBitWithinByte = kStrictModeBit % kBitsPerByte;
7230 static const int kStrongModeBitWithinByte = kStrongModeBit % kBitsPerByte;
7231 static const int kNativeBitWithinByte = kNativeBit % kBitsPerByte;
Ben Murdoche0cee9b2011-05-25 10:26:03 +01007232
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007233 static const int kClassConstructorBitsWithinByte =
7234 FunctionKind::kClassConstructor << kCompilerHintsSmiTagSize;
7235 STATIC_ASSERT(kClassConstructorBitsWithinByte < (1 << kBitsPerByte));
Ben Murdoch257744e2011-11-30 15:57:28 +00007236
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007237#if defined(V8_TARGET_LITTLE_ENDIAN)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007238#define BYTE_OFFSET(compiler_hint) \
7239 kCompilerHintsOffset + \
7240 (compiler_hint + kCompilerHintsSmiTagSize) / kBitsPerByte
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007241#elif defined(V8_TARGET_BIG_ENDIAN)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007242#define BYTE_OFFSET(compiler_hint) \
7243 kCompilerHintsOffset + (kCompilerHintsSize - 1) - \
7244 ((compiler_hint + kCompilerHintsSmiTagSize) / kBitsPerByte)
Ben Murdoche0cee9b2011-05-25 10:26:03 +01007245#else
7246#error Unknown byte ordering
7247#endif
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007248 static const int kStrictModeByteOffset = BYTE_OFFSET(kStrictModeFunction);
7249 static const int kStrongModeByteOffset = BYTE_OFFSET(kStrongModeFunction);
7250 static const int kNativeByteOffset = BYTE_OFFSET(kNative);
7251 static const int kFunctionKindByteOffset = BYTE_OFFSET(kFunctionKind);
7252#undef BYTE_OFFSET
Ben Murdoche0cee9b2011-05-25 10:26:03 +01007253
7254 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007255 // Returns entry from optimized code map for specified context and OSR entry.
7256 // The result is either kNotFound, kSharedCodeIndex for context-independent
7257 // entry or a start index of the context-dependent entry.
7258 int SearchOptimizedCodeMapEntry(Context* native_context,
7259 BailoutId osr_ast_id);
7260
7261 // If code is undefined, then existing code won't be overwritten.
7262 static void AddToOptimizedCodeMapInternal(Handle<SharedFunctionInfo> shared,
7263 Handle<Context> native_context,
7264 Handle<HeapObject> code,
7265 Handle<LiteralsArray> literals,
7266 BailoutId osr_ast_id);
7267
Steve Blocka7e24c12009-10-30 11:49:00 +00007268 DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo);
7269};
7270
7271
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007272// Printing support.
7273struct SourceCodeOf {
7274 explicit SourceCodeOf(SharedFunctionInfo* v, int max = -1)
7275 : value(v), max_length(max) {}
7276 const SharedFunctionInfo* value;
7277 int max_length;
7278};
7279
7280
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007281std::ostream& operator<<(std::ostream& os, const SourceCodeOf& v);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007282
7283
7284class JSGeneratorObject: public JSObject {
7285 public:
7286 // [function]: The function corresponding to this generator object.
7287 DECL_ACCESSORS(function, JSFunction)
7288
7289 // [context]: The context of the suspended computation.
7290 DECL_ACCESSORS(context, Context)
7291
7292 // [receiver]: The receiver of the suspended computation.
7293 DECL_ACCESSORS(receiver, Object)
7294
Ben Murdoch097c5b22016-05-18 11:27:45 +01007295 // [input]: The most recent input value.
7296 DECL_ACCESSORS(input, Object)
7297
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007298 // [continuation]: Offset into code of continuation.
7299 //
7300 // A positive offset indicates a suspended generator. The special
7301 // kGeneratorExecuting and kGeneratorClosed values indicate that a generator
7302 // cannot be resumed.
7303 inline int continuation() const;
7304 inline void set_continuation(int continuation);
7305 inline bool is_closed();
7306 inline bool is_executing();
7307 inline bool is_suspended();
7308
7309 // [operand_stack]: Saved operand stack.
7310 DECL_ACCESSORS(operand_stack, FixedArray)
7311
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007312 DECLARE_CAST(JSGeneratorObject)
7313
7314 // Dispatched behavior.
7315 DECLARE_PRINTER(JSGeneratorObject)
7316 DECLARE_VERIFIER(JSGeneratorObject)
7317
7318 // Magic sentinel values for the continuation.
7319 static const int kGeneratorExecuting = -1;
7320 static const int kGeneratorClosed = 0;
7321
7322 // Layout description.
7323 static const int kFunctionOffset = JSObject::kHeaderSize;
7324 static const int kContextOffset = kFunctionOffset + kPointerSize;
7325 static const int kReceiverOffset = kContextOffset + kPointerSize;
Ben Murdoch097c5b22016-05-18 11:27:45 +01007326 static const int kInputOffset = kReceiverOffset + kPointerSize;
7327 static const int kContinuationOffset = kInputOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007328 static const int kOperandStackOffset = kContinuationOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007329 static const int kSize = kOperandStackOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007330
7331 // Resume mode, for use by runtime functions.
Ben Murdoch097c5b22016-05-18 11:27:45 +01007332 enum ResumeMode { NEXT, RETURN, THROW };
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007333
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007334 private:
7335 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGeneratorObject);
7336};
7337
7338
7339// Representation for module instance objects.
7340class JSModule: public JSObject {
7341 public:
7342 // [context]: the context holding the module's locals, or undefined if none.
7343 DECL_ACCESSORS(context, Object)
7344
7345 // [scope_info]: Scope info.
7346 DECL_ACCESSORS(scope_info, ScopeInfo)
7347
7348 DECLARE_CAST(JSModule)
7349
7350 // Dispatched behavior.
7351 DECLARE_PRINTER(JSModule)
7352 DECLARE_VERIFIER(JSModule)
7353
7354 // Layout description.
7355 static const int kContextOffset = JSObject::kHeaderSize;
7356 static const int kScopeInfoOffset = kContextOffset + kPointerSize;
7357 static const int kSize = kScopeInfoOffset + kPointerSize;
7358
7359 private:
7360 DISALLOW_IMPLICIT_CONSTRUCTORS(JSModule);
7361};
7362
7363
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007364// JSBoundFunction describes a bound function exotic object.
7365class JSBoundFunction : public JSObject {
7366 public:
7367 // [length]: The bound function "length" property.
7368 DECL_ACCESSORS(length, Object)
7369
7370 // [name]: The bound function "name" property.
7371 DECL_ACCESSORS(name, Object)
7372
7373 // [bound_target_function]: The wrapped function object.
7374 DECL_ACCESSORS(bound_target_function, JSReceiver)
7375
7376 // [bound_this]: The value that is always passed as the this value when
7377 // calling the wrapped function.
7378 DECL_ACCESSORS(bound_this, Object)
7379
7380 // [bound_arguments]: A list of values whose elements are used as the first
7381 // arguments to any call to the wrapped function.
7382 DECL_ACCESSORS(bound_arguments, FixedArray)
7383
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007384 static MaybeHandle<Context> GetFunctionRealm(
7385 Handle<JSBoundFunction> function);
7386
7387 DECLARE_CAST(JSBoundFunction)
7388
7389 // Dispatched behavior.
7390 DECLARE_PRINTER(JSBoundFunction)
7391 DECLARE_VERIFIER(JSBoundFunction)
7392
7393 // The bound function's string representation implemented according
7394 // to ES6 section 19.2.3.5 Function.prototype.toString ( ).
7395 static Handle<String> ToString(Handle<JSBoundFunction> function);
7396
7397 // Layout description.
7398 static const int kBoundTargetFunctionOffset = JSObject::kHeaderSize;
7399 static const int kBoundThisOffset = kBoundTargetFunctionOffset + kPointerSize;
7400 static const int kBoundArgumentsOffset = kBoundThisOffset + kPointerSize;
Ben Murdoch097c5b22016-05-18 11:27:45 +01007401 static const int kLengthOffset = kBoundArgumentsOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007402 static const int kNameOffset = kLengthOffset + kPointerSize;
7403 static const int kSize = kNameOffset + kPointerSize;
7404
7405 // Indices of in-object properties.
7406 static const int kLengthIndex = 0;
7407 static const int kNameIndex = 1;
7408
7409 private:
7410 DISALLOW_IMPLICIT_CONSTRUCTORS(JSBoundFunction);
7411};
7412
7413
Steve Blocka7e24c12009-10-30 11:49:00 +00007414// JSFunction describes JavaScript functions.
7415class JSFunction: public JSObject {
7416 public:
7417 // [prototype_or_initial_map]:
7418 DECL_ACCESSORS(prototype_or_initial_map, Object)
7419
Ben Murdoch589d6972011-11-30 16:04:58 +00007420 // [shared]: The information about the function that
Steve Blocka7e24c12009-10-30 11:49:00 +00007421 // can be shared by instances.
7422 DECL_ACCESSORS(shared, SharedFunctionInfo)
7423
7424 // [context]: The context for this function.
7425 inline Context* context();
Steve Blocka7e24c12009-10-30 11:49:00 +00007426 inline void set_context(Object* context);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007427 inline JSObject* global_proxy();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007428 inline Context* native_context();
7429
7430 static Handle<Context> GetFunctionRealm(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +00007431
7432 // [code]: The generated code object for this function. Executed
7433 // when the function is invoked, e.g. foo() or new foo(). See
7434 // [[Call]] and [[Construct]] description in ECMA-262, section
7435 // 8.6.2, page 27.
7436 inline Code* code();
Ben Murdochb0fe1622011-05-05 13:52:32 +01007437 inline void set_code(Code* code);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007438 inline void set_code_no_write_barrier(Code* code);
Ben Murdochb0fe1622011-05-05 13:52:32 +01007439 inline void ReplaceCode(Code* code);
Steve Blocka7e24c12009-10-30 11:49:00 +00007440
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007441 // Tells whether this function inlines the given shared function info.
7442 bool Inlines(SharedFunctionInfo* candidate);
Ben Murdochb0fe1622011-05-05 13:52:32 +01007443
7444 // Tells whether or not this function has been optimized.
7445 inline bool IsOptimized();
7446
7447 // Mark this function for lazy recompilation. The function will be
7448 // recompiled the next time it is executed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007449 void MarkForOptimization();
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007450 void AttemptConcurrentOptimization();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007451
Ben Murdochb0fe1622011-05-05 13:52:32 +01007452 // Tells whether or not the function is already marked for lazy
7453 // recompilation.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007454 inline bool IsMarkedForOptimization();
7455 inline bool IsMarkedForConcurrentOptimization();
Ben Murdochb0fe1622011-05-05 13:52:32 +01007456
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007457 // Tells whether or not the function is on the concurrent recompilation queue.
7458 inline bool IsInOptimizationQueue();
7459
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007460 // Completes inobject slack tracking on initial map if it is active.
7461 inline void CompleteInobjectSlackTrackingIfActive();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007462
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007463 // [literals]: Fixed array holding the materialized literals.
Steve Blocka7e24c12009-10-30 11:49:00 +00007464 //
7465 // If the function contains object, regexp or array literals, the
7466 // literals array prefix contains the object, regexp, and array
7467 // function to be used when creating these literals. This is
7468 // necessary so that we do not dynamically lookup the object, regexp
7469 // or array functions. Performing a dynamic lookup, we might end up
7470 // using the functions from a new context that we should not have
7471 // access to.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007472 DECL_ACCESSORS(literals, LiteralsArray)
Steve Blocka7e24c12009-10-30 11:49:00 +00007473
7474 // The initial map for an object created by this constructor.
7475 inline Map* initial_map();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007476 static void SetInitialMap(Handle<JSFunction> function, Handle<Map> map,
7477 Handle<Object> prototype);
Steve Blocka7e24c12009-10-30 11:49:00 +00007478 inline bool has_initial_map();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007479 static void EnsureHasInitialMap(Handle<JSFunction> function);
Steve Blocka7e24c12009-10-30 11:49:00 +00007480
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007481 // Creates a map that matches the constructor's initial map, but with
7482 // [[prototype]] being new.target.prototype. Because new.target can be a
7483 // JSProxy, this can call back into JavaScript.
7484 static MUST_USE_RESULT MaybeHandle<Map> GetDerivedMap(
7485 Isolate* isolate, Handle<JSFunction> constructor,
7486 Handle<JSReceiver> new_target);
7487
Steve Blocka7e24c12009-10-30 11:49:00 +00007488 // Get and set the prototype property on a JSFunction. If the
7489 // function has an initial map the prototype is set on the initial
7490 // map. Otherwise, the prototype is put in the initial map field
7491 // until an initial map is needed.
7492 inline bool has_prototype();
7493 inline bool has_instance_prototype();
7494 inline Object* prototype();
7495 inline Object* instance_prototype();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007496 static void SetPrototype(Handle<JSFunction> function,
7497 Handle<Object> value);
7498 static void SetInstancePrototype(Handle<JSFunction> function,
7499 Handle<Object> value);
7500
Steve Block6ded16b2010-05-10 14:33:55 +01007501 // After prototype is removed, it will not be created when accessed, and
7502 // [[Construct]] from this function will not be allowed.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007503 bool RemovePrototype();
Steve Blocka7e24c12009-10-30 11:49:00 +00007504
7505 // Returns if this function has been compiled to native code yet.
7506 inline bool is_compiled();
7507
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007508 // [next_function_link]: Links functions into various lists, e.g. the list
7509 // of optimized functions hanging off the native_context. The CodeFlusher
7510 // uses this link to chain together flushing candidates. Treated weakly
7511 // by the garbage collector.
Ben Murdochb0fe1622011-05-05 13:52:32 +01007512 DECL_ACCESSORS(next_function_link, Object)
7513
7514 // Prints the name of the function using PrintF.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007515 void PrintName(FILE* out = stdout);
Ben Murdochb0fe1622011-05-05 13:52:32 +01007516
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007517 DECLARE_CAST(JSFunction)
Steve Blocka7e24c12009-10-30 11:49:00 +00007518
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007519 // Calculate the instance size and in-object properties count.
7520 void CalculateInstanceSize(InstanceType instance_type,
7521 int requested_internal_fields, int* instance_size,
7522 int* in_object_properties);
7523 void CalculateInstanceSizeForDerivedClass(InstanceType instance_type,
7524 int requested_internal_fields,
7525 int* instance_size,
7526 int* in_object_properties);
7527
7528 // Visiting policy flags define whether the code entry or next function
7529 // should be visited or not.
7530 enum BodyVisitingPolicy {
7531 kVisitCodeEntry = 1 << 0,
7532 kVisitNextFunction = 1 << 1,
7533
7534 kSkipCodeEntryAndNextFunction = 0,
7535 kVisitCodeEntryAndNextFunction = kVisitCodeEntry | kVisitNextFunction
7536 };
7537 // Iterates the function object according to the visiting policy.
7538 template <BodyVisitingPolicy>
7539 class BodyDescriptorImpl;
7540
7541 // Visit the whole object.
7542 typedef BodyDescriptorImpl<kVisitCodeEntryAndNextFunction> BodyDescriptor;
7543
7544 // Don't visit next function.
7545 typedef BodyDescriptorImpl<kVisitCodeEntry> BodyDescriptorStrongCode;
7546 typedef BodyDescriptorImpl<kSkipCodeEntryAndNextFunction>
7547 BodyDescriptorWeakCode;
Steve Block791712a2010-08-27 10:21:07 +01007548
Steve Blocka7e24c12009-10-30 11:49:00 +00007549 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007550 DECLARE_PRINTER(JSFunction)
7551 DECLARE_VERIFIER(JSFunction)
Steve Blocka7e24c12009-10-30 11:49:00 +00007552
7553 // Returns the number of allocated literals.
7554 inline int NumberOfLiterals();
7555
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007556 // Used for flags such as --hydrogen-filter.
7557 bool PassesFilter(const char* raw_filter);
Steve Blocka7e24c12009-10-30 11:49:00 +00007558
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007559 // The function's name if it is configured, otherwise shared function info
7560 // debug name.
7561 static Handle<String> GetName(Handle<JSFunction> function);
7562
Ben Murdoch097c5b22016-05-18 11:27:45 +01007563 // ES6 section 9.2.11 SetFunctionName
7564 // Because of the way this abstract operation is used in the spec,
7565 // it should never fail.
7566 static void SetName(Handle<JSFunction> function, Handle<Name> name,
7567 Handle<String> prefix);
7568
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007569 // The function's displayName if it is set, otherwise name if it is
7570 // configured, otherwise shared function info
7571 // debug name.
7572 static Handle<String> GetDebugName(Handle<JSFunction> function);
7573
7574 // The function's string representation implemented according to
7575 // ES6 section 19.2.3.5 Function.prototype.toString ( ).
7576 static Handle<String> ToString(Handle<JSFunction> function);
7577
Ben Murdochb0fe1622011-05-05 13:52:32 +01007578 // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to
7579 // kSize) is weak and has special handling during garbage collection.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007580 static const int kPrototypeOrInitialMapOffset = JSObject::kHeaderSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00007581 static const int kSharedFunctionInfoOffset =
7582 kPrototypeOrInitialMapOffset + kPointerSize;
7583 static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
7584 static const int kLiteralsOffset = kContextOffset + kPointerSize;
Ben Murdochb0fe1622011-05-05 13:52:32 +01007585 static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007586 static const int kCodeEntryOffset = kNonWeakFieldsEndOffset;
7587 static const int kNextFunctionLinkOffset = kCodeEntryOffset + kPointerSize;
Ben Murdochb0fe1622011-05-05 13:52:32 +01007588 static const int kSize = kNextFunctionLinkOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00007589
Steve Blocka7e24c12009-10-30 11:49:00 +00007590 private:
7591 DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
7592};
7593
7594
7595// JSGlobalProxy's prototype must be a JSGlobalObject or null,
7596// and the prototype is hidden. JSGlobalProxy always delegates
7597// property accesses to its prototype if the prototype is not null.
7598//
7599// A JSGlobalProxy can be reinitialized which will preserve its identity.
7600//
7601// Accessing a JSGlobalProxy requires security check.
7602
7603class JSGlobalProxy : public JSObject {
7604 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007605 // [native_context]: the owner native context of this global proxy object.
Steve Blocka7e24c12009-10-30 11:49:00 +00007606 // It is null value if this object is not used by any context.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007607 DECL_ACCESSORS(native_context, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +00007608
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007609 // [hash]: The hash code property (undefined if not initialized yet).
7610 DECL_ACCESSORS(hash, Object)
7611
7612 DECLARE_CAST(JSGlobalProxy)
7613
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007614 inline bool IsDetachedFrom(JSGlobalObject* global) const;
Steve Blocka7e24c12009-10-30 11:49:00 +00007615
7616 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007617 DECLARE_PRINTER(JSGlobalProxy)
7618 DECLARE_VERIFIER(JSGlobalProxy)
Steve Blocka7e24c12009-10-30 11:49:00 +00007619
7620 // Layout description.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007621 static const int kNativeContextOffset = JSObject::kHeaderSize;
7622 static const int kHashOffset = kNativeContextOffset + kPointerSize;
7623 static const int kSize = kHashOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00007624
7625 private:
Steve Blocka7e24c12009-10-30 11:49:00 +00007626 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
7627};
7628
7629
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007630// JavaScript global object.
7631class JSGlobalObject : public JSObject {
Steve Blocka7e24c12009-10-30 11:49:00 +00007632 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007633 // [native context]: the natives corresponding to this global object.
7634 DECL_ACCESSORS(native_context, Context)
7635
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007636 // [global proxy]: the global proxy object of the context
7637 DECL_ACCESSORS(global_proxy, JSObject)
Steve Blocka7e24c12009-10-30 11:49:00 +00007638
Steve Blocka7e24c12009-10-30 11:49:00 +00007639
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007640 static void InvalidatePropertyCell(Handle<JSGlobalObject> object,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04007641 Handle<Name> name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007642 // Ensure that the global object has a cell for the given property name.
7643 static Handle<PropertyCell> EnsurePropertyCell(Handle<JSGlobalObject> global,
7644 Handle<Name> name);
7645
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007646 DECLARE_CAST(JSGlobalObject)
7647
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007648 inline bool IsDetached();
Steve Blocka7e24c12009-10-30 11:49:00 +00007649
7650 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007651 DECLARE_PRINTER(JSGlobalObject)
7652 DECLARE_VERIFIER(JSGlobalObject)
Steve Blocka7e24c12009-10-30 11:49:00 +00007653
7654 // Layout description.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007655 static const int kNativeContextOffset = JSObject::kHeaderSize;
7656 static const int kGlobalProxyOffset = kNativeContextOffset + kPointerSize;
7657 static const int kHeaderSize = kGlobalProxyOffset + kPointerSize;
7658 static const int kSize = kHeaderSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00007659
7660 private:
7661 DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject);
7662};
7663
7664
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007665// Representation for JS Wrapper objects, String, Number, Boolean, etc.
Steve Blocka7e24c12009-10-30 11:49:00 +00007666class JSValue: public JSObject {
7667 public:
7668 // [value]: the object being wrapped.
7669 DECL_ACCESSORS(value, Object)
7670
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007671 DECLARE_CAST(JSValue)
Steve Blocka7e24c12009-10-30 11:49:00 +00007672
7673 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007674 DECLARE_PRINTER(JSValue)
7675 DECLARE_VERIFIER(JSValue)
Steve Blocka7e24c12009-10-30 11:49:00 +00007676
7677 // Layout description.
7678 static const int kValueOffset = JSObject::kHeaderSize;
7679 static const int kSize = kValueOffset + kPointerSize;
7680
7681 private:
7682 DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue);
7683};
7684
Steve Block1e0659c2011-05-24 12:43:12 +01007685
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007686class DateCache;
7687
7688// Representation for JS date objects.
7689class JSDate: public JSObject {
7690 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007691 static MUST_USE_RESULT MaybeHandle<JSDate> New(Handle<JSFunction> constructor,
7692 Handle<JSReceiver> new_target,
7693 double tv);
7694
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007695 // If one component is NaN, all of them are, indicating a NaN time value.
7696 // [value]: the time value.
7697 DECL_ACCESSORS(value, Object)
7698 // [year]: caches year. Either undefined, smi, or NaN.
7699 DECL_ACCESSORS(year, Object)
7700 // [month]: caches month. Either undefined, smi, or NaN.
7701 DECL_ACCESSORS(month, Object)
7702 // [day]: caches day. Either undefined, smi, or NaN.
7703 DECL_ACCESSORS(day, Object)
7704 // [weekday]: caches day of week. Either undefined, smi, or NaN.
7705 DECL_ACCESSORS(weekday, Object)
7706 // [hour]: caches hours. Either undefined, smi, or NaN.
7707 DECL_ACCESSORS(hour, Object)
7708 // [min]: caches minutes. Either undefined, smi, or NaN.
7709 DECL_ACCESSORS(min, Object)
7710 // [sec]: caches seconds. Either undefined, smi, or NaN.
7711 DECL_ACCESSORS(sec, Object)
7712 // [cache stamp]: sample of the date cache stamp at the
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007713 // moment when chached fields were cached.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007714 DECL_ACCESSORS(cache_stamp, Object)
7715
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007716 DECLARE_CAST(JSDate)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007717
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007718 // Returns the time value (UTC) identifying the current time.
7719 static double CurrentTimeValue(Isolate* isolate);
7720
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007721 // Returns the date field with the specified index.
7722 // See FieldIndex for the list of date fields.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007723 static Object* GetField(Object* date, Smi* index);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007724
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007725 static Handle<Object> SetValue(Handle<JSDate> date, double v);
7726
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007727 void SetValue(Object* value, bool is_value_nan);
7728
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007729 // ES6 section 20.3.4.45 Date.prototype [ @@toPrimitive ]
7730 static MUST_USE_RESULT MaybeHandle<Object> ToPrimitive(
7731 Handle<JSReceiver> receiver, Handle<Object> hint);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007732
7733 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007734 DECLARE_PRINTER(JSDate)
7735 DECLARE_VERIFIER(JSDate)
7736
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007737 // The order is important. It must be kept in sync with date macros
7738 // in macros.py.
7739 enum FieldIndex {
7740 kDateValue,
7741 kYear,
7742 kMonth,
7743 kDay,
7744 kWeekday,
7745 kHour,
7746 kMinute,
7747 kSecond,
7748 kFirstUncachedField,
7749 kMillisecond = kFirstUncachedField,
7750 kDays,
7751 kTimeInDay,
7752 kFirstUTCField,
7753 kYearUTC = kFirstUTCField,
7754 kMonthUTC,
7755 kDayUTC,
7756 kWeekdayUTC,
7757 kHourUTC,
7758 kMinuteUTC,
7759 kSecondUTC,
7760 kMillisecondUTC,
7761 kDaysUTC,
7762 kTimeInDayUTC,
7763 kTimezoneOffset
7764 };
7765
7766 // Layout description.
7767 static const int kValueOffset = JSObject::kHeaderSize;
7768 static const int kYearOffset = kValueOffset + kPointerSize;
7769 static const int kMonthOffset = kYearOffset + kPointerSize;
7770 static const int kDayOffset = kMonthOffset + kPointerSize;
7771 static const int kWeekdayOffset = kDayOffset + kPointerSize;
7772 static const int kHourOffset = kWeekdayOffset + kPointerSize;
7773 static const int kMinOffset = kHourOffset + kPointerSize;
7774 static const int kSecOffset = kMinOffset + kPointerSize;
7775 static const int kCacheStampOffset = kSecOffset + kPointerSize;
7776 static const int kSize = kCacheStampOffset + kPointerSize;
7777
7778 private:
7779 inline Object* DoGetField(FieldIndex index);
7780
7781 Object* GetUTCField(FieldIndex index, double value, DateCache* date_cache);
7782
7783 // Computes and caches the cacheable fields of the date.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007784 inline void SetCachedFields(int64_t local_time_ms, DateCache* date_cache);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01007785
7786
7787 DISALLOW_IMPLICIT_CONSTRUCTORS(JSDate);
7788};
7789
7790
Steve Block1e0659c2011-05-24 12:43:12 +01007791// Representation of message objects used for error reporting through
7792// the API. The messages are formatted in JavaScript so this object is
7793// a real JavaScript object. The information used for formatting the
7794// error messages are not directly accessible from JavaScript to
7795// prevent leaking information to user code called during error
7796// formatting.
7797class JSMessageObject: public JSObject {
7798 public:
7799 // [type]: the type of error message.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007800 inline int type() const;
7801 inline void set_type(int value);
Steve Block1e0659c2011-05-24 12:43:12 +01007802
7803 // [arguments]: the arguments for formatting the error message.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007804 DECL_ACCESSORS(argument, Object)
Steve Block1e0659c2011-05-24 12:43:12 +01007805
7806 // [script]: the script from which the error message originated.
7807 DECL_ACCESSORS(script, Object)
7808
Steve Block1e0659c2011-05-24 12:43:12 +01007809 // [stack_frames]: an array of stack frames for this error object.
7810 DECL_ACCESSORS(stack_frames, Object)
7811
7812 // [start_position]: the start position in the script for the error message.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007813 inline int start_position() const;
Steve Block1e0659c2011-05-24 12:43:12 +01007814 inline void set_start_position(int value);
7815
7816 // [end_position]: the end position in the script for the error message.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007817 inline int end_position() const;
Steve Block1e0659c2011-05-24 12:43:12 +01007818 inline void set_end_position(int value);
7819
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007820 DECLARE_CAST(JSMessageObject)
Steve Block1e0659c2011-05-24 12:43:12 +01007821
7822 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007823 DECLARE_PRINTER(JSMessageObject)
7824 DECLARE_VERIFIER(JSMessageObject)
Steve Block1e0659c2011-05-24 12:43:12 +01007825
7826 // Layout description.
7827 static const int kTypeOffset = JSObject::kHeaderSize;
7828 static const int kArgumentsOffset = kTypeOffset + kPointerSize;
7829 static const int kScriptOffset = kArgumentsOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007830 static const int kStackFramesOffset = kScriptOffset + kPointerSize;
Steve Block1e0659c2011-05-24 12:43:12 +01007831 static const int kStartPositionOffset = kStackFramesOffset + kPointerSize;
7832 static const int kEndPositionOffset = kStartPositionOffset + kPointerSize;
7833 static const int kSize = kEndPositionOffset + kPointerSize;
7834
7835 typedef FixedBodyDescriptor<HeapObject::kMapOffset,
7836 kStackFramesOffset + kPointerSize,
7837 kSize> BodyDescriptor;
7838};
7839
7840
Steve Blocka7e24c12009-10-30 11:49:00 +00007841// Regular expressions
7842// The regular expression holds a single reference to a FixedArray in
7843// the kDataOffset field.
7844// The FixedArray contains the following data:
7845// - tag : type of regexp implementation (not compiled yet, atom or irregexp)
7846// - reference to the original source string
7847// - reference to the original flag string
7848// If it is an atom regexp
7849// - a reference to a literal string to search for
7850// If it is an irregexp regexp:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007851// - a reference to code for Latin1 inputs (bytecode or compiled), or a smi
Ben Murdoch257744e2011-11-30 15:57:28 +00007852// used for tracking the last usage (used for code flushing).
7853// - a reference to code for UC16 inputs (bytecode or compiled), or a smi
7854// used for tracking the last usage (used for code flushing)..
Steve Blocka7e24c12009-10-30 11:49:00 +00007855// - max number of registers used by irregexp implementations.
7856// - number of capture registers (output values) of the regexp.
7857class JSRegExp: public JSObject {
7858 public:
7859 // Meaning of Type:
7860 // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
7861 // ATOM: A simple string to match against using an indexOf operation.
7862 // IRREGEXP: Compiled with Irregexp.
7863 // IRREGEXP_NATIVE: Compiled to native code with Irregexp.
7864 enum Type { NOT_COMPILED, ATOM, IRREGEXP };
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007865 enum Flag {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007866 kNone = 0,
7867 kGlobal = 1 << 0,
7868 kIgnoreCase = 1 << 1,
7869 kMultiline = 1 << 2,
7870 kSticky = 1 << 3,
7871 kUnicode = 1 << 4,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007872 };
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007873 typedef base::Flags<Flag> Flags;
Steve Blocka7e24c12009-10-30 11:49:00 +00007874
7875 DECL_ACCESSORS(data, Object)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007876 DECL_ACCESSORS(flags, Object)
7877 DECL_ACCESSORS(source, Object)
7878
7879 static MaybeHandle<JSRegExp> New(Handle<String> source, Flags flags);
7880 static MaybeHandle<JSRegExp> New(Handle<String> source, Handle<String> flags);
7881 static Handle<JSRegExp> Copy(Handle<JSRegExp> regexp);
7882
7883 static MaybeHandle<JSRegExp> Initialize(Handle<JSRegExp> regexp,
7884 Handle<String> source, Flags flags);
7885 static MaybeHandle<JSRegExp> Initialize(Handle<JSRegExp> regexp,
7886 Handle<String> source,
7887 Handle<String> flags_string);
Steve Blocka7e24c12009-10-30 11:49:00 +00007888
7889 inline Type TypeTag();
7890 inline int CaptureCount();
7891 inline Flags GetFlags();
7892 inline String* Pattern();
7893 inline Object* DataAt(int index);
7894 // Set implementation data after the object has been prepared.
7895 inline void SetDataAt(int index, Object* value);
Ben Murdoch257744e2011-11-30 15:57:28 +00007896
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007897 static int code_index(bool is_latin1) {
7898 if (is_latin1) {
7899 return kIrregexpLatin1CodeIndex;
Steve Blocka7e24c12009-10-30 11:49:00 +00007900 } else {
7901 return kIrregexpUC16CodeIndex;
7902 }
7903 }
7904
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007905 static int saved_code_index(bool is_latin1) {
7906 if (is_latin1) {
7907 return kIrregexpLatin1CodeSavedIndex;
Ben Murdoch257744e2011-11-30 15:57:28 +00007908 } else {
7909 return kIrregexpUC16CodeSavedIndex;
7910 }
7911 }
7912
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007913 DECLARE_CAST(JSRegExp)
Steve Blocka7e24c12009-10-30 11:49:00 +00007914
7915 // Dispatched behavior.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007916 DECLARE_PRINTER(JSRegExp)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007917 DECLARE_VERIFIER(JSRegExp)
Steve Blocka7e24c12009-10-30 11:49:00 +00007918
7919 static const int kDataOffset = JSObject::kHeaderSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007920 static const int kSourceOffset = kDataOffset + kPointerSize;
7921 static const int kFlagsOffset = kSourceOffset + kPointerSize;
7922 static const int kSize = kFlagsOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00007923
7924 // Indices in the data array.
7925 static const int kTagIndex = 0;
7926 static const int kSourceIndex = kTagIndex + 1;
7927 static const int kFlagsIndex = kSourceIndex + 1;
7928 static const int kDataIndex = kFlagsIndex + 1;
7929 // The data fields are used in different ways depending on the
7930 // value of the tag.
7931 // Atom regexps (literal strings).
7932 static const int kAtomPatternIndex = kDataIndex;
7933
7934 static const int kAtomDataSize = kAtomPatternIndex + 1;
7935
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007936 // Irregexp compiled code or bytecode for Latin1. If compilation
Steve Blocka7e24c12009-10-30 11:49:00 +00007937 // fails, this fields hold an exception object that should be
7938 // thrown if the regexp is used again.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007939 static const int kIrregexpLatin1CodeIndex = kDataIndex;
Steve Blocka7e24c12009-10-30 11:49:00 +00007940 // Irregexp compiled code or bytecode for UC16. If compilation
7941 // fails, this fields hold an exception object that should be
7942 // thrown if the regexp is used again.
7943 static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
Ben Murdoch257744e2011-11-30 15:57:28 +00007944
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007945 // Saved instance of Irregexp compiled code or bytecode for Latin1 that
Ben Murdoch257744e2011-11-30 15:57:28 +00007946 // is a potential candidate for flushing.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007947 static const int kIrregexpLatin1CodeSavedIndex = kDataIndex + 2;
Ben Murdoch257744e2011-11-30 15:57:28 +00007948 // Saved instance of Irregexp compiled code or bytecode for UC16 that is
7949 // a potential candidate for flushing.
7950 static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3;
7951
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007952 // Maximal number of registers used by either Latin1 or UC16.
Steve Blocka7e24c12009-10-30 11:49:00 +00007953 // Only used to check that there is enough stack space
Ben Murdoch257744e2011-11-30 15:57:28 +00007954 static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4;
Steve Blocka7e24c12009-10-30 11:49:00 +00007955 // Number of captures in the compiled regexp.
Ben Murdoch257744e2011-11-30 15:57:28 +00007956 static const int kIrregexpCaptureCountIndex = kDataIndex + 5;
Steve Blocka7e24c12009-10-30 11:49:00 +00007957
7958 static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1;
Leon Clarkee46be812010-01-19 14:06:41 +00007959
7960 // Offsets directly into the data fixed array.
7961 static const int kDataTagOffset =
7962 FixedArray::kHeaderSize + kTagIndex * kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007963 static const int kDataOneByteCodeOffset =
7964 FixedArray::kHeaderSize + kIrregexpLatin1CodeIndex * kPointerSize;
Leon Clarked91b9f72010-01-27 17:25:45 +00007965 static const int kDataUC16CodeOffset =
7966 FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize;
Leon Clarkee46be812010-01-19 14:06:41 +00007967 static const int kIrregexpCaptureCountOffset =
7968 FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
Steve Block6ded16b2010-05-10 14:33:55 +01007969
7970 // In-object fields.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007971 static const int kLastIndexFieldIndex = 0;
7972 static const int kInObjectFieldCount = 1;
Ben Murdoch257744e2011-11-30 15:57:28 +00007973
7974 // The uninitialized value for a regexp code object.
7975 static const int kUninitializedValue = -1;
7976
7977 // The compilation error value for the regexp code object. The real error
7978 // object is in the saved code field.
7979 static const int kCompilationErrorValue = -2;
7980
7981 // When we store the sweep generation at which we moved the code from the
7982 // code index to the saved code index we mask it of to be in the [0:255]
7983 // range.
7984 static const int kCodeAgeMask = 0xff;
Steve Blocka7e24c12009-10-30 11:49:00 +00007985};
7986
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007987DEFINE_OPERATORS_FOR_FLAGS(JSRegExp::Flags)
7988
Steve Blocka7e24c12009-10-30 11:49:00 +00007989
Ben Murdochc7cc0282012-03-05 14:35:55 +00007990class CompilationCacheShape : public BaseShape<HashTableKey*> {
Steve Blocka7e24c12009-10-30 11:49:00 +00007991 public:
7992 static inline bool IsMatch(HashTableKey* key, Object* value) {
7993 return key->IsMatch(value);
7994 }
7995
7996 static inline uint32_t Hash(HashTableKey* key) {
7997 return key->Hash();
7998 }
7999
8000 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
8001 return key->HashForObject(object);
8002 }
8003
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008004 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
Steve Blocka7e24c12009-10-30 11:49:00 +00008005
8006 static const int kPrefixSize = 0;
8007 static const int kEntrySize = 2;
8008};
8009
Steve Block3ce2e202009-11-05 08:53:23 +00008010
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008011// This cache is used in two different variants. For regexp caching, it simply
8012// maps identifying info of the regexp to the cached regexp object. Scripts and
8013// eval code only gets cached after a second probe for the code object. To do
8014// so, on first "put" only a hash identifying the source is entered into the
8015// cache, mapping it to a lifetime count of the hash. On each call to Age all
8016// such lifetimes get reduced, and removed once they reach zero. If a second put
8017// is called while such a hash is live in the cache, the hash gets replaced by
8018// an actual cache entry. Age also removes stale live entries from the cache.
8019// Such entries are identified by SharedFunctionInfos pointing to either the
8020// recompilation stub, or to "old" code. This avoids memory leaks due to
8021// premature caching of scripts and eval strings that are never needed later.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008022class CompilationCacheTable: public HashTable<CompilationCacheTable,
8023 CompilationCacheShape,
Steve Blocka7e24c12009-10-30 11:49:00 +00008024 HashTableKey*> {
8025 public:
8026 // Find cached value for a string key, otherwise return null.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008027 Handle<Object> Lookup(
8028 Handle<String> src, Handle<Context> context, LanguageMode language_mode);
8029 Handle<Object> LookupEval(
8030 Handle<String> src, Handle<SharedFunctionInfo> shared,
8031 LanguageMode language_mode, int scope_position);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008032 Handle<Object> LookupRegExp(Handle<String> source, JSRegExp::Flags flags);
8033 static Handle<CompilationCacheTable> Put(
8034 Handle<CompilationCacheTable> cache, Handle<String> src,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008035 Handle<Context> context, LanguageMode language_mode,
8036 Handle<Object> value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008037 static Handle<CompilationCacheTable> PutEval(
8038 Handle<CompilationCacheTable> cache, Handle<String> src,
8039 Handle<SharedFunctionInfo> context, Handle<SharedFunctionInfo> value,
8040 int scope_position);
8041 static Handle<CompilationCacheTable> PutRegExp(
8042 Handle<CompilationCacheTable> cache, Handle<String> src,
8043 JSRegExp::Flags flags, Handle<FixedArray> value);
Ben Murdochb0fe1622011-05-05 13:52:32 +01008044 void Remove(Object* value);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008045 void Age();
8046 static const int kHashGenerations = 10;
Ben Murdochb0fe1622011-05-05 13:52:32 +01008047
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008048 DECLARE_CAST(CompilationCacheTable)
Steve Blocka7e24c12009-10-30 11:49:00 +00008049
8050 private:
8051 DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable);
8052};
8053
8054
Steve Block6ded16b2010-05-10 14:33:55 +01008055class CodeCache: public Struct {
8056 public:
8057 DECL_ACCESSORS(default_cache, FixedArray)
8058 DECL_ACCESSORS(normal_type_cache, Object)
8059
8060 // Add the code object to the cache.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008061 static void Update(
8062 Handle<CodeCache> cache, Handle<Name> name, Handle<Code> code);
Steve Block6ded16b2010-05-10 14:33:55 +01008063
8064 // Lookup code object in the cache. Returns code object if found and undefined
8065 // if not.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008066 Object* Lookup(Name* name, Code::Flags flags);
Steve Block6ded16b2010-05-10 14:33:55 +01008067
8068 // Get the internal index of a code object in the cache. Returns -1 if the
8069 // code object is not in that cache. This index can be used to later call
8070 // RemoveByIndex. The cache cannot be modified between a call to GetIndex and
8071 // RemoveByIndex.
8072 int GetIndex(Object* name, Code* code);
8073
8074 // Remove an object from the cache with the provided internal index.
8075 void RemoveByIndex(Object* name, Code* code, int index);
8076
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008077 DECLARE_CAST(CodeCache)
Steve Block6ded16b2010-05-10 14:33:55 +01008078
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008079 // Dispatched behavior.
8080 DECLARE_PRINTER(CodeCache)
8081 DECLARE_VERIFIER(CodeCache)
Steve Block6ded16b2010-05-10 14:33:55 +01008082
8083 static const int kDefaultCacheOffset = HeapObject::kHeaderSize;
8084 static const int kNormalTypeCacheOffset =
8085 kDefaultCacheOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008086 static const int kSize = kNormalTypeCacheOffset + kPointerSize;
Steve Block6ded16b2010-05-10 14:33:55 +01008087
8088 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008089 static void UpdateDefaultCache(
8090 Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code);
8091 static void UpdateNormalTypeCache(
8092 Handle<CodeCache> code_cache, Handle<Name> name, Handle<Code> code);
8093 Object* LookupDefaultCache(Name* name, Code::Flags flags);
8094 Object* LookupNormalTypeCache(Name* name, Code::Flags flags);
Steve Block6ded16b2010-05-10 14:33:55 +01008095
8096 // Code cache layout of the default cache. Elements are alternating name and
8097 // code objects for non normal load/store/call IC's.
8098 static const int kCodeCacheEntrySize = 2;
8099 static const int kCodeCacheEntryNameOffset = 0;
8100 static const int kCodeCacheEntryCodeOffset = 1;
8101
8102 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache);
8103};
8104
8105
Ben Murdochc7cc0282012-03-05 14:35:55 +00008106class CodeCacheHashTableShape : public BaseShape<HashTableKey*> {
Steve Block6ded16b2010-05-10 14:33:55 +01008107 public:
8108 static inline bool IsMatch(HashTableKey* key, Object* value) {
8109 return key->IsMatch(value);
8110 }
8111
8112 static inline uint32_t Hash(HashTableKey* key) {
8113 return key->Hash();
8114 }
8115
8116 static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
8117 return key->HashForObject(object);
8118 }
8119
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008120 static inline Handle<Object> AsHandle(Isolate* isolate, HashTableKey* key);
Steve Block6ded16b2010-05-10 14:33:55 +01008121
8122 static const int kPrefixSize = 0;
8123 static const int kEntrySize = 2;
8124};
8125
8126
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008127class CodeCacheHashTable: public HashTable<CodeCacheHashTable,
8128 CodeCacheHashTableShape,
Steve Block6ded16b2010-05-10 14:33:55 +01008129 HashTableKey*> {
8130 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008131 Object* Lookup(Name* name, Code::Flags flags);
8132 static Handle<CodeCacheHashTable> Put(
8133 Handle<CodeCacheHashTable> table,
8134 Handle<Name> name,
8135 Handle<Code> code);
Steve Block6ded16b2010-05-10 14:33:55 +01008136
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008137 int GetIndex(Name* name, Code::Flags flags);
Steve Block6ded16b2010-05-10 14:33:55 +01008138 void RemoveByIndex(int index);
8139
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008140 DECLARE_CAST(CodeCacheHashTable)
Steve Block6ded16b2010-05-10 14:33:55 +01008141
8142 // Initial size of the fixed array backing the hash table.
8143 static const int kInitialSize = 64;
8144
8145 private:
8146 DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable);
8147};
8148
8149
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00008150class PolymorphicCodeCache: public Struct {
8151 public:
8152 DECL_ACCESSORS(cache, Object)
8153
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008154 static void Update(Handle<PolymorphicCodeCache> cache,
8155 MapHandleList* maps,
8156 Code::Flags flags,
8157 Handle<Code> code);
8158
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008159
8160 // Returns an undefined value if the entry is not found.
8161 Handle<Object> Lookup(MapHandleList* maps, Code::Flags flags);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00008162
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008163 DECLARE_CAST(PolymorphicCodeCache)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00008164
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008165 // Dispatched behavior.
8166 DECLARE_PRINTER(PolymorphicCodeCache)
8167 DECLARE_VERIFIER(PolymorphicCodeCache)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00008168
8169 static const int kCacheOffset = HeapObject::kHeaderSize;
8170 static const int kSize = kCacheOffset + kPointerSize;
8171
8172 private:
8173 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache);
8174};
8175
8176
8177class PolymorphicCodeCacheHashTable
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008178 : public HashTable<PolymorphicCodeCacheHashTable,
8179 CodeCacheHashTableShape,
8180 HashTableKey*> {
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00008181 public:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008182 Object* Lookup(MapHandleList* maps, int code_kind);
8183
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008184 static Handle<PolymorphicCodeCacheHashTable> Put(
8185 Handle<PolymorphicCodeCacheHashTable> hash_table,
8186 MapHandleList* maps,
8187 int code_kind,
8188 Handle<Code> code);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00008189
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008190 DECLARE_CAST(PolymorphicCodeCacheHashTable)
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00008191
8192 static const int kInitialSize = 64;
8193 private:
8194 DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable);
8195};
8196
8197
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008198class TypeFeedbackInfo: public Struct {
8199 public:
8200 inline int ic_total_count();
8201 inline void set_ic_total_count(int count);
8202
Ben Murdoch8f9999f2012-04-23 10:39:17 +01008203 inline int ic_with_type_info_count();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008204 inline void change_ic_with_type_info_count(int delta);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008205
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008206 inline int ic_generic_count();
8207 inline void change_ic_generic_count(int delta);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008208
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008209 inline void initialize_storage();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008210
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008211 inline void change_own_type_change_checksum();
8212 inline int own_type_change_checksum();
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008213
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008214 inline void set_inlined_type_change_checksum(int checksum);
8215 inline bool matches_inlined_type_change_checksum(int checksum);
8216
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008217 DECLARE_CAST(TypeFeedbackInfo)
8218
8219 // Dispatched behavior.
8220 DECLARE_PRINTER(TypeFeedbackInfo)
8221 DECLARE_VERIFIER(TypeFeedbackInfo)
8222
8223 static const int kStorage1Offset = HeapObject::kHeaderSize;
8224 static const int kStorage2Offset = kStorage1Offset + kPointerSize;
8225 static const int kStorage3Offset = kStorage2Offset + kPointerSize;
8226 static const int kSize = kStorage3Offset + kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008227
8228 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008229 static const int kTypeChangeChecksumBits = 7;
8230
8231 class ICTotalCountField: public BitField<int, 0,
8232 kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT
8233 class OwnTypeChangeChecksum: public BitField<int,
8234 kSmiValueSize - kTypeChangeChecksumBits,
8235 kTypeChangeChecksumBits> {}; // NOLINT
8236 class ICsWithTypeInfoCountField: public BitField<int, 0,
8237 kSmiValueSize - kTypeChangeChecksumBits> {}; // NOLINT
8238 class InlinedTypeChangeChecksum: public BitField<int,
8239 kSmiValueSize - kTypeChangeChecksumBits,
8240 kTypeChangeChecksumBits> {}; // NOLINT
8241
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008242 DISALLOW_IMPLICIT_CONSTRUCTORS(TypeFeedbackInfo);
8243};
8244
8245
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008246enum AllocationSiteMode {
8247 DONT_TRACK_ALLOCATION_SITE,
8248 TRACK_ALLOCATION_SITE,
8249 LAST_ALLOCATION_SITE_MODE = TRACK_ALLOCATION_SITE
8250};
8251
8252
8253class AllocationSite: public Struct {
8254 public:
8255 static const uint32_t kMaximumArrayBytesToPretransition = 8 * 1024;
8256 static const double kPretenureRatio;
8257 static const int kPretenureMinimumCreated = 100;
8258
8259 // Values for pretenure decision field.
8260 enum PretenureDecision {
8261 kUndecided = 0,
8262 kDontTenure = 1,
8263 kMaybeTenure = 2,
8264 kTenure = 3,
8265 kZombie = 4,
8266 kLastPretenureDecisionValue = kZombie
8267 };
8268
8269 const char* PretenureDecisionName(PretenureDecision decision);
8270
8271 DECL_ACCESSORS(transition_info, Object)
8272 // nested_site threads a list of sites that represent nested literals
8273 // walked in a particular order. So [[1, 2], 1, 2] will have one
8274 // nested_site, but [[1, 2], 3, [4]] will have a list of two.
8275 DECL_ACCESSORS(nested_site, Object)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008276 DECL_INT_ACCESSORS(pretenure_data)
8277 DECL_INT_ACCESSORS(pretenure_create_count)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008278 DECL_ACCESSORS(dependent_code, DependentCode)
8279 DECL_ACCESSORS(weak_next, Object)
8280
8281 inline void Initialize();
8282
8283 // This method is expensive, it should only be called for reporting.
8284 bool IsNestedSite();
8285
8286 // transition_info bitfields, for constructed array transition info.
8287 class ElementsKindBits: public BitField<ElementsKind, 0, 15> {};
8288 class UnusedBits: public BitField<int, 15, 14> {};
8289 class DoNotInlineBit: public BitField<bool, 29, 1> {};
8290
8291 // Bitfields for pretenure_data
8292 class MementoFoundCountBits: public BitField<int, 0, 26> {};
8293 class PretenureDecisionBits: public BitField<PretenureDecision, 26, 3> {};
8294 class DeoptDependentCodeBit: public BitField<bool, 29, 1> {};
8295 STATIC_ASSERT(PretenureDecisionBits::kMax >= kLastPretenureDecisionValue);
8296
8297 // Increments the mementos found counter and returns true when the first
8298 // memento was found for a given allocation site.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008299 inline bool IncrementMementoFoundCount(int increment = 1);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008300
8301 inline void IncrementMementoCreateCount();
8302
8303 PretenureFlag GetPretenureMode();
8304
8305 void ResetPretenureDecision();
8306
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008307 inline PretenureDecision pretenure_decision();
8308 inline void set_pretenure_decision(PretenureDecision decision);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008309
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008310 inline bool deopt_dependent_code();
8311 inline void set_deopt_dependent_code(bool deopt);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008312
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008313 inline int memento_found_count();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008314 inline void set_memento_found_count(int count);
8315
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008316 inline int memento_create_count();
8317 inline void set_memento_create_count(int count);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008318
8319 // The pretenuring decision is made during gc, and the zombie state allows
8320 // us to recognize when an allocation site is just being kept alive because
8321 // a later traversal of new space may discover AllocationMementos that point
8322 // to this AllocationSite.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008323 inline bool IsZombie();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008324
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008325 inline bool IsMaybeTenure();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008326
8327 inline void MarkZombie();
8328
8329 inline bool MakePretenureDecision(PretenureDecision current_decision,
8330 double ratio,
8331 bool maximum_size_scavenge);
8332
8333 inline bool DigestPretenuringFeedback(bool maximum_size_scavenge);
8334
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008335 inline ElementsKind GetElementsKind();
8336 inline void SetElementsKind(ElementsKind kind);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008337
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008338 inline bool CanInlineCall();
8339 inline void SetDoNotInlineCall();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008340
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008341 inline bool SitePointsToLiteral();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008342
8343 static void DigestTransitionFeedback(Handle<AllocationSite> site,
8344 ElementsKind to_kind);
8345
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008346 DECLARE_PRINTER(AllocationSite)
8347 DECLARE_VERIFIER(AllocationSite)
8348
8349 DECLARE_CAST(AllocationSite)
8350 static inline AllocationSiteMode GetMode(
8351 ElementsKind boilerplate_elements_kind);
8352 static inline AllocationSiteMode GetMode(ElementsKind from, ElementsKind to);
8353 static inline bool CanTrack(InstanceType type);
8354
8355 static const int kTransitionInfoOffset = HeapObject::kHeaderSize;
8356 static const int kNestedSiteOffset = kTransitionInfoOffset + kPointerSize;
8357 static const int kPretenureDataOffset = kNestedSiteOffset + kPointerSize;
8358 static const int kPretenureCreateCountOffset =
8359 kPretenureDataOffset + kPointerSize;
8360 static const int kDependentCodeOffset =
8361 kPretenureCreateCountOffset + kPointerSize;
8362 static const int kWeakNextOffset = kDependentCodeOffset + kPointerSize;
8363 static const int kSize = kWeakNextOffset + kPointerSize;
8364
8365 // During mark compact we need to take special care for the dependent code
8366 // field.
8367 static const int kPointerFieldsBeginOffset = kTransitionInfoOffset;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008368 static const int kPointerFieldsEndOffset = kWeakNextOffset;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008369
8370 // For other visitors, use the fixed body descriptor below.
Ben Murdoch097c5b22016-05-18 11:27:45 +01008371 typedef FixedBodyDescriptor<HeapObject::kHeaderSize, kSize, kSize>
8372 BodyDescriptor;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008373
8374 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008375 inline bool PretenuringDecisionMade();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008376
8377 DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationSite);
8378};
8379
8380
8381class AllocationMemento: public Struct {
8382 public:
8383 static const int kAllocationSiteOffset = HeapObject::kHeaderSize;
8384 static const int kSize = kAllocationSiteOffset + kPointerSize;
8385
8386 DECL_ACCESSORS(allocation_site, Object)
8387
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008388 inline bool IsValid();
8389 inline AllocationSite* GetAllocationSite();
Ben Murdoch097c5b22016-05-18 11:27:45 +01008390 inline Address GetAllocationSiteUnchecked();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008391
8392 DECLARE_PRINTER(AllocationMemento)
8393 DECLARE_VERIFIER(AllocationMemento)
8394
8395 DECLARE_CAST(AllocationMemento)
8396
8397 private:
8398 DISALLOW_IMPLICIT_CONSTRUCTORS(AllocationMemento);
8399};
8400
8401
8402// Representation of a slow alias as part of a sloppy arguments objects.
8403// For fast aliases (if HasSloppyArgumentsElements()):
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008404// - the parameter map contains an index into the context
8405// - all attributes of the element have default values
8406// For slow aliases (if HasDictionaryArgumentsElements()):
8407// - the parameter map contains no fast alias mapping (i.e. the hole)
8408// - this struct (in the slow backing store) contains an index into the context
8409// - all attributes are available as part if the property details
8410class AliasedArgumentsEntry: public Struct {
8411 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008412 inline int aliased_context_slot() const;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008413 inline void set_aliased_context_slot(int count);
8414
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008415 DECLARE_CAST(AliasedArgumentsEntry)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008416
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008417 // Dispatched behavior.
8418 DECLARE_PRINTER(AliasedArgumentsEntry)
8419 DECLARE_VERIFIER(AliasedArgumentsEntry)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008420
8421 static const int kAliasedContextSlot = HeapObject::kHeaderSize;
8422 static const int kSize = kAliasedContextSlot + kPointerSize;
8423
8424 private:
8425 DISALLOW_IMPLICIT_CONSTRUCTORS(AliasedArgumentsEntry);
8426};
8427
8428
Steve Blocka7e24c12009-10-30 11:49:00 +00008429enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS};
8430enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL};
8431
8432
8433class StringHasher {
8434 public:
Ben Murdochc7cc0282012-03-05 14:35:55 +00008435 explicit inline StringHasher(int length, uint32_t seed);
Steve Blocka7e24c12009-10-30 11:49:00 +00008436
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008437 template <typename schar>
8438 static inline uint32_t HashSequentialString(const schar* chars,
8439 int length,
8440 uint32_t seed);
Steve Blocka7e24c12009-10-30 11:49:00 +00008441
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008442 // Reads all the data, even for long strings and computes the utf16 length.
8443 static uint32_t ComputeUtf8Hash(Vector<const char> chars,
8444 uint32_t seed,
8445 int* utf16_length_out);
Steve Blocka7e24c12009-10-30 11:49:00 +00008446
Kristian Monsen80d68ea2010-09-08 11:05:35 +01008447 // Calculated hash value for a string consisting of 1 to
8448 // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
8449 // value is represented decimal value.
Iain Merrick9ac36c92010-09-13 15:29:50 +01008450 static uint32_t MakeArrayIndexHash(uint32_t value, int length);
Kristian Monsen80d68ea2010-09-08 11:05:35 +01008451
Ben Murdochc7cc0282012-03-05 14:35:55 +00008452 // No string is allowed to have a hash of zero. That value is reserved
8453 // for internal properties. If the hash calculation yields zero then we
8454 // use 27 instead.
8455 static const int kZeroHash = 27;
8456
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008457 // Reusable parts of the hashing algorithm.
8458 INLINE(static uint32_t AddCharacterCore(uint32_t running_hash, uint16_t c));
8459 INLINE(static uint32_t GetHashCore(uint32_t running_hash));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008460 INLINE(static uint32_t ComputeRunningHash(uint32_t running_hash,
8461 const uc16* chars, int length));
8462 INLINE(static uint32_t ComputeRunningHashOneByte(uint32_t running_hash,
8463 const char* chars,
8464 int length));
Steve Blocka7e24c12009-10-30 11:49:00 +00008465
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008466 protected:
8467 // Returns the value to store in the hash field of a string with
8468 // the given length and contents.
8469 uint32_t GetHashField();
8470 // Returns true if the hash of this string can be computed without
8471 // looking at the contents.
8472 inline bool has_trivial_hash();
8473 // Adds a block of characters to the hash.
8474 template<typename Char>
8475 inline void AddCharacters(const Char* chars, int len);
8476
8477 private:
8478 // Add a character to the hash.
8479 inline void AddCharacter(uint16_t c);
8480 // Update index. Returns true if string is still an index.
8481 inline bool UpdateIndex(uint16_t c);
Steve Blocka7e24c12009-10-30 11:49:00 +00008482
8483 int length_;
8484 uint32_t raw_running_hash_;
8485 uint32_t array_index_;
8486 bool is_array_index_;
8487 bool is_first_char_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008488 DISALLOW_COPY_AND_ASSIGN(StringHasher);
Steve Blocka7e24c12009-10-30 11:49:00 +00008489};
8490
8491
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008492class IteratingStringHasher : public StringHasher {
8493 public:
8494 static inline uint32_t Hash(String* string, uint32_t seed);
8495 inline void VisitOneByteString(const uint8_t* chars, int length);
8496 inline void VisitTwoByteString(const uint16_t* chars, int length);
8497
8498 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008499 inline IteratingStringHasher(int len, uint32_t seed);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008500 void VisitConsString(ConsString* cons_string);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008501 DISALLOW_COPY_AND_ASSIGN(IteratingStringHasher);
8502};
Steve Block44f0eee2011-05-26 01:26:41 +01008503
8504
Steve Blocka7e24c12009-10-30 11:49:00 +00008505// The characteristics of a string are stored in its map. Retrieving these
8506// few bits of information is moderately expensive, involving two memory
8507// loads where the second is dependent on the first. To improve efficiency
8508// the shape of the string is given its own class so that it can be retrieved
8509// once and used for several string operations. A StringShape is small enough
8510// to be passed by value and is immutable, but be aware that flattening a
8511// string can potentially alter its shape. Also be aware that a GC caused by
8512// something else can alter the shape of a string due to ConsString
8513// shortcutting. Keeping these restrictions in mind has proven to be error-
8514// prone and so we no longer put StringShapes in variables unless there is a
8515// concrete performance benefit at that particular point in the code.
8516class StringShape BASE_EMBEDDED {
8517 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008518 inline explicit StringShape(const String* s);
Steve Blocka7e24c12009-10-30 11:49:00 +00008519 inline explicit StringShape(Map* s);
8520 inline explicit StringShape(InstanceType t);
8521 inline bool IsSequential();
8522 inline bool IsExternal();
8523 inline bool IsCons();
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008524 inline bool IsSliced();
8525 inline bool IsIndirect();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008526 inline bool IsExternalOneByte();
Steve Blocka7e24c12009-10-30 11:49:00 +00008527 inline bool IsExternalTwoByte();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008528 inline bool IsSequentialOneByte();
Steve Blocka7e24c12009-10-30 11:49:00 +00008529 inline bool IsSequentialTwoByte();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008530 inline bool IsInternalized();
Steve Blocka7e24c12009-10-30 11:49:00 +00008531 inline StringRepresentationTag representation_tag();
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008532 inline uint32_t encoding_tag();
Steve Blocka7e24c12009-10-30 11:49:00 +00008533 inline uint32_t full_representation_tag();
8534 inline uint32_t size_tag();
8535#ifdef DEBUG
8536 inline uint32_t type() { return type_; }
8537 inline void invalidate() { valid_ = false; }
8538 inline bool valid() { return valid_; }
8539#else
8540 inline void invalidate() { }
8541#endif
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00008542
Steve Blocka7e24c12009-10-30 11:49:00 +00008543 private:
8544 uint32_t type_;
8545#ifdef DEBUG
8546 inline void set_valid() { valid_ = true; }
8547 bool valid_;
8548#else
8549 inline void set_valid() { }
8550#endif
8551};
8552
8553
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008554// The Name abstract class captures anything that can be used as a property
8555// name, i.e., strings and symbols. All names store a hash value.
8556class Name: public HeapObject {
8557 public:
8558 // Get and set the hash field of the name.
8559 inline uint32_t hash_field();
8560 inline void set_hash_field(uint32_t value);
8561
8562 // Tells whether the hash code has been computed.
8563 inline bool HasHashCode();
8564
8565 // Returns a hash value used for the property table
8566 inline uint32_t Hash();
8567
8568 // Equality operations.
8569 inline bool Equals(Name* other);
8570 inline static bool Equals(Handle<Name> one, Handle<Name> two);
8571
8572 // Conversion.
8573 inline bool AsArrayIndex(uint32_t* index);
8574
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008575 // If the name is private, it can only name own properties.
8576 inline bool IsPrivate();
8577
Ben Murdoch097c5b22016-05-18 11:27:45 +01008578 inline bool IsUniqueName() const;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008579
8580 // Return a string version of this name that is converted according to the
8581 // rules described in ES6 section 9.2.11.
8582 MUST_USE_RESULT static MaybeHandle<String> ToFunctionName(Handle<Name> name);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008583
8584 DECLARE_CAST(Name)
8585
8586 DECLARE_PRINTER(Name)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008587#if TRACE_MAPS
8588 void NameShortPrint();
8589 int NameShortPrint(Vector<char> str);
8590#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008591
8592 // Layout description.
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008593 static const int kHashFieldSlot = HeapObject::kHeaderSize;
8594#if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT
8595 static const int kHashFieldOffset = kHashFieldSlot;
8596#else
8597 static const int kHashFieldOffset = kHashFieldSlot + kIntSize;
8598#endif
8599 static const int kSize = kHashFieldSlot + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008600
8601 // Mask constant for checking if a name has a computed hash code
8602 // and if it is a string that is an array index. The least significant bit
8603 // indicates whether a hash code has been computed. If the hash code has
8604 // been computed the 2nd bit tells whether the string can be used as an
8605 // array index.
8606 static const int kHashNotComputedMask = 1;
8607 static const int kIsNotArrayIndexMask = 1 << 1;
8608 static const int kNofHashBitFields = 2;
8609
8610 // Shift constant retrieving hash code from hash field.
8611 static const int kHashShift = kNofHashBitFields;
8612
8613 // Only these bits are relevant in the hash, since the top two are shifted
8614 // out.
8615 static const uint32_t kHashBitMask = 0xffffffffu >> kHashShift;
8616
8617 // Array index strings this short can keep their index in the hash field.
8618 static const int kMaxCachedArrayIndexLength = 7;
8619
8620 // For strings which are array indexes the hash value has the string length
8621 // mixed into the hash, mainly to avoid a hash value of zero which would be
8622 // the case for the string '0'. 24 bits are used for the array index value.
8623 static const int kArrayIndexValueBits = 24;
8624 static const int kArrayIndexLengthBits =
8625 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
8626
8627 STATIC_ASSERT((kArrayIndexLengthBits > 0));
8628
8629 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields,
8630 kArrayIndexValueBits> {}; // NOLINT
8631 class ArrayIndexLengthBits : public BitField<unsigned int,
8632 kNofHashBitFields + kArrayIndexValueBits,
8633 kArrayIndexLengthBits> {}; // NOLINT
8634
8635 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
8636 // could use a mask to test if the length of string is less than or equal to
8637 // kMaxCachedArrayIndexLength.
8638 STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
8639
8640 static const unsigned int kContainsCachedArrayIndexMask =
8641 (~static_cast<unsigned>(kMaxCachedArrayIndexLength)
8642 << ArrayIndexLengthBits::kShift) |
8643 kIsNotArrayIndexMask;
8644
8645 // Value of empty hash field indicating that the hash is not computed.
8646 static const int kEmptyHashField =
8647 kIsNotArrayIndexMask | kHashNotComputedMask;
8648
8649 protected:
8650 static inline bool IsHashFieldComputed(uint32_t field);
8651
8652 private:
8653 DISALLOW_IMPLICIT_CONSTRUCTORS(Name);
8654};
8655
8656
8657// ES6 symbols.
8658class Symbol: public Name {
8659 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008660 // [name]: The print name of a symbol, or undefined if none.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008661 DECL_ACCESSORS(name, Object)
8662
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008663 DECL_INT_ACCESSORS(flags)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008664
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008665 // [is_private]: Whether this is a private symbol. Private symbols can only
8666 // be used to designate own properties of objects.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008667 DECL_BOOLEAN_ACCESSORS(is_private)
8668
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008669 // [is_well_known_symbol]: Whether this is a spec-defined well-known symbol,
8670 // or not. Well-known symbols do not throw when an access check fails during
8671 // a load.
8672 DECL_BOOLEAN_ACCESSORS(is_well_known_symbol)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008673
8674 DECLARE_CAST(Symbol)
8675
8676 // Dispatched behavior.
8677 DECLARE_PRINTER(Symbol)
8678 DECLARE_VERIFIER(Symbol)
8679
8680 // Layout description.
8681 static const int kNameOffset = Name::kSize;
8682 static const int kFlagsOffset = kNameOffset + kPointerSize;
8683 static const int kSize = kFlagsOffset + kPointerSize;
8684
8685 typedef FixedBodyDescriptor<kNameOffset, kFlagsOffset, kSize> BodyDescriptor;
8686
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008687 void SymbolShortPrint(std::ostream& os);
8688
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008689 private:
8690 static const int kPrivateBit = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008691 static const int kWellKnownSymbolBit = 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008692
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008693 const char* PrivateSymbolToName() const;
8694
8695#if TRACE_MAPS
8696 friend class Name; // For PrivateSymbolToName.
8697#endif
8698
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008699 DISALLOW_IMPLICIT_CONSTRUCTORS(Symbol);
8700};
8701
8702
8703class ConsString;
8704
Steve Blocka7e24c12009-10-30 11:49:00 +00008705// The String abstract class captures JavaScript string values:
8706//
8707// Ecma-262:
8708// 4.3.16 String Value
8709// A string value is a member of the type String and is a finite
8710// ordered sequence of zero or more 16-bit unsigned integer values.
8711//
8712// All string values have a length field.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008713class String: public Name {
Steve Blocka7e24c12009-10-30 11:49:00 +00008714 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008715 enum Encoding { ONE_BYTE_ENCODING, TWO_BYTE_ENCODING };
8716
8717 // Array index strings this short can keep their index in the hash field.
8718 static const int kMaxCachedArrayIndexLength = 7;
8719
8720 // For strings which are array indexes the hash value has the string length
8721 // mixed into the hash, mainly to avoid a hash value of zero which would be
8722 // the case for the string '0'. 24 bits are used for the array index value.
8723 static const int kArrayIndexValueBits = 24;
8724 static const int kArrayIndexLengthBits =
8725 kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
8726
8727 STATIC_ASSERT((kArrayIndexLengthBits > 0));
8728
8729 class ArrayIndexValueBits : public BitField<unsigned int, kNofHashBitFields,
8730 kArrayIndexValueBits> {}; // NOLINT
8731 class ArrayIndexLengthBits : public BitField<unsigned int,
8732 kNofHashBitFields + kArrayIndexValueBits,
8733 kArrayIndexLengthBits> {}; // NOLINT
8734
8735 // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
8736 // could use a mask to test if the length of string is less than or equal to
8737 // kMaxCachedArrayIndexLength.
8738 STATIC_ASSERT(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
8739
8740 static const unsigned int kContainsCachedArrayIndexMask =
8741 (~static_cast<unsigned>(kMaxCachedArrayIndexLength)
8742 << ArrayIndexLengthBits::kShift) |
8743 kIsNotArrayIndexMask;
8744
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008745 class SubStringRange {
8746 public:
8747 explicit inline SubStringRange(String* string, int first = 0,
8748 int length = -1);
8749 class iterator;
8750 inline iterator begin();
8751 inline iterator end();
8752
8753 private:
8754 String* string_;
8755 int first_;
8756 int length_;
8757 };
8758
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008759 // Representation of the flat content of a String.
8760 // A non-flat string doesn't have flat content.
8761 // A flat string has content that's encoded as a sequence of either
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008762 // one-byte chars or two-byte UC16.
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008763 // Returned by String::GetFlatContent().
8764 class FlatContent {
8765 public:
8766 // Returns true if the string is flat and this structure contains content.
8767 bool IsFlat() { return state_ != NON_FLAT; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008768 // Returns true if the structure contains one-byte content.
8769 bool IsOneByte() { return state_ == ONE_BYTE; }
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008770 // Returns true if the structure contains two-byte content.
8771 bool IsTwoByte() { return state_ == TWO_BYTE; }
8772
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008773 // Return the one byte content of the string. Only use if IsOneByte()
8774 // returns true.
8775 Vector<const uint8_t> ToOneByteVector() {
8776 DCHECK_EQ(ONE_BYTE, state_);
8777 return Vector<const uint8_t>(onebyte_start, length_);
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008778 }
8779 // Return the two-byte content of the string. Only use if IsTwoByte()
8780 // returns true.
8781 Vector<const uc16> ToUC16Vector() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008782 DCHECK_EQ(TWO_BYTE, state_);
8783 return Vector<const uc16>(twobyte_start, length_);
8784 }
8785
8786 uc16 Get(int i) {
8787 DCHECK(i < length_);
8788 DCHECK(state_ != NON_FLAT);
8789 if (state_ == ONE_BYTE) return onebyte_start[i];
8790 return twobyte_start[i];
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008791 }
8792
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008793 bool UsesSameString(const FlatContent& other) const {
8794 return onebyte_start == other.onebyte_start;
8795 }
8796
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008797 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008798 enum State { NON_FLAT, ONE_BYTE, TWO_BYTE };
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008799
8800 // Constructors only used by String::GetFlatContent().
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008801 explicit FlatContent(const uint8_t* start, int length)
8802 : onebyte_start(start), length_(length), state_(ONE_BYTE) {}
8803 explicit FlatContent(const uc16* start, int length)
8804 : twobyte_start(start), length_(length), state_(TWO_BYTE) { }
8805 FlatContent() : onebyte_start(NULL), length_(0), state_(NON_FLAT) { }
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008806
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008807 union {
8808 const uint8_t* onebyte_start;
8809 const uc16* twobyte_start;
8810 };
8811 int length_;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008812 State state_;
8813
8814 friend class String;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008815 friend class IterableSubString;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008816 };
8817
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008818 template <typename Char>
8819 INLINE(Vector<const Char> GetCharVector());
8820
Steve Blocka7e24c12009-10-30 11:49:00 +00008821 // Get and set the length of the string.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008822 inline int length() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00008823 inline void set_length(int value);
8824
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008825 // Get and set the length of the string using acquire loads and release
8826 // stores.
8827 inline int synchronized_length() const;
8828 inline void synchronized_set_length(int value);
Steve Blocka7e24c12009-10-30 11:49:00 +00008829
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008830 // Returns whether this string has only one-byte chars, i.e. all of them can
8831 // be one-byte encoded. This might be the case even if the string is
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008832 // two-byte. Such strings may appear when the embedder prefers
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008833 // two-byte external representations even for one-byte data.
8834 inline bool IsOneByteRepresentation() const;
8835 inline bool IsTwoByteRepresentation() const;
Steve Blocka7e24c12009-10-30 11:49:00 +00008836
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008837 // Cons and slices have an encoding flag that may not represent the actual
8838 // encoding of the underlying string. This is taken into account here.
8839 // Requires: this->IsFlat()
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008840 inline bool IsOneByteRepresentationUnderneath();
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008841 inline bool IsTwoByteRepresentationUnderneath();
8842
Kristian Monsen9dcf7e22010-06-28 14:14:28 +01008843 // NOTE: this should be considered only a hint. False negatives are
8844 // possible.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008845 inline bool HasOnlyOneByteChars();
Steve Block6ded16b2010-05-10 14:33:55 +01008846
Steve Blocka7e24c12009-10-30 11:49:00 +00008847 // Get and set individual two byte chars in the string.
8848 inline void Set(int index, uint16_t value);
8849 // Get individual two byte char in the string. Repeated calls
8850 // to this method are not efficient unless the string is flat.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008851 INLINE(uint16_t Get(int index));
Steve Blocka7e24c12009-10-30 11:49:00 +00008852
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008853 // ES6 section 7.1.3.1 ToNumber Applied to the String Type
8854 static Handle<Object> ToNumber(Handle<String> subject);
8855
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008856 // Flattens the string. Checks first inline to see if it is
Leon Clarkef7060e22010-06-03 12:02:55 +01008857 // necessary. Does nothing if the string is not a cons string.
8858 // Flattening allocates a sequential string with the same data as
8859 // the given string and mutates the cons string to a degenerate
8860 // form, where the first component is the new sequential string and
8861 // the second component is the empty string. If allocation fails,
8862 // this function returns a failure. If flattening succeeds, this
8863 // function returns the sequential string that is now the first
8864 // component of the cons string.
8865 //
8866 // Degenerate cons strings are handled specially by the garbage
8867 // collector (see IsShortcutCandidate).
Steve Blocka7e24c12009-10-30 11:49:00 +00008868
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008869 static inline Handle<String> Flatten(Handle<String> string,
8870 PretenureFlag pretenure = NOT_TENURED);
Leon Clarkef7060e22010-06-03 12:02:55 +01008871
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008872 // Tries to return the content of a flat string as a structure holding either
8873 // a flat vector of char or of uc16.
8874 // If the string isn't flat, and therefore doesn't have flat content, the
8875 // returned structure will report so, and can't provide a vector of either
8876 // kind.
8877 FlatContent GetFlatContent();
8878
8879 // Returns the parent of a sliced string or first part of a flat cons string.
8880 // Requires: StringShape(this).IsIndirect() && this->IsFlat()
8881 inline String* GetUnderlying();
Steve Blocka7e24c12009-10-30 11:49:00 +00008882
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008883 // String relational comparison, implemented according to ES6 section 7.2.11
8884 // Abstract Relational Comparison (step 5): The comparison of Strings uses a
8885 // simple lexicographic ordering on sequences of code unit values. There is no
8886 // attempt to use the more complex, semantically oriented definitions of
8887 // character or string equality and collating order defined in the Unicode
8888 // specification. Therefore String values that are canonically equal according
8889 // to the Unicode standard could test as unequal. In effect this algorithm
8890 // assumes that both Strings are already in normalized form. Also, note that
8891 // for strings containing supplementary characters, lexicographic ordering on
8892 // sequences of UTF-16 code unit values differs from that on sequences of code
8893 // point values.
8894 MUST_USE_RESULT static ComparisonResult Compare(Handle<String> x,
8895 Handle<String> y);
Steve Blocka7e24c12009-10-30 11:49:00 +00008896
Steve Blocka7e24c12009-10-30 11:49:00 +00008897 // String equality operations.
8898 inline bool Equals(String* other);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008899 inline static bool Equals(Handle<String> one, Handle<String> two);
8900 bool IsUtf8EqualTo(Vector<const char> str, bool allow_prefix_match = false);
8901 bool IsOneByteEqualTo(Vector<const uint8_t> str);
Steve Block9fac8402011-05-12 15:51:54 +01008902 bool IsTwoByteEqualTo(Vector<const uc16> str);
Steve Blocka7e24c12009-10-30 11:49:00 +00008903
8904 // Return a UTF8 representation of the string. The string is null
8905 // terminated but may optionally contain nulls. Length is returned
8906 // in length_output if length_output is not a null pointer The string
8907 // should be nearly flat, otherwise the performance of this method may
8908 // be very slow (quadratic in the length). Setting robustness_flag to
8909 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
8910 // handles unexpected data without causing assert failures and it does not
8911 // do any heap allocations. This is useful when printing stack traces.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008912 base::SmartArrayPointer<char> ToCString(AllowNullsFlag allow_nulls,
8913 RobustnessFlag robustness_flag,
8914 int offset, int length,
8915 int* length_output = 0);
8916 base::SmartArrayPointer<char> ToCString(
Steve Blocka7e24c12009-10-30 11:49:00 +00008917 AllowNullsFlag allow_nulls = DISALLOW_NULLS,
8918 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL,
8919 int* length_output = 0);
8920
Steve Blocka7e24c12009-10-30 11:49:00 +00008921 // Return a 16 bit Unicode representation of the string.
8922 // The string should be nearly flat, otherwise the performance of
8923 // of this method may be very bad. Setting robustness_flag to
8924 // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it
8925 // handles unexpected data without causing assert failures and it does not
8926 // do any heap allocations. This is useful when printing stack traces.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00008927 base::SmartArrayPointer<uc16> ToWideCString(
Steve Blocka7e24c12009-10-30 11:49:00 +00008928 RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
8929
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008930 bool ComputeArrayIndex(uint32_t* index);
Steve Blocka7e24c12009-10-30 11:49:00 +00008931
8932 // Externalization.
8933 bool MakeExternal(v8::String::ExternalStringResource* resource);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008934 bool MakeExternal(v8::String::ExternalOneByteStringResource* resource);
Steve Blocka7e24c12009-10-30 11:49:00 +00008935
8936 // Conversion.
8937 inline bool AsArrayIndex(uint32_t* index);
8938
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008939 DECLARE_CAST(String)
Steve Blocka7e24c12009-10-30 11:49:00 +00008940
8941 void PrintOn(FILE* out);
8942
8943 // For use during stack traces. Performs rudimentary sanity check.
8944 bool LooksValid();
8945
8946 // Dispatched behavior.
8947 void StringShortPrint(StringStream* accumulator);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04008948 void PrintUC16(std::ostream& os, int start = 0, int end = -1); // NOLINT
8949#if defined(DEBUG) || defined(OBJECT_PRINT)
Ben Murdoch69a99ed2011-11-30 16:03:39 +00008950 char* ToAsciiArray();
Ben Murdochb0fe1622011-05-05 13:52:32 +01008951#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008952 DECLARE_PRINTER(String)
8953 DECLARE_VERIFIER(String)
8954
Steve Blocka7e24c12009-10-30 11:49:00 +00008955 inline bool IsFlat();
8956
8957 // Layout description.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008958 static const int kLengthOffset = Name::kSize;
8959 static const int kSize = kLengthOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +00008960
Steve Blockd0582a62009-12-15 09:54:21 +00008961 // Maximum number of characters to consider when trying to convert a string
8962 // value into an array index.
Steve Blocka7e24c12009-10-30 11:49:00 +00008963 static const int kMaxArrayIndexSize = 10;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008964 STATIC_ASSERT(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
Steve Blocka7e24c12009-10-30 11:49:00 +00008965
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008966 // Max char codes.
8967 static const int32_t kMaxOneByteCharCode = unibrow::Latin1::kMaxChar;
8968 static const uint32_t kMaxOneByteCharCodeU = unibrow::Latin1::kMaxChar;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01008969 static const int kMaxUtf16CodeUnit = 0xffff;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008970 static const uint32_t kMaxUtf16CodeUnitU = kMaxUtf16CodeUnit;
Ben Murdoch097c5b22016-05-18 11:27:45 +01008971 static const uc32 kMaxCodePoint = 0x10ffff;
Steve Blockd0582a62009-12-15 09:54:21 +00008972
8973 // Maximal string length.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008974 static const int kMaxLength = (1 << 28) - 16;
Steve Blockd0582a62009-12-15 09:54:21 +00008975
8976 // Max length for computing hash. For strings longer than this limit the
8977 // string length is used as the hash value.
8978 static const int kMaxHashCalcLength = 16383;
Steve Blocka7e24c12009-10-30 11:49:00 +00008979
8980 // Limit for truncation in short printing.
8981 static const int kMaxShortPrintLength = 1024;
8982
8983 // Support for regular expressions.
Steve Blocka7e24c12009-10-30 11:49:00 +00008984 const uc16* GetTwoByteData(unsigned start);
8985
Steve Blocka7e24c12009-10-30 11:49:00 +00008986 // Helper function for flattening strings.
8987 template <typename sinkchar>
8988 static void WriteToFlat(String* source,
8989 sinkchar* sink,
8990 int from,
8991 int to);
8992
Ben Murdochb8a8cc12014-11-26 15:28:44 +00008993 // The return value may point to the first aligned word containing the first
8994 // non-one-byte character, rather than directly to the non-one-byte character.
8995 // If the return value is >= the passed length, the entire string was
8996 // one-byte.
8997 static inline int NonAsciiStart(const char* chars, int length) {
8998 const char* start = chars;
Steve Block9fac8402011-05-12 15:51:54 +01008999 const char* limit = chars + length;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009000
9001 if (length >= kIntptrSize) {
9002 // Check unaligned bytes.
9003 while (!IsAligned(reinterpret_cast<intptr_t>(chars), sizeof(uintptr_t))) {
9004 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) {
9005 return static_cast<int>(chars - start);
9006 }
9007 ++chars;
Steve Block9fac8402011-05-12 15:51:54 +01009008 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009009 // Check aligned words.
9010 DCHECK(unibrow::Utf8::kMaxOneByteChar == 0x7F);
9011 const uintptr_t non_one_byte_mask = kUintptrAllBitsSet / 0xFF * 0x80;
9012 while (chars + sizeof(uintptr_t) <= limit) {
9013 if (*reinterpret_cast<const uintptr_t*>(chars) & non_one_byte_mask) {
9014 return static_cast<int>(chars - start);
9015 }
9016 chars += sizeof(uintptr_t);
9017 }
Steve Block9fac8402011-05-12 15:51:54 +01009018 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009019 // Check remaining unaligned bytes.
Steve Block9fac8402011-05-12 15:51:54 +01009020 while (chars < limit) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009021 if (static_cast<uint8_t>(*chars) > unibrow::Utf8::kMaxOneByteChar) {
9022 return static_cast<int>(chars - start);
9023 }
Steve Block9fac8402011-05-12 15:51:54 +01009024 ++chars;
9025 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009026
9027 return static_cast<int>(chars - start);
Steve Block9fac8402011-05-12 15:51:54 +01009028 }
9029
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009030 static inline bool IsAscii(const char* chars, int length) {
9031 return NonAsciiStart(chars, length) >= length;
9032 }
9033
9034 static inline bool IsAscii(const uint8_t* chars, int length) {
9035 return
9036 NonAsciiStart(reinterpret_cast<const char*>(chars), length) >= length;
9037 }
9038
9039 static inline int NonOneByteStart(const uc16* chars, int length) {
Steve Block9fac8402011-05-12 15:51:54 +01009040 const uc16* limit = chars + length;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009041 const uc16* start = chars;
Steve Block9fac8402011-05-12 15:51:54 +01009042 while (chars < limit) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009043 if (*chars > kMaxOneByteCharCodeU) return static_cast<int>(chars - start);
Steve Block9fac8402011-05-12 15:51:54 +01009044 ++chars;
9045 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009046 return static_cast<int>(chars - start);
Steve Block9fac8402011-05-12 15:51:54 +01009047 }
9048
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009049 static inline bool IsOneByte(const uc16* chars, int length) {
9050 return NonOneByteStart(chars, length) >= length;
9051 }
Steve Blocka7e24c12009-10-30 11:49:00 +00009052
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009053 template<class Visitor>
9054 static inline ConsString* VisitFlat(Visitor* visitor,
9055 String* string,
9056 int offset = 0);
9057
9058 static Handle<FixedArray> CalculateLineEnds(Handle<String> string,
9059 bool include_ending_line);
9060
9061 // Use the hash field to forward to the canonical internalized string
9062 // when deserializing an internalized string.
9063 inline void SetForwardedInternalizedString(String* string);
9064 inline String* GetForwardedInternalizedString();
Steve Blocka7e24c12009-10-30 11:49:00 +00009065
9066 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009067 friend class Name;
9068 friend class StringTableInsertionKey;
Leon Clarkef7060e22010-06-03 12:02:55 +01009069
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009070 static Handle<String> SlowFlatten(Handle<ConsString> cons,
9071 PretenureFlag tenure);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01009072
Steve Blocka7e24c12009-10-30 11:49:00 +00009073 // Slow case of String::Equals. This implementation works on any strings
9074 // but it is most efficient on strings that are almost flat.
9075 bool SlowEquals(String* other);
9076
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009077 static bool SlowEquals(Handle<String> one, Handle<String> two);
9078
Steve Blocka7e24c12009-10-30 11:49:00 +00009079 // Slow case of AsArrayIndex.
9080 bool SlowAsArrayIndex(uint32_t* index);
9081
9082 // Compute and set the hash code.
9083 uint32_t ComputeAndSetHash();
9084
9085 DISALLOW_IMPLICIT_CONSTRUCTORS(String);
9086};
9087
9088
9089// The SeqString abstract class captures sequential string values.
9090class SeqString: public String {
9091 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009092 DECLARE_CAST(SeqString)
Steve Blocka7e24c12009-10-30 11:49:00 +00009093
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009094 // Layout description.
9095 static const int kHeaderSize = String::kSize;
9096
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009097 // Truncate the string in-place if possible and return the result.
9098 // In case of new_length == 0, the empty string is returned without
9099 // truncating the original string.
9100 MUST_USE_RESULT static Handle<String> Truncate(Handle<SeqString> string,
9101 int new_length);
Steve Blocka7e24c12009-10-30 11:49:00 +00009102 private:
9103 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
9104};
9105
9106
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009107// The OneByteString class captures sequential one-byte string objects.
9108// Each character in the OneByteString is an one-byte character.
9109class SeqOneByteString: public SeqString {
Steve Blocka7e24c12009-10-30 11:49:00 +00009110 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009111 static const bool kHasOneByteEncoding = true;
Leon Clarkeac952652010-07-15 11:15:24 +01009112
Steve Blocka7e24c12009-10-30 11:49:00 +00009113 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009114 inline uint16_t SeqOneByteStringGet(int index);
9115 inline void SeqOneByteStringSet(int index, uint16_t value);
Steve Blocka7e24c12009-10-30 11:49:00 +00009116
9117 // Get the address of the characters in this string.
9118 inline Address GetCharsAddress();
9119
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009120 inline uint8_t* GetChars();
Steve Blocka7e24c12009-10-30 11:49:00 +00009121
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009122 DECLARE_CAST(SeqOneByteString)
Steve Blocka7e24c12009-10-30 11:49:00 +00009123
9124 // Garbage collection support. This method is called by the
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009125 // garbage collector to compute the actual size of an OneByteString
Steve Blocka7e24c12009-10-30 11:49:00 +00009126 // instance.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009127 inline int SeqOneByteStringSize(InstanceType instance_type);
Steve Blocka7e24c12009-10-30 11:49:00 +00009128
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009129 // Computes the size for an OneByteString instance of a given length.
Steve Blocka7e24c12009-10-30 11:49:00 +00009130 static int SizeFor(int length) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01009131 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00009132 }
9133
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009134 // Maximal memory usage for a single sequential one-byte string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009135 static const int kMaxSize = 512 * MB - 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009136 STATIC_ASSERT((kMaxSize - kHeaderSize) >= String::kMaxLength);
Steve Blocka7e24c12009-10-30 11:49:00 +00009137
9138 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009139 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqOneByteString);
Steve Blocka7e24c12009-10-30 11:49:00 +00009140};
9141
9142
9143// The TwoByteString class captures sequential unicode string objects.
9144// Each character in the TwoByteString is a two-byte uint16_t.
9145class SeqTwoByteString: public SeqString {
9146 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009147 static const bool kHasOneByteEncoding = false;
Leon Clarkeac952652010-07-15 11:15:24 +01009148
Steve Blocka7e24c12009-10-30 11:49:00 +00009149 // Dispatched behavior.
9150 inline uint16_t SeqTwoByteStringGet(int index);
9151 inline void SeqTwoByteStringSet(int index, uint16_t value);
9152
9153 // Get the address of the characters in this string.
9154 inline Address GetCharsAddress();
9155
9156 inline uc16* GetChars();
9157
9158 // For regexp code.
9159 const uint16_t* SeqTwoByteStringGetData(unsigned start);
9160
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009161 DECLARE_CAST(SeqTwoByteString)
Steve Blocka7e24c12009-10-30 11:49:00 +00009162
9163 // Garbage collection support. This method is called by the
9164 // garbage collector to compute the actual size of a TwoByteString
9165 // instance.
9166 inline int SeqTwoByteStringSize(InstanceType instance_type);
9167
9168 // Computes the size for a TwoByteString instance of a given length.
9169 static int SizeFor(int length) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01009170 return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
Steve Blocka7e24c12009-10-30 11:49:00 +00009171 }
9172
Leon Clarkee46be812010-01-19 14:06:41 +00009173 // Maximal memory usage for a single sequential two-byte string.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009174 static const int kMaxSize = 512 * MB - 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009175 STATIC_ASSERT(static_cast<int>((kMaxSize - kHeaderSize)/sizeof(uint16_t)) >=
9176 String::kMaxLength);
Steve Blocka7e24c12009-10-30 11:49:00 +00009177
9178 private:
9179 DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
9180};
9181
9182
9183// The ConsString class describes string values built by using the
9184// addition operator on strings. A ConsString is a pair where the
9185// first and second components are pointers to other string values.
9186// One or both components of a ConsString can be pointers to other
9187// ConsStrings, creating a binary tree of ConsStrings where the leaves
9188// are non-ConsString string values. The string value represented by
9189// a ConsString can be obtained by concatenating the leaf string
9190// values in a left-to-right depth-first traversal of the tree.
9191class ConsString: public String {
9192 public:
9193 // First string of the cons cell.
9194 inline String* first();
9195 // Doesn't check that the result is a string, even in debug mode. This is
9196 // useful during GC where the mark bits confuse the checks.
9197 inline Object* unchecked_first();
9198 inline void set_first(String* first,
9199 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
9200
9201 // Second string of the cons cell.
9202 inline String* second();
9203 // Doesn't check that the result is a string, even in debug mode. This is
9204 // useful during GC where the mark bits confuse the checks.
9205 inline Object* unchecked_second();
9206 inline void set_second(String* second,
9207 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
9208
9209 // Dispatched behavior.
9210 uint16_t ConsStringGet(int index);
9211
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009212 DECLARE_CAST(ConsString)
Steve Blocka7e24c12009-10-30 11:49:00 +00009213
Steve Blocka7e24c12009-10-30 11:49:00 +00009214 // Layout description.
9215 static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
9216 static const int kSecondOffset = kFirstOffset + kPointerSize;
9217 static const int kSize = kSecondOffset + kPointerSize;
9218
Steve Blocka7e24c12009-10-30 11:49:00 +00009219 // Minimum length for a cons string.
9220 static const int kMinLength = 13;
9221
Iain Merrick75681382010-08-19 15:07:18 +01009222 typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
9223 BodyDescriptor;
9224
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009225 DECLARE_VERIFIER(ConsString)
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009226
Steve Blocka7e24c12009-10-30 11:49:00 +00009227 private:
9228 DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
9229};
9230
9231
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009232// The Sliced String class describes strings that are substrings of another
9233// sequential string. The motivation is to save time and memory when creating
9234// a substring. A Sliced String is described as a pointer to the parent,
9235// the offset from the start of the parent string and the length. Using
9236// a Sliced String therefore requires unpacking of the parent string and
9237// adding the offset to the start address. A substring of a Sliced String
9238// are not nested since the double indirection is simplified when creating
9239// such a substring.
9240// Currently missing features are:
9241// - handling externalized parent strings
9242// - external strings as parent
9243// - truncating sliced string to enable otherwise unneeded parent to be GC'ed.
9244class SlicedString: public String {
9245 public:
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009246 inline String* parent();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009247 inline void set_parent(String* parent,
9248 WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
9249 inline int offset() const;
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009250 inline void set_offset(int offset);
9251
9252 // Dispatched behavior.
9253 uint16_t SlicedStringGet(int index);
9254
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009255 DECLARE_CAST(SlicedString)
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009256
9257 // Layout description.
9258 static const int kParentOffset = POINTER_SIZE_ALIGN(String::kSize);
9259 static const int kOffsetOffset = kParentOffset + kPointerSize;
9260 static const int kSize = kOffsetOffset + kPointerSize;
9261
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009262 // Minimum length for a sliced string.
9263 static const int kMinLength = 13;
9264
9265 typedef FixedBodyDescriptor<kParentOffset,
9266 kOffsetOffset + kPointerSize, kSize>
9267 BodyDescriptor;
9268
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009269 DECLARE_VERIFIER(SlicedString)
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009270
9271 private:
9272 DISALLOW_IMPLICIT_CONSTRUCTORS(SlicedString);
9273};
9274
9275
Steve Blocka7e24c12009-10-30 11:49:00 +00009276// The ExternalString class describes string values that are backed by
9277// a string resource that lies outside the V8 heap. ExternalStrings
9278// consist of the length field common to all strings, a pointer to the
9279// external resource. It is important to ensure (externally) that the
9280// resource is not deallocated while the ExternalString is live in the
9281// V8 heap.
9282//
9283// The API expects that all ExternalStrings are created through the
9284// API. Therefore, ExternalStrings should not be used internally.
9285class ExternalString: public String {
9286 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009287 DECLARE_CAST(ExternalString)
Steve Blocka7e24c12009-10-30 11:49:00 +00009288
9289 // Layout description.
9290 static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009291 static const int kShortSize = kResourceOffset + kPointerSize;
9292 static const int kResourceDataOffset = kResourceOffset + kPointerSize;
9293 static const int kSize = kResourceDataOffset + kPointerSize;
9294
9295 // Return whether external string is short (data pointer is not cached).
9296 inline bool is_short();
Steve Blocka7e24c12009-10-30 11:49:00 +00009297
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009298 STATIC_ASSERT(kResourceOffset == Internals::kStringResourceOffset);
Steve Blocka7e24c12009-10-30 11:49:00 +00009299
9300 private:
9301 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
9302};
9303
9304
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009305// The ExternalOneByteString class is an external string backed by an
9306// one-byte string.
9307class ExternalOneByteString : public ExternalString {
Steve Blocka7e24c12009-10-30 11:49:00 +00009308 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009309 static const bool kHasOneByteEncoding = true;
Leon Clarkeac952652010-07-15 11:15:24 +01009310
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009311 typedef v8::String::ExternalOneByteStringResource Resource;
Steve Blocka7e24c12009-10-30 11:49:00 +00009312
9313 // The underlying resource.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009314 inline const Resource* resource();
9315 inline void set_resource(const Resource* buffer);
9316
9317 // Update the pointer cache to the external character array.
9318 // The cached pointer is always valid, as the external character array does =
9319 // not move during lifetime. Deserialization is the only exception, after
9320 // which the pointer cache has to be refreshed.
9321 inline void update_data_cache();
9322
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009323 inline const uint8_t* GetChars();
Steve Blocka7e24c12009-10-30 11:49:00 +00009324
9325 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009326 inline uint16_t ExternalOneByteStringGet(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00009327
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009328 DECLARE_CAST(ExternalOneByteString)
Steve Blocka7e24c12009-10-30 11:49:00 +00009329
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009330 class BodyDescriptor;
Steve Blocka7e24c12009-10-30 11:49:00 +00009331
Steve Blocka7e24c12009-10-30 11:49:00 +00009332 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009333 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalOneByteString);
Steve Blocka7e24c12009-10-30 11:49:00 +00009334};
9335
9336
9337// The ExternalTwoByteString class is an external string backed by a UTF-16
9338// encoded string.
9339class ExternalTwoByteString: public ExternalString {
9340 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009341 static const bool kHasOneByteEncoding = false;
Leon Clarkeac952652010-07-15 11:15:24 +01009342
Steve Blocka7e24c12009-10-30 11:49:00 +00009343 typedef v8::String::ExternalStringResource Resource;
9344
9345 // The underlying string resource.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009346 inline const Resource* resource();
9347 inline void set_resource(const Resource* buffer);
9348
9349 // Update the pointer cache to the external character array.
9350 // The cached pointer is always valid, as the external character array does =
9351 // not move during lifetime. Deserialization is the only exception, after
9352 // which the pointer cache has to be refreshed.
9353 inline void update_data_cache();
9354
9355 inline const uint16_t* GetChars();
Steve Blocka7e24c12009-10-30 11:49:00 +00009356
9357 // Dispatched behavior.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009358 inline uint16_t ExternalTwoByteStringGet(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00009359
9360 // For regexp code.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009361 inline const uint16_t* ExternalTwoByteStringGetData(unsigned start);
Steve Blocka7e24c12009-10-30 11:49:00 +00009362
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009363 DECLARE_CAST(ExternalTwoByteString)
Steve Blocka7e24c12009-10-30 11:49:00 +00009364
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009365 class BodyDescriptor;
Iain Merrick75681382010-08-19 15:07:18 +01009366
Steve Blocka7e24c12009-10-30 11:49:00 +00009367 private:
9368 DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString);
9369};
9370
9371
9372// Utility superclass for stack-allocated objects that must be updated
9373// on gc. It provides two ways for the gc to update instances, either
9374// iterating or updating after gc.
9375class Relocatable BASE_EMBEDDED {
9376 public:
Steve Block44f0eee2011-05-26 01:26:41 +01009377 explicit inline Relocatable(Isolate* isolate);
9378 inline virtual ~Relocatable();
Steve Blocka7e24c12009-10-30 11:49:00 +00009379 virtual void IterateInstance(ObjectVisitor* v) { }
9380 virtual void PostGarbageCollection() { }
9381
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009382 static void PostGarbageCollectionProcessing(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00009383 static int ArchiveSpacePerThread();
Ben Murdoch257744e2011-11-30 15:57:28 +00009384 static char* ArchiveState(Isolate* isolate, char* to);
9385 static char* RestoreState(Isolate* isolate, char* from);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009386 static void Iterate(Isolate* isolate, ObjectVisitor* v);
Steve Blocka7e24c12009-10-30 11:49:00 +00009387 static void Iterate(ObjectVisitor* v, Relocatable* top);
9388 static char* Iterate(ObjectVisitor* v, char* t);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009389
Steve Blocka7e24c12009-10-30 11:49:00 +00009390 private:
Steve Block44f0eee2011-05-26 01:26:41 +01009391 Isolate* isolate_;
Steve Blocka7e24c12009-10-30 11:49:00 +00009392 Relocatable* prev_;
9393};
9394
9395
9396// A flat string reader provides random access to the contents of a
9397// string independent of the character width of the string. The handle
9398// must be valid as long as the reader is being used.
9399class FlatStringReader : public Relocatable {
9400 public:
Steve Block44f0eee2011-05-26 01:26:41 +01009401 FlatStringReader(Isolate* isolate, Handle<String> str);
9402 FlatStringReader(Isolate* isolate, Vector<const char> input);
Steve Blocka7e24c12009-10-30 11:49:00 +00009403 void PostGarbageCollection();
9404 inline uc32 Get(int index);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009405 template <typename Char>
9406 inline Char Get(int index);
Steve Blocka7e24c12009-10-30 11:49:00 +00009407 int length() { return length_; }
9408 private:
9409 String** str_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009410 bool is_one_byte_;
Steve Blocka7e24c12009-10-30 11:49:00 +00009411 int length_;
9412 const void* start_;
9413};
9414
9415
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009416// This maintains an off-stack representation of the stack frames required
9417// to traverse a ConsString, allowing an entirely iterative and restartable
9418// traversal of the entire string
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009419class ConsStringIterator {
Steve Blocka7e24c12009-10-30 11:49:00 +00009420 public:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009421 inline ConsStringIterator() {}
9422 inline explicit ConsStringIterator(ConsString* cons_string, int offset = 0) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009423 Reset(cons_string, offset);
9424 }
9425 inline void Reset(ConsString* cons_string, int offset = 0) {
9426 depth_ = 0;
9427 // Next will always return NULL.
9428 if (cons_string == NULL) return;
9429 Initialize(cons_string, offset);
9430 }
9431 // Returns NULL when complete.
9432 inline String* Next(int* offset_out) {
9433 *offset_out = 0;
9434 if (depth_ == 0) return NULL;
9435 return Continue(offset_out);
9436 }
9437
9438 private:
9439 static const int kStackSize = 32;
9440 // Use a mask instead of doing modulo operations for stack wrapping.
9441 static const int kDepthMask = kStackSize-1;
9442 STATIC_ASSERT(IS_POWER_OF_TWO(kStackSize));
9443 static inline int OffsetForDepth(int depth);
9444
9445 inline void PushLeft(ConsString* string);
9446 inline void PushRight(ConsString* string);
9447 inline void AdjustMaximumDepth();
9448 inline void Pop();
9449 inline bool StackBlown() { return maximum_depth_ - depth_ == kStackSize; }
9450 void Initialize(ConsString* cons_string, int offset);
9451 String* Continue(int* offset_out);
9452 String* NextLeaf(bool* blew_stack);
9453 String* Search(int* offset_out);
9454
9455 // Stack must always contain only frames for which right traversal
9456 // has not yet been performed.
9457 ConsString* frames_[kStackSize];
9458 ConsString* root_;
9459 int depth_;
9460 int maximum_depth_;
9461 int consumed_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009462 DISALLOW_COPY_AND_ASSIGN(ConsStringIterator);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009463};
9464
9465
9466class StringCharacterStream {
9467 public:
9468 inline StringCharacterStream(String* string,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009469 int offset = 0);
9470 inline uint16_t GetNext();
9471 inline bool HasMore();
9472 inline void Reset(String* string, int offset = 0);
9473 inline void VisitOneByteString(const uint8_t* chars, int length);
9474 inline void VisitTwoByteString(const uint16_t* chars, int length);
9475
9476 private:
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009477 ConsStringIterator iter_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009478 bool is_one_byte_;
9479 union {
9480 const uint8_t* buffer8_;
9481 const uint16_t* buffer16_;
9482 };
9483 const uint8_t* end_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009484 DISALLOW_COPY_AND_ASSIGN(StringCharacterStream);
Steve Blocka7e24c12009-10-30 11:49:00 +00009485};
9486
9487
9488template <typename T>
9489class VectorIterator {
9490 public:
9491 VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { }
9492 explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { }
9493 T GetNext() { return data_[index_++]; }
9494 bool has_more() { return index_ < data_.length(); }
9495 private:
9496 Vector<const T> data_;
9497 int index_;
9498};
9499
9500
9501// The Oddball describes objects null, undefined, true, and false.
9502class Oddball: public HeapObject {
9503 public:
9504 // [to_string]: Cached to_string computed at startup.
9505 DECL_ACCESSORS(to_string, String)
9506
9507 // [to_number]: Cached to_number computed at startup.
9508 DECL_ACCESSORS(to_number, Object)
9509
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009510 // [typeof]: Cached type_of computed at startup.
9511 DECL_ACCESSORS(type_of, String)
9512
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009513 inline byte kind() const;
Steve Block44f0eee2011-05-26 01:26:41 +01009514 inline void set_kind(byte kind);
9515
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009516 // ES6 section 7.1.3 ToNumber for Boolean, Null, Undefined.
9517 MUST_USE_RESULT static inline Handle<Object> ToNumber(Handle<Oddball> input);
9518
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009519 DECLARE_CAST(Oddball)
Steve Blocka7e24c12009-10-30 11:49:00 +00009520
9521 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009522 DECLARE_VERIFIER(Oddball)
Steve Blocka7e24c12009-10-30 11:49:00 +00009523
9524 // Initialize the fields.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009525 static void Initialize(Isolate* isolate, Handle<Oddball> oddball,
9526 const char* to_string, Handle<Object> to_number,
9527 const char* type_of, byte kind);
Steve Blocka7e24c12009-10-30 11:49:00 +00009528
9529 // Layout description.
9530 static const int kToStringOffset = HeapObject::kHeaderSize;
9531 static const int kToNumberOffset = kToStringOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009532 static const int kTypeOfOffset = kToNumberOffset + kPointerSize;
9533 static const int kKindOffset = kTypeOfOffset + kPointerSize;
Steve Block44f0eee2011-05-26 01:26:41 +01009534 static const int kSize = kKindOffset + kPointerSize;
9535
9536 static const byte kFalse = 0;
9537 static const byte kTrue = 1;
9538 static const byte kNotBooleanMask = ~1;
9539 static const byte kTheHole = 2;
9540 static const byte kNull = 3;
Ben Murdoch097c5b22016-05-18 11:27:45 +01009541 static const byte kArgumentsMarker = 4;
Steve Block44f0eee2011-05-26 01:26:41 +01009542 static const byte kUndefined = 5;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009543 static const byte kUninitialized = 6;
9544 static const byte kOther = 7;
9545 static const byte kException = 8;
Steve Blocka7e24c12009-10-30 11:49:00 +00009546
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009547 typedef FixedBodyDescriptor<kToStringOffset, kTypeOfOffset + kPointerSize,
Iain Merrick75681382010-08-19 15:07:18 +01009548 kSize> BodyDescriptor;
9549
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009550 STATIC_ASSERT(kKindOffset == Internals::kOddballKindOffset);
9551 STATIC_ASSERT(kNull == Internals::kNullOddballKind);
9552 STATIC_ASSERT(kUndefined == Internals::kUndefinedOddballKind);
9553
Steve Blocka7e24c12009-10-30 11:49:00 +00009554 private:
9555 DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball);
9556};
9557
9558
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009559class Cell: public HeapObject {
Steve Blocka7e24c12009-10-30 11:49:00 +00009560 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009561 // [value]: value of the cell.
Steve Blocka7e24c12009-10-30 11:49:00 +00009562 DECL_ACCESSORS(value, Object)
9563
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009564 DECLARE_CAST(Cell)
Steve Blocka7e24c12009-10-30 11:49:00 +00009565
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009566 static inline Cell* FromValueAddress(Address value) {
9567 Object* result = FromAddress(value - kValueOffset);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009568 return static_cast<Cell*>(result);
Ben Murdochb0fe1622011-05-05 13:52:32 +01009569 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009570
9571 inline Address ValueAddress() {
9572 return address() + kValueOffset;
9573 }
9574
9575 // Dispatched behavior.
9576 DECLARE_PRINTER(Cell)
9577 DECLARE_VERIFIER(Cell)
Steve Blocka7e24c12009-10-30 11:49:00 +00009578
9579 // Layout description.
9580 static const int kValueOffset = HeapObject::kHeaderSize;
9581 static const int kSize = kValueOffset + kPointerSize;
9582
Iain Merrick75681382010-08-19 15:07:18 +01009583 typedef FixedBodyDescriptor<kValueOffset,
9584 kValueOffset + kPointerSize,
9585 kSize> BodyDescriptor;
9586
Steve Blocka7e24c12009-10-30 11:49:00 +00009587 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009588 DISALLOW_IMPLICIT_CONSTRUCTORS(Cell);
9589};
9590
9591
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009592class PropertyCell : public HeapObject {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009593 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009594 // [property_details]: details of the global property.
9595 DECL_ACCESSORS(property_details_raw, Object)
9596 // [value]: value of the global property.
9597 DECL_ACCESSORS(value, Object)
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009598 // [dependent_code]: dependent code that depends on the type of the global
9599 // property.
9600 DECL_ACCESSORS(dependent_code, DependentCode)
9601
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009602 inline PropertyDetails property_details();
9603 inline void set_property_details(PropertyDetails details);
9604
9605 PropertyCellConstantType GetConstantType();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009606
9607 // Computes the new type of the cell's contents for the given value, but
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009608 // without actually modifying the details.
9609 static PropertyCellType UpdatedType(Handle<PropertyCell> cell,
9610 Handle<Object> value,
9611 PropertyDetails details);
9612 static void UpdateCell(Handle<GlobalDictionary> dictionary, int entry,
9613 Handle<Object> value, PropertyDetails details);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009614
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009615 static Handle<PropertyCell> InvalidateEntry(
9616 Handle<GlobalDictionary> dictionary, int entry);
9617
9618 static void SetValueWithInvalidation(Handle<PropertyCell> cell,
9619 Handle<Object> new_value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009620
9621 DECLARE_CAST(PropertyCell)
9622
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009623 // Dispatched behavior.
9624 DECLARE_PRINTER(PropertyCell)
9625 DECLARE_VERIFIER(PropertyCell)
9626
9627 // Layout description.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009628 static const int kDetailsOffset = HeapObject::kHeaderSize;
9629 static const int kValueOffset = kDetailsOffset + kPointerSize;
9630 static const int kDependentCodeOffset = kValueOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009631 static const int kSize = kDependentCodeOffset + kPointerSize;
9632
9633 static const int kPointerFieldsBeginOffset = kValueOffset;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009634 static const int kPointerFieldsEndOffset = kSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009635
9636 typedef FixedBodyDescriptor<kValueOffset,
9637 kSize,
9638 kSize> BodyDescriptor;
9639
9640 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009641 DISALLOW_IMPLICIT_CONSTRUCTORS(PropertyCell);
Steve Blocka7e24c12009-10-30 11:49:00 +00009642};
9643
9644
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009645class WeakCell : public HeapObject {
9646 public:
9647 inline Object* value() const;
9648
9649 // This should not be called by anyone except GC.
9650 inline void clear();
9651
9652 // This should not be called by anyone except allocator.
9653 inline void initialize(HeapObject* value);
9654
9655 inline bool cleared() const;
9656
9657 DECL_ACCESSORS(next, Object)
9658
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009659 inline void clear_next(Object* the_hole_value);
9660
9661 inline bool next_cleared();
9662
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009663 DECLARE_CAST(WeakCell)
9664
9665 DECLARE_PRINTER(WeakCell)
9666 DECLARE_VERIFIER(WeakCell)
9667
9668 // Layout description.
9669 static const int kValueOffset = HeapObject::kHeaderSize;
9670 static const int kNextOffset = kValueOffset + kPointerSize;
9671 static const int kSize = kNextOffset + kPointerSize;
9672
9673 typedef FixedBodyDescriptor<kValueOffset, kSize, kSize> BodyDescriptor;
9674
9675 private:
9676 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakCell);
9677};
9678
9679
Ben Murdoch257744e2011-11-30 15:57:28 +00009680// The JSProxy describes EcmaScript Harmony proxies
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00009681class JSProxy: public JSReceiver {
Steve Blocka7e24c12009-10-30 11:49:00 +00009682 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009683 MUST_USE_RESULT static MaybeHandle<JSProxy> New(Isolate* isolate,
9684 Handle<Object>,
9685 Handle<Object>);
9686
Ben Murdoch257744e2011-11-30 15:57:28 +00009687 // [handler]: The handler property.
9688 DECL_ACCESSORS(handler, Object)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009689 // [target]: The target property.
9690 DECL_ACCESSORS(target, JSReceiver)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009691 // [hash]: The hash code property (undefined if not initialized yet).
9692 DECL_ACCESSORS(hash, Object)
9693
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009694 static MaybeHandle<Context> GetFunctionRealm(Handle<JSProxy> proxy);
9695
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009696 DECLARE_CAST(JSProxy)
Steve Blocka7e24c12009-10-30 11:49:00 +00009697
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009698 INLINE(bool IsRevoked() const);
9699 static void Revoke(Handle<JSProxy> proxy);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00009700
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009701 // ES6 9.5.1
9702 static MaybeHandle<Object> GetPrototype(Handle<JSProxy> receiver);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009703
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009704 // ES6 9.5.2
9705 MUST_USE_RESULT static Maybe<bool> SetPrototype(Handle<JSProxy> proxy,
9706 Handle<Object> value,
9707 bool from_javascript,
9708 ShouldThrow should_throw);
9709 // ES6 9.5.3
9710 MUST_USE_RESULT static Maybe<bool> IsExtensible(Handle<JSProxy> proxy);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00009711
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009712 // ES6 9.5.4 (when passed DONT_THROW)
9713 MUST_USE_RESULT static Maybe<bool> PreventExtensions(
9714 Handle<JSProxy> proxy, ShouldThrow should_throw);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00009715
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009716 // ES6 9.5.5
9717 MUST_USE_RESULT static Maybe<bool> GetOwnPropertyDescriptor(
9718 Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name,
9719 PropertyDescriptor* desc);
Ben Murdoch589d6972011-11-30 16:04:58 +00009720
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009721 // ES6 9.5.6
9722 MUST_USE_RESULT static Maybe<bool> DefineOwnProperty(
9723 Isolate* isolate, Handle<JSProxy> object, Handle<Object> key,
9724 PropertyDescriptor* desc, ShouldThrow should_throw);
9725
9726 // ES6 9.5.7
9727 MUST_USE_RESULT static Maybe<bool> HasProperty(Isolate* isolate,
9728 Handle<JSProxy> proxy,
9729 Handle<Name> name);
9730
9731 // ES6 9.5.8
9732 MUST_USE_RESULT static MaybeHandle<Object> GetProperty(
9733 Isolate* isolate, Handle<JSProxy> proxy, Handle<Name> name,
Ben Murdoch097c5b22016-05-18 11:27:45 +01009734 Handle<Object> receiver);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009735
9736 // ES6 9.5.9
9737 MUST_USE_RESULT static Maybe<bool> SetProperty(Handle<JSProxy> proxy,
9738 Handle<Name> name,
9739 Handle<Object> value,
9740 Handle<Object> receiver,
9741 LanguageMode language_mode);
9742
9743 // ES6 9.5.10 (when passed SLOPPY)
9744 MUST_USE_RESULT static Maybe<bool> DeletePropertyOrElement(
9745 Handle<JSProxy> proxy, Handle<Name> name, LanguageMode language_mode);
9746
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009747 // ES6 9.5.12
9748 MUST_USE_RESULT static Maybe<bool> OwnPropertyKeys(
9749 Isolate* isolate, Handle<JSReceiver> receiver, Handle<JSProxy> proxy,
9750 PropertyFilter filter, KeyAccumulator* accumulator);
9751
9752 MUST_USE_RESULT static Maybe<PropertyAttributes> GetPropertyAttributes(
9753 LookupIterator* it);
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009754
Steve Blocka7e24c12009-10-30 11:49:00 +00009755 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009756 DECLARE_PRINTER(JSProxy)
9757 DECLARE_VERIFIER(JSProxy)
Ben Murdoch257744e2011-11-30 15:57:28 +00009758
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009759 // Layout description.
9760 static const int kTargetOffset = JSReceiver::kHeaderSize;
9761 static const int kHandlerOffset = kTargetOffset + kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009762 static const int kHashOffset = kHandlerOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009763 static const int kSize = kHashOffset + kPointerSize;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00009764
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009765 typedef FixedBodyDescriptor<JSReceiver::kPropertiesOffset, kSize, kSize>
9766 BodyDescriptor;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009767
9768 MUST_USE_RESULT Object* GetIdentityHash();
9769
9770 static Handle<Smi> GetOrCreateIdentityHash(Handle<JSProxy> proxy);
9771
Ben Murdoch097c5b22016-05-18 11:27:45 +01009772 static Maybe<bool> SetPrivateProperty(Isolate* isolate, Handle<JSProxy> proxy,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009773 Handle<Symbol> private_name,
9774 PropertyDescriptor* desc,
9775 ShouldThrow should_throw);
9776
Ben Murdoch097c5b22016-05-18 11:27:45 +01009777 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009778 DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy);
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00009779};
9780
Ben Murdoch257744e2011-11-30 15:57:28 +00009781
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009782class JSCollection : public JSObject {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009783 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009784 // [table]: the backing hash table
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009785 DECL_ACCESSORS(table, Object)
9786
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009787 static const int kTableOffset = JSObject::kHeaderSize;
9788 static const int kSize = kTableOffset + kPointerSize;
9789
9790 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009791 DISALLOW_IMPLICIT_CONSTRUCTORS(JSCollection);
9792};
9793
9794
9795// The JSSet describes EcmaScript Harmony sets
9796class JSSet : public JSCollection {
9797 public:
9798 DECLARE_CAST(JSSet)
9799
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009800 static void Initialize(Handle<JSSet> set, Isolate* isolate);
9801 static void Clear(Handle<JSSet> set);
9802
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009803 // Dispatched behavior.
9804 DECLARE_PRINTER(JSSet)
9805 DECLARE_VERIFIER(JSSet)
9806
9807 private:
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009808 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSet);
9809};
9810
9811
9812// The JSMap describes EcmaScript Harmony maps
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009813class JSMap : public JSCollection {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009814 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009815 DECLARE_CAST(JSMap)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009816
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009817 static void Initialize(Handle<JSMap> map, Isolate* isolate);
9818 static void Clear(Handle<JSMap> map);
9819
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009820 // Dispatched behavior.
9821 DECLARE_PRINTER(JSMap)
9822 DECLARE_VERIFIER(JSMap)
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009823
9824 private:
9825 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMap);
9826};
9827
9828
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009829// OrderedHashTableIterator is an iterator that iterates over the keys and
9830// values of an OrderedHashTable.
9831//
9832// The iterator has a reference to the underlying OrderedHashTable data,
9833// [table], as well as the current [index] the iterator is at.
9834//
9835// When the OrderedHashTable is rehashed it adds a reference from the old table
9836// to the new table as well as storing enough data about the changes so that the
9837// iterator [index] can be adjusted accordingly.
9838//
9839// When the [Next] result from the iterator is requested, the iterator checks if
9840// there is a newer table that it needs to transition to.
9841template<class Derived, class TableType>
9842class OrderedHashTableIterator: public JSObject {
9843 public:
9844 // [table]: the backing hash table mapping keys to values.
9845 DECL_ACCESSORS(table, Object)
9846
9847 // [index]: The index into the data table.
9848 DECL_ACCESSORS(index, Object)
9849
9850 // [kind]: The kind of iteration this is. One of the [Kind] enum values.
9851 DECL_ACCESSORS(kind, Object)
9852
9853#ifdef OBJECT_PRINT
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009854 void OrderedHashTableIteratorPrint(std::ostream& os); // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009855#endif
9856
9857 static const int kTableOffset = JSObject::kHeaderSize;
9858 static const int kIndexOffset = kTableOffset + kPointerSize;
9859 static const int kKindOffset = kIndexOffset + kPointerSize;
9860 static const int kSize = kKindOffset + kPointerSize;
9861
9862 enum Kind {
9863 kKindKeys = 1,
9864 kKindValues = 2,
9865 kKindEntries = 3
9866 };
9867
9868 // Whether the iterator has more elements. This needs to be called before
9869 // calling |CurrentKey| and/or |CurrentValue|.
9870 bool HasMore();
9871
9872 // Move the index forward one.
9873 void MoveNext() {
9874 set_index(Smi::FromInt(Smi::cast(index())->value() + 1));
9875 }
9876
9877 // Populates the array with the next key and value and then moves the iterator
9878 // forward.
9879 // This returns the |kind| or 0 if the iterator is already at the end.
9880 Smi* Next(JSArray* value_array);
9881
9882 // Returns the current key of the iterator. This should only be called when
9883 // |HasMore| returns true.
9884 inline Object* CurrentKey();
9885
9886 private:
9887 // Transitions the iterator to the non obsolete backing store. This is a NOP
9888 // if the [table] is not obsolete.
9889 void Transition();
9890
9891 DISALLOW_IMPLICIT_CONSTRUCTORS(OrderedHashTableIterator);
9892};
9893
9894
9895class JSSetIterator: public OrderedHashTableIterator<JSSetIterator,
9896 OrderedHashSet> {
9897 public:
9898 // Dispatched behavior.
9899 DECLARE_PRINTER(JSSetIterator)
9900 DECLARE_VERIFIER(JSSetIterator)
9901
9902 DECLARE_CAST(JSSetIterator)
9903
9904 // Called by |Next| to populate the array. This allows the subclasses to
9905 // populate the array differently.
9906 inline void PopulateValueArray(FixedArray* array);
9907
9908 private:
9909 DISALLOW_IMPLICIT_CONSTRUCTORS(JSSetIterator);
9910};
9911
9912
9913class JSMapIterator: public OrderedHashTableIterator<JSMapIterator,
9914 OrderedHashMap> {
9915 public:
9916 // Dispatched behavior.
9917 DECLARE_PRINTER(JSMapIterator)
9918 DECLARE_VERIFIER(JSMapIterator)
9919
9920 DECLARE_CAST(JSMapIterator)
9921
9922 // Called by |Next| to populate the array. This allows the subclasses to
9923 // populate the array differently.
9924 inline void PopulateValueArray(FixedArray* array);
9925
9926 private:
9927 // Returns the current value of the iterator. This should only be called when
9928 // |HasMore| returns true.
9929 inline Object* CurrentValue();
9930
9931 DISALLOW_IMPLICIT_CONSTRUCTORS(JSMapIterator);
9932};
9933
9934
9935// Base class for both JSWeakMap and JSWeakSet
9936class JSWeakCollection: public JSObject {
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009937 public:
9938 // [table]: the backing hash table mapping keys to values.
Ben Murdoch3ef787d2012-04-12 10:51:47 +01009939 DECL_ACCESSORS(table, Object)
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009940
9941 // [next]: linked list of encountered weak maps during GC.
9942 DECL_ACCESSORS(next, Object)
9943
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009944 static void Initialize(Handle<JSWeakCollection> collection, Isolate* isolate);
9945 static void Set(Handle<JSWeakCollection> collection, Handle<Object> key,
9946 Handle<Object> value, int32_t hash);
9947 static bool Delete(Handle<JSWeakCollection> collection, Handle<Object> key,
9948 int32_t hash);
9949
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009950 static const int kTableOffset = JSObject::kHeaderSize;
9951 static const int kNextOffset = kTableOffset + kPointerSize;
9952 static const int kSize = kNextOffset + kPointerSize;
9953
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00009954 // Visiting policy defines whether the table and next collection fields
9955 // should be visited or not.
9956 enum BodyVisitingPolicy { kVisitStrong, kVisitWeak };
9957
9958 // Iterates the function object according to the visiting policy.
9959 template <BodyVisitingPolicy>
9960 class BodyDescriptorImpl;
9961
9962 // Visit the whole object.
9963 typedef BodyDescriptorImpl<kVisitStrong> BodyDescriptor;
9964
9965 // Don't visit table and next collection fields.
9966 typedef BodyDescriptorImpl<kVisitWeak> BodyDescriptorWeak;
9967
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009968 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009969 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakCollection);
9970};
9971
9972
9973// The JSWeakMap describes EcmaScript Harmony weak maps
9974class JSWeakMap: public JSWeakCollection {
9975 public:
9976 DECLARE_CAST(JSWeakMap)
9977
9978 // Dispatched behavior.
9979 DECLARE_PRINTER(JSWeakMap)
9980 DECLARE_VERIFIER(JSWeakMap)
9981
9982 private:
Ben Murdoch69a99ed2011-11-30 16:03:39 +00009983 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap);
9984};
9985
9986
Ben Murdochb8a8cc12014-11-26 15:28:44 +00009987// The JSWeakSet describes EcmaScript Harmony weak sets
9988class JSWeakSet: public JSWeakCollection {
9989 public:
9990 DECLARE_CAST(JSWeakSet)
9991
9992 // Dispatched behavior.
9993 DECLARE_PRINTER(JSWeakSet)
9994 DECLARE_VERIFIER(JSWeakSet)
9995
9996 private:
9997 DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakSet);
9998};
9999
10000
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010001// Whether a JSArrayBuffer is a SharedArrayBuffer or not.
10002enum class SharedFlag { kNotShared, kShared };
10003
10004
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010005class JSArrayBuffer: public JSObject {
10006 public:
10007 // [backing_store]: backing memory for this array
10008 DECL_ACCESSORS(backing_store, void)
10009
10010 // [byte_length]: length in bytes
10011 DECL_ACCESSORS(byte_length, Object)
10012
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010013 inline uint32_t bit_field() const;
10014 inline void set_bit_field(uint32_t bits);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010015
10016 inline bool is_external();
10017 inline void set_is_external(bool value);
10018
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010019 inline bool is_neuterable();
10020 inline void set_is_neuterable(bool value);
10021
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010022 inline bool was_neutered();
10023 inline void set_was_neutered(bool value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010024
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010025 inline bool is_shared();
10026 inline void set_is_shared(bool value);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010027
10028 DECLARE_CAST(JSArrayBuffer)
10029
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010030 void Neuter();
10031
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010032 static void Setup(Handle<JSArrayBuffer> array_buffer, Isolate* isolate,
10033 bool is_external, void* data, size_t allocated_length,
10034 SharedFlag shared = SharedFlag::kNotShared);
10035
10036 static bool SetupAllocatingData(Handle<JSArrayBuffer> array_buffer,
10037 Isolate* isolate, size_t allocated_length,
10038 bool initialize = true,
10039 SharedFlag shared = SharedFlag::kNotShared);
10040
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010041 // Dispatched behavior.
10042 DECLARE_PRINTER(JSArrayBuffer)
10043 DECLARE_VERIFIER(JSArrayBuffer)
10044
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010045 static const int kByteLengthOffset = JSObject::kHeaderSize;
10046 static const int kBackingStoreOffset = kByteLengthOffset + kPointerSize;
10047 static const int kBitFieldSlot = kBackingStoreOffset + kPointerSize;
10048#if V8_TARGET_LITTLE_ENDIAN || !V8_HOST_ARCH_64_BIT
10049 static const int kBitFieldOffset = kBitFieldSlot;
10050#else
10051 static const int kBitFieldOffset = kBitFieldSlot + kIntSize;
10052#endif
10053 static const int kSize = kBitFieldSlot + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010054
10055 static const int kSizeWithInternalFields =
10056 kSize + v8::ArrayBuffer::kInternalFieldCount * kPointerSize;
10057
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010058 // Iterates all fields in the object including internal ones except
10059 // kBackingStoreOffset and kBitFieldSlot.
10060 class BodyDescriptor;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010061
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010062 class IsExternal : public BitField<bool, 1, 1> {};
10063 class IsNeuterable : public BitField<bool, 2, 1> {};
10064 class WasNeutered : public BitField<bool, 3, 1> {};
10065 class IsShared : public BitField<bool, 4, 1> {};
10066
10067 private:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010068 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBuffer);
10069};
10070
10071
10072class JSArrayBufferView: public JSObject {
10073 public:
10074 // [buffer]: ArrayBuffer that this typed array views.
10075 DECL_ACCESSORS(buffer, Object)
10076
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010077 // [byte_offset]: offset of typed array in bytes.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010078 DECL_ACCESSORS(byte_offset, Object)
10079
10080 // [byte_length]: length of typed array in bytes.
10081 DECL_ACCESSORS(byte_length, Object)
10082
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010083 DECLARE_CAST(JSArrayBufferView)
10084
10085 DECLARE_VERIFIER(JSArrayBufferView)
10086
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010087 inline bool WasNeutered() const;
10088
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010089 static const int kBufferOffset = JSObject::kHeaderSize;
10090 static const int kByteOffsetOffset = kBufferOffset + kPointerSize;
10091 static const int kByteLengthOffset = kByteOffsetOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010092 static const int kViewSize = kByteLengthOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010093
10094 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010095#ifdef VERIFY_HEAP
10096 DECL_ACCESSORS(raw_byte_offset, Object)
10097 DECL_ACCESSORS(raw_byte_length, Object)
10098#endif
10099
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010100 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArrayBufferView);
10101};
10102
10103
10104class JSTypedArray: public JSArrayBufferView {
10105 public:
10106 // [length]: length of typed array in elements.
10107 DECL_ACCESSORS(length, Object)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010108 inline uint32_t length_value() const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010109
10110 DECLARE_CAST(JSTypedArray)
10111
10112 ExternalArrayType type();
10113 size_t element_size();
10114
10115 Handle<JSArrayBuffer> GetBuffer();
10116
10117 // Dispatched behavior.
10118 DECLARE_PRINTER(JSTypedArray)
10119 DECLARE_VERIFIER(JSTypedArray)
10120
10121 static const int kLengthOffset = kViewSize + kPointerSize;
10122 static const int kSize = kLengthOffset + kPointerSize;
10123
10124 static const int kSizeWithInternalFields =
10125 kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize;
10126
10127 private:
10128 static Handle<JSArrayBuffer> MaterializeArrayBuffer(
10129 Handle<JSTypedArray> typed_array);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010130#ifdef VERIFY_HEAP
10131 DECL_ACCESSORS(raw_length, Object)
10132#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010133
10134 DISALLOW_IMPLICIT_CONSTRUCTORS(JSTypedArray);
10135};
10136
10137
10138class JSDataView: public JSArrayBufferView {
10139 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010140 DECLARE_CAST(JSDataView)
10141
10142 // Dispatched behavior.
10143 DECLARE_PRINTER(JSDataView)
10144 DECLARE_VERIFIER(JSDataView)
10145
10146 static const int kSize = kViewSize;
10147
10148 static const int kSizeWithInternalFields =
10149 kSize + v8::ArrayBufferView::kInternalFieldCount * kPointerSize;
10150
10151 private:
10152 DISALLOW_IMPLICIT_CONSTRUCTORS(JSDataView);
10153};
10154
10155
Ben Murdoch257744e2011-11-30 15:57:28 +000010156// Foreign describes objects pointing from JavaScript to C structures.
Ben Murdoch257744e2011-11-30 15:57:28 +000010157class Foreign: public HeapObject {
10158 public:
10159 // [address]: field containing the address.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010160 inline Address foreign_address();
10161 inline void set_foreign_address(Address value);
Ben Murdoch257744e2011-11-30 15:57:28 +000010162
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010163 DECLARE_CAST(Foreign)
Ben Murdoch257744e2011-11-30 15:57:28 +000010164
10165 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010166 DECLARE_PRINTER(Foreign)
10167 DECLARE_VERIFIER(Foreign)
Steve Blocka7e24c12009-10-30 11:49:00 +000010168
10169 // Layout description.
10170
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010171 static const int kForeignAddressOffset = HeapObject::kHeaderSize;
10172 static const int kSize = kForeignAddressOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +000010173
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010174 STATIC_ASSERT(kForeignAddressOffset == Internals::kForeignAddressOffset);
Steve Blocka7e24c12009-10-30 11:49:00 +000010175
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010176 class BodyDescriptor;
10177
Steve Blocka7e24c12009-10-30 11:49:00 +000010178 private:
Ben Murdoch257744e2011-11-30 15:57:28 +000010179 DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign);
Steve Blocka7e24c12009-10-30 11:49:00 +000010180};
10181
10182
10183// The JSArray describes JavaScript Arrays
10184// Such an array can be in one of two modes:
10185// - fast, backing storage is a FixedArray and length <= elements.length();
10186// Please note: push and pop can be used to grow and shrink the array.
10187// - slow, backing storage is a HashTable with numbers as keys.
10188class JSArray: public JSObject {
10189 public:
10190 // [length]: The length property.
10191 DECL_ACCESSORS(length, Object)
10192
Leon Clarke4515c472010-02-03 11:58:03 +000010193 // Overload the length setter to skip write barrier when the length
10194 // is set to a smi. This matches the set function on FixedArray.
10195 inline void set_length(Smi* length);
10196
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010197 static bool HasReadOnlyLength(Handle<JSArray> array);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010198 static bool WouldChangeReadOnlyLength(Handle<JSArray> array, uint32_t index);
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010199
Steve Blocka7e24c12009-10-30 11:49:00 +000010200 // Initialize the array with the given capacity. The function may
10201 // fail due to out-of-memory situations, but only if the requested
10202 // capacity is non-zero.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010203 static void Initialize(Handle<JSArray> array, int capacity, int length = 0);
Steve Blocka7e24c12009-10-30 11:49:00 +000010204
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010205 // If the JSArray has fast elements, and new_length would result in
10206 // normalization, returns true.
10207 bool SetLengthWouldNormalize(uint32_t new_length);
10208 static inline bool SetLengthWouldNormalize(Heap* heap, uint32_t new_length);
10209
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010210 // Initializes the array to a certain length.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010211 inline bool AllowsSetLength();
10212
10213 static void SetLength(Handle<JSArray> array, uint32_t length);
10214 // Same as above but will also queue splice records if |array| is observed.
10215 static MaybeHandle<Object> ObservableSetLength(Handle<JSArray> array,
10216 uint32_t length);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010217
Steve Blocka7e24c12009-10-30 11:49:00 +000010218 // Set the content of the array to the content of storage.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010219 static inline void SetContent(Handle<JSArray> array,
10220 Handle<FixedArrayBase> storage);
Steve Blocka7e24c12009-10-30 11:49:00 +000010221
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010222 // ES6 9.4.2.1
10223 MUST_USE_RESULT static Maybe<bool> DefineOwnProperty(
10224 Isolate* isolate, Handle<JSArray> o, Handle<Object> name,
10225 PropertyDescriptor* desc, ShouldThrow should_throw);
10226
10227 static bool AnythingToArrayLength(Isolate* isolate,
10228 Handle<Object> length_object,
10229 uint32_t* output);
10230 MUST_USE_RESULT static Maybe<bool> ArraySetLength(Isolate* isolate,
10231 Handle<JSArray> a,
10232 PropertyDescriptor* desc,
10233 ShouldThrow should_throw);
10234
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010235 DECLARE_CAST(JSArray)
Steve Blocka7e24c12009-10-30 11:49:00 +000010236
Steve Blocka7e24c12009-10-30 11:49:00 +000010237 // Dispatched behavior.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010238 DECLARE_PRINTER(JSArray)
10239 DECLARE_VERIFIER(JSArray)
Steve Blocka7e24c12009-10-30 11:49:00 +000010240
10241 // Number of element slots to pre-allocate for an empty array.
10242 static const int kPreallocatedArrayElements = 4;
10243
10244 // Layout description.
10245 static const int kLengthOffset = JSObject::kHeaderSize;
10246 static const int kSize = kLengthOffset + kPointerSize;
10247
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010248 // 600 * KB is the Page::kMaxRegularHeapObjectSize defined in spaces.h which
10249 // we do not want to include in objects.h
10250 // Note that Page::kMaxRegularHeapObjectSize has to be in sync with
10251 // kInitialMaxFastElementArray which is checked in a DCHECK in heap.cc.
10252 static const int kInitialMaxFastElementArray =
10253 (600 * KB - FixedArray::kHeaderSize - kSize - AllocationMemento::kSize) /
10254 kPointerSize;
10255
Steve Blocka7e24c12009-10-30 11:49:00 +000010256 private:
Steve Blocka7e24c12009-10-30 11:49:00 +000010257 DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
10258};
10259
10260
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010261Handle<Object> CacheInitialJSArrayMaps(Handle<Context> native_context,
10262 Handle<Map> initial_map);
10263
10264
Steve Block6ded16b2010-05-10 14:33:55 +010010265// JSRegExpResult is just a JSArray with a specific initial map.
10266// This initial map adds in-object properties for "index" and "input"
10267// properties, as assigned by RegExp.prototype.exec, which allows
10268// faster creation of RegExp exec results.
10269// This class just holds constants used when creating the result.
10270// After creation the result must be treated as a JSArray in all regards.
10271class JSRegExpResult: public JSArray {
10272 public:
10273 // Offsets of object fields.
10274 static const int kIndexOffset = JSArray::kSize;
10275 static const int kInputOffset = kIndexOffset + kPointerSize;
10276 static const int kSize = kInputOffset + kPointerSize;
10277 // Indices of in-object properties.
10278 static const int kIndexIndex = 0;
10279 static const int kInputIndex = 1;
10280 private:
10281 DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult);
10282};
10283
10284
Ben Murdoch097c5b22016-05-18 11:27:45 +010010285// An accessor must have a getter, but can have no setter.
10286//
10287// When setting a property, V8 searches accessors in prototypes.
10288// If an accessor was found and it does not have a setter,
10289// the request is ignored.
10290//
10291// If the accessor in the prototype has the READ_ONLY property attribute, then
10292// a new value is added to the derived object when the property is set.
10293// This shadows the accessor in the prototype.
Steve Blocka7e24c12009-10-30 11:49:00 +000010294class AccessorInfo: public Struct {
10295 public:
Steve Blocka7e24c12009-10-30 11:49:00 +000010296 DECL_ACCESSORS(name, Object)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010297 DECL_INT_ACCESSORS(flag)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010298 DECL_ACCESSORS(expected_receiver_type, Object)
Ben Murdoch097c5b22016-05-18 11:27:45 +010010299 DECL_ACCESSORS(getter, Object)
10300 DECL_ACCESSORS(setter, Object)
10301 DECL_ACCESSORS(data, Object)
10302
10303 // Dispatched behavior.
10304 DECLARE_PRINTER(AccessorInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010305
10306 inline bool all_can_read();
10307 inline void set_all_can_read(bool value);
10308
10309 inline bool all_can_write();
10310 inline void set_all_can_write(bool value);
10311
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010312 inline bool is_special_data_property();
10313 inline void set_is_special_data_property(bool value);
10314
Steve Blocka7e24c12009-10-30 11:49:00 +000010315 inline PropertyAttributes property_attributes();
10316 inline void set_property_attributes(PropertyAttributes attributes);
10317
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010318 // Checks whether the given receiver is compatible with this accessor.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010319 static bool IsCompatibleReceiverMap(Isolate* isolate,
10320 Handle<AccessorInfo> info,
10321 Handle<Map> map);
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010322 inline bool IsCompatibleReceiver(Object* receiver);
Steve Blocka7e24c12009-10-30 11:49:00 +000010323
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010324 DECLARE_CAST(AccessorInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010325
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010326 // Dispatched behavior.
10327 DECLARE_VERIFIER(AccessorInfo)
10328
10329 // Append all descriptors to the array that are not already there.
10330 // Return number added.
10331 static int AppendUnique(Handle<Object> descriptors,
10332 Handle<FixedArray> array,
10333 int valid_descriptors);
10334
10335 static const int kNameOffset = HeapObject::kHeaderSize;
Steve Blocka7e24c12009-10-30 11:49:00 +000010336 static const int kFlagOffset = kNameOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010337 static const int kExpectedReceiverTypeOffset = kFlagOffset + kPointerSize;
Ben Murdoch097c5b22016-05-18 11:27:45 +010010338 static const int kGetterOffset = kExpectedReceiverTypeOffset + kPointerSize;
10339 static const int kSetterOffset = kGetterOffset + kPointerSize;
10340 static const int kDataOffset = kSetterOffset + kPointerSize;
10341 static const int kSize = kDataOffset + kPointerSize;
10342
Steve Blocka7e24c12009-10-30 11:49:00 +000010343
10344 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010345 inline bool HasExpectedReceiverType();
10346
Steve Blocka7e24c12009-10-30 11:49:00 +000010347 // Bit positions in flag.
10348 static const int kAllCanReadBit = 0;
10349 static const int kAllCanWriteBit = 1;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010350 static const int kSpecialDataProperty = 2;
10351 class AttributesField : public BitField<PropertyAttributes, 3, 3> {};
Steve Blocka7e24c12009-10-30 11:49:00 +000010352
10353 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo);
10354};
10355
10356
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010357// Support for JavaScript accessors: A pair of a getter and a setter. Each
10358// accessor can either be
10359// * a pointer to a JavaScript function or proxy: a real accessor
10360// * undefined: considered an accessor by the spec, too, strangely enough
10361// * the hole: an accessor which has not been set
10362// * a pointer to a map: a transition used to ensure map sharing
10363class AccessorPair: public Struct {
10364 public:
10365 DECL_ACCESSORS(getter, Object)
10366 DECL_ACCESSORS(setter, Object)
10367
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010368 DECLARE_CAST(AccessorPair)
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010369
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010370 static Handle<AccessorPair> Copy(Handle<AccessorPair> pair);
10371
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010372 inline Object* get(AccessorComponent component);
10373 inline void set(AccessorComponent component, Object* value);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010374
10375 // Note: Returns undefined instead in case of a hole.
Ben Murdoch097c5b22016-05-18 11:27:45 +010010376 static Handle<Object> GetComponent(Handle<AccessorPair> accessor_pair,
10377 AccessorComponent component);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010378
10379 // Set both components, skipping arguments which are a JavaScript null.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010380 inline void SetComponents(Object* getter, Object* setter);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010381
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010382 inline bool Equals(AccessorPair* pair);
10383 inline bool Equals(Object* getter_value, Object* setter_value);
10384
10385 inline bool ContainsAccessor();
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010386
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010387 // Dispatched behavior.
10388 DECLARE_PRINTER(AccessorPair)
10389 DECLARE_VERIFIER(AccessorPair)
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010390
10391 static const int kGetterOffset = HeapObject::kHeaderSize;
10392 static const int kSetterOffset = kGetterOffset + kPointerSize;
10393 static const int kSize = kSetterOffset + kPointerSize;
10394
10395 private:
10396 // Strangely enough, in addition to functions and harmony proxies, the spec
10397 // requires us to consider undefined as a kind of accessor, too:
10398 // var obj = {};
10399 // Object.defineProperty(obj, "foo", {get: undefined});
10400 // assertTrue("foo" in obj);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010401 inline bool IsJSAccessor(Object* obj);
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010402
10403 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorPair);
10404};
10405
10406
Steve Blocka7e24c12009-10-30 11:49:00 +000010407class AccessCheckInfo: public Struct {
10408 public:
10409 DECL_ACCESSORS(named_callback, Object)
10410 DECL_ACCESSORS(indexed_callback, Object)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010411 DECL_ACCESSORS(callback, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +000010412 DECL_ACCESSORS(data, Object)
10413
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010414 DECLARE_CAST(AccessCheckInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010415
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010416 // Dispatched behavior.
10417 DECLARE_PRINTER(AccessCheckInfo)
10418 DECLARE_VERIFIER(AccessCheckInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010419
10420 static const int kNamedCallbackOffset = HeapObject::kHeaderSize;
10421 static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010422 static const int kCallbackOffset = kIndexedCallbackOffset + kPointerSize;
10423 static const int kDataOffset = kCallbackOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +000010424 static const int kSize = kDataOffset + kPointerSize;
10425
10426 private:
10427 DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo);
10428};
10429
10430
10431class InterceptorInfo: public Struct {
10432 public:
10433 DECL_ACCESSORS(getter, Object)
10434 DECL_ACCESSORS(setter, Object)
10435 DECL_ACCESSORS(query, Object)
10436 DECL_ACCESSORS(deleter, Object)
10437 DECL_ACCESSORS(enumerator, Object)
10438 DECL_ACCESSORS(data, Object)
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010439 DECL_BOOLEAN_ACCESSORS(can_intercept_symbols)
10440 DECL_BOOLEAN_ACCESSORS(all_can_read)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010441 DECL_BOOLEAN_ACCESSORS(non_masking)
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010442
10443 inline int flags() const;
10444 inline void set_flags(int flags);
Steve Blocka7e24c12009-10-30 11:49:00 +000010445
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010446 DECLARE_CAST(InterceptorInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010447
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010448 // Dispatched behavior.
10449 DECLARE_PRINTER(InterceptorInfo)
10450 DECLARE_VERIFIER(InterceptorInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010451
10452 static const int kGetterOffset = HeapObject::kHeaderSize;
10453 static const int kSetterOffset = kGetterOffset + kPointerSize;
10454 static const int kQueryOffset = kSetterOffset + kPointerSize;
10455 static const int kDeleterOffset = kQueryOffset + kPointerSize;
10456 static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
10457 static const int kDataOffset = kEnumeratorOffset + kPointerSize;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010458 static const int kFlagsOffset = kDataOffset + kPointerSize;
10459 static const int kSize = kFlagsOffset + kPointerSize;
10460
10461 static const int kCanInterceptSymbolsBit = 0;
10462 static const int kAllCanReadBit = 1;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010463 static const int kNonMasking = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +000010464
10465 private:
10466 DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
10467};
10468
10469
10470class CallHandlerInfo: public Struct {
10471 public:
10472 DECL_ACCESSORS(callback, Object)
10473 DECL_ACCESSORS(data, Object)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010474 DECL_ACCESSORS(fast_handler, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +000010475
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010476 DECLARE_CAST(CallHandlerInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010477
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010478 // Dispatched behavior.
10479 DECLARE_PRINTER(CallHandlerInfo)
10480 DECLARE_VERIFIER(CallHandlerInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010481
10482 static const int kCallbackOffset = HeapObject::kHeaderSize;
10483 static const int kDataOffset = kCallbackOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010484 static const int kFastHandlerOffset = kDataOffset + kPointerSize;
10485 static const int kSize = kFastHandlerOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +000010486
10487 private:
10488 DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
10489};
10490
10491
10492class TemplateInfo: public Struct {
10493 public:
10494 DECL_ACCESSORS(tag, Object)
Ben Murdoch097c5b22016-05-18 11:27:45 +010010495 DECL_ACCESSORS(serial_number, Object)
10496 DECL_INT_ACCESSORS(number_of_properties)
Steve Blocka7e24c12009-10-30 11:49:00 +000010497 DECL_ACCESSORS(property_list, Object)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010498 DECL_ACCESSORS(property_accessors, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +000010499
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010500 DECLARE_VERIFIER(TemplateInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010501
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010502 static const int kTagOffset = HeapObject::kHeaderSize;
Ben Murdoch097c5b22016-05-18 11:27:45 +010010503 static const int kSerialNumberOffset = kTagOffset + kPointerSize;
10504 static const int kNumberOfProperties = kSerialNumberOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010505 static const int kPropertyListOffset = kNumberOfProperties + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010506 static const int kPropertyAccessorsOffset =
10507 kPropertyListOffset + kPointerSize;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010508 static const int kPropertyIntrinsicsOffset =
10509 kPropertyAccessorsOffset + kPointerSize;
10510 static const int kHeaderSize = kPropertyIntrinsicsOffset + kPointerSize;
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010511
10512 private:
Steve Blocka7e24c12009-10-30 11:49:00 +000010513 DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
10514};
10515
10516
10517class FunctionTemplateInfo: public TemplateInfo {
10518 public:
Steve Blocka7e24c12009-10-30 11:49:00 +000010519 DECL_ACCESSORS(call_code, Object)
Steve Blocka7e24c12009-10-30 11:49:00 +000010520 DECL_ACCESSORS(prototype_template, Object)
10521 DECL_ACCESSORS(parent_template, Object)
10522 DECL_ACCESSORS(named_property_handler, Object)
10523 DECL_ACCESSORS(indexed_property_handler, Object)
10524 DECL_ACCESSORS(instance_template, Object)
10525 DECL_ACCESSORS(class_name, Object)
10526 DECL_ACCESSORS(signature, Object)
10527 DECL_ACCESSORS(instance_call_handler, Object)
10528 DECL_ACCESSORS(access_check_info, Object)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010529 DECL_INT_ACCESSORS(flag)
Steve Blocka7e24c12009-10-30 11:49:00 +000010530
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010531 inline int length() const;
10532 inline void set_length(int value);
10533
Steve Blocka7e24c12009-10-30 11:49:00 +000010534 // Following properties use flag bits.
10535 DECL_BOOLEAN_ACCESSORS(hidden_prototype)
10536 DECL_BOOLEAN_ACCESSORS(undetectable)
10537 // If the bit is set, object instances created by this function
10538 // requires access check.
10539 DECL_BOOLEAN_ACCESSORS(needs_access_check)
Ben Murdoch69a99ed2011-11-30 16:03:39 +000010540 DECL_BOOLEAN_ACCESSORS(read_only_prototype)
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010541 DECL_BOOLEAN_ACCESSORS(remove_prototype)
10542 DECL_BOOLEAN_ACCESSORS(do_not_cache)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010543 DECL_BOOLEAN_ACCESSORS(instantiated)
10544 DECL_BOOLEAN_ACCESSORS(accept_any_receiver)
Steve Blocka7e24c12009-10-30 11:49:00 +000010545
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010546 DECLARE_CAST(FunctionTemplateInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010547
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010548 // Dispatched behavior.
10549 DECLARE_PRINTER(FunctionTemplateInfo)
10550 DECLARE_VERIFIER(FunctionTemplateInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010551
Ben Murdoch097c5b22016-05-18 11:27:45 +010010552 static const int kCallCodeOffset = TemplateInfo::kHeaderSize;
Steve Blocka7e24c12009-10-30 11:49:00 +000010553 static const int kPrototypeTemplateOffset =
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010554 kCallCodeOffset + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +000010555 static const int kParentTemplateOffset =
10556 kPrototypeTemplateOffset + kPointerSize;
10557 static const int kNamedPropertyHandlerOffset =
10558 kParentTemplateOffset + kPointerSize;
10559 static const int kIndexedPropertyHandlerOffset =
10560 kNamedPropertyHandlerOffset + kPointerSize;
10561 static const int kInstanceTemplateOffset =
10562 kIndexedPropertyHandlerOffset + kPointerSize;
10563 static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
10564 static const int kSignatureOffset = kClassNameOffset + kPointerSize;
10565 static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
10566 static const int kAccessCheckInfoOffset =
10567 kInstanceCallHandlerOffset + kPointerSize;
10568 static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010569 static const int kLengthOffset = kFlagOffset + kPointerSize;
10570 static const int kSize = kLengthOffset + kPointerSize;
10571
10572 // Returns true if |object| is an instance of this function template.
10573 bool IsTemplateFor(Object* object);
10574 bool IsTemplateFor(Map* map);
Steve Blocka7e24c12009-10-30 11:49:00 +000010575
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010576 // Returns the holder JSObject if the function can legally be called with this
10577 // receiver. Returns Heap::null_value() if the call is illegal.
10578 Object* GetCompatibleReceiver(Isolate* isolate, Object* receiver);
10579
Steve Blocka7e24c12009-10-30 11:49:00 +000010580 private:
10581 // Bit position in the flag, from least significant bit position.
10582 static const int kHiddenPrototypeBit = 0;
10583 static const int kUndetectableBit = 1;
10584 static const int kNeedsAccessCheckBit = 2;
Ben Murdoch69a99ed2011-11-30 16:03:39 +000010585 static const int kReadOnlyPrototypeBit = 3;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010586 static const int kRemovePrototypeBit = 4;
10587 static const int kDoNotCacheBit = 5;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010588 static const int kInstantiatedBit = 6;
10589 static const int kAcceptAnyReceiver = 7;
Steve Blocka7e24c12009-10-30 11:49:00 +000010590
10591 DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
10592};
10593
10594
10595class ObjectTemplateInfo: public TemplateInfo {
10596 public:
10597 DECL_ACCESSORS(constructor, Object)
10598 DECL_ACCESSORS(internal_field_count, Object)
10599
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010600 DECLARE_CAST(ObjectTemplateInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010601
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010602 // Dispatched behavior.
10603 DECLARE_PRINTER(ObjectTemplateInfo)
10604 DECLARE_VERIFIER(ObjectTemplateInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010605
10606 static const int kConstructorOffset = TemplateInfo::kHeaderSize;
10607 static const int kInternalFieldCountOffset =
10608 kConstructorOffset + kPointerSize;
10609 static const int kSize = kInternalFieldCountOffset + kPointerSize;
10610};
10611
10612
Steve Blocka7e24c12009-10-30 11:49:00 +000010613// The DebugInfo class holds additional information for a function being
10614// debugged.
10615class DebugInfo: public Struct {
10616 public:
10617 // The shared function info for the source being debugged.
10618 DECL_ACCESSORS(shared, SharedFunctionInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010619 // Code object for the patched code. This code object is the code object
10620 // currently active for the function.
Ben Murdoch097c5b22016-05-18 11:27:45 +010010621 DECL_ACCESSORS(abstract_code, AbstractCode)
Steve Blocka7e24c12009-10-30 11:49:00 +000010622 // Fixed array holding status information for each active break point.
10623 DECL_ACCESSORS(break_points, FixedArray)
10624
Ben Murdoch097c5b22016-05-18 11:27:45 +010010625 // Check if there is a break point at a code offset.
10626 bool HasBreakPoint(int code_offset);
10627 // Get the break point info object for a code offset.
10628 Object* GetBreakPointInfo(int code_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +000010629 // Clear a break point.
Ben Murdoch097c5b22016-05-18 11:27:45 +010010630 static void ClearBreakPoint(Handle<DebugInfo> debug_info, int code_offset,
Steve Blocka7e24c12009-10-30 11:49:00 +000010631 Handle<Object> break_point_object);
10632 // Set a break point.
Ben Murdoch097c5b22016-05-18 11:27:45 +010010633 static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_offset,
Steve Blocka7e24c12009-10-30 11:49:00 +000010634 int source_position, int statement_position,
10635 Handle<Object> break_point_object);
Ben Murdoch097c5b22016-05-18 11:27:45 +010010636 // Get the break point objects for a code offset.
10637 Handle<Object> GetBreakPointObjects(int code_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +000010638 // Find the break point info holding this break point object.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010639 static Handle<Object> FindBreakPointInfo(Handle<DebugInfo> debug_info,
10640 Handle<Object> break_point_object);
Steve Blocka7e24c12009-10-30 11:49:00 +000010641 // Get the number of break points for this function.
10642 int GetBreakPointCount();
10643
Ben Murdoch097c5b22016-05-18 11:27:45 +010010644 static Smi* uninitialized() { return Smi::FromInt(0); }
10645
10646 inline BytecodeArray* original_bytecode_array();
10647
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010648 DECLARE_CAST(DebugInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010649
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010650 // Dispatched behavior.
10651 DECLARE_PRINTER(DebugInfo)
10652 DECLARE_VERIFIER(DebugInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010653
10654 static const int kSharedFunctionInfoIndex = Struct::kHeaderSize;
Ben Murdoch097c5b22016-05-18 11:27:45 +010010655 static const int kAbstractCodeIndex = kSharedFunctionInfoIndex + kPointerSize;
10656 static const int kBreakPointsStateIndex = kAbstractCodeIndex + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +000010657 static const int kSize = kBreakPointsStateIndex + kPointerSize;
10658
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010659 static const int kEstimatedNofBreakPointsInFunction = 16;
10660
Steve Blocka7e24c12009-10-30 11:49:00 +000010661 private:
10662 static const int kNoBreakPointInfo = -1;
10663
Ben Murdoch097c5b22016-05-18 11:27:45 +010010664 // Lookup the index in the break_points array for a code offset.
10665 int GetBreakPointInfoIndex(int code_offset);
Steve Blocka7e24c12009-10-30 11:49:00 +000010666
10667 DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo);
10668};
10669
10670
10671// The BreakPointInfo class holds information for break points set in a
10672// function. The DebugInfo object holds a BreakPointInfo object for each code
10673// position with one or more break points.
10674class BreakPointInfo: public Struct {
10675 public:
Ben Murdoch097c5b22016-05-18 11:27:45 +010010676 // The code offset for the break point.
10677 DECL_INT_ACCESSORS(code_offset)
Steve Blocka7e24c12009-10-30 11:49:00 +000010678 // The position in the source for the break position.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010679 DECL_INT_ACCESSORS(source_position)
Steve Blocka7e24c12009-10-30 11:49:00 +000010680 // The position in the source for the last statement before this break
10681 // position.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010682 DECL_INT_ACCESSORS(statement_position)
Steve Blocka7e24c12009-10-30 11:49:00 +000010683 // List of related JavaScript break points.
10684 DECL_ACCESSORS(break_point_objects, Object)
10685
10686 // Removes a break point.
10687 static void ClearBreakPoint(Handle<BreakPointInfo> info,
10688 Handle<Object> break_point_object);
10689 // Set a break point.
10690 static void SetBreakPoint(Handle<BreakPointInfo> info,
10691 Handle<Object> break_point_object);
10692 // Check if break point info has this break point object.
10693 static bool HasBreakPointObject(Handle<BreakPointInfo> info,
10694 Handle<Object> break_point_object);
Ben Murdoch097c5b22016-05-18 11:27:45 +010010695 // Get the number of break points for this code offset.
Steve Blocka7e24c12009-10-30 11:49:00 +000010696 int GetBreakPointCount();
10697
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010698 DECLARE_CAST(BreakPointInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010699
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010700 // Dispatched behavior.
10701 DECLARE_PRINTER(BreakPointInfo)
10702 DECLARE_VERIFIER(BreakPointInfo)
Steve Blocka7e24c12009-10-30 11:49:00 +000010703
Ben Murdoch097c5b22016-05-18 11:27:45 +010010704 static const int kCodeOffsetIndex = Struct::kHeaderSize;
10705 static const int kSourcePositionIndex = kCodeOffsetIndex + kPointerSize;
Steve Blocka7e24c12009-10-30 11:49:00 +000010706 static const int kStatementPositionIndex =
10707 kSourcePositionIndex + kPointerSize;
10708 static const int kBreakPointObjectsIndex =
10709 kStatementPositionIndex + kPointerSize;
10710 static const int kSize = kBreakPointObjectsIndex + kPointerSize;
10711
10712 private:
10713 DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo);
10714};
Steve Blocka7e24c12009-10-30 11:49:00 +000010715
10716
10717#undef DECL_BOOLEAN_ACCESSORS
10718#undef DECL_ACCESSORS
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010719#undef DECLARE_CAST
10720#undef DECLARE_VERIFIER
Steve Blocka7e24c12009-10-30 11:49:00 +000010721
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010722#define VISITOR_SYNCHRONIZATION_TAGS_LIST(V) \
10723 V(kStringTable, "string_table", "(Internalized strings)") \
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010724 V(kExternalStringsTable, "external_strings_table", "(External strings)") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010725 V(kStrongRootList, "strong_root_list", "(Strong roots)") \
10726 V(kSmiRootList, "smi_root_list", "(Smi roots)") \
10727 V(kBootstrapper, "bootstrapper", "(Bootstrapper)") \
10728 V(kTop, "top", "(Isolate)") \
10729 V(kRelocatable, "relocatable", "(Relocatable)") \
10730 V(kDebug, "debug", "(Debugger)") \
10731 V(kCompilationCache, "compilationcache", "(Compilation cache)") \
10732 V(kHandleScope, "handlescope", "(Handle scope)") \
Ben Murdoch097c5b22016-05-18 11:27:45 +010010733 V(kDispatchTable, "dispatchtable", "(Dispatch table)") \
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010734 V(kBuiltins, "builtins", "(Builtins)") \
10735 V(kGlobalHandles, "globalhandles", "(Global handles)") \
10736 V(kEternalHandles, "eternalhandles", "(Eternal handles)") \
10737 V(kThreadManager, "threadmanager", "(Thread manager)") \
10738 V(kStrongRoots, "strong roots", "(Strong roots)") \
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010739 V(kExtensions, "Extensions", "(Extensions)")
10740
10741class VisitorSynchronization : public AllStatic {
10742 public:
10743#define DECLARE_ENUM(enum_item, ignore1, ignore2) enum_item,
10744 enum SyncTag {
10745 VISITOR_SYNCHRONIZATION_TAGS_LIST(DECLARE_ENUM)
10746 kNumberOfSyncTags
10747 };
10748#undef DECLARE_ENUM
10749
10750 static const char* const kTags[kNumberOfSyncTags];
10751 static const char* const kTagNames[kNumberOfSyncTags];
10752};
Steve Blocka7e24c12009-10-30 11:49:00 +000010753
10754// Abstract base class for visiting, and optionally modifying, the
10755// pointers contained in Objects. Used in GC and serialization/deserialization.
10756class ObjectVisitor BASE_EMBEDDED {
10757 public:
10758 virtual ~ObjectVisitor() {}
10759
10760 // Visits a contiguous arrays of pointers in the half-open range
10761 // [start, end). Any or all of the values may be modified on return.
10762 virtual void VisitPointers(Object** start, Object** end) = 0;
10763
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010764 // Handy shorthand for visiting a single pointer.
10765 virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); }
10766
10767 // Visit weak next_code_link in Code object.
10768 virtual void VisitNextCodeLink(Object** p) { VisitPointers(p, p + 1); }
10769
Steve Blocka7e24c12009-10-30 11:49:00 +000010770 // To allow lazy clearing of inline caches the visitor has
10771 // a rich interface for iterating over Code objects..
10772
10773 // Visits a code target in the instruction stream.
10774 virtual void VisitCodeTarget(RelocInfo* rinfo);
10775
Steve Block791712a2010-08-27 10:21:07 +010010776 // Visits a code entry in a JS function.
10777 virtual void VisitCodeEntry(Address entry_address);
10778
Ben Murdochb0fe1622011-05-05 13:52:32 +010010779 // Visits a global property cell reference in the instruction stream.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010780 virtual void VisitCell(RelocInfo* rinfo);
Ben Murdochb0fe1622011-05-05 13:52:32 +010010781
Steve Blocka7e24c12009-10-30 11:49:00 +000010782 // Visits a runtime entry in the instruction stream.
10783 virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
10784
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010785 // Visits the resource of an one-byte or two-byte string.
10786 virtual void VisitExternalOneByteString(
10787 v8::String::ExternalOneByteStringResource** resource) {}
Steve Blockd0582a62009-12-15 09:54:21 +000010788 virtual void VisitExternalTwoByteString(
10789 v8::String::ExternalStringResource** resource) {}
10790
Steve Blocka7e24c12009-10-30 11:49:00 +000010791 // Visits a debug call target in the instruction stream.
10792 virtual void VisitDebugTarget(RelocInfo* rinfo);
10793
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010794 // Visits the byte sequence in a function's prologue that contains information
10795 // about the code's age.
10796 virtual void VisitCodeAgeSequence(RelocInfo* rinfo);
Steve Blocka7e24c12009-10-30 11:49:00 +000010797
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010798 // Visit pointer embedded into a code object.
10799 virtual void VisitEmbeddedPointer(RelocInfo* rinfo);
10800
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010801 // Visits an external reference embedded into a code object.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010802 virtual void VisitExternalReference(RelocInfo* rinfo);
10803
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010804 // Visits an external reference.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000010805 virtual void VisitExternalReference(Address* p) {}
Steve Blocka7e24c12009-10-30 11:49:00 +000010806
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010807 // Visits an (encoded) internal reference.
10808 virtual void VisitInternalReference(RelocInfo* rinfo) {}
10809
Steve Block44f0eee2011-05-26 01:26:41 +010010810 // Visits a handle that has an embedder-assigned class ID.
10811 virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {}
10812
Steve Blocka7e24c12009-10-30 11:49:00 +000010813 // Intended for serialization/deserialization checking: insert, or
10814 // check for the presence of, a tag at this position in the stream.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010010815 // Also used for marking up GC roots in heap snapshots.
10816 virtual void Synchronize(VisitorSynchronization::SyncTag tag) {}
Steve Blocka7e24c12009-10-30 11:49:00 +000010817};
10818
10819
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010820// BooleanBit is a helper class for setting and getting a bit in an integer.
Steve Blocka7e24c12009-10-30 11:49:00 +000010821class BooleanBit : public AllStatic {
10822 public:
Steve Blocka7e24c12009-10-30 11:49:00 +000010823 static inline bool get(int value, int bit_position) {
10824 return (value & (1 << bit_position)) != 0;
10825 }
10826
Steve Blocka7e24c12009-10-30 11:49:00 +000010827 static inline int set(int value, int bit_position, bool v) {
10828 if (v) {
10829 value |= (1 << bit_position);
10830 } else {
10831 value &= ~(1 << bit_position);
10832 }
10833 return value;
10834 }
10835};
10836
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010837
10838} // NOLINT, false-positive due to second-order macros.
10839} // NOLINT, false-positive due to second-order macros.
Steve Blocka7e24c12009-10-30 11:49:00 +000010840
10841#endif // V8_OBJECTS_H_