18b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch// Copyright 2011 the V8 project authors. All rights reserved.
2a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Redistribution and use in source and binary forms, with or without
3a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// modification, are permitted provided that the following conditions are
4a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// met:
5a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
6a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions of source code must retain the above copyright
7a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       notice, this list of conditions and the following disclaimer.
8a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Redistributions in binary form must reproduce the above
9a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       copyright notice, this list of conditions and the following
10a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       disclaimer in the documentation and/or other materials provided
11a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       with the distribution.
12a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     * Neither the name of Google Inc. nor the names of its
13a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       contributors may be used to endorse or promote products derived
14a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       from this software without specific prior written permission.
15a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
16a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifndef V8_OBJECTS_H_
29a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define V8_OBJECTS_H_
30a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
31a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include "builtins.h"
32a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include "smart-pointer.h"
33a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#include "unicode-inl.h"
343ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#if V8_TARGET_ARCH_ARM
353ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#include "arm/constants-arm.h"
363100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#elif V8_TARGET_ARCH_MIPS
373100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu#include "mips/constants-mips.h"
383ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#endif
39a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
40a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
4150ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen// Most object types in the V8 JavaScript are described in this file.
42a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
43a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Inheritance hierarchy:
445913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck// - MaybeObject    (an object or a failure)
455913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck//   - Failure      (immediate for marking failed operation)
46a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   - Object
47a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     - Smi          (immediate small integer)
48a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     - HeapObject   (superclass for everything allocated in the heap)
49a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       - JSObject
50a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - JSArray
51a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - JSRegExp
52a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - JSFunction
53a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - GlobalObject
54a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//           - JSGlobalObject
55a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//           - JSBuiltinsObject
56a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - JSGlobalProxy
571e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//         - JSValue
581e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block//         - JSMessageObject
597f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//       - ByteArray
607f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//       - ExternalArray
6144f0eee88ff00398ff7f715fab053374d808c90dSteve Block//         - ExternalPixelArray
627f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - ExternalByteArray
637f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - ExternalUnsignedByteArray
647f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - ExternalShortArray
657f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - ExternalUnsignedShortArray
667f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - ExternalIntArray
677f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - ExternalUnsignedIntArray
687f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - ExternalFloatArray
697f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//       - FixedArray
707f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - DescriptorArray
717f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - HashTable
727f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//           - Dictionary
737f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//           - SymbolTable
747f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//           - CompilationCacheTable
757f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//           - CodeCacheHashTable
767f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//           - MapCache
777f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - Context
787f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch//         - JSFunctionResultCache
7950ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen//         - SerializedScopeInfo
80a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       - String
81a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - SeqString
82a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//           - SeqAsciiString
83a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//           - SeqTwoByteString
84a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - ConsString
85a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - ExternalString
86a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//           - ExternalAsciiString
87a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//           - ExternalTwoByteString
88a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       - HeapNumber
89a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       - Code
90a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       - Map
91a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       - Oddball
92a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       - Proxy
93a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       - SharedFunctionInfo
94a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       - Struct
95a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - AccessorInfo
96a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - AccessCheckInfo
97a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - InterceptorInfo
98a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - CallHandlerInfo
99a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - TemplateInfo
100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//           - FunctionTemplateInfo
101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//           - ObjectTemplateInfo
102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - Script
103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - SignatureInfo
104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - TypeSwitchInfo
105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - DebugInfo
106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//         - BreakPointInfo
1076ded16be15dd865a9b21ea304d5273c8be299c87Steve Block//         - CodeCache
108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Formats of Object*:
110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//  Smi:        [31 bit signed int] 0
111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//  HeapObject: [32 bit direct pointer] (4 byte aligned) | 01
112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//  Failure:    [30 bit signed int] 11
113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Ecma-262 3rd 8.6.1
115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum PropertyAttributes {
116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  NONE              = v8::None,
117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  READ_ONLY         = v8::ReadOnly,
118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DONT_ENUM         = v8::DontEnum,
119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DONT_DELETE       = v8::DontDelete,
120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ABSENT            = 16  // Used in runtime to indicate a property is absent.
121a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ABSENT can never be stored in or returned from a descriptor's attributes
122a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // bitfield.  It is only used as a return value meaning the attributes of
123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // a non-existent property.
124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace v8 {
127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocknamespace internal {
128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// PropertyDetails captures type and attributes for a property.
131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// They are used both in property dictionaries and instance descriptors.
132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass PropertyDetails BASE_EMBEDDED {
133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyDetails(PropertyAttributes attributes,
136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                  PropertyType type,
137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                  int index = 0) {
13844f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(type != EXTERNAL_ARRAY_TRANSITION);
139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(TypeField::is_valid(type));
140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(AttributesField::is_valid(attributes));
14144f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(StorageField::is_valid(index));
142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    value_ = TypeField::encode(type)
144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        | AttributesField::encode(attributes)
14544f0eee88ff00398ff7f715fab053374d808c90dSteve Block        | StorageField::encode(index);
146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(type == this->type());
148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(attributes == this->attributes());
149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(index == this->index());
150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  PropertyDetails(PropertyAttributes attributes,
15344f0eee88ff00398ff7f715fab053374d808c90dSteve Block                  PropertyType type,
15444f0eee88ff00398ff7f715fab053374d808c90dSteve Block                  ExternalArrayType array_type) {
15544f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(type == EXTERNAL_ARRAY_TRANSITION);
15644f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(TypeField::is_valid(type));
15744f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(AttributesField::is_valid(attributes));
15844f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(StorageField::is_valid(static_cast<int>(array_type)));
15944f0eee88ff00398ff7f715fab053374d808c90dSteve Block
16044f0eee88ff00398ff7f715fab053374d808c90dSteve Block    value_ = TypeField::encode(type)
16144f0eee88ff00398ff7f715fab053374d808c90dSteve Block        | AttributesField::encode(attributes)
16244f0eee88ff00398ff7f715fab053374d808c90dSteve Block        | StorageField::encode(static_cast<int>(array_type));
16344f0eee88ff00398ff7f715fab053374d808c90dSteve Block
16444f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(type == this->type());
16544f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(attributes == this->attributes());
16644f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(array_type == this->array_type());
16744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  }
16844f0eee88ff00398ff7f715fab053374d808c90dSteve Block
169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Conversion for storing details as Object*.
1708b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  explicit inline PropertyDetails(Smi* smi);
171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Smi* AsSmi();
172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyType type() { return TypeField::decode(value_); }
174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsTransition() {
176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    PropertyType t = type();
177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(t != INTERCEPTOR);
17844f0eee88ff00398ff7f715fab053374d808c90dSteve Block    return t == MAP_TRANSITION || t == CONSTANT_TRANSITION ||
17944f0eee88ff00398ff7f715fab053374d808c90dSteve Block        t == EXTERNAL_ARRAY_TRANSITION;
180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsProperty() {
183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return type() < FIRST_PHANTOM_PROPERTY_TYPE;
184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyAttributes attributes() { return AttributesField::decode(value_); }
187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
18844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  int index() { return StorageField::decode(value_); }
18944f0eee88ff00398ff7f715fab053374d808c90dSteve Block
19044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  ExternalArrayType array_type() {
19144f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(type() == EXTERNAL_ARRAY_TRANSITION);
19244f0eee88ff00398ff7f715fab053374d808c90dSteve Block    return static_cast<ExternalArrayType>(StorageField::decode(value_));
19344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  }
194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline PropertyDetails AsDeleted();
196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
19744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static bool IsValidIndex(int index) {
19844f0eee88ff00398ff7f715fab053374d808c90dSteve Block    return StorageField::is_valid(index);
19944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  }
200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; }
202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; }
203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; }
204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsDeleted() { return DeletedField::decode(value_) != 0;}
205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit fields in value_ (type, shift, size). Must be public so the
207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // constants can be embedded in generated code.
20844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  class TypeField:       public BitField<PropertyType,       0, 4> {};
20944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  class AttributesField: public BitField<PropertyAttributes, 4, 3> {};
21044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  class DeletedField:    public BitField<uint32_t,           7, 1> {};
21144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  class StorageField:    public BitField<uint32_t,           8, 32-8> {};
212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInitialIndex = 1;
214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t value_;
216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER.
220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER };
221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// PropertyNormalizationMode is used to specify whether to keep
224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// inobject properties when normalizing properties of a JSObject.
225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum PropertyNormalizationMode {
226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CLEAR_INOBJECT_PROPERTIES,
227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  KEEP_INOBJECT_PROPERTIES
228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2310d5e116f6aee03185f237311a943491bb079a768Kristian Monsen// NormalizedMapSharingMode is used to specify whether a map may be shared
2320d5e116f6aee03185f237311a943491bb079a768Kristian Monsen// by different objects with normalized properties.
2330d5e116f6aee03185f237311a943491bb079a768Kristian Monsenenum NormalizedMapSharingMode {
2340d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  UNIQUE_NORMALIZED_MAP,
2350d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  SHARED_NORMALIZED_MAP
2360d5e116f6aee03185f237311a943491bb079a768Kristian Monsen};
2370d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
2380d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
239791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block// Instance size sentinel for objects of variable size.
240791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Blockstatic const int kVariableSizeSentinel = 0;
241791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block
242791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block
243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// All Maps have a field instance_type containing a InstanceType.
244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// It describes the type of the instances.
245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// As an example, a JavaScript object is a heap object and its map
247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// instance_type is JS_OBJECT_TYPE.
248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The names of the string instance types are intended to systematically
250e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// mirror their encoding in the instance_type field of the map.  The default
251e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// encoding is considered TWO_BYTE.  It is not mentioned in the name.  ASCII
252e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// encoding is mentioned explicitly in the name.  Likewise, the default
253e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// representation is considered sequential.  It is not mentioned in the
254e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// name.  The other representations (eg, CONS, EXTERNAL) are explicitly
255e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// mentioned.  Finally, the string is either a SYMBOL_TYPE (if it is a
256e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// symbol) or a STRING_TYPE (if it is not a symbol).
257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// NOTE: The following things are some that depend on the string types having
259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// instance_types that are less than those of all other types:
260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// HeapObject::Size, HeapObject::IterateBody, the typeof operator, and
261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Object::IsString.
262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// NOTE: Everything following JS_VALUE_TYPE is considered a
264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// JSObject for GC purposes. The first four entries here have typeof
265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 'object', whereas JS_FUNCTION_TYPE has typeof 'function'.
266d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block#define INSTANCE_TYPE_LIST_ALL(V)                                              \
267d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(SYMBOL_TYPE)                                                               \
268d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(ASCII_SYMBOL_TYPE)                                                         \
269d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CONS_SYMBOL_TYPE)                                                          \
270d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CONS_ASCII_SYMBOL_TYPE)                                                    \
271d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_SYMBOL_TYPE)                                                      \
272756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE)                                      \
273d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_ASCII_SYMBOL_TYPE)                                                \
274d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(STRING_TYPE)                                                               \
275d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(ASCII_STRING_TYPE)                                                         \
276d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CONS_STRING_TYPE)                                                          \
277d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CONS_ASCII_STRING_TYPE)                                                    \
278d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_STRING_TYPE)                                                      \
279756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE)                                      \
280d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_ASCII_STRING_TYPE)                                                \
281d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE)                                        \
282d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block                                                                               \
283d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(MAP_TYPE)                                                                  \
284d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CODE_TYPE)                                                                 \
285d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(ODDBALL_TYPE)                                                              \
286756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  V(JS_GLOBAL_PROPERTY_CELL_TYPE)                                              \
287e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke                                                                               \
288e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  V(HEAP_NUMBER_TYPE)                                                          \
289d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(PROXY_TYPE)                                                                \
290d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(BYTE_ARRAY_TYPE)                                                           \
291d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  /* Note: the order of these external array */                                \
292d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  /* types is relied upon in */                                                \
293d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  /* Object::IsExternalArray(). */                                             \
294d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_BYTE_ARRAY_TYPE)                                                  \
295d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE)                                         \
296d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_SHORT_ARRAY_TYPE)                                                 \
297d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE)                                        \
298d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_INT_ARRAY_TYPE)                                                   \
299d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE)                                          \
300d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_FLOAT_ARRAY_TYPE)                                                 \
30144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  V(EXTERNAL_PIXEL_ARRAY_TYPE)                                                 \
302d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(FILLER_TYPE)                                                               \
303d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block                                                                               \
304d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(ACCESSOR_INFO_TYPE)                                                        \
305d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(ACCESS_CHECK_INFO_TYPE)                                                    \
306d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(INTERCEPTOR_INFO_TYPE)                                                     \
307d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CALL_HANDLER_INFO_TYPE)                                                    \
308d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(FUNCTION_TEMPLATE_INFO_TYPE)                                               \
309d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(OBJECT_TEMPLATE_INFO_TYPE)                                                 \
310d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(SIGNATURE_INFO_TYPE)                                                       \
311d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(TYPE_SWITCH_INFO_TYPE)                                                     \
312d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(SCRIPT_TYPE)                                                               \
3136ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  V(CODE_CACHE_TYPE)                                                           \
314d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block                                                                               \
315756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  V(FIXED_ARRAY_TYPE)                                                          \
316756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  V(SHARED_FUNCTION_INFO_TYPE)                                                 \
317756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                                                                               \
3181e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  V(JS_MESSAGE_OBJECT_TYPE)                                                    \
3191e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block                                                                               \
320d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(JS_VALUE_TYPE)                                                             \
321d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(JS_OBJECT_TYPE)                                                            \
322d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(JS_CONTEXT_EXTENSION_OBJECT_TYPE)                                          \
323d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(JS_GLOBAL_OBJECT_TYPE)                                                     \
324d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(JS_BUILTINS_OBJECT_TYPE)                                                   \
325d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(JS_GLOBAL_PROXY_TYPE)                                                      \
326d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(JS_ARRAY_TYPE)                                                             \
327d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(JS_REGEXP_TYPE)                                                            \
328d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block                                                                               \
329d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(JS_FUNCTION_TYPE)                                                          \
330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef ENABLE_DEBUGGER_SUPPORT
332d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block#define INSTANCE_TYPE_LIST_DEBUGGER(V)                                         \
333d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(DEBUG_INFO_TYPE)                                                           \
334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V(BREAK_POINT_INFO_TYPE)
335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define INSTANCE_TYPE_LIST_DEBUGGER(V)
337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
339d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block#define INSTANCE_TYPE_LIST(V)                                                  \
340d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  INSTANCE_TYPE_LIST_ALL(V)                                                    \
341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  INSTANCE_TYPE_LIST_DEBUGGER(V)
342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Since string types are not consecutive, this macro is used to
345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// iterate over them.
346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define STRING_TYPE_LIST(V)                                                    \
347d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(SYMBOL_TYPE,                                                               \
348791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block    kVariableSizeSentinel,                                                     \
349d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    symbol,                                                                    \
350d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    Symbol)                                                                    \
351d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(ASCII_SYMBOL_TYPE,                                                         \
352791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block    kVariableSizeSentinel,                                                     \
353d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    ascii_symbol,                                                              \
354d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    AsciiSymbol)                                                               \
355d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CONS_SYMBOL_TYPE,                                                          \
356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ConsString::kSize,                                                         \
357d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    cons_symbol,                                                               \
358d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    ConsSymbol)                                                                \
359d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CONS_ASCII_SYMBOL_TYPE,                                                    \
360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ConsString::kSize,                                                         \
361d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    cons_ascii_symbol,                                                         \
362d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    ConsAsciiSymbol)                                                           \
363d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_SYMBOL_TYPE,                                                      \
364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalTwoByteString::kSize,                                              \
365d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    external_symbol,                                                           \
366d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    ExternalSymbol)                                                            \
3679dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE,                                      \
3689dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    ExternalTwoByteString::kSize,                                              \
3699dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    external_symbol_with_ascii_data,                                           \
3709dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    ExternalSymbolWithAsciiData)                                               \
371d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_ASCII_SYMBOL_TYPE,                                                \
372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalAsciiString::kSize,                                                \
373d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    external_ascii_symbol,                                                     \
374d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    ExternalAsciiSymbol)                                                       \
375d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(STRING_TYPE,                                                               \
376791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block    kVariableSizeSentinel,                                                     \
377d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    string,                                                                    \
378d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    String)                                                                    \
379d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(ASCII_STRING_TYPE,                                                         \
380791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block    kVariableSizeSentinel,                                                     \
381d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    ascii_string,                                                              \
382d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    AsciiString)                                                               \
383d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CONS_STRING_TYPE,                                                          \
384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ConsString::kSize,                                                         \
385d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    cons_string,                                                               \
386d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    ConsString)                                                                \
387d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CONS_ASCII_STRING_TYPE,                                                    \
388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ConsString::kSize,                                                         \
389d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    cons_ascii_string,                                                         \
390d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    ConsAsciiString)                                                           \
391d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_STRING_TYPE,                                                      \
392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalTwoByteString::kSize,                                              \
393d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    external_string,                                                           \
394d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    ExternalString)                                                            \
3959dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE,                                      \
3969dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    ExternalTwoByteString::kSize,                                              \
3979dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    external_string_with_ascii_data,                                           \
3989dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    ExternalStringWithAsciiData)                                               \
399d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(EXTERNAL_ASCII_STRING_TYPE,                                                \
400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ExternalAsciiString::kSize,                                                \
401d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block    external_ascii_string,                                                     \
402791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block    ExternalAsciiString)
403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A struct is a simple object a set of object-valued fields.  Including an
405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// object type in this causes the compiler to generate most of the boilerplate
406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// code for the class including allocation and garbage collection routines,
407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// casts and predicates.  All you need to define is the class, methods and
408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// object verification routines.  Easy, no?
409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Note that for subtle reasons related to the ordering or numerical values of
411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST
412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// manually.
413d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block#define STRUCT_LIST_ALL(V)                                                     \
414d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(ACCESSOR_INFO, AccessorInfo, accessor_info)                                \
415d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info)                     \
416d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info)                       \
417d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info)                     \
418d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info)      \
419d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info)            \
420d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(SIGNATURE_INFO, SignatureInfo, signature_info)                             \
421d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info)                        \
4226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  V(SCRIPT, Script, script)                                                    \
4236ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  V(CODE_CACHE, CodeCache, code_cache)
424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef ENABLE_DEBUGGER_SUPPORT
426d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block#define STRUCT_LIST_DEBUGGER(V)                                                \
427d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  V(DEBUG_INFO, DebugInfo, debug_info)                                         \
428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  V(BREAK_POINT_INFO, BreakPointInfo, break_point_info)
429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define STRUCT_LIST_DEBUGGER(V)
431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
433d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block#define STRUCT_LIST(V)                                                         \
434d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  STRUCT_LIST_ALL(V)                                                           \
435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  STRUCT_LIST_DEBUGGER(V)
436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// We use the full 8 bits of the instance_type field to encode heap object
438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// instance types.  The high-order bit (bit 7) is set if the object is not a
439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// string, and cleared if it is a string.
440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kIsNotStringMask = 0x80;
441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kStringTag = 0x0;
442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kNotStringTag = 0x80;
443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
444e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// Bit 6 indicates that the object is a symbol (if set) or not (if cleared).
445e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// There are not enough types that the non-string types (with bit 7 set) can
446e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke// have bit 6 set too.
447e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarkeconst uint32_t kIsSymbolMask = 0x40;
448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kNotSymbolTag = 0x0;
449e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarkeconst uint32_t kSymbolTag = 0x40;
450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// If bit 7 is clear then bit 2 indicates whether the string consists of
452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// two-byte characters or one-byte characters.
453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kStringEncodingMask = 0x4;
454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kTwoByteStringTag = 0x0;
455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kAsciiStringTag = 0x4;
456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// If bit 7 is clear, the low-order 2 bits indicate the representation
458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// of the string.
459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kStringRepresentationMask = 0x03;
460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum StringRepresentationTag {
461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  kSeqStringTag = 0x0,
462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  kConsStringTag = 0x1,
4637f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  kExternalStringTag = 0x2
464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
4657f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochconst uint32_t kIsConsStringMask = 0x1;
466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4679dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen// If bit 7 is clear, then bit 3 indicates whether this two-byte
4689dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen// string actually contains ascii data.
4699dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsenconst uint32_t kAsciiDataHintMask = 0x08;
4709dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsenconst uint32_t kAsciiDataHintTag = 0x08;
4719dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen
472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A ConsString with an empty string as the right side is a candidate
474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// for being shortcut by the garbage collector unless it is a
475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// symbol. It's not common to have non-flat symbols, so we do not
476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// shortcut them thereby avoiding turning symbols into strings. See
477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// heap.cc and mark-compact.cc.
478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kShortcutTypeMask =
479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    kIsNotStringMask |
480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    kIsSymbolMask |
481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    kStringRepresentationMask;
482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst uint32_t kShortcutTypeTag = kConsStringTag;
483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum InstanceType {
486e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // String types.
4871e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // FIRST_STRING_TYPE
4889dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag,
489d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag,
4909dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag,
491d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag,
4929dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag,
4939dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE =
4949dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen      kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag,
495d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  EXTERNAL_ASCII_SYMBOL_TYPE =
496d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block      kAsciiStringTag | kSymbolTag | kExternalStringTag,
4979dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  STRING_TYPE = kTwoByteStringTag | kSeqStringTag,
498d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag,
4999dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag,
500d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag,
5019dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag,
5029dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  EXTERNAL_STRING_WITH_ASCII_DATA_TYPE =
5039dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen      kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag,
5041e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // LAST_STRING_TYPE
505d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag,
506d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE,
507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
508e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Objects allocated in their own spaces (never in new space).
509e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  MAP_TYPE = kNotStringTag,  // FIRST_NONSTRING_TYPE
510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CODE_TYPE,
511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ODDBALL_TYPE,
512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  JS_GLOBAL_PROPERTY_CELL_TYPE,
513e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
514e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // "Data", objects that cannot contain non-map-word pointers to heap
515e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // objects.
516e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  HEAP_NUMBER_TYPE,
517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PROXY_TYPE,
518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  BYTE_ARRAY_TYPE,
519e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  EXTERNAL_BYTE_ARRAY_TYPE,  // FIRST_EXTERNAL_ARRAY_TYPE
5203ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE,
5213ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  EXTERNAL_SHORT_ARRAY_TYPE,
5223ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE,
5233ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  EXTERNAL_INT_ARRAY_TYPE,
5243ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  EXTERNAL_UNSIGNED_INT_ARRAY_TYPE,
52544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  EXTERNAL_FLOAT_ARRAY_TYPE,
52644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  EXTERNAL_PIXEL_ARRAY_TYPE,  // LAST_EXTERNAL_ARRAY_TYPE
527e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  FILLER_TYPE,  // LAST_DATA_TYPE
528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
529e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Structs.
530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESSOR_INFO_TYPE,
531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ACCESS_CHECK_INFO_TYPE,
532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  INTERCEPTOR_INFO_TYPE,
533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  CALL_HANDLER_INFO_TYPE,
534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  FUNCTION_TEMPLATE_INFO_TYPE,
535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  OBJECT_TEMPLATE_INFO_TYPE,
536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  SIGNATURE_INFO_TYPE,
537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  TYPE_SWITCH_INFO_TYPE,
538e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  SCRIPT_TYPE,
5396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  CODE_CACHE_TYPE,
5409dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT
5419dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // is defined. However as include/v8.h contain some of the instance type
5429dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // constants always having them avoids them getting different numbers
5439dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not.
544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DEBUG_INFO_TYPE,
545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  BREAK_POINT_INFO_TYPE,
546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
547e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  FIXED_ARRAY_TYPE,
548e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  SHARED_FUNCTION_INFO_TYPE,
549e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
5501e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  JS_MESSAGE_OBJECT_TYPE,
5511e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
552e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  JS_VALUE_TYPE,  // FIRST_JS_OBJECT_TYPE
553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  JS_OBJECT_TYPE,
554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  JS_CONTEXT_EXTENSION_OBJECT_TYPE,
555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  JS_GLOBAL_OBJECT_TYPE,
556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  JS_BUILTINS_OBJECT_TYPE,
557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  JS_GLOBAL_PROXY_TYPE,
558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  JS_ARRAY_TYPE,
5591e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
5601e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  JS_REGEXP_TYPE,  // LAST_JS_OBJECT_TYPE, FIRST_FUNCTION_CLASS_TYPE
561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  JS_FUNCTION_TYPE,
563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Pseudo-types
565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  FIRST_TYPE = 0x0,
566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  LAST_TYPE = JS_FUNCTION_TYPE,
567e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  INVALID_TYPE = FIRST_TYPE - 1,
568e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  FIRST_NONSTRING_TYPE = MAP_TYPE,
5691e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  FIRST_STRING_TYPE = FIRST_TYPE,
5701e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  LAST_STRING_TYPE = FIRST_NONSTRING_TYPE - 1,
571e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Boundaries for testing for an external array.
572e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE,
57344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE,
574e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Boundary for promotion to old data space/old pointer space.
575e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  LAST_DATA_TYPE = FILLER_TYPE,
576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Boundaries for testing the type is a JavaScript "object".  Note that
577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // function objects are not counted as objects, even though they are
578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // implemented as such; only values whose typeof is "object" are included.
579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  FIRST_JS_OBJECT_TYPE = JS_VALUE_TYPE,
5801e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  LAST_JS_OBJECT_TYPE = JS_REGEXP_TYPE,
5811e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // RegExp objects have [[Class]] "function" because they are callable.
5821e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // All types from this type and above are objects with [[Class]] "function".
5831e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  FIRST_FUNCTION_CLASS_TYPE = JS_REGEXP_TYPE
584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
58644f0eee88ff00398ff7f715fab053374d808c90dSteve Blockstatic const int kExternalArrayTypeCount = LAST_EXTERNAL_ARRAY_TYPE -
58744f0eee88ff00398ff7f715fab053374d808c90dSteve Block    FIRST_EXTERNAL_ARRAY_TYPE + 1;
588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5899dcf7e2f83591d471e88bf7d230651900b8e424bKristian MonsenSTATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType);
5909dcf7e2f83591d471e88bf7d230651900b8e424bKristian MonsenSTATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType);
5919dcf7e2f83591d471e88bf7d230651900b8e424bKristian MonsenSTATIC_CHECK(PROXY_TYPE == Internals::kProxyType);
5929dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen
5939dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen
594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum CompareResult {
595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  LESS      = -1,
596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  EQUAL     =  0,
597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  GREATER   =  1,
598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  NOT_EQUAL = GREATER
600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define DECL_BOOLEAN_ACCESSORS(name)   \
604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool name();                  \
605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_##name(bool value);  \
606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define DECL_ACCESSORS(name, type)                                      \
609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline type* name();                                                  \
610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_##name(type* value,                                   \
611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                         WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \
612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass StringStream;
615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ObjectVisitor;
616053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Blockclass Failure;
617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockstruct ValueInfo : public Malloced {
619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { }
620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  InstanceType type;
621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* ptr;
622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const char* str;
623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  double number;
624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A template-ized version of the IsXXX functions.
628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <class C> static inline bool Is(Object* obj);
629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
630b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
6315913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reckclass MaybeObject BASE_EMBEDDED {
6325913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck public:
6335913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline bool IsFailure();
6345913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline bool IsRetryAfterGC();
6355913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline bool IsOutOfMemory();
6365913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline bool IsException();
6375913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  INLINE(bool IsTheHole());
6385913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline bool ToObject(Object** obj) {
6395913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    if (IsFailure()) return false;
6405913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    *obj = reinterpret_cast<Object*>(this);
6415913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    return true;
6425913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  }
643053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  inline Failure* ToFailureUnchecked() {
644053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block    ASSERT(IsFailure());
645053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block    return reinterpret_cast<Failure*>(this);
646053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  }
6475913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline Object* ToObjectUnchecked() {
6485913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    ASSERT(!IsFailure());
6495913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    return reinterpret_cast<Object*>(this);
6505913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  }
6515913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline Object* ToObjectChecked() {
6525913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    CHECK(!IsFailure());
6535913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    return reinterpret_cast<Object*>(this);
6545913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  }
6555913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
656053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  template<typename T>
657053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  inline bool To(T** obj) {
658053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block    if (IsFailure()) return false;
659053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block    *obj = T::cast(reinterpret_cast<Object*>(this));
660053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block    return true;
661053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  }
662053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block
663b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6645913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  // Prints this object with details.
665b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void Print() {
666b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    Print(stdout);
667b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  };
668b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void PrintLn() {
669b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    PrintLn(stdout);
670b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
671b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void Print(FILE* out);
672b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void PrintLn(FILE* out);
673b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
674b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef DEBUG
6755913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  // Verifies the object.
6765913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  void Verify();
6775913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck#endif
6785913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck};
679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
680b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
681b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch#define OBJECT_TYPE_LIST(V)                    \
682b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Smi)                                       \
683b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(HeapObject)                                \
684b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Number)                                    \
685b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
686b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch#define HEAP_OBJECT_TYPE_LIST(V)               \
687b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(HeapNumber)                                \
688b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(String)                                    \
689b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Symbol)                                    \
690b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(SeqString)                                 \
691b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalString)                            \
692b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ConsString)                                \
693b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalTwoByteString)                     \
694b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalAsciiString)                       \
695b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(SeqTwoByteString)                          \
696b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(SeqAsciiString)                            \
697b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch                                               \
698b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalArray)                             \
699b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalByteArray)                         \
700b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalUnsignedByteArray)                 \
701b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalShortArray)                        \
702b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalUnsignedShortArray)                \
703b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalIntArray)                          \
704b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalUnsignedIntArray)                  \
705b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ExternalFloatArray)                        \
70644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  V(ExternalPixelArray)                        \
707b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(ByteArray)                                 \
708b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSObject)                                  \
709b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSContextExtensionObject)                  \
710b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Map)                                       \
711b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(DescriptorArray)                           \
712b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(DeoptimizationInputData)                   \
713b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(DeoptimizationOutputData)                  \
714b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(FixedArray)                                \
715b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Context)                                   \
716b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(CatchContext)                              \
717b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(GlobalContext)                             \
718b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSFunction)                                \
719b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Code)                                      \
720b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Oddball)                                   \
721b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(SharedFunctionInfo)                        \
722b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSValue)                                   \
7231e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  V(JSMessageObject)                           \
724b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(StringWrapper)                             \
725b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Proxy)                                     \
726b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Boolean)                                   \
727b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSArray)                                   \
728b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSRegExp)                                  \
729b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(HashTable)                                 \
730b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Dictionary)                                \
731b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(SymbolTable)                               \
732b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSFunctionResultCache)                     \
733b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(NormalizedMapCache)                        \
734b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(CompilationCacheTable)                     \
735b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(CodeCacheHashTable)                        \
736b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(MapCache)                                  \
737b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(Primitive)                                 \
738b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(GlobalObject)                              \
739b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSGlobalObject)                            \
740b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSBuiltinsObject)                          \
741b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSGlobalProxy)                             \
742b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(UndetectableObject)                        \
743b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(AccessCheckNeeded)                         \
744b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  V(JSGlobalPropertyCell)                      \
745b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
746a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Object is the abstract superclass for all classes in the
747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// object hierarchy.
748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Object does not use any virtual functions to avoid the
749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// allocation of the C++ vtable.
750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Since Smi and Failure are subclasses of Object no
751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// data members can be present in Object.
7525913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reckclass Object : public MaybeObject {
753a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Type testing.
755b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch#define IS_TYPE_FUNCTION_DECL(type_)  inline bool Is##type_();
756b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
757b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL)
758b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch#undef IS_TYPE_FUNCTION_DECL
759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns true if this object is an instance of the specified
761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // function template.
762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsInstanceOf(FunctionTemplateInfo* type);
763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
764a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsStruct();
765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name();
766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  STRUCT_LIST(DECLARE_STRUCT_PREDICATE)
767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef DECLARE_STRUCT_PREDICATE
768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Oddball testing.
770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  INLINE(bool IsUndefined());
771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  INLINE(bool IsNull());
77244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  INLINE(bool IsTheHole());  // Shadows MaybeObject's implementation.
773a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  INLINE(bool IsTrue());
774a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  INLINE(bool IsFalse());
775086aeeaae12517475c22695a200be45495516549Ben Murdoch  inline bool IsArgumentsMarker();
776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Extract the number.
778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline double Number();
779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool HasSpecificClassOf(String* name);
781a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
7825913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* ToObject();             // ECMA-262 9.9.
7835913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  Object* ToBoolean();                                 // ECMA-262 9.2.
784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Convert to a JSObject if needed.
786a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // global_context is used when creating wrapper object.
7875913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* ToObject(Context* global_context);
788a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
789a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Converts this to a Smi if possible.
790a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Failure is returned otherwise.
7915913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT inline MaybeObject* ToSmi();
792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Lookup(String* name, LookupResult* result);
794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Property access.
7965913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT inline MaybeObject* GetProperty(String* key);
7975913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT inline MaybeObject* GetProperty(
7985913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* key,
7995913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes* attributes);
8005913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver(
8015913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* receiver,
8025913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* key,
8035913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes* attributes);
8045913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver,
8055913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                           LookupResult* result,
8065913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                           String* key,
8075913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                           PropertyAttributes* attributes);
8085913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver,
8095913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                       Object* structure,
8105913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                       String* name,
8115913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                       Object* holder);
8125913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver,
8135913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                            JSFunction* getter);
8145913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
8155913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline MaybeObject* GetElement(uint32_t index);
8165913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  // For use when we know that no exception can be thrown.
8175913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline Object* GetElementNoExceptionThrown(uint32_t index);
8185913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index);
819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return the object's prototype (might be Heap::null_value()).
821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* GetPrototype();
822a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
8237f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Tries to convert an object to an array index.  Returns true and sets
8247f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // the output parameter if it succeeds.
8257f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  inline bool ToArrayIndex(uint32_t* index);
8267f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
827a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns true if this is a JSValue containing a string and the index is
828a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // < the length of the string.  Used to implement [] on strings.
829a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsStringObjectWithCharacterAt(uint32_t index);
830a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Verify a pointer is a valid object pointer.
833a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void VerifyPointer(Object* p);
834a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
836a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Prints this object without details.
837b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ShortPrint() {
838b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ShortPrint(stdout);
839b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
840b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ShortPrint(FILE* out);
841a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
842a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Prints this object without details to a message accumulator.
843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void ShortPrint(StringStream* accumulator);
844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting: This cast is only needed to satisfy macros in objects-inl.h.
846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Object* cast(Object* value) { return value; }
847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeaderSize = 0;  // Object does not take up any space.
850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(Object);
853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Smi represents integer Numbers that can be stored in 31 bits.
857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Smis are immediate which means they are NOT allocated in the heap.
858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The this pointer has the following format: [31 bit signed int] 0
8593ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// For long smis it has the following format:
8603ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block//     [32 bit signed int] [31 bits zero padding] 0
8613ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Smi stands for small integer.
862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Smi: public Object {
863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the integer value.
865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int value();
866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Convert a value to a Smi object.
868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Smi* FromInt(int value);
869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Smi* FromIntptr(intptr_t value);
871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns whether value can be represented in a Smi.
873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool IsValid(intptr_t value);
874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
876a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Smi* cast(Object* object);
877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
879b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void SmiPrint() {
880b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    SmiPrint(stdout);
881b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
882b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void SmiPrint(FILE* out);
883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SmiPrint(StringStream* accumulator);
884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SmiVerify();
886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
8883ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kMinValue = (-1 << (kSmiValueSize - 1));
8893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kMaxValue = -(kMinValue + 1);
890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(Smi);
893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Failure is used for reporting out of memory situations and
897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// propagating exceptions through the runtime system.  Failure objects
898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// are transient and cannot occur as part of the object graph.
899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Failures are a single word, encoded as follows:
901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// +-------------------------+---+--+--+
902f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch// |.........unused..........|sss|tt|11|
903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// +-------------------------+---+--+--+
9043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block//                          7 6 4 32 10
9053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block//
906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The low two bits, 0-1, are the failure tag, 11.  The next two bits,
908a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// 2-3, are a failure type tag 'tt' with possible values:
909a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   00 RETRY_AFTER_GC
910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   01 EXCEPTION
911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   10 INTERNAL_ERROR
912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   11 OUT_OF_MEMORY_EXCEPTION
913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The next three bits, 4-6, are an allocation space tag 'sss'.  The
915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// allocation space tag is 000 for all failure types except
916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// RETRY_AFTER_GC.  For RETRY_AFTER_GC, the possible values are the
917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// allocation spaces (the encoding is found in globals.h).
918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Failure type tag info.
920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kFailureTypeTagSize = 2;
921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockconst int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1;
922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
9235913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reckclass Failure: public MaybeObject {
924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code.
926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  enum Type {
927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    RETRY_AFTER_GC = 0,
928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    EXCEPTION = 1,       // Returning this marker tells the real exception
92944f0eee88ff00398ff7f715fab053374d808c90dSteve Block                         // is in Isolate::pending_exception.
930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    INTERNAL_ERROR = 2,
931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    OUT_OF_MEMORY_EXCEPTION = 3
932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Type type() const;
935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the space that needs to be collected for RetryAfterGC failures.
937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline AllocationSpace allocation_space() const;
938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsInternalError() const;
940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsOutOfMemoryException() const;
941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
942f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  static inline Failure* RetryAfterGC(AllocationSpace space);
943f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  static inline Failure* RetryAfterGC();  // NEW_SPACE
944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Failure* Exception();
945a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Failure* InternalError();
946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Failure* OutOfMemoryException();
947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
9485913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  static inline Failure* cast(MaybeObject* object);
949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
951b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void FailurePrint() {
952b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    FailurePrint(stdout);
953b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
954b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void FailurePrint(FILE* out);
955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void FailurePrint(StringStream* accumulator);
956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void FailureVerify();
958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
9613ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline intptr_t value() const;
9623ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline Failure* Construct(Type type, intptr_t value = 0);
963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(Failure);
965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Heap objects typically have a map pointer in their first word.  However,
969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// during GC other data (eg, mark bits, forwarding addresses) is sometimes
970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// encoded in the first word.  The class MapWord is an abstraction of the
971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// value in a heap object's first word.
972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass MapWord BASE_EMBEDDED {
973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Normal state: the map word contains a map pointer.
975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Create a map word from a map pointer.
977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline MapWord FromMap(Map* map);
978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // View this map word as a map pointer.
980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Map* ToMap();
981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Scavenge collection: the map word of live objects in the from space
984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // contains a forwarding address (a heap object pointer in the to space).
985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // True if this map word is a forwarding address for a scavenge
987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // collection.  Only valid during a scavenge collection (specifically,
988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // when all map words are heap object pointers, ie. not during a full GC).
989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsForwardingAddress();
990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Create a map word from a forwarding address.
992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline MapWord FromForwardingAddress(HeapObject* object);
993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // View this map word as a forwarding address.
995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline HeapObject* ToForwardingAddress();
996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Marking phase of full collection: the map word of live objects is
998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // marked, and may be marked as overflowed (eg, the object is live, its
999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // children have not been visited, and it does not fit in the marking
1000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // stack).
1001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // True if this map word's mark bit is set.
1003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsMarked();
1004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return this map word but with its mark bit set.
1006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SetMark();
1007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return this map word but with its mark bit cleared.
1009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ClearMark();
1010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // True if this map word's overflow bit is set.
1012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsOverflowed();
1013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return this map word but with its overflow bit set.
1015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SetOverflow();
1016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return this map word but with its overflow bit cleared.
1018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ClearOverflow();
1019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1021a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Compacting phase of a full compacting collection: the map word of live
1022a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // objects contains an encoding of the original map address along with the
1023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // forwarding address (represented as an offset from the first live object
1024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // in the same page as the (old) object address).
1025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Create a map word from a map address and a forwarding address offset.
1027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline MapWord EncodeAddress(Address map_address, int offset);
1028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return the map address encoded in this map word.
1030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Address DecodeMapAddress(MapSpace* map_space);
1031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return the forwarding offset encoded in this map word.
1033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int DecodeOffset();
1034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // During serialization: the map word is used to hold an encoded
1037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // address, and possibly a mark bit (set and cleared with SetMark
1038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // and ClearMark).
1039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Create a map word from an encoded address.
1041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline MapWord FromEncodedAddress(Address address);
1042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Address ToEncodedAddress();
1044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bits used by the marking phase of the garbage collector.
1046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //
1047a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The first word of a heap object is normally a map pointer. The last two
1048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to
1049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // mark an object as live and/or overflowed:
1050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //   last bit = 0, marked as alive
1051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //   second bit = 1, overflowed
1052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // An object is only marked as overflowed when it is marked as live while
1053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the marking stack is overflowed.
1054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMarkingBit = 0;  // marking bit
1055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMarkingMask = (1 << kMarkingBit);  // marking mask
1056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kOverflowBit = 1;  // overflow bit
1057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kOverflowMask = (1 << kOverflowBit);  // overflow mask
1058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1059e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Forwarding pointers and map pointer encoding. On 32 bit all the bits are
1060e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // used.
1061a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // +-----------------+------------------+-----------------+
1062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // |forwarding offset|page offset of map|page index of map|
1063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // +-----------------+------------------+-----------------+
1064e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  //          ^                 ^                  ^
1065e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  //          |                 |                  |
1066e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  //          |                 |          kMapPageIndexBits
1067e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  //          |         kMapPageOffsetBits
1068e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // kForwardingOffsetBits
1069e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMapPageOffsetBits = kPageSizeBits - kMapAlignmentBits;
1070e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kForwardingOffsetBits = kPageSizeBits - kObjectAlignmentBits;
1071e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke#ifdef V8_HOST_ARCH_64_BIT
1072e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMapPageIndexBits = 16;
1073e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke#else
1074e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Use all the 32-bits to encode on a 32-bit platform.
1075e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMapPageIndexBits =
1076e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      32 - (kMapPageOffsetBits + kForwardingOffsetBits);
1077e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke#endif
1078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMapPageIndexShift = 0;
1080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMapPageOffsetShift =
1081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kMapPageIndexShift + kMapPageIndexBits;
1082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kForwardingOffsetShift =
1083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kMapPageOffsetShift + kMapPageOffsetBits;
1084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1085e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Bit masks covering the different parts the encoding.
1086e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const uintptr_t kMapPageIndexMask =
1087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      (1 << kMapPageOffsetShift) - 1;
1088e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const uintptr_t kMapPageOffsetMask =
1089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask;
1090e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const uintptr_t kForwardingOffsetMask =
1091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      ~(kMapPageIndexMask | kMapPageOffsetMask);
1092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
1094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // HeapObject calls the private constructor and directly reads the value.
1095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class HeapObject;
1096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  explicit MapWord(uintptr_t value) : value_(value) {}
1098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uintptr_t value_;
1100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// HeapObject is the superclass for all classes describing heap allocated
1104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// objects.
1105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass HeapObject: public Object {
1106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [map]: Contains a map which contains the object's reflective
1108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // information.
1109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Map* map();
1110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_map(Map* value);
1111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // During garbage collection, the map word of a heap object does not
1113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // necessarily contain a map pointer.
1114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline MapWord map_word();
1115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_map_word(MapWord map_word);
1116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
111744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // The Heap the object was allocated in. Used also to access Isolate.
111844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // This method can not be used during GC, it ASSERTs this.
111944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline Heap* GetHeap();
112044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // Convenience method to get current isolate. This method can be
112144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // accessed only when its result is the same as
112244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // Isolate::Current(), it ASSERTs this. See also comment for GetHeap.
112344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline Isolate* GetIsolate();
112444f0eee88ff00398ff7f715fab053374d808c90dSteve Block
1125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Converts an address to a HeapObject pointer.
1126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline HeapObject* FromAddress(Address address);
1127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the address of this HeapObject.
1129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Address address();
1130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Iterates over pointers contained in the object (including the Map)
1132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Iterate(ObjectVisitor* v);
1133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Iterates over all pointers contained in the object except the
1135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // first map pointer.  The object type is given in the first
1136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // parameter. This function does not access the map pointer in the
1137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // object, and so is safe to call while the map pointer is modified.
1138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void IterateBody(InstanceType type, int object_size, ObjectVisitor* v);
1139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the heap object's size in bytes
1141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int Size();
1142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Given a heap object's map pointer, returns the heap size in bytes
1144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Useful when the map pointer field is used for other purposes.
1145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // GC internal.
1146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int SizeFromMap(Map* map);
1147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1148a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Support for the marking heap objects during the marking phase of GC.
1149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // True if the object is marked live.
1150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsMarked();
1151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Mutate this object's map pointer to indicate that the object is live.
1153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SetMark();
1154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Mutate this object's map pointer to remove the indication that the
1156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // object is live (ie, partially restore the map pointer).
1157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ClearMark();
1158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // True if this object is marked as overflowed.  Overflowed objects have
1160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // been reached and marked during marking of the heap, but their children
1161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // have not necessarily been marked and they have not been pushed on the
1162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // marking stack.
1163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsOverflowed();
1164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Mutate this object's map pointer to indicate that the object is
1166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // overflowed.
1167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SetOverflow();
1168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Mutate this object's map pointer to remove the indication that the
1170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // object is overflowed (ie, partially restore the map pointer).
1171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ClearOverflow();
1172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the field at offset in obj, as a read/write Object* reference.
1174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Does no checking, and is safe to use during GC, while maps are invalid.
11757f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Does not invoke write barrier, so should only be assigned to
1176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // during marking GC.
1177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Object** RawField(HeapObject* obj, int offset);
1178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
1180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline HeapObject* cast(Object* obj);
1181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
11824515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // Return the write barrier mode for this. Callers of this function
11834515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // must be able to present a reference to an AssertNoAllocation
11844515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // object as a sign that they are not going to use this function
11854515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // from code that allocates and thus invalidates the returned write
11864515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // barrier mode.
11874515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&);
1188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
1190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void HeapObjectShortPrint(StringStream* accumulator);
1191b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
1192b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void HeapObjectPrint() {
1193b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    HeapObjectPrint(stdout);
1194b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
1195b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void HeapObjectPrint(FILE* out);
1196b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
1197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
1198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void HeapObjectVerify();
1199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void VerifyObjectField(int offset);
12007f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  inline void VerifySmiField(int offset);
1201b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
1202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1203b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
1204b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void PrintHeader(FILE* out, const char* id);
1205b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
1206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1207b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef DEBUG
1208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Verify a pointer is a valid HeapObject pointer that points to object
1209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // areas in the heap.
1210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void VerifyHeapPointer(Object* p);
1211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
1212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
1214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // First field in a heap object is map.
1215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMapOffset = Object::kHeaderSize;
1216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeaderSize = kMapOffset + kPointerSize;
1217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset);
1219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block protected:
1221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // helpers for calling an ObjectVisitor to iterate over pointers in the
1222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // half-open range [start, end) specified as integer offsets
1223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void IteratePointers(ObjectVisitor* v, int start, int end);
1224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // as above, for the single element at "offset"
1225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void IteratePointer(ObjectVisitor* v, int offset);
1226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
1228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject);
1229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1232756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick#define SLOT_ADDR(obj, offset) \
1233756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  reinterpret_cast<Object**>((obj)->address() + offset)
1234756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1235756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick// This class describes a body of an object of a fixed size
1236756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick// in which all pointer fields are located in the [start_offset, end_offset)
1237756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick// interval.
1238756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merricktemplate<int start_offset, int end_offset, int size>
1239756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrickclass FixedBodyDescriptor {
1240756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick public:
1241756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static const int kStartOffset = start_offset;
1242756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static const int kEndOffset = end_offset;
1243756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static const int kSize = size;
1244756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1245756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static inline void IterateBody(HeapObject* obj, ObjectVisitor* v);
1246756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1247756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  template<typename StaticVisitor>
1248756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static inline void IterateBody(HeapObject* obj) {
1249756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset),
1250756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                                 SLOT_ADDR(obj, end_offset));
1251756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  }
1252756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick};
1253756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1254756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1255756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick// This class describes a body of an object of a variable size
1256756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick// in which all pointer fields are located in the [start_offset, object_size)
1257756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick// interval.
1258756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merricktemplate<int start_offset>
1259756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrickclass FlexibleBodyDescriptor {
1260756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick public:
1261756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static const int kStartOffset = start_offset;
1262756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1263756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static inline void IterateBody(HeapObject* obj,
1264756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                                 int object_size,
1265756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                                 ObjectVisitor* v);
1266756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1267756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  template<typename StaticVisitor>
1268756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static inline void IterateBody(HeapObject* obj, int object_size) {
1269756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset),
1270756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                                 SLOT_ADDR(obj, object_size));
1271756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  }
1272756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick};
1273756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1274756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick#undef SLOT_ADDR
1275756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1276756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The HeapNumber class describes heap allocated numbers that cannot be
1278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// represented in a Smi (small integer)
1279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass HeapNumber: public HeapObject {
1280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [value]: number value.
1282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline double value();
1283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_value(double value);
1284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
1286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline HeapNumber* cast(Object* obj);
1287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
1289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* HeapNumberToBoolean();
1290b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void HeapNumberPrint() {
1291b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    HeapNumberPrint(stdout);
1292b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
1293b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void HeapNumberPrint(FILE* out);
1294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void HeapNumberPrint(StringStream* accumulator);
1295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
1296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void HeapNumberVerify();
1297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
1298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
12996ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline int get_exponent();
13006ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline int get_sign();
13016ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
1302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
1303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kValueOffset = HeapObject::kHeaderSize;
1304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // IEEE doubles are two 32 bit words.  The first is just mantissa, the second
1305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // is a mixture of sign, exponent and mantissa.  Our current platforms are all
1306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // little endian apart from non-EABI arm which is little endian with big
1307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // endian floating point word ordering!
1308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMantissaOffset = kValueOffset;
1309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kExponentOffset = kValueOffset + 4;
13108b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch
1311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kValueOffset + kDoubleSize;
1312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const uint32_t kSignMask = 0x80000000u;
1313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const uint32_t kExponentMask = 0x7ff00000u;
1314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const uint32_t kMantissaMask = 0xfffffu;
13156ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kMantissaBits = 52;
13169dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  static const int kExponentBits = 11;
1317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kExponentBias = 1023;
1318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kExponentShift = 20;
1319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMantissaBitsInTopWord = 20;
1320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNonMantissaBitsInTopWord = 12;
1321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
1323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber);
1324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The JSObject describes real heap allocated JavaScript objects with
1328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// properties.
1329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Note that the map of JSObject changes during execution to enable inline
1330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// caching.
1331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSObject: public HeapObject {
1332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1333e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  enum DeleteMode {
1334e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    NORMAL_DELETION,
1335e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    STRICT_DELETION,
1336e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    FORCE_DELETION
1337e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  };
1338e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch
1339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  enum ElementsKind {
1340756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    // The only "fast" kind.
1341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    FAST_ELEMENTS,
1342756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    // All the kinds below are "slow".
1343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    DICTIONARY_ELEMENTS,
13443ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    EXTERNAL_BYTE_ELEMENTS,
13453ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    EXTERNAL_UNSIGNED_BYTE_ELEMENTS,
13463ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    EXTERNAL_SHORT_ELEMENTS,
13473ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    EXTERNAL_UNSIGNED_SHORT_ELEMENTS,
13483ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    EXTERNAL_INT_ELEMENTS,
13493ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block    EXTERNAL_UNSIGNED_INT_ELEMENTS,
135044f0eee88ff00398ff7f715fab053374d808c90dSteve Block    EXTERNAL_FLOAT_ELEMENTS,
135144f0eee88ff00398ff7f715fab053374d808c90dSteve Block    EXTERNAL_PIXEL_ELEMENTS
1352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [properties]: Backing storage for properties.
13557f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // properties is a FixedArray in the fast case and a Dictionary in the
1356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // slow case.
1357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(properties, FixedArray)  // Get and set fast properties.
1358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void initialize_properties();
1359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool HasFastProperties();
1360a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline StringDictionary* property_dictionary();  // Gets slow properties.
1361a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [elements]: The elements (properties with names that are integers).
1363756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  //
1364756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // Elements can be in two general modes: fast and slow. Each mode
1365756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // corrensponds to a set of object representations of elements that
1366756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // have something in common.
1367756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  //
1368756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // In the fast mode elements is a FixedArray and so each element can
1369756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // be quickly accessed. This fact is used in the generated code. The
1370756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // elements array can have one of the two maps in this mode:
1371756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // fixed_array_map or fixed_cow_array_map (for copy-on-write
1372756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // arrays). In the latter case the elements array may be shared by a
1373756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // few objects and so before writing to any element the array must
1374756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // be copied. Use EnsureWritableFastElements in this case.
1375756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  //
137644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // In the slow mode elements is either a NumberDictionary or an ExternalArray.
13777f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  DECL_ACCESSORS(elements, HeapObject)
1378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void initialize_elements();
13795913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT inline MaybeObject* ResetElements();
1380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline ElementsKind GetElementsKind();
1381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool HasFastElements();
1382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool HasDictionaryElements();
138344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline bool HasExternalPixelElements();
13843ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline bool HasExternalArrayElements();
13853ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline bool HasExternalByteElements();
13863ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline bool HasExternalUnsignedByteElements();
13873ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline bool HasExternalShortElements();
13883ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline bool HasExternalUnsignedShortElements();
13893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline bool HasExternalIntElements();
13903ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline bool HasExternalUnsignedIntElements();
13913ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline bool HasExternalFloatElements();
13926ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline bool AllowsSetElementsLength();
1393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline NumberDictionary* element_dictionary();  // Gets slow elements.
1394756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // Requires: this->HasFastElements().
13955913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements();
1396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Collects elements starting at index 0.
1398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Undefined values are placed after non-undefined values.
1399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of non-undefined values.
14005913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit);
1401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // As PrepareElementsForSort, but only on objects where elements is
1402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // a dictionary, and it will stay a dictionary.
14035913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit);
14045913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
14055913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetProperty(String* key,
14065913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                           Object* value,
1407e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch                                           PropertyAttributes attributes,
1408e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch                                           StrictModeFlag strict_mode);
14095913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result,
14105913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                           String* key,
14115913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                           Object* value,
1412e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch                                           PropertyAttributes attributes,
1413e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch                                           StrictModeFlag strict_mode);
14145913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck(
14155913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      LookupResult* result,
14165913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
1417086aeeaae12517475c22695a200be45495516549Ben Murdoch      Object* value,
1418086aeeaae12517475c22695a200be45495516549Ben Murdoch      bool check_prototype);
14195913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetPropertyWithCallback(Object* structure,
14205913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                       String* name,
14215913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                       Object* value,
14225913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                       JSObject* holder);
14235913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSFunction* setter,
14245913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                            Object* value);
14255913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor(
14265913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
14275913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* value,
1428e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      PropertyAttributes attributes,
1429e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      StrictModeFlag strict_mode);
14305913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor(
14315913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
14325913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* value,
1433e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      PropertyAttributes attributes,
1434e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      StrictModeFlag strict_mode);
1435086aeeaae12517475c22695a200be45495516549Ben Murdoch  MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes(
14365913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* key,
14375913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* value,
14385913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes attributes);
1439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Retrieve a value in a normalized object given a lookup result.
1441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Handles the special representation of JS global objects.
1442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* GetNormalizedProperty(LookupResult* result);
1443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets the property value in a normalized object given a lookup result.
1445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Handles the special representation of JS global objects.
1446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* SetNormalizedProperty(LookupResult* result, Object* value);
1447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets the property value in a normalized object given (key, value, details).
1449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Handles the special representation of JS global objects.
14505913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name,
14515913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                     Object* value,
14525913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                     PropertyDetails details);
1453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Deletes the named property in a normalized object.
14555913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name,
14565913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                        DeleteMode mode);
1457a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the class name ([[Class]] property in the specification).
1459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  String* class_name();
1460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the constructor name (the name (possibly, inferred name) of the
1462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // function that was used to instantiate the object).
1463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  String* constructor_name();
1464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Retrieve interceptors.
1466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  InterceptorInfo* GetNamedInterceptor();
1467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  InterceptorInfo* GetIndexedInterceptor();
1468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline PropertyAttributes GetPropertyAttribute(String* name);
1470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyAttributes GetPropertyAttributeWithReceiver(JSObject* receiver,
1471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                      String* name);
1472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyAttributes GetLocalPropertyAttribute(String* name);
1473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14745913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DefineAccessor(String* name,
14755913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                              bool is_getter,
1476b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch                                              Object* fun,
14775913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                              PropertyAttributes attributes);
1478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* LookupAccessor(String* name, bool is_getter);
1479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
14805913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info);
1481f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
1482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Used from Object::GetProperty().
14835913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* GetPropertyWithFailedAccessCheck(
14845913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* receiver,
14855913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      LookupResult* result,
14865913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
14875913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes* attributes);
14885913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* GetPropertyWithInterceptor(
14895913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      JSObject* receiver,
14905913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
14915913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes* attributes);
14925913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* GetPropertyPostInterceptor(
14935913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      JSObject* receiver,
14945913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
14955913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes* attributes);
14965913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* GetLocalPropertyPostInterceptor(JSObject* receiver,
14975913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                               String* name,
14985913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                               PropertyAttributes* attributes);
1499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns true if this is an instance of an api function and has
1501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // been modified since it was created.  May give false positives.
1502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsDirty();
1503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasProperty(String* name) {
1505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return GetPropertyAttribute(name) != ABSENT;
1506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
1507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Can cause a GC if it hits an interceptor.
1509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasLocalProperty(String* name) {
1510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return GetLocalPropertyAttribute(name) != ABSENT;
1511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
1512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1513d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // If the receiver is a JSGlobalProxy this method will return its prototype,
1514d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // otherwise the result is the receiver itself.
1515d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  inline Object* BypassGlobalProxy();
1516d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
1517d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Accessors for hidden properties object.
1518d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  //
1519d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Hidden properties are not local properties of the object itself.
1520d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Instead they are stored on an auxiliary JSObject stored as a local
1521d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // property with a special name Heap::hidden_symbol(). But if the
1522d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // receiver is a JSGlobalProxy then the auxiliary object is a property
1523d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // of its prototype.
1524d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  //
1525d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Has/Get/SetHiddenPropertiesObject methods don't allow the holder to be
1526d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // a JSGlobalProxy. Use BypassGlobalProxy method above to get to the real
1527d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // holder.
1528d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  //
1529d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // These accessors do not touch interceptors or accessors.
1530d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  inline bool HasHiddenPropertiesObject();
1531d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  inline Object* GetHiddenPropertiesObject();
15325913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT inline MaybeObject* SetHiddenPropertiesObject(
15335913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* hidden_obj);
1534d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
15355913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode);
15365913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode);
1537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tests for the fast common case for property enumeration.
1539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsSimpleEnum();
1540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Do we want to keep the elements in fast case when increasing the
1542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // capacity?
1543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool ShouldConvertToSlowElements(int new_capacity);
1544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns true if the backing storage for the slow-case elements of
1545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // this object takes up nearly as much space as a fast-case backing
1546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // storage would.  In that case the JSObject should have fast
1547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // elements.
1548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool ShouldConvertToFastElements();
1549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return the object's prototype (might be Heap::null_value()).
1551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* GetPrototype();
1552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1553402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // Set the object's prototype (only JSObject and null are allowed).
15545913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetPrototype(Object* value,
15555913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                            bool skip_hidden_prototypes);
1556402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
1557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether the index'th element is present.
1558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool HasElement(uint32_t index);
1559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasElementWithReceiver(JSObject* receiver, uint32_t index);
15600d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
1561e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // Computes the new capacity when expanding the elements of a JSObject.
1562e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  static int NewElementsCapacity(int old_capacity) {
1563e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    // (old_capacity + 50%) + 16
1564e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    return old_capacity + (old_capacity >> 1) + 16;
1565e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  }
1566e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch
15670d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Tells whether the index'th element is present and how it is stored.
15680d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  enum LocalElementType {
15690d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    // There is no element with given index.
15700d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    UNDEFINED_ELEMENT,
15710d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
15720d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    // Element with given index is handled by interceptor.
15730d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    INTERCEPTED_ELEMENT,
15740d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
15750d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    // Element with given index is character in string.
15760d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    STRING_CHARACTER_ELEMENT,
15770d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
15780d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    // Element with given index is stored in fast backing store.
15790d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    FAST_ELEMENT,
15800d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
15810d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    // Element with given index is stored in slow backing store.
15820d5e116f6aee03185f237311a943491bb079a768Kristian Monsen    DICTIONARY_ELEMENT
15830d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  };
15840d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
15850d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  LocalElementType HasLocalElement(uint32_t index);
1586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasElementWithInterceptor(JSObject* receiver, uint32_t index);
1588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasElementPostInterceptor(JSObject* receiver, uint32_t index);
1589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
15909fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index,
15919fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block                                              Object* value,
1592e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch                                              StrictModeFlag strict_mode,
15939fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block                                              bool check_prototype = true);
1594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set the index'th array element.
1596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // A Failure object is returned if GC is needed.
15979fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  MUST_USE_RESULT MaybeObject* SetElement(uint32_t index,
15989fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block                                          Object* value,
1599e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch                                          StrictModeFlag strict_mode,
16009fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block                                          bool check_prototype = true);
1601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the index'th element.
1603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The undefined object if index is out of bounds.
1604e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index);
1605e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index);
1606e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch
1607e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // Get external element value at index if there is one and undefined
1608e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // otherwise. Can return a failure if allocation of a heap number
1609e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // failed.
1610e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  MaybeObject* GetExternalElement(uint32_t index);
1611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
16125913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity,
16135913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                                int length);
16145913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length);
1615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Lookup interceptors are used for handling properties controlled by host
1617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // objects.
1618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool HasNamedInterceptor();
1619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool HasIndexedInterceptor();
1620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Support functions for v8 api (needed for correct interceptor behavior).
1622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasRealNamedProperty(String* key);
1623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasRealElementProperty(uint32_t index);
1624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasRealNamedCallbackProperty(String* key);
1625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Initializes the array to a certain length
16275913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length);
1628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get the header size for a JSObject.  Used to compute the index of
1630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // internal fields as well as the number of internal fields.
1631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int GetHeaderSize();
1632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int GetInternalFieldCount();
163444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline int GetInternalFieldOffset(int index);
1635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* GetInternalField(int index);
1636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SetInternalField(int index, Object* value);
1637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Lookup a property.  If found, the result is valid and has
1639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // detailed information.
1640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void LocalLookup(String* name, LookupResult* result);
1641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Lookup(String* name, LookupResult* result);
1642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The following lookup functions skip interceptors.
1644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void LocalLookupRealNamedProperty(String* name, LookupResult* result);
1645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void LookupRealNamedProperty(String* name, LookupResult* result);
1646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result);
1647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void LookupCallbackSetterInPrototypes(String* name, LookupResult* result);
16481e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes(
16491e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block      uint32_t index, Object* value, bool* found);
1650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void LookupCallback(String* name, LookupResult* result);
1651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1652a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of properties on this object filtering out properties
1653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // with the specified attributes (ignoring interceptors).
1654a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NumberOfLocalProperties(PropertyAttributes filter);
1655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of enumerable properties (ignoring interceptors).
1656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NumberOfEnumProperties();
1657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Fill in details for properties into storage starting at the specified
1658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // index.
1659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void GetLocalPropertyNames(FixedArray* storage, int index);
1660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of properties on this object filtering out properties
1662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // with the specified attributes (ignoring interceptors).
1663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NumberOfLocalElements(PropertyAttributes filter);
1664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of enumerable elements (ignoring interceptors).
1665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NumberOfEnumElements();
1666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of elements on this object filtering out elements
1667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // with the specified attributes (ignoring interceptors).
1668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter);
1669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Count and fill in the enumerable elements into storage.
1670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // (storage->length() == NumberOfEnumElements()).
1671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // If storage is NULL, will count the elements without adding
1672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // them to any storage.
1673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of enumerable elements.
1674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetEnumElementKeys(FixedArray* storage);
1675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add a property to a fast-case object using a map transition to
1677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // new_map.
16785913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map,
16795913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                       String* name,
16805913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                       Object* value);
1681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add a constant function property to a fast-case object.
1683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // This leaves a CONSTANT_TRANSITION in the old map, and
1684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // if it is called on a second object with this map, a
1685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // normal property is added instead, with a map transition.
1686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // This avoids the creation of many maps with the same constant
1687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // function, all orphaned.
16885913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty(
16895913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
16905913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      JSFunction* function,
16915913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes attributes);
1692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
16935913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* ReplaceSlowProperty(
16945913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
16955913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* value,
16965913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes attributes);
1697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Converts a descriptor of any other type to a real field,
1699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // backed by the properties array.  Descriptors of visible
1700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // types, such as CONSTANT_FUNCTION, keep their enumeration order.
1701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Converts the descriptor on the original object's map to a
1702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // map transition, and the the new field is on the object's new map.
17035913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition(
1704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      String* name,
1705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Object* new_value,
1706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      PropertyAttributes attributes);
1707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Converts a descriptor of any other type to a real field,
1709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // backed by the properties array.  Descriptors of visible
1710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // types, such as CONSTANT_FUNCTION, keep their enumeration order.
17115913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* ConvertDescriptorToField(
17125913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
17135913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* new_value,
17145913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes attributes);
1715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add a property to a fast-case object.
17175913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AddFastProperty(String* name,
17185913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                               Object* value,
17195913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                               PropertyAttributes attributes);
1720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add a property to a slow-case object.
17225913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name,
17235913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                               Object* value,
17245913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                               PropertyAttributes attributes);
1725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add a property to an object.
17275913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AddProperty(String* name,
17285913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                           Object* value,
172944f0eee88ff00398ff7f715fab053374d808c90dSteve Block                                           PropertyAttributes attributes,
173044f0eee88ff00398ff7f715fab053374d808c90dSteve Block                                           StrictModeFlag strict_mode);
1731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Convert the object to use the canonical dictionary
1733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // representation. If the object is expected to have additional properties
1734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // added this number can be indicated to have the backing store allocated to
1735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // an initial capacity for holding these properties.
17365913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* NormalizeProperties(
17375913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyNormalizationMode mode,
17385913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      int expected_additional_properties);
17395913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* NormalizeElements();
1740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
17415913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code);
174280d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
1743a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Transform slow named properties to fast variants.
1744a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns failure if allocation failed.
17455913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* TransformToFastProperties(
17465913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      int unused_property_fields);
1747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Access fast-case object properties at index.
1749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* FastPropertyAt(int index);
1750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* FastPropertyAtPut(int index, Object* value);
1751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Access to in object properties.
175344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline int GetInObjectPropertyOffset(int index);
1754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* InObjectPropertyAt(int index);
1755a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* InObjectPropertyAtPut(int index,
1756a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       Object* value,
1757a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       WriteBarrierMode mode
1758a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                       = UPDATE_WRITE_BARRIER);
1759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // initializes the body after properties slot, properties slot is
1761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // initialized by set_properties
1762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Note: this call does not update write barrier, it is caller's
1763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // reponsibility to ensure that *v* can be collected without WB here.
17640d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline void InitializeBody(int object_size, Object* value);
1765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Check whether this object references another object
1767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool ReferencesObject(Object* obj);
1768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
1770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline JSObject* cast(Object* obj);
1771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
17728defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // Disalow further properties to be added to the object.
17735913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* PreventExtensions();
17748defd9ff6930b4e24729971a61cf7469daf119beSteve Block
17758defd9ff6930b4e24729971a61cf7469daf119beSteve Block
1776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
1777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSObjectShortPrint(StringStream* accumulator);
1778b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
1779b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void JSObjectPrint() {
1780b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    JSObjectPrint(stdout);
1781b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
1782b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void JSObjectPrint(FILE* out);
1783b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
1784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
1785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSObjectVerify();
1786b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
1787b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
1788b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void PrintProperties() {
1789b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    PrintProperties(stdout);
1790b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
1791b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void PrintProperties(FILE* out);
1792b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
1793b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void PrintElements() {
1794b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    PrintElements(stdout);
1795b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
1796b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void PrintElements(FILE* out);
1797b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
1798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1799b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef DEBUG
1800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Structure for collecting spill information about JSObjects.
1801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class SpillInformation {
1802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
1803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void Clear();
1804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    void Print();
1805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_objects_;
1806a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_objects_with_fast_properties_;
1807a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_objects_with_fast_elements_;
1808a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_fast_used_fields_;
1809a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_fast_unused_fields_;
1810a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_slow_used_properties_;
1811a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_slow_unused_properties_;
1812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_fast_used_elements_;
1813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_fast_unused_elements_;
1814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_slow_used_elements_;
1815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    int number_of_slow_unused_elements_;
1816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
1817a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1818a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void IncrementSpillStatistics(SpillInformation* info);
1819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
1820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* SlowReverseLookup(Object* value);
1821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
18228defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // Maximal number of fast properties for the JSObject. Used to
18238defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // restrict the number of map transitions to avoid an explosion in
18248defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // the number of maps for objects used as dictionaries.
18258defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline int MaxFastProperties();
18268defd9ff6930b4e24729971a61cf7469daf119beSteve Block
1827e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximal number of elements (numbered 0 .. kMaxElementCount - 1).
1828e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Also maximal value of JSArray's length property.
1829e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const uint32_t kMaxElementCount = 0xffffffffu;
1830e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
1831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const uint32_t kMaxGap = 1024;
1832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxFastElementsLength = 5000;
1833a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInitialMaxFastElementArray = 100000;
1834b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kMaxFastProperties = 12;
1835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxInstanceSize = 255 * kPointerSize;
1836a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // When extending the backing storage for property values, we increase
1837a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // its size by more than the 1 entry necessary, so sequentially adding fields
1838a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // to the same object requires fewer allocations and copies.
1839a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFieldsAdded = 3;
1840a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1841a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
1842a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPropertiesOffset = HeapObject::kHeaderSize;
1843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kElementsOffset = kPropertiesOffset + kPointerSize;
1844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeaderSize = kElementsOffset + kPointerSize;
1845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize);
1847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1848756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> {
1849756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick   public:
1850756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    static inline int SizeOf(Map* map, HeapObject* object);
1851756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  };
1852756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
1853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
18545913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver,
18555913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                      Object* structure,
18565913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                      uint32_t index,
18575913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                      Object* holder);
18585913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* SetElementWithCallback(Object* structure,
18595913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                      uint32_t index,
18605913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                      Object* value,
18615913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                      JSObject* holder);
1862e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  MUST_USE_RESULT MaybeObject* SetElementWithInterceptor(
1863e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      uint32_t index,
1864e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      Object* value,
1865e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      StrictModeFlag strict_mode,
1866e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      bool check_prototype);
18679fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor(
18689fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      uint32_t index,
18699fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      Object* value,
1870e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      StrictModeFlag strict_mode,
18719fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      bool check_prototype);
18725913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
1873e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  MaybeObject* GetElementPostInterceptor(Object* receiver, uint32_t index);
18745913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
18755913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name,
18765913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                             DeleteMode mode);
18775913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name);
18785913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
18795913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DeleteElementPostInterceptor(uint32_t index,
18805913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                            DeleteMode mode);
18815913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index);
1882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver,
1884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                         String* name,
1885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                         bool continue_search);
1886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver,
1887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                         String* name,
1888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                         bool continue_search);
1889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyAttributes GetPropertyAttributeWithFailedAccessCheck(
1890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Object* receiver,
1891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      LookupResult* result,
1892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      String* name,
1893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      bool continue_search);
1894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyAttributes GetPropertyAttribute(JSObject* receiver,
1895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          LookupResult* result,
1896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          String* name,
1897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                          bool continue_search);
1898a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns true if most of the elements backing storage is used.
1900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasDenseElements();
1901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1902f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  bool CanSetCallback(String* name);
19035913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetElementCallback(
19045913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      uint32_t index,
19055913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* structure,
19065913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes attributes);
19075913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetPropertyCallback(
19085913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
19095913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      Object* structure,
19105913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes attributes);
19115913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* DefineGetterSetter(
19125913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      String* name,
19135913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      PropertyAttributes attributes);
1914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void LookupInDescriptor(String* name, LookupResult* result);
1916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject);
1918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
1919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
19217f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch// FixedArray describes fixed-sized arrays with element type Object*.
19227f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochclass FixedArray: public HeapObject {
1923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
1924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [length]: length of the array.
1925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int length();
1926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_length(int value);
1927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Setter and getter for elements.
1929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* get(int index);
1930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Setter that uses write barrier.
1931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set(int index, Object* value);
1932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Setter that doesn't need write barrier).
1934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set(int index, Smi* value);
1935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Setter with explicit barrier mode.
1936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set(int index, Object* value, WriteBarrierMode mode);
1937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Setters for frequently used oddballs located in old space.
1939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_undefined(int index);
194044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // TODO(isolates): duplicate.
194144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void set_undefined(Heap* heap, int index);
1942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_null(int index);
194344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // TODO(isolates): duplicate.
194444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void set_null(Heap* heap, int index);
1945a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_the_hole(int index);
1946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1947756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // Setters with less debug checks for the GC to use.
1948756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void set_unchecked(int index, Smi* value);
194944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void set_null_unchecked(Heap* heap, int index);
195044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void set_unchecked(Heap* heap, int index, Object* value,
195144f0eee88ff00398ff7f715fab053374d808c90dSteve Block                            WriteBarrierMode mode);
1952756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
19536ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Gives access to raw memory which stores the array's data.
19546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline Object** data_start();
19556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
1956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Copy operations.
19575913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT inline MaybeObject* Copy();
19585913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* CopySize(int new_length);
1959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add the elements of a JSArray to this FixedArray.
19615913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array);
1962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Compute the union of this and other.
19645913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other);
1965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Copy a sub array from the receiver to dest.
1967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CopyTo(int pos, FixedArray* dest, int dest_pos, int len);
1968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Garbage collection support.
1970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; }
1971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Code Generation support.
1973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int OffsetOfElementAt(int index) { return SizeFor(index); }
1974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
1976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline FixedArray* cast(Object* obj);
1977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
19787f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Layout description.
19797f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Length is smi tagged when it is stored.
19807f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kLengthOffset = HeapObject::kHeaderSize;
19817f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kHeaderSize = kLengthOffset + kPointerSize;
1982e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
1983e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximal allowed size, in bytes, of a single FixedArray.
1984e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Prevents overflowing size computations, as well as extreme memory
1985e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // consumption.
1986e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMaxSize = 512 * MB;
1987e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximally allowed length of a FixedArray.
1988e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize;
1989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
1990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
1991b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
1992b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void FixedArrayPrint() {
1993b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    FixedArrayPrint(stdout);
1994b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
1995b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void FixedArrayPrint(FILE* out);
1996b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
1997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
1998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void FixedArrayVerify();
1999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Checks if two FixedArrays have identical contents.
2000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsEqualTo(FixedArray* other);
2001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
2002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Swap two elements in a pair of arrays.  If this array and the
2004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // numbers array are the same object, the elements are only swapped
2005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // once.
2006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SwapPairs(FixedArray* numbers, int i, int j);
2007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sort prefix of this array and the numbers array as pairs wrt. the
2009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // numbers.  If the numbers array and the this array are the same
2010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // object, the prefix of this array is sorted.
2011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SortPairs(FixedArray* numbers, uint32_t len);
2012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2013756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> {
2014756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick   public:
2015756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    static inline int SizeOf(Map* map, HeapObject* object) {
2016756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick      return SizeFor(reinterpret_cast<FixedArray*>(object)->length());
2017756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    }
2018756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  };
2019756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
2020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block protected:
20214515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // Set operation on FixedArray without using write barriers. Can
20224515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // only be used for storing old space objects or smis.
2023a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline void fast_set(FixedArray* array, int index, Object* value);
2024a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2025a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2026a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray);
2027a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// DescriptorArrays are fixed arrays used to hold instance descriptors.
2031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The format of the these objects is:
2032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   [0]: point to a fixed array with (value, detail) pairs.
2033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   [1]: next enumeration index (Smi), or pointer to small fixed array:
2034a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//          [0]: next enumeration index (Smi)
2035a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//          [1]: pointer to fixed array with enum cache
2036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   [2]: first key
2037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   [length() - 1]: last key
2038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
2039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass DescriptorArray: public FixedArray {
2040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Is this the singleton empty_descriptor_array?
2042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsEmpty();
2043e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
2044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of descriptors in the array.
2045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int number_of_descriptors() {
204644f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ASSERT(length() > kFirstIndex || IsEmpty());
204744f0eee88ff00398ff7f715fab053374d808c90dSteve Block    int len = length();
204844f0eee88ff00398ff7f715fab053374d808c90dSteve Block    return len <= kFirstIndex ? 0 : len - kFirstIndex;
2049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NextEnumerationIndex() {
2052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (IsEmpty()) return PropertyDetails::kInitialIndex;
2053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    Object* obj = get(kEnumerationIndexIndex);
2054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (obj->IsSmi()) {
2055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      return Smi::cast(obj)->value();
2056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    } else {
2057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex);
2058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      return Smi::cast(index)->value();
2059a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
2060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2061a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set next enumeration index and flush any enum cache.
2063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetNextEnumerationIndex(int value) {
2064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (!IsEmpty()) {
2065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      fast_set(this, kEnumerationIndexIndex, Smi::FromInt(value));
2066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
2067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasEnumCache() {
2069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi();
2070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* GetEnumCache() {
2073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(HasEnumCache());
2074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex));
2075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return bridge->get(kEnumCacheBridgeCacheIndex);
2076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Initialize or change the enum cache,
2079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // using the supplied storage for the small "bridge".
2080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetEnumCache(FixedArray* bridge_storage, FixedArray* new_cache);
2081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Accessors for fetching instance descriptor at descriptor number.
2083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline String* GetKey(int descriptor_number);
2084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* GetValue(int descriptor_number);
2085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Smi* GetDetails(int descriptor_number);
2086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline PropertyType GetType(int descriptor_number);
2087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int GetFieldIndex(int descriptor_number);
2088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline JSFunction* GetConstantFunction(int descriptor_number);
2089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* GetCallbacksObject(int descriptor_number);
2090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline AccessorDescriptor* GetCallbacks(int descriptor_number);
2091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsProperty(int descriptor_number);
2092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsTransition(int descriptor_number);
2093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsNullDescriptor(int descriptor_number);
2094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsDontEnum(int descriptor_number);
2095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Accessor for complete descriptor.
2097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Get(int descriptor_number, Descriptor* desc);
2098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Set(int descriptor_number, Descriptor* desc);
2099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Transfer complete descriptor from another descriptor array to
2101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // this one.
2102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void CopyFrom(int index, DescriptorArray* src, int src_index);
2103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Copy the descriptor array, insert a new descriptor and optionally
2105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // remove map transitions.  If the descriptor is already present, it is
2106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // replaced.  If a replaced descriptor is a real property (not a transition
2107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // or null), its enumeration index is kept as is.
2108a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // If adding a real property, map transitions must be removed.  If adding
2109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // a transition, they must not be removed.  All null descriptors are removed.
21105913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor,
21115913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                          TransitionFlag transition_flag);
2112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Remove all transitions.  Return  a copy of the array with all transitions
2114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // removed, or a Failure object if the new array could not be allocated.
21155913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* RemoveTransitions();
2116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sort the instance descriptors by the hash codes of their keys.
21180d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Does not check for duplicates.
21190d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  void SortUnchecked();
21200d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
21210d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Sort the instance descriptors by the hash codes of their keys.
21220d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Checks the result for duplicates.
2123a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Sort();
2124a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2125a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Search the instance descriptors for given name.
2126a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int Search(String* name);
2127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2128756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // As the above, but uses DescriptorLookupCache and updates it when
2129756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // necessary.
2130756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline int SearchWithCache(String* name);
2131756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
2132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether the name is present int the array.
2133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool Contains(String* name) { return kNotFound != Search(name); }
2134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Perform a binary search in the instance descriptors represented
2136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // by this fixed array.  low and high are descriptor indices.  If there
2137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // are three instance descriptors in this array it should be called
2138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // with low=0 and high=2.
2139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int BinarySearch(String* name, int low, int high);
2140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Perform a linear search in the instance descriptors represented
2142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // by this fixed array.  len is the number of descriptor indices that are
2143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // valid.  Does not require the descriptors to be sorted.
2144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int LinearSearch(String* name, int len);
2145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Allocates a DescriptorArray, but returns the singleton
2147a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // empty descriptor array object if number_of_descriptors is 0.
21485913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors);
2149a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2150a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
2151a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline DescriptorArray* cast(Object* obj);
2152a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2153a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Constant for denoting key was not found.
2154a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNotFound = -1;
2155a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2156a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kContentArrayIndex = 0;
2157a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEnumerationIndexIndex = 1;
2158a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFirstIndex = 2;
2159a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2160a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The length of the "bridge" to the enum cache.
2161a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEnumCacheBridgeLength = 2;
2162a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEnumCacheBridgeEnumIndex = 0;
2163a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEnumCacheBridgeCacheIndex = 1;
2164a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2165a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
2166a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kContentArrayOffset = FixedArray::kHeaderSize;
2167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize;
2168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize;
2169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description for the bridge array.
2171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize;
2172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEnumCacheBridgeCacheOffset =
2173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    kEnumCacheBridgeEnumOffset + kPointerSize;
2174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2175b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
2176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Print all the descriptors.
2177b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void PrintDescriptors() {
2178b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    PrintDescriptors(stdout);
2179b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
2180b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void PrintDescriptors(FILE* out);
2181b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
2182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2183b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef DEBUG
2184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Is the descriptor array sorted and without duplicates?
2185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsSortedNoDuplicates();
2186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Are two DescriptorArrays equal?
2188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsEqualTo(DescriptorArray* other);
2189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
2190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The maximum number of descriptors we want in a descriptor array (should
2192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // fit in a page).
2193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxNumberOfDescriptors = 1024 + 512;
2194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Conversion from descriptor number to array indices.
2197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int ToKeyIndex(int descriptor_number) {
2198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return descriptor_number+kFirstIndex;
2199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2200e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
2201e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static int ToDetailsIndex(int descriptor_number) {
2202e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    return (descriptor_number << 1) + 1;
2203e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  }
2204e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
2205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int ToValueIndex(int descriptor_number) {
2206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return descriptor_number << 1;
2207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_null_descriptor(int descriptor_number) {
2210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return PropertyDetails(GetDetails(descriptor_number)).type() ==
2211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block        NULL_DESCRIPTOR;
2212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2213a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Swap operation on FixedArray without using write barriers.
2214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline void fast_swap(FixedArray* array, int first, int second);
2215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Swap descriptor first and second.
2217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Swap(int first, int second);
2218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  FixedArray* GetContentArray() {
2220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return FixedArray::cast(get(kContentArrayIndex));
2221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray);
2223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// HashTable is a subclass of FixedArray that implements a hash table
2227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// that uses open addressing and quadratic probing.
2228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
2229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// In order for the quadratic probing to work, elements that have not
2230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// yet been used and elements that have been deleted are
2231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// distinguished.  Probing continues when deleted elements are
2232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// encountered and stops when unused elements are encountered.
2233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
2234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - Elements with key == undefined have not been used yet.
2235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - Elements with key == null have been deleted.
2236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
2237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The hash table class is parameterized with a Shape and a Key.
2238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Shape must be a class with the following interface:
2239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   class ExampleShape {
2240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//    public:
2241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//      // Tells whether key matches other.
2242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     static bool IsMatch(Key key, Object* other);
2243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     // Returns the hash value for key.
2244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     static uint32_t Hash(Key key);
2245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     // Returns the hash value for object.
2246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     static uint32_t HashForObject(Key key, Object* object);
2247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     // Convert key to an object.
2248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     static inline Object* AsObject(Key key);
2249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     // The prefix size indicates number of elements in the beginning
2250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     // of the backing storage.
2251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     static const int kPrefixSize = ..;
2252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     // The Element size indicates number of elements per entry.
2253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//     static const int kEntrySize = ..;
2254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//   };
22553ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// The prefix size indicates an amount of memory in the
2256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// beginning of the backing storage that can be used for non-element
2257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// information by subclasses.
2258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate<typename Shape, typename Key>
2260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass HashTable: public FixedArray {
2261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
22623ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Returns the number of elements in the hash table.
2263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NumberOfElements() {
2264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Smi::cast(get(kNumberOfElementsIndex))->value();
2265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2267e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Returns the number of deleted elements in the hash table.
2268e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  int NumberOfDeletedElements() {
2269e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    return Smi::cast(get(kNumberOfDeletedElementsIndex))->value();
2270e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  }
2271e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
22723ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Returns the capacity of the hash table.
2273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int Capacity() {
2274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Smi::cast(get(kCapacityIndex))->value();
2275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ElementAdded should be called whenever an element is added to a
22783ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // hash table.
2279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); }
2280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ElementRemoved should be called whenever an element is removed from
22823ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // a hash table.
2283e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  void ElementRemoved() {
2284e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    SetNumberOfElements(NumberOfElements() - 1);
2285e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    SetNumberOfDeletedElements(NumberOfDeletedElements() + 1);
2286e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  }
2287e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  void ElementsRemoved(int n) {
2288e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    SetNumberOfElements(NumberOfElements() - n);
2289e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    SetNumberOfDeletedElements(NumberOfDeletedElements() + n);
2290e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  }
2291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
22923ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Returns a new HashTable object. Might return Failure.
22935913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT static MaybeObject* Allocate(
229480d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen      int at_least_space_for,
229580d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen      PretenureFlag pretenure = NOT_TENURED);
2296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the key at entry.
2298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* KeyAt(int entry) { return get(EntryToIndex(entry)); }
2299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether k is a real key.  Null and undefined are not allowed
2301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // as keys and can be used to indicate missing or deleted elements.
2302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsKey(Object* k) {
2303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return !k->IsNull() && !k->IsUndefined();
2304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Garbage collection support.
2307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void IteratePrefix(ObjectVisitor* visitor);
2308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void IterateElements(ObjectVisitor* visitor);
2309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
2311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline HashTable* cast(Object* obj);
2312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Compute the probe offset (quadratic probing).
2314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  INLINE(static uint32_t GetProbeOffset(uint32_t n)) {
2315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return (n + n * n) >> 1;
2316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNumberOfElementsIndex = 0;
2319e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kNumberOfDeletedElementsIndex = 1;
2320e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kCapacityIndex = 2;
2321e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kPrefixStartIndex = 3;
2322e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kElementsStartIndex =
2323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kPrefixStartIndex + Shape::kPrefixSize;
2324e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kEntrySize = Shape::kEntrySize;
2325e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kElementsStartOffset =
2326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kHeaderSize + kElementsStartIndex * kPointerSize;
23276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kCapacityOffset =
23286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      kHeaderSize + kCapacityIndex * kPointerSize;
2329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Constant used for denoting a absent entry.
2331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNotFound = -1;
2332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2333e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximal capacity of HashTable. Based on maximal length of underlying
2334e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex
2335e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // cannot overflow.
2336e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMaxCapacity =
2337e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize;
2338e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
23393bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  // Find entry for key otherwise return kNotFound.
234044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline int FindEntry(Key key);
234144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  int FindEntry(Isolate* isolate, Key key);
2342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block protected:
2344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Find the entry at which to insert element with the given key that
2346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // has the given hash value.
2347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t FindInsertionEntry(uint32_t hash);
2348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the index for an entry (of the key)
2350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline int EntryToIndex(int entry) {
2351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return (entry * kEntrySize) + kElementsStartIndex;
2352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
23543ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Update the number of elements in the hash table.
2355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetNumberOfElements(int nof) {
2356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof));
2357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2359e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Update the number of deleted elements in the hash table.
2360e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  void SetNumberOfDeletedElements(int nod) {
2361e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    fast_set(this, kNumberOfDeletedElementsIndex, Smi::FromInt(nod));
2362e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  }
2363e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
2364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets the capacity of the hash table.
2365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetCapacity(int capacity) {
2366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // To scale a computed hash code to fit within the hash table, we
2367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // use bit-wise AND with a mask, so the capacity must be positive
2368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // and non-zero.
2369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(capacity > 0);
2370e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    ASSERT(capacity <= kMaxCapacity);
2371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    fast_set(this, kCapacityIndex, Smi::FromInt(capacity));
2372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns probe entry.
2376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) {
2377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(IsPowerOf2(size));
2378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return (hash + GetProbeOffset(number)) & (size - 1);
2379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2381e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static uint32_t FirstProbe(uint32_t hash, uint32_t size) {
2382e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    return hash & (size - 1);
2383e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  }
2384e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
2385e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) {
2386e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke    return (last + number) & (size - 1);
2387e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  }
2388e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
2389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Ensure enough space for n additional elements.
23905913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
2391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// HashTableKey is an abstract superclass for virtual key behavior.
2396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass HashTableKey {
2397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns whether the other object matches this key.
2399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual bool IsMatch(Object* other) = 0;
2400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the hash value for this key.
2401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual uint32_t Hash() = 0;
2402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the hash value for object.
2403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual uint32_t HashForObject(Object* key) = 0;
24043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Returns the key object for storing into the hash table.
2405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // If allocations fails a failure object is returned.
24065913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT virtual MaybeObject* AsObject() = 0;
2407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Required.
2408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual ~HashTableKey() {}
2409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass SymbolTableShape {
2412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
241344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline bool IsMatch(HashTableKey* key, Object* value) {
2414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->IsMatch(value);
2415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
241644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline uint32_t Hash(HashTableKey* key) {
2417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->Hash();
2418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
241944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
2420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->HashForObject(object);
2421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
242244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
2423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->AsObject();
2424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPrefixSize = 0;
2427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEntrySize = 1;
2428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SymbolTable.
2431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
2432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// No special elements in the prefix and the element size is 1
2433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// because only the symbol itself (the key) needs to be stored.
2434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> {
2435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Find symbol in the symbol table.  If it is not there yet, it is
2437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // added.  The return value is the symbol table which might have
2438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // been enlarged.  If the return value is not a failure, the symbol
2439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // pointer *s is set to the symbol found.
24405913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s);
24419fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str,
24429fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block                                                 Object** s);
24439fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str,
24449fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block                                                   Object** s);
24455913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s);
2446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Looks up a symbol that is equal to the given string and returns
2448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // true if it is found, assigning the symbol to the given output
2449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // parameter.
2450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool LookupSymbolIfExists(String* str, String** symbol);
2451d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol);
2452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
2454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline SymbolTable* cast(Object* obj);
2455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2456a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
24575913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s);
2458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2459a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable);
2460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass MapCacheShape {
2464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
246544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline bool IsMatch(HashTableKey* key, Object* value) {
2466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->IsMatch(value);
2467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
246844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline uint32_t Hash(HashTableKey* key) {
2469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->Hash();
2470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
247244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
2473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->HashForObject(object);
2474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
247644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) {
2477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->AsObject();
2478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPrefixSize = 0;
2481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEntrySize = 2;
2482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// MapCache.
2486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
2487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Maps keys that are a fixed array of symbols to a map.
2488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Used for canonicalize maps for object literals.
2489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass MapCache: public HashTable<MapCacheShape, HashTableKey*> {
2490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Find cached value for a string key, otherwise return null.
2492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* Lookup(FixedArray* key);
24935913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value);
2494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline MapCache* cast(Object* obj);
2495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache);
2498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <typename Shape, typename Key>
2502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Dictionary: public HashTable<Shape, Key> {
2503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Dictionary<Shape, Key>* cast(Object* obj) {
2506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return reinterpret_cast<Dictionary<Shape, Key>*>(obj);
2507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the value at entry.
2510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* ValueAt(int entry) {
25116ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return this->get(HashTable<Shape, Key>::EntryToIndex(entry)+1);
2512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set the value for entry.
2515e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // Returns false if the put wasn't performed due to property being read only.
2516e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // Returns true on successful put.
2517e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  bool ValueAtPut(int entry, Object* value) {
25189dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    // Check that this value can actually be written.
25199dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    PropertyDetails details = DetailsAt(entry);
25209dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    // If a value has not been initilized we allow writing to it even if
25219dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen    // it is read only (a declared const that has not been initialized).
2522e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    if (details.IsReadOnly() && !ValueAt(entry)->IsTheHole()) {
2523e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      return false;
2524e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    }
2525e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value);
2526e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    return true;
2527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the property details for the property at entry.
2530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  PropertyDetails DetailsAt(int entry) {
2531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(entry >= 0);  // Not found is -1, which is not caught by get().
2532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return PropertyDetails(
25336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block        Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2)));
2534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set the details for entry.
2537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void DetailsAtPut(int entry, PropertyDetails value) {
25386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi());
2539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sorting support
2542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CopyValuesTo(FixedArray* elements);
2543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Delete a property from the dictionary.
2545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* DeleteProperty(int entry, JSObject::DeleteMode mode);
2546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of elements in the dictionary filtering out properties
2548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // with the specified attributes.
2549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NumberOfElementsFilterAttributes(PropertyAttributes filter);
2550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of enumerable elements in the dictionary.
2552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NumberOfEnumElements();
2553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Copies keys to preallocated fixed array.
2555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CopyKeysTo(FixedArray* storage, PropertyAttributes filter);
2556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Fill in details for properties into storage.
25576d7cb000ed533f52d745e60663019ff891bb19a8Ben Murdoch  void CopyKeysTo(FixedArray* storage, int index);
2558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Accessors for next enumeration index.
2560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetNextEnumerationIndex(int index) {
25616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    this->fast_set(this, kNextEnumerationIndexIndex, Smi::FromInt(index));
2562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NextEnumerationIndex() {
2565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value();
2566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns a new array for dictionary usage. Might return Failure.
25695913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for);
2570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Ensure enough space for n additional elements.
25725913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key);
2573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2574b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
2575b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void Print() {
2576b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    Print(stdout);
2577b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
2578b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void Print(FILE* out);
2579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
2580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the key (slow).
2581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* SlowReverseLookup(Object* value);
2582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Sets the entry to (key, value) pair.
2584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SetEntry(int entry,
2585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                       Object* key,
25868b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch                       Object* value);
25878b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  inline void SetEntry(int entry,
25888b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch                       Object* key,
2589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                       Object* value,
2590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                       PropertyDetails details);
2591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
25925913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* Add(Key key,
25935913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                   Object* value,
25945913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                   PropertyDetails details);
2595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block protected:
2597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Generic at put operation.
25985913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value);
2599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add entry to dictionary.
26015913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AddEntry(Key key,
26025913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                        Object* value,
26035913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                        PropertyDetails details,
26045913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                        uint32_t hash);
2605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Generate new enumeration indices to avoid enumeration index overflow.
26075913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices();
2608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxNumberKeyIndex =
2609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      HashTable<Shape, Key>::kPrefixStartIndex;
2610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1;
2611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass StringDictionaryShape {
2615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool IsMatch(String* key, Object* other);
2617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline uint32_t Hash(String* key);
2618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline uint32_t HashForObject(String* key, Object* object);
26195913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT static inline MaybeObject* AsObject(String* key);
2620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPrefixSize = 2;
2621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEntrySize = 3;
2622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const bool kIsEnumerable = true;
2623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass StringDictionary: public Dictionary<StringDictionaryShape, String*> {
2627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline StringDictionary* cast(Object* obj) {
2629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(obj->IsDictionary());
2630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return reinterpret_cast<StringDictionary*>(obj);
2631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Copies enumerable keys to preallocated fixed array.
2634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array);
2635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // For transforming properties of a JSObject.
26375913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor(
26385913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      JSObject* obj,
26395913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck      int unused_property_fields);
26403bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
26413bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  // Find entry for key otherwise return kNotFound. Optimzed version of
26423bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  // HashTable::FindEntry.
26433bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  int FindEntry(String* key);
2644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass NumberDictionaryShape {
2648a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool IsMatch(uint32_t key, Object* other);
2650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline uint32_t Hash(uint32_t key);
2651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline uint32_t HashForObject(uint32_t key, Object* object);
26525913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key);
2653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPrefixSize = 2;
2654a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEntrySize = 3;
2655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const bool kIsEnumerable = false;
2656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> {
2660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
2661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static NumberDictionary* cast(Object* obj) {
2662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(obj->IsDictionary());
2663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return reinterpret_cast<NumberDictionary*>(obj);
2664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Type specific at put (default NONE attributes is used when adding).
26675913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value);
26685913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key,
26695913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                              Object* value,
26705913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                              PropertyDetails details);
2671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set an existing entry or add a new one if needed.
26735913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* Set(uint32_t key,
26745913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                   Object* value,
26755913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                   PropertyDetails details);
2676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void UpdateMaxNumberKey(uint32_t key);
2678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // If slow elements are required we will never go back to fast-case
2680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // for the elements kept in this dictionary.  We require slow
2681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // elements if an element has been added at an index larger than
2682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called
2683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // when defining a getter or setter with a number key.
2684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool requires_slow_elements();
2685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_requires_slow_elements();
2686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get the value of the max number key that has been added to this
2688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // dictionary.  max_number_key can only be called if
2689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // requires_slow_elements returns false.
2690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uint32_t max_number_key();
2691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Remove all entries were key is a number and (from <= key && key < to).
2693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void RemoveNumberEntries(uint32_t from, uint32_t to);
2694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit masks.
2696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kRequiresSlowElementsMask = 1;
2697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kRequiresSlowElementsTagSize = 1;
2698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1;
2699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2701a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
27026ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// JSFunctionResultCache caches results of some JSFunction invocation.
27036ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// It is a fixed array with fixed structure:
27046ded16be15dd865a9b21ea304d5273c8be299c87Steve Block//   [0]: factory function
27056ded16be15dd865a9b21ea304d5273c8be299c87Steve Block//   [1]: finger index
27066ded16be15dd865a9b21ea304d5273c8be299c87Steve Block//   [2]: current cache size
27076ded16be15dd865a9b21ea304d5273c8be299c87Steve Block//   [3]: dummy field.
27086ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// The rest of array are key/value pairs.
27096ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockclass JSFunctionResultCache: public FixedArray {
27106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block public:
27116ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kFactoryIndex = 0;
27126ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kFingerIndex = kFactoryIndex + 1;
27136ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kCacheSizeIndex = kFingerIndex + 1;
27146ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kDummyIndex = kCacheSizeIndex + 1;
27156ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kEntriesIndex = kDummyIndex + 1;
27166ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
27176ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kEntrySize = 2;  // key + value
27186ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
271925f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kFactoryOffset = kHeaderSize;
272025f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kFingerOffset = kFactoryOffset + kPointerSize;
272125f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen  static const int kCacheSizeOffset = kFingerOffset + kPointerSize;
272225f6136652d8341ed047e7fc1a450af5bd218ea9Kristian Monsen
27236ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline void MakeZeroSize();
27246ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline void Clear();
27256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
2726b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  inline int size();
2727b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  inline void set_size(int size);
2728b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  inline int finger_index();
2729b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  inline void set_finger_index(int finger_index);
2730b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
27316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Casting
27326ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static inline JSFunctionResultCache* cast(Object* obj);
27336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
27346ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#ifdef DEBUG
27356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  void JSFunctionResultCacheVerify();
27366ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#endif
27376ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
27386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
27396ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
274080d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen// The cache for maps used by normalized (dictionary mode) objects.
274180d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen// Such maps do not have property descriptors, so a typical program
274280d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen// needs very limited number of distinct normalized maps.
274380d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsenclass NormalizedMapCache: public FixedArray {
274480d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen public:
274580d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  static const int kEntries = 64;
274680d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
27475913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* Get(JSObject* object,
27485913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                   PropertyNormalizationMode mode);
274980d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
275080d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  void Clear();
275180d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
275280d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  // Casting
275380d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  static inline NormalizedMapCache* cast(Object* obj);
275480d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
275580d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen#ifdef DEBUG
275680d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  void NormalizedMapCacheVerify();
275780d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen#endif
275880d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
275980d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen private:
276080d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  static int Hash(Map* fast);
276180d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
276280d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  static bool CheckHit(Map* slow, Map* fast, PropertyNormalizationMode mode);
276380d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen};
276480d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
276580d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
2766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// ByteArray represents fixed sized byte arrays.  Used by the outside world,
2767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// such as PCRE, and also by the memory allocator and garbage collector to
2768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// fill in free blocks in the heap.
27697f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochclass ByteArray: public HeapObject {
2770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
27717f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // [length]: length of the array.
27727f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  inline int length();
27737f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  inline void set_length(int value);
27747f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
2775a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Setter and getter.
2776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline byte get(int index);
2777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set(int index, byte value);
2778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Treat contents as an int array.
2780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int get_int(int index);
2781a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2782a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int SizeFor(int length) {
27837f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    return OBJECT_POINTER_ALIGN(kHeaderSize + length);
2784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // We use byte arrays for free blocks in the heap.  Given a desired size in
2786a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // bytes that is a multiple of the word size and big enough to hold a byte
2787a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // array, this function returns the number of elements a byte array should
2788a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // have.
2789a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int LengthFor(int size_in_bytes) {
2790a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(IsAligned(size_in_bytes, kPointerSize));
2791a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(size_in_bytes >= kHeaderSize);
2792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return size_in_bytes - kHeaderSize;
2793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
2794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns data start address.
2796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Address GetDataStartAddress();
2797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns a pointer to the ByteArray object for a given data start address.
2799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline ByteArray* FromDataStartAddress(Address address);
2800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
2802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline ByteArray* cast(Object* obj);
2803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
2805756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline int ByteArraySize() {
2806756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    return SizeFor(this->length());
2807756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  }
2808b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
2809b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ByteArrayPrint() {
2810b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ByteArrayPrint(stdout);
2811b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
2812b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ByteArrayPrint(FILE* out);
2813b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
2814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
2815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void ByteArrayVerify();
2816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
2817a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28187f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Layout description.
28197f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Length is smi tagged when it is stored.
28207f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kLengthOffset = HeapObject::kHeaderSize;
28217f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kHeaderSize = kLengthOffset + kPointerSize;
28227f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
28237f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
2824a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2825e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximal memory consumption for a single ByteArray.
2826e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMaxSize = 512 * MB;
2827e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximal length of a single ByteArray.
2828e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMaxLength = kMaxSize - kHeaderSize;
2829e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
2830a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
2831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray);
2832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
2833a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
2834a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
28353ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// An ExternalArray represents a fixed-size array of primitive values
28363ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// which live outside the JavaScript heap. Its subclasses are used to
28373ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// implement the CanvasArray types being defined in the WebGL
28383ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// specification. As of this writing the first public draft is not yet
28393ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// available, but Khronos members can access the draft at:
28403ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block//   https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html
28413ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block//
28423ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// The semantics of these arrays differ from CanvasPixelArray.
28433ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// Out-of-range values passed to the setter are converted via a C
28443ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// cast, not clamping. Out-of-range indices cause exceptions to be
28453ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block// raised rather than being silently ignored.
28467f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdochclass ExternalArray: public HeapObject {
28473ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
28487f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // [length]: length of the array.
28497f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  inline int length();
28507f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  inline void set_length(int value);
28517f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
28523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // [external_pointer]: The pointer to the external memory area backing this
28533ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // external array.
28543ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  DECL_ACCESSORS(external_pointer, void)  // Pointer to the data store.
28553ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
28563ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Casting.
28573ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline ExternalArray* cast(Object* obj);
28583ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
28593ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Maximal acceptable length for an external array.
28603ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kMaxLength = 0x3fffffff;
28613ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
28623ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // ExternalArray headers are not quadword aligned.
28637f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kLengthOffset = HeapObject::kHeaderSize;
28647f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kExternalPointerOffset =
28657f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      POINTER_SIZE_ALIGN(kLengthOffset + kIntSize);
28663ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static const int kHeaderSize = kExternalPointerOffset + kPointerSize;
28677f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize);
28683ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
28693ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
28703ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray);
28713ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
28723ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
28733ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
287444f0eee88ff00398ff7f715fab053374d808c90dSteve Block// A ExternalPixelArray represents a fixed-size byte array with special
287544f0eee88ff00398ff7f715fab053374d808c90dSteve Block// semantics used for implementing the CanvasPixelArray object. Please see the
287644f0eee88ff00398ff7f715fab053374d808c90dSteve Block// specification at:
287744f0eee88ff00398ff7f715fab053374d808c90dSteve Block
287844f0eee88ff00398ff7f715fab053374d808c90dSteve Block// http://www.whatwg.org/specs/web-apps/current-work/
287944f0eee88ff00398ff7f715fab053374d808c90dSteve Block//                      multipage/the-canvas-element.html#canvaspixelarray
288044f0eee88ff00398ff7f715fab053374d808c90dSteve Block// In particular, write access clamps the value written to 0 or 255 if the
288144f0eee88ff00398ff7f715fab053374d808c90dSteve Block// value written is outside this range.
288244f0eee88ff00398ff7f715fab053374d808c90dSteve Blockclass ExternalPixelArray: public ExternalArray {
288344f0eee88ff00398ff7f715fab053374d808c90dSteve Block public:
288444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline uint8_t* external_pixel_pointer();
288544f0eee88ff00398ff7f715fab053374d808c90dSteve Block
288644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // Setter and getter.
288744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline uint8_t get(int index);
288844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void set(int index, uint8_t value);
288944f0eee88ff00398ff7f715fab053374d808c90dSteve Block
289044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // This accessor applies the correct conversion from Smi, HeapNumber and
289144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // undefined and clamps the converted value between 0 and 255.
289244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  Object* SetValue(uint32_t index, Object* value);
289344f0eee88ff00398ff7f715fab053374d808c90dSteve Block
289444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // Casting.
289544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static inline ExternalPixelArray* cast(Object* obj);
289644f0eee88ff00398ff7f715fab053374d808c90dSteve Block
289744f0eee88ff00398ff7f715fab053374d808c90dSteve Block#ifdef OBJECT_PRINT
289844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void ExternalPixelArrayPrint() {
289944f0eee88ff00398ff7f715fab053374d808c90dSteve Block    ExternalPixelArrayPrint(stdout);
290044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  }
290144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  void ExternalPixelArrayPrint(FILE* out);
290244f0eee88ff00398ff7f715fab053374d808c90dSteve Block#endif
290344f0eee88ff00398ff7f715fab053374d808c90dSteve Block#ifdef DEBUG
290444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  void ExternalPixelArrayVerify();
290544f0eee88ff00398ff7f715fab053374d808c90dSteve Block#endif  // DEBUG
290644f0eee88ff00398ff7f715fab053374d808c90dSteve Block
290744f0eee88ff00398ff7f715fab053374d808c90dSteve Block private:
290844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray);
290944f0eee88ff00398ff7f715fab053374d808c90dSteve Block};
291044f0eee88ff00398ff7f715fab053374d808c90dSteve Block
291144f0eee88ff00398ff7f715fab053374d808c90dSteve Block
29123ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass ExternalByteArray: public ExternalArray {
29133ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
29143ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Setter and getter.
29153ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline int8_t get(int index);
29163ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline void set(int index, int8_t value);
29173ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29183ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // This accessor applies the correct conversion from Smi, HeapNumber
29193ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // and undefined.
29205913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* SetValue(uint32_t index, Object* value);
29213ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29223ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Casting.
29233ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline ExternalByteArray* cast(Object* obj);
29243ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
2925b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
2926b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ExternalByteArrayPrint() {
2927b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ExternalByteArrayPrint(stdout);
2928b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
2929b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ExternalByteArrayPrint(FILE* out);
2930b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
29313ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#ifdef DEBUG
29323ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void ExternalByteArrayVerify();
29333ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#endif  // DEBUG
29343ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29353ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
29363ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray);
29373ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
29383ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29393ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29403ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass ExternalUnsignedByteArray: public ExternalArray {
29413ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
29423ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Setter and getter.
29433ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline uint8_t get(int index);
29443ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline void set(int index, uint8_t value);
29453ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29463ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // This accessor applies the correct conversion from Smi, HeapNumber
29473ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // and undefined.
29485913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* SetValue(uint32_t index, Object* value);
29493ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29503ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Casting.
29513ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline ExternalUnsignedByteArray* cast(Object* obj);
29523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
2953b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
2954b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ExternalUnsignedByteArrayPrint() {
2955b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ExternalUnsignedByteArrayPrint(stdout);
2956b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
2957b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ExternalUnsignedByteArrayPrint(FILE* out);
2958b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
29593ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#ifdef DEBUG
29603ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void ExternalUnsignedByteArrayVerify();
29613ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#endif  // DEBUG
29623ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29633ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
29643ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray);
29653ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
29663ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29673ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29683ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass ExternalShortArray: public ExternalArray {
29693ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
29703ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Setter and getter.
29713ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline int16_t get(int index);
29723ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline void set(int index, int16_t value);
29733ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29743ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // This accessor applies the correct conversion from Smi, HeapNumber
29753ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // and undefined.
29765913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* SetValue(uint32_t index, Object* value);
29773ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29783ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Casting.
29793ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline ExternalShortArray* cast(Object* obj);
29803ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
2981b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
2982b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ExternalShortArrayPrint() {
2983b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ExternalShortArrayPrint(stdout);
2984b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
2985b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ExternalShortArrayPrint(FILE* out);
2986b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
29873ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#ifdef DEBUG
29883ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void ExternalShortArrayVerify();
29893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#endif  // DEBUG
29903ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29913ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
29923ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray);
29933ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
29943ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29953ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
29963ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass ExternalUnsignedShortArray: public ExternalArray {
29973ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
29983ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Setter and getter.
29993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline uint16_t get(int index);
30003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline void set(int index, uint16_t value);
30013ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30023ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // This accessor applies the correct conversion from Smi, HeapNumber
30033ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // and undefined.
30045913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* SetValue(uint32_t index, Object* value);
30053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Casting.
30073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline ExternalUnsignedShortArray* cast(Object* obj);
30083ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
3009b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
3010b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ExternalUnsignedShortArrayPrint() {
3011b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ExternalUnsignedShortArrayPrint(stdout);
3012b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3013b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ExternalUnsignedShortArrayPrint(FILE* out);
3014b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
30153ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#ifdef DEBUG
30163ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void ExternalUnsignedShortArrayVerify();
30173ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#endif  // DEBUG
30183ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30193ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
30203ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray);
30213ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
30223ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30233ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30243ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass ExternalIntArray: public ExternalArray {
30253ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
30263ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Setter and getter.
30273ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline int32_t get(int index);
30283ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline void set(int index, int32_t value);
30293ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30303ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // This accessor applies the correct conversion from Smi, HeapNumber
30313ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // and undefined.
30325913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* SetValue(uint32_t index, Object* value);
30333ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30343ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Casting.
30353ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline ExternalIntArray* cast(Object* obj);
30363ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
3037b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
3038b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ExternalIntArrayPrint() {
3039b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ExternalIntArrayPrint(stdout);
3040b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3041b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ExternalIntArrayPrint(FILE* out);
3042b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
30433ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#ifdef DEBUG
30443ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void ExternalIntArrayVerify();
30453ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#endif  // DEBUG
30463ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30473ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
30483ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray);
30493ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
30503ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30513ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30523ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass ExternalUnsignedIntArray: public ExternalArray {
30533ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
30543ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Setter and getter.
30553ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline uint32_t get(int index);
30563ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline void set(int index, uint32_t value);
30573ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30583ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // This accessor applies the correct conversion from Smi, HeapNumber
30593ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // and undefined.
30605913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* SetValue(uint32_t index, Object* value);
30613ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30623ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Casting.
30633ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline ExternalUnsignedIntArray* cast(Object* obj);
30643ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
3065b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
3066b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ExternalUnsignedIntArrayPrint() {
3067b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ExternalUnsignedIntArrayPrint(stdout);
3068b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3069b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ExternalUnsignedIntArrayPrint(FILE* out);
3070b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
30713ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#ifdef DEBUG
30723ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void ExternalUnsignedIntArrayVerify();
30733ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#endif  // DEBUG
30743ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30753ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
30763ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray);
30773ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
30783ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30793ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30803ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Blockclass ExternalFloatArray: public ExternalArray {
30813ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block public:
30823ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Setter and getter.
30833ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline float get(int index);
30843ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline void set(int index, float value);
30853ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30863ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // This accessor applies the correct conversion from Smi, HeapNumber
30873ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // and undefined.
30885913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* SetValue(uint32_t index, Object* value);
30893ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
30903ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // Casting.
30913ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  static inline ExternalFloatArray* cast(Object* obj);
30923ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
3093b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
3094b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ExternalFloatArrayPrint() {
3095b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ExternalFloatArrayPrint(stdout);
3096b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3097b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ExternalFloatArrayPrint(FILE* out);
3098b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
30993ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#ifdef DEBUG
31003ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  void ExternalFloatArrayVerify();
31013ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block#endif  // DEBUG
31023ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
31033ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block private:
31043ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray);
31053ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block};
31063ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
31073ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
3108b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// DeoptimizationInputData is a fixed array used to hold the deoptimization
3109b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// data for code generated by the Hydrogen/Lithium compiler.  It also
3110b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// contains information about functions that were inlined.  If N different
3111b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// functions were inlined then first N elements of the literal array will
3112b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// contain these functions.
3113b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch//
3114b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// It can be empty.
3115b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochclass DeoptimizationInputData: public FixedArray {
3116b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch public:
3117b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Layout description.  Indices in the array.
3118b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kTranslationByteArrayIndex = 0;
3119b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kInlinedFunctionCountIndex = 1;
3120b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kLiteralArrayIndex = 2;
3121b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kOsrAstIdIndex = 3;
3122b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kOsrPcOffsetIndex = 4;
3123b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kFirstDeoptEntryIndex = 5;
3124b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3125b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Offsets of deopt entry elements relative to the start of the entry.
3126b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kAstIdOffset = 0;
3127b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kTranslationIndexOffset = 1;
3128b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kArgumentsStackHeightOffset = 2;
3129b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kDeoptEntrySize = 3;
3130b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3131b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Simple element accessors.
3132b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#define DEFINE_ELEMENT_ACCESSORS(name, type)      \
3133b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  type* name() {                                  \
3134b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    return type::cast(get(k##name##Index));       \
3135b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }                                               \
3136b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void Set##name(type* value) {                   \
3137b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    set(k##name##Index, value);                   \
3138b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3139b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3140b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray)
3141b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi)
3142b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray)
3143b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi)
3144b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi)
3145b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3146b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Unchecked accessor to be used during GC.
3147b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  FixedArray* UncheckedLiteralArray() {
3148b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    return reinterpret_cast<FixedArray*>(get(kLiteralArrayIndex));
3149b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3150b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3151b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#undef DEFINE_ELEMENT_ACCESSORS
3152b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3153b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Accessors for elements of the ith deoptimization entry.
3154b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#define DEFINE_ENTRY_ACCESSORS(name, type)                       \
3155b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  type* name(int i) {                                            \
3156b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    return type::cast(get(IndexForEntry(i) + k##name##Offset));  \
3157b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }                                                              \
3158b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void Set##name(int i, type* value) {                           \
3159b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    set(IndexForEntry(i) + k##name##Offset, value);              \
3160b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3161b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3162b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DEFINE_ENTRY_ACCESSORS(AstId, Smi)
3163b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi)
3164b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi)
3165b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3166b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#undef DEFINE_ENTRY_ACCESSORS
3167b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3168b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  int DeoptCount() {
3169b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize;
3170b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3171b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3172b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Allocates a DeoptimizationInputData.
3173b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count,
3174b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch                                               PretenureFlag pretenure);
3175b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3176b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Casting.
3177b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static inline DeoptimizationInputData* cast(Object* obj);
3178b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3179b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
3180b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void DeoptimizationInputDataPrint(FILE* out);
3181b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
3182b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3183b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch private:
3184b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static int IndexForEntry(int i) {
3185b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    return kFirstDeoptEntryIndex + (i * kDeoptEntrySize);
3186b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3187b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3188b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static int LengthFor(int entry_count) {
3189b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    return IndexForEntry(entry_count);
3190b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3191b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch};
3192b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3193b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3194b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// DeoptimizationOutputData is a fixed array used to hold the deoptimization
3195b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// data for code generated by the full compiler.
3196b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// The format of the these objects is
3197b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch//   [i * 2]: Ast ID for ith deoptimization.
3198b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch//   [i * 2 + 1]: PC and state of ith deoptimization
3199b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochclass DeoptimizationOutputData: public FixedArray {
3200b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch public:
3201b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  int DeoptPoints() { return length() / 2; }
3202b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  Smi* AstId(int index) { return Smi::cast(get(index * 2)); }
3203b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void SetAstId(int index, Smi* id) { set(index * 2, id); }
3204b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); }
3205b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); }
3206b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3207b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static int LengthOfFixedArray(int deopt_points) {
3208b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    return deopt_points * 2;
3209b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3210b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3211b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Allocates a DeoptimizationOutputData.
3212b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points,
3213b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch                                               PretenureFlag pretenure);
3214b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3215b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Casting.
3216b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static inline DeoptimizationOutputData* cast(Object* obj);
3217b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3218b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
3219b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void DeoptimizationOutputDataPrint(FILE* out);
3220b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
3221b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch};
3222b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3223b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3224b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdochclass SafepointEntry;
3225b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
3226b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
3227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Code describes objects with on-the-fly generated machine code.
3228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Code: public HeapObject {
3229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Opaque data type for encapsulating code flags like kind, inline
3231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // cache state, and arguments count.
3232756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that
3233756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // enumeration type has correct value range (see Issue 830 for more details).
3234756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  enum Flags {
3235756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    FLAGS_MIN_VALUE = kMinInt,
3236756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    FLAGS_MAX_VALUE = kMaxInt
3237756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  };
3238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  enum Kind {
3240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    FUNCTION,
3241b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    OPTIMIZED_FUNCTION,
3242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    STUB,
3243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    BUILTIN,
3244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    LOAD_IC,
3245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    KEYED_LOAD_IC,
324644f0eee88ff00398ff7f715fab053374d808c90dSteve Block    KEYED_EXTERNAL_ARRAY_LOAD_IC,
3247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    CALL_IC,
32487f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    KEYED_CALL_IC,
3249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    STORE_IC,
3250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    KEYED_STORE_IC,
325144f0eee88ff00398ff7f715fab053374d808c90dSteve Block    KEYED_EXTERNAL_ARRAY_STORE_IC,
3252b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    TYPE_RECORDING_BINARY_OP_IC,
3253b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    COMPARE_IC,
32546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    // No more than 16 kinds. The value currently encoded in four bits in
3255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Flags.
3256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Pseudo-kinds.
3258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    REGEXP = BUILTIN,
3259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    FIRST_IC_KIND = LOAD_IC,
3260b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    LAST_IC_KIND = COMPARE_IC
3261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
3262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  enum {
326450ef84f5fad2def87d3fbc737bec4a32711fdef4Kristian Monsen    NUMBER_OF_KINDS = LAST_IC_KIND + 1
3265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
3266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3267b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  typedef int ExtraICState;
3268b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
3269b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  static const ExtraICState kNoExtraICState = 0;
3270b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch
3271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef ENABLE_DISASSEMBLER
3272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Printing
3273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const char* Kind2String(Kind kind);
3274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const char* ICState2String(InlineCacheState state);
3275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const char* PropertyType2String(PropertyType type);
32761e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra);
3277b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void Disassemble(const char* name) {
3278b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    Disassemble(name, stdout);
3279b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3280b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void Disassemble(const char* name, FILE* out);
3281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // ENABLE_DISASSEMBLER
3282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [instruction_size]: Size of the native instructions
3284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int instruction_size();
3285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_instruction_size(int value);
3286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3287ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  // [relocation_info]: Code relocation information
3288ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  DECL_ACCESSORS(relocation_info, ByteArray)
3289b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void InvalidateRelocation();
3290ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke
3291b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [deoptimization_data]: Array containing data for deopt.
3292b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DECL_ACCESSORS(deoptimization_data, FixedArray)
3293b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3294b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Unchecked accessors to be used during GC.
3295ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  inline ByteArray* unchecked_relocation_info();
3296b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline FixedArray* unchecked_deoptimization_data();
3297ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke
3298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int relocation_size();
3299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [flags]: Various code flags.
3301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Flags flags();
3302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_flags(Flags flags);
3303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [flags]: Access to specific code flags.
3305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Kind kind();
3306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline InlineCacheState ic_state();  // Only valid for IC stubs.
3307b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  inline ExtraICState extra_ic_state();  // Only valid for IC stubs.
3308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline InLoopFlag ic_in_loop();  // Only valid for IC stubs.
3309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline PropertyType type();  // Only valid for monomorphic IC stubs.
3310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int arguments_count();  // Only valid for call IC stubs.
3311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Testers for IC stub kinds.
3313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_inline_cache_stub();
3314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_load_stub() { return kind() == LOAD_IC; }
3315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; }
3316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_store_stub() { return kind() == STORE_IC; }
3317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; }
3318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_call_stub() { return kind() == CALL_IC; }
33197f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; }
3320b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool is_type_recording_binary_op_stub() {
3321b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    return kind() == TYPE_RECORDING_BINARY_OP_IC;
3322b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3323b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; }
332444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline bool is_external_array_load_stub() {
332544f0eee88ff00398ff7f715fab053374d808c90dSteve Block    return kind() == KEYED_EXTERNAL_ARRAY_LOAD_IC;
332644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  }
332744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline bool is_external_array_store_stub() {
332844f0eee88ff00398ff7f715fab053374d808c90dSteve Block    return kind() == KEYED_EXTERNAL_ARRAY_STORE_IC;
332944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  }
3330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
33316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // [major_key]: For kind STUB or BINARY_OP_IC, the major key.
333280d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  inline int major_key();
3333b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_major_key(int value);
3334b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3335b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [optimizable]: For FUNCTION kind, tells if it is optimizable.
3336b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool optimizable();
3337b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_optimizable(bool value);
3338b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3339b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [has_deoptimization_support]: For FUNCTION kind, tells if it has
3340b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // deoptimization support.
3341b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool has_deoptimization_support();
3342b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_has_deoptimization_support(bool value);
3343b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3344b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for
3345b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // how long the function has been marked for OSR and therefore which
3346b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // level of loop nesting we are willing to do on-stack replacement
3347b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // for.
3348b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_allow_osr_at_loop_nesting_level(int level);
3349b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline int allow_osr_at_loop_nesting_level();
3350b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3351b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots
3352b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // reserved in the code prologue.
3353b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline unsigned stack_slots();
3354b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_stack_slots(unsigned slots);
3355b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3356b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in
3357b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // the instruction stream where the safepoint table starts.
33581e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline unsigned safepoint_table_offset();
33591e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline void set_safepoint_table_offset(unsigned offset);
3360b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3361b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [stack_check_table_start]: For kind FUNCTION, the offset in the
3362b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // instruction stream where the stack check table starts.
33631e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline unsigned stack_check_table_offset();
33641e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline void set_stack_check_table_offset(unsigned offset);
3365b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3366b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [check type]: For kind CALL_IC, tells how to check if the
3367b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // receiver is valid for the given call.
3368b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline CheckType check_type();
3369b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_check_type(CheckType value);
3370b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
337144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // [external array type]: For kind KEYED_EXTERNAL_ARRAY_LOAD_IC and
337244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // KEYED_EXTERNAL_ARRAY_STORE_IC, identifies the type of external
337344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // array that the code stub is specialized for.
337444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline ExternalArrayType external_array_type();
337544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void set_external_array_type(ExternalArrayType value);
337644f0eee88ff00398ff7f715fab053374d808c90dSteve Block
3377b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [type-recording binary op type]: For all TYPE_RECORDING_BINARY_OP_IC.
3378b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline byte type_recording_binary_op_type();
3379b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_type_recording_binary_op_type(byte value);
3380b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline byte type_recording_binary_op_result_type();
3381b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_type_recording_binary_op_result_type(byte value);
3382b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3383b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [compare state]: For kind compare IC stubs, tells what state the
3384b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // stub is in.
3385b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline byte compare_state();
3386b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_compare_state(byte value);
3387b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3388b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  // Get the safepoint entry for the given pc.
3389b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  SafepointEntry GetSafepointEntry(Address pc);
3390b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3391b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Mark this code object as not having a stack check table.  Assumes kind
3392b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // is FUNCTION.
3393b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void SetNoStackCheckTable();
3394b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3395b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Find the first map in an IC stub.
3396b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  Map* FindFirstMap();
3397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Flags operations.
3399b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  static inline Flags ComputeFlags(
3400b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      Kind kind,
3401b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      InLoopFlag in_loop = NOT_IN_LOOP,
3402b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      InlineCacheState ic_state = UNINITIALIZED,
3403b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      ExtraICState extra_ic_state = kNoExtraICState,
3404b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      PropertyType type = NORMAL,
3405b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      int argc = -1,
3406b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      InlineCacheHolderFlag holder = OWN_MAP);
3407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Flags ComputeMonomorphicFlags(
3409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      Kind kind,
3410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      PropertyType type,
3411b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch      ExtraICState extra_ic_state = kNoExtraICState,
34128defd9ff6930b4e24729971a61cf7469daf119beSteve Block      InlineCacheHolderFlag holder = OWN_MAP,
3413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      InLoopFlag in_loop = NOT_IN_LOOP,
3414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      int argc = -1);
3415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Kind ExtractKindFromFlags(Flags flags);
3417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline InlineCacheState ExtractICStateFromFlags(Flags flags);
3418b8e0da25ee8efac3bb05cd6b2730aafbd96119f4Ben Murdoch  static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags);
3419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags);
3420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline PropertyType ExtractTypeFromFlags(Flags flags);
3421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline int ExtractArgumentsCountFromFlags(Flags flags);
34228defd9ff6930b4e24729971a61cf7469daf119beSteve Block  static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags);
3423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Flags RemoveTypeFromFlags(Flags flags);
3424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Convert a target address into a code object.
3426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Code* GetCodeFromTargetAddress(Address address);
3427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3428791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  // Convert an entry address into an object.
3429791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  static inline Object* GetObjectFromEntryAddress(Address location_of_address);
3430791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block
3431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the address of the first instruction.
3432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline byte* instruction_start();
3433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3434ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  // Returns the address right after the last instruction.
3435ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  inline byte* instruction_end();
3436ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke
3437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the size of the instructions, padding, and relocation information.
3438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int body_size();
3439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the address of the first relocation info (read backwards!).
3441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline byte* relocation_start();
3442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Code entry point.
3444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline byte* entry();
3445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns true if pc is inside this object's instructions.
3447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool contains(byte* pc);
3448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Relocate the code by delta bytes. Called to signal that this code
3450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // object has been moved by delta bytes.
3451d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  void Relocate(intptr_t delta);
3452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Migrate code described by desc.
3454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CopyFrom(const CodeDesc& desc);
3455a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
34563bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  // Returns the object size for a given body (used for allocation).
34573bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  static int SizeFor(int body_size) {
3458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT_SIZE_TAG_ALIGNED(body_size);
34593bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch    return RoundUp(kHeaderSize + body_size, kCodeAlignment);
3460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Calculate the size of the code object to report for log events. This takes
3463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the layout of the code object into account.
3464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int ExecutableSize() {
3465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    // Check that the assumptions about the layout of the code object holds.
3466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT_EQ(static_cast<int>(instruction_start() - address()),
3467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block              Code::kHeaderSize);
3468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return instruction_size() + Code::kHeaderSize;
3469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Locating source position.
3472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int SourcePosition(Address pc);
3473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int SourceStatementPosition(Address pc);
3474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
3476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Code* cast(Object* obj);
3477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
34793bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  int CodeSize() { return SizeFor(body_size()); }
3480756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void CodeIterateBody(ObjectVisitor* v);
3481756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
3482756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  template<typename StaticVisitor>
348344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void CodeIterateBody(Heap* heap);
3484b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
3485b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void CodePrint() {
3486b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    CodePrint(stdout);
3487b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3488b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void CodePrint(FILE* out);
3489b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
3490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
3491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CodeVerify();
3492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3493b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
34948b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  // Returns the isolate/heap this code object belongs to.
34958b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  inline Isolate* isolate();
34968b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  inline Heap* heap();
34978b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch
3498b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Max loop nesting marker used to postpose OSR. We don't take loop
3499b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // nesting that is deeper than 5 levels into account.
3500b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kMaxLoopNestingMarker = 6;
3501b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
3503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInstructionSizeOffset = HeapObject::kHeaderSize;
3504ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize;
3505b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kDeoptimizationDataOffset =
3506b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch      kRelocationInfoOffset + kPointerSize;
3507b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kFlagsOffset = kDeoptimizationDataOffset + kPointerSize;
3508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kKindSpecificFlagsOffset  = kFlagsOffset + kIntSize;
3509b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3510b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kKindSpecificFlagsSize = 2 * kIntSize;
3511b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3512b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kHeaderPaddingStart = kKindSpecificFlagsOffset +
3513b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch      kKindSpecificFlagsSize;
3514b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add padding to align the instruction start following right after
3516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the Code object header.
3517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeaderSize =
3518b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch      (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask;
3519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Byte offsets within kKindSpecificFlagsOffset.
3521b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset;
3522b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kOptimizableOffset = kKindSpecificFlagsOffset;
3523b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kStackSlotsOffset = kKindSpecificFlagsOffset;
3524b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kCheckTypeOffset = kKindSpecificFlagsOffset;
352544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kExternalArrayTypeOffset = kKindSpecificFlagsOffset;
3526b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3527b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kCompareStateOffset = kStubMajorKeyOffset + 1;
3528b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1;
3529b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kHasDeoptimizationSupportOffset = kOptimizableOffset + 1;
3530b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
3531b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1;
3532b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kAllowOSRAtLoopNestingLevelOffset =
3533b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch      kHasDeoptimizationSupportOffset + 1;
3534b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
35351e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize;
35361e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize;
3537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Flags layout.
3539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFlagsICStateShift        = 0;
3540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFlagsICInLoopShift       = 3;
35419dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  static const int kFlagsTypeShift           = 4;
354244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kFlagsKindShift           = 8;
354344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kFlagsICHolderShift       = 12;
354444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kFlagsExtraICStateShift   = 13;
354544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kFlagsArgumentsCountShift = 15;
3546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
35476ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kFlagsICStateMask        = 0x00000007;  // 00000000111
35486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kFlagsICInLoopMask       = 0x00000008;  // 00000001000
354944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kFlagsTypeMask           = 0x000000F0;  // 00001110000
355044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kFlagsKindMask           = 0x00000F00;  // 11110000000
355144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kFlagsCacheInPrototypeMapMask = 0x00001000;
355244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kFlagsExtraICStateMask   = 0x00006000;
355344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kFlagsArgumentsCountMask = 0xFFFF8000;
3554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFlagsNotUsedInLookup =
35568defd9ff6930b4e24729971a61cf7469daf119beSteve Block      (kFlagsICInLoopMask | kFlagsTypeMask | kFlagsCacheInPrototypeMapMask);
3557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(Code);
3560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// All heap objects have a Map that describes their structure.
3564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//  A Map contains information about:
3565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//  - Size information about the object
3566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//  - How to iterate over an object (for garbage collection)
3567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Map: public HeapObject {
3568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Instance size.
3570791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  // Size in bytes or kVariableSizeSentinel if instances do not have
3571791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  // a fixed size.
3572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int instance_size();
3573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_instance_size(int value);
3574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Count of properties allocated in the object.
3576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int inobject_properties();
3577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_inobject_properties(int value);
3578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Count of property fields pre-allocated in the object when first allocated.
3580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int pre_allocated_property_fields();
3581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_pre_allocated_property_fields(int value);
3582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Instance type.
3584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline InstanceType instance_type();
3585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_instance_type(InstanceType value);
3586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells how many unused property fields are available in the
3588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // instance (only used for JSObject in fast mode).
3589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int unused_property_fields();
3590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_unused_property_fields(int value);
3591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit field.
3593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline byte bit_field();
3594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_bit_field(byte value);
3595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit field 2.
3597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline byte bit_field2();
3598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_bit_field2(byte value);
3599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether the object in the prototype property will be used
3601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // for instances created from this function.  If the prototype
3602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // property is set to a value that is not a JSObject, the prototype
3603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // property will not be used to create instances of the function.
3604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // See ECMA-262, 13.2.2.
3605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_non_instance_prototype(bool value);
3606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool has_non_instance_prototype();
3607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
36086ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Tells whether function has special prototype property. If not, prototype
36096ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // property will not be created when accessed (will return undefined),
36106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // and construction from this function will not be allowed.
36116ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline void set_function_with_prototype(bool value);
36126ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline bool function_with_prototype();
36136ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
3614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether the instance with this map should be ignored by the
3615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // __proto__ accessor.
3616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_is_hidden_prototype() {
3617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    set_bit_field(bit_field() | (1 << kIsHiddenPrototype));
3618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_hidden_prototype() {
3621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((1 << kIsHiddenPrototype) & bit_field()) != 0;
3622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Records and queries whether the instance has a named interceptor.
3625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_has_named_interceptor() {
3626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    set_bit_field(bit_field() | (1 << kHasNamedInterceptor));
3627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool has_named_interceptor() {
3630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((1 << kHasNamedInterceptor) & bit_field()) != 0;
3631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Records and queries whether the instance has an indexed interceptor.
3634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_has_indexed_interceptor() {
3635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    set_bit_field(bit_field() | (1 << kHasIndexedInterceptor));
3636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool has_indexed_interceptor() {
3639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((1 << kHasIndexedInterceptor) & bit_field()) != 0;
3640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether the instance is undetectable.
3643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // An undetectable object is a special class of JSObject: 'typeof' operator
3644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // returns undefined, ToBoolean returns false. Otherwise it behaves like
3645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // a normal JS object.  It is useful for implementing undetectable
3646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // document.all in Firefox & Safari.
3647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
3648a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_is_undetectable() {
3649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    set_bit_field(bit_field() | (1 << kIsUndetectable));
3650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3652a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_undetectable() {
3653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((1 << kIsUndetectable) & bit_field()) != 0;
3654a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether the instance has a call-as-function handler.
3657a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_has_instance_call_handler() {
3658a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    set_bit_field(bit_field() | (1 << kHasInstanceCallHandler));
3659a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool has_instance_call_handler() {
3662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return ((1 << kHasInstanceCallHandler) & bit_field()) != 0;
3663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
3664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
36658defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline void set_is_extensible(bool value);
36668defd9ff6930b4e24729971a61cf7469daf119beSteve Block  inline bool is_extensible();
36678defd9ff6930b4e24729971a61cf7469daf119beSteve Block
36688defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // Tells whether the instance has fast elements.
3669756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS.
3670756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void set_has_fast_elements(bool value) {
36718defd9ff6930b4e24729971a61cf7469daf119beSteve Block    if (value) {
36728defd9ff6930b4e24729971a61cf7469daf119beSteve Block      set_bit_field2(bit_field2() | (1 << kHasFastElements));
36738defd9ff6930b4e24729971a61cf7469daf119beSteve Block    } else {
36748defd9ff6930b4e24729971a61cf7469daf119beSteve Block      set_bit_field2(bit_field2() & ~(1 << kHasFastElements));
36758defd9ff6930b4e24729971a61cf7469daf119beSteve Block    }
3676e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  }
3677e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
3678756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline bool has_fast_elements() {
36798defd9ff6930b4e24729971a61cf7469daf119beSteve Block    return ((1 << kHasFastElements) & bit_field2()) != 0;
3680e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  }
3681e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
36821e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // Tells whether an instance has pixel array elements.
368344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void set_has_external_array_elements(bool value) {
36841e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block    if (value) {
368544f0eee88ff00398ff7f715fab053374d808c90dSteve Block      set_bit_field2(bit_field2() | (1 << kHasExternalArrayElements));
36861e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block    } else {
368744f0eee88ff00398ff7f715fab053374d808c90dSteve Block      set_bit_field2(bit_field2() & ~(1 << kHasExternalArrayElements));
36881e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block    }
36891e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  }
36901e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
369144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline bool has_external_array_elements() {
369244f0eee88ff00398ff7f715fab053374d808c90dSteve Block    return ((1 << kHasExternalArrayElements) & bit_field2()) != 0;
36931e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  }
36941e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
36950d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Tells whether the map is attached to SharedFunctionInfo
36960d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // (for inobject slack tracking).
36970d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline void set_attached_to_shared_function_info(bool value);
36980d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
36990d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline bool attached_to_shared_function_info();
37000d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
37010d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Tells whether the map is shared between objects that may have different
37020d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // behavior. If true, the map should never be modified, instead a clone
37030d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // should be created and modified.
37040d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline void set_is_shared(bool value);
37050d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
37060d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline bool is_shared();
37070d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
3708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether the instance needs security checks when accessing its
3709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // properties.
3710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_is_access_check_needed(bool access_check_needed);
3711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_access_check_needed();
3712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [prototype]: implicit prototype object.
3714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(prototype, Object)
3715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [constructor]: points back to the function responsible for this map.
3717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(constructor, Object)
3718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
37190d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline JSFunction* unchecked_constructor();
37200d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
3721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [instance descriptors]: describes the object.
3722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(instance_descriptors, DescriptorArray)
3723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [stub cache]: contains stubs compiled for this map.
37256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  DECL_ACCESSORS(code_cache, Object)
3726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3727053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  // [prototype transitions]: cache of prototype transitions.
3728053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  // Prototype transition is a transition that happens
3729053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  // when we change object's prototype to a new one.
3730053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  // Cache format:
3731053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  //    0: finger - index of the first free cell in the cache
3732053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  //    1 + 2 * i: prototype
3733053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  //    2 + 2 * i: target map
3734053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  DECL_ACCESSORS(prototype_transitions, FixedArray)
3735053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  inline FixedArray* unchecked_prototype_transitions();
3736053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block
3737b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Lookup in the map's instance descriptors and fill out the result
3738b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // with the given holder if the name is found. The holder may be
3739b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // NULL when this function is used from the compiler.
3740b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void LookupInDescriptors(JSObject* holder,
3741b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch                           String* name,
3742b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch                           LookupResult* result);
3743b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
37445913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* CopyDropDescriptors();
374580d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
37465913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode,
37475913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                              NormalizedMapSharingMode sharing);
3748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns a copy of the map, with all transitions dropped from the
3750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // instance descriptors.
37515913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* CopyDropTransitions();
3752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
37538defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // Returns this map if it has the fast elements bit set, otherwise
37548defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // returns a copy of the map, with all transitions dropped from the
37558defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // descriptors and the fast elements bit set.
37565913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT inline MaybeObject* GetFastElementsMap();
37578defd9ff6930b4e24729971a61cf7469daf119beSteve Block
37588defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // Returns this map if it has the fast elements bit cleared,
37598defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // otherwise returns a copy of the map, with all transitions dropped
37608defd9ff6930b4e24729971a61cf7469daf119beSteve Block  // from the descriptors and the fast elements bit cleared.
37615913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT inline MaybeObject* GetSlowElementsMap();
37628defd9ff6930b4e24729971a61cf7469daf119beSteve Block
376344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // Returns a new map with all transitions dropped from the descriptors and the
376444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // external array elements bit set.
376544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  MUST_USE_RESULT MaybeObject* GetExternalArrayElementsMap(
376644f0eee88ff00398ff7f715fab053374d808c90dSteve Block      ExternalArrayType array_type,
376744f0eee88ff00398ff7f715fab053374d808c90dSteve Block      bool safe_to_add_transition);
37681e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
3769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the property index for name (only valid for FAST MODE).
3770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int PropertyIndexFor(String* name);
3771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3772a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the next free property index (only valid for FAST MODE).
3773a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NextFreePropertyIndex();
3774a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3775a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of properties described in instance_descriptors.
3776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int NumberOfDescribedProperties();
3777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
3779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Map* cast(Object* obj);
3780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3781a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Locate an accessor in the instance descriptor.
3782a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  AccessorDescriptor* FindAccessor(String* name);
3783a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Code cache operations.
3785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3786a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Clears the code cache.
378744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void ClearCodeCache(Heap* heap);
3788a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3789a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Update code cache.
37905913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code);
3791a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the found code or undefined if absent.
3793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* FindInCodeCache(String* name, Code::Flags flags);
3794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the non-negative index of the code object if it is in the
3796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // cache and -1 otherwise.
37976ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  int IndexInCodeCache(Object* name, Code* code);
3798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Removes a code object from the code cache at the given index.
38006ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  void RemoveFromCodeCache(String* name, Code* code, int index);
3801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // For every transition in this map, makes the transition's
3803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // target's prototype pointer point back to this map.
3804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // This is undone in MarkCompactCollector::ClearNonLiveTransitions().
3805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CreateBackPointers();
3806a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3807a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set all map transitions from this map to dead maps to null.
3808a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Also, restore the original prototype on the targets of these
3809a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // transitions, so that we do not process this map again while
3810a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // following back pointers.
381144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  void ClearNonLiveTransitions(Heap* heap, Object* real_prototype);
3812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
3814b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
3815b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void MapPrint() {
3816b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    MapPrint(stdout);
3817b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3818b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void MapPrint(FILE* out);
3819b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
3820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
3821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void MapVerify();
38220d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  void SharedMapVerify();
3823a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3824a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3825756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline int visitor_id();
3826756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void set_visitor_id(int visitor_id);
38273bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
382844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // Returns the isolate/heap this map belongs to.
382944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline Isolate* isolate();
383044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline Heap* heap();
383144f0eee88ff00398ff7f715fab053374d808c90dSteve Block
38320d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  typedef void (*TraverseCallback)(Map* map, void* data);
38330d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
38340d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  void TraverseTransitionTree(TraverseCallback callback, void* data);
38350d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
3836053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  static const int kMaxCachedPrototypeTransitions = 256;
3837053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block
3838053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  Object* GetPrototypeTransition(Object* prototype);
3839053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block
3840053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  MaybeObject* PutPrototypeTransition(Object* prototype, Map* map);
3841053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block
3842a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxPreAllocatedPropertyFields = 255;
3843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
3845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInstanceSizesOffset = HeapObject::kHeaderSize;
3846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize;
3847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize;
3848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kConstructorOffset = kPrototypeOffset + kPointerSize;
3849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInstanceDescriptorsOffset =
3850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kConstructorOffset + kPointerSize;
3851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kCodeCacheOffset = kInstanceDescriptorsOffset + kPointerSize;
3852053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  static const int kPrototypeTransitionsOffset =
3853053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block      kCodeCacheOffset + kPointerSize;
3854053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block  static const int kPadStart = kPrototypeTransitionsOffset + kPointerSize;
38557f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kSize = MAP_POINTER_ALIGN(kPadStart);
38567f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
38577f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Layout of pointer fields. Heap iteration code relies on them
38587f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // being continiously allocated.
38597f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset;
38607f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kPointerFieldsEndOffset =
3861053d10c438f14580aaf4ab1b2aad93a5a4fe8b82Steve Block      Map::kPrototypeTransitionsOffset + kPointerSize;
3862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Byte offsets within kInstanceSizesOffset.
3864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInstanceSizeOffset = kInstanceSizesOffset + 0;
3865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInObjectPropertiesByte = 1;
3866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInObjectPropertiesOffset =
3867a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kInstanceSizesOffset + kInObjectPropertiesByte;
3868a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPreAllocatedPropertyFieldsByte = 2;
3869a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPreAllocatedPropertyFieldsOffset =
3870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte;
38719ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  static const int kVisitorIdByte = 3;
38729ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte;
3873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Byte offsets within kInstanceAttributesOffset attributes.
3875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0;
3876a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1;
3877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kBitFieldOffset = kInstanceAttributesOffset + 2;
3878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kBitField2Offset = kInstanceAttributesOffset + 3;
3879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3880a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset);
3881a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit positions for bit field.
3883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kUnused = 0;  // To be used for marking recently used maps.
3884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHasNonInstancePrototype = 1;
3885a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIsHiddenPrototype = 2;
3886a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHasNamedInterceptor = 3;
3887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHasIndexedInterceptor = 4;
3888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIsUndetectable = 5;
3889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHasInstanceCallHandler = 6;
3890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIsAccessCheckNeeded = 7;
3891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit positions for bit field 2
38933100271588b61cbc1dc472a3f2f105d2eed8497fAndrei Popescu  static const int kIsExtensible = 0;
38946ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kFunctionWithPrototype = 1;
38958defd9ff6930b4e24729971a61cf7469daf119beSteve Block  static const int kHasFastElements = 2;
3896756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static const int kStringWrapperSafeForDefaultValueOf = 3;
38970d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  static const int kAttachedToSharedFunctionInfo = 4;
38980d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  static const int kIsShared = 5;
389944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kHasExternalArrayElements = 6;
39006ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
39016ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Layout of the default cache. It holds alternating name and code objects.
39026ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kCodeCacheEntrySize = 2;
39036ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kCodeCacheEntryNameOffset = 0;
39046ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kCodeCacheEntryCodeOffset = 1;
3905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3906756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  typedef FixedBodyDescriptor<kPointerFieldsBeginOffset,
3907756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                              kPointerFieldsEndOffset,
3908756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                              kSize> BodyDescriptor;
3909756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
3910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
3911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(Map);
3912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// An abstract superclass, a marker class really, for simple structure classes.
3916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// It doesn't carry much functionality but allows struct classes to me
3917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// identified in the type system.
3918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Struct: public HeapObject {
3919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void InitializeBody(int object_size);
3921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Struct* cast(Object* that);
3922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
3923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Script describes a script which has been added to the VM.
3926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Script: public Struct {
3927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
3928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Script types.
3929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  enum Type {
3930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_NATIVE = 0,
3931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_EXTENSION = 1,
3932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    TYPE_NORMAL = 2
3933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
3934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Script compilation types.
3936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  enum CompilationType {
3937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    COMPILATION_TYPE_HOST = 0,
39383e5fa29ddb82551500b118e9bf37af3966277b70Teng-Hui Zhu    COMPILATION_TYPE_EVAL = 1
3939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
3940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [source]: the script source.
3942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(source, Object)
3943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [name]: the script name.
3945a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(name, Object)
3946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [id]: the script id.
3948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(id, Object)
3949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [line_offset]: script line offset in resource from where it was extracted.
3951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(line_offset, Smi)
3952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [column_offset]: script column offset in resource from where it was
3954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // extracted.
3955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(column_offset, Smi)
3956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [data]: additional data associated with this script.
3958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(data, Object)
3959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [context_data]: context data for the context this script was compiled in.
3961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(context_data, Object)
3962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [wrapper]: the wrapper cache.
3964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(wrapper, Proxy)
3965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [type]: the script type.
3967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(type, Smi)
3968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [compilation]: how the the script was compiled.
3970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(compilation_type, Smi)
3971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3972d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // [line_ends]: FixedArray of line ends positions.
3973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(line_ends, Object)
3974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3975d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // [eval_from_shared]: for eval scripts the shared funcion info for the
3976d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // function from which eval was called.
3977d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  DECL_ACCESSORS(eval_from_shared, Object)
3978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [eval_from_instructions_offset]: the instruction offset in the code for the
3980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // function from which eval was called where eval was called.
3981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(eval_from_instructions_offset, Smi)
3982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Script* cast(Object* obj);
3984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
39853ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // If script source is an external string, check that the underlying
39863ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  // resource is accessible. Otherwise, always return true.
39873ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block  inline bool HasValidSource();
39883ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
3989b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
3990b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ScriptPrint() {
3991b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ScriptPrint(stdout);
3992b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
3993b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ScriptPrint(FILE* out);
3994b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
3995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
3996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void ScriptVerify();
3997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
3998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
3999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSourceOffset = HeapObject::kHeaderSize;
4000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNameOffset = kSourceOffset + kPointerSize;
4001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLineOffsetOffset = kNameOffset + kPointerSize;
4002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize;
4003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kDataOffset = kColumnOffsetOffset + kPointerSize;
4004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kContextOffset = kDataOffset + kPointerSize;
4005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kWrapperOffset = kContextOffset + kPointerSize;
4006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kTypeOffset = kWrapperOffset + kPointerSize;
4007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kCompilationTypeOffset = kTypeOffset + kPointerSize;
4008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLineEndsOffset = kCompilationTypeOffset + kPointerSize;
4009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIdOffset = kLineEndsOffset + kPointerSize;
4010d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static const int kEvalFromSharedOffset = kIdOffset + kPointerSize;
4011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEvalFrominstructionsOffsetOffset =
4012d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block      kEvalFromSharedOffset + kPointerSize;
4013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize;
4014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
4016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(Script);
4017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
4018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4020b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// List of builtin functions we want to identify to improve code
4021b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// generation.
4022b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch//
4023b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// Each entry has a name of a global object property holding an object
4024b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// optionally followed by ".prototype", a name of a builtin function
4025b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// on the object (the one the id is set for), and a label.
4026b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch//
4027b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// Installation of ids for the selected builtin functions is handled
4028b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// by the bootstrapper.
4029b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch//
4030b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// NOTE: Order is important: math functions should be at the end of
4031b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch// the list and MathFloor should be the first math function.
4032b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#define FUNCTIONS_WITH_ID_LIST(V)                   \
4033b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Array.prototype, push, ArrayPush)               \
4034b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Array.prototype, pop, ArrayPop)                 \
403542effa50d92d47f80404ee63808dbde9921e6202Ben Murdoch  V(Function.prototype, apply, FunctionApply)       \
4036b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(String.prototype, charCodeAt, StringCharCodeAt) \
4037b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(String.prototype, charAt, StringCharAt)         \
4038b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(String, fromCharCode, StringFromCharCode)       \
4039b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, floor, MathFloor)                         \
4040b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, round, MathRound)                         \
4041b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, ceil, MathCeil)                           \
4042b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, abs, MathAbs)                             \
4043b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, log, MathLog)                             \
4044b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, sin, MathSin)                             \
4045b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, cos, MathCos)                             \
4046b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, tan, MathTan)                             \
4047b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, asin, MathASin)                           \
4048b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, acos, MathACos)                           \
4049b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, atan, MathATan)                           \
4050b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, exp, MathExp)                             \
4051b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, sqrt, MathSqrt)                           \
4052b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  V(Math, pow, MathPow)
4053b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4054b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4055b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochenum BuiltinFunctionId {
4056b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#define DECLARE_FUNCTION_ID(ignored1, ignore2, name)    \
4057b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  k##name,
4058b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID)
4059b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#undef DECLARE_FUNCTION_ID
4060b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Fake id for a special case of Math.pow. Note, it continues the
4061b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // list of math functions.
4062b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  kMathPowHalf,
4063b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  kFirstMathFunctionId = kMathFloor
4064b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch};
4065b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4066b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4067a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// SharedFunctionInfo describes the JSFunction information that can be
4068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// shared by multiple instances of the function.
4069a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass SharedFunctionInfo: public HeapObject {
4070a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
4071a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [name]: Function name.
4072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(name, Object)
4073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [code]: Function code.
4075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(code, Code)
4076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
40773bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  // [scope_info]: Scope info.
40783bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  DECL_ACCESSORS(scope_info, SerializedScopeInfo)
40793bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch
4080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [construct stub]: Code stub for constructing instances of this function.
4081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(construct_stub, Code)
4082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4083756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline Code* unchecked_code();
4084756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
4085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns if this function has been compiled to native code yet.
4086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_compiled();
4087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [length]: The function length - usually the number of declared parameters.
4089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Use up to 2^30 parameters.
4090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int length();
4091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_length(int value);
4092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [formal parameter count]: The declared number of parameters.
4094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int formal_parameter_count();
4095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_formal_parameter_count(int value);
4096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set the formal parameter count so the function code will be
4098a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // called without using argument adaptor frames.
4099a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void DontAdaptArguments();
4100a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4101a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [expected_nof_properties]: Expected number of properties for the function.
4102a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int expected_nof_properties();
4103a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_expected_nof_properties(int value);
4104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
41050d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Inobject slack tracking is the way to reclaim unused inobject space.
41060d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //
41070d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // The instance size is initially determined by adding some slack to
41080d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // expected_nof_properties (to allow for a few extra properties added
41090d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // after the constructor). There is no guarantee that the extra space
41100d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // will not be wasted.
41110d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //
41120d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Here is the algorithm to reclaim the unused inobject space:
41130d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // - Detect the first constructor call for this SharedFunctionInfo.
41140d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   When it happens enter the "in progress" state: remember the
41150d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   constructor's initial_map and install a special construct stub that
41160d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   counts constructor calls.
41170d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // - While the tracking is in progress create objects filled with
41180d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   one_pointer_filler_map instead of undefined_value. This way they can be
41190d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   resized quickly and safely.
41200d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // - Once enough (kGenerousAllocationCount) objects have been created
41210d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   compute the 'slack' (traverse the map transition tree starting from the
41220d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   initial_map and find the lowest value of unused_property_fields).
41230d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // - Traverse the transition tree again and decrease the instance size
41240d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   of every map. Existing objects will resize automatically (they are
41250d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   filled with one_pointer_filler_map). All further allocations will
41260d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   use the adjusted instance size.
41270d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // - Decrease expected_nof_properties so that an allocations made from
41280d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   another context will use the adjusted instance size too.
41290d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // - Exit "in progress" state by clearing the reference to the initial_map
41300d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   and setting the regular construct stub (generic or inline).
41310d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //
41320d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //  The above is the main event sequence. Some special cases are possible
41330d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //  while the tracking is in progress:
41340d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //
41350d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // - GC occurs.
41360d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   Check if the initial_map is referenced by any live objects (except this
41370d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   SharedFunctionInfo). If it is, continue tracking as usual.
41380d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   If it is not, clear the reference and reset the tracking state. The
41390d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   tracking will be initiated again on the next constructor call.
41400d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //
41410d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // - The constructor is called from another context.
41420d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   Immediately complete the tracking, perform all the necessary changes
41430d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   to maps. This is  necessary because there is no efficient way to track
41440d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   multiple initial_maps.
41450d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   Proceed to create an object in the current context (with the adjusted
41460d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   size).
41470d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //
41480d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // - A different constructor function sharing the same SharedFunctionInfo is
41490d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   called in the same context. This could be another closure in the same
41500d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   context, or the first function could have been disposed.
41510d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //   This is handled the same way as the previous case.
41520d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //
41530d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //  Important: inobject slack tracking is not attempted during the snapshot
41540d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  //  creation.
41550d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
4156f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  static const int kGenerousAllocationCount = 8;
41570d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
41580d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // [construction_count]: Counter for constructor calls made during
41590d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // the tracking phase.
41600d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline int construction_count();
41610d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline void set_construction_count(int value);
41620d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
41630d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // [initial_map]: initial map of the first function called as a constructor.
41640d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Saved for the duration of the tracking phase.
41650d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // This is a weak link (GC resets it to undefined_value if no other live
41660d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // object reference this map).
41670d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  DECL_ACCESSORS(initial_map, Object)
41680d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
41690d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // True if the initial_map is not undefined and the countdown stub is
41700d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // installed.
41710d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline bool IsInobjectSlackTrackingInProgress();
41720d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
41730d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Starts the tracking.
41740d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Stores the initial map and installs the countdown stub.
41750d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // IsInobjectSlackTrackingInProgress is normally true after this call,
41760d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // except when tracking have not been started (e.g. the map has no unused
41770d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // properties or the snapshot is being built).
41780d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  void StartInobjectSlackTracking(Map* map);
41790d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
41800d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Completes the tracking.
41810d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // IsInobjectSlackTrackingInProgress is false after this call.
41820d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  void CompleteInobjectSlackTracking();
41830d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
41840d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Clears the initial_map before the GC marking phase to ensure the reference
41850d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // is weak. IsInobjectSlackTrackingInProgress is false after this call.
41860d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  void DetachInitialMap();
41870d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
41880d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Restores the link to the initial map after the GC marking phase.
41890d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // IsInobjectSlackTrackingInProgress is true after this call.
41900d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  void AttachInitialMap(Map* map);
41910d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
41920d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // False if there are definitely no live objects created from this function.
41930d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // True if live objects _may_ exist (existence not guaranteed).
41940d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // May go back from true to false after GC.
41950d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline bool live_objects_may_exist();
41960d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
41970d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  inline void set_live_objects_may_exist(bool value);
41980d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
4199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [instance class name]: class name for instances.
4200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(instance_class_name, Object)
4201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
42026ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // [function data]: This field holds some additional data for function.
42036ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Currently it either has FunctionTemplateInfo to make benefit the API
4204b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // or Smi identifying a builtin function.
4205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // In the long run we don't want all functions to have this field but
4206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // we can fix that when we have a better model for storing hidden data
4207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // on objects.
4208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(function_data, Object)
4209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
42106ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline bool IsApiFunction();
42116ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline FunctionTemplateInfo* get_api_func_data();
4212b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool HasBuiltinFunctionId();
4213b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline BuiltinFunctionId builtin_function_id();
42146ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
4215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [script info]: Script from which the function originates.
4216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(script, Object)
4217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
42186ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // [num_literals]: Number of literals used by this function.
42196ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline int num_literals();
42206ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline void set_num_literals(int value);
42216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
4222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [start_position_and_type]: Field used to store both the source code
4223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // position, whether or not the function is a function expression,
4224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // and whether or not the function is a toplevel function. The two
4225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // least significants bit indicates whether the function is an
4226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // expression and the rest contains the source code position.
4227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int start_position_and_type();
4228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_start_position_and_type(int value);
4229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [debug info]: Debug information.
4231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(debug_info, Object)
4232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [inferred name]: Name inferred from variable or property
4234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // assignment of this function. Used to facilitate debugging and
4235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // profiling of JavaScript code written in OO style, where almost
4236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // all functions are anonymous but are assigned to object
4237a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // properties.
4238a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(inferred_name, String)
4239a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4240f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  // The function's name if it is non-empty, otherwise the inferred name.
4241f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch  String* DebugName();
4242f87a203d89e1bbb6708282e0b64dbd13d59b723dBen Murdoch
4243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Position of the 'function' token in the script source.
4244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int function_token_position();
4245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_function_token_position(int function_token_position);
4246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Position of this function in the script source.
4248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int start_position();
4249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_start_position(int start_position);
4250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // End position of this function in the script source.
4252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int end_position();
4253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_end_position(int end_position);
4254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Is this function a function expression in the source code.
4256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_expression();
4257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_is_expression(bool value);
4258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Is this function a top-level function (scripts, evals).
4260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_toplevel();
4261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_is_toplevel(bool value);
4262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit field containing various information collected by the compiler to
4264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // drive optimization.
4265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int compiler_hints();
4266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_compiler_hints(int value);
4267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4268b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // A counter used to determine when to stress the deoptimizer with a
4269b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // deopt.
4270b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline Smi* deopt_counter();
4271b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_deopt_counter(Smi* counter);
4272b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add information on assignments of the form this.x = ...;
4274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SetThisPropertyAssignmentsInfo(
4275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      bool has_only_simple_this_property_assignments,
4276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      FixedArray* this_property_assignments);
4277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Clear information on assignments of the form this.x = ...;
4279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void ClearThisPropertyAssignmentsInfo();
4280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Indicate that this function only consists of assignments of the form
4282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // this.x = y; where y is either a constant or refers to an argument.
4283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool has_only_simple_this_property_assignments();
4284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
42857f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Indicates if this function can be lazy compiled.
42867f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // This is used to determine if we can safely flush code from a function
42877f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // when doing GC if we expect that the function will no longer be used.
42887f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  inline bool allows_lazy_compilation();
42897f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  inline void set_allows_lazy_compilation(bool flag);
42907f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
4291756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // Indicates how many full GCs this function has survived with assigned
4292756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // code object. Used to determine when it is relatively safe to flush
4293756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // this code object and replace it with lazy compilation stub.
4294756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // Age is reset when GC notices that the code object is referenced
4295756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  // from the stack or compilation cache.
4296756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline int code_age();
4297756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void set_code_age(int age);
4298756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
4299b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Indicates whether optimizations have been disabled for this
4300b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // shared function info. If a function is repeatedly optimized or if
4301b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // we cannot optimize the function we disable optimization to avoid
4302b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // spending time attempting to optimize it again.
4303b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool optimization_disabled();
4304b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_optimization_disabled(bool value);
4305b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
43061e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // Indicates whether the function is a strict mode function.
43071e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline bool strict_mode();
43081e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline void set_strict_mode(bool value);
43091e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
4310b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Indicates whether or not the code in the shared function support
4311b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // deoptimization.
4312b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool has_deoptimization_support();
4313b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4314b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Enable deoptimization support through recompiled code.
4315b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void EnableDeoptimizationSupport(Code* recompiled);
4316b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4317b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Lookup the bailout ID and ASSERT that it exists in the non-optimized
4318b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // code, returns whether it asserted (i.e., always true if assertions are
4319b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // disabled).
4320b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  bool VerifyBailoutId(int id);
4321756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
4322402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // Check whether a inlined constructor can be generated with the given
4323402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  // prototype.
4324402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu  bool CanGenerateInlineConstructor(Object* prototype);
4325402d937239b0e2fd11bf2f4fe972ad78aa9fd481Andrei Popescu
43260d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Prevents further attempts to generate inline constructors.
43270d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // To be called if generation failed for any reason.
43280d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  void ForbidInlineConstructor();
43290d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
4330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // For functions which only contains this property assignments this provides
4331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // access to the names for the properties assigned.
4332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(this_property_assignments, Object)
4333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int this_property_assignments_count();
4334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_this_property_assignments_count(int value);
4335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  String* GetThisPropertyAssignmentName(int index);
4336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsThisPropertyAssignmentArgument(int index);
4337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetThisPropertyAssignmentArgument(int index);
4338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* GetThisPropertyAssignmentConstant(int index);
4339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [source code]: Source code for the function.
4341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasSourceCode();
4342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* GetSourceCode();
4343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4344b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline int opt_count();
4345b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_opt_count(int opt_count);
4346b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4347b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Source size of this function.
4348b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  int SourceSize();
4349b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Calculate the instance size.
4351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int CalculateInstanceSize();
4352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Calculate the number of in-object properties.
4354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int CalculateInObjectProperties();
4355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
4357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set max_length to -1 for unlimited length.
4358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SourceCodePrint(StringStream* accumulator, int max_length);
4359b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
4360b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void SharedFunctionInfoPrint() {
4361b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    SharedFunctionInfoPrint(stdout);
4362b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
4363b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void SharedFunctionInfoPrint(FILE* out);
4364b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
4365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
4366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SharedFunctionInfoVerify();
4367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
4370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline SharedFunctionInfo* cast(Object* obj);
4371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Constants.
4373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kDontAdaptArgumentsSentinel = -1;
4374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
43766ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Pointer fields.
4377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNameOffset = HeapObject::kHeaderSize;
4378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kCodeOffset = kNameOffset + kPointerSize;
43793bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  static const int kScopeInfoOffset = kCodeOffset + kPointerSize;
43803bec4d28b1f388dbc06a9c4276e1a03e86c52b04Ben Murdoch  static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize;
43816ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kInstanceClassNameOffset =
43826ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      kConstructStubOffset + kPointerSize;
43836ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kFunctionDataOffset =
43846ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      kInstanceClassNameOffset + kPointerSize;
43856ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kScriptOffset = kFunctionDataOffset + kPointerSize;
43866ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kDebugInfoOffset = kScriptOffset + kPointerSize;
43876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize;
43880d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  static const int kInitialMapOffset =
43896ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      kInferredNameOffset + kPointerSize;
43900d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  static const int kThisPropertyAssignmentsOffset =
43910d5e116f6aee03185f237311a943491bb079a768Kristian Monsen      kInitialMapOffset + kPointerSize;
4392b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kDeoptCounterOffset =
4393b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch      kThisPropertyAssignmentsOffset + kPointerSize;
43947f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch#if V8_HOST_ARCH_32_BIT
43957f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Smi fields.
43966ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kLengthOffset =
4397b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch      kDeoptCounterOffset + kPointerSize;
43987f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize;
4399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kExpectedNofPropertiesOffset =
44007f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kFormalParameterCountOffset + kPointerSize;
44017f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kNumLiteralsOffset =
44027f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kExpectedNofPropertiesOffset + kPointerSize;
4403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kStartPositionAndTypeOffset =
44047f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kNumLiteralsOffset + kPointerSize;
44057f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kEndPositionOffset =
44067f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kStartPositionAndTypeOffset + kPointerSize;
44077f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kFunctionTokenPositionOffset =
44087f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kEndPositionOffset + kPointerSize;
44097f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kCompilerHintsOffset =
44107f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kFunctionTokenPositionOffset + kPointerSize;
44117f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kThisPropertyAssignmentsCountOffset =
44127f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kCompilerHintsOffset + kPointerSize;
4413b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kOptCountOffset =
4414b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch      kThisPropertyAssignmentsCountOffset + kPointerSize;
44157f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Total size.
4416b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kSize = kOptCountOffset + kPointerSize;
44177f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch#else
44187f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // The only reason to use smi fields instead of int fields
44190d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // is to allow iteration without maps decoding during
44207f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // garbage collections.
44217f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // To avoid wasting space on 64-bit architectures we use
44227f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // the following trick: we group integer fields into pairs
44237f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // First integer in each pair is shifted left by 1.
44247f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // By doing this we guarantee that LSB of each kPointerSize aligned
44257f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // word is not set and thus this word cannot be treated as pointer
44267f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // to HeapObject during old space traversal.
44277f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kLengthOffset =
4428b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch      kDeoptCounterOffset + kPointerSize;
44297f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kFormalParameterCountOffset =
44307f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kLengthOffset + kIntSize;
44317f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
44327f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kExpectedNofPropertiesOffset =
44337f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kFormalParameterCountOffset + kIntSize;
44347f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kNumLiteralsOffset =
44357f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kExpectedNofPropertiesOffset + kIntSize;
44367f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
44377f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kEndPositionOffset =
44386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      kNumLiteralsOffset + kIntSize;
44397f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kStartPositionAndTypeOffset =
44407f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kEndPositionOffset + kIntSize;
44417f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
44427f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kFunctionTokenPositionOffset =
44437f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kStartPositionAndTypeOffset + kIntSize;
44446ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kCompilerHintsOffset =
4445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kFunctionTokenPositionOffset + kIntSize;
44467f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
4447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kThisPropertyAssignmentsCountOffset =
44486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      kCompilerHintsOffset + kIntSize;
4449b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kOptCountOffset =
4450b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch      kThisPropertyAssignmentsCountOffset + kIntSize;
44517f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
44526ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Total size.
4453b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kSize = kOptCountOffset + kIntSize;
44547f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
44557f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch#endif
44560d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
44570d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // The construction counter for inobject slack tracking is stored in the
44580d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // most significant byte of compiler_hints which is otherwise unused.
44590d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  // Its offset depends on the endian-ness of the architecture.
44600d5e116f6aee03185f237311a943491bb079a768Kristian Monsen#if __BYTE_ORDER == __LITTLE_ENDIAN
44610d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  static const int kConstructionCountOffset = kCompilerHintsOffset + 3;
44620d5e116f6aee03185f237311a943491bb079a768Kristian Monsen#elif __BYTE_ORDER == __BIG_ENDIAN
44630d5e116f6aee03185f237311a943491bb079a768Kristian Monsen  static const int kConstructionCountOffset = kCompilerHintsOffset + 0;
44640d5e116f6aee03185f237311a943491bb079a768Kristian Monsen#else
44650d5e116f6aee03185f237311a943491bb079a768Kristian Monsen#error Unknown byte ordering
44660d5e116f6aee03185f237311a943491bb079a768Kristian Monsen#endif
44670d5e116f6aee03185f237311a943491bb079a768Kristian Monsen
44686ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize);
4469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4470756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  typedef FixedBodyDescriptor<kNameOffset,
4471756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                              kThisPropertyAssignmentsOffset + kPointerSize,
4472756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                              kSize> BodyDescriptor;
4473756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
4474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit positions in start_position_and_type.
4475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The source code start position is in the 30 most significant bits of
4476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the start_position_and_type field.
4477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIsExpressionBit = 0;
4478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIsTopLevelBit   = 1;
4479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kStartPositionShift = 2;
4480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);
4481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit positions in compiler_hints.
4483d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static const int kHasOnlySimpleThisPropertyAssignments = 0;
44848b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  static const int kAllowLazyCompilation = 1;
44858b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  static const int kLiveObjectsMayExist = 2;
44868b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  static const int kCodeAgeShift = 3;
4487b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kCodeAgeMask = 0x7;
44888b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  static const int kOptimizationDisabled = 6;
44898b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  static const int kStrictModeFunction = 7;
4490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4491e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch private:
4492e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch#if V8_HOST_ARCH_32_BIT
4493e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // On 32 bit platforms, compiler hints is a smi.
4494e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  static const int kCompilerHintsSmiTagSize = kSmiTagSize;
4495e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  static const int kCompilerHintsSize = kPointerSize;
4496e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch#else
4497e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // On 64 bit platforms, compiler hints is not a smi, see comment above.
4498e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  static const int kCompilerHintsSmiTagSize = 0;
4499e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  static const int kCompilerHintsSize = kIntSize;
4500e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch#endif
4501e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch
4502e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch public:
4503e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // Constants for optimizing codegen for strict mode function tests.
4504e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  // Allows to use byte-widgh instructions.
4505e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  static const int kStrictModeBitWithinByte =
4506e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch      (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte;
4507e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch
4508e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch#if __BYTE_ORDER == __LITTLE_ENDIAN
4509e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  static const int kStrictModeByteOffset = kCompilerHintsOffset +
4510e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte;
4511e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch#elif __BYTE_ORDER == __BIG_ENDIAN
4512e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch  static const int kStrictModeByteOffset = kCompilerHintsOffset +
4513e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    (kCompilerHintsSize - 1) -
4514e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch    ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte);
4515e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch#else
4516e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch#error Unknown byte ordering
4517e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch#endif
4518e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch
4519e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch private:
4520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo);
4521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
4522a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// JSFunction describes JavaScript functions.
4525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSFunction: public JSObject {
4526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
4527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [prototype_or_initial_map]:
4528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(prototype_or_initial_map, Object)
4529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [shared_function_info]: The information about the function that
4531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // can be shared by instances.
4532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(shared, SharedFunctionInfo)
4533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4534756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline SharedFunctionInfo* unchecked_shared();
4535756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
4536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [context]: The context for this function.
4537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Context* context();
4538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* unchecked_context();
4539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_context(Object* context);
4540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [code]: The generated code object for this function.  Executed
4542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // when the function is invoked, e.g. foo() or new foo(). See
4543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [[Call]] and [[Construct]] description in ECMA-262, section
4544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // 8.6.2, page 27.
4545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Code* code();
4546b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void set_code(Code* code);
4547b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ReplaceCode(Code* code);
4548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4549756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline Code* unchecked_code();
4550756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
4551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether this function is builtin.
4552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsBuiltin();
4553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4554b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Tells whether or not the function needs arguments adaption.
4555b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool NeedsArgumentsAdaption();
4556b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4557b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Tells whether or not this function has been optimized.
4558b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool IsOptimized();
4559b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
45608b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  // Tells whether or not this function can be optimized.
45618b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  inline bool IsOptimizable();
45628b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch
4563b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Mark this function for lazy recompilation. The function will be
4564b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // recompiled the next time it is executed.
4565b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void MarkForLazyRecompilation();
4566b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4567b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Tells whether or not the function is already marked for lazy
4568b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // recompilation.
4569b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline bool IsMarkedForLazyRecompilation();
4570b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4571b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Compute a hash code for the source code of this function.
4572b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  uint32_t SourceHash();
4573b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4574b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Check whether or not this function is inlineable.
4575b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  bool IsInlineable();
4576b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [literals]: Fixed array holding the materialized literals.
4578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  //
4579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // If the function contains object, regexp or array literals, the
4580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // literals array prefix contains the object, regexp, and array
4581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // function to be used when creating these literals.  This is
4582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // necessary so that we do not dynamically lookup the object, regexp
4583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // or array functions.  Performing a dynamic lookup, we might end up
4584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // using the functions from a new context that we should not have
4585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // access to.
4586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(literals, FixedArray)
4587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The initial map for an object created by this constructor.
4589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Map* initial_map();
4590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_initial_map(Map* value);
4591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool has_initial_map();
4592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get and set the prototype property on a JSFunction. If the
4594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // function has an initial map the prototype is set on the initial
4595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // map. Otherwise, the prototype is put in the initial map field
4596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // until an initial map is needed.
4597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool has_prototype();
4598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool has_instance_prototype();
4599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* prototype();
4600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* instance_prototype();
4601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* SetInstancePrototype(Object* value);
46025913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SetPrototype(Object* value);
4603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
46046ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // After prototype is removed, it will not be created when accessed, and
46056ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // [[Construct]] from this function will not be allowed.
46066ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  Object* RemovePrototype();
46076ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline bool should_have_prototype();
46086ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
4609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Accessor for this function's initial map's [[class]]
4610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // property. This is primarily used by ECMA native functions.  This
4611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // method sets the class_name field of this function's initial map
4612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // to a given value. It creates an initial map if this function does
4613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // not have one. Note that this method does not copy the initial map
4614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // if it has one already, but simply replaces it with the new value.
4615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Instances created afterwards will have a map whose [[class]] is
4616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // set to 'value', but there is no guarantees on instances created
4617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // before.
4618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* SetInstanceClassName(String* name);
4619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns if this function has been compiled to native code yet.
4621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool is_compiled();
4622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4623b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // [next_function_link]: Field for linking functions. This list is treated as
4624b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // a weak list by the GC.
4625b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  DECL_ACCESSORS(next_function_link, Object)
4626b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4627b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Prints the name of the function using PrintF.
4628b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void PrintName() {
4629b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    PrintName(stdout);
4630b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
4631b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void PrintName(FILE* out);
4632b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
4633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
4634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline JSFunction* cast(Object* obj);
4635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4636791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  // Iterates the objects, including code objects indirectly referenced
4637791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  // through pointers to the first instruction in the code object.
4638791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  void JSFunctionIterateBody(int object_size, ObjectVisitor* v);
4639791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block
4640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
4641b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
4642b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void JSFunctionPrint() {
4643b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    JSFunctionPrint(stdout);
4644b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
4645b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void JSFunctionPrint(FILE* out);
4646b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
4647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
4648a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSFunctionVerify();
4649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the number of allocated literals.
4652a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int NumberOfLiterals();
4653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4654a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Retrieve the global context from a function's literal array.
4655a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Context* GlobalContextFromLiterals(FixedArray* literals);
4656a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4657b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to
4658b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // kSize) is weak and has special handling during garbage collection.
4659791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  static const int kCodeEntryOffset = JSObject::kHeaderSize;
4660756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static const int kPrototypeOrInitialMapOffset =
4661791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block      kCodeEntryOffset + kPointerSize;
4662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSharedFunctionInfoOffset =
4663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kPrototypeOrInitialMapOffset + kPointerSize;
4664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize;
4665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLiteralsOffset = kContextOffset + kPointerSize;
4666b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize;
4667b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset;
4668b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  static const int kSize = kNextFunctionLinkOffset + kPointerSize;
4669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout of the literals array.
4671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLiteralsPrefixSize = 1;
4672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLiteralGlobalContextIndex = 0;
4673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
4674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction);
4675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
4676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// JSGlobalProxy's prototype must be a JSGlobalObject or null,
4679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// and the prototype is hidden. JSGlobalProxy always delegates
4680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// property accesses to its prototype if the prototype is not null.
4681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
4682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A JSGlobalProxy can be reinitialized which will preserve its identity.
4683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
4684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Accessing a JSGlobalProxy requires security check.
4685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSGlobalProxy : public JSObject {
4687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
4688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [context]: the owner global context of this proxy object.
4689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // It is null value if this object is not used by any context.
4690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(context, Object)
4691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
4693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline JSGlobalProxy* cast(Object* obj);
4694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
4696b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
4697b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void JSGlobalProxyPrint() {
4698b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    JSGlobalProxyPrint(stdout);
4699b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
4700b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void JSGlobalProxyPrint(FILE* out);
4701b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
4702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
4703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSGlobalProxyVerify();
4704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
4707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kContextOffset = JSObject::kHeaderSize;
4708a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kContextOffset + kPointerSize;
4709a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4710a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
4711a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4712a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy);
4713a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
4714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Forward declaration.
4717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSBuiltinsObject;
4718b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdochclass JSGlobalPropertyCell;
4719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Common super class for JavaScript global objects and the special
4721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// builtins global objects.
4722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass GlobalObject: public JSObject {
4723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
4724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [builtins]: the object holding the runtime routines written in JS.
4725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(builtins, JSBuiltinsObject)
4726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [global context]: the global context corresponding to this global object.
4728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(global_context, Context)
4729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [global receiver]: the global receiver object of the context
4731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(global_receiver, JSObject)
4732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Retrieve the property cell used to store a property.
4734b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  JSGlobalPropertyCell* GetPropertyCell(LookupResult* result);
4735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
47365913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  // This is like GetProperty, but is used when you know the lookup won't fail
47375913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  // by throwing an exception.  This is for the debug and builtins global
47385913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  // objects, where it is known which properties can be expected to be present
47395913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  // on the object.
47405913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  Object* GetPropertyNoExceptionThrown(String* key) {
47415913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    Object* answer = GetProperty(key)->ToObjectUnchecked();
47425913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck    return answer;
47435913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  }
47445913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck
4745a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Ensure that the global object has a cell for the given property name.
47465913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name);
4747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
4749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline GlobalObject* cast(Object* obj);
4750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
4752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kBuiltinsOffset = JSObject::kHeaderSize;
4753a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize;
4754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize;
4755a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize;
4756a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4757a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
4758a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs;
4759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject);
4761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
4762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4764a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// JavaScript global object.
4765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSGlobalObject: public GlobalObject {
4766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
4767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
4769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline JSGlobalObject* cast(Object* obj);
4770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
4772b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
4773b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void JSGlobalObjectPrint() {
4774b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    JSGlobalObjectPrint(stdout);
4775b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
4776b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void JSGlobalObjectPrint(FILE* out);
4777b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
4778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
4779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSGlobalObjectVerify();
4780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4781a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4782a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
4783a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = GlobalObject::kHeaderSize;
4784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
4786a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject);
4787a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
4788a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4789a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4790a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Builtins global object which holds the runtime routines written in
4791a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// JavaScript.
4792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSBuiltinsObject: public GlobalObject {
4793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
4794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Accessors for the runtime routines written in JavaScript.
4795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* javascript_builtin(Builtins::JavaScript id);
4796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_javascript_builtin(Builtins::JavaScript id, Object* value);
4797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
47986ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Accessors for code of the runtime routines written in JavaScript.
47996ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline Code* javascript_builtin_code(Builtins::JavaScript id);
48006ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value);
48016ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
4802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
4803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline JSBuiltinsObject* cast(Object* obj);
4804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
4806b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
4807b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void JSBuiltinsObjectPrint() {
4808b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    JSBuiltinsObjectPrint(stdout);
4809b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
4810b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void JSBuiltinsObjectPrint(FILE* out);
4811b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
4812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
4813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSBuiltinsObjectVerify();
4814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.  The size of the builtins object includes
48176ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // room for two pointers per runtime routine written in javascript
48186ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // (function and code object).
4819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kJSBuiltinsCount = Builtins::id_count;
4820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize;
48216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kJSBuiltinsCodeOffset =
48226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize);
4823a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize =
48246ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize);
48256ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
48266ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static int OffsetOfFunctionWithId(Builtins::JavaScript id) {
48276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return kJSBuiltinsOffset + id * kPointerSize;
48286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
48296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
48306ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static int OffsetOfCodeWithId(Builtins::JavaScript id) {
48316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return kJSBuiltinsCodeOffset + id * kPointerSize;
48326ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
48336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
4834a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
4835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject);
4836a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
4837a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4838a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4839a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Representation for JS Wrapper objects, String, Number, Boolean, Date, etc.
4840a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSValue: public JSObject {
4841a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
4842a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [value]: the object being wrapped.
4843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(value, Object)
4844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
4846a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline JSValue* cast(Object* obj);
4847a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
4849b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
4850b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void JSValuePrint() {
4851b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    JSValuePrint(stdout);
4852b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
4853b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void JSValuePrint(FILE* out);
4854b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
4855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
4856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSValueVerify();
4857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4859a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
4860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kValueOffset = JSObject::kHeaderSize;
4861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kValueOffset + kPointerSize;
4862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4863a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
4864a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue);
4865a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
4866a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
48671e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
48681e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// Representation of message objects used for error reporting through
48691e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// the API. The messages are formatted in JavaScript so this object is
48701e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// a real JavaScript object. The information used for formatting the
48711e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// error messages are not directly accessible from JavaScript to
48721e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// prevent leaking information to user code called during error
48731e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// formatting.
48741e0659c275bb392c045087af4f6b0d7565cb3d77Steve Blockclass JSMessageObject: public JSObject {
48751e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block public:
48761e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // [type]: the type of error message.
48771e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  DECL_ACCESSORS(type, String)
48781e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
48791e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // [arguments]: the arguments for formatting the error message.
48801e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  DECL_ACCESSORS(arguments, JSArray)
48811e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
48821e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // [script]: the script from which the error message originated.
48831e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  DECL_ACCESSORS(script, Object)
48841e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
48851e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // [stack_trace]: the stack trace for this error message.
48861e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  DECL_ACCESSORS(stack_trace, Object)
48871e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
48881e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // [stack_frames]: an array of stack frames for this error object.
48891e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  DECL_ACCESSORS(stack_frames, Object)
48901e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
48911e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // [start_position]: the start position in the script for the error message.
48921e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline int start_position();
48931e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline void set_start_position(int value);
48941e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
48951e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // [end_position]: the end position in the script for the error message.
48961e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline int end_position();
48971e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline void set_end_position(int value);
48981e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
48991e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // Casting.
49001e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static inline JSMessageObject* cast(Object* obj);
49011e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
49021e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // Dispatched behavior.
49031e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block#ifdef OBJECT_PRINT
49041e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  inline void JSMessageObjectPrint() {
49051e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block    JSMessageObjectPrint(stdout);
49061e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  }
49071e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  void JSMessageObjectPrint(FILE* out);
49081e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block#endif
49091e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block#ifdef DEBUG
49101e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  void JSMessageObjectVerify();
49111e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block#endif
49121e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
49131e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  // Layout description.
49141e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kTypeOffset = JSObject::kHeaderSize;
49151e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kArgumentsOffset = kTypeOffset + kPointerSize;
49161e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kScriptOffset = kArgumentsOffset + kPointerSize;
49171e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kStackTraceOffset = kScriptOffset + kPointerSize;
49181e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kStackFramesOffset = kStackTraceOffset + kPointerSize;
49191e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kStartPositionOffset = kStackFramesOffset + kPointerSize;
49201e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kEndPositionOffset = kStartPositionOffset + kPointerSize;
49211e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  static const int kSize = kEndPositionOffset + kPointerSize;
49221e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
49231e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  typedef FixedBodyDescriptor<HeapObject::kMapOffset,
49241e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block                              kStackFramesOffset + kPointerSize,
49251e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block                              kSize> BodyDescriptor;
49261e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block};
49271e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
49281e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block
4929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Regular expressions
4930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The regular expression holds a single reference to a FixedArray in
4931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// the kDataOffset field.
4932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The FixedArray contains the following data:
4933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - tag : type of regexp implementation (not compiled yet, atom or irregexp)
4934a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - reference to the original source string
4935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - reference to the original flag string
4936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// If it is an atom regexp
4937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - a reference to a literal string to search for
4938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// If it is an irregexp regexp:
4939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - a reference to code for ASCII inputs (bytecode or compiled).
4940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - a reference to code for UC16 inputs (bytecode or compiled).
4941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - max number of registers used by irregexp implementations.
4942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// - number of capture registers (output values) of the regexp.
4943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSRegExp: public JSObject {
4944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
4945a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Meaning of Type:
4946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet.
4947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ATOM: A simple string to match against using an indexOf operation.
4948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // IRREGEXP: Compiled with Irregexp.
4949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // IRREGEXP_NATIVE: Compiled to native code with Irregexp.
4950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  enum Type { NOT_COMPILED, ATOM, IRREGEXP };
4951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 };
4952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class Flags {
4954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
4955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    explicit Flags(uint32_t value) : value_(value) { }
4956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    bool is_global() { return (value_ & GLOBAL) != 0; }
4957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; }
4958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    bool is_multiline() { return (value_ & MULTILINE) != 0; }
4959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint32_t value() { return value_; }
4960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   private:
4961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    uint32_t value_;
4962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
4963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(data, Object)
4965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Type TypeTag();
4967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int CaptureCount();
4968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Flags GetFlags();
4969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline String* Pattern();
4970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* DataAt(int index);
4971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set implementation data after the object has been prepared.
4972a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SetDataAt(int index, Object* value);
4973a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int code_index(bool is_ascii) {
4974a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (is_ascii) {
4975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      return kIrregexpASCIICodeIndex;
4976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    } else {
4977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      return kIrregexpUC16CodeIndex;
4978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
4979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
4980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline JSRegExp* cast(Object* obj);
4982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
4984a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
4985a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSRegExpVerify();
4986a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
4987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kDataOffset = JSObject::kHeaderSize;
4989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kDataOffset + kPointerSize;
4990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
4991a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Indices in the data array.
4992a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kTagIndex = 0;
4993a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSourceIndex = kTagIndex + 1;
4994a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFlagsIndex = kSourceIndex + 1;
4995a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kDataIndex = kFlagsIndex + 1;
4996a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The data fields are used in different ways depending on the
4997a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // value of the tag.
4998a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Atom regexps (literal strings).
4999a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kAtomPatternIndex = kDataIndex;
5000a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5001a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kAtomDataSize = kAtomPatternIndex + 1;
5002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5003a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Irregexp compiled code or bytecode for ASCII. If compilation
5004a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // fails, this fields hold an exception object that should be
5005a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // thrown if the regexp is used again.
5006a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIrregexpASCIICodeIndex = kDataIndex;
5007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Irregexp compiled code or bytecode for UC16.  If compilation
5008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // fails, this fields hold an exception object that should be
5009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // thrown if the regexp is used again.
5010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIrregexpUC16CodeIndex = kDataIndex + 1;
5011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Maximal number of registers used by either ASCII or UC16.
5012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Only used to check that there is enough stack space
5013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 2;
5014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Number of captures in the compiled regexp.
5015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIrregexpCaptureCountIndex = kDataIndex + 3;
5016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1;
5018e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
5019e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Offsets directly into the data fixed array.
5020e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kDataTagOffset =
5021e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      FixedArray::kHeaderSize + kTagIndex * kPointerSize;
5022e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kDataAsciiCodeOffset =
5023e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize;
5024d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke  static const int kDataUC16CodeOffset =
5025d91b9f7d46489a9ee00f9cb415630299c76a502bLeon Clarke      FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize;
5026e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kIrregexpCaptureCountOffset =
5027e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke      FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize;
50286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
50296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // In-object fields.
50306ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kSourceFieldIndex = 0;
50316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kGlobalFieldIndex = 1;
50326ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kIgnoreCaseFieldIndex = 2;
50336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kMultilineFieldIndex = 3;
50346ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kLastIndexFieldIndex = 4;
5035bb769b257e753aafcbd96767abb2abc645eaa20cBen Murdoch  static const int kInObjectFieldCount = 5;
5036a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5037a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5038a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5039a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass CompilationCacheShape {
5040a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5041a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool IsMatch(HashTableKey* key, Object* value) {
5042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->IsMatch(value);
5043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
5044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline uint32_t Hash(HashTableKey* key) {
5046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->Hash();
5047a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
5048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
5050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->HashForObject(object);
5051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
5052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
50535913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
5054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return key->AsObject();
5055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
5056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPrefixSize = 0;
5058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEntrySize = 2;
5059a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
50613ce2e2076e8e3e60cf1810eec160ea2d8557e9e7Steve Block
5062a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass CompilationCacheTable: public HashTable<CompilationCacheShape,
5063a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                              HashTableKey*> {
5064a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5065a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Find cached value for a string key, otherwise return null.
5066a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* Lookup(String* src);
50671e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  Object* LookupEval(String* src, Context* context, StrictModeFlag strict_mode);
5068a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* LookupRegExp(String* source, JSRegExp::Flags flags);
50695913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* Put(String* src, Object* value);
50701e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block  MaybeObject* PutEval(String* src,
50711e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block                       Context* context,
50721e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block                       SharedFunctionInfo* value);
50735913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MaybeObject* PutRegExp(String* src, JSRegExp::Flags flags, FixedArray* value);
5074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5075b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Remove given value from cache.
5076b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void Remove(Object* value);
5077b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
5078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline CompilationCacheTable* cast(Object* obj);
5079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable);
5082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
50856ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockclass CodeCache: public Struct {
50866ded16be15dd865a9b21ea304d5273c8be299c87Steve Block public:
50876ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  DECL_ACCESSORS(default_cache, FixedArray)
50886ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  DECL_ACCESSORS(normal_type_cache, Object)
50896ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
50906ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Add the code object to the cache.
50915913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* Update(String* name, Code* code);
50926ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
50936ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Lookup code object in the cache. Returns code object if found and undefined
50946ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // if not.
50956ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  Object* Lookup(String* name, Code::Flags flags);
50966ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
50976ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Get the internal index of a code object in the cache. Returns -1 if the
50986ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // code object is not in that cache. This index can be used to later call
50996ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // RemoveByIndex. The cache cannot be modified between a call to GetIndex and
51006ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // RemoveByIndex.
51016ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  int GetIndex(Object* name, Code* code);
51026ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51036ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Remove an object from the cache with the provided internal index.
51046ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  void RemoveByIndex(Object* name, Code* code, int index);
51056ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51066ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static inline CodeCache* cast(Object* obj);
51076ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
5108b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
5109b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void CodeCachePrint() {
5110b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    CodeCachePrint(stdout);
5111b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
5112b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void CodeCachePrint(FILE* out);
5113b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
51146ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#ifdef DEBUG
51156ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  void CodeCacheVerify();
51166ded16be15dd865a9b21ea304d5273c8be299c87Steve Block#endif
51176ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51186ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kDefaultCacheOffset = HeapObject::kHeaderSize;
51196ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kNormalTypeCacheOffset =
51206ded16be15dd865a9b21ea304d5273c8be299c87Steve Block      kDefaultCacheOffset + kPointerSize;
51216ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kSize = kNormalTypeCacheOffset + kPointerSize;
51226ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51236ded16be15dd865a9b21ea304d5273c8be299c87Steve Block private:
51245913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code);
51255913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code);
51266ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  Object* LookupDefaultCache(String* name, Code::Flags flags);
51276ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  Object* LookupNormalTypeCache(String* name, Code::Flags flags);
51286ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51296ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Code cache layout of the default cache. Elements are alternating name and
51306ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // code objects for non normal load/store/call IC's.
51316ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kCodeCacheEntrySize = 2;
51326ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kCodeCacheEntryNameOffset = 0;
51336ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kCodeCacheEntryCodeOffset = 1;
51346ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache);
51366ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
51376ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51386ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51396ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockclass CodeCacheHashTableShape {
51406ded16be15dd865a9b21ea304d5273c8be299c87Steve Block public:
51416ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static inline bool IsMatch(HashTableKey* key, Object* value) {
51426ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return key->IsMatch(value);
51436ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
51446ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51456ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static inline uint32_t Hash(HashTableKey* key) {
51466ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return key->Hash();
51476ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
51486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51496ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static inline uint32_t HashForObject(HashTableKey* key, Object* object) {
51506ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return key->HashForObject(object);
51516ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
51526ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51535913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) {
51546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block    return key->AsObject();
51556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  }
51566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51576ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kPrefixSize = 0;
51586ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kEntrySize = 2;
51596ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
51606ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51626ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockclass CodeCacheHashTable: public HashTable<CodeCacheHashTableShape,
51636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block                                           HashTableKey*> {
51646ded16be15dd865a9b21ea304d5273c8be299c87Steve Block public:
51656ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  Object* Lookup(String* name, Code::Flags flags);
51665913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* Put(String* name, Code* code);
51676ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51686ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  int GetIndex(String* name, Code::Flags flags);
51696ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  void RemoveByIndex(int index);
51706ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51716ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static inline CodeCacheHashTable* cast(Object* obj);
51726ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51736ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Initial size of the fixed array backing the hash table.
51746ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kInitialSize = 64;
51756ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51766ded16be15dd865a9b21ea304d5273c8be299c87Steve Block private:
51776ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable);
51786ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
51796ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
51806ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
5181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS};
5182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockenum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL};
5183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass StringHasher {
5186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
51878b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  explicit inline StringHasher(int length);
5188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns true if the hash of this string can be computed without
5190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // looking at the contents.
5191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool has_trivial_hash();
5192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Add a character to the hash and update the array index calculation.
5194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void AddCharacter(uc32 c);
5195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Adds a character to the hash but does not update the array index
5197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // calculation.  This can only be called when it has been verified
5198a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // that the input is not an array index.
5199a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void AddCharacterNoIndex(uc32 c);
5200a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5201a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns the value to store in the hash field of a string with
5202a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the given length and contents.
5203a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t GetHashField();
5204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns true if the characters seen so far make up a legal array
5206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // index.
5207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_array_index() { return is_array_index_; }
5208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_valid() { return is_valid_; }
5210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void invalidate() { is_valid_ = false; }
5212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
521380d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  // Calculated hash value for a string consisting of 1 to
521480d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  // String::kMaxArrayIndexSize digits with no leading zeros (except "0").
521580d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen  // value is represented decimal value.
52169ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  static uint32_t MakeArrayIndexHash(uint32_t value, int length);
521780d68eab642096c1a48b6474d6ec33064b0ad1f5Kristian Monsen
5218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t array_index() {
5221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ASSERT(is_array_index());
5222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return array_index_;
5223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
5224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uint32_t GetHash();
5226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int length_;
5228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t raw_running_hash_;
5229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t array_index_;
5230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_array_index_;
5231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_first_char_;
5232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_valid_;
5233d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  friend class TwoCharHashTableKey;
5234a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5235a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5236a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
523744f0eee88ff00398ff7f715fab053374d808c90dSteve Block// Calculates string hash.
523844f0eee88ff00398ff7f715fab053374d808c90dSteve Blocktemplate <typename schar>
523944f0eee88ff00398ff7f715fab053374d808c90dSteve Blockinline uint32_t HashSequentialString(const schar* chars, int length);
524044f0eee88ff00398ff7f715fab053374d808c90dSteve Block
524144f0eee88ff00398ff7f715fab053374d808c90dSteve Block
5242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The characteristics of a string are stored in its map.  Retrieving these
5243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// few bits of information is moderately expensive, involving two memory
5244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// loads where the second is dependent on the first.  To improve efficiency
5245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// the shape of the string is given its own class so that it can be retrieved
5246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// once and used for several string operations.  A StringShape is small enough
5247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// to be passed by value and is immutable, but be aware that flattening a
5248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// string can potentially alter its shape.  Also be aware that a GC caused by
5249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// something else can alter the shape of a string due to ConsString
5250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// shortcutting.  Keeping these restrictions in mind has proven to be error-
5251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// prone and so we no longer put StringShapes in variables unless there is a
5252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// concrete performance benefit at that particular point in the code.
5253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass StringShape BASE_EMBEDDED {
5254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline explicit StringShape(String* s);
5256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline explicit StringShape(Map* s);
5257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline explicit StringShape(InstanceType t);
5258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsSequential();
5259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsExternal();
5260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsCons();
5261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsExternalAscii();
5262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsExternalTwoByte();
5263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsSequentialAscii();
5264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsSequentialTwoByte();
5265a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsSymbol();
5266a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline StringRepresentationTag representation_tag();
5267a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uint32_t full_representation_tag();
5268a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uint32_t size_tag();
5269a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
5270a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uint32_t type() { return type_; }
5271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void invalidate() { valid_ = false; }
5272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool valid() { return valid_; }
5273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
5274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void invalidate() { }
5275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
5276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t type_;
5278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
5279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_valid() { valid_ = true; }
5280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool valid_;
5281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#else
5282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_valid() { }
5283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
5284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The String abstract class captures JavaScript string values:
5288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
5289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Ecma-262:
5290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//  4.3.16 String Value
5291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//    A string value is a member of the type String and is a finite
5292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//    ordered sequence of zero or more 16-bit unsigned integer values.
5293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
5294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// All string values have a length field.
5295a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass String: public HeapObject {
5296a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5297a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get and set the length of the string.
5298a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int length();
5299a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_length(int value);
5300a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5301d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Get and set the hash field of the string.
5302d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  inline uint32_t hash_field();
5303d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  inline void set_hash_field(uint32_t value);
5304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsAsciiRepresentation();
5306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsTwoByteRepresentation();
5307a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
53089dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // Returns whether this string has ascii chars, i.e. all of them can
53099dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // be ascii encoded.  This might be the case even if the string is
53109dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // two-byte.  Such strings may appear when the embedder prefers
53119dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // two-byte external representations even for ascii data.
53126ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  //
53139dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // NOTE: this should be considered only a hint.  False negatives are
53149dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  // possible.
53159dcf7e2f83591d471e88bf7d230651900b8e424bKristian Monsen  inline bool HasOnlyAsciiChars();
53166ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
5317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get and set individual two byte chars in the string.
5318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void Set(int index, uint16_t value);
5319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get individual two byte char in the string.  Repeated calls
5320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // to this method are not efficient unless the string is flat.
5321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uint16_t Get(int index);
5322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5323f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // Try to flatten the string.  Checks first inline to see if it is
5324f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // necessary.  Does nothing if the string is not a cons string.
5325f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // Flattening allocates a sequential string with the same data as
5326f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // the given string and mutates the cons string to a degenerate
5327f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // form, where the first component is the new sequential string and
5328f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // the second component is the empty string.  If allocation fails,
5329f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // this function returns a failure.  If flattening succeeds, this
5330f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // function returns the sequential string that is now the first
5331f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // component of the cons string.
5332f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  //
5333f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // Degenerate cons strings are handled specially by the garbage
5334f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // collector (see IsShortcutCandidate).
5335f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  //
5336f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // Use FlattenString from Handles.cc to flatten even in case an
5337f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // allocation failure happens.
53385913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED);
5339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5340f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // Convenience function.  Has exactly the same behavior as
5341f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // TryFlatten(), except in the case of failure returns the original
5342f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // string.
5343f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED);
5344f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
5345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Vector<const char> ToAsciiVector();
5346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Vector<const uc16> ToUC16Vector();
5347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Mark the string as an undetectable object. It only applies to
5349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ascii and two byte string types.
5350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool MarkAsUndetectable();
5351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5352d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Return a substring.
53535913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SubString(int from,
53545913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                         int to,
53555913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                         PretenureFlag pretenure = NOT_TENURED);
5356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5357a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // String equality operations.
5358a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool Equals(String* other);
5359a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool IsEqualTo(Vector<const char> str);
53609fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  bool IsAsciiEqualTo(Vector<const char> str);
53619fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  bool IsTwoByteEqualTo(Vector<const uc16> str);
5362a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return a UTF8 representation of the string.  The string is null
5364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // terminated but may optionally contain nulls.  Length is returned
5365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // in length_output if length_output is not a null pointer  The string
5366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // should be nearly flat, otherwise the performance of this method may
5367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // be very slow (quadratic in the length).  Setting robustness_flag to
5368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust  This means it
5369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // handles unexpected data without causing assert failures and it does not
5370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // do any heap allocations.  This is useful when printing stack traces.
5371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  SmartPointer<char> ToCString(AllowNullsFlag allow_nulls,
5372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               RobustnessFlag robustness_flag,
5373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               int offset,
5374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               int length,
5375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                               int* length_output = 0);
5376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  SmartPointer<char> ToCString(
5377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      AllowNullsFlag allow_nulls = DISALLOW_NULLS,
5378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL,
5379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      int* length_output = 0);
5380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int Utf8Length();
5382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Return a 16 bit Unicode representation of the string.
5384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The string should be nearly flat, otherwise the performance of
5385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // of this method may be very bad.  Setting robustness_flag to
5386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust  This means it
5387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // handles unexpected data without causing assert failures and it does not
5388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // do any heap allocations.  This is useful when printing stack traces.
5389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  SmartPointer<uc16> ToWideCString(
5390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL);
5391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Tells whether the hash code has been computed.
5393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool HasHashCode();
5394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Returns a hash value used for the property table
5396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uint32_t Hash();
5397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5398d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static uint32_t ComputeHashField(unibrow::CharacterStream* buffer,
5399d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block                                   int length);
5400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool ComputeArrayIndex(unibrow::CharacterStream* buffer,
5402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                uint32_t* index,
5403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                int length);
5404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5405a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Externalization.
5406a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool MakeExternal(v8::String::ExternalStringResource* resource);
5407a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool MakeExternal(v8::String::ExternalAsciiStringResource* resource);
5408a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5409a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Conversion.
5410a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool AsArrayIndex(uint32_t* index);
5411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
5413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline String* cast(Object* obj);
5414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void PrintOn(FILE* out);
5416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // For use during stack traces.  Performs rudimentary sanity check.
5418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool LooksValid();
5419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
5421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void StringShortPrint(StringStream* accumulator);
5422b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
5423b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void StringPrint() {
5424b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    StringPrint(stdout);
5425b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
5426b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void StringPrint(FILE* out);
5427b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
5428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
5429a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void StringVerify();
5430a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
5431a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool IsFlat();
5432a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5433a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
5434a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLengthOffset = HeapObject::kHeaderSize;
54356ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kHashFieldOffset = kLengthOffset + kPointerSize;
54367f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kSize = kHashFieldOffset + kPointerSize;
5437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5438d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Maximum number of characters to consider when trying to convert a string
5439d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // value into an array index.
5440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxArrayIndexSize = 10;
5441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Max ascii char code.
5443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar;
5444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar;
5445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxUC16CharCode = 0xffff;
5446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5447d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Minimum length for a cons string.
5448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMinNonFlatLength = 13;
5449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Mask constant for checking if a string has a computed hash code
5451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // and if it is an array index.  The least significant bit indicates
5452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // whether a hash code has been computed.  If the hash code has been
5453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // computed the 2nd bit tells whether the string can be used as an
5454a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // array index.
54557f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kHashNotComputedMask = 1;
54567f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kIsNotArrayIndexMask = 1 << 1;
54577f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kNofHashBitFields = 2;
5458a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5459d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Shift constant retrieving hash code from hash field.
54607f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kHashShift = kNofHashBitFields;
5461d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
5462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Array index strings this short can keep their index in the hash
5463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // field.
5464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxCachedArrayIndexLength = 7;
5465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5466d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // For strings which are array indexes the hash value has the string length
5467d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // mixed into the hash, mainly to avoid a hash value of zero which would be
5468d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // the case for the string '0'. 24 bits are used for the array index value.
54697f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kArrayIndexValueBits = 24;
54707f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kArrayIndexLengthBits =
54717f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields;
54727f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
54737f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  STATIC_CHECK((kArrayIndexLengthBits > 0));
54749ac36c9faca11611ada13b4054edbaa0738661d0Iain Merrick  STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits));
54757f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
54767f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kArrayIndexHashLengthShift =
54777f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kArrayIndexValueBits + kNofHashBitFields;
54787f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
5479d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1;
54807f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
54817f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kArrayIndexValueMask =
54827f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      ((1 << kArrayIndexValueBits) - 1) << kHashShift;
54837f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
54847f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we
54857f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // could use a mask to test if the length of string is less than or equal to
54867f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // kMaxCachedArrayIndexLength.
54877f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1));
54887f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
54897f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kContainsCachedArrayIndexMask =
54907f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) |
54917f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kIsNotArrayIndexMask;
5492d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
5493d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Value of empty hash field indicating that the hash is not computed.
54947f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kEmptyHashField =
54957f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch      kIsNotArrayIndexMask | kHashNotComputedMask;
54967f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
54977f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  // Value of hash field containing computed hash equal to zero.
54987f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static const int kZeroHash = kIsNotArrayIndexMask;
5499d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
5500d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Maximal string length.
5501d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static const int kMaxLength = (1 << (32 - 2)) - 1;
5502d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
5503d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Max length for computing hash. For strings longer than this limit the
5504d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // string length is used as the hash value.
5505d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  static const int kMaxHashCalcLength = 16383;
5506a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5507a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Limit for truncation in short printing.
5508a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMaxShortPrintLength = 1024;
5509a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5510a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Support for regular expressions.
5511a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const uc16* GetTwoByteData();
5512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const uc16* GetTwoByteData(unsigned start);
5513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Support for StringInputBuffer
5515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const unibrow::byte* ReadBlock(String* input,
5516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        unibrow::byte* util_buffer,
5517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        unsigned capacity,
5518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        unsigned* remaining,
5519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        unsigned* offset);
5520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const unibrow::byte* ReadBlock(String** input,
5521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        unibrow::byte* util_buffer,
5522a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        unsigned capacity,
5523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        unsigned* remaining,
5524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                        unsigned* offset);
5525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Helper function for flattening strings.
5527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  template <typename sinkchar>
5528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void WriteToFlat(String* source,
5529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                          sinkchar* sink,
5530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                          int from,
5531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                          int to);
5532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
55339fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  static inline bool IsAscii(const char* chars, int length) {
55349fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    const char* limit = chars + length;
55359fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block#ifdef V8_HOST_CAN_READ_UNALIGNED
55369fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    ASSERT(kMaxAsciiCharCode == 0x7F);
55379fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80;
55389fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    while (chars <= limit - sizeof(uintptr_t)) {
55399fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) {
55409fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block        return false;
55419fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      }
55429fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      chars += sizeof(uintptr_t);
55439fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    }
55449fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block#endif
55459fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    while (chars < limit) {
55469fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false;
55479fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      ++chars;
55489fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    }
55499fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    return true;
55509fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  }
55519fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block
55529fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  static inline bool IsAscii(const uc16* chars, int length) {
55539fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    const uc16* limit = chars + length;
55549fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    while (chars < limit) {
55559fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      if (*chars > kMaxAsciiCharCodeU) return false;
55569fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block      ++chars;
55579fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    }
55589fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block    return true;
55599fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block  }
55609fac840a46e8b7e26894f4792ba26dde14c56b04Steve Block
5561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block protected:
5562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class ReadBlockBuffer {
5563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block   public:
5564a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    ReadBlockBuffer(unibrow::byte* util_buffer_,
5565a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                    unsigned cursor_,
5566a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                    unsigned capacity_,
5567a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                    unsigned remaining_) :
5568a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      util_buffer(util_buffer_),
5569a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      cursor(cursor_),
5570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      capacity(capacity_),
5571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      remaining(remaining_) {
5572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
5573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    unibrow::byte* util_buffer;
5574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    unsigned       cursor;
5575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    unsigned       capacity;
5576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    unsigned       remaining;
5577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  };
5578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline const unibrow::byte* ReadBlock(String* input,
5580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               ReadBlockBuffer* buffer,
5581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               unsigned* offset,
5582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                               unsigned max_chars);
5583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void ReadBlockIntoBuffer(String* input,
5584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                  ReadBlockBuffer* buffer,
5585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                  unsigned* offset_ptr,
5586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                  unsigned max_chars);
5587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5589f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // Try to flatten the top level ConsString that is hiding behind this
5590f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // string.  This is a no-op unless the string is a ConsString.  Flatten
5591f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke  // mutates the ConsString and might return a failure.
55925913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure);
5593f7060e27768c550ace7ec48ad8c093466db52dfaLeon Clarke
55947f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch  static inline bool IsHashFieldComputed(uint32_t field);
55957f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch
5596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Slow case of String::Equals.  This implementation works on any strings
5597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // but it is most efficient on strings that are almost flat.
5598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool SlowEquals(String* other);
5599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Slow case of AsArrayIndex.
5601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool SlowAsArrayIndex(uint32_t* index);
5602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Compute and set the hash code.
5604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint32_t ComputeAndSetHash();
5605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(String);
5607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5608a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5609a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5610a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The SeqString abstract class captures sequential string values.
5611a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass SeqString: public String {
5612a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5613a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
5615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline SeqString* cast(Object* obj);
5616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5617a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5618a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString);
5619a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5620a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5621a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5622a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The AsciiString class captures sequential ascii string objects.
5623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Each character in the AsciiString is an ascii character.
5624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass SeqAsciiString: public SeqString {
5625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5626ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  static const bool kHasAsciiEncoding = true;
5627ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke
5628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
5629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uint16_t SeqAsciiStringGet(int index);
5630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SeqAsciiStringSet(int index, uint16_t value);
5631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get the address of the characters in this string.
5633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Address GetCharsAddress();
5634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline char* GetChars();
5636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting
5638a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline SeqAsciiString* cast(Object* obj);
5639a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5640a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Garbage collection support.  This method is called by the
5641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // garbage collector to compute the actual size of an AsciiString
5642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // instance.
5643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int SeqAsciiStringSize(InstanceType instance_type);
5644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5645a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Computes the size for an AsciiString instance of a given length.
5646a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int SizeFor(int length) {
56477f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize);
5648a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
5649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
5651a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeaderSize = String::kSize;
5652a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize);
5653a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5654e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximal memory usage for a single sequential ASCII string.
5655e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMaxSize = 512 * MB;
5656e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximal length of a single sequential ASCII string.
5657e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
5658e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMaxLength = (kMaxSize - kHeaderSize);
5659e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
5660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Support for StringInputBuffer.
5661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
5662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                unsigned* offset,
5663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                unsigned chars);
5664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining,
5665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                      unsigned* offset,
5666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                      unsigned chars);
5667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString);
5670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The TwoByteString class captures sequential unicode string objects.
5674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Each character in the TwoByteString is a two-byte uint16_t.
5675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass SeqTwoByteString: public SeqString {
5676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5677ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  static const bool kHasAsciiEncoding = false;
5678ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke
5679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
5680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uint16_t SeqTwoByteStringGet(int index);
5681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SeqTwoByteStringSet(int index, uint16_t value);
5682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get the address of the characters in this string.
5684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Address GetCharsAddress();
5685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uc16* GetChars();
5687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // For regexp code.
5689a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const uint16_t* SeqTwoByteStringGetData(unsigned start);
5690a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5691a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting
5692a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline SeqTwoByteString* cast(Object* obj);
5693a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5694a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Garbage collection support.  This method is called by the
5695a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // garbage collector to compute the actual size of a TwoByteString
5696a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // instance.
5697a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline int SeqTwoByteStringSize(InstanceType instance_type);
5698a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5699a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Computes the size for a TwoByteString instance of a given length.
5700a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int SizeFor(int length) {
57017f4d5bd8c03935e2c0cd412e561b8fc5a6a880aeBen Murdoch    return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize);
5702a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
5703a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5704a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
5705a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeaderSize = String::kSize;
5706a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize);
5707a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5708e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximal memory usage for a single sequential two-byte string.
5709e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMaxSize = 512 * MB;
5710e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Maximal length of a single sequential two-byte string.
5711e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  // Q.v. String::kMaxLength which is the maximal size of concatenated strings.
5712e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke  static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t);
5713e46be819fca9468a0cd4e74859ce0f778eb8ca60Leon Clarke
5714a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Support for StringInputBuffer.
5715a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
5716a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                  unsigned* offset_ptr,
5717a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                  unsigned chars);
5718a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5719a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5720a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString);
5721a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5722a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5723a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5724a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The ConsString class describes string values built by using the
5725a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// addition operator on strings.  A ConsString is a pair where the
5726a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// first and second components are pointers to other string values.
5727a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// One or both components of a ConsString can be pointers to other
5728a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// ConsStrings, creating a binary tree of ConsStrings where the leaves
5729a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// are non-ConsString string values.  The string value represented by
5730a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// a ConsString can be obtained by concatenating the leaf string
5731a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// values in a left-to-right depth-first traversal of the tree.
5732a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ConsString: public String {
5733a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5734a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // First string of the cons cell.
5735a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline String* first();
5736a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Doesn't check that the result is a string, even in debug mode.  This is
5737a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // useful during GC where the mark bits confuse the checks.
5738a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* unchecked_first();
5739a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_first(String* first,
5740a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                        WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
5741a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5742a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Second string of the cons cell.
5743a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline String* second();
5744a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Doesn't check that the result is a string, even in debug mode.  This is
5745a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // useful during GC where the mark bits confuse the checks.
5746a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Object* unchecked_second();
5747a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_second(String* second,
5748a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                         WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
5749a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5750a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
5751a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint16_t ConsStringGet(int index);
5752a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5753a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
5754a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline ConsString* cast(Object* obj);
5755a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5756a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
5757a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize);
5758a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSecondOffset = kFirstOffset + kPointerSize;
5759a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kSecondOffset + kPointerSize;
5760a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5761a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Support for StringInputBuffer.
5762a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer,
5763a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                  unsigned* offset_ptr,
5764a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                  unsigned chars);
5765a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
5766a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                            unsigned* offset_ptr,
5767a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                            unsigned chars);
5768a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5769a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Minimum length for a cons string.
5770a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kMinLength = 13;
5771a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5772756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize>
5773756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick          BodyDescriptor;
5774756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
5775a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5776a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString);
5777a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5778a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5779a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5780a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The ExternalString class describes string values that are backed by
5781a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// a string resource that lies outside the V8 heap.  ExternalStrings
5782a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// consist of the length field common to all strings, a pointer to the
5783a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// external resource.  It is important to ensure (externally) that the
5784a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// resource is not deallocated while the ExternalString is live in the
5785a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// V8 heap.
5786a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
5787a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The API expects that all ExternalStrings are created through the
5788a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// API.  Therefore, ExternalStrings should not be used internally.
5789a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ExternalString: public String {
5790a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5791a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting
5792a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline ExternalString* cast(Object* obj);
5793a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5794a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
5795a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize);
5796a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kResourceOffset + kPointerSize;
5797a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5798a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset);
5799a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5800a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5801a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString);
5802a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5803a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5804a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5805a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The ExternalAsciiString class is an external string backed by an
5806a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// ASCII string.
5807a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ExternalAsciiString: public ExternalString {
5808a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5809ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  static const bool kHasAsciiEncoding = true;
5810ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke
5811a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef v8::String::ExternalAsciiStringResource Resource;
5812a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5813a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The underlying resource.
5814a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Resource* resource();
5815a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_resource(Resource* buffer);
5816a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5817a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
5818a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint16_t ExternalAsciiStringGet(int index);
5819a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5820a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
5821a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline ExternalAsciiString* cast(Object* obj);
5822a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5823d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Garbage collection support.
5824756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void ExternalAsciiStringIterateBody(ObjectVisitor* v);
5825756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
5826756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  template<typename StaticVisitor>
5827756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void ExternalAsciiStringIterateBody();
5828d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
5829a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Support for StringInputBuffer.
5830a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining,
5831a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                    unsigned* offset,
5832a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                    unsigned chars);
5833a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
5834a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                     unsigned* offset,
5835a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                     unsigned chars);
5836a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5837a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5838a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString);
5839a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5840a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5841a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5842a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The ExternalTwoByteString class is an external string backed by a UTF-16
5843a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// encoded string.
5844a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ExternalTwoByteString: public ExternalString {
5845a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5846ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke  static const bool kHasAsciiEncoding = false;
5847ac95265630a4e0c317a7a7201d17a57df7d9bcceLeon Clarke
5848a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  typedef v8::String::ExternalStringResource Resource;
5849a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5850a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The underlying string resource.
5851a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Resource* resource();
5852a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_resource(Resource* buffer);
5853a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5854a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
5855a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  uint16_t ExternalTwoByteStringGet(int index);
5856a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5857a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // For regexp code.
5858a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const uint16_t* ExternalTwoByteStringGetData(unsigned start);
5859a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5860a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
5861a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline ExternalTwoByteString* cast(Object* obj);
5862a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5863d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Garbage collection support.
5864756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v);
5865756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
5866756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  template<typename StaticVisitor>
5867756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void ExternalTwoByteStringIterateBody();
5868756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
5869d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
5870a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Support for StringInputBuffer.
5871a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer,
5872a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                unsigned* offset_ptr,
5873a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                                unsigned chars);
5874a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5875a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5876a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString);
5877a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5878a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5879a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5880a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Utility superclass for stack-allocated objects that must be updated
5881a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// on gc.  It provides two ways for the gc to update instances, either
5882a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// iterating or updating after gc.
5883a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Relocatable BASE_EMBEDDED {
5884a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
588544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  explicit inline Relocatable(Isolate* isolate);
588644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline virtual ~Relocatable();
5887a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void IterateInstance(ObjectVisitor* v) { }
5888a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void PostGarbageCollection() { }
5889a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5890a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void PostGarbageCollectionProcessing();
5891a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static int ArchiveSpacePerThread();
5892a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static char* ArchiveState(char* to);
5893a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static char* RestoreState(char* from);
5894a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void Iterate(ObjectVisitor* v);
5895a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void Iterate(ObjectVisitor* v, Relocatable* top);
5896a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static char* Iterate(ObjectVisitor* v, char* t);
5897a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
589844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  Isolate* isolate_;
5899a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Relocatable* prev_;
5900a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5901a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5902a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5903a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// A flat string reader provides random access to the contents of a
5904a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// string independent of the character width of the string.  The handle
5905a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// must be valid as long as the reader is being used.
5906a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass FlatStringReader : public Relocatable {
5907a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
590844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  FlatStringReader(Isolate* isolate, Handle<String> str);
590944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  FlatStringReader(Isolate* isolate, Vector<const char> input);
5910a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void PostGarbageCollection();
5911a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline uc32 Get(int index);
5912a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int length() { return length_; }
5913a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5914a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  String** str_;
5915a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool is_ascii_;
5916a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int length_;
5917a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  const void* start_;
5918a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5919a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5920a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5921a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Note that StringInputBuffers are not valid across a GC!  To fix this
5922a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// it would have to store a String Handle instead of a String* and
5923a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// AsciiStringReadBlock would have to be modified to use memcpy.
5924a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
5925a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// StringInputBuffer is able to traverse any string regardless of how
5926a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// deeply nested a sequence of ConsStrings it is made of.  However,
5927a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// performance will be better if deep strings are flattened before they
5928a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// are traversed.  Since flattening requires memory allocation this is
5929a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// not always desirable, however (esp. in debugging situations).
5930a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> {
5931a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5932a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void Seek(unsigned pos);
5933a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {}
59348b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  explicit inline StringInputBuffer(String* backing):
5935a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      unibrow::InputBuffer<String, String*, 1024>(backing) {}
5936a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5937a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5938a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5939a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass SafeStringInputBuffer
5940a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  : public unibrow::InputBuffer<String, String**, 256> {
5941a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5942a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void Seek(unsigned pos);
5943a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline SafeStringInputBuffer()
5944a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : unibrow::InputBuffer<String, String**, 256>() {}
59458b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  explicit inline SafeStringInputBuffer(String** backing)
5946a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      : unibrow::InputBuffer<String, String**, 256>(backing) {}
5947a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5948a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5949a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5950a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blocktemplate <typename T>
5951a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass VectorIterator {
5952a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5953a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { }
5954a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { }
5955a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  T GetNext() { return data_[index_++]; }
5956a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool has_more() { return index_ < data_.length(); }
5957a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
5958a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Vector<const T> data_;
5959a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int index_;
5960a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
5961a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5962a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5963a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The Oddball describes objects null, undefined, true, and false.
5964a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Oddball: public HeapObject {
5965a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
5966a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [to_string]: Cached to_string computed at startup.
5967a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(to_string, String)
5968a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5969a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [to_number]: Cached to_number computed at startup.
5970a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(to_number, Object)
5971a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
597244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline byte kind();
597344f0eee88ff00398ff7f715fab053374d808c90dSteve Block  inline void set_kind(byte kind);
597444f0eee88ff00398ff7f715fab053374d808c90dSteve Block
5975a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
5976a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Oddball* cast(Object* obj);
5977a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5978a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
5979a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
5980a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void OddballVerify();
5981a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
5982a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5983a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Initialize the fields.
59845913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* Initialize(const char* to_string,
598544f0eee88ff00398ff7f715fab053374d808c90dSteve Block                                          Object* to_number,
598644f0eee88ff00398ff7f715fab053374d808c90dSteve Block                                          byte kind);
5987a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
5988a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
5989a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kToStringOffset = HeapObject::kHeaderSize;
5990a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kToNumberOffset = kToStringOffset + kPointerSize;
599144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kKindOffset = kToNumberOffset + kPointerSize;
599244f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const int kSize = kKindOffset + kPointerSize;
599344f0eee88ff00398ff7f715fab053374d808c90dSteve Block
599444f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const byte kFalse = 0;
599544f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const byte kTrue = 1;
599644f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const byte kNotBooleanMask = ~1;
599744f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const byte kTheHole = 2;
599844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const byte kNull = 3;
599944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const byte kArgumentMarker = 4;
600044f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const byte kUndefined = 5;
600144f0eee88ff00398ff7f715fab053374d808c90dSteve Block  static const byte kOther = 6;
6002a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6003756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  typedef FixedBodyDescriptor<kToStringOffset,
6004756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                              kToNumberOffset + kPointerSize,
6005756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                              kSize> BodyDescriptor;
6006756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
6007a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6008a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball);
6009a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6010a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6011a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6012a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSGlobalPropertyCell: public HeapObject {
6013a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6014a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [value]: value of the global property.
6015a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(value, Object)
6016a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6017a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
6018a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline JSGlobalPropertyCell* cast(Object* obj);
6019a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6020a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6021a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSGlobalPropertyCellVerify();
6022b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6023b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6024b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void JSGlobalPropertyCellPrint() {
6025b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    JSGlobalPropertyCellPrint(stdout);
6026b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6027b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void JSGlobalPropertyCellPrint(FILE* out);
6028a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6029a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6030a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
6031a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kValueOffset = HeapObject::kHeaderSize;
6032a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kValueOffset + kPointerSize;
6033a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6034756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  typedef FixedBodyDescriptor<kValueOffset,
6035756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                              kValueOffset + kPointerSize,
6036756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick                              kSize> BodyDescriptor;
6037756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
60388b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  // Returns the isolate/heap this cell object belongs to.
60398b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  inline Isolate* isolate();
60408b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch  inline Heap* heap();
60418b112d2025046f85ef7f6be087c6129c872ebad2Ben Murdoch
6042a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6043a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell);
6044a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6045a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6046a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6047a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6048a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Proxy describes objects pointing from JavaScript to C structures.
6049a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Since they cannot contain references to JS HeapObjects they can be
6050a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// placed in old_data_space.
6051a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass Proxy: public HeapObject {
6052a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6053a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [proxy]: field containing the address.
6054a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline Address proxy();
6055a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_proxy(Address value);
6056a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6057a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
6058a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Proxy* cast(Object* obj);
6059a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6060a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
6061a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void ProxyIterateBody(ObjectVisitor* v);
6062756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
6063756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  template<typename StaticVisitor>
6064756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  inline void ProxyIterateBody();
6065756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
6066b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6067b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ProxyPrint() {
6068b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ProxyPrint(stdout);
6069b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6070b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ProxyPrint(FILE* out);
6071b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6072a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6073a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void ProxyVerify();
6074a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6075a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6076a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
6077a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6078a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kProxyOffset = HeapObject::kHeaderSize;
6079a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kProxyOffset + kPointerSize;
6080a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6081a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  STATIC_CHECK(kProxyOffset == Internals::kProxyProxyOffset);
6082a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6083a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6084a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(Proxy);
6085a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6086a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6087a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6088a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The JSArray describes JavaScript Arrays
6089a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//  Such an array can be in one of two modes:
6090a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//    - fast, backing storage is a FixedArray and length <= elements.length();
6091a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//       Please note: push and pop can be used to grow and shrink the array.
6092a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//    - slow, backing storage is a HashTable with numbers as keys.
6093a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass JSArray: public JSObject {
6094a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6095a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [length]: The length property.
6096a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(length, Object)
6097a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
60984515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // Overload the length setter to skip write barrier when the length
60994515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  // is set to a smi. This matches the set function on FixedArray.
61004515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke  inline void set_length(Smi* length);
61014515c472dc3e5ed2448a564600976759e569a0a8Leon Clarke
61025913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index,
61035913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck                                                            Object* value);
6104a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6105a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Initialize the array with the given capacity. The function may
6106a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // fail due to out-of-memory situations, but only if the requested
6107a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // capacity is non-zero.
61085913587db4c6bab03d97bfe44b06289fd6d7270dJohn Reck  MUST_USE_RESULT MaybeObject* Initialize(int capacity);
6109a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6110a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set the content of the array to the content of storage.
6111a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void SetContent(FixedArray* storage);
6112a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6113a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Casting.
6114a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline JSArray* cast(Object* obj);
6115a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6116a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Uses handles.  Ensures that the fixed array backing the JSArray has at
6117a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // least the stated size.
6118a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void EnsureSize(int minimum_size_of_backing_fixed_array);
6119a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6120a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Dispatched behavior.
6121b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6122b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void JSArrayPrint() {
6123b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    JSArrayPrint(stdout);
6124b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6125b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void JSArrayPrint(FILE* out);
6126b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6127a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6128a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void JSArrayVerify();
6129a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6130a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6131a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Number of element slots to pre-allocate for an empty array.
6132a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPreallocatedArrayElements = 4;
6133a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6134a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Layout description.
6135a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kLengthOffset = JSObject::kHeaderSize;
6136a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kLengthOffset + kPointerSize;
6137a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6138a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6139a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Expand the fixed array backing of a fast-case JSArray to at least
6140a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // the requested size.
6141a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void Expand(int minimum_size_of_backing_fixed_array);
6142a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6143a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray);
6144a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6145a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6146a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
61476ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// JSRegExpResult is just a JSArray with a specific initial map.
61486ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// This initial map adds in-object properties for "index" and "input"
61496ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// properties, as assigned by RegExp.prototype.exec, which allows
61506ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// faster creation of RegExp exec results.
61516ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// This class just holds constants used when creating the result.
61526ded16be15dd865a9b21ea304d5273c8be299c87Steve Block// After creation the result must be treated as a JSArray in all regards.
61536ded16be15dd865a9b21ea304d5273c8be299c87Steve Blockclass JSRegExpResult: public JSArray {
61546ded16be15dd865a9b21ea304d5273c8be299c87Steve Block public:
61556ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Offsets of object fields.
61566ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kIndexOffset = JSArray::kSize;
61576ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kInputOffset = kIndexOffset + kPointerSize;
61586ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kSize = kInputOffset + kPointerSize;
61596ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  // Indices of in-object properties.
61606ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kIndexIndex = 0;
61616ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  static const int kInputIndex = 1;
61626ded16be15dd865a9b21ea304d5273c8be299c87Steve Block private:
61636ded16be15dd865a9b21ea304d5273c8be299c87Steve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult);
61646ded16be15dd865a9b21ea304d5273c8be299c87Steve Block};
61656ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
61666ded16be15dd865a9b21ea304d5273c8be299c87Steve Block
6167a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// An accessor must have a getter, but can have no setter.
6168a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
6169a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// When setting a property, V8 searches accessors in prototypes.
6170a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// If an accessor was found and it does not have a setter,
6171a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// the request is ignored.
6172a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block//
6173a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// If the accessor in the prototype has the READ_ONLY property attribute, then
6174a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// a new value is added to the local object when the property is set.
6175a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// This shadows the accessor in the prototype.
6176a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass AccessorInfo: public Struct {
6177a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6178a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(getter, Object)
6179a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(setter, Object)
6180a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(data, Object)
6181a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(name, Object)
6182a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(flag, Smi)
6183a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6184a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool all_can_read();
6185a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_all_can_read(bool value);
6186a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6187a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool all_can_write();
6188a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_all_can_write(bool value);
6189a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6190a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline bool prohibits_overwriting();
6191a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_prohibits_overwriting(bool value);
6192a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6193a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline PropertyAttributes property_attributes();
6194a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void set_property_attributes(PropertyAttributes attributes);
6195a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6196a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline AccessorInfo* cast(Object* obj);
6197a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6198b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6199b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void AccessorInfoPrint() {
6200b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    AccessorInfoPrint(stdout);
6201b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6202b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void AccessorInfoPrint(FILE* out);
6203b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6204a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6205a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void AccessorInfoVerify();
6206a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6207a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6208a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kGetterOffset = HeapObject::kHeaderSize;
6209a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSetterOffset = kGetterOffset + kPointerSize;
6210a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kDataOffset = kSetterOffset + kPointerSize;
6211a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNameOffset = kDataOffset + kPointerSize;
6212a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFlagOffset = kNameOffset + kPointerSize;
62138a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kSize = kFlagOffset + kPointerSize;
6214a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6215a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6216a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit positions in flag.
6217a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kAllCanReadBit = 0;
6218a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kAllCanWriteBit = 1;
6219a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kProhibitsOverwritingBit = 2;
6220a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
6221a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6222a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo);
6223a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6224a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6225a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6226a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass AccessCheckInfo: public Struct {
6227a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6228a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(named_callback, Object)
6229a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(indexed_callback, Object)
6230a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(data, Object)
6231a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6232a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline AccessCheckInfo* cast(Object* obj);
6233a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6234b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6235b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void AccessCheckInfoPrint() {
6236b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    AccessCheckInfoPrint(stdout);
6237b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6238b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void AccessCheckInfoPrint(FILE* out);
6239b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6240a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6241a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void AccessCheckInfoVerify();
6242a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6243a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6244a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNamedCallbackOffset   = HeapObject::kHeaderSize;
6245a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize;
6246a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kDataOffset = kIndexedCallbackOffset + kPointerSize;
6247a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kDataOffset + kPointerSize;
6248a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6249a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6250a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo);
6251a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6252a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6253a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6254a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass InterceptorInfo: public Struct {
6255a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6256a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(getter, Object)
6257a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(setter, Object)
6258a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(query, Object)
6259a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(deleter, Object)
6260a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(enumerator, Object)
6261a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(data, Object)
6262a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6263a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline InterceptorInfo* cast(Object* obj);
6264a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6265b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6266b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void InterceptorInfoPrint() {
6267b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    InterceptorInfoPrint(stdout);
6268b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6269b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void InterceptorInfoPrint(FILE* out);
6270b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6271a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6272a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void InterceptorInfoVerify();
6273a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6274a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6275a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kGetterOffset = HeapObject::kHeaderSize;
6276a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSetterOffset = kGetterOffset + kPointerSize;
6277a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kQueryOffset = kSetterOffset + kPointerSize;
6278a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kDeleterOffset = kQueryOffset + kPointerSize;
6279a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kEnumeratorOffset = kDeleterOffset + kPointerSize;
6280a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kDataOffset = kEnumeratorOffset + kPointerSize;
6281a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kDataOffset + kPointerSize;
6282a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6283a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6284a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo);
6285a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6286a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6287a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6288a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass CallHandlerInfo: public Struct {
6289a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6290a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(callback, Object)
6291a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(data, Object)
6292a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6293a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline CallHandlerInfo* cast(Object* obj);
6294a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6295b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6296b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void CallHandlerInfoPrint() {
6297b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    CallHandlerInfoPrint(stdout);
6298b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6299b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void CallHandlerInfoPrint(FILE* out);
6300b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6301a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6302a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void CallHandlerInfoVerify();
6303a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6304a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6305a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kCallbackOffset = HeapObject::kHeaderSize;
6306a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kDataOffset = kCallbackOffset + kPointerSize;
63078a31eba00023874d4a1dcdc5f411cc4336776874Shimeng (Simon) Wang  static const int kSize = kDataOffset + kPointerSize;
6308a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6309a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6310a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo);
6311a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6312a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6313a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6314a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass TemplateInfo: public Struct {
6315a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6316a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(tag, Object)
6317a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(property_list, Object)
6318a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6319a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6320a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void TemplateInfoVerify();
6321a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6322a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6323a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kTagOffset          = HeapObject::kHeaderSize;
6324a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPropertyListOffset = kTagOffset + kPointerSize;
6325a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHeaderSize         = kPropertyListOffset + kPointerSize;
6326a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block protected:
6327a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs;
6328a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo);
6329a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6330a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6331a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6332a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass FunctionTemplateInfo: public TemplateInfo {
6333a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6334a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(serial_number, Object)
6335a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(call_code, Object)
6336a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(property_accessors, Object)
6337a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(prototype_template, Object)
6338a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(parent_template, Object)
6339a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(named_property_handler, Object)
6340a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(indexed_property_handler, Object)
6341a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(instance_template, Object)
6342a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(class_name, Object)
6343a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(signature, Object)
6344a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(instance_call_handler, Object)
6345a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(access_check_info, Object)
6346a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(flag, Smi)
6347a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6348a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Following properties use flag bits.
6349a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_BOOLEAN_ACCESSORS(hidden_prototype)
6350a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_BOOLEAN_ACCESSORS(undetectable)
6351a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // If the bit is set, object instances created by this function
6352a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // requires access check.
6353a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_BOOLEAN_ACCESSORS(needs_access_check)
6354a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6355a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline FunctionTemplateInfo* cast(Object* obj);
6356a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6357b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6358b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void FunctionTemplateInfoPrint() {
6359b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    FunctionTemplateInfoPrint(stdout);
6360b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6361b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void FunctionTemplateInfoPrint(FILE* out);
6362b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6363a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6364a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void FunctionTemplateInfoVerify();
6365a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6366a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6367a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSerialNumberOffset = TemplateInfo::kHeaderSize;
6368a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize;
6369a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize;
6370a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPrototypeTemplateOffset =
6371a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kPropertyAccessorsOffset + kPointerSize;
6372a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kParentTemplateOffset =
6373a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kPrototypeTemplateOffset + kPointerSize;
6374a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNamedPropertyHandlerOffset =
6375a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kParentTemplateOffset + kPointerSize;
6376a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kIndexedPropertyHandlerOffset =
6377a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kNamedPropertyHandlerOffset + kPointerSize;
6378a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInstanceTemplateOffset =
6379a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kIndexedPropertyHandlerOffset + kPointerSize;
6380a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize;
6381a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSignatureOffset = kClassNameOffset + kPointerSize;
6382a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize;
6383a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kAccessCheckInfoOffset =
6384a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kInstanceCallHandlerOffset + kPointerSize;
6385a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize;
6386a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kFlagOffset + kPointerSize;
6387a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6388a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6389a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Bit position in the flag, from least significant bit position.
6390a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kHiddenPrototypeBit   = 0;
6391a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kUndetectableBit      = 1;
6392a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNeedsAccessCheckBit  = 2;
6393a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6394a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo);
6395a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6396a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6397a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6398a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ObjectTemplateInfo: public TemplateInfo {
6399a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6400a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(constructor, Object)
6401a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(internal_field_count, Object)
6402a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6403a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline ObjectTemplateInfo* cast(Object* obj);
6404a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6405b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6406b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void ObjectTemplateInfoPrint() {
6407b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    ObjectTemplateInfoPrint(stdout);
6408b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6409b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void ObjectTemplateInfoPrint(FILE* out);
6410b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6411a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6412a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void ObjectTemplateInfoVerify();
6413a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6414a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6415a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kConstructorOffset = TemplateInfo::kHeaderSize;
6416a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kInternalFieldCountOffset =
6417a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kConstructorOffset + kPointerSize;
6418a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kInternalFieldCountOffset + kPointerSize;
6419a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6420a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6421a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6422a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass SignatureInfo: public Struct {
6423a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6424a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(receiver, Object)
6425a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(args, Object)
6426a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6427a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline SignatureInfo* cast(Object* obj);
6428a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6429b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6430b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void SignatureInfoPrint() {
6431b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    SignatureInfoPrint(stdout);
6432b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6433b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void SignatureInfoPrint(FILE* out);
6434b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6435a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6436a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void SignatureInfoVerify();
6437a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6438a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6439a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kReceiverOffset = Struct::kHeaderSize;
6440a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kArgsOffset     = kReceiverOffset + kPointerSize;
6441a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize           = kArgsOffset + kPointerSize;
6442a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6443a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6444a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo);
6445a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6446a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6447a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6448a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass TypeSwitchInfo: public Struct {
6449a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6450a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(types, Object)
6451a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6452a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline TypeSwitchInfo* cast(Object* obj);
6453a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6454b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6455b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void TypeSwitchInfoPrint() {
6456b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    TypeSwitchInfoPrint(stdout);
6457b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6458b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void TypeSwitchInfoPrint(FILE* out);
6459b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6460a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6461a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void TypeSwitchInfoVerify();
6462a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6463a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6464a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kTypesOffset = Struct::kHeaderSize;
6465a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize        = kTypesOffset + kPointerSize;
6466a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6467a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6468a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6469a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef ENABLE_DEBUGGER_SUPPORT
6470a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The DebugInfo class holds additional information for a function being
6471a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// debugged.
6472a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass DebugInfo: public Struct {
6473a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6474a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The shared function info for the source being debugged.
6475a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(shared, SharedFunctionInfo)
6476a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Code object for the original code.
6477a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(original_code, Code)
6478a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Code object for the patched code. This code object is the code object
6479a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // currently active for the function.
6480a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(code, Code)
6481a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Fixed array holding status information for each active break point.
6482a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(break_points, FixedArray)
6483a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6484a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Check if there is a break point at a code position.
6485a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  bool HasBreakPoint(int code_position);
6486a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get the break point info object for a code position.
6487a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* GetBreakPointInfo(int code_position);
6488a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Clear a break point.
6489a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void ClearBreakPoint(Handle<DebugInfo> debug_info,
6490a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                              int code_position,
6491a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                              Handle<Object> break_point_object);
6492a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set a break point.
6493a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position,
6494a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                            int source_position, int statement_position,
6495a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                            Handle<Object> break_point_object);
6496a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get the break point objects for a code position.
6497a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  Object* GetBreakPointObjects(int code_position);
6498a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Find the break point info holding this break point object.
6499a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info,
6500a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                    Handle<Object> break_point_object);
6501a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get the number of break points for this function.
6502a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetBreakPointCount();
6503a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6504a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline DebugInfo* cast(Object* obj);
6505a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6506b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6507b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void DebugInfoPrint() {
6508b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    DebugInfoPrint(stdout);
6509b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6510b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void DebugInfoPrint(FILE* out);
6511b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6512a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6513a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void DebugInfoVerify();
6514a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6515a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6516a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSharedFunctionInfoIndex = Struct::kHeaderSize;
6517a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize;
6518a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize;
6519a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kActiveBreakPointsCountIndex =
6520a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kPatchedCodeIndex + kPointerSize;
6521a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kBreakPointsStateIndex =
6522a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kActiveBreakPointsCountIndex + kPointerSize;
6523a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kBreakPointsStateIndex + kPointerSize;
6524a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6525a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6526a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kNoBreakPointInfo = -1;
6527a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6528a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Lookup the index in the break_points array for a code position.
6529a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetBreakPointInfoIndex(int code_position);
6530a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6531a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo);
6532a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6533a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6534a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6535a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// The BreakPointInfo class holds information for break points set in a
6536a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// function. The DebugInfo object holds a BreakPointInfo object for each code
6537a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// position with one or more break points.
6538a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass BreakPointInfo: public Struct {
6539a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6540a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The position in the code for the break point.
6541a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(code_position, Smi)
6542a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The position in the source for the break position.
6543a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(source_position, Smi)
6544a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // The position in the source for the last statement before this break
6545a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // position.
6546a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(statement_position, Smi)
6547a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // List of related JavaScript break points.
6548a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DECL_ACCESSORS(break_point_objects, Object)
6549a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6550a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Removes a break point.
6551a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void ClearBreakPoint(Handle<BreakPointInfo> info,
6552a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                              Handle<Object> break_point_object);
6553a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Set a break point.
6554a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static void SetBreakPoint(Handle<BreakPointInfo> info,
6555a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                            Handle<Object> break_point_object);
6556a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Check if break point info has this break point object.
6557a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static bool HasBreakPointObject(Handle<BreakPointInfo> info,
6558a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block                                  Handle<Object> break_point_object);
6559a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Get the number of break points for this code position.
6560a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  int GetBreakPointCount();
6561a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6562a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline BreakPointInfo* cast(Object* obj);
6563a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6564b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#ifdef OBJECT_PRINT
6565b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  inline void BreakPointInfoPrint() {
6566b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch    BreakPointInfoPrint(stdout);
6567b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  }
6568b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  void BreakPointInfoPrint(FILE* out);
6569b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch#endif
6570a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6571a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  void BreakPointInfoVerify();
6572a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6573a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6574a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kCodePositionIndex = Struct::kHeaderSize;
6575a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize;
6576a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kStatementPositionIndex =
6577a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kSourcePositionIndex + kPointerSize;
6578a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kBreakPointObjectsIndex =
6579a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      kStatementPositionIndex + kPointerSize;
6580a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static const int kSize = kBreakPointObjectsIndex + kPointerSize;
6581a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6582a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block private:
6583a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo);
6584a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6585a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // ENABLE_DEBUGGER_SUPPORT
6586a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6587a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6588a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef DECL_BOOLEAN_ACCESSORS
6589a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#undef DECL_ACCESSORS
6590a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6591a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6592a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// Abstract base class for visiting, and optionally modifying, the
6593a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// pointers contained in Objects. Used in GC and serialization/deserialization.
6594a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass ObjectVisitor BASE_EMBEDDED {
6595a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6596a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual ~ObjectVisitor() {}
6597a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6598a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Visits a contiguous arrays of pointers in the half-open range
6599a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // [start, end). Any or all of the values may be modified on return.
6600a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void VisitPointers(Object** start, Object** end) = 0;
6601a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6602a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // To allow lazy clearing of inline caches the visitor has
6603a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // a rich interface for iterating over Code objects..
6604a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6605a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Visits a code target in the instruction stream.
6606a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void VisitCodeTarget(RelocInfo* rinfo);
6607a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6608791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  // Visits a code entry in a JS function.
6609791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block  virtual void VisitCodeEntry(Address entry_address);
6610791712a13f1814dd3ab5d1a5ab8ff5dbc476f6d6Steve Block
6611b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  // Visits a global property cell reference in the instruction stream.
6612b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch  virtual void VisitGlobalPropertyCell(RelocInfo* rinfo);
6613b0fe1620dcb4135ac3ab2d66ff93072373911299Ben Murdoch
6614a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Visits a runtime entry in the instruction stream.
6615a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void VisitRuntimeEntry(RelocInfo* rinfo) {}
6616a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6617d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  // Visits the resource of an ASCII or two-byte string.
6618d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  virtual void VisitExternalAsciiString(
6619d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block      v8::String::ExternalAsciiStringResource** resource) {}
6620d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  virtual void VisitExternalTwoByteString(
6621d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block      v8::String::ExternalStringResource** resource) {}
6622d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block
6623a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Visits a debug call target in the instruction stream.
6624a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void VisitDebugTarget(RelocInfo* rinfo);
6625a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6626a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Handy shorthand for visiting a single pointer.
6627a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); }
6628a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6629a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Visits a contiguous arrays of external references (references to the C++
6630a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // heap) in the half-open range [start, end). Any or all of the values
6631a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // may be modified on return.
6632a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void VisitExternalReferences(Address* start, Address* end) {}
6633a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6634a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  inline void VisitExternalReference(Address* p) {
6635a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    VisitExternalReferences(p, p + 1);
6636a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
6637a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
663844f0eee88ff00398ff7f715fab053374d808c90dSteve Block  // Visits a handle that has an embedder-assigned class ID.
663944f0eee88ff00398ff7f715fab053374d808c90dSteve Block  virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {}
664044f0eee88ff00398ff7f715fab053374d808c90dSteve Block
6641a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#ifdef DEBUG
6642a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // Intended for serialization/deserialization checking: insert, or
6643a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  // check for the presence of, a tag at this position in the stream.
6644a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  virtual void Synchronize(const char* tag) {}
6645d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block#else
6646d0582a6c46733687d045e4188a1bcd0123c758a1Steve Block  inline void Synchronize(const char* tag) {}
6647a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif
6648a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6649a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6650a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6651756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrickclass StructBodyDescriptor : public
6652756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  FlexibleBodyDescriptor<HeapObject::kHeaderSize> {
6653756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick public:
6654756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  static inline int SizeOf(Map* map, HeapObject* object) {
6655756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick    return map->instance_size();
6656756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick  }
6657756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick};
6658756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
6659756813857a4c2a4d8ad2e805969d5768d3cf43a0Iain Merrick
6660a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// BooleanBit is a helper class for setting and getting a bit in an
6661a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block// integer or Smi.
6662a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Blockclass BooleanBit : public AllStatic {
6663a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block public:
6664a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool get(Smi* smi, int bit_position) {
6665a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return get(smi->value(), bit_position);
6666a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
6667a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6668a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline bool get(int value, int bit_position) {
6669a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return (value & (1 << bit_position)) != 0;
6670a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
6671a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6672a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline Smi* set(Smi* smi, int bit_position, bool v) {
6673a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return Smi::FromInt(set(smi->value(), bit_position, v));
6674a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
6675a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6676a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  static inline int set(int value, int bit_position, bool v) {
6677a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    if (v) {
6678a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      value |= (1 << bit_position);
6679a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    } else {
6680a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block      value &= ~(1 << bit_position);
6681a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    }
6682a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block    return value;
6683a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block  }
6684a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block};
6685a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6686a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block} }  // namespace v8::internal
6687a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block
6688a7e24c173cf37484693b9abb38e494fa7bd7baebSteve Block#endif  // V8_OBJECTS_H_
6689