kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_OBJECTS_H_ |
| 29 | #define V8_OBJECTS_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 32 | #include "builtins.h" |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 33 | #include "list.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 34 | #include "smart-pointer.h" |
| 35 | #include "unicode-inl.h" |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 36 | #if V8_TARGET_ARCH_ARM |
| 37 | #include "arm/constants-arm.h" |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 38 | #elif V8_TARGET_ARCH_MIPS |
| 39 | #include "mips/constants-mips.h" |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 40 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 41 | |
| 42 | // |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 43 | // Most object types in the V8 JavaScript are described in this file. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | // |
| 45 | // Inheritance hierarchy: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 46 | // - MaybeObject (an object or a failure) |
| 47 | // - Failure (immediate for marking failed operation) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 48 | // - Object |
| 49 | // - Smi (immediate small integer) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 50 | // - HeapObject (superclass for everything allocated in the heap) |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 51 | // - JSReceiver (suitable for property access) |
| 52 | // - JSObject |
| 53 | // - JSArray |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 54 | // - JSWeakMap |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 55 | // - JSRegExp |
| 56 | // - JSFunction |
| 57 | // - GlobalObject |
| 58 | // - JSGlobalObject |
| 59 | // - JSBuiltinsObject |
| 60 | // - JSGlobalProxy |
| 61 | // - JSValue |
| 62 | // - JSMessageObject |
| 63 | // - JSProxy |
| 64 | // - JSFunctionProxy |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 65 | // - ByteArray |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 66 | // - ExternalArray |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 67 | // - ExternalPixelArray |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 68 | // - ExternalByteArray |
| 69 | // - ExternalUnsignedByteArray |
| 70 | // - ExternalShortArray |
| 71 | // - ExternalUnsignedShortArray |
| 72 | // - ExternalIntArray |
| 73 | // - ExternalUnsignedIntArray |
| 74 | // - ExternalFloatArray |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 75 | // - FixedArrayBase |
| 76 | // - FixedArray |
| 77 | // - DescriptorArray |
| 78 | // - HashTable |
| 79 | // - Dictionary |
| 80 | // - SymbolTable |
| 81 | // - CompilationCacheTable |
| 82 | // - CodeCacheHashTable |
| 83 | // - MapCache |
| 84 | // - Context |
| 85 | // - JSFunctionResultCache |
| 86 | // - SerializedScopeInfo |
| 87 | // - FixedDoubleArray |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | // - String |
| 89 | // - SeqString |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 90 | // - SeqAsciiString |
| 91 | // - SeqTwoByteString |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 92 | // - ConsString |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 93 | // - ExternalString |
| 94 | // - ExternalAsciiString |
| 95 | // - ExternalTwoByteString |
| 96 | // - HeapNumber |
| 97 | // - Code |
| 98 | // - Map |
| 99 | // - Oddball |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 100 | // - Foreign |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 101 | // - SharedFunctionInfo |
| 102 | // - Struct |
| 103 | // - AccessorInfo |
| 104 | // - AccessCheckInfo |
| 105 | // - InterceptorInfo |
| 106 | // - CallHandlerInfo |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 107 | // - TemplateInfo |
| 108 | // - FunctionTemplateInfo |
| 109 | // - ObjectTemplateInfo |
| 110 | // - Script |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 111 | // - SignatureInfo |
| 112 | // - TypeSwitchInfo |
| 113 | // - DebugInfo |
| 114 | // - BreakPointInfo |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 115 | // - CodeCache |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 116 | // |
| 117 | // Formats of Object*: |
| 118 | // Smi: [31 bit signed int] 0 |
| 119 | // HeapObject: [32 bit direct pointer] (4 byte aligned) | 01 |
| 120 | // Failure: [30 bit signed int] 11 |
| 121 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 122 | // Ecma-262 3rd 8.6.1 |
| 123 | enum PropertyAttributes { |
| 124 | NONE = v8::None, |
| 125 | READ_ONLY = v8::ReadOnly, |
| 126 | DONT_ENUM = v8::DontEnum, |
| 127 | DONT_DELETE = v8::DontDelete, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 128 | ABSENT = 16 // Used in runtime to indicate a property is absent. |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 129 | // ABSENT can never be stored in or returned from a descriptor's attributes |
| 130 | // bitfield. It is only used as a return value meaning the attributes of |
| 131 | // a non-existent property. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 132 | }; |
| 133 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 134 | namespace v8 { |
| 135 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 136 | |
| 137 | |
| 138 | // PropertyDetails captures type and attributes for a property. |
| 139 | // They are used both in property dictionaries and instance descriptors. |
| 140 | class PropertyDetails BASE_EMBEDDED { |
| 141 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 142 | PropertyDetails(PropertyAttributes attributes, |
| 143 | PropertyType type, |
| 144 | int index = 0) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 145 | ASSERT(type != EXTERNAL_ARRAY_TRANSITION); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 146 | ASSERT(TypeField::is_valid(type)); |
| 147 | ASSERT(AttributesField::is_valid(attributes)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 148 | ASSERT(StorageField::is_valid(index)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 149 | |
| 150 | value_ = TypeField::encode(type) |
| 151 | | AttributesField::encode(attributes) |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 152 | | StorageField::encode(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 153 | |
| 154 | ASSERT(type == this->type()); |
| 155 | ASSERT(attributes == this->attributes()); |
| 156 | ASSERT(index == this->index()); |
| 157 | } |
| 158 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 159 | PropertyDetails(PropertyAttributes attributes, |
| 160 | PropertyType type, |
| 161 | ExternalArrayType array_type) { |
| 162 | ASSERT(type == EXTERNAL_ARRAY_TRANSITION); |
| 163 | ASSERT(TypeField::is_valid(type)); |
| 164 | ASSERT(AttributesField::is_valid(attributes)); |
| 165 | ASSERT(StorageField::is_valid(static_cast<int>(array_type))); |
| 166 | |
| 167 | value_ = TypeField::encode(type) |
| 168 | | AttributesField::encode(attributes) |
| 169 | | StorageField::encode(static_cast<int>(array_type)); |
| 170 | |
| 171 | ASSERT(type == this->type()); |
| 172 | ASSERT(attributes == this->attributes()); |
| 173 | ASSERT(array_type == this->array_type()); |
| 174 | } |
| 175 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 176 | // Conversion for storing details as Object*. |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 177 | explicit inline PropertyDetails(Smi* smi); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 178 | inline Smi* AsSmi(); |
| 179 | |
| 180 | PropertyType type() { return TypeField::decode(value_); } |
| 181 | |
| 182 | bool IsTransition() { |
| 183 | PropertyType t = type(); |
| 184 | ASSERT(t != INTERCEPTOR); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 185 | return t == MAP_TRANSITION || t == CONSTANT_TRANSITION || |
| 186 | t == EXTERNAL_ARRAY_TRANSITION; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 187 | } |
| 188 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 189 | bool IsProperty() { |
| 190 | return type() < FIRST_PHANTOM_PROPERTY_TYPE; |
| 191 | } |
| 192 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 193 | PropertyAttributes attributes() { return AttributesField::decode(value_); } |
| 194 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 195 | int index() { return StorageField::decode(value_); } |
| 196 | |
| 197 | ExternalArrayType array_type() { |
| 198 | ASSERT(type() == EXTERNAL_ARRAY_TRANSITION); |
| 199 | return static_cast<ExternalArrayType>(StorageField::decode(value_)); |
| 200 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 201 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 202 | inline PropertyDetails AsDeleted(); |
| 203 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 204 | static bool IsValidIndex(int index) { |
| 205 | return StorageField::is_valid(index); |
| 206 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 207 | |
| 208 | bool IsReadOnly() { return (attributes() & READ_ONLY) != 0; } |
| 209 | bool IsDontDelete() { return (attributes() & DONT_DELETE) != 0; } |
| 210 | bool IsDontEnum() { return (attributes() & DONT_ENUM) != 0; } |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 211 | bool IsDeleted() { return DeletedField::decode(value_) != 0;} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 212 | |
| 213 | // Bit fields in value_ (type, shift, size). Must be public so the |
| 214 | // constants can be embedded in generated code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 215 | class TypeField: public BitField<PropertyType, 0, 4> {}; |
| 216 | class AttributesField: public BitField<PropertyAttributes, 4, 3> {}; |
| 217 | class DeletedField: public BitField<uint32_t, 7, 1> {}; |
| 218 | class StorageField: public BitField<uint32_t, 8, 32-8> {}; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 219 | |
| 220 | static const int kInitialIndex = 1; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 221 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 222 | private: |
| 223 | uint32_t value_; |
| 224 | }; |
| 225 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 226 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 227 | // Setter that skips the write barrier if mode is SKIP_WRITE_BARRIER. |
| 228 | enum WriteBarrierMode { SKIP_WRITE_BARRIER, UPDATE_WRITE_BARRIER }; |
| 229 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 230 | |
| 231 | // PropertyNormalizationMode is used to specify whether to keep |
| 232 | // inobject properties when normalizing properties of a JSObject. |
| 233 | enum PropertyNormalizationMode { |
| 234 | CLEAR_INOBJECT_PROPERTIES, |
| 235 | KEEP_INOBJECT_PROPERTIES |
| 236 | }; |
| 237 | |
| 238 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 239 | // NormalizedMapSharingMode is used to specify whether a map may be shared |
| 240 | // by different objects with normalized properties. |
| 241 | enum NormalizedMapSharingMode { |
| 242 | UNIQUE_NORMALIZED_MAP, |
| 243 | SHARED_NORMALIZED_MAP |
| 244 | }; |
| 245 | |
| 246 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 247 | // Instance size sentinel for objects of variable size. |
| 248 | static const int kVariableSizeSentinel = 0; |
| 249 | |
| 250 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 251 | // All Maps have a field instance_type containing a InstanceType. |
| 252 | // It describes the type of the instances. |
| 253 | // |
| 254 | // As an example, a JavaScript object is a heap object and its map |
| 255 | // instance_type is JS_OBJECT_TYPE. |
| 256 | // |
| 257 | // The names of the string instance types are intended to systematically |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 258 | // mirror their encoding in the instance_type field of the map. The default |
| 259 | // encoding is considered TWO_BYTE. It is not mentioned in the name. ASCII |
| 260 | // encoding is mentioned explicitly in the name. Likewise, the default |
| 261 | // representation is considered sequential. It is not mentioned in the |
| 262 | // name. The other representations (eg, CONS, EXTERNAL) are explicitly |
| 263 | // mentioned. Finally, the string is either a SYMBOL_TYPE (if it is a |
| 264 | // symbol) or a STRING_TYPE (if it is not a symbol). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 265 | // |
| 266 | // NOTE: The following things are some that depend on the string types having |
| 267 | // instance_types that are less than those of all other types: |
| 268 | // HeapObject::Size, HeapObject::IterateBody, the typeof operator, and |
| 269 | // Object::IsString. |
| 270 | // |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 271 | // NOTE: Everything following JS_VALUE_TYPE is considered a |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 272 | // JSObject for GC purposes. The first four entries here have typeof |
| 273 | // 'object', whereas JS_FUNCTION_TYPE has typeof 'function'. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 274 | #define INSTANCE_TYPE_LIST_ALL(V) \ |
| 275 | V(SYMBOL_TYPE) \ |
| 276 | V(ASCII_SYMBOL_TYPE) \ |
| 277 | V(CONS_SYMBOL_TYPE) \ |
| 278 | V(CONS_ASCII_SYMBOL_TYPE) \ |
| 279 | V(EXTERNAL_SYMBOL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 280 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 281 | V(EXTERNAL_ASCII_SYMBOL_TYPE) \ |
| 282 | V(STRING_TYPE) \ |
| 283 | V(ASCII_STRING_TYPE) \ |
| 284 | V(CONS_STRING_TYPE) \ |
| 285 | V(CONS_ASCII_STRING_TYPE) \ |
| 286 | V(EXTERNAL_STRING_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 287 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 288 | V(EXTERNAL_ASCII_STRING_TYPE) \ |
| 289 | V(PRIVATE_EXTERNAL_ASCII_STRING_TYPE) \ |
| 290 | \ |
| 291 | V(MAP_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 292 | V(CODE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 293 | V(ODDBALL_TYPE) \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 294 | V(JS_GLOBAL_PROPERTY_CELL_TYPE) \ |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 295 | \ |
| 296 | V(HEAP_NUMBER_TYPE) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 297 | V(FOREIGN_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 298 | V(BYTE_ARRAY_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 299 | /* Note: the order of these external array */ \ |
| 300 | /* types is relied upon in */ \ |
| 301 | /* Object::IsExternalArray(). */ \ |
| 302 | V(EXTERNAL_BYTE_ARRAY_TYPE) \ |
| 303 | V(EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) \ |
| 304 | V(EXTERNAL_SHORT_ARRAY_TYPE) \ |
| 305 | V(EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) \ |
| 306 | V(EXTERNAL_INT_ARRAY_TYPE) \ |
| 307 | V(EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) \ |
| 308 | V(EXTERNAL_FLOAT_ARRAY_TYPE) \ |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 309 | V(EXTERNAL_PIXEL_ARRAY_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 310 | V(FILLER_TYPE) \ |
| 311 | \ |
| 312 | V(ACCESSOR_INFO_TYPE) \ |
| 313 | V(ACCESS_CHECK_INFO_TYPE) \ |
| 314 | V(INTERCEPTOR_INFO_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 315 | V(CALL_HANDLER_INFO_TYPE) \ |
| 316 | V(FUNCTION_TEMPLATE_INFO_TYPE) \ |
| 317 | V(OBJECT_TEMPLATE_INFO_TYPE) \ |
| 318 | V(SIGNATURE_INFO_TYPE) \ |
| 319 | V(TYPE_SWITCH_INFO_TYPE) \ |
| 320 | V(SCRIPT_TYPE) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 321 | V(CODE_CACHE_TYPE) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 322 | V(POLYMORPHIC_CODE_CACHE_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 323 | \ |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 324 | V(FIXED_ARRAY_TYPE) \ |
| 325 | V(SHARED_FUNCTION_INFO_TYPE) \ |
| 326 | \ |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 327 | V(JS_MESSAGE_OBJECT_TYPE) \ |
| 328 | \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 329 | V(JS_VALUE_TYPE) \ |
| 330 | V(JS_OBJECT_TYPE) \ |
| 331 | V(JS_CONTEXT_EXTENSION_OBJECT_TYPE) \ |
| 332 | V(JS_GLOBAL_OBJECT_TYPE) \ |
| 333 | V(JS_BUILTINS_OBJECT_TYPE) \ |
| 334 | V(JS_GLOBAL_PROXY_TYPE) \ |
| 335 | V(JS_ARRAY_TYPE) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 336 | V(JS_PROXY_TYPE) \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 337 | V(JS_WEAK_MAP_TYPE) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 338 | V(JS_REGEXP_TYPE) \ |
| 339 | \ |
| 340 | V(JS_FUNCTION_TYPE) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 341 | V(JS_FUNCTION_PROXY_TYPE) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 342 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 343 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 344 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) \ |
| 345 | V(DEBUG_INFO_TYPE) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 346 | V(BREAK_POINT_INFO_TYPE) |
| 347 | #else |
| 348 | #define INSTANCE_TYPE_LIST_DEBUGGER(V) |
| 349 | #endif |
| 350 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 351 | #define INSTANCE_TYPE_LIST(V) \ |
| 352 | INSTANCE_TYPE_LIST_ALL(V) \ |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 353 | INSTANCE_TYPE_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 354 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 355 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 356 | // Since string types are not consecutive, this macro is used to |
| 357 | // iterate over them. |
| 358 | #define STRING_TYPE_LIST(V) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 359 | V(SYMBOL_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 360 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 361 | symbol, \ |
| 362 | Symbol) \ |
| 363 | V(ASCII_SYMBOL_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 364 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 365 | ascii_symbol, \ |
| 366 | AsciiSymbol) \ |
| 367 | V(CONS_SYMBOL_TYPE, \ |
| 368 | ConsString::kSize, \ |
| 369 | cons_symbol, \ |
| 370 | ConsSymbol) \ |
| 371 | V(CONS_ASCII_SYMBOL_TYPE, \ |
| 372 | ConsString::kSize, \ |
| 373 | cons_ascii_symbol, \ |
| 374 | ConsAsciiSymbol) \ |
| 375 | V(EXTERNAL_SYMBOL_TYPE, \ |
| 376 | ExternalTwoByteString::kSize, \ |
| 377 | external_symbol, \ |
| 378 | ExternalSymbol) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 379 | V(EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE, \ |
| 380 | ExternalTwoByteString::kSize, \ |
| 381 | external_symbol_with_ascii_data, \ |
| 382 | ExternalSymbolWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 383 | V(EXTERNAL_ASCII_SYMBOL_TYPE, \ |
| 384 | ExternalAsciiString::kSize, \ |
| 385 | external_ascii_symbol, \ |
| 386 | ExternalAsciiSymbol) \ |
| 387 | V(STRING_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 388 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 389 | string, \ |
| 390 | String) \ |
| 391 | V(ASCII_STRING_TYPE, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 392 | kVariableSizeSentinel, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 393 | ascii_string, \ |
| 394 | AsciiString) \ |
| 395 | V(CONS_STRING_TYPE, \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 396 | ConsString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 397 | cons_string, \ |
| 398 | ConsString) \ |
| 399 | V(CONS_ASCII_STRING_TYPE, \ |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 400 | ConsString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 401 | cons_ascii_string, \ |
| 402 | ConsAsciiString) \ |
| 403 | V(EXTERNAL_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 404 | ExternalTwoByteString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 405 | external_string, \ |
| 406 | ExternalString) \ |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 407 | V(EXTERNAL_STRING_WITH_ASCII_DATA_TYPE, \ |
| 408 | ExternalTwoByteString::kSize, \ |
| 409 | external_string_with_ascii_data, \ |
| 410 | ExternalStringWithAsciiData) \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 411 | V(EXTERNAL_ASCII_STRING_TYPE, \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 412 | ExternalAsciiString::kSize, \ |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 413 | external_ascii_string, \ |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 414 | ExternalAsciiString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 415 | |
| 416 | // A struct is a simple object a set of object-valued fields. Including an |
| 417 | // object type in this causes the compiler to generate most of the boilerplate |
| 418 | // code for the class including allocation and garbage collection routines, |
| 419 | // casts and predicates. All you need to define is the class, methods and |
| 420 | // object verification routines. Easy, no? |
| 421 | // |
| 422 | // Note that for subtle reasons related to the ordering or numerical values of |
| 423 | // type tags, elements in this list have to be added to the INSTANCE_TYPE_LIST |
| 424 | // manually. |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 425 | #define STRUCT_LIST_ALL(V) \ |
| 426 | V(ACCESSOR_INFO, AccessorInfo, accessor_info) \ |
| 427 | V(ACCESS_CHECK_INFO, AccessCheckInfo, access_check_info) \ |
| 428 | V(INTERCEPTOR_INFO, InterceptorInfo, interceptor_info) \ |
| 429 | V(CALL_HANDLER_INFO, CallHandlerInfo, call_handler_info) \ |
| 430 | V(FUNCTION_TEMPLATE_INFO, FunctionTemplateInfo, function_template_info) \ |
| 431 | V(OBJECT_TEMPLATE_INFO, ObjectTemplateInfo, object_template_info) \ |
| 432 | V(SIGNATURE_INFO, SignatureInfo, signature_info) \ |
| 433 | V(TYPE_SWITCH_INFO, TypeSwitchInfo, type_switch_info) \ |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 434 | V(SCRIPT, Script, script) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 435 | V(CODE_CACHE, CodeCache, code_cache) \ |
| 436 | V(POLYMORPHIC_CODE_CACHE, PolymorphicCodeCache, polymorphic_code_cache) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 437 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 438 | #ifdef ENABLE_DEBUGGER_SUPPORT |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 439 | #define STRUCT_LIST_DEBUGGER(V) \ |
| 440 | V(DEBUG_INFO, DebugInfo, debug_info) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 441 | V(BREAK_POINT_INFO, BreakPointInfo, break_point_info) |
| 442 | #else |
| 443 | #define STRUCT_LIST_DEBUGGER(V) |
| 444 | #endif |
| 445 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 446 | #define STRUCT_LIST(V) \ |
| 447 | STRUCT_LIST_ALL(V) \ |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 448 | STRUCT_LIST_DEBUGGER(V) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 449 | |
| 450 | // We use the full 8 bits of the instance_type field to encode heap object |
| 451 | // instance types. The high-order bit (bit 7) is set if the object is not a |
| 452 | // string, and cleared if it is a string. |
| 453 | const uint32_t kIsNotStringMask = 0x80; |
| 454 | const uint32_t kStringTag = 0x0; |
| 455 | const uint32_t kNotStringTag = 0x80; |
| 456 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 457 | // Bit 6 indicates that the object is a symbol (if set) or not (if cleared). |
| 458 | // There are not enough types that the non-string types (with bit 7 set) can |
| 459 | // have bit 6 set too. |
| 460 | const uint32_t kIsSymbolMask = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 461 | const uint32_t kNotSymbolTag = 0x0; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 462 | const uint32_t kSymbolTag = 0x40; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 463 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 464 | // If bit 7 is clear then bit 2 indicates whether the string consists of |
| 465 | // two-byte characters or one-byte characters. |
| 466 | const uint32_t kStringEncodingMask = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 467 | const uint32_t kTwoByteStringTag = 0x0; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 468 | const uint32_t kAsciiStringTag = 0x4; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 469 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 470 | // If bit 7 is clear, the low-order 2 bits indicate the representation |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 471 | // of the string. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 472 | const uint32_t kStringRepresentationMask = 0x03; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 473 | enum StringRepresentationTag { |
| 474 | kSeqStringTag = 0x0, |
| 475 | kConsStringTag = 0x1, |
sgjesse@chromium.org | 82dbbab | 2010-06-02 08:57:44 +0000 | [diff] [blame] | 476 | kExternalStringTag = 0x2 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 477 | }; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 478 | const uint32_t kIsConsStringMask = 0x1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 479 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 480 | // If bit 7 is clear, then bit 3 indicates whether this two-byte |
| 481 | // string actually contains ascii data. |
| 482 | const uint32_t kAsciiDataHintMask = 0x08; |
| 483 | const uint32_t kAsciiDataHintTag = 0x08; |
| 484 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 485 | |
| 486 | // A ConsString with an empty string as the right side is a candidate |
| 487 | // for being shortcut by the garbage collector unless it is a |
| 488 | // symbol. It's not common to have non-flat symbols, so we do not |
| 489 | // shortcut them thereby avoiding turning symbols into strings. See |
| 490 | // heap.cc and mark-compact.cc. |
| 491 | const uint32_t kShortcutTypeMask = |
| 492 | kIsNotStringMask | |
| 493 | kIsSymbolMask | |
| 494 | kStringRepresentationMask; |
| 495 | const uint32_t kShortcutTypeTag = kConsStringTag; |
| 496 | |
| 497 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 498 | enum InstanceType { |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 499 | // String types. |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 500 | SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 501 | ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 502 | CONS_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 503 | CONS_ASCII_SYMBOL_TYPE = kAsciiStringTag | kSymbolTag | kConsStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 504 | EXTERNAL_SYMBOL_TYPE = kTwoByteStringTag | kSymbolTag | kExternalStringTag, |
| 505 | EXTERNAL_SYMBOL_WITH_ASCII_DATA_TYPE = |
| 506 | kTwoByteStringTag | kSymbolTag | kExternalStringTag | kAsciiDataHintTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 507 | EXTERNAL_ASCII_SYMBOL_TYPE = |
| 508 | kAsciiStringTag | kSymbolTag | kExternalStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 509 | STRING_TYPE = kTwoByteStringTag | kSeqStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 510 | ASCII_STRING_TYPE = kAsciiStringTag | kSeqStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 511 | CONS_STRING_TYPE = kTwoByteStringTag | kConsStringTag, |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 512 | CONS_ASCII_STRING_TYPE = kAsciiStringTag | kConsStringTag, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 513 | EXTERNAL_STRING_TYPE = kTwoByteStringTag | kExternalStringTag, |
| 514 | EXTERNAL_STRING_WITH_ASCII_DATA_TYPE = |
| 515 | kTwoByteStringTag | kExternalStringTag | kAsciiDataHintTag, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 516 | // LAST_STRING_TYPE |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 517 | EXTERNAL_ASCII_STRING_TYPE = kAsciiStringTag | kExternalStringTag, |
| 518 | PRIVATE_EXTERNAL_ASCII_STRING_TYPE = EXTERNAL_ASCII_STRING_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 519 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 520 | // Objects allocated in their own spaces (never in new space). |
| 521 | MAP_TYPE = kNotStringTag, // FIRST_NONSTRING_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 522 | CODE_TYPE, |
| 523 | ODDBALL_TYPE, |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 524 | JS_GLOBAL_PROPERTY_CELL_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 525 | |
| 526 | // "Data", objects that cannot contain non-map-word pointers to heap |
| 527 | // objects. |
| 528 | HEAP_NUMBER_TYPE, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 529 | FOREIGN_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 530 | BYTE_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 531 | EXTERNAL_BYTE_ARRAY_TYPE, // FIRST_EXTERNAL_ARRAY_TYPE |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 532 | EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE, |
| 533 | EXTERNAL_SHORT_ARRAY_TYPE, |
| 534 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE, |
| 535 | EXTERNAL_INT_ARRAY_TYPE, |
| 536 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 537 | EXTERNAL_FLOAT_ARRAY_TYPE, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 538 | EXTERNAL_DOUBLE_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 539 | EXTERNAL_PIXEL_ARRAY_TYPE, // LAST_EXTERNAL_ARRAY_TYPE |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 540 | FIXED_DOUBLE_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 541 | FILLER_TYPE, // LAST_DATA_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 542 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 543 | // Structs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 544 | ACCESSOR_INFO_TYPE, |
| 545 | ACCESS_CHECK_INFO_TYPE, |
| 546 | INTERCEPTOR_INFO_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | CALL_HANDLER_INFO_TYPE, |
| 548 | FUNCTION_TEMPLATE_INFO_TYPE, |
| 549 | OBJECT_TEMPLATE_INFO_TYPE, |
| 550 | SIGNATURE_INFO_TYPE, |
| 551 | TYPE_SWITCH_INFO_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 552 | SCRIPT_TYPE, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 553 | CODE_CACHE_TYPE, |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 554 | POLYMORPHIC_CODE_CACHE_TYPE, |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 555 | // The following two instance types are only used when ENABLE_DEBUGGER_SUPPORT |
| 556 | // is defined. However as include/v8.h contain some of the instance type |
| 557 | // constants always having them avoids them getting different numbers |
| 558 | // depending on whether ENABLE_DEBUGGER_SUPPORT is defined or not. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 559 | DEBUG_INFO_TYPE, |
| 560 | BREAK_POINT_INFO_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 561 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 562 | FIXED_ARRAY_TYPE, |
| 563 | SHARED_FUNCTION_INFO_TYPE, |
| 564 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 565 | JS_MESSAGE_OBJECT_TYPE, |
| 566 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 567 | JS_VALUE_TYPE, // FIRST_NON_CALLABLE_OBJECT_TYPE, FIRST_JS_RECEIVER_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 568 | JS_OBJECT_TYPE, |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 569 | JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 570 | JS_GLOBAL_OBJECT_TYPE, |
| 571 | JS_BUILTINS_OBJECT_TYPE, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 572 | JS_GLOBAL_PROXY_TYPE, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 573 | JS_ARRAY_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 574 | JS_PROXY_TYPE, |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 575 | JS_WEAK_MAP_TYPE, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 576 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 577 | JS_REGEXP_TYPE, // LAST_NONCALLABLE_SPEC_OBJECT_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 578 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 579 | JS_FUNCTION_TYPE, // FIRST_CALLABLE_SPEC_OBJECT_TYPE |
| 580 | JS_FUNCTION_PROXY_TYPE, // LAST_CALLABLE_SPEC_OBJECT_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 581 | |
| 582 | // Pseudo-types |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 583 | FIRST_TYPE = 0x0, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 584 | LAST_TYPE = JS_FUNCTION_PROXY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 585 | INVALID_TYPE = FIRST_TYPE - 1, |
| 586 | FIRST_NONSTRING_TYPE = MAP_TYPE, |
| 587 | // Boundaries for testing for an external array. |
| 588 | FIRST_EXTERNAL_ARRAY_TYPE = EXTERNAL_BYTE_ARRAY_TYPE, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 589 | LAST_EXTERNAL_ARRAY_TYPE = EXTERNAL_PIXEL_ARRAY_TYPE, |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 590 | // Boundary for promotion to old data space/old pointer space. |
| 591 | LAST_DATA_TYPE = FILLER_TYPE, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 592 | // Boundary for objects represented as JSReceiver (i.e. JSObject or JSProxy). |
| 593 | // Note that there is no range for JSObject or JSProxy, since their subtypes |
| 594 | // are not continuous in this enum! The enum ranges instead reflect the |
| 595 | // external class names, where proxies are treated as either ordinary objects, |
| 596 | // or functions. |
| 597 | FIRST_JS_RECEIVER_TYPE = JS_VALUE_TYPE, |
| 598 | LAST_JS_RECEIVER_TYPE = LAST_TYPE, |
| 599 | // Boundaries for testing the types for which typeof is "object". |
| 600 | FIRST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_VALUE_TYPE, |
| 601 | LAST_NONCALLABLE_SPEC_OBJECT_TYPE = JS_REGEXP_TYPE, |
| 602 | // Boundaries for testing the types for which typeof is "function". |
| 603 | FIRST_CALLABLE_SPEC_OBJECT_TYPE = JS_FUNCTION_TYPE, |
| 604 | LAST_CALLABLE_SPEC_OBJECT_TYPE = JS_FUNCTION_PROXY_TYPE, |
| 605 | // Boundaries for testing whether the type is a JavaScript object. |
| 606 | FIRST_SPEC_OBJECT_TYPE = FIRST_NONCALLABLE_SPEC_OBJECT_TYPE, |
| 607 | LAST_SPEC_OBJECT_TYPE = LAST_CALLABLE_SPEC_OBJECT_TYPE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 608 | }; |
| 609 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 610 | static const int kExternalArrayTypeCount = LAST_EXTERNAL_ARRAY_TYPE - |
| 611 | FIRST_EXTERNAL_ARRAY_TYPE + 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 612 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 613 | STATIC_CHECK(JS_OBJECT_TYPE == Internals::kJSObjectType); |
| 614 | STATIC_CHECK(FIRST_NONSTRING_TYPE == Internals::kFirstNonstringType); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 615 | STATIC_CHECK(FOREIGN_TYPE == Internals::kForeignType); |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 616 | |
| 617 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 618 | enum CompareResult { |
| 619 | LESS = -1, |
| 620 | EQUAL = 0, |
| 621 | GREATER = 1, |
| 622 | |
| 623 | NOT_EQUAL = GREATER |
| 624 | }; |
| 625 | |
| 626 | |
| 627 | #define DECL_BOOLEAN_ACCESSORS(name) \ |
| 628 | inline bool name(); \ |
| 629 | inline void set_##name(bool value); \ |
| 630 | |
| 631 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 632 | #define DECL_ACCESSORS(name, type) \ |
| 633 | inline type* name(); \ |
| 634 | inline void set_##name(type* value, \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 635 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 636 | |
| 637 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 638 | class ElementsAccessor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 639 | class StringStream; |
| 640 | class ObjectVisitor; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 641 | class DictionaryElementsAccessor; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 642 | |
| 643 | struct ValueInfo : public Malloced { |
| 644 | ValueInfo() : type(FIRST_TYPE), ptr(NULL), str(NULL), number(0) { } |
| 645 | InstanceType type; |
| 646 | Object* ptr; |
| 647 | const char* str; |
| 648 | double number; |
| 649 | }; |
| 650 | |
| 651 | |
| 652 | // A template-ized version of the IsXXX functions. |
| 653 | template <class C> static inline bool Is(Object* obj); |
| 654 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 655 | class Failure; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 656 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 657 | class MaybeObject BASE_EMBEDDED { |
| 658 | public: |
| 659 | inline bool IsFailure(); |
| 660 | inline bool IsRetryAfterGC(); |
| 661 | inline bool IsOutOfMemory(); |
| 662 | inline bool IsException(); |
| 663 | INLINE(bool IsTheHole()); |
| 664 | inline bool ToObject(Object** obj) { |
| 665 | if (IsFailure()) return false; |
| 666 | *obj = reinterpret_cast<Object*>(this); |
| 667 | return true; |
| 668 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 669 | inline Failure* ToFailureUnchecked() { |
| 670 | ASSERT(IsFailure()); |
| 671 | return reinterpret_cast<Failure*>(this); |
| 672 | } |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 673 | inline Object* ToObjectUnchecked() { |
| 674 | ASSERT(!IsFailure()); |
| 675 | return reinterpret_cast<Object*>(this); |
| 676 | } |
| 677 | inline Object* ToObjectChecked() { |
| 678 | CHECK(!IsFailure()); |
| 679 | return reinterpret_cast<Object*>(this); |
| 680 | } |
| 681 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 682 | template<typename T> |
| 683 | inline bool To(T** obj) { |
| 684 | if (IsFailure()) return false; |
| 685 | *obj = T::cast(reinterpret_cast<Object*>(this)); |
| 686 | return true; |
| 687 | } |
| 688 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 689 | #ifdef OBJECT_PRINT |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 690 | // Prints this object with details. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 691 | inline void Print() { |
| 692 | Print(stdout); |
| 693 | }; |
| 694 | inline void PrintLn() { |
| 695 | PrintLn(stdout); |
| 696 | } |
| 697 | void Print(FILE* out); |
| 698 | void PrintLn(FILE* out); |
| 699 | #endif |
| 700 | #ifdef DEBUG |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 701 | // Verifies the object. |
| 702 | void Verify(); |
| 703 | #endif |
| 704 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 705 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 706 | |
| 707 | #define OBJECT_TYPE_LIST(V) \ |
| 708 | V(Smi) \ |
| 709 | V(HeapObject) \ |
| 710 | V(Number) \ |
| 711 | |
| 712 | #define HEAP_OBJECT_TYPE_LIST(V) \ |
| 713 | V(HeapNumber) \ |
| 714 | V(String) \ |
| 715 | V(Symbol) \ |
| 716 | V(SeqString) \ |
| 717 | V(ExternalString) \ |
| 718 | V(ConsString) \ |
| 719 | V(ExternalTwoByteString) \ |
| 720 | V(ExternalAsciiString) \ |
| 721 | V(SeqTwoByteString) \ |
| 722 | V(SeqAsciiString) \ |
| 723 | \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 724 | V(ExternalArray) \ |
| 725 | V(ExternalByteArray) \ |
| 726 | V(ExternalUnsignedByteArray) \ |
| 727 | V(ExternalShortArray) \ |
| 728 | V(ExternalUnsignedShortArray) \ |
| 729 | V(ExternalIntArray) \ |
| 730 | V(ExternalUnsignedIntArray) \ |
| 731 | V(ExternalFloatArray) \ |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 732 | V(ExternalDoubleArray) \ |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 733 | V(ExternalPixelArray) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 734 | V(ByteArray) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 735 | V(JSReceiver) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 736 | V(JSObject) \ |
| 737 | V(JSContextExtensionObject) \ |
| 738 | V(Map) \ |
| 739 | V(DescriptorArray) \ |
| 740 | V(DeoptimizationInputData) \ |
| 741 | V(DeoptimizationOutputData) \ |
| 742 | V(FixedArray) \ |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 743 | V(FixedDoubleArray) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 744 | V(Context) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 745 | V(GlobalContext) \ |
| 746 | V(JSFunction) \ |
| 747 | V(Code) \ |
| 748 | V(Oddball) \ |
| 749 | V(SharedFunctionInfo) \ |
| 750 | V(JSValue) \ |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 751 | V(JSMessageObject) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 752 | V(StringWrapper) \ |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 753 | V(Foreign) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 754 | V(Boolean) \ |
| 755 | V(JSArray) \ |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 756 | V(JSProxy) \ |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 757 | V(JSFunctionProxy) \ |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 758 | V(JSWeakMap) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 759 | V(JSRegExp) \ |
| 760 | V(HashTable) \ |
| 761 | V(Dictionary) \ |
| 762 | V(SymbolTable) \ |
| 763 | V(JSFunctionResultCache) \ |
| 764 | V(NormalizedMapCache) \ |
| 765 | V(CompilationCacheTable) \ |
| 766 | V(CodeCacheHashTable) \ |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 767 | V(PolymorphicCodeCacheHashTable) \ |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 768 | V(MapCache) \ |
| 769 | V(Primitive) \ |
| 770 | V(GlobalObject) \ |
| 771 | V(JSGlobalObject) \ |
| 772 | V(JSBuiltinsObject) \ |
| 773 | V(JSGlobalProxy) \ |
| 774 | V(UndetectableObject) \ |
| 775 | V(AccessCheckNeeded) \ |
| 776 | V(JSGlobalPropertyCell) \ |
| 777 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 778 | // Object is the abstract superclass for all classes in the |
| 779 | // object hierarchy. |
| 780 | // Object does not use any virtual functions to avoid the |
| 781 | // allocation of the C++ vtable. |
| 782 | // Since Smi and Failure are subclasses of Object no |
| 783 | // data members can be present in Object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 784 | class Object : public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 785 | public: |
| 786 | // Type testing. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 787 | #define IS_TYPE_FUNCTION_DECL(type_) inline bool Is##type_(); |
| 788 | OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 789 | HEAP_OBJECT_TYPE_LIST(IS_TYPE_FUNCTION_DECL) |
| 790 | #undef IS_TYPE_FUNCTION_DECL |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 791 | |
| 792 | // Returns true if this object is an instance of the specified |
| 793 | // function template. |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 794 | inline bool IsInstanceOf(FunctionTemplateInfo* type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 795 | |
| 796 | inline bool IsStruct(); |
| 797 | #define DECLARE_STRUCT_PREDICATE(NAME, Name, name) inline bool Is##Name(); |
| 798 | STRUCT_LIST(DECLARE_STRUCT_PREDICATE) |
| 799 | #undef DECLARE_STRUCT_PREDICATE |
| 800 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 801 | INLINE(bool IsSpecObject()); |
| 802 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 803 | // Oddball testing. |
| 804 | INLINE(bool IsUndefined()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 805 | INLINE(bool IsNull()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 806 | INLINE(bool IsTheHole()); // Shadows MaybeObject's implementation. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 807 | INLINE(bool IsTrue()); |
| 808 | INLINE(bool IsFalse()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 809 | inline bool IsArgumentsMarker(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 810 | |
| 811 | // Extract the number. |
| 812 | inline double Number(); |
| 813 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 814 | // Returns true if the object is of the correct type to be used as a |
| 815 | // implementation of a JSObject's elements. |
| 816 | inline bool HasValidElements(); |
| 817 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 818 | inline bool HasSpecificClassOf(String* name); |
| 819 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 820 | MUST_USE_RESULT MaybeObject* ToObject(); // ECMA-262 9.9. |
| 821 | Object* ToBoolean(); // ECMA-262 9.2. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 822 | |
| 823 | // Convert to a JSObject if needed. |
| 824 | // global_context is used when creating wrapper object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 825 | MUST_USE_RESULT MaybeObject* ToObject(Context* global_context); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 826 | |
| 827 | // Converts this to a Smi if possible. |
| 828 | // Failure is returned otherwise. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 829 | MUST_USE_RESULT inline MaybeObject* ToSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 830 | |
| 831 | void Lookup(String* name, LookupResult* result); |
| 832 | |
| 833 | // Property access. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 834 | MUST_USE_RESULT inline MaybeObject* GetProperty(String* key); |
| 835 | MUST_USE_RESULT inline MaybeObject* GetProperty( |
| 836 | String* key, |
| 837 | PropertyAttributes* attributes); |
| 838 | MUST_USE_RESULT MaybeObject* GetPropertyWithReceiver( |
| 839 | Object* receiver, |
| 840 | String* key, |
| 841 | PropertyAttributes* attributes); |
| 842 | MUST_USE_RESULT MaybeObject* GetProperty(Object* receiver, |
| 843 | LookupResult* result, |
| 844 | String* key, |
| 845 | PropertyAttributes* attributes); |
| 846 | MUST_USE_RESULT MaybeObject* GetPropertyWithCallback(Object* receiver, |
| 847 | Object* structure, |
| 848 | String* name, |
| 849 | Object* holder); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 850 | MUST_USE_RESULT MaybeObject* GetPropertyWithHandler(Object* receiver, |
| 851 | String* name, |
| 852 | Object* handler); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 853 | MUST_USE_RESULT MaybeObject* GetPropertyWithDefinedGetter(Object* receiver, |
| 854 | JSFunction* getter); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 855 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 856 | inline MaybeObject* GetElement(uint32_t index); |
| 857 | // For use when we know that no exception can be thrown. |
| 858 | inline Object* GetElementNoExceptionThrown(uint32_t index); |
| 859 | MaybeObject* GetElementWithReceiver(Object* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 860 | |
| 861 | // Return the object's prototype (might be Heap::null_value()). |
| 862 | Object* GetPrototype(); |
| 863 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 864 | // Tries to convert an object to an array index. Returns true and sets |
| 865 | // the output parameter if it succeeds. |
| 866 | inline bool ToArrayIndex(uint32_t* index); |
| 867 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 868 | // Returns true if this is a JSValue containing a string and the index is |
| 869 | // < the length of the string. Used to implement [] on strings. |
| 870 | inline bool IsStringObjectWithCharacterAt(uint32_t index); |
| 871 | |
| 872 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 873 | // Verify a pointer is a valid object pointer. |
| 874 | static void VerifyPointer(Object* p); |
| 875 | #endif |
| 876 | |
| 877 | // Prints this object without details. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 878 | inline void ShortPrint() { |
| 879 | ShortPrint(stdout); |
| 880 | } |
| 881 | void ShortPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 882 | |
| 883 | // Prints this object without details to a message accumulator. |
| 884 | void ShortPrint(StringStream* accumulator); |
| 885 | |
| 886 | // Casting: This cast is only needed to satisfy macros in objects-inl.h. |
| 887 | static Object* cast(Object* value) { return value; } |
| 888 | |
| 889 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 890 | static const int kHeaderSize = 0; // Object does not take up any space. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 891 | |
| 892 | private: |
| 893 | DISALLOW_IMPLICIT_CONSTRUCTORS(Object); |
| 894 | }; |
| 895 | |
| 896 | |
| 897 | // Smi represents integer Numbers that can be stored in 31 bits. |
| 898 | // Smis are immediate which means they are NOT allocated in the heap. |
ager@chromium.org | 4af710e | 2009-09-15 12:20:11 +0000 | [diff] [blame] | 899 | // The this pointer has the following format: [31 bit signed int] 0 |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 900 | // For long smis it has the following format: |
| 901 | // [32 bit signed int] [31 bits zero padding] 0 |
| 902 | // Smi stands for small integer. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 903 | class Smi: public Object { |
| 904 | public: |
| 905 | // Returns the integer value. |
| 906 | inline int value(); |
| 907 | |
| 908 | // Convert a value to a Smi object. |
| 909 | static inline Smi* FromInt(int value); |
| 910 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 911 | static inline Smi* FromIntptr(intptr_t value); |
| 912 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 913 | // Returns whether value can be represented in a Smi. |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 914 | static inline bool IsValid(intptr_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 915 | |
| 916 | // Casting. |
| 917 | static inline Smi* cast(Object* object); |
| 918 | |
| 919 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 920 | inline void SmiPrint() { |
| 921 | SmiPrint(stdout); |
| 922 | } |
| 923 | void SmiPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 924 | void SmiPrint(StringStream* accumulator); |
| 925 | #ifdef DEBUG |
| 926 | void SmiVerify(); |
| 927 | #endif |
| 928 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 929 | static const int kMinValue = (-1 << (kSmiValueSize - 1)); |
| 930 | static const int kMaxValue = -(kMinValue + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 931 | |
| 932 | private: |
| 933 | DISALLOW_IMPLICIT_CONSTRUCTORS(Smi); |
| 934 | }; |
| 935 | |
| 936 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 937 | // Failure is used for reporting out of memory situations and |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 938 | // propagating exceptions through the runtime system. Failure objects |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 939 | // are transient and cannot occur as part of the object graph. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 940 | // |
| 941 | // Failures are a single word, encoded as follows: |
| 942 | // +-------------------------+---+--+--+ |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 943 | // |.........unused..........|sss|tt|11| |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 944 | // +-------------------------+---+--+--+ |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 945 | // 7 6 4 32 10 |
| 946 | // |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 947 | // |
| 948 | // The low two bits, 0-1, are the failure tag, 11. The next two bits, |
| 949 | // 2-3, are a failure type tag 'tt' with possible values: |
| 950 | // 00 RETRY_AFTER_GC |
| 951 | // 01 EXCEPTION |
| 952 | // 10 INTERNAL_ERROR |
| 953 | // 11 OUT_OF_MEMORY_EXCEPTION |
| 954 | // |
| 955 | // The next three bits, 4-6, are an allocation space tag 'sss'. The |
| 956 | // allocation space tag is 000 for all failure types except |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 957 | // RETRY_AFTER_GC. For RETRY_AFTER_GC, the possible values are the |
| 958 | // allocation spaces (the encoding is found in globals.h). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 959 | |
| 960 | // Failure type tag info. |
| 961 | const int kFailureTypeTagSize = 2; |
| 962 | const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; |
| 963 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 964 | class Failure: public MaybeObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 965 | public: |
| 966 | // RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code. |
| 967 | enum Type { |
| 968 | RETRY_AFTER_GC = 0, |
| 969 | EXCEPTION = 1, // Returning this marker tells the real exception |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 970 | // is in Isolate::pending_exception. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 971 | INTERNAL_ERROR = 2, |
| 972 | OUT_OF_MEMORY_EXCEPTION = 3 |
| 973 | }; |
| 974 | |
| 975 | inline Type type() const; |
| 976 | |
| 977 | // Returns the space that needs to be collected for RetryAfterGC failures. |
| 978 | inline AllocationSpace allocation_space() const; |
| 979 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 980 | inline bool IsInternalError() const; |
| 981 | inline bool IsOutOfMemoryException() const; |
| 982 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 983 | static inline Failure* RetryAfterGC(AllocationSpace space); |
| 984 | static inline Failure* RetryAfterGC(); // NEW_SPACE |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 985 | static inline Failure* Exception(); |
| 986 | static inline Failure* InternalError(); |
| 987 | static inline Failure* OutOfMemoryException(); |
| 988 | // Casting. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 989 | static inline Failure* cast(MaybeObject* object); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 990 | |
| 991 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 992 | inline void FailurePrint() { |
| 993 | FailurePrint(stdout); |
| 994 | } |
| 995 | void FailurePrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 996 | void FailurePrint(StringStream* accumulator); |
| 997 | #ifdef DEBUG |
| 998 | void FailureVerify(); |
| 999 | #endif |
| 1000 | |
| 1001 | private: |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1002 | inline intptr_t value() const; |
| 1003 | static inline Failure* Construct(Type type, intptr_t value = 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1004 | |
| 1005 | DISALLOW_IMPLICIT_CONSTRUCTORS(Failure); |
| 1006 | }; |
| 1007 | |
| 1008 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1009 | // Heap objects typically have a map pointer in their first word. However, |
| 1010 | // during GC other data (eg, mark bits, forwarding addresses) is sometimes |
| 1011 | // encoded in the first word. The class MapWord is an abstraction of the |
| 1012 | // value in a heap object's first word. |
| 1013 | class MapWord BASE_EMBEDDED { |
| 1014 | public: |
| 1015 | // Normal state: the map word contains a map pointer. |
| 1016 | |
| 1017 | // Create a map word from a map pointer. |
| 1018 | static inline MapWord FromMap(Map* map); |
| 1019 | |
| 1020 | // View this map word as a map pointer. |
| 1021 | inline Map* ToMap(); |
| 1022 | |
| 1023 | |
| 1024 | // Scavenge collection: the map word of live objects in the from space |
| 1025 | // contains a forwarding address (a heap object pointer in the to space). |
| 1026 | |
| 1027 | // True if this map word is a forwarding address for a scavenge |
| 1028 | // collection. Only valid during a scavenge collection (specifically, |
| 1029 | // when all map words are heap object pointers, ie. not during a full GC). |
| 1030 | inline bool IsForwardingAddress(); |
| 1031 | |
| 1032 | // Create a map word from a forwarding address. |
| 1033 | static inline MapWord FromForwardingAddress(HeapObject* object); |
| 1034 | |
| 1035 | // View this map word as a forwarding address. |
| 1036 | inline HeapObject* ToForwardingAddress(); |
| 1037 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1038 | // Marking phase of full collection: the map word of live objects is |
| 1039 | // marked, and may be marked as overflowed (eg, the object is live, its |
| 1040 | // children have not been visited, and it does not fit in the marking |
| 1041 | // stack). |
| 1042 | |
| 1043 | // True if this map word's mark bit is set. |
| 1044 | inline bool IsMarked(); |
| 1045 | |
| 1046 | // Return this map word but with its mark bit set. |
| 1047 | inline void SetMark(); |
| 1048 | |
| 1049 | // Return this map word but with its mark bit cleared. |
| 1050 | inline void ClearMark(); |
| 1051 | |
| 1052 | // True if this map word's overflow bit is set. |
| 1053 | inline bool IsOverflowed(); |
| 1054 | |
| 1055 | // Return this map word but with its overflow bit set. |
| 1056 | inline void SetOverflow(); |
| 1057 | |
| 1058 | // Return this map word but with its overflow bit cleared. |
| 1059 | inline void ClearOverflow(); |
| 1060 | |
| 1061 | |
| 1062 | // Compacting phase of a full compacting collection: the map word of live |
| 1063 | // objects contains an encoding of the original map address along with the |
| 1064 | // forwarding address (represented as an offset from the first live object |
| 1065 | // in the same page as the (old) object address). |
| 1066 | |
| 1067 | // Create a map word from a map address and a forwarding address offset. |
| 1068 | static inline MapWord EncodeAddress(Address map_address, int offset); |
| 1069 | |
| 1070 | // Return the map address encoded in this map word. |
| 1071 | inline Address DecodeMapAddress(MapSpace* map_space); |
| 1072 | |
| 1073 | // Return the forwarding offset encoded in this map word. |
| 1074 | inline int DecodeOffset(); |
| 1075 | |
| 1076 | |
| 1077 | // During serialization: the map word is used to hold an encoded |
| 1078 | // address, and possibly a mark bit (set and cleared with SetMark |
| 1079 | // and ClearMark). |
| 1080 | |
| 1081 | // Create a map word from an encoded address. |
| 1082 | static inline MapWord FromEncodedAddress(Address address); |
| 1083 | |
| 1084 | inline Address ToEncodedAddress(); |
| 1085 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1086 | // Bits used by the marking phase of the garbage collector. |
| 1087 | // |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 1088 | // The first word of a heap object is normally a map pointer. The last two |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1089 | // bits are tagged as '01' (kHeapObjectTag). We reuse the last two bits to |
| 1090 | // mark an object as live and/or overflowed: |
| 1091 | // last bit = 0, marked as alive |
| 1092 | // second bit = 1, overflowed |
| 1093 | // An object is only marked as overflowed when it is marked as live while |
| 1094 | // the marking stack is overflowed. |
| 1095 | static const int kMarkingBit = 0; // marking bit |
| 1096 | static const int kMarkingMask = (1 << kMarkingBit); // marking mask |
| 1097 | static const int kOverflowBit = 1; // overflow bit |
| 1098 | static const int kOverflowMask = (1 << kOverflowBit); // overflow mask |
| 1099 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1100 | // Forwarding pointers and map pointer encoding. On 32 bit all the bits are |
| 1101 | // used. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1102 | // +-----------------+------------------+-----------------+ |
| 1103 | // |forwarding offset|page offset of map|page index of map| |
| 1104 | // +-----------------+------------------+-----------------+ |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1105 | // ^ ^ ^ |
| 1106 | // | | | |
| 1107 | // | | kMapPageIndexBits |
| 1108 | // | kMapPageOffsetBits |
| 1109 | // kForwardingOffsetBits |
| 1110 | static const int kMapPageOffsetBits = kPageSizeBits - kMapAlignmentBits; |
| 1111 | static const int kForwardingOffsetBits = kPageSizeBits - kObjectAlignmentBits; |
| 1112 | #ifdef V8_HOST_ARCH_64_BIT |
| 1113 | static const int kMapPageIndexBits = 16; |
| 1114 | #else |
| 1115 | // Use all the 32-bits to encode on a 32-bit platform. |
| 1116 | static const int kMapPageIndexBits = |
| 1117 | 32 - (kMapPageOffsetBits + kForwardingOffsetBits); |
| 1118 | #endif |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1119 | |
| 1120 | static const int kMapPageIndexShift = 0; |
| 1121 | static const int kMapPageOffsetShift = |
| 1122 | kMapPageIndexShift + kMapPageIndexBits; |
| 1123 | static const int kForwardingOffsetShift = |
| 1124 | kMapPageOffsetShift + kMapPageOffsetBits; |
| 1125 | |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1126 | // Bit masks covering the different parts the encoding. |
| 1127 | static const uintptr_t kMapPageIndexMask = |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1128 | (1 << kMapPageOffsetShift) - 1; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1129 | static const uintptr_t kMapPageOffsetMask = |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1130 | ((1 << kForwardingOffsetShift) - 1) & ~kMapPageIndexMask; |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 1131 | static const uintptr_t kForwardingOffsetMask = |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1132 | ~(kMapPageIndexMask | kMapPageOffsetMask); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1133 | |
| 1134 | private: |
| 1135 | // HeapObject calls the private constructor and directly reads the value. |
| 1136 | friend class HeapObject; |
| 1137 | |
| 1138 | explicit MapWord(uintptr_t value) : value_(value) {} |
| 1139 | |
| 1140 | uintptr_t value_; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1141 | }; |
| 1142 | |
| 1143 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1144 | // HeapObject is the superclass for all classes describing heap allocated |
| 1145 | // objects. |
| 1146 | class HeapObject: public Object { |
| 1147 | public: |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1148 | // [map]: Contains a map which contains the object's reflective |
| 1149 | // information. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1150 | inline Map* map(); |
| 1151 | inline void set_map(Map* value); |
| 1152 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1153 | // During garbage collection, the map word of a heap object does not |
| 1154 | // necessarily contain a map pointer. |
| 1155 | inline MapWord map_word(); |
| 1156 | inline void set_map_word(MapWord map_word); |
| 1157 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1158 | // The Heap the object was allocated in. Used also to access Isolate. |
| 1159 | // This method can not be used during GC, it ASSERTs this. |
| 1160 | inline Heap* GetHeap(); |
| 1161 | // Convenience method to get current isolate. This method can be |
| 1162 | // accessed only when its result is the same as |
| 1163 | // Isolate::Current(), it ASSERTs this. See also comment for GetHeap. |
| 1164 | inline Isolate* GetIsolate(); |
| 1165 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1166 | // Converts an address to a HeapObject pointer. |
| 1167 | static inline HeapObject* FromAddress(Address address); |
| 1168 | |
| 1169 | // Returns the address of this HeapObject. |
| 1170 | inline Address address(); |
| 1171 | |
| 1172 | // Iterates over pointers contained in the object (including the Map) |
| 1173 | void Iterate(ObjectVisitor* v); |
| 1174 | |
| 1175 | // Iterates over all pointers contained in the object except the |
| 1176 | // first map pointer. The object type is given in the first |
| 1177 | // parameter. This function does not access the map pointer in the |
| 1178 | // object, and so is safe to call while the map pointer is modified. |
| 1179 | void IterateBody(InstanceType type, int object_size, ObjectVisitor* v); |
| 1180 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1181 | // Returns the heap object's size in bytes |
| 1182 | inline int Size(); |
| 1183 | |
| 1184 | // Given a heap object's map pointer, returns the heap size in bytes |
| 1185 | // Useful when the map pointer field is used for other purposes. |
| 1186 | // GC internal. |
| 1187 | inline int SizeFromMap(Map* map); |
| 1188 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1189 | // Support for the marking heap objects during the marking phase of GC. |
| 1190 | // True if the object is marked live. |
| 1191 | inline bool IsMarked(); |
| 1192 | |
| 1193 | // Mutate this object's map pointer to indicate that the object is live. |
| 1194 | inline void SetMark(); |
| 1195 | |
| 1196 | // Mutate this object's map pointer to remove the indication that the |
| 1197 | // object is live (ie, partially restore the map pointer). |
| 1198 | inline void ClearMark(); |
| 1199 | |
| 1200 | // True if this object is marked as overflowed. Overflowed objects have |
| 1201 | // been reached and marked during marking of the heap, but their children |
| 1202 | // have not necessarily been marked and they have not been pushed on the |
| 1203 | // marking stack. |
| 1204 | inline bool IsOverflowed(); |
| 1205 | |
| 1206 | // Mutate this object's map pointer to indicate that the object is |
| 1207 | // overflowed. |
| 1208 | inline void SetOverflow(); |
| 1209 | |
| 1210 | // Mutate this object's map pointer to remove the indication that the |
| 1211 | // object is overflowed (ie, partially restore the map pointer). |
| 1212 | inline void ClearOverflow(); |
| 1213 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1214 | // Returns the field at offset in obj, as a read/write Object* reference. |
| 1215 | // Does no checking, and is safe to use during GC, while maps are invalid. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1216 | // Does not invoke write barrier, so should only be assigned to |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 1217 | // during marking GC. |
| 1218 | static inline Object** RawField(HeapObject* obj, int offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1219 | |
| 1220 | // Casting. |
| 1221 | static inline HeapObject* cast(Object* obj); |
| 1222 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1223 | // Return the write barrier mode for this. Callers of this function |
| 1224 | // must be able to present a reference to an AssertNoAllocation |
| 1225 | // object as a sign that they are not going to use this function |
| 1226 | // from code that allocates and thus invalidates the returned write |
| 1227 | // barrier mode. |
| 1228 | inline WriteBarrierMode GetWriteBarrierMode(const AssertNoAllocation&); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1229 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1230 | // Dispatched behavior. |
| 1231 | void HeapObjectShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1232 | #ifdef OBJECT_PRINT |
| 1233 | inline void HeapObjectPrint() { |
| 1234 | HeapObjectPrint(stdout); |
| 1235 | } |
| 1236 | void HeapObjectPrint(FILE* out); |
| 1237 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1238 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1239 | void HeapObjectVerify(); |
| 1240 | inline void VerifyObjectField(int offset); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1241 | inline void VerifySmiField(int offset); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1242 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1243 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1244 | #ifdef OBJECT_PRINT |
| 1245 | void PrintHeader(FILE* out, const char* id); |
| 1246 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1247 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1248 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1249 | // Verify a pointer is a valid HeapObject pointer that points to object |
| 1250 | // areas in the heap. |
| 1251 | static void VerifyHeapPointer(Object* p); |
| 1252 | #endif |
| 1253 | |
| 1254 | // Layout description. |
| 1255 | // First field in a heap object is map. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1256 | static const int kMapOffset = Object::kHeaderSize; |
| 1257 | static const int kHeaderSize = kMapOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1258 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1259 | STATIC_CHECK(kMapOffset == Internals::kHeapObjectMapOffset); |
| 1260 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1261 | protected: |
| 1262 | // helpers for calling an ObjectVisitor to iterate over pointers in the |
| 1263 | // half-open range [start, end) specified as integer offsets |
| 1264 | inline void IteratePointers(ObjectVisitor* v, int start, int end); |
| 1265 | // as above, for the single element at "offset" |
| 1266 | inline void IteratePointer(ObjectVisitor* v, int offset); |
| 1267 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1268 | private: |
| 1269 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapObject); |
| 1270 | }; |
| 1271 | |
| 1272 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1273 | #define SLOT_ADDR(obj, offset) \ |
| 1274 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 1275 | |
| 1276 | // This class describes a body of an object of a fixed size |
| 1277 | // in which all pointer fields are located in the [start_offset, end_offset) |
| 1278 | // interval. |
| 1279 | template<int start_offset, int end_offset, int size> |
| 1280 | class FixedBodyDescriptor { |
| 1281 | public: |
| 1282 | static const int kStartOffset = start_offset; |
| 1283 | static const int kEndOffset = end_offset; |
| 1284 | static const int kSize = size; |
| 1285 | |
| 1286 | static inline void IterateBody(HeapObject* obj, ObjectVisitor* v); |
| 1287 | |
| 1288 | template<typename StaticVisitor> |
| 1289 | static inline void IterateBody(HeapObject* obj) { |
| 1290 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1291 | SLOT_ADDR(obj, end_offset)); |
| 1292 | } |
| 1293 | }; |
| 1294 | |
| 1295 | |
| 1296 | // This class describes a body of an object of a variable size |
| 1297 | // in which all pointer fields are located in the [start_offset, object_size) |
| 1298 | // interval. |
| 1299 | template<int start_offset> |
| 1300 | class FlexibleBodyDescriptor { |
| 1301 | public: |
| 1302 | static const int kStartOffset = start_offset; |
| 1303 | |
| 1304 | static inline void IterateBody(HeapObject* obj, |
| 1305 | int object_size, |
| 1306 | ObjectVisitor* v); |
| 1307 | |
| 1308 | template<typename StaticVisitor> |
| 1309 | static inline void IterateBody(HeapObject* obj, int object_size) { |
| 1310 | StaticVisitor::VisitPointers(SLOT_ADDR(obj, start_offset), |
| 1311 | SLOT_ADDR(obj, object_size)); |
| 1312 | } |
| 1313 | }; |
| 1314 | |
| 1315 | #undef SLOT_ADDR |
| 1316 | |
| 1317 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1318 | // The HeapNumber class describes heap allocated numbers that cannot be |
| 1319 | // represented in a Smi (small integer) |
| 1320 | class HeapNumber: public HeapObject { |
| 1321 | public: |
| 1322 | // [value]: number value. |
| 1323 | inline double value(); |
| 1324 | inline void set_value(double value); |
| 1325 | |
| 1326 | // Casting. |
| 1327 | static inline HeapNumber* cast(Object* obj); |
| 1328 | |
| 1329 | // Dispatched behavior. |
| 1330 | Object* HeapNumberToBoolean(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1331 | inline void HeapNumberPrint() { |
| 1332 | HeapNumberPrint(stdout); |
| 1333 | } |
| 1334 | void HeapNumberPrint(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1335 | void HeapNumberPrint(StringStream* accumulator); |
| 1336 | #ifdef DEBUG |
| 1337 | void HeapNumberVerify(); |
| 1338 | #endif |
| 1339 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1340 | inline int get_exponent(); |
| 1341 | inline int get_sign(); |
| 1342 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1343 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1344 | static const int kValueOffset = HeapObject::kHeaderSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1345 | // IEEE doubles are two 32 bit words. The first is just mantissa, the second |
| 1346 | // is a mixture of sign, exponent and mantissa. Our current platforms are all |
| 1347 | // little endian apart from non-EABI arm which is little endian with big |
| 1348 | // endian floating point word ordering! |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1349 | static const int kMantissaOffset = kValueOffset; |
| 1350 | static const int kExponentOffset = kValueOffset + 4; |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1351 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1352 | static const int kSize = kValueOffset + kDoubleSize; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1353 | static const uint32_t kSignMask = 0x80000000u; |
| 1354 | static const uint32_t kExponentMask = 0x7ff00000u; |
| 1355 | static const uint32_t kMantissaMask = 0xfffffu; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 1356 | static const int kMantissaBits = 52; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 1357 | static const int kExponentBits = 11; |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 1358 | static const int kExponentBias = 1023; |
| 1359 | static const int kExponentShift = 20; |
| 1360 | static const int kMantissaBitsInTopWord = 20; |
| 1361 | static const int kNonMantissaBitsInTopWord = 12; |
| 1362 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1363 | private: |
| 1364 | DISALLOW_IMPLICIT_CONSTRUCTORS(HeapNumber); |
| 1365 | }; |
| 1366 | |
| 1367 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1368 | // JSReceiver includes types on which properties can be defined, i.e., |
| 1369 | // JSObject and JSProxy. |
| 1370 | class JSReceiver: public HeapObject { |
| 1371 | public: |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1372 | enum DeleteMode { |
| 1373 | NORMAL_DELETION, |
| 1374 | STRICT_DELETION, |
| 1375 | FORCE_DELETION |
| 1376 | }; |
| 1377 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1378 | // Casting. |
| 1379 | static inline JSReceiver* cast(Object* obj); |
| 1380 | |
| 1381 | // Can cause GC. |
| 1382 | MUST_USE_RESULT MaybeObject* SetProperty(String* key, |
| 1383 | Object* value, |
| 1384 | PropertyAttributes attributes, |
| 1385 | StrictModeFlag strict_mode); |
| 1386 | MUST_USE_RESULT MaybeObject* SetProperty(LookupResult* result, |
| 1387 | String* key, |
| 1388 | Object* value, |
| 1389 | PropertyAttributes attributes, |
| 1390 | StrictModeFlag strict_mode); |
| 1391 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1392 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
| 1393 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1394 | // Returns the class name ([[Class]] property in the specification). |
| 1395 | String* class_name(); |
| 1396 | |
| 1397 | // Returns the constructor name (the name (possibly, inferred name) of the |
| 1398 | // function that was used to instantiate the object). |
| 1399 | String* constructor_name(); |
| 1400 | |
| 1401 | inline PropertyAttributes GetPropertyAttribute(String* name); |
| 1402 | PropertyAttributes GetPropertyAttributeWithReceiver(JSReceiver* receiver, |
| 1403 | String* name); |
| 1404 | PropertyAttributes GetLocalPropertyAttribute(String* name); |
| 1405 | |
| 1406 | // Can cause a GC. |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 1407 | inline bool HasProperty(String* name); |
| 1408 | inline bool HasLocalProperty(String* name); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1409 | |
| 1410 | // Return the object's prototype (might be Heap::null_value()). |
| 1411 | inline Object* GetPrototype(); |
| 1412 | |
| 1413 | // Set the object's prototype (only JSReceiver and null are allowed). |
| 1414 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value, |
| 1415 | bool skip_hidden_prototypes); |
| 1416 | |
| 1417 | // Lookup a property. If found, the result is valid and has |
| 1418 | // detailed information. |
| 1419 | void LocalLookup(String* name, LookupResult* result); |
| 1420 | void Lookup(String* name, LookupResult* result); |
| 1421 | |
| 1422 | private: |
| 1423 | PropertyAttributes GetPropertyAttribute(JSReceiver* receiver, |
| 1424 | LookupResult* result, |
| 1425 | String* name, |
| 1426 | bool continue_search); |
| 1427 | |
| 1428 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSReceiver); |
| 1429 | }; |
| 1430 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1431 | // The JSObject describes real heap allocated JavaScript objects with |
| 1432 | // properties. |
| 1433 | // Note that the map of JSObject changes during execution to enable inline |
| 1434 | // caching. |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1435 | class JSObject: public JSReceiver { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1436 | public: |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1437 | enum ElementsKind { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1438 | // The "fast" kind for tagged values. Must be first to make it possible |
| 1439 | // to efficiently check maps if they have fast elements. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1440 | FAST_ELEMENTS, |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1441 | |
| 1442 | // The "fast" kind for unwrapped, non-tagged double values. |
| 1443 | FAST_DOUBLE_ELEMENTS, |
| 1444 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1445 | // The "slow" kind. |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1446 | DICTIONARY_ELEMENTS, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1447 | NON_STRICT_ARGUMENTS_ELEMENTS, |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1448 | // The "fast" kind for external arrays |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1449 | EXTERNAL_BYTE_ELEMENTS, |
| 1450 | EXTERNAL_UNSIGNED_BYTE_ELEMENTS, |
| 1451 | EXTERNAL_SHORT_ELEMENTS, |
| 1452 | EXTERNAL_UNSIGNED_SHORT_ELEMENTS, |
| 1453 | EXTERNAL_INT_ELEMENTS, |
| 1454 | EXTERNAL_UNSIGNED_INT_ELEMENTS, |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1455 | EXTERNAL_FLOAT_ELEMENTS, |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1456 | EXTERNAL_DOUBLE_ELEMENTS, |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1457 | EXTERNAL_PIXEL_ELEMENTS, |
| 1458 | |
| 1459 | // Derived constants from ElementsKind |
| 1460 | FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_BYTE_ELEMENTS, |
| 1461 | LAST_EXTERNAL_ARRAY_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS, |
| 1462 | FIRST_ELEMENTS_KIND = FAST_ELEMENTS, |
| 1463 | LAST_ELEMENTS_KIND = EXTERNAL_PIXEL_ELEMENTS |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1464 | }; |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1465 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1466 | static const int kElementsKindCount = |
| 1467 | LAST_ELEMENTS_KIND - FIRST_ELEMENTS_KIND + 1; |
| 1468 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1469 | // [properties]: Backing storage for properties. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1470 | // properties is a FixedArray in the fast case and a Dictionary in the |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1471 | // slow case. |
| 1472 | DECL_ACCESSORS(properties, FixedArray) // Get and set fast properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1473 | inline void initialize_properties(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1474 | inline bool HasFastProperties(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1475 | inline StringDictionary* property_dictionary(); // Gets slow properties. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1476 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1477 | // [elements]: The elements (properties with names that are integers). |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1478 | // |
| 1479 | // Elements can be in two general modes: fast and slow. Each mode |
| 1480 | // corrensponds to a set of object representations of elements that |
| 1481 | // have something in common. |
| 1482 | // |
| 1483 | // In the fast mode elements is a FixedArray and so each element can |
| 1484 | // be quickly accessed. This fact is used in the generated code. The |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1485 | // elements array can have one of three maps in this mode: |
| 1486 | // fixed_array_map, non_strict_arguments_elements_map or |
| 1487 | // fixed_cow_array_map (for copy-on-write arrays). In the latter case |
| 1488 | // the elements array may be shared by a few objects and so before |
| 1489 | // writing to any element the array must be copied. Use |
| 1490 | // EnsureWritableFastElements in this case. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1491 | // |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1492 | // In the slow mode the elements is either a NumberDictionary, an |
| 1493 | // ExternalArray, or a FixedArray parameter map for a (non-strict) |
| 1494 | // arguments object. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1495 | DECL_ACCESSORS(elements, HeapObject) |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1496 | inline void initialize_elements(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1497 | MUST_USE_RESULT inline MaybeObject* ResetElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1498 | inline ElementsKind GetElementsKind(); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 1499 | inline ElementsAccessor* GetElementsAccessor(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1500 | inline bool HasFastElements(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1501 | inline bool HasFastDoubleElements(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1502 | inline bool HasDictionaryElements(); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1503 | inline bool HasExternalPixelElements(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 1504 | inline bool HasExternalArrayElements(); |
| 1505 | inline bool HasExternalByteElements(); |
| 1506 | inline bool HasExternalUnsignedByteElements(); |
| 1507 | inline bool HasExternalShortElements(); |
| 1508 | inline bool HasExternalUnsignedShortElements(); |
| 1509 | inline bool HasExternalIntElements(); |
| 1510 | inline bool HasExternalUnsignedIntElements(); |
| 1511 | inline bool HasExternalFloatElements(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1512 | inline bool HasExternalDoubleElements(); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1513 | bool HasFastArgumentsElements(); |
| 1514 | bool HasDictionaryArgumentsElements(); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 1515 | inline bool AllowsSetElementsLength(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 1516 | inline NumberDictionary* element_dictionary(); // Gets slow elements. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1517 | |
| 1518 | // Requires: HasFastElements(). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1519 | MUST_USE_RESULT inline MaybeObject* EnsureWritableFastElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1520 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1521 | // Collects elements starting at index 0. |
| 1522 | // Undefined values are placed after non-undefined values. |
| 1523 | // Returns the number of non-undefined values. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1524 | MUST_USE_RESULT MaybeObject* PrepareElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1525 | // As PrepareElementsForSort, but only on objects where elements is |
| 1526 | // a dictionary, and it will stay a dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1527 | MUST_USE_RESULT MaybeObject* PrepareSlowElementsForSort(uint32_t limit); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 1528 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1529 | MUST_USE_RESULT MaybeObject* SetPropertyForResult(LookupResult* result, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1530 | String* key, |
| 1531 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1532 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1533 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1534 | MUST_USE_RESULT MaybeObject* SetPropertyWithFailedAccessCheck( |
| 1535 | LookupResult* result, |
| 1536 | String* name, |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1537 | Object* value, |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1538 | bool check_prototype, |
| 1539 | StrictModeFlag strict_mode); |
| 1540 | MUST_USE_RESULT MaybeObject* SetPropertyWithCallback( |
| 1541 | Object* structure, |
| 1542 | String* name, |
| 1543 | Object* value, |
| 1544 | JSObject* holder, |
| 1545 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1546 | MUST_USE_RESULT MaybeObject* SetPropertyWithDefinedSetter(JSFunction* setter, |
| 1547 | Object* value); |
| 1548 | MUST_USE_RESULT MaybeObject* SetPropertyWithInterceptor( |
| 1549 | String* name, |
| 1550 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1551 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1552 | StrictModeFlag strict_mode); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1553 | MUST_USE_RESULT MaybeObject* SetPropertyPostInterceptor( |
| 1554 | String* name, |
| 1555 | Object* value, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1556 | PropertyAttributes attributes, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1557 | StrictModeFlag strict_mode); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1558 | MUST_USE_RESULT MaybeObject* SetLocalPropertyIgnoreAttributes( |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1559 | String* key, |
| 1560 | Object* value, |
| 1561 | PropertyAttributes attributes); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1562 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1563 | // Retrieve a value in a normalized object given a lookup result. |
| 1564 | // Handles the special representation of JS global objects. |
| 1565 | Object* GetNormalizedProperty(LookupResult* result); |
| 1566 | |
| 1567 | // Sets the property value in a normalized object given a lookup result. |
| 1568 | // Handles the special representation of JS global objects. |
| 1569 | Object* SetNormalizedProperty(LookupResult* result, Object* value); |
| 1570 | |
| 1571 | // Sets the property value in a normalized object given (key, value, details). |
| 1572 | // Handles the special representation of JS global objects. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1573 | MUST_USE_RESULT MaybeObject* SetNormalizedProperty(String* name, |
| 1574 | Object* value, |
| 1575 | PropertyDetails details); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1576 | |
| 1577 | // Deletes the named property in a normalized object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1578 | MUST_USE_RESULT MaybeObject* DeleteNormalizedProperty(String* name, |
| 1579 | DeleteMode mode); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1580 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1581 | // Retrieve interceptors. |
| 1582 | InterceptorInfo* GetNamedInterceptor(); |
| 1583 | InterceptorInfo* GetIndexedInterceptor(); |
| 1584 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1585 | // Used from JSReceiver. |
| 1586 | PropertyAttributes GetPropertyAttributePostInterceptor(JSObject* receiver, |
| 1587 | String* name, |
| 1588 | bool continue_search); |
| 1589 | PropertyAttributes GetPropertyAttributeWithInterceptor(JSObject* receiver, |
| 1590 | String* name, |
| 1591 | bool continue_search); |
| 1592 | PropertyAttributes GetPropertyAttributeWithFailedAccessCheck( |
| 1593 | Object* receiver, |
| 1594 | LookupResult* result, |
| 1595 | String* name, |
| 1596 | bool continue_search); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1597 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1598 | MUST_USE_RESULT MaybeObject* DefineAccessor(String* name, |
| 1599 | bool is_getter, |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1600 | Object* fun, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1601 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1602 | Object* LookupAccessor(String* name, bool is_getter); |
| 1603 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1604 | MUST_USE_RESULT MaybeObject* DefineAccessor(AccessorInfo* info); |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 1605 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1606 | // Used from Object::GetProperty(). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1607 | MaybeObject* GetPropertyWithFailedAccessCheck( |
| 1608 | Object* receiver, |
| 1609 | LookupResult* result, |
| 1610 | String* name, |
| 1611 | PropertyAttributes* attributes); |
| 1612 | MaybeObject* GetPropertyWithInterceptor( |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1613 | JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1614 | String* name, |
| 1615 | PropertyAttributes* attributes); |
| 1616 | MaybeObject* GetPropertyPostInterceptor( |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1617 | JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1618 | String* name, |
| 1619 | PropertyAttributes* attributes); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1620 | MaybeObject* GetLocalPropertyPostInterceptor(JSReceiver* receiver, |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1621 | String* name, |
| 1622 | PropertyAttributes* attributes); |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 1623 | |
christian.plesner.hansen@gmail.com | 2bc58ef | 2009-09-22 10:00:30 +0000 | [diff] [blame] | 1624 | // Returns true if this is an instance of an api function and has |
| 1625 | // been modified since it was created. May give false positives. |
| 1626 | bool IsDirty(); |
| 1627 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1628 | // If the receiver is a JSGlobalProxy this method will return its prototype, |
| 1629 | // otherwise the result is the receiver itself. |
| 1630 | inline Object* BypassGlobalProxy(); |
| 1631 | |
| 1632 | // Accessors for hidden properties object. |
| 1633 | // |
| 1634 | // Hidden properties are not local properties of the object itself. |
| 1635 | // Instead they are stored on an auxiliary JSObject stored as a local |
| 1636 | // property with a special name Heap::hidden_symbol(). But if the |
| 1637 | // receiver is a JSGlobalProxy then the auxiliary object is a property |
| 1638 | // of its prototype. |
| 1639 | // |
| 1640 | // Has/Get/SetHiddenPropertiesObject methods don't allow the holder to be |
| 1641 | // a JSGlobalProxy. Use BypassGlobalProxy method above to get to the real |
| 1642 | // holder. |
| 1643 | // |
| 1644 | // These accessors do not touch interceptors or accessors. |
| 1645 | inline bool HasHiddenPropertiesObject(); |
| 1646 | inline Object* GetHiddenPropertiesObject(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1647 | MUST_USE_RESULT inline MaybeObject* SetHiddenPropertiesObject( |
| 1648 | Object* hidden_obj); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 1649 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 1650 | // Indicates whether the hidden properties object should be created. |
| 1651 | enum HiddenPropertiesFlag { ALLOW_CREATION, OMIT_CREATION }; |
| 1652 | |
| 1653 | // Retrieves the hidden properties object. |
| 1654 | // |
| 1655 | // The undefined value might be returned in case no hidden properties object |
| 1656 | // is present and creation was omitted. |
| 1657 | inline bool HasHiddenProperties(); |
| 1658 | MUST_USE_RESULT MaybeObject* GetHiddenProperties(HiddenPropertiesFlag flag); |
| 1659 | |
| 1660 | // Retrieves a permanent object identity hash code. |
| 1661 | // |
| 1662 | // The identity hash is stored as a hidden property. The undefined value might |
| 1663 | // be returned in case no hidden properties object is present and creation was |
| 1664 | // omitted. |
| 1665 | MUST_USE_RESULT MaybeObject* GetIdentityHash(HiddenPropertiesFlag flag); |
| 1666 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1667 | MUST_USE_RESULT MaybeObject* DeleteProperty(String* name, DeleteMode mode); |
| 1668 | MUST_USE_RESULT MaybeObject* DeleteElement(uint32_t index, DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1669 | |
| 1670 | // Tests for the fast common case for property enumeration. |
| 1671 | bool IsSimpleEnum(); |
| 1672 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1673 | // Do we want to keep the elements in fast case when increasing the |
| 1674 | // capacity? |
| 1675 | bool ShouldConvertToSlowElements(int new_capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1676 | // Returns true if the backing storage for the slow-case elements of |
| 1677 | // this object takes up nearly as much space as a fast-case backing |
| 1678 | // storage would. In that case the JSObject should have fast |
| 1679 | // elements. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1680 | bool ShouldConvertToFastElements(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1681 | // Returns true if the elements of JSObject contains only values that can be |
| 1682 | // represented in a FixedDoubleArray. |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1683 | bool CanConvertToFastDoubleElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1684 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1685 | // Tells whether the index'th element is present. |
| 1686 | inline bool HasElement(uint32_t index); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1687 | bool HasElementWithReceiver(JSReceiver* receiver, uint32_t index); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1688 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1689 | // Computes the new capacity when expanding the elements of a JSObject. |
| 1690 | static int NewElementsCapacity(int old_capacity) { |
| 1691 | // (old_capacity + 50%) + 16 |
| 1692 | return old_capacity + (old_capacity >> 1) + 16; |
| 1693 | } |
| 1694 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1695 | // Tells whether the index'th element is present and how it is stored. |
| 1696 | enum LocalElementType { |
| 1697 | // There is no element with given index. |
| 1698 | UNDEFINED_ELEMENT, |
| 1699 | |
| 1700 | // Element with given index is handled by interceptor. |
| 1701 | INTERCEPTED_ELEMENT, |
| 1702 | |
| 1703 | // Element with given index is character in string. |
| 1704 | STRING_CHARACTER_ELEMENT, |
| 1705 | |
| 1706 | // Element with given index is stored in fast backing store. |
| 1707 | FAST_ELEMENT, |
| 1708 | |
| 1709 | // Element with given index is stored in slow backing store. |
| 1710 | DICTIONARY_ELEMENT |
| 1711 | }; |
| 1712 | |
| 1713 | LocalElementType HasLocalElement(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1714 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1715 | bool HasElementWithInterceptor(JSReceiver* receiver, uint32_t index); |
| 1716 | bool HasElementPostInterceptor(JSReceiver* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1717 | |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1718 | MUST_USE_RESULT MaybeObject* SetFastElement(uint32_t index, |
| 1719 | Object* value, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1720 | StrictModeFlag strict_mode, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1721 | bool check_prototype); |
| 1722 | MUST_USE_RESULT MaybeObject* SetDictionaryElement(uint32_t index, |
| 1723 | Object* value, |
| 1724 | StrictModeFlag strict_mode, |
| 1725 | bool check_prototype); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1726 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1727 | MUST_USE_RESULT MaybeObject* SetFastDoubleElement( |
| 1728 | uint32_t index, |
| 1729 | Object* value, |
| 1730 | StrictModeFlag strict_mode, |
| 1731 | bool check_prototype = true); |
| 1732 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1733 | // Set the index'th array element. |
| 1734 | // A Failure object is returned if GC is needed. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1735 | MUST_USE_RESULT MaybeObject* SetElement(uint32_t index, |
| 1736 | Object* value, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1737 | StrictModeFlag strict_mode, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1738 | bool check_prototype); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1739 | |
| 1740 | // Returns the index'th element. |
| 1741 | // The undefined object if index is out of bounds. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1742 | MaybeObject* GetElementWithInterceptor(Object* receiver, uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1743 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1744 | // Replace the elements' backing store with fast elements of the given |
| 1745 | // capacity. Update the length for JSArrays. Returns the new backing |
| 1746 | // store. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1747 | MUST_USE_RESULT MaybeObject* SetFastElementsCapacityAndLength(int capacity, |
| 1748 | int length); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1749 | MUST_USE_RESULT MaybeObject* SetFastDoubleElementsCapacityAndLength( |
| 1750 | int capacity, |
| 1751 | int length); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1752 | MUST_USE_RESULT MaybeObject* SetSlowElements(Object* length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1753 | |
| 1754 | // Lookup interceptors are used for handling properties controlled by host |
| 1755 | // objects. |
| 1756 | inline bool HasNamedInterceptor(); |
| 1757 | inline bool HasIndexedInterceptor(); |
| 1758 | |
| 1759 | // Support functions for v8 api (needed for correct interceptor behavior). |
| 1760 | bool HasRealNamedProperty(String* key); |
| 1761 | bool HasRealElementProperty(uint32_t index); |
| 1762 | bool HasRealNamedCallbackProperty(String* key); |
| 1763 | |
| 1764 | // Initializes the array to a certain length |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1765 | MUST_USE_RESULT MaybeObject* SetElementsLength(Object* length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1766 | |
| 1767 | // Get the header size for a JSObject. Used to compute the index of |
| 1768 | // internal fields as well as the number of internal fields. |
| 1769 | inline int GetHeaderSize(); |
| 1770 | |
| 1771 | inline int GetInternalFieldCount(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1772 | inline int GetInternalFieldOffset(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1773 | inline Object* GetInternalField(int index); |
| 1774 | inline void SetInternalField(int index, Object* value); |
| 1775 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1776 | // Lookup a property. If found, the result is valid and has |
| 1777 | // detailed information. |
| 1778 | void LocalLookup(String* name, LookupResult* result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1779 | |
| 1780 | // The following lookup functions skip interceptors. |
| 1781 | void LocalLookupRealNamedProperty(String* name, LookupResult* result); |
| 1782 | void LookupRealNamedProperty(String* name, LookupResult* result); |
| 1783 | void LookupRealNamedPropertyInPrototypes(String* name, LookupResult* result); |
| 1784 | void LookupCallbackSetterInPrototypes(String* name, LookupResult* result); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1785 | MUST_USE_RESULT MaybeObject* SetElementWithCallbackSetterInPrototypes( |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1786 | uint32_t index, Object* value, bool* found, StrictModeFlag strict_mode); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 1787 | void LookupCallback(String* name, LookupResult* result); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1788 | |
| 1789 | // Returns the number of properties on this object filtering out properties |
| 1790 | // with the specified attributes (ignoring interceptors). |
| 1791 | int NumberOfLocalProperties(PropertyAttributes filter); |
| 1792 | // Returns the number of enumerable properties (ignoring interceptors). |
| 1793 | int NumberOfEnumProperties(); |
ager@chromium.org | ddb913d | 2009-01-27 10:01:48 +0000 | [diff] [blame] | 1794 | // Fill in details for properties into storage starting at the specified |
| 1795 | // index. |
| 1796 | void GetLocalPropertyNames(FixedArray* storage, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1797 | |
| 1798 | // Returns the number of properties on this object filtering out properties |
| 1799 | // with the specified attributes (ignoring interceptors). |
| 1800 | int NumberOfLocalElements(PropertyAttributes filter); |
| 1801 | // Returns the number of enumerable elements (ignoring interceptors). |
| 1802 | int NumberOfEnumElements(); |
| 1803 | // Returns the number of elements on this object filtering out elements |
| 1804 | // with the specified attributes (ignoring interceptors). |
| 1805 | int GetLocalElementKeys(FixedArray* storage, PropertyAttributes filter); |
| 1806 | // Count and fill in the enumerable elements into storage. |
| 1807 | // (storage->length() == NumberOfEnumElements()). |
| 1808 | // If storage is NULL, will count the elements without adding |
| 1809 | // them to any storage. |
| 1810 | // Returns the number of enumerable elements. |
| 1811 | int GetEnumElementKeys(FixedArray* storage); |
| 1812 | |
| 1813 | // Add a property to a fast-case object using a map transition to |
| 1814 | // new_map. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1815 | MUST_USE_RESULT MaybeObject* AddFastPropertyUsingMap(Map* new_map, |
| 1816 | String* name, |
| 1817 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1818 | |
| 1819 | // Add a constant function property to a fast-case object. |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 1820 | // This leaves a CONSTANT_TRANSITION in the old map, and |
| 1821 | // if it is called on a second object with this map, a |
| 1822 | // normal property is added instead, with a map transition. |
| 1823 | // This avoids the creation of many maps with the same constant |
| 1824 | // function, all orphaned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1825 | MUST_USE_RESULT MaybeObject* AddConstantFunctionProperty( |
| 1826 | String* name, |
| 1827 | JSFunction* function, |
| 1828 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1829 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1830 | MUST_USE_RESULT MaybeObject* ReplaceSlowProperty( |
| 1831 | String* name, |
| 1832 | Object* value, |
| 1833 | PropertyAttributes attributes); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1834 | |
| 1835 | // Converts a descriptor of any other type to a real field, |
| 1836 | // backed by the properties array. Descriptors of visible |
| 1837 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
| 1838 | // Converts the descriptor on the original object's map to a |
| 1839 | // map transition, and the the new field is on the object's new map. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1840 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToFieldAndMapTransition( |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1841 | String* name, |
| 1842 | Object* new_value, |
| 1843 | PropertyAttributes attributes); |
| 1844 | |
| 1845 | // Converts a descriptor of any other type to a real field, |
| 1846 | // backed by the properties array. Descriptors of visible |
| 1847 | // types, such as CONSTANT_FUNCTION, keep their enumeration order. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1848 | MUST_USE_RESULT MaybeObject* ConvertDescriptorToField( |
| 1849 | String* name, |
| 1850 | Object* new_value, |
| 1851 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1852 | |
| 1853 | // Add a property to a fast-case object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1854 | MUST_USE_RESULT MaybeObject* AddFastProperty(String* name, |
| 1855 | Object* value, |
| 1856 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1857 | |
| 1858 | // Add a property to a slow-case object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1859 | MUST_USE_RESULT MaybeObject* AddSlowProperty(String* name, |
| 1860 | Object* value, |
| 1861 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1862 | |
| 1863 | // Add a property to an object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1864 | MUST_USE_RESULT MaybeObject* AddProperty(String* name, |
| 1865 | Object* value, |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1866 | PropertyAttributes attributes, |
| 1867 | StrictModeFlag strict_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1868 | |
| 1869 | // Convert the object to use the canonical dictionary |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1870 | // representation. If the object is expected to have additional properties |
| 1871 | // added this number can be indicated to have the backing store allocated to |
| 1872 | // an initial capacity for holding these properties. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1873 | MUST_USE_RESULT MaybeObject* NormalizeProperties( |
| 1874 | PropertyNormalizationMode mode, |
| 1875 | int expected_additional_properties); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1876 | |
| 1877 | // Convert and update the elements backing store to be a NumberDictionary |
| 1878 | // dictionary. Returns the backing after conversion. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1879 | MUST_USE_RESULT MaybeObject* NormalizeElements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1880 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1881 | MUST_USE_RESULT MaybeObject* UpdateMapCodeCache(String* name, Code* code); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1882 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1883 | // Transform slow named properties to fast variants. |
| 1884 | // Returns failure if allocation failed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1885 | MUST_USE_RESULT MaybeObject* TransformToFastProperties( |
| 1886 | int unused_property_fields); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1887 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1888 | // Access fast-case object properties at index. |
| 1889 | inline Object* FastPropertyAt(int index); |
| 1890 | inline Object* FastPropertyAtPut(int index, Object* value); |
| 1891 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1892 | // Access to in object properties. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1893 | inline int GetInObjectPropertyOffset(int index); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1894 | inline Object* InObjectPropertyAt(int index); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1895 | inline Object* InObjectPropertyAtPut(int index, |
| 1896 | Object* value, |
| 1897 | WriteBarrierMode mode |
| 1898 | = UPDATE_WRITE_BARRIER); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1899 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1900 | // initializes the body after properties slot, properties slot is |
| 1901 | // initialized by set_properties |
| 1902 | // Note: this call does not update write barrier, it is caller's |
| 1903 | // reponsibility to ensure that *v* can be collected without WB here. |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 1904 | inline void InitializeBody(int object_size, Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1905 | |
| 1906 | // Check whether this object references another object |
| 1907 | bool ReferencesObject(Object* obj); |
| 1908 | |
| 1909 | // Casting. |
| 1910 | static inline JSObject* cast(Object* obj); |
| 1911 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1912 | // Disalow further properties to be added to the object. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1913 | MUST_USE_RESULT MaybeObject* PreventExtensions(); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1914 | |
| 1915 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1916 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1917 | void JSObjectShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1918 | #ifdef OBJECT_PRINT |
| 1919 | inline void JSObjectPrint() { |
| 1920 | JSObjectPrint(stdout); |
| 1921 | } |
| 1922 | void JSObjectPrint(FILE* out); |
| 1923 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1924 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1925 | void JSObjectVerify(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1926 | #endif |
| 1927 | #ifdef OBJECT_PRINT |
| 1928 | inline void PrintProperties() { |
| 1929 | PrintProperties(stdout); |
| 1930 | } |
| 1931 | void PrintProperties(FILE* out); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1932 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1933 | inline void PrintElements() { |
| 1934 | PrintElements(stdout); |
| 1935 | } |
| 1936 | void PrintElements(FILE* out); |
| 1937 | #endif |
| 1938 | |
| 1939 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1940 | // Structure for collecting spill information about JSObjects. |
| 1941 | class SpillInformation { |
| 1942 | public: |
| 1943 | void Clear(); |
| 1944 | void Print(); |
| 1945 | int number_of_objects_; |
| 1946 | int number_of_objects_with_fast_properties_; |
| 1947 | int number_of_objects_with_fast_elements_; |
| 1948 | int number_of_fast_used_fields_; |
| 1949 | int number_of_fast_unused_fields_; |
| 1950 | int number_of_slow_used_properties_; |
| 1951 | int number_of_slow_unused_properties_; |
| 1952 | int number_of_fast_used_elements_; |
| 1953 | int number_of_fast_unused_elements_; |
| 1954 | int number_of_slow_used_elements_; |
| 1955 | int number_of_slow_unused_elements_; |
| 1956 | }; |
| 1957 | |
| 1958 | void IncrementSpillStatistics(SpillInformation* info); |
| 1959 | #endif |
| 1960 | Object* SlowReverseLookup(Object* value); |
| 1961 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1962 | // Maximal number of fast properties for the JSObject. Used to |
| 1963 | // restrict the number of map transitions to avoid an explosion in |
| 1964 | // the number of maps for objects used as dictionaries. |
| 1965 | inline int MaxFastProperties(); |
| 1966 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 1967 | // Maximal number of elements (numbered 0 .. kMaxElementCount - 1). |
| 1968 | // Also maximal value of JSArray's length property. |
| 1969 | static const uint32_t kMaxElementCount = 0xffffffffu; |
| 1970 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1971 | // Constants for heuristics controlling conversion of fast elements |
| 1972 | // to slow elements. |
| 1973 | |
| 1974 | // Maximal gap that can be introduced by adding an element beyond |
| 1975 | // the current elements length. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1976 | static const uint32_t kMaxGap = 1024; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 1977 | |
| 1978 | // Maximal length of fast elements array that won't be checked for |
| 1979 | // being dense enough on expansion. |
| 1980 | static const int kMaxUncheckedFastElementsLength = 5000; |
| 1981 | |
| 1982 | // Same as above but for old arrays. This limit is more strict. We |
| 1983 | // don't want to be wasteful with long lived objects. |
| 1984 | static const int kMaxUncheckedOldFastElementsLength = 500; |
| 1985 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 1986 | static const int kInitialMaxFastElementArray = 100000; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1987 | static const int kMaxFastProperties = 12; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1988 | static const int kMaxInstanceSize = 255 * kPointerSize; |
| 1989 | // When extending the backing storage for property values, we increase |
| 1990 | // its size by more than the 1 entry necessary, so sequentially adding fields |
| 1991 | // to the same object requires fewer allocations and copies. |
| 1992 | static const int kFieldsAdded = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1993 | |
| 1994 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1995 | static const int kPropertiesOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1996 | static const int kElementsOffset = kPropertiesOffset + kPointerSize; |
| 1997 | static const int kHeaderSize = kElementsOffset + kPointerSize; |
| 1998 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 1999 | STATIC_CHECK(kHeaderSize == Internals::kJSObjectHeaderSize); |
| 2000 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2001 | class BodyDescriptor : public FlexibleBodyDescriptor<kPropertiesOffset> { |
| 2002 | public: |
| 2003 | static inline int SizeOf(Map* map, HeapObject* object); |
| 2004 | }; |
| 2005 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2006 | private: |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 2007 | friend class DictionaryElementsAccessor; |
| 2008 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2009 | MUST_USE_RESULT MaybeObject* GetElementWithCallback(Object* receiver, |
| 2010 | Object* structure, |
| 2011 | uint32_t index, |
| 2012 | Object* holder); |
| 2013 | MaybeObject* SetElementWithCallback(Object* structure, |
| 2014 | uint32_t index, |
| 2015 | Object* value, |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 2016 | JSObject* holder, |
| 2017 | StrictModeFlag strict_mode); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2018 | MUST_USE_RESULT MaybeObject* SetElementWithInterceptor( |
| 2019 | uint32_t index, |
| 2020 | Object* value, |
| 2021 | StrictModeFlag strict_mode, |
| 2022 | bool check_prototype); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2023 | MUST_USE_RESULT MaybeObject* SetElementWithoutInterceptor( |
| 2024 | uint32_t index, |
| 2025 | Object* value, |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2026 | StrictModeFlag strict_mode, |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 2027 | bool check_prototype); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2028 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2029 | MUST_USE_RESULT MaybeObject* DeletePropertyPostInterceptor(String* name, |
| 2030 | DeleteMode mode); |
| 2031 | MUST_USE_RESULT MaybeObject* DeletePropertyWithInterceptor(String* name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2032 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2033 | MUST_USE_RESULT MaybeObject* DeleteElementWithInterceptor(uint32_t index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2034 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2035 | MUST_USE_RESULT MaybeObject* DeleteFastElement(uint32_t index); |
| 2036 | MUST_USE_RESULT MaybeObject* DeleteDictionaryElement(uint32_t index, |
| 2037 | DeleteMode mode); |
| 2038 | |
| 2039 | bool ReferencesObjectFromElements(FixedArray* elements, |
| 2040 | ElementsKind kind, |
| 2041 | Object* object); |
| 2042 | bool HasElementInElements(FixedArray* elements, |
| 2043 | ElementsKind kind, |
| 2044 | uint32_t index); |
| 2045 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2046 | // Returns true if most of the elements backing storage is used. |
| 2047 | bool HasDenseElements(); |
| 2048 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2049 | // Gets the current elements capacity and the number of used elements. |
| 2050 | void GetElementsCapacityAndUsage(int* capacity, int* used); |
| 2051 | |
kmillikin@chromium.org | 9155e25 | 2010-05-26 13:27:57 +0000 | [diff] [blame] | 2052 | bool CanSetCallback(String* name); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2053 | MUST_USE_RESULT MaybeObject* SetElementCallback( |
| 2054 | uint32_t index, |
| 2055 | Object* structure, |
| 2056 | PropertyAttributes attributes); |
| 2057 | MUST_USE_RESULT MaybeObject* SetPropertyCallback( |
| 2058 | String* name, |
| 2059 | Object* structure, |
| 2060 | PropertyAttributes attributes); |
| 2061 | MUST_USE_RESULT MaybeObject* DefineGetterSetter( |
| 2062 | String* name, |
| 2063 | PropertyAttributes attributes); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2064 | |
| 2065 | void LookupInDescriptor(String* name, LookupResult* result); |
| 2066 | |
| 2067 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSObject); |
| 2068 | }; |
| 2069 | |
| 2070 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2071 | // Common superclass for FixedArrays that allow implementations to share |
| 2072 | // common accessors and some code paths. |
| 2073 | class FixedArrayBase: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2074 | public: |
| 2075 | // [length]: length of the array. |
| 2076 | inline int length(); |
| 2077 | inline void set_length(int value); |
| 2078 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2079 | inline static FixedArrayBase* cast(Object* object); |
| 2080 | |
| 2081 | // Layout description. |
| 2082 | // Length is smi tagged when it is stored. |
| 2083 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 2084 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 2085 | }; |
| 2086 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 2087 | class FixedDoubleArray; |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2088 | |
| 2089 | // FixedArray describes fixed-sized arrays with element type Object*. |
| 2090 | class FixedArray: public FixedArrayBase { |
| 2091 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2092 | // Setter and getter for elements. |
| 2093 | inline Object* get(int index); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2094 | // Setter that uses write barrier. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2095 | inline void set(int index, Object* value); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 2096 | inline bool is_the_hole(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2097 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 2098 | // Setter that doesn't need write barrier). |
| 2099 | inline void set(int index, Smi* value); |
| 2100 | // Setter with explicit barrier mode. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2101 | inline void set(int index, Object* value, WriteBarrierMode mode); |
| 2102 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2103 | // Setters for frequently used oddballs located in old space. |
| 2104 | inline void set_undefined(int index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2105 | // TODO(isolates): duplicate. |
| 2106 | inline void set_undefined(Heap* heap, int index); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2107 | inline void set_null(int index); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2108 | // TODO(isolates): duplicate. |
| 2109 | inline void set_null(Heap* heap, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2110 | inline void set_the_hole(int index); |
| 2111 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2112 | // Setters with less debug checks for the GC to use. |
| 2113 | inline void set_unchecked(int index, Smi* value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2114 | inline void set_null_unchecked(Heap* heap, int index); |
| 2115 | inline void set_unchecked(Heap* heap, int index, Object* value, |
| 2116 | WriteBarrierMode mode); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 2117 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2118 | // Gives access to raw memory which stores the array's data. |
| 2119 | inline Object** data_start(); |
| 2120 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2121 | // Copy operations. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2122 | MUST_USE_RESULT inline MaybeObject* Copy(); |
| 2123 | MUST_USE_RESULT MaybeObject* CopySize(int new_length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2124 | |
| 2125 | // Add the elements of a JSArray to this FixedArray. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2126 | MUST_USE_RESULT MaybeObject* AddKeysFromJSArray(JSArray* array); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2127 | |
| 2128 | // Compute the union of this and other. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2129 | MUST_USE_RESULT MaybeObject* UnionOfKeys(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2130 | |
| 2131 | // Copy a sub array from the receiver to dest. |
| 2132 | void CopyTo(int pos, FixedArray* dest, int dest_pos, int len); |
| 2133 | |
| 2134 | // Garbage collection support. |
| 2135 | static int SizeFor(int length) { return kHeaderSize + length * kPointerSize; } |
| 2136 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 2137 | // Code Generation support. |
| 2138 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2139 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2140 | // Casting. |
| 2141 | static inline FixedArray* cast(Object* obj); |
| 2142 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2143 | // Maximal allowed size, in bytes, of a single FixedArray. |
| 2144 | // Prevents overflowing size computations, as well as extreme memory |
| 2145 | // consumption. |
| 2146 | static const int kMaxSize = 512 * MB; |
| 2147 | // Maximally allowed length of a FixedArray. |
| 2148 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2149 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2150 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2151 | #ifdef OBJECT_PRINT |
| 2152 | inline void FixedArrayPrint() { |
| 2153 | FixedArrayPrint(stdout); |
| 2154 | } |
| 2155 | void FixedArrayPrint(FILE* out); |
| 2156 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2157 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2158 | void FixedArrayVerify(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2159 | // Checks if two FixedArrays have identical contents. |
| 2160 | bool IsEqualTo(FixedArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2161 | #endif |
| 2162 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2163 | // Swap two elements in a pair of arrays. If this array and the |
| 2164 | // numbers array are the same object, the elements are only swapped |
| 2165 | // once. |
| 2166 | void SwapPairs(FixedArray* numbers, int i, int j); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2167 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 2168 | // Sort prefix of this array and the numbers array as pairs wrt. the |
| 2169 | // numbers. If the numbers array and the this array are the same |
| 2170 | // object, the prefix of this array is sorted. |
| 2171 | void SortPairs(FixedArray* numbers, uint32_t len); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2172 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2173 | class BodyDescriptor : public FlexibleBodyDescriptor<kHeaderSize> { |
| 2174 | public: |
| 2175 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 2176 | return SizeFor(reinterpret_cast<FixedArray*>(object)->length()); |
| 2177 | } |
| 2178 | }; |
| 2179 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2180 | protected: |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2181 | // Set operation on FixedArray without using write barriers. Can |
| 2182 | // only be used for storing old space objects or smis. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2183 | static inline void fast_set(FixedArray* array, int index, Object* value); |
| 2184 | |
| 2185 | private: |
| 2186 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedArray); |
| 2187 | }; |
| 2188 | |
| 2189 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2190 | // FixedDoubleArray describes fixed-sized arrays with element type double. |
| 2191 | class FixedDoubleArray: public FixedArrayBase { |
| 2192 | public: |
| 2193 | inline void Initialize(FixedArray* from); |
| 2194 | inline void Initialize(FixedDoubleArray* from); |
| 2195 | inline void Initialize(NumberDictionary* from); |
| 2196 | |
| 2197 | // Setter and getter for elements. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 2198 | inline double get_scalar(int index); |
| 2199 | inline MaybeObject* get(int index); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2200 | inline void set(int index, double value); |
| 2201 | inline void set_the_hole(int index); |
| 2202 | |
| 2203 | // Checking for the hole. |
| 2204 | inline bool is_the_hole(int index); |
| 2205 | |
| 2206 | // Garbage collection support. |
| 2207 | inline static int SizeFor(int length) { |
| 2208 | return kHeaderSize + length * kDoubleSize; |
| 2209 | } |
| 2210 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 2211 | // Code Generation support. |
| 2212 | static int OffsetOfElementAt(int index) { return SizeFor(index); } |
| 2213 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 2214 | inline static bool is_the_hole_nan(double value); |
| 2215 | inline static double hole_nan_as_double(); |
| 2216 | inline static double canonical_not_the_hole_nan_as_double(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2217 | |
| 2218 | // Casting. |
| 2219 | static inline FixedDoubleArray* cast(Object* obj); |
| 2220 | |
| 2221 | // Maximal allowed size, in bytes, of a single FixedDoubleArray. |
| 2222 | // Prevents overflowing size computations, as well as extreme memory |
| 2223 | // consumption. |
| 2224 | static const int kMaxSize = 512 * MB; |
| 2225 | // Maximally allowed length of a FixedArray. |
| 2226 | static const int kMaxLength = (kMaxSize - kHeaderSize) / kDoubleSize; |
| 2227 | |
| 2228 | // Dispatched behavior. |
| 2229 | #ifdef OBJECT_PRINT |
| 2230 | inline void FixedDoubleArrayPrint() { |
| 2231 | FixedDoubleArrayPrint(stdout); |
| 2232 | } |
| 2233 | void FixedDoubleArrayPrint(FILE* out); |
| 2234 | #endif |
| 2235 | |
| 2236 | #ifdef DEBUG |
| 2237 | void FixedDoubleArrayVerify(); |
| 2238 | #endif |
| 2239 | |
| 2240 | private: |
| 2241 | DISALLOW_IMPLICIT_CONSTRUCTORS(FixedDoubleArray); |
| 2242 | }; |
| 2243 | |
| 2244 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2245 | // DescriptorArrays are fixed arrays used to hold instance descriptors. |
| 2246 | // The format of the these objects is: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2247 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2248 | // without overloading the instance descriptors field in the map |
| 2249 | // (and storing it in the DescriptorArray when the map has one). |
| 2250 | // [0]: storage for bit_field3 for Map owning this object (Smi) |
| 2251 | // [1]: point to a fixed array with (value, detail) pairs. |
| 2252 | // [2]: next enumeration index (Smi), or pointer to small fixed array: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2253 | // [0]: next enumeration index (Smi) |
| 2254 | // [1]: pointer to fixed array with enum cache |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2255 | // [3]: first key |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2256 | // [length() - 1]: last key |
| 2257 | // |
| 2258 | class DescriptorArray: public FixedArray { |
| 2259 | public: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2260 | // Returns true for both shared empty_descriptor_array and for smis, which the |
| 2261 | // map uses to encode additional bit fields when the descriptor array is not |
| 2262 | // yet used. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2263 | inline bool IsEmpty(); |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2264 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2265 | // Returns the number of descriptors in the array. |
| 2266 | int number_of_descriptors() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2267 | ASSERT(length() > kFirstIndex || IsEmpty()); |
| 2268 | int len = length(); |
| 2269 | return len <= kFirstIndex ? 0 : len - kFirstIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | int NextEnumerationIndex() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2273 | if (IsEmpty()) return PropertyDetails::kInitialIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2274 | Object* obj = get(kEnumerationIndexIndex); |
| 2275 | if (obj->IsSmi()) { |
| 2276 | return Smi::cast(obj)->value(); |
| 2277 | } else { |
| 2278 | Object* index = FixedArray::cast(obj)->get(kEnumCacheBridgeEnumIndex); |
| 2279 | return Smi::cast(index)->value(); |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | // Set next enumeration index and flush any enum cache. |
| 2284 | void SetNextEnumerationIndex(int value) { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2285 | if (!IsEmpty()) { |
| 2286 | fast_set(this, kEnumerationIndexIndex, Smi::FromInt(value)); |
| 2287 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2288 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2289 | bool HasEnumCache() { |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2290 | return !IsEmpty() && !get(kEnumerationIndexIndex)->IsSmi(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | Object* GetEnumCache() { |
| 2294 | ASSERT(HasEnumCache()); |
| 2295 | FixedArray* bridge = FixedArray::cast(get(kEnumerationIndexIndex)); |
| 2296 | return bridge->get(kEnumCacheBridgeCacheIndex); |
| 2297 | } |
| 2298 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2299 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 2300 | // without overloading the instance descriptors field in the map |
| 2301 | // (and storing it in the DescriptorArray when the map has one). |
| 2302 | inline int bit_field3_storage(); |
| 2303 | inline void set_bit_field3_storage(int value); |
| 2304 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2305 | // Initialize or change the enum cache, |
| 2306 | // using the supplied storage for the small "bridge". |
| 2307 | void SetEnumCache(FixedArray* bridge_storage, FixedArray* new_cache); |
| 2308 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2309 | // Accessors for fetching instance descriptor at descriptor number. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2310 | inline String* GetKey(int descriptor_number); |
| 2311 | inline Object* GetValue(int descriptor_number); |
| 2312 | inline Smi* GetDetails(int descriptor_number); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2313 | inline PropertyType GetType(int descriptor_number); |
| 2314 | inline int GetFieldIndex(int descriptor_number); |
| 2315 | inline JSFunction* GetConstantFunction(int descriptor_number); |
| 2316 | inline Object* GetCallbacksObject(int descriptor_number); |
| 2317 | inline AccessorDescriptor* GetCallbacks(int descriptor_number); |
| 2318 | inline bool IsProperty(int descriptor_number); |
| 2319 | inline bool IsTransition(int descriptor_number); |
| 2320 | inline bool IsNullDescriptor(int descriptor_number); |
| 2321 | inline bool IsDontEnum(int descriptor_number); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2322 | |
| 2323 | // Accessor for complete descriptor. |
| 2324 | inline void Get(int descriptor_number, Descriptor* desc); |
| 2325 | inline void Set(int descriptor_number, Descriptor* desc); |
| 2326 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2327 | // Transfer complete descriptor from another descriptor array to |
| 2328 | // this one. |
| 2329 | inline void CopyFrom(int index, DescriptorArray* src, int src_index); |
| 2330 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2331 | // Copy the descriptor array, insert a new descriptor and optionally |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2332 | // remove map transitions. If the descriptor is already present, it is |
| 2333 | // replaced. If a replaced descriptor is a real property (not a transition |
| 2334 | // or null), its enumeration index is kept as is. |
| 2335 | // If adding a real property, map transitions must be removed. If adding |
| 2336 | // a transition, they must not be removed. All null descriptors are removed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2337 | MUST_USE_RESULT MaybeObject* CopyInsert(Descriptor* descriptor, |
| 2338 | TransitionFlag transition_flag); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2339 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2340 | // Remove all transitions. Return a copy of the array with all transitions |
| 2341 | // removed, or a Failure object if the new array could not be allocated. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2342 | MUST_USE_RESULT MaybeObject* RemoveTransitions(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2343 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2344 | // Sort the instance descriptors by the hash codes of their keys. |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 2345 | // Does not check for duplicates. |
| 2346 | void SortUnchecked(); |
| 2347 | |
| 2348 | // Sort the instance descriptors by the hash codes of their keys. |
| 2349 | // Checks the result for duplicates. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2350 | void Sort(); |
| 2351 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2352 | // Search the instance descriptors for given name. |
| 2353 | inline int Search(String* name); |
| 2354 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2355 | // As the above, but uses DescriptorLookupCache and updates it when |
| 2356 | // necessary. |
| 2357 | inline int SearchWithCache(String* name); |
| 2358 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2359 | // Tells whether the name is present int the array. |
| 2360 | bool Contains(String* name) { return kNotFound != Search(name); } |
| 2361 | |
| 2362 | // Perform a binary search in the instance descriptors represented |
| 2363 | // by this fixed array. low and high are descriptor indices. If there |
| 2364 | // are three instance descriptors in this array it should be called |
| 2365 | // with low=0 and high=2. |
| 2366 | int BinarySearch(String* name, int low, int high); |
| 2367 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2368 | // Perform a linear search in the instance descriptors represented |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2369 | // by this fixed array. len is the number of descriptor indices that are |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 2370 | // valid. Does not require the descriptors to be sorted. |
| 2371 | int LinearSearch(String* name, int len); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2372 | |
| 2373 | // Allocates a DescriptorArray, but returns the singleton |
| 2374 | // empty descriptor array object if number_of_descriptors is 0. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2375 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_descriptors); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2376 | |
| 2377 | // Casting. |
| 2378 | static inline DescriptorArray* cast(Object* obj); |
| 2379 | |
| 2380 | // Constant for denoting key was not found. |
| 2381 | static const int kNotFound = -1; |
| 2382 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2383 | static const int kBitField3StorageIndex = 0; |
| 2384 | static const int kContentArrayIndex = 1; |
| 2385 | static const int kEnumerationIndexIndex = 2; |
| 2386 | static const int kFirstIndex = 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2387 | |
| 2388 | // The length of the "bridge" to the enum cache. |
| 2389 | static const int kEnumCacheBridgeLength = 2; |
| 2390 | static const int kEnumCacheBridgeEnumIndex = 0; |
| 2391 | static const int kEnumCacheBridgeCacheIndex = 1; |
| 2392 | |
| 2393 | // Layout description. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2394 | static const int kBitField3StorageOffset = FixedArray::kHeaderSize; |
| 2395 | static const int kContentArrayOffset = kBitField3StorageOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2396 | static const int kEnumerationIndexOffset = kContentArrayOffset + kPointerSize; |
| 2397 | static const int kFirstOffset = kEnumerationIndexOffset + kPointerSize; |
| 2398 | |
| 2399 | // Layout description for the bridge array. |
| 2400 | static const int kEnumCacheBridgeEnumOffset = FixedArray::kHeaderSize; |
| 2401 | static const int kEnumCacheBridgeCacheOffset = |
| 2402 | kEnumCacheBridgeEnumOffset + kPointerSize; |
| 2403 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2404 | #ifdef OBJECT_PRINT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2405 | // Print all the descriptors. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2406 | inline void PrintDescriptors() { |
| 2407 | PrintDescriptors(stdout); |
| 2408 | } |
| 2409 | void PrintDescriptors(FILE* out); |
| 2410 | #endif |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2411 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2412 | #ifdef DEBUG |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 2413 | // Is the descriptor array sorted and without duplicates? |
| 2414 | bool IsSortedNoDuplicates(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 2415 | |
| 2416 | // Are two DescriptorArrays equal? |
| 2417 | bool IsEqualTo(DescriptorArray* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2418 | #endif |
| 2419 | |
| 2420 | // The maximum number of descriptors we want in a descriptor array (should |
| 2421 | // fit in a page). |
| 2422 | static const int kMaxNumberOfDescriptors = 1024 + 512; |
| 2423 | |
| 2424 | private: |
| 2425 | // Conversion from descriptor number to array indices. |
| 2426 | static int ToKeyIndex(int descriptor_number) { |
| 2427 | return descriptor_number+kFirstIndex; |
| 2428 | } |
sgjesse@chromium.org | 846fb74 | 2009-12-18 08:56:33 +0000 | [diff] [blame] | 2429 | |
| 2430 | static int ToDetailsIndex(int descriptor_number) { |
| 2431 | return (descriptor_number << 1) + 1; |
| 2432 | } |
| 2433 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2434 | static int ToValueIndex(int descriptor_number) { |
| 2435 | return descriptor_number << 1; |
| 2436 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2437 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 2438 | bool is_null_descriptor(int descriptor_number) { |
| 2439 | return PropertyDetails(GetDetails(descriptor_number)).type() == |
| 2440 | NULL_DESCRIPTOR; |
| 2441 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2442 | // Swap operation on FixedArray without using write barriers. |
| 2443 | static inline void fast_swap(FixedArray* array, int first, int second); |
| 2444 | |
| 2445 | // Swap descriptor first and second. |
| 2446 | inline void Swap(int first, int second); |
| 2447 | |
| 2448 | FixedArray* GetContentArray() { |
| 2449 | return FixedArray::cast(get(kContentArrayIndex)); |
| 2450 | } |
| 2451 | DISALLOW_IMPLICIT_CONSTRUCTORS(DescriptorArray); |
| 2452 | }; |
| 2453 | |
| 2454 | |
| 2455 | // HashTable is a subclass of FixedArray that implements a hash table |
| 2456 | // that uses open addressing and quadratic probing. |
| 2457 | // |
| 2458 | // In order for the quadratic probing to work, elements that have not |
| 2459 | // yet been used and elements that have been deleted are |
| 2460 | // distinguished. Probing continues when deleted elements are |
| 2461 | // encountered and stops when unused elements are encountered. |
| 2462 | // |
| 2463 | // - Elements with key == undefined have not been used yet. |
| 2464 | // - Elements with key == null have been deleted. |
| 2465 | // |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2466 | // The hash table class is parameterized with a Shape and a Key. |
| 2467 | // Shape must be a class with the following interface: |
| 2468 | // class ExampleShape { |
| 2469 | // public: |
| 2470 | // // Tells whether key matches other. |
| 2471 | // static bool IsMatch(Key key, Object* other); |
| 2472 | // // Returns the hash value for key. |
| 2473 | // static uint32_t Hash(Key key); |
| 2474 | // // Returns the hash value for object. |
| 2475 | // static uint32_t HashForObject(Key key, Object* object); |
| 2476 | // // Convert key to an object. |
| 2477 | // static inline Object* AsObject(Key key); |
| 2478 | // // The prefix size indicates number of elements in the beginning |
| 2479 | // // of the backing storage. |
| 2480 | // static const int kPrefixSize = ..; |
| 2481 | // // The Element size indicates number of elements per entry. |
| 2482 | // static const int kEntrySize = ..; |
| 2483 | // }; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2484 | // The prefix size indicates an amount of memory in the |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2485 | // beginning of the backing storage that can be used for non-element |
| 2486 | // information by subclasses. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 2487 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2488 | template<typename Shape, typename Key> |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2489 | class HashTable: public FixedArray { |
| 2490 | public: |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2491 | // Returns the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2492 | int NumberOfElements() { |
| 2493 | return Smi::cast(get(kNumberOfElementsIndex))->value(); |
| 2494 | } |
| 2495 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2496 | // Returns the number of deleted elements in the hash table. |
| 2497 | int NumberOfDeletedElements() { |
| 2498 | return Smi::cast(get(kNumberOfDeletedElementsIndex))->value(); |
| 2499 | } |
| 2500 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2501 | // Returns the capacity of the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2502 | int Capacity() { |
| 2503 | return Smi::cast(get(kCapacityIndex))->value(); |
| 2504 | } |
| 2505 | |
| 2506 | // ElementAdded should be called whenever an element is added to a |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2507 | // hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2508 | void ElementAdded() { SetNumberOfElements(NumberOfElements() + 1); } |
| 2509 | |
| 2510 | // ElementRemoved should be called whenever an element is removed from |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2511 | // a hash table. |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2512 | void ElementRemoved() { |
| 2513 | SetNumberOfElements(NumberOfElements() - 1); |
| 2514 | SetNumberOfDeletedElements(NumberOfDeletedElements() + 1); |
| 2515 | } |
| 2516 | void ElementsRemoved(int n) { |
| 2517 | SetNumberOfElements(NumberOfElements() - n); |
| 2518 | SetNumberOfDeletedElements(NumberOfDeletedElements() + n); |
| 2519 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2520 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2521 | // Returns a new HashTable object. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2522 | MUST_USE_RESULT static MaybeObject* Allocate( |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 2523 | int at_least_space_for, |
| 2524 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2525 | |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2526 | // Computes the required capacity for a table holding the given |
| 2527 | // number of elements. May be more than HashTable::kMaxCapacity. |
| 2528 | static int ComputeCapacity(int at_least_space_for); |
| 2529 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2530 | // Returns the key at entry. |
| 2531 | Object* KeyAt(int entry) { return get(EntryToIndex(entry)); } |
| 2532 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 2533 | // Tells whether k is a real key. Null and undefined are not allowed |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2534 | // as keys and can be used to indicate missing or deleted elements. |
| 2535 | bool IsKey(Object* k) { |
| 2536 | return !k->IsNull() && !k->IsUndefined(); |
| 2537 | } |
| 2538 | |
| 2539 | // Garbage collection support. |
| 2540 | void IteratePrefix(ObjectVisitor* visitor); |
| 2541 | void IterateElements(ObjectVisitor* visitor); |
| 2542 | |
| 2543 | // Casting. |
| 2544 | static inline HashTable* cast(Object* obj); |
| 2545 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2546 | // Compute the probe offset (quadratic probing). |
| 2547 | INLINE(static uint32_t GetProbeOffset(uint32_t n)) { |
| 2548 | return (n + n * n) >> 1; |
| 2549 | } |
| 2550 | |
| 2551 | static const int kNumberOfElementsIndex = 0; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2552 | static const int kNumberOfDeletedElementsIndex = 1; |
| 2553 | static const int kCapacityIndex = 2; |
| 2554 | static const int kPrefixStartIndex = 3; |
| 2555 | static const int kElementsStartIndex = |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2556 | kPrefixStartIndex + Shape::kPrefixSize; |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2557 | static const int kEntrySize = Shape::kEntrySize; |
| 2558 | static const int kElementsStartOffset = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2559 | kHeaderSize + kElementsStartIndex * kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2560 | static const int kCapacityOffset = |
| 2561 | kHeaderSize + kCapacityIndex * kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2562 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2563 | // Constant used for denoting a absent entry. |
| 2564 | static const int kNotFound = -1; |
| 2565 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2566 | // Maximal capacity of HashTable. Based on maximal length of underlying |
| 2567 | // FixedArray. Staying below kMaxCapacity also ensures that EntryToIndex |
| 2568 | // cannot overflow. |
| 2569 | static const int kMaxCapacity = |
| 2570 | (FixedArray::kMaxLength - kElementsStartOffset) / kEntrySize; |
| 2571 | |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2572 | // Find entry for key otherwise return kNotFound. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2573 | inline int FindEntry(Key key); |
| 2574 | int FindEntry(Isolate* isolate, Key key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2575 | |
| 2576 | protected: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2577 | // Find the entry at which to insert element with the given key that |
| 2578 | // has the given hash value. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2579 | uint32_t FindInsertionEntry(uint32_t hash); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2580 | |
| 2581 | // Returns the index for an entry (of the key) |
| 2582 | static inline int EntryToIndex(int entry) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2583 | return (entry * kEntrySize) + kElementsStartIndex; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2586 | // Update the number of elements in the hash table. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2587 | void SetNumberOfElements(int nof) { |
| 2588 | fast_set(this, kNumberOfElementsIndex, Smi::FromInt(nof)); |
| 2589 | } |
| 2590 | |
kasperl@chromium.org | edf0cd1 | 2010-01-05 13:29:12 +0000 | [diff] [blame] | 2591 | // Update the number of deleted elements in the hash table. |
| 2592 | void SetNumberOfDeletedElements(int nod) { |
| 2593 | fast_set(this, kNumberOfDeletedElementsIndex, Smi::FromInt(nod)); |
| 2594 | } |
| 2595 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2596 | // Sets the capacity of the hash table. |
| 2597 | void SetCapacity(int capacity) { |
| 2598 | // To scale a computed hash code to fit within the hash table, we |
| 2599 | // use bit-wise AND with a mask, so the capacity must be positive |
| 2600 | // and non-zero. |
| 2601 | ASSERT(capacity > 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2602 | ASSERT(capacity <= kMaxCapacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2603 | fast_set(this, kCapacityIndex, Smi::FromInt(capacity)); |
| 2604 | } |
| 2605 | |
| 2606 | |
| 2607 | // Returns probe entry. |
| 2608 | static uint32_t GetProbe(uint32_t hash, uint32_t number, uint32_t size) { |
| 2609 | ASSERT(IsPowerOf2(size)); |
| 2610 | return (hash + GetProbeOffset(number)) & (size - 1); |
| 2611 | } |
| 2612 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 2613 | static uint32_t FirstProbe(uint32_t hash, uint32_t size) { |
| 2614 | return hash & (size - 1); |
| 2615 | } |
| 2616 | |
| 2617 | static uint32_t NextProbe(uint32_t last, uint32_t number, uint32_t size) { |
| 2618 | return (last + number) & (size - 1); |
| 2619 | } |
| 2620 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2621 | // Rehashes this hash-table into the new table. |
| 2622 | MUST_USE_RESULT MaybeObject* Rehash(HashTable* new_table, Key key); |
| 2623 | |
| 2624 | // Attempt to shrink hash table after removal of key. |
| 2625 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 2626 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2627 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2628 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2629 | }; |
| 2630 | |
| 2631 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2632 | |
| 2633 | // HashTableKey is an abstract superclass for virtual key behavior. |
| 2634 | class HashTableKey { |
| 2635 | public: |
| 2636 | // Returns whether the other object matches this key. |
| 2637 | virtual bool IsMatch(Object* other) = 0; |
| 2638 | // Returns the hash value for this key. |
| 2639 | virtual uint32_t Hash() = 0; |
| 2640 | // Returns the hash value for object. |
| 2641 | virtual uint32_t HashForObject(Object* key) = 0; |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 2642 | // Returns the key object for storing into the hash table. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2643 | // If allocations fails a failure object is returned. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2644 | MUST_USE_RESULT virtual MaybeObject* AsObject() = 0; |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2645 | // Required. |
| 2646 | virtual ~HashTableKey() {} |
| 2647 | }; |
| 2648 | |
| 2649 | class SymbolTableShape { |
| 2650 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2651 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2652 | return key->IsMatch(value); |
| 2653 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2654 | static inline uint32_t Hash(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2655 | return key->Hash(); |
| 2656 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2657 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2658 | return key->HashForObject(object); |
| 2659 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2660 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2661 | return key->AsObject(); |
| 2662 | } |
| 2663 | |
| 2664 | static const int kPrefixSize = 0; |
| 2665 | static const int kEntrySize = 1; |
| 2666 | }; |
| 2667 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2668 | class SeqAsciiString; |
| 2669 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2670 | // SymbolTable. |
| 2671 | // |
| 2672 | // No special elements in the prefix and the element size is 1 |
| 2673 | // because only the symbol itself (the key) needs to be stored. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2674 | class SymbolTable: public HashTable<SymbolTableShape, HashTableKey*> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2675 | public: |
| 2676 | // Find symbol in the symbol table. If it is not there yet, it is |
| 2677 | // added. The return value is the symbol table which might have |
| 2678 | // been enlarged. If the return value is not a failure, the symbol |
| 2679 | // pointer *s is set to the symbol found. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2680 | MUST_USE_RESULT MaybeObject* LookupSymbol(Vector<const char> str, Object** s); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2681 | MUST_USE_RESULT MaybeObject* LookupAsciiSymbol(Vector<const char> str, |
| 2682 | Object** s); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2683 | MUST_USE_RESULT MaybeObject* LookupSubStringAsciiSymbol( |
| 2684 | Handle<SeqAsciiString> str, |
| 2685 | int from, |
| 2686 | int length, |
| 2687 | Object** s); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 2688 | MUST_USE_RESULT MaybeObject* LookupTwoByteSymbol(Vector<const uc16> str, |
| 2689 | Object** s); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2690 | MUST_USE_RESULT MaybeObject* LookupString(String* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2691 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2692 | // Looks up a symbol that is equal to the given string and returns |
| 2693 | // true if it is found, assigning the symbol to the given output |
| 2694 | // parameter. |
| 2695 | bool LookupSymbolIfExists(String* str, String** symbol); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 2696 | bool LookupTwoCharsSymbolIfExists(uint32_t c1, uint32_t c2, String** symbol); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2697 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2698 | // Casting. |
| 2699 | static inline SymbolTable* cast(Object* obj); |
| 2700 | |
| 2701 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2702 | MUST_USE_RESULT MaybeObject* LookupKey(HashTableKey* key, Object** s); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2703 | |
| 2704 | DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolTable); |
| 2705 | }; |
| 2706 | |
| 2707 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2708 | class MapCacheShape { |
| 2709 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2710 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2711 | return key->IsMatch(value); |
| 2712 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2713 | static inline uint32_t Hash(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2714 | return key->Hash(); |
| 2715 | } |
| 2716 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2717 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2718 | return key->HashForObject(object); |
| 2719 | } |
| 2720 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2721 | MUST_USE_RESULT static inline MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2722 | return key->AsObject(); |
| 2723 | } |
| 2724 | |
| 2725 | static const int kPrefixSize = 0; |
| 2726 | static const int kEntrySize = 2; |
| 2727 | }; |
| 2728 | |
| 2729 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2730 | // MapCache. |
| 2731 | // |
| 2732 | // Maps keys that are a fixed array of symbols to a map. |
| 2733 | // Used for canonicalize maps for object literals. |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2734 | class MapCache: public HashTable<MapCacheShape, HashTableKey*> { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2735 | public: |
| 2736 | // Find cached value for a string key, otherwise return null. |
| 2737 | Object* Lookup(FixedArray* key); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2738 | MUST_USE_RESULT MaybeObject* Put(FixedArray* key, Map* value); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2739 | static inline MapCache* cast(Object* obj); |
| 2740 | |
| 2741 | private: |
| 2742 | DISALLOW_IMPLICIT_CONSTRUCTORS(MapCache); |
| 2743 | }; |
| 2744 | |
| 2745 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2746 | template <typename Shape, typename Key> |
| 2747 | class Dictionary: public HashTable<Shape, Key> { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2748 | public: |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2749 | static inline Dictionary<Shape, Key>* cast(Object* obj) { |
| 2750 | return reinterpret_cast<Dictionary<Shape, Key>*>(obj); |
| 2751 | } |
| 2752 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2753 | // Returns the value at entry. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2754 | Object* ValueAt(int entry) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2755 | return this->get(HashTable<Shape, Key>::EntryToIndex(entry)+1); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2756 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2757 | |
| 2758 | // Set the value for entry. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2759 | // Returns false if the put wasn't performed due to property being read only. |
| 2760 | // Returns true on successful put. |
| 2761 | bool ValueAtPut(int entry, Object* value) { |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 2762 | // Check that this value can actually be written. |
| 2763 | PropertyDetails details = DetailsAt(entry); |
| 2764 | // If a value has not been initilized we allow writing to it even if |
| 2765 | // it is read only (a declared const that has not been initialized). |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2766 | if (details.IsReadOnly() && !ValueAt(entry)->IsTheHole()) { |
| 2767 | return false; |
| 2768 | } |
| 2769 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); |
| 2770 | return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2771 | } |
| 2772 | |
| 2773 | // Returns the property details for the property at entry. |
| 2774 | PropertyDetails DetailsAt(int entry) { |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2775 | ASSERT(entry >= 0); // Not found is -1, which is not caught by get(). |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2776 | return PropertyDetails( |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2777 | Smi::cast(this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 2))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | // Set the details for entry. |
| 2781 | void DetailsAtPut(int entry, PropertyDetails value) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2782 | this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 2, value.AsSmi()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2783 | } |
| 2784 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2785 | // Sorting support |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2786 | void CopyValuesTo(FixedArray* elements); |
| 2787 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2788 | // Delete a property from the dictionary. |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 2789 | Object* DeleteProperty(int entry, JSObject::DeleteMode mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2790 | |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2791 | // Attempt to shrink the dictionary after deletion of key. |
| 2792 | MUST_USE_RESULT MaybeObject* Shrink(Key key); |
| 2793 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2794 | // Returns the number of elements in the dictionary filtering out properties |
| 2795 | // with the specified attributes. |
| 2796 | int NumberOfElementsFilterAttributes(PropertyAttributes filter); |
| 2797 | |
| 2798 | // Returns the number of enumerable elements in the dictionary. |
| 2799 | int NumberOfEnumElements(); |
| 2800 | |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2801 | enum SortMode { UNSORTED, SORTED }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2802 | // Copies keys to preallocated fixed array. |
sgjesse@chromium.org | 6db8871 | 2011-07-11 11:41:22 +0000 | [diff] [blame] | 2803 | void CopyKeysTo(FixedArray* storage, |
| 2804 | PropertyAttributes filter, |
| 2805 | SortMode sort_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2806 | // Fill in details for properties into storage. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 2807 | void CopyKeysTo(FixedArray* storage, int index, SortMode sort_mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2808 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2809 | // Accessors for next enumeration index. |
| 2810 | void SetNextEnumerationIndex(int index) { |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 2811 | this->fast_set(this, kNextEnumerationIndexIndex, Smi::FromInt(index)); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | int NextEnumerationIndex() { |
| 2815 | return Smi::cast(FixedArray::get(kNextEnumerationIndexIndex))->value(); |
| 2816 | } |
| 2817 | |
| 2818 | // Returns a new array for dictionary usage. Might return Failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2819 | MUST_USE_RESULT static MaybeObject* Allocate(int at_least_space_for); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2820 | |
| 2821 | // Ensure enough space for n additional elements. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2822 | MUST_USE_RESULT MaybeObject* EnsureCapacity(int n, Key key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2823 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2824 | #ifdef OBJECT_PRINT |
| 2825 | inline void Print() { |
| 2826 | Print(stdout); |
| 2827 | } |
| 2828 | void Print(FILE* out); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2829 | #endif |
| 2830 | // Returns the key (slow). |
| 2831 | Object* SlowReverseLookup(Object* value); |
| 2832 | |
| 2833 | // Sets the entry to (key, value) pair. |
| 2834 | inline void SetEntry(int entry, |
| 2835 | Object* key, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2836 | Object* value); |
| 2837 | inline void SetEntry(int entry, |
| 2838 | Object* key, |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2839 | Object* value, |
| 2840 | PropertyDetails details); |
| 2841 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2842 | MUST_USE_RESULT MaybeObject* Add(Key key, |
| 2843 | Object* value, |
| 2844 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2845 | |
| 2846 | protected: |
| 2847 | // Generic at put operation. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2848 | MUST_USE_RESULT MaybeObject* AtPut(Key key, Object* value); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2849 | |
| 2850 | // Add entry to dictionary. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2851 | MUST_USE_RESULT MaybeObject* AddEntry(Key key, |
| 2852 | Object* value, |
| 2853 | PropertyDetails details, |
| 2854 | uint32_t hash); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2855 | |
| 2856 | // Generate new enumeration indices to avoid enumeration index overflow. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2857 | MUST_USE_RESULT MaybeObject* GenerateNewEnumerationIndices(); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2858 | static const int kMaxNumberKeyIndex = |
| 2859 | HashTable<Shape, Key>::kPrefixStartIndex; |
| 2860 | static const int kNextEnumerationIndexIndex = kMaxNumberKeyIndex + 1; |
| 2861 | }; |
| 2862 | |
| 2863 | |
| 2864 | class StringDictionaryShape { |
| 2865 | public: |
| 2866 | static inline bool IsMatch(String* key, Object* other); |
| 2867 | static inline uint32_t Hash(String* key); |
| 2868 | static inline uint32_t HashForObject(String* key, Object* object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2869 | MUST_USE_RESULT static inline MaybeObject* AsObject(String* key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2870 | static const int kPrefixSize = 2; |
| 2871 | static const int kEntrySize = 3; |
| 2872 | static const bool kIsEnumerable = true; |
| 2873 | }; |
| 2874 | |
| 2875 | |
| 2876 | class StringDictionary: public Dictionary<StringDictionaryShape, String*> { |
| 2877 | public: |
| 2878 | static inline StringDictionary* cast(Object* obj) { |
| 2879 | ASSERT(obj->IsDictionary()); |
| 2880 | return reinterpret_cast<StringDictionary*>(obj); |
| 2881 | } |
| 2882 | |
| 2883 | // Copies enumerable keys to preallocated fixed array. |
| 2884 | void CopyEnumKeysTo(FixedArray* storage, FixedArray* sort_array); |
| 2885 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2886 | // For transforming properties of a JSObject. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2887 | MUST_USE_RESULT MaybeObject* TransformPropertiesToFastFor( |
| 2888 | JSObject* obj, |
| 2889 | int unused_property_fields); |
ricow@chromium.org | 4980dff | 2010-07-19 08:33:45 +0000 | [diff] [blame] | 2890 | |
| 2891 | // Find entry for key otherwise return kNotFound. Optimzed version of |
| 2892 | // HashTable::FindEntry. |
| 2893 | int FindEntry(String* key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2894 | }; |
| 2895 | |
| 2896 | |
| 2897 | class NumberDictionaryShape { |
| 2898 | public: |
| 2899 | static inline bool IsMatch(uint32_t key, Object* other); |
| 2900 | static inline uint32_t Hash(uint32_t key); |
| 2901 | static inline uint32_t HashForObject(uint32_t key, Object* object); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2902 | MUST_USE_RESULT static inline MaybeObject* AsObject(uint32_t key); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2903 | static const int kPrefixSize = 2; |
| 2904 | static const int kEntrySize = 3; |
| 2905 | static const bool kIsEnumerable = false; |
| 2906 | }; |
| 2907 | |
| 2908 | |
| 2909 | class NumberDictionary: public Dictionary<NumberDictionaryShape, uint32_t> { |
| 2910 | public: |
| 2911 | static NumberDictionary* cast(Object* obj) { |
| 2912 | ASSERT(obj->IsDictionary()); |
| 2913 | return reinterpret_cast<NumberDictionary*>(obj); |
| 2914 | } |
| 2915 | |
| 2916 | // Type specific at put (default NONE attributes is used when adding). |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2917 | MUST_USE_RESULT MaybeObject* AtNumberPut(uint32_t key, Object* value); |
| 2918 | MUST_USE_RESULT MaybeObject* AddNumberEntry(uint32_t key, |
| 2919 | Object* value, |
| 2920 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2921 | |
| 2922 | // Set an existing entry or add a new one if needed. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2923 | MUST_USE_RESULT MaybeObject* Set(uint32_t key, |
| 2924 | Object* value, |
| 2925 | PropertyDetails details); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2926 | |
| 2927 | void UpdateMaxNumberKey(uint32_t key); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2928 | |
| 2929 | // If slow elements are required we will never go back to fast-case |
| 2930 | // for the elements kept in this dictionary. We require slow |
| 2931 | // elements if an element has been added at an index larger than |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2932 | // kRequiresSlowElementsLimit or set_requires_slow_elements() has been called |
| 2933 | // when defining a getter or setter with a number key. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2934 | inline bool requires_slow_elements(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2935 | inline void set_requires_slow_elements(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2936 | |
| 2937 | // Get the value of the max number key that has been added to this |
| 2938 | // dictionary. max_number_key can only be called if |
| 2939 | // requires_slow_elements returns false. |
| 2940 | inline uint32_t max_number_key(); |
| 2941 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2942 | // Remove all entries were key is a number and (from <= key && key < to). |
| 2943 | void RemoveNumberEntries(uint32_t from, uint32_t to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2944 | |
| 2945 | // Bit masks. |
| 2946 | static const int kRequiresSlowElementsMask = 1; |
| 2947 | static const int kRequiresSlowElementsTagSize = 1; |
| 2948 | static const uint32_t kRequiresSlowElementsLimit = (1 << 29) - 1; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2949 | }; |
| 2950 | |
| 2951 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2952 | class ObjectHashTableShape { |
| 2953 | public: |
| 2954 | static inline bool IsMatch(JSObject* key, Object* other); |
| 2955 | static inline uint32_t Hash(JSObject* key); |
| 2956 | static inline uint32_t HashForObject(JSObject* key, Object* object); |
| 2957 | MUST_USE_RESULT static inline MaybeObject* AsObject(JSObject* key); |
| 2958 | static const int kPrefixSize = 0; |
| 2959 | static const int kEntrySize = 2; |
| 2960 | }; |
| 2961 | |
| 2962 | |
| 2963 | // ObjectHashTable maps keys that are JavaScript objects to object values by |
| 2964 | // using the identity hash of the key for hashing purposes. |
| 2965 | class ObjectHashTable: public HashTable<ObjectHashTableShape, JSObject*> { |
| 2966 | public: |
| 2967 | static inline ObjectHashTable* cast(Object* obj) { |
| 2968 | ASSERT(obj->IsHashTable()); |
| 2969 | return reinterpret_cast<ObjectHashTable*>(obj); |
| 2970 | } |
| 2971 | |
| 2972 | // Looks up the value associated with the given key. The undefined value is |
| 2973 | // returned in case the key is not present. |
| 2974 | Object* Lookup(JSObject* key); |
| 2975 | |
| 2976 | // Adds (or overwrites) the value associated with the given key. Mapping a |
| 2977 | // key to the undefined value causes removal of the whole entry. |
| 2978 | MUST_USE_RESULT MaybeObject* Put(JSObject* key, Object* value); |
| 2979 | |
| 2980 | private: |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 2981 | friend class MarkCompactCollector; |
| 2982 | |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2983 | void AddEntry(int entry, JSObject* key, Object* value); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 2984 | void RemoveEntry(int entry, Heap* heap); |
| 2985 | inline void RemoveEntry(int entry); |
| 2986 | |
| 2987 | // Returns the index to the value of an entry. |
| 2988 | static inline int EntryToValueIndex(int entry) { |
| 2989 | return EntryToIndex(entry) + 1; |
| 2990 | } |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 2991 | }; |
| 2992 | |
| 2993 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 2994 | // JSFunctionResultCache caches results of some JSFunction invocation. |
| 2995 | // It is a fixed array with fixed structure: |
| 2996 | // [0]: factory function |
| 2997 | // [1]: finger index |
| 2998 | // [2]: current cache size |
| 2999 | // [3]: dummy field. |
| 3000 | // The rest of array are key/value pairs. |
| 3001 | class JSFunctionResultCache: public FixedArray { |
| 3002 | public: |
| 3003 | static const int kFactoryIndex = 0; |
| 3004 | static const int kFingerIndex = kFactoryIndex + 1; |
| 3005 | static const int kCacheSizeIndex = kFingerIndex + 1; |
| 3006 | static const int kDummyIndex = kCacheSizeIndex + 1; |
| 3007 | static const int kEntriesIndex = kDummyIndex + 1; |
antonm@chromium.org | 397e23c | 2010-04-21 12:00:05 +0000 | [diff] [blame] | 3008 | |
| 3009 | static const int kEntrySize = 2; // key + value |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3010 | |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 3011 | static const int kFactoryOffset = kHeaderSize; |
| 3012 | static const int kFingerOffset = kFactoryOffset + kPointerSize; |
| 3013 | static const int kCacheSizeOffset = kFingerOffset + kPointerSize; |
| 3014 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3015 | inline void MakeZeroSize(); |
| 3016 | inline void Clear(); |
| 3017 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3018 | inline int size(); |
| 3019 | inline void set_size(int size); |
| 3020 | inline int finger_index(); |
| 3021 | inline void set_finger_index(int finger_index); |
| 3022 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 3023 | // Casting |
| 3024 | static inline JSFunctionResultCache* cast(Object* obj); |
| 3025 | |
| 3026 | #ifdef DEBUG |
| 3027 | void JSFunctionResultCacheVerify(); |
| 3028 | #endif |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 3029 | }; |
| 3030 | |
| 3031 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3032 | // The cache for maps used by normalized (dictionary mode) objects. |
| 3033 | // Such maps do not have property descriptors, so a typical program |
| 3034 | // needs very limited number of distinct normalized maps. |
| 3035 | class NormalizedMapCache: public FixedArray { |
| 3036 | public: |
| 3037 | static const int kEntries = 64; |
| 3038 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3039 | MUST_USE_RESULT MaybeObject* Get(JSObject* object, |
| 3040 | PropertyNormalizationMode mode); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3041 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3042 | void Clear(); |
| 3043 | |
| 3044 | // Casting |
| 3045 | static inline NormalizedMapCache* cast(Object* obj); |
| 3046 | |
| 3047 | #ifdef DEBUG |
| 3048 | void NormalizedMapCacheVerify(); |
| 3049 | #endif |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3050 | }; |
| 3051 | |
| 3052 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3053 | // ByteArray represents fixed sized byte arrays. Used by the outside world, |
| 3054 | // such as PCRE, and also by the memory allocator and garbage collector to |
| 3055 | // fill in free blocks in the heap. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3056 | class ByteArray: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3057 | public: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3058 | // [length]: length of the array. |
| 3059 | inline int length(); |
| 3060 | inline void set_length(int value); |
| 3061 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3062 | // Setter and getter. |
| 3063 | inline byte get(int index); |
| 3064 | inline void set(int index, byte value); |
| 3065 | |
| 3066 | // Treat contents as an int array. |
| 3067 | inline int get_int(int index); |
| 3068 | |
| 3069 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3070 | return OBJECT_POINTER_ALIGN(kHeaderSize + length); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3071 | } |
| 3072 | // We use byte arrays for free blocks in the heap. Given a desired size in |
| 3073 | // bytes that is a multiple of the word size and big enough to hold a byte |
| 3074 | // array, this function returns the number of elements a byte array should |
| 3075 | // have. |
| 3076 | static int LengthFor(int size_in_bytes) { |
| 3077 | ASSERT(IsAligned(size_in_bytes, kPointerSize)); |
| 3078 | ASSERT(size_in_bytes >= kHeaderSize); |
| 3079 | return size_in_bytes - kHeaderSize; |
| 3080 | } |
| 3081 | |
| 3082 | // Returns data start address. |
| 3083 | inline Address GetDataStartAddress(); |
| 3084 | |
| 3085 | // Returns a pointer to the ByteArray object for a given data start address. |
| 3086 | static inline ByteArray* FromDataStartAddress(Address address); |
| 3087 | |
| 3088 | // Casting. |
| 3089 | static inline ByteArray* cast(Object* obj); |
| 3090 | |
| 3091 | // Dispatched behavior. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3092 | inline int ByteArraySize() { |
| 3093 | return SizeFor(this->length()); |
| 3094 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3095 | #ifdef OBJECT_PRINT |
| 3096 | inline void ByteArrayPrint() { |
| 3097 | ByteArrayPrint(stdout); |
| 3098 | } |
| 3099 | void ByteArrayPrint(FILE* out); |
| 3100 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3101 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3102 | void ByteArrayVerify(); |
| 3103 | #endif |
| 3104 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3105 | // Layout description. |
| 3106 | // Length is smi tagged when it is stored. |
| 3107 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 3108 | static const int kHeaderSize = kLengthOffset + kPointerSize; |
| 3109 | |
| 3110 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 3111 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 3112 | // Maximal memory consumption for a single ByteArray. |
| 3113 | static const int kMaxSize = 512 * MB; |
| 3114 | // Maximal length of a single ByteArray. |
| 3115 | static const int kMaxLength = kMaxSize - kHeaderSize; |
| 3116 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3117 | private: |
| 3118 | DISALLOW_IMPLICIT_CONSTRUCTORS(ByteArray); |
| 3119 | }; |
| 3120 | |
| 3121 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3122 | // An ExternalArray represents a fixed-size array of primitive values |
| 3123 | // which live outside the JavaScript heap. Its subclasses are used to |
| 3124 | // implement the CanvasArray types being defined in the WebGL |
| 3125 | // specification. As of this writing the first public draft is not yet |
| 3126 | // available, but Khronos members can access the draft at: |
| 3127 | // https://cvs.khronos.org/svn/repos/3dweb/trunk/doc/spec/WebGL-spec.html |
| 3128 | // |
| 3129 | // The semantics of these arrays differ from CanvasPixelArray. |
| 3130 | // Out-of-range values passed to the setter are converted via a C |
| 3131 | // cast, not clamping. Out-of-range indices cause exceptions to be |
| 3132 | // raised rather than being silently ignored. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3133 | class ExternalArray: public HeapObject { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3134 | public: |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3135 | // [length]: length of the array. |
| 3136 | inline int length(); |
| 3137 | inline void set_length(int value); |
| 3138 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3139 | inline bool is_the_hole(int index) { return false; } |
| 3140 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3141 | // [external_pointer]: The pointer to the external memory area backing this |
| 3142 | // external array. |
| 3143 | DECL_ACCESSORS(external_pointer, void) // Pointer to the data store. |
| 3144 | |
| 3145 | // Casting. |
| 3146 | static inline ExternalArray* cast(Object* obj); |
| 3147 | |
| 3148 | // Maximal acceptable length for an external array. |
| 3149 | static const int kMaxLength = 0x3fffffff; |
| 3150 | |
| 3151 | // ExternalArray headers are not quadword aligned. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3152 | static const int kLengthOffset = HeapObject::kHeaderSize; |
| 3153 | static const int kExternalPointerOffset = |
| 3154 | POINTER_SIZE_ALIGN(kLengthOffset + kIntSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3155 | static const int kHeaderSize = kExternalPointerOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3156 | static const int kAlignedSize = OBJECT_POINTER_ALIGN(kHeaderSize); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3157 | |
| 3158 | private: |
| 3159 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalArray); |
| 3160 | }; |
| 3161 | |
| 3162 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3163 | // A ExternalPixelArray represents a fixed-size byte array with special |
| 3164 | // semantics used for implementing the CanvasPixelArray object. Please see the |
| 3165 | // specification at: |
| 3166 | |
| 3167 | // http://www.whatwg.org/specs/web-apps/current-work/ |
| 3168 | // multipage/the-canvas-element.html#canvaspixelarray |
| 3169 | // In particular, write access clamps the value written to 0 or 255 if the |
| 3170 | // value written is outside this range. |
| 3171 | class ExternalPixelArray: public ExternalArray { |
| 3172 | public: |
| 3173 | inline uint8_t* external_pixel_pointer(); |
| 3174 | |
| 3175 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3176 | inline uint8_t get_scalar(int index); |
| 3177 | inline MaybeObject* get(int index); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 3178 | inline void set(int index, uint8_t value); |
| 3179 | |
| 3180 | // This accessor applies the correct conversion from Smi, HeapNumber and |
| 3181 | // undefined and clamps the converted value between 0 and 255. |
| 3182 | Object* SetValue(uint32_t index, Object* value); |
| 3183 | |
| 3184 | // Casting. |
| 3185 | static inline ExternalPixelArray* cast(Object* obj); |
| 3186 | |
| 3187 | #ifdef OBJECT_PRINT |
| 3188 | inline void ExternalPixelArrayPrint() { |
| 3189 | ExternalPixelArrayPrint(stdout); |
| 3190 | } |
| 3191 | void ExternalPixelArrayPrint(FILE* out); |
| 3192 | #endif |
| 3193 | #ifdef DEBUG |
| 3194 | void ExternalPixelArrayVerify(); |
| 3195 | #endif // DEBUG |
| 3196 | |
| 3197 | private: |
| 3198 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalPixelArray); |
| 3199 | }; |
| 3200 | |
| 3201 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3202 | class ExternalByteArray: public ExternalArray { |
| 3203 | public: |
| 3204 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3205 | inline int8_t get_scalar(int index); |
| 3206 | inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3207 | inline void set(int index, int8_t value); |
| 3208 | |
| 3209 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3210 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3211 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3212 | |
| 3213 | // Casting. |
| 3214 | static inline ExternalByteArray* cast(Object* obj); |
| 3215 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3216 | #ifdef OBJECT_PRINT |
| 3217 | inline void ExternalByteArrayPrint() { |
| 3218 | ExternalByteArrayPrint(stdout); |
| 3219 | } |
| 3220 | void ExternalByteArrayPrint(FILE* out); |
| 3221 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3222 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3223 | void ExternalByteArrayVerify(); |
| 3224 | #endif // DEBUG |
| 3225 | |
| 3226 | private: |
| 3227 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalByteArray); |
| 3228 | }; |
| 3229 | |
| 3230 | |
| 3231 | class ExternalUnsignedByteArray: public ExternalArray { |
| 3232 | public: |
| 3233 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3234 | inline uint8_t get_scalar(int index); |
| 3235 | inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3236 | inline void set(int index, uint8_t value); |
| 3237 | |
| 3238 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3239 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3240 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3241 | |
| 3242 | // Casting. |
| 3243 | static inline ExternalUnsignedByteArray* cast(Object* obj); |
| 3244 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3245 | #ifdef OBJECT_PRINT |
| 3246 | inline void ExternalUnsignedByteArrayPrint() { |
| 3247 | ExternalUnsignedByteArrayPrint(stdout); |
| 3248 | } |
| 3249 | void ExternalUnsignedByteArrayPrint(FILE* out); |
| 3250 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3251 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3252 | void ExternalUnsignedByteArrayVerify(); |
| 3253 | #endif // DEBUG |
| 3254 | |
| 3255 | private: |
| 3256 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedByteArray); |
| 3257 | }; |
| 3258 | |
| 3259 | |
| 3260 | class ExternalShortArray: public ExternalArray { |
| 3261 | public: |
| 3262 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3263 | inline int16_t get_scalar(int index); |
| 3264 | inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3265 | inline void set(int index, int16_t value); |
| 3266 | |
| 3267 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3268 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3269 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3270 | |
| 3271 | // Casting. |
| 3272 | static inline ExternalShortArray* cast(Object* obj); |
| 3273 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3274 | #ifdef OBJECT_PRINT |
| 3275 | inline void ExternalShortArrayPrint() { |
| 3276 | ExternalShortArrayPrint(stdout); |
| 3277 | } |
| 3278 | void ExternalShortArrayPrint(FILE* out); |
| 3279 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3280 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3281 | void ExternalShortArrayVerify(); |
| 3282 | #endif // DEBUG |
| 3283 | |
| 3284 | private: |
| 3285 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalShortArray); |
| 3286 | }; |
| 3287 | |
| 3288 | |
| 3289 | class ExternalUnsignedShortArray: public ExternalArray { |
| 3290 | public: |
| 3291 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3292 | inline uint16_t get_scalar(int index); |
| 3293 | inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3294 | inline void set(int index, uint16_t value); |
| 3295 | |
| 3296 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3297 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3298 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3299 | |
| 3300 | // Casting. |
| 3301 | static inline ExternalUnsignedShortArray* cast(Object* obj); |
| 3302 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3303 | #ifdef OBJECT_PRINT |
| 3304 | inline void ExternalUnsignedShortArrayPrint() { |
| 3305 | ExternalUnsignedShortArrayPrint(stdout); |
| 3306 | } |
| 3307 | void ExternalUnsignedShortArrayPrint(FILE* out); |
| 3308 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3309 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3310 | void ExternalUnsignedShortArrayVerify(); |
| 3311 | #endif // DEBUG |
| 3312 | |
| 3313 | private: |
| 3314 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedShortArray); |
| 3315 | }; |
| 3316 | |
| 3317 | |
| 3318 | class ExternalIntArray: public ExternalArray { |
| 3319 | public: |
| 3320 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3321 | inline int32_t get_scalar(int index); |
| 3322 | inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3323 | inline void set(int index, int32_t value); |
| 3324 | |
| 3325 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3326 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3327 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3328 | |
| 3329 | // Casting. |
| 3330 | static inline ExternalIntArray* cast(Object* obj); |
| 3331 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3332 | #ifdef OBJECT_PRINT |
| 3333 | inline void ExternalIntArrayPrint() { |
| 3334 | ExternalIntArrayPrint(stdout); |
| 3335 | } |
| 3336 | void ExternalIntArrayPrint(FILE* out); |
| 3337 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3338 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3339 | void ExternalIntArrayVerify(); |
| 3340 | #endif // DEBUG |
| 3341 | |
| 3342 | private: |
| 3343 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalIntArray); |
| 3344 | }; |
| 3345 | |
| 3346 | |
| 3347 | class ExternalUnsignedIntArray: public ExternalArray { |
| 3348 | public: |
| 3349 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3350 | inline uint32_t get_scalar(int index); |
| 3351 | inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3352 | inline void set(int index, uint32_t value); |
| 3353 | |
| 3354 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3355 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3356 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3357 | |
| 3358 | // Casting. |
| 3359 | static inline ExternalUnsignedIntArray* cast(Object* obj); |
| 3360 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3361 | #ifdef OBJECT_PRINT |
| 3362 | inline void ExternalUnsignedIntArrayPrint() { |
| 3363 | ExternalUnsignedIntArrayPrint(stdout); |
| 3364 | } |
| 3365 | void ExternalUnsignedIntArrayPrint(FILE* out); |
| 3366 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3367 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3368 | void ExternalUnsignedIntArrayVerify(); |
| 3369 | #endif // DEBUG |
| 3370 | |
| 3371 | private: |
| 3372 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalUnsignedIntArray); |
| 3373 | }; |
| 3374 | |
| 3375 | |
| 3376 | class ExternalFloatArray: public ExternalArray { |
| 3377 | public: |
| 3378 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3379 | inline float get_scalar(int index); |
| 3380 | inline MaybeObject* get(int index); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3381 | inline void set(int index, float value); |
| 3382 | |
| 3383 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3384 | // and undefined. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 3385 | MaybeObject* SetValue(uint32_t index, Object* value); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3386 | |
| 3387 | // Casting. |
| 3388 | static inline ExternalFloatArray* cast(Object* obj); |
| 3389 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3390 | #ifdef OBJECT_PRINT |
| 3391 | inline void ExternalFloatArrayPrint() { |
| 3392 | ExternalFloatArrayPrint(stdout); |
| 3393 | } |
| 3394 | void ExternalFloatArrayPrint(FILE* out); |
| 3395 | #endif |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3396 | #ifdef DEBUG |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 3397 | void ExternalFloatArrayVerify(); |
| 3398 | #endif // DEBUG |
| 3399 | |
| 3400 | private: |
| 3401 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalFloatArray); |
| 3402 | }; |
| 3403 | |
| 3404 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3405 | class ExternalDoubleArray: public ExternalArray { |
| 3406 | public: |
| 3407 | // Setter and getter. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 3408 | inline double get_scalar(int index); |
| 3409 | inline MaybeObject* get(int index); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 3410 | inline void set(int index, double value); |
| 3411 | |
| 3412 | // This accessor applies the correct conversion from Smi, HeapNumber |
| 3413 | // and undefined. |
| 3414 | MaybeObject* SetValue(uint32_t index, Object* value); |
| 3415 | |
| 3416 | // Casting. |
| 3417 | static inline ExternalDoubleArray* cast(Object* obj); |
| 3418 | |
| 3419 | #ifdef OBJECT_PRINT |
| 3420 | inline void ExternalDoubleArrayPrint() { |
| 3421 | ExternalDoubleArrayPrint(stdout); |
| 3422 | } |
| 3423 | void ExternalDoubleArrayPrint(FILE* out); |
| 3424 | #endif // OBJECT_PRINT |
| 3425 | #ifdef DEBUG |
| 3426 | void ExternalDoubleArrayVerify(); |
| 3427 | #endif // DEBUG |
| 3428 | |
| 3429 | private: |
| 3430 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalDoubleArray); |
| 3431 | }; |
| 3432 | |
| 3433 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3434 | // DeoptimizationInputData is a fixed array used to hold the deoptimization |
| 3435 | // data for code generated by the Hydrogen/Lithium compiler. It also |
| 3436 | // contains information about functions that were inlined. If N different |
| 3437 | // functions were inlined then first N elements of the literal array will |
| 3438 | // contain these functions. |
| 3439 | // |
| 3440 | // It can be empty. |
| 3441 | class DeoptimizationInputData: public FixedArray { |
| 3442 | public: |
| 3443 | // Layout description. Indices in the array. |
| 3444 | static const int kTranslationByteArrayIndex = 0; |
| 3445 | static const int kInlinedFunctionCountIndex = 1; |
| 3446 | static const int kLiteralArrayIndex = 2; |
| 3447 | static const int kOsrAstIdIndex = 3; |
| 3448 | static const int kOsrPcOffsetIndex = 4; |
| 3449 | static const int kFirstDeoptEntryIndex = 5; |
| 3450 | |
| 3451 | // Offsets of deopt entry elements relative to the start of the entry. |
| 3452 | static const int kAstIdOffset = 0; |
| 3453 | static const int kTranslationIndexOffset = 1; |
| 3454 | static const int kArgumentsStackHeightOffset = 2; |
| 3455 | static const int kDeoptEntrySize = 3; |
| 3456 | |
| 3457 | // Simple element accessors. |
| 3458 | #define DEFINE_ELEMENT_ACCESSORS(name, type) \ |
| 3459 | type* name() { \ |
| 3460 | return type::cast(get(k##name##Index)); \ |
| 3461 | } \ |
| 3462 | void Set##name(type* value) { \ |
| 3463 | set(k##name##Index, value); \ |
| 3464 | } |
| 3465 | |
| 3466 | DEFINE_ELEMENT_ACCESSORS(TranslationByteArray, ByteArray) |
| 3467 | DEFINE_ELEMENT_ACCESSORS(InlinedFunctionCount, Smi) |
| 3468 | DEFINE_ELEMENT_ACCESSORS(LiteralArray, FixedArray) |
| 3469 | DEFINE_ELEMENT_ACCESSORS(OsrAstId, Smi) |
| 3470 | DEFINE_ELEMENT_ACCESSORS(OsrPcOffset, Smi) |
| 3471 | |
| 3472 | // Unchecked accessor to be used during GC. |
| 3473 | FixedArray* UncheckedLiteralArray() { |
| 3474 | return reinterpret_cast<FixedArray*>(get(kLiteralArrayIndex)); |
| 3475 | } |
| 3476 | |
| 3477 | #undef DEFINE_ELEMENT_ACCESSORS |
| 3478 | |
| 3479 | // Accessors for elements of the ith deoptimization entry. |
| 3480 | #define DEFINE_ENTRY_ACCESSORS(name, type) \ |
| 3481 | type* name(int i) { \ |
| 3482 | return type::cast(get(IndexForEntry(i) + k##name##Offset)); \ |
| 3483 | } \ |
| 3484 | void Set##name(int i, type* value) { \ |
| 3485 | set(IndexForEntry(i) + k##name##Offset, value); \ |
| 3486 | } |
| 3487 | |
| 3488 | DEFINE_ENTRY_ACCESSORS(AstId, Smi) |
| 3489 | DEFINE_ENTRY_ACCESSORS(TranslationIndex, Smi) |
| 3490 | DEFINE_ENTRY_ACCESSORS(ArgumentsStackHeight, Smi) |
| 3491 | |
| 3492 | #undef DEFINE_ENTRY_ACCESSORS |
| 3493 | |
| 3494 | int DeoptCount() { |
| 3495 | return (length() - kFirstDeoptEntryIndex) / kDeoptEntrySize; |
| 3496 | } |
| 3497 | |
| 3498 | // Allocates a DeoptimizationInputData. |
| 3499 | MUST_USE_RESULT static MaybeObject* Allocate(int deopt_entry_count, |
| 3500 | PretenureFlag pretenure); |
| 3501 | |
| 3502 | // Casting. |
| 3503 | static inline DeoptimizationInputData* cast(Object* obj); |
| 3504 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 3505 | #ifdef ENABLE_DISASSEMBLER |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3506 | void DeoptimizationInputDataPrint(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3507 | #endif |
| 3508 | |
| 3509 | private: |
| 3510 | static int IndexForEntry(int i) { |
| 3511 | return kFirstDeoptEntryIndex + (i * kDeoptEntrySize); |
| 3512 | } |
| 3513 | |
| 3514 | static int LengthFor(int entry_count) { |
| 3515 | return IndexForEntry(entry_count); |
| 3516 | } |
| 3517 | }; |
| 3518 | |
| 3519 | |
| 3520 | // DeoptimizationOutputData is a fixed array used to hold the deoptimization |
| 3521 | // data for code generated by the full compiler. |
| 3522 | // The format of the these objects is |
| 3523 | // [i * 2]: Ast ID for ith deoptimization. |
| 3524 | // [i * 2 + 1]: PC and state of ith deoptimization |
| 3525 | class DeoptimizationOutputData: public FixedArray { |
| 3526 | public: |
| 3527 | int DeoptPoints() { return length() / 2; } |
| 3528 | Smi* AstId(int index) { return Smi::cast(get(index * 2)); } |
| 3529 | void SetAstId(int index, Smi* id) { set(index * 2, id); } |
| 3530 | Smi* PcAndState(int index) { return Smi::cast(get(1 + index * 2)); } |
| 3531 | void SetPcAndState(int index, Smi* offset) { set(1 + index * 2, offset); } |
| 3532 | |
| 3533 | static int LengthOfFixedArray(int deopt_points) { |
| 3534 | return deopt_points * 2; |
| 3535 | } |
| 3536 | |
| 3537 | // Allocates a DeoptimizationOutputData. |
| 3538 | MUST_USE_RESULT static MaybeObject* Allocate(int number_of_deopt_points, |
| 3539 | PretenureFlag pretenure); |
| 3540 | |
| 3541 | // Casting. |
| 3542 | static inline DeoptimizationOutputData* cast(Object* obj); |
| 3543 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3544 | #if defined(OBJECT_PRINT) || defined(ENABLE_DISASSEMBLER) |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3545 | void DeoptimizationOutputDataPrint(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3546 | #endif |
| 3547 | }; |
| 3548 | |
| 3549 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3550 | class SafepointEntry; |
| 3551 | |
| 3552 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3553 | // Code describes objects with on-the-fly generated machine code. |
| 3554 | class Code: public HeapObject { |
| 3555 | public: |
| 3556 | // Opaque data type for encapsulating code flags like kind, inline |
| 3557 | // cache state, and arguments count. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3558 | // FLAGS_MIN_VALUE and FLAGS_MAX_VALUE are specified to ensure that |
| 3559 | // enumeration type has correct value range (see Issue 830 for more details). |
| 3560 | enum Flags { |
| 3561 | FLAGS_MIN_VALUE = kMinInt, |
| 3562 | FLAGS_MAX_VALUE = kMaxInt |
| 3563 | }; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3564 | |
| 3565 | enum Kind { |
| 3566 | FUNCTION, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3567 | OPTIMIZED_FUNCTION, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3568 | STUB, |
| 3569 | BUILTIN, |
| 3570 | LOAD_IC, |
| 3571 | KEYED_LOAD_IC, |
| 3572 | CALL_IC, |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3573 | KEYED_CALL_IC, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3574 | STORE_IC, |
| 3575 | KEYED_STORE_IC, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3576 | UNARY_OP_IC, |
| 3577 | BINARY_OP_IC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3578 | COMPARE_IC, |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3579 | TO_BOOLEAN_IC, |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3580 | // No more than 16 kinds. The value currently encoded in four bits in |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3581 | // Flags. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3582 | |
| 3583 | // Pseudo-kinds. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 3584 | REGEXP = BUILTIN, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3585 | FIRST_IC_KIND = LOAD_IC, |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3586 | LAST_IC_KIND = TO_BOOLEAN_IC |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3587 | }; |
| 3588 | |
| 3589 | enum { |
fschneider@chromium.org | ed78ffd | 2010-07-21 11:05:19 +0000 | [diff] [blame] | 3590 | NUMBER_OF_KINDS = LAST_IC_KIND + 1 |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3591 | }; |
| 3592 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3593 | typedef int ExtraICState; |
| 3594 | |
| 3595 | static const ExtraICState kNoExtraICState = 0; |
| 3596 | |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 3597 | #ifdef ENABLE_DISASSEMBLER |
| 3598 | // Printing |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3599 | static const char* Kind2String(Kind kind); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 3600 | static const char* ICState2String(InlineCacheState state); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3601 | static const char* PropertyType2String(PropertyType type); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 3602 | static void PrintExtraICState(FILE* out, Kind kind, ExtraICState extra); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3603 | inline void Disassemble(const char* name) { |
| 3604 | Disassemble(name, stdout); |
| 3605 | } |
| 3606 | void Disassemble(const char* name, FILE* out); |
mads.s.ager@gmail.com | 769cc96 | 2008-08-06 10:02:49 +0000 | [diff] [blame] | 3607 | #endif // ENABLE_DISASSEMBLER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3608 | |
| 3609 | // [instruction_size]: Size of the native instructions |
| 3610 | inline int instruction_size(); |
| 3611 | inline void set_instruction_size(int value); |
| 3612 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3613 | // [relocation_info]: Code relocation information |
| 3614 | DECL_ACCESSORS(relocation_info, ByteArray) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3615 | void InvalidateRelocation(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3616 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3617 | // [deoptimization_data]: Array containing data for deopt. |
| 3618 | DECL_ACCESSORS(deoptimization_data, FixedArray) |
| 3619 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3620 | // [code_flushing_candidate]: Field only used during garbage |
| 3621 | // collection to hold code flushing candidates. The contents of this |
| 3622 | // field does not have to be traced during garbage collection since |
| 3623 | // it is only used by the garbage collector itself. |
| 3624 | DECL_ACCESSORS(next_code_flushing_candidate, Object) |
| 3625 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3626 | // Unchecked accessors to be used during GC. |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3627 | inline ByteArray* unchecked_relocation_info(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3628 | inline FixedArray* unchecked_deoptimization_data(); |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3629 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3630 | inline int relocation_size(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3631 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3632 | // [flags]: Various code flags. |
| 3633 | inline Flags flags(); |
| 3634 | inline void set_flags(Flags flags); |
| 3635 | |
| 3636 | // [flags]: Access to specific code flags. |
| 3637 | inline Kind kind(); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3638 | inline InlineCacheState ic_state(); // Only valid for IC stubs. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3639 | inline ExtraICState extra_ic_state(); // Only valid for IC stubs. |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 3640 | inline InLoopFlag ic_in_loop(); // Only valid for IC stubs. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3641 | inline PropertyType type(); // Only valid for monomorphic IC stubs. |
| 3642 | inline int arguments_count(); // Only valid for call IC stubs. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3643 | |
| 3644 | // Testers for IC stub kinds. |
| 3645 | inline bool is_inline_cache_stub(); |
| 3646 | inline bool is_load_stub() { return kind() == LOAD_IC; } |
| 3647 | inline bool is_keyed_load_stub() { return kind() == KEYED_LOAD_IC; } |
| 3648 | inline bool is_store_stub() { return kind() == STORE_IC; } |
| 3649 | inline bool is_keyed_store_stub() { return kind() == KEYED_STORE_IC; } |
| 3650 | inline bool is_call_stub() { return kind() == CALL_IC; } |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3651 | inline bool is_keyed_call_stub() { return kind() == KEYED_CALL_IC; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3652 | inline bool is_unary_op_stub() { return kind() == UNARY_OP_IC; } |
| 3653 | inline bool is_binary_op_stub() { return kind() == BINARY_OP_IC; } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3654 | inline bool is_compare_ic_stub() { return kind() == COMPARE_IC; } |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3655 | inline bool is_to_boolean_ic_stub() { return kind() == TO_BOOLEAN_IC; } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3656 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3657 | // [major_key]: For kind STUB or BINARY_OP_IC, the major key. |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3658 | inline int major_key(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3659 | inline void set_major_key(int value); |
| 3660 | |
| 3661 | // [optimizable]: For FUNCTION kind, tells if it is optimizable. |
| 3662 | inline bool optimizable(); |
| 3663 | inline void set_optimizable(bool value); |
| 3664 | |
| 3665 | // [has_deoptimization_support]: For FUNCTION kind, tells if it has |
| 3666 | // deoptimization support. |
| 3667 | inline bool has_deoptimization_support(); |
| 3668 | inline void set_has_deoptimization_support(bool value); |
| 3669 | |
| 3670 | // [allow_osr_at_loop_nesting_level]: For FUNCTION kind, tells for |
| 3671 | // how long the function has been marked for OSR and therefore which |
| 3672 | // level of loop nesting we are willing to do on-stack replacement |
| 3673 | // for. |
| 3674 | inline void set_allow_osr_at_loop_nesting_level(int level); |
| 3675 | inline int allow_osr_at_loop_nesting_level(); |
| 3676 | |
| 3677 | // [stack_slots]: For kind OPTIMIZED_FUNCTION, the number of stack slots |
| 3678 | // reserved in the code prologue. |
| 3679 | inline unsigned stack_slots(); |
| 3680 | inline void set_stack_slots(unsigned slots); |
| 3681 | |
| 3682 | // [safepoint_table_start]: For kind OPTIMIZED_CODE, the offset in |
| 3683 | // the instruction stream where the safepoint table starts. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3684 | inline unsigned safepoint_table_offset(); |
| 3685 | inline void set_safepoint_table_offset(unsigned offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3686 | |
| 3687 | // [stack_check_table_start]: For kind FUNCTION, the offset in the |
| 3688 | // instruction stream where the stack check table starts. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3689 | inline unsigned stack_check_table_offset(); |
| 3690 | inline void set_stack_check_table_offset(unsigned offset); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3691 | |
| 3692 | // [check type]: For kind CALL_IC, tells how to check if the |
| 3693 | // receiver is valid for the given call. |
| 3694 | inline CheckType check_type(); |
| 3695 | inline void set_check_type(CheckType value); |
| 3696 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3697 | // [type-recording unary op type]: For kind UNARY_OP_IC. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3698 | inline byte unary_op_type(); |
| 3699 | inline void set_unary_op_type(byte value); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3700 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3701 | // [type-recording binary op type]: For kind BINARY_OP_IC. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3702 | inline byte binary_op_type(); |
| 3703 | inline void set_binary_op_type(byte value); |
| 3704 | inline byte binary_op_result_type(); |
| 3705 | inline void set_binary_op_result_type(byte value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3706 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3707 | // [compare state]: For kind COMPARE_IC, tells what state the stub is in. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3708 | inline byte compare_state(); |
| 3709 | inline void set_compare_state(byte value); |
| 3710 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3711 | // [to_boolean_foo]: For kind TO_BOOLEAN_IC tells what state the stub is in. |
| 3712 | inline byte to_boolean_state(); |
| 3713 | inline void set_to_boolean_state(byte value); |
| 3714 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 3715 | // Get the safepoint entry for the given pc. |
| 3716 | SafepointEntry GetSafepointEntry(Address pc); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3717 | |
| 3718 | // Mark this code object as not having a stack check table. Assumes kind |
| 3719 | // is FUNCTION. |
| 3720 | void SetNoStackCheckTable(); |
| 3721 | |
| 3722 | // Find the first map in an IC stub. |
| 3723 | Map* FindFirstMap(); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3724 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3725 | // Flags operations. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3726 | static inline Flags ComputeFlags( |
| 3727 | Kind kind, |
| 3728 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3729 | InlineCacheState ic_state = UNINITIALIZED, |
| 3730 | ExtraICState extra_ic_state = kNoExtraICState, |
| 3731 | PropertyType type = NORMAL, |
| 3732 | int argc = -1, |
| 3733 | InlineCacheHolderFlag holder = OWN_MAP); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3734 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3735 | static inline Flags ComputeMonomorphicFlags( |
| 3736 | Kind kind, |
| 3737 | PropertyType type, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3738 | ExtraICState extra_ic_state = kNoExtraICState, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3739 | InlineCacheHolderFlag holder = OWN_MAP, |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3740 | InLoopFlag in_loop = NOT_IN_LOOP, |
| 3741 | int argc = -1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3742 | |
| 3743 | static inline Kind ExtractKindFromFlags(Flags flags); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3744 | static inline InlineCacheState ExtractICStateFromFlags(Flags flags); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3745 | static inline ExtraICState ExtractExtraICStateFromFlags(Flags flags); |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3746 | static inline InLoopFlag ExtractICInLoopFromFlags(Flags flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3747 | static inline PropertyType ExtractTypeFromFlags(Flags flags); |
| 3748 | static inline int ExtractArgumentsCountFromFlags(Flags flags); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3749 | static inline InlineCacheHolderFlag ExtractCacheHolderFromFlags(Flags flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3750 | static inline Flags RemoveTypeFromFlags(Flags flags); |
| 3751 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 3752 | // Convert a target address into a code object. |
| 3753 | static inline Code* GetCodeFromTargetAddress(Address address); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3754 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3755 | // Convert an entry address into an object. |
| 3756 | static inline Object* GetObjectFromEntryAddress(Address location_of_address); |
| 3757 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3758 | // Returns the address of the first instruction. |
| 3759 | inline byte* instruction_start(); |
| 3760 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3761 | // Returns the address right after the last instruction. |
| 3762 | inline byte* instruction_end(); |
| 3763 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3764 | // Returns the size of the instructions, padding, and relocation information. |
| 3765 | inline int body_size(); |
| 3766 | |
| 3767 | // Returns the address of the first relocation info (read backwards!). |
| 3768 | inline byte* relocation_start(); |
| 3769 | |
| 3770 | // Code entry point. |
| 3771 | inline byte* entry(); |
| 3772 | |
| 3773 | // Returns true if pc is inside this object's instructions. |
| 3774 | inline bool contains(byte* pc); |
| 3775 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3776 | // Relocate the code by delta bytes. Called to signal that this code |
| 3777 | // object has been moved by delta bytes. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3778 | void Relocate(intptr_t delta); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3779 | |
| 3780 | // Migrate code described by desc. |
| 3781 | void CopyFrom(const CodeDesc& desc); |
| 3782 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3783 | // Returns the object size for a given body (used for allocation). |
| 3784 | static int SizeFor(int body_size) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3785 | ASSERT_SIZE_TAG_ALIGNED(body_size); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3786 | return RoundUp(kHeaderSize + body_size, kCodeAlignment); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3789 | // Calculate the size of the code object to report for log events. This takes |
| 3790 | // the layout of the code object into account. |
| 3791 | int ExecutableSize() { |
| 3792 | // Check that the assumptions about the layout of the code object holds. |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 3793 | ASSERT_EQ(static_cast<int>(instruction_start() - address()), |
| 3794 | Code::kHeaderSize); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3795 | return instruction_size() + Code::kHeaderSize; |
| 3796 | } |
| 3797 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3798 | // Locating source position. |
| 3799 | int SourcePosition(Address pc); |
| 3800 | int SourceStatementPosition(Address pc); |
| 3801 | |
| 3802 | // Casting. |
| 3803 | static inline Code* cast(Object* obj); |
| 3804 | |
| 3805 | // Dispatched behavior. |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 3806 | int CodeSize() { return SizeFor(body_size()); } |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 3807 | inline void CodeIterateBody(ObjectVisitor* v); |
| 3808 | |
| 3809 | template<typename StaticVisitor> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3810 | inline void CodeIterateBody(Heap* heap); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 3811 | #ifdef OBJECT_PRINT |
| 3812 | inline void CodePrint() { |
| 3813 | CodePrint(stdout); |
| 3814 | } |
| 3815 | void CodePrint(FILE* out); |
| 3816 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3817 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3818 | void CodeVerify(); |
| 3819 | #endif |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3820 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 3821 | // Returns the isolate/heap this code object belongs to. |
| 3822 | inline Isolate* isolate(); |
| 3823 | inline Heap* heap(); |
| 3824 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3825 | // Max loop nesting marker used to postpose OSR. We don't take loop |
| 3826 | // nesting that is deeper than 5 levels into account. |
| 3827 | static const int kMaxLoopNestingMarker = 6; |
| 3828 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3829 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 3830 | static const int kInstructionSizeOffset = HeapObject::kHeaderSize; |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 3831 | static const int kRelocationInfoOffset = kInstructionSizeOffset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3832 | static const int kDeoptimizationDataOffset = |
| 3833 | kRelocationInfoOffset + kPointerSize; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3834 | static const int kNextCodeFlushingCandidateOffset = |
| 3835 | kDeoptimizationDataOffset + kPointerSize; |
| 3836 | static const int kFlagsOffset = |
| 3837 | kNextCodeFlushingCandidateOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3838 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3839 | static const int kKindSpecificFlagsOffset = kFlagsOffset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3840 | static const int kKindSpecificFlagsSize = 2 * kIntSize; |
| 3841 | |
| 3842 | static const int kHeaderPaddingStart = kKindSpecificFlagsOffset + |
| 3843 | kKindSpecificFlagsSize; |
| 3844 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3845 | // Add padding to align the instruction start following right after |
kasperl@chromium.org | 061ef74 | 2009-02-27 12:16:20 +0000 | [diff] [blame] | 3846 | // the Code object header. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3847 | static const int kHeaderSize = |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3848 | (kHeaderPaddingStart + kCodeAlignmentMask) & ~kCodeAlignmentMask; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3849 | |
| 3850 | // Byte offsets within kKindSpecificFlagsOffset. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3851 | static const int kStubMajorKeyOffset = kKindSpecificFlagsOffset; |
| 3852 | static const int kOptimizableOffset = kKindSpecificFlagsOffset; |
| 3853 | static const int kStackSlotsOffset = kKindSpecificFlagsOffset; |
| 3854 | static const int kCheckTypeOffset = kKindSpecificFlagsOffset; |
| 3855 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3856 | static const int kUnaryOpTypeOffset = kStubMajorKeyOffset + 1; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3857 | static const int kBinaryOpTypeOffset = kStubMajorKeyOffset + 1; |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3858 | static const int kCompareStateOffset = kStubMajorKeyOffset + 1; |
| 3859 | static const int kToBooleanTypeOffset = kStubMajorKeyOffset + 1; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3860 | static const int kHasDeoptimizationSupportOffset = kOptimizableOffset + 1; |
| 3861 | |
| 3862 | static const int kBinaryOpReturnTypeOffset = kBinaryOpTypeOffset + 1; |
| 3863 | static const int kAllowOSRAtLoopNestingLevelOffset = |
| 3864 | kHasDeoptimizationSupportOffset + 1; |
| 3865 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3866 | static const int kSafepointTableOffsetOffset = kStackSlotsOffset + kIntSize; |
| 3867 | static const int kStackCheckTableOffsetOffset = kStackSlotsOffset + kIntSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3868 | |
| 3869 | // Flags layout. |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3870 | static const int kFlagsICStateShift = 0; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3871 | static const int kFlagsICInLoopShift = 3; |
whesse@chromium.org | 2c186ca | 2010-06-16 11:32:39 +0000 | [diff] [blame] | 3872 | static const int kFlagsTypeShift = 4; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3873 | static const int kFlagsKindShift = 8; |
| 3874 | static const int kFlagsICHolderShift = 12; |
| 3875 | static const int kFlagsExtraICStateShift = 13; |
| 3876 | static const int kFlagsArgumentsCountShift = 15; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3877 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3878 | static const int kFlagsICStateMask = 0x00000007; // 00000000111 |
| 3879 | static const int kFlagsICInLoopMask = 0x00000008; // 00000001000 |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3880 | static const int kFlagsTypeMask = 0x000000F0; // 00001110000 |
| 3881 | static const int kFlagsKindMask = 0x00000F00; // 11110000000 |
| 3882 | static const int kFlagsCacheInPrototypeMapMask = 0x00001000; |
| 3883 | static const int kFlagsExtraICStateMask = 0x00006000; |
| 3884 | static const int kFlagsArgumentsCountMask = 0xFFFF8000; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 3885 | |
| 3886 | static const int kFlagsNotUsedInLookup = |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3887 | (kFlagsICInLoopMask | kFlagsTypeMask | kFlagsCacheInPrototypeMapMask); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3888 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3889 | private: |
| 3890 | DISALLOW_IMPLICIT_CONSTRUCTORS(Code); |
| 3891 | }; |
| 3892 | |
| 3893 | |
| 3894 | // All heap objects have a Map that describes their structure. |
| 3895 | // A Map contains information about: |
| 3896 | // - Size information about the object |
| 3897 | // - How to iterate over an object (for garbage collection) |
| 3898 | class Map: public HeapObject { |
| 3899 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3900 | // Instance size. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3901 | // Size in bytes or kVariableSizeSentinel if instances do not have |
| 3902 | // a fixed size. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3903 | inline int instance_size(); |
| 3904 | inline void set_instance_size(int value); |
| 3905 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 3906 | // Count of properties allocated in the object. |
| 3907 | inline int inobject_properties(); |
| 3908 | inline void set_inobject_properties(int value); |
| 3909 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3910 | // Count of property fields pre-allocated in the object when first allocated. |
| 3911 | inline int pre_allocated_property_fields(); |
| 3912 | inline void set_pre_allocated_property_fields(int value); |
| 3913 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3914 | // Instance type. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3915 | inline InstanceType instance_type(); |
| 3916 | inline void set_instance_type(InstanceType value); |
| 3917 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3918 | // Tells how many unused property fields are available in the |
| 3919 | // instance (only used for JSObject in fast mode). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3920 | inline int unused_property_fields(); |
| 3921 | inline void set_unused_property_fields(int value); |
| 3922 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 3923 | // Bit field. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3924 | inline byte bit_field(); |
| 3925 | inline void set_bit_field(byte value); |
| 3926 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 3927 | // Bit field 2. |
| 3928 | inline byte bit_field2(); |
| 3929 | inline void set_bit_field2(byte value); |
| 3930 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3931 | // Bit field 3. |
| 3932 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 3933 | // without overloading the instance descriptors field (and storing it in the |
| 3934 | // DescriptorArray when the map has one). |
| 3935 | inline int bit_field3(); |
| 3936 | inline void set_bit_field3(int value); |
| 3937 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3938 | // Tells whether the object in the prototype property will be used |
| 3939 | // for instances created from this function. If the prototype |
| 3940 | // property is set to a value that is not a JSObject, the prototype |
| 3941 | // property will not be used to create instances of the function. |
| 3942 | // See ECMA-262, 13.2.2. |
| 3943 | inline void set_non_instance_prototype(bool value); |
| 3944 | inline bool has_non_instance_prototype(); |
| 3945 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 3946 | // Tells whether function has special prototype property. If not, prototype |
| 3947 | // property will not be created when accessed (will return undefined), |
| 3948 | // and construction from this function will not be allowed. |
| 3949 | inline void set_function_with_prototype(bool value); |
| 3950 | inline bool function_with_prototype(); |
| 3951 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3952 | // Tells whether the instance with this map should be ignored by the |
| 3953 | // __proto__ accessor. |
| 3954 | inline void set_is_hidden_prototype() { |
| 3955 | set_bit_field(bit_field() | (1 << kIsHiddenPrototype)); |
| 3956 | } |
| 3957 | |
| 3958 | inline bool is_hidden_prototype() { |
| 3959 | return ((1 << kIsHiddenPrototype) & bit_field()) != 0; |
| 3960 | } |
| 3961 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3962 | // Records and queries whether the instance has a named interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3963 | inline void set_has_named_interceptor() { |
| 3964 | set_bit_field(bit_field() | (1 << kHasNamedInterceptor)); |
| 3965 | } |
| 3966 | |
| 3967 | inline bool has_named_interceptor() { |
| 3968 | return ((1 << kHasNamedInterceptor) & bit_field()) != 0; |
| 3969 | } |
| 3970 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 3971 | // Records and queries whether the instance has an indexed interceptor. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3972 | inline void set_has_indexed_interceptor() { |
| 3973 | set_bit_field(bit_field() | (1 << kHasIndexedInterceptor)); |
| 3974 | } |
| 3975 | |
| 3976 | inline bool has_indexed_interceptor() { |
| 3977 | return ((1 << kHasIndexedInterceptor) & bit_field()) != 0; |
| 3978 | } |
| 3979 | |
| 3980 | // Tells whether the instance is undetectable. |
| 3981 | // An undetectable object is a special class of JSObject: 'typeof' operator |
| 3982 | // returns undefined, ToBoolean returns false. Otherwise it behaves like |
| 3983 | // a normal JS object. It is useful for implementing undetectable |
| 3984 | // document.all in Firefox & Safari. |
| 3985 | // See https://bugzilla.mozilla.org/show_bug.cgi?id=248549. |
| 3986 | inline void set_is_undetectable() { |
| 3987 | set_bit_field(bit_field() | (1 << kIsUndetectable)); |
| 3988 | } |
| 3989 | |
| 3990 | inline bool is_undetectable() { |
| 3991 | return ((1 << kIsUndetectable) & bit_field()) != 0; |
| 3992 | } |
| 3993 | |
| 3994 | // Tells whether the instance has a call-as-function handler. |
| 3995 | inline void set_has_instance_call_handler() { |
| 3996 | set_bit_field(bit_field() | (1 << kHasInstanceCallHandler)); |
| 3997 | } |
| 3998 | |
| 3999 | inline bool has_instance_call_handler() { |
| 4000 | return ((1 << kHasInstanceCallHandler) & bit_field()) != 0; |
| 4001 | } |
| 4002 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 4003 | inline void set_is_extensible(bool value); |
| 4004 | inline bool is_extensible(); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 4005 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4006 | inline void set_elements_kind(JSObject::ElementsKind elements_kind) { |
| 4007 | ASSERT(elements_kind < JSObject::kElementsKindCount); |
| 4008 | ASSERT(JSObject::kElementsKindCount <= (1 << kElementsKindBitCount)); |
| 4009 | set_bit_field2((bit_field2() & ~kElementsKindMask) | |
| 4010 | (elements_kind << kElementsKindShift)); |
| 4011 | ASSERT(this->elements_kind() == elements_kind); |
| 4012 | } |
| 4013 | |
| 4014 | inline JSObject::ElementsKind elements_kind() { |
| 4015 | return static_cast<JSObject::ElementsKind>( |
| 4016 | (bit_field2() & kElementsKindMask) >> kElementsKindShift); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4017 | } |
| 4018 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4019 | // Tells whether the instance has fast elements. |
| 4020 | // Equivalent to instance->GetElementsKind() == FAST_ELEMENTS. |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4021 | inline bool has_fast_elements() { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4022 | return elements_kind() == JSObject::FAST_ELEMENTS; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4023 | } |
| 4024 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4025 | inline bool has_fast_double_elements() { |
| 4026 | return elements_kind() == JSObject::FAST_DOUBLE_ELEMENTS; |
| 4027 | } |
| 4028 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4029 | inline bool has_external_array_elements() { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4030 | JSObject::ElementsKind kind(elements_kind()); |
| 4031 | return kind >= JSObject::FIRST_EXTERNAL_ARRAY_ELEMENTS_KIND && |
| 4032 | kind <= JSObject::LAST_EXTERNAL_ARRAY_ELEMENTS_KIND; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4033 | } |
| 4034 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 4035 | inline bool has_dictionary_elements() { |
| 4036 | return elements_kind() == JSObject::DICTIONARY_ELEMENTS; |
| 4037 | } |
| 4038 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4039 | // Tells whether the map is attached to SharedFunctionInfo |
| 4040 | // (for inobject slack tracking). |
| 4041 | inline void set_attached_to_shared_function_info(bool value); |
| 4042 | |
| 4043 | inline bool attached_to_shared_function_info(); |
| 4044 | |
| 4045 | // Tells whether the map is shared between objects that may have different |
| 4046 | // behavior. If true, the map should never be modified, instead a clone |
| 4047 | // should be created and modified. |
| 4048 | inline void set_is_shared(bool value); |
| 4049 | |
| 4050 | inline bool is_shared(); |
| 4051 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4052 | // Tells whether the instance needs security checks when accessing its |
| 4053 | // properties. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4054 | inline void set_is_access_check_needed(bool access_check_needed); |
| 4055 | inline bool is_access_check_needed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4056 | |
| 4057 | // [prototype]: implicit prototype object. |
| 4058 | DECL_ACCESSORS(prototype, Object) |
| 4059 | |
| 4060 | // [constructor]: points back to the function responsible for this map. |
| 4061 | DECL_ACCESSORS(constructor, Object) |
| 4062 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4063 | inline JSFunction* unchecked_constructor(); |
| 4064 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4065 | // Should only be called by the code that initializes map to set initial valid |
| 4066 | // value of the instance descriptor member. |
| 4067 | inline void init_instance_descriptors(); |
| 4068 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4069 | // [instance descriptors]: describes the object. |
| 4070 | DECL_ACCESSORS(instance_descriptors, DescriptorArray) |
| 4071 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4072 | // Sets the instance descriptor array for the map to be an empty descriptor |
| 4073 | // array. |
| 4074 | inline void clear_instance_descriptors(); |
| 4075 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4076 | // [stub cache]: contains stubs compiled for this map. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4077 | DECL_ACCESSORS(code_cache, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4078 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4079 | // [prototype transitions]: cache of prototype transitions. |
| 4080 | // Prototype transition is a transition that happens |
| 4081 | // when we change object's prototype to a new one. |
| 4082 | // Cache format: |
| 4083 | // 0: finger - index of the first free cell in the cache |
| 4084 | // 1 + 2 * i: prototype |
| 4085 | // 2 + 2 * i: target map |
| 4086 | DECL_ACCESSORS(prototype_transitions, FixedArray) |
| 4087 | inline FixedArray* unchecked_prototype_transitions(); |
| 4088 | |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4089 | static const int kProtoTransitionHeaderSize = 1; |
| 4090 | static const int kProtoTransitionNumberOfEntriesOffset = 0; |
| 4091 | static const int kProtoTransitionElementsPerEntry = 2; |
| 4092 | static const int kProtoTransitionPrototypeOffset = 0; |
| 4093 | static const int kProtoTransitionMapOffset = 1; |
| 4094 | |
| 4095 | inline int NumberOfProtoTransitions() { |
| 4096 | FixedArray* cache = unchecked_prototype_transitions(); |
| 4097 | if (cache->length() == 0) return 0; |
| 4098 | return |
| 4099 | Smi::cast(cache->get(kProtoTransitionNumberOfEntriesOffset))->value(); |
| 4100 | } |
| 4101 | |
| 4102 | inline void SetNumberOfProtoTransitions(int value) { |
| 4103 | FixedArray* cache = unchecked_prototype_transitions(); |
| 4104 | ASSERT(cache->length() != 0); |
| 4105 | cache->set_unchecked(kProtoTransitionNumberOfEntriesOffset, |
| 4106 | Smi::FromInt(value)); |
| 4107 | } |
| 4108 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4109 | // Lookup in the map's instance descriptors and fill out the result |
| 4110 | // with the given holder if the name is found. The holder may be |
| 4111 | // NULL when this function is used from the compiler. |
| 4112 | void LookupInDescriptors(JSObject* holder, |
| 4113 | String* name, |
| 4114 | LookupResult* result); |
| 4115 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4116 | MUST_USE_RESULT MaybeObject* CopyDropDescriptors(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4117 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4118 | MUST_USE_RESULT MaybeObject* CopyNormalized(PropertyNormalizationMode mode, |
| 4119 | NormalizedMapSharingMode sharing); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4120 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4121 | // Returns a copy of the map, with all transitions dropped from the |
| 4122 | // instance descriptors. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4123 | MUST_USE_RESULT MaybeObject* CopyDropTransitions(); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 4124 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4125 | // Returns this map if it already has elements that are fast, otherwise |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4126 | // returns a copy of the map, with all transitions dropped from the |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4127 | // descriptors and the ElementsKind set to FAST_ELEMENTS. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4128 | MUST_USE_RESULT inline MaybeObject* GetFastElementsMap(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4129 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4130 | // Returns this map if it already has fast elements that are doubles, |
| 4131 | // otherwise returns a copy of the map, with all transitions dropped from the |
| 4132 | // descriptors and the ElementsKind set to FAST_DOUBLE_ELEMENTS. |
| 4133 | MUST_USE_RESULT inline MaybeObject* GetFastDoubleElementsMap(); |
| 4134 | |
| 4135 | // Returns this map if already has dictionary elements, otherwise returns a |
| 4136 | // copy of the map, with all transitions dropped from the descriptors and the |
| 4137 | // ElementsKind set to DICTIONARY_ELEMENTS. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4138 | MUST_USE_RESULT inline MaybeObject* GetSlowElementsMap(); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 4139 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4140 | // Returns a new map with all transitions dropped from the descriptors and the |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4141 | // ElementsKind set to one of the value corresponding to array_type. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4142 | MUST_USE_RESULT MaybeObject* GetExternalArrayElementsMap( |
| 4143 | ExternalArrayType array_type, |
| 4144 | bool safe_to_add_transition); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 4145 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4146 | // Returns the property index for name (only valid for FAST MODE). |
| 4147 | int PropertyIndexFor(String* name); |
| 4148 | |
| 4149 | // Returns the next free property index (only valid for FAST MODE). |
| 4150 | int NextFreePropertyIndex(); |
| 4151 | |
| 4152 | // Returns the number of properties described in instance_descriptors. |
| 4153 | int NumberOfDescribedProperties(); |
| 4154 | |
| 4155 | // Casting. |
| 4156 | static inline Map* cast(Object* obj); |
| 4157 | |
| 4158 | // Locate an accessor in the instance descriptor. |
| 4159 | AccessorDescriptor* FindAccessor(String* name); |
| 4160 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4161 | // Code cache operations. |
| 4162 | |
| 4163 | // Clears the code cache. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4164 | inline void ClearCodeCache(Heap* heap); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4165 | |
| 4166 | // Update code cache. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4167 | MUST_USE_RESULT MaybeObject* UpdateCodeCache(String* name, Code* code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4168 | |
| 4169 | // Returns the found code or undefined if absent. |
| 4170 | Object* FindInCodeCache(String* name, Code::Flags flags); |
| 4171 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4172 | // Returns the non-negative index of the code object if it is in the |
| 4173 | // cache and -1 otherwise. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 4174 | int IndexInCodeCache(Object* name, Code* code); |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4175 | |
| 4176 | // Removes a code object from the code cache at the given index. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4177 | void RemoveFromCodeCache(String* name, Code* code, int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4178 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4179 | // For every transition in this map, makes the transition's |
| 4180 | // target's prototype pointer point back to this map. |
| 4181 | // This is undone in MarkCompactCollector::ClearNonLiveTransitions(). |
| 4182 | void CreateBackPointers(); |
| 4183 | |
| 4184 | // Set all map transitions from this map to dead maps to null. |
| 4185 | // Also, restore the original prototype on the targets of these |
| 4186 | // transitions, so that we do not process this map again while |
| 4187 | // following back pointers. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4188 | void ClearNonLiveTransitions(Heap* heap, Object* real_prototype); |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 4189 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4190 | // Computes a hash value for this map, to be used in HashTables and such. |
| 4191 | int Hash(); |
| 4192 | |
| 4193 | // Compares this map to another to see if they describe equivalent objects. |
| 4194 | // If |mode| is set to CLEAR_INOBJECT_PROPERTIES, |other| is treated as if |
| 4195 | // it had exactly zero inobject properties. |
| 4196 | // The "shared" flags of both this map and |other| are ignored. |
| 4197 | bool EquivalentToForNormalization(Map* other, PropertyNormalizationMode mode); |
| 4198 | |
| 4199 | // Returns true if this map and |other| describe equivalent objects. |
| 4200 | // The "shared" flags of both this map and |other| are ignored. |
| 4201 | bool EquivalentTo(Map* other) { |
| 4202 | return EquivalentToForNormalization(other, KEEP_INOBJECT_PROPERTIES); |
| 4203 | } |
| 4204 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4205 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4206 | #ifdef OBJECT_PRINT |
| 4207 | inline void MapPrint() { |
| 4208 | MapPrint(stdout); |
| 4209 | } |
| 4210 | void MapPrint(FILE* out); |
| 4211 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4212 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4213 | void MapVerify(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4214 | void SharedMapVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4215 | #endif |
| 4216 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4217 | inline int visitor_id(); |
| 4218 | inline void set_visitor_id(int visitor_id); |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4219 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4220 | // Returns the isolate/heap this map belongs to. |
| 4221 | inline Isolate* isolate(); |
| 4222 | inline Heap* heap(); |
| 4223 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4224 | typedef void (*TraverseCallback)(Map* map, void* data); |
| 4225 | |
| 4226 | void TraverseTransitionTree(TraverseCallback callback, void* data); |
| 4227 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4228 | static const int kMaxCachedPrototypeTransitions = 256; |
| 4229 | |
| 4230 | Object* GetPrototypeTransition(Object* prototype); |
| 4231 | |
| 4232 | MaybeObject* PutPrototypeTransition(Object* prototype, Map* map); |
| 4233 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4234 | static const int kMaxPreAllocatedPropertyFields = 255; |
| 4235 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4236 | // Layout description. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4237 | static const int kInstanceSizesOffset = HeapObject::kHeaderSize; |
| 4238 | static const int kInstanceAttributesOffset = kInstanceSizesOffset + kIntSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4239 | static const int kPrototypeOffset = kInstanceAttributesOffset + kIntSize; |
| 4240 | static const int kConstructorOffset = kPrototypeOffset + kPointerSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4241 | // Storage for instance descriptors is overloaded to also contain additional |
| 4242 | // map flags when unused (bit_field3). When the map has instance descriptors, |
| 4243 | // the flags are transferred to the instance descriptor array and accessed |
| 4244 | // through an extra indirection. |
| 4245 | // TODO(1399): It should be possible to make room for bit_field3 in the map |
| 4246 | // without overloading the instance descriptors field, but the map is |
| 4247 | // currently perfectly aligned to 32 bytes and extending it at all would |
| 4248 | // double its size. After the increment GC work lands, this size restriction |
| 4249 | // could be loosened and bit_field3 moved directly back in the map. |
| 4250 | static const int kInstanceDescriptorsOrBitField3Offset = |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4251 | kConstructorOffset + kPointerSize; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4252 | static const int kCodeCacheOffset = |
| 4253 | kInstanceDescriptorsOrBitField3Offset + kPointerSize; |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4254 | static const int kPrototypeTransitionsOffset = |
| 4255 | kCodeCacheOffset + kPointerSize; |
| 4256 | static const int kPadStart = kPrototypeTransitionsOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4257 | static const int kSize = MAP_POINTER_ALIGN(kPadStart); |
| 4258 | |
| 4259 | // Layout of pointer fields. Heap iteration code relies on them |
| 4260 | // being continiously allocated. |
| 4261 | static const int kPointerFieldsBeginOffset = Map::kPrototypeOffset; |
| 4262 | static const int kPointerFieldsEndOffset = |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4263 | Map::kPrototypeTransitionsOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4264 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4265 | // Byte offsets within kInstanceSizesOffset. |
| 4266 | static const int kInstanceSizeOffset = kInstanceSizesOffset + 0; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 4267 | static const int kInObjectPropertiesByte = 1; |
| 4268 | static const int kInObjectPropertiesOffset = |
| 4269 | kInstanceSizesOffset + kInObjectPropertiesByte; |
| 4270 | static const int kPreAllocatedPropertyFieldsByte = 2; |
| 4271 | static const int kPreAllocatedPropertyFieldsOffset = |
| 4272 | kInstanceSizesOffset + kPreAllocatedPropertyFieldsByte; |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 4273 | static const int kVisitorIdByte = 3; |
| 4274 | static const int kVisitorIdOffset = kInstanceSizesOffset + kVisitorIdByte; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4275 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4276 | // Byte offsets within kInstanceAttributesOffset attributes. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4277 | static const int kInstanceTypeOffset = kInstanceAttributesOffset + 0; |
| 4278 | static const int kUnusedPropertyFieldsOffset = kInstanceAttributesOffset + 1; |
| 4279 | static const int kBitFieldOffset = kInstanceAttributesOffset + 2; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 4280 | static const int kBitField2Offset = kInstanceAttributesOffset + 3; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4281 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4282 | STATIC_CHECK(kInstanceTypeOffset == Internals::kMapInstanceTypeOffset); |
| 4283 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4284 | // Bit positions for bit field. |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4285 | static const int kUnused = 0; // To be used for marking recently used maps. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4286 | static const int kHasNonInstancePrototype = 1; |
| 4287 | static const int kIsHiddenPrototype = 2; |
| 4288 | static const int kHasNamedInterceptor = 3; |
| 4289 | static const int kHasIndexedInterceptor = 4; |
| 4290 | static const int kIsUndetectable = 5; |
| 4291 | static const int kHasInstanceCallHandler = 6; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4292 | static const int kIsAccessCheckNeeded = 7; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 4293 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4294 | // Bit positions for bit field 2 |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4295 | static const int kIsExtensible = 0; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 4296 | static const int kFunctionWithPrototype = 1; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4297 | static const int kStringWrapperSafeForDefaultValueOf = 2; |
| 4298 | static const int kAttachedToSharedFunctionInfo = 3; |
| 4299 | // No bits can be used after kElementsKindFirstBit, they are all reserved for |
| 4300 | // storing ElementKind. for anything other than storing the ElementKind. |
| 4301 | static const int kElementsKindShift = 4; |
| 4302 | static const int kElementsKindBitCount = 4; |
| 4303 | |
| 4304 | // Derived values from bit field 2 |
| 4305 | static const int kElementsKindMask = (-1 << kElementsKindShift) & |
| 4306 | ((1 << (kElementsKindShift + kElementsKindBitCount)) - 1); |
| 4307 | static const int8_t kMaximumBitField2FastElementValue = static_cast<int8_t>( |
| 4308 | (JSObject::FAST_ELEMENTS + 1) << Map::kElementsKindShift) - 1; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4309 | |
| 4310 | // Bit positions for bit field 3 |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4311 | static const int kIsShared = 0; |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 4312 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4313 | // Layout of the default cache. It holds alternating name and code objects. |
| 4314 | static const int kCodeCacheEntrySize = 2; |
| 4315 | static const int kCodeCacheEntryNameOffset = 0; |
| 4316 | static const int kCodeCacheEntryCodeOffset = 1; |
| 4317 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4318 | typedef FixedBodyDescriptor<kPointerFieldsBeginOffset, |
| 4319 | kPointerFieldsEndOffset, |
| 4320 | kSize> BodyDescriptor; |
| 4321 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4322 | private: |
| 4323 | DISALLOW_IMPLICIT_CONSTRUCTORS(Map); |
| 4324 | }; |
| 4325 | |
| 4326 | |
| 4327 | // An abstract superclass, a marker class really, for simple structure classes. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4328 | // It doesn't carry much functionality but allows struct classes to be |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4329 | // identified in the type system. |
| 4330 | class Struct: public HeapObject { |
| 4331 | public: |
| 4332 | inline void InitializeBody(int object_size); |
| 4333 | static inline Struct* cast(Object* that); |
| 4334 | }; |
| 4335 | |
| 4336 | |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4337 | // Script describes a script which has been added to the VM. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4338 | class Script: public Struct { |
| 4339 | public: |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4340 | // Script types. |
| 4341 | enum Type { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4342 | TYPE_NATIVE = 0, |
| 4343 | TYPE_EXTENSION = 1, |
| 4344 | TYPE_NORMAL = 2 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4345 | }; |
| 4346 | |
| 4347 | // Script compilation types. |
| 4348 | enum CompilationType { |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 4349 | COMPILATION_TYPE_HOST = 0, |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 4350 | COMPILATION_TYPE_EVAL = 1 |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4351 | }; |
| 4352 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4353 | // [source]: the script source. |
| 4354 | DECL_ACCESSORS(source, Object) |
| 4355 | |
| 4356 | // [name]: the script name. |
| 4357 | DECL_ACCESSORS(name, Object) |
| 4358 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4359 | // [id]: the script id. |
| 4360 | DECL_ACCESSORS(id, Object) |
| 4361 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4362 | // [line_offset]: script line offset in resource from where it was extracted. |
| 4363 | DECL_ACCESSORS(line_offset, Smi) |
| 4364 | |
| 4365 | // [column_offset]: script column offset in resource from where it was |
| 4366 | // extracted. |
| 4367 | DECL_ACCESSORS(column_offset, Smi) |
| 4368 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 4369 | // [data]: additional data associated with this script. |
| 4370 | DECL_ACCESSORS(data, Object) |
| 4371 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4372 | // [context_data]: context data for the context this script was compiled in. |
| 4373 | DECL_ACCESSORS(context_data, Object) |
| 4374 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4375 | // [wrapper]: the wrapper cache. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4376 | DECL_ACCESSORS(wrapper, Foreign) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4377 | |
| 4378 | // [type]: the script type. |
| 4379 | DECL_ACCESSORS(type, Smi) |
| 4380 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4381 | // [compilation]: how the the script was compiled. |
| 4382 | DECL_ACCESSORS(compilation_type, Smi) |
| 4383 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4384 | // [line_ends]: FixedArray of line ends positions. |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 4385 | DECL_ACCESSORS(line_ends, Object) |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 4386 | |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 4387 | // [eval_from_shared]: for eval scripts the shared funcion info for the |
| 4388 | // function from which eval was called. |
| 4389 | DECL_ACCESSORS(eval_from_shared, Object) |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4390 | |
| 4391 | // [eval_from_instructions_offset]: the instruction offset in the code for the |
| 4392 | // function from which eval was called where eval was called. |
| 4393 | DECL_ACCESSORS(eval_from_instructions_offset, Smi) |
| 4394 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4395 | static inline Script* cast(Object* obj); |
| 4396 | |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 4397 | // If script source is an external string, check that the underlying |
| 4398 | // resource is accessible. Otherwise, always return true. |
| 4399 | inline bool HasValidSource(); |
| 4400 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4401 | #ifdef OBJECT_PRINT |
| 4402 | inline void ScriptPrint() { |
| 4403 | ScriptPrint(stdout); |
| 4404 | } |
| 4405 | void ScriptPrint(FILE* out); |
| 4406 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4407 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4408 | void ScriptVerify(); |
| 4409 | #endif |
| 4410 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4411 | static const int kSourceOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4412 | static const int kNameOffset = kSourceOffset + kPointerSize; |
| 4413 | static const int kLineOffsetOffset = kNameOffset + kPointerSize; |
| 4414 | static const int kColumnOffsetOffset = kLineOffsetOffset + kPointerSize; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 4415 | static const int kDataOffset = kColumnOffsetOffset + kPointerSize; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 4416 | static const int kContextOffset = kDataOffset + kPointerSize; |
| 4417 | static const int kWrapperOffset = kContextOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4418 | static const int kTypeOffset = kWrapperOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4419 | static const int kCompilationTypeOffset = kTypeOffset + kPointerSize; |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 4420 | static const int kLineEndsOffset = kCompilationTypeOffset + kPointerSize; |
| 4421 | static const int kIdOffset = kLineEndsOffset + kPointerSize; |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 4422 | static const int kEvalFromSharedOffset = kIdOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4423 | static const int kEvalFrominstructionsOffsetOffset = |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 4424 | kEvalFromSharedOffset + kPointerSize; |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame] | 4425 | static const int kSize = kEvalFrominstructionsOffsetOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4426 | |
| 4427 | private: |
| 4428 | DISALLOW_IMPLICIT_CONSTRUCTORS(Script); |
| 4429 | }; |
| 4430 | |
| 4431 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4432 | // List of builtin functions we want to identify to improve code |
| 4433 | // generation. |
| 4434 | // |
| 4435 | // Each entry has a name of a global object property holding an object |
| 4436 | // optionally followed by ".prototype", a name of a builtin function |
| 4437 | // on the object (the one the id is set for), and a label. |
| 4438 | // |
| 4439 | // Installation of ids for the selected builtin functions is handled |
| 4440 | // by the bootstrapper. |
| 4441 | // |
| 4442 | // NOTE: Order is important: math functions should be at the end of |
| 4443 | // the list and MathFloor should be the first math function. |
| 4444 | #define FUNCTIONS_WITH_ID_LIST(V) \ |
| 4445 | V(Array.prototype, push, ArrayPush) \ |
| 4446 | V(Array.prototype, pop, ArrayPop) \ |
| 4447 | V(String.prototype, charCodeAt, StringCharCodeAt) \ |
| 4448 | V(String.prototype, charAt, StringCharAt) \ |
| 4449 | V(String, fromCharCode, StringFromCharCode) \ |
| 4450 | V(Math, floor, MathFloor) \ |
| 4451 | V(Math, round, MathRound) \ |
| 4452 | V(Math, ceil, MathCeil) \ |
| 4453 | V(Math, abs, MathAbs) \ |
| 4454 | V(Math, log, MathLog) \ |
| 4455 | V(Math, sin, MathSin) \ |
| 4456 | V(Math, cos, MathCos) \ |
| 4457 | V(Math, tan, MathTan) \ |
| 4458 | V(Math, asin, MathASin) \ |
| 4459 | V(Math, acos, MathACos) \ |
| 4460 | V(Math, atan, MathATan) \ |
| 4461 | V(Math, exp, MathExp) \ |
| 4462 | V(Math, sqrt, MathSqrt) \ |
| 4463 | V(Math, pow, MathPow) |
| 4464 | |
| 4465 | |
| 4466 | enum BuiltinFunctionId { |
| 4467 | #define DECLARE_FUNCTION_ID(ignored1, ignore2, name) \ |
| 4468 | k##name, |
| 4469 | FUNCTIONS_WITH_ID_LIST(DECLARE_FUNCTION_ID) |
| 4470 | #undef DECLARE_FUNCTION_ID |
| 4471 | // Fake id for a special case of Math.pow. Note, it continues the |
| 4472 | // list of math functions. |
| 4473 | kMathPowHalf, |
| 4474 | kFirstMathFunctionId = kMathFloor |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4475 | }; |
| 4476 | |
| 4477 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4478 | // SharedFunctionInfo describes the JSFunction information that can be |
| 4479 | // shared by multiple instances of the function. |
| 4480 | class SharedFunctionInfo: public HeapObject { |
| 4481 | public: |
| 4482 | // [name]: Function name. |
| 4483 | DECL_ACCESSORS(name, Object) |
| 4484 | |
| 4485 | // [code]: Function code. |
| 4486 | DECL_ACCESSORS(code, Code) |
| 4487 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4488 | // [scope_info]: Scope info. |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 4489 | DECL_ACCESSORS(scope_info, SerializedScopeInfo) |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4490 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 4491 | // [construct stub]: Code stub for constructing instances of this function. |
| 4492 | DECL_ACCESSORS(construct_stub, Code) |
| 4493 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4494 | inline Code* unchecked_code(); |
| 4495 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4496 | // Returns if this function has been compiled to native code yet. |
| 4497 | inline bool is_compiled(); |
| 4498 | |
| 4499 | // [length]: The function length - usually the number of declared parameters. |
| 4500 | // Use up to 2^30 parameters. |
| 4501 | inline int length(); |
| 4502 | inline void set_length(int value); |
| 4503 | |
| 4504 | // [formal parameter count]: The declared number of parameters. |
| 4505 | inline int formal_parameter_count(); |
| 4506 | inline void set_formal_parameter_count(int value); |
| 4507 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4508 | // Set the formal parameter count so the function code will be |
| 4509 | // called without using argument adaptor frames. |
| 4510 | inline void DontAdaptArguments(); |
| 4511 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4512 | // [expected_nof_properties]: Expected number of properties for the function. |
| 4513 | inline int expected_nof_properties(); |
| 4514 | inline void set_expected_nof_properties(int value); |
| 4515 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4516 | // Inobject slack tracking is the way to reclaim unused inobject space. |
| 4517 | // |
| 4518 | // The instance size is initially determined by adding some slack to |
| 4519 | // expected_nof_properties (to allow for a few extra properties added |
| 4520 | // after the constructor). There is no guarantee that the extra space |
| 4521 | // will not be wasted. |
| 4522 | // |
| 4523 | // Here is the algorithm to reclaim the unused inobject space: |
| 4524 | // - Detect the first constructor call for this SharedFunctionInfo. |
| 4525 | // When it happens enter the "in progress" state: remember the |
| 4526 | // constructor's initial_map and install a special construct stub that |
| 4527 | // counts constructor calls. |
| 4528 | // - While the tracking is in progress create objects filled with |
| 4529 | // one_pointer_filler_map instead of undefined_value. This way they can be |
| 4530 | // resized quickly and safely. |
| 4531 | // - Once enough (kGenerousAllocationCount) objects have been created |
| 4532 | // compute the 'slack' (traverse the map transition tree starting from the |
| 4533 | // initial_map and find the lowest value of unused_property_fields). |
| 4534 | // - Traverse the transition tree again and decrease the instance size |
| 4535 | // of every map. Existing objects will resize automatically (they are |
| 4536 | // filled with one_pointer_filler_map). All further allocations will |
| 4537 | // use the adjusted instance size. |
| 4538 | // - Decrease expected_nof_properties so that an allocations made from |
| 4539 | // another context will use the adjusted instance size too. |
| 4540 | // - Exit "in progress" state by clearing the reference to the initial_map |
| 4541 | // and setting the regular construct stub (generic or inline). |
| 4542 | // |
| 4543 | // The above is the main event sequence. Some special cases are possible |
| 4544 | // while the tracking is in progress: |
| 4545 | // |
| 4546 | // - GC occurs. |
| 4547 | // Check if the initial_map is referenced by any live objects (except this |
| 4548 | // SharedFunctionInfo). If it is, continue tracking as usual. |
| 4549 | // If it is not, clear the reference and reset the tracking state. The |
| 4550 | // tracking will be initiated again on the next constructor call. |
| 4551 | // |
| 4552 | // - The constructor is called from another context. |
| 4553 | // Immediately complete the tracking, perform all the necessary changes |
| 4554 | // to maps. This is necessary because there is no efficient way to track |
| 4555 | // multiple initial_maps. |
| 4556 | // Proceed to create an object in the current context (with the adjusted |
| 4557 | // size). |
| 4558 | // |
| 4559 | // - A different constructor function sharing the same SharedFunctionInfo is |
| 4560 | // called in the same context. This could be another closure in the same |
| 4561 | // context, or the first function could have been disposed. |
| 4562 | // This is handled the same way as the previous case. |
| 4563 | // |
| 4564 | // Important: inobject slack tracking is not attempted during the snapshot |
| 4565 | // creation. |
| 4566 | |
ricow@chromium.org | eb7c144 | 2010-10-04 08:54:21 +0000 | [diff] [blame] | 4567 | static const int kGenerousAllocationCount = 8; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4568 | |
| 4569 | // [construction_count]: Counter for constructor calls made during |
| 4570 | // the tracking phase. |
| 4571 | inline int construction_count(); |
| 4572 | inline void set_construction_count(int value); |
| 4573 | |
| 4574 | // [initial_map]: initial map of the first function called as a constructor. |
| 4575 | // Saved for the duration of the tracking phase. |
| 4576 | // This is a weak link (GC resets it to undefined_value if no other live |
| 4577 | // object reference this map). |
| 4578 | DECL_ACCESSORS(initial_map, Object) |
| 4579 | |
| 4580 | // True if the initial_map is not undefined and the countdown stub is |
| 4581 | // installed. |
| 4582 | inline bool IsInobjectSlackTrackingInProgress(); |
| 4583 | |
| 4584 | // Starts the tracking. |
| 4585 | // Stores the initial map and installs the countdown stub. |
| 4586 | // IsInobjectSlackTrackingInProgress is normally true after this call, |
| 4587 | // except when tracking have not been started (e.g. the map has no unused |
| 4588 | // properties or the snapshot is being built). |
| 4589 | void StartInobjectSlackTracking(Map* map); |
| 4590 | |
| 4591 | // Completes the tracking. |
| 4592 | // IsInobjectSlackTrackingInProgress is false after this call. |
| 4593 | void CompleteInobjectSlackTracking(); |
| 4594 | |
| 4595 | // Clears the initial_map before the GC marking phase to ensure the reference |
| 4596 | // is weak. IsInobjectSlackTrackingInProgress is false after this call. |
| 4597 | void DetachInitialMap(); |
| 4598 | |
| 4599 | // Restores the link to the initial map after the GC marking phase. |
| 4600 | // IsInobjectSlackTrackingInProgress is true after this call. |
| 4601 | void AttachInitialMap(Map* map); |
| 4602 | |
| 4603 | // False if there are definitely no live objects created from this function. |
| 4604 | // True if live objects _may_ exist (existence not guaranteed). |
| 4605 | // May go back from true to false after GC. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4606 | DECL_BOOLEAN_ACCESSORS(live_objects_may_exist) |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4607 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4608 | // [instance class name]: class name for instances. |
| 4609 | DECL_ACCESSORS(instance_class_name, Object) |
| 4610 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4611 | // [function data]: This field holds some additional data for function. |
| 4612 | // Currently it either has FunctionTemplateInfo to make benefit the API |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4613 | // or Smi identifying a builtin function. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4614 | // In the long run we don't want all functions to have this field but |
| 4615 | // we can fix that when we have a better model for storing hidden data |
| 4616 | // on objects. |
| 4617 | DECL_ACCESSORS(function_data, Object) |
| 4618 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4619 | inline bool IsApiFunction(); |
| 4620 | inline FunctionTemplateInfo* get_api_func_data(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4621 | inline bool HasBuiltinFunctionId(); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4622 | inline BuiltinFunctionId builtin_function_id(); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4623 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4624 | // [script info]: Script from which the function originates. |
| 4625 | DECL_ACCESSORS(script, Object) |
| 4626 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4627 | // [num_literals]: Number of literals used by this function. |
| 4628 | inline int num_literals(); |
| 4629 | inline void set_num_literals(int value); |
| 4630 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4631 | // [start_position_and_type]: Field used to store both the source code |
| 4632 | // position, whether or not the function is a function expression, |
| 4633 | // and whether or not the function is a toplevel function. The two |
| 4634 | // least significants bit indicates whether the function is an |
| 4635 | // expression and the rest contains the source code position. |
| 4636 | inline int start_position_and_type(); |
| 4637 | inline void set_start_position_and_type(int value); |
| 4638 | |
| 4639 | // [debug info]: Debug information. |
| 4640 | DECL_ACCESSORS(debug_info, Object) |
| 4641 | |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 4642 | // [inferred name]: Name inferred from variable or property |
| 4643 | // assignment of this function. Used to facilitate debugging and |
| 4644 | // profiling of JavaScript code written in OO style, where almost |
| 4645 | // all functions are anonymous but are assigned to object |
| 4646 | // properties. |
| 4647 | DECL_ACCESSORS(inferred_name, String) |
| 4648 | |
ager@chromium.org | b61a0d1 | 2010-10-13 08:35:23 +0000 | [diff] [blame] | 4649 | // The function's name if it is non-empty, otherwise the inferred name. |
| 4650 | String* DebugName(); |
| 4651 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4652 | // Position of the 'function' token in the script source. |
| 4653 | inline int function_token_position(); |
| 4654 | inline void set_function_token_position(int function_token_position); |
| 4655 | |
| 4656 | // Position of this function in the script source. |
| 4657 | inline int start_position(); |
| 4658 | inline void set_start_position(int start_position); |
| 4659 | |
| 4660 | // End position of this function in the script source. |
| 4661 | inline int end_position(); |
| 4662 | inline void set_end_position(int end_position); |
| 4663 | |
| 4664 | // Is this function a function expression in the source code. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 4665 | DECL_BOOLEAN_ACCESSORS(is_expression) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4666 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 4667 | // Is this function a top-level function (scripts, evals). |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 4668 | DECL_BOOLEAN_ACCESSORS(is_toplevel) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4669 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4670 | // Bit field containing various information collected by the compiler to |
| 4671 | // drive optimization. |
| 4672 | inline int compiler_hints(); |
| 4673 | inline void set_compiler_hints(int value); |
| 4674 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4675 | // A counter used to determine when to stress the deoptimizer with a |
| 4676 | // deopt. |
| 4677 | inline Smi* deopt_counter(); |
| 4678 | inline void set_deopt_counter(Smi* counter); |
| 4679 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4680 | // Add information on assignments of the form this.x = ...; |
| 4681 | void SetThisPropertyAssignmentsInfo( |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4682 | bool has_only_simple_this_property_assignments, |
| 4683 | FixedArray* this_property_assignments); |
| 4684 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4685 | // Clear information on assignments of the form this.x = ...; |
| 4686 | void ClearThisPropertyAssignmentsInfo(); |
| 4687 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4688 | // Indicate that this function only consists of assignments of the form |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4689 | // this.x = y; where y is either a constant or refers to an argument. |
| 4690 | inline bool has_only_simple_this_property_assignments(); |
| 4691 | |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 4692 | // Indicates if this function can be lazy compiled. |
| 4693 | // This is used to determine if we can safely flush code from a function |
| 4694 | // when doing GC if we expect that the function will no longer be used. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4695 | DECL_BOOLEAN_ACCESSORS(allows_lazy_compilation) |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 4696 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4697 | // Indicates how many full GCs this function has survived with assigned |
| 4698 | // code object. Used to determine when it is relatively safe to flush |
| 4699 | // this code object and replace it with lazy compilation stub. |
| 4700 | // Age is reset when GC notices that the code object is referenced |
| 4701 | // from the stack or compilation cache. |
| 4702 | inline int code_age(); |
| 4703 | inline void set_code_age(int age); |
| 4704 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4705 | // Indicates whether optimizations have been disabled for this |
| 4706 | // shared function info. If a function is repeatedly optimized or if |
| 4707 | // we cannot optimize the function we disable optimization to avoid |
| 4708 | // spending time attempting to optimize it again. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4709 | DECL_BOOLEAN_ACCESSORS(optimization_disabled) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4710 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4711 | // Indicates whether the function is a strict mode function. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4712 | DECL_BOOLEAN_ACCESSORS(strict_mode) |
| 4713 | |
| 4714 | // False if the function definitely does not allocate an arguments object. |
| 4715 | DECL_BOOLEAN_ACCESSORS(uses_arguments) |
| 4716 | |
| 4717 | // True if the function has any duplicated parameter names. |
| 4718 | DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters) |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 4719 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4720 | // Indicates whether the function is a native function. |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4721 | // These needs special threatment in .call and .apply since |
| 4722 | // null passed as the receiver should not be translated to the |
| 4723 | // global object. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 4724 | DECL_BOOLEAN_ACCESSORS(native) |
| 4725 | |
| 4726 | // Indicates that the function was created by the Function function. |
| 4727 | // Though it's anonymous, toString should treat it as if it had the name |
| 4728 | // "anonymous". We don't set the name itself so that the system does not |
| 4729 | // see a binding for it. |
| 4730 | DECL_BOOLEAN_ACCESSORS(name_should_print_as_anonymous) |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4731 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4732 | // Indicates whether the function is a bound function created using |
| 4733 | // the bind function. |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 4734 | DECL_BOOLEAN_ACCESSORS(bound) |
| 4735 | |
| 4736 | // Indicates that the function is anonymous (the name field can be set |
| 4737 | // through the API, which does not change this flag). |
| 4738 | DECL_BOOLEAN_ACCESSORS(is_anonymous) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4739 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4740 | // Indicates whether or not the code in the shared function support |
| 4741 | // deoptimization. |
| 4742 | inline bool has_deoptimization_support(); |
| 4743 | |
| 4744 | // Enable deoptimization support through recompiled code. |
| 4745 | void EnableDeoptimizationSupport(Code* recompiled); |
| 4746 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 4747 | // Disable (further) attempted optimization of all functions sharing this |
| 4748 | // shared function info. The function is the one we actually tried to |
| 4749 | // optimize. |
| 4750 | void DisableOptimization(JSFunction* function); |
| 4751 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4752 | // Lookup the bailout ID and ASSERT that it exists in the non-optimized |
| 4753 | // code, returns whether it asserted (i.e., always true if assertions are |
| 4754 | // disabled). |
| 4755 | bool VerifyBailoutId(int id); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4756 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 4757 | // Check whether a inlined constructor can be generated with the given |
| 4758 | // prototype. |
| 4759 | bool CanGenerateInlineConstructor(Object* prototype); |
| 4760 | |
fschneider@chromium.org | c20610a | 2010-09-22 09:44:58 +0000 | [diff] [blame] | 4761 | // Prevents further attempts to generate inline constructors. |
| 4762 | // To be called if generation failed for any reason. |
| 4763 | void ForbidInlineConstructor(); |
| 4764 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4765 | // For functions which only contains this property assignments this provides |
| 4766 | // access to the names for the properties assigned. |
| 4767 | DECL_ACCESSORS(this_property_assignments, Object) |
| 4768 | inline int this_property_assignments_count(); |
| 4769 | inline void set_this_property_assignments_count(int value); |
| 4770 | String* GetThisPropertyAssignmentName(int index); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 4771 | bool IsThisPropertyAssignmentArgument(int index); |
| 4772 | int GetThisPropertyAssignmentArgument(int index); |
| 4773 | Object* GetThisPropertyAssignmentConstant(int index); |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4774 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4775 | // [source code]: Source code for the function. |
| 4776 | bool HasSourceCode(); |
| 4777 | Object* GetSourceCode(); |
| 4778 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4779 | inline int opt_count(); |
| 4780 | inline void set_opt_count(int opt_count); |
| 4781 | |
| 4782 | // Source size of this function. |
| 4783 | int SourceSize(); |
| 4784 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4785 | // Calculate the instance size. |
| 4786 | int CalculateInstanceSize(); |
| 4787 | |
| 4788 | // Calculate the number of in-object properties. |
| 4789 | int CalculateInObjectProperties(); |
| 4790 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4791 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4792 | // Set max_length to -1 for unlimited length. |
| 4793 | void SourceCodePrint(StringStream* accumulator, int max_length); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 4794 | #ifdef OBJECT_PRINT |
| 4795 | inline void SharedFunctionInfoPrint() { |
| 4796 | SharedFunctionInfoPrint(stdout); |
| 4797 | } |
| 4798 | void SharedFunctionInfoPrint(FILE* out); |
| 4799 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4800 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4801 | void SharedFunctionInfoVerify(); |
| 4802 | #endif |
| 4803 | |
| 4804 | // Casting. |
| 4805 | static inline SharedFunctionInfo* cast(Object* obj); |
| 4806 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4807 | // Constants. |
| 4808 | static const int kDontAdaptArgumentsSentinel = -1; |
| 4809 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4810 | // Layout description. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4811 | // Pointer fields. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4812 | static const int kNameOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4813 | static const int kCodeOffset = kNameOffset + kPointerSize; |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 4814 | static const int kScopeInfoOffset = kCodeOffset + kPointerSize; |
| 4815 | static const int kConstructStubOffset = kScopeInfoOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4816 | static const int kInstanceClassNameOffset = |
| 4817 | kConstructStubOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4818 | static const int kFunctionDataOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4819 | kInstanceClassNameOffset + kPointerSize; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4820 | static const int kScriptOffset = kFunctionDataOffset + kPointerSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4821 | static const int kDebugInfoOffset = kScriptOffset + kPointerSize; |
| 4822 | static const int kInferredNameOffset = kDebugInfoOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4823 | static const int kInitialMapOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4824 | kInferredNameOffset + kPointerSize; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4825 | static const int kThisPropertyAssignmentsOffset = |
| 4826 | kInitialMapOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4827 | static const int kDeoptCounterOffset = |
| 4828 | kThisPropertyAssignmentsOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4829 | #if V8_HOST_ARCH_32_BIT |
| 4830 | // Smi fields. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4831 | static const int kLengthOffset = |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4832 | kDeoptCounterOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4833 | static const int kFormalParameterCountOffset = kLengthOffset + kPointerSize; |
| 4834 | static const int kExpectedNofPropertiesOffset = |
| 4835 | kFormalParameterCountOffset + kPointerSize; |
| 4836 | static const int kNumLiteralsOffset = |
| 4837 | kExpectedNofPropertiesOffset + kPointerSize; |
| 4838 | static const int kStartPositionAndTypeOffset = |
| 4839 | kNumLiteralsOffset + kPointerSize; |
| 4840 | static const int kEndPositionOffset = |
| 4841 | kStartPositionAndTypeOffset + kPointerSize; |
| 4842 | static const int kFunctionTokenPositionOffset = |
| 4843 | kEndPositionOffset + kPointerSize; |
| 4844 | static const int kCompilerHintsOffset = |
| 4845 | kFunctionTokenPositionOffset + kPointerSize; |
| 4846 | static const int kThisPropertyAssignmentsCountOffset = |
| 4847 | kCompilerHintsOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4848 | static const int kOptCountOffset = |
| 4849 | kThisPropertyAssignmentsCountOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4850 | // Total size. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4851 | static const int kSize = kOptCountOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4852 | #else |
| 4853 | // The only reason to use smi fields instead of int fields |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4854 | // is to allow iteration without maps decoding during |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4855 | // garbage collections. |
| 4856 | // To avoid wasting space on 64-bit architectures we use |
| 4857 | // the following trick: we group integer fields into pairs |
| 4858 | // First integer in each pair is shifted left by 1. |
| 4859 | // By doing this we guarantee that LSB of each kPointerSize aligned |
| 4860 | // word is not set and thus this word cannot be treated as pointer |
| 4861 | // to HeapObject during old space traversal. |
| 4862 | static const int kLengthOffset = |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4863 | kDeoptCounterOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4864 | static const int kFormalParameterCountOffset = |
| 4865 | kLengthOffset + kIntSize; |
| 4866 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4867 | static const int kExpectedNofPropertiesOffset = |
| 4868 | kFormalParameterCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4869 | static const int kNumLiteralsOffset = |
| 4870 | kExpectedNofPropertiesOffset + kIntSize; |
| 4871 | |
| 4872 | static const int kEndPositionOffset = |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4873 | kNumLiteralsOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4874 | static const int kStartPositionAndTypeOffset = |
| 4875 | kEndPositionOffset + kIntSize; |
| 4876 | |
| 4877 | static const int kFunctionTokenPositionOffset = |
| 4878 | kStartPositionAndTypeOffset + kIntSize; |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4879 | static const int kCompilerHintsOffset = |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 4880 | kFunctionTokenPositionOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4881 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4882 | static const int kThisPropertyAssignmentsCountOffset = |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4883 | kCompilerHintsOffset + kIntSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4884 | static const int kOptCountOffset = |
| 4885 | kThisPropertyAssignmentsCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4886 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4887 | // Total size. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4888 | static const int kSize = kOptCountOffset + kIntSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4889 | |
| 4890 | #endif |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 4891 | |
| 4892 | // The construction counter for inobject slack tracking is stored in the |
| 4893 | // most significant byte of compiler_hints which is otherwise unused. |
| 4894 | // Its offset depends on the endian-ness of the architecture. |
| 4895 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 4896 | static const int kConstructionCountOffset = kCompilerHintsOffset + 3; |
| 4897 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 4898 | static const int kConstructionCountOffset = kCompilerHintsOffset + 0; |
| 4899 | #else |
| 4900 | #error Unknown byte ordering |
| 4901 | #endif |
| 4902 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 4903 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4904 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 4905 | typedef FixedBodyDescriptor<kNameOffset, |
| 4906 | kThisPropertyAssignmentsOffset + kPointerSize, |
| 4907 | kSize> BodyDescriptor; |
| 4908 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4909 | // Bit positions in start_position_and_type. |
| 4910 | // The source code start position is in the 30 most significant bits of |
| 4911 | // the start_position_and_type field. |
| 4912 | static const int kIsExpressionBit = 0; |
| 4913 | static const int kIsTopLevelBit = 1; |
| 4914 | static const int kStartPositionShift = 2; |
| 4915 | static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1); |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4916 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4917 | // Bit positions in compiler_hints. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4918 | static const int kCodeAgeSize = 3; |
| 4919 | static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4920 | |
| 4921 | enum CompilerHints { |
| 4922 | kHasOnlySimpleThisPropertyAssignments, |
| 4923 | kAllowLazyCompilation, |
| 4924 | kLiveObjectsMayExist, |
| 4925 | kCodeAgeShift, |
| 4926 | kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize, |
| 4927 | kStrictModeFunction, |
| 4928 | kUsesArguments, |
| 4929 | kHasDuplicateParameters, |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 4930 | kNative, |
| 4931 | kBoundFunction, |
| 4932 | kIsAnonymous, |
| 4933 | kNameShouldPrintAsAnonymous, |
| 4934 | kCompilerHintsCount // Pseudo entry |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4935 | }; |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 4936 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4937 | private: |
| 4938 | #if V8_HOST_ARCH_32_BIT |
| 4939 | // On 32 bit platforms, compiler hints is a smi. |
| 4940 | static const int kCompilerHintsSmiTagSize = kSmiTagSize; |
| 4941 | static const int kCompilerHintsSize = kPointerSize; |
| 4942 | #else |
| 4943 | // On 64 bit platforms, compiler hints is not a smi, see comment above. |
| 4944 | static const int kCompilerHintsSmiTagSize = 0; |
| 4945 | static const int kCompilerHintsSize = kIntSize; |
| 4946 | #endif |
| 4947 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 4948 | STATIC_ASSERT(SharedFunctionInfo::kCompilerHintsCount <= |
| 4949 | SharedFunctionInfo::kCompilerHintsSize * kBitsPerByte); |
| 4950 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4951 | public: |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4952 | // Constants for optimizing codegen for strict mode function and |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4953 | // native tests. |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4954 | // Allows to use byte-widgh instructions. |
| 4955 | static const int kStrictModeBitWithinByte = |
| 4956 | (kStrictModeFunction + kCompilerHintsSmiTagSize) % kBitsPerByte; |
| 4957 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4958 | static const int kNativeBitWithinByte = |
| 4959 | (kNative + kCompilerHintsSmiTagSize) % kBitsPerByte; |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4960 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4961 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 4962 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4963 | (kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4964 | static const int kNativeByteOffset = kCompilerHintsOffset + |
| 4965 | (kNative + kCompilerHintsSmiTagSize) / kBitsPerByte; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4966 | #elif __BYTE_ORDER == __BIG_ENDIAN |
| 4967 | static const int kStrictModeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4968 | (kCompilerHintsSize - 1) - |
| 4969 | ((kStrictModeFunction + kCompilerHintsSmiTagSize) / kBitsPerByte); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4970 | static const int kNativeByteOffset = kCompilerHintsOffset + |
ricow@chromium.org | 6fe7a8e | 2011-05-13 07:57:29 +0000 | [diff] [blame] | 4971 | (kCompilerHintsSize - 1) - |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4972 | ((kNative + kCompilerHintsSmiTagSize) / kBitsPerByte); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 4973 | #else |
| 4974 | #error Unknown byte ordering |
| 4975 | #endif |
| 4976 | |
| 4977 | private: |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 4978 | DISALLOW_IMPLICIT_CONSTRUCTORS(SharedFunctionInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4979 | }; |
| 4980 | |
| 4981 | |
| 4982 | // JSFunction describes JavaScript functions. |
| 4983 | class JSFunction: public JSObject { |
| 4984 | public: |
| 4985 | // [prototype_or_initial_map]: |
| 4986 | DECL_ACCESSORS(prototype_or_initial_map, Object) |
| 4987 | |
| 4988 | // [shared_function_info]: The information about the function that |
| 4989 | // can be shared by instances. |
| 4990 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 4991 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4992 | inline SharedFunctionInfo* unchecked_shared(); |
| 4993 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4994 | // [context]: The context for this function. |
| 4995 | inline Context* context(); |
| 4996 | inline Object* unchecked_context(); |
| 4997 | inline void set_context(Object* context); |
| 4998 | |
| 4999 | // [code]: The generated code object for this function. Executed |
| 5000 | // when the function is invoked, e.g. foo() or new foo(). See |
| 5001 | // [[Call]] and [[Construct]] description in ECMA-262, section |
| 5002 | // 8.6.2, page 27. |
| 5003 | inline Code* code(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5004 | inline void set_code(Code* code); |
| 5005 | inline void ReplaceCode(Code* code); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5006 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 5007 | inline Code* unchecked_code(); |
| 5008 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 5009 | // Tells whether this function is builtin. |
| 5010 | inline bool IsBuiltin(); |
| 5011 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5012 | // Tells whether or not the function needs arguments adaption. |
| 5013 | inline bool NeedsArgumentsAdaption(); |
| 5014 | |
| 5015 | // Tells whether or not this function has been optimized. |
| 5016 | inline bool IsOptimized(); |
| 5017 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 5018 | // Tells whether or not this function can be optimized. |
| 5019 | inline bool IsOptimizable(); |
| 5020 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5021 | // Mark this function for lazy recompilation. The function will be |
| 5022 | // recompiled the next time it is executed. |
| 5023 | void MarkForLazyRecompilation(); |
| 5024 | |
| 5025 | // Tells whether or not the function is already marked for lazy |
| 5026 | // recompilation. |
| 5027 | inline bool IsMarkedForLazyRecompilation(); |
| 5028 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5029 | // Check whether or not this function is inlineable. |
| 5030 | bool IsInlineable(); |
| 5031 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5032 | // [literals]: Fixed array holding the materialized literals. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5033 | // |
| 5034 | // If the function contains object, regexp or array literals, the |
| 5035 | // literals array prefix contains the object, regexp, and array |
| 5036 | // function to be used when creating these literals. This is |
| 5037 | // necessary so that we do not dynamically lookup the object, regexp |
| 5038 | // or array functions. Performing a dynamic lookup, we might end up |
| 5039 | // using the functions from a new context that we should not have |
| 5040 | // access to. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5041 | DECL_ACCESSORS(literals, FixedArray) |
| 5042 | |
| 5043 | // The initial map for an object created by this constructor. |
| 5044 | inline Map* initial_map(); |
| 5045 | inline void set_initial_map(Map* value); |
| 5046 | inline bool has_initial_map(); |
| 5047 | |
| 5048 | // Get and set the prototype property on a JSFunction. If the |
| 5049 | // function has an initial map the prototype is set on the initial |
| 5050 | // map. Otherwise, the prototype is put in the initial map field |
| 5051 | // until an initial map is needed. |
| 5052 | inline bool has_prototype(); |
| 5053 | inline bool has_instance_prototype(); |
| 5054 | inline Object* prototype(); |
| 5055 | inline Object* instance_prototype(); |
| 5056 | Object* SetInstancePrototype(Object* value); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5057 | MUST_USE_RESULT MaybeObject* SetPrototype(Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5058 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 5059 | // After prototype is removed, it will not be created when accessed, and |
| 5060 | // [[Construct]] from this function will not be allowed. |
| 5061 | Object* RemovePrototype(); |
| 5062 | inline bool should_have_prototype(); |
| 5063 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5064 | // Accessor for this function's initial map's [[class]] |
| 5065 | // property. This is primarily used by ECMA native functions. This |
| 5066 | // method sets the class_name field of this function's initial map |
| 5067 | // to a given value. It creates an initial map if this function does |
| 5068 | // not have one. Note that this method does not copy the initial map |
| 5069 | // if it has one already, but simply replaces it with the new value. |
| 5070 | // Instances created afterwards will have a map whose [[class]] is |
| 5071 | // set to 'value', but there is no guarantees on instances created |
| 5072 | // before. |
| 5073 | Object* SetInstanceClassName(String* name); |
| 5074 | |
| 5075 | // Returns if this function has been compiled to native code yet. |
| 5076 | inline bool is_compiled(); |
| 5077 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5078 | // [next_function_link]: Field for linking functions. This list is treated as |
| 5079 | // a weak list by the GC. |
| 5080 | DECL_ACCESSORS(next_function_link, Object) |
| 5081 | |
| 5082 | // Prints the name of the function using PrintF. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5083 | inline void PrintName() { |
| 5084 | PrintName(stdout); |
| 5085 | } |
| 5086 | void PrintName(FILE* out); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5087 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5088 | // Casting. |
| 5089 | static inline JSFunction* cast(Object* obj); |
| 5090 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5091 | // Iterates the objects, including code objects indirectly referenced |
| 5092 | // through pointers to the first instruction in the code object. |
| 5093 | void JSFunctionIterateBody(int object_size, ObjectVisitor* v); |
| 5094 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5095 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5096 | #ifdef OBJECT_PRINT |
| 5097 | inline void JSFunctionPrint() { |
| 5098 | JSFunctionPrint(stdout); |
| 5099 | } |
| 5100 | void JSFunctionPrint(FILE* out); |
| 5101 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5102 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5103 | void JSFunctionVerify(); |
| 5104 | #endif |
| 5105 | |
| 5106 | // Returns the number of allocated literals. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5107 | inline int NumberOfLiterals(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5108 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5109 | // Retrieve the global context from a function's literal array. |
| 5110 | static Context* GlobalContextFromLiterals(FixedArray* literals); |
| 5111 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5112 | // Layout descriptors. The last property (from kNonWeakFieldsEndOffset to |
| 5113 | // kSize) is weak and has special handling during garbage collection. |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5114 | static const int kCodeEntryOffset = JSObject::kHeaderSize; |
vegorov@chromium.org | 26c16f8 | 2010-08-11 13:41:03 +0000 | [diff] [blame] | 5115 | static const int kPrototypeOrInitialMapOffset = |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 5116 | kCodeEntryOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5117 | static const int kSharedFunctionInfoOffset = |
| 5118 | kPrototypeOrInitialMapOffset + kPointerSize; |
| 5119 | static const int kContextOffset = kSharedFunctionInfoOffset + kPointerSize; |
| 5120 | static const int kLiteralsOffset = kContextOffset + kPointerSize; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5121 | static const int kNonWeakFieldsEndOffset = kLiteralsOffset + kPointerSize; |
| 5122 | static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; |
| 5123 | static const int kSize = kNextFunctionLinkOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5124 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 5125 | // Layout of the literals array. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5126 | static const int kLiteralsPrefixSize = 1; |
| 5127 | static const int kLiteralGlobalContextIndex = 0; |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 5128 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5129 | private: |
| 5130 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunction); |
| 5131 | }; |
| 5132 | |
| 5133 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5134 | // JSGlobalProxy's prototype must be a JSGlobalObject or null, |
| 5135 | // and the prototype is hidden. JSGlobalProxy always delegates |
| 5136 | // property accesses to its prototype if the prototype is not null. |
| 5137 | // |
| 5138 | // A JSGlobalProxy can be reinitialized which will preserve its identity. |
| 5139 | // |
| 5140 | // Accessing a JSGlobalProxy requires security check. |
| 5141 | |
| 5142 | class JSGlobalProxy : public JSObject { |
| 5143 | public: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5144 | // [context]: the owner global context of this global proxy object. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5145 | // It is null value if this object is not used by any context. |
| 5146 | DECL_ACCESSORS(context, Object) |
| 5147 | |
| 5148 | // Casting. |
| 5149 | static inline JSGlobalProxy* cast(Object* obj); |
| 5150 | |
| 5151 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5152 | #ifdef OBJECT_PRINT |
| 5153 | inline void JSGlobalProxyPrint() { |
| 5154 | JSGlobalProxyPrint(stdout); |
| 5155 | } |
| 5156 | void JSGlobalProxyPrint(FILE* out); |
| 5157 | #endif |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5158 | #ifdef DEBUG |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5159 | void JSGlobalProxyVerify(); |
| 5160 | #endif |
| 5161 | |
| 5162 | // Layout description. |
| 5163 | static const int kContextOffset = JSObject::kHeaderSize; |
| 5164 | static const int kSize = kContextOffset + kPointerSize; |
| 5165 | |
| 5166 | private: |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5167 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalProxy); |
| 5168 | }; |
| 5169 | |
| 5170 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5171 | // Forward declaration. |
| 5172 | class JSBuiltinsObject; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5173 | class JSGlobalPropertyCell; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5174 | |
| 5175 | // Common super class for JavaScript global objects and the special |
| 5176 | // builtins global objects. |
| 5177 | class GlobalObject: public JSObject { |
| 5178 | public: |
| 5179 | // [builtins]: the object holding the runtime routines written in JS. |
| 5180 | DECL_ACCESSORS(builtins, JSBuiltinsObject) |
| 5181 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 5182 | // [global context]: the global context corresponding to this global object. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5183 | DECL_ACCESSORS(global_context, Context) |
| 5184 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5185 | // [global receiver]: the global receiver object of the context |
| 5186 | DECL_ACCESSORS(global_receiver, JSObject) |
| 5187 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5188 | // Retrieve the property cell used to store a property. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5189 | JSGlobalPropertyCell* GetPropertyCell(LookupResult* result); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 5190 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5191 | // This is like GetProperty, but is used when you know the lookup won't fail |
| 5192 | // by throwing an exception. This is for the debug and builtins global |
| 5193 | // objects, where it is known which properties can be expected to be present |
| 5194 | // on the object. |
| 5195 | Object* GetPropertyNoExceptionThrown(String* key) { |
| 5196 | Object* answer = GetProperty(key)->ToObjectUnchecked(); |
| 5197 | return answer; |
| 5198 | } |
| 5199 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 5200 | // Ensure that the global object has a cell for the given property name. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5201 | MUST_USE_RESULT MaybeObject* EnsurePropertyCell(String* name); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 5202 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5203 | // Casting. |
| 5204 | static inline GlobalObject* cast(Object* obj); |
| 5205 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5206 | // Layout description. |
| 5207 | static const int kBuiltinsOffset = JSObject::kHeaderSize; |
| 5208 | static const int kGlobalContextOffset = kBuiltinsOffset + kPointerSize; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5209 | static const int kGlobalReceiverOffset = kGlobalContextOffset + kPointerSize; |
| 5210 | static const int kHeaderSize = kGlobalReceiverOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5211 | |
| 5212 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5213 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 5214 | |
| 5215 | DISALLOW_IMPLICIT_CONSTRUCTORS(GlobalObject); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5216 | }; |
| 5217 | |
| 5218 | |
| 5219 | // JavaScript global object. |
| 5220 | class JSGlobalObject: public GlobalObject { |
| 5221 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5222 | // Casting. |
| 5223 | static inline JSGlobalObject* cast(Object* obj); |
| 5224 | |
| 5225 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5226 | #ifdef OBJECT_PRINT |
| 5227 | inline void JSGlobalObjectPrint() { |
| 5228 | JSGlobalObjectPrint(stdout); |
| 5229 | } |
| 5230 | void JSGlobalObjectPrint(FILE* out); |
| 5231 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5232 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5233 | void JSGlobalObjectVerify(); |
| 5234 | #endif |
| 5235 | |
| 5236 | // Layout description. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5237 | static const int kSize = GlobalObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5238 | |
| 5239 | private: |
| 5240 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalObject); |
| 5241 | }; |
| 5242 | |
| 5243 | |
| 5244 | // Builtins global object which holds the runtime routines written in |
| 5245 | // JavaScript. |
| 5246 | class JSBuiltinsObject: public GlobalObject { |
| 5247 | public: |
| 5248 | // Accessors for the runtime routines written in JavaScript. |
| 5249 | inline Object* javascript_builtin(Builtins::JavaScript id); |
| 5250 | inline void set_javascript_builtin(Builtins::JavaScript id, Object* value); |
| 5251 | |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5252 | // Accessors for code of the runtime routines written in JavaScript. |
| 5253 | inline Code* javascript_builtin_code(Builtins::JavaScript id); |
| 5254 | inline void set_javascript_builtin_code(Builtins::JavaScript id, Code* value); |
| 5255 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5256 | // Casting. |
| 5257 | static inline JSBuiltinsObject* cast(Object* obj); |
| 5258 | |
| 5259 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5260 | #ifdef OBJECT_PRINT |
| 5261 | inline void JSBuiltinsObjectPrint() { |
| 5262 | JSBuiltinsObjectPrint(stdout); |
| 5263 | } |
| 5264 | void JSBuiltinsObjectPrint(FILE* out); |
| 5265 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5266 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5267 | void JSBuiltinsObjectVerify(); |
| 5268 | #endif |
| 5269 | |
| 5270 | // Layout description. The size of the builtins object includes |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5271 | // room for two pointers per runtime routine written in javascript |
| 5272 | // (function and code object). |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5273 | static const int kJSBuiltinsCount = Builtins::id_count; |
| 5274 | static const int kJSBuiltinsOffset = GlobalObject::kHeaderSize; |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5275 | static const int kJSBuiltinsCodeOffset = |
| 5276 | GlobalObject::kHeaderSize + (kJSBuiltinsCount * kPointerSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5277 | static const int kSize = |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 5278 | kJSBuiltinsCodeOffset + (kJSBuiltinsCount * kPointerSize); |
| 5279 | |
| 5280 | static int OffsetOfFunctionWithId(Builtins::JavaScript id) { |
| 5281 | return kJSBuiltinsOffset + id * kPointerSize; |
| 5282 | } |
| 5283 | |
| 5284 | static int OffsetOfCodeWithId(Builtins::JavaScript id) { |
| 5285 | return kJSBuiltinsCodeOffset + id * kPointerSize; |
| 5286 | } |
| 5287 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5288 | private: |
| 5289 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSBuiltinsObject); |
| 5290 | }; |
| 5291 | |
| 5292 | |
| 5293 | // Representation for JS Wrapper objects, String, Number, Boolean, Date, etc. |
| 5294 | class JSValue: public JSObject { |
| 5295 | public: |
| 5296 | // [value]: the object being wrapped. |
| 5297 | DECL_ACCESSORS(value, Object) |
| 5298 | |
| 5299 | // Casting. |
| 5300 | static inline JSValue* cast(Object* obj); |
| 5301 | |
| 5302 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5303 | #ifdef OBJECT_PRINT |
| 5304 | inline void JSValuePrint() { |
| 5305 | JSValuePrint(stdout); |
| 5306 | } |
| 5307 | void JSValuePrint(FILE* out); |
| 5308 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5309 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5310 | void JSValueVerify(); |
| 5311 | #endif |
| 5312 | |
| 5313 | // Layout description. |
| 5314 | static const int kValueOffset = JSObject::kHeaderSize; |
| 5315 | static const int kSize = kValueOffset + kPointerSize; |
| 5316 | |
| 5317 | private: |
| 5318 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSValue); |
| 5319 | }; |
| 5320 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 5321 | |
| 5322 | // Representation of message objects used for error reporting through |
| 5323 | // the API. The messages are formatted in JavaScript so this object is |
| 5324 | // a real JavaScript object. The information used for formatting the |
| 5325 | // error messages are not directly accessible from JavaScript to |
| 5326 | // prevent leaking information to user code called during error |
| 5327 | // formatting. |
| 5328 | class JSMessageObject: public JSObject { |
| 5329 | public: |
| 5330 | // [type]: the type of error message. |
| 5331 | DECL_ACCESSORS(type, String) |
| 5332 | |
| 5333 | // [arguments]: the arguments for formatting the error message. |
| 5334 | DECL_ACCESSORS(arguments, JSArray) |
| 5335 | |
| 5336 | // [script]: the script from which the error message originated. |
| 5337 | DECL_ACCESSORS(script, Object) |
| 5338 | |
| 5339 | // [stack_trace]: the stack trace for this error message. |
| 5340 | DECL_ACCESSORS(stack_trace, Object) |
| 5341 | |
| 5342 | // [stack_frames]: an array of stack frames for this error object. |
| 5343 | DECL_ACCESSORS(stack_frames, Object) |
| 5344 | |
| 5345 | // [start_position]: the start position in the script for the error message. |
| 5346 | inline int start_position(); |
| 5347 | inline void set_start_position(int value); |
| 5348 | |
| 5349 | // [end_position]: the end position in the script for the error message. |
| 5350 | inline int end_position(); |
| 5351 | inline void set_end_position(int value); |
| 5352 | |
| 5353 | // Casting. |
| 5354 | static inline JSMessageObject* cast(Object* obj); |
| 5355 | |
| 5356 | // Dispatched behavior. |
| 5357 | #ifdef OBJECT_PRINT |
| 5358 | inline void JSMessageObjectPrint() { |
| 5359 | JSMessageObjectPrint(stdout); |
| 5360 | } |
| 5361 | void JSMessageObjectPrint(FILE* out); |
| 5362 | #endif |
| 5363 | #ifdef DEBUG |
| 5364 | void JSMessageObjectVerify(); |
| 5365 | #endif |
| 5366 | |
| 5367 | // Layout description. |
| 5368 | static const int kTypeOffset = JSObject::kHeaderSize; |
| 5369 | static const int kArgumentsOffset = kTypeOffset + kPointerSize; |
| 5370 | static const int kScriptOffset = kArgumentsOffset + kPointerSize; |
| 5371 | static const int kStackTraceOffset = kScriptOffset + kPointerSize; |
| 5372 | static const int kStackFramesOffset = kStackTraceOffset + kPointerSize; |
| 5373 | static const int kStartPositionOffset = kStackFramesOffset + kPointerSize; |
| 5374 | static const int kEndPositionOffset = kStartPositionOffset + kPointerSize; |
| 5375 | static const int kSize = kEndPositionOffset + kPointerSize; |
| 5376 | |
| 5377 | typedef FixedBodyDescriptor<HeapObject::kMapOffset, |
| 5378 | kStackFramesOffset + kPointerSize, |
| 5379 | kSize> BodyDescriptor; |
| 5380 | }; |
| 5381 | |
| 5382 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5383 | // Regular expressions |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5384 | // The regular expression holds a single reference to a FixedArray in |
| 5385 | // the kDataOffset field. |
| 5386 | // The FixedArray contains the following data: |
| 5387 | // - tag : type of regexp implementation (not compiled yet, atom or irregexp) |
| 5388 | // - reference to the original source string |
| 5389 | // - reference to the original flag string |
| 5390 | // If it is an atom regexp |
| 5391 | // - a reference to a literal string to search for |
| 5392 | // If it is an irregexp regexp: |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5393 | // - a reference to code for ASCII inputs (bytecode or compiled), or a smi |
| 5394 | // used for tracking the last usage (used for code flushing). |
| 5395 | // - a reference to code for UC16 inputs (bytecode or compiled), or a smi |
| 5396 | // used for tracking the last usage (used for code flushing).. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5397 | // - max number of registers used by irregexp implementations. |
| 5398 | // - number of capture registers (output values) of the regexp. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5399 | class JSRegExp: public JSObject { |
| 5400 | public: |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5401 | // Meaning of Type: |
| 5402 | // NOT_COMPILED: Initial value. No data has been stored in the JSRegExp yet. |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5403 | // ATOM: A simple string to match against using an indexOf operation. |
| 5404 | // IRREGEXP: Compiled with Irregexp. |
| 5405 | // IRREGEXP_NATIVE: Compiled to native code with Irregexp. |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5406 | enum Type { NOT_COMPILED, ATOM, IRREGEXP }; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5407 | enum Flag { NONE = 0, GLOBAL = 1, IGNORE_CASE = 2, MULTILINE = 4 }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5408 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5409 | class Flags { |
| 5410 | public: |
| 5411 | explicit Flags(uint32_t value) : value_(value) { } |
| 5412 | bool is_global() { return (value_ & GLOBAL) != 0; } |
| 5413 | bool is_ignore_case() { return (value_ & IGNORE_CASE) != 0; } |
| 5414 | bool is_multiline() { return (value_ & MULTILINE) != 0; } |
| 5415 | uint32_t value() { return value_; } |
| 5416 | private: |
| 5417 | uint32_t value_; |
| 5418 | }; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5419 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5420 | DECL_ACCESSORS(data, Object) |
| 5421 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5422 | inline Type TypeTag(); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5423 | inline int CaptureCount(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 5424 | inline Flags GetFlags(); |
| 5425 | inline String* Pattern(); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5426 | inline Object* DataAt(int index); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5427 | // Set implementation data after the object has been prepared. |
| 5428 | inline void SetDataAt(int index, Object* value); |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5429 | |
| 5430 | // Used during GC when flushing code or setting age. |
| 5431 | inline Object* DataAtUnchecked(int index); |
| 5432 | inline void SetDataAtUnchecked(int index, Object* value, Heap* heap); |
| 5433 | inline Type TypeTagUnchecked(); |
| 5434 | |
kasperl@chromium.org | 68ac009 | 2009-07-09 06:00:35 +0000 | [diff] [blame] | 5435 | static int code_index(bool is_ascii) { |
| 5436 | if (is_ascii) { |
| 5437 | return kIrregexpASCIICodeIndex; |
| 5438 | } else { |
| 5439 | return kIrregexpUC16CodeIndex; |
| 5440 | } |
| 5441 | } |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5442 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5443 | static int saved_code_index(bool is_ascii) { |
| 5444 | if (is_ascii) { |
| 5445 | return kIrregexpASCIICodeSavedIndex; |
| 5446 | } else { |
| 5447 | return kIrregexpUC16CodeSavedIndex; |
| 5448 | } |
| 5449 | } |
| 5450 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5451 | static inline JSRegExp* cast(Object* obj); |
| 5452 | |
| 5453 | // Dispatched behavior. |
| 5454 | #ifdef DEBUG |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5455 | void JSRegExpVerify(); |
| 5456 | #endif |
| 5457 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5458 | static const int kDataOffset = JSObject::kHeaderSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 5459 | static const int kSize = kDataOffset + kPointerSize; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5460 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5461 | // Indices in the data array. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5462 | static const int kTagIndex = 0; |
| 5463 | static const int kSourceIndex = kTagIndex + 1; |
| 5464 | static const int kFlagsIndex = kSourceIndex + 1; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5465 | static const int kDataIndex = kFlagsIndex + 1; |
| 5466 | // The data fields are used in different ways depending on the |
| 5467 | // value of the tag. |
| 5468 | // Atom regexps (literal strings). |
| 5469 | static const int kAtomPatternIndex = kDataIndex; |
| 5470 | |
| 5471 | static const int kAtomDataSize = kAtomPatternIndex + 1; |
| 5472 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5473 | // Irregexp compiled code or bytecode for ASCII. If compilation |
| 5474 | // fails, this fields hold an exception object that should be |
| 5475 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5476 | static const int kIrregexpASCIICodeIndex = kDataIndex; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 5477 | // Irregexp compiled code or bytecode for UC16. If compilation |
| 5478 | // fails, this fields hold an exception object that should be |
| 5479 | // thrown if the regexp is used again. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5480 | static const int kIrregexpUC16CodeIndex = kDataIndex + 1; |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5481 | |
| 5482 | // Saved instance of Irregexp compiled code or bytecode for ASCII that |
| 5483 | // is a potential candidate for flushing. |
| 5484 | static const int kIrregexpASCIICodeSavedIndex = kDataIndex + 2; |
| 5485 | // Saved instance of Irregexp compiled code or bytecode for UC16 that is |
| 5486 | // a potential candidate for flushing. |
| 5487 | static const int kIrregexpUC16CodeSavedIndex = kDataIndex + 3; |
| 5488 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5489 | // Maximal number of registers used by either ASCII or UC16. |
| 5490 | // Only used to check that there is enough stack space |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5491 | static const int kIrregexpMaxRegisterCountIndex = kDataIndex + 4; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5492 | // Number of captures in the compiled regexp. |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5493 | static const int kIrregexpCaptureCountIndex = kDataIndex + 5; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 5494 | |
| 5495 | static const int kIrregexpDataSize = kIrregexpCaptureCountIndex + 1; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5496 | |
| 5497 | // Offsets directly into the data fixed array. |
| 5498 | static const int kDataTagOffset = |
| 5499 | FixedArray::kHeaderSize + kTagIndex * kPointerSize; |
| 5500 | static const int kDataAsciiCodeOffset = |
| 5501 | FixedArray::kHeaderSize + kIrregexpASCIICodeIndex * kPointerSize; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5502 | static const int kDataUC16CodeOffset = |
| 5503 | FixedArray::kHeaderSize + kIrregexpUC16CodeIndex * kPointerSize; |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 5504 | static const int kIrregexpCaptureCountOffset = |
| 5505 | FixedArray::kHeaderSize + kIrregexpCaptureCountIndex * kPointerSize; |
lrn@chromium.org | 25156de | 2010-04-06 13:10:27 +0000 | [diff] [blame] | 5506 | |
| 5507 | // In-object fields. |
| 5508 | static const int kSourceFieldIndex = 0; |
| 5509 | static const int kGlobalFieldIndex = 1; |
| 5510 | static const int kIgnoreCaseFieldIndex = 2; |
| 5511 | static const int kMultilineFieldIndex = 3; |
| 5512 | static const int kLastIndexFieldIndex = 4; |
lrn@chromium.org | c4e51ac | 2010-08-09 09:47:21 +0000 | [diff] [blame] | 5513 | static const int kInObjectFieldCount = 5; |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 5514 | |
| 5515 | // The uninitialized value for a regexp code object. |
| 5516 | static const int kUninitializedValue = -1; |
| 5517 | |
| 5518 | // The compilation error value for the regexp code object. The real error |
| 5519 | // object is in the saved code field. |
| 5520 | static const int kCompilationErrorValue = -2; |
| 5521 | |
| 5522 | // When we store the sweep generation at which we moved the code from the |
| 5523 | // code index to the saved code index we mask it of to be in the [0:255] |
| 5524 | // range. |
| 5525 | static const int kCodeAgeMask = 0xff; |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5526 | }; |
| 5527 | |
| 5528 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5529 | class CompilationCacheShape { |
| 5530 | public: |
| 5531 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5532 | return key->IsMatch(value); |
| 5533 | } |
| 5534 | |
| 5535 | static inline uint32_t Hash(HashTableKey* key) { |
| 5536 | return key->Hash(); |
| 5537 | } |
| 5538 | |
| 5539 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 5540 | return key->HashForObject(object); |
| 5541 | } |
| 5542 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5543 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5544 | return key->AsObject(); |
| 5545 | } |
| 5546 | |
| 5547 | static const int kPrefixSize = 0; |
| 5548 | static const int kEntrySize = 2; |
| 5549 | }; |
| 5550 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 5551 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5552 | class CompilationCacheTable: public HashTable<CompilationCacheShape, |
| 5553 | HashTableKey*> { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5554 | public: |
| 5555 | // Find cached value for a string key, otherwise return null. |
| 5556 | Object* Lookup(String* src); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5557 | Object* LookupEval(String* src, Context* context, StrictModeFlag strict_mode); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5558 | Object* LookupRegExp(String* source, JSRegExp::Flags flags); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5559 | MaybeObject* Put(String* src, Object* value); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 5560 | MaybeObject* PutEval(String* src, |
| 5561 | Context* context, |
| 5562 | SharedFunctionInfo* value); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5563 | MaybeObject* PutRegExp(String* src, JSRegExp::Flags flags, FixedArray* value); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5564 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5565 | // Remove given value from cache. |
| 5566 | void Remove(Object* value); |
| 5567 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5568 | static inline CompilationCacheTable* cast(Object* obj); |
| 5569 | |
| 5570 | private: |
| 5571 | DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheTable); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5572 | }; |
| 5573 | |
| 5574 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5575 | class CodeCache: public Struct { |
| 5576 | public: |
| 5577 | DECL_ACCESSORS(default_cache, FixedArray) |
| 5578 | DECL_ACCESSORS(normal_type_cache, Object) |
| 5579 | |
| 5580 | // Add the code object to the cache. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5581 | MUST_USE_RESULT MaybeObject* Update(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5582 | |
| 5583 | // Lookup code object in the cache. Returns code object if found and undefined |
| 5584 | // if not. |
| 5585 | Object* Lookup(String* name, Code::Flags flags); |
| 5586 | |
| 5587 | // Get the internal index of a code object in the cache. Returns -1 if the |
| 5588 | // code object is not in that cache. This index can be used to later call |
| 5589 | // RemoveByIndex. The cache cannot be modified between a call to GetIndex and |
| 5590 | // RemoveByIndex. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 5591 | int GetIndex(Object* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5592 | |
| 5593 | // Remove an object from the cache with the provided internal index. |
sgjesse@chromium.org | 99a37fa | 2010-03-11 09:23:46 +0000 | [diff] [blame] | 5594 | void RemoveByIndex(Object* name, Code* code, int index); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5595 | |
| 5596 | static inline CodeCache* cast(Object* obj); |
| 5597 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5598 | #ifdef OBJECT_PRINT |
| 5599 | inline void CodeCachePrint() { |
| 5600 | CodeCachePrint(stdout); |
| 5601 | } |
| 5602 | void CodeCachePrint(FILE* out); |
| 5603 | #endif |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5604 | #ifdef DEBUG |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5605 | void CodeCacheVerify(); |
| 5606 | #endif |
| 5607 | |
| 5608 | static const int kDefaultCacheOffset = HeapObject::kHeaderSize; |
| 5609 | static const int kNormalTypeCacheOffset = |
| 5610 | kDefaultCacheOffset + kPointerSize; |
| 5611 | static const int kSize = kNormalTypeCacheOffset + kPointerSize; |
| 5612 | |
| 5613 | private: |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5614 | MUST_USE_RESULT MaybeObject* UpdateDefaultCache(String* name, Code* code); |
| 5615 | MUST_USE_RESULT MaybeObject* UpdateNormalTypeCache(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5616 | Object* LookupDefaultCache(String* name, Code::Flags flags); |
| 5617 | Object* LookupNormalTypeCache(String* name, Code::Flags flags); |
| 5618 | |
| 5619 | // Code cache layout of the default cache. Elements are alternating name and |
| 5620 | // code objects for non normal load/store/call IC's. |
| 5621 | static const int kCodeCacheEntrySize = 2; |
| 5622 | static const int kCodeCacheEntryNameOffset = 0; |
| 5623 | static const int kCodeCacheEntryCodeOffset = 1; |
| 5624 | |
| 5625 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCache); |
| 5626 | }; |
| 5627 | |
| 5628 | |
| 5629 | class CodeCacheHashTableShape { |
| 5630 | public: |
| 5631 | static inline bool IsMatch(HashTableKey* key, Object* value) { |
| 5632 | return key->IsMatch(value); |
| 5633 | } |
| 5634 | |
| 5635 | static inline uint32_t Hash(HashTableKey* key) { |
| 5636 | return key->Hash(); |
| 5637 | } |
| 5638 | |
| 5639 | static inline uint32_t HashForObject(HashTableKey* key, Object* object) { |
| 5640 | return key->HashForObject(object); |
| 5641 | } |
| 5642 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5643 | MUST_USE_RESULT static MaybeObject* AsObject(HashTableKey* key) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5644 | return key->AsObject(); |
| 5645 | } |
| 5646 | |
| 5647 | static const int kPrefixSize = 0; |
| 5648 | static const int kEntrySize = 2; |
| 5649 | }; |
| 5650 | |
| 5651 | |
| 5652 | class CodeCacheHashTable: public HashTable<CodeCacheHashTableShape, |
| 5653 | HashTableKey*> { |
| 5654 | public: |
| 5655 | Object* Lookup(String* name, Code::Flags flags); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5656 | MUST_USE_RESULT MaybeObject* Put(String* name, Code* code); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 5657 | |
| 5658 | int GetIndex(String* name, Code::Flags flags); |
| 5659 | void RemoveByIndex(int index); |
| 5660 | |
| 5661 | static inline CodeCacheHashTable* cast(Object* obj); |
| 5662 | |
| 5663 | // Initial size of the fixed array backing the hash table. |
| 5664 | static const int kInitialSize = 64; |
| 5665 | |
| 5666 | private: |
| 5667 | DISALLOW_IMPLICIT_CONSTRUCTORS(CodeCacheHashTable); |
| 5668 | }; |
| 5669 | |
| 5670 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 5671 | class PolymorphicCodeCache: public Struct { |
| 5672 | public: |
| 5673 | DECL_ACCESSORS(cache, Object) |
| 5674 | |
| 5675 | MUST_USE_RESULT MaybeObject* Update(MapList* maps, |
| 5676 | Code::Flags flags, |
| 5677 | Code* code); |
| 5678 | Object* Lookup(MapList* maps, Code::Flags flags); |
| 5679 | |
| 5680 | static inline PolymorphicCodeCache* cast(Object* obj); |
| 5681 | |
| 5682 | #ifdef OBJECT_PRINT |
| 5683 | inline void PolymorphicCodeCachePrint() { |
| 5684 | PolymorphicCodeCachePrint(stdout); |
| 5685 | } |
| 5686 | void PolymorphicCodeCachePrint(FILE* out); |
| 5687 | #endif |
| 5688 | #ifdef DEBUG |
| 5689 | void PolymorphicCodeCacheVerify(); |
| 5690 | #endif |
| 5691 | |
| 5692 | static const int kCacheOffset = HeapObject::kHeaderSize; |
| 5693 | static const int kSize = kCacheOffset + kPointerSize; |
| 5694 | |
| 5695 | private: |
| 5696 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCache); |
| 5697 | }; |
| 5698 | |
| 5699 | |
| 5700 | class PolymorphicCodeCacheHashTable |
| 5701 | : public HashTable<CodeCacheHashTableShape, HashTableKey*> { |
| 5702 | public: |
| 5703 | Object* Lookup(MapList* maps, int code_kind); |
| 5704 | MUST_USE_RESULT MaybeObject* Put(MapList* maps, int code_kind, Code* code); |
| 5705 | |
| 5706 | static inline PolymorphicCodeCacheHashTable* cast(Object* obj); |
| 5707 | |
| 5708 | static const int kInitialSize = 64; |
| 5709 | private: |
| 5710 | DISALLOW_IMPLICIT_CONSTRUCTORS(PolymorphicCodeCacheHashTable); |
| 5711 | }; |
| 5712 | |
| 5713 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5714 | enum AllowNullsFlag {ALLOW_NULLS, DISALLOW_NULLS}; |
| 5715 | enum RobustnessFlag {ROBUST_STRING_TRAVERSAL, FAST_STRING_TRAVERSAL}; |
| 5716 | |
| 5717 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5718 | class StringHasher { |
| 5719 | public: |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 5720 | explicit inline StringHasher(int length); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5721 | |
| 5722 | // Returns true if the hash of this string can be computed without |
| 5723 | // looking at the contents. |
| 5724 | inline bool has_trivial_hash(); |
| 5725 | |
| 5726 | // Add a character to the hash and update the array index calculation. |
| 5727 | inline void AddCharacter(uc32 c); |
| 5728 | |
| 5729 | // Adds a character to the hash but does not update the array index |
| 5730 | // calculation. This can only be called when it has been verified |
| 5731 | // that the input is not an array index. |
| 5732 | inline void AddCharacterNoIndex(uc32 c); |
| 5733 | |
| 5734 | // Returns the value to store in the hash field of a string with |
| 5735 | // the given length and contents. |
| 5736 | uint32_t GetHashField(); |
| 5737 | |
| 5738 | // Returns true if the characters seen so far make up a legal array |
| 5739 | // index. |
| 5740 | bool is_array_index() { return is_array_index_; } |
| 5741 | |
| 5742 | bool is_valid() { return is_valid_; } |
| 5743 | |
| 5744 | void invalidate() { is_valid_ = false; } |
| 5745 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 5746 | // Calculated hash value for a string consisting of 1 to |
| 5747 | // String::kMaxArrayIndexSize digits with no leading zeros (except "0"). |
| 5748 | // value is represented decimal value. |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 5749 | static uint32_t MakeArrayIndexHash(uint32_t value, int length); |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 5750 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5751 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5752 | uint32_t array_index() { |
| 5753 | ASSERT(is_array_index()); |
| 5754 | return array_index_; |
| 5755 | } |
| 5756 | |
| 5757 | inline uint32_t GetHash(); |
| 5758 | |
| 5759 | int length_; |
| 5760 | uint32_t raw_running_hash_; |
| 5761 | uint32_t array_index_; |
| 5762 | bool is_array_index_; |
| 5763 | bool is_first_char_; |
| 5764 | bool is_valid_; |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5765 | friend class TwoCharHashTableKey; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5766 | }; |
| 5767 | |
| 5768 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 5769 | // Calculates string hash. |
| 5770 | template <typename schar> |
| 5771 | inline uint32_t HashSequentialString(const schar* chars, int length); |
| 5772 | |
| 5773 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5774 | // The characteristics of a string are stored in its map. Retrieving these |
| 5775 | // few bits of information is moderately expensive, involving two memory |
| 5776 | // loads where the second is dependent on the first. To improve efficiency |
| 5777 | // the shape of the string is given its own class so that it can be retrieved |
| 5778 | // once and used for several string operations. A StringShape is small enough |
| 5779 | // to be passed by value and is immutable, but be aware that flattening a |
ager@chromium.org | c3e50d8 | 2008-11-05 11:53:10 +0000 | [diff] [blame] | 5780 | // string can potentially alter its shape. Also be aware that a GC caused by |
| 5781 | // something else can alter the shape of a string due to ConsString |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5782 | // shortcutting. Keeping these restrictions in mind has proven to be error- |
| 5783 | // prone and so we no longer put StringShapes in variables unless there is a |
| 5784 | // concrete performance benefit at that particular point in the code. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5785 | class StringShape BASE_EMBEDDED { |
| 5786 | public: |
| 5787 | inline explicit StringShape(String* s); |
| 5788 | inline explicit StringShape(Map* s); |
| 5789 | inline explicit StringShape(InstanceType t); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5790 | inline bool IsSequential(); |
| 5791 | inline bool IsExternal(); |
| 5792 | inline bool IsCons(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5793 | inline bool IsExternalAscii(); |
| 5794 | inline bool IsExternalTwoByte(); |
| 5795 | inline bool IsSequentialAscii(); |
| 5796 | inline bool IsSequentialTwoByte(); |
| 5797 | inline bool IsSymbol(); |
| 5798 | inline StringRepresentationTag representation_tag(); |
| 5799 | inline uint32_t full_representation_tag(); |
| 5800 | inline uint32_t size_tag(); |
| 5801 | #ifdef DEBUG |
| 5802 | inline uint32_t type() { return type_; } |
| 5803 | inline void invalidate() { valid_ = false; } |
| 5804 | inline bool valid() { return valid_; } |
| 5805 | #else |
| 5806 | inline void invalidate() { } |
| 5807 | #endif |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 5808 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 5809 | private: |
| 5810 | uint32_t type_; |
| 5811 | #ifdef DEBUG |
| 5812 | inline void set_valid() { valid_ = true; } |
| 5813 | bool valid_; |
| 5814 | #else |
| 5815 | inline void set_valid() { } |
| 5816 | #endif |
| 5817 | }; |
| 5818 | |
| 5819 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5820 | // The String abstract class captures JavaScript string values: |
| 5821 | // |
| 5822 | // Ecma-262: |
| 5823 | // 4.3.16 String Value |
| 5824 | // A string value is a member of the type String and is a finite |
| 5825 | // ordered sequence of zero or more 16-bit unsigned integer values. |
| 5826 | // |
| 5827 | // All string values have a length field. |
| 5828 | class String: public HeapObject { |
| 5829 | public: |
| 5830 | // Get and set the length of the string. |
| 5831 | inline int length(); |
| 5832 | inline void set_length(int value); |
| 5833 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5834 | // Get and set the hash field of the string. |
| 5835 | inline uint32_t hash_field(); |
| 5836 | inline void set_hash_field(uint32_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5837 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 5838 | inline bool IsAsciiRepresentation(); |
| 5839 | inline bool IsTwoByteRepresentation(); |
| 5840 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5841 | // Returns whether this string has ascii chars, i.e. all of them can |
| 5842 | // be ascii encoded. This might be the case even if the string is |
| 5843 | // two-byte. Such strings may appear when the embedder prefers |
| 5844 | // two-byte external representations even for ascii data. |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 5845 | // |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 5846 | // NOTE: this should be considered only a hint. False negatives are |
| 5847 | // possible. |
| 5848 | inline bool HasOnlyAsciiChars(); |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 5849 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5850 | // Get and set individual two byte chars in the string. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5851 | inline void Set(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5852 | // Get individual two byte char in the string. Repeated calls |
| 5853 | // to this method are not efficient unless the string is flat. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5854 | inline uint16_t Get(int index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5855 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5856 | // Try to flatten the string. Checks first inline to see if it is |
| 5857 | // necessary. Does nothing if the string is not a cons string. |
| 5858 | // Flattening allocates a sequential string with the same data as |
| 5859 | // the given string and mutates the cons string to a degenerate |
| 5860 | // form, where the first component is the new sequential string and |
| 5861 | // the second component is the empty string. If allocation fails, |
| 5862 | // this function returns a failure. If flattening succeeds, this |
| 5863 | // function returns the sequential string that is now the first |
| 5864 | // component of the cons string. |
| 5865 | // |
| 5866 | // Degenerate cons strings are handled specially by the garbage |
| 5867 | // collector (see IsShortcutCandidate). |
| 5868 | // |
| 5869 | // Use FlattenString from Handles.cc to flatten even in case an |
| 5870 | // allocation failure happens. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5871 | inline MaybeObject* TryFlatten(PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5872 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 5873 | // Convenience function. Has exactly the same behavior as |
| 5874 | // TryFlatten(), except in the case of failure returns the original |
| 5875 | // string. |
| 5876 | inline String* TryFlattenGetString(PretenureFlag pretenure = NOT_TENURED); |
| 5877 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5878 | Vector<const char> ToAsciiVector(); |
| 5879 | Vector<const uc16> ToUC16Vector(); |
| 5880 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5881 | // Mark the string as an undetectable object. It only applies to |
| 5882 | // ascii and two byte string types. |
| 5883 | bool MarkAsUndetectable(); |
| 5884 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5885 | // Return a substring. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5886 | MUST_USE_RESULT MaybeObject* SubString(int from, |
| 5887 | int to, |
| 5888 | PretenureFlag pretenure = NOT_TENURED); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5889 | |
| 5890 | // String equality operations. |
| 5891 | inline bool Equals(String* other); |
| 5892 | bool IsEqualTo(Vector<const char> str); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 5893 | bool IsAsciiEqualTo(Vector<const char> str); |
| 5894 | bool IsTwoByteEqualTo(Vector<const uc16> str); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5895 | |
| 5896 | // Return a UTF8 representation of the string. The string is null |
| 5897 | // terminated but may optionally contain nulls. Length is returned |
| 5898 | // in length_output if length_output is not a null pointer The string |
| 5899 | // should be nearly flat, otherwise the performance of this method may |
| 5900 | // be very slow (quadratic in the length). Setting robustness_flag to |
| 5901 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 5902 | // handles unexpected data without causing assert failures and it does not |
| 5903 | // do any heap allocations. This is useful when printing stack traces. |
| 5904 | SmartPointer<char> ToCString(AllowNullsFlag allow_nulls, |
| 5905 | RobustnessFlag robustness_flag, |
| 5906 | int offset, |
| 5907 | int length, |
| 5908 | int* length_output = 0); |
| 5909 | SmartPointer<char> ToCString( |
| 5910 | AllowNullsFlag allow_nulls = DISALLOW_NULLS, |
| 5911 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL, |
| 5912 | int* length_output = 0); |
| 5913 | |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 5914 | int Utf8Length(); |
| 5915 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5916 | // Return a 16 bit Unicode representation of the string. |
| 5917 | // The string should be nearly flat, otherwise the performance of |
| 5918 | // of this method may be very bad. Setting robustness_flag to |
| 5919 | // ROBUST_STRING_TRAVERSAL invokes behaviour that is robust This means it |
| 5920 | // handles unexpected data without causing assert failures and it does not |
| 5921 | // do any heap allocations. This is useful when printing stack traces. |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 5922 | SmartPointer<uc16> ToWideCString( |
| 5923 | RobustnessFlag robustness_flag = FAST_STRING_TRAVERSAL); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5924 | |
| 5925 | // Tells whether the hash code has been computed. |
| 5926 | inline bool HasHashCode(); |
| 5927 | |
| 5928 | // Returns a hash value used for the property table |
| 5929 | inline uint32_t Hash(); |
| 5930 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5931 | static uint32_t ComputeHashField(unibrow::CharacterStream* buffer, |
| 5932 | int length); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5933 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5934 | static bool ComputeArrayIndex(unibrow::CharacterStream* buffer, |
| 5935 | uint32_t* index, |
| 5936 | int length); |
| 5937 | |
ager@chromium.org | 6f10e41 | 2009-02-13 10:11:16 +0000 | [diff] [blame] | 5938 | // Externalization. |
| 5939 | bool MakeExternal(v8::String::ExternalStringResource* resource); |
| 5940 | bool MakeExternal(v8::String::ExternalAsciiStringResource* resource); |
| 5941 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5942 | // Conversion. |
| 5943 | inline bool AsArrayIndex(uint32_t* index); |
| 5944 | |
| 5945 | // Casting. |
| 5946 | static inline String* cast(Object* obj); |
| 5947 | |
| 5948 | void PrintOn(FILE* out); |
| 5949 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5950 | // For use during stack traces. Performs rudimentary sanity check. |
| 5951 | bool LooksValid(); |
| 5952 | |
| 5953 | // Dispatched behavior. |
| 5954 | void StringShortPrint(StringStream* accumulator); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5955 | #ifdef OBJECT_PRINT |
| 5956 | inline void StringPrint() { |
| 5957 | StringPrint(stdout); |
| 5958 | } |
| 5959 | void StringPrint(FILE* out); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 5960 | |
| 5961 | char* ToAsciiArray(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 5962 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5963 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5964 | void StringVerify(); |
| 5965 | #endif |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 5966 | inline bool IsFlat(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5967 | |
| 5968 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 5969 | static const int kLengthOffset = HeapObject::kHeaderSize; |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 5970 | static const int kHashFieldOffset = kLengthOffset + kPointerSize; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5971 | static const int kSize = kHashFieldOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5972 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 5973 | // Maximum number of characters to consider when trying to convert a string |
| 5974 | // value into an array index. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5975 | static const int kMaxArrayIndexSize = 10; |
| 5976 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5977 | // Max ascii char code. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5978 | static const int kMaxAsciiCharCode = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 5979 | static const unsigned kMaxAsciiCharCodeU = unibrow::Utf8::kMaxOneByteChar; |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 5980 | static const int kMaxUC16CharCode = 0xffff; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5981 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 5982 | // Minimum length for a cons string. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5983 | static const int kMinNonFlatLength = 13; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5984 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5985 | // Mask constant for checking if a string has a computed hash code |
| 5986 | // and if it is an array index. The least significant bit indicates |
| 5987 | // whether a hash code has been computed. If the hash code has been |
| 5988 | // computed the 2nd bit tells whether the string can be used as an |
| 5989 | // array index. |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5990 | static const int kHashNotComputedMask = 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5991 | static const int kIsNotArrayIndexMask = 1 << 1; |
| 5992 | static const int kNofHashBitFields = 2; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5993 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5994 | // Shift constant retrieving hash code from hash field. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 5995 | static const int kHashShift = kNofHashBitFields; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 5996 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5997 | // Array index strings this short can keep their index in the hash |
| 5998 | // field. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 5999 | static const int kMaxCachedArrayIndexLength = 7; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6000 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6001 | // For strings which are array indexes the hash value has the string length |
| 6002 | // mixed into the hash, mainly to avoid a hash value of zero which would be |
| 6003 | // the case for the string '0'. 24 bits are used for the array index value. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6004 | static const int kArrayIndexValueBits = 24; |
| 6005 | static const int kArrayIndexLengthBits = |
| 6006 | kBitsPerInt - kArrayIndexValueBits - kNofHashBitFields; |
| 6007 | |
| 6008 | STATIC_CHECK((kArrayIndexLengthBits > 0)); |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 6009 | STATIC_CHECK(kMaxArrayIndexSize < (1 << kArrayIndexLengthBits)); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6010 | |
| 6011 | static const int kArrayIndexHashLengthShift = |
| 6012 | kArrayIndexValueBits + kNofHashBitFields; |
| 6013 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6014 | static const int kArrayIndexHashMask = (1 << kArrayIndexHashLengthShift) - 1; |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6015 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6016 | static const int kArrayIndexValueMask = |
| 6017 | ((1 << kArrayIndexValueBits) - 1) << kHashShift; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 6018 | |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6019 | // Check that kMaxCachedArrayIndexLength + 1 is a power of two so we |
| 6020 | // could use a mask to test if the length of string is less than or equal to |
| 6021 | // kMaxCachedArrayIndexLength. |
| 6022 | STATIC_CHECK(IS_POWER_OF_TWO(kMaxCachedArrayIndexLength + 1)); |
| 6023 | |
| 6024 | static const int kContainsCachedArrayIndexMask = |
| 6025 | (~kMaxCachedArrayIndexLength << kArrayIndexHashLengthShift) | |
| 6026 | kIsNotArrayIndexMask; |
| 6027 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6028 | // Value of empty hash field indicating that the hash is not computed. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6029 | static const int kEmptyHashField = |
| 6030 | kIsNotArrayIndexMask | kHashNotComputedMask; |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6031 | |
| 6032 | // Value of hash field containing computed hash equal to zero. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 6033 | static const int kZeroHash = kIsNotArrayIndexMask; |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 6034 | |
| 6035 | // Maximal string length. |
| 6036 | static const int kMaxLength = (1 << (32 - 2)) - 1; |
| 6037 | |
| 6038 | // Max length for computing hash. For strings longer than this limit the |
| 6039 | // string length is used as the hash value. |
| 6040 | static const int kMaxHashCalcLength = 16383; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6041 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 6042 | // Limit for truncation in short printing. |
| 6043 | static const int kMaxShortPrintLength = 1024; |
| 6044 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6045 | // Support for regular expressions. |
| 6046 | const uc16* GetTwoByteData(); |
| 6047 | const uc16* GetTwoByteData(unsigned start); |
| 6048 | |
| 6049 | // Support for StringInputBuffer |
| 6050 | static const unibrow::byte* ReadBlock(String* input, |
| 6051 | unibrow::byte* util_buffer, |
| 6052 | unsigned capacity, |
| 6053 | unsigned* remaining, |
| 6054 | unsigned* offset); |
| 6055 | static const unibrow::byte* ReadBlock(String** input, |
| 6056 | unibrow::byte* util_buffer, |
| 6057 | unsigned capacity, |
| 6058 | unsigned* remaining, |
| 6059 | unsigned* offset); |
| 6060 | |
| 6061 | // Helper function for flattening strings. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6062 | template <typename sinkchar> |
| 6063 | static void WriteToFlat(String* source, |
| 6064 | sinkchar* sink, |
| 6065 | int from, |
| 6066 | int to); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6067 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 6068 | static inline bool IsAscii(const char* chars, int length) { |
| 6069 | const char* limit = chars + length; |
| 6070 | #ifdef V8_HOST_CAN_READ_UNALIGNED |
| 6071 | ASSERT(kMaxAsciiCharCode == 0x7F); |
| 6072 | const uintptr_t non_ascii_mask = kUintptrAllBitsSet / 0xFF * 0x80; |
| 6073 | while (chars <= limit - sizeof(uintptr_t)) { |
| 6074 | if (*reinterpret_cast<const uintptr_t*>(chars) & non_ascii_mask) { |
| 6075 | return false; |
| 6076 | } |
| 6077 | chars += sizeof(uintptr_t); |
| 6078 | } |
| 6079 | #endif |
| 6080 | while (chars < limit) { |
| 6081 | if (static_cast<uint8_t>(*chars) > kMaxAsciiCharCodeU) return false; |
| 6082 | ++chars; |
| 6083 | } |
| 6084 | return true; |
| 6085 | } |
| 6086 | |
| 6087 | static inline bool IsAscii(const uc16* chars, int length) { |
| 6088 | const uc16* limit = chars + length; |
| 6089 | while (chars < limit) { |
| 6090 | if (*chars > kMaxAsciiCharCodeU) return false; |
| 6091 | ++chars; |
| 6092 | } |
| 6093 | return true; |
| 6094 | } |
| 6095 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6096 | protected: |
| 6097 | class ReadBlockBuffer { |
| 6098 | public: |
| 6099 | ReadBlockBuffer(unibrow::byte* util_buffer_, |
| 6100 | unsigned cursor_, |
| 6101 | unsigned capacity_, |
| 6102 | unsigned remaining_) : |
| 6103 | util_buffer(util_buffer_), |
| 6104 | cursor(cursor_), |
| 6105 | capacity(capacity_), |
| 6106 | remaining(remaining_) { |
| 6107 | } |
| 6108 | unibrow::byte* util_buffer; |
| 6109 | unsigned cursor; |
| 6110 | unsigned capacity; |
| 6111 | unsigned remaining; |
| 6112 | }; |
| 6113 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6114 | static inline const unibrow::byte* ReadBlock(String* input, |
| 6115 | ReadBlockBuffer* buffer, |
| 6116 | unsigned* offset, |
| 6117 | unsigned max_chars); |
| 6118 | static void ReadBlockIntoBuffer(String* input, |
| 6119 | ReadBlockBuffer* buffer, |
| 6120 | unsigned* offset_ptr, |
| 6121 | unsigned max_chars); |
| 6122 | |
| 6123 | private: |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6124 | // Try to flatten the top level ConsString that is hiding behind this |
| 6125 | // string. This is a no-op unless the string is a ConsString. Flatten |
| 6126 | // mutates the ConsString and might return a failure. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6127 | MUST_USE_RESULT MaybeObject* SlowTryFlatten(PretenureFlag pretenure); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 6128 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6129 | static inline bool IsHashFieldComputed(uint32_t field); |
| 6130 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6131 | // Slow case of String::Equals. This implementation works on any strings |
| 6132 | // but it is most efficient on strings that are almost flat. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6133 | bool SlowEquals(String* other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6134 | |
| 6135 | // Slow case of AsArrayIndex. |
| 6136 | bool SlowAsArrayIndex(uint32_t* index); |
| 6137 | |
| 6138 | // Compute and set the hash code. |
| 6139 | uint32_t ComputeAndSetHash(); |
| 6140 | |
| 6141 | DISALLOW_IMPLICIT_CONSTRUCTORS(String); |
| 6142 | }; |
| 6143 | |
| 6144 | |
| 6145 | // The SeqString abstract class captures sequential string values. |
| 6146 | class SeqString: public String { |
| 6147 | public: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6148 | // Casting. |
| 6149 | static inline SeqString* cast(Object* obj); |
| 6150 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6151 | private: |
| 6152 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqString); |
| 6153 | }; |
| 6154 | |
| 6155 | |
| 6156 | // The AsciiString class captures sequential ascii string objects. |
| 6157 | // Each character in the AsciiString is an ascii character. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6158 | class SeqAsciiString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6159 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 6160 | static const bool kHasAsciiEncoding = true; |
| 6161 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6162 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6163 | inline uint16_t SeqAsciiStringGet(int index); |
| 6164 | inline void SeqAsciiStringSet(int index, uint16_t value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6165 | |
| 6166 | // Get the address of the characters in this string. |
| 6167 | inline Address GetCharsAddress(); |
| 6168 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6169 | inline char* GetChars(); |
| 6170 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6171 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6172 | static inline SeqAsciiString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6173 | |
| 6174 | // Garbage collection support. This method is called by the |
| 6175 | // garbage collector to compute the actual size of an AsciiString |
| 6176 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6177 | inline int SeqAsciiStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6178 | |
| 6179 | // Computes the size for an AsciiString instance of a given length. |
| 6180 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6181 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kCharSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6182 | } |
| 6183 | |
| 6184 | // Layout description. |
| 6185 | static const int kHeaderSize = String::kSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6186 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6187 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6188 | // Maximal memory usage for a single sequential ASCII string. |
| 6189 | static const int kMaxSize = 512 * MB; |
| 6190 | // Maximal length of a single sequential ASCII string. |
| 6191 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6192 | static const int kMaxLength = (kMaxSize - kHeaderSize); |
| 6193 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6194 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6195 | inline void SeqAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6196 | unsigned* offset, |
| 6197 | unsigned chars); |
| 6198 | inline const unibrow::byte* SeqAsciiStringReadBlock(unsigned* remaining, |
| 6199 | unsigned* offset, |
| 6200 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6201 | |
| 6202 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6203 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqAsciiString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6204 | }; |
| 6205 | |
| 6206 | |
| 6207 | // The TwoByteString class captures sequential unicode string objects. |
| 6208 | // Each character in the TwoByteString is a two-byte uint16_t. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6209 | class SeqTwoByteString: public SeqString { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6210 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 6211 | static const bool kHasAsciiEncoding = false; |
| 6212 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6213 | // Dispatched behavior. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6214 | inline uint16_t SeqTwoByteStringGet(int index); |
| 6215 | inline void SeqTwoByteStringSet(int index, uint16_t value); |
| 6216 | |
| 6217 | // Get the address of the characters in this string. |
| 6218 | inline Address GetCharsAddress(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6219 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6220 | inline uc16* GetChars(); |
| 6221 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6222 | // For regexp code. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6223 | const uint16_t* SeqTwoByteStringGetData(unsigned start); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6224 | |
| 6225 | // Casting |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6226 | static inline SeqTwoByteString* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6227 | |
| 6228 | // Garbage collection support. This method is called by the |
| 6229 | // garbage collector to compute the actual size of a TwoByteString |
| 6230 | // instance. |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 6231 | inline int SeqTwoByteStringSize(InstanceType instance_type); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6232 | |
| 6233 | // Computes the size for a TwoByteString instance of a given length. |
| 6234 | static int SizeFor(int length) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 6235 | return OBJECT_POINTER_ALIGN(kHeaderSize + length * kShortSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6236 | } |
| 6237 | |
| 6238 | // Layout description. |
| 6239 | static const int kHeaderSize = String::kSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6240 | static const int kAlignedSize = POINTER_SIZE_ALIGN(kHeaderSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6241 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 6242 | // Maximal memory usage for a single sequential two-byte string. |
| 6243 | static const int kMaxSize = 512 * MB; |
| 6244 | // Maximal length of a single sequential two-byte string. |
| 6245 | // Q.v. String::kMaxLength which is the maximal size of concatenated strings. |
| 6246 | static const int kMaxLength = (kMaxSize - kHeaderSize) / sizeof(uint16_t); |
| 6247 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6248 | // Support for StringInputBuffer. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6249 | inline void SeqTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6250 | unsigned* offset_ptr, |
| 6251 | unsigned chars); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6252 | |
| 6253 | private: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6254 | DISALLOW_IMPLICIT_CONSTRUCTORS(SeqTwoByteString); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6255 | }; |
| 6256 | |
| 6257 | |
| 6258 | // The ConsString class describes string values built by using the |
| 6259 | // addition operator on strings. A ConsString is a pair where the |
| 6260 | // first and second components are pointers to other string values. |
| 6261 | // One or both components of a ConsString can be pointers to other |
| 6262 | // ConsStrings, creating a binary tree of ConsStrings where the leaves |
| 6263 | // are non-ConsString string values. The string value represented by |
| 6264 | // a ConsString can be obtained by concatenating the leaf string |
| 6265 | // values in a left-to-right depth-first traversal of the tree. |
| 6266 | class ConsString: public String { |
| 6267 | public: |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6268 | // First string of the cons cell. |
| 6269 | inline String* first(); |
| 6270 | // Doesn't check that the result is a string, even in debug mode. This is |
| 6271 | // useful during GC where the mark bits confuse the checks. |
| 6272 | inline Object* unchecked_first(); |
| 6273 | inline void set_first(String* first, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6274 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6275 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6276 | // Second string of the cons cell. |
| 6277 | inline String* second(); |
| 6278 | // Doesn't check that the result is a string, even in debug mode. This is |
| 6279 | // useful during GC where the mark bits confuse the checks. |
| 6280 | inline Object* unchecked_second(); |
| 6281 | inline void set_second(String* second, |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 6282 | WriteBarrierMode mode = UPDATE_WRITE_BARRIER); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6283 | |
| 6284 | // Dispatched behavior. |
| 6285 | uint16_t ConsStringGet(int index); |
| 6286 | |
| 6287 | // Casting. |
| 6288 | static inline ConsString* cast(Object* obj); |
| 6289 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6290 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6291 | static const int kFirstOffset = POINTER_SIZE_ALIGN(String::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6292 | static const int kSecondOffset = kFirstOffset + kPointerSize; |
| 6293 | static const int kSize = kSecondOffset + kPointerSize; |
| 6294 | |
| 6295 | // Support for StringInputBuffer. |
| 6296 | inline const unibrow::byte* ConsStringReadBlock(ReadBlockBuffer* buffer, |
| 6297 | unsigned* offset_ptr, |
| 6298 | unsigned chars); |
| 6299 | inline void ConsStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6300 | unsigned* offset_ptr, |
| 6301 | unsigned chars); |
| 6302 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 6303 | // Minimum length for a cons string. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6304 | static const int kMinLength = 13; |
| 6305 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6306 | typedef FixedBodyDescriptor<kFirstOffset, kSecondOffset + kPointerSize, kSize> |
| 6307 | BodyDescriptor; |
| 6308 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6309 | private: |
| 6310 | DISALLOW_IMPLICIT_CONSTRUCTORS(ConsString); |
| 6311 | }; |
| 6312 | |
| 6313 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6314 | // The ExternalString class describes string values that are backed by |
| 6315 | // a string resource that lies outside the V8 heap. ExternalStrings |
| 6316 | // consist of the length field common to all strings, a pointer to the |
| 6317 | // external resource. It is important to ensure (externally) that the |
| 6318 | // resource is not deallocated while the ExternalString is live in the |
| 6319 | // V8 heap. |
| 6320 | // |
| 6321 | // The API expects that all ExternalStrings are created through the |
| 6322 | // API. Therefore, ExternalStrings should not be used internally. |
| 6323 | class ExternalString: public String { |
| 6324 | public: |
| 6325 | // Casting |
| 6326 | static inline ExternalString* cast(Object* obj); |
| 6327 | |
| 6328 | // Layout description. |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 6329 | static const int kResourceOffset = POINTER_SIZE_ALIGN(String::kSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6330 | static const int kSize = kResourceOffset + kPointerSize; |
| 6331 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6332 | STATIC_CHECK(kResourceOffset == Internals::kStringResourceOffset); |
| 6333 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6334 | private: |
| 6335 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalString); |
| 6336 | }; |
| 6337 | |
| 6338 | |
| 6339 | // The ExternalAsciiString class is an external string backed by an |
| 6340 | // ASCII string. |
| 6341 | class ExternalAsciiString: public ExternalString { |
| 6342 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 6343 | static const bool kHasAsciiEncoding = true; |
| 6344 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6345 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 6346 | |
| 6347 | // The underlying resource. |
| 6348 | inline Resource* resource(); |
| 6349 | inline void set_resource(Resource* buffer); |
| 6350 | |
| 6351 | // Dispatched behavior. |
| 6352 | uint16_t ExternalAsciiStringGet(int index); |
| 6353 | |
| 6354 | // Casting. |
| 6355 | static inline ExternalAsciiString* cast(Object* obj); |
| 6356 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6357 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6358 | inline void ExternalAsciiStringIterateBody(ObjectVisitor* v); |
| 6359 | |
| 6360 | template<typename StaticVisitor> |
| 6361 | inline void ExternalAsciiStringIterateBody(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6362 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6363 | // Support for StringInputBuffer. |
| 6364 | const unibrow::byte* ExternalAsciiStringReadBlock(unsigned* remaining, |
| 6365 | unsigned* offset, |
| 6366 | unsigned chars); |
| 6367 | inline void ExternalAsciiStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6368 | unsigned* offset, |
| 6369 | unsigned chars); |
| 6370 | |
| 6371 | private: |
| 6372 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalAsciiString); |
| 6373 | }; |
| 6374 | |
| 6375 | |
| 6376 | // The ExternalTwoByteString class is an external string backed by a UTF-16 |
| 6377 | // encoded string. |
| 6378 | class ExternalTwoByteString: public ExternalString { |
| 6379 | public: |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 6380 | static const bool kHasAsciiEncoding = false; |
| 6381 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6382 | typedef v8::String::ExternalStringResource Resource; |
| 6383 | |
| 6384 | // The underlying string resource. |
| 6385 | inline Resource* resource(); |
| 6386 | inline void set_resource(Resource* buffer); |
| 6387 | |
| 6388 | // Dispatched behavior. |
| 6389 | uint16_t ExternalTwoByteStringGet(int index); |
| 6390 | |
| 6391 | // For regexp code. |
| 6392 | const uint16_t* ExternalTwoByteStringGetData(unsigned start); |
| 6393 | |
| 6394 | // Casting. |
| 6395 | static inline ExternalTwoByteString* cast(Object* obj); |
| 6396 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6397 | // Garbage collection support. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6398 | inline void ExternalTwoByteStringIterateBody(ObjectVisitor* v); |
| 6399 | |
| 6400 | template<typename StaticVisitor> |
| 6401 | inline void ExternalTwoByteStringIterateBody(); |
| 6402 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 6403 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6404 | // Support for StringInputBuffer. |
| 6405 | void ExternalTwoByteStringReadBlockIntoBuffer(ReadBlockBuffer* buffer, |
| 6406 | unsigned* offset_ptr, |
| 6407 | unsigned chars); |
| 6408 | |
| 6409 | private: |
| 6410 | DISALLOW_IMPLICIT_CONSTRUCTORS(ExternalTwoByteString); |
| 6411 | }; |
| 6412 | |
| 6413 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6414 | // Utility superclass for stack-allocated objects that must be updated |
| 6415 | // on gc. It provides two ways for the gc to update instances, either |
| 6416 | // iterating or updating after gc. |
| 6417 | class Relocatable BASE_EMBEDDED { |
| 6418 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6419 | explicit inline Relocatable(Isolate* isolate); |
| 6420 | inline virtual ~Relocatable(); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6421 | virtual void IterateInstance(ObjectVisitor* v) { } |
| 6422 | virtual void PostGarbageCollection() { } |
| 6423 | |
| 6424 | static void PostGarbageCollectionProcessing(); |
| 6425 | static int ArchiveSpacePerThread(); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6426 | static char* ArchiveState(Isolate* isolate, char* to); |
| 6427 | static char* RestoreState(Isolate* isolate, char* from); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6428 | static void Iterate(ObjectVisitor* v); |
| 6429 | static void Iterate(ObjectVisitor* v, Relocatable* top); |
| 6430 | static char* Iterate(ObjectVisitor* v, char* t); |
| 6431 | private: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6432 | Isolate* isolate_; |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6433 | Relocatable* prev_; |
| 6434 | }; |
| 6435 | |
| 6436 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6437 | // A flat string reader provides random access to the contents of a |
| 6438 | // string independent of the character width of the string. The handle |
| 6439 | // must be valid as long as the reader is being used. |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6440 | class FlatStringReader : public Relocatable { |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6441 | public: |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6442 | FlatStringReader(Isolate* isolate, Handle<String> str); |
| 6443 | FlatStringReader(Isolate* isolate, Vector<const char> input); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6444 | void PostGarbageCollection(); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6445 | inline uc32 Get(int index); |
| 6446 | int length() { return length_; } |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6447 | private: |
| 6448 | String** str_; |
| 6449 | bool is_ascii_; |
| 6450 | int length_; |
| 6451 | const void* start_; |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 6452 | }; |
| 6453 | |
| 6454 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6455 | // Note that StringInputBuffers are not valid across a GC! To fix this |
| 6456 | // it would have to store a String Handle instead of a String* and |
| 6457 | // AsciiStringReadBlock would have to be modified to use memcpy. |
| 6458 | // |
| 6459 | // StringInputBuffer is able to traverse any string regardless of how |
| 6460 | // deeply nested a sequence of ConsStrings it is made of. However, |
| 6461 | // performance will be better if deep strings are flattened before they |
| 6462 | // are traversed. Since flattening requires memory allocation this is |
| 6463 | // not always desirable, however (esp. in debugging situations). |
| 6464 | class StringInputBuffer: public unibrow::InputBuffer<String, String*, 1024> { |
| 6465 | public: |
| 6466 | virtual void Seek(unsigned pos); |
| 6467 | inline StringInputBuffer(): unibrow::InputBuffer<String, String*, 1024>() {} |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 6468 | explicit inline StringInputBuffer(String* backing): |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6469 | unibrow::InputBuffer<String, String*, 1024>(backing) {} |
| 6470 | }; |
| 6471 | |
| 6472 | |
| 6473 | class SafeStringInputBuffer |
| 6474 | : public unibrow::InputBuffer<String, String**, 256> { |
| 6475 | public: |
| 6476 | virtual void Seek(unsigned pos); |
| 6477 | inline SafeStringInputBuffer() |
| 6478 | : unibrow::InputBuffer<String, String**, 256>() {} |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 6479 | explicit inline SafeStringInputBuffer(String** backing) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6480 | : unibrow::InputBuffer<String, String**, 256>(backing) {} |
| 6481 | }; |
| 6482 | |
| 6483 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6484 | template <typename T> |
| 6485 | class VectorIterator { |
| 6486 | public: |
| 6487 | VectorIterator(T* d, int l) : data_(Vector<const T>(d, l)), index_(0) { } |
| 6488 | explicit VectorIterator(Vector<const T> data) : data_(data), index_(0) { } |
| 6489 | T GetNext() { return data_[index_++]; } |
| 6490 | bool has_more() { return index_ < data_.length(); } |
| 6491 | private: |
| 6492 | Vector<const T> data_; |
| 6493 | int index_; |
| 6494 | }; |
| 6495 | |
| 6496 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6497 | // The Oddball describes objects null, undefined, true, and false. |
| 6498 | class Oddball: public HeapObject { |
| 6499 | public: |
| 6500 | // [to_string]: Cached to_string computed at startup. |
| 6501 | DECL_ACCESSORS(to_string, String) |
| 6502 | |
| 6503 | // [to_number]: Cached to_number computed at startup. |
| 6504 | DECL_ACCESSORS(to_number, Object) |
| 6505 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6506 | inline byte kind(); |
| 6507 | inline void set_kind(byte kind); |
| 6508 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6509 | // Casting. |
| 6510 | static inline Oddball* cast(Object* obj); |
| 6511 | |
| 6512 | // Dispatched behavior. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6513 | #ifdef DEBUG |
| 6514 | void OddballVerify(); |
| 6515 | #endif |
| 6516 | |
| 6517 | // Initialize the fields. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6518 | MUST_USE_RESULT MaybeObject* Initialize(const char* to_string, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6519 | Object* to_number, |
| 6520 | byte kind); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6521 | |
| 6522 | // Layout description. |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6523 | static const int kToStringOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6524 | static const int kToNumberOffset = kToStringOffset + kPointerSize; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 6525 | static const int kKindOffset = kToNumberOffset + kPointerSize; |
| 6526 | static const int kSize = kKindOffset + kPointerSize; |
| 6527 | |
| 6528 | static const byte kFalse = 0; |
| 6529 | static const byte kTrue = 1; |
| 6530 | static const byte kNotBooleanMask = ~1; |
| 6531 | static const byte kTheHole = 2; |
| 6532 | static const byte kNull = 3; |
| 6533 | static const byte kArgumentMarker = 4; |
| 6534 | static const byte kUndefined = 5; |
| 6535 | static const byte kOther = 6; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6536 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6537 | typedef FixedBodyDescriptor<kToStringOffset, |
| 6538 | kToNumberOffset + kPointerSize, |
| 6539 | kSize> BodyDescriptor; |
| 6540 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6541 | private: |
| 6542 | DISALLOW_IMPLICIT_CONSTRUCTORS(Oddball); |
| 6543 | }; |
| 6544 | |
| 6545 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6546 | class JSGlobalPropertyCell: public HeapObject { |
| 6547 | public: |
| 6548 | // [value]: value of the global property. |
| 6549 | DECL_ACCESSORS(value, Object) |
| 6550 | |
| 6551 | // Casting. |
| 6552 | static inline JSGlobalPropertyCell* cast(Object* obj); |
| 6553 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6554 | #ifdef DEBUG |
| 6555 | void JSGlobalPropertyCellVerify(); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6556 | #endif |
| 6557 | #ifdef OBJECT_PRINT |
| 6558 | inline void JSGlobalPropertyCellPrint() { |
| 6559 | JSGlobalPropertyCellPrint(stdout); |
| 6560 | } |
| 6561 | void JSGlobalPropertyCellPrint(FILE* out); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6562 | #endif |
| 6563 | |
| 6564 | // Layout description. |
| 6565 | static const int kValueOffset = HeapObject::kHeaderSize; |
| 6566 | static const int kSize = kValueOffset + kPointerSize; |
| 6567 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6568 | typedef FixedBodyDescriptor<kValueOffset, |
| 6569 | kValueOffset + kPointerSize, |
| 6570 | kSize> BodyDescriptor; |
| 6571 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6572 | // Returns the isolate/heap this cell object belongs to. |
| 6573 | inline Isolate* isolate(); |
| 6574 | inline Heap* heap(); |
| 6575 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6576 | private: |
| 6577 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSGlobalPropertyCell); |
| 6578 | }; |
| 6579 | |
| 6580 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6581 | // The JSProxy describes EcmaScript Harmony proxies |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6582 | class JSProxy: public JSReceiver { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6583 | public: |
| 6584 | // [handler]: The handler property. |
| 6585 | DECL_ACCESSORS(handler, Object) |
| 6586 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 6587 | // [padding]: The padding slot (unused, see below). |
| 6588 | DECL_ACCESSORS(padding, Object) |
| 6589 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6590 | // Casting. |
| 6591 | static inline JSProxy* cast(Object* obj); |
| 6592 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 6593 | bool HasPropertyWithHandler(String* name); |
| 6594 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6595 | MUST_USE_RESULT MaybeObject* SetPropertyWithHandler( |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6596 | String* name, |
| 6597 | Object* value, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6598 | PropertyAttributes attributes, |
| 6599 | StrictModeFlag strict_mode); |
| 6600 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6601 | MUST_USE_RESULT MaybeObject* DeletePropertyWithHandler( |
| 6602 | String* name, |
| 6603 | DeleteMode mode); |
| 6604 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6605 | MUST_USE_RESULT PropertyAttributes GetPropertyAttributeWithHandler( |
| 6606 | JSReceiver* receiver, |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 6607 | String* name, |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6608 | bool* has_exception); |
| 6609 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 6610 | // Turn this into an (empty) JSObject. |
| 6611 | void Fix(); |
| 6612 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6613 | // Dispatched behavior. |
| 6614 | #ifdef OBJECT_PRINT |
| 6615 | inline void JSProxyPrint() { |
| 6616 | JSProxyPrint(stdout); |
| 6617 | } |
| 6618 | void JSProxyPrint(FILE* out); |
| 6619 | #endif |
| 6620 | #ifdef DEBUG |
| 6621 | void JSProxyVerify(); |
| 6622 | #endif |
| 6623 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 6624 | // Layout description. We add padding so that a proxy has the same |
| 6625 | // size as a virgin JSObject. This is essential for becoming a JSObject |
| 6626 | // upon freeze. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6627 | static const int kHandlerOffset = HeapObject::kHeaderSize; |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 6628 | static const int kPaddingOffset = kHandlerOffset + kPointerSize; |
| 6629 | static const int kSize = kPaddingOffset + kPointerSize; |
| 6630 | |
| 6631 | STATIC_CHECK(kSize == JSObject::kHeaderSize); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6632 | |
| 6633 | typedef FixedBodyDescriptor<kHandlerOffset, |
| 6634 | kHandlerOffset + kPointerSize, |
| 6635 | kSize> BodyDescriptor; |
| 6636 | |
| 6637 | private: |
| 6638 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSProxy); |
| 6639 | }; |
| 6640 | |
| 6641 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 6642 | // TODO(rossberg): Only a stub for now. |
| 6643 | class JSFunctionProxy: public JSProxy { |
| 6644 | public: |
| 6645 | // Casting. |
| 6646 | static inline JSFunctionProxy* cast(Object* obj); |
| 6647 | |
| 6648 | private: |
| 6649 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSFunctionProxy); |
| 6650 | }; |
| 6651 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 6652 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame^] | 6653 | // The JSWeakMap describes EcmaScript Harmony weak maps |
| 6654 | class JSWeakMap: public JSObject { |
| 6655 | public: |
| 6656 | // [table]: the backing hash table mapping keys to values. |
| 6657 | DECL_ACCESSORS(table, ObjectHashTable) |
| 6658 | |
| 6659 | // [next]: linked list of encountered weak maps during GC. |
| 6660 | DECL_ACCESSORS(next, Object) |
| 6661 | |
| 6662 | // Unchecked accessors to be used during GC. |
| 6663 | inline ObjectHashTable* unchecked_table(); |
| 6664 | |
| 6665 | // Casting. |
| 6666 | static inline JSWeakMap* cast(Object* obj); |
| 6667 | |
| 6668 | #ifdef OBJECT_PRINT |
| 6669 | inline void JSWeakMapPrint() { |
| 6670 | JSWeakMapPrint(stdout); |
| 6671 | } |
| 6672 | void JSWeakMapPrint(FILE* out); |
| 6673 | #endif |
| 6674 | #ifdef DEBUG |
| 6675 | void JSWeakMapVerify(); |
| 6676 | #endif |
| 6677 | |
| 6678 | static const int kTableOffset = JSObject::kHeaderSize; |
| 6679 | static const int kNextOffset = kTableOffset + kPointerSize; |
| 6680 | static const int kSize = kNextOffset + kPointerSize; |
| 6681 | |
| 6682 | private: |
| 6683 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSWeakMap); |
| 6684 | }; |
| 6685 | |
| 6686 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6687 | // Foreign describes objects pointing from JavaScript to C structures. |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 6688 | // Since they cannot contain references to JS HeapObjects they can be |
| 6689 | // placed in old_data_space. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6690 | class Foreign: public HeapObject { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6691 | public: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6692 | // [address]: field containing the address. |
| 6693 | inline Address address(); |
| 6694 | inline void set_address(Address value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6695 | |
| 6696 | // Casting. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6697 | static inline Foreign* cast(Object* obj); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6698 | |
| 6699 | // Dispatched behavior. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6700 | inline void ForeignIterateBody(ObjectVisitor* v); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6701 | |
| 6702 | template<typename StaticVisitor> |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6703 | inline void ForeignIterateBody(); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 6704 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6705 | #ifdef OBJECT_PRINT |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6706 | inline void ForeignPrint() { |
| 6707 | ForeignPrint(stdout); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6708 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6709 | void ForeignPrint(FILE* out); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6710 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6711 | #ifdef DEBUG |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6712 | void ForeignVerify(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6713 | #endif |
| 6714 | |
| 6715 | // Layout description. |
| 6716 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6717 | static const int kAddressOffset = HeapObject::kHeaderSize; |
| 6718 | static const int kSize = kAddressOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6719 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6720 | STATIC_CHECK(kAddressOffset == Internals::kForeignAddressOffset); |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 6721 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6722 | private: |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 6723 | DISALLOW_IMPLICIT_CONSTRUCTORS(Foreign); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6724 | }; |
| 6725 | |
| 6726 | |
| 6727 | // The JSArray describes JavaScript Arrays |
| 6728 | // Such an array can be in one of two modes: |
| 6729 | // - fast, backing storage is a FixedArray and length <= elements.length(); |
| 6730 | // Please note: push and pop can be used to grow and shrink the array. |
| 6731 | // - slow, backing storage is a HashTable with numbers as keys. |
| 6732 | class JSArray: public JSObject { |
| 6733 | public: |
| 6734 | // [length]: The length property. |
| 6735 | DECL_ACCESSORS(length, Object) |
| 6736 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 6737 | // Overload the length setter to skip write barrier when the length |
| 6738 | // is set to a smi. This matches the set function on FixedArray. |
| 6739 | inline void set_length(Smi* length); |
| 6740 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6741 | MUST_USE_RESULT MaybeObject* JSArrayUpdateLengthFromIndex(uint32_t index, |
| 6742 | Object* value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6743 | |
| 6744 | // Initialize the array with the given capacity. The function may |
| 6745 | // fail due to out-of-memory situations, but only if the requested |
| 6746 | // capacity is non-zero. |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 6747 | MUST_USE_RESULT MaybeObject* Initialize(int capacity); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6748 | |
| 6749 | // Set the content of the array to the content of storage. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 6750 | inline void SetContent(FixedArray* storage); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6751 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6752 | // Casting. |
| 6753 | static inline JSArray* cast(Object* obj); |
| 6754 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6755 | // Uses handles. Ensures that the fixed array backing the JSArray has at |
| 6756 | // least the stated size. |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 6757 | inline void EnsureSize(int minimum_size_of_backing_fixed_array); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 6758 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6759 | // Dispatched behavior. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6760 | #ifdef OBJECT_PRINT |
| 6761 | inline void JSArrayPrint() { |
| 6762 | JSArrayPrint(stdout); |
| 6763 | } |
| 6764 | void JSArrayPrint(FILE* out); |
| 6765 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6766 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6767 | void JSArrayVerify(); |
| 6768 | #endif |
| 6769 | |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 6770 | // Number of element slots to pre-allocate for an empty array. |
| 6771 | static const int kPreallocatedArrayElements = 4; |
| 6772 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6773 | // Layout description. |
| 6774 | static const int kLengthOffset = JSObject::kHeaderSize; |
| 6775 | static const int kSize = kLengthOffset + kPointerSize; |
| 6776 | |
| 6777 | private: |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 6778 | // Expand the fixed array backing of a fast-case JSArray to at least |
| 6779 | // the requested size. |
| 6780 | void Expand(int minimum_size_of_backing_fixed_array); |
| 6781 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6782 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSArray); |
| 6783 | }; |
| 6784 | |
| 6785 | |
whesse@chromium.org | b6e43bb | 2010-04-14 09:36:28 +0000 | [diff] [blame] | 6786 | // JSRegExpResult is just a JSArray with a specific initial map. |
| 6787 | // This initial map adds in-object properties for "index" and "input" |
| 6788 | // properties, as assigned by RegExp.prototype.exec, which allows |
| 6789 | // faster creation of RegExp exec results. |
| 6790 | // This class just holds constants used when creating the result. |
| 6791 | // After creation the result must be treated as a JSArray in all regards. |
| 6792 | class JSRegExpResult: public JSArray { |
| 6793 | public: |
| 6794 | // Offsets of object fields. |
| 6795 | static const int kIndexOffset = JSArray::kSize; |
| 6796 | static const int kInputOffset = kIndexOffset + kPointerSize; |
| 6797 | static const int kSize = kInputOffset + kPointerSize; |
| 6798 | // Indices of in-object properties. |
| 6799 | static const int kIndexIndex = 0; |
| 6800 | static const int kInputIndex = 1; |
| 6801 | private: |
| 6802 | DISALLOW_IMPLICIT_CONSTRUCTORS(JSRegExpResult); |
| 6803 | }; |
| 6804 | |
| 6805 | |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 6806 | // An accessor must have a getter, but can have no setter. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6807 | // |
| 6808 | // When setting a property, V8 searches accessors in prototypes. |
| 6809 | // If an accessor was found and it does not have a setter, |
| 6810 | // the request is ignored. |
| 6811 | // |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 6812 | // If the accessor in the prototype has the READ_ONLY property attribute, then |
| 6813 | // a new value is added to the local object when the property is set. |
| 6814 | // This shadows the accessor in the prototype. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6815 | class AccessorInfo: public Struct { |
| 6816 | public: |
| 6817 | DECL_ACCESSORS(getter, Object) |
| 6818 | DECL_ACCESSORS(setter, Object) |
| 6819 | DECL_ACCESSORS(data, Object) |
| 6820 | DECL_ACCESSORS(name, Object) |
| 6821 | DECL_ACCESSORS(flag, Smi) |
| 6822 | |
| 6823 | inline bool all_can_read(); |
| 6824 | inline void set_all_can_read(bool value); |
| 6825 | |
| 6826 | inline bool all_can_write(); |
| 6827 | inline void set_all_can_write(bool value); |
| 6828 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6829 | inline bool prohibits_overwriting(); |
| 6830 | inline void set_prohibits_overwriting(bool value); |
| 6831 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6832 | inline PropertyAttributes property_attributes(); |
| 6833 | inline void set_property_attributes(PropertyAttributes attributes); |
| 6834 | |
| 6835 | static inline AccessorInfo* cast(Object* obj); |
| 6836 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6837 | #ifdef OBJECT_PRINT |
| 6838 | inline void AccessorInfoPrint() { |
| 6839 | AccessorInfoPrint(stdout); |
| 6840 | } |
| 6841 | void AccessorInfoPrint(FILE* out); |
| 6842 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6843 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6844 | void AccessorInfoVerify(); |
| 6845 | #endif |
| 6846 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6847 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6848 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 6849 | static const int kDataOffset = kSetterOffset + kPointerSize; |
| 6850 | static const int kNameOffset = kDataOffset + kPointerSize; |
| 6851 | static const int kFlagOffset = kNameOffset + kPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 6852 | static const int kSize = kFlagOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6853 | |
| 6854 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6855 | // Bit positions in flag. |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6856 | static const int kAllCanReadBit = 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6857 | static const int kAllCanWriteBit = 1; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 6858 | static const int kProhibitsOverwritingBit = 2; |
| 6859 | class AttributesField: public BitField<PropertyAttributes, 3, 3> {}; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 6860 | |
| 6861 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessorInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6862 | }; |
| 6863 | |
| 6864 | |
| 6865 | class AccessCheckInfo: public Struct { |
| 6866 | public: |
| 6867 | DECL_ACCESSORS(named_callback, Object) |
| 6868 | DECL_ACCESSORS(indexed_callback, Object) |
| 6869 | DECL_ACCESSORS(data, Object) |
| 6870 | |
| 6871 | static inline AccessCheckInfo* cast(Object* obj); |
| 6872 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6873 | #ifdef OBJECT_PRINT |
| 6874 | inline void AccessCheckInfoPrint() { |
| 6875 | AccessCheckInfoPrint(stdout); |
| 6876 | } |
| 6877 | void AccessCheckInfoPrint(FILE* out); |
| 6878 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6879 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6880 | void AccessCheckInfoVerify(); |
| 6881 | #endif |
| 6882 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6883 | static const int kNamedCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6884 | static const int kIndexedCallbackOffset = kNamedCallbackOffset + kPointerSize; |
| 6885 | static const int kDataOffset = kIndexedCallbackOffset + kPointerSize; |
| 6886 | static const int kSize = kDataOffset + kPointerSize; |
| 6887 | |
| 6888 | private: |
| 6889 | DISALLOW_IMPLICIT_CONSTRUCTORS(AccessCheckInfo); |
| 6890 | }; |
| 6891 | |
| 6892 | |
| 6893 | class InterceptorInfo: public Struct { |
| 6894 | public: |
| 6895 | DECL_ACCESSORS(getter, Object) |
| 6896 | DECL_ACCESSORS(setter, Object) |
| 6897 | DECL_ACCESSORS(query, Object) |
| 6898 | DECL_ACCESSORS(deleter, Object) |
| 6899 | DECL_ACCESSORS(enumerator, Object) |
| 6900 | DECL_ACCESSORS(data, Object) |
| 6901 | |
| 6902 | static inline InterceptorInfo* cast(Object* obj); |
| 6903 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6904 | #ifdef OBJECT_PRINT |
| 6905 | inline void InterceptorInfoPrint() { |
| 6906 | InterceptorInfoPrint(stdout); |
| 6907 | } |
| 6908 | void InterceptorInfoPrint(FILE* out); |
| 6909 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6910 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6911 | void InterceptorInfoVerify(); |
| 6912 | #endif |
| 6913 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6914 | static const int kGetterOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6915 | static const int kSetterOffset = kGetterOffset + kPointerSize; |
| 6916 | static const int kQueryOffset = kSetterOffset + kPointerSize; |
| 6917 | static const int kDeleterOffset = kQueryOffset + kPointerSize; |
| 6918 | static const int kEnumeratorOffset = kDeleterOffset + kPointerSize; |
| 6919 | static const int kDataOffset = kEnumeratorOffset + kPointerSize; |
| 6920 | static const int kSize = kDataOffset + kPointerSize; |
| 6921 | |
| 6922 | private: |
| 6923 | DISALLOW_IMPLICIT_CONSTRUCTORS(InterceptorInfo); |
| 6924 | }; |
| 6925 | |
| 6926 | |
| 6927 | class CallHandlerInfo: public Struct { |
| 6928 | public: |
| 6929 | DECL_ACCESSORS(callback, Object) |
| 6930 | DECL_ACCESSORS(data, Object) |
| 6931 | |
| 6932 | static inline CallHandlerInfo* cast(Object* obj); |
| 6933 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6934 | #ifdef OBJECT_PRINT |
| 6935 | inline void CallHandlerInfoPrint() { |
| 6936 | CallHandlerInfoPrint(stdout); |
| 6937 | } |
| 6938 | void CallHandlerInfoPrint(FILE* out); |
| 6939 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6940 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6941 | void CallHandlerInfoVerify(); |
| 6942 | #endif |
| 6943 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6944 | static const int kCallbackOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6945 | static const int kDataOffset = kCallbackOffset + kPointerSize; |
erik.corry@gmail.com | 4a6c327 | 2010-11-18 12:04:40 +0000 | [diff] [blame] | 6946 | static const int kSize = kDataOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6947 | |
| 6948 | private: |
| 6949 | DISALLOW_IMPLICIT_CONSTRUCTORS(CallHandlerInfo); |
| 6950 | }; |
| 6951 | |
| 6952 | |
| 6953 | class TemplateInfo: public Struct { |
| 6954 | public: |
| 6955 | DECL_ACCESSORS(tag, Object) |
| 6956 | DECL_ACCESSORS(property_list, Object) |
| 6957 | |
| 6958 | #ifdef DEBUG |
| 6959 | void TemplateInfoVerify(); |
| 6960 | #endif |
| 6961 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 6962 | static const int kTagOffset = HeapObject::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6963 | static const int kPropertyListOffset = kTagOffset + kPointerSize; |
| 6964 | static const int kHeaderSize = kPropertyListOffset + kPointerSize; |
| 6965 | protected: |
| 6966 | friend class AGCCVersionRequiresThisClassToHaveAFriendSoHereItIs; |
| 6967 | DISALLOW_IMPLICIT_CONSTRUCTORS(TemplateInfo); |
| 6968 | }; |
| 6969 | |
| 6970 | |
| 6971 | class FunctionTemplateInfo: public TemplateInfo { |
| 6972 | public: |
| 6973 | DECL_ACCESSORS(serial_number, Object) |
| 6974 | DECL_ACCESSORS(call_code, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6975 | DECL_ACCESSORS(property_accessors, Object) |
| 6976 | DECL_ACCESSORS(prototype_template, Object) |
| 6977 | DECL_ACCESSORS(parent_template, Object) |
| 6978 | DECL_ACCESSORS(named_property_handler, Object) |
| 6979 | DECL_ACCESSORS(indexed_property_handler, Object) |
| 6980 | DECL_ACCESSORS(instance_template, Object) |
| 6981 | DECL_ACCESSORS(class_name, Object) |
| 6982 | DECL_ACCESSORS(signature, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6983 | DECL_ACCESSORS(instance_call_handler, Object) |
| 6984 | DECL_ACCESSORS(access_check_info, Object) |
| 6985 | DECL_ACCESSORS(flag, Smi) |
| 6986 | |
| 6987 | // Following properties use flag bits. |
| 6988 | DECL_BOOLEAN_ACCESSORS(hidden_prototype) |
| 6989 | DECL_BOOLEAN_ACCESSORS(undetectable) |
| 6990 | // If the bit is set, object instances created by this function |
| 6991 | // requires access check. |
| 6992 | DECL_BOOLEAN_ACCESSORS(needs_access_check) |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 6993 | DECL_BOOLEAN_ACCESSORS(read_only_prototype) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 6994 | |
| 6995 | static inline FunctionTemplateInfo* cast(Object* obj); |
| 6996 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 6997 | #ifdef OBJECT_PRINT |
| 6998 | inline void FunctionTemplateInfoPrint() { |
| 6999 | FunctionTemplateInfoPrint(stdout); |
| 7000 | } |
| 7001 | void FunctionTemplateInfoPrint(FILE* out); |
| 7002 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7003 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7004 | void FunctionTemplateInfoVerify(); |
| 7005 | #endif |
| 7006 | |
| 7007 | static const int kSerialNumberOffset = TemplateInfo::kHeaderSize; |
| 7008 | static const int kCallCodeOffset = kSerialNumberOffset + kPointerSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 7009 | static const int kPropertyAccessorsOffset = kCallCodeOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7010 | static const int kPrototypeTemplateOffset = |
| 7011 | kPropertyAccessorsOffset + kPointerSize; |
| 7012 | static const int kParentTemplateOffset = |
| 7013 | kPrototypeTemplateOffset + kPointerSize; |
| 7014 | static const int kNamedPropertyHandlerOffset = |
| 7015 | kParentTemplateOffset + kPointerSize; |
| 7016 | static const int kIndexedPropertyHandlerOffset = |
| 7017 | kNamedPropertyHandlerOffset + kPointerSize; |
| 7018 | static const int kInstanceTemplateOffset = |
| 7019 | kIndexedPropertyHandlerOffset + kPointerSize; |
| 7020 | static const int kClassNameOffset = kInstanceTemplateOffset + kPointerSize; |
| 7021 | static const int kSignatureOffset = kClassNameOffset + kPointerSize; |
v8.team.kasperl | 727e995 | 2008-09-02 14:56:44 +0000 | [diff] [blame] | 7022 | static const int kInstanceCallHandlerOffset = kSignatureOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7023 | static const int kAccessCheckInfoOffset = |
| 7024 | kInstanceCallHandlerOffset + kPointerSize; |
| 7025 | static const int kFlagOffset = kAccessCheckInfoOffset + kPointerSize; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 7026 | static const int kSize = kFlagOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7027 | |
| 7028 | private: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7029 | // Bit position in the flag, from least significant bit position. |
| 7030 | static const int kHiddenPrototypeBit = 0; |
| 7031 | static const int kUndetectableBit = 1; |
| 7032 | static const int kNeedsAccessCheckBit = 2; |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 7033 | static const int kReadOnlyPrototypeBit = 3; |
mads.s.ager | 31e7138 | 2008-08-13 09:32:07 +0000 | [diff] [blame] | 7034 | |
| 7035 | DISALLOW_IMPLICIT_CONSTRUCTORS(FunctionTemplateInfo); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7036 | }; |
| 7037 | |
| 7038 | |
| 7039 | class ObjectTemplateInfo: public TemplateInfo { |
| 7040 | public: |
| 7041 | DECL_ACCESSORS(constructor, Object) |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 7042 | DECL_ACCESSORS(internal_field_count, Object) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7043 | |
| 7044 | static inline ObjectTemplateInfo* cast(Object* obj); |
| 7045 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7046 | #ifdef OBJECT_PRINT |
| 7047 | inline void ObjectTemplateInfoPrint() { |
| 7048 | ObjectTemplateInfoPrint(stdout); |
| 7049 | } |
| 7050 | void ObjectTemplateInfoPrint(FILE* out); |
| 7051 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7052 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7053 | void ObjectTemplateInfoVerify(); |
| 7054 | #endif |
| 7055 | |
| 7056 | static const int kConstructorOffset = TemplateInfo::kHeaderSize; |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 7057 | static const int kInternalFieldCountOffset = |
| 7058 | kConstructorOffset + kPointerSize; |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 7059 | static const int kSize = kInternalFieldCountOffset + kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7060 | }; |
| 7061 | |
| 7062 | |
| 7063 | class SignatureInfo: public Struct { |
| 7064 | public: |
| 7065 | DECL_ACCESSORS(receiver, Object) |
| 7066 | DECL_ACCESSORS(args, Object) |
| 7067 | |
| 7068 | static inline SignatureInfo* cast(Object* obj); |
| 7069 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7070 | #ifdef OBJECT_PRINT |
| 7071 | inline void SignatureInfoPrint() { |
| 7072 | SignatureInfoPrint(stdout); |
| 7073 | } |
| 7074 | void SignatureInfoPrint(FILE* out); |
| 7075 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7076 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7077 | void SignatureInfoVerify(); |
| 7078 | #endif |
| 7079 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 7080 | static const int kReceiverOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7081 | static const int kArgsOffset = kReceiverOffset + kPointerSize; |
| 7082 | static const int kSize = kArgsOffset + kPointerSize; |
| 7083 | |
| 7084 | private: |
| 7085 | DISALLOW_IMPLICIT_CONSTRUCTORS(SignatureInfo); |
| 7086 | }; |
| 7087 | |
| 7088 | |
| 7089 | class TypeSwitchInfo: public Struct { |
| 7090 | public: |
| 7091 | DECL_ACCESSORS(types, Object) |
| 7092 | |
| 7093 | static inline TypeSwitchInfo* cast(Object* obj); |
| 7094 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7095 | #ifdef OBJECT_PRINT |
| 7096 | inline void TypeSwitchInfoPrint() { |
| 7097 | TypeSwitchInfoPrint(stdout); |
| 7098 | } |
| 7099 | void TypeSwitchInfoPrint(FILE* out); |
| 7100 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7101 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7102 | void TypeSwitchInfoVerify(); |
| 7103 | #endif |
| 7104 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 7105 | static const int kTypesOffset = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7106 | static const int kSize = kTypesOffset + kPointerSize; |
| 7107 | }; |
| 7108 | |
| 7109 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 7110 | #ifdef ENABLE_DEBUGGER_SUPPORT |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 7111 | // The DebugInfo class holds additional information for a function being |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7112 | // debugged. |
| 7113 | class DebugInfo: public Struct { |
| 7114 | public: |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 7115 | // The shared function info for the source being debugged. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7116 | DECL_ACCESSORS(shared, SharedFunctionInfo) |
| 7117 | // Code object for the original code. |
| 7118 | DECL_ACCESSORS(original_code, Code) |
| 7119 | // Code object for the patched code. This code object is the code object |
| 7120 | // currently active for the function. |
| 7121 | DECL_ACCESSORS(code, Code) |
| 7122 | // Fixed array holding status information for each active break point. |
| 7123 | DECL_ACCESSORS(break_points, FixedArray) |
| 7124 | |
| 7125 | // Check if there is a break point at a code position. |
| 7126 | bool HasBreakPoint(int code_position); |
| 7127 | // Get the break point info object for a code position. |
| 7128 | Object* GetBreakPointInfo(int code_position); |
| 7129 | // Clear a break point. |
| 7130 | static void ClearBreakPoint(Handle<DebugInfo> debug_info, |
| 7131 | int code_position, |
| 7132 | Handle<Object> break_point_object); |
| 7133 | // Set a break point. |
| 7134 | static void SetBreakPoint(Handle<DebugInfo> debug_info, int code_position, |
| 7135 | int source_position, int statement_position, |
| 7136 | Handle<Object> break_point_object); |
| 7137 | // Get the break point objects for a code position. |
| 7138 | Object* GetBreakPointObjects(int code_position); |
| 7139 | // Find the break point info holding this break point object. |
| 7140 | static Object* FindBreakPointInfo(Handle<DebugInfo> debug_info, |
| 7141 | Handle<Object> break_point_object); |
| 7142 | // Get the number of break points for this function. |
| 7143 | int GetBreakPointCount(); |
| 7144 | |
| 7145 | static inline DebugInfo* cast(Object* obj); |
| 7146 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7147 | #ifdef OBJECT_PRINT |
| 7148 | inline void DebugInfoPrint() { |
| 7149 | DebugInfoPrint(stdout); |
| 7150 | } |
| 7151 | void DebugInfoPrint(FILE* out); |
| 7152 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7153 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7154 | void DebugInfoVerify(); |
| 7155 | #endif |
| 7156 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 7157 | static const int kSharedFunctionInfoIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7158 | static const int kOriginalCodeIndex = kSharedFunctionInfoIndex + kPointerSize; |
| 7159 | static const int kPatchedCodeIndex = kOriginalCodeIndex + kPointerSize; |
| 7160 | static const int kActiveBreakPointsCountIndex = |
| 7161 | kPatchedCodeIndex + kPointerSize; |
| 7162 | static const int kBreakPointsStateIndex = |
| 7163 | kActiveBreakPointsCountIndex + kPointerSize; |
| 7164 | static const int kSize = kBreakPointsStateIndex + kPointerSize; |
| 7165 | |
| 7166 | private: |
| 7167 | static const int kNoBreakPointInfo = -1; |
| 7168 | |
| 7169 | // Lookup the index in the break_points array for a code position. |
| 7170 | int GetBreakPointInfoIndex(int code_position); |
| 7171 | |
| 7172 | DISALLOW_IMPLICIT_CONSTRUCTORS(DebugInfo); |
| 7173 | }; |
| 7174 | |
| 7175 | |
| 7176 | // The BreakPointInfo class holds information for break points set in a |
| 7177 | // function. The DebugInfo object holds a BreakPointInfo object for each code |
| 7178 | // position with one or more break points. |
| 7179 | class BreakPointInfo: public Struct { |
| 7180 | public: |
| 7181 | // The position in the code for the break point. |
| 7182 | DECL_ACCESSORS(code_position, Smi) |
| 7183 | // The position in the source for the break position. |
| 7184 | DECL_ACCESSORS(source_position, Smi) |
| 7185 | // The position in the source for the last statement before this break |
| 7186 | // position. |
| 7187 | DECL_ACCESSORS(statement_position, Smi) |
| 7188 | // List of related JavaScript break points. |
| 7189 | DECL_ACCESSORS(break_point_objects, Object) |
| 7190 | |
| 7191 | // Removes a break point. |
| 7192 | static void ClearBreakPoint(Handle<BreakPointInfo> info, |
| 7193 | Handle<Object> break_point_object); |
| 7194 | // Set a break point. |
| 7195 | static void SetBreakPoint(Handle<BreakPointInfo> info, |
| 7196 | Handle<Object> break_point_object); |
| 7197 | // Check if break point info has this break point object. |
| 7198 | static bool HasBreakPointObject(Handle<BreakPointInfo> info, |
| 7199 | Handle<Object> break_point_object); |
| 7200 | // Get the number of break points for this code position. |
| 7201 | int GetBreakPointCount(); |
| 7202 | |
| 7203 | static inline BreakPointInfo* cast(Object* obj); |
| 7204 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 7205 | #ifdef OBJECT_PRINT |
| 7206 | inline void BreakPointInfoPrint() { |
| 7207 | BreakPointInfoPrint(stdout); |
| 7208 | } |
| 7209 | void BreakPointInfoPrint(FILE* out); |
| 7210 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7211 | #ifdef DEBUG |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7212 | void BreakPointInfoVerify(); |
| 7213 | #endif |
| 7214 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 7215 | static const int kCodePositionIndex = Struct::kHeaderSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7216 | static const int kSourcePositionIndex = kCodePositionIndex + kPointerSize; |
| 7217 | static const int kStatementPositionIndex = |
| 7218 | kSourcePositionIndex + kPointerSize; |
| 7219 | static const int kBreakPointObjectsIndex = |
| 7220 | kStatementPositionIndex + kPointerSize; |
| 7221 | static const int kSize = kBreakPointObjectsIndex + kPointerSize; |
| 7222 | |
| 7223 | private: |
| 7224 | DISALLOW_IMPLICIT_CONSTRUCTORS(BreakPointInfo); |
| 7225 | }; |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 7226 | #endif // ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7227 | |
| 7228 | |
| 7229 | #undef DECL_BOOLEAN_ACCESSORS |
| 7230 | #undef DECL_ACCESSORS |
| 7231 | |
| 7232 | |
| 7233 | // Abstract base class for visiting, and optionally modifying, the |
| 7234 | // pointers contained in Objects. Used in GC and serialization/deserialization. |
| 7235 | class ObjectVisitor BASE_EMBEDDED { |
| 7236 | public: |
| 7237 | virtual ~ObjectVisitor() {} |
| 7238 | |
| 7239 | // Visits a contiguous arrays of pointers in the half-open range |
| 7240 | // [start, end). Any or all of the values may be modified on return. |
| 7241 | virtual void VisitPointers(Object** start, Object** end) = 0; |
| 7242 | |
| 7243 | // To allow lazy clearing of inline caches the visitor has |
| 7244 | // a rich interface for iterating over Code objects.. |
| 7245 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7246 | // Visits a code target in the instruction stream. |
| 7247 | virtual void VisitCodeTarget(RelocInfo* rinfo); |
| 7248 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 7249 | // Visits a code entry in a JS function. |
| 7250 | virtual void VisitCodeEntry(Address entry_address); |
| 7251 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7252 | // Visits a global property cell reference in the instruction stream. |
| 7253 | virtual void VisitGlobalPropertyCell(RelocInfo* rinfo); |
| 7254 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7255 | // Visits a runtime entry in the instruction stream. |
| 7256 | virtual void VisitRuntimeEntry(RelocInfo* rinfo) {} |
| 7257 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 7258 | // Visits the resource of an ASCII or two-byte string. |
| 7259 | virtual void VisitExternalAsciiString( |
| 7260 | v8::String::ExternalAsciiStringResource** resource) {} |
| 7261 | virtual void VisitExternalTwoByteString( |
| 7262 | v8::String::ExternalStringResource** resource) {} |
| 7263 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7264 | // Visits a debug call target in the instruction stream. |
| 7265 | virtual void VisitDebugTarget(RelocInfo* rinfo); |
| 7266 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7267 | // Handy shorthand for visiting a single pointer. |
| 7268 | virtual void VisitPointer(Object** p) { VisitPointers(p, p + 1); } |
| 7269 | |
| 7270 | // Visits a contiguous arrays of external references (references to the C++ |
| 7271 | // heap) in the half-open range [start, end). Any or all of the values |
| 7272 | // may be modified on return. |
| 7273 | virtual void VisitExternalReferences(Address* start, Address* end) {} |
| 7274 | |
| 7275 | inline void VisitExternalReference(Address* p) { |
| 7276 | VisitExternalReferences(p, p + 1); |
| 7277 | } |
| 7278 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 7279 | // Visits a handle that has an embedder-assigned class ID. |
| 7280 | virtual void VisitEmbedderReference(Object** p, uint16_t class_id) {} |
| 7281 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7282 | #ifdef DEBUG |
| 7283 | // Intended for serialization/deserialization checking: insert, or |
| 7284 | // check for the presence of, a tag at this position in the stream. |
| 7285 | virtual void Synchronize(const char* tag) {} |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 7286 | #else |
| 7287 | inline void Synchronize(const char* tag) {} |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7288 | #endif |
| 7289 | }; |
| 7290 | |
| 7291 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 7292 | class StructBodyDescriptor : public |
| 7293 | FlexibleBodyDescriptor<HeapObject::kHeaderSize> { |
| 7294 | public: |
| 7295 | static inline int SizeOf(Map* map, HeapObject* object) { |
| 7296 | return map->instance_size(); |
| 7297 | } |
| 7298 | }; |
| 7299 | |
| 7300 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 7301 | // BooleanBit is a helper class for setting and getting a bit in an |
| 7302 | // integer or Smi. |
| 7303 | class BooleanBit : public AllStatic { |
| 7304 | public: |
| 7305 | static inline bool get(Smi* smi, int bit_position) { |
| 7306 | return get(smi->value(), bit_position); |
| 7307 | } |
| 7308 | |
| 7309 | static inline bool get(int value, int bit_position) { |
| 7310 | return (value & (1 << bit_position)) != 0; |
| 7311 | } |
| 7312 | |
| 7313 | static inline Smi* set(Smi* smi, int bit_position, bool v) { |
| 7314 | return Smi::FromInt(set(smi->value(), bit_position, v)); |
| 7315 | } |
| 7316 | |
| 7317 | static inline int set(int value, int bit_position, bool v) { |
| 7318 | if (v) { |
| 7319 | value |= (1 << bit_position); |
| 7320 | } else { |
| 7321 | value &= ~(1 << bit_position); |
| 7322 | } |
| 7323 | return value; |
| 7324 | } |
| 7325 | }; |
| 7326 | |
| 7327 | } } // namespace v8::internal |
| 7328 | |
| 7329 | #endif // V8_OBJECTS_H_ |